Shadows not supported in CZML

Shadows feature does not work with CZML. I get following error when tried:
Cesium.js:448 TypeError: Cannot read property ‘length’ of undefined(…)

terrainShadows property is enabled in js as follows:

viewer.terrainShadows = Cesium.ShadowMode.ENABLED;

What am i missing to get this working?

This is my sample CZML file.
[
{
“id”:“document”,
“name”:“CZML Geometries: Polygon”,
“version”:“1.0”
},
{
“id”:“abcd”,
“name”:“Sample Data”,
“polygon”:{
“positions”:{
“cartographicDegrees”:[
-96.804157261687,
32.779763115598,
0,
-96.804112061058,
32.779769858449,
0,
-96.804112051068,
32.779769856449,
0
]
},
“extrudedHeight”:{
“number”:3
},
“heightReference”:1,
“material”:{
“solidColor”:{
“color”:{
“rgba”:[135,206,250,100]
}
}
},
“outline”:true,

“shadows” => 1 // 1 For enabled
}
}
]

By default terrain shadows are Cesium.ShadowMode.RECEIVE_ONLY, which means you don’t need to set it to ENABLED unless you want terrain to cast shadows onto itself (good with really hilly terrain, but not needed for flat areas). Besides that you also need to set:

viewer.shadows = true;

To turn shadowing on for the entire engine.

The problem with your CZML is that it should be “shadows” : “ENABLED”. In CZML you need to use the name of the enum rather than the number value.

Here is the working code:

Thanks Sean. I tried with following czml sample and could not see shadows of the drawn polygon.

var czml = [

{

“id”:“document”,

“name”:“CZML Geometries: Polygon”,

“version”:“1.0”

},

{

“id”:“abcd”,

“name”:“Sample Data”,

“polygon”:{

“positions”:{

“cartographicDegrees”:[

-90.0, 30.0, 0, -80.0, 30.0, 0, -80.0, 40.0,0, -90.0, 40.0,0

]

},

“extrudedHeight”:{

“number”:300000

},

“material”:{

“solidColor”:{

“color”:{

“rgba”:[135,206,250,100]

}

}

},

“heightReference”:“CLAMP_TO_GROUND”,

“outline”:true,

“shadows” : “ENABLED”

}

}

];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSource = Cesium.CzmlDataSource.load(czml);

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

viewer.shadows = true;

Ah ok. Right now the shadow system is tuned for views that are closer to the earth like primitives/models that are close to the ground. It works on a range of about 5000 meters which views from space usually exceed. We may get around to supporting views like this eventually.

Hey Sean,

That was just an example I posted here. I tried with smaller polygon. But does not seem to work. No shadow is visible if I load data from CZML. Here is my example:

var czml = [

{

“id”:“document”,

“name”:“CZML Geometries: Polygon”,

“version”:“1.0”

},

{

“id”:“abcd”,

“name”:“Sample Data”,

“polygon”:{

“positions”:{

“cartographicDegrees”:[

-90.0, 30.0, 0, -90.0001, 30.0, 0, -90.0001, 30.0001,0, -90.0, 30.0001,0

]

},

“extrudedHeight”:{

“number”:10

},

“material”:{

“solidColor”:{

“color”:{

“rgba”:[135,206,250,100]

}

}

},

“heightReference”:“CLAMP_TO_GROUND”,

“outline”:true,

“shadows” : “ENABLED”

}

}

];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSource = Cesium.CzmlDataSource.load(czml);

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

viewer.shadows = true;

That example works for me, check out the attached screenshot. Shadows are affected by the sun position so it’s possible the sun was below the horizon and so there weren’t any shadows. Try adjusting the time slider and let me know how that goes. It’s also possible there’s some latent issue that is only affecting your machine.

shadows.JPG

Hi Sean,

Can “Mapbox streets classic” imagery provider be the issue for this? Coz when I tried with default imagery provider it worked.

Do you have some sample code I can test out? When I choose different imagery providers they all work for me.

Hey Sean, M sorry. I was trying with sample czml which had no ‘“shadows” :“ENABLED”’ added in it.

Thanks.