|
3#
樓主 |
發表于 2016-5-12 12:03:47
|
只看該作者
給點核心程序吧。這也是我老師整的。好東西就要分享,
! W+ U C. G6 u! u5 |var loader = new THREE.STLLoader();& g9 N- R* [( G, _7 z ~/ l! q
var group = new THREE.Object3D();
) y) l# S/ p! s7 T( C; g$ S loader.load("../assets/models/a.stl", function (geometry) {
! t- Y; A& ?8 n' s console.log(geometry);- l$ S0 f. W- Q$ m( C# Y. e- G
! z3 h2 Q$ N2 n
//加載到 mesh& E8 \) ]5 ?2 d K
var mat = new THREE.MeshLambertMaterial({color: 0x444444});
; J7 \& \% u7 `, Y; q4 t9 l: g mesh = new THREE.Mesh(geometry, mat);
9 P6 l \6 I4 r4 B) b) l mesh .rotation.x = -0.5 * Math.PI;( u \0 k6 t& X) u
mesh .scale.set(0.6, 0.6, 0.6);) F0 {+ `% K4 I
* L# T$ |' {1 s* h2 t0 h
//使用 box 生成邊界,將物體調整到原點
8 q6 \3 {5 }! L+ [( X var box = new THREE.Box3().setFromObject( mesh );
4 H% S8 c9 O/ a7 b box.center( mesh.position ); // this re-sets the mesh position
) o8 f; l+ ? b. ?* J mesh.position.multiplyScalar( - 1 );
% ?, `: i8 K" n1 [4 e //將mesh 加到組中
6 j; `& W* u/ ~; |- J( a% k# Z group = new THREE.Group();9 D3 V* J5 u) o3 n3 s( F( V
scene.add( group );0 m* d" R( I2 d( l+ d
group.add( mesh );
( S- W/ D1 R, s
! `# V5 y$ x0 ]% @ [) v! V) o //設置組的坐標為mesh顯示到原點時mesh的中心點坐標取負值,移到加載時的位置- I* c0 Z# \- X& f3 ~1 E
group.position.y = -mesh.position.y;( {' D; K+ H. ], `, @
group.position.x = -mesh.position.x;9 L0 ?0 v3 F' {' |; |, E
group.position.z = -mesh.position.z;
7 g' k* y+ ?: Z# F& p3 s9 g' x0 w! _8 \& }; A6 t
}); |
|