Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Orillusion/orillusion into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenderJK committed May 6, 2023
2 parents f3dfebc + d70bba0 commit 61c541f
Show file tree
Hide file tree
Showing 15 changed files with 754 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: pnpm install

- name: Test Build
run: pnpm run build
run: pnpm run build:test

- name: Test in Electron
run: pnpm run test:ci
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"scripts": {
"dev": "vite",
"build": "tsc --p tsconfig.build.json && vite build && npm run build:types && npm run minify:es",
"build:test": "tsc --p tsconfig.build.json && vite build",
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"minify:es": "uglifyjs dist/orillusion.es.js -o dist/orillusion.es.js -c -m",
"test": "electron test/ci/main.js",
Expand Down
75 changes: 0 additions & 75 deletions samples/base/Sample_Base_0.ts

This file was deleted.

27 changes: 27 additions & 0 deletions samples/base/Sample_InitEngine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Engine3D, Scene3D, CameraUtil, webGPUContext, View3D, AtmosphericComponent } from "@orillusion/core";

// init engine
class Sample_InitEngine {
async run() {
// init engine
await Engine3D.init();
// create new Scene
let scene = new Scene3D();
// add atmospheric sky
scene.addComponent(AtmosphericComponent);

// init camera3D
let mainCamera = CameraUtil.createCamera3D(null, scene);
mainCamera.perspective(60, webGPUContext.aspect, 1, 2000.0);

// create a view with target scene and camera
let view = new View3D();
view.scene = scene;
view.camera = mainCamera;

// start render
Engine3D.startRenderView(view);
}
}

new Sample_InitEngine().run();
72 changes: 72 additions & 0 deletions samples/base/Sample_Transform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { GUIHelp } from '@orillusion/debug/GUIHelp';
import { Stats } from '@orillusion/stats'
import { Engine3D, Scene3D, AtmosphericComponent, CameraUtil, webGPUContext, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, KelvinUtil, View3D } from '@orillusion/core';

// simple base demo
class Sample_Transform {
async run() {
// init engine
await Engine3D.init();
// create new Scene
let scene = new Scene3D();

// add performance stats
scene.addComponent(Stats);

// add an Atmospheric sky enviroment
let sky = scene.addComponent(AtmosphericComponent);
sky.sunY = 0.6

// init camera3D
let mainCamera = CameraUtil.createCamera3D(null, scene);
mainCamera.perspective(60, webGPUContext.aspect, 1, 2000.0);

// add a basic camera controller
let hoverCameraController = mainCamera.object3D.addComponent(HoverCameraController);
hoverCameraController.setCamera(15, -15, 10);

// create a basic cube
let cubeObj = new Object3D();
let mr = cubeObj.addComponent(MeshRenderer);
mr.geometry = new BoxGeometry();
let mat = new LitMaterial();
mr.material = mat;
scene.addChild(cubeObj);

// add a basic direct light
let lightObj = new Object3D();
lightObj.rotationX = 45;
lightObj.rotationY = 60;
lightObj.rotationZ = 150;
let dirLight = lightObj.addComponent(DirectLight);
dirLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355);
dirLight.intensity = 10;
scene.addChild(lightObj);

// create a view with target scene and camera
let view = new View3D();
view.scene = scene;
view.camera = mainCamera;

// start render
Engine3D.startRenderView(view);

let transform = cubeObj.transform;
// debug GUI
GUIHelp.init();
GUIHelp.addFolder('Transform');
GUIHelp.add(transform, 'x', -10.0, 10.0, 0.01);
GUIHelp.add(transform, 'y', -10.0, 10.0, 0.01);
GUIHelp.add(transform, 'z', -10.0, 10.0, 0.01);
GUIHelp.add(transform, 'rotationX', 0.0, 360.0, 0.01);
GUIHelp.add(transform, 'rotationY', 0.0, 360.0, 0.01);
GUIHelp.add(transform, 'rotationZ', 0.0, 360.0, 0.01);
GUIHelp.add(transform, 'scaleX', 0.0, 2.0, 0.01);
GUIHelp.add(transform, 'scaleY', 0.0, 2.0, 0.01);
GUIHelp.add(transform, 'scaleZ', 0.0, 2.0, 0.01);
GUIHelp.open();
GUIHelp.endFolder();
}
}

new Sample_Transform().run()
70 changes: 70 additions & 0 deletions samples/base/Sample_UseComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Engine3D, Scene3D, CameraUtil, webGPUContext, View3D, AtmosphericComponent, ComponentBase, Time, AxisObject, Object3DUtil, KelvinUtil, DirectLight, Object3D, HoverCameraController } from "@orillusion/core";
import { GUIHelp } from "@orillusion/debug/GUIHelp";

// sample use component
class Sample_UseComponent {
async run() {
// init engine
await Engine3D.init();
// create new Scene
let scene = new Scene3D();
// add atmospheric sky
scene.addComponent(AtmosphericComponent);

// init camera3D
let mainCamera = CameraUtil.createCamera3D(null, scene);
mainCamera.perspective(60, webGPUContext.aspect, 1, 2000.0);
let hoverCameraController = mainCamera.object3D.addComponent(HoverCameraController);
hoverCameraController.setCamera(15, -30, 10);

// create a view with target scene and camera
let view = new View3D();
view.scene = scene;
view.camera = mainCamera;

// start render
Engine3D.startRenderView(view);


// create cube
let cube = Object3DUtil.GetSingleCube(2, 4, 1, 0.7, 1, 0.5);
cube.name = 'AxisObject';
scene.addChild(cube);

// register a component
let component = cube.addComponent(RotateComponent);

// gui
GUIHelp.init();
GUIHelp.add(component, 'enable');
GUIHelp.open();
GUIHelp.endFolder();
}
}


class RotateComponent extends ComponentBase {
public init(param?: any): void {
console.log('RotateComponent init, name : ', this.object3D.name);

}
public start(): void {
console.log('RotateComponent start, name :', this.object3D.name);
}

public onUpdate(): void {
this.transform.rotationY = Math.sin(Time.time * 0.01) * 90;
}

public onEnable(view?: View3D) {
console.log('RotateComponent init, name : ', this.object3D.name);
this._enable = true;
}
public onDisable(view?: View3D) {
console.log('RotateComponent init, name : ', this.object3D.name);
this._enable = false;
}
}


new Sample_UseComponent().run();
91 changes: 91 additions & 0 deletions samples/render/Sample_BlendMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { GUIHelp } from "@orillusion/debug/GUIHelp";
import { Object3D, Scene3D, HoverCameraController, Engine3D, AtmosphericComponent, webGPUContext, View3D, DirectLight, KelvinUtil, MeshRenderer, BoxGeometry, LitMaterial, Color, BlendMode, GPUCullMode, CameraUtil } from "@orillusion/core";

//sample of change BlendMode and CullMode
class Sample_BlendMode {
lightObj: Object3D;
scene: Scene3D;

async run() {

Engine3D.setting.material.materialChannelDebug = true;
await Engine3D.init({});

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

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

mainCamera.object3D.addComponent(HoverCameraController).setCamera(-125, 0, 120);

await this.initScene(this.scene);

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

this.initLight();
//
Engine3D.startRenderView(view);
}

private initLight(): void {
this.lightObj = new Object3D();
this.lightObj.x = 0;
this.lightObj.y = 30;
this.lightObj.z = -40;
this.lightObj.rotationX = 46;
this.lightObj.rotationY = 62;
this.lightObj.rotationZ = 360;
let lc = this.lightObj.addComponent(DirectLight);
lc.lightColor = KelvinUtil.color_temperature_to_rgb(5355);
lc.castShadow = false;
lc.intensity = 200;
lc.debug();
this.scene.addChild(this.lightObj);
}

async initScene(scene: Scene3D) {

//create a box into scene
let box = new Object3D();
scene.addChild(box);

//register a mesh renderer
let meshRenderer = box.addComponent(MeshRenderer);
meshRenderer.geometry = new BoxGeometry(20, 20, 20);
let material = meshRenderer.material = new LitMaterial();
material.baseColor = new Color(0.1, 0.3, 0.6, 0.5);
material.blendMode = BlendMode.ADD;

// blend mode
let blendMode = {
NONE: BlendMode.NONE,
NORMAL: BlendMode.NORMAL,
ADD: BlendMode.ADD,
ALPHA: BlendMode.ALPHA,
}
GUIHelp.init();
// change blend mode by click dropdown box
GUIHelp.add({ blendMode: material.blendMode }, 'blendMode', blendMode).onChange((v) => {
material.blendMode = BlendMode[BlendMode[parseInt(v)]];
});

//cull mode
let cullMode = {};
cullMode[GPUCullMode.none] = GPUCullMode.none;
cullMode[GPUCullMode.front] = GPUCullMode.front;
cullMode[GPUCullMode.back] = GPUCullMode.back;

// change cull mode by click dropdown box
GUIHelp.add({ cullMode: GPUCullMode.none }, 'cullMode', cullMode).onChange((v) => {
material.cullMode = v;
});

GUIHelp.open();
GUIHelp.endFolder();
}
}

new Sample_BlendMode().run();
Loading

0 comments on commit 61c541f

Please sign in to comment.