xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
728 stars 287 forks source link

[with solution]: accessing wrong Mesh state hash from DrawRenderer class #114

Closed tmarti closed 5 years ago

tmarti commented 5 years ago

In the following piece of code...

https://github.com/xeokit/xeokit-sdk/blob/6d449ebe58500f0b60b4e30a5c46e3db047d74ba/src/viewer/scene/mesh/Mesh.js#L214-L233

... we can see that the drawHash of the Mesh class is stored inside _state.drawHash.

If we now look at...

https://github.com/xeokit/xeokit-sdk/blob/6d449ebe58500f0b60b4e30a5c46e3db047d74ba/src/viewer/scene/mesh/draw/DrawRenderer.js#L29-L38

... we can see that the DrawRenderer class is using mesh._state.hash, which does not exist and is undefined.

This makes different meshes with different computed _state.drawHash properties get assigned the same renderer, and produce that for example you cannot set different billboard flags to the different meshes (all of them will be rendered with the same billboard flag becuase the first mesh to arrive will dictate how other meshes behave).

The solution is as simple as (in DrawRenderer' class) changing...

 const hash = [ 
     scene.canvas.canvas.id, 
     (scene.gammaInput ? "gi;" : ";") + (scene.gammaOutput ? "go" : ""), 
     scene._lightsState.getHash(), 
     scene._sectionPlanesState.getHash(), 
     mesh._geometry._state.hash, 
     mesh._material._state.hash, 
     mesh._state.hash 
 ].join(";"); 
 let renderer = drawRenderers[hash]; 

... to...

 const hash = [ 
     scene.canvas.canvas.id, 
     (scene.gammaInput ? "gi;" : ";") + (scene.gammaOutput ? "go" : ""), 
     scene._lightsState.getHash(), 
     scene._sectionPlanesState.getHash(), 
     mesh._geometry._state.hash, 
     mesh._material._state.hash, 
     mesh._state.drawHash // here is the change
 ].join(";"); 
 let renderer = drawRenderers[hash]; 
xeolabs commented 5 years ago

Fixed - https://github.com/xeokit/xeokit-sdk/commit/292d00a055ca4d8db793de9d42fa61ab1cdcfbd8