Skip to content

Commit

Permalink
Merge branch 'main' into dev/1.0
Browse files Browse the repository at this point in the history
* main:
  Fix `Mesh` change IndexBuffer、VertexBuffer、VertexElements bug( need to update VAO) (#719)
  "v0.9.0-beta.73"
  fix: scene parser error (#1426)
  Fix SpriteRenderer bounding box error (#1425)
  Update README.md
  Update README.md
  "v0.9.0-beta.72"
  "v0.9.0-beta.71"
  Revert "fix: InputManager default listener target" (#1414)
  • Loading branch information
GuoLei1990 committed Mar 30, 2023
2 parents b7ad908 + 9635996 commit 78484d5
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 76 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/2d/sprite/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class Sprite extends ReferResource {
if (this._texture !== value) {
this._texture = value;
this._dispatchSpriteChange(SpriteModifyFlags.texture);
(this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
}
}

Expand Down Expand Up @@ -105,6 +106,7 @@ export class Sprite extends ReferResource {
const y = MathUtil.clamp(value.y, 0, 1);
this._atlasRegion.set(x, y, MathUtil.clamp(value.width, 0, 1 - x), MathUtil.clamp(value.height, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
(this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
}

/**
Expand All @@ -119,6 +121,7 @@ export class Sprite extends ReferResource {
const y = MathUtil.clamp(value.y, 0, 1);
this._atlasRegionOffset.set(x, y, MathUtil.clamp(value.z, 0, 1 - x), MathUtil.clamp(value.w, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
(this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
}

/**
Expand All @@ -134,6 +137,7 @@ export class Sprite extends ReferResource {
const y = MathUtil.clamp(value.y, 0, 1);
region.set(x, y, MathUtil.clamp(value.width, 0, 1 - x), MathUtil.clamp(value.height, 0, 1 - y));
this._dispatchSpriteChange(SpriteModifyFlags.region);
(this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
}

/**
Expand Down Expand Up @@ -251,11 +255,11 @@ export class Sprite extends ReferResource {
if (this._texture) {
const { _texture, _atlasRegion, _atlasRegionOffset, _region } = this;
const pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
this.width =
this._width =
((_texture.width * _atlasRegion.width) / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z)) *
_region.width *
pixelsPerUnitReciprocal;
this.height =
this._height =
((_texture.height * _atlasRegion.height) / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w)) *
_region.height *
pixelsPerUnitReciprocal;
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/2d/sprite/SpriteRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ export class SpriteRenderer extends Renderer implements ICustomClone {
* Render width.
*/
get width(): number {
if (this._width === undefined && this._sprite) {
this.width = this._sprite.width;
}
this._width === undefined && this._sprite && (this.width = this._sprite.width);
return this._width;
}

set width(value: number) {
// Update width if undefined
this._width === undefined && this._sprite && (this._width = this._sprite.width);
if (this._width !== value) {
this._width = value;
this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
Expand All @@ -175,13 +175,13 @@ export class SpriteRenderer extends Renderer implements ICustomClone {
* Render height.
*/
get height(): number {
if (this._height === undefined && this._sprite) {
this.height = this._sprite.height;
}
this._height === undefined && this._sprite && (this.height = this._sprite.height);
return this._height;
}

set height(value: number) {
// Update height if undefined
this._height === undefined && this._sprite && (this._height = this._sprite.height);
if (this._height !== value) {
this._height = value;
this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
Expand Down Expand Up @@ -351,10 +351,17 @@ export class SpriteRenderer extends Renderer implements ICustomClone {
this.shaderData.setTexture(SpriteRenderer._textureProperty, this.sprite.texture);
break;
case SpriteModifyFlags.size:
if (this._drawMode === SpriteDrawMode.Sliced) {
const { _drawMode: drawMode } = this;
if (drawMode === SpriteDrawMode.Sliced) {
this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
} else if (this._drawMode === SpriteDrawMode.Tiled) {
} else if (drawMode === SpriteDrawMode.Tiled) {
this._dirtyUpdateFlag |= SpriteRendererUpdateFlags.All;
} else {
// When the width and height of `SpriteRenderer` are `undefined`,
// the `size` of `Sprite` will affect the position of `SpriteRenderer`.
if (this._width === undefined || this._height === undefined) {
this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
}
}
break;
case SpriteModifyFlags.border:
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/graphic/Mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export abstract class Mesh extends GraphicsResource {
/** @internal */
_glIndexByteCount: number;
/** @internal */
_bufferStructChanged: boolean;
/** @internal */
_platformPrimitive: IPlatformPrimitive;

/** @internal */
Expand Down Expand Up @@ -183,6 +185,7 @@ export abstract class Mesh extends GraphicsResource {
*/
_draw(shaderProgram: ShaderProgram, subMesh: SubMesh): void {
this._platformPrimitive.draw(shaderProgram, subMesh);
this._bufferStructChanged = false;
}

/**
Expand Down Expand Up @@ -221,16 +224,20 @@ export abstract class Mesh extends GraphicsResource {
for (let i = 0, n = elements.length; i < n; i++) {
this._addVertexElement(elements[i]);
}
this._bufferStructChanged = true;
}

protected _setIndexBufferBinding(binding: IndexBufferBinding | null): void {
const lastBinding = this._indexBufferBinding;
if (binding) {
this._indexBufferBinding = binding;
this._glIndexType = BufferUtil._getGLIndexType(binding.format);
this._glIndexByteCount = BufferUtil._getGLIndexByteCount(binding.format);
(!lastBinding || lastBinding._buffer !== binding._buffer) && (this._bufferStructChanged = true);
} else {
this._indexBufferBinding = null;
this._glIndexType = undefined;
lastBinding && (this._bufferStructChanged = true);
}
}

Expand Down
11 changes: 0 additions & 11 deletions packages/core/src/input/keyboard/KeyboardManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ export class KeyboardManager implements IInput {
}
curFrameUpList.add(codeKey);
upKeyToFrameCountMap[codeKey] = frameCount;
// @todo
// Because on the mac, the keyup event is not responded to when the meta key is held down,
// in order to maintain the correct keystroke record, it is necessary to clear the record
// when the meta key is lifted.
// link: https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser
// if (codeKey === Keys.MetaLeft || codeKey === Keys.MetaRight) {
// for (let i = 0, len = curFrameHeldDownList.length; i < len; i++) {
// curHeldDownKeyToIndexMap[curFrameHeldDownList.get(i)] = null;
// }
// curFrameHeldDownList.length = 0;
// }
break;
default:
break;
Expand Down
28 changes: 14 additions & 14 deletions packages/core/src/input/pointer/PointerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export class PointerManager implements IInput {
if (!this._hadListener) {
const { _htmlCanvas: htmlCanvas, _onPointerEvent: onPointerEvent } = this;
htmlCanvas.addEventListener("pointerdown", onPointerEvent);
document.addEventListener("pointermove", onPointerEvent);
document.addEventListener("pointerup", onPointerEvent);
document.addEventListener("pointerleave", onPointerEvent);
document.addEventListener("pointercancel", onPointerEvent);
htmlCanvas.addEventListener("pointerup", onPointerEvent);
htmlCanvas.addEventListener("pointerout", onPointerEvent);
htmlCanvas.addEventListener("pointermove", onPointerEvent);
htmlCanvas.addEventListener("pointercancel", onPointerEvent);
this._hadListener = true;
}
}
Expand All @@ -130,10 +130,10 @@ export class PointerManager implements IInput {
if (this._hadListener) {
const { _htmlCanvas: htmlCanvas, _onPointerEvent: onPointerEvent } = this;
htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
document.removeEventListener("pointermove", onPointerEvent);
document.removeEventListener("pointerup", onPointerEvent);
document.removeEventListener("pointerleave", onPointerEvent);
document.removeEventListener("pointercancel", onPointerEvent);
htmlCanvas.removeEventListener("pointerup", onPointerEvent);
htmlCanvas.removeEventListener("pointerout", onPointerEvent);
htmlCanvas.removeEventListener("pointermove", onPointerEvent);
htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
this._hadListener = false;
this._downList.length = 0;
this._upList.length = 0;
Expand All @@ -153,10 +153,10 @@ export class PointerManager implements IInput {
if (this._hadListener) {
const { _htmlCanvas: htmlCanvas, _onPointerEvent: onPointerEvent } = this;
htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
document.removeEventListener("pointermove", onPointerEvent);
document.removeEventListener("pointerup", onPointerEvent);
document.removeEventListener("pointerleave", onPointerEvent);
document.removeEventListener("pointercancel", onPointerEvent);
htmlCanvas.removeEventListener("pointerup", onPointerEvent);
htmlCanvas.removeEventListener("pointerout", onPointerEvent);
htmlCanvas.removeEventListener("pointermove", onPointerEvent);
htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
this._hadListener = false;
}
this._pointerPool.length = 0;
Expand Down Expand Up @@ -290,7 +290,7 @@ export class PointerManager implements IInput {
pointer.phase = PointerPhase.Up;
pointer._firePointerUpAndClick(rayCastEntity);
break;
case "pointerleave":
case "pointerout":
case "pointercancel":
pointer.phase = PointerPhase.Leave;
pointer._firePointerExitAndEnter(null);
Expand Down Expand Up @@ -348,7 +348,7 @@ export class PointerManager implements IInput {
case "pointermove":
pointer.phase = PointerPhase.Move;
break;
case "pointerleave":
case "pointerout":
case "pointercancel":
pointer.phase = PointerPhase.Leave;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class SceneParser {
}
}

private _parseComponents() {
private _parseComponents(): Promise<any[]> {
const entitiesConfig = this.context.originalData.entities;
const entityMap = this.context.entityMap;

Expand All @@ -103,6 +103,7 @@ export class SceneParser {
promises.push(promise);
}
}
return Promise.all(promises);
}

private _clearAndResolveScene() {
Expand Down
Loading

0 comments on commit 78484d5

Please sign in to comment.