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

feat: text #586

Merged
merged 74 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
df25f03
feat: solve math design circular dependency (#485)
yangfengzzz Sep 7, 2021
f064cc8
Revert "feat: solve math design circular dependency (#485)" (#487)
GuoLei1990 Sep 7, 2021
2878bdf
feat: add rotateAxisAngle for Quaternion (#480)
JujieX Sep 7, 2021
7d17191
refactor: delete useless scene raycast (#493)
gz65555 Sep 8, 2021
aea4277
fix: group other uniform block (#504)
zhuxudong Sep 10, 2021
6b86f88
fix(primitivemesh): fix cylinder error (#526)
singlecoder Oct 8, 2021
750be3c
Perf: release gpu command (#503)
zhuxudong Oct 9, 2021
bc9487d
fix: reset clipTime (#530)
luzhuang Oct 9, 2021
2b94bb7
feat(text): init TextRenderer
singlecoder Oct 11, 2021
279bc2b
Merge branch 'dev/0.6' of https://github.com/oasis-engine/engine into…
singlecoder Oct 11, 2021
a707c94
feat(text): add bounds
singlecoder Oct 12, 2021
0108031
Merge branch 'dev/0.6' of https://github.com/oasis-engine/engine into…
singlecoder Oct 12, 2021
365219c
fix: use string replace asset type to extend easily (#520)
gz65555 Oct 12, 2021
159e5a2
Fix/animator (#531)
luzhuang Oct 12, 2021
18909ed
Update README.md
eyworldwide Oct 12, 2021
3085ac8
Fix: cubic interpolation and crossfade bug: From fixed pose to dest p…
luzhuang Oct 12, 2021
b5bd22d
v0.5.3
GuoLei1990 Oct 12, 2021
871c102
v0.5.4
GuoLei1990 Oct 12, 2021
d9ef75d
v0.5.5
GuoLei1990 Oct 12, 2021
e8cc0e1
v0.5.6
GuoLei1990 Oct 12, 2021
3b4a242
fix(2d): opt shader precision (#542)
singlecoder Oct 15, 2021
e36cb48
fix: delete default gl state (#550)
zhuxudong Oct 25, 2021
f757f7f
fix(gl): fix gl error (#555)
singlecoder Oct 26, 2021
e8b3097
v0.5.7
GuoLei1990 Oct 26, 2021
35355e2
Merge branch 'dev/0.6' of https://github.com/oasis-engine/engine into…
singlecoder Nov 1, 2021
81f8fe5
feat(text): first basic version
singlecoder Nov 2, 2021
1a0105a
feat(text): fix black border
singlecoder Nov 2, 2021
e57fdf9
feat(text): opt canvas for 2d
singlecoder Nov 4, 2021
d9832dd
Fix Call EndRender Error (#563)
gz65555 Nov 4, 2021
1a0862d
feat(text): opt text color
singlecoder Nov 5, 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
b70ca9f
Update README.md
GuoLei1990 Nov 9, 2021
72761a6
Update README.md
GuoLei1990 Nov 9, 2021
aca8331
Update README.md
GuoLei1990 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
f986b98
Merge dev/0.6 branch (#574)
GuoLei1990 Nov 10, 2021
a5a77ce
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 10, 2021
8ced19e
v0.6.0-alpha.0
GuoLei1990 Nov 10, 2021
11690f3
refactor: fix physics package.json
GuoLei1990 Nov 10, 2021
056cc8d
refactor: fix physics package.json (#575)
GuoLei1990 Nov 10, 2021
7f9f533
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 10, 2021
9c1e648
v0.6.0-alpha.1
GuoLei1990 Nov 10, 2021
0d54a6f
feat: support env loader (#577)
zhuxudong Nov 11, 2021
18577dd
fix: fix physcis update time and dynamic collider update (#578)
yangfengzzz Nov 12, 2021
61c7c5d
Merge branch 'dev/0.6'
GuoLei1990 Nov 12, 2021
bac0857
feat: support env loader (#577) (#580)
GuoLei1990 Nov 12, 2021
55deb20
Feat/animator reset (#533)
luzhuang Nov 12, 2021
9c0b2db
Merge branch 'dev/0.6'
GuoLei1990 Nov 12, 2021
c9da58a
Merge latest dev/0.6 (#581)
GuoLei1990 Nov 12, 2021
f98a156
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 12, 2021
221743b
feat: adapter env (#582)
zhuxudong Nov 12, 2021
346b809
feat: add rgbm switch (#584)
zhuxudong Nov 12, 2021
6801e51
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 12, 2021
a8f3fda
Feat/animator reset (#583)
luzhuang Nov 12, 2021
ee9e5f3
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 12, 2021
c1a7473
feat(text): fix conflicts
singlecoder Nov 15, 2021
28455a8
feat(text): opt code
singlecoder Nov 15, 2021
99dde83
feat(text): modify version
singlecoder Nov 15, 2021
32fdb20
Fix Background UV Error and Update TypeScript Version (#585)
gz65555 Nov 15, 2021
95005fb
Merge branch 'main' of github.com:oasis-engine/engine
GuoLei1990 Nov 15, 2021
a84eee3
v0.6.0-alpha.2
GuoLei1990 Nov 15, 2021
23f58d7
v0.6.0-alpha.3
GuoLei1990 Nov 15, 2021
7df7a01
feat(text): fix conflicts
singlecoder Nov 16, 2021
80d3fa8
feat(text): fix conflicts
singlecoder Nov 16, 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
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.0-alpha.1",
"version": "0.6.0-alpha.3",
"bootstrap": {
"hoist": true
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"rollup-plugin-modify": "^3.0.0",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^3.9.3"
"typescript": "^4.4.3"
},
"husky": {
"hooks": {
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.0-alpha.1",
"version": "0.6.0-alpha.3",
"license": "MIT",
"scripts": {
"b:types": "tsc",
Expand All @@ -15,6 +15,6 @@
"types/**/*"
],
"dependencies": {
"oasis-engine": "0.6.0-alpha.1"
"oasis-engine": "0.6.0-alpha.3"
}
}
2 changes: 2 additions & 0 deletions packages/controls/src/OrbitControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { Entity, Matrix, Script, Vector2, Vector3 } from "oasis-engine";
import { Spherical } from "./Spherical";

type MouseWheelEvent = any;

/**
* The camera's track controller, can rotate, zoom, pan, support mouse and touch events.
*/
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.0-alpha.1",
"version": "0.6.0-alpha.3",
"license": "MIT",
"main": "dist/main.js",
"module": "dist/module.js",
Expand All @@ -14,9 +14,9 @@
"types/**/*"
],
"dependencies": {
"@oasis-engine/math": "0.6.0-alpha.1"
"@oasis-engine/math": "0.6.0-alpha.3"
},
"devDependencies": {
"@oasis-engine/design": "0.6.0-alpha.1"
"@oasis-engine/design": "0.6.0-alpha.3"
}
}
17 changes: 17 additions & 0 deletions packages/core/src/2d/enums/TextAlignment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Text horizontal alignment.
*/
export enum TextHorizontalAlignment {
Left = 0,
Center = 1,
Right = 2
}

/**
* Text vertical alignment.
*/
export enum TextVerticalAlignment {
Top = 0,
Center = 1,
Bottom = 2
}
15 changes: 15 additions & 0 deletions packages/core/src/2d/enums/TextOverflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Text horizontal overflow.
*/
export enum TextHorizontalOverflow {
Overflow = 0,
Wrap = 1
}

/**
* Text vertical overflow.
*/
export enum TextVerticalOverflow {
Overflow = 0,
Truncate = 1
}
3 changes: 3 additions & 0 deletions packages/core/src/2d/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { SpriteMaskInteraction } from "./enums/SpriteMaskInteraction";
export { SpriteMaskLayer } from "./enums/SpriteMaskLayer";
export { TextHorizontalAlignment, TextVerticalAlignment } from "./enums/TextAlignment";
export { TextHorizontalOverflow, TextVerticalOverflow } from "./enums/TextOverflow";
export { SpriteAtlas } from "./atlas/SpriteAtlas";
export * from "./sprite/index";
export * from "./text/index";
249 changes: 249 additions & 0 deletions packages/core/src/2d/text/TextRenderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import { BoundingBox } from "@oasis-engine/math";
import { Camera } from "../../Camera";
import { assignmentClone, ignoreClone } from "../../clone/CloneManager";
import { Entity } from "../../Entity";
import { Texture2D } from "../../texture";
import { TextHorizontalAlignment, TextVerticalAlignment } from "../enums/TextAlignment";
import { TextHorizontalOverflow, TextVerticalOverflow } from "../enums/TextOverflow";
import { Sprite, SpriteRenderer } from "../sprite";
import { TextUtils } from "./TextUtils";

export class TextRenderer extends SpriteRenderer {
@assignmentClone
private _text: string = "";
@assignmentClone
private _width: number = 0;
@assignmentClone
private _height: number = 0;
@assignmentClone
private _fontName: string = "Arial";
@assignmentClone
private _fontSize: number = 24;
@assignmentClone
private _lineHeight: number = 1;
@assignmentClone
private _isBold: boolean = false;
@assignmentClone
private _isItalic: boolean = false;
@assignmentClone
private _horizontalAlignment: TextHorizontalAlignment = TextHorizontalAlignment.Center;
@assignmentClone
private _verticalAlignment: TextVerticalAlignment = TextVerticalAlignment.Center;
@assignmentClone
private _horizontalOverflow: TextHorizontalOverflow = TextHorizontalOverflow.Wrap;
@assignmentClone
private _verticalOverflow: TextVerticalOverflow = TextVerticalOverflow.Truncate;
@ignoreClone
private _styleDirtyFlag: boolean = true;

/**
*
*/
get text(): string {
return this._text;
}

set text(value: string) {
value = value || "";
if (this._text !== value) {
this._text = value;
this._styleDirtyFlag = true;
}
}

get width(): number {
return this._width;
}

set width(value: number) {
if (this._width !== value) {
this._width = value;
this._styleDirtyFlag = true;
}
}

get height(): number {
return this._height;
}

set height(value: number) {
if (this._height !== value) {
this._height = value;
this._styleDirtyFlag = true;
}
}

get fontName(): string {
return this._fontName;
}

set fontName(value: string) {
value = value || "Arial";
if (this._fontName !== value) {
this._fontName = value;
this._styleDirtyFlag = true;
}
}

get fontSize(): number {
return this._fontSize;
}

set fontSize(value: number) {
if (this._fontSize !== value) {
this._fontSize = value;
this._styleDirtyFlag = true;
}
}

get lineHeight(): number {
return this._lineHeight;
}

set lineHeight(value: number) {
if (this._lineHeight !== value) {
this._lineHeight = value;
this._styleDirtyFlag = true;
}
}

get isBold(): boolean {
return this._isBold;
}

set isBold(value: boolean) {
if (this._isBold !== value) {
this._isBold = value;
this._styleDirtyFlag = true;
}
}

get isItalic(): boolean {
return this._isItalic;
}

set isItalic(value: boolean) {
if (this._isItalic !== value) {
this._isItalic = value;
this._styleDirtyFlag = true;
}
}

get horizontalAlignment(): TextHorizontalAlignment {
return this._horizontalAlignment;
}

set horizontalAlignment(value: TextHorizontalAlignment) {
if (this._horizontalAlignment !== value) {
this._horizontalAlignment = value;
this._styleDirtyFlag = true;
}
}

get verticalAlignment(): TextVerticalAlignment {
return this._verticalAlignment;
}

set verticalAlignment(value: TextVerticalAlignment) {
if (this._verticalAlignment !== value) {
this._verticalAlignment = value;
this._styleDirtyFlag = true;
}
}

get horizontalOverflow(): TextHorizontalOverflow {
return this._horizontalOverflow;
}

set horizontalOverflow(value: TextHorizontalOverflow) {
if (this._horizontalOverflow !== value) {
this._horizontalOverflow = value;
this._styleDirtyFlag = true;
}
}

get verticalOverflow(): TextVerticalOverflow {
return this._verticalOverflow;
}

set verticalOverflow(value: TextVerticalOverflow) {
if (this._verticalOverflow !== value) {
this._verticalOverflow = value;
this._styleDirtyFlag = true;
}
}

constructor(entity: Entity) {
super(entity);

// const canvas = this._canvas = document.createElement("canvas");
// this._context = canvas.getContext("2d");
// canvas.width = canvas.height = 1;

this.sprite = new Sprite(this.engine);
}

/**
* @internal
*/
_render(camera: Camera): void {
if (this._styleDirtyFlag) {
this._updateText();
this._styleDirtyFlag = false;
}

super._render(camera);
}

/**
* @override
*/
protected _updateBounds(worldBounds: BoundingBox): void {
const sprite = this.sprite;
if (sprite) {
if (this._customLocalBounds && this._customRootEntity) {
const worldMatrix = this._customRootEntity.transform.worldMatrix;
BoundingBox.transform(this._customLocalBounds, worldMatrix, worldBounds);
} else {
const localBounds = sprite.bounds;
const worldMatrix = this._entity.transform.worldMatrix;
BoundingBox.transform(localBounds, worldMatrix, worldBounds);
}
} else {
worldBounds.min.setValue(0, 0, 0);
worldBounds.max.setValue(0, 0, 0);
}
}

private _getFontString() {
let str = "";
if (this.isBold) {
str += "bold ";
}
if (this.isItalic) {
str += "italic ";
}
str += `${this._fontSize}px ${this._fontName}`;
return str;
}

private _updateText() {
const fontStr = this._getFontString();
TextUtils.measureText(TextUtils.textContext(), this, fontStr);
this._updateTexture();
}

private _updateTexture() {
const textContext = TextUtils.textContext();
const { canvas, context } = textContext;
const trimData = TextUtils.trimCanvas(textContext);
const { width, height } = trimData;
canvas.width = width;
canvas.height = height;
context.putImageData(trimData.data, 0, 0);
const texture = new Texture2D(this.engine, width, height);
texture.setImageSource(canvas);
texture.generateMipmaps();
this.sprite.texture = texture;
}
}
Loading