|

楼主 |
发表于 2016-5-12 12:03:47
|
显示全部楼层
给点核心程序吧。这也是我老师整的。好东西就要分享,
$ l5 d) k! K- b! Jvar loader = new THREE.STLLoader();
$ j, J7 o. o# w h( d* U var group = new THREE.Object3D();) W d7 B5 o2 Q( ]; V% I6 X
loader.load("../assets/models/a.stl", function (geometry) {
/ N" @& t: Q* a. Z- u0 Q console.log(geometry);4 }2 ^" W; |2 k* ~$ ^
/ J, j& ~. T: |
//加载到 mesh
0 O+ x: R* O8 D8 t: \# f var mat = new THREE.MeshLambertMaterial({color: 0x444444});
; h- ^/ J0 S5 m2 f; S* d7 K( L mesh = new THREE.Mesh(geometry, mat);: {- p/ c" D! I m: O! g6 I4 d
mesh .rotation.x = -0.5 * Math.PI;
; Q c' ^9 o/ k9 w0 q: c mesh .scale.set(0.6, 0.6, 0.6);( H; G3 o$ {+ x, p2 U/ m5 }. \
6 Z6 n; w! }& L0 ^' P8 K
//使用 box 生成边界,将物体调整到原点
2 f* H/ z1 @3 V. t, h+ @% Z var box = new THREE.Box3().setFromObject( mesh );
5 t/ O: P! A# k8 s# ^7 g8 M6 \ box.center( mesh.position ); // this re-sets the mesh position
2 U N6 b) }6 [. |# R; i mesh.position.multiplyScalar( - 1 );
2 Y! H" M; D+ P4 v, | //将mesh 加到组中
\( c- S$ ?" j( P group = new THREE.Group();" H% B9 c0 v$ O" j) r9 H8 t
scene.add( group );& {3 q( c: X8 `. m) l
group.add( mesh );( K2 |7 _: V2 p
4 `' @1 p' e$ Q* ~3 Z- ] //设置组的坐标为mesh显示到原点时mesh的中心点坐标取负值,移到加载时的位置
7 M4 R7 q! j6 N, U* g* A0 s" o8 b2 C group.position.y = -mesh.position.y;5 P/ T2 O9 C, e$ D$ j3 L
group.position.x = -mesh.position.x;
9 }! E0 M2 _7 F) ` group.position.z = -mesh.position.z;5 h5 ?: W" `2 y! o4 [ u3 {
. E; g, u h) H% n- R; a8 p8 l
}); |
|