Forge Viewer Custom Shaders -




i've done research towards shaders , found this:

https://forge.autodesk.com/blog/forge-viewer-custom-shaders-part-1

my question is. seems won't change color, changes material, meaning can't undo it. in scenario need able undo (resetting color , material). somehow make possible?

to undo changes, have keep relations between original materials , id of forge fragment. example, can create array remember mapping in function setmaterial, way:

setmaterial( fragids, material ) {      const fraglist = this._viewer.model.getfragmentlist();      // array kepping original materials of forge fragment.     if( !array.isarray( this.materialmap ) ) {         this.materialmap = [];     }      this.toarray(fragids).foreach( ( fragid ) => {           // keep material relations.           const originalmat = fraglist.getmaterial( fragid );           this.materialmap[fragid] = originalmat;            fraglist.setmaterial( fragid, material );     });      this._viewer.impl.invalidate( true ); } 

for restoring materials, can follow way:

restorematerials() {    if( !array.isarray( this.materialmap ) ) return;    for( let fragid in this.materialmap ) {       const material = this.materialmap[fragid];       fraglist.setmaterial( fragid, material );   }    this._viewer.impl.invalidate( true );   // clean mappings.   this.materialmap.length = 0; } 




wiki

Comments

Popular posts from this blog

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -