Skip to content

Commit

Permalink
feat(sample): sample of loader (#114)
Browse files Browse the repository at this point in the history
Add samples of load glb/json file.
  • Loading branch information
hellmor authored May 8, 2023
1 parent c0254c6 commit 4745a5e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 14 deletions.
9 changes: 5 additions & 4 deletions samples/loader/Sample_FlightHelmet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GUIHelp } from "@orillusion/debug/GUIHelp";
import { Object3D, Camera3D, Scene3D, HoverCameraController, Engine3D, CameraUtil, View3D, SSRPost, HDRBloomPost, AtmosphericComponent, DirectLight, KelvinUtil, Time } from "@orillusion/core";
import { Object3D, Scene3D, HoverCameraController, Engine3D, CameraUtil, View3D, SSRPost, HDRBloomPost, AtmosphericComponent, DirectLight, KelvinUtil, Time } from "@orillusion/core";
import { GUIUtil as GUIUtil } from "@samples/utils/GUIUtil";

class Sample_FlightHelmet {
Expand Down Expand Up @@ -27,8 +27,9 @@ class Sample_FlightHelmet {
enable: true,
blurX: 4,
blurY: 4,
intensity: 0.5,
brightness: 1.25,
strength: 1.5,
luminosityThreshold: 0.1,
radius: 4,
debug: false
};

Expand Down Expand Up @@ -61,7 +62,7 @@ class Sample_FlightHelmet {
let atmospheric = this.scene.addComponent(AtmosphericComponent);
atmospheric.sunY = 0.73;
atmospheric.sunRadiance = 47;
atmospheric.enable = false
atmospheric.enable = false;
}
/******** light *******/
{
Expand Down
72 changes: 72 additions & 0 deletions samples/loader/Sample_LoadGLB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Object3D, Scene3D, HoverCameraController, Engine3D, CameraUtil, View3D, DirectLight, KelvinUtil, LitMaterial, MeshRenderer, PlaneGeometry, AtmosphericComponent } from "@orillusion/core";

// Sample to load glb file
export class Sample_LoadGLB {
lightObj3D: Object3D;
scene: Scene3D;

async run() {
await Engine3D.init();
Engine3D.setting.shadow.autoUpdate = true;
Engine3D.setting.shadow.shadowBias = 0.0001;

this.scene = new Scene3D();
this.scene.addComponent(AtmosphericComponent);

let camera = CameraUtil.createCamera3DObject(this.scene);
camera.perspective(60, Engine3D.aspect, 1, 5000.0);

camera.object3D.addComponent(HoverCameraController).setCamera(-45, -30, 15);

let view = new View3D();
view.scene = this.scene;
view.camera = camera;

Engine3D.startRenderView(view);

await this.initScene();
}

async initScene() {
/******** light *******/
{
this.lightObj3D = new Object3D();
this.lightObj3D.rotationX = 21;
this.lightObj3D.rotationY = 108;
this.lightObj3D.rotationZ = 10;
let lc = this.lightObj3D.addComponent(DirectLight);
lc.lightColor = KelvinUtil.color_temperature_to_rgb(5355);
lc.castShadow = true;
lc.intensity = 10;
lc.debug();
this.scene.addChild(this.lightObj3D);
}

/******** floor *******/
{
let mat = new LitMaterial();
mat.baseMap = Engine3D.res.whiteTexture;
mat.roughness = 0.85;
mat.metallic = 0.1;
let floor = new Object3D();
let mr = floor.addComponent(MeshRenderer);
mr.geometry = new PlaneGeometry(100, 100);
mr.material = mat;
this.scene.addChild(floor);
}

/******** load glb file *******/
let model = (await Engine3D.res.loadGltf('gltfs/UR3E/UR3E.glb', { onProgress: (e) => this.onLoadProgress(e), onComplete: (e) => this.onComplete(e) })) as Object3D;
this.scene.addChild(model);
model.scaleX = model.scaleY = model.scaleZ = 5;
}

onLoadProgress(e) {
console.log(e);
}

onComplete(e) {
console.log(e);
}

}
5 changes: 3 additions & 2 deletions samples/loader/Sample_LoadGLTF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class Sample_LoadGLTF {
enable: true,
blurX: 4,
blurY: 4,
intensity: 5,
brightness: 0.86,
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
debug: false
};

Expand Down
35 changes: 35 additions & 0 deletions samples/loader/Sample_LoadJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Scene3D, Engine3D, AtmosphericComponent, CameraUtil, View3D } from "@orillusion/core";

// Sample to load json file
export class Sample_LoadJson {
scene: Scene3D;

async run() {
await Engine3D.init();

this.scene = new Scene3D();
this.scene.addComponent(AtmosphericComponent);

let camera = CameraUtil.createCamera3DObject(this.scene);
camera.perspective(60, Engine3D.aspect, 1, 5000.0);

let view = new View3D();
view.scene = this.scene;
view.camera = camera;

Engine3D.startRenderView(view);

let json = await Engine3D.res.loadJSON('json/anim.json', { onProgress: (e) => this.onLoadProgress(e), onComplete: (e) => this.onComplete(e) });
console.log('json file loaded');
console.log(json);
}

onLoadProgress(e) {
console.log(e);
}

onComplete(e) {
console.log(e);
}

}
5 changes: 3 additions & 2 deletions samples/material/Sample_PBRMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Sample_PBRMaterial {
enable: true,
blurX: 4,
blurY: 4,
intensity: 1.6,
brightness: 0.8,
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
debug: false
};

Expand Down
7 changes: 4 additions & 3 deletions samples/material/Sample_UVMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class Sample_UVMove {
enable: true,
blurX: 4,
blurY: 4,
intensity: 5,
brightness: 0.629,
debug: true
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
debug: false
};

this.scene = new Scene3D();
Expand Down
7 changes: 4 additions & 3 deletions samples/render/Sample_BlendMode2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class Sample_BlendMode2 {
enable: true,
blurX: 4,
blurY: 4,
intensity: 5,
brightness: 0.629,
debug: true
luminosityThreshold: 0.8,
strength: 0.86,
radius: 4,
debug: false
};

this.scene = new Scene3D();
Expand Down

0 comments on commit 4745a5e

Please sign in to comment.