forked from galacean/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> Co-authored-by: yangfengzzz <[email protected]> Co-authored-by: Hu Song <[email protected]> Co-authored-by: gz65555 <[email protected]> Co-authored-by: luzhuang <[email protected]> Co-authored-by: Bob <[email protected]> Co-authored-by: shensi.zxd <[email protected]> Co-authored-by: singlecoder <[email protected]> * 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 <[email protected]> Co-authored-by: yangfengzzz <[email protected]> Co-authored-by: Hu Song <[email protected]> Co-authored-by: gz65555 <[email protected]> Co-authored-by: luzhuang <[email protected]> Co-authored-by: Bob <[email protected]> Co-authored-by: shensi.zxd <[email protected]> Co-authored-by: singlecoder <[email protected]> Co-authored-by: AZhan <[email protected]>
- Loading branch information
1 parent
bd25e48
commit a1b56e8
Showing
172 changed files
with
6,612 additions
and
3,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
packages/core/src/2d/dynamic-atlas/DynamicTextAtlasManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.