Skip to content

Commit

Permalink
Merge branch 'dev/1.4' into feature/ui-init
Browse files Browse the repository at this point in the history
  • Loading branch information
singlecoder authored Jan 6, 2025
2 parents 152368f + 42d0927 commit ab7cf58
Show file tree
Hide file tree
Showing 44 changed files with 594 additions and 140 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ jobs:
cp -r ${{ github.workspace }}/packages/galacean/dist ${{ github.workspace }}/temp/@galacean/engine
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-xr
cp -r ${{ github.workspace }}/packages/xr/dist ${{ github.workspace }}/temp/@galacean/engine-xr
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-shader-lab
cp -r ${{ github.workspace }}/packages/shader-lab/dist ${{ github.workspace }}/temp/@galacean/engine-shader-lab
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-shaderlab
cp -r ${{ github.workspace }}/packages/shader-lab/dist ${{ github.workspace }}/temp/@galacean/engine-shaderlab
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-shader-shaderlab
cp -r ${{ github.workspace }}/packages/shader-shaderlab/dist ${{ github.workspace }}/temp/@galacean/engine-shader-shaderlab
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-physics-lite
cp -r ${{ github.workspace }}/packages/physics-lite/dist ${{ github.workspace }}/temp/@galacean/engine-physics-lite
mkdir -p ${{ github.workspace }}/temp/@galacean/engine-physics-physx
Expand Down Expand Up @@ -111,7 +113,8 @@ jobs:
"engine": [
"${{ github.workspace }}/temp/@galacean/engine/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-xr/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-shader-lab/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-shaderlab/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-shader-shaderlab/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-physics-lite/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-physics-physx/dist/browser.js",
"${{ github.workspace }}/temp/@galacean/engine-toolkit/umd/browser.js",
Expand Down
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@galacean/engine-e2e",
"private": true,
"version": "1.4.0-alpha.1",
"version": "1.4.0-alpha.3",
"license": "MIT",
"scripts": {
"case": "vite serve .dev --config .dev/vite.config.js",
Expand All @@ -10,7 +10,7 @@
"files": [],
"dependencies": {
"@galacean/engine-toolkit": "^1.3.9",
"@galacean/engine-shader-lab": "workspace:*",
"@galacean/engine-shaderlab": "workspace:*",
"@galacean/engine": "workspace:*",
"@galacean/engine-core": "workspace:*",
"@galacean/engine-loader": "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.4.0-alpha.1",
"version": "1.4.0-alpha.3",
"packageManager": "[email protected]",
"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.4.0-alpha.1",
"version": "1.4.0-alpha.3",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
Expand Down
32 changes: 21 additions & 11 deletions packages/core/src/asset/ResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class ResourceManager {
* @internal
*/
_getRemoteUrl(url: string): string {
return this._virtualPathMap[url] ?? url;
return this._virtualPathResourceMap[url]?.path ?? url;
}

/**
Expand All @@ -206,7 +206,7 @@ export class ResourceManager {
* @internal
*/
_onSubAssetSuccess<T>(assetBaseURL: string, assetSubPath: string, value: T): void {
const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL;
const remoteAssetBaseURL = this._virtualPathResourceMap[assetBaseURL]?.path ?? assetBaseURL;

const subPromiseCallback = this._subAssetPromiseCallbacks[remoteAssetBaseURL]?.[assetSubPath];
if (subPromiseCallback) {
Expand Down Expand Up @@ -361,7 +361,7 @@ export class ResourceManager {
const paths = queryPath ? this._parseQueryPath(queryPath) : [];

// Get remote asset base url
const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL;
const remoteAssetBaseURL = this._virtualPathResourceMap[assetBaseURL]?.path ?? assetBaseURL;

// Check cache
const cacheObject = this._assetUrlPool[remoteAssetBaseURL];
Expand Down Expand Up @@ -553,9 +553,9 @@ export class ResourceManager {
/** @internal */
_objectPool: { [key: string]: any } = Object.create(null);
/** @internal */
_editorResourceConfig: EditorResourceConfig = Object.create(null);
_idResourceMap: Record<ResourceId, EditorResourceItem> = Object.create(null);
/** @internal */
_virtualPathMap: Record<string, string> = Object.create(null);
_virtualPathResourceMap: Record<VirtualPath, EditorResourceItem> = Object.create(null);

/**
* @internal
Expand All @@ -568,9 +568,9 @@ export class ResourceManager {
if (obj) {
promise = Promise.resolve(obj);
} else {
const resourceConfig = this._editorResourceConfig[refId];
const resourceConfig = this._idResourceMap[refId];
if (!resourceConfig) {
Logger.warn(`refId:${refId} is not find in this._editorResourceConfig.`);
Logger.warn(`refId:${refId} is not find in this._idResourceMap.`);
return Promise.resolve(null);
}
let url = resourceConfig.virtualPath;
Expand All @@ -592,8 +592,11 @@ export class ResourceManager {
*/
initVirtualResources(config: EditorResourceItem[]): void {
config.forEach((element) => {
this._virtualPathMap[element.virtualPath] = element.path;
this._editorResourceConfig[element.id] = element;
this._virtualPathResourceMap[element.virtualPath] = element;
this._idResourceMap[element.id] = element;
if (element.dependentAssetMap) {
this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
}
});
}
//-----------------Editor temp solution-----------------
Expand Down Expand Up @@ -631,8 +634,15 @@ const rePropName = RegExp(
"g"
);

type EditorResourceItem = { virtualPath: string; path: string; type: string; id: string };
type EditorResourceConfig = Record<string, EditorResourceItem>;
type ResourceId = string;
type VirtualPath = string;
type EditorResourceItem = {
virtualPath: string;
path: string;
type: string;
id: string;
dependentAssetMap?: { [key: string]: string };
};
type SubAssetPromiseCallbacks<T> = Record<
// main asset url, ie. "https://***.glb"
string,
Expand Down
106 changes: 57 additions & 49 deletions packages/core/src/material/BaseMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export class BaseMaterial extends Material {
protected static _emissiveColorProp: ShaderProperty = ShaderProperty.getByName("material_EmissiveColor");
protected static _emissiveTextureProp: ShaderProperty = ShaderProperty.getByName("material_EmissiveTexture");

private static _alphaCutoffProp: ShaderProperty = ShaderProperty.getByName("material_AlphaCutoff");
protected static _alphaCutoffProp: ShaderProperty = ShaderProperty.getByName("material_AlphaCutoff");
private static _alphaCutoffMacro: ShaderMacro = ShaderMacro.getByName("MATERIAL_IS_ALPHA_CUTOFF");

private _renderFace: RenderFace = RenderFace.Front;
private _isTransparent: boolean = false;
protected _isTransparent: boolean = false;
private _blendMode: BlendMode = BlendMode.Normal;

/**
Expand Down Expand Up @@ -73,24 +73,7 @@ export class BaseMaterial extends Material {
}

set isTransparent(value: boolean) {
if (value !== this._isTransparent) {
this.setIsTransparent(0, value);

const { shaderData } = this;
if (value) {
// Use alpha test queue to simulate transparent shadow
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
const alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
if (alphaCutoff) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

this._isTransparent = value;
}
this._seIsTransparent(value);
}

/**
Expand Down Expand Up @@ -119,35 +102,7 @@ export class BaseMaterial extends Material {
}

set alphaCutoff(value: number) {
const { shaderData } = this;
if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
if (value) {
shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
if (this._isTransparent) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

const { renderStates } = this;
for (let i = 0, n = renderStates.length; i < n; i++) {
const renderState = renderStates[i];
if (value > 0) {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.AlphaTest;
} else {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.Opaque;
}
}
shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
}
this._setAlphaCutoff(value);
}

/**
Expand Down Expand Up @@ -279,4 +234,57 @@ export class BaseMaterial extends Material {
target._isTransparent = this._isTransparent;
target._blendMode = this._blendMode;
}

protected _seIsTransparent(value: boolean): void {
if (value !== this._isTransparent) {
this.setIsTransparent(0, value);

const { shaderData } = this;
if (value) {
// Use alpha test queue to simulate transparent shadow
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
const alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
if (alphaCutoff) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

this._isTransparent = value;
}
}

protected _setAlphaCutoff(value: number): void {
const { shaderData } = this;
if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
if (value) {
shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
if (this._isTransparent) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

const { renderStates } = this;
for (let i = 0, n = renderStates.length; i < n; i++) {
const renderState = renderStates[i];
if (value > 0) {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.AlphaTest;
} else {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.Opaque;
}
}
shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
}
}
}
Loading

0 comments on commit ab7cf58

Please sign in to comment.