Skip to content

Commit

Permalink
Merge branch 'main' into pr/merge-latest-main
Browse files Browse the repository at this point in the history
* main:
  fix(text): fix horizontal and vertical alignment error (galacean#772)
  v0.7.0-beta.6
  fix: fixed the bug of animator revert when blendWeight length exceeds 4 (galacean#817)
  v0.7.0-beta.5
  Improve BlendShape when use attribute mode (galacean#804)
  fix(Renderer): destroy crash when material is null (galacean#808)
  Add component denpendent decorator (galacean#796) (galacean#807)
  Update README.md
  Update README.md
  Update README.md

# Conflicts:
#	packages/controls/package.json
#	packages/core/src/2d/sprite/Sprite.ts
#	packages/core/src/Renderer.ts
#	packages/framebuffer-picker/package.json
#	packages/stats/package.json
  • Loading branch information
GuoLei1990 committed Jun 7, 2022
2 parents 9889b3f + 2f50271 commit 03aba54
Show file tree
Hide file tree
Showing 21 changed files with 591 additions and 390 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
![npm-download](https://img.shields.io/npm/dm/oasis-engine)
[![codecov](https://codecov.io/gh/oasis-engine/engine/branch/main/graph/badge.svg?token=KR2UBKE3OX)](https://codecov.io/gh/oasis-engine/engine)

This is a **web-first** and **mobile-first** high-performance real-time development platform. Use **component system design** and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code.
This is a **web-first** and **mobile-first** high-performance real-time interactive engine. Use **component system design** and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code.

## Features

- 🖥  **Platform** - Suppport HTML5 and Alipay miniprogram
- 🔮  **Graphics** - Advanced 2D + 3D graphics engine
- 🏃  **Animation** - Powerful animation system
- 🧱  **Physics** - Powerful and easy-to-use physical features
- 📑  **Scripts** - Use TypeScript to write logic efficiently

## Usage
Expand Down
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.7.0-beta.4",
"version": "0.7.0-beta.6",
"bootstrap": {
"hoist": true
},
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.7.0-beta.4",
"version": "0.7.0-beta.6",
"license": "MIT",
"main": "dist/main.js",
"module": "dist/module.js",
Expand All @@ -14,9 +14,9 @@
"types/**/*"
],
"dependencies": {
"@oasis-engine/math": "0.7.0-beta.4"
"@oasis-engine/math": "0.7.0-beta.6"
},
"devDependencies": {
"@oasis-engine/design": "0.7.0-beta.4"
"@oasis-engine/design": "0.7.0-beta.6"
}
}
5 changes: 3 additions & 2 deletions packages/core/src/2d/sprite/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ export class Sprite extends RefObject {

set pivot(value: Vector2) {
const pivot = this._pivot;
if (pivot === value || pivot.x !== value.x || pivot.y !== value.y) {
pivot.setValue(value.x, value.y);
const { x, y } = value;
if (pivot === value || pivot.x !== x || pivot.y !== y) {
pivot.setValue(x, y);
this._setDirtyFlagTrue(DirtyFlag.positions);
}
}
Expand Down
46 changes: 33 additions & 13 deletions packages/core/src/2d/text/TextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,12 @@ export class TextRenderer extends Renderer {
* @override
*/
protected _updateBounds(worldBounds: BoundingBox): void {
const sprite = this._sprite;
if (sprite && sprite.texture) {
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);
}
if (this._customLocalBounds && this._customRootEntity) {
const worldMatrix = this._customRootEntity.transform.worldMatrix;
BoundingBox.transform(this._customLocalBounds, worldMatrix, worldBounds);
} else {
worldBounds.min.setValue(0, 0, 0);
worldBounds.max.setValue(0, 0, 0);
const worldMatrix = this._entity.transform.worldMatrix;
BoundingBox.transform(this._sprite.bounds, worldMatrix, worldBounds);
}
}

Expand Down Expand Up @@ -378,7 +371,34 @@ export class TextRenderer extends Renderer {
const { width, height } = trimData;
const canvas = TextUtils.updateCanvas(width, height, trimData.data);
this._clearTexture();
const { _sprite: sprite } = this;
const { _sprite: sprite, horizontalAlignment, verticalAlignment } = this;

// Handle the case that width or height of text is larger than real width or height.
const { pixelsPerUnit, pivot } = sprite;
switch (horizontalAlignment) {
case TextHorizontalAlignment.Left:
pivot.x = (this.width * pixelsPerUnit) / width * 0.5;
break;
case TextHorizontalAlignment.Right:
pivot.x = 1 - (this.width * pixelsPerUnit) / width * 0.5;
break;
case TextHorizontalAlignment.Center:
pivot.x = 0.5;
break;
}
switch (verticalAlignment) {
case TextVerticalAlignment.Top:
pivot.y = 1 - (this.height * pixelsPerUnit) / height * 0.5;
break;
case TextVerticalAlignment.Bottom:
pivot.y = (this.height * pixelsPerUnit) / height * 0.5;
break;
case TextVerticalAlignment.Center:
pivot.y = 0.5;
break;
}
sprite.pivot = pivot;

// If add fail, set texture for sprite.
if (!this.engine._dynamicTextAtlasManager.addSprite(sprite, canvas)) {
const texture = new Texture2D(this.engine, width, height);
Expand Down
44 changes: 23 additions & 21 deletions packages/core/src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ShaderMacroCollection } from "./shader/ShaderMacroCollection";
import { Transform } from "./Transform";

/**
* Renderable component.
* Basis for all renderers.
* @decorator `@dependentComponents(Transform)`
*/
@dependentComponents(Transform)
Expand Down Expand Up @@ -177,26 +177,10 @@ export class Renderer extends Component {
setMaterial(index: number, material: Material): void;

setMaterial(indexOrMaterial: number | Material, material: Material = null): void {
let index;
if (typeof indexOrMaterial === "number") {
index = indexOrMaterial;
this._setMaterial(indexOrMaterial, material);
} else {
index = 0;
material = indexOrMaterial;
}

const materials = this._materials;
if (index >= materials.length) {
materials.length = index + 1;
}

const materialsInstance = this._materialsInstanced;
const internalMaterial = materials[index];
if (internalMaterial !== material) {
materials[index] = material;
index < materialsInstance.length && (materialsInstance[index] = false);
internalMaterial && internalMaterial._addRefCount(-1);
material && material._addRefCount(1);
this._setMaterial(0, indexOrMaterial);
}
}

Expand Down Expand Up @@ -314,8 +298,9 @@ export class Renderer extends Component {

this.shaderData._addRefCount(-1);

for (let i = 0, n = this._materials.length; i < n; i++) {
this._materials[i]._addRefCount(-1);
const materials = this._materials;
for (let i = 0, n = materials.length; i < n; i++) {
materials[i]?._addRefCount(-1);
}
}

Expand All @@ -330,4 +315,21 @@ export class Renderer extends Component {
this._materials[index] = insMaterial;
return insMaterial;
}

private _setMaterial(index: number, material: Material): void {
const materials = this._materials;
if (index >= materials.length) {
materials.length = index + 1;
}

const internalMaterial = materials[index];
if (internalMaterial !== material) {
const materialsInstance = this._materialsInstanced;
index < materialsInstance.length && (materialsInstance[index] = false);

internalMaterial && internalMaterial._addRefCount(-1);
material && material._addRefCount(1);
materials[index] = material;
}
}
}
9 changes: 5 additions & 4 deletions packages/core/src/animation/internal/AnimationCurveOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AnimationCurveOwner {
readonly component: Component;
readonly defaultValue: InterpolableValue;
readonly fixedPoseValue: InterpolableValue;

/** @internal */
_hasSavedDefaultValue: boolean = false;

Expand All @@ -43,9 +43,10 @@ export class AnimationCurveOwner {
this.component = target.transform;
break;
case AnimationProperty.BlendShapeWeights:
this.defaultValue = new Float32Array(4);
this.fixedPoseValue = new Float32Array(4);
this.component = target.getComponent(SkinnedMeshRenderer);
const weightLength = (<SkinnedMeshRenderer>this.component).blendShapeWeights.length;
this.defaultValue = new Float32Array(weightLength);
this.fixedPoseValue = new Float32Array(weightLength);
break;
}
}
Expand All @@ -64,7 +65,7 @@ export class AnimationCurveOwner {
case AnimationProperty.BlendShapeWeights:
const { blendShapeWeights } = <SkinnedMeshRenderer>this.component;
for (let i = 0, length = blendShapeWeights.length; i < length; ++i) {
this.defaultValue[i] = (<SkinnedMeshRenderer>this.component).blendShapeWeights[i];
this.defaultValue[i] = blendShapeWeights[i];
}
break;
}
Expand Down
23 changes: 14 additions & 9 deletions packages/core/src/graphic/Mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export abstract class Mesh extends RefObject {
_indexBufferBinding: IndexBufferBinding = null;
/** @internal */
_vertexElements: VertexElement[] = [];
/** @internal */
_enableVAO: boolean = true;

private _subMeshes: SubMesh[] = [];
private _updateFlagManager: UpdateFlagManager = new UpdateFlagManager();
Expand Down Expand Up @@ -139,6 +141,18 @@ export abstract class Mesh extends RefObject {
this._updateFlagManager.dispatch();
}

/**
* @internal
*/
_setVertexBufferBinding(index: number, binding: VertexBufferBinding): void {
if (this._getRefCount() > 0) {
const lastBinding = this._vertexBufferBindings[index];
lastBinding && lastBinding._buffer._addRefCount(-1);
binding._buffer._addRefCount(1);
}
this._vertexBufferBindings[index] = binding;
}

/**
* @internal
*/
Expand Down Expand Up @@ -176,15 +190,6 @@ export abstract class Mesh extends RefObject {
}
}

protected _setVertexBufferBinding(index: number, binding: VertexBufferBinding): void {
if (this._getRefCount() > 0) {
const lastBinding = this._vertexBufferBindings[index];
lastBinding && lastBinding._buffer._addRefCount(-1);
binding._buffer._addRefCount(1);
}
this._vertexBufferBindings[index] = binding;
}

protected _setIndexBufferBinding(binding: IndexBufferBinding | null): void {
if (binding) {
this._indexBufferBinding = binding;
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/graphic/VertexElement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BufferUtil, ElementInfo } from "./BufferUtil";
import { VertexElementFormat } from "./enums/VertexElementFormat";
import { ElementInfo, BufferUtil } from "./BufferUtil";

/**
* Vertex element.
Expand Down Expand Up @@ -27,6 +27,10 @@ export class VertexElement {
return this._offset;
}

set offset(value: number) {
this._offset = value;
}

/**
* Vertex data format.
*/
Expand All @@ -41,6 +45,10 @@ export class VertexElement {
return this._bindingIndex;
}

set bindingIndex(value: number) {
this._bindingIndex = value;
}

/**
* Instance cadence, the number of instances drawn for each vertex in the buffer, non-instance elements must be 0.
*/
Expand Down
Loading

0 comments on commit 03aba54

Please sign in to comment.