Delphi FMX:TModel3D 上的 Text3D(位置和旋转)
我有一个用 N
.obj-Files 描述的 3D 对象。例如,一个立方体由 6 个 .obj 文件描述。我将每个 obj-File 加载到 TModel3D
中:
files := TDirectory.GetFiles(aDirectory, '*.obj');
for I := 0 to Length(files) - 1 do begin
Self.Add(TModel3D.Create(nil));
Self.Items[Self.Count - 1].Parent := nil;
Self.Items[Self.Count - 1].Position.X := 0;
Self.Items[Self.Count - 1].Position.Y := 0;
Self.Items[Self.Count - 1].Position.Z := 0;
Self.Items[Self.Count - 1].TagString := 'File: ' + ExtractFileName(files[I]);
Self.Items[Self.Count - 1].HitTest := True;
Self.Items[Self.Count - 1].WrapMode := TMeshWrapMode.Original;
Self.Items[Self.Count - 1].LoadFromFile(files[I]);
它看起来像这样:
现在我想在每个表面上添加文本 ->所以我为每个 TModel3D
创建一个 TText3D
:
Self.Items[Self.Count - 1].FText := TText3D.Create(Self.Items[Self.Count - 1]);
Self.Items[Self.Count - 1].FText.Parent := Self.Items[Self.Count - 1];
Self.Items[Self.Count - 1].FText.Text := (I + 1).ToString;
//
Self.Items[Self.Count - 1].FText.WordWrap := False;
//
Self.Items[Self.Count - 1].FText.Stretch := False;
Self.Items[Self.Count - 1].FText.Font.Size := 0.002;
Self.Items[Self.Count - 1].FText.Depth := 0.01;
Self.Items[Self.Count - 1].FText.Height := 0.2;
Self.Items[Self.Count - 1].FText.Width := 0.5;
Self.Items[Self.Count - 1].FText.scale.X := 1;
Self.Items[Self.Count - 1].FText.scale.Y := 1;
Self.Items[Self.Count - 1].FText.WrapMode := TMeshWrapMode.Fit;
Self.Items[Self.Count - 1].FText.RotationAngle.X := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.X;
Self.Items[Self.Count - 1].FText.RotationAngle.Y := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.Y;
Self.Items[Self.Count - 1].FText.RotationAngle.Z := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.Z;
Self.Items[Self.Count - 1].FText.Position.X := Self.Items[Self.Count - 1].MeshCollection[0].Position.X;
Self.Items[Self.Count - 1].FText.Position.Y := Self.Items[Self.Count - 1].MeshCollection[0].Position.Y;
Self.Items[Self.Count - 1].FText.Position.Z := Self.Items[Self.Count - 1].MeshCollection[0].Position.Z;
end;
现在它看起来像这样:
问题是,我需要更改与 TModel3D
相比,每个 TText3D
的文本的 rotationAngle
。我不知道如何计算旋转,也许使用“faceNormals”
?
I have a 3D-Object described with N
.obj-Files. For example a cube is described with 6 .obj-Files. I load every obj-File into a TModel3D
:
files := TDirectory.GetFiles(aDirectory, '*.obj');
for I := 0 to Length(files) - 1 do begin
Self.Add(TModel3D.Create(nil));
Self.Items[Self.Count - 1].Parent := nil;
Self.Items[Self.Count - 1].Position.X := 0;
Self.Items[Self.Count - 1].Position.Y := 0;
Self.Items[Self.Count - 1].Position.Z := 0;
Self.Items[Self.Count - 1].TagString := 'File: ' + ExtractFileName(files[I]);
Self.Items[Self.Count - 1].HitTest := True;
Self.Items[Self.Count - 1].WrapMode := TMeshWrapMode.Original;
Self.Items[Self.Count - 1].LoadFromFile(files[I]);
It looks like this:
Now I want to add a text on every surface -> so I create a TText3D
for every TModel3D
:
Self.Items[Self.Count - 1].FText := TText3D.Create(Self.Items[Self.Count - 1]);
Self.Items[Self.Count - 1].FText.Parent := Self.Items[Self.Count - 1];
Self.Items[Self.Count - 1].FText.Text := (I + 1).ToString;
//
Self.Items[Self.Count - 1].FText.WordWrap := False;
//
Self.Items[Self.Count - 1].FText.Stretch := False;
Self.Items[Self.Count - 1].FText.Font.Size := 0.002;
Self.Items[Self.Count - 1].FText.Depth := 0.01;
Self.Items[Self.Count - 1].FText.Height := 0.2;
Self.Items[Self.Count - 1].FText.Width := 0.5;
Self.Items[Self.Count - 1].FText.scale.X := 1;
Self.Items[Self.Count - 1].FText.scale.Y := 1;
Self.Items[Self.Count - 1].FText.WrapMode := TMeshWrapMode.Fit;
Self.Items[Self.Count - 1].FText.RotationAngle.X := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.X;
Self.Items[Self.Count - 1].FText.RotationAngle.Y := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.Y;
Self.Items[Self.Count - 1].FText.RotationAngle.Z := Self.Items[Self.Count - 1].MeshCollection[0].RotationAngle.Z;
Self.Items[Self.Count - 1].FText.Position.X := Self.Items[Self.Count - 1].MeshCollection[0].Position.X;
Self.Items[Self.Count - 1].FText.Position.Y := Self.Items[Self.Count - 1].MeshCollection[0].Position.Y;
Self.Items[Self.Count - 1].FText.Position.Z := Self.Items[Self.Count - 1].MeshCollection[0].Position.Z;
end;
Now it looks like this:
The problem is, that I need to change the rotationAngle
of the text for every TText3D
in comparison of the TModel3D
. I don't know how to calculate the rotation, maybe with the "faceNormals"
?
This is how it should look like (I changed the rotationAngle
manually):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:
我为每个模型添加描述的方法是错误的。我在这里找到了一个解决方案: FireMonkey ViewPort procedure 计算不同的世界在 Mac 上屏幕
通过“WorldToScreen”功能,我能够为每个模型添加描述。
Solution:
My method to add a description for every model was wrong. I found a solution here: FireMonkey ViewPort procedure calculated differently world to screen on Mac
With the function "WorldToScreen" i was able to add a description for every model.