Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Colors 使用three.js加载具有顶点颜色的collada文件_Colors_Three.js_Vertex_Collada - Fatal编程技术网

Colors 使用three.js加载具有顶点颜色的collada文件

Colors 使用three.js加载具有顶点颜色的collada文件,colors,three.js,vertex,collada,Colors,Three.js,Vertex,Collada,我正在尝试使用three.js加载dae文件,但无法获取要显示的材质。我找不到任何使用dae文件加载文件本身中的顶点颜色的示例。通过将材质设置为MeshBasicMaterial,将属性顶点颜色设置为顶点颜色,我可以在threejs.org/editor上加载它。我试图在代码中复制它,但我不太明白怎么做。这是我的加载函数 loader.load( 'objects/chair.dae', function ( collada ) { //dummy1.dae var dae = coll

我正在尝试使用three.js加载dae文件,但无法获取要显示的材质。我找不到任何使用dae文件加载文件本身中的顶点颜色的示例。通过将材质设置为MeshBasicMaterial,将属性顶点颜色设置为顶点颜色,我可以在threejs.org/editor上加载它。我试图在代码中复制它,但我不太明白怎么做。这是我的加载函数

loader.load( 'objects/chair.dae', function ( collada ) {
//dummy1.dae
    var dae = collada.scene;
    var skin = collada.skins[ 0 ];
    console.log(collada.scene);
    //collada.dae.materials[0] =   collada.scene.children[0].children[0].material;
    //dae.material = collada.scene.children[0].children[0].material;
    //var material = collada.scene.children[0].children[0].material;
    var material = new THREE.MeshBasicMaterial({
    vertexColors: THREE.VertexColors
    });
    collada.scene.position.set(0,0,0);//x,z,y- if you think in blender     dimensions ;)
    collada.scene.scale.set(15.0, 15.0, 15.0);
    var mesh = new THREE.Mesh(collada, material);
    scene.add(mesh);
    //scene.add(collada.scene);
    var axes = new THREE.AxisHelper(50);
    axes.position = dae.position;
    scene.add(axes);
    var gridXZ = new THREE.GridHelper(100, 10);
    gridXZ.setColors( new THREE.Color(0x8f8f8f), new THREE.Color(0x8f8f8f) );
    gridXZ.position.set(0,0,0 );
    scene.add(gridXZ);
});

这产生了一个错误

至于代码,基本上您必须更改Collada对象中网格的材质。比如:

        loader.load(
            // resource URL
            'models/example.dae',
            // Function when resource is loaded
            function ( collada ) {
                var dae = collada.scene;

                // CORRECT FOR IMPORTER
                // collada object with only vertex color are not correctly loaded
                dae.traverse( function(child) {
                    if (child instanceof THREE.Mesh) {
                        child.material = new THREE.MeshBasicMaterial( { vertexColors: true } );
                    }
                });

                dae.position.set(0,0,0);
                dae.scale.set(10, 10, 10);

                scene.add(dae);
                animate();
            },
            // Function called when download progresses
            function ( xhr ) {
                console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
            }
        );

这是我正在尝试加载的dae文件。。。