@eva/plugin-renderer-particle 2.1.0-beta.2 → 2.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,10 @@ var _EVA_IIFE_particle = function (exports, eva_js, pluginRenderer, pixi_js) {
41
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
42
  });
43
43
  }
44
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
45
+ var e = new Error(message);
46
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
47
+ };
44
48
  function __rest(s, e) {
45
49
  var t = {};
46
50
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_particle=function(e,t,r,n){"use strict";function i(e,t,r,n){var i,a=arguments.length,s=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,r,s):i(t,r))||s);return a>3&&s&&Object.defineProperty(t,r,s),s}function a(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,r,n){return new(r||(r=Promise))(function(i,a){function s(e){try{l(n.next(e))}catch(e){a(e)}}function o(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,o)}l((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class o extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const l="IDE_PROPERTY_METADATA";function c(e,t,r,n){let i=Reflect.getMetadata("design:type",e,t),a=i===Array;const s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(i);if("unknown"!==s&&(i=s),n){const e=n();Array.isArray(e)?(a=!0,i=e[0]):i=e}const o=Reflect.getMetadata(l,e.constructor)||{},c=_extends(_extends(_extends({},o[t]||{}),{type:i,isArray:a}),r);o[t]=c,Reflect.defineMetadata(l,o,e.constructor);!function(e,t,r){const n=e.constructor,i=n.IDEProps||{};i[t]=_extends(_extends({key:t},i[t]),r),n.IDEProps=i}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(c,["isArray"]))}function u(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new o;const{options:i,returnTypeFunc:a}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);c(e,n,i,a)};var t,r}var d;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(d||(d={}));class h extends t.Component{constructor(){super(...arguments),this.resource="",this.auto=!0,this.duration=-1,this.frequency=250,this.quantity=1,this.maxParticles=500,this.lifespan=1e3,this.gravityX=0,this.gravityY=0,this.paused=!1}init(e){e&&_extends(this,e)}stop(){this.paused=!0}start(){this.paused=!1}}h.componentName="ParticleEmitter",i([u("string"),a("design:type",String)],h.prototype,"resource",void 0),i([u("boolean"),a("design:type",Boolean)],h.prototype,"auto",void 0),i([u("number"),a("design:type",Number)],h.prototype,"duration",void 0),i([u("number"),a("design:type",Number)],h.prototype,"frequency",void 0),i([u("number"),a("design:type",Number)],h.prototype,"quantity",void 0),i([u("number"),a("design:type",Number)],h.prototype,"maxParticles",void 0),i([u("number"),a("design:type",Number)],h.prototype,"gravityX",void 0),i([u("number"),a("design:type",Number)],h.prototype,"gravityY",void 0);const p=2*Math.PI,y={linear:e=>e,"sine.in":e=>1-Math.cos(e*Math.PI/2),"sine.out":e=>Math.sin(e*Math.PI/2),"sine.inout":e=>-(Math.cos(Math.PI*e)-1)/2,"quad.in":e=>e*e,"quad.out":e=>1-(1-e)*(1-e),"quad.inout":e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,"cubic.in":e=>e*e*e,"cubic.out":e=>1-Math.pow(1-e,3),"expo.out":e=>1===e?1:1-Math.pow(2,-10*e)};function f(e){if(!e)return y.linear;const t=e.toLowerCase();return y[t]||y.linear}function m(e,t){return e+Math.random()*(t-e)}function v(e,t=0){return null==e?t:"number"==typeof e?e:Array.isArray(e)?e[Math.floor(Math.random()*e.length)]:"min"in e&&"max"in e?m(e.min,e.max):"start"in e&&"end"in e?e.start:t}function x(e){return null==e||"number"==typeof e||Array.isArray(e)?null:"start"in e&&"end"in e?e:null}function g(e){return e?function(e,t){var r,n,i,a,s,o,l,c;switch(e.type){case"point":return{x:null!==(r=e.x)&&void 0!==r?r:0,y:null!==(n=e.y)&&void 0!==n?n:0};case"rect":{const r=null!==(i=e.x)&&void 0!==i?i:0,n=null!==(a=e.y)&&void 0!==a?a:0;if(t){const t=2*(e.width+e.height),i=Math.random()*t;return i<e.width?{x:r+i,y:n}:i<e.width+e.height?{x:r+e.width,y:n+(i-e.width)}:i<2*e.width+e.height?{x:r+e.width-(i-e.width-e.height),y:n+e.height}:{x:r,y:n+e.height-(i-2*e.width-e.height)}}return{x:m(r,r+e.width),y:m(n,n+e.height)}}case"circle":{const r=null!==(s=e.x)&&void 0!==s?s:0,n=null!==(o=e.y)&&void 0!==o?o:0,i=Math.random()*p,a=t?e.radius:e.radius*Math.sqrt(Math.random());return{x:r+Math.cos(i)*a,y:n+Math.sin(i)*a}}case"ellipse":{const r=null!==(l=e.x)&&void 0!==l?l:0,n=null!==(c=e.y)&&void 0!==c?c:0,i=Math.random()*p,a=t?1:Math.sqrt(Math.random());return{x:r+Math.cos(i)*e.rx*a,y:n+Math.sin(i)*e.ry*a}}case"line":{const t=Math.random();return{x:e.x1+(e.x2-e.x1)*t,y:e.y1+(e.y2-e.y1)*t}}}}(e.shape,"edge"===e.type):{x:0,y:0}}class E{constructor(e,t,r){this.frameTextures=null,this.particles=[],this.elapsed=0,this.emittedTotal=0,this.emitTimer=0,this.explodeDone=!1,this.params=e,this.container=t,this.texture=r}setTexture(e){this.texture=e}setFrameTextures(e){this.frameTextures=e&&e.length>0?e:null}setParams(e){this.params=e}destroy(){this.particles.length=0,this.container.particleChildren.length=0,this.container.update()}update(e){this.elapsed+=e,this.advanceParticles(e),this.spawn(e),this.container.update()}advanceParticles(e){var t,r;const n=e/1e3,i=[];for(const a of this.particles){if(a.age+=e,a.age>a.lifespan)continue;a.vx+=a.ax*n+(null!==(t=this.params.gravityX)&&void 0!==t?t:0)*n,a.vy+=a.ay*n+(null!==(r=this.params.gravityY)&&void 0!==r?r:0)*n,a.particle.x+=a.vx*n,a.particle.y+=a.vy*n,a.particle.rotation+=a.rotateSpeed*n;const s=a.age/a.lifespan;if(a.scaleStart&&a.scaleEnd){const e=(a.scaleEase||y.linear)(s);a.particle.scaleX=a.scaleStart.x+(a.scaleEnd.x-a.scaleStart.x)*e,a.particle.scaleY=a.scaleStart.y+(a.scaleEnd.y-a.scaleStart.y)*e}if(null!=a.alphaStart&&null!=a.alphaEnd){const e=(a.alphaEase||y.linear)(s);a.particle.alpha=a.alphaStart+(a.alphaEnd-a.alphaStart)*e}this.params.deathZone&&this.shouldDie(a.particle.x,a.particle.y)||i.push(a)}this.particles=i,this.container.particleChildren.length=0;for(const e of this.particles)this.container.particleChildren.push(e.particle)}shouldDie(e,t){const r=this.params.deathZone;if(!r)return!1;const n=function(e,t,r){var n,i,a,s,o,l;switch(e.type){case"rect":{const a=null!==(n=e.x)&&void 0!==n?n:0,s=null!==(i=e.y)&&void 0!==i?i:0;return t>=a&&t<=a+e.width&&r>=s&&r<=s+e.height}case"circle":{const n=t-(null!==(a=e.x)&&void 0!==a?a:0),i=r-(null!==(s=e.y)&&void 0!==s?s:0);return n*n+i*i<=e.radius*e.radius}case"ellipse":{const n=(t-(null!==(o=e.x)&&void 0!==o?o:0))/e.rx,i=(r-(null!==(l=e.y)&&void 0!==l?l:0))/e.ry;return n*n+i*i<=1}case"point":case"line":return!1}}(r.shape,e,t);return"onLeave"===r.mode?!n:n}spawn(e){var t,r,n;const i=this.params;if(null!=i.duration&&i.duration>0&&this.elapsed>i.duration)return;if(null!=i.stopAfter&&this.emittedTotal>=i.stopAfter)return;if(i.paused)return;const a=null!==(t=i.maxParticles)&&void 0!==t?t:500;if(this.particles.length>=a)return;if(null!=i.explode&&!this.explodeDone){const e=Math.min(i.explode,a-this.particles.length);for(let t=0;t<e;t++)this.emitOne();return void(this.explodeDone=!0)}if(null!=i.explode)return;if(!1===i.auto)return;this.emitTimer+=e;const s=null!==(r=i.frequency)&&void 0!==r?r:250,o=null!==(n=i.quantity)&&void 0!==n?n:1;for(;this.emitTimer>=s&&this.particles.length<a;){for(let e=0;e<o&&this.particles.length<a&&!(null!=i.stopAfter&&this.emittedTotal>=i.stopAfter);e++)this.emitOne();this.emitTimer-=s}}emitOne(){var e,t,r,i,a,s,o,l,c,u;const d=this.params,h=g(d.emitZone),p=v(d.speed,0);let y,m;if(d.moveTo){const e=d.moveTo.x-h.x,t=d.moveTo.y-h.y,r=Math.hypot(e,t)||1;y=e/r*(p||100),m=t/r*(p||100)}else if(null!=d.speedX||null!=d.speedY)y=v(d.speedX,0),m=v(d.speedY,0);else{const e=v(d.angle,0)*Math.PI/180;y=Math.cos(e)*p,m=Math.sin(e)*p}const E=v(d.accelerationX,0),b=v(d.accelerationY,0),T=null!=d.scaleX?v(d.scaleX,1):v(d.scale,1),M=null!=d.scaleY?v(d.scaleY,1):v(d.scale,1),A=v(d.alpha,1),P=v(d.rotate,0),w=Array.isArray(d.tint)?d.tint[Math.floor(Math.random()*d.tint.length)]:null!==(e=d.tint)&&void 0!==e?e:16777215,O=this.frameTextures?this.frameTextures[Math.floor(Math.random()*this.frameTextures.length)]:this.texture,S=new n.Particle({texture:O,x:h.x,y:h.y,scaleX:T,scaleY:M,alpha:A,rotation:P,tint:w,anchorX:.5,anchorY:.5}),_={particle:S,age:0,lifespan:v(d.lifespan,1e3),vx:y,vy:m,ax:E,ay:b,rotateSpeed:0},R=x(d.scale),I=x(d.scaleX),Y=x(d.scaleY);if(R||I||Y){const e=null!==(r=null!==(t=null==I?void 0:I.start)&&void 0!==t?t:null==R?void 0:R.start)&&void 0!==r?r:T,n=null!==(a=null!==(i=null==I?void 0:I.end)&&void 0!==i?i:null==R?void 0:R.end)&&void 0!==a?a:T,d=null!==(o=null!==(s=null==Y?void 0:Y.start)&&void 0!==s?s:null==R?void 0:R.start)&&void 0!==o?o:M,h=null!==(c=null!==(l=null==Y?void 0:Y.end)&&void 0!==l?l:null==R?void 0:R.end)&&void 0!==c?c:M;_.scaleStart={x:e,y:d},_.scaleEnd={x:n,y:h},_.scaleEase=f(null!==(u=null==I?void 0:I.ease)&&void 0!==u?u:null==R?void 0:R.ease),S.scaleX=e,S.scaleY=d}const j=x(d.alpha);j&&(_.alphaStart=j.start,_.alphaEnd=j.end,_.alphaEase=f(j.ease),S.alpha=j.start),this.particles.push(_),this.container.particleChildren.push(S),this.emittedTotal++}}function b(e){return!!e&&!0===e.isTexture&&!!e.orig&&!!e.uvs}function T(e,t,r){if(b(e))return{texture:e,frameTextures:null};if(e&&"object"==typeof e){const n=r=>{var n;const i=null!==(n=e[t+"_s|r|c_"+r])&&void 0!==n?n:e[r];return b(i)?i:null},i=Array.isArray(r)?r:r?[r]:[],a=[];for(const e of i){const t=n(e);t&&a.push(t)}if(a.length>0)return{texture:a[0],frameTextures:a};for(const t in e){const r=e[t];if(b(r))return{texture:r,frameTextures:null}}}return{texture:null,frameTextures:null}}let M=class extends r.Renderer{constructor(){super(...arguments),this.name="ParticleEmitter",this.records={},this.lastDeltaTime=1e3/60}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}update(e){(null==e?void 0:e.deltaTime)&&(this.lastDeltaTime=e.deltaTime),super.update(e)}rendererUpdate(e){const t=this.records[e.id];t&&(t.emitter.setParams(t.component),t.emitter.update(this.lastDeltaTime))}componentChanged(e){var r,i,a,o;return s(this,void 0,void 0,function*(){if("ParticleEmitter"!==e.componentName)return;const s=e.component,l=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){const r=this.increaseAsyncId(l);let i=null,a=null;if(s.resource){const{instance:n}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(l,r))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s ParticleEmitter resource load error`);const o=T(n,s.resource,s.frame);i=o.texture,a=o.frameTextures}if(!i)return;const o=new n.ParticleContainer({dynamicProperties:{position:!0,rotation:!0,scale:!0,color:!0,uvs:!0}});o.texture=i,this.containerManager.getContainer(l).addChildAt(o,0);const c=new E(s,o,i);c.setFrameTextures(a),this.records[l]={container:o,emitter:c,component:s}}else if(e.type===t.OBSERVER_TYPE.CHANGE){const n=this.records[l];if(!n)return;if("resource"===(null===(i=null===(r=e.prop)||void 0===r?void 0:r.prop)||void 0===i?void 0:i[0])){const e=this.increaseAsyncId(l),{instance:r}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(l,e))return;if(r){const e=T(r,s.resource,s.frame);e.texture&&(n.container.texture=e.texture,n.emitter.setTexture(e.texture)),n.emitter.setFrameTextures(e.frameTextures)}}n.component=s,n.emitter.setParams(s)}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(l);const e=this.records[l];if(!e)return;e.emitter.destroy(),null===(o=null===(a=this.containerManager)||void 0===a?void 0:a.getContainer(l))||void 0===o||o.removeChild(e.container),e.container.destroy({children:!0}),delete this.records[l]}})}destroy(){var e,t;for(const r in this.records){const n=parseInt(r),i=this.records[n];i.emitter.destroy(),null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(n))||void 0===t||t.removeChild(i.container),i.container.destroy({children:!0}),delete this.records[n]}}};M.systemName="ParticleEmitter",M=i([t.decorators.componentObserver({ParticleEmitter:[{prop:["resource"],deep:!1}]})],M);var A=M;return e.Emitter=E,e.ParticleEmitter=h,e.ParticleEmitterSystem=A,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.particle=globalThis.EVA.plugin.renderer.particle||_EVA_IIFE_particle;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_particle=function(e,t,r,n){"use strict";function i(e,t,r,n){var i,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,r,a):i(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function a(e,t,r,n){return new(r||(r=Promise))(function(i,s){function a(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,o)}l((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class o extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const l="IDE_PROPERTY_METADATA";function c(e,t,r,n){let i=Reflect.getMetadata("design:type",e,t),s=i===Array;const a=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(i);if("unknown"!==a&&(i=a),n){const e=n();Array.isArray(e)?(s=!0,i=e[0]):i=e}const o=Reflect.getMetadata(l,e.constructor)||{},c=_extends(_extends(_extends({},o[t]||{}),{type:i,isArray:s}),r);o[t]=c,Reflect.defineMetadata(l,o,e.constructor);!function(e,t,r){const n=e.constructor,i=n.IDEProps||{};i[t]=_extends(_extends({key:t},i[t]),r),n.IDEProps=i}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(c,["isArray"]))}function u(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new o;const{options:i,returnTypeFunc:s}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);c(e,n,i,s)};var t,r}var d;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(d||(d={}));class h extends t.Component{constructor(){super(...arguments),this.resource="",this.auto=!0,this.duration=-1,this.frequency=250,this.quantity=1,this.maxParticles=500,this.lifespan=1e3,this.gravityX=0,this.gravityY=0,this.paused=!1}init(e){e&&_extends(this,e)}stop(){this.paused=!0}start(){this.paused=!1}}h.componentName="ParticleEmitter",i([u("string"),s("design:type",String)],h.prototype,"resource",void 0),i([u("boolean"),s("design:type",Boolean)],h.prototype,"auto",void 0),i([u("number"),s("design:type",Number)],h.prototype,"duration",void 0),i([u("number"),s("design:type",Number)],h.prototype,"frequency",void 0),i([u("number"),s("design:type",Number)],h.prototype,"quantity",void 0),i([u("number"),s("design:type",Number)],h.prototype,"maxParticles",void 0),i([u("number"),s("design:type",Number)],h.prototype,"gravityX",void 0),i([u("number"),s("design:type",Number)],h.prototype,"gravityY",void 0);const p=2*Math.PI,y={linear:e=>e,"sine.in":e=>1-Math.cos(e*Math.PI/2),"sine.out":e=>Math.sin(e*Math.PI/2),"sine.inout":e=>-(Math.cos(Math.PI*e)-1)/2,"quad.in":e=>e*e,"quad.out":e=>1-(1-e)*(1-e),"quad.inout":e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,"cubic.in":e=>e*e*e,"cubic.out":e=>1-Math.pow(1-e,3),"expo.out":e=>1===e?1:1-Math.pow(2,-10*e)};function f(e){if(!e)return y.linear;const t=e.toLowerCase();return y[t]||y.linear}function m(e,t){return e+Math.random()*(t-e)}function v(e,t=0){return null==e?t:"number"==typeof e?e:Array.isArray(e)?e[Math.floor(Math.random()*e.length)]:"min"in e&&"max"in e?m(e.min,e.max):"start"in e&&"end"in e?e.start:t}function x(e){return null==e||"number"==typeof e||Array.isArray(e)?null:"start"in e&&"end"in e?e:null}function g(e){return e?function(e,t){var r,n,i,s,a,o,l,c;switch(e.type){case"point":return{x:null!==(r=e.x)&&void 0!==r?r:0,y:null!==(n=e.y)&&void 0!==n?n:0};case"rect":{const r=null!==(i=e.x)&&void 0!==i?i:0,n=null!==(s=e.y)&&void 0!==s?s:0;if(t){const t=2*(e.width+e.height),i=Math.random()*t;return i<e.width?{x:r+i,y:n}:i<e.width+e.height?{x:r+e.width,y:n+(i-e.width)}:i<2*e.width+e.height?{x:r+e.width-(i-e.width-e.height),y:n+e.height}:{x:r,y:n+e.height-(i-2*e.width-e.height)}}return{x:m(r,r+e.width),y:m(n,n+e.height)}}case"circle":{const r=null!==(a=e.x)&&void 0!==a?a:0,n=null!==(o=e.y)&&void 0!==o?o:0,i=Math.random()*p,s=t?e.radius:e.radius*Math.sqrt(Math.random());return{x:r+Math.cos(i)*s,y:n+Math.sin(i)*s}}case"ellipse":{const r=null!==(l=e.x)&&void 0!==l?l:0,n=null!==(c=e.y)&&void 0!==c?c:0,i=Math.random()*p,s=t?1:Math.sqrt(Math.random());return{x:r+Math.cos(i)*e.rx*s,y:n+Math.sin(i)*e.ry*s}}case"line":{const t=Math.random();return{x:e.x1+(e.x2-e.x1)*t,y:e.y1+(e.y2-e.y1)*t}}}}(e.shape,"edge"===e.type):{x:0,y:0}}class E{constructor(e,t,r){this.frameTextures=null,this.particles=[],this.elapsed=0,this.emittedTotal=0,this.emitTimer=0,this.explodeDone=!1,this.params=e,this.container=t,this.texture=r}setTexture(e){this.texture=e}setFrameTextures(e){this.frameTextures=e&&e.length>0?e:null}setParams(e){this.params=e}destroy(){this.particles.length=0,this.container.particleChildren.length=0,this.container.update()}update(e){this.elapsed+=e,this.advanceParticles(e),this.spawn(e),this.container.update()}advanceParticles(e){var t,r;const n=e/1e3,i=[];for(const s of this.particles){if(s.age+=e,s.age>s.lifespan)continue;s.vx+=s.ax*n+(null!==(t=this.params.gravityX)&&void 0!==t?t:0)*n,s.vy+=s.ay*n+(null!==(r=this.params.gravityY)&&void 0!==r?r:0)*n,s.particle.x+=s.vx*n,s.particle.y+=s.vy*n,s.particle.rotation+=s.rotateSpeed*n;const a=s.age/s.lifespan;if(s.scaleStart&&s.scaleEnd){const e=(s.scaleEase||y.linear)(a);s.particle.scaleX=s.scaleStart.x+(s.scaleEnd.x-s.scaleStart.x)*e,s.particle.scaleY=s.scaleStart.y+(s.scaleEnd.y-s.scaleStart.y)*e}if(null!=s.alphaStart&&null!=s.alphaEnd){const e=(s.alphaEase||y.linear)(a);s.particle.alpha=s.alphaStart+(s.alphaEnd-s.alphaStart)*e}this.params.deathZone&&this.shouldDie(s.particle.x,s.particle.y)||i.push(s)}this.particles=i,this.container.particleChildren.length=0;for(const e of this.particles)this.container.particleChildren.push(e.particle)}shouldDie(e,t){const r=this.params.deathZone;if(!r)return!1;const n=function(e,t,r){var n,i,s,a,o,l;switch(e.type){case"rect":{const s=null!==(n=e.x)&&void 0!==n?n:0,a=null!==(i=e.y)&&void 0!==i?i:0;return t>=s&&t<=s+e.width&&r>=a&&r<=a+e.height}case"circle":{const n=t-(null!==(s=e.x)&&void 0!==s?s:0),i=r-(null!==(a=e.y)&&void 0!==a?a:0);return n*n+i*i<=e.radius*e.radius}case"ellipse":{const n=(t-(null!==(o=e.x)&&void 0!==o?o:0))/e.rx,i=(r-(null!==(l=e.y)&&void 0!==l?l:0))/e.ry;return n*n+i*i<=1}case"point":case"line":return!1}}(r.shape,e,t);return"onLeave"===r.mode?!n:n}spawn(e){var t,r,n;const i=this.params;if(null!=i.duration&&i.duration>0&&this.elapsed>i.duration)return;if(null!=i.stopAfter&&this.emittedTotal>=i.stopAfter)return;if(i.paused)return;const s=null!==(t=i.maxParticles)&&void 0!==t?t:500;if(this.particles.length>=s)return;if(null!=i.explode&&!this.explodeDone){const e=Math.min(i.explode,s-this.particles.length);for(let t=0;t<e;t++)this.emitOne();return void(this.explodeDone=!0)}if(null!=i.explode)return;if(!1===i.auto)return;this.emitTimer+=e;const a=null!==(r=i.frequency)&&void 0!==r?r:250,o=null!==(n=i.quantity)&&void 0!==n?n:1;for(;this.emitTimer>=a&&this.particles.length<s;){for(let e=0;e<o&&this.particles.length<s&&!(null!=i.stopAfter&&this.emittedTotal>=i.stopAfter);e++)this.emitOne();this.emitTimer-=a}}emitOne(){var e,t,r,i,s,a,o,l,c,u;const d=this.params,h=g(d.emitZone),p=v(d.speed,0);let y,m;if(d.moveTo){const e=d.moveTo.x-h.x,t=d.moveTo.y-h.y,r=Math.hypot(e,t)||1;y=e/r*(p||100),m=t/r*(p||100)}else if(null!=d.speedX||null!=d.speedY)y=v(d.speedX,0),m=v(d.speedY,0);else{const e=v(d.angle,0)*Math.PI/180;y=Math.cos(e)*p,m=Math.sin(e)*p}const E=v(d.accelerationX,0),b=v(d.accelerationY,0),T=null!=d.scaleX?v(d.scaleX,1):v(d.scale,1),M=null!=d.scaleY?v(d.scaleY,1):v(d.scale,1),A=v(d.alpha,1),P=v(d.rotate,0),w=Array.isArray(d.tint)?d.tint[Math.floor(Math.random()*d.tint.length)]:null!==(e=d.tint)&&void 0!==e?e:16777215,O=this.frameTextures?this.frameTextures[Math.floor(Math.random()*this.frameTextures.length)]:this.texture,S=new n.Particle({texture:O,x:h.x,y:h.y,scaleX:T,scaleY:M,alpha:A,rotation:P,tint:w,anchorX:.5,anchorY:.5}),_={particle:S,age:0,lifespan:v(d.lifespan,1e3),vx:y,vy:m,ax:E,ay:b,rotateSpeed:0},R=x(d.scale),I=x(d.scaleX),Y=x(d.scaleY);if(R||I||Y){const e=null!==(r=null!==(t=null==I?void 0:I.start)&&void 0!==t?t:null==R?void 0:R.start)&&void 0!==r?r:T,n=null!==(s=null!==(i=null==I?void 0:I.end)&&void 0!==i?i:null==R?void 0:R.end)&&void 0!==s?s:T,d=null!==(o=null!==(a=null==Y?void 0:Y.start)&&void 0!==a?a:null==R?void 0:R.start)&&void 0!==o?o:M,h=null!==(c=null!==(l=null==Y?void 0:Y.end)&&void 0!==l?l:null==R?void 0:R.end)&&void 0!==c?c:M;_.scaleStart={x:e,y:d},_.scaleEnd={x:n,y:h},_.scaleEase=f(null!==(u=null==I?void 0:I.ease)&&void 0!==u?u:null==R?void 0:R.ease),S.scaleX=e,S.scaleY=d}const j=x(d.alpha);j&&(_.alphaStart=j.start,_.alphaEnd=j.end,_.alphaEase=f(j.ease),S.alpha=j.start),this.particles.push(_),this.container.particleChildren.push(S),this.emittedTotal++}}function b(e){return!!e&&!0===e.isTexture&&!!e.orig&&!!e.uvs}function T(e,t,r){if(b(e))return{texture:e,frameTextures:null};if(e&&"object"==typeof e){const n=r=>{var n;const i=null!==(n=e[t+"_s|r|c_"+r])&&void 0!==n?n:e[r];return b(i)?i:null},i=Array.isArray(r)?r:r?[r]:[],s=[];for(const e of i){const t=n(e);t&&s.push(t)}if(s.length>0)return{texture:s[0],frameTextures:s};for(const t in e){const r=e[t];if(b(r))return{texture:r,frameTextures:null}}}return{texture:null,frameTextures:null}}let M=class extends r.Renderer{constructor(){super(...arguments),this.name="ParticleEmitter",this.records={},this.lastDeltaTime=1e3/60}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}update(e){(null==e?void 0:e.deltaTime)&&(this.lastDeltaTime=e.deltaTime),super.update(e)}rendererUpdate(e){const t=this.records[e.id];t&&(t.emitter.setParams(t.component),t.emitter.update(this.lastDeltaTime))}componentChanged(e){var r,i,s,o;return a(this,void 0,void 0,function*(){if("ParticleEmitter"!==e.componentName)return;const a=e.component,l=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){const r=this.increaseAsyncId(l);let i=null,s=null;if(a.resource){const{instance:n}=yield t.resource.getResource(a.resource);if(!this.validateAsyncId(l,r))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s ParticleEmitter resource load error`);const o=T(n,a.resource,a.frame);i=o.texture,s=o.frameTextures}if(!i)return;const o=new n.ParticleContainer({dynamicProperties:{position:!0,rotation:!0,scale:!0,color:!0,uvs:!0}});o.texture=i,this.containerManager.getContainer(l).addChildAt(o,0);const c=new E(a,o,i);c.setFrameTextures(s),this.records[l]={container:o,emitter:c,component:a}}else if(e.type===t.OBSERVER_TYPE.CHANGE){const n=this.records[l];if(!n)return;if("resource"===(null===(i=null===(r=e.prop)||void 0===r?void 0:r.prop)||void 0===i?void 0:i[0])){const e=this.increaseAsyncId(l),{instance:r}=yield t.resource.getResource(a.resource);if(!this.validateAsyncId(l,e))return;if(r){const e=T(r,a.resource,a.frame);e.texture&&(n.container.texture=e.texture,n.emitter.setTexture(e.texture)),n.emitter.setFrameTextures(e.frameTextures)}}n.component=a,n.emitter.setParams(a)}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(l);const e=this.records[l];if(!e)return;e.emitter.destroy(),null===(o=null===(s=this.containerManager)||void 0===s?void 0:s.getContainer(l))||void 0===o||o.removeChild(e.container),e.container.destroy({children:!0}),delete this.records[l]}})}destroy(){var e,t;for(const r in this.records){const n=parseInt(r),i=this.records[n];i.emitter.destroy(),null===(t=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(n))||void 0===t||t.removeChild(i.container),i.container.destroy({children:!0}),delete this.records[n]}}};M.systemName="ParticleEmitter",M=i([t.decorators.componentObserver({ParticleEmitter:[{prop:["resource"],deep:!1}]})],M);var A=M;return e.Emitter=E,e.ParticleEmitter=h,e.ParticleEmitterSystem=A,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.particle=globalThis.EVA.plugin.renderer.particle||_EVA_IIFE_particle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-particle",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.4",
4
4
  "description": "@eva/plugin-renderer-particle",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-particle.esm.js",
@@ -20,8 +20,8 @@
20
20
  "homepage": "https://eva.js.org",
21
21
  "dependencies": {
22
22
  "@eva/inspector-decorator": "^2.0.0-beta.0",
23
- "@eva/eva.js": "2.1.0-beta.2",
24
- "@eva/plugin-renderer": "2.1.0-beta.2",
23
+ "@eva/eva.js": "2.1.0-beta.4",
24
+ "@eva/plugin-renderer": "2.1.0-beta.4",
25
25
  "pixi.js": "^8.6.3"
26
26
  }
27
27
  }