javascript - How to create mesh with Three.js -


i have .obj file

v 1 2 3 v 4 5 6 v 7 8 9  vt 0 1 vt 1 0  vn 0 0 1 vn 0 1 0 vn 0 0 1  f 1/1/1 2/2/2 3/3/3 f 1/1/2 2/2/3 1/2/3 

and need create three.mesh.

var geometry = new three.buffergeometry(); geometry.addattribute('position', new three.bufferattribute(vertices, 3)); geometry.addattribute('normal', new three.bufferattribute(normals, 3)); geometry.addattribute('uv', new three.bufferattribute(uvs, 2)); geometry.setindex(new three.bufferattribute(indices, 1));  var mesh = new three.mesh(geometry, material); 

i suppose need have follow data in arrays:

var vertices = [1, 2, 3, 4, 5, 6, 7, 8, 9]; var normals = [0, 0, 1, 0, 1, 0, 0, 0, 1]; var uvs = [0, 1, 1, 0] var indices = // ... ? 

i don't understand need store in indices array?

here example on how should like. definition of faces shows, there no vertices, have same texture , normals indices. so, other in normal geometry, cannot reuse vertices, because in buffergeometry index defined in indices array apply vertices, uvs, , normals array. (i think, that's @gaitat tried explain.)

v 1 2 3 v 4 5 6 v 7 8 9  vt 0 1 vt 0.5 0.5 vt 1 0  vn 0 0 1 vn 0 1 0 vn 1 0 0  f 1/1/1 2/2/2 3/3/3 f 1/1/2 2/2/3 1/2/3      var vertices = [1,2,3,  4,5,6,    7,8,9,  1,2,3,  4,5,6,    1,2,1];   // itemsize: 3 var uvs =      [0,1,    0.5,0.5,  1,0,    0,1,    0.5,0.5,  0.5,0.5]; // itemsize: 2 var normals =  [0,0,1,  0,1,0,    1,0,0,  0,1,0,  1,0,0,    1,0,0];   // itemsize: 3  var indices = [0,1,2, 3,4,5]; // itemsize: 1 

edit: in example above, second vertex of first face (2/2/2) indexed 1. so, second item set vertices, uvs, , normals array: 4,5,6 0.5,0.5 0,1,0. second vertex of second face (2/2/3) indexed 4. so, 5th item set each array: 4,5,6 0.5,0.5 1,0,0. vertex position , uvs of both same normals different, cannot reused. because index array stores 1 index , not 3 each vertex position, uv, , normal.

f 1/1/1 2/2/2 3/3/3 f 1/1/2 2/2/2 1/2/3      var vertices = [1,2,3,  4,5,6,    7,8,9,  1,2,3,  1,2,1];   // itemsize: 3 var uvs =      [0,1,    0.5,0.5,  1,0,    0,1,    0.5,0.5]; // itemsize: 2 var normals =  [0,0,1,  0,1,0,    1,0,0,  0,1,0,  1,0,0];   // itemsize: 3  var indices = [0,1,2, 3,1,5]; // itemsize: 1 

in example, second vertices of both faces same (2/2/2). in case, values can reused. arrays shorter , index of vertex in second face 1, too.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -