|
3#
楼主
|
发表于 2016-5-12 12:03:47
|
只看该作者
给点核心程序吧。这也是我老师整的。好东西就要分享, " F. F* g6 X# `4 Y8 ~. e5 pvar loader = new THREE.STLLoader();4 K% S. L2 E3 p2 }6 z w var group = new THREE.Object3D();8 W @ I$ K; _! Z. w) x6 r6 O8 c loader.load("../assets/models/a.stl", function (geometry) {+ F: P- a! \# R4 E- a4 I2 F8 E console.log(geometry);3 u i) h$ d2 ^8 }3 w$ X" h, U8 o# m+ R
* G& Z1 j7 ]7 Q5 H r/ h6 C- O1 l6 L" R//加载到 mesh 4 i; A: t. r( }; \1 f. wvar mat = new THREE.MeshLambertMaterial({color: 0x444444}); 2 H- o3 O |1 P" zmesh = new THREE.Mesh(geometry, mat); + H0 |/ o' a% D$ k5 G( Jmesh .rotation.x = -0.5 * Math.PI;% D! d, `: u, U% c7 s mesh .scale.set(0.6, 0.6, 0.6);+ z! H7 |4 ?8 ^* S* j% i. P) ? + R5 v5 G# i/ a! H4 ` //使用 box 生成边界,将物体调整到原点 . |8 z0 r+ ?. j7 D7 j! o; |var box = new THREE.Box3().setFromObject( mesh ); ; U9 q1 a' ?3 D) `box.center( mesh.position ); // this re-sets the mesh position! X$ L7 A, ^( k8 T5 f' \. E mesh.position.multiplyScalar( - 1 ); $ Y) @' M8 X1 F//将mesh 加到组中 ( k4 N- I, r; i- Tgroup = new THREE.Group(); 2 R& T! K- `2 _: w% C5 L3 Y% a oscene.add( group );1 R4 \( X, ^: l group.add( mesh );5 p* r: F2 L1 ]
3 n# K' F3 J1 `$ g. ^/ k. @//设置组的坐标为mesh显示到原点时mesh的中心点坐标取负值,移到加载时的位置 2 k" f3 d. T1 W0 d W$ {group.position.y = -mesh.position.y;/ Y: C! e$ c8 l/ ] group.position.x = -mesh.position.x; 2 T* _9 C0 r5 sgroup.position.z = -mesh.position.z; 0 M: A7 w% ~- G; O8 ` 2 ^2 e& u+ ]% g) B* r2 M A}); |
|