Skip to content

Commit

Permalink
Merge pull request #795 from galacean/dev
Browse files Browse the repository at this point in the history
Merge origin/dev into origin/main
  • Loading branch information
yiiqii authored Dec 20, 2024
2 parents 3cc8779 + 08b486d commit db44b7f
Show file tree
Hide file tree
Showing 41 changed files with 294 additions and 647 deletions.
6 changes: 6 additions & 0 deletions packages/effects-core/src/components/base-render-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export class BaseRenderComponent extends RendererComponent {
texParams.x = renderer.occlusion ? +(renderer.transparentOcclusion) : 1;
texParams.y = +this.preMultiAlpha;
texParams.z = renderer.renderMode;

if (texParams.x === 0) {
this.material.enableMacro('ALPHA_CLIP');
} else {
this.material.disableMacro('ALPHA_CLIP');
}
}

const attributes = {
Expand Down
6 changes: 3 additions & 3 deletions packages/effects-core/src/plugins/sprite/sprite-mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export function spriteMeshShaderFromRenderInfo (renderInfo: ItemRenderInfo, coun
});

shader.shared = true;
if (!wireframe) {
shader.cacheId = spriteMeshShaderIdFromRenderInfo(renderInfo, count);
}
// if (!wireframe) {
// shader.cacheId = spriteMeshShaderIdFromRenderInfo(renderInfo, count);
// }

return shader;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/effects-core/src/shader/item.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ void main() {
vec4 color = vec4(0.);
vec4 texColor = texture2D(_MainTex, vTexCoord.xy);
color = blendColor(texColor, vColor, floor(0.5 + vParams.y));

#ifdef ALPHA_CLIP
if(vParams.z == 0. && color.a < 0.04) { // 1/256 = 0.04
discard;
}
#endif
//color.rgb = pow(color.rgb, vec3(2.2));
color.a = clamp(color.a, 0.0, 1.0);
gl_FragColor = color;
Expand Down
181 changes: 11 additions & 170 deletions plugin-packages/orientation-transformer/demo/src/simple.ts
Original file line number Diff line number Diff line change
@@ -1,189 +1,30 @@
// @ts-nocheck
import { Player } from '@galacean/effects';
import { getAdapter, type OrientationAdapterAcceler } from '@galacean/effects-plugin-orientation-transformer';

const json = {
'compositionId':1,
'requires':[],
'compositions':[
{
'name':'composition_1',
'id':1,
'duration':999,
'camera':{
'fov':30,
'far':20,
'near':0.1,
'position':[
0,
0,
8,
],
'clipMode':1,
},
'items':[
{
'name':'item_3',
'delay':0,
'id':3,
'type':'2',
'parentId':2,
'ro':0.01,
'particle':{
'options':{
'startLifetime':1.2,
'startSize':0.2,
'sizeAspect':1,
'startSpeed':1,
'startColor':[
'color',
[
255,
255,
255,
],
],
'duration':2,
'maxCount':10,
'gravityModifier':1,
'renderLevel':'B+',
'looping':true,
},
'emission':{
'rateOverTime':5,
},
'shape':{
'shape':'Sphere',
'radius':1,
'arc':360,
'arcMode':0,
},
},
},
{
'name':'plugin_3',
'delay':0,
'id':4,
'type':'5',
'content':{
'options':{
'duration':999,
'type':'orientation-transformer',
'renderLevel':'B+',
'targets':[
{
'name':'null_1',
'xMin':'3',
'xMax':'-3',
'yMin':'3',
'yMax':'-3',
'vMin': '-20',
'vMax': '20',
'hMin': '-20',
'hMax': '20',
},
],
},
},
},
{
'name':'null_1',
'delay':0,
'id':2,
'type':'3',
'cal':{
'options':{
'duration':2,
'startSize':1,
'sizeAspect':1,
'relative':true,
'renderLevel':'B+',
'looping':true,
},
},
},
{
'name':'item_1',
'delay':0,
'id':1,
'type':'1',
'parentId':2,
'ro':0.02,
'sprite':{
'options':{
'startLifetime':2,
'startSize':1.2,
'sizeAspect':1,
'startColor':[
'color',
[
255,
255,
255,
],
],
'duration':2,
'gravityModifier':1,
'renderLevel':'B+',
'looping':true,
},
'renderer':{
'renderMode':1,
},
},
},
],
'meta':{
'previewSize':[
750,
1334,
],
},
},
],
'gltf':[],
'images':[],
'version':'0.9.0',
'shapes':[],
'plugins':[
'orientation-transformer',
],
'type':'mars',
'_imgs':{
'1':[],
},
};
const json = 'https://mdn.alipayobjects.com/mars/afts/file/A*GbiuQIresOsAAAAAAAAAAAAADlB4AQ';
const container = document.getElementById('J-container');
const betaInput = document.querySelector('input[name="beta"]');
const gammaInput = document.querySelector('input[name="gamma"]');
const betaInput = document.querySelector('input[name="beta"]') as HTMLInputElement;
const gammaInput = document.querySelector('input[name="gamma"]') as HTMLInputElement;

(async () => {
const adapter = getAdapter();
const player = createPlayer();
const scene = await player.loadScene(json);
const player = new Player({
container,
pixelRatio: window.devicePixelRatio,
interactive: true,
});

betaInput.addEventListener('input', () => { handleInputChange(adapter); });
gammaInput.addEventListener('input', () => { handleInputChange(adapter); });

void player.play(scene);
await player.loadScene(json);
})();

function handleInputChange (adapter: OrientationAdapterAcceler) {
adapter.dispatchMotion({
x: +betaInput.value / 100,
y: +gammaInput.value / 100,
beta: +betaInput.value / 100,
gamma:+gammaInput.value / 100,
});
document.getElementById('J-info').innerText = `[info] x: ${betaInput.value}, y: ${gammaInput.value}`;
}

function createPlayer () {
const player = new Player({
container,
pixelRatio: window.devicePixelRatio,
interactive: true,
gamma: +gammaInput.value / 100,
});

return player;
document.getElementById('J-info')!.innerText = `[info] x: ${betaInput.value}, y: ${gammaInput.value}`;
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<script>
!function(f,a,c){var s,l=256,p="random",d=c.pow(l,6),g=c.pow(2,52),y=2*g,h=l-1;function n(n,t,r){function e(){for(var n=u.g(6),t=d,r=0;n<g;)n=(n+r)*l,t*=l,r=u.g(1);for(;y<=n;)n/=2,t/=2,r>>>=1;return(n+r)/t}var o=[],i=j(function n(t,r){var e,o=[],i=typeof t;if(r&&"object"==i)for(e in t)try{o.push(n(t[e],r-1))}catch(n){}return o.length?o:"string"==i?t:t+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[n,S(a)]:null==n?function(){try{var n;return s&&(n=s.randomBytes)?n=n(l):(n=new Uint8Array(l),(f.crypto||f.msCrypto).getRandomValues(n)),S(n)}catch(n){var t=f.navigator,r=t&&t.plugins;return[+new Date,f,r,f.screen,S(a)]}}():n,3),o),u=new m(o);return e.int32=function(){return 0|u.g(4)},e.quick=function(){return u.g(4)/4294967296},e.double=e,j(S(u.S),a),(t.pass||r||function(n,t,r,e){return e&&(e.S&&v(e,u),n.state=function(){return v(u,{})}),r?(c[p]=n,t):n})(e,i,"global"in t?t.global:this==c,t.state)}function m(n){var t,r=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(r||(n=[r++]);e<l;)i[e]=e++;for(e=0;e<l;e++)i[e]=i[o=h&o+n[e%r]+(t=i[e])],i[o]=t;(u.g=function(n){for(var t,r=0,e=u.i,o=u.j,i=u.S;n--;)t=i[e=h&e+1],r=r*l+i[h&(i[e]=i[o=h&o+t])+(i[o]=t)];return u.i=e,u.j=o,r})(l)}function v(n,t){return t.i=n.i,t.j=n.j,t.S=n.S.slice(),t}function j(n,t){for(var r,e=n+"",o=0;o<e.length;)t[h&o]=h&(r^=19*t[h&o])+e.charCodeAt(o++);return S(t)}function S(n){return String.fromCharCode.apply(0,n)}if(j(c.random(),a),"object"==typeof module&&module.exports){module.exports=n;try{s=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd?define(function(){return n}):c["seed"+p]=n}("undefined"!=typeof self?self:this,[],Math);
</script>
<script type="module" src="./src/index.ts"></script>
<script type="module" src="./src/2d/index.ts"></script>
<script type="module" class="mocha-exec">
mocha.run();
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<script>
!function(f,a,c){var s,l=256,p="random",d=c.pow(l,6),g=c.pow(2,52),y=2*g,h=l-1;function n(n,t,r){function e(){for(var n=u.g(6),t=d,r=0;n<g;)n=(n+r)*l,t*=l,r=u.g(1);for(;y<=n;)n/=2,t/=2,r>>>=1;return(n+r)/t}var o=[],i=j(function n(t,r){var e,o=[],i=typeof t;if(r&&"object"==i)for(e in t)try{o.push(n(t[e],r-1))}catch(n){}return o.length?o:"string"==i?t:t+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[n,S(a)]:null==n?function(){try{var n;return s&&(n=s.randomBytes)?n=n(l):(n=new Uint8Array(l),(f.crypto||f.msCrypto).getRandomValues(n)),S(n)}catch(n){var t=f.navigator,r=t&&t.plugins;return[+new Date,f,r,f.screen,S(a)]}}():n,3),o),u=new m(o);return e.int32=function(){return 0|u.g(4)},e.quick=function(){return u.g(4)/4294967296},e.double=e,j(S(u.S),a),(t.pass||r||function(n,t,r,e){return e&&(e.S&&v(e,u),n.state=function(){return v(u,{})}),r?(c[p]=n,t):n})(e,i,"global"in t?t.global:this==c,t.state)}function m(n){var t,r=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(r||(n=[r++]);e<l;)i[e]=e++;for(e=0;e<l;e++)i[e]=i[o=h&o+n[e%r]+(t=i[e])],i[o]=t;(u.g=function(n){for(var t,r=0,e=u.i,o=u.j,i=u.S;n--;)t=i[e=h&e+1],r=r*l+i[h&(i[e]=i[o=h&o+t])+(i[o]=t)];return u.i=e,u.j=o,r})(l)}function v(n,t){return t.i=n.i,t.j=n.j,t.S=n.S.slice(),t}function j(n,t){for(var r,e=n+"",o=0;o<e.length;)t[h&o]=h&(r^=19*t[h&o])+e.charCodeAt(o++);return S(t)}function S(n){return String.fromCharCode.apply(0,n)}if(j(c.random(),a),"object"==typeof module&&module.exports){module.exports=n;try{s=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd?define(function(){return n}):c["seed"+p]=n}("undefined"!=typeof self?self:this,[],Math);
</script>
<script type="module" src="./src/index.ts"></script>
<script type="module" src="./src/3d/index.ts"></script>
<script type="module" class="mocha-exec">
mocha.run();
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<script type="module" src="./src/index.ts"></script>
<script type="module" src="./src/all/index.ts"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions web-packages/test/case/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<body>
<div class="am-list">
<div class="am-list-body">
<a href="2d/index.html" class="am-list-item">
<a href="2d.html" class="am-list-item">
<div class="am-list-content">2D 测试</div>
<div class="am-list-arrow"><span class="am-icon arrow horizontal"></span></div>
</a>
<a href="3d/index.html" class="am-list-item">
<a href="3d.html" class="am-list-item">
<div class="am-list-content">3D 测试</div>
<div class="am-list-arrow"><span class="am-icon arrow horizontal"></span></div>
</a>
<a href="spine/index.html" class="am-list-item">
<a href="spine.html" class="am-list-item">
<div class="am-list-content">Spine 测试</div>
<div class="am-list-arrow"><span class="am-icon arrow horizontal"></span></div>
</a>
<a href="all/index.html" class="am-list-item">
<a href="all.html" class="am-list-item">
<div class="am-list-content">全部测试(多页面并行)</div>
<div class="am-list-arrow"><span class="am-icon arrow horizontal"></span></div>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<script>
!function(f,a,c){var s,l=256,p="random",d=c.pow(l,6),g=c.pow(2,52),y=2*g,h=l-1;function n(n,t,r){function e(){for(var n=u.g(6),t=d,r=0;n<g;)n=(n+r)*l,t*=l,r=u.g(1);for(;y<=n;)n/=2,t/=2,r>>>=1;return(n+r)/t}var o=[],i=j(function n(t,r){var e,o=[],i=typeof t;if(r&&"object"==i)for(e in t)try{o.push(n(t[e],r-1))}catch(n){}return o.length?o:"string"==i?t:t+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[n,S(a)]:null==n?function(){try{var n;return s&&(n=s.randomBytes)?n=n(l):(n=new Uint8Array(l),(f.crypto||f.msCrypto).getRandomValues(n)),S(n)}catch(n){var t=f.navigator,r=t&&t.plugins;return[+new Date,f,r,f.screen,S(a)]}}():n,3),o),u=new m(o);return e.int32=function(){return 0|u.g(4)},e.quick=function(){return u.g(4)/4294967296},e.double=e,j(S(u.S),a),(t.pass||r||function(n,t,r,e){return e&&(e.S&&v(e,u),n.state=function(){return v(u,{})}),r?(c[p]=n,t):n})(e,i,"global"in t?t.global:this==c,t.state)}function m(n){var t,r=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(r||(n=[r++]);e<l;)i[e]=e++;for(e=0;e<l;e++)i[e]=i[o=h&o+n[e%r]+(t=i[e])],i[o]=t;(u.g=function(n){for(var t,r=0,e=u.i,o=u.j,i=u.S;n--;)t=i[e=h&e+1],r=r*l+i[h&(i[e]=i[o=h&o+t])+(i[o]=t)];return u.i=e,u.j=o,r})(l)}function v(n,t){return t.i=n.i,t.j=n.j,t.S=n.S.slice(),t}function j(n,t){for(var r,e=n+"",o=0;o<e.length;)t[h&o]=h&(r^=19*t[h&o])+e.charCodeAt(o++);return S(t)}function S(n){return String.fromCharCode.apply(0,n)}if(j(c.random(),a),"object"==typeof module&&module.exports){module.exports=n;try{s=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd?define(function(){return n}):c["seed"+p]=n}("undefined"!=typeof self?self:this,[],Math);
</script>
<script type="module" src="./src/index.spec.ts"></script>
<script type="module" src="./src/spine/index.spec.ts"></script>
<script type="module" class="mocha-exec">
mocha.run();
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GLType } from '@galacean/effects';
import { TestController, ImageComparator, getCurrnetTimeStr } from './common';
import { TestController, ImageComparator, getCurrnetTimeStr } from '../common';
import sceneList from './assets/dynamic';

const { expect } = chai;
Expand Down Expand Up @@ -50,6 +50,7 @@ async function checkScene (keyName: string, name: string, url: string, idx: [num
1.1, 1.23, 1.45, 1.67, 1.88, 2.1, 2.5, 3.3, 4.7, 5.2, 6.8,
7.5, 8.6, 9.7, 10.01,
];
const diffRatioList = [];
let marsRet, runtimeRet;

for (let i = 0; i < timeList.length; i++) {
Expand Down Expand Up @@ -116,12 +117,11 @@ async function checkScene (keyName: string, name: string, url: string, idx: [num

await oldPlayer.saveCanvasToImage(oldFileName, idx);
await newPlayer.saveCanvasToImage(newFileName, idx, true);
diffRatioList.push(diffCountRatio);
}

// 红包雨 case player 点击后有元素不消失的问题
expect(diffCountRatio).to.lte(accumRatioThreshold);
}

expect(diffRatioList).to.be.eqls([], `diffs: ${JSON.stringify(diffRatioList)}`);
console.info(`[Test] Compare end: ${name}, ${url}`);
});
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GLType } from '@galacean/effects';
import { TestController, ImageComparator, getCurrnetTimeStr, ComparatorStats } from './common';
import { TestController, ImageComparator, getCurrnetTimeStr, ComparatorStats } from '../common';
import sceneList from './assets/inspire';
import '@galacean/effects-plugin-orientation-transformer';

Expand Down Expand Up @@ -74,6 +74,7 @@ async function checkScene (keyName: string, name: string, url: string, idx: [num
1.1, 1.2, 1.4, 1.7, 1.9, 2.2, 2.5, 2.7, 3.3, 3.8,
4.7, 5.2, 6.8, 7.5, 8.6, 9.7, 9.99, 12.5, 18.9,
];
const diffRatioList = [];

for (let i = 0; i < timeList.length; i++) {
const time = timeList[i];
Expand Down Expand Up @@ -102,11 +103,12 @@ async function checkScene (keyName: string, name: string, url: string, idx: [num

await oldPlayer.saveCanvasToImage(oldFileName, idx);
await newPlayer.saveCanvasToImage(newFileName, idx, true);
diffRatioList.push(diffCountRatio);
}

expect(diffCountRatio).to.lte(accumRatioThreshold);
}

expect(diffRatioList).to.be.eqls([], `diffs: ${JSON.stringify(diffRatioList)}`);

const oldLoadCost = oldPlayer.loadSceneTime();
const oldFirstCost = oldPlayer.firstFrameTime();
const newLoadCost = newPlayer.loadSceneTime();
Expand Down
Loading

0 comments on commit db44b7f

Please sign in to comment.