Skip to content

Commit d233eef

Browse files
committed
Merge branch 'main' into dev/1.2
* main: fix: material destroy bug (#1864) Fix asset promise (#1867) Set `SpriteMask.sprite` to null after destroying the sprite. (#1866) "v1.1.0-beta.19" Add recursive class and methods (#1865) Fix url clamp bug (#1860) feat: add recursive object parse (#1863) Fix ShaderLab compatible with no varying variable (#1859) Fix ShaderLab umd package compilation and circle reference (#1856) Add unit test case of `ColliderShape` (#1740)
2 parents bb12e4e + c8cad90 commit d233eef

30 files changed

+444
-99
lines changed

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-core",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/core/src/2d/sprite/SpriteMask.ts

+3
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ export class SpriteMask extends Renderer {
276276
case SpriteModifyFlags.pivot:
277277
this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
278278
break;
279+
case SpriteModifyFlags.destroy:
280+
this.sprite = null;
281+
break;
279282
default:
280283
break;
281284
}

packages/core/src/asset/AssetPromise.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class AssetPromise<T> implements PromiseLike<T> {
5252

5353
private _promise: Promise<T>;
5454
private _state = PromiseState.Pending;
55+
private _progress = 0;
5556
private _onProgressCallback: Array<(progress: number) => void> = [];
5657
private _onCancelHandler: () => void;
5758
private _reject: (reason: any) => void;
@@ -87,6 +88,7 @@ export class AssetPromise<T> implements PromiseLike<T> {
8788
};
8889
const setProgress = (progress: number) => {
8990
if (this._state === PromiseState.Pending) {
91+
this._progress = progress;
9092
this._onProgressCallback.forEach((callback) => callback(progress));
9193
}
9294
};
@@ -101,7 +103,12 @@ export class AssetPromise<T> implements PromiseLike<T> {
101103
* @returns AssetPromise
102104
*/
103105
onProgress(callback: (progress: number) => void): AssetPromise<T> {
104-
this._onProgressCallback.push(callback);
106+
if (this._progress) {
107+
callback(this._progress);
108+
}
109+
if (this._state === PromiseState.Pending) {
110+
this._onProgressCallback.push(callback);
111+
}
105112
return this;
106113
}
107114

packages/core/src/asset/ResourceManager.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ export class ResourceManager {
322322
// Check cache
323323
const cacheObject = this._assetUrlPool[assetBaseURL];
324324
if (cacheObject) {
325-
return new AssetPromise((resolve) => {
325+
return new AssetPromise((resolve, _, setProgress) => {
326+
setProgress(1);
326327
resolve(this._getResolveResource(cacheObject, paths) as T);
327328
});
328329
}
@@ -342,8 +343,11 @@ export class ResourceManager {
342343
const loadingPromises = this._loadingPromises;
343344
const loadingPromise = loadingPromises[assetURL];
344345
if (loadingPromise) {
345-
return new AssetPromise((resolve, reject) => {
346+
return new AssetPromise((resolve, reject, setProgress) => {
346347
loadingPromise
348+
.onProgress((v) => {
349+
setProgress(v);
350+
})
347351
.then((resource: EngineObject) => {
348352
resolve(resource as T);
349353
})
@@ -426,21 +430,12 @@ export class ResourceManager {
426430
}
427431

428432
private _parseURL(path: string): { assetBaseURL: string; queryPath: string } {
429-
let assetBaseURL = path;
430-
const index = assetBaseURL.indexOf("?");
431-
if (index !== -1) {
432-
assetBaseURL = assetBaseURL.slice(0, index);
433-
}
434-
return { assetBaseURL, queryPath: this._getParameterByName("q", path) };
435-
}
436-
437-
private _getParameterByName(name, url = window.location.href) {
438-
name = name.replace(/[\[\]]/g, "\\$&");
439-
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
440-
results = regex.exec(url);
441-
if (!results) return null;
442-
if (!results[2]) return "";
443-
return decodeURIComponent(results[2].replace(/\+/g, " "));
433+
const [baseUrl, searchStr] = path.split("?");
434+
const searchParams = new URLSearchParams(searchStr);
435+
const queryPath = searchParams.get("q");
436+
searchParams.delete("q");
437+
const assetBaseURL = searchParams.size > 0 ? baseUrl + "?" + searchParams.toString() : baseUrl;
438+
return { assetBaseURL, queryPath };
444439
}
445440

446441
private _parseQueryPath(string): string[] {

packages/core/src/mesh/MeshRenderer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export class MeshRenderer extends Renderer {
8888
Logger.error("mesh is null.");
8989
return;
9090
}
91+
if (this._mesh.destroyed) {
92+
Logger.error("mesh is destroyed.");
93+
return;
94+
}
9195
super._prepareRender(context);
9296
}
9397

packages/core/src/shader/ShaderProgram.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,11 @@ export class ShaderProgram {
380380
case gl.BOOL_VEC3:
381381
case gl.INT_VEC3:
382382
if (isArray) {
383+
shaderUniform.applyFunc = shaderUniform.upload3iv;
383384
} else {
385+
shaderUniform.applyFunc = shaderUniform.upload3i;
386+
shaderUniform.cacheValue = new Vector3(0, 0, 0);
384387
}
385-
shaderUniform.applyFunc = isArray ? shaderUniform.upload3iv : shaderUniform.upload3i;
386-
shaderUniform.cacheValue = new Vector3(0, 0, 0);
387388
break;
388389
case gl.BOOL_VEC4:
389390
case gl.INT_VEC4:

packages/core/src/sky/Sky.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ export class Sky {
6464
Logger.warn("The material of sky is not defined.");
6565
return;
6666
}
67+
68+
if (material.destroyed) {
69+
Logger.warn("The material of sky is destroyed.");
70+
return;
71+
}
72+
6773
if (!mesh) {
6874
Logger.warn("The mesh of sky is not defined.");
6975
return;
7076
}
7177

72-
const { engine, aspectRatio, fieldOfView, viewMatrix, shaderData: cameraShaderData } = context.camera;
73-
const sceneData = context.camera.scene.shaderData;
78+
if (mesh.destroyed) {
79+
Logger.warn("The mesh of sky is destroyed.");
80+
return;
81+
}
82+
83+
const { engine, scene, aspectRatio, fieldOfView, viewMatrix, shaderData: cameraShaderData } = context.camera;
84+
const sceneData = scene.shaderData;
85+
7486
const { _viewProjMatrix: viewProjMatrix, _projectionMatrix: projectionMatrix } = Sky;
7587
const rhi = engine._hardwareRenderer;
7688
const { shaderData: materialShaderData, shader, renderState } = material;

packages/design/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-design",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/draco/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-draco",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/galacean/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/loader/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-loader",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts

+26-12
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export class ReflectionParser {
2525
parseClassObject(item: IClassObject) {
2626
const Class = Loader.getClass(item.class);
2727
const params = item.constructParams ?? [];
28-
const instance = new Class(...params);
29-
return this.parsePropsAndMethods(instance, item);
28+
return Promise.all(params.map((param) => this.parseBasicType(param)))
29+
.then((resultParams) => new Class(...resultParams))
30+
.then((instance) => this.parsePropsAndMethods(instance, item));
3031
}
3132

3233
parsePropsAndMethods(instance: any, item: Omit<IClassObject, "class">) {
@@ -35,17 +36,15 @@ export class ReflectionParser {
3536
for (let methodName in item.methods) {
3637
const methodParams = item.methods[methodName];
3738
for (let i = 0, count = methodParams.length; i < count; i++) {
38-
const params = methodParams[i];
39-
const promise = this.parseMethod(instance, methodName, params);
40-
promises.push(promise);
39+
promises.push(this.parseMethod(instance, methodName, methodParams[i]));
4140
}
4241
}
4342
}
4443

4544
if (item.props) {
4645
for (let key in item.props) {
4746
const value = item.props[key];
48-
const promise = this.parseBasicType(value).then((v) => {
47+
const promise = this.parseBasicType(value, instance[key]).then((v) => {
4948
return (instance[key] = v);
5049
});
5150
promises.push(promise);
@@ -65,7 +64,7 @@ export class ReflectionParser {
6564
});
6665
}
6766

68-
parseBasicType(value: IBasicType): Promise<any> {
67+
parseBasicType(value: IBasicType, originValue?: any): Promise<any> {
6968
if (Array.isArray(value)) {
7069
return Promise.all(value.map((item) => this.parseBasicType(item)));
7170
} else if (typeof value === "object" && value != null) {
@@ -79,13 +78,28 @@ export class ReflectionParser {
7978
} else if (ReflectionParser._isEntityRef(value)) {
8079
// entity reference
8180
return Promise.resolve(this._context.entityMap.get(value.entityId));
82-
} else {
83-
// basic type
84-
return Promise.resolve(value);
81+
} else if (originValue) {
82+
const promises: Promise<any>[] = [];
83+
for (let key in value as any) {
84+
if (key === "methods") {
85+
const methods: any = value[key];
86+
for (let methodName in methods) {
87+
const methodParams = methods[methodName];
88+
for (let i = 0, count = methodParams.length; i < count; i++) {
89+
const params = methodParams[i];
90+
const promise = this.parseMethod(originValue, methodName, params);
91+
promises.push(promise);
92+
}
93+
}
94+
} else {
95+
promises.push(this.parseBasicType(value[key], originValue[key]).then((v) => (originValue[key] = v)));
96+
}
97+
}
98+
return Promise.all(promises).then(() => originValue);
8599
}
86-
} else {
87-
return Promise.resolve(value);
88100
}
101+
// primitive type
102+
return Promise.resolve(value);
89103
}
90104

91105
private _getEntityByConfig(entityConfig: IEntity) {

packages/math/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-math",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/physics-lite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-physics-lite",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/physics-physx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-physics-physx",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/rhi-webgl/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-rhi-webgl",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/shader-lab/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@galacean/engine-shader-lab",
3-
"version": "1.1.0-beta.18",
3+
"version": "1.1.0-beta.19",
44
"publishConfig": {
55
"access": "public",
66
"registry": "https://registry.npmjs.org"

packages/shader-lab/src/Ast2GLSLUtils.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@ export class Ast2GLSLUtils {
2424

2525
// parse varying variables
2626
const varyingStructAstNode = context.findGlobal(vertFnAst.content.returnType.content.text)?.ast as StructAstNode;
27-
if (!varyingStructAstNode) {
28-
context.diagnostics.push({
29-
severity: DiagnosticSeverity.Error,
30-
message: "no varying struct definition",
31-
token: vertFnAst.content.returnType.position
32-
});
33-
return "";
27+
if (varyingStructAstNode) {
28+
context.varyingStructInfo.structAstNode = varyingStructAstNode;
29+
context.varyingStructInfo.reference = varyingStructAstNode.content.variables.map((v) => ({
30+
referenced: false,
31+
property: v,
32+
text: `varying ${v.content.type.serialize(context)} ${v.content.variableNode.serialize(context)}`
33+
}));
3434
}
35-
context.varyingStructInfo.structAstNode = varyingStructAstNode;
36-
context.varyingStructInfo.reference = varyingStructAstNode.content.variables.map((v) => ({
37-
referenced: false,
38-
property: v,
39-
text: `varying ${v.content.type.serialize(context)} ${v.content.variableNode.serialize(context)}`
40-
}));
4135

4236
// parsing attribute variables
4337
vertFnAst.content.args.forEach((arg) => {
@@ -101,7 +95,7 @@ export class Ast2GLSLUtils {
10195
}
10296
context.setMainFnAst(fragFnAst);
10397

104-
context.varyingStructInfo.objectName = fragFnAst.content.args[0].content.name;
98+
context.varyingStructInfo.objectName = fragFnAst.content.args?.[0].content.name;
10599
const fragmentFnStr = fragFnAst.serialize(context);
106100

107101
// There may be global variable references in conditional macro statement, so it needs to be serialized first.

packages/shader-lab/src/AstNodeUtils.ts

-30
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { CstChildrenDictionary, CstNode, ICstVisitor, IToken } from "chevrotain";
22

3-
import { IShaderInfo } from "@galacean/engine-design";
4-
import RuntimeContext, { IDiagnostic } from "./RuntimeContext";
5-
import { ShaderVisitor } from "./ShaderVisitor";
63
import { AstNode, ObjectAstNode } from "./ast-node";
74
import { IPosition, IPositionRange } from "./ast-node/";
8-
import { DiagnosticSeverity } from "./Constants";
9-
import { Logger } from "@galacean/engine";
10-
import { ShaderParser } from "./parser/ShaderParser";
115

126
export class AstNodeUtils {
137
static isCstNode(node: any) {
@@ -102,28 +96,4 @@ export class AstNodeUtils {
10296
static astSortDesc(a: AstNode, b: AstNode) {
10397
return -AstNodeUtils.astSortAsc(a, b);
10498
}
105-
106-
static parseShader(input: string, parser: ShaderParser, visitor: ShaderVisitor): IShaderInfo {
107-
parser.parse(input);
108-
const cst = parser.ruleShader();
109-
if (parser.errors.length > 0) {
110-
console.log(parser.errors);
111-
throw parser.errors;
112-
}
113-
114-
const ast = visitor.visit(cst);
115-
116-
const context = new RuntimeContext();
117-
const shaderInfo = context.parse(ast);
118-
119-
// context.diagnostics.forEach((item) => {
120-
// if (item.severity !== DiagnosticSeverity.Error) {
121-
// Logger.warn(item);
122-
// } else {
123-
// Logger.error(item);
124-
// }
125-
// });
126-
127-
return shaderInfo;
128-
}
12999
}

0 commit comments

Comments
 (0)