如何将纹理分配给 java3d 中加载的 OBJ 文件
我有一个 java 3d 应用程序,该应用程序将 OBJ 文件加载到我的场景中。如何为该模型分配纹理(jpg 文件)? 更准确地说,当我想将纹理分配给原始 java 对象(例如球体)时,我使用以下方法:
Sphere sphere = new Sphere(Radius, Primflags, Appearance);
但是,在加载和添加 obj 文件时,我这样做:
Scene scene = getSceneFromFile("OBJ file");
myBranchGroup = scene.getSceneGroup();
在第二种情况下,我找不到分配纹理的方法质地。我该怎么做呢?
I have a java 3d application and this application I load an OBJ file into my scene. How can I assign a texture (a jpg file) to this model?
To be more precise, when I want to assign texture to a primitive java object (e.g. sphere) I use the following:
Sphere sphere = new Sphere(Radius, Primflags, Appearance);
However, when loading and adding an obj file I do:
Scene scene = getSceneFromFile("OBJ file");
myBranchGroup = scene.getSceneGroup();
And in second case, I can find no way of assigning the texture. How should I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用制作 obj 文件的程序或者可以加载该文件。绘制它,然后导出该文件。然后在任何方法之外添加此代码
然后
然后在将模型分配到场景之前添加此代码。假设 3D 模型变量称为 model
You would have to use a program that you made the obj file or were you can load the file. Paint it, then export that file. Then add this code to it outside any methods
Then
Then add this before you assign the model to the scene. Assuming the 3D model varrible is called model
IIRC 您需要从分支组获取要应用纹理的
Shape3D
节点(调用setAppearance(...)
),例如使用getChild (index)
等。请注意,您可能会递归地遍历子级,因为您获得的分支组实际上可能包含其他组,因此您可能会在组树的下方找到形状。或者,您应该能够将
AlternateAppearance
对象添加到分支组中。IIRC you need to get the
Shape3D
node you want to apply the texture to (callingsetAppearance(...)
) from your branch group, e.g. by usinggetChild(index)
etc. Note that you might to iterate recursively through the children, since the branch group you get might actually contain other groups, so you might find the shapes further down the group tree.Alternatively you should be able to add an
AlternateAppearance
object to the branch group.