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 7, 2023
2 parents 61c541f + d2cd53c commit efbb73a
Show file tree
Hide file tree
Showing 34 changed files with 1,321 additions and 562 deletions.
2 changes: 1 addition & 1 deletion packages/ammo/ammo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default Ammo;
*/
declare function Ammo<T>(target?: T): Promise<T & typeof Ammo>;
/**
* Ammo 原生类 by Bullet2
* Ammo.js by Bullet2
*/
declare module Ammo {
function destroy(obj: any): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/ammo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/ammo",
"version": "0.1.1",
"version": "0.1.2",
"author": "Orillusion",
"description": "Orillusion WebGPU Engine",
"main": "ammo.js",
Expand Down
2 changes: 0 additions & 2 deletions packages/debug/GUIHelp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @ts-ignore
import { GUI } from 'https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js'


/**
* @internal
*/
Expand Down
138 changes: 138 additions & 0 deletions packages/debug/dat.gui.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
declare module "https://unpkg.com/dat.gui*" {
export interface GUIParams {
/**
* Handles GUI's element placement for you.
* @default true
*/
autoPlace?: boolean | undefined;
/**
* If true, starts closed.
* @default false
*/
closed?: boolean | undefined;
/**
* If true, close/open button shows on top of the GUI.
* @default false
*/
closeOnTop?: boolean | undefined;
/**
* If true, GUI is closed by the "h" keypress.
* @default false
*/
hideable?: boolean | undefined;
/**
* JSON object representing the saved state of this GUI.
*/
load?: any;
/**
* The name of this GUI.
*/
name?: string | undefined;
/**
* The identifier for a set of saved values.
*/
preset?: string | undefined;
/**
* The width of GUI element.
*/
width?: number | undefined;
}
export class GUI {
static CLASS_AUTO_PLACE: string;
static CLASS_AUTO_PLACE_CONTAINER: string;
static CLASS_MAIN: string;
static CLASS_CONTROLLER_ROW: string;
static CLASS_TOO_TALL: string;
static CLASS_CLOSED: string;
static CLASS_CLOSE_BUTTON: string;
static CLASS_CLOSE_TOP: string;
static CLASS_CLOSE_BOTTOM: string;
static CLASS_DRAG: string;
static DEFAULT_WIDTH: number;
static TEXT_CLOSED: string;
static TEXT_OPEN: string;

constructor(option?: GUIParams);

__controllers: GUIController[];
__folders: { [folderName: string]: GUI };
domElement: HTMLElement;

add<T extends object>(
target: T,
propName: keyof T,
min?: number,
max?: number,
step?: number,
): GUIController;
add<T extends object>(target: T, propName: keyof T, status: boolean): GUIController;
add<T extends object>(target: T, propName: keyof T, items: string[]): GUIController;
add<T extends object>(target: T, propName: keyof T, items: number[]): GUIController;
add<T extends object>(target: T, propName: keyof T, items: Object): GUIController;

addColor(target: Object, propName: string): GUIController;

remove(controller: GUIController): void;
destroy(): void;

addFolder(propName: string): GUI;
removeFolder(subFolder: GUI): void;

open(): void;
close(): void;
hide(): void;
show(): void;

remember(target: Object, ...additionalTargets: Object[]): void;
getRoot(): GUI;

getSaveObject(): Object;
save(): void;
saveAs(presetName: string): void;
revert(gui: GUI): void;

listen(controller: GUIController): void;
updateDisplay(): void;

// gui properties in dat/gui/GUI.js
readonly parent: GUI;
readonly scrollable: boolean;
readonly autoPlace: boolean;
preset: string;
width: number;
name: string;
closed: boolean;
readonly load: Object;
useLocalStorage: boolean;
}
export class GUIController<T extends object = object> {
domElement: HTMLElement;
object: Object;
property: string;

constructor(object: T, property: keyof T);

options(option: any): GUIController;
name(name: string): GUIController;

listen(): GUIController;
remove(): GUIController;

onChange(fnc: (value?: any) => void): GUIController;
onFinishChange(fnc: (value?: any) => void): GUIController;

setValue(value: any): GUIController;
getValue(): any;

updateDisplay(): GUIController;
isModified(): boolean;

// NumberController
min(n: number): GUIController;
max(n: number): GUIController;
step(n: number): GUIController;

// FunctionController
fire(): GUIController;
}
}
12 changes: 12 additions & 0 deletions packages/debug/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true
}
}
4 changes: 2 additions & 2 deletions packages/media-extention/ImageMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class ImageMaterial extends MaterialBase {
*/
constructor() {
super();
ShaderLib.register("ImageShVideoShaderader", ImageMaterialShader);
let shader = this.setShader(`ImageShader`, `ImageShader`);
ShaderLib.register("ImageMaterialShader", ImageMaterialShader);
let shader = this.setShader(`ImageMaterialShader`, `ImageMaterialShader`);
shader.setShaderEntry(`VertMain`, `FragMain`)
shader.setUniformVector4(`transformUV1`, new Vector4(0, 0, 1, 1));
shader.setUniformVector4(`transformUV2`, new Vector4(0, 0, 1, 1));
Expand Down
2 changes: 1 addition & 1 deletion packages/media-extention/VideoMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class VideoMaterial extends MaterialBase {
*/
constructor() {
super();
ShaderLib['VideoShader'] = VideoShader;
ShaderLib.register('VideoShader', VideoShader);
let shader = this.setShader(`VideoShader`, `VideoShader`);
shader.setShaderEntry(`VertMain`, `FragMain`)
shader.setUniformVector4(`transformUV1`, new Vector4(0, 0, 1, 1));
Expand Down
2 changes: 1 addition & 1 deletion packages/media-extention/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/media-extention",
"version": "0.1.7",
"version": "0.2.0",
"author": "Orillusion",
"description": "Orillusion Media Material Extention",
"main": "./dist/media.umd.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/media-extention/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"moduleResolution": "bundler",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/physics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/physics",
"version": "0.1.8",
"version": "0.2.0",
"author": "Orillusion",
"description": "Orillusion Physics Plugin, Powerd by Ammo.js",
"main": "./dist/physics.umd.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/physics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"moduleResolution": "bundler",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/stats/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/stats",
"version": "0.1.5",
"version": "0.2.0",
"author": "Orillusion",
"description": "Orillusion Stats Plugin",
"main": "./dist/stats.umd.js",
Expand All @@ -21,6 +21,6 @@
"url": "git+https://github.com/Orillusion/orillusion.git"
},
"dependencies": {
"@orillusion/core": ">=0.4.0"
"@orillusion/core": "^0.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/stats/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"moduleResolution": "bundler",
"sourceMap": false,
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
1 change: 1 addition & 0 deletions samples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// create menu
let title = '', list = ''
for (const path in modules) {
if (!path.includes('Sample_')) continue
const arr = path.split('/')
const _title = arr[1]
const _demo = arr[2].replace(/Sample_|Sample|\.ts/g, '')
Expand Down
129 changes: 129 additions & 0 deletions samples/lights/PointLightsScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { GUIHelp } from "@orillusion/debug/GUIHelp";
import { Vector3, ComponentBase, PointLight, SphereGeometry, LitMaterial, BoundingBox, Object3D, UUID, Quaternion, Time, View3D } from "@orillusion/core";

class PointLightItem {
public dir: Vector3 = new Vector3();
public speed: number = 300;
public mass: number = 10;
}

export class PointLightsScript extends ComponentBase {
private _points: PointLight[];
private _pointLightItems: PointLightItem[];
private _startAnim: boolean = false;

private static geo: SphereGeometry;
private static mat: LitMaterial
private static boundBox: BoundingBox;

private _geo: SphereGeometry;
private _mat: LitMaterial;
private _boundBox: BoundingBox;

constructor() {
super();
PointLightsScript.geo ||= new SphereGeometry(0.5, 6, 6);
PointLightsScript.mat ||= new LitMaterial();
PointLightsScript.boundBox ||= new BoundingBox(new Vector3(0, 10, 0), new Vector3(500, 50, 500));

this._geo = PointLightsScript.geo;
this._mat = PointLightsScript.mat;
this._boundBox = PointLightsScript.boundBox;
this._points = [];
this._pointLightItems = [];

this._startAnim = false;

GUIHelp.addFolder('random pointLight');
GUIHelp.addButton('append light', () => {
this.beginAnim();
});
GUIHelp.addButton('remove light', () => {
this.stopAnim();
});
GUIHelp.open();
GUIHelp.endFolder();
}

public beginAnim() {
this._startAnim = true;
this.transform.enable = true;

const count = 100;
for (let i = 0; i < count; i++) {
this.createLight();
}

}

public stopAnim() {
this._startAnim = false;
this.transform.enable = false;

for (let i = 0; i < this._points.length; i++) {
const element = this._points[i];
this.object3D.removeChild(element.object3D);
element.destroy();
}
this._points.length = 0;
}

private createLight() {
let obj = new Object3D();
let poi = obj.addComponent(PointLight);
poi.name = UUID();
poi.transform.x = this._boundBox.center.x + this._boundBox.extents.x * Math.random();
poi.transform.y = this._boundBox.center.y + this._boundBox.extents.y * Math.random();
poi.transform.z = this._boundBox.center.z + this._boundBox.extents.z * Math.random();
poi.range = 30
poi.r = Math.random() + 0.1;
poi.g = Math.random() + 0.1;
poi.b = Math.random() + 0.1;
poi.intensity = Math.random() * 1.5 + 10;
poi.range *= Math.random() * 0.5 + 0.5;


this.object3D.addChild(obj);
this._points.push(poi);

let item = new PointLightItem();
Quaternion.HELP_0.fromEulerAngles(Math.random() * 360, Math.random() * 360, Math.random() * 360);
item.dir = Quaternion.HELP_0.transformVector(Vector3.FORWARD);
item.speed = 50 + Math.random() * 150;
item.mass = 5 + Math.random() * 5;
this._pointLightItems.push(item);
return poi;
}

onUpdate(): void {
if (!this._startAnim)
return;
if (Time.delta > 30)
return;
for (let i = 0; i < this._points.length; i++) {
const po = this._points[i];
const pd = this._pointLightItems[i];

if (po && pd) {
pd.mass -= Time.delta * 0.001;
if (pd.mass < 0) {
Quaternion.HELP_0.fromEulerAngles(Math.random() * 360, Math.random() * 360, Math.random() * 360);
pd.dir = Quaternion.HELP_0.transformVector(Vector3.FORWARD);
pd.speed = 50 + Math.random() * 150;
pd.mass = 5 + Math.random() * 5;
}

if (!this._boundBox.containsPoint(po.transform.localPosition)) {
pd.dir = pd.dir.negate();
}

Vector3.HELP_0.copyFrom(pd.dir);
Vector3.HELP_0.scaleBy(Time.delta * 0.001 * pd.speed * 0.1);

po.transform.x += Vector3.HELP_0.x;
po.transform.y += Vector3.HELP_0.y;
po.transform.z += Vector3.HELP_0.z;
}
}
}
}
Loading

0 comments on commit efbb73a

Please sign in to comment.