UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 3.76 kB
import{Curve as e}from"../../../core/math/curve.js";import{CurveSet as t}from"../../../core/math/curve-set.js";import{Vec3 as r}from"../../../core/math/vec3.js";import{Asset as a}from"../../asset/asset.js";import{ComponentSystem as s}from"../system.js";import{ParticleSystemComponent as i}from"./component.js";import{ParticleSystemComponentData as o}from"./data.js";const n=["enabled","autoPlay","numParticles","lifetime","rate","rate2","startAngle","startAngle2","loop","preWarm","lighting","halfLambert","intensity","depthWrite","noFog","depthSoftening","sort","blendType","stretch","alignToMotion","emitterShape","emitterExtents","emitterExtentsInner","emitterRadius","emitterRadiusInner","emitterLength","emitterLengthInner","initialVelocity","wrap","wrapBounds","localSpace","screenSpace","colorMapAsset","normalMapAsset","mesh","meshAsset","renderAsset","orientation","particleNormal","localVelocityGraph","localVelocityGraph2","velocityGraph","velocityGraph2","rotationSpeedGraph","rotationSpeedGraph2","radialSpeedGraph","radialSpeedGraph2","scaleGraph","scaleGraph2","colorGraph","colorGraph2","alphaGraph","alphaGraph2","colorMap","normalMap","animTilesX","animTilesY","animStartFrame","animNumFrames","animNumAnimations","animIndex","randomizeAnimIndex","animSpeed","animLoop","layers"];class p extends s{constructor(e){super(e),this.id="particlesystem",this.ComponentType=i,this.DataType=o,this.schema=n,this.propertyTypes={emitterExtents:"vec3",emitterExtentsInner:"vec3",particleNormal:"vec3",wrapBounds:"vec3",localVelocityGraph:"curveset",localVelocityGraph2:"curveset",velocityGraph:"curveset",velocityGraph2:"curveset",colorGraph:"curveset",colorGraph2:"curveset",alphaGraph:"curve",alphaGraph2:"curve",rotationSpeedGraph:"curve",rotationSpeedGraph2:"curve",radialSpeedGraph:"curve",radialSpeedGraph2:"curve",scaleGraph:"curve",scaleGraph2:"curve"},this.on("beforeremove",this.onBeforeRemove,this),this.app.systems.on("update",this.onUpdate,this)}initializeComponentData(s,i,o){const n={};o=[];const p=this.propertyTypes;(i.mesh instanceof a||"number"==typeof i.mesh)&&(i.meshAsset=i.mesh,delete i.mesh);for(const a in i){if(i.hasOwnProperty(a)&&(o.push(a),n[a]=i[a]),"vec3"===p[a])Array.isArray(n[a])&&(n[a]=new r(n[a][0],n[a][1],n[a][2]));else if("curve"===p[a]){if(!(n[a]instanceof e)){const t=n[a].type;n[a]=new e(n[a].keys),n[a].type=t}}else if("curveset"===p[a]&&!(n[a]instanceof t)){const e=n[a].type;n[a]=new t(n[a].keys),n[a].type=e}n.layers&&Array.isArray(n.layers)&&(n.layers=n.layers.slice(0))}super.initializeComponentData(s,n,o)}cloneComponent(a,s){const i=a.particlesystem.data,o=this.schema,n={};for(let a=0,s=o.length;a<s;a++){const s=o[a];let p=i[s];p instanceof r||p instanceof e||p instanceof t?(p=p.clone(),n[s]=p):"layers"===s?n.layers=i.layers.slice(0):null!=p&&(n[s]=p)}return this.addComponent(s,n)}onUpdate(e){const t=this.store;let r;const a=this.app.stats.particles,s=this.app.scene.layers;for(let e=0;e<s.layerList.length;e++)s.layerList[e].requiresLightCube=!1;for(const i in t)if(t.hasOwnProperty(i)){const o=t[i],n=o.entity,p=o.data;if(p.enabled&&n.enabled){const t=n.particlesystem.emitter;if(null==t||!t.meshInstance.visible)continue;if(t.lighting){const e=p.layers;for(let t=0;t<e.length;t++){const r=s.getLayerById(e[t]);r&&(r.requiresLightCube=!0)}}if(!p.paused){if(t.simTime+=e,t.simTime>t.fixedTimeStep&&(r=Math.floor(t.simTime/t.fixedTimeStep),t.simTime-=r*t.fixedTimeStep),r){r=Math.min(r,t.maxSubSteps);for(let e=0;e<r;e++)t.addTime(t.fixedTimeStep,!1);a._updatesPerFrame+=r,a._frameTime+=t._addTimeTime,t._addTimeTime=0}t.finishFrame()}}}}onBeforeRemove(e,t){t.onBeforeRemove()}destroy(){super.destroy(),this.app.systems.off("update",this.onUpdate,this)}}export{p as ParticleSystemComponentSystem};