CAD shadows
CAD shadows add a world-space sun and a projected shadow to CAD geometry. The feature is off by default. An application turns it on with the viewer options or with Cognite3DViewer.shadowsEnabled.
Turning shadows on also turns on the sun shading that matches them. A face gets brighter when it looks toward the sun and darker when it looks away, including on surfaces that are not covered by a cast shadow and on ghosted nodes. A fully covered surface is darkened and stays partly lit. Point clouds and 360 images are left unchanged.
The API is marked @beta.
Enable shadows
Pass enableShadows when creating the viewer:
const viewer = new Cognite3DViewer({
sdk: client,
domElement,
enableShadows: true
});
The same flag can be changed after the viewer exists. Assigning it requests a redraw:
viewer.shadowsEnabled = true;
viewer.shadowsEnabled = false;
The GPU resources for the shadow map are allocated the first time shadows are enabled. Turning them off keeps those resources until the viewer is disposed.
The examples application exposes the same switch in the Rendering folder as CAD shadows. Opening that application with ?shadows=true starts with shadows on.
Custom objects
CAD geometry casts the shadow and receives it. A custom object does not, unless the application opts in.
A custom object receives the shadow when its mesh uses a CustomObjectEffectMaterial that requested it with setReceivesShadow(true). viewer.addObject3D and viewer.addCustomObject both work:
import { CustomObjectEffectMaterial } from '@cognite/reveal';
const floorMaterial = new CustomObjectEffectMaterial('#ffffff', floorTexture);
floorMaterial.setReceivesShadow(true);
const floor = new Mesh(new PlaneGeometry(100, 100), floorMaterial);
viewer.addObject3D(floor);
The request belongs to the material. viewer.shadowsEnabled only decides whether the shadow is drawn: turning shadows on does not shade a material that did not ask for it, and turning them off keeps the request for when they come back. Meshes that share one material share its request; use separate materials to shade one and not the other.
ICustomObject.receiveShadow is deprecated and no longer read.