|
3#

樓主 |
發(fā)表于 2016-5-12 12:03:47
|
只看該作者
給點(diǎn)核心程序吧,。這也是我老師整的。好東西就要分享,,
0 g6 F+ f: m" R s5 Fvar loader = new THREE.STLLoader();. u/ d6 w- } G; a' o- `) I S f% ]
var group = new THREE.Object3D();$ I, U" H! O# v; a7 c
loader.load("../assets/models/a.stl", function (geometry) {- r' ]& @) q9 w. p% d. E' W
console.log(geometry);
5 T* E: c$ O1 D5 c
( }; T+ G: @* B5 I3 E. l- K //加載到 mesh2 }: Q9 E i9 i% v" i) p9 s1 ]( O
var mat = new THREE.MeshLambertMaterial({color: 0x444444});
- q. w6 w) a: E% n8 \+ p mesh = new THREE.Mesh(geometry, mat);0 e) Z% G) Q9 v7 h, G) a; k5 ?. z
mesh .rotation.x = -0.5 * Math.PI;7 c4 H# {# M" j+ G7 L% _
mesh .scale.set(0.6, 0.6, 0.6); q! e# q z8 W- E* g7 Q
3 [, Y1 O- r- K' A2 m% s //使用 box 生成邊界,,將物體調(diào)整到原點(diǎn)
$ p6 ^& w9 S5 P2 P3 K var box = new THREE.Box3().setFromObject( mesh );
9 T& Z L1 T5 s7 G" h box.center( mesh.position ); // this re-sets the mesh position
% ~ L. ?# V5 z" O mesh.position.multiplyScalar( - 1 );: a0 p. O! N7 Z% ^7 {
//將mesh 加到組中2 h3 }5 D3 ]! |5 V5 g
group = new THREE.Group();7 q( |9 {# K5 T
scene.add( group );
% m+ N! k7 J9 \! h: M3 l+ u( ?7 \1 m group.add( mesh );
: b% I7 C7 k5 R) h) J& A- E* G! d/ w$ Y
//設(shè)置組的坐標(biāo)為mesh顯示到原點(diǎn)時(shí)mesh的中心點(diǎn)坐標(biāo)取負(fù)值,移到加載時(shí)的位置; p4 P! s4 s9 y
group.position.y = -mesh.position.y;0 v: p8 v& q- N
group.position.x = -mesh.position.x;* Q2 h; n: X0 v9 e
group.position.z = -mesh.position.z;, o. {& [- G" b# k, z
* d4 ]" v3 i& o" w1 E7 w3 I, W }); |
|