THREE.js have included TriangleStripDrawMode, or TriangleFanDrawMode for some revisions now.
I have tried searching for it online, as well as experimenting on my own to understand it better, but all is wasted. I still don’t know how to utilize these modes to prevent redundancy, or to minimize the data exchange.
Consider this mesh for example:
JavaScript
x
17
17
1
var geo = new THREE.Geometry( );
2
geo.vertices.push( new THREE.Vector3( 0, 0, 0 ),
3
new THREE.Vector3( 0, 100, 0 ),
4
new THREE.Vector3( 0, 100, 100 ),
5
new THREE.Vector3( 0, 0, 100 )
6
);
7
8
// Placeholder
9
10
var mesh = new THREE.Mesh( geo, new THREE.MeshBasicMaterial( {
11
side: THREE.DoubleSide
12
} ) );
13
mesh.setDrawMode( THREE.TriangleStripDrawMode );
14
15
// Nothing renders
16
scene.add(mesh);
17
unless I replace // Placeholder
with
JavaScript
1
3
1
geo.faces.push( new THREE.Face3( 0, 1, 2 ),
2
new THREE.Face3( 2, 3, 0 ) );
3
What is the use of setting the draw mode if I end up replicating indices – 2, 0
here?
Or is there something obvious that I am missing?
Advertisement
Answer
You should use THREE.BufferGeometry
if you want to use THREE.TriangleStripDrawMode
.
Here is a very simple example:
JavaScript
1
28
28
1
var geometry = new THREE.BufferGeometry();
2
3
var positions = new Float32Array( 4 * 3 ); // 4 triangles, 3 vertices each
4
5
positions[ 0 ] = 0;
6
positions[ 1 ] = 10;
7
positions[ 2 ] = 0;
8
9
positions[ 3 ] = 0;
10
positions[ 4 ] = 10;
11
positions[ 5 ] = 10;
12
13
positions[ 6 ] = 0;
14
positions[ 7 ] = 0;
15
positions[ 8 ] = 10;
16
17
positions[ 9 ] = 10;
18
positions[ 10 ] = 10;
19
positions[ 11 ] = 10;
20
21
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
22
23
var mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide } ) );
24
25
mesh.setDrawMode( THREE.TriangleStripDrawMode );
26
27
scene.add( mesh );
28
three.js r.76