Java3d:纹理未正确应用于 OBJ 模型
我使用以下几行将环面(obj 文件)的 3D 模型加载到我的程序中:
Shape3D torus=null;
Scene t1 = getSceneFromFile("Some local path\torus.obj");
然后我使用以下代码从场景中抓取模型:
BranchGroup branchGroup = t1.getSceneGroup();
torus = (Shape3D) branchGroup.getChild(0);
以下代码段将图像设置为纹理,然后将该纹理应用于外观目的。
TextureLoader textureLoader=new TextureLoader("Another local path\myImage.jpg",null);
ImageComponent2D image=textureLoader.getImage();
Texture2D texture=new Texture2D(Texture.BASE_LEVEL,Texture.RGBA,image.getWidth(),image.getHeight());
texture.setImage(0, image);
Appearance app = new Appearance();
app.setTexture(texture);
torus.setAppearance(app);
当我运行代码时,环面模型已正确加载,但纹理未正确分配。更准确地说,整个 3D 模型具有单一颜色而不是图像作为纹理。提到的颜色是图像左下角像素的颜色。
解决办法是什么? 提前致谢。
I load a 3d model of a torus (obj file) into my program, using these lines:
Shape3D torus=null;
Scene t1 = getSceneFromFile("Some local path\torus.obj");
Then I grab the model from the scene using this code:
BranchGroup branchGroup = t1.getSceneGroup();
torus = (Shape3D) branchGroup.getChild(0);
The following piece of code set an image as texture and then apply that texture to an Appearance object.
TextureLoader textureLoader=new TextureLoader("Another local path\myImage.jpg",null);
ImageComponent2D image=textureLoader.getImage();
Texture2D texture=new Texture2D(Texture.BASE_LEVEL,Texture.RGBA,image.getWidth(),image.getHeight());
texture.setImage(0, image);
Appearance app = new Appearance();
app.setTexture(texture);
torus.setAppearance(app);
When I run the code the torus model is loaded correctly but the texture is not assigned correctly. More accurately, the whole 3d model has a single color instead of an image as texture. Mentioned color, is the color of the pixel at bottom-left of the image.
What's the solution?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用于创建 obj 文件的程序(例如 Mudbox)还允许您分配 UV 模型图像。指定一个油漆层,然后将其导出为正确的格式。以为你可以加载纹理,但你不会获得对象的最佳细节。尝试使用此纹理加载器代码。
然后取你的 3D 模型名称,例如我巧妙命名的模型,并将外观设置为 ap 或
这将几乎 100% 加载它(如果你原来拥有它)。加载纹理海峡不会将其加载到所需的coridants。
A Program, for example Mudbox That you use to create the obj file, also allows you to assign UV model images. Assign a paint layer than export it to the correct format. Thought this you can load the texture, you wont have the best detail to the obj. Try using this textur loader code instead.
Then take your 3d models name, example mines cleverly named model, and set apperance to ap or
This will load it almost 100% were you origanly had it. Loading a texture strait up is not going to load it to the desired coridants.