0

我能够通过 three.js 成功读取 stl 文件,但问题是没有显示 stl 文件中定义的确切颜色。我的代码如下所示:

var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
    var geometry = event.content;
    var material = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0xAAAAAA, specular: 0x111111, shininess: 200 } );
    if (geometry.hasColors) {
        material = new THREE.MeshPhongMaterial({ color: 0xFFFFFF, specular: 0x111111, ambient: 0x555555, opacity: geometry.alpha, vertexColors: THREE.VertexColors });
    }
    var mesh = new THREE.Mesh( geometry, material );
    mesh.position.x = x - w/2;
    mesh.position.y = y;
    mesh.position.z = - h + h/2 + z/2;
    //mesh.rotation.set( 0.5, 0, 0 );
    mesh.castShadow = true;
    mesh.receiveShadow = true;
    board.add(mesh);
} );

loader.load( fileName ); 

但是在应用顶点颜色后它只显示黑色。有什么建议吗?

4

0 回答 0