@hology/core 0.0.44 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/dist/csm.d.ts +8 -2
  2. package/dist/csm.js +1 -1
  3. package/dist/effects/vfx/behaviours.d.ts +28 -0
  4. package/dist/effects/vfx/behaviours.js +1 -1
  5. package/dist/effects/vfx/initializsers.d.ts +16 -0
  6. package/dist/effects/vfx/initializsers.js +1 -1
  7. package/dist/effects/vfx/rates.d.ts +7 -2
  8. package/dist/effects/vfx/rates.js +1 -1
  9. package/dist/effects/vfx/vfx-actor.js +1 -1
  10. package/dist/effects/vfx/vfx-asset.d.ts +7 -5
  11. package/dist/effects/vfx/vfx-asset.js +1 -1
  12. package/dist/effects/vfx/vfx-defs.d.ts +28 -2
  13. package/dist/effects/vfx/vfx-defs.js +1 -1
  14. package/dist/effects/vfx/vfx-materializer.d.ts +2 -2
  15. package/dist/effects/vfx/vfx-materializer.js +1 -1
  16. package/dist/effects/vfx/vfx-param.d.ts +31 -1
  17. package/dist/effects/vfx/vfx-param.js +1 -1
  18. package/dist/effects/vfx/vfx-renderers.d.ts +36 -0
  19. package/dist/effects/vfx/vfx-renderers.js +5 -0
  20. package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
  21. package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +3 -0
  22. package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
  23. package/dist/gameplay/services/physics/physics-system.js +1 -1
  24. package/dist/rendering.d.ts +1 -1
  25. package/dist/rendering.js +1 -1
  26. package/dist/scene/asset-resource-loader.js +1 -1
  27. package/dist/scene/landscape/landscape-manager.js +1 -1
  28. package/dist/scene/landscape/landscape.js +1 -1
  29. package/dist/scene/materializer.d.ts +3 -2
  30. package/dist/scene/materializer.js +1 -1
  31. package/dist/scene/objects/ramp-geometry.d.ts +1 -1
  32. package/dist/scene/objects/shapes.d.ts +3 -3
  33. package/dist/scene/objects/stairs-geometry.d.ts +2 -2
  34. package/dist/scene/scene-data-service.js +1 -1
  35. package/dist/scene/sky.d.ts +1 -1
  36. package/dist/scene/sky.js +1 -1
  37. package/dist/shader-nodes/particle.d.ts +1 -0
  38. package/dist/shader-nodes/particle.js +1 -1
  39. package/dist/utils/materials.d.ts +2 -1
  40. package/dist/utils/three/outline-pass.d.ts +8 -8
  41. package/dist/utils/three/positional-audio-helper.d.ts +2 -1
  42. package/dist/utils/three/transform-controls.d.ts +5 -3
  43. package/dist/utils/three/traverse.d.ts +1 -1
  44. package/package.json +8 -8
  45. package/tsconfig.tsbuildinfo +1 -1
package/dist/csm.d.ts CHANGED
@@ -1,7 +1,13 @@
1
- import { Material, Shader } from 'three';
1
+ import { Material } from 'three';
2
2
  import { RenderingView } from './rendering.js';
3
+ import * as THREE from 'three';
3
4
  export declare const CSMUtil: {
4
5
  renderingView: RenderingView;
5
- onBeforeCompile(material: Material, shader: Shader): void;
6
+ onBeforeCompile(material: Material, shader: THREE.WebGLProgramParametersWithUniforms): void;
6
7
  patchThreeAdd(): void;
7
8
  };
9
+ export declare const CSMShader: {
10
+ lights_fragment_begin: (cascades: number) => string;
11
+ lights_fragment_begi2: (cascades: number) => string;
12
+ lights_pars_begin: (maxCascades: number) => string;
13
+ };
package/dist/csm.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as e from"three";const n=e.Object3D.prototype.add,r=new WeakMap,a=new WeakMap;export const CSMUtil=new class{constructor(){this.renderingView=null}onBeforeCompile(n,r){n.defines=n.defines||{},n.defines.USE_CSM=1,n.defines.CSM_CASCADES=this.renderingView.csm.cascades;const a=this.renderingView.camera instanceof e.PerspectiveCamera?this.renderingView.camera.far:Number.MAX_SAFE_INTEGER,t=this.renderingView.camera instanceof e.PerspectiveCamera?this.renderingView.camera.near:0,i=Math.min(a,this.renderingView.csm.maxFar),s=[];this.renderingView.csm.getExtendedBreaks(s),r.uniforms.CSM_cascades={value:s},r.uniforms.cameraNear={value:t},r.uniforms.shadowFar={value:i}}patchThreeAdd(){const t=this.renderingView;r.set(t.scene,t.csm),e.Object3D.prototype.add=function(...t){let i=this;for(;null!=i.parent;)i=i.parent;const s=i,c=r.get(s);if(null==c)return n.apply(this,arguments),this;a.has(s)||a.set(s,new WeakSet);const o=a.get(s);function d(e){e&&!o.has(e)&&(o.add(e),c?.setupMaterial(e))}return t.forEach((n=>n?.traverse((n=>{if(n instanceof e.Mesh||n instanceof e.SkinnedMesh)if(n.material instanceof Array)for(const e of n.material)d(e);else d(n.material)})))),n.apply(this,arguments),this}}};
1
+ import*as t from"three";const i={add:t.Object3D.prototype.add,attach:t.Object3D.prototype.attach},e=new WeakMap,n=new WeakMap;export const CSMUtil=new class{constructor(){this.renderingView=null}onBeforeCompile(i,e){i.defines=i.defines||{},i.defines.USE_CSM=1,i.defines.CSM_CASCADES=this.renderingView.csm.cascades,console.log(e.fragmentShader);const n=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.far:Number.MAX_SAFE_INTEGER,o=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.near:0,a=Math.min(n,this.renderingView.csm.maxFar),r=[];this.renderingView.csm.getExtendedBreaks(r),e.uniforms.CSM_cascades={value:r},e.uniforms.cameraNear={value:o},e.uniforms.shadowFar={value:a}}patchThreeAdd(){const o=this.renderingView;e.set(o.scene,o.csm);for(const[o,a]of Object.entries(i))t.Object3D.prototype[o]=function(...i){let o=this;for(;null!=o.parent;)o=o.parent;const r=o,d=e.get(r);if(null==d)return a.apply(this,arguments),this;n.has(r)||n.set(r,new WeakSet);const h=n.get(r);function c(t){t&&!h.has(t)&&(h.add(t),d?.setupMaterial(t))}return i.forEach((i=>i?.traverse((i=>{if(i instanceof t.Mesh||i instanceof t.SkinnedMesh)if(i.material instanceof Array)for(const t of i.material)c(t);else c(i.material)})))),a.apply(this,arguments),this}}};import{ShaderChunk as o}from"three";const a=o.lights_pars_begin;export const CSMShader={lights_fragment_begin:t=>"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n\n#ifdef USE_CLEARCOAT\n\n\tgeometryClearcoatNormal = clearcoatNormal;\n\n#endif\n\n#ifdef USE_IRIDESCENCE\n\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\n\tif ( material.iridescenceThickness == 0.0 ) {\n\n\t\tmaterial.iridescence = 0.0;\n\n\t} else {\n\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\n\t}\n\n\tif ( material.iridescence > 0.0 ) {\n\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\n\t\t// Iridescence F0 approximation\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\n\t}\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n\t\tpointLight = pointLights[ i ];\n\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n\t\tspotLight = spotLights[ i ];\n\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\n\t\t// spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n\tRectAreaLight rectAreaLight;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n\tvec3 iblIrradiance = vec3( 0.0 );\n\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n\t#if defined( USE_LIGHT_PROBES )\n\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\n\t#endif\n\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n\t",lights_fragment_begi2:t=>`\nGeometricContext geometry;\n\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\n#ifdef CLEARCOAT\n\n\tgeometry.clearcoatNormal = clearcoatNormal;\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n\t\tpointLight = pointLights[ i ];\n\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n\t\tspotLight = spotLights[ i ];\n\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0) && defined( RE_Direct ) && defined( USE_CSM ) && defined( CSM_CASCADES )\n\n\tDirectionalLight directionalLight;\n\tfloat linearDepth = (vViewPosition.z) / (shadowFar - cameraNear);\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#if defined( USE_SHADOWMAP ) && defined( CSM_FADE ) && CSM_FADE == 1\n\tvec2 cascade;\n\tfloat cascadeCenter;\n\tfloat closestEdge;\n\tfloat margin;\n\tfloat csmx;\n\tfloat csmy;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t \t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\t\t// NOTE: Depth gets larger away from the camera.\n\t\t\t// cascade.x is closer, cascade.y is further\n\n\t\t\t\t#if ( UNROLLED_LOOP_INDEX < ${t} )\n\n\t\t\t\t\t// NOTE: Apply CSM shadows\n\n\t\t\t\t\tcascade = CSM_cascades[ i ];\n\t\t\t\t\tcascadeCenter = ( cascade.x + cascade.y ) / 2.0;\n\t\t\t\t\tclosestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;\n\t\t\t\t\tmargin = 0.25 * pow( closestEdge, 2.0 );\n\t\t\t\t\tcsmx = cascade.x - margin / 2.0;\n\t\t\t\t\tcsmy = cascade.y + margin / 2.0;\n\t\t\t\t\tif( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {\n\n\t\t\t\t\t\tfloat dist = min( linearDepth - csmx, csmy - linearDepth );\n\t\t\t\t\t\tfloat ratio = clamp( dist / margin, 0.0, 1.0 );\n\n\t\t\t\t\t\tvec3 prevColor = directLight.color;\n\t\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\t\tbool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;\n\t\t\t\t\t\tdirectLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );\n\n\t\t\t\t\t\tReflectedLight prevLight = reflectedLight;\n\t\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t\t\tbool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;\n\t\t\t\t\t\tfloat blendRatio = shouldBlend ? ratio : 1.0;\n\n\t\t\t\t\t\treflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );\n\t\t\t\t\t\treflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );\n\t\t\t\t\t\treflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );\n\t\t\t\t\t\treflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );\n\n\t\t\t\t\t}\n\n\t\t\t\t#else\n\n\t\t\t\t\t// NOTE: Apply the reminder of directional lights\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#endif\n\n\t \t#endif\n\n\t}\n\t#pragma unroll_loop_end\n\t#else\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\t\tdirectionalLight = directionalLights[ i ];\n\t\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) \n\n\t\t\t\t#if ( UNROLLED_LOOP_INDEX < ${t} )\n\n\t\t\t\t\t// NOTE: Apply CSM shadows\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#else\n\n\t\t\t\t\t// NOTE: Apply the reminder of directional lights\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\n\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n\t#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)\n\t\t// compute the lights not casting shadows (if any)\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = NUM_DIR_LIGHT_SHADOWS; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\t\tdirectionalLight = directionalLights[ i ];\n\n\t\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) && !defined( USE_CSM ) && !defined( CSM_CASCADES )\n\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n\tRectAreaLight rectAreaLight;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n\tvec3 iblIrradiance = vec3( 0.0 );\n\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n`,lights_pars_begin:t=>a};
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,5 @@
1
1
  import { Behaviour, Emitter, Particle, EasingFunction } from "three-nebula";
2
+ import * as THREE from 'three';
2
3
  /**
3
4
  * Rotate position around an axis.
4
5
  */
@@ -9,11 +10,38 @@ export declare class RotatePosition extends Behaviour {
9
10
  private axis3D;
10
11
  mutate(target: Particle | Emitter, time: number, index: number): void;
11
12
  }
13
+ export declare enum AxisDirection {
14
+ x = 0,
15
+ y = 1,
16
+ z = 2,
17
+ mx = 3,
18
+ my = 4,
19
+ mz = 5
20
+ }
21
+ export declare class OrientAlongVelocity extends Behaviour {
22
+ private axisDirection;
23
+ constructor(axisDirection: AxisDirection);
24
+ initialize(particle: Particle): void;
25
+ mutate(target: Particle | Emitter, time: number, index: number): void;
26
+ }
12
27
  export declare class LinearDamping extends Behaviour {
13
28
  private factor;
14
29
  constructor(factor: number);
15
30
  mutate(target: Particle | Emitter, time: number, index: number): void;
16
31
  }
32
+ export declare enum AxisPlane {
33
+ xy = 0,
34
+ xz = 1,
35
+ yz = 2,
36
+ xyz = 3
37
+ }
38
+ export declare class Disperse extends Behaviour {
39
+ private distance;
40
+ private plane;
41
+ constructor(distance: number, plane: AxisPlane, easing?: EasingFunction);
42
+ initialize(particle: Particle): void;
43
+ mutate(target: Particle | Emitter, time: number, index: number): void;
44
+ }
17
45
  export declare class MoveOverLife extends Behaviour {
18
46
  private x;
19
47
  private y;
@@ -1,4 +1,4 @@
1
- import{Behaviour as i,Vector3D as t,ease as s}from"three-nebula";export class RotatePosition extends i{constructor(i,s){super(),this.axis=i,this.angle=s,this.axis3D=new t(this.axis.x,this.axis.y,this.axis.z)}mutate(i,t,s){this.energize(i,t),i.position.sub(i.parent.position),i.position.applyAxisAngle(this.axis3D,this.angle*t),i.position.add(i.parent.position)}}export class LinearDamping extends i{constructor(i){super(),this.factor=i}mutate(i,t,s){this.energize(i,t);const o=e.copy(i.velocity).multiplyScalar(-this.factor*t);i.velocity.add(o)}}const e=new t;export class MoveOverLife extends i{constructor(i,t,e,o=s.easeLinear){super(void 0,o,void 0,!0),this.x=i,this.y=t,this.z=e}initialize(i){i.transform.initialPos=i.position.clone()}mutate(i,t,s){this.energize(i,t);const e=i.transform.initialPos,o=1-this.energy;i.position.x=e.x+this.x*o,i.position.y=e.y+this.y*o,i.position.z=e.z+this.z*o}}
1
+ import{Behaviour as i,Vector3D as t,ease as s}from"three-nebula";import*as e from"three";export class RotatePosition extends i{constructor(i,s){super(),this.axis=i,this.angle=s,this.axis3D=new t(this.axis.x,this.axis.y,this.axis.z)}mutate(i,t,s){this.energize(i,t),i.position.sub(i.parent.position),i.position.applyAxisAngle(this.axis3D,this.angle*t),i.position.add(i.parent.position)}}export var AxisDirection;!function(i){i[i.x=0]="x",i[i.y=1]="y",i[i.z=2]="z",i[i.mx=3]="mx",i[i.my=4]="my",i[i.mz=5]="mz"}(AxisDirection||(AxisDirection={}));export class OrientAlongVelocity extends i{constructor(i){super(),this.axisDirection=i}initialize(i){i.transform.orientAlongVelocity=!0}mutate(i,t,s){i.target,e.Object3D}}export class LinearDamping extends i{constructor(i){super(),this.factor=i}mutate(i,t,s){this.energize(i,t);const e=n.copy(i.velocity).multiplyScalar(-this.factor*t);i.velocity.add(e)}}const n=new t;export var AxisPlane;!function(i){i[i.xy=0]="xy",i[i.xz=1]="xz",i[i.yz=2]="yz",i[i.xyz=3]="xyz"}(AxisPlane||(AxisPlane={}));export class Disperse extends i{constructor(i,t,e=s.easeLinear){super(void 0,e,void 0,!0),this.distance=i,this.plane=t}initialize(i){i.transform.initialPos=i.position.clone();const t=o.copy(i.transform.initialPos).sub(i.parent.position).normalize();switch(this.plane){case AxisPlane.xy:t.setComponent(2,0);break;case AxisPlane.xz:t.setComponent(1,0);break;case AxisPlane.yz:t.setComponent(0,0)}i.transform.displacement=t.clone().multiplyScalar(this.distance),i.transform.prevEnergy=1}mutate(i,t,s){this.energize(i,t);i.transform.initialPos;const e=i.transform.displacement,n=i.transform.prevEnergy-this.energy;i.transform.prevEnergy=this.energy;i.position.x+=e.x*n,i.position.y+=e.y*n,i.position.z+=e.z*n}}export class MoveOverLife extends i{constructor(i,t,e,n=s.easeLinear){super(void 0,n,void 0,!0),this.x=i,this.y=t,this.z=e}initialize(i){i.transform.initialPos=i.position.clone()}mutate(i,t,s){this.energize(i,t);const e=i.transform.initialPos,n=1-this.energy;i.position.x=e.x+this.x*n,i.position.y=e.y+this.y*n,i.position.z=e.z+this.z*n}}const o=new t;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,17 +1,33 @@
1
1
  import { Vector3 } from "three";
2
2
  import { Emitter, Particle } from "three-nebula";
3
+ declare const DefaultInitializer_base: any;
4
+ export declare class DefaultInitializer extends DefaultInitializer_base {
5
+ init(emitter: Emitter, particle: Particle): void;
6
+ }
3
7
  declare const Rotation_base: any;
4
8
  export declare class Rotation extends Rotation_base {
5
9
  private rotation;
6
10
  constructor(rotation: Vector3);
7
11
  init(emitter: Emitter, particle: Particle): void;
8
12
  }
13
+ declare const RandomRotation_base: any;
14
+ export declare class RandomRotation extends RandomRotation_base {
15
+ constructor();
16
+ init(emitter: Emitter, particle: Particle): void;
17
+ private randomAngle;
18
+ }
9
19
  declare const InitialScale_base: any;
10
20
  export declare class InitialScale extends InitialScale_base {
11
21
  private scale;
12
22
  constructor(scale: number);
13
23
  init(emitter: Emitter, particle: Particle): void;
14
24
  }
25
+ declare const InitialScaleComponents_base: any;
26
+ export declare class InitialScaleComponents extends InitialScaleComponents_base {
27
+ private scale;
28
+ constructor(scale: Vector3);
29
+ init(emitter: Emitter, particle: Particle): void;
30
+ }
15
31
  declare const AdditiveVelocity_base: any;
16
32
  export declare class AdditiveVelocity extends AdditiveVelocity_base {
17
33
  private velocity;
@@ -1,4 +1,4 @@
1
- import{Vector3 as t}from"three";import{Span as e,Position as i}from"three-nebula";export class Rotation extends(Object.getPrototypeOf(i)){constructor(t){super(),this.rotation=t}init(t,e){"number"!=typeof e.rotation&&e.rotation.copy(this.rotation)}}export class InitialScale extends(Object.getPrototypeOf(i)){constructor(t){super(),this.scale=t}init(t,e){e.scale=this.scale}}export class AdditiveVelocity extends(Object.getPrototypeOf(i)){constructor(t){super(),this.velocity=t}init(t,e){e.velocity.x+=this.velocity.x,e.velocity.y+=this.velocity.y,e.velocity.z+=this.velocity.z}}export class RandomDirection extends(Object.getPrototypeOf(i)){constructor(t){super(),this.speed=t}init(t,e){s.set(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1).normalize().multiplyScalar(this.speed),e.velocity.x+=s.x,e.velocity.y+=s.y,e.velocity.z+=s.z}}export class RandomComponentsDirection extends(Object.getPrototypeOf(i)){constructor(t,i,s){super(),this.speed=t,this.min=i,this.max=s,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,e){s.set(this.x.getValue(),this.y.getValue(),this.z.getValue()).normalize().multiplyScalar(this.speed),e.velocity.x+=s.x,e.velocity.y+=s.y,e.velocity.z+=s.z}}export class RandomVelocity extends(Object.getPrototypeOf(i)){constructor(t,i){super(),this.min=t,this.max=i,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,e){e.velocity.x+=this.x.getValue(),e.velocity.y+=this.y.getValue(),e.velocity.z+=this.z.getValue()}}const s=new t;
1
+ import{Vector3 as t}from"three";import{Span as e,Position as i}from"three-nebula";export class DefaultInitializer extends(Object.getPrototypeOf(i)){init(t,e){e.parent=t}}export class Rotation extends(Object.getPrototypeOf(i)){constructor(t){super(),this.rotation=t}init(t,e){"number"!=typeof e.rotation&&e.rotation.copy(this.rotation)}}export class RandomRotation extends(Object.getPrototypeOf(i)){constructor(){super()}init(t,e){e.rotation.set(this.randomAngle(),this.randomAngle(),this.randomAngle())}randomAngle(){return 2*Math.PI*Math.random()}}export class InitialScale extends(Object.getPrototypeOf(i)){constructor(t){super(),this.scale=t}init(t,e){e.scale=this.scale}}export class InitialScaleComponents extends(Object.getPrototypeOf(i)){constructor(t){super(),this.scale=t}init(t,e){e.transform.initialScale=this.scale}}export class AdditiveVelocity extends(Object.getPrototypeOf(i)){constructor(t){super(),this.velocity=t}init(t,e){e.velocity.x+=this.velocity.x,e.velocity.y+=this.velocity.y,e.velocity.z+=this.velocity.z}}export class RandomDirection extends(Object.getPrototypeOf(i)){constructor(t){super(),this.speed=t}init(t,e){s.set(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1).normalize().multiplyScalar(this.speed),e.velocity.x+=s.x,e.velocity.y+=s.y,e.velocity.z+=s.z}}export class RandomComponentsDirection extends(Object.getPrototypeOf(i)){constructor(t,i,s){super(),this.speed=t,this.min=i,this.max=s,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,e){s.set(this.x.getValue(),this.y.getValue(),this.z.getValue()).normalize().multiplyScalar(this.speed),e.velocity.x+=s.x,e.velocity.y+=s.y,e.velocity.z+=s.z}}export class RandomVelocity extends(Object.getPrototypeOf(i)){constructor(t,i){super(),this.min=t,this.max=i,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,e){e.velocity.x+=this.x.getValue(),e.velocity.y+=this.y.getValue(),e.velocity.z+=this.z.getValue()}}const s=new t;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,6 +1,11 @@
1
1
  import { Rate } from "three-nebula";
2
+ import type { RateNumPan, RateTimePan } from "three-nebula/src/initializer/Rate";
2
3
  export { Rate } from 'three-nebula';
3
- export declare class OnceRate extends Rate {
4
- constructor(count?: number);
4
+ export declare class DelayRate extends Rate {
5
+ readonly delay: number;
6
+ constructor(delay?: number, numPan?: RateNumPan, timePan?: RateTimePan);
5
7
  restart(): void;
6
8
  }
9
+ export declare class OnceRate extends DelayRate {
10
+ constructor(delay: number, count?: number);
11
+ }
@@ -1,4 +1,4 @@
1
- import{Rate as e}from"three-nebula";export{Rate}from"three-nebula";export class OnceRate extends e{constructor(e=1){super(e,1/0)}restart(){this.nextTime=0}}
1
+ import{Rate as e}from"three-nebula";export{Rate}from"three-nebula";export class DelayRate extends e{constructor(e=0,t,s){super(t,s),this.delay=e,this.restart()}restart(){this.nextTime=0,null!=this.delay&&this.delay>0&&(this.startTime=-this.delay)}}export class OnceRate extends DelayRate{constructor(e,t=1){super(e,t,1/0)}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{__decorate as s}from"tslib";import{Actor as t,BaseActor as e,AssetLoader as i,inject as o,World as r}from"../../gameplay/index.js";import{Rate as a}from"three-nebula";import{materializeVfx as h}from"./vfx-materializer.js";import*as m from"three";let d=class extends e{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=o(i),this.world=o(r),this._worldPos=new m.Vector3,this.max=0}async fromAsset(s){null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((s=>s.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem();const{system:t,dispose:e}=await h(s,this.world.scene,{getAsset:s=>this.assetLoader.getAsset(s),getMaterial:s=>this.assetLoader.getMaterialByAssetId(s),getTexture:s=>this.assetLoader.getTextureByAssetId(s),getMesh:s=>this.assetLoader.getModelByAssetId(s).then((s=>s.scene))});this.system=t,this.disposeSystem=e}play(){this.paused=!1;this.system.emitters.every((s=>s.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((s=>{const t=s.rate;t instanceof a&&(console.log("set rate to infinity",t),t.nextTime=1/0)}))}restart(){for(const s of this.system.emitters){s.rate.nextTime=0,s.removeAllParticles()}}onUpdate(s){this.paused||(this.object.getWorldPosition(this._worldPos),this.system?.emitters.forEach((s=>{s.setPosition(this._worldPos)})),this.system?.update(s*this.timescale))}getParticleCount(){return this.system?.getCount()??0}onEndPlay(){this.stop(),console.log("end play"),null!=this.disposeSystem&&this.disposeSystem()}};d=s([t()],d);export{d as VfxActor};
1
+ import{__decorate as s}from"tslib";import{Actor as t,BaseActor as e,AssetLoader as i,inject as o,World as r}from"../../gameplay/index.js";import{Rate as a}from"three-nebula";import{materializeVfx as h}from"./vfx-materializer.js";import*as m from"three";import{DelayRate as d}from"./rates.js";let n=class extends e{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=o(i),this.world=o(r),this._worldPos=new m.Vector3,this.max=0}async fromAsset(s){null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((s=>s.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem();const{system:t,dispose:e}=await h(s,this.world.scene,{getAsset:s=>this.assetLoader.getAsset(s),getMaterial:s=>this.assetLoader.getMaterialByAssetId(s),getTexture:s=>this.assetLoader.getTextureByAssetId(s),getMesh:s=>this.assetLoader.getModelByAssetId(s).then((s=>s.scene))});this.system=t,this.disposeSystem=e}play(){this.paused=!1;this.system.emitters.every((s=>s.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((s=>{const t=s.rate;t instanceof a&&(console.log("set rate to infinity",t),t.nextTime=1/0)}))}restart(){for(const s of this.system.emitters){const t=s.rate;t instanceof d?t.restart():t.nextTime=0,s.removeAllParticles()}}onUpdate(s){this.paused||(this.object.getWorldPosition(this._worldPos),this.system?.emitters.forEach((s=>{s.setPosition(this._worldPos)})),this.system?.update(s*this.timescale))}getParticleCount(){return this.system?.getCount()??0}onEndPlay(){this.stop(),null!=this.disposeSystem&&this.disposeSystem()}};n=s([t()],n);export{n as VfxActor};
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,15 +1,16 @@
1
1
  import { LibraryShapeType } from '../../scene/objects/shapes.js';
2
2
  import { AssetId, CustomParamValue, SerializedParamType } from '../../scene/model.js';
3
3
  import { LibraryVfxBehaviourType, LibraryVfxInitalizerType } from './vfx-defs.js';
4
- import * as THREE from "three";
5
4
  export type OnceRateData = {
6
5
  type: 'once';
7
6
  count: number;
7
+ delay: number;
8
8
  };
9
9
  export type ContinuousRateData = {
10
10
  type: 'continuous';
11
11
  count: number;
12
12
  time: number;
13
+ delay: number;
13
14
  };
14
15
  export type RateData = OnceRateData | ContinuousRateData;
15
16
  export type InitializerData = {
@@ -26,10 +27,10 @@ export type Vector3Data = [number, number, number];
26
27
  export declare const BlendingModes: readonly ["additive", "subtractive", "multiply", "normal"];
27
28
  export type BlendingMode = (typeof BlendingModes)[number];
28
29
  export declare const ThreeBlendingMode: {
29
- normal: THREE.Blending;
30
- additive: THREE.Blending;
31
- subtractive: THREE.Blending;
32
- multiply: THREE.Blending;
30
+ normal: 1;
31
+ additive: 2;
32
+ subtractive: 3;
33
+ multiply: 4;
33
34
  };
34
35
  export type SpriteOutput = {
35
36
  type: 'sprite';
@@ -75,6 +76,7 @@ export declare function EmitterDataConstructor(): {
75
76
  type: "continuous";
76
77
  count: number;
77
78
  time: number;
79
+ delay: number;
78
80
  };
79
81
  position: [number, number, number];
80
82
  rotation: [number, number, number];
@@ -1,4 +1,4 @@
1
- import{SerializedParamType as t}from"../../scene/model.js";import*as e from"three";import{randomString as i}from"../../utils/math.js";export const BlendingModes=["additive","subtractive","multiply","normal"];export const ThreeBlendingMode={normal:e.NormalBlending,additive:e.AdditiveBlending,subtractive:e.SubtractiveBlending,multiply:e.MultiplyBlending};export function EmitterDataConstructor(){return{id:i(),name:"Emitter",rate:{type:"continuous",count:1,time:.5},position:[0,0,0],rotation:[0,0,0],initializers:[{id:i(),type:"lifetime",params:{duration:{type:t.Number,value:1}}}],behaviours:[],children:[],output:{type:"sprite",texture:null,color:"#ffffff",blendingMode:"normal"}}}
1
+ import{SerializedParamType as t}from"../../scene/model.js";import*as e from"three";import{randomString as i}from"../../utils/math.js";export const BlendingModes=["additive","subtractive","multiply","normal"];export const ThreeBlendingMode={normal:e.NormalBlending,additive:e.AdditiveBlending,subtractive:e.SubtractiveBlending,multiply:e.MultiplyBlending};export function EmitterDataConstructor(){return{id:i(),name:"Emitter",rate:{type:"continuous",count:1,time:.5,delay:0},position:[0,0,0],rotation:[0,0,0],initializers:[{id:i(),type:"lifetime",params:{duration:{type:t.Number,value:1}}}],behaviours:[],children:[],output:{type:"sprite",texture:null,color:"#ffffff",blendingMode:"normal"}}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -99,12 +99,22 @@ declare class RotationDef extends BaseIniDef<RotationDef> {
99
99
  };
100
100
  make(params?: ParamsType<this>): Initializer;
101
101
  }
102
+ declare class RandomRotationDef extends BaseIniDef<RandomRotationDef> {
103
+ parameters: {};
104
+ make(params?: ParamsType<this>): Initializer;
105
+ }
102
106
  declare class InitialScaleDef extends BaseIniDef<InitialScaleDef> {
103
107
  parameters: {
104
108
  scale: FloatParameterDef;
105
109
  };
106
110
  make(params?: ParamsType<this>): Initializer;
107
111
  }
112
+ declare class InitialScaleComponentsDef extends BaseIniDef<InitialScaleComponentsDef> {
113
+ parameters: {
114
+ scale: ShapeParameterDef<Vector3>;
115
+ };
116
+ make(params?: ParamsType<this>): Initializer;
117
+ }
108
118
  declare class ForceDef extends BaseBevDef<ForceDef> {
109
119
  parameters: {
110
120
  force: ShapeParameterDef<Vector3>;
@@ -134,6 +144,14 @@ declare class RandomDriftDef extends BaseBevDef<RandomDriftDef> {
134
144
  };
135
145
  make(params?: ParamsType<this>): Behaviour;
136
146
  }
147
+ declare class DisperseDef extends BaseBevDef<DisperseDef> {
148
+ parameters: {
149
+ distance: FloatParameterDef;
150
+ axis: SelectParameterDef<string>;
151
+ ease: SelectParameterDef<string>;
152
+ };
153
+ make(params?: ParamsType<this>): Behaviour;
154
+ }
137
155
  declare class RotateDef extends BaseBevDef<RotateDef> {
138
156
  parameters: {
139
157
  rotation: ShapeParameterDef<Vector3>;
@@ -141,6 +159,10 @@ declare class RotateDef extends BaseBevDef<RotateDef> {
141
159
  };
142
160
  make(params?: ParamsType<this>): Behaviour;
143
161
  }
162
+ declare class OrientAlongVelocityDef extends BaseBevDef<OrientAlongVelocityDef> {
163
+ parameters: {};
164
+ make(params?: ParamsType<this>): Behaviour;
165
+ }
144
166
  declare class ChangeColorDef extends BaseBevDef<ChangeColorDef> {
145
167
  parameters: {
146
168
  a: ShapeParameterDef<`#${string}`>;
@@ -184,7 +206,9 @@ declare const vfxInitializsers: {
184
206
  positionSphere: PositionSphereDef;
185
207
  positionLine: PositionLineDef;
186
208
  rotation: RotationDef;
209
+ randomRotation: RandomRotationDef;
187
210
  scale: InitialScaleDef;
211
+ scaleComponents: InitialScaleComponentsDef;
188
212
  mass: MassDef;
189
213
  velocity: VelocityDef;
190
214
  randomDirection: RandomDirectionDef;
@@ -194,7 +218,9 @@ declare const vfxBehaviours: {
194
218
  gravity: GravityDef;
195
219
  scale: ScaleDef;
196
220
  randomDrift: RandomDriftDef;
221
+ disperse: DisperseDef;
197
222
  rotate: RotateDef;
223
+ orientAlongVelocity: OrientAlongVelocityDef;
198
224
  changeColor: ChangeColorDef;
199
225
  changeOpacity: ChangeOpacityDef;
200
226
  vortex: VortexDef;
@@ -203,8 +229,8 @@ declare const vfxBehaviours: {
203
229
  };
204
230
  export type LibraryVfxInitalizerType = keyof typeof vfxInitializsers;
205
231
  export declare const VfxInitializserLibrary: Record<LibraryVfxInitalizerType, InitializerDefinition>;
206
- export declare const VfxInitializserLibraryKeys: ("rotation" | "mass" | "scale" | "velocity" | "lifetime" | "positionPoint" | "positionBox" | "positionSphere" | "positionLine" | "randomDirection")[];
232
+ export declare const VfxInitializserLibraryKeys: ("rotation" | "mass" | "scale" | "velocity" | "lifetime" | "positionPoint" | "positionBox" | "positionSphere" | "positionLine" | "randomRotation" | "scaleComponents" | "randomDirection")[];
207
233
  export type LibraryVfxBehaviourType = keyof typeof vfxBehaviours;
208
234
  export declare const VfxBehaviourLibrary: Record<LibraryVfxBehaviourType, BehaviourDefinition>;
209
- export declare const VfxBehaviourLibraryKeys: ("scale" | "force" | "gravity" | "randomDrift" | "rotate" | "changeColor" | "changeOpacity" | "vortex" | "moveTo" | "linearDamping")[];
235
+ export declare const VfxBehaviourLibraryKeys: ("scale" | "orientAlongVelocity" | "force" | "gravity" | "randomDrift" | "disperse" | "rotate" | "changeColor" | "changeOpacity" | "vortex" | "moveTo" | "linearDamping")[];
210
236
  export {};
@@ -1,4 +1,4 @@
1
- import{Color as e,MathUtils as r,Vector2 as t,Vector3 as s}from"three";import{Life as n,Force as a,Gravity as o,Scale as i,RandomDrift as c,Color as u,Alpha as p,Rotate as m,Mass as d,ease as l,Position as f,BoxZone as w,LineZone as x}from"three-nebula";import{LinearDamping as y,MoveOverLife as h,RotatePosition as b}from"./behaviours.js";import{AdditiveVelocity as k,InitialScale as v,RandomDirection as z,Rotation as g}from"./initializsers.js";import{SphereZone as L,PointZone as j}from"./zones.js";Object.getPrototypeOf(n);class O{build(e={}){const r=R(e,this.parameters);return this.make(r)}}class V{build(e={}){const r=R(e,this.parameters);return this.make(r)}}function B(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function T(e){return{type:"vec3",default:(new s).fromArray(e)}}function D(e){return{type:"color",default:e}}function I(){return{type:"select",opts:Array.from(Object.keys(l)).map((e=>e.substring(4))),default:"Linear"}}function R(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function A(e){return null!=e?l["ease"+e]:l.easeLinear}const C={lifetime:new class extends V{constructor(){var e;super(...arguments),this.parameters={duration:(e=1,{type:"number",default:e})}}make(e={}){return new n(e.duration)}},positionPoint:new class extends V{constructor(){super(...arguments),this.parameters={position:T([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position;return new f(new j(r,t,s))}},positionBox:new class extends V{constructor(){super(...arguments),this.parameters={position:T([0,0,0]),dimensions:T([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position,{x:n,y:a,z:o}=e.dimensions;return new f(new w(r,t,s,n,a,o))}},positionSphere:new class extends V{constructor(){super(...arguments),this.parameters={position:T([0,0,0]),radius:B(1)}}make(e={}){const{x:r,y:t,z:s}=e.position;return new f(new L(r,t,s,e.radius))}},positionLine:new class extends V{constructor(){super(...arguments),this.parameters={a:T([0,0,0]),b:T([0,0,1])}}make(e={}){const{x:r,y:t,z:s}=e.a,{x:n,y:a,z:o}=e.b;return new f(new x(r,t,s,n,a,o))}},rotation:new class extends V{constructor(){super(...arguments),this.parameters={rotation:T([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.rotation;return new g(new s(r,t,n))}},scale:new class extends V{constructor(){super(...arguments),this.parameters={scale:B(1)}}make(e={}){return new v(e.scale)}},mass:new class extends V{constructor(){super(...arguments),this.parameters={min:B(1)}}make(e={}){return new d(e.min)}},velocity:new class extends V{constructor(){super(...arguments),this.parameters={velocity:T([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.velocity;return new k(new s(r,t,n))}},randomDirection:new class extends V{constructor(){super(...arguments),this.parameters={speed:B(1)}}make(e={}){return new z(e.speed)}}},K={force:new class extends O{constructor(){super(...arguments),this.parameters={force:T([0,0,0]),ease:I()}}make(e={}){return new a(e.force.x,e.force.y,e.force.z,void 0,A(e.ease))}},gravity:new class extends O{constructor(){super(...arguments),this.parameters={gravity:B(8)}}make(e={}){return new o(e.gravity)}},scale:new class extends O{constructor(){super(...arguments),this.parameters={a:B(1),b:B(1),ease:I()}}make(e={}){return new i(e.a,e.b,void 0,A(e.ease))}},randomDrift:new class extends O{constructor(){super(...arguments),this.parameters={drift:T([1,1,1]),delay:B(0),ease:I()}}make(e={}){return new c(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,A(e.ease))}},rotate:new class extends O{constructor(){super(...arguments),this.parameters={rotation:T([0,0,0]),ease:I()}}make(e={}){const{x:t,y:s,z:n}=e.rotation;return new m(r.degToRad(t),r.degToRad(s),r.degToRad(n),void 0,A(e.ease))}},changeColor:new class extends O{constructor(){super(...arguments),this.parameters={a:D("#ffffff"),b:D("#ffffff"),ease:I()}}make(r={}){return new u(new e(r.a),new e(r.b),void 0,A(r.ease))}},changeOpacity:new class extends O{constructor(){super(...arguments),this.parameters={a:B(1,0,1),b:B(0,0,1),ease:I()}}make(e={}){return new p(e.a,e.b,void 0,A(e.ease))}},vortex:new class extends O{constructor(){super(...arguments),this.parameters={axis:T([0,1,0]),amount:B(1)}}make(e={}){return new b(e.axis,e.amount)}},moveTo:new class extends O{constructor(){super(...arguments),this.parameters={target:T([0,1,0]),ease:I()}}make(e={}){return new h(e.target.x,e.target.y,e.target.z,A(e.ease))}},linearDamping:new class extends O{constructor(){super(...arguments),this.parameters={factor:B(.1,0,1)}}make(e={}){return new y(e.factor)}}};export const VfxInitializserLibrary=C;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=K;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);
1
+ import{Color as e,MathUtils as r,Vector2 as t,Vector3 as s}from"three";import{Life as n,Force as a,Gravity as o,Scale as i,RandomDrift as c,Color as u,Alpha as p,Rotate as m,Mass as l,ease as d,Position as w,BoxZone as f,LineZone as x}from"three-nebula";import{AxisDirection as y,AxisPlane as h,Disperse as k,LinearDamping as b,MoveOverLife as v,OrientAlongVelocity as z,RotatePosition as g}from"./behaviours.js";import{AdditiveVelocity as L,InitialScale as j,InitialScaleComponents as V,RandomDirection as O,RandomRotation as B,Rotation as C}from"./initializsers.js";import{SphereZone as R,PointZone as T}from"./zones.js";Object.getPrototypeOf(n);class X{build(e={}){const r=P(e,this.parameters);return this.make(r)}}class Y{build(e={}){const r=P(e,this.parameters);return this.make(r)}}function Z(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function A(e){return{type:"vec3",default:(new s).fromArray(e)}}function D(e){return{type:"color",default:e}}function I(e,r){return{type:"select",opts:e,default:r}}function K(){return I(Array.from(Object.keys(d)).map((e=>e.substring(4))),"Linear")}function P(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function S(e){return null!=e?d["ease"+e]:d.easeLinear}const q={lifetime:new class extends Y{constructor(){var e;super(...arguments),this.parameters={duration:(e=1,{type:"number",default:e})}}make(e={}){return new n(e.duration)}},positionPoint:new class extends Y{constructor(){super(...arguments),this.parameters={position:A([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position;return new w(new T(r,t,s))}},positionBox:new class extends Y{constructor(){super(...arguments),this.parameters={position:A([0,0,0]),dimensions:A([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position,{x:n,y:a,z:o}=e.dimensions;return new w(new f(r,t,s,n,a,o))}},positionSphere:new class extends Y{constructor(){super(...arguments),this.parameters={position:A([0,0,0]),radius:Z(1)}}make(e={}){const{x:r,y:t,z:s}=e.position;return new w(new R(r,t,s,e.radius))}},positionLine:new class extends Y{constructor(){super(...arguments),this.parameters={a:A([0,0,0]),b:A([0,0,1])}}make(e={}){const{x:r,y:t,z:s}=e.a,{x:n,y:a,z:o}=e.b;return new w(new x(r,t,s,n,a,o))}},rotation:new class extends Y{constructor(){super(...arguments),this.parameters={rotation:A([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.rotation;return new C(new s(r,t,n))}},randomRotation:new class extends Y{constructor(){super(...arguments),this.parameters={}}make(e={}){return new B}},scale:new class extends Y{constructor(){super(...arguments),this.parameters={scale:Z(1)}}make(e={}){return new j(e.scale)}},scaleComponents:new class extends Y{constructor(){super(...arguments),this.parameters={scale:A([1,1,1])}}make(e={}){return new V(e.scale)}},mass:new class extends Y{constructor(){super(...arguments),this.parameters={min:Z(1)}}make(e={}){return new l(e.min)}},velocity:new class extends Y{constructor(){super(...arguments),this.parameters={velocity:A([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.velocity;return new L(new s(r,t,n))}},randomDirection:new class extends Y{constructor(){super(...arguments),this.parameters={speed:Z(1)}}make(e={}){return new O(e.speed)}}},E={force:new class extends X{constructor(){super(...arguments),this.parameters={force:A([0,0,0]),ease:K()}}make(e={}){return new a(e.force.x,e.force.y,e.force.z,void 0,S(e.ease))}},gravity:new class extends X{constructor(){super(...arguments),this.parameters={gravity:Z(8)}}make(e={}){return new o(e.gravity)}},scale:new class extends X{constructor(){super(...arguments),this.parameters={a:Z(1),b:Z(1),ease:K()}}make(e={}){return new i(e.a,e.b,void 0,S(e.ease))}},randomDrift:new class extends X{constructor(){super(...arguments),this.parameters={drift:A([1,1,1]),delay:Z(0),ease:K()}}make(e={}){return new c(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,S(e.ease))}},disperse:new class extends X{constructor(){super(...arguments),this.parameters={distance:Z(1),axis:I(["XYZ","XZ","XY","YZ"],"XYZ"),ease:K()}}make(e={}){return new k(e.distance,h[e.axis.toLowerCase()],S(e.ease))}},rotate:new class extends X{constructor(){super(...arguments),this.parameters={rotation:A([0,0,0]),ease:K()}}make(e={}){const{x:t,y:s,z:n}=e.rotation;return new m(r.degToRad(t),r.degToRad(s),r.degToRad(n),void 0,S(e.ease))}},orientAlongVelocity:new class extends X{constructor(){super(...arguments),this.parameters={}}make(e={}){return new z(y.z)}},changeColor:new class extends X{constructor(){super(...arguments),this.parameters={a:D("#ffffff"),b:D("#ffffff"),ease:K()}}make(r={}){return new u(new e(r.a),new e(r.b),void 0,S(r.ease))}},changeOpacity:new class extends X{constructor(){super(...arguments),this.parameters={a:Z(1,0,1),b:Z(0,0,1),ease:K()}}make(e={}){return new p(e.a,e.b,void 0,S(e.ease))}},vortex:new class extends X{constructor(){super(...arguments),this.parameters={axis:A([0,1,0]),amount:Z(1)}}make(e={}){return new g(e.axis,e.amount)}},moveTo:new class extends X{constructor(){super(...arguments),this.parameters={target:A([0,1,0]),ease:K()}}make(e={}){return new v(e.target.x,e.target.y,e.target.z,S(e.ease))}},linearDamping:new class extends X{constructor(){super(...arguments),this.parameters={factor:Z(.1,0,1)}}make(e={}){return new b(e.factor)}}};export const VfxInitializserLibrary=q;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=E;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -10,11 +10,11 @@ export type VfxAssetProvider = {
10
10
  };
11
11
  export declare function materializeVfx(asset: VfxAsset, target: Object3D, assetProvider: VfxAssetProvider): Promise<{
12
12
  system: System;
13
- dispose: () => Object3D<THREE.Event>;
13
+ dispose: () => void;
14
14
  }>;
15
15
  export declare function materializeVfxOld(asset: VfxAsset, target: Object3D): {
16
16
  system: System;
17
17
  rate: Rate;
18
18
  renderer: MeshRenderer;
19
- dispose: () => Object3D<THREE.Event>;
19
+ dispose: () => Object3D<THREE.Object3DEventMap>;
20
20
  };
@@ -1,4 +1,4 @@
1
- import{Object3D as e}from"three";import*as t from"three";import a,{Behaviour as r,Body as n,BoxZone as o,Emitter as i,Force as s,Life as l,Mass as m,MeshRenderer as c,PUID as d,PointZone as u,Position as w,RadialVelocity as p,Radius as h,Rate as f,Rotate as g,Scale as A,Span as y,Vector3D as M,ease as x}from"three-nebula";import{RotatePosition as b}from"./behaviours.js";import{OnceRate as I}from"./rates.js";import{VfxBehaviourLibrary as S,VfxInitializserLibrary as B}from"./vfx-defs.js";import{ThreeBlendingMode as E}from"./vfx-asset.js";import{ShapeLibrary as P}from"../../scene/objects/shapes.js";import{prepareShapeParameters as R,shapeDefaultColor as v}from"../../scene/materializer.js";import{particleEnergyUniformName as Q,particleVelcoityUniformName as U}from"../../shader-nodes/particle.js";import{NodeShaderMaterial as V}from"three-shader-graph";class j extends c{scale(e){e.target instanceof t.Sprite?e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(a){a.target||(a.target=this._targetPool.get(a.body),(a.useAlpha||a.useColor)&&(a.target instanceof t.Mesh||a.target instanceof t.Sprite&&a.target.material instanceof t.Material)&&(a.target.material.__puid=d.id(a.body.material),a.target.material=this._materialPool.get(a.target.material))),a.target&&a.target instanceof e&&(a.target.position.set(a.position.x,a.position.y,a.position.z),this.container.add(a.target))}onParticleUpdate(e){const{target:a,useAlpha:r,useColor:n,rotation:o}=e;a&&(a.position.copy(e.position),this.isThreeSprite(e)||a.rotation.set(o.x,o.y,o.z),this.scale(e),a.material instanceof t.Material&&(r&&(a.material.opacity=e.alpha,a.material.transparent=!0),n&&a.material.color.copy(e.color)))}onParticleDead(e){e.target&&(e.target.material&&(e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export async function materializeVfx(r,o,s){let l=o;if(!0!==r.vfx.localSpace)for(;null!=l.parent;)l=l.parent;const m=new e;m.name="particle system",l.add(m);const c=new j(m,t),d=(new t.Mesh(new t.BoxGeometry(.3,.3,.3),new t.MeshStandardMaterial({color:16777215})),new a),u=await Promise.all(r.vfx.emitters.map((async a=>{let r,o;switch(a.rate.type){case"continuous":r=new f(a.rate.count,a.rate.time);break;case"once":r=new I(a.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(a)}`),r=new f(0,1/0)}switch(a.output.type){case"sprite":o=new n(await async function(e,a){const r=null!=e.texture?await a.getTexture(e.texture):k;var n=new t.SpriteMaterial({map:r,color:e.color??16777215,blending:E[e.blendingMode]??t.NormalBlending,fog:!0,transparent:!0});return new t.Sprite(n)}(a.output,s));break;case"shape":o=new n(await async function(a,r){const n=P[a.shape];if(null==n)return console.error(`No shape with type ${a.shape}`),new e;const o=R(a.params??{}),i=n.geometry(o),s=null!=a.material?await r.getMaterial(a.material):new t.MeshStandardMaterial({color:v});return new t.Mesh(i,s)}(a.output,s));break;case"mesh":o=new n(await async function(a,r){if(null==a.assetId)return console.warn("Can't use mesh as particle without asset id"),new e;const n=await r.getMesh(a.assetId),o=await r.getAsset(a.assetId),i=[];if(null!=o.materialAssignments)for(const e of o.materialAssignments)n.traverse((a=>{a instanceof t.Mesh&&a.material instanceof t.Material&&a.material.color instanceof t.Color&&(a.material.name!=e.name&&null!=e.name||"#"+a.material.color.getHexString()!==e.color||i.push(r.getMaterial(e.materialId).then((e=>a.material=e))))}));return await Promise.all(i),n.traverse((e=>{})),n}(a.output,s));break;default:console.error("Failed to create particly system body: "+JSON.stringify(a))}const l=(new i).setRate(r),m=await Promise.all(a.initializers.filter((e=>null!=B[e.type])).map((async e=>{const t=B[e.type],a=await R(e.params??{});return t.build(a)})));m.push(o),l.addInitializers(m);const c=await Promise.all(a.behaviours.filter((e=>null!=S[e.type])).map((async e=>{const t=S[e.type],a=await R(e.params??{});return t.build(a)})));return c.push(new C),l.addBehaviours(c),l.emit()})));return u.forEach((e=>d.addEmitter(e))),d.addRenderer(c).emit({onEnd:()=>{console.log("ended")}}),{system:d,dispose:()=>m.removeFromParent()}}const k=(new t.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");export function materializeVfxOld(r,d){let S=d;if(!0!==r.vfx.localSpace)for(;null!=S.parent;)S=S.parent;const B=new e;B.name="particle system",S.add(B);const E=new c(B,t),P=new t.Mesh(new t.BoxGeometry(.3,.3,.3),new t.MeshStandardMaterial({color:16777215})),R=new f(new y(3,9),new y(.02,.15)),v=new i,Q=new a;v.setLife(4).setRate(R).addInitializers([new m(1),new h(1),new l(1),new n(P),new w(new o(.5)),new p(10,new M(0,0,1),30)]).addBehaviours([new b(new t.Vector3(0,0,1),4),new s(0,0,.1),new g("random",2.5*-Math.PI,2*Math.PI,1,x.easeOutCubic),new A(1,.2)]).emit();const U=new I,V=(new i).setLife(5).addInitializers([new m(1),new h(1),new l(3),new n(P),new w(new u(0,0,0))]).addBehaviours([new A(4,6,void 0,x.easeOutExpo)]).setRate(U).emit();return U.nextTime=0,Q.addEmitter(v).addEmitter(V).addRenderer(E).emit({onEnd:()=>{console.log("ended")}}),{system:Q,rate:R,renderer:E,dispose:()=>B.removeFromParent()}}class C extends r{initialize(e){if(e.body instanceof t.Mesh){const t=e.body.material;t instanceof V&&(null!=t.uniforms[Q]||null!=t.uniforms[U])&&(e.body.material=t.clone())}}mutate(e,a,r){if(e.target instanceof t.Mesh){const t=e.target.material;t instanceof V&&(null!=t.uniforms[Q]&&(t.uniforms[Q].value=this.energy),null!=t.uniforms[U]&&(t.uniforms[U].value=e.velocity))}}}
1
+ import{Object3D as e}from"three";import*as t from"three";import a,{Behaviour as n,Body as r,BoxZone as o,Emitter as s,Force as i,Life as l,Mass as m,MeshRenderer as c,PointZone as w,Position as d,RadialVelocity as u,Radius as f,Rate as p,Rotate as A,Scale as h,Span as g,Vector3D as y,ease as b}from"three-nebula";import{RotatePosition as M}from"./behaviours.js";import{DelayRate as x,OnceRate as I}from"./rates.js";import{VfxBehaviourLibrary as B,VfxInitializserLibrary as E}from"./vfx-defs.js";import{ThreeBlendingMode as R}from"./vfx-asset.js";import{ShapeLibrary as S}from"../../scene/objects/shapes.js";import{prepareShapeParameters as v}from"../../scene/materializer.js";import{particleEnergyUniformName as j,particleVelcoityUniformName as Q}from"../../shader-nodes/particle.js";import{AttributeVec3Node as V,NodeShaderMaterial as U,RgbNode as k,Vec3ExpressionNode as F,lambertMaterial as H,varyingVec3 as P}from"three-shader-graph";import{DefaultInitializer as J}from"./initializsers.js";import{MultiRenderer as q}from"./vfx-renderers.js";export async function materializeVfx(n,o,i){let l=o;if(!0!==n.vfx.localSpace)for(;null!=l.parent;)l=l.parent;const m=new e;m.name="particle system",l.add(m);const c=new q(m,t),w=new a,d=await Promise.all(n.vfx.emitters.map((async a=>{let n,o;switch(a.rate.type){case"continuous":n=new x(a.rate.delay??0,a.rate.count,a.rate.time);break;case"once":n=new I(a.rate.delay??0,a.rate.count);break;default:console.warn(`Failed to configure r\n ate for emitter: ${JSON.stringify(a)}`),n=new p(0,1/0)}switch(a.output.type){case"sprite":o=new r(await async function(e,a){const n=null!=e.texture?await a.getTexture(e.texture):T;var r=new t.SpriteMaterial({map:n,color:e.color??16777215,blending:R[e.blendingMode]??t.NormalBlending,fog:!0,transparent:!0});const o=new t.Sprite(r);return o}(a.output,i));break;case"shape":o=new r(await async function(a,n){const r=S[a.shape];if(null==r)return console.error(`No shape with type ${a.shape}`),new e;const o=v(a.params??{}),s=r.geometry(o),i=null!=a.material?await n.getMaterial(a.material):function(){const e=P(new F("instanceColor")).rgb(),t=P(new V("particleData")).x();return new U({color:H({color:e}).rgb().rgba(t),transparent:!0})}();return new t.Mesh(s,i)}(a.output,i));break;case"mesh":o=new r(await async function(a,n){if(null==a.assetId)return console.warn("Can't use mesh as particle without asset id"),new e;const r=await n.getMesh(a.assetId),o=await n.getAsset(a.assetId),s=[];if(null!=o.materialAssignments)for(const e of o.materialAssignments)r.traverse((a=>{a instanceof t.Mesh&&a.material instanceof t.Material&&a.material.color instanceof t.Color&&(a.material.name!=e.name&&null!=e.name||"#"+a.material.color.getHexString()!==e.color||s.push(n.getMaterial(e.materialId).then((e=>a.material=e))))}));return await Promise.all(s),r.traverse((e=>{})),r}(a.output,i));break;default:console.error("Failed to create particly system body: "+JSON.stringify(a))}const l=(new s).setRate(n),m=await Promise.all(a.initializers.filter((e=>null!=E[e.type])).map((async e=>{const t=E[e.type],a=await v(e.params??{});return t.build(a)})));m.push(o,new J),l.addInitializers(m);const c=await Promise.all(a.behaviours.filter((e=>null!=B[e.type])).map((async e=>{const t=B[e.type],a=await v(e.params??{});return t.build(a)})));return c.push(new W),l.addBehaviours(c),l.emit()})));return d.forEach((e=>w.addEmitter(e))),w.addRenderer(c).emit({onEnd:()=>{console.log("ended")}}),{system:w,dispose:()=>{m.removeFromParent(),c.dispose()}}}const T=(new t.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");export function materializeVfxOld(n,x){let B=x;if(!0!==n.vfx.localSpace)for(;null!=B.parent;)B=B.parent;const E=new e;E.name="particle system",B.add(E);const R=new c(E,t),S=new t.Mesh(new t.BoxGeometry(.3,.3,.3),new t.MeshStandardMaterial({color:16777215})),v=new p(new g(3,9),new g(.02,.15)),j=new s,Q=new a;j.setLife(4).setRate(v).addInitializers([new m(1),new f(1),new l(1),new r(S),new d(new o(.5)),new u(10,new y(0,0,1),30)]).addBehaviours([new M(new t.Vector3(0,0,1),4),new i(0,0,.1),new A("random",2.5*-Math.PI,2*Math.PI,1,b.easeOutCubic),new h(1,.2)]).emit();const V=new I(0),U=(new s).setLife(5).addInitializers([new m(1),new f(1),new l(3),new r(S),new d(new w(0,0,0))]).addBehaviours([new h(4,6,void 0,b.easeOutExpo)]).setRate(V).emit();return V.nextTime=0,Q.addEmitter(j).addEmitter(U).addRenderer(R).emit({onEnd:()=>{console.log("ended")}}),{system:Q,rate:v,renderer:R,dispose:()=>E.removeFromParent()}}class W extends n{initialize(e){if(e.body instanceof t.Mesh){const t=e.body.material;t instanceof U&&(null!=t.uniforms[j]||null!=t.uniforms[Q])&&(e.body.material=t.clone())}}mutate(e,a,n){if(e.target instanceof t.Mesh){const t=e.target.material;t instanceof U&&(null!=t.uniforms[j]&&(t.uniforms[j].value=this.energy),null!=t.uniforms[Q]&&(t.uniforms[Q].value=e.velocity))}}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -7,5 +7,35 @@ export declare class VisualEffect {
7
7
  private actorProvider;
8
8
  private asset;
9
9
  constructor(actorProvider: ActorProvider, asset: VfxAsset);
10
- spawn(parent: Object3D | BaseActor): Promise<VfxActor>;
10
+ /**
11
+ * Create a new instance of the VFX Actor.
12
+ * Make sure to add the actor to the world for it to be visible
13
+ * and call play. Remove the actor from the world using world.removeActor
14
+ * to clean up.
15
+ * @param parent The object that the VFX should be parented to to make particles spawn relative to its location.
16
+ */
17
+ create(parent: Object3D | BaseActor): Promise<VfxActor>;
18
+ /**
19
+ * Create a pool that can be used to create actors and reuse them.
20
+ * @param parent The object that the VFX should be parented to to make particles spawn relative to its location.
21
+ * @returns
22
+ */
23
+ createPool(parent: Object3D | BaseActor): Pool<VfxActor>;
11
24
  }
25
+ declare class Pool<T extends VfxActor> {
26
+ private creator;
27
+ instances: T[];
28
+ constructor(creator: () => Promise<T>);
29
+ /**
30
+ * Creates a new instance of a VFX actor or
31
+ * reuses a previously released one.
32
+ */
33
+ get(): Promise<T>;
34
+ /**
35
+ * Release the VFX Actor to be reusable in future
36
+ * calls to the get function.
37
+ */
38
+ release(instance: T): void;
39
+ dispose(): void;
40
+ }
41
+ export {};
@@ -1,4 +1,4 @@
1
- import{VfxActor as t}from"./vfx-actor.js";import{BaseActor as s}from"../../gameplay/index.js";export class VisualEffect{constructor(t,s){this.actorProvider=t,this.asset=s}async spawn(a){const o=await this.actorProvider.create(t);return a instanceof s?a.object.add(o.object):a.add(o.object),await o.fromAsset(this.asset),o}}
1
+ import{VfxActor as t}from"./vfx-actor.js";import{BaseActor as s}from"../../gameplay/index.js";export class VisualEffect{constructor(t,s){this.actorProvider=t,this.asset=s}async create(e){const a=await this.actorProvider.create(t);return e instanceof s?e.object.add(a.object):e.add(a.object),await a.fromAsset(this.asset),a}createPool(t){return new e((()=>this.create(t)))}}class e{constructor(t){this.creator=t,this.instances=[]}async get(){0==this.instances.length&&this.instances.push(await this.creator());const t=this.instances.shift();return t.restart(),t}release(t){this.instances.push(t)}dispose(){this.instances.length=0}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1,36 @@
1
+ import * as THREE from 'three';
2
+ import { Object3D } from 'three';
3
+ import { CustomRenderer, MeshRenderer, Particle } from 'three-nebula';
4
+ export declare class MultiRenderer extends CustomRenderer {
5
+ private container;
6
+ private three;
7
+ private renderers;
8
+ constructor(container: Object3D, three: typeof THREE);
9
+ onSystemUpdate(): void;
10
+ onParticleCreated(particle: Particle): void;
11
+ onParticleUpdate(particle: Particle): void;
12
+ onParticleDead(particle: Particle): void;
13
+ private getRenderer;
14
+ dispose(): void;
15
+ }
16
+ export declare class CombinedRenderer extends MeshRenderer {
17
+ dispose(): void;
18
+ scale(particle: any): void;
19
+ rotate(particle: any): void;
20
+ onParticleCreated(particle: Particle & {
21
+ body?: MeshRenderer['_body'];
22
+ target: THREE.Mesh | Object3D;
23
+ }): void;
24
+ onParticleUpdate(particle: any): void;
25
+ onParticleDead(particle: any): void;
26
+ }
27
+ export declare class InstancedRenderer extends MeshRenderer {
28
+ dispose(): void;
29
+ private meshes;
30
+ onParticleCreated(particle: Particle & {
31
+ body?: MeshRenderer['_body'];
32
+ target: any;
33
+ }): void;
34
+ onParticleUpdate(particle: any): void;
35
+ onParticleDead(particle: any): void;
36
+ }
@@ -0,0 +1,5 @@
1
+ import*as e from"three";import{Object3D as t}from"three";import{CustomRenderer as r,MeshRenderer as i,PUID as a}from"three-nebula";import{NodeShaderMaterial as s}from"three-shader-graph";var n;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite"}(n||(n={}));export class MultiRenderer extends r{constructor(e,t){super(),this.container=e,this.three=t,this.renderers=[]}onSystemUpdate(){}onParticleCreated(e){this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e)}getRenderer(t){return t._renderer?t._renderer:t.body instanceof e.Sprite?(this.renderers[n.sprite]||(this.renderers[n.sprite]=new CombinedRenderer(this.container,this.three)),t._renderer=this.renderers[n.sprite]):t.body instanceof e.Mesh&&0==t.body.children.length&&t.body.material instanceof s?(this.renderers[n.instanced]||(this.renderers[n.instanced]=new InstancedRenderer(this.container,this.three)),t._renderer=this.renderers[n.instanced]):t.body instanceof e.Object3D?(this.renderers[n.mesh]||(this.renderers[n.mesh]=new CombinedRenderer(this.container,this.three)),t._renderer=this.renderers[n.mesh]):void 0}dispose(){this.renderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class CombinedRenderer extends i{dispose(){}scale(t){const r=t.transform.initialScale;t.target instanceof e.Sprite?null!=r?t.target.scale.set(r.x*t.scale*t.radius,r.y*t.scale*t.radius,1):t.target.scale.set(t.scale*t.radius,t.scale*t.radius,1):null!=r?t.target.scale.set(r.x*t.scale,r.y*t.scale,r.z*t.scale):super.scale(t)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(r){r.target||(r.target=this._targetPool.get(r.body),(r.useAlpha||r.useColor)&&(r.target instanceof e.Mesh||r.target instanceof e.Sprite&&r.target.material instanceof e.Material)&&(r.target.material.__puid=a.id(r.body.material),r.target.material=this._materialPool.get(r.target.material))),r.target&&r.target instanceof t&&(r.target.position.set(r.position.x,r.position.y,r.position.z),this.container.add(r.target))}onParticleUpdate(r){const{target:i,useAlpha:a,useColor:s,rotation:n}=r;if(i){if(i.position.copy(r.position),this.isThreeSprite(r)||i.rotation.set(n.x,n.y,n.z),this.scale(r),r.transform&&r.transform.orientAlongVelocity&&i instanceof t){const e=o.set(r.velocity.x,r.velocity.y,r.velocity.z).normalize(),t=i.getWorldDirection(l);t.applyAxisAngle(d,Math.PI/-2),c.setFromUnitVectors(t,e),i.quaternion.copy(c)}i.material instanceof e.Material&&(a&&(i.material.opacity=r.alpha,i.material.transparent=!0),s&&null!=i.material.color&&i.material.color.copy(r.color))}}onParticleDead(e){e.target&&(e.target.material&&(e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}const o=new e.Vector3,l=new e.Vector3,c=new e.Quaternion,d=new e.Vector3(1,0,0);export class InstancedRenderer extends i{constructor(){super(...arguments),this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onParticleCreated(t){if(!(t.body instanceof e.Sprite)){if(null==t.target){const r=t.body;let i=this.meshes.find((e=>e.mesh.geometry.uuid===r.geometry.uuid&&e.mesh.material.uuid===r.material.uuid));if(null==i){const a=t.parent.rate,s=Math.min(Math.ceil(a.numPan.b/Math.min(Math.max(a.timePan.a,.01),1)),1e5);i={mesh:new e.InstancedMesh(r.geometry,r.material,s),indices:new Array(s).fill(null)},i.mesh.setColorAt(0,x.copy(new e.Color(t.color)));const n=new Float32Array(3*s);u.makeScale(0,0,0);for(let e=0;e<s;e++)n[3*e+0]=1,n[3*e+1]=1,i.mesh.setMatrixAt(e,u);i.mesh.instanceMatrix.needsUpdate=!0,i.mesh.geometry.setAttribute("particleData",new e.InstancedBufferAttribute(n,3)),this.meshes.push(i),this.container.add(i.mesh)}let a=i.indices.findIndex((e=>null==e));a<0&&(a=i.indices.indexOf(Math.min(...i.indices))),i.indices[a]=performance.now(),t.target=a}if("number"==typeof t.target){t.transform.initialScale;const e=t.body;let r=this.meshes.find((t=>t.mesh.geometry.uuid===e.geometry.uuid&&t.mesh.material.uuid===e.material.uuid));h(t,r.mesh),t.useAlpha&&(r.mesh.material.transparent=!0)}}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:i,rotation:a}=e;if(null==t)return;const s=e.body;let n=this.meshes.find((e=>e.mesh.geometry.uuid===s.geometry.uuid&&e.mesh.material.uuid===s.material.uuid));if(h(e,n.mesh),i&&(n.mesh.setColorAt(e.target,x.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0),r){const t=n.mesh.geometry.getAttribute("particleData");t.setX(e.target,e.alpha),t.needsUpdate=!0}}onParticleDead(e){if(null!=e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));r.indices[e.target]=null,e.scale=0,h(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const m=new t;function h(e,t){if(g.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=o.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize();t.getMatrixAt(e.target,m.matrix);const i=m.getWorldDirection(f);i.applyAxisAngle(d,Math.PI/-2),p.setFromUnitVectors(i,r)}else y.set(e.rotation.x,e.rotation.y,e.rotation.z),p.setFromEuler(y);const r=e.transform.initialScale;null!=r?f.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):f.set(e.scale,e.scale,e.scale),u.compose(g,p,f),t.setMatrixAt(e.target,u),t.instanceMatrix.needsUpdate=!0}const u=new e.Matrix4,p=new e.Quaternion,g=new e.Vector3,f=new e.Vector3,y=new e.Euler,x=new e.Color(0);
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -1,4 +1,4 @@
1
- import{__decorate as t}from"tslib";import{ActorComponent as i,Component as e}from"../../../component.js";import{RootMotionClip as r}from"../../../../animation/root-motion.js";import{inject as s}from"../../../../inject.js";import{ViewController as o}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,LoopOnce as l}from"three";let h=class extends i{constructor(){super(...arguments),this.viewController=s(o),this.stateMachines=[],this.upperStateMachines=[],this.fadeTime=.2,this.movementSpeed=null,this.upperBodyTimer=0,this.upperBodyOverride=!1,this.fullBodyTimer=0,this.currentFullBodyPriority=-1,this.currentUpperBodyPriority=-1,this.getFullBodyClip=c((t=>t.uuid),(t=>u(this.fullBodyMask,t))),this.getUpperBodyClip=c((t=>t.uuid),(t=>u(this.upperBodyMask,t)))}onInit(){this.viewController.onUpdate(this.actor).subscribe((t=>this.updateInternal(t)))}getRootMotionAction(){if(this.fullBodyAction.getClip()instanceof r)return this.fullBodyAction}setup(t,i,e){null!=i&&(this.upperBodyMask=a(i),this.fullBodyMask=function(t,i){const e=new Set(a(i).map((t=>t.uuid))),r=[];return t.traverse((t=>{(t instanceof p||t.isBone)&&!e.has(t.uuid)&&r.push(t)})),r}(function(t){let i;return t.traverse((t=>{(t instanceof p||t.isBone)&&null==i&&(i=t)})),i}(t),i)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e&&this.play(e,{priority:0})})),this.upperStateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e?this.playUpper(e,{priority:0}):this.play(this.fullBodyClip)}))}updateInternal(t){null!=this.mixer&&(this.upperBodyTimer+=t,this.fullBodyTimer+=t,this.upperBodyAction&&this.upperBodyOverride&&this.upperBodyAction.getClip().duration-2*this.fadeTime<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip))),this.fullBodyAction&&this.fullBodyAction.loop===l&&this.fullBodyAction.getClip().duration-2*this.fadeTime<this.fullBodyTimer&&(this.currentFullBodyPriority=-1),this.updateStateMachines(t),this.syncMovementSpeed(this.fullBodyAction),this.upperBodyOverride||this.syncMovementSpeed(this.upperBodyAction),this.mixer.update(t))}syncMovementSpeed(t){if(null!=t){const i=t.getClip();i instanceof r&&i.fixedInPlace&&null!=this.movementSpeed&&(t.timeScale=i.duration/i.displacement*this.movementSpeed)}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){this.stateMachines.splice(this.stateMachines.indexOf(t))}removeUpperStateMachine(t){this.upperStateMachines.splice(this.upperStateMachines.indexOf(t))}playUpper(t,i={}){const e=i?.priority??1;e<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=e,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i),this.upperBodyTimer=0,this.upperBodyOverride=!0)}play(t,i={}){!function(t,i){if(!1===t||"function"==typeof t&&!1===t())throw new Error(i)}(null!=this.mixer,"Can't play animation before setup is called");const e=i.priority??1;e<this.currentFullBodyPriority||(this.currentFullBodyPriority=e,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i)),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),i),this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction))}onActionDone(t){return new Promise((i=>{const e=r=>{r.target===t&&(i(r.target),this.mixer.removeEventListener("finished",e))};this.mixer.addEventListener("finished",e)}))}transition(t,i,e={}){if(null!=t&&t.getClip().uuid===i.uuid)return t;if(t){const e=t,r=t=this.mixer.clipAction(i);r.play(),r.enabled=!0,r.setEffectiveTimeScale(1),r.setEffectiveWeight(1),r.time=0,e.crossFadeTo(r,this.fadeTime,!0)}else t=this.mixer.clipAction(i),t?.fadeIn(.3),t?.play();return!1===e.loop&&(t.setLoop(l,1),t.clampWhenFinished=!0,t.reset()),t}};h=t([e()],h);export{h as CharacterAnimationComponent};function u(t,i){if(null==t)return i;const e=i.clone(),r=new Set(t.map((t=>t.name)));return e.tracks=e.tracks.filter((t=>r.has(t.name.split(".")[0]))),e}function a(t){return t.flatMap((t=>function(t){const i=[];return t.traverse((t=>{i.push(t)})),i}(t))).filter((t=>t instanceof p))}function c(t,i){const e=new Map;return(r,...s)=>{const o=t(r);return e.has(o)||e.set(o,i(r,...s)),e.get(o)}}
1
+ import{__decorate as t}from"tslib";import{ActorComponent as i,Component as e}from"../../../component.js";import{RootMotionClip as s}from"../../../../animation/root-motion.js";import{inject as r}from"../../../../inject.js";import{ViewController as o}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,LoopOnce as l}from"three";let h=class extends i{constructor(){super(...arguments),this.viewController=r(o),this.stateMachines=[],this.upperStateMachines=[],this.fadeTime=.2,this.movementSpeed=null,this.upperBodyTimer=0,this.upperBodyOverride=!1,this.fullBodyTimer=0,this.currentFullBodyPriority=-1,this.currentUpperBodyPriority=-1,this.getFullBodyClip=a((t=>t.uuid),(t=>u(this.fullBodyMask,t))),this.getUpperBodyClip=a((t=>t.uuid),(t=>u(this.upperBodyMask,t)))}onInit(){this.viewController.onUpdate(this.actor).subscribe((t=>this.updateInternal(t)))}getRootMotionAction(){if(this.fullBodyAction.getClip()instanceof s)return this.fullBodyAction}setup(t,i,e){null!=i&&(this.upperBodyMask=c(i),this.fullBodyMask=function(t,i){const e=new Set(c(i).map((t=>t.uuid))),s=[];return t.traverse((t=>{(t instanceof p||t.isBone)&&!e.has(t.uuid)&&s.push(t)})),s}(function(t){let i;return t.traverse((t=>{(t instanceof p||t.isBone)&&null==i&&(i=t)})),i}(t),i)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e&&this.play(e,{priority:0})})),this.upperStateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e?this.playUpper(e,{priority:0}):this.play(this.fullBodyClip)}))}updateInternal(t){null!=this.mixer&&(this.upperBodyTimer+=t,this.fullBodyTimer+=t,this.upperBodyAction&&this.upperBodyOverride&&this.upperBodyAction.getClip().duration-2*this.fadeTime<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip))),this.fullBodyAction&&this.fullBodyAction.loop===l&&this.fullBodyAction.getClip().duration-2*this.fadeTime<this.fullBodyTimer&&(this.currentFullBodyPriority=-1),this.updateStateMachines(t),this.syncMovementSpeed(this.fullBodyAction),this.upperBodyOverride||this.syncMovementSpeed(this.upperBodyAction),this.mixer.update(t))}syncMovementSpeed(t){if(null!=t){const i=t.getClip();i instanceof s&&i.fixedInPlace&&null!=this.movementSpeed&&(t.timeScale=i.duration/i.displacement*this.movementSpeed)}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){this.stateMachines.splice(this.stateMachines.indexOf(t))}removeUpperStateMachine(t){this.upperStateMachines.splice(this.upperStateMachines.indexOf(t))}playUpper(t,i={}){const e=i?.priority??1;e<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=e,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i),this.upperBodyTimer=0,this.upperBodyOverride=!0)}play(t,i={}){!function(t,i){if(!1===t||"function"==typeof t&&!1===t())throw new Error(i)}(null!=this.mixer,"Can't play animation before setup is called");const e=i.priority??1;e<this.currentFullBodyPriority||(this.currentFullBodyPriority=e,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i)),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),i),this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction))}onActionDone(t){return new Promise((i=>{const e=s=>{s.action===t&&(i(s.action),this.mixer.removeEventListener("finished",e))};this.mixer.addEventListener("finished",e)}))}transition(t,i,e={}){if(null!=t&&t.getClip().uuid===i.uuid)return t;if(t){const e=t,s=t=this.mixer.clipAction(i);s.play(),s.enabled=!0,s.setEffectiveTimeScale(1),s.setEffectiveWeight(1),s.time=0,e.crossFadeTo(s,this.fadeTime,!0)}else t=this.mixer.clipAction(i),t?.fadeIn(.3),t?.play();return!1===e.loop&&(t.setLoop(l,1),t.clampWhenFinished=!0,t.reset()),t}};h=t([e()],h);export{h as CharacterAnimationComponent};function u(t,i){if(null==t)return i;const e=i.clone(),s=new Set(t.map((t=>t.name)));return e.tracks=e.tracks.filter((t=>s.has(t.name.split(".")[0]))),e}function c(t){return t.flatMap((t=>function(t){const i=[];return t.traverse((t=>{i.push(t)})),i}(t))).filter((t=>t instanceof p))}function a(t,i){const e=new Map;return(s,...r)=>{const o=t(s);return e.has(o)||e.set(o,i(s,...r)),e.get(o)}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -35,6 +35,8 @@ export declare class CharacterMovementComponent extends ActorComponent {
35
35
  set snapToGround(distance: number);
36
36
  set offset(distance: number);
37
37
  get offset(): number;
38
+ set normalNudgeFactor(factor: number);
39
+ get normalNudgeFactor(): number;
38
40
  readonly velocity: Vector3;
39
41
  mode: CharacterMovementMode;
40
42
  isSprinting: boolean;
@@ -45,6 +47,7 @@ export declare class CharacterMovementComponent extends ActorComponent {
45
47
  private resetRootMotion;
46
48
  private rootMotionInterpolant;
47
49
  onInit(): void | Promise<void>;
50
+ private debugDirection;
48
51
  private rootMotionAction;
49
52
  setRootMotionAction(action: AnimationAction): void;
50
53
  private getWallDirection;