@hology/core 0.0.136 → 0.0.138
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.
- package/dist/csm.js +1 -1
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-collision-behaviour.js +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-param.js +1 -1
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/effects/vfx/vfx-service.js +1 -1
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/builtin/positional-audio-actor.js +1 -1
- package/dist/gameplay/actors/builtin/post-process-volume-actor.js +1 -1
- package/dist/gameplay/actors/builtin/trigger-volume.js +1 -1
- package/dist/gameplay/actors/camera/camera-component.js +1 -1
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/ai/behavior-tree/bt.js +1 -1
- package/dist/gameplay/ai/dynamic-tiled-navmesh.js +1 -1
- package/dist/gameplay/ai/dynamic-tiled-navmesh.worker.js +1 -1
- package/dist/gameplay/ai/navigation.js +1 -1
- package/dist/gameplay/animation/anim-sm.js +1 -1
- package/dist/gameplay/animation/root-motion.js +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/input/input-service.js +1 -1
- package/dist/gameplay/input/input.js +1 -1
- package/dist/gameplay/polyfill.js +1 -1
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/pointer-events.js +1 -1
- package/dist/gameplay/services/render.js +1 -1
- package/dist/gameplay/services/shader-provider.js +1 -1
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering/color-pass.js +1 -1
- package/dist/rendering/fog/volumetric-fog-pass.d.ts +20 -4
- package/dist/rendering/fog/volumetric-fog-pass.d.ts.map +1 -1
- package/dist/rendering/fog/volumetric-fog-pass.js +1 -1
- package/dist/rendering/outline-effect.js +1 -1
- package/dist/rendering/ssr/SSRPass.js +1 -1
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/bootstrap.js +1 -1
- package/dist/scene/collision/collision-shape-import.js +1 -1
- package/dist/scene/landscape/landscape-manager.js +1 -1
- package/dist/scene/landscape/landscape.js +1 -1
- package/dist/scene/landscape/utils.js +1 -1
- package/dist/scene/materializer.d.ts +13 -1
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/materials/grass-foliage.js +1 -1
- package/dist/scene/materials/water.js +1 -1
- package/dist/scene/model.d.ts +1 -1
- package/dist/scene/model.d.ts.map +1 -1
- package/dist/scene/runtime-asset-service.js +1 -1
- package/dist/scene/scene-data-service.js +1 -1
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/builtin/landscape-composite-shader.js +1 -1
- package/dist/shader/builtin/layered-shader.js +1 -1
- package/dist/shader/color-layer.js +1 -1
- package/dist/shader/parameter.js +1 -1
- package/dist/shader-nodes/effects.js +1 -1
- package/dist/shader-nodes/glsl-node.js +1 -1
- package/dist/shader-nodes/layers.js +1 -1
- package/dist/shader-nodes/particle.js +1 -1
- package/dist/shader-nodes/voronoi.js +1 -1
- package/dist/test/injection.test.js +1 -1
- package/dist/utils/async.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/files.js +1 -1
- package/dist/utils/math.js +1 -1
- package/dist/utils/three/depth-pass.js +1 -1
- package/dist/utils/three/outline-pass.js +1 -1
- package/dist/utils/three/stats.js +1 -1
- package/dist/utils/three/transform-controls.js +1 -1
- package/dist/utils/three/traverse.js +1 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/dist/csm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as t from"three";import{ShaderChunk as e}from"three";import{CSM as i}from"three/examples/jsm/csm/CSM.js";const n={add:t.Object3D.prototype.add,attach:t.Object3D.prototype.attach},a=new WeakMap,o=new WeakMap;let r=new WeakSet;export const CSMUtil=new class{constructor(){this.renderingView=null}onBeforeCompile(e,i){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.renderingView.csm.cascades;const n=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.far:Number.MAX_SAFE_INTEGER,a=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.near:0,o=Math.min(n,this.renderingView.csm.maxFar),r=[];this.renderingView.csm.getExtendedBreaks(r),i.uniforms.CSM_cascades={value:r},i.uniforms.cameraNear={value:a},i.uniforms.shadowFar={value:o}}patchSetupMaterial(){i.prototype.setupMaterial=function(t){if(r.has(t))return;r.add(t),t.defines=t.defines||{},t.defines.USE_CSM=1,t.defines.CSM_CASCADES=this.cascades,this.fade&&(t.defines.CSM_FADE="");const e=[],i=this,n=this.shaders,a=t.onBeforeCompile;t.onBeforeCompile=function(o,r){a.call(t,o,r);const d=Math.min(i.camera.far,i.maxFar);i.getExtendedBreaks(e),o.uniforms.CSM_cascades={value:e},o.uniforms.cameraNear={value:i.camera.near},o.uniforms.shadowFar={value:d},n.set(t,o)},n.set(t,null)}}patchThreeAdd(){const e=this.renderingView;a.set(e.scene,e.csm);for(const[e,i]of Object.entries(n))t.Object3D.prototype[e]=function(...e){let n=this;for(;null!=n.parent;)n=n.parent;const r=n,d=a.get(r);if(null==d)return i.apply(this,arguments),this;o.has(r)||o.set(r,new WeakSet);const c=o.get(r);function h(t){t&&!c.has(t)&&(c.add(t),d?.setupMaterial(t))}return e.forEach((e=>e?.traverse((e=>{if(e instanceof t.Mesh||e instanceof t.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)h(t);else h(e.material)})))),i.apply(this,arguments),this}}};e.lights_pars_begin;export const CSMShader={lights_fragment_begin:"\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\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\t// Iridescence F0 approximation\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\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\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\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\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 ) && 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 )\n\t\tvec2 cascade;\n\t\tfloat cascadeCenter;\n\t\tfloat closestEdge;\n\t\tfloat margin;\n\t\tfloat csmx;\n\t\tfloat csmy;\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, directLight );\n\n\t\t\t#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\t\t\t// NOTE: Depth gets larger away from the camera.\n\t\t\t\t// cascade.x is closer, cascade.y is further\n\t\t\t\tcascade = CSM_cascades[ i ];\n\t\t\t\tcascadeCenter = ( cascade.x + cascade.y ) / 2.0;\n\t\t\t\tclosestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;\n\t\t\t\tmargin = 0.25 * pow( closestEdge, 2.0 );\n\t\t\t\tcsmx = cascade.x - margin / 2.0;\n\t\t\t\tcsmy = cascade.y + margin / 2.0;\n\t\t\t\tif( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {\n\n\t\t\t\t\tfloat dist = min( linearDepth - csmx, csmy - linearDepth );\n\t\t\t\t\tfloat ratio = clamp( dist / margin, 0.0, 1.0 );\n\n\t\t\t\t\tvec3 prevColor = directLight.color;\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tbool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;\n\t\t\t\t\tdirectLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );\n\n\t\t\t\t\tReflectedLight prevLight = reflectedLight;\n\t\t\t\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\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\tfloat blendRatio = shouldBlend ? ratio : 1.0;\n\n\t\t\t\t\treflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );\n\t\t\t\t\treflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );\n\t\t\t\t\treflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );\n\t\t\t\t\treflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );\n\n\t\t\t\t}\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#elif defined (USE_SHADOWMAP)\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, directLight );\n\n\t\t\t#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\n\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\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, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#elif ( NUM_DIR_LIGHT_SHADOWS > 0 )\n\t\t// note: no loop here - all CSM lights are in fact one light only\n\t\tgetDirectionalLightInfo( directionalLights[0], directLight );\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\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, directLight );\n\n\t\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, 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, 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",lights_pars_begin:"\n#if defined( USE_CSM ) && defined( CSM_CASCADES )\nuniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;\n#endif\n\t"+e.lights_pars_begin};/*
|
|
1
|
+
import*as t from"three";import{ShaderChunk as e}from"three";import{CSM as i}from"three/examples/jsm/csm/CSM.js";const n={add:t.Object3D.prototype.add,attach:t.Object3D.prototype.attach},a=new WeakMap,o=new WeakMap;let r=new WeakSet;export const CSMUtil=new class{constructor(){this.renderingView=null}onBeforeCompile(e,i){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.renderingView.csm.cascades;const n=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.far:Number.MAX_SAFE_INTEGER,a=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.near:0,o=Math.min(n,this.renderingView.csm.maxFar),r=[];this.renderingView.csm.getExtendedBreaks(r),i.uniforms.CSM_cascades={value:r},i.uniforms.cameraNear={value:a},i.uniforms.shadowFar={value:o}}patchSetupMaterial(){i.prototype.setupMaterial=function(t){if(r.has(t))return;r.add(t),t.defines=t.defines||{},t.defines.USE_CSM=1,t.defines.CSM_CASCADES=this.cascades,this.fade&&(t.defines.CSM_FADE="");const e=[],i=this,n=this.shaders,a=t.onBeforeCompile;t.onBeforeCompile=function(o,r){a.call(t,o,r);const d=Math.min(i.camera.far,i.maxFar);i.getExtendedBreaks(e),o.uniforms.CSM_cascades={value:e},o.uniforms.cameraNear={value:i.camera.near},o.uniforms.shadowFar={value:d},n.set(t,o)},n.set(t,null)}}patchThreeAdd(){const e=this.renderingView;a.set(e.scene,e.csm);for(const[e,i]of Object.entries(n))t.Object3D.prototype[e]=function(...e){let n=this;for(;null!=n.parent;)n=n.parent;const r=n,d=a.get(r);if(null==d)return i.apply(this,arguments),this;o.has(r)||o.set(r,new WeakSet);const c=o.get(r);function h(t){t&&!c.has(t)&&(c.add(t),d?.setupMaterial(t))}return e.forEach(e=>e?.traverse(e=>{if(e instanceof t.Mesh||e instanceof t.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)h(t);else h(e.material)})),i.apply(this,arguments),this}}};e.lights_pars_begin;export const CSMShader={lights_fragment_begin:"\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\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\t// Iridescence F0 approximation\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\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\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\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\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 ) && 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 )\n\t\tvec2 cascade;\n\t\tfloat cascadeCenter;\n\t\tfloat closestEdge;\n\t\tfloat margin;\n\t\tfloat csmx;\n\t\tfloat csmy;\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, directLight );\n\n\t\t\t#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\t\t\t// NOTE: Depth gets larger away from the camera.\n\t\t\t\t// cascade.x is closer, cascade.y is further\n\t\t\t\tcascade = CSM_cascades[ i ];\n\t\t\t\tcascadeCenter = ( cascade.x + cascade.y ) / 2.0;\n\t\t\t\tclosestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;\n\t\t\t\tmargin = 0.25 * pow( closestEdge, 2.0 );\n\t\t\t\tcsmx = cascade.x - margin / 2.0;\n\t\t\t\tcsmy = cascade.y + margin / 2.0;\n\t\t\t\tif( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {\n\n\t\t\t\t\tfloat dist = min( linearDepth - csmx, csmy - linearDepth );\n\t\t\t\t\tfloat ratio = clamp( dist / margin, 0.0, 1.0 );\n\n\t\t\t\t\tvec3 prevColor = directLight.color;\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tbool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;\n\t\t\t\t\tdirectLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );\n\n\t\t\t\t\tReflectedLight prevLight = reflectedLight;\n\t\t\t\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\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\tfloat blendRatio = shouldBlend ? ratio : 1.0;\n\n\t\t\t\t\treflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );\n\t\t\t\t\treflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );\n\t\t\t\t\treflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );\n\t\t\t\t\treflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );\n\n\t\t\t\t}\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#elif defined (USE_SHADOWMAP)\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, directLight );\n\n\t\t\t#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\n\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\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, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#elif ( NUM_DIR_LIGHT_SHADOWS > 0 )\n\t\t// note: no loop here - all CSM lights are in fact one light only\n\t\tgetDirectionalLightInfo( directionalLights[0], directLight );\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\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, directLight );\n\n\t\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, 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, 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",lights_pars_begin:"\n#if defined( USE_CSM ) && defined( CSM_CASCADES )\nuniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;\n#endif\n\t"+e.lights_pars_begin};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as s}from"tslib";import*as t from"three";import{Rate as e}from"@hology/nebula";import{Actor as i,BaseActor as r}from"../../gameplay/actors/actor.js";import{inject as o}from"../../gameplay/inject.js";import{AssetLoader as a}from"../../gameplay/services/asset-loader.js";import{ViewController as h}from"../../gameplay/services/render.js";import{World as m}from"../../gameplay/services/world.js";import{DelayRate as l}from"./rates.js";import{materializeVfx as d}from"./vfx-materializer.js";import{PhysicsSystem as n}from"../../gameplay/index.js";import{ShaderProvider as p}from"../../gameplay/services/shader-provider.js";let y=class extends r{constructor(){super(...arguments),this.timescale=1,this.paused=!0,this.assetLoader=o(a),this.world=o(m),this.view=o(h),this.physics=o(n),this.shaderProvider=o(p),this._worldPos=new t.Vector3,this._worldRot=new t.Quaternion,this._worldEul=new t.Euler,this.max=0}async fromAsset(s){if("vfx"!==s.type)throw"Asset must be a VFX asset but is "+s.type;null!=this.system&&(this.system.destroy(),this.system.emitters.forEach(
|
|
1
|
+
import{__decorate as s}from"tslib";import*as t from"three";import{Rate as e}from"@hology/nebula";import{Actor as i,BaseActor as r}from"../../gameplay/actors/actor.js";import{inject as o}from"../../gameplay/inject.js";import{AssetLoader as a}from"../../gameplay/services/asset-loader.js";import{ViewController as h}from"../../gameplay/services/render.js";import{World as m}from"../../gameplay/services/world.js";import{DelayRate as l}from"./rates.js";import{materializeVfx as d}from"./vfx-materializer.js";import{PhysicsSystem as n}from"../../gameplay/index.js";import{ShaderProvider as p}from"../../gameplay/services/shader-provider.js";let y=class extends r{constructor(){super(...arguments),this.timescale=1,this.paused=!0,this.assetLoader=o(a),this.world=o(m),this.view=o(h),this.physics=o(n),this.shaderProvider=o(p),this._worldPos=new t.Vector3,this._worldRot=new t.Quaternion,this._worldEul=new t.Euler,this.max=0}async fromAsset(s){if("vfx"!==s.type)throw"Asset must be a VFX asset but is "+s.type;null!=this.system&&(this.system.destroy(),this.system.emitters.forEach(s=>s.reset())),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem(),this.world.scene.add(this.object);const{system:t,dispose:e,container:i}=await d(this.sourceAsset,this.object,{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.view,this.physics,this.shaderProvider);this.system=t,this.disposeSystem=e,this.particleSystemContainer=i}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 e&&(t.nextTime=1/0)})}restart(){if(null!=this.system&&null!=this.system.emitters)for(const s of this.system.emitters){const t=s.rate;t instanceof l?t.restart():t.nextTime=0,s.removeAllParticles()}}onUpdate(s){this.paused||(this.object.getWorldPosition(this._worldPos),this.object.getWorldQuaternion(this._worldRot),this._worldEul.setFromQuaternion(this._worldRot),this.system?.emitters.forEach(s=>{"world"===s._space&&(s.setPosition(this._worldPos),s.setRotation(this._worldEul))}),this.system?.update(s*this.timescale))}getParticleCount(){return this.system?.getCount()??0}onEndPlay(){this.stop(),null!=this.disposeSystem&&this.disposeSystem()}};y=s([i()],y);export{y as VfxActor};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Behaviour as o,Emitter as t}from"@hology/nebula";import{RayTestResult as i}from"../../gameplay/services/physics/physics-system.js";import{Color as e,Vector3 as l}from"three";export class WorldCollisionBehaviour extends o{constructor(o,t=0,i=0,e=0){super(),this.physics=o,this.bounce=t,this.friction=i,this.lifeLoss=e}initialize(o){null==o.old.rayFrom?o.old.rayFrom=new l:o.old.rayFrom.set(0,0,0),o.old.rayLength=-1,null==o.old.hitNormal?o.old.hitNormal=new l:o.old.hitNormal.set(0,0,0),o.old.hitDistance=-1}mutate(o,i,e){if(0===o.velocity.length())return;const l=.5*o.scale*.5;a.copy(o.velocity).normalize(),s.copy(o.velocity).multiplyScalar(i);const y=r.copy(o.old.velocity).normalize(),d=o.old.rayFrom,m=o.old.hitDistance,p=o.old.hitNormal,u=o.old.rayLength;if(y.dot(a)>.99&&o.position.distanceTo(d)+l<u)m>0?(n.hasHit=!0,n.distance=m-d.distanceTo(o.position),n.hitNormal.copy(p)):n.hasHit=!1;else{const t=15;c.copy(o.position).addScaledVector(o.velocity,i*t).addScaledVector(a,l),this.physics.rayTest(o.position,c,n),o.old.rayFrom.copy(o.position),o.old.hitDistance=n.hasHit?n.distance:-1,o.old.hitNormal.copy(n.hitNormal),o.old.rayLength=o.position.distanceTo(c)}var f,v,w;n.hasHit&&s.length()+l>n.distance&&(o.acceleration.set(0,0,0),this.bounce>0?(f=o.velocity,v=n.hitNormal,w=this.bounce,o.velocity.copy(f).sub(h.copy(v).multiplyScalar(2*f.dot(v))).multiplyScalar(w)):function(o,t,i=.95,e){const l=h.copy(t).multiplyScalar(o.dot(t)),s=e.sub(l).multiplyScalar(1-i)}(o.velocity,n.hitNormal,this.friction,o.velocity),o.old.hitDistance=-1,o.parent instanceof t&&o.parent.dispatch("PARTICLE_COLLISION",o),this.lifeLoss>0&&setTimeout((
|
|
1
|
+
import{Behaviour as o,Emitter as t}from"@hology/nebula";import{RayTestResult as i}from"../../gameplay/services/physics/physics-system.js";import{Color as e,Vector3 as l}from"three";export class WorldCollisionBehaviour extends o{constructor(o,t=0,i=0,e=0){super(),this.physics=o,this.bounce=t,this.friction=i,this.lifeLoss=e}initialize(o){null==o.old.rayFrom?o.old.rayFrom=new l:o.old.rayFrom.set(0,0,0),o.old.rayLength=-1,null==o.old.hitNormal?o.old.hitNormal=new l:o.old.hitNormal.set(0,0,0),o.old.hitDistance=-1}mutate(o,i,e){if(0===o.velocity.length())return;const l=.5*o.scale*.5;a.copy(o.velocity).normalize(),s.copy(o.velocity).multiplyScalar(i);const y=r.copy(o.old.velocity).normalize(),d=o.old.rayFrom,m=o.old.hitDistance,p=o.old.hitNormal,u=o.old.rayLength;if(y.dot(a)>.99&&o.position.distanceTo(d)+l<u)m>0?(n.hasHit=!0,n.distance=m-d.distanceTo(o.position),n.hitNormal.copy(p)):n.hasHit=!1;else{const t=15;c.copy(o.position).addScaledVector(o.velocity,i*t).addScaledVector(a,l),this.physics.rayTest(o.position,c,n),o.old.rayFrom.copy(o.position),o.old.hitDistance=n.hasHit?n.distance:-1,o.old.hitNormal.copy(n.hitNormal),o.old.rayLength=o.position.distanceTo(c)}var f,v,w;n.hasHit&&s.length()+l>n.distance&&(o.acceleration.set(0,0,0),this.bounce>0?(f=o.velocity,v=n.hitNormal,w=this.bounce,o.velocity.copy(f).sub(h.copy(v).multiplyScalar(2*f.dot(v))).multiplyScalar(w)):function(o,t,i=.95,e){const l=h.copy(t).multiplyScalar(o.dot(t)),s=e.sub(l).multiplyScalar(1-i)}(o.velocity,n.hitNormal,this.friction,o.velocity),o.old.hitDistance=-1,o.parent instanceof t&&o.parent.dispatch("PARTICLE_COLLISION",o),this.lifeLoss>0&&setTimeout(()=>{o.life-=this.lifeLoss+30},30))}}const s=new l,a=new l,c=new l,n=new i,r=(new l,new l),h=new l;(new e).setRGB(Math.random(),Math.random(),Math.random());/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e,{Behaviour as t,Body as i,Emitter as n,Rate as a}from"@hology/nebula";import*as s from"three";import{Object3D as r}from"three";import{AttributeVec3Node as o,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as u,UniformFloatNode as m,UniformVec3Node as p,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as g,attributes as w,float as v,glslFunction as b,lambertMaterial as x,log as A,pow as E,rgb as M,rgba as P,saturate as T,standardMaterial as I,textureSampler2d as B,transformed as C,uniformFloat as R,uniforms as k,varying as S,varyingAttributes as j,varyingVec3 as z,varyingVec4 as D}from"three-shader-graph";import{prepareClassParameters as V,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as Q}from"../../scene/model.js";import{ShapeLibrary as U}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as W,linearEyeDepth as L}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as q,particleTimeUniformName as H,particleUniforms as G,particleVelcoityUniformName as J}from"../../shader-nodes/particle.js";import{sampleFlipbook as O}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as X}from"./rates.js";import{StretchedSprite as Y}from"./stretched-sprite.js";import{ThreeBlendingMode as Z}from"./vfx-asset.js";import{VfxBehaviourLibrary as _,VfxInitializserLibrary as $}from"./vfx-defs.js";import{MultiRenderer as ee}from"./vfx-renderers.js";import{WorldCollisionBehaviour as te}from"./vfx-collision-behaviour.js";import{SpriteNodeShaderMaterial as ie}from"../../shader/sprite-shader.js";export async function materializeVfx(t,i,n,a,o,l){let c=i;for(;null!=c.parent;)c=c.parent;const u=new r;u.name="particle system local",i.add(u);const m=new r;m.name="particle system world",c.add(m);const p=new ee(m,u,s,a),h=new e;return(await Promise.all(t.vfx.emitters.map((async e=>{const t=await ne(e,n,h,o,l);return t.setParentRecursive(h),t.emit()})))).forEach((e=>h.addEmitter(e))),h.addRenderer(p).emit({onEnd:()=>{}}),{container:m,system:h,dispose:()=>{m.removeFromParent(),u.removeFromParent(),p.dispose()}}}async function ne(e,t,n,u,M){const I=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new X(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new a(0,1/0)}return t}(e);let z;switch(e.output.type){case"sprite":z=new i(await async function(e,t,i){let n=null;n=null!=e.shader?await se(e,t,i):await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ae,n=B(i);let a=n.sample(j.uv);e.flipbook?.enabled&&(a=O(n,w.uv,e.flipbook.columns,e.flipbook.rows,G.time,e.flipbook.fps,e.flipbook.mode));const r=new m("rotation",0),o=new p("color").rgb,l=R("opacity",1),c=L.subtract(W).divide(L);let u=l;switch(e.opacityChannel??"red"){case"none":break;case"red":u=u.multiply(a.r);break;case"alpha":u=u.multiply(a.a)}if("number"==typeof e.softness&&e.softness>0){const t=E(c,v(e.softness));u=u.multiply(t)}const h=b(d,{position:C.position,modelViewMatrix:k.modelViewMatrix,rotation:r},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new ie({color:P(o.multiply(a.rgb).multiplyScalar(e.intensity??1),u),transparent:!0,position:h,uniforms:{color:{value:new s.Color(e.color)}}});null!=f&&!0===e.bloom&&(f.userData.hasBloom=!0);return f.blending=Z[e.blendingMode]??s.NormalBlending,f}(e,t);const a=new s.Mesh(new s.PlaneGeometry(1,1),n);return a.name="sprite",a}(e.output,t,M));break;case"stretchedSprite":z=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ae,n=B(i).sample(j.uv),a=D(new l("color")),r=a.rgb.multiply(n.rgb);let o=a.w;switch(e.opacityChannel??"red"){case"none":break;case"red":o=o.multiply(n.r);break;case"alpha":o=o.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=L.subtract(W).divide(A(L)),i=E(t,v(e.softness));o=T(o.multiply(i))}const c=b(d,{position:w.position,offset:y("offset"),modelViewMatrix:k.modelViewMatrix,velocity:g("velocity"),size:y("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \n mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; \n mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;\n return projectionMatrix * mvPosition;\n ");var u=new ie({color:P(r.multiplyScalar(e.intensity??1),o),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new s.Color(e.color)}}});null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);u.blending=Z[e.blendingMode]??s.NormalBlending;const m=new Y(new s.PlaneGeometry(1,1),u);return m.scaleFactor=e.scale,m}(e.output,t));break;case"shape":z=new i(await async function(e,t,i){if(null==e.shape)return console.log("Shape is null"),new r;const n=U[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new r;const a=F(e.params??{}),l=n.geometry(a);let u=null;u=null!=e.shader?await se(e,t,i):null!=e.material?re(await t.getMaterial(e.material)):function(){const e=S(new h("instanceColor")).rgb,t=S(new o("particleData")).x;return new c({color:x({color:e}).rgb.rgba(t),transparent:!0})}();null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);return new s.Mesh(l,u)}(e.output,t,M));break;case"mesh":z=new i(await async function(e,t,i){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new r;const n=await t.getMesh(e.assetId),a=await t.getAsset(e.assetId);if(null!=e.shader||null!=e.material){let a;a=null!=e.shader?await se(e,t,i):re(await t.getMaterial(e.material)),null!=a&&!0===e.bloom&&(a.userData.hasBloom=!0),null!=a&&!0===e.bloom&&(a.userData.hasBloom=!0),n.traverse((e=>{e instanceof s.Mesh&&(e.material=a)}))}else{const e=[];if(null!=a.materialAssignments)for(const i of a.materialAssignments)n.traverse((n=>{n instanceof s.Mesh&&n.material instanceof s.Material&&n.material.color instanceof s.Color&&(n.material.name!=i.name&&null!=i.name||"#"+n.material.color.getHexString()!==i.color||e.push(t.getMaterial(i.materialId).then((e=>n.material=e))))}));await Promise.all(e)}const o=[];if(n.traverse((e=>{e instanceof s.Mesh&&o.push(e)})),1===o.length){const e=o[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return n}(e.output,t,M));break;case"trail":z=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,texture:null!=e.output.texture?await t.getTexture(e.output.texture):null,opacityChannel:e.output.opacityChannel,color:e.output.color,colorEnd:e.output.colorEnd,intensity:e.output.intensity??1,intensityEnd:e.output.intensityEnd??1,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom,scrollSpeed:e.output.scrollSpeed,width:e.output.width,billboard:e.output.billboard??!1});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const V=new le;V.parent=n,V.setRate(I),V._space=e.output.space;const q=await Promise.all(e.initializers.filter((e=>!1!==e.enabled)).filter((e=>null!=$[e.type])).map((async e=>{const t=$[e.type],i=await F(e.params??{});return t.build(i)})));q.push(z,new N),V.addInitializers(q);const H=await Promise.all(e.behaviours.filter((e=>!1!==e.enabled)).filter((e=>null!=_[e.type])).map((async e=>{const t=_[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==Q.Curve&&(n.type=Q.Curve);const i=await F(e.params??{});return t.build(i)})).sort(((e,t)=>e instanceof te?1:0)));H.push(new oe);for(const e of H)e instanceof te&&(e.physics=u);V.addBehaviours(H);for(const i of e.children){const e=await ne(i,t,n,u,M),a=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=V.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&V.childEmitters.splice(e,1),a.release(t)},t})),s=V.eventDispatcher,r=new Map;V.bindEmitterEvent=!0,s.addEventListener("PARTICLE_DEAD",(e=>{const t=r.get(e.id);if(null!=t){const e=V.childEmitters.findIndex((e=>e.id===t.id));null!=e&&(t.stopEmit(),V.childEmitters.splice(e,1))}}));let o="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":o="PARTICLE_COLLISION";break;case"start":o="PARTICLE_CREATED"}s.addEventListener(o,(e=>{const t=a.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),V.childEmitters.push(t),r.set(e.id,t),t.parentParticle=e,t.system=V.system,t.emit()}))}return V}const ae=(new s.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=");async function se(e,t,i){const n=i.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new s.Material;const a=new n.type,r=await V(e.shaderParams,n.type,t,{getTexture:e=>t.getTexture(e.id),getMaterial:e=>t.getMaterial(e.id),getMesh:e=>t.getMesh(e.id)},void 0,void 0,void 0,void 0);return Object.assign(a,r),a.build()}function re(e){const t=S(new h("instanceColor")).rgb;let i,n=S(new o("particleData")).x;if(e instanceof s.MeshStandardMaterial||e instanceof s.MeshLambertMaterial||e instanceof s.MeshBasicMaterial){let a=t.multiply(M(e.color));null!=e.map&&(a=a.multiply(B(e.map).sample(j.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(B(e.alphaMap).sample(j.uv).r)),e instanceof s.MeshStandardMaterial?i=new c({color:I({color:a,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof s.MeshLambertMaterial?i=new c({color:x({color:a}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof s.MeshBasicMaterial&&(i=new c({color:a.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}return null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent),i??e}class oe extends t{initialize(e){e.body instanceof s.Object3D&&e.body.traverse((e=>{if(e instanceof s.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[q]||null!=t.uniforms[H]||t.uniforms[J])}}))}mutate(e,t,i){this.energize(e,t),e.target instanceof r&&e.target.traverse((t=>{if(t instanceof s.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[q]&&(i.uniforms[q].value=this.energy),null!=i.uniforms[H]&&(i.uniforms[H].value=e.age),null!=i.uniforms[J]&&(i.uniforms[J].value=e.velocity))}}))}}class le extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new le;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach((t=>t.setParentRecursive(e)))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
|
|
1
|
+
import e,{Behaviour as t,Body as i,Emitter as n,Rate as a}from"@hology/nebula";import*as s from"three";import{Object3D as r}from"three";import{AttributeVec3Node as o,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as u,UniformFloatNode as m,UniformVec3Node as p,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as g,attributes as w,float as v,glslFunction as b,lambertMaterial as x,log as A,pow as E,rgb as M,rgba as P,saturate as T,standardMaterial as I,textureSampler2d as B,transformed as C,uniformFloat as R,uniforms as k,varying as S,varyingAttributes as j,varyingVec3 as z,varyingVec4 as D}from"three-shader-graph";import{prepareClassParameters as V,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as Q}from"../../scene/model.js";import{ShapeLibrary as U}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as W,linearEyeDepth as L}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as q,particleTimeUniformName as H,particleUniforms as G,particleVelcoityUniformName as J}from"../../shader-nodes/particle.js";import{sampleFlipbook as O}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as X}from"./rates.js";import{StretchedSprite as Y}from"./stretched-sprite.js";import{ThreeBlendingMode as Z}from"./vfx-asset.js";import{VfxBehaviourLibrary as _,VfxInitializserLibrary as $}from"./vfx-defs.js";import{MultiRenderer as ee}from"./vfx-renderers.js";import{WorldCollisionBehaviour as te}from"./vfx-collision-behaviour.js";import{SpriteNodeShaderMaterial as ie}from"../../shader/sprite-shader.js";export async function materializeVfx(t,i,n,a,o,l){let c=i;for(;null!=c.parent;)c=c.parent;const u=new r;u.name="particle system local",i.add(u);const m=new r;m.name="particle system world",c.add(m);const p=new ee(m,u,s,a),h=new e;return(await Promise.all(t.vfx.emitters.map(async e=>{const t=await ne(e,n,h,o,l);return t.setParentRecursive(h),t.emit()}))).forEach(e=>h.addEmitter(e)),h.addRenderer(p).emit({onEnd:()=>{}}),{container:m,system:h,dispose:()=>{m.removeFromParent(),u.removeFromParent(),p.dispose()}}}async function ne(e,t,n,u,M){const I=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new X(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new a(0,1/0)}return t}(e);let z;switch(e.output.type){case"sprite":z=new i(await async function(e,t,i){let n=null;n=null!=e.shader?await se(e,t,i):await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ae,n=B(i);let a=n.sample(j.uv);e.flipbook?.enabled&&(a=O(n,w.uv,e.flipbook.columns,e.flipbook.rows,G.time,e.flipbook.fps,e.flipbook.mode));const r=new m("rotation",0),o=new p("color").rgb,l=R("opacity",1),c=L.subtract(W).divide(L);let u=l;switch(e.opacityChannel??"red"){case"none":break;case"red":u=u.multiply(a.r);break;case"alpha":u=u.multiply(a.a)}if("number"==typeof e.softness&&e.softness>0){const t=E(c,v(e.softness));u=u.multiply(t)}const h=b(d,{position:C.position,modelViewMatrix:k.modelViewMatrix,rotation:r},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new ie({color:P(o.multiply(a.rgb).multiplyScalar(e.intensity??1),u),transparent:!0,position:h,uniforms:{color:{value:new s.Color(e.color)}}});null!=f&&!0===e.bloom&&(f.userData.hasBloom=!0);return f.blending=Z[e.blendingMode]??s.NormalBlending,f}(e,t);const a=new s.Mesh(new s.PlaneGeometry(1,1),n);return a.name="sprite",a}(e.output,t,M));break;case"stretchedSprite":z=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ae,n=B(i).sample(j.uv),a=D(new l("color")),r=a.rgb.multiply(n.rgb);let o=a.w;switch(e.opacityChannel??"red"){case"none":break;case"red":o=o.multiply(n.r);break;case"alpha":o=o.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=L.subtract(W).divide(A(L)),i=E(t,v(e.softness));o=T(o.multiply(i))}const c=b(d,{position:w.position,offset:y("offset"),modelViewMatrix:k.modelViewMatrix,velocity:g("velocity"),size:y("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \n mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; \n mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;\n return projectionMatrix * mvPosition;\n ");var u=new ie({color:P(r.multiplyScalar(e.intensity??1),o),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new s.Color(e.color)}}});null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);u.blending=Z[e.blendingMode]??s.NormalBlending;const m=new Y(new s.PlaneGeometry(1,1),u);return m.scaleFactor=e.scale,m}(e.output,t));break;case"shape":z=new i(await async function(e,t,i){if(null==e.shape)return console.log("Shape is null"),new r;const n=U[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new r;const a=F(e.params??{}),l=n.geometry(a);let u=null;u=null!=e.shader?await se(e,t,i):null!=e.material?re(await t.getMaterial(e.material)):function(){const e=S(new h("instanceColor")).rgb,t=S(new o("particleData")).x;return new c({color:x({color:e}).rgb.rgba(t),transparent:!0})}();null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);return new s.Mesh(l,u)}(e.output,t,M));break;case"mesh":z=new i(await async function(e,t,i){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new r;const n=await t.getMesh(e.assetId),a=await t.getAsset(e.assetId);if(null!=e.shader||null!=e.material){let a;a=null!=e.shader?await se(e,t,i):re(await t.getMaterial(e.material)),null!=a&&!0===e.bloom&&(a.userData.hasBloom=!0),null!=a&&!0===e.bloom&&(a.userData.hasBloom=!0),n.traverse(e=>{e instanceof s.Mesh&&(e.material=a)})}else{const e=[];if(null!=a.materialAssignments)for(const i of a.materialAssignments)n.traverse(n=>{n instanceof s.Mesh&&n.material instanceof s.Material&&n.material.color instanceof s.Color&&(n.material.name!=i.name&&null!=i.name||"#"+n.material.color.getHexString()!==i.color||e.push(t.getMaterial(i.materialId).then(e=>n.material=e)))});await Promise.all(e)}const o=[];if(n.traverse(e=>{e instanceof s.Mesh&&o.push(e)}),1===o.length){const e=o[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return n}(e.output,t,M));break;case"trail":z=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,texture:null!=e.output.texture?await t.getTexture(e.output.texture):null,opacityChannel:e.output.opacityChannel,color:e.output.color,colorEnd:e.output.colorEnd,intensity:e.output.intensity??1,intensityEnd:e.output.intensityEnd??1,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom,scrollSpeed:e.output.scrollSpeed,width:e.output.width,billboard:e.output.billboard??!1});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const V=new le;V.parent=n,V.setRate(I),V._space=e.output.space;const q=await Promise.all(e.initializers.filter(e=>!1!==e.enabled).filter(e=>null!=$[e.type]).map(async e=>{const t=$[e.type],i=await F(e.params??{});return t.build(i)}));q.push(z,new N),V.addInitializers(q);const H=await Promise.all(e.behaviours.filter(e=>!1!==e.enabled).filter(e=>null!=_[e.type]).map(async e=>{const t=_[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==Q.Curve&&(n.type=Q.Curve);const i=await F(e.params??{});return t.build(i)}).sort((e,t)=>e instanceof te?1:0));H.push(new oe);for(const e of H)e instanceof te&&(e.physics=u);V.addBehaviours(H);for(const i of e.children){const e=await ne(i,t,n,u,M),a=new EmitterPool(()=>{const t=e.clone();return t.onExpired=()=>{const e=V.childEmitters.findIndex(e=>e.id===t.id);-1!=e&&V.childEmitters.splice(e,1),a.release(t)},t}),s=V.eventDispatcher,r=new Map;V.bindEmitterEvent=!0,s.addEventListener("PARTICLE_DEAD",e=>{const t=r.get(e.id);if(null!=t){const e=V.childEmitters.findIndex(e=>e.id===t.id);null!=e&&(t.stopEmit(),V.childEmitters.splice(e,1))}});let o="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":o="PARTICLE_COLLISION";break;case"start":o="PARTICLE_CREATED"}s.addEventListener(o,e=>{const t=a.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),V.childEmitters.push(t),r.set(e.id,t),t.parentParticle=e,t.system=V.system,t.emit()})}return V}const ae=(new s.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=");async function se(e,t,i){const n=i.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new s.Material;const a=new n.type,r=await V(e.shaderParams,n.type,t,{getTexture:e=>t.getTexture(e.id),getMaterial:e=>t.getMaterial(e.id),getMesh:e=>t.getMesh(e.id)},void 0,void 0,void 0,void 0);return Object.assign(a,r),a.build()}function re(e){const t=S(new h("instanceColor")).rgb;let i,n=S(new o("particleData")).x;if(e instanceof s.MeshStandardMaterial||e instanceof s.MeshLambertMaterial||e instanceof s.MeshBasicMaterial){let a=t.multiply(M(e.color));null!=e.map&&(a=a.multiply(B(e.map).sample(j.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(B(e.alphaMap).sample(j.uv).r)),e instanceof s.MeshStandardMaterial?i=new c({color:I({color:a,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof s.MeshLambertMaterial?i=new c({color:x({color:a}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof s.MeshBasicMaterial&&(i=new c({color:a.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}return null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent),i??e}class oe extends t{initialize(e){e.body instanceof s.Object3D&&e.body.traverse(e=>{if(e instanceof s.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[q]||null!=t.uniforms[H]||t.uniforms[J])}})}mutate(e,t,i){this.energize(e,t),e.target instanceof r&&e.target.traverse(t=>{if(t instanceof s.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[q]&&(i.uniforms[q].value=this.energy),null!=i.uniforms[H]&&(i.uniforms[H].value=e.age),null!=i.uniforms[J]&&(i.uniforms[J].value=e.velocity))}})}}class le extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new le;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach(t=>t.setParentRecursive(e))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -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 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 VfxPool((
|
|
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 VfxPool(()=>this.create(t))}}export class VfxPool{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){t.stop(),this.instances.push(t)}dispose(){this.instances.length=0}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CustomRenderer as e,MeshRenderer as t,PUID as r}from"@hology/nebula";import*as a from"three";import{InstancedBufferAttribute as o,Object3D as i}from"three";import{NodeShaderMaterial as n}from"three-shader-graph";import{StretchedSprite as s}from"./stretched-sprite.js";import{Trail as l}from"./trail-renderer.js";import{SpriteNodeShaderMaterial as c}from"../../shader/sprite-shader";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){e.target=null,this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,o="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==o[d.trail]&&(o[d.trail]=new TrailRenderer(r,this.three)),e._renderer=o[d.trail]):e.body instanceof s?(null==o[d.stretchedBillboard]&&(o[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=o[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==o[d.sprite]&&(o[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=o[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof n?(null==o[d.instanced]&&(o[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=o[d.instanced]):e.body instanceof a.Object3D?(null==o[d.mesh]&&(o[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=o[d.mesh]):void 0}dispose(){this.localRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()})),this.worldRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new l(this.container,!1),o=new i;this.container.add(o),o.updateMatrixWorld(),o.updateWorldMatrix(!0,!0);const n=l.createBaseMaterial(t.texture,t.scrollSpeed,t.opacityChannel,t.billboard??!1);n.uniforms.taper.value=t.taper??!1;const s=new a.Color(t.color??0).multiplyScalar(t.intensity),c=new a.Color(t.colorEnd??0).multiplyScalar(t.intensityEnd??t.intensity??1);n.uniforms.headColor&&n.uniforms.tailColor&&(n.uniforms.headColor.value=new a.Vector4(s.r,s.g,s.b,t.opacityStart??1),n.uniforms.tailColor.value=new a.Vector4(c.r,c.g,c.b,t.opacityEnd??1)),t.bloom&&(n.userData.hasBloom=!0),r.initialize(n,Math.round(t.length??10),!1,t.width,null,o,t.billboard??!1);const d=e.rotation;o.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=o}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);const r=e.body;let a=x;e.old&&e.old.position?a.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize():a.copy(e.velocity).normalize();const o=w;o.setFromUnitVectors(a,y),t.rotation.set(0,0,0),t.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),t.applyQuaternion(o);const i=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=i){const t=this.trails[i];if(e.useAlpha&&t.material.uniforms.headColor&&t.material.uniforms.tailColor){t.material.uniforms.headColor.value.setW(r.opacityStart*e.alpha);t.material.uniforms.tailColor.value.setW(r.opacityEnd*e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),e.targetObject.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof i&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:o,rotation:n}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof c?e.target.material.rotation=e.rotation.z:t.rotation.set(n.x,n.y,n.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof i){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(u);a.applyAxisAngle(p,Math.PI/-2),h.setFromUnitVectors(a,r),t.quaternion.copy(h)}t.material instanceof a.Material&&(r&&(t.material instanceof c&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),o&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}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 class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.geometry.dispose()))}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),o=e.mesh.geometry.getAttribute("velocity"),i=e.mesh.geometry.getAttribute("rotation"),n=e.mesh.geometry.getAttribute("color");let s=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=C.copy(l.color).getRGB(M);n.setXYZW(s,e.r,e.g,e.b,1),n.needsUpdate=!0}l.useAlpha&&(n.setW(s,l.alpha),n.needsUpdate=!0),"number"==typeof l.rotation?i.setX(s,l.rotation):i.setX(s,l.rotation.x);const e=l.position;if(t.setXYZ(s,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(s,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;o.setXYZW(s,m.x*c,m.y*c,m.z*c,d),s++}s>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*s),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*s),r.needsUpdate=!0,n.clearUpdateRanges(),n.addUpdateRange(0,4*s),n.needsUpdate=!0,o.clearUpdateRanges(),o.addUpdateRange(0,4*s),o.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,s),i.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof s&&null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(null==r){const i=this.calcMaxCount(e),n=new a.InstancedBufferGeometry;n.setIndex(t.geometry.getIndex()),n.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&n.setAttribute("normal",t.geometry.getAttribute("normal")),n.setAttribute("uv",t.geometry.getAttribute("uv"));const s=new o(new Float32Array(3*i),3);s.setUsage(a.DynamicDrawUsage),n.setAttribute("offset",s);const l=new o(new Float32Array(4*i),4);if(l.setUsage(a.DynamicDrawUsage),n.setAttribute("color",l),t.material instanceof c){const e=new a.Color(t.material.color);for(let t=0;t<l.count;t++)l.setXYZW(t,e.r,e.g,e.b,1)}const d=new o(new Float32Array(3*i),3);d.setUsage(a.DynamicDrawUsage),n.setAttribute("size",d);const m=new o(new Float32Array(4*i),4);m.setUsage(a.DynamicDrawUsage),n.setAttribute("velocity",m);const u=new o(new Float32Array(4*i),1);u.setUsage(a.DynamicDrawUsage),n.setAttribute("rotation",u),r={mesh:new a.Mesh(n,t.material),indices:new Float32Array(i),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex((e=>0===e));i<0&&(i=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,u=new a.Vector3,h=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof a.Sprite)return;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r){const o=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,o),indices:new Array(o).fill(null),particles:[]},r.mesh.setColorAt(0,C.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const i=new Float32Array(3*o);b.makeScale(0,0,0);for(let e=0;e<o;e++)i[3*e+0]=1,i[3*e+1]=1,r.mesh.setMatrixAt(e,b);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(i,3)),this.meshes.push(r),this.container.add(r.mesh)}let o=r.indices.findIndex((e=>null==e));if(o<0&&(o=r.indices.indexOf(Math.min(...r.indices))),r.indices[o]=performance.now(),e.target=o,r.particles[o]=e,"number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:o}=e;if(null==t)return;const i=e.body,n=this.meshes.find((e=>e.mesh.geometry.uuid===i.geometry.uuid&&e.mesh.material.uuid===i.material.uuid));if(null==n)return;n.mesh.frustumCulled=!1,f(e,n.mesh),a&&(n.mesh.setColorAt(e.target,C.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0);const s=n.mesh.geometry.getAttribute("particleData");r&&s.setX(e.target,e.alpha),s.setY(e.target,e.energy),s.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new i;function f(e,t){if(x.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.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,g.matrix);const a=g.getWorldDirection(A);a.applyAxisAngle(p,Math.PI/-2),w.setFromUnitVectors(a,r)}else U.set(e.rotation.x,e.rotation.y,e.rotation.z),w.setFromEuler(U);const r=e.transform.initialScale;null!=r?A.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):A.set(e.scale,e.scale,e.scale),b.compose(x,w,A),t.setMatrixAt(e.target,b),t.instanceMatrix.needsUpdate=!0}const y=new a.Vector3(0,0,-1),b=new a.Matrix4,w=new a.Quaternion,x=new a.Vector3,A=new a.Vector3,U=new a.Euler,C=new a.Color(0),M={r:0,g:0,b:0};function P(e,t){const r=e.mesh,o=r.count,i=[],n=r.geometry.getAttribute("particleData"),s=new a.Vector3;for(let l=0;l<o;l++){const o=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,o),r.getColorAt(l,c);const d=n.getX(l);s.setFromMatrixPosition(o);const m=s.distanceTo(t.position);i.push({index:l,distance:m,matrix:o,particle:e.particles[l],color:c,pdx:d})}i.sort(((e,t)=>t.distance-e.distance));for(let e=0;e<o;e++){const t=i[e].matrix;null==i[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,i[e].color),n.setX(e,i[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{P as sortInstancedMeshByDistance};/*
|
|
1
|
+
import{CustomRenderer as e,MeshRenderer as t,PUID as r}from"@hology/nebula";import*as a from"three";import{InstancedBufferAttribute as o,Object3D as i}from"three";import{NodeShaderMaterial as n}from"three-shader-graph";import{StretchedSprite as s}from"./stretched-sprite.js";import{Trail as l}from"./trail-renderer.js";import{SpriteNodeShaderMaterial as c}from"../../shader/sprite-shader";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){e.target=null,this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,o="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==o[d.trail]&&(o[d.trail]=new TrailRenderer(r,this.three)),e._renderer=o[d.trail]):e.body instanceof s?(null==o[d.stretchedBillboard]&&(o[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=o[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==o[d.sprite]&&(o[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=o[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof n?(null==o[d.instanced]&&(o[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=o[d.instanced]):e.body instanceof a.Object3D?(null==o[d.mesh]&&(o[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=o[d.mesh]):void 0}dispose(){this.localRenderers.forEach(e=>{e instanceof InstancedRenderer&&e.dispose()}),this.worldRenderers.forEach(e=>{e instanceof InstancedRenderer&&e.dispose()})}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new l(this.container,!1),o=new i;this.container.add(o),o.updateMatrixWorld(),o.updateWorldMatrix(!0,!0);const n=l.createBaseMaterial(t.texture,t.scrollSpeed,t.opacityChannel,t.billboard??!1);n.uniforms.taper.value=t.taper??!1;const s=new a.Color(t.color??0).multiplyScalar(t.intensity),c=new a.Color(t.colorEnd??0).multiplyScalar(t.intensityEnd??t.intensity??1);n.uniforms.headColor&&n.uniforms.tailColor&&(n.uniforms.headColor.value=new a.Vector4(s.r,s.g,s.b,t.opacityStart??1),n.uniforms.tailColor.value=new a.Vector4(c.r,c.g,c.b,t.opacityEnd??1)),t.bloom&&(n.userData.hasBloom=!0),r.initialize(n,Math.round(t.length??10),!1,t.width,null,o,t.billboard??!1);const d=e.rotation;o.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=o}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);const r=e.body;let a=x;e.old&&e.old.position?a.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize():a.copy(e.velocity).normalize();const o=w;o.setFromUnitVectors(a,y),t.rotation.set(0,0,0),t.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),t.applyQuaternion(o);const i=this.trails.findIndex(e=>e.targetObject.id===t.id);if(-1!=i){const t=this.trails[i];if(e.useAlpha&&t.material.uniforms.headColor&&t.material.uniforms.tailColor){t.material.uniforms.headColor.value.setW(r.opacityStart*e.alpha);t.material.uniforms.tailColor.value.setW(r.opacityEnd*e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex(e=>e.targetObject.id===t.id);if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),e.targetObject.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof i&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:o,rotation:n}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof c?e.target.material.rotation=e.rotation.z:t.rotation.set(n.x,n.y,n.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof i){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(u);a.applyAxisAngle(p,Math.PI/-2),h.setFromUnitVectors(a,r),t.quaternion.copy(h)}t.material instanceof a.Material&&(r&&(t.material instanceof c&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),o&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}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 class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach(e=>e.mesh.geometry.dispose())}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),o=e.mesh.geometry.getAttribute("velocity"),i=e.mesh.geometry.getAttribute("rotation"),n=e.mesh.geometry.getAttribute("color");let s=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=C.copy(l.color).getRGB(M);n.setXYZW(s,e.r,e.g,e.b,1),n.needsUpdate=!0}l.useAlpha&&(n.setW(s,l.alpha),n.needsUpdate=!0),"number"==typeof l.rotation?i.setX(s,l.rotation):i.setX(s,l.rotation.x);const e=l.position;if(t.setXYZ(s,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(s,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;o.setXYZW(s,m.x*c,m.y*c,m.z*c,d),s++}s>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*s),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*s),r.needsUpdate=!0,n.clearUpdateRanges(),n.addUpdateRange(0,4*s),n.needsUpdate=!0,o.clearUpdateRanges(),o.addUpdateRange(0,4*s),o.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,s),i.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof s&&null==e.target){const t=e.body;let r=this.meshes.find(e=>e.mesh.material.uuid===t.material.uuid);if(null==r){const i=this.calcMaxCount(e),n=new a.InstancedBufferGeometry;n.setIndex(t.geometry.getIndex()),n.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&n.setAttribute("normal",t.geometry.getAttribute("normal")),n.setAttribute("uv",t.geometry.getAttribute("uv"));const s=new o(new Float32Array(3*i),3);s.setUsage(a.DynamicDrawUsage),n.setAttribute("offset",s);const l=new o(new Float32Array(4*i),4);if(l.setUsage(a.DynamicDrawUsage),n.setAttribute("color",l),t.material instanceof c){const e=new a.Color(t.material.color);for(let t=0;t<l.count;t++)l.setXYZW(t,e.r,e.g,e.b,1)}const d=new o(new Float32Array(3*i),3);d.setUsage(a.DynamicDrawUsage),n.setAttribute("size",d);const m=new o(new Float32Array(4*i),4);m.setUsage(a.DynamicDrawUsage),n.setAttribute("velocity",m);const u=new o(new Float32Array(4*i),1);u.setUsage(a.DynamicDrawUsage),n.setAttribute("rotation",u),r={mesh:new a.Mesh(n,t.material),indices:new Float32Array(i),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex(e=>0===e);i<0&&(i=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find(e=>e.mesh.material.uuid===t.material.uuid);if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,u=new a.Vector3,h=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach(e=>e.mesh.dispose())}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof a.Sprite)return;const t=e.body;let r=this.meshes.find(e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid);if(null==r){const o=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,o),indices:new Array(o).fill(null),particles:[]},r.mesh.setColorAt(0,C.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const i=new Float32Array(3*o);b.makeScale(0,0,0);for(let e=0;e<o;e++)i[3*e+0]=1,i[3*e+1]=1,r.mesh.setMatrixAt(e,b);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(i,3)),this.meshes.push(r),this.container.add(r.mesh)}let o=r.indices.findIndex(e=>null==e);if(o<0&&(o=r.indices.indexOf(Math.min(...r.indices))),r.indices[o]=performance.now(),e.target=o,r.particles[o]=e,"number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find(e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid);f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:o}=e;if(null==t)return;const i=e.body,n=this.meshes.find(e=>e.mesh.geometry.uuid===i.geometry.uuid&&e.mesh.material.uuid===i.material.uuid);if(null==n)return;n.mesh.frustumCulled=!1,f(e,n.mesh),a&&(n.mesh.setColorAt(e.target,C.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0);const s=n.mesh.geometry.getAttribute("particleData");r&&s.setX(e.target,e.alpha),s.setY(e.target,e.energy),s.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find(e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid);if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new i;function f(e,t){if(x.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.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,g.matrix);const a=g.getWorldDirection(A);a.applyAxisAngle(p,Math.PI/-2),w.setFromUnitVectors(a,r)}else U.set(e.rotation.x,e.rotation.y,e.rotation.z),w.setFromEuler(U);const r=e.transform.initialScale;null!=r?A.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):A.set(e.scale,e.scale,e.scale),b.compose(x,w,A),t.setMatrixAt(e.target,b),t.instanceMatrix.needsUpdate=!0}const y=new a.Vector3(0,0,-1),b=new a.Matrix4,w=new a.Quaternion,x=new a.Vector3,A=new a.Vector3,U=new a.Euler,C=new a.Color(0),M={r:0,g:0,b:0};function P(e,t){const r=e.mesh,o=r.count,i=[],n=r.geometry.getAttribute("particleData"),s=new a.Vector3;for(let l=0;l<o;l++){const o=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,o),r.getColorAt(l,c);const d=n.getX(l);s.setFromMatrixPosition(o);const m=s.distanceTo(t.position);i.push({index:l,distance:m,matrix:o,particle:e.particles[l],color:c,pdx:d})}i.sort((e,t)=>t.distance-e.distance);for(let e=0;e<o;e++){const t=i[e].matrix;null==i[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,i[e].color),n.setX(e,i[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{P as sortInstancedMeshByDistance};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t}from"tslib";import{ActorFactory as s,AssetLoader as e,BaseActor as r,inject as o,Service as a,VfxActor as c,World as i}from"../../gameplay";import{VfxPool as n}from"./vfx-param";let h=class{constructor(){this.pools=new Map,this.actorFactory=o(s),this.assetService=o(e),this.world=o(i)}async createFromAssetId(t,s=this.world.scene){const e=await this.assetService.getAsset(t);return this.createFromAsset(e,s)}async createFromAsset(t,s=this.world.scene){const e=await this.actorFactory.create(c);return s instanceof r?s.object.add(e.object):s.add(e.object),await e.fromAsset(t),e}async createPoolFromAssetId(t,s=this.world.scene){const e=await this.assetService.getAsset(t);return this.createPoolFromAsset(e,s)}async createPoolFromAsset(t,s=this.world.scene){let e;return this.pools.has(t.id)||(e=new n((
|
|
1
|
+
import{__decorate as t}from"tslib";import{ActorFactory as s,AssetLoader as e,BaseActor as r,inject as o,Service as a,VfxActor as c,World as i}from"../../gameplay";import{VfxPool as n}from"./vfx-param";let h=class{constructor(){this.pools=new Map,this.actorFactory=o(s),this.assetService=o(e),this.world=o(i)}async createFromAssetId(t,s=this.world.scene){const e=await this.assetService.getAsset(t);return this.createFromAsset(e,s)}async createFromAsset(t,s=this.world.scene){const e=await this.actorFactory.create(c);return s instanceof r?s.object.add(e.object):s.add(e.object),await e.fromAsset(t),e}async createPoolFromAssetId(t,s=this.world.scene){const e=await this.assetService.getAsset(t);return this.createPoolFromAsset(e,s)}async createPoolFromAsset(t,s=this.world.scene){let e;return this.pools.has(t.id)||(e=new n(()=>this.createFromAsset(t,s)),this.pools.set(t.id,e)),e}};h=t([a()],h);export{h as VfxService};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import o,{ignore as i}from"@plumier/reflect";import{Subject as n,skipWhile as s}from"rxjs";import{Group as r}from"three";import a,{Service as p}from"typedi";import{ActorComponent as c}from"./component.js";import{initComponents as d}from"./internal/component-init.js";import{activeContainerInstance as m,containerRefMap as h}from"./internal/container-map.js";import{randomString as l}from"../../utils/math.js";import{inject as u}from"../inject.js";import{ViewController as f}from"../services/render.js";export function Actor(){const t=p({transient:!0});return function(e){e.__isActor=!0,t(e),o.noop()(e),o.parameterProperties()(e)}}let U=0;export class BaseActor{get position(){return this.object?.position}get quaternion(){return this.object?.quaternion}get rotation(){return this.object?.rotation}onInit(){}onBeginPlay(){}onEndPlay(){}onUpdate(t){}onLateUpdate(t){}constructor(){this.id=++U,this.__isInitialised=!1,this.object=new r,this.disposed=new n,this.onUpdate!==BaseActor.prototype.onUpdate&&u(f).onUpdate(this).pipe(s((
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import o,{ignore as i}from"@plumier/reflect";import{Subject as n,skipWhile as s}from"rxjs";import{Group as r}from"three";import a,{Service as p}from"typedi";import{ActorComponent as c}from"./component.js";import{initComponents as d}from"./internal/component-init.js";import{activeContainerInstance as m,containerRefMap as h}from"./internal/container-map.js";import{randomString as l}from"../../utils/math.js";import{inject as u}from"../inject.js";import{ViewController as f}from"../services/render.js";export function Actor(){const t=p({transient:!0});return function(e){e.__isActor=!0,t(e),o.noop()(e),o.parameterProperties()(e)}}let U=0;export class BaseActor{get position(){return this.object?.position}get quaternion(){return this.object?.quaternion}get rotation(){return this.object?.rotation}onInit(){}onBeginPlay(){}onEndPlay(){}onUpdate(t){}onLateUpdate(t){}constructor(){this.id=++U,this.__isInitialised=!1,this.object=new r,this.disposed=new n,this.onUpdate!==BaseActor.prototype.onUpdate&&u(f).onUpdate(this).pipe(s(()=>!this.__isInitialised)).subscribe(t=>this.onUpdate(t)),this.onLateUpdate!==BaseActor.prototype.onLateUpdate&&u(f).onLateUpdate(this).pipe(s(()=>!this.__isInitialised)).subscribe(t=>this.onLateUpdate(t))}attach(t,e){const o=m.value,i=h.get(this)??m.value??a.of("default");m.value=i;const n=l();i.set({id:n,type:t,transient:!0});const s=i.get(n);if(m.value=o,null!=e)for(const t of Object.keys(e))s[t]=e[t];return this.__isInitialised&&(s.actor=this,s.onInit(),d(s,this)),s}getComponent(t){for(const e of Object.values(this))if(e instanceof t)return e}}t([i(),e("design:type",Object),e("design:paramtypes",[])],BaseActor.prototype,"position",null),t([i(),e("design:type",Object),e("design:paramtypes",[])],BaseActor.prototype,"quaternion",null),t([i(),e("design:type",Object),e("design:paramtypes",[])],BaseActor.prototype,"rotation",null);export function _setupActorUpdateEventHandlers(){this.onUpdate!==c.prototype.onUpdate&&u(f).onUpdate(this.actor).pipe(s(()=>!this.actor?.__isInitialised)).subscribe(t=>this.onUpdate(t)),this.onLateUpdate!==c.prototype.onLateUpdate&&u(f).onLateUpdate(this.actor).pipe(s(()=>!this.actor?.__isInitialised)).subscribe(t=>this.onLateUpdate(t))}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t}from"tslib";import{ActorComponent as e,Component as i}from"../../../component.js";import{RootMotionClip as o}from"../../../../animation/root-motion.js";import{inject as r}from"../../../../inject.js";import{ViewController as s}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,Object3D as l,LoopOnce as h}from"three";import{CharacterMovementComponent as c}from"./character-movement.js";let u=class extends e{constructor(){super(...arguments),this.viewController=r(s),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=m(
|
|
1
|
+
import{__decorate as t}from"tslib";import{ActorComponent as e,Component as i}from"../../../component.js";import{RootMotionClip as o}from"../../../../animation/root-motion.js";import{inject as r}from"../../../../inject.js";import{ViewController as s}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,Object3D as l,LoopOnce as h}from"three";import{CharacterMovementComponent as c}from"./character-movement.js";let u=class extends e{constructor(){super(...arguments),this.viewController=r(s),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=m(t=>t.uuid,t=>a(this.fullBodyMask,t)),this.getUpperBodyClip=m(t=>t.uuid,t=>a(this.upperBodyMask,t))}onInit(){this.viewController.onUpdate(this.actor).subscribe(t=>this.updateInternal(t)),this.characterMovement=this.actor.getComponent(c)}getRootMotionAction(){if(this.fullBodyAction.getClip()instanceof o)return this.fullBodyAction}setup(t,e,i){null!=e&&(this.upperBodyMask=d(e),this.fullBodyMask=function(t,e){const i=new Set(d(e).map(t=>t.uuid)),o=[];return t.traverse(t=>{(t instanceof p||t.isBone)&&!i.has(t.uuid)&&o.push(t)}),o}(function(t){let e;return t.traverse(t=>{(t instanceof p||t.isBone)&&null==e&&(e=t)}),e}(t),e)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach(e=>{e.step(t);const i=e.current.clip;null!=i&&this.play(i,{priority:0,loop:e.current.options.loop??!0})}),this.upperStateMachines.forEach(e=>{e.step(t);const i=e.current.clip;null!=i?this.playUpper(i,{priority:0,loop:e.current.options.loop??!0}):this.play(this.fullBodyClip)})}updateInternal(t){null!=this.mixer&&(this.upperBodyTimer+=t*(this.upperBodyAction?.timeScale??1),this.fullBodyTimer+=t*(this.fullBodyAction?.timeScale??1),this.upperBodyAction&&this.upperBodyOverride&&this.upperBodyAction.getClip().duration-2*(this.overrideFadeTimeUpper??this.fadeTime)<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip)),this.upperBodyAction=null,this.overrideFadeTimeUpper=null),this.fullBodyAction&&this.fullBodyAction.loop===h&&this.fullBodyAction.getClip().duration-2*(this.overrideFadeTime??this.fadeTime)<this.fullBodyTimer&&(this.currentFullBodyPriority=-1,this.overrideFadeTime=null),null!=this.characterMovement&&(this.movementSpeed=this.characterMovement.horizontalSpeed),this.updateStateMachines(t),this.syncMovementSpeed(this.fullBodyAction),this.upperBodyOverride||this.syncMovementSpeed(this.upperBodyAction),this.mixer.update(t))}syncMovementSpeed(t){if(null!=t){const e=t.getClip();if(e instanceof o&&e.fixedInPlace&&null!=this.movementSpeed){t.timeScale=e.duration/e.displacement*this.movementSpeed;const i=this.mixer.getRoot();i instanceof l&&(t.timeScale/=i.scale.x)}}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){const e=this.stateMachines.indexOf(t);e>=0&&this.stateMachines.splice(e,1)}removeUpperStateMachine(t){const e=this.upperStateMachines.indexOf(t);e>=0&&this.upperStateMachines.splice(e,1)}playUpper(t,e={}){const i=e?.priority??1;i<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=i,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e),this.upperBodyAction.timeScale=e?.timeScale??1,this.upperBodyTimer=0,this.upperBodyOverride=!0,this.overrideFadeTimeUpper=e.fadeTime)}play(t,e={}){!function(t,e){if(!1===t||"function"==typeof t&&!1===t())throw new Error(e)}(null!=this.mixer,"Can't play animation before setup is called");const i=e.priority??1;i<this.currentFullBodyPriority||(this.currentFullBodyPriority=i,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e),this.upperBodyAction.timeScale=e?.timeScale??1),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),e),this.fullBodyAction.timeScale=e?.timeScale??1,this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction),this.overrideFadeTime=e.fadeTime)}onActionDone(t){return new Promise(e=>{const i=o=>{o.action===t&&(e(o.action),this.mixer.removeEventListener("finished",i))};this.mixer.addEventListener("finished",i)})}transition(t,e,i={}){if(null!=t&&t.getClip().uuid===e.uuid)return t;if(t){const o=t,r=t=this.mixer.clipAction(e);r.play(),r.enabled=!0,r.setEffectiveTimeScale(1),r.setEffectiveWeight(1),r.time=0,o.crossFadeTo(r,i?.fadeTime??this.fadeTime,!0)}else t=this.mixer.clipAction(e),t?.fadeIn(.3),t?.play();return!1===i.loop&&(t.setLoop(h,1),t.clampWhenFinished=!0,t.reset()),t}};u=t([i({inEditor:!0})],u);export{u as CharacterAnimationComponent};function a(t,e){if(null==t)return e;const i=e.clone(),o=new Set(t.map(t=>t.name));return i.tracks=i.tracks.filter(t=>o.has(t.name.split(".")[0])),i}function d(t){return t.flatMap(t=>function(t){const e=[];return t.traverse(t=>{e.push(t)}),e}(t)).filter(t=>t instanceof p)}function m(t,e){const i=new Map;return(o,...r)=>{const s=t(o);return i.has(s)||i.set(s,e(o,...r)),i.get(s)}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{ActionInput as i,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as u}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as d}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";import{clamp as w}from"../../../../../utils/math.js";const v=new c,M=new c,x=1/30,T=131070;let b=class extends h{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new i,this.sprintInput=new i,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.characterCollision=!1,this.enabled=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1,this.rotateToMovementDirection=!1,this.smoothRotation=!0,this.impulse=new c,this.impulseDamping=2;const e=this.cc=this.physicsSystem.getCharacterController(.1);e.enableSnapToGround(.1),e.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:y.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let e=this.rotationInput.rotation.y;const i=new c,o=new c,s=new c,n=new c(0,0,1),r=new c,l=new c,h=new c;let p=0,u=null;const g=new c,b=new c,j=new c,C=new c,R=new c,D=new c,k=this.characterCollision?null:T;let q=this.rotateToMovementDirection;this.physicsSystem.beforeStep.pipe(d(this.disposed)).subscribe(
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActionInput as i,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as u}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as d}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";import{clamp as w}from"../../../../../utils/math.js";const v=new c,M=new c,x=1/30,T=131070;let b=class extends h{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new i,this.sprintInput=new i,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.characterCollision=!1,this.enabled=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1,this.rotateToMovementDirection=!1,this.smoothRotation=!0,this.impulse=new c,this.impulseDamping=2;const e=this.cc=this.physicsSystem.getCharacterController(.1);e.enableSnapToGround(.1),e.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:y.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let e=this.rotationInput.rotation.y;const i=new c,o=new c,s=new c,n=new c(0,0,1),r=new c,l=new c,h=new c;let p=0,u=null;const g=new c,b=new c,j=new c,C=new c,R=new c,D=new c,k=this.characterCollision?null:T;let q=this.rotateToMovementDirection;this.physicsSystem.beforeStep.pipe(d(this.disposed)).subscribe(d=>{if(this.checkGrounded(d),!this.enabled)return;if(null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(g.fromArray(t.evaluate(0)),this.resetRootMotion=!1),C.fromArray(t.evaluate(this.rootMotionAction.time)),b.subVectors(C,g),g.copy(C),this.rootMotionAction.getRoot().getWorldScale(j),b.multiply(j)}}d>x&&(d=x);const y=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=b.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;const T=q!==this.rotateToMovementDirection;let B=this.rotationInput.rotation.y-e;T&&(this.actor.object.quaternion.setFromEuler(H.set(0,this.rotationInput.rotation.y,0)),q?this.actor.object.quaternion.setFromEuler(H.set(0,this.rotationInput.rotation.y,0)):(B=0,e=this.rotationInput.rotation.y,n.set(0,0,1)),q=this.rotateToMovementDirection),s.copy(this.actor.position),r.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const W=!this.rotateToMovementDirection&&r.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;if(h.set(0,0,0),this.rotateToMovementDirection){if(r.lengthSq()>0){this.smoothRotation?(P=r,Q=11*d,O=D,(N=n).normalize(),P.normalize(),G.setFromUnitVectors(N,P),F.identity(),F.slerp(G,Q),O.copy(N).applyQuaternion(F)):D.copy(r),G.setFromUnitVectors(n.clone().normalize(),D.clone().normalize()),n.copy(D);const t=(B%(2*Math.PI)+3*Math.PI)%(2*Math.PI)-Math.PI,i=Math.abs(t),o=this.smoothRotation?w(10*d*t,-i,i):t;E.setFromEuler(H.set(0,o,0)),G.multiply(E),this.actor.object.applyQuaternion(G),h.copy(this.actor.object.getWorldDirection(V).normalize()),e+=o}}else e+=B,this.actor.object.quaternion.multiply(G.setFromEuler(H.set(0,B,0))),r.lengthSq()>0&&h.copy(r).applyQuaternion(this.actor.object.quaternion).normalize();var N,P,Q,O;if(R.set(0,0,0),this.rayTestResult.hasHit&&null!=this.rayTestResult.actor&&this.physicsSystem.getLinearVelocity(this.rayTestResult.actor,R),this.mode===m.walking?(0!==h.lengthSq()?(p=Math.min(W,p),p=a.lerp(p,W,4*d)):p=0,l.copy(h).multiplyScalar(p),this.pressedJump&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),l.y=d*this.getEffectiveGravity(),l.add(R)):this.mode===m.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),this.velocity.y+=d*this.getEffectiveGravity(),l.copy(this.velocity),l.addScaledVector(h,this.fallingMovementControl),this.fallingReorientation&&l.applyAxisAngle(new c(0,1,0),B)),this.impulse.lengthSq()>.1){const t=Math.min(1,this.impulse.length()/5);l.x=a.lerp(l.x,this.impulse.x,t),l.z=a.lerp(l.z,this.impulse.z,t),l.y+=this.impulse.y;const e=Math.exp(-this.impulseDamping*d);this.impulse.x*=e,this.impulse.y>0?this.impulse.y+=d*this.getEffectiveGravity():this.impulse.y*=e,this.impulse.z*=e}else this.impulse.set(0,0,0);if(o.copy(l).normalize(),i.copy(l),l.length(),y?(b.applyQuaternion(this.actor.quaternion),b.y+=d*this.getEffectiveGravity(),v.copy(b)):v.copy(l).multiplyScalar(d),this.isGrounded&&this.mode===m.walking&&(this.rayTestResult.distance>t.offset()||(v.y=Math.max(0,R.y*d)),this.physicsSystem.getActorComputedMovement(this.actor,t,v,k),t.computedCollision(0,z),null!=z&&null!=z.normal1)){const e=(new S.Vector3).copy(z.normal1);Math.acos(e.dot(A))>t.maxSlopeClimbAngle()&&(v.y=.016*this.getEffectiveGravity()*.5)}M.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v,k)),this.physicsSystem.setNextKinematicTranslation(this.actor,M);let J=function(t){if(t.numComputedCollisions()>0){const e=t.computedCollision(0);I.x=e.normal2.x,I.y=e.normal2.y,I.z=e.normal2.z;const i=I.angleTo(A);I.x=e.normal1.x,I.y=e.normal1.y,I.z=e.normal1.z;const o=I.angleTo(A);return!(i<100)&&o>t.minSlopeSlideAngle()}return!1}(t);y||this.isGrounded&&!J||this.mode!==m.falling&&(null==u?u=performance.now():performance.now()-u>100&&(this.mode=m.falling,this.velocity.copy(i))),this.isGrounded&&this.velocity.y<=0&&(this.mode,m.falling,this.mode=m.walking,this.velocity.y=0,u=null),this.mode,m.walking,this.horizontalSpeed=p})}applyImpulse(t){this.impulse.add(t)}debugDirection(){const t=new l(v,this.actor.position,1,65280);this.actor.object.parent.add(t),setTimeout(()=>{t.removeFromParent()},30);const e=new l(M,this.actor.position,1,16711680);this.actor.object.parent.add(e),setTimeout(()=>{e.removeFromParent()},30)}setRootMotionAction(t){const e=t?.getClip();if(e instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const i=[];this.rootMotionInterpolant=e.motionTrack.InterpolantFactoryMethodSmooth(i)}}getWallDirection(t,e){const i=t.clone().negate().cross(A);return i.dot(e)<0?i.negate():i}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}checkGrounded(t){this.colliderHeight,this.colliderRadius;D.y=-.05,this.physicsSystem.rayTest(j.addVectors(this.actor.position,R.set(0,this.offset,0)),C.addVectors(this.actor.position,D),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}createCollisionShape(){const t=new u(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t.collisionGroup=T,t}step(t){}performMovement(t){}arrowHelper(t,e,i){const o=new l(t.clone().normalize(),e,1,i);this.actor.object.parent.add(o),setTimeout(()=>{o.removeFromParent()},30)}};b=t([p({inEditor:!1}),e("design:paramtypes",[n])],b);export{b as CharacterMovementComponent};const A=new c(0,1,0),I=new c;const j=new c,C=new c,R=new c(0,1,0),D=new c(0,-.1,0),z=(new c(0,-1,0),new g.CharacterCollision),G=new S.Quaternion,F=new S.Quaternion,E=new S.Quaternion,H=new S.Euler,V=new S.Vector3;/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as i}from"tslib";import{PhysicsBodyType as s,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as r}from"../../../../index.js";import{Parameter as n}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component.js";import{firstValueFrom as m}from"rxjs";const u={friction:.1,mass:0,restitution:1,bodyType:s.static,continousCollisionDetection:!1};let y=class extends a{constructor(t){super(),this.physicsSystem=t,this.position=new p,this.rotation=new c,this.scale=new p(1,1,1),this.mass=u.mass,this.friction=u.friction,this.restitution=u.restitution,this.bodyType=s.static,this.isTrigger=!1,this.continousCollisionDetection=u.continousCollisionDetection}onInit(){null!=this.object&&(this.currentMesh=this.object,this.updateMesh()),m(this.disposed).then((
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{PhysicsBodyType as s,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as r}from"../../../../index.js";import{Parameter as n}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component.js";import{firstValueFrom as m}from"rxjs";const u={friction:.1,mass:0,restitution:1,bodyType:s.static,continousCollisionDetection:!1};let y=class extends a{constructor(t){super(),this.physicsSystem=t,this.position=new p,this.rotation=new c,this.scale=new p(1,1,1),this.mass=u.mass,this.friction=u.friction,this.restitution=u.restitution,this.bodyType=s.static,this.isTrigger=!1,this.continousCollisionDetection=u.continousCollisionDetection}onInit(){null!=this.object&&(this.currentMesh=this.object,this.updateMesh()),m(this.disposed).then(()=>{this.physicsSystem.removeActor(this.actor)})}setObject(t){null!=this.currentMesh&&this.actor.object.remove(this.currentMesh),this.object=this.currentMesh=t,this.updateMesh()}updateMesh(){this.currentMesh.position.copy(this.position),this.currentMesh.rotation.copy(this.rotation),this.currentMesh.scale.copy(this.scale);const t=this.getCollisionShapes();t.length>0&&this.physicsSystem.addActor(this.actor,t,{...u,isTrigger:this.isTrigger??!1,mass:this.mass,friction:this.friction,type:this.bodyType,continousCollisionDetection:this.continousCollisionDetection,restitution:this.restitution}),this.actor.object.add(this.currentMesh)}getCollisionShapes(){return this.currentMesh instanceof o?this.currentMesh.collisionShapes:this.currentMesh instanceof r?[this.currentMesh.collisionShape]:"collisionShape"in this.currentMesh?(console.error("Could not understand wehre to get collision shapes from. This is likely due to an import issue"),[this.currentMesh.collisionShape]):[]}};t([n({type:h}),i("design:type",Object)],y.prototype,"object",void 0),t([n(),i("design:type",p)],y.prototype,"position",void 0),t([n(),i("design:type",c)],y.prototype,"rotation",void 0),t([n(),i("design:type",p)],y.prototype,"scale",void 0),t([n(),i("design:type",Number)],y.prototype,"mass",void 0),t([n(),i("design:type",Number)],y.prototype,"friction",void 0),t([n(),i("design:type",Number)],y.prototype,"restitution",void 0),t([n({options:[{name:"Static",value:s.static},{name:"Kinematic",value:s.kinematic},{name:"Dynamic",value:s.dynamic}]}),i("design:type",Number)],y.prototype,"bodyType",void 0),t([n(),i("design:type",Boolean)],y.prototype,"isTrigger",void 0),y=t([l({inEditor:!0}),i("design:paramtypes",[e])],y);export{y as MeshComponent};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as o,Cone as s,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as l,ShapeType as c,TriMesh as h}from"@dimforge/rapier3d-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as g,firstValueFrom as b,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as M}from"three/examples/jsm/Addons.js";import{Actor as B,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as C,World as j,attach as k,inject as F}from"../../";import{sleepDelay as I}from"../../../utils/async";import{hasSharedArrayBufferSupport as P,toSharedFloat32Array as V,toSharedUint32Array as G}from"../../../utils/buffer";import{DynamicTiledNavMesh as N}from"../../ai/dynamic-tiled-navmesh";import{TriggerVolumeMesh as D}from"./components/volume-editor-component";var E;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(E||(E={}));let T=E.none,H=new m(!1);export async function safeRecastInit(){return T===E.none?(T=E.starting,p().then((
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as o,Cone as s,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as l,ShapeType as c,TriMesh as h}from"@dimforge/rapier3d-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as g,firstValueFrom as b,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as M}from"three/examples/jsm/Addons.js";import{Actor as B,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as C,World as j,attach as k,inject as F}from"../../";import{sleepDelay as I}from"../../../utils/async";import{hasSharedArrayBufferSupport as P,toSharedFloat32Array as V,toSharedUint32Array as G}from"../../../utils/buffer";import{DynamicTiledNavMesh as N}from"../../ai/dynamic-tiled-navmesh";import{TriggerVolumeMesh as D}from"./components/volume-editor-component";var E;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(E||(E={}));let T=E.none,H=new m(!1);export async function safeRecastInit(){return T===E.none?(T=E.starting,p().then(()=>{H.next(!0),T=E.started})):b(H.pipe(g(e=>e)))}new x.Box3(new x.Vector3(-100,-100,-100),new x.Vector3(100,100,100));const R=navigator.hardwareConcurrency??1;let U=!1,q=class extends S{constructor(){super(...arguments),this.physics=F(A),this.view=F(C),this.world=F(j),this.editorVisualisation=k(D),this.debug=!0,this.refreshMs=4e3,this.tileSize=50,this.walkableClimb=.3,this.walkableSlopeAngle=45,this.cellSize=.2,this.bounds=new x.Box3}async onInit(){U||(await safeRecastInit(),U=!0),setTimeout(()=>{this.init()},10),this.recreateInterval=setInterval(()=>{if("_hology_transform_group"===this.object.parent?.name)return;X.setFromCenterAndSize(this.position,this.object.scale).equals(this.bounds)||(this.disposed.next(!0),this.disposed=new f,this.init())},2e3)}onEndPlay(){clearInterval(this.recreateInterval)}init(){this.bounds.setFromCenterAndSize(this.position,this.object.scale),console.log(this.bounds);const e=this.bounds.max.x-this.bounds.min.x,t=this.bounds.max.z-this.bounds.min.z,n=Math.max(1,Math.min(e,t)),o=Math.min(400,Math.max(50,Math.ceil(n/2))),s=Math.max(this.cellSize,.01),i={tileSize:Math.max(32,Math.floor(o/s)),walkableClimb:this.walkableClimb/s,walkableSlopeAngle:this.walkableSlopeAngle,walkableRadius:2,walkableHeight:5,detailSampleDist:1,minRegionArea:6,mergeRegionArea:400,cs:s,ch:s,maxSimplificationError:1.3,maxEdgeLen:200},r=new N({navMeshBounds:this.bounds,recastConfig:i,maxTiles:1024,workers:R,cacheId:"nav"+this.object.userData?.src?.id});this.navMesh=r.navMesh;const a=this.tileSize*i.cs*2,l=performance.now(),c=new Map,h=new u;h.userData.isDebugDrawer=!0;r.navMesh;const p=this.bounds,m=()=>{const e=this.view.getCamera().getWorldPosition(new x.Vector3),t=new x.Box3((new x.Vector3).copy(e).subScalar(a),(new x.Vector3).copy(e).addScalar(a)),n=[],o=this.physics.world.bodies;if(null==o)return[];const s=new x.Box3;for(const e of o.getAll())for(let o=0,i=e.numColliders();o<i;o++){const i=e.collider(o);if(i.isSensor()||null!=i.parent().userData&&!0===i.parent().userData.ignoreForNavMesh)continue;const r=e.handle+","+o,a=c.get(r)?.mesh,l=a??O(i);if(W(i,l),null!=l){s.copy(l.geometry.boundingBox),s.min.add(l.position),s.max.add(l.position);const e=s.intersectsBox(t)||!0,o=s.intersectsBox(this.bounds);c.set(r,{pos:i.translation(),mesh:l}),e&&o&&n.push(l)}}return n},f=new x.Box3,g=new Map,b=new Map;let v=!0,M=performance.now(),B=!1;const S=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await I(t)})(),()=>{n=!0}}(async()=>{if(B)return;const e=new x.Box3,t=m();for(const n of t){const t=g.get(n);!0!==t?.equals(n.position)&&(null!=t&&e.expandByPoint(t),e.expandByObject(n),g.set(n,n.position.clone()))}e.min.subScalar(50),e.max.addScalar(50);const n=r.getTilesForBounds(e);n.length>500&&console.warn("Too many tiles to update. Consider increasing tile size");const o=n.slice(0,500);if(0!=o.length){const n=[];for(const o of t)f.setFromObject(o),f.intersectsBox(e)&&n.push(o);console.log("intersecting meshes",n.length);let[s,i]=d(n);i=function(e,t,n){const o=new x.Vector3,s=[];for(let i=0;i<t.length;i+=3){let r=!0;for(let s=0;s<3;s++){const a=3*t[i+s];if(o.fromArray(e,a),!n.containsPoint(o)){r=!1;break}}r&&s.push(t[i],t[i+1],t[i+2])}return new Uint32Array(s)}(s,i,p),P&&(s=V(s),i=G(i));const a=v;v=!1,await Promise.all(o.map(e=>(M=performance.now(),r.buildTile(s,i,e,a).then(()=>{const t=e[0]+","+e[1];b.set(t,(b.get(t)??0)+1),this.debug})))).then(()=>{this.debug,B=!1})}else B=!1},this.refreshMs??1e4);this.disposed.subscribe(()=>S()),r.onNavMeshUpdate.pipe(y(this.disposed),w(200)).subscribe(()=>{h.clear(),h.drawNavMesh(r.navMesh)}),console.log("Create navmesh with debug",this.debug),this.debug&&(this.object.rotation.set(0,0,0),this.object.updateMatrix(),this.object.updateMatrixWorld(),this.object.parent.add(h)),this.disposed.subscribe(()=>{r?.destroy(),h.removeFromParent(),h.dispose()});const z=performance.now()-l;z>1e3&&console.warn(`NavMesh update took ${z} ms. Consider changing tileSize or other parameter that may affect performance`)}};e([z(),t("design:type",Boolean)],q.prototype,"debug",void 0),e([z(),t("design:type",Number)],q.prototype,"walkableClimb",void 0),e([z({range:[0,89]}),t("design:type",Number)],q.prototype,"walkableSlopeAngle",void 0),e([z({range:[.01,10]}),t("design:type",Number)],q.prototype,"cellSize",void 0),q=e([B()],q);export default q;function _(e){if(e.shape instanceof l)return function(e){const t=e.shape;if(t.type!==c.HeightField)throw new Error("The provided collider is not a height field.");let n=!1;const o=t,s=o.heights,i=o.nrows,r=o.ncols,a=o.scale.x,l=o.scale.z,h=o.scale.y,p=i+1,u=new x.PlaneGeometry(l,a,r,i);u.rotateX(-Math.PI/2);const d=u.attributes.position.array;let m=0;for(let e=0;e<p;e++)for(let t=0;t<p;t++)d[m+1]=s[t*p+e]*h,m+=3,0!=d[m+1]&&(n=!0);if(!n){const e=new x.PlaneGeometry(a,l,2,2);return e.rotateX(-Math.PI/2),e}return u}(e);if(e.shape instanceof n)return new x.SphereGeometry(e.shape.radius);if(e.shape instanceof r){const t=e.shape.halfExtents;return new x.BoxGeometry(2*t.x,2*t.y,2*t.z)}if(e.shape instanceof i)return function(e){const t=[];for(let n=0;n<e.length;n+=3)t.push(new x.Vector3(e[n],e[n+1],e[n+2]));const n=(new M).setFromPoints(t),o=[];n.faces.forEach(e=>{const t=e.edge.head().point,n=e.edge.next.head().point,s=e.edge.next.next.head().point;o.push(t.x,t.y,t.z),o.push(n.x,n.y,n.z),o.push(s.x,s.y,s.z)});const s=new x.BufferGeometry;return s.setAttribute("position",new x.Float32BufferAttribute(o,3)),s}(e.shape.vertices);if(e.shape instanceof h){const t=e.shape.vertices,n=e.shape.indices;let o=new x.BufferGeometry;return o.setAttribute("position",new x.Float32BufferAttribute(t,3)),null!=n?o.setIndex(new x.Uint16BufferAttribute(n,1)):o=v.mergeVertices(o),o.computeVertexNormals(),o}if(e.shape instanceof a){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CylinderGeometry(n,n,2*t)}if(e.shape instanceof s){const t=e.shape.halfHeight,n=e.shape.radius;return new x.ConeGeometry(n,2*t)}if(e.shape instanceof o){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CapsuleGeometry(n,2*t)}return console.warn("Unsupported shape",e.shape.type,e),null}function O(e){const t=_(e);if(null==t)return null;const n=L,o=new x.Mesh(t,n);return o.geometry.computeBoundingBox(),o.geometry.scale(1.01,1.01,1.01),o}function W(e,t){const n=e.translation(),o=e.rotation();t.position.set(n.x,n.y,n.z),t.quaternion.set(o.x,o.y,o.z,o.w)}const X=new x.Box3,L=new x.MeshBasicMaterial({wireframe:!1,color:16711680,side:x.FrontSide});/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as o,__metadata as t}from"tslib";import*as s from"three";import{Actor as i,BaseActor as e}from"../actor.js";import{ActorComponent as n,Component as r,attach as a}from"../component.js";import{Parameter as d}from"../../../shader/index.js";import{ViewController as u}from"../../services/render.js";import{inject as l}from"../../inject.js";import{PositionalAudioHelper as p}from"../../../utils/three/positional-audio-helper.js";let h=class extends e{constructor(){super(...arguments),this.audio=a(c)}};h=o([i()],h);export{h as PositionalAudioActor};let m=class extends n{onInit(){const o=(new s.TextureLoader).load("assets/audio.png"),t=new s.SpriteMaterial({map:o}),i=new s.Sprite(t);this.actor.object.add(i),this.helper=new p(this.positionalAudio)}};m=o([r({inEditor:!0,editorOnly:!0})],m);let c=class extends n{constructor(){super(...arguments),this.volume=1,this.loop=!1,this.autoPlay=!0,this.view=l(u),this.sound=new s.PositionalAudio(this.view.audioListener),this.visualisation=a(m,{positionalAudio:this.sound})}onInit(){this.sound.setBuffer(this.audioBuffer),null!=this.refDistance&&this.sound.setRefDistance(Math.max(this.refDistance,0)),null!=this.rollofFactor&&this.sound.setRolloffFactor(this.rollofFactor),null!=this.maxDistance&&this.sound.setMaxDistance(this.maxDistance),null!=this.volume?this.sound.setVolume(Math.max(this.volume,0)):this.sound.setVolume(0),this.sound.loop=this.loop??!1,this.visualisation?.helper?.update(),this.actor.object.add(this.sound),this.autoPlay&&this.sound?.play(),this.disposed.subscribe((
|
|
1
|
+
import{__decorate as o,__metadata as t}from"tslib";import*as s from"three";import{Actor as i,BaseActor as e}from"../actor.js";import{ActorComponent as n,Component as r,attach as a}from"../component.js";import{Parameter as d}from"../../../shader/index.js";import{ViewController as u}from"../../services/render.js";import{inject as l}from"../../inject.js";import{PositionalAudioHelper as p}from"../../../utils/three/positional-audio-helper.js";let h=class extends e{constructor(){super(...arguments),this.audio=a(c)}};h=o([i()],h);export{h as PositionalAudioActor};let m=class extends n{onInit(){const o=(new s.TextureLoader).load("assets/audio.png"),t=new s.SpriteMaterial({map:o}),i=new s.Sprite(t);this.actor.object.add(i),this.helper=new p(this.positionalAudio)}};m=o([r({inEditor:!0,editorOnly:!0})],m);let c=class extends n{constructor(){super(...arguments),this.volume=1,this.loop=!1,this.autoPlay=!0,this.view=l(u),this.sound=new s.PositionalAudio(this.view.audioListener),this.visualisation=a(m,{positionalAudio:this.sound})}onInit(){this.sound.setBuffer(this.audioBuffer),null!=this.refDistance&&this.sound.setRefDistance(Math.max(this.refDistance,0)),null!=this.rollofFactor&&this.sound.setRolloffFactor(this.rollofFactor),null!=this.maxDistance&&this.sound.setMaxDistance(this.maxDistance),null!=this.volume?this.sound.setVolume(Math.max(this.volume,0)):this.sound.setVolume(0),this.sound.loop=this.loop??!1,this.visualisation?.helper?.update(),this.actor.object.add(this.sound),this.autoPlay&&this.sound?.play(),this.disposed.subscribe(()=>{this.sound.isPlaying&&(this.sound?.stop(),console.log(this.sound.getVolume(),this.volume)),this.sound.removeFromParent()}),console.log(this.sound)}onEndPlay(){this.sound.isPlaying&&(this.sound?.stop(),this.sound.loop=!1),this.sound.removeFromParent()}};o([d(),t("design:type",AudioBuffer)],c.prototype,"audioBuffer",void 0),o([d({range:[0,1]}),t("design:type",Number)],c.prototype,"volume",void 0),o([d(),t("design:type",Boolean)],c.prototype,"loop",void 0),o([d(),t("design:type",Boolean)],c.prototype,"autoPlay",void 0),o([d({range:[0,1e3]}),t("design:type",Number)],c.prototype,"refDistance",void 0),o([d(),t("design:type",Number)],c.prototype,"rollofFactor",void 0),o([d(),t("design:type",Number)],c.prototype,"maxDistance",void 0),c=o([r({inEditor:!0})],c);export{c as PositionalAudioComponent};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Actor as o,Attach as i,attach as r,BaseActor as p,Component as s,inject as n,Parameter as d}from"../..";import{Texture as m}from"three";import{tonemapMappings as y}from"../../../rendering/tone-mapping";import{OBB as u}from"three/examples/jsm/math/OBB.js";import{Vector3 as a}from"three";import*as b from"three";import{RenderingView as g}from"../../../rendering.js";import{TriggerVolumeMesh as h}from"./components/volume-editor-component.js";import{ActorComponent as l}from"../../../gameplay";let v=class extends l{};e([d({options:y}),t("design:type",Number)],v.prototype,"tonemapMapping",void 0),e([d(),t("design:type",Number)],v.prototype,"tonemapExposure",void 0),e([d(),t("design:type",m)],v.prototype,"envTexture",void 0),e([d(),t("design:type",Number)],v.prototype,"envIntensity",void 0),e([d(),t("design:type",Number)],v.prototype,"vignetteIntensity",void 0),e([d(),t("design:type",b.Color)],v.prototype,"colorTint",void 0),e([d(),t("design:type",Number)],v.prototype,"colorTintIntensity",void 0),e([d(),t("design:type",Number)],v.prototype,"depthFocus",void 0),e([d(),t("design:type",Number)],v.prototype,"depthAperture",void 0),e([d(),t("design:type",Number)],v.prototype,"depthMaxBlur",void 0),e([d({range:[1e3,4e4],precision:.1}),t("design:type",Number)],v.prototype,"temperature",void 0),e([d({range:[-1,1]}),t("design:type",Number)],v.prototype,"temperatureTint",void 0),e([d({label:"LUT"}),t("design:type",m)],v.prototype,"lut",void 0),e([d({label:"LUT Intensity",range:[0,1]}),t("design:type",Number)],v.prototype,"lutIntensity",void 0),v=e([s()],v);export{v as PostProcessSettings};let c=class extends p{constructor(){super(),this.bounded=!1,this.priority=0,this.blendWeight=1,this.blendRadius=0,this.box=new u(void 0,new b.Vector3(.5,.5,.5)),this.view=n(g),this.editorView=r(h),this.disposed.subscribe((
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Actor as o,Attach as i,attach as r,BaseActor as p,Component as s,inject as n,Parameter as d}from"../..";import{Texture as m}from"three";import{tonemapMappings as y}from"../../../rendering/tone-mapping";import{OBB as u}from"three/examples/jsm/math/OBB.js";import{Vector3 as a}from"three";import*as b from"three";import{RenderingView as g}from"../../../rendering.js";import{TriggerVolumeMesh as h}from"./components/volume-editor-component.js";import{ActorComponent as l}from"../../../gameplay";let v=class extends l{};e([d({options:y}),t("design:type",Number)],v.prototype,"tonemapMapping",void 0),e([d(),t("design:type",Number)],v.prototype,"tonemapExposure",void 0),e([d(),t("design:type",m)],v.prototype,"envTexture",void 0),e([d(),t("design:type",Number)],v.prototype,"envIntensity",void 0),e([d(),t("design:type",Number)],v.prototype,"vignetteIntensity",void 0),e([d(),t("design:type",b.Color)],v.prototype,"colorTint",void 0),e([d(),t("design:type",Number)],v.prototype,"colorTintIntensity",void 0),e([d(),t("design:type",Number)],v.prototype,"depthFocus",void 0),e([d(),t("design:type",Number)],v.prototype,"depthAperture",void 0),e([d(),t("design:type",Number)],v.prototype,"depthMaxBlur",void 0),e([d({range:[1e3,4e4],precision:.1}),t("design:type",Number)],v.prototype,"temperature",void 0),e([d({range:[-1,1]}),t("design:type",Number)],v.prototype,"temperatureTint",void 0),e([d({label:"LUT"}),t("design:type",m)],v.prototype,"lut",void 0),e([d({label:"LUT Intensity",range:[0,1]}),t("design:type",Number)],v.prototype,"lutIntensity",void 0),v=e([s()],v);export{v as PostProcessSettings};let c=class extends p{constructor(){super(),this.bounded=!1,this.priority=0,this.blendWeight=1,this.blendRadius=0,this.box=new u(void 0,new b.Vector3(.5,.5,.5)),this.view=n(g),this.editorView=r(h),this.disposed.subscribe(()=>{this.view.removePostProcessVolume(this)})}onInit(){this.view.addPostProcessVolume(this),this.editorView.visible=this.bounded}containsPoint(e){return!this.bounded||(this.resetBox(),this.box.containsPoint(e))}distanceToPoint(e){return this.bounded?(this.resetBox(),this.box.clampPoint(e,N),N.distanceTo(e)):0}resetBox(){const e=this.box;e.center.set(0,0,0),e.halfSize.set(.5,.5,.5),e.rotation.copy(x.rotation),e.applyMatrix4(this.object.matrixWorld)}};e([i(),t("design:type",v)],c.prototype,"settings",void 0),e([d(),t("design:type",Boolean)],c.prototype,"bounded",void 0),e([d({precision:0}),t("design:type",Number)],c.prototype,"priority",void 0),e([d({range:[0,1]}),t("design:type",Number)],c.prototype,"blendWeight",void 0),e([d(),t("design:type",Number)],c.prototype,"blendRadius",void 0),c=e([o(),t("design:paramtypes",[])],c);export{c as PostProcessVolume};const x=new u,N=new a;/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as s}from"tslib";import{EdgesGeometry as i,LineSegments as e,LineBasicMaterial as o,Vector3 as r,BoxGeometry as n,Mesh as h,MeshBasicMaterial as c,Group as p,Color as m}from"three";import{Actor as a,BaseActor as d}from"../actor.js";import{Component as l,ActorComponent as y,attach as f}from"../component.js";import{PhysicsSystem as w}from"../../services/physics/physics-system.js";import{BoxCollisionShape as v}from"../../../scene/collision/collision-shape.js";import{Parameter as O}from"../../../shader/parameter.js";import{firstValueFrom as g}from"rxjs";let u=class extends y{constructor(){super(...arguments),this.color=new m(16777215),this.dimensions=new r(1,1,1)}onInit(){const t=new n(this.dimensions.x,this.dimensions.y,this.dimensions.z),s=new i(t),r=new e(s,new o({color:this.color})),m=(new h(t,new c({color:this.color,transparent:!0,opacity:.3,visible:!1})),new p);m.add(r),this.actor.object.add(m)}};t([O(),s("design:type",m)],u.prototype,"color",void 0),u=t([l({inEditor:!0,editorOnly:!0})],u);export{u as TriggerVolumeMesh};let A=class extends y{constructor(t){super(),this.physicsSystem=t,this.dimensions=new r(1,1,1),this.offset=new r(0,0,0),this.editorMesh=f(u)}onInit(){this.physicsSystem.addActor(this.actor,[new v(this.dimensions).withOffset(this.offset)],{isTrigger:!0}),g(this.disposed).then((
|
|
1
|
+
import{__decorate as t,__metadata as s}from"tslib";import{EdgesGeometry as i,LineSegments as e,LineBasicMaterial as o,Vector3 as r,BoxGeometry as n,Mesh as h,MeshBasicMaterial as c,Group as p,Color as m}from"three";import{Actor as a,BaseActor as d}from"../actor.js";import{Component as l,ActorComponent as y,attach as f}from"../component.js";import{PhysicsSystem as w}from"../../services/physics/physics-system.js";import{BoxCollisionShape as v}from"../../../scene/collision/collision-shape.js";import{Parameter as O}from"../../../shader/parameter.js";import{firstValueFrom as g}from"rxjs";let u=class extends y{constructor(){super(...arguments),this.color=new m(16777215),this.dimensions=new r(1,1,1)}onInit(){const t=new n(this.dimensions.x,this.dimensions.y,this.dimensions.z),s=new i(t),r=new e(s,new o({color:this.color})),m=(new h(t,new c({color:this.color,transparent:!0,opacity:.3,visible:!1})),new p);m.add(r),this.actor.object.add(m)}};t([O(),s("design:type",m)],u.prototype,"color",void 0),u=t([l({inEditor:!0,editorOnly:!0})],u);export{u as TriggerVolumeMesh};let A=class extends y{constructor(t){super(),this.physicsSystem=t,this.dimensions=new r(1,1,1),this.offset=new r(0,0,0),this.editorMesh=f(u)}onInit(){this.physicsSystem.addActor(this.actor,[new v(this.dimensions).withOffset(this.offset)],{isTrigger:!0}),g(this.disposed).then(()=>{this.physicsSystem.removeActor(this.actor)})}onBeginOverlapWithActor(t){return this.physicsSystem.onBeginOverlapWithActor(this.actor,t)}onEndOverlapWithActor(t){return this.physicsSystem.onEndOverlapWithActor(this.actor,t)}onBeginOverlapWithActorType(t){return this.physicsSystem.onBeginOverlapWithActorType(this.actor,t)}onEndOverlapWithActorType(t){return this.physicsSystem.onEndOverlapWithActorType(this.actor,t)}};A=t([l({inEditor:!0,editorOnly:!1}),s("design:paramtypes",[w])],A);export{A as TriggerVolumeComponent};let x=class extends d{constructor(){super(...arguments),this.trigger=f(A)}};x=t([a()],x);export{x as TriggerVolume};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{ArrowHelper as r,ConeGeometry as i,EdgesGeometry as s,LineBasicMaterial as o,LineSegments as n,MeshStandardMaterial as a,PerspectiveCamera as l,Vector3 as h}from"three";import{Parameter as d}from"../../../shader/parameter.js";import{ViewController as c}from"../../services/render.js";import{ActorComponent as p,attach as w,Component as m}from"../component.js";const v=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let b=class extends p{constructor(e){super(),this.viewController=e,this.near=.5,this.far=500,this.viewAngle=v?30:45,this.debugMesh=w(y),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.instance=new l(this.viewAngle,this.aspect,this.near,this.far)}onInit(){this.actor.object.add(this.instance),this.instance.near=this.near,this.instance.far=this.far,this.instance.fov=this.viewAngle}};e([d(),t("design:type",Number)],b.prototype,"near",void 0),e([d(),t("design:type",Number)],b.prototype,"far",void 0),e([d(),t("design:type",Number)],b.prototype,"viewAngle",void 0),b=e([m({inEditor:!0}),t("design:paramtypes",[c])],b);export{b as CameraComponent};let y=class extends p{constructor(){super(...arguments),this.arrowColor=16101442}onInit(){const e=new i(1,1,4);e.rotateX(Math.PI/2),e.rotateZ(Math.PI/4),e.scale(1,9/16,1);const t=new s(e),l=(new a({color:3355443}),new n(t,new o({color:16777215}))),d=new r(new h(0,0,-1),new h(0,0,0),1.2,this.arrowColor,.15,.2);l.add(d),d.layers.disableAll(),d.layers.enable(19),d.traverse(
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ArrowHelper as r,ConeGeometry as i,EdgesGeometry as s,LineBasicMaterial as o,LineSegments as n,MeshStandardMaterial as a,PerspectiveCamera as l,Vector3 as h}from"three";import{Parameter as d}from"../../../shader/parameter.js";import{ViewController as c}from"../../services/render.js";import{ActorComponent as p,attach as w,Component as m}from"../component.js";const v=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let b=class extends p{constructor(e){super(),this.viewController=e,this.near=.5,this.far=500,this.viewAngle=v?30:45,this.debugMesh=w(y),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.instance=new l(this.viewAngle,this.aspect,this.near,this.far)}onInit(){this.actor.object.add(this.instance),this.instance.near=this.near,this.instance.far=this.far,this.instance.fov=this.viewAngle}};e([d(),t("design:type",Number)],b.prototype,"near",void 0),e([d(),t("design:type",Number)],b.prototype,"far",void 0),e([d(),t("design:type",Number)],b.prototype,"viewAngle",void 0),b=e([m({inEditor:!0}),t("design:paramtypes",[c])],b);export{b as CameraComponent};let y=class extends p{constructor(){super(...arguments),this.arrowColor=16101442}onInit(){const e=new i(1,1,4);e.rotateX(Math.PI/2),e.rotateZ(Math.PI/4),e.scale(1,9/16,1);const t=new s(e),l=(new a({color:3355443}),new n(t,new o({color:16777215}))),d=new r(new h(0,0,-1),new h(0,0,0),1.2,this.arrowColor,.15,.2);l.add(d),d.layers.disableAll(),d.layers.enable(19),d.traverse(e=>{e.layers.disableAll(),e.layers.enable(19)}),this.actor.object.add(l)}};y=e([m({inEditor:!0,editorOnly:!0})],y);export{y as CameraMesh};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as h,Object3D as r}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as c,RestrictedRotationInput as d}from"../../input/index.js";import{PhysicsSystem as l,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as p}from"../../../shader/parameter.js";import{World as f}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as v}from"@hology/nebula";const w=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let k=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=w?30:45,this.camera=new h(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new d(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new c(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(f),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()},this.prevLookAt=new o}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.activated=!0,this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as h,Object3D as r}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as c,RestrictedRotationInput as d}from"../../input/index.js";import{PhysicsSystem as l,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as p}from"../../../shader/parameter.js";import{World as f}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as v}from"@hology/nebula";const w=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let k=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=w?30:45,this.camera=new h(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new d(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new c(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(f),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()},this.prevLookAt=new o}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.activated=!0,this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe(()=>{t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)}))}onLateUpdate(t){this.activated&&this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.fixedBehind!==this.prevFixedBehind?(this.blendDurationLeft=1,this.prevFixedBehind=this.fixedBehind):this.blendDurationLeft>0&&(this.blendDurationLeft-=t),this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.fixedBehind&&this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=x;let s=!1,o=this.distance;const h=new m,r=this.camera.getWorldPosition(A);for(let t=-1;t<=1;t++){const n=g.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,h,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),h.hasHit&&h.distance<this.distance&&(o=Math.min(h.distance,o),s||(s=h.hasHit))}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=L;return t.set(0,0,0),t.y=this.height,this.fixedBehind&&t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(y.position.set(this.offset.x,this.offset.y,this.offset.z),y.rotation.set(0,0,0),y.scale.set(1,1,1),y.applyMatrix4(this.actor.object.matrix)):y.position.copy(this.actor.position).add(this.offset);const t=v.easeInOutCubic(1-this.blendDurationLeft);this.blendDurationLeft>0?this.camera.position.lerp(y.position,t):this.camera.position.copy(y.position);const e=this.getLookAtPosition();this.blendDurationLeft>0?(this.prevLookAt.lerp(e,t),this.camera.lookAt(this.prevLookAt)):(this.camera.lookAt(e),this.prevLookAt.copy(e))}};t([p(),e("design:type",Number)],k.prototype,"near",void 0),t([p(),e("design:type",Number)],k.prototype,"far",void 0),t([p(),e("design:type",Number)],k.prototype,"viewAngle",void 0),k=t([s(),e("design:paramtypes",[a,l])],k);export{k as ThirdPersonCameraComponent};const y=new r,L=new o,x=new o,g=(new o,new o),A=new o;export class ThirdPartyCameraComponent extends k{}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Container as t,Service as n,Inject as o}from"typedi";import{_setupActorUpdateEventHandlers as e}from"./actor.js";import{activeContainerInstance as r}from"./internal/container-map.js";import{randomString as i}from"../../utils/math.js";export class ActorComponent{constructor(){e.call(this)}onInit(){}onBeginPlay(){}onEndPlay(){}onUpdate(t){}onLateUpdate(t){}get disposed(){return this.actor.disposed}attach(t,n){return this.actor.attach(t,n)}}ActorComponent.__isActorComponent=!0;export function Component(t={inEditor:!1,editorOnly:!1}){const o=n({transient:!0});return function(n){n.__inEditor=t.inEditor,n.__onlyEditor=t.editorOnly,o(n)}}export function Attach(n={},e){return function(r,i,a){if(null==r)return void Reflect.defineMetadata("design:type",e,e.prototype,i);const c=e??Reflect.getMetadata("design:type",r,i);o((
|
|
1
|
+
import{Container as t,Service as n,Inject as o}from"typedi";import{_setupActorUpdateEventHandlers as e}from"./actor.js";import{activeContainerInstance as r}from"./internal/container-map.js";import{randomString as i}from"../../utils/math.js";export class ActorComponent{constructor(){e.call(this)}onInit(){}onBeginPlay(){}onEndPlay(){}onUpdate(t){}onLateUpdate(t){}get disposed(){return this.actor.disposed}attach(t,n){return this.actor.attach(t,n)}}ActorComponent.__isActorComponent=!0;export function Component(t={inEditor:!1,editorOnly:!1}){const o=n({transient:!0});return function(n){n.__inEditor=t.inEditor,n.__onlyEditor=t.editorOnly,o(n)}}export function Attach(n={},e){return function(r,i,a){if(null==r)return void Reflect.defineMetadata("design:type",e,e.prototype,i);const c=e??Reflect.getMetadata("design:type",r,i);o(()=>c)(r,i,a);const s=t.handlers.find(t=>t.object===r&&t.propertyName===i&&t.index===a),d=s.value;s.value=t=>{const o=d(t);return Object.assign(o,n)}}}export function attach(n,o){const e=r.value??t.of("default"),a=i();e.set({id:a,type:n,transient:!0});const c=e.get(a);if(null!=o)for(const t of Object.keys(o))c[t]=o[t];return c}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|