forked from galacean/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathculling-mask.ts
More file actions
79 lines (71 loc) · 2.1 KB
/
Copy pathculling-mask.ts
File metadata and controls
79 lines (71 loc) · 2.1 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @title Culling Mask
* @category Camera
* @thumbnail https://mdn.alipayobjects.com/merchant_appfe/afts/img/A*iln0RKi5dIkAAAAAAAAAAAAADiR2AQ/original
*/
import * as dat from "dat.gui";
import {
DirectLight,
Logger,
WebGLEngine,
Camera,
Vector3,
MeshRenderer,
BlinnPhongMaterial,
Color,
Layer,
PrimitiveMesh,
} from "@galacean/engine";
Logger.enable();
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize();
const rootEntity = engine.sceneManager.activeScene.createRootEntity();
// init camera
const cameraEntity = rootEntity.createChild("camera");
const camera = cameraEntity.addComponent(Camera);
const pos = cameraEntity.transform.position;
pos.set(10, 10, 10);
cameraEntity.transform.position = pos;
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
const lightNode = rootEntity.createChild("Light");
lightNode.transform.setRotation(-30, 0, 0);
lightNode.addComponent(DirectLight);
// init cube
const cubeEntity = rootEntity.createChild("cube");
const renderer = cubeEntity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
const material = new BlinnPhongMaterial(engine);
material.baseColor = new Color(1, 0.25, 0.25, 1);
renderer.setMaterial(material);
engine.run();
function addGUI() {
const gui = new dat.GUI();
const cameraFolder = gui.addFolder("camera cullingMask");
cameraFolder.open();
const constMap = {
EveryThing: Layer.Everything,
Layer1: Layer.Layer1,
Layer2: Layer.Layer2,
Layer3: Layer.Layer3,
};
const cameraController = cameraFolder.add(
{ cullingMask: "EveryThing" },
"cullingMask",
Object.keys(constMap)
);
cameraController.onChange((v) => {
camera.cullingMask = constMap[v];
});
const boxFolder = gui.addFolder("box layer");
boxFolder.open();
const boxController = boxFolder.add(
{ layer: "EveryThing" },
"layer",
Object.keys(constMap)
);
boxController.onChange((v) => {
renderer.entity.layer = constMap[v];
});
}
addGUI();
});