I have a TModel3D that I can get to show up inside a viewport3d, but I cannot figure out how to texture it...
procedure TForm2.createMap(r:integer;c:integer);
var
player : tmodel3d;
begin
player := TModel3d.Create(self);
player.Visible := true;
Player.Position.X := 0;
player.Position.Y := 0;
player.position.Z := 2;
player.LoadFromFile(gamedir + '\pics\player.dae');
player.Parent := viewport3d1;
I have tried all I can think of, but how do make "texture.jpg" texture the model?
When I run this I do see the model without texture.
Tested contextually on XE2 here with my own DAE model and texture file, and seems to work well.
procedure TForm2.createMap(r:integer;c:integer);
var
player : tmodel3d;
begin
// NEVER create a 3D object as a sub-component of anything other than a 3D viewport!
player := TModel3d.Create(viewport3d1);
{
Ensure that the Parent is always set before operating on the control.
Some operations (such as texturing) will force the object to be re-rendered
so if your parent isn't specified (or isn't ready for rendering) it will cause
some nasty bugs.
}
player.Parent := viewport3d1;
player.Visible := true;
Player.Position.X := 0;
player.Position.Y := 0;
player.position.Z := 2;
player.LoadFromFile(gamedir+'\pics\player.dae');
player.MeshCollection[0].Material.texture.loadfromfile(gamedir+'\pics\playertexture.bmp');
From a game architecture perspective, you should really create a custom class akin to TPlayer
, and have the model as a member of that object. This way, all player controls can be associated with TPlayer
, and it becomes a described entity as opposed to just a model you have to manually manipulate from higher up in your game logic.
Also you want to ensure that the position of your model and that of your camera are such that it's within the camera's perspective frame.