55Cs
November 23, 2022, 3:44pm
1
With Cesium <= 1.96 and gltf 1.0, I can change a primitive’s colors like so
var primitive = viewer.scene.primitives._primitives[0]._primitives[0];
var material = primitive.getMaterial(materialName);
material.setValue(‘diffuse’, new Cesium.Cartesian4(1, 0, 0, 1));
But with Cesium 1.99 and gltf 2.0, I haven’t figured out the syntax to do so.
I can change the whole primitive’s color with
primitive.color = Cesium.Color.RED;
But to change a node’s color this doesn’t work
primitive.getNode(nodeName).color=Cesium.Color.RED;
However the node is accessible because this hides it
primitive.getNode(nodeName).show=false;
This also doesn’t work
primitive._loader._gltfJsonLoader._gltf.materials[0].pbrMetallicRoughness.baseColorFactor=[1, 0, 0, 1];
With Cesium 1.99 and gltf 2.0 , how can I change a primitive’s nodes’ colors ?
Thank you for your help!
55Cs
November 29, 2022, 8:13pm
2
I figured it out!
Choose your primitive containing the node
var primitive = viewer.scene.primitives._primitives[0];
View node names like this
Object.keys(primitive._nodesByName);
Choose the node to be colored (1st one in this example)
var nodeName = Object.keys(primitive._nodesByName)[0];
Change the node’s color like this!
primitive.getNode(nodeName)._runtimeNode.node.primitives[0].material.metallicRoughness.baseColorFactor =Cesium.Cartesian4.fromColor(Cesium.Color.RED);
I got inspired by these posts :
Changing material of single mesh in model
How to color specific part of Model
Jacky
December 10, 2022, 3:14pm
3
First of all thank you for sharing codes. I’ve tried your solution but it doesn’t work. Check this sandcastle link .
55Cs
December 23, 2022, 8:29pm
4
I used the Primitive API, I haven’t tried with the Entity API.
viewer.entities.add uses the Entity API
Cesium.Model.fromGltf uses the Primitive API
I used this reference model to get the colors working with Cesium.Model.fromGltf
{
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5121,
"count" : 78,
"max" : [
51
],
"min" : [
0
],
"type" : "SCALAR"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 52,
"max" : [
-0.6740907430648804,
This file has been truncated. show original
Hope this helps.
1 Like