Skip to content

Commit

Permalink
Merge pull request #391 from galacean/feat/1.5
Browse files Browse the repository at this point in the history
Merge origin/feat/1.5 into origin/main
  • Loading branch information
yiiqii authored Jun 3, 2024
2 parents 6fe75ea + 0943f2f commit 05a1359
Show file tree
Hide file tree
Showing 38 changed files with 508 additions and 236 deletions.
2 changes: 1 addition & 1 deletion packages/effects-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"registry": "https://registry.npmjs.org"
},
"dependencies": {
"@galacean/effects-specification": "1.2.0",
"@galacean/effects-specification": "1.3.0-alpha.0",
"@galacean/effects-math": "1.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/effects-core/src/asset-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class AssetManager implements Disposable {
);
}
} catch (e) {
throw new Error(`Failed to load. Check the template or if the URL is ${isVideo ? 'video' : 'image'} type, URL: ${url}.`);
throw new Error(`Failed to load. Check the template or if the URL is ${isVideo ? 'video' : 'image'} type, URL: ${url}, Error: ${(e as any).message}`);
}
} else {
// 旧版模板或没有背景的处理
Expand Down
5 changes: 5 additions & 0 deletions packages/effects-core/src/utils/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export function isAndroid (): boolean {
export function isSimulatorCellPhone (): boolean {
return isAndroid() || /\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent);
}

export function isAlipayMiniApp (): boolean {
//@ts-expect-error
return typeof my !== 'undefined' && my?.renderTarget === 'web';
}
4 changes: 2 additions & 2 deletions packages/effects-webgl/src/gl-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class GLProgram implements Disposable {
private readonly shared: boolean,
private readonly id: string,
) {

let blockUniformNames: string[] = [];

this.pipelineContext = engine.getGLPipelineContext();
Expand Down Expand Up @@ -84,7 +83,8 @@ export class GLProgram implements Disposable {
geometry.vaos[programId] = vao;
}

if (vao) {
// 兼容小程序下不支持vao
if (vao && vao.vao) {
vao.bind();
if (vao.ready) {
return vao;
Expand Down
17 changes: 5 additions & 12 deletions packages/effects-webgl/src/gl-renderer-internal.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Disposable, LostHandler, Material, Geometry } from '@galacean/effects-core';
import { TextureSourceType, addItem, logger, removeItem } from '@galacean/effects-core';
import type { Disposable, Geometry, LostHandler, Material } from '@galacean/effects-core';
import { addItem, logger, removeItem, TextureSourceType } from '@galacean/effects-core';
import type { GLEngine } from './gl-engine';
import type { GLFrameBuffer } from './gl-frame-buffer';
import type { GLGeometry } from './gl-geometry';
import type { GLGPUBuffer } from './gl-gpu-buffer';
import type { GLMaterial } from './gl-material';
import type { GLPipelineContext } from './gl-pipeline-context';
import type { GLRenderBuffer } from './gl-render-buffer';
import { GLTexture } from './gl-texture';
import { GLVertexArrayObject } from './gl-vertex-array-object';
import type { GLEngine } from './gl-engine';
import type { GLMaterial } from './gl-material';

let seed = 1;

Expand Down Expand Up @@ -249,15 +249,8 @@ export class GLRendererInternal implements Disposable, LostHandler {
this.deleteResource();
}

dispose (haltGL?: boolean) {
dispose () {
this.deleteResource();
const gl = this.gl;

if (gl && haltGL) {
const ex = gl.getExtension('WEBGL_lose_context');

ex?.loseContext();
}
// @ts-expect-error safe to assign
this.emptyTexture2D = this.emptyTextureCube = this.pipelineContext = this.gpu = this.gl = null;
this.destroyed = true;
Expand Down
16 changes: 11 additions & 5 deletions packages/effects-webgl/src/gl-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { Disposable, FrameBuffer, Geometry, LostHandler, Material, Mesh, RenderFrame, RenderPass, RenderPassClearAction, RenderPassStoreAction, RestoreHandler, ShaderLibrary, math } from '@galacean/effects-core';
import { assertExist, glContext, Renderer, RenderPassAttachmentStorageType, TextureLoadAction, TextureSourceType, FilterMode, RenderTextureFormat, sortByOrder } from '@galacean/effects-core';
import type {
Disposable, FrameBuffer, Geometry, LostHandler, Material, Mesh, RenderFrame, RenderPass,
RenderPassClearAction, RenderPassStoreAction, RestoreHandler, ShaderLibrary, math,
} from '@galacean/effects-core';
import {
assertExist, glContext, Renderer, RenderPassAttachmentStorageType, TextureLoadAction,
TextureSourceType, FilterMode, RenderTextureFormat, sortByOrder,
} from '@galacean/effects-core';
import { ExtWrap } from './ext-wrap';
import { GLContextManager } from './gl-context-manager';
import { GLEngine } from './gl-engine';
import { GLFrameBuffer } from './gl-frame-buffer';
import { GLPipelineContext } from './gl-pipeline-context';
import { GLRendererInternal } from './gl-renderer-internal';
import { GLTexture } from './gl-texture';
import { GLEngine } from './gl-engine';

type Matrix4 = math.Matrix4;

Expand Down Expand Up @@ -292,11 +298,11 @@ export class GLRenderer extends Renderer implements Disposable {
return this.height;
}

override dispose (haltGL?: boolean): void {
override dispose (): void {
this.context.dispose();
this.extension.dispose();
this.pipelineContext.dispose();
this.glRenderer?.dispose(haltGL);
this.glRenderer?.dispose();
// @ts-expect-error
this.canvas = null;
this.engine.dispose();
Expand Down
8 changes: 8 additions & 0 deletions packages/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
"import": "./dist/weapp.mjs",
"require": "./dist/weapp.js",
"types": "./dist/index.d.ts"
},
"./alipay": {
"import": "./dist/alipay.mjs",
"require": "./dist/alipay.js",
"types": "./dist/index.d.ts"
}
},
"typesVersions": {
"*": {
"weapp": [
"./dist/index.d.ts"
],
"alipay": [
"./dist/index.d.ts"
]
}
},
Expand Down
19 changes: 19 additions & 0 deletions packages/effects/rollup.appx.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 小程序产物编译配置
*/
import inject from '@rollup/plugin-inject';

const module = '@galacean/appx-adapter';
const commonAdapterList = [
'window',
Expand All @@ -20,17 +21,35 @@ const commonAdapterList = [
'performance',
'requestAnimationFrame',
'cancelAnimationFrame',
'btoa',
'atob',
'devicePixelRatio',
'Element',
'Event',
'EventTarget',
'HTMLMediaElement',
'Node',
'screen',
'WebGL2RenderingContext',
'ImageData',
'OffscreenCanvas',
'URLSearchParams'
];
const adapterList = {
weapp: [...commonAdapterList],
alipay: [...commonAdapterList],
}

export default [
'weapp',
'alipay'
].map(platform => {
const adapterVars = {};

adapterList[platform].forEach(name => {
adapterVars[name] = [`${module}/${platform}`, name];
});

return {
input: `src/index.ts`,
output: [{
Expand Down
20 changes: 15 additions & 5 deletions plugin-packages/alipay-downgrade/demo/src/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { checkDowngrade, setAlipayDowngradeBizId } from '@galacean/effects-plugin-alipay-downgrade';
import { isAlipayMiniApp } from '@galacean/effects';
import { checkDowngrade, getSystemInfo, setAlipayDowngradeBizId, downgradeForMiniprogram } from '@galacean/effects-plugin-alipay-downgrade';

(async () => {
let bizId = 'test';
Expand All @@ -9,9 +10,18 @@ import { checkDowngrade, setAlipayDowngradeBizId } from '@galacean/effects-plugi
console.info('Input bizId:', bizId);
}
setAlipayDowngradeBizId(bizId);
const result = await checkDowngrade(bizId);
const label = document.createElement('label');
const downgradeResult = await checkDowngrade(bizId);
const systemInfoResult = await getSystemInfo();
const isAlipayMiniProgram = isAlipayMiniApp();
const downgradeMiniprogram = downgradeForMiniprogram();
const downgradeLabel = document.createElement('label');
const systemInfoLabel = document.createElement('label');
const miniprogramLabel = document.createElement('label');

label.innerHTML = `<div><pre>${JSON.stringify(result, undefined, 2)}</pre></div>`;
document.body.append(label);
downgradeLabel.innerHTML = `<div><pre>${JSON.stringify(downgradeResult, undefined, 2)}</pre></div>`;
systemInfoLabel.innerHTML = `<div><pre>${JSON.stringify(systemInfoResult, undefined, 2)}</pre></div>`;
miniprogramLabel.innerHTML = `<div><pre>MiniProgram: ${isAlipayMiniProgram}, downgrade: ${downgradeMiniprogram}</pre></div>`;
document.body.append(downgradeLabel);
document.body.append(systemInfoLabel);
document.body.append(miniprogramLabel);
})();
5 changes: 5 additions & 0 deletions plugin-packages/alipay-downgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./alipay": {
"import": "./dist/alipay.mjs",
"require": "./dist/alipay.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
Expand Down
42 changes: 42 additions & 0 deletions plugin-packages/alipay-downgrade/rollup.appx.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 小程序产物编译配置
*/
import inject from '@rollup/plugin-inject';

const module = '@galacean/appx-adapter';
const commonAdapterList = [
'window'
];
const adapterList = {
alipay: [...commonAdapterList],
}

export default [
'alipay'
].map(platform => {
const adapterVars = {};
const paths = { '@galacean/effects': `@galacean/effects/${platform}`};

adapterList[platform].forEach(name => {
adapterVars[name] = [`${module}/${platform}`, name];
});

return {
input: `src/index.ts`,
output: [{
file: `./dist/${platform}.mjs`,
format: 'es',
sourcemap: true,
paths,
}, {
file: `./dist/${platform}.js`,
format: 'cjs',
sourcemap: true,
paths,
}],
external: ['@galacean/effects'],
plugins: [
inject(adapterVars),
],
};
});
7 changes: 5 additions & 2 deletions plugin-packages/alipay-downgrade/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import terser from '@rollup/plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import glslInner from '../../scripts/rollup-plugin-glsl-inner';
import appxConfig from './rollup.appx.config';

const pkg = require('./package.json');
const banner = `/*!
Expand Down Expand Up @@ -65,5 +66,7 @@ export default (commandLineArgs) => {
plugins: plugins.concat(
terser()
),
}];
},
...appxConfig.map(config => ({ ...config, plugins: plugins.concat(config.plugins) }))
]
};
56 changes: 14 additions & 42 deletions plugin-packages/alipay-downgrade/src/native-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,30 @@
* nativeLog.error('this is native log from h5, error:', error);
* ```
*/
import { isAndroid, isIOS, logger } from '@galacean/effects';
import { isAlipayMiniApp, isAndroid, logger } from '@galacean/effects';

const prefix = '[Galacean Effects]';
//@ts-expect-error
const ap = isAlipayMiniApp() ? my : window.AlipayJSBridge;

logger.register(nativeLogger);

function nativeLogger (type: string, msg: string, ...args: string[]) {
const content: {
message: string,
level: string,
'anr_info'?: string,
} = {
'message': `${prefix} ${msg} ${args.join('')}`,
'level': type,
};

if (isAndroid()) {
androidLogger(type, `${prefix} ${msg}`, ...args);
} else if (isIOS()) {
iOSLogger(type, msg, ...args);
content['anr_info'] = 'mars';
}
}

function iOSLogger (type: string, msg: string, ...args: string[]) {
try {
const ap = window.AlipayJSBridge;
const content = formatMessage(type, msg, ...args);

ap?.call('H5APLog', {
content,
});
ap?.call('localLog', content);
} catch (e) {
console.error(e);
}
}

// Android H5 容器支持 console 日志直接写入 aplog
function androidLogger (type: string, msg: string, ...args: string[]) {
try {
const ap = window.AlipayJSBridge;

ap?.call('localLog', {
'anr_info': 'mars',
'message': msg + args.join(''),
'level': type,
});
} catch (e) {
console.error(e);
}
}

function formatMessage (level: string, msg: string, ...args: string[]) {
const result = [
'<MARS_PLAYER>',
`(${level}):`,
msg,
];

args.forEach(i => {
result.push(i + '');
});

return result.join(' ');
}
Loading

0 comments on commit 05a1359

Please sign in to comment.