Skip to content

Commit

Permalink
Merge branch 'main' into dev/1.2
Browse files Browse the repository at this point in the history
* main:
  Fix `PointerEvent` and `BlurEvent` triggered in same frame caused the wrong count of pointers. (#1958)
  Fix element buffer read error (#1950)
  Add extend height for measure text (#1947)
  "v1.1.0-beta.37"
  fix(sort): fix sort error (#1951)

# Conflicts:
#	packages/core/package.json
#	packages/design/package.json
#	packages/draco/package.json
#	packages/galacean/package.json
#	packages/loader/package.json
#	packages/math/package.json
#	packages/physics-lite/package.json
#	packages/physics-physx/package.json
#	packages/rhi-webgl/package.json
#	packages/shader-lab/package.json
  • Loading branch information
GuoLei1990 committed Jan 12, 2024
2 parents f04b98a + 9aba5f8 commit 2e8b172
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 80 deletions.
2 changes: 0 additions & 2 deletions e2e/case/material-blinn-phong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
light1.addComponent(DirectLight);
light2.addComponent(DirectLight);

engine.run();

engine.resourceManager
.load([
{
Expand Down
14 changes: 0 additions & 14 deletions e2e/case/material-pbr-clearcoat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import {
AmbientLight,
AssetType,
BackgroundMode,
Camera,
DirectLight,
GLTFResource,
Logger,
PrimitiveMesh,
SkyBoxMaterial,
Vector3,
WebGLEngine
} from "@galacean/engine";
Expand All @@ -37,14 +34,6 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
cameraNode.transform.lookAt(new Vector3());
const camera = cameraNode.addComponent(Camera);

// Create sky
const sky = background.sky;
const skyMaterial = new SkyBoxMaterial(engine);
background.mode = BackgroundMode.Sky;

sky.material = skyMaterial;
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);

Promise.all([
engine.resourceManager
.load<GLTFResource>("https://gw.alipayobjects.com/os/bmw-prod/16875768-21cf-481f-b05f-454c17866ba0.glb")
Expand All @@ -60,11 +49,8 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
})
.then((ambientLight) => {
scene.ambientLight = ambientLight;
skyMaterial.texture = ambientLight.specularTexture;
skyMaterial.textureDecodeRGBM = true;
})
]).then(() => {
engine.run();
updateForE2E(engine);
const category = "Material";
const name = "material-pbr-clearcoat";
Expand Down
27 changes: 3 additions & 24 deletions e2e/case/material-pbr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
* @title PBR Base
* @category Material
*/
import {
AmbientLight,
AssetType,
BackgroundMode,
Camera,
DirectLight,
GLTFResource,
PrimitiveMesh,
SkyBoxMaterial,
Vector3,
WebGLEngine
} from "@galacean/engine";
import { AmbientLight, AssetType, Camera, DirectLight, GLTFResource, Vector3, WebGLEngine } from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create engine
Expand All @@ -31,23 +20,15 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {

//Create camera
const cameraNode = rootEntity.createChild("camera_node");
cameraNode.transform.position = new Vector3(0.25, 0.25, 1.5);
cameraNode.transform.position = new Vector3(0, 5, 20);
const camera = cameraNode.addComponent(Camera);

// Create sky
const sky = scene.background.sky;
const skyMaterial = new SkyBoxMaterial(engine);
scene.background.mode = BackgroundMode.Sky;
sky.material = skyMaterial;
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);

Promise.all([
engine.resourceManager
.load<GLTFResource>("https://gw.alipayobjects.com/os/bmw-prod/477b0093-7ee8-41af-a0dd-836608a4f130.gltf")
.load<GLTFResource>("https://gw.alipayobjects.com/os/bmw-prod/7c7b887c-05d6-43dd-b354-216e738e81ed.gltf")
.then((gltf) => {
const { defaultSceneRoot } = gltf;
rootEntity.addChild(defaultSceneRoot);
defaultSceneRoot.transform.setScale(100, 100, 100);
}),
engine.resourceManager
.load<AmbientLight>({
Expand All @@ -56,8 +37,6 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
})
.then((ambientLight) => {
scene.ambientLight = ambientLight;
skyMaterial.texture = ambientLight.specularTexture;
skyMaterial.textureDecodeRGBM = true;
})
]).then(() => {
updateForE2E(engine);
Expand Down
17 changes: 0 additions & 17 deletions e2e/case/material-shaderReplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import {
AmbientLight,
AssetType,
BackgroundMode,
Camera,
DirectLight,
GLTFResource,
Logger,
PrimitiveMesh,
Shader,
SkyBoxMaterial,
Texture2D,
WebGLEngine
} from "@galacean/engine";
Expand Down Expand Up @@ -48,15 +45,6 @@ async function main() {
cameraEntity.transform.setPosition(0, 0, 5);
const camera = cameraEntity.addComponent(Camera);

// Create sky
const background = scene.background;
background.mode = BackgroundMode.Sky;

const sky = background.sky;
const skyMaterial = new SkyBoxMaterial(engine);
sky.material = skyMaterial;
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);

engine.resourceManager
.load([
{
Expand All @@ -80,8 +68,6 @@ async function main() {
// Add ambient light
const ambientLight = <AmbientLight>resources[0];
scene.ambientLight = ambientLight;
skyMaterial.texture = ambientLight.specularTexture;
skyMaterial.textureDecodeRGBM = true;

// Add helmet model
const glTFResourceHelmet = <GLTFResource>resources[1];
Expand All @@ -104,9 +90,6 @@ async function main() {
material.shaderData.setTexture("u_UVCheckTexture", uvCheckTexture);
}

// Run engine
engine.run();

camera.setReplacementShader(Shader.find("UVCheckShader"));
updateForE2E(engine);
const category = "Material";
Expand Down
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Material_material-pbr-clearcoat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2e/fixtures/originImage/Material_material-pbr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion e2e/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Cypress.Commands.add("screenshotWithThreshold", (category, name, threshold = 0)
cy.visit(`/mpa/${name}.html`);
const imageName = `${category}_${name}.jpg`;
const filePath = path.join(downloadsFolder, imageName);
cy.get("#screenshot")
cy.get("#screenshot", { timeout: 60000 })
.click({ force: true })
.then(() => {
return new Promise((resolve) => {
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/material.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
describe("Material", () => {
it("PBR", () => {
cy.screenshotWithThreshold("Material", "material-pbr", 0.2);
});

it("PBR Clearcoat", () => {
cy.screenshotWithThreshold("Material", "material-pbr-clearcoat", 0.2);
});

it("PBR", () => {
cy.screenshotWithThreshold("Material", "material-pbr", 0.2);
});

it("Unlit", () => {
cy.screenshotWithThreshold("Material", "material-unlit", 0.2);
});
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/2d/text/TextUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export class TextUtils {
"fangsong"
];

// _heightMultiplier used to measure the height of text, but in miniprogram performance is different from h5.
// so can set _heightMultiplier to adapt miniprogram, the larger the value, the worse the performance.
// _extendHeight used to extend the height of canvas, because in miniprogram performance is different from h5.
/** @internal */
static _heightMultiplier: number = 2;
static _extendHeight: number = 0;
/** These characters are all tall to help calculate the height required for text. */
private static _measureString: string = "|ÉqÅ";
private static _measureBaseline: string = "M";
private static _heightMultiplier: number = 2;
private static _baselineMultiplier: number = 1.4;
private static _fontSizeInfoCache: Record<string, FontSizeInfo> = {};
private static _textContext: TextContext = null;
Expand Down Expand Up @@ -353,8 +353,11 @@ export class TextUtils {
// @todo: Text layout may vary from standard and not support emoji.
const width = Math.max(1, Math.round(context.measureText(measureString).width));
let baseline = Math.ceil(context.measureText(TextUtils._measureBaseline).width);
const height = baseline * TextUtils._heightMultiplier;
let height = baseline * TextUtils._heightMultiplier;
baseline = (TextUtils._baselineMultiplier * baseline) | 0;
const { _extendHeight } = TextUtils;
height += _extendHeight;
baseline += _extendHeight * 0.5;

canvas.width = width;
canvas.height = height;
Expand Down Expand Up @@ -397,6 +400,7 @@ export class TextUtils {

if (top !== -1 && bottom !== -1) {
ascent = baseline - top;
// Baseline belong to descent
descent = bottom - baseline + 1;
size = ascent + descent;
}
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/RenderPipeline/RenderQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export class RenderQueue {
dataA.material._priority - dataB.material._priority || componentA._distanceForSort - componentB._distanceForSort
);
} else {
return componentA._distanceForSort - componentB._distanceForSort;
const distanceDiff = componentA._distanceForSort - componentB._distanceForSort;
if (distanceDiff === 0) {
return componentA.instanceId - componentB.instanceId;
} else {
return distanceDiff;
}
}
}

Expand All @@ -52,7 +57,12 @@ export class RenderQueue {
dataA.material._priority - dataB.material._priority || componentB._distanceForSort - componentA._distanceForSort
);
} else {
return componentB._distanceForSort - componentA._distanceForSort;
const distanceDiff = componentB._distanceForSort - componentA._distanceForSort;
if (distanceDiff === 0) {
return componentA.instanceId - componentB.instanceId;
} else {
return distanceDiff;
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/graphic/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export class Buffer extends GraphicsResource {
this._byteLength = byteLength;
this._platformBuffer = engine._hardwareRenderer.createPlatformBuffer(type, byteLength, bufferUsage, data);
if (readable) {
const buffer = (data.constructor === ArrayBuffer ? data : (<ArrayBufferView>data).buffer).slice(0, byteLength);
const buffer =
data.constructor === ArrayBuffer
? data.slice(0)
: (<ArrayBufferView>data).buffer.slice(
(<ArrayBufferView>data).byteOffset,
(<ArrayBufferView>data).byteOffset + byteLength
);
this._data = new Uint8Array(buffer);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/input/pointer/PointerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class PointerManager implements IInput {
this._pointers.length = 0;
this._downList.length = 0;
this._upList.length = 0;
this._nativeEvents.length = 0;
}
}

Expand Down
11 changes: 6 additions & 5 deletions tests/src/core/ModelMesh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("ModelMesh Test", async function () {
let falsyTangents: Vector4[];
let falsyWeights: Vector4[];
let falsyJoints: Vector4[];
before(async function () {
before(async function () {
engine = await WebGLEngine.create({ canvas: document.createElement("canvas") });
modelMesh = new ModelMesh(engine);
positions = [new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0)];
Expand Down Expand Up @@ -245,9 +245,10 @@ describe("ModelMesh Test", async function () {

it("Read the advanced vertex data of the model set by buffer", () => {
const modelMesh = new ModelMesh(engine);
const arrayBuffer = new ArrayBuffer(40 * 2);
const arrayBuffer = new ArrayBuffer(40 * 2 + 20); // test offset 20
const arrayBufferView = new Uint8Array(arrayBuffer, 20);

const float32Array = new Float32Array(arrayBuffer);
const float32Array = new Float32Array(arrayBuffer, 20);
(float32Array[0] = 1), (float32Array[1] = 2), (float32Array[2] = 3);
(float32Array[3] = 1), (float32Array[4] = 1), (float32Array[5] = 1);
(float32Array[6] = 0.5), (float32Array[7] = 0.5);
Expand All @@ -256,14 +257,14 @@ describe("ModelMesh Test", async function () {
(float32Array[13] = 0), (float32Array[14] = -1), (float32Array[15] = 0);
(float32Array[16] = -0.5), (float32Array[17] = -0.5);

const uint8Array = new Uint8Array(arrayBuffer);
const uint8Array = new Uint8Array(arrayBuffer, 20);
(uint8Array[32] = 1), (uint8Array[33] = 2), (uint8Array[34] = 3), (uint8Array[35] = 4);
(uint8Array[36] = 11), (uint8Array[37] = 12), (uint8Array[38] = 13), (uint8Array[39] = 14);

(uint8Array[72] = 9), (uint8Array[73] = 10), (uint8Array[74] = 11), (uint8Array[75] = 12);
(uint8Array[76] = 29), (uint8Array[77] = 55), (uint8Array[78] = 77), (uint8Array[79] = 88);

const vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, arrayBuffer, BufferUsage.Static, true);
const vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, arrayBufferView, BufferUsage.Static, true);
modelMesh.setVertexBufferBinding(vertexBuffer, 40, 0);
// Test Vector3、Vector2、UByte4、NormalizedUByte4 format
modelMesh.setVertexElements([
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/input/InputManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ describe("InputManager", async () => {
expect(inputManager._wheelManager._hadListener).to.eq(true);
// @ts-ignore
expect(inputManager._keyboardManager._hadListener).to.eq(true);

engine.update();
canvasDOM.dispatchEvent(generatePointerEvent("pointerdown", 1, 1, 1));
canvasDOM.dispatchEvent(generateKeyboardEvent("keydown", "KeyA"));
canvasDOM.dispatchEvent(generateWheelEvent(1, 1, 1));
window.dispatchEvent(new Event("blur"));
engine.update();
expect(inputManager.pointers.length).to.eq(0);
expect(inputManager.isKeyDown()).to.eq(false);
expect(inputManager.wheelDelta).to.deep.eq(new Vector3(0, 0, 0));
});

it("destroy", () => {
Expand Down

0 comments on commit 2e8b172

Please sign in to comment.