我有一個二進制STL彩色文件。我可以使用在線網格查看器http://www.viewstl.com/查看顏色。如何使用three.js查看STL文件的內在顏色?
我正在使用下面的標準方法加載和可視化stl文件,它運作良好。但是,內在顏色顯示不正確,對照明變化太敏感。
Detector.addGetWebGLMessage();
scene = new THREE.Scene();
var aspect = window.innerWidth/window.innerHeight;
var d = 100;
camera = new THREE.OrthographicCamera(- d * aspect, d, d * aspect,- d, 1, 1000);
camera.position.set(0, 0, 200);
camera.lookAt(scene.position);
scene.add(camera);
var light = new THREE.AmbientLight(0x404040); // soft white light
scene.add(light);
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.x = 0;
directionalLight.position.y = 0;
directionalLight.position.z = 1;
directionalLight.position.normalize();
scene.add(directionalLight);
var loader = new THREE.STLLoader();
var material = new THREE.MeshPhongMaterial({ color: 0xAAAAAA, specular: 0x111111, shininess: 0 });
// Colored binary STL
var stlfile = "myBinarySTLColoredFile.stl"
loader.load(stlfile, function (geometry) {
var meshMaterial = material;
if (geometry.hasColors) {
meshMaterial = new THREE.MeshPhongMaterial({ opacity: geometry.alpha, vertexColors: THREE.VertexColors });
}
mesh = new THREE.Mesh(geometry, meshMaterial);
scene.add(
mesh.position.set(-100, -100, 0);
});
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(....);
var container = document.getElementById('`enter code here`flex2');
問題:如何以可視化封閉在STL文件中的顏色?
感謝
嗨,我正在一個項目,需要在瀏覽器上顯示STL文件,但目前我不知道如何做到這一點。你能給我一些建議嗎?如果你能爲我提供一個工作演示,那將非常棒。謝謝 –