我有一个TModel3D,我可以在viewport3d中显示,但我无法弄清楚如何纹理...
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;
我已经尝试了所有我能想到的,但是如何让“texture.jpg”纹理模型?
当我运行时,我确实看到没有纹理的模型。
答案 0 :(得分:1)
使用我自己的DAE模型和纹理文件在XE2上进行了上下文测试,似乎运行良好。
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');
从游戏架构的角度来看,您应该创建一个类似于TPlayer
的自定义类,并将模型作为该对象的成员。这样,所有玩家控件都可以与TPlayer
相关联,并且它成为一个描述的实体,而不是只需要在游戏逻辑中从高处手动操作的模型。
此外,您还需要确保模型的位置和相机的位置在相机的透视框内。
答案 1 :(得分:1)
Delphi 10
For I := 0 to Length(Model3d1.MeshCollection) - 1 do
Model3d1.MeshCollection[I].MaterialSource := TextureMaterialSource1;