forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_Transform.ts
77 lines (67 loc) · 2.23 KB
/
Sample_Transform.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Engine3D, Scene3D, AtmosphericComponent, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, View3D, Camera3D } from "@orillusion/core";
import { Stats } from "@orillusion/stats";
import * as dat from "dat.gui"
// initializa engine
await Engine3D.init();
// create new scene as root node
let scene3D: Scene3D = new Scene3D();
// add performance stats
scene3D.addComponent(Stats)
// add an Atmospheric sky enviroment
let sky = scene3D.addComponent(AtmosphericComponent);
sky.sunY = 0.6;
// create camera
let cameraObj: Object3D = new Object3D();
let camera = cameraObj.addComponent(Camera3D);
// adjust camera view
camera.perspective(45, Engine3D.aspect, 1, 5000.0);
// set camera controller
let controller = cameraObj.addComponent(HoverCameraController);
controller.setCamera(0, 0, 30);
// add camera node
scene3D.addChild(cameraObj);
// create light obj
let light: Object3D = new Object3D();
// adjust light rotation
light.rotationX = 45;
light.rotationY = 30;
// add direct light component
let dirLight: DirectLight = light.addComponent(DirectLight);
dirLight.intensity = 1;
// add light object to scene
scene3D.addChild(light);
// create a box
const box: Object3D = new Object3D();
// add MeshRenderer
let mr: MeshRenderer = box.addComponent(MeshRenderer);
// set geometry
mr.geometry = new BoxGeometry(5, 5, 5);
// set material
mr.material = new LitMaterial();
// set rotation
box.rotationY = 45;
// add object
scene3D.addChild(box);
// create a view with target scene and camera
let view = new View3D();
view.scene = scene3D;
view.camera = camera;
// start render
Engine3D.startRenderView(view);
// add debug GUI
let gui = new dat.GUI();
let f = gui.addFolder('Sun')
f.add(sky, "sunX", 0, 1);
f.add(sky, "sunY", 0, 1);
f.open()
let f2 = gui.addFolder('Transform')
f2.add(box.transform, 'x', -20.0, 20.0, 0.01);
f2.add(box.transform, 'y', -20.0, 20.0, 0.01);
f2.add(box.transform, 'z', -20.0, 20.0, 0.01);
f2.add(box.transform, 'rotationX', -180, 180, 0.01);
f2.add(box.transform, 'rotationY', -180, 180, 0.01);
f2.add(box.transform, 'rotationZ', -180, 180.0, 0.01);
f2.add(box.transform, 'scaleX', -2.0, 2.0, 0.01);
f2.add(box.transform, 'scaleY', -2.0, 2.0, 0.01);
f2.add(box.transform, 'scaleZ', -2.0, 2.0, 0.01);
f2.open()