WebGL做的减速器展示(根据soildworks模型导入的)
一直在学习。怎么附件显示不出来
给点核心程序吧。这也是我老师整的。好东西就要分享,
var loader = new THREE.STLLoader();
var group = new THREE.Object3D();
loader.load("../assets/models/a.stl", function (geometry) {
console.log(geometry);
//加载到 mesh
var mat = new THREE.MeshLambertMaterial({color: 0x444444});
mesh= new THREE.Mesh(geometry, mat);
mesh .rotation.x = -0.5 * Math.PI;
mesh .scale.set(0.6, 0.6, 0.6);
//使用 box 生成边界,将物体调整到原点
var box = new THREE.Box3().setFromObject( mesh );
box.center( mesh.position ); // this re-sets the mesh position
mesh.position.multiplyScalar( - 1 );
//将mesh 加到组中
group = new THREE.Group();
scene.add( group );
group.add( mesh );
//设置组的坐标为mesh显示到原点时mesh的中心点坐标取负值,移到加载时的位置
group.position.y =-mesh.position.y;
group.position.x =-mesh.position.x;
group.position.z =-mesh.position.z;
});
页:
[1]