-
Notifications
You must be signed in to change notification settings - Fork 3.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
Change the material of a primitive in a ModelMesh #2387
Comments
How I can create multiple instances of a loaded Model? I think that I can create a pre-highlighted model hidden instance of the main model in the background showing only the selected node when picked. Thanks for adding the issue as a future enhancement! |
Create two separate |
Thanks! I will do it in that way |
OK, I'm going to keep this issue open though to consider the case for picking individual nodes without affecting all nodes with the same material. |
So if I want to pick individual nodes without affecting nodes with the same material, I need to modify the |
@yqrashawn if you want to be able to change the material of an individual node, e.g., mouseover highlight, then each node will need a unique material. You could try modifying Cesium as you suggested, but you could also just author the model to have many material objects (even if they are the same material in practice) so each node can reference a different one. Generally, this won't bloat the size of the glTF asset much, but there is potentially more WebGL overhead at runtime. If you update Cesium, we would gladly accept a pull request, see https://github.com/AnalyticalGraphicsInc/cesium/blob/master/CONTRIBUTING.md#opening-a-pull-request |
@pjcozzi Thanks for your reply. I'm on this these days. I modified the Is there anything I missed or better way I hadn't found? Or maybe modify the gltf file is a better choice. What about shader level, can we change the material of nodes in runtime rather than modify it? Thus I can achieve highlighting or translucent. |
Yes, this should be more simple than changing the loading code.
Yes, if you use a custom fragment shader with an extra uniform that is the highlight color that is multiple with the computed color (default to white for no highlight). Note that you won't be able to change a material from opaque to translucent or vice versa without more work since the render state also would need to change. |
@pjcozzi realy thanks for your reply. I've already came up with a command line tool to make each material and node correspond.
So if I want to change the material of specific node translucent at runtime, other than modify the shader, I also need to modify the render state. Right? |
@pjcozzi @yqrashawn Thanks two. It helps me much.
We need to highlight individual nodes or make individual nodes translucent after loading models in gltf format. By studying the source of Cesium, I am clear about that Instanced Rendering was used to improve the rendering performance. Materials are shared by meshes and meshes are shared by nodes. It's difficult to modify only one node's color by changing it's material of meshes. I intend to add some attributes to vertex/fragment shader, binding another two buffers to webgl context when drawing. Maybe like below...
Is this the right way? Thanks. |
I am familiar with Three.js and OpenGL ES shader, and have created some advanced materials by write shaders. But Cesium is so complex that I haven't find any entries. |
The ability to change a material's texture was mentioned in https://groups.google.com/forum/#!topic/cesium-dev/mW0VxrU3yhA |
Related forum post about wanting to change a model node's color: https://groups.google.com/forum/#!topic/cesium-dev/HGUDMzBBIeo |
Hi,@QingchaoHu Have you highlight individual nodes of model successfully? and how to? |
@wangxiaolun sorry, but we haven't had a chance to implement this feature yet. If you have a chance to implement it yourself we'd be happy to review a pull request! |
Is there a way of changing the material linked to a primitive in a ModelMesh created from a glTF model?
The goal is to highlight the picked node by changing the material's parameters but
ModelMaterial.selValue
is applied over every primitive linked to that material. I think that the best solution is to temporary link the primitive to a special 'highlight' material but it does not have any effect over the rendered model. Maybe there is a better solution to solve the problem so I am open to suggestions!Thanks!
The text was updated successfully, but these errors were encountered: