|
楼主 |
发表于 2016-5-12 12:03:47
|
显示全部楼层
给点核心程序吧。这也是我老师整的。好东西就要分享,
2 }2 H5 A" X8 _& H7 Jvar loader = new THREE.STLLoader();
6 @* m/ [! a, I/ i+ `+ {' | var group = new THREE.Object3D();
$ z3 q( Z2 u5 C: B. r loader.load("../assets/models/a.stl", function (geometry) {
0 s7 W8 }9 t% N console.log(geometry);. z9 A- K* K8 K
, @/ D/ D" K! H( g+ d //加载到 mesh3 I/ Y, ?# n0 I+ `, \8 [/ Y
var mat = new THREE.MeshLambertMaterial({color: 0x444444});2 ^, `2 C/ q0 E. W
mesh = new THREE.Mesh(geometry, mat);; S& Q* A T. y1 n# L' l
mesh .rotation.x = -0.5 * Math.PI;
7 L8 o7 j" Z& |0 h) o mesh .scale.set(0.6, 0.6, 0.6);5 V* }4 Z7 _9 ]# f- b) P+ i( a9 G H
# g- q0 C: H( Y! {
//使用 box 生成边界,将物体调整到原点- p, g5 B+ [0 H9 D3 q6 K# x
var box = new THREE.Box3().setFromObject( mesh );% V; E. g- m* N+ i* j, l9 `* Z: s
box.center( mesh.position ); // this re-sets the mesh position
$ p* x7 ?. x9 ^) r+ u, o+ T mesh.position.multiplyScalar( - 1 );% C- D9 | }9 p: c; I g
//将mesh 加到组中
8 f8 l) r" V1 [8 j0 G2 W' i$ D group = new THREE.Group();
' Y2 q+ h6 f2 V; M6 d4 _: N scene.add( group );
+ F$ l j- ~$ v- y2 a2 s0 R group.add( mesh );
8 W! b- @% p! O& S4 J- Y7 Z& s4 a$ k t5 n/ M7 ~2 ]- c
//设置组的坐标为mesh显示到原点时mesh的中心点坐标取负值,移到加载时的位置
" B- `& b* e5 F- ^3 g group.position.y = -mesh.position.y;
) h% ^; I. X# J x6 v6 H group.position.x = -mesh.position.x;6 l' r% l9 z3 N9 [/ |
group.position.z = -mesh.position.z;3 `, L8 I t+ E9 D% W) y
! I k! U8 y- Y$ j2 J: t }); |
|