Models¶
Types and methods that allows you to load and project 3D models.
This is mostly for internal use for RSObjects and RSEntities but you may use this directly if you need and know what you are doing.
If you are curious about how the projection works you should read about Projection.
TModelFace type¶
Type that represents a model face.
A model face consists of 3 vertices indices making a triangle and a “material” index to give the face a color.
A 3D model will have several of these.
TModel type¶
Type that represents a 3D model.
A model in it’s basic form confists of several Vertices (TVector3Array) and
faces that represent triangles among those vertices
(array of TModelFace type).
Model.LoadMTL¶
procedure TModel.LoadMTL(fileName: string);
Read and parses a material .mtl file and loads it’s data into the TModel.
This is used to load materials (colors) into the TModel.
Model.LoadOBJ¶
procedure TModel.LoadOBJ(fileName: string);
Read and parses a model .obj file and loads it’s data into the TModel.
This is used load vertices and faces information into the TModel.
Model.Construct¶
function TModel.Construct(objFile: String; mtlFile: String = ''): TModel; static;
Creates a new TModel out of the objFile and mtlFile passed in.
If mtlFile is left empty no material data is loaded.
Example:
{$I WaspLib/osrs.simba}
var
model: TModel;
begin
model := new TModel('path/to/my/model.obj');
end.
Model.Scale¶
procedure TModel.Scale(factor: Single);
Scales a model by the factor.
Example:
{$I WaspLib/osrs.simba}
var
img: TImage;
model: TModel;
tpa: TPointArray;
i: Integer;
begin
model := new TModel('path/to/my/model.obj');
while True do
begin
for i := 0 to 100 do
begin
img := Target.GetImage(MainScreen.Bounds);
model.Scale(0.99);
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
model.DrawModel(img, tpa, True);
img.Show();
end;
for i := 0 to 100 do
begin
img := Target.GetImage(MainScreen.Bounds);
model.Scale(1.01);
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
model.DrawModel(img, tpa, True);
img.Show();
end;
end;
end.
Model.Rotate¶
procedure TModel.Rotate(radians: Single);
Rotates a model in the X axis by radians.
Example:
{$I WaspLib/osrs.simba}
var
img: TImage;
model: TModel;
tpa: TPointArray;
begin
model := new TModel('path/to/my/model.obj');
while True do
begin
img := Target.GetImage(MainScreen.Bounds);
model.Rotate(0.005);
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
model.DrawModel(img, tpa, True);
img.Show();
end;
end.
Model.Offset¶
procedure TModel.Offset(value: TVector3);
Offsets a model in the 3D space by value.
Example:
{$I WaspLib/osrs.simba}
var
img: TImage;
model: TModel;
tpa: TPointArray;
i: Integer;
begin
model := new TModel('path/to/my/model.obj');
while True do
begin
for i := 1 to 600 do
begin
img := Target.GetImage(MainScreen.Bounds);
case i of
1..100: model.Offset([0,0,0.1]);
101..200: model.Offset([0,0,-0.1]);
201..300: model.Offset([0.1,0,0]);
301..400: model.Offset([-0.1,0,0]);
401..500: model.Offset([0,0.1,0]);
501..600: model.Offset([0,-0.1,0]);
end;
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
model.DrawModel(img, tpa, True);
img.Show();
end;
end;
end.
Model.GetArea¶
function TModel.GetArea(projection: TPointArray): TPointArray;
Takes a model projection as a TPointArray which you can get with
Model.Project and returns it’s area filled as a TPointArray with the
“faces” information.
It’s very useful to get clickboxes of models.
Example:
{$I WaspLib/osrs.simba}
var
model: TModel;
tpa: TPointArray;
begin
model := new TModel('path/to/my/model.obj');
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
ShowOnTarget(model.GetArea(tpa));
end.
Model.GetEdges¶
function TModel.GetEdges(projection: TPointArray): TPointArray;
Takes a model projection as a TPointArray which you can get with
Model.Project and returns it’s area edges as a TPointArray with the
“faces” information.
Essentially gives you the model outline.
Example:
{$I WaspLib/osrs.simba}
var
model: TModel;
tpa: TPointArray;
begin
model := new TModel('path/to/my/model.obj');
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
ShowOnTarget(model.GetEdges(tpa));
end.
Model.DrawModel¶
procedure TModel.DrawModel(img: TImage; projection: TPointArray; outline: Boolean = True);
Draws a model projection into a img.
Example:
{$I WaspLib/osrs.simba}
var
img: TImage;
model: TModel;
tpa: TPointArray;
begin
img := Target.GetImage(MainScreen.Bounds);
model := new TModel('path/to/my/model.obj');
tpa := Projection.ProjectModel(model, Minimap.Center.ToVec3(), Minimap.CompassRadians, 0);
model.DrawModel(img, tpa, True);
img.Show();
end.