-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathscene-basic.ts
53 lines (45 loc) · 1.49 KB
/
scene-basic.ts
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
/**
* @title Scene Basic
* @category Basic
* @thumbnail https://mdn.alipayobjects.com/merchant_appfe/afts/img/A*qnCQRJ_-fwQAAAAAAAAAAAAADiR2AQ/original
*/
// Import Modules
import {
BlinnPhongMaterial,
Camera,
Color,
DirectLight,
MeshRenderer,
PrimitiveMesh,
Vector3,
WebGLEngine,
} from "@galacean/engine";
// Init Engine
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
// Adapter to screen
engine.canvas.resizeByClientSize();
// Get root entity of current scene
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity("root");
// Init Camera
let cameraEntity = rootEntity.createChild("camera_entity");
cameraEntity.transform.position = new Vector3(0, 5, 10);
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
cameraEntity.addComponent(Camera);
scene.background.solidColor.set(1, 1, 1, 1);
// Create a entity to add light component
let lightEntity = rootEntity.createChild("light");
// Create light component
let directLight = lightEntity.addComponent(DirectLight);
directLight.color = new Color(1.0, 1.0, 1.0);
directLight.intensity = 0.5;
// Control light direction by entity's transform
lightEntity.transform.rotation = new Vector3(45, 45, 45);
// Create Cube
let cubeEntity = rootEntity.createChild("cube");
let cube = cubeEntity.addComponent(MeshRenderer);
cube.mesh = PrimitiveMesh.createCuboid(engine, 2, 2, 2);
cube.setMaterial(new BlinnPhongMaterial(engine));
// Run Engine
engine.run();
});