[英].obj Texture and Color Not Showing in Three.js
For some reason when I add a new model in .obj and .mtl into my three.js code, the color will become white, despite whatever the original color or texture is.出于某种原因,当我将 .obj 和 .mtl 中的新模型添加到我的 Three.js 代码中时,无论原始颜色或纹理是什么,颜色都会变成白色。 The following is a snippet of the code responsible for the pig model:以下是负责猪模型的代码片段:
// pigmodel var objLoader = new OBJLoader(); var mtlLoader = new MTLLoader(); function loadpigmodel( x, y, z, ang, scale ) { mtlLoader.setPath( './images/' ); mtlLoader.load( 'Pig1.mtl', function ( loadedMesh ) { objLoader.setMaterials( loadedMesh ); objLoader.load( './images/Pig1.obj', function ( object ) { switch ( scale ) { case 'big': object.scale.set( 100, 100, 100 ); break; case 'small': object.scale.set( 90, 90, 90 ); break; default: }
The code above simulates a pigsty with some compost boxes.上面的代码模拟了一个带有一些堆肥箱的猪圈。 As you can see, the pig displayed in the code is white, even though it should be pink.如您所见,代码中显示的猪是白色的,尽管它应该是粉红色的。 The fence should also have wooden texture, but instead, it is also white.栅栏也应该有木质纹理,但它也是白色的。 pig model image猪模型图像
We suspect that there is something wrong with the mtl file of the things that became white.我们怀疑变白的东西的mtl文件有问题。 The full code and the mtl files are included in this hyperlink .完整代码和 mtl 文件包含在此 超链接中。
in Pig1.obj
you have usemtl Pig1
(use material Pig1) which assumes there is a decleration newmtl Pig1
(new material Pig1) somewhere in Pig1.mtl
, but when you check that file, there is no such material, only newmtl pigskin
在Pig1.obj
您有usemtl Pig1
(使用材料 Pig1),它假定 Pig1.mtl 中某处有Pig1.mtl
newmtl Pig1
(新材料 Pig1),但是当您检查该文件时,没有这样的材料,只有newmtl pigskin
Solution:解决方案:
Pig1.mtl
打开Pig1.mtl
newmtl pigskin
to newmtl Pig1
更改newmtl pigskin
来newmtl Pig1
Or change the usemtl to pigskin in your obj-file, whichever makes you happier.或者在您的 obj 文件中将 usemtl 更改为 pigskin,以让您更开心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.