Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev/0.6 branch #574

Merged
merged 33 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
986cbc4
feat: solve math design circular dependency (#488)
yangfengzzz Sep 7, 2021
fa92e1c
PhysX based raycast and collider (#505)
yangfengzzz Sep 24, 2021
81f8f7d
feat: Add InputManager (#497)
cptbtptpbcptdtptp Sep 29, 2021
da53f3c
Fix InputManager's Bug which will be triggered when there is no physi…
cptbtptpbcptdtptp Oct 8, 2021
9492ddc
Lite Physics Package (#522)
yangfengzzz Oct 9, 2021
8c517ad
Refactor: split pbr shader (#514)
zhuxudong Oct 9, 2021
0e14a9f
feat: add createCapsule in PrimitiveMesh (#515)
JujieX Oct 11, 2021
483d05f
Feat: support read/write mipmap data from textures and render target …
zhuxudong Oct 11, 2021
0a8c480
Feat: hdr runtime (#523)
zhuxudong Oct 12, 2021
f4d524e
perf: plane horizontal default (#535)
singlecoder Oct 12, 2021
2a487a7
fix(plane): fix cull face (#537)
singlecoder Oct 12, 2021
24eaed0
fix(plane): fix uv error (#538)
singlecoder Oct 13, 2021
c118802
feat: add more uv channel and color (#548)
GuoLei1990 Oct 22, 2021
b1b2878
Feat: Sprite add clone function. (#532)
cptbtptpbcptdtptp Oct 25, 2021
60c6f80
Add color space (#543)
GuoLei1990 Oct 25, 2021
331ebc7
fix: opt code (#519)
yangfengzzz Oct 25, 2021
c8c355a
feat: modify physics-related class for editor (#547)
yangfengzzz Oct 25, 2021
82563c9
Merge main to dev/0.6 (#553)
GuoLei1990 Oct 26, 2021
259bd7f
fix: bump verison (#557)
zhuxudong Oct 28, 2021
4edd2ee
fix: shader error (#556)
zhuxudong Oct 28, 2021
a6d1f11
feat/add AnimatorState script for handle animatorState's lifecycle (#…
luzhuang Oct 29, 2021
f571fe0
feat: support skybox with hdr(rgbe) format (#567)
zhuxudong Nov 8, 2021
5c0414e
fix: color space correction (#566)
zhuxudong Nov 8, 2021
adde3a2
fix: bump version (#568)
JujieX Nov 8, 2021
be224b3
feat: change clipTime to normalized as same as transitionTime for mo…
luzhuang Nov 9, 2021
72ce686
feat: add method: addEvent overload (#559)
luzhuang Nov 9, 2021
b33681f
feat: support ambient-light replacement (#569)
zhuxudong Nov 9, 2021
3c1065a
Feat/ambient light adapter editor (#570)
zhuxudong Nov 9, 2021
9845181
feat: add getCurrentAnimatorState API and fix crossfade time (#565)
luzhuang Nov 10, 2021
9b695b0
fix: use alipay cdn for physx wasm (#571)
yangfengzzz Nov 10, 2021
00f74cd
add wasm file (#572)
yangfengzzz Nov 10, 2021
97be84a
Fix : the compatibility problem of IOS lower version (#573)
cptbtptpbcptdtptp Nov 10, 2021
b87b09f
Merge branch 'dev/0.6'
GuoLei1990 Nov 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/core/src/2d/sprite/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ export class Sprite extends RefObject {
}

set pivot(value: Vector2) {
this._pivot.setValue(MathUtil.clamp(value.x, 0, 1), MathUtil.clamp(value.y, 0, 1));
this._setDirtyFlagTrue(DirtyFlag.positions);
const pivot = this._pivot;
const x = MathUtil.clamp(value.x, 0, 1);
const y = MathUtil.clamp(value.y, 0, 1);
if (pivot === value || pivot.x !== x || pivot.y !== y) {
pivot.setValue(x, y);
this._setDirtyFlagTrue(DirtyFlag.positions);
}
}

/**
Expand Down Expand Up @@ -141,6 +146,26 @@ export class Sprite extends RefObject {
}
}

/**
* Clone.
* @returns Cloned sprite
*/
clone(): Sprite {
const cloneSprite = new Sprite(
this._engine,
this._texture,
this._region,
this._pivot,
this._pixelsPerUnit,
this.name
);
cloneSprite._assetID = this._assetID;
cloneSprite._atlasRotated = this._atlasRotated;
this._atlasRegion.cloneTo(cloneSprite._atlasRegion);
this._atlasRegionOffset.cloneTo(cloneSprite._atlasRegionOffset);
return cloneSprite;
}

/**
* Constructor a Sprite.
* @param engine - Engine to which the sprite belongs
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/Camera.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BoundingFrustum, MathUtil, Matrix, Ray, Vector2, Vector3, Vector4 } from "@oasis-engine/math";
import { Logger } from "./base";
import { deepClone, ignoreClone } from "./clone/CloneManager";
import { Component } from "./Component";
import { dependencies } from "./ComponentsDependencies";
Expand Down Expand Up @@ -414,8 +415,9 @@ export class Camera extends Component {
/**
* Manually call the rendering of the camera.
* @param cubeFace - Cube rendering surface collection
* @param mipLevel - Set mip level the data want to write, only take effect in webgl2.0
*/
render(cubeFace?: TextureCubeFace): void {
render(cubeFace?: TextureCubeFace, mipLevel: number = 0): void {
// compute cull frustum.
const context = this.engine._renderContext;
context._setContext(this);
Expand All @@ -429,12 +431,16 @@ export class Camera extends Component {

// union scene and camera macro.
ShaderMacroCollection.unionCollection(
this.scene.shaderData._macroCollection,
this.scene._globalShaderMacro,
this.shaderData._macroCollection,
this._globalShaderMacro
);

this._renderPipeline.render(context, cubeFace);
if (mipLevel > 0 && !this.engine._hardwareRenderer.isWebGL2) {
mipLevel = 0;
Logger.error("mipLevel only take effect in WebGL2.0");
}
this._renderPipeline.render(context, cubeFace, mipLevel);
this._engine._renderCount++;
}

Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/ComponentsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Script } from "./Script";
import { ShaderMacroCollection } from "./shader/ShaderMacroCollection";
import { RenderContext } from "./RenderPipeline/RenderContext";
import { Vector3 } from "@oasis-engine/math";
import { Collider } from "./physics/Collider";

/**
* The manager of the components.
Expand All @@ -30,6 +31,9 @@ export class ComponentsManager {
// Delay dispose active/inActive Pool
private _componentsContainerPool: Component[][] = [];

// Physics
private _colliders: DisorderedArray<Collider> = new DisorderedArray();

addRenderer(renderer: Renderer) {
renderer._rendererIndex = this._renderers.length;
this._renderers.add(renderer);
Expand All @@ -52,6 +56,17 @@ export class ComponentsManager {
script._onStartIndex = -1;
}

addCollider(collider: Collider) {
collider._index = this._colliders.length;
this._colliders.add(collider);
}

removeCollider(collider: Collider): void {
const replaced = this._colliders.deleteByIndex(collider._index);
replaced && (replaced._index = collider._index);
collider._index = -1;
}

addOnUpdateScript(script: Script) {
script._onUpdateIndex = this._onUpdateScripts.length;
this._onUpdateScripts.add(script);
Expand Down Expand Up @@ -224,6 +239,20 @@ export class ComponentsManager {
}
}

callColliderOnUpdate() {
const elements = this._colliders._elements;
for (let i = this._colliders.length - 1; i >= 0; --i) {
elements[i]._onUpdate();
}
}

callColliderOnLateUpdate() {
const elements = this._colliders._elements;
for (let i = this._colliders.length - 1; i >= 0; --i) {
elements[i]._onLateUpdate();
}
}

getActiveChangedTempList(): Component[] {
return this._componentsContainerPool.length ? this._componentsContainerPool.pop() : [];
}
Expand Down
56 changes: 47 additions & 9 deletions packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { IPhysics } from "@oasis-engine/design";
import { ColorSpace } from ".";
import { ResourceManager } from "./asset/ResourceManager";
import { Event, EventDispatcher, Logger, Time } from "./base";
import { Canvas } from "./Canvas";
import { ComponentsManager } from "./ComponentsManager";
import { EngineFeature } from "./EngineFeature";
import { EngineSettings } from "./EngineSettings";
import { Entity } from "./Entity";
import { FeatureManager } from "./FeatureManager";
import { InputManager } from "./input/InputManager";
import { RenderQueueType } from "./material/enums/RenderQueueType";
import { Material } from "./material/Material";
import { ModelMesh, PrimitiveMesh } from "./mesh";
import { PhysicsManager } from "./physics";
import { IHardwareRenderer } from "./renderingHardwareInterface/IHardwareRenderer";
import { ClassPool } from "./RenderPipeline/ClassPool";
import { RenderContext } from "./RenderPipeline/RenderContext";
Expand All @@ -16,18 +22,18 @@ import { SpriteMaskElement } from "./RenderPipeline/SpriteMaskElement";
import { SpriteMaskManager } from "./RenderPipeline/SpriteMaskManager";
import { Scene } from "./Scene";
import { SceneManager } from "./SceneManager";
import { CompareFunction } from "./shader";
import { BlendFactor } from "./shader/enums/BlendFactor";
import { BlendOperation } from "./shader/enums/BlendOperation";
import { ColorWriteMask } from "./shader/enums/ColorWriteMask";
import { CullMode } from "./shader/enums/CullMode";
import { Shader } from "./shader/Shader";
import { ShaderMacro } from "./shader/ShaderMacro";
import { ShaderMacroCollection } from "./shader/ShaderMacroCollection";
import { ShaderPool } from "./shader/ShaderPool";
import { ShaderProgramPool } from "./shader/ShaderProgramPool";
import { RenderState } from "./shader/state/RenderState";
import { Texture2D, TextureCubeFace, TextureCubeMap, TextureFormat } from "./texture";
import { PhysicsManager } from "./PhysicsManager";
import { ModelMesh, PrimitiveMesh } from "./mesh";
import { CompareFunction } from "./shader";

/** TODO: delete */
const engineFeatureManager = new FeatureManager<EngineFeature>();
Expand All @@ -37,8 +43,11 @@ ShaderPool.init();
* Engine.
*/
export class Engine extends EventDispatcher {
/** @internal */
static _gammaMacro: ShaderMacro = Shader.getMacroByName("OASIS_COLORSPACE_GAMMA");

/** Physics manager of Engine. */
readonly physicsManager: PhysicsManager = new PhysicsManager(this);
readonly physicsManager: PhysicsManager;

_componentsManager: ComponentsManager = new ComponentsManager();
_hardwareRenderer: IHardwareRenderer;
Expand All @@ -64,8 +73,14 @@ export class Engine extends EventDispatcher {
_shaderProgramPools: ShaderProgramPool[] = [];
/** @internal */
_spriteMaskManager: SpriteMaskManager;
/** @internal */
_inputManager: InputManager;
/** @internal */
_macroCollection: ShaderMacroCollection = new ShaderMacroCollection();

protected _canvas: Canvas;

private _settings: EngineSettings = {};
private _resourceManager: ResourceManager = new ResourceManager(this);
private _sceneManager: SceneManager = new SceneManager(this);
private _vSyncCount: number = 1;
Expand All @@ -90,6 +105,13 @@ export class Engine extends EventDispatcher {
}
};

/**
* Settings of Engine.
*/
get settings(): Readonly<EngineSettings> {
return this._settings;
}

/**
* The canvas to use for rendering.
*/
Expand Down Expand Up @@ -157,11 +179,16 @@ export class Engine extends EventDispatcher {
* Create engine.
* @param canvas - The canvas to use for rendering
* @param hardwareRenderer - Graphics API renderer
* @param physics - native physics Engine
*/
constructor(canvas: Canvas, hardwareRenderer: IHardwareRenderer) {
constructor(canvas: Canvas, hardwareRenderer: IHardwareRenderer, physics?: IPhysics, settings?: EngineSettings) {
super(null);
this._hardwareRenderer = hardwareRenderer;
this._hardwareRenderer.init(canvas);
if (physics) {
PhysicsManager._nativePhysics = physics;
this.physicsManager = new PhysicsManager();
}
this._canvas = canvas;
// @todo delete
engineFeatureManager.addObject(this);
Expand All @@ -171,6 +198,8 @@ export class Engine extends EventDispatcher {
this._spriteDefaultMaterial = this._createSpriteMaterial();
this._spriteMaskDefaultMaterial = this._createSpriteMaskMaterial();

this._inputManager = new InputManager(this);

const whitePixel = new Uint8Array([255, 255, 255, 255]);

const whiteTexture2D = new Texture2D(this, 1, 1, TextureFormat.R8G8B8A8, false);
Expand All @@ -195,6 +224,10 @@ export class Engine extends EventDispatcher {

this._backgroundTextureMesh = PrimitiveMesh.createPlane(this, 2, 2, 1, 1, false);
this._backgroundTextureMesh.isGCIgnored = true;

const colorSpace = settings?.colorSpace || ColorSpace.Linear;
colorSpace === ColorSpace.Gamma && this._macroCollection.enable(Engine._gammaMacro);
this._settings.colorSpace = colorSpace;
}

/**
Expand Down Expand Up @@ -242,7 +275,15 @@ export class Engine extends EventDispatcher {
const scene = this._sceneManager._activeScene;
const componentsManager = this._componentsManager;
if (scene) {
scene._activeCameras.sort((camera1, camera2) => camera1.priority - camera2.priority);

componentsManager.callScriptOnStart();
if (this.physicsManager) {
componentsManager.callColliderOnUpdate();
this.physicsManager._update(deltaTime);
componentsManager.callColliderOnLateUpdate();
}
this._inputManager._update();
componentsManager.callScriptOnUpdate(deltaTime);
componentsManager.callAnimationUpdate(deltaTime);
componentsManager.callScriptOnLateUpdate(deltaTime);
Expand Down Expand Up @@ -272,7 +313,7 @@ export class Engine extends EventDispatcher {
if (this._sceneManager) {
this._whiteTexture2D.destroy(true);
this._whiteTextureCube.destroy(true);

this._inputManager._destroy();
this.trigger(new Event("shutdown", this));
engineFeatureManager.callFeatureMethod(this, "shutdown", [this]);

Expand Down Expand Up @@ -328,9 +369,6 @@ export class Engine extends EventDispatcher {
scene._updateShaderData();

if (cameras.length > 0) {
// Sort on priority
//@ts-ignore
cameras.sort((camera1, camera2) => camera1.priority - camera2.priority);
for (let i = 0, l = cameras.length; i < l; i++) {
const camera = cameras[i];
const cameraEntity = camera.entity;
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/EngineSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ColorSpace } from "./enums/ColorSpace";

/**
* Render settings.
*/
export interface EngineSettings {
/** Color space.*/
colorSpace?: ColorSpace;
}
Loading