Skip to content

Commit

Permalink
feat: add GridObject (Orillusion#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
lslzl3000 authored Jul 29, 2024
1 parent fc74fa1 commit a939ce6
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 273 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/core",
"version": "0.8.3-dev.1",
"version": "0.8.3-dev.2",
"author": "Orillusion",
"description": "Orillusion WebGPU Engine",
"type": "module",
Expand Down
6 changes: 5 additions & 1 deletion samples/base/Sample_AddRemove.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Engine3D, Scene3D, CameraUtil, View3D, AtmosphericComponent, ComponentBase, Time, AxisObject, Object3DUtil, KelvinUtil, DirectLight, Object3D, HoverCameraController, MeshRenderer, LitMaterial, BoxGeometry, UnLit, UnLitMaterial, Interpolator, FXAAPost, PostProcessingComponent } from "@orillusion/core";
import { Engine3D, Scene3D, CameraUtil, View3D, AtmosphericComponent, ComponentBase, Time, AxisObject, Object3DUtil, KelvinUtil, DirectLight, Object3D, HoverCameraController, MeshRenderer, LitMaterial, BoxGeometry, UnLit, UnLitMaterial, Interpolator, FXAAPost, PostProcessingComponent, GridObject } from "@orillusion/core";
import { GUIHelp } from "@orillusion/debug/GUIHelp";

// sample use component
Expand Down Expand Up @@ -43,6 +43,10 @@ class Sample_AddRemove {
scene.addChild(lightObj);
sky.relativeTransform = dirLight.transform;

// add a grid
let grid = new GridObject(10000, 100);
scene.addChild(grid)

// create a view with target scene and camera
this.view = new View3D();
this.view.scene = scene;
Expand Down
18 changes: 9 additions & 9 deletions samples/base/Sample_BoundingBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GUIHelp } from '@orillusion/debug/GUIHelp';
import { Color, Engine3D, Object3D, Object3DUtil, Transform, View3D, } from '@orillusion/core';
import { Color, Engine3D, GridObject, Object3D, Object3DUtil, Transform, View3D, } from '@orillusion/core';
import { GUIUtil } from '@samples/utils/GUIUtil';
import { createExampleScene, createSceneParam } from '@samples/utils/ExampleScene';
import { Graphic3D } from '@orillusion/graphic';
Expand Down Expand Up @@ -27,21 +27,22 @@ class Sample_BoundingBox {

this.box = box;
this.view = exampleScene.view;
// add a graphic3D to draw lines
this.graphic3D = new Graphic3D();
exampleScene.scene.addChild(this.graphic3D);


let parent = this.container = new Object3D();
parent.addChild(box);
exampleScene.scene.addChild(parent);

GUIHelp.open();
GUIHelp.addButton('Remove Box', () => { box.transform.parent && box.removeFromParent(); })
GUIHelp.addButton('Add Box', () => { !box.transform.parent && parent.addChild(box); })
let grid = new GridObject(1000, 100);
exampleScene.scene.addChild(grid);

GUIHelp.open();
GUIUtil.renderTransform(parent.transform, true, 'Container');
GUIUtil.renderTransform(box.transform, true, 'Box');

// add a graphic3D to draw lines
this.graphic3D = new Graphic3D();
exampleScene.scene.addChild(this.graphic3D);

}

logChange() {
Expand All @@ -52,7 +53,6 @@ class Sample_BoundingBox {
green = new Color(0, 1, 0, 1);
loop() {
this.graphic3D.drawBoundingBox(this.box.instanceID, this.box.bound as any, this.green);
this.graphic3D.drawBoundingBox(this.container.instanceID, this.container.bound as any, this.red);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Sample_UseComponent {

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

// gui
GUIHelp.init();
GUIHelp.add(component, 'enable');
Expand All @@ -52,33 +51,33 @@ class Sample_UseComponent {
directLight.lightColor = KelvinUtil.color_temperature_to_rgb(5355);
directLight.castShadow = true;
directLight.intensity = 3;
GUIUtil.renderDirLight(directLight);
scene.addChild(lightObj3D);
}
}
}


/*
* simple component of lifecyle
*/
class RotateComponent extends ComponentBase {
public init(param?: any): void {
console.log('RotateComponent init, name : ', this.object3D.name);
console.log('RotateComponent init');

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

public onUpdate(): void {
console.log('RotateComponent update')
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;
console.log('RotateComponent enable');
}
public onDisable(view?: View3D) {
console.log('RotateComponent init, name : ', this.object3D.name);
this._enable = false;
console.log('RotateComponent disable');
}
}

Expand Down
65 changes: 0 additions & 65 deletions samples/base/Sample_ComponentLife.ts

This file was deleted.

49 changes: 0 additions & 49 deletions samples/base/Sample_ComponentLifeCycle.ts

This file was deleted.

8 changes: 5 additions & 3 deletions samples/base/Sample_MatrixAllocation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GUIHelp } from '@orillusion/debug/GUIHelp';
import { Stats } from '@orillusion/stats'
import { Engine3D, Scene3D, AtmosphericComponent, CameraUtil, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, KelvinUtil, View3D, Matrix4 } from '@orillusion/core';
import { Engine3D, Scene3D, AtmosphericComponent, CameraUtil, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, KelvinUtil, View3D, Matrix4, GridObject } from '@orillusion/core';
import { GUIUtil } from '@samples/utils/GUIUtil';

class Sample_MatrixAllocation {
Expand Down Expand Up @@ -29,6 +29,8 @@ class Sample_MatrixAllocation {
mr.material = mat;
scene.addChild(cubeObj);

scene.addChild(new GridObject(1000, 100))

let view = new View3D();
view.scene = scene;
view.camera = mainCamera;
Expand All @@ -38,8 +40,8 @@ class Sample_MatrixAllocation {
GUIHelp.init();
GUIHelp.addButton('add', () => {
let obj = new Object3D();
obj.x = -5 + Math.random() * 10;
obj.z = -5 + Math.random() * 10;
obj.x = -10 + Math.random() * 20;
obj.z = -10 + Math.random() * 20;
let mr = obj.addComponent(MeshRenderer);
mr.geometry = new BoxGeometry();
mr.material = new LitMaterial();
Expand Down
11 changes: 8 additions & 3 deletions samples/base/Sample_Transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Engine3D, Scene3D, AtmosphericComponent, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, View3D, Camera3D } from "@orillusion/core";
import { Engine3D, Scene3D, AtmosphericComponent, HoverCameraController, Object3D, MeshRenderer, BoxGeometry, LitMaterial, DirectLight, View3D, Camera3D, GridObject } from "@orillusion/core";
import { Stats } from "@orillusion/stats";
import * as dat from "dat.gui"

Expand Down Expand Up @@ -43,14 +43,19 @@ const box: Object3D = new Object3D();
// add MeshRenderer
let mr: MeshRenderer = box.addComponent(MeshRenderer);
// set geometry
mr.geometry = new BoxGeometry(5, 5, 5);
mr.geometry = new BoxGeometry(1, 1, 1);
// set material
mr.material = new LitMaterial();
// set rotation
box.rotationY = 45;
box.rotationY = 0;
box.y = 0.5
// add object
scene3D.addChild(box);

// add a grid
let grid = new GridObject(1000, 100);
scene3D.addChild(grid)

// create a view with target scene and camera
let view = new View3D();
view.scene = scene3D;
Expand Down
Loading

0 comments on commit a939ce6

Please sign in to comment.