I am having trouble using the Cesium.Material.fromType
function to create a material using a type and uniforms.
I am referring to the docs here: link
I have the following example I am trying to get to work, however I would like to next use the Dot
dynamic type not color. Color seems easier for the moment.
This works:
material : Cesium.Color.GREEN
This does not:
material : Cesium.Material.fromType('Color', {
color : new Cesium.Color(1.0, 0.0, 0.0, 1.0)
})
I am getting this error:
Uncaught DeveloperError: Unable to infer material type: [object Object]
It seems like the material property on entities cannot be an object, am I missing a step to convert the material into a primitive type?
So I don't have great news here, but I can at least explain what's wrong. As you know Cesium has two separate API layers, the "Entity" layer (for complex objects like moving vehicles), and the "Primitive" layer (for graphics primitives, like collections of billboards or meshes). What you're doing here is directly constructing a material from the Primitive layer and trying to assign it to an Entity, which will not work.
At the Entity layer, materials are described by a class derived from the abstract base class of MaterialProperty. The derived classes are all Entity-layer classes listed in that doc link, for example there's a ColorMaterialProperty class for solid colors. Being at the entity layer makes these things time-dynamic, so for example your solid color could be blue when the simulation time is at 04:00
and change to red at 06:00
, etc. Primitive materials do not have a concept of time baked in and are much lighter-weight as a result.
And now the bad news: There doesn't appear to be a DotMaterialProperty
class in Cesium currently. This means the Dot material exists only at the primitive layer API and is not hooked up to the entity layer. The team likes to say "contributions welcome" at this point, and if you were so inclined you could probably get this hooked up by copying either StripeMaterialProperty
or GridMaterialProperty
and editing it to hook up to Dot.
But in the short term, if you need the Dot material more than you need the Entity layer, you could transition your code over to graphics primitives. You can find sample code for this in the Material Sandcastle Demo under the Procedural Textures
drop-down box.