Skip to content

Commit

Permalink
Merge branch 'dev/1.4' of https://github.com/galacean/engine into fea…
Browse files Browse the repository at this point in the history
…t/editor_module
  • Loading branch information
Sway007 committed Nov 12, 2024
2 parents 2b911ee + 14027ac commit 5badefe
Show file tree
Hide file tree
Showing 74 changed files with 742 additions and 300 deletions.
43 changes: 43 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Note: Require install git-lfs
We use [git-lfs](https://git-lfs.com/) (Install by official website) to manage baseline images for e2e tests, so it's necessary to install it, ignore if already installed.
### 1. Create a case page in the e2e/case directory
You can refer to e2e/case/animator-play.ts.
### 2. Configure your e2e test in e2e/config.ts
The threshold is color difference threshold (from 0 to 1). Less more precise.
### 3. Debug your test cases:
#### Launch the Case page:

```
npm run e2e:case
```

After successfully launching the case page, run:

```
git lfs pull
```
Pull image from github, then run

```
npm run e2e:debug
```

Open the Cypress client for debugging.
Cypress will capture screenshots of your case pages.
Review the screenshots in e2e/downloads folder, store them in the e2e/fixtures/originImage directory if there are no issues, then rerun the test cases. If the test cases pass, the debugging is complete.

### 4. Run the complete e2e tests:
```
npm run e2e
```
Note: The e2e testing framework for this project is Cypress. For detailed usage instructions, please refer to https://www.cypress.io/.


### Add new e2e case

1. modify `config.ts` based on the new test case.
2. run `npm run e2e:debug`

the new image of test case for comparison will be present under directory `e2e/downloads`, you need to copy it into directory `e2e/fixtures/originImage`.


29 changes: 29 additions & 0 deletions e2e/case/project-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @title Project loader
* @category Advance
*/
import { Logger, WebGLEngine, AssetType, Camera } from "@galacean/engine";
import { ShaderLab } from "@galacean/engine-shader-lab";
import { registerIncludes } from "@galacean/engine-toolkit";
import { initScreenshot, updateForE2E } from './.mockForE2E';

// Create ShaderLab
const shaderLab = new ShaderLab();
registerIncludes();

Logger.enable();
WebGLEngine.create({ canvas: "canvas", shaderLab }).then( (engine) => {
engine.canvas.resizeByClientSize(2);
engine.resourceManager
.load({
type: AssetType.Project,
url: "https://mdn.alipayobjects.com/oasis_be/afts/file/A*o15SSopTBh0AAAAAAAAAAAAADkp5AQ/project.json"
}).then(() => {
updateForE2E(engine);

const cameraEntity =
engine.sceneManager.activeScene.findEntityByName('Camera');
const camera = cameraEntity.getComponent(Camera)
initScreenshot(engine, camera)
})
});
9 changes: 8 additions & 1 deletion e2e/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,12 @@ export const E2E_CONFIG = {
caseFileName: "text-typed",
threshold: 0.4
}
}
},
Other: {
ProjectLoader: {
category: "Advance",
caseFileName: "project-loader",
threshold: 0.4
}
},
};
3 changes: 3 additions & 0 deletions e2e/fixtures/originImage/Advance_project-loader.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/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@galacean/engine-e2e",
"private": true,
"version": "1.3.15",
"version": "1.3.20",
"license": "MIT",
"scripts": {
"case": "vite serve .dev --config .dev/vite.config.js",
"b:types": "echo hi"
},
"files": [],
"dependencies": {
"@galacean/engine-toolkit": "^1.0.0-beta.1",
"@galacean/engine-toolkit": "^1.3.9",
"@galacean/engine-shader-lab": "workspace:*",
"@galacean/engine": "workspace:*",
"@galacean/engine-core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-root",
"version": "1.3.15",
"version": "1.3.20",
"packageManager": "pnpm@9.3.0",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-core",
"version": "1.3.15",
"version": "1.3.20",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/Background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color, Vector2, Vector3 } from "@galacean/engine-math";
import { CompareFunction, Material, ModelMesh, Shader } from ".";
import { CompareFunction, ContentRestorer, Material, ModelMesh, Shader } from ".";
import { Engine } from "./Engine";
import { BackgroundMode } from "./enums/BackgroundMode";
import { BackgroundTextureFillMode } from "./enums/BackgroundTextureFillMode";
Expand Down Expand Up @@ -134,7 +134,20 @@ export class Background {
}

private _initMesh(engine: Engine): void {
this._mesh = this._createPlane(engine);
const mesh = (this._mesh = this._createPlane(engine));
engine.resourceManager.addContentRestorer(
new (class extends ContentRestorer<ModelMesh> {
constructor() {
super(mesh);
}
restoreContent() {
mesh.setPositions(mesh.getPositions());
mesh.setUVs(mesh.getUVs());
mesh.setIndices(mesh.getIndices());
mesh.uploadData(false);
}
})()
);
this._mesh._addReferCount(1);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,19 @@ export class BasicResources {
const mesh = new ModelMesh(engine);
mesh._addReferCount(1);
mesh.setVertexElements([new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)]);
mesh.setVertexBufferBinding(new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static), 16);
const buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
mesh.setVertexBufferBinding(buffer, 16);
mesh.addSubMesh(0, 3, MeshTopology.Triangles);
engine.resourceManager.addContentRestorer(
new (class extends ContentRestorer<ModelMesh> {
constructor() {
super(mesh);
}
restoreContent() {
buffer.setData(buffer.data);
}
})()
);
return mesh;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export class Utils {
return relativeUrl;
}

if (!/^https?:/.test(baseUrl)) {
const fileSchema = "files://";
baseUrl = fileSchema + baseUrl;
return new URL(relativeUrl, baseUrl).href.substring(fileSchema.length);
}

return relativeUrl ? new URL(relativeUrl, baseUrl).href : baseUrl;
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/asset/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ export abstract class Loader<T> {
constructor(public readonly useCache: boolean) {}
initialize?(engine: Engine, configuration: EngineConfiguration): Promise<void>;
abstract load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<T>;
request: <U>(url: string, config: RequestConfig) => AssetPromise<U> = request;
}
Loading

0 comments on commit 5badefe

Please sign in to comment.