I’m trying to load an .stl
file into three.js. Everything works fine and I get the model as BufferGeometry using this code:
JavaScript
x
15
15
1
var loader = new THREE.STLLoader();
2
loader.addEventListener( 'load', function ( event )
3
{
4
5
var material = new THREE.MeshLambertMaterial({
6
color: 0x888888,
7
side: THREE.DoubleSide
8
});
9
10
var bufferGeometry = event.content;
11
var mesh = new THREE.Mesh(geometry, material);
12
scene.add( mesh );
13
});
14
loader.load( 'model.stl' );
15
To make it easier to further manipulate the model I would like to have the geometry as regular THREE.Geometry
instead of THREE.BufferGeometry
. Is it possible to either load the .stl
in a way so I receive it as a THREE.Geometry
or is it possible to convert from THREE.BufferGeometry
to THREE.Geometry
? Or is this possible using a .obj
file or sth else?
Advertisement
Answer
This answer only applies to versions of three.js prior to r.125.
STLLoader
now returns a BufferGeometry
object.
You can convert that to a THREE.Geometry
like so:
JavaScript
1
2
1
var geometry = new THREE.Geometry().fromBufferGeometry( bufferGeometry );
2
three.js r.124