forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
planar-shadow.js
50 lines (43 loc) · 1.7 KB
/
planar-shadow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const scene = new cc.Scene();
const root = new cc.Node();
root.parent = scene;
const altitude = 0;
root.setPosition(0, altitude, 0);
const cameraNode = new cc.Node('Camera');
cameraNode.parent = root;
cameraNode.setPosition(-16, 2, 16);
cameraNode.setRotationFromEuler(-12, -63, 0);
cameraNode.addComponent(cc.Camera);
cameraNode.addComponent(window.FirstPersonCamera);
const lightNode = new cc.Node('Light');
lightNode.parent = root;
lightNode.setPosition(-10, 10, -10);
lightNode.setRotationFromEuler(-50, 0, 0);
lightNode.addComponent('cc.DirectionalLight');
const material = new cc.Material();
material.initialize({ effectName: 'builtin-standard' });
const manifest = [
{ name: 'box', pos: cc.v3(0, 1, 10) },
{ name: 'sphere', pos: cc.v3(5, 1, 15) },
{ name: 'cylinder', pos: cc.v3(-5, 1, 5) },
{ name: 'torus', pos: cc.v3(5, 1, 5) },
{ name: 'cone', pos: cc.v3(-5, 1, 15) },
{ name: 'plane', pos: cc.v3(0, 0, 0), param: { width: 100, length: 100 } },
];
const models = {};
for (const info of manifest) {
const modelNode = new cc.Node(`${info.name}`);
modelNode.parent = root;
const modelComp = modelNode.addComponent('cc.MeshRenderer');
modelComp.material = info.mat || material;
modelComp.mesh = cc.utils.createMesh(cc.primitives[info.name](info.param));
if (info.name !== 'plane') modelComp.shadowCastingMode = cc.ModelComponent.ShadowCastingMode.ON;
modelNode.setPosition(info.pos);
models[info.name] = modelComp;
}
const qt = cc.Quat.fromEuler(cc.quat(), 10, 20, 0);
models.plane.node.setRotation(qt);
scene.globals.shadows.enabled = true;
scene.globals.shadows.setPlaneFromNode(models.plane.node);
scene.globals.shadows.shadowColor = cc.color('#2a4e90');
cc.director.runSceneImmediate(scene);