Skip to content

Commit

Permalink
chore: update folder (Orillusion#83)
Browse files Browse the repository at this point in the history
update folder fix not run
update folder
Removes all non-ASCII characters
add gltf parser
fix SkinMeshRender not work.
  • Loading branch information
ZenderJK authored Apr 29, 2023
1 parent d7f5dee commit e22b4d4
Show file tree
Hide file tree
Showing 492 changed files with 7,551 additions and 3,548 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</head>

<body>
<script type="module" src="/src/sample/index.ts"></script>
<script type="module" src="/sample/index.ts"></script>
</body>

</html>
103 changes: 54 additions & 49 deletions src/engine/Engine3D.ts → src/Engine3D.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,81 @@
import { version } from '../../package.json';
import { Res } from './assets/Res';
import { ShaderLib } from './assets/shader/ShaderLib';
import { CanvasConfig } from './gfx/graphics/webGpu/CanvasConfig';
import { Color } from './math/Color';
import { EngineSetting } from './setting/EngineSetting';
import { Time } from './util/Time';
import { InputSystem } from './io/InputSystem';
import { View3D } from './core/View3D';
import { version } from '../package.json';
import { webGPUContext } from './gfx/graphics/webGpu/Context3D';
import { CanvasConfig } from './gfx/graphics/webGpu/CanvasConfig';
import { FXAAPost } from './gfx/renderJob/post/FXAAPost';
import { ForwardRenderJob } from './gfx/renderJob/jobs/ForwardRenderJob';
import { GlobalBindGroup } from './gfx/graphics/webGpu/core/bindGroups/GlobalBindGroup';
import { Interpolator } from './math/TimeInterpolator';
import { RTResourceMap } from './gfx/renderJob/frame/RTResourceMap';
import { ForwardRenderJob } from './gfx/renderJob/jobs/ForwardRenderJob';
import { RendererJob } from './gfx/renderJob/jobs/RendererJob';
import { FXAAPost } from './gfx/renderJob/post/FXAAPost';
import { InputSystem } from './io/InputSystem';
import { Color } from './math/Color';
import { Interpolator } from './math/TimeInterpolator';
import { EngineSetting } from './setting/EngineSetting';
import { defaultRes } from './textures/DefaultRes';
import { Time } from './util/Time';
import { Res } from './assets/Res';
import { ShaderLib } from './assets/shader/ShaderLib';
import { ShaderUtil } from './gfx/graphics/webGpu/shader/util/ShaderUtil';
import { ComponentCollect } from './gfx/renderJob/collect/ComponentCollect';

/**
/**
* Orillusion 3D Engine
* @notExported
* @group engine3D
*/
class _Engine3D {
export class Engine3D {
/**
* @internal
*/
// [x: string]: any;
/**
* resource manager
*/
public res: Res;
public static res: Res;
/**
* input system
*/
public inputSystem: InputSystem;
public views: View3D[];
public static inputSystem: InputSystem;
public static views: View3D[];

private _frameRateValue: number = 0;
private _frameRate: number = 360;
private _isRun: boolean = false;
private _frameTimeCount: number = 0;
private _deltaTime: number = 0;
private _time: number = 0;
private static _frameRateValue: number = 0;
private static _frameRate: number = 360;
private static _isRun: boolean = false;
private static _frameTimeCount: number = 0;
private static _deltaTime: number = 0;
private static _time: number = 0;

public get frameRate(): number {
public static get frameRate(): number {
return this._frameRate;
}

public set frameRate(value: number) {
public static set frameRate(value: number) {
this._frameRate = value;
this._frameRateValue = 1.0 / value;
if (value >= 360) {
this._frameRateValue = 0;
}
}

public get size(): number[] {
public static get size(): number[] {
return webGPUContext.presentationSize;
}

public get aspect(): number {
public static get aspect(): number {
return webGPUContext.aspect;
}

public static get width(): number {
return webGPUContext.windowWidth;
}

public static get height(): number {
return webGPUContext.windowHeight;
}

/**
* engine setting
*/
public setting: EngineSetting = {
public static setting: EngineSetting = {
occlusionQuery: {
enable: true,
debug: false,
Expand Down Expand Up @@ -236,44 +245,40 @@ class _Engine3D {
},
};

private _beforeRender: Function;
private _renderLoop: Function;
private _lateRender: Function;
private static _beforeRender: Function;
private static _renderLoop: Function;
private static _lateRender: Function;
/**
* @internal
*/
public renderJobs: Map<View3D, RendererJob>;
public static renderJobs: Map<View3D, RendererJob>;

public get width(): number {
return webGPUContext.windowWidth;
}

public get height(): number {
return webGPUContext.windowHeight;
}

/**
* create webgpu 3d engine
* @param descriptor {@link CanvasConfig}
* @returns
*/
public async init(descriptor: { canvasConfig?: CanvasConfig; beforeRender?: Function; renderLoop?: Function; lateRender?: Function, engineSetting?: EngineSetting } = {}) {
public static async init(descriptor: { canvasConfig?: CanvasConfig; beforeRender?: Function; renderLoop?: Function; lateRender?: Function, engineSetting?: EngineSetting } = {}) {
console.log('engine version', version);

this.setting = { ...this.setting, ...descriptor.engineSetting }

await webGPUContext.init(descriptor.canvasConfig);

ShaderLib.init();
ComponentCollect.init();

GlobalBindGroup.initCommon();
ShaderLib.init();

this.res = new Res();
ShaderUtil.init();

await defaultRes.initCommon();
GlobalBindGroup.init();

RTResourceMap.init();

this.res = new Res();

this._beforeRender = descriptor.beforeRender;
this._renderLoop = descriptor.renderLoop;
this._lateRender = descriptor.lateRender;
Expand All @@ -282,7 +287,7 @@ class _Engine3D {
return;
}

public startRenderView(view: View3D) {
public static startRenderView(view: View3D) {
this.renderJobs ||= new Map<View3D, RendererJob>();
this.views = [view];
let renderJob = new ForwardRenderJob(view);
Expand All @@ -293,7 +298,7 @@ class _Engine3D {
return renderJob;
}

public startRenderViews(views: View3D[]) {
public static startRenderViews(views: View3D[]) {
this.renderJobs ||= new Map<View3D, RendererJob>();
this.views = views;
for (let i = 0; i < views.length; i++) {
Expand All @@ -306,15 +311,15 @@ class _Engine3D {
this.render(0);
}

public getRenderJob(view: View3D): RendererJob {
public static getRenderJob(view: View3D): RendererJob {
return this.renderJobs.get(view);
}


/**
* @internal
*/
public render(time) {
public static render(time) {
if (!this._isRun) {
this._deltaTime = time - this._time;
this._time = time;
Expand All @@ -332,7 +337,7 @@ class _Engine3D {
requestAnimationFrame((t) => this.render(t));
}

public updateFrame(time: number) {
public static updateFrame(time: number) {
Time.delta = time - Time.time;
Time.time = time;
Time.frame += 1;
Expand All @@ -352,4 +357,4 @@ class _Engine3D {
* Orillusion 3D
* @group engine3D
*/
export let Engine3D = new _Engine3D();
// export let Engine3D = new _Engine3D();
96 changes: 96 additions & 0 deletions src/engine/assets/Res.ts → src/assets/Res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { I3DMParser } from "../loader/parser/I3DMParser";
import { GLTF_Info } from '../loader/parser/gltf/GLTFInfo';
import { HDRTexture } from '../textures/HDRTexture';
import { LDRTextureCube } from '../textures/LDRTextureCube';
import { BRDFLUTGenerate } from '../gfx/generate/BrdfLUTGenerate';
import { Uint8ArrayTexture } from '../textures/Uint8ArrayTexture';

/**
* Resource management classes for textures, materials, models, and preset bodies.
Expand All @@ -24,6 +26,7 @@ export class Res {
private _texturePool: Map<string, Texture>;
private _materialPool: Map<string, MaterialBase>;
private _prefabPool: Map<string, Object3D>;
// private _prefabLoaderPool: Map<string, PrefabLoader>;
private _gltfPool: Map<string, GLTF_Info>;

/**
Expand All @@ -33,7 +36,10 @@ export class Res {
this._texturePool = new Map<string, Texture>();
this._materialPool = new Map<string, MaterialBase>();
this._prefabPool = new Map<string, Object3D>();
// this._prefabLoaderPool = new Map<string, PrefabLoader>;
this._gltfPool = new Map<string, GLTF_Info>;

this.initDefault();
}

public getGltf(url: string): GLTF_Info {
Expand Down Expand Up @@ -279,13 +285,103 @@ export class Res {
return cubeMap;
}

/**
* load json data from url.
* @param url the path of image
*/
public async loadJSON(url: string, loaderFunctions?: LoaderFunctions) {
return await new FileLoader()
.loadJson(url, loaderFunctions)
.then(async (ret) => {
return ret;
})
.catch((e) => {
console.log(e);
});
}

/**
* normal texture
*/
public normalTexture: Uint8ArrayTexture;
public maskTexture: Uint8ArrayTexture;
public whiteTexture: Uint8ArrayTexture;
public blackTexture: Uint8ArrayTexture;
public redTexture: Uint8ArrayTexture;
public blueTexture: Uint8ArrayTexture;
public greenTexture: Uint8ArrayTexture;
public yellowTexture: Uint8ArrayTexture;
public grayTexture: Uint8ArrayTexture;

public defaultSky: HDRTextureCube;

/**
* create a texture
* @param width width of texture
* @param height height of texture
* @param r component-red
* @param g component-green
* @param b component-blue
* @param a component-alpha(0 for transparent,1 for opaque)
* @param name name string
* @returns
*/
public createTexture(width: number, height: number, r: number, g: number, b: number, a: number, name?: string) {
let w = 32;
let h = 32;
let textureData = new Uint8Array(w * h * 4);
this.fillColor(textureData, width, height, r, g, b, a);
let texture = new Uint8ArrayTexture();
texture.name = name;
texture.create(16, 16, textureData, true);
if (name) {
this.addTexture(name, texture);
}
return texture;
}

/**
* fill slod color to this texture
* @param array data of texture
* @param w width of texture
* @param h height of texture
* @param r component-red
* @param g component-green
* @param b component-blue
* @param a component-alpha(0 for transparent,1 for opaque)
*/
public fillColor(array: any, w: number, h: number, r: number, g: number, b: number, a: number) {
for (let i = 0; i < w; i++) {
for (let j = 0; j < h; j++) {
let pixelIndex = j * w + i;
array[pixelIndex * 4 + 0] = r;
array[pixelIndex * 4 + 1] = g;
array[pixelIndex * 4 + 2] = b;
array[pixelIndex * 4 + 3] = a;
}
}
}

/**
* Initialize a common texture object. Provide a universal solid color texture object.
*/
private initDefault() {
this.normalTexture = this.createTexture(32, 32, 255 * 0.5, 255 * 0.5, 255.0, 255.0, 'default-normalTexture');
this.maskTexture = this.createTexture(32, 32, 255, 255 * 0.5, 0.0, 255.0, 'default-maskTexture');
this.whiteTexture = this.createTexture(32, 32, 255, 255, 255, 255, 'default-whiteTexture');
this.blackTexture = this.createTexture(32, 32, 0, 0, 0, 255.0, 'default-blackTexture');
this.redTexture = this.createTexture(32, 32, 255, 0, 0, 255.0, 'default-redTexture');
this.blueTexture = this.createTexture(32, 32, 0, 0, 255, 255.0, 'default-blueTexture');
this.greenTexture = this.createTexture(32, 32, 0, 255, 0, 255, 'default-greenTexture');
this.yellowTexture = this.createTexture(32, 32, 0, 255, 255, 255.0, 'default-yellowTexture');
this.grayTexture = this.createTexture(32, 32, 128, 128, 128, 255.0, 'default-grayTexture');

let brdf = new BRDFLUTGenerate();
let texture = brdf.generateBRDFLUTTexture();
let BRDFLUT = texture.name = 'BRDFLUT';
this.addTexture(BRDFLUT, texture);

this.defaultSky = new HDRTextureCube();
this.defaultSky.createFromTexture(128, this.blackTexture);
}
}
Loading

0 comments on commit e22b4d4

Please sign in to comment.