-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstancedMesh's setMatrixAt fails when another mesh in the scene has the same material #17701
Comments
I have not checked whether other OS'es or Browsers have this issue, I just confirmed it on Windows, both Chrome and Edge. |
Yeah, known issue. Haven't made that work yet. |
Not sure if that is a related issue or intended behaviour, but I also have problems re-usinng the |
@s-ol Interesting. Do you mind putting together a jsfiddle? |
@mrdoob sure, here you go: http://jsfiddle.net/x7Lzvqte/ you can toggle the red & green batches on and off individually with the bools at the top. |
I've debugged the issue a bit and found out that the bug refers to the same root cause mentioned here: #17959 (comment). The renderer needs the ability to manage multiple shader programs per material, see #15047. Currently there is always a 1:1 relationship (which is somewhat wrong since material properties are not the only factors which determine the correct shader program). So the renderer assumes it can reuse the same shader for both the mesh and instanced mesh. |
Or alternatively, a property on the material that enables instancing, similar to the relationship between .skinning=true and THREE.SkinnedMesh. I’m not sure which solution is better but would prefer consistency. 🤔 |
Note that in any outcome here, you really do need two shader programs for this situation. You might find that using an InstancedMesh with count=1 for the second object avoids this, not sure if there should be any side effects of that... |
I just got bit by this as well. A note in the docs while the fix is underway would be great. |
@mracette Good point. Let me update the docs. |
Description of the problem
I'm having a problem where the InstancedMesh method
setMatrixAt
seems to fail (the matrix positions doesn't change visually) whenever I add another object with the same material object (not a clone) in the scene. No log/warning/errors are emitted.The following briefly illustrates:
Note that if I use material.clone() at the instanced mesh declaration, the problem also goes away / is fixed, but now I have two materials, and I intend to have one for performance reasons.
A live example is available here:
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
(Not applicable, as far as I know)
The text was updated successfully, but these errors were encountered: