Is it possible to modify materials of a loaded gltf model?

1,927 views
Skip to first unread message

David E

unread,
Apr 29, 2014, 11:57:41 AM4/29/14
to cesiu...@googlegroups.com

I need the ability to dynamically adjust the colors and/or opacity of components within a loaded gLTF model.  I can do this without difficulty in THREE.js, but am unable to get the model to update in Cesium.

I can access the named materials on the loaded model in Cesium using model.gltf.materials[MATERIAL_NAME].  From here, material.instanceTechnique.values.diffuse corresponds to the defined color of the material.  I can modify these values directly, however the results are never redrawn.  Do I need to call another function to force an update of the model, or should I be taking a different approach?

thanks,
- David  

Patrick Cozzi

unread,
Apr 29, 2014, 7:36:17 PM4/29/14
to cesiu...@googlegroups.com
Hi David,

We just started adding support for modifying glTF material/technique parameters.  The initial support will ship on Thursday in b28.  It is in master now.  See Model.getMaterial, ModelMaterial, and ModelMesh.material.  For example:

        if (model.ready) {
            model.getMaterial('Default').setValue('diffuse', Cartesian4.fromColor(this.color, scratchColor));
        }

model.gltf is just a read-only object of the original glTF JSON.

Regards,
Patrick

David E

unread,
May 1, 2014, 7:53:07 PM5/1/14
to cesiu...@googlegroups.com
Good timing then.  I just updated and the getMaterial calls are working nicely.  

I also like the new minimumPixelSize option for the gLTF models.  Are there any plans on adding an equivalent option to other components for consistency? For example, the various Primitive or Geometry classes for directly drawing geometric objects.  

Thanks for another nice update,
- David

Patrick Cozzi

unread,
May 1, 2014, 11:16:05 PM5/1/14
to cesiu...@googlegroups.com
Hi David,

Are there any plans on adding an equivalent option to other components for consistency? For example, the various Primitive or Geometry classes for directly drawing geometric objects.

Maybe.  It doesn't fit for some geometries like Polygon, but could be useful for others like sphere or box.  What is your use case?  Currently, you can, of course, just use a glTF model in place of a geometry.

Patrick



--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/TtHPKGhZxlo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

David E

unread,
May 2, 2014, 3:09:12 PM5/2/14
to cesiu...@googlegroups.com
I am currently drawing translucent highlight spheres (variable colors) around certain objects (a mix of Billboard icons and gltf models) and simply giving them a large radius to keep them visible.  Up to now, this has been the only way to create fully dynamic highlights like this, though I still prefer explicitly drawing them versus creating and loading a new model.

A separate issue that I need to tackle next is to make that highlight invisible when the camera zooms into its radius (where my gLTF model with dynamic material shadings will come in).  Now that I think of it, that may also be an issue more easily solved by moving to a gLTF model...  

David E

unread,
May 6, 2014, 10:54:35 AM5/6/14
to cesiu...@googlegroups.com
Is there a method to clone an existing gltf model?  If I take the gLTF model route in place of the sphere/ellipsoid geometries, then I will need to load multiple instances of the model.  The model would be small enough that this shouldn't matter, but a clone method would be preferable if one exists.

thanks,
- David

Patrick Cozzi

unread,
May 6, 2014, 5:31:53 PM5/6/14
to cesiu...@googlegroups.com
Hi David,

Allocate a new Model instance each time.  We have instancing on the roadmap (#927) and I'm pretty sure it is going to be transparent in the API.  For example, if we create ten instances of the same Model, only one glTF model will be loaded, but each instance will have independently modifiable transforms, materials, animation, etc.

This is a ways out as we are currently working on stabilizing the API.

Patrick

mail...@gmail.com

unread,
Apr 17, 2016, 7:08:17 AM4/17/16
to cesium-dev
Hi Patrick,

I also have a use-case in which I need multiple (500-ish) instances of the same model. I checked the roadmap you mentioned and saw that the topic "Reuse texture and vertex buffers when loading multiple models. Probably separate model and instances." is checked. Not sure though if this means that instancing of gltf models is now possible.

Neither I could find a clone() method on Cesium.Model in the API. Could you fill me in about the current status?

Best,
Lucas

Patrick Cozzi

unread,
Apr 18, 2016, 1:22:46 PM4/18/16
to cesiu...@googlegroups.com
Hi Lucas,

The model cache was added in Cesium 1.5: https://cesiumjs.org/2015/01/05/Cesium-version-1.5-released/

Patrick
Reply all
Reply to author
Forward
0 new messages