|
3#
![](static/image/common/ico_lz.png)
樓主 |
發(fā)表于 2016-5-12 12:03:47
|
只看該作者
給點核心程序吧,。這也是我老師整的,。好東西就要分享,
) ~! c# ?! M3 N; y6 l2 uvar loader = new THREE.STLLoader();7 s, z! g) Y% r: ~& U- |& }
var group = new THREE.Object3D();. Z9 t( d, F; |/ |+ ]
loader.load("../assets/models/a.stl", function (geometry) {
' J/ v c3 a2 | J8 | m# i& ~ console.log(geometry);
* s) @) e; B9 D, w- m2 v8 E. \6 _! \9 D
//加載到 mesh
R M) R; ?3 J6 {/ J var mat = new THREE.MeshLambertMaterial({color: 0x444444});
4 r+ o- u8 W) C. T j4 a mesh = new THREE.Mesh(geometry, mat);- a. W# d" W; e. x6 s
mesh .rotation.x = -0.5 * Math.PI;
- k2 \! H: D/ D8 C mesh .scale.set(0.6, 0.6, 0.6);
1 [5 j( H8 w2 p# N" O2 d% b/ `( `8 `* J
1 `" J* Z' Y {+ X7 g. x //使用 box 生成邊界,,將物體調整到原點
* ?3 J$ r- f; F" W var box = new THREE.Box3().setFromObject( mesh );
1 F, d) @3 L$ P7 T% k box.center( mesh.position ); // this re-sets the mesh position E! H! W& P1 E; j6 ?5 U0 H
mesh.position.multiplyScalar( - 1 );0 p+ z. n5 c. |) y6 m" x$ x N
//將mesh 加到組中2 a2 O8 g4 w0 N' x
group = new THREE.Group();
# |8 n, {$ G1 X% W6 |; A! |* _& @; X scene.add( group );
; E2 r3 D) b, y- `) d \ group.add( mesh );! E4 X c7 C3 d
/ H6 `' ?5 R! d' K2 W7 J$ j8 T //設置組的坐標為mesh顯示到原點時mesh的中心點坐標取負值,,移到加載時的位置
# K/ T& y1 i! H3 E group.position.y = -mesh.position.y;
9 G B. s- |: C- A) _ group.position.x = -mesh.position.x;
& z$ w% S& k" c) e group.position.z = -mesh.position.z;
, {" d' _9 R+ f+ d/ b+ R: u
o6 z3 f2 B% w- }; g' ^ }); |
|