javascript - THREE JS computeVertexNormals() performance -


i have large buffer geometry, around 4 million vertexes, needs have small area of shading updated. randomly update vertexnormals, causes lag. have tried using updaterange.offset of geometry(how update large buffergeometry?) looking source code dont think effects vertexnormals() function.

loop me 1,000 times:

grid.geometry.attributes.position.array[ (array_position + 2)  ] = _position[2] -  webglztranslate ;  grid.geometry.attributes.color.array[ (array_position) + 0 ] = color.r; grid.geometry.attributes.color.array[ (array_position) + 1 ] = color.g; grid.geometry.attributes.color.array[ (array_position) + 2 ] = color.b; 

then set update:

if(minarrayposition < infinity){     grid.geometry.attributes.position.updaterange = {};     grid.geometry.attributes.position.offset = minarrayposition;     grid.geometry.attributes.position.count = maxarrayposition - minarrayposition;     grid.geometry.attributes.position.needsupdate = true;     grid.geometry.verticesneedupdate = true; }  grid.geometry.attributes.color.needsupdate = true; grid.material.needsupdate = true; if(math.random() > .99) {     grid.geometry.computefacenormals();      grid.geometry.computevertexnormals();     console.log('updating shadding'); } 

ideally have range work vertexnormals, think. maybe somewhere in here(buffergeometry.js:657):

if ( attributes.position ) {          var positions = attributes.position.array;          if ( attributes.normal === undefined ) {              this.addattribute( 'normal', new bufferattribute( new float32array( positions.length ), 3 ) );          } else {              // reset existing normals 0              var array = attributes.normal.array;              ( var = 0, il = array.length; < il; ++ ) {                  array[ ] = 0;              }          }          var normals = attributes.normal.array;          var va, vb, vc,          pa = new vector3(),         pb = new vector3(),         pc = new vector3(),          cb = new vector3(),         ab = new vector3();          // indexed elements          if ( index ) {              var indices = index.array;              if ( groups.length === 0 ) {                  this.addgroup( 0, indices.length );              }              ( var j = 0, jl = groups.length; j < jl; ++ j ) {                  var group = groups[ j ];                  var start = group.start;                 var count = group.count;                  ( var = start, il = start + count; < il; += 3 ) {                      va = indices[ + 0 ] * 3;                     vb = indices[ + 1 ] * 3;                     vc = indices[ + 2 ] * 3;                      pa.fromarray( positions, va );                     pb.fromarray( positions, vb );                     pc.fromarray( positions, vc );                      cb.subvectors( pc, pb );                     ab.subvectors( pa, pb );                     cb.cross( ab );                      normals[ va ] += cb.x;                     normals[ va + 1 ] += cb.y;                     normals[ va + 2 ] += cb.z;                      normals[ vb ] += cb.x;                     normals[ vb + 1 ] += cb.y;                     normals[ vb + 2 ] += cb.z;                      normals[ vc ] += cb.x;                     normals[ vc + 1 ] += cb.y;                     normals[ vc + 2 ] += cb.z;                  }              } 

should looking morphing materials instead?? thanks

buffergeometry supports updating sub-range of attribute -- includes normal.

buffergeometry.computevertexnormals() supports both indexed , non-indexed geometries. indexed geometries support shared vertices, there may faces outside index range must included in calculation achieve proper results.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -