简体   繁体   English

如何修改用OBJMTLLoader加载的场景中对象的参数?

[英]How can I modify parameters of Objects in my scene loaded with OBJMTLLoader?

I have an scene with 3 cubes and a DAT.GUI menu, I just want to set any cube to wireframe when it is checked on the menu (separatedly). 我有一个包含3个多维数据集和一个DAT.GUI菜单的场景,我只想将菜单上选中的任何多维数据集设置为线框(单独)。

What I did works for 2 of my 3 cubes, but I don't know why, the first cube is not modified, you can se the example here: 我所做的工作可用于3个多维数据集中的2个,但我不知道为什么,第一个多维数据集未修改,您可以在此处查看示例:

Link to Example 链接到示例

And here is the main code: 这是主要代码:

var loader = new THREE.OBJMTLLoader( manager );

    loader.load( '/pruebas/models/cubosMateriales.obj', "/pruebas/models/textures/cubosMateriales.mtl", function(object){

        contenido = object;
        contenido.position.set(0,0,0);
        contenido.position.y = -80;
        contenido.name = "cubes";

        scene.add(contenido);
        console.log(contenido);

        return contenido;
    })

    renderer.setSize( window.innerWidth, window.innerHeight );
    canvas.appendChild( renderer.domElement );

    window.addEventListener( 'resize', onWindowResize, false );
}

function animate()
{

    requestAnimationFrame( animate );
    controls.update();

    if(contenido != undefined){             
        contenido.traverse( function( object ) {            
                    if( object.material ) {
                        object.material.opacity = opciones.Opacidad;
                        object.material.transparent = true;

                        contenido.getObjectByName("Box001").material.wireframe=opciones.cube_1;
                        contenido.getObjectByName("Box002").material.wireframe=opciones.cube_2;
                        contenido.getObjectByName("Box003").material.wireframe=opciones.cube_3;     
                   }
        })
    }
    render();
}

And if you have a look at the DOM Tree, this is the structure created for 3 cubes. 如果您看一下DOM树,这是为3个多维数据集创建的结构。

树

Where the cubes are on the positions 1, 3 and 5. The rest of the positions contains some unidentified mess (haha, get it? Mesh.... ok... Forget it). 多维数据集在位置1、3和5上的位置。其余位置包含一些未知的混乱(哈哈,明白了吗?网格……好吧……算了吧)。

Can someone help me to identify the problem? 有人可以帮助我确定问题所在吗? Why I can't access the first cube, and what are all that meshes created with no name? 为什么我无法访问第一个多维数据集,而没有名称的所有网格物体是什么?

Although OBJMTLLoader is now deprecated, the result is the same if using OBJLoader + MTLLoader. 尽管现在已弃用OBJMTLLoader,但使用OBJLoader + MTLLoader的结果是相同的。 The problem here is that objects who share the same material in the OBJ (objects with the same material assigned in 3DS Max) inherit that property in Three.js, no matter what the DOM Tree says, each material is assigned to his geometry, and when you try to change only one by modifying a concrete child, all children with that material are modified . 这里的问题是,在OBJ中共享相同材质的对象(在3DS Max中分配了相同材质的对象)在Three.js中继承了该属性,无论DOM树说什么,每种材质都分配给了他的几何体,并且当您尝试通过修改一个具体的子项仅更改一个子项时, 所有具有该材质的子项都将被修改

The solution is to assign a different material to every object in 3DS Max and then export it to OBJ + MTL 解决方案是为3DS Max中的每个对象分配不同的材质 ,然后将其导出到OBJ + MTL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM