-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathscript-basic.ts
55 lines (46 loc) · 1.33 KB
/
script-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
54
55
/**
* @title Script Basic
* @category Basic
* @thumbnail https://mdn.alipayobjects.com/merchant_appfe/afts/img/A*cHnfTJxLtpkAAAAAAAAAAAAADiR2AQ/original
*/
import { OrbitControl } from "@galacean/engine-toolkit-controls";
import {
Camera,
GLTFResource,
Script,
Vector3,
WebGLEngine,
} from "@galacean/engine";
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize();
const rootEntity = engine.sceneManager.activeScene.createRootEntity();
const cameraEntity = rootEntity.createChild("camera");
cameraEntity.addComponent(Camera);
cameraEntity.transform.setPosition(3, 3, 3);
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
cameraEntity.addComponent(OrbitControl);
engine.sceneManager.activeScene.ambientLight.diffuseSolidColor.set(
1,
1,
1,
1
);
// Create Rotate Script
class Rotate extends Script {
private _tempVector = new Vector3(0, 1, 0);
onUpdate() {
this.entity.transform.rotate(this._tempVector);
}
}
engine.resourceManager
.load<GLTFResource>(
"https://gw.alipayobjects.com/os/OasisHub/267000040/9994/%25E5%25BD%2592%25E6%25A1%25A3.gltf"
)
.then((gltf) => {
const duck = gltf.defaultSceneRoot;
rootEntity.addChild(duck);
// Add Script
duck.addComponent(Rotate);
});
engine.run();
});