|
楼主 |
发表于 2016-5-12 12:03:47
|
显示全部楼层
给点核心程序吧。这也是我老师整的。好东西就要分享,$ e! j8 I) l* m
var loader = new THREE.STLLoader();& L- S: M F/ ~$ D$ |$ X
var group = new THREE.Object3D();+ |9 f- H; r7 ]' s
loader.load("../assets/models/a.stl", function (geometry) {
# C4 a' f: h+ @0 X- S+ C. R+ ~ console.log(geometry);9 C+ ~) a: X7 i' m1 P6 e! H- S
; j2 l4 D9 h/ v9 c4 S; w+ U7 b
//加载到 mesh$ ` g1 F# {6 ?, k: |) x
var mat = new THREE.MeshLambertMaterial({color: 0x444444});
" `. x7 |+ X& q' C mesh = new THREE.Mesh(geometry, mat);+ M5 k8 D3 S7 O* M
mesh .rotation.x = -0.5 * Math.PI;
2 e' Y* s M+ z8 l mesh .scale.set(0.6, 0.6, 0.6);: j" c. Q6 e& r
4 B+ l% `0 p, y* N //使用 box 生成边界,将物体调整到原点
- d3 u9 B1 s: U x var box = new THREE.Box3().setFromObject( mesh );4 U; ~# U; N" @8 P" A
box.center( mesh.position ); // this re-sets the mesh position
5 D0 W& L$ m( P mesh.position.multiplyScalar( - 1 );
: |6 w# a& p1 A //将mesh 加到组中
! V- }4 R+ T/ _9 K group = new THREE.Group();. h- }* S! N( F1 n I7 q
scene.add( group );6 _ s% R* U( Z6 a! D5 P. o
group.add( mesh );
( r) b& Q0 ^& v( U( Y8 d- e6 H6 b7 \9 E' O$ b1 K z% F
//设置组的坐标为mesh显示到原点时mesh的中心点坐标取负值,移到加载时的位置
' B5 @/ @5 u& D* `2 q" K) a group.position.y = -mesh.position.y;
' F( Q8 } C2 W' x$ ? group.position.x = -mesh.position.x;
) @7 S8 s- A4 H group.position.z = -mesh.position.z;( M) r7 F: ^9 v* F" w% S h, l' `
+ d4 y2 o8 B' M. S, S0 G
}); |
|