forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_InternalGeometry.ts
119 lines (101 loc) · 4.05 KB
/
Sample_InternalGeometry.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { GUIHelp } from "@orillusion/debug/GUIHelp";
import { Engine3D, View3D, Scene3D, CameraUtil, AtmosphericComponent, webGPUContext, HoverCameraController, Object3D, DirectLight, KelvinUtil, PlaneGeometry, VertexAttributeName, LitMaterial, MeshRenderer, BoxGeometry, SphereGeometry, CylinderGeometry, TorusGeometry, Vector2, Color } from "@orillusion/core";
import { GUIUtil } from "@samples/utils/GUIUtil";
// An sample of display internal geometry
class Sample_InternalGeometry {
lightObj: Object3D;
async run() {
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBound = 200;
Engine3D.setting.shadow.shadowSize = 2048;
GUIHelp.init();
await Engine3D.init();
let view = new View3D();
view.scene = new Scene3D();
let sky = view.scene.addComponent(AtmosphericComponent);
view.camera = CameraUtil.createCamera3DObject(view.scene);
view.camera.perspective(60, webGPUContext.aspect, 1, 5000.0);
view.camera.object3D.z = -15;
view.camera.object3D.addComponent(HoverCameraController).setCamera(35, -20, 150);
Engine3D.startRenderView(view);
await this.createScene(view.scene);
sky.relativeTransform = this.lightObj.transform;
}
private async createScene(scene: Scene3D) {
// add a direction light
let lightObj3D = this.lightObj = new Object3D();
let sunLight = lightObj3D.addComponent(DirectLight);
sunLight.intensity = 3;
sunLight.lightColor = KelvinUtil.color_temperature_to_rgb(6553);
sunLight.castShadow = true;
lightObj3D.rotationX = 53.2;
lightObj3D.rotationY = 220;
lightObj3D.rotationZ = 5.58;
GUIUtil.renderDirLight(sunLight);
scene.addChild(lightObj3D);
let material = new LitMaterial();
// add a plane
{
let plane = new Object3D();
let meshRenderer = plane.addComponent(MeshRenderer);
meshRenderer.geometry = new PlaneGeometry(200, 200, 80, 80);
meshRenderer.material = material;
scene.addChild(plane);
}
// add a box
{
let box = new Object3D();
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new BoxGeometry(50, 10, 20);
meshRenderer.material = material;
box.y = 10;
scene.addChild(box);
}
// add a box
{
let box = new Object3D();
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new SphereGeometry(10, 20, 20);
meshRenderer.material = material;
box.y = 10;
box.x = -50;
scene.addChild(box);
}
// add a cylinder opened
{
let box = new Object3D();
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new CylinderGeometry(5, 10, 20, 50, 20, true);
meshRenderer.material = material;
material.cullMode = 'none'
box.y = 20;
box.x = 50;
scene.addChild(box);
}
// add a cylinder closed
{
let box = new Object3D();
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new CylinderGeometry(5, 10, 20, 50, 20);
let topMaterial = new LitMaterial();
topMaterial.baseColor = new Color(1, 0, 0, 1);
meshRenderer.materials = [material, material, material];
box.y = 20;
box.x = 50;
box.z = 50;
scene.addChild(box);
}
// add a torus
{
let box = new Object3D();
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new TorusGeometry(10, 4, 20, 50);
meshRenderer.material = material;
box.y = 20;
box.x = 50;
box.z = -50;
scene.addChild(box);
}
}
}
new Sample_InternalGeometry().run();