Skip to content

Commit

Permalink
Merge dev/0.7 to main (galacean#754)
Browse files Browse the repository at this point in the history
* refactor: delete deprecate code (galacean#630)

* Optimize the use of `Transform` API (galacean#638)

* refactor: opt transform API

* Merge latest main to dev/0.6 (galacean#672)

* fix: normal attributer is need in unlit (galacean#637)

* fix: normal attributer is need in unlit

* fix: physx bug (galacean#651)

* fix: physx bug

* fix: opt collider shape scale

* v0.6.7

* fix: get pixel buffer use mip level should right shift (galacean#656)

Co-authored-by: gz65555 <kevin.hs@antgroup.com>

* Update AnimatorState.ts (galacean#657)

fix: fix comment

* Rename `ability` to `component`. (galacean#608)

* fix: resize max uniform vector count (galacean#660)

* fix: resize max uniform vector count

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* fix(2d): can not update world position for sprite renderer when call … (galacean#635)

* fix(2d): can not update wrold position for sprite renderer when call bounds in the same frame

Co-authored-by: zhuxudong <callzhuxudong@163.com>
Co-authored-by: yangfengzzz <yangfengzzz@hotmail.com>
Co-authored-by: Hu Song <gz65555@gmail.com>
Co-authored-by: gz65555 <kevin.hs@antgroup.com>
Co-authored-by: luzhuang <364439895@qq.com>
Co-authored-by: Bob <768442443@qq.com>
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>
Co-authored-by: singlecoder <singlecoder2014@gmail.com>

* fix: trigger event update (galacean#673)

* fix: trigger event update

* fix: ignore scale (galacean#670)

* fix: camera ignore scale

* Fix transform bug (galacean#678)

* fix: transform

* Fix: ModelMesh._indicesChangeFlag (galacean#685)


* Fix: ModelMesh._indicesChangeFlag

* feat: non-trigger script and dynamic collider (galacean#680)

* feat: non-trigger script and dynamic collider

* fix: rotation not normalized bug (galacean#693)

* Offscreen canvas requires no input interaction. (galacean#689)

* fix:InputManager when use OffScreenCanvas

* feat: keyboardevent (galacean#677)

* feat: keyboardevent

* feat: physics fix-time update (galacean#700)

* feat: fix-time physics update

* feat: add physicsUpdate in Script

* Optimize: Optimize the lookat function of transform. (galacean#701)

* fix:transform lookat

* fix: transoform `rotate` bug when `relativeToLocal` is true (galacean#702)

* fix: wordRotationQuatenion bug (galacean#703)

* Feat:The first version of text system (galacean#686)

* feat(text): init TextRenderer

* fix: fix text renderer clone error (galacean#716)

* fix(text): fix text renderer clone error

* Optimization texture structure (galacean#715)

* feat: opt texture struct

* fix: script destroy bug (galacean#720)

* fix: script destroy bug

* Feat: support multi-uv and occlusion texture coordinate (galacean#683)

* feat: support multi uv and occlusion texture coord

* Optimization physics init (galacean#722)

* refactor: opt physics int

* fix: physics update order and destroy method (galacean#727)

* fix: physcis event remove when collider shape destroy (galacean#738)

* fix: physcis event remove when collider shape destroy

* physics test (galacean#742)

* Fix RenderTaget type problem (galacean#741)

* Test: text system (galacean#740)

* feat(text): test for text renderer

* Fix unit test and compile bug (galacean#746)

* fix: component unit test

* test: test for text renderer (galacean#745)

* feat(text): fix test for text renderer

* FloatTexture version Blendshape  (galacean#737)

* feat: add texture-2d-array and rename TextureCubeMap to TextureCube

* feat: opt blendshape animation and improve attribute version

* Opt ModelMesh code (galacean#739)

* refactor: opt `ModelMesh` code

* refactor: opt code

* refactor: opt code (galacean#747)

* Feat: support load hdr to cubemap in RGBM format and invert x axis (galacean#733)

* feat: add HDR loader

* Feat: support pbr clearcoat (galacean#669)

* feat: support clearcoat

* feat: support  Specular  AA

* feat: animator play backwards (galacean#730)

* feat: animator play backwward

* refactor: fix code

* refactor: opt code

* Merge latest `main` to `dev/0.7` (galacean#751)

* refactor: merge latest `main` to `dev/0.7

* feat: update wasm version (galacean#753)

* refactor:opt code

Co-authored-by: zhuxudong <callzhuxudong@163.com>
Co-authored-by: yangfengzzz <yangfengzzz@hotmail.com>
Co-authored-by: Hu Song <gz65555@gmail.com>
Co-authored-by: gz65555 <kevin.hs@antgroup.com>
Co-authored-by: luzhuang <364439895@qq.com>
Co-authored-by: Bob <768442443@qq.com>
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>
Co-authored-by: singlecoder <singlecoder2014@gmail.com>
Co-authored-by: AZhan <njktsmshh@163.com>
  • Loading branch information
10 people committed Apr 22, 2022
1 parent bd25e48 commit a1b56e8
Show file tree
Hide file tree
Showing 172 changed files with 6,612 additions and 3,002 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"npmClient": "npm",
"version": "0.6.8",
"version": "0.7.0-beta.0",
"bootstrap": {
"hoist": true
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-replace": "^2.3.4",
"@types/jest": "^26.0.20",
"@types/offscreencanvas": "^2019.6.4",
"@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0",
"babel-jest": "^26.6.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/controls/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasis-engine/controls",
"version": "0.6.8",
"version": "0.7.0-beta.0",
"license": "MIT",
"scripts": {
"b:types": "tsc",
Expand All @@ -15,6 +15,6 @@
"types/**/*"
],
"dependencies": {
"oasis-engine": "0.6.8"
"oasis-engine": "0.7.0-beta.0"
}
}
2 changes: 1 addition & 1 deletion packages/controls/src/FreeControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class FreeControl extends Script {
*/
updateSpherical(): void {
this._v3Cache.setValue(0, 0, -1);
Vector3.transformByQuat(this._v3Cache, this.camera.rotation, this._v3Cache);
Vector3.transformByQuat(this._v3Cache, this.camera.transform.rotationQuaternion, this._v3Cache);
this._spherical.setFromVec3(this._v3Cache);
this._theta = this._spherical.theta;
this._phi = this._spherical.phi;
Expand Down
9 changes: 5 additions & 4 deletions packages/controls/src/Spherical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export class Spherical {

setToVec3(v3: Vector3) {
const sinPhiRadius = Math.sin(this.phi) * this.radius;

v3.x = sinPhiRadius * Math.sin(this.theta);
v3.y = Math.cos(this.phi) * this.radius;
v3.z = sinPhiRadius * Math.cos(this.theta);
v3.setValue(
sinPhiRadius * Math.sin(this.theta),
Math.cos(this.phi) * this.radius,
sinPhiRadius * Math.cos(this.theta)
);

return this;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasis-engine/core",
"version": "0.6.8",
"version": "0.7.0-beta.0",
"license": "MIT",
"main": "dist/main.js",
"module": "dist/module.js",
Expand All @@ -14,9 +14,9 @@
"types/**/*"
],
"dependencies": {
"@oasis-engine/math": "0.6.8"
"@oasis-engine/math": "0.7.0-beta.0"
},
"devDependencies": {
"@oasis-engine/design": "0.6.8"
"@oasis-engine/design": "0.7.0-beta.0"
}
}
95 changes: 95 additions & 0 deletions packages/core/src/2d/dynamic-atlas/DynamicTextAtlas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Rect } from "@oasis-engine/math";
import { Engine } from "../../Engine";
import { Texture2D } from "../../texture/Texture2D";
import { Sprite } from "../sprite/Sprite";

/**
* Dynamic atlas for text.
*/
export class DynamicTextAtlas {
private static _region: Rect = new Rect();

private _texture: Texture2D;
private _width: number;
private _height: number;

private _space: number = 1;
private _curX: number = 1;
private _curY: number = 1;
private _nextY: number = 1;

private _sprites: Record<number, Sprite> = {};

constructor(engine: Engine, width: number, height: number) {
this._width = width;
this._height = height;
this._texture = new Texture2D(engine, width, height);
this._texture._addRefCount(1);
}

/**
* Destroy atlas, it will release the texture.
*/
public destroy() {
this._sprites = {};
this._texture.destroy(true);
}

/**
* Add a sprite.
* @param sprite - the sprite to add
* @param imageSource - The source of texture
* @returns true if add sprite success, otherwise false
*/
public addSprite(sprite: Sprite, imageSource: TexImageSource | OffscreenCanvas): boolean {
const { _space: space, _texture: texture } = this;
const { width, height } = imageSource;

const endX = this._curX + width + space;
if (endX >= this._width) {
this._curX = space;
this._curY = this._nextY + space;
}

const endY = this._curY + height + space;
if (endY > this._nextY) {
this._nextY = endY;
}

if (this._nextY >= this._height) {
return false;
}

texture.setImageSource(imageSource, 0, false, false, this._curX, this._curY);
texture.generateMipmaps();

const { _width, _height } = this;
const region = DynamicTextAtlas._region;
region.setValue(this._curX / _width, this._curY / _height, width / _width, height / _height);

// destroy origin texture.
sprite.texture && sprite.texture.destroy();
// Update atlas texture.
sprite.atlasRegion = region;
sprite.texture = texture;
this._curX = endX + space;

return true;
}

/**
* Remove a sprite.
* @param sprite - the sprite to remove
* @returns true if remove sprite success, otherwise false
*/
public removeSprite(sprite: Sprite): boolean {
const id = sprite.instanceId;
const { _sprites } = this;
if (_sprites[id]) {
delete _sprites[id];
return true;
}
return false;
}
}

126 changes: 126 additions & 0 deletions packages/core/src/2d/dynamic-atlas/DynamicTextAtlasManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Sprite } from "../sprite/Sprite";
import { Engine } from "../../Engine";
import { DynamicTextAtlas } from "./DynamicTextAtlas";

/**
* Dynamic atlas manager for text.
*/
export class DynamicTextAtlasManager {
private _maxAtlasCount: number = 2;
private _textureSize: number = 1024;
private _atlases: Array<DynamicTextAtlas> = [];
private _atlasIndex: number = -1;
private _spritesInAtlasIndex: Record<number, number> = {};

/**
* Indicates how many atlases should be created.
*/
get maxAtlasCount(): number {
return this._maxAtlasCount;
}

set maxAtlasCount(val: number) {
this._maxAtlasCount = val;
}

/**
* Indicates the size of the texture.
*/
get textureSize(): number {
return this._textureSize;
}

set textureSize(val: number) {
this._textureSize = Math.min(val, 2048);
}

/**
* @internal
*/
constructor(public readonly engine: Engine) {}

/**
* Add a sprite to atlas.
* @param sprite - the sprite to add
* @param imageSource - The source of texture
* @returns true if add sprite success, otherwise false
*/
public addSprite(sprite: Sprite, imageSource: TexImageSource | OffscreenCanvas): boolean {
// Remove sprite if the sprite has been add.
const { _spritesInAtlasIndex, _atlases } = this;
const id = sprite.instanceId;
const atlasIndex = _spritesInAtlasIndex[id];
if (atlasIndex) {
_atlases[atlasIndex].removeSprite(sprite);
delete _spritesInAtlasIndex[id];
}

if (this._atlasIndex >= this._maxAtlasCount) {
return false;
}

let atlas = _atlases[this._atlasIndex];
if (!atlas) {
atlas = this._createAtlas();
}

if (atlas.addSprite(sprite, imageSource)) {
_spritesInAtlasIndex[id] = this._atlasIndex;
return true;
}

if (this._atlasIndex + 1 >= this._maxAtlasCount) {
this._atlasIndex = this._maxAtlasCount;
return false;
}

atlas = this._createAtlas();
if (atlas.addSprite(sprite, imageSource)) {
_spritesInAtlasIndex[id] = this._atlasIndex;
return true;
}
return false;
}

/**
* Remove a sprite from atlas.
* @param sprite - the sprite to remove
* @returns true if remove sprite success, otherwise false
*/
public removeSprite(sprite: Sprite): boolean {
if (!sprite) return false;

const { _atlases } = this;
for (let i = _atlases.length - 1; i >= 0; --i) {
const atlas = _atlases[i];
if(atlas.removeSprite(sprite)) {
delete this._spritesInAtlasIndex[i];
return true;
}
}

return false;
}

/**
* Reset all atlases.
*/
public reset() {
const { _atlases } = this;
for (let i = 0, l = _atlases.length; i < l; ++i) {
_atlases[i].destroy();
}

_atlases.length = 0;
this._atlasIndex = -1;
this._spritesInAtlasIndex = {};
}

private _createAtlas(): DynamicTextAtlas {
this._atlasIndex++;
const { _textureSize } = this;
const atlas = new DynamicTextAtlas(this.engine, _textureSize, _textureSize);
this._atlases.push(atlas);
return atlas;
}
}
11 changes: 11 additions & 0 deletions packages/core/src/2d/enums/FontStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* The style of the font.
*/
export enum FontStyle {
/** Set font without style */
None = 0x0,
/** Set font bold */
Bold = 0x1,
/** Set font italic */
Italic = 0x2
}
23 changes: 23 additions & 0 deletions packages/core/src/2d/enums/TextAlignment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The horizontal alignment of the text.
*/
export enum TextHorizontalAlignment {
/** Align left horizontally */
Left = 0,
/** Align center horizontally */
Center = 1,
/** Align right horizontally */
Right = 2
}

/**
* The vertical alignment of the text.
*/
export enum TextVerticalAlignment {
/** Align top vertically */
Top = 0,
/** Align center vertically */
Center = 1,
/** Align bottom vertically */
Bottom = 2
}
9 changes: 9 additions & 0 deletions packages/core/src/2d/enums/TextOverflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The way to handle the situation where wrapped text is too tall to fit in the height.
*/
export enum OverflowMode {
/** Overflow when the text is too tall */
Overflow = 0,
/** Truncate with height when the text is too tall */
Truncate = 1
}
4 changes: 4 additions & 0 deletions packages/core/src/2d/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { SpriteMaskInteraction } from "./enums/SpriteMaskInteraction";
export { SpriteMaskLayer } from "./enums/SpriteMaskLayer";
export { TextHorizontalAlignment, TextVerticalAlignment } from "./enums/TextAlignment";
export { OverflowMode } from "./enums/TextOverflow";
export { FontStyle } from "./enums/FontStyle";
export { SpriteAtlas } from "./atlas/SpriteAtlas";
export * from "./sprite/index";
export * from "./text/index";
10 changes: 5 additions & 5 deletions packages/core/src/2d/sprite/Sprite.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BoundingBox, MathUtil, Rect, Vector2, Vector4 } from "@oasis-engine/math";
import { RefObject } from "../../asset/RefObject";
import { BoolUpdateFlag } from "../../BoolUpdateFlag";
import { Engine } from "../../Engine";
import { Texture2D } from "../../texture/Texture2D";
import { UpdateFlag } from "../../UpdateFlag";
import { UpdateFlagManager } from "../../UpdateFlagManager";

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ export class Sprite extends RefObject {
* Clone.
* @returns Cloned sprite
*/
clone(): Sprite {
clone(): Sprite {
const cloneSprite = new Sprite(
this._engine,
this._texture,
Expand All @@ -201,8 +201,8 @@ export class Sprite extends RefObject {
/**
* @internal
*/
_registerUpdateFlag(): UpdateFlag {
return this._updateFlagManager.register();
_registerUpdateFlag(): BoolUpdateFlag {
return this._updateFlagManager.createFlag(BoolUpdateFlag);
}

/**
Expand Down Expand Up @@ -363,7 +363,7 @@ export class Sprite extends RefObject {

private _setDirtyFlagTrue(type: number): void {
this._dirtyFlag |= type;
this._updateFlagManager.distribute();
this._updateFlagManager.dispatch();
}

private _setDirtyFlagFalse(type: number): void {
Expand Down
Loading

0 comments on commit a1b56e8

Please sign in to comment.