@hology/core 0.0.55 → 0.0.56

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,4 +9,9 @@ export interface ProjectConfig {
9
9
  * This folder is sometimes called "public"
10
10
  */
11
11
  staticPath: string;
12
+ play?: {
13
+ command: string;
14
+ showTerminal: boolean;
15
+ openIn: 'browser';
16
+ };
12
17
  }
package/dist/csm.d.ts CHANGED
@@ -7,7 +7,6 @@ export declare const CSMUtil: {
7
7
  patchThreeAdd(): void;
8
8
  };
9
9
  export declare const CSMShader: {
10
- lights_fragment_begin: (cascades: number) => string;
11
- lights_fragment_begi2: (cascades: number) => string;
12
- lights_pars_begin: (maxCascades: number) => string;
10
+ lights_fragment_begin: string;
11
+ lights_pars_begin: string;
13
12
  };
package/dist/csm.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as t from"three";const i={add:t.Object3D.prototype.add,attach:t.Object3D.prototype.attach},e=new WeakMap,n=new WeakMap;export const CSMUtil=new class{constructor(){this.renderingView=null}onBeforeCompile(i,e){i.defines=i.defines||{},i.defines.USE_CSM=1,i.defines.CSM_CASCADES=this.renderingView.csm.cascades,console.log(e.fragmentShader);const n=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.far:Number.MAX_SAFE_INTEGER,o=this.renderingView.camera instanceof t.PerspectiveCamera?this.renderingView.camera.near:0,a=Math.min(n,this.renderingView.csm.maxFar),r=[];this.renderingView.csm.getExtendedBreaks(r),e.uniforms.CSM_cascades={value:r},e.uniforms.cameraNear={value:o},e.uniforms.shadowFar={value:a}}patchThreeAdd(){const o=this.renderingView;e.set(o.scene,o.csm);for(const[o,a]of Object.entries(i))t.Object3D.prototype[o]=function(...i){let o=this;for(;null!=o.parent;)o=o.parent;const r=o,d=e.get(r);if(null==d)return a.apply(this,arguments),this;n.has(r)||n.set(r,new WeakSet);const h=n.get(r);function c(t){t&&!h.has(t)&&(h.add(t),d?.setupMaterial(t))}return i.forEach((i=>i?.traverse((i=>{if(i instanceof t.Mesh||i instanceof t.SkinnedMesh)if(i.material instanceof Array)for(const t of i.material)c(t);else c(i.material)})))),a.apply(this,arguments),this}}};import{ShaderChunk as o}from"three";const a=o.lights_pars_begin;export const CSMShader={lights_fragment_begin:t=>"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n\n#ifdef USE_CLEARCOAT\n\n\tgeometryClearcoatNormal = clearcoatNormal;\n\n#endif\n\n#ifdef USE_IRIDESCENCE\n\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\n\tif ( material.iridescenceThickness == 0.0 ) {\n\n\t\tmaterial.iridescence = 0.0;\n\n\t} else {\n\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\n\t}\n\n\tif ( material.iridescence > 0.0 ) {\n\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\n\t\t// Iridescence F0 approximation\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\n\t}\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n\t\tpointLight = pointLights[ i ];\n\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n\t\tspotLight = spotLights[ i ];\n\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\n\t\t// spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n\tRectAreaLight rectAreaLight;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n\tvec3 iblIrradiance = vec3( 0.0 );\n\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n\t#if defined( USE_LIGHT_PROBES )\n\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\n\t#endif\n\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n\t",lights_fragment_begi2:t=>`\nGeometricContext geometry;\n\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\n#ifdef CLEARCOAT\n\n\tgeometry.clearcoatNormal = clearcoatNormal;\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n\t\tpointLight = pointLights[ i ];\n\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n\t\tspotLight = spotLights[ i ];\n\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0) && defined( RE_Direct ) && defined( USE_CSM ) && defined( CSM_CASCADES )\n\n\tDirectionalLight directionalLight;\n\tfloat linearDepth = (vViewPosition.z) / (shadowFar - cameraNear);\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#if defined( USE_SHADOWMAP ) && defined( CSM_FADE ) && CSM_FADE == 1\n\tvec2 cascade;\n\tfloat cascadeCenter;\n\tfloat closestEdge;\n\tfloat margin;\n\tfloat csmx;\n\tfloat csmy;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t \t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\t\t// NOTE: Depth gets larger away from the camera.\n\t\t\t// cascade.x is closer, cascade.y is further\n\n\t\t\t\t#if ( UNROLLED_LOOP_INDEX < ${t} )\n\n\t\t\t\t\t// NOTE: Apply CSM shadows\n\n\t\t\t\t\tcascade = CSM_cascades[ i ];\n\t\t\t\t\tcascadeCenter = ( cascade.x + cascade.y ) / 2.0;\n\t\t\t\t\tclosestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;\n\t\t\t\t\tmargin = 0.25 * pow( closestEdge, 2.0 );\n\t\t\t\t\tcsmx = cascade.x - margin / 2.0;\n\t\t\t\t\tcsmy = cascade.y + margin / 2.0;\n\t\t\t\t\tif( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {\n\n\t\t\t\t\t\tfloat dist = min( linearDepth - csmx, csmy - linearDepth );\n\t\t\t\t\t\tfloat ratio = clamp( dist / margin, 0.0, 1.0 );\n\n\t\t\t\t\t\tvec3 prevColor = directLight.color;\n\t\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\t\tbool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;\n\t\t\t\t\t\tdirectLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );\n\n\t\t\t\t\t\tReflectedLight prevLight = reflectedLight;\n\t\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t\t\tbool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;\n\t\t\t\t\t\tfloat blendRatio = shouldBlend ? ratio : 1.0;\n\n\t\t\t\t\t\treflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );\n\t\t\t\t\t\treflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );\n\t\t\t\t\t\treflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );\n\t\t\t\t\t\treflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );\n\n\t\t\t\t\t}\n\n\t\t\t\t#else\n\n\t\t\t\t\t// NOTE: Apply the reminder of directional lights\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#endif\n\n\t \t#endif\n\n\t}\n\t#pragma unroll_loop_end\n\t#else\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\t\tdirectionalLight = directionalLights[ i ];\n\t\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) \n\n\t\t\t\t#if ( UNROLLED_LOOP_INDEX < ${t} )\n\n\t\t\t\t\t// NOTE: Apply CSM shadows\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n\t\t\t\t\tif(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#else\n\n\t\t\t\t\t// NOTE: Apply the reminder of directional lights\n\n\t\t\t\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\t\t\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\n\t\t\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n\t#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)\n\t\t// compute the lights not casting shadows (if any)\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = NUM_DIR_LIGHT_SHADOWS; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\t\tdirectionalLight = directionalLights[ i ];\n\n\t\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) && !defined( USE_CSM ) && !defined( CSM_CASCADES )\n\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n\tRectAreaLight rectAreaLight;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n\tvec3 iblIrradiance = vec3( 0.0 );\n\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n`,lights_pars_begin:t=>a};
1
+ import*as t from"three";const e={add:t.Object3D.prototype.add,attach:t.Object3D.prototype.attach},i=new WeakMap,n=new WeakMap;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}}patchThreeAdd(){const a=this.renderingView;i.set(a.scene,a.csm);for(const[a,o]of Object.entries(e))t.Object3D.prototype[a]=function(...e){let a=this;for(;null!=a.parent;)a=a.parent;const r=a,d=i.get(r);if(null==d)return o.apply(this,arguments),this;n.has(r)||n.set(r,new WeakSet);const c=n.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)})))),o.apply(this,arguments),this}}};import{ShaderChunk as a}from"three";a.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"+a.lights_pars_begin};
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import*as t from"three";import{Object3D as e}from"three";import i,{Behaviour as n,Body as o,Emitter as s,Rate as r}from"three-nebula";import{AttributeFloatNode as a,AttributeVec3Node as l,AttributeVec4Node as c,NodeShaderMaterial as m,RgbNode as u,UniformVec3Node as p,Vec3ExpressionNode as d,Vec4Node as h,attributes as f,float as w,glslFunction as g,lambertMaterial as y,log as A,pow as v,rgba as x,saturate as E,textureSampler2d as b,transformed as P,uniforms as M,varyingAttributes as I,varyingVec3 as R,varyingVec4 as z}from"three-shader-graph";import{prepareShapeParameters as V}from"../../scene/materializer.js";import{ShapeLibrary as B}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as T,linearEyeDepth as S}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as j,particleVelcoityUniformName as k}from"../../shader-nodes/particle.js";import{DefaultInitializer as C}from"./initializsers.js";import{DelayRate as F,OnceRate as Q}from"./rates.js";import{ThreeBlendingMode as U}from"./vfx-asset.js";import{VfxBehaviourLibrary as H,VfxInitializserLibrary as D}from"./vfx-defs.js";import{MultiRenderer as G}from"./vfx-renderers.js";import{StretchedSprite as J}from"./stretched-sprite.js";export async function materializeVfx(n,o,s,r){let a=o;for(;null!=a.parent;)a=a.parent;const l=new e;l.name="particle system local",o.add(l);const c=new e;c.name="particle system world",a.add(c);const m=new G(c,l,t,r),u=new i;return(await Promise.all(n.vfx.emitters.map((async t=>{const e=await q(t,s,u);return e.setParentRecursive(u),e.emit()})))).forEach((t=>u.addEmitter(t))),u.addRenderer(m).emit({onEnd:()=>{console.log("ended")}}),{container:c,system:u,dispose:()=>{c.removeFromParent(),l.removeFromParent(),m.dispose()}}}async function q(i,n,s){const u=function(t){let e;switch(t.rate.type){case"continuous":e=new F(t.rate.delay??0,t.rate.count,t.rate.time);break;case"once":e=new Q(t.rate.delay??0,t.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(t)}`),e=new r(0,1/0)}return e}(i);let j;switch(i.output.type){case"sprite":j=new o(await async function(e,i){const n=null!=e.texture?await i.getTexture(e.texture):W,o=b(n).sample(I.uv),s=new p("color").rgb(),r=(new p("opacity").rgb(),S.subtract(T).divide(S));let a=o.x();if("number"==typeof e.softness&&e.softness>0){const t=v(r,w(e.softness));a=a.multiply(t)}const l=g(h,{position:P.position,modelViewMatrix:M.modelViewMatrix},"\n vec2 center = vec2(0.5, 0.5);\n float rotation = 0.0;\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 c=new L({color:x(s,a).multiply(o),transparent:!0,position:l,uniforms:{color:{value:new t.Color(e.color)}}});c.blending=U[e.blendingMode]??t.NormalBlending;const m=new t.Mesh(new t.PlaneGeometry(1,1),c);return m.name="sprite",m}(i.output,n));break;case"stretchedSprite":j=new o(await async function(e,i){const n=null!=e.texture?await i.getTexture(e.texture):W,o=b(n).sample(I.uv),s=z(new c("color")),r=s.rgb();let m=s.w();if("number"==typeof e.softness&&e.softness>0){const t=S.subtract(T).divide(A(S)),i=v(t,w(e.softness));m=E(m.multiply(i))}const u=g(h,{position:f.position,offset:new l("offset"),modelViewMatrix:M.modelViewMatrix,velocity:new c("velocity"),size:new l("size"),rotation:new a("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 p=new L({color:x(r,m).multiply(o),transparent:!0,position:u,uniforms:{}});p.blending=U[e.blendingMode]??t.NormalBlending;const d=new J(new t.PlaneGeometry(1,1),p);return d.scaleFactor=e.scale,d}(i.output,n));break;case"shape":j=new o(await async function(i,n){const o=B[i.shape];if(null==o)return console.error(`No shape with type ${i.shape}`),new e;const s=V(i.params??{}),r=o.geometry(s),a=null!=i.material?await n.getMaterial(i.material):function(){const t=R(new d("instanceColor")).rgb(),e=R(new l("particleData")).x();return new m({color:y({color:t}).rgb().rgba(e),transparent:!0})}();return new t.Mesh(r,a)}(i.output,n));break;case"mesh":j=new o(await async function(i,n){if(null==i.assetId)return console.warn("Can't use mesh as particle without asset id"),new e;const o=await n.getMesh(i.assetId),s=await n.getAsset(i.assetId),r=[];if(null!=s.materialAssignments)for(const e of s.materialAssignments)o.traverse((i=>{i instanceof t.Mesh&&i.material instanceof t.Material&&i.material.color instanceof t.Color&&(i.material.name!=e.name&&null!=e.name||"#"+i.material.color.getHexString()!==e.color||r.push(n.getMaterial(e.materialId).then((t=>i.material=t))))}));return await Promise.all(r),o.traverse((t=>{})),o}(i.output,n));break;case"trail":j=new o({type:"trail",taper:i.output.taper,headGeometry:null,dragTexture:!1,color:i.output.color,colorEnd:i.output.colorEnd,length:i.output.length,opacityStart:i.output.opacityStart,opacityEnd:i.output.opacityEnd,bloom:i.output.bloom});break;default:console.error("Failed to create particly system body: "+JSON.stringify(i))}const k=new K;k.parent=s,k.setRate(u),k._space=i.output.space;const G=await Promise.all(i.initializers.filter((t=>null!=D[t.type])).map((async t=>{const e=D[t.type],i=await V(t.params??{});return e.build(i)})));G.push(j,new C),k.addInitializers(G);const O=await Promise.all(i.behaviours.filter((t=>null!=H[t.type])).map((async t=>{const e=H[t.type],i=await V(t.params??{});return e.build(i)})));O.push(new N),k.addBehaviours(O);for(const t of i.children){const e=await q(t,n,s),i=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=k.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&k.childEmitters.splice(e,1),i.release(t)},t})),o=k.eventDispatcher,r=new Map;k.bindEmitterEvent=!0,o.addEventListener("PARTICLE_DEAD",(t=>{const e=r.get(t.id);if(null!=e){const t=k.childEmitters.findIndex((t=>t.id===e.id));null!=t&&e.stopEmit()}})),o.addEventListener("PARTICLE_CREATED",(t=>{const e=i.get();e.age=0,e.totalEmitTimes=-1,e.particles.length=0,e.currentEmitTime=0,e.cID=0,k.childEmitters.push(e),r.set(t.id,e),e.parentParticle=t,e.emit()}))}return k}const W=(new t.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");class L extends m{get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new t.Color(e)}}class N extends n{initialize(e){if(e.body instanceof t.Mesh){const t=e.body.material;t instanceof m&&(null!=t.uniforms[j]||null!=t.uniforms[k])&&(e.body.material=t.clone())}}mutate(e,i,n){if(this.energize(e,i),e.target instanceof t.Mesh){const t=e.target.material;t instanceof m&&(null!=t.uniforms[j]&&(t.uniforms[j].value=this.energy),null!=t.uniforms[k]&&(t.uniforms[k].value=e.velocity))}}}class K extends s{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(t){if(!this.isEmitting&&0===this.particles.length)return;this.age+=t,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(t),this.integrate(t);let e=this.particles.length;for(;e--;){const t=this.particles[e];t.dead&&(this.parent&&this.parent.dispatch("PARTICLE_DEAD",t),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",t),this.parent.pool.expire(t.reset()),this.particles.splice(e,1))}if(this.updateEmitterBehaviours(t),this.isEmitting||0!==this.particles.length)for(const e of this.childEmitters)null!=e.parentParticle?e.position.copy(e.parentParticle.position):e.setPosition(this.position),e.update(t);else this.onExpired()}clone(){const t=new K;return t.setRate(this.rate.clone()),t.behaviours=this.behaviours,t.initializers=this.initializers,t._space=this._space,t.body=this.body,t.parent=this.parent,t}setParentRecursive(t){this.parent=t,this.childEmitters.forEach((e=>e.setParentRecursive(t)))}}export class EmitterPool{constructor(t){this.creator=t,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(t){this.instances.push(t)}dispose(){this.instances.length=0}}
1
+ import*as t from"three";import{Object3D as e}from"three";import i,{Behaviour as n,Body as o,Emitter as s,Rate as r}from"three-nebula";import{AttributeVec3Node as a,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as m,UniformVec3Node as u,Vec3ExpressionNode as p,Vec4Node as d,attributeFloat as h,attributeVec3 as f,attributeVec4 as g,attributes as w,float as y,glslFunction as A,lambertMaterial as v,log as x,pow as E,rgba as b,saturate as P,textureSampler2d as M,transformed as I,uniforms as R,varyingAttributes as z,varyingVec3 as V,varyingVec4 as B}from"three-shader-graph";import{prepareShapeParameters as T}from"../../scene/materializer.js";import{ShapeLibrary as S}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as j,linearEyeDepth as k}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as C,particleVelcoityUniformName as F}from"../../shader-nodes/particle.js";import{DefaultInitializer as Q}from"./initializsers.js";import{DelayRate as U,OnceRate as H}from"./rates.js";import{ThreeBlendingMode as D}from"./vfx-asset.js";import{VfxBehaviourLibrary as G,VfxInitializserLibrary as J}from"./vfx-defs.js";import{MultiRenderer as q}from"./vfx-renderers.js";import{StretchedSprite as W}from"./stretched-sprite.js";export async function materializeVfx(n,o,s,r){let a=o;for(;null!=a.parent;)a=a.parent;const l=new e;l.name="particle system local",o.add(l);const c=new e;c.name="particle system world",a.add(c);const m=new q(c,l,t,r),u=new i;return(await Promise.all(n.vfx.emitters.map((async t=>{const e=await L(t,s,u);return e.setParentRecursive(u),e.emit()})))).forEach((t=>u.addEmitter(t))),u.addRenderer(m).emit({onEnd:()=>{console.log("ended")}}),{container:c,system:u,dispose:()=>{c.removeFromParent(),l.removeFromParent(),m.dispose()}}}async function L(i,n,s){const m=function(t){let e;switch(t.rate.type){case"continuous":e=new U(t.rate.delay??0,t.rate.count,t.rate.time);break;case"once":e=new H(t.rate.delay??0,t.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(t)}`),e=new r(0,1/0)}return e}(i);let C;switch(i.output.type){case"sprite":C=new o(await async function(e,i){const n=null!=e.texture?await i.getTexture(e.texture):N,o=M(n).sample(z.uv),s=new u("color").rgb,r=(new u("opacity").rgb,k.subtract(j).divide(k));let a=o.x;if("number"==typeof e.softness&&e.softness>0){const t=E(r,y(e.softness));a=a.multiply(t)}const l=A(d,{position:I.position,modelViewMatrix:R.modelViewMatrix},"\n vec2 center = vec2(0.5, 0.5);\n float rotation = 0.0;\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 c=new K({color:b(s,a).multiply(o),transparent:!0,position:l,uniforms:{color:{value:new t.Color(e.color)}}});c.blending=D[e.blendingMode]??t.NormalBlending;const m=new t.Mesh(new t.PlaneGeometry(1,1),c);return m.name="sprite",m}(i.output,n));break;case"stretchedSprite":C=new o(await async function(e,i){const n=null!=e.texture?await i.getTexture(e.texture):N,o=M(n).sample(z.uv),s=B(new l("color")),r=s.rgb;let a=s.w;if("number"==typeof e.softness&&e.softness>0){const t=k.subtract(j).divide(x(k)),i=E(t,y(e.softness));a=P(a.multiply(i))}const c=A(d,{position:w.position,offset:g("offset"),modelViewMatrix:R.modelViewMatrix,velocity:g("velocity"),size:f("size"),rotation:h("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 m=new K({color:b(r,a).multiply(o),transparent:!0,position:c,uniforms:{}});m.blending=D[e.blendingMode]??t.NormalBlending;const u=new W(new t.PlaneGeometry(1,1),m);return u.scaleFactor=e.scale,u}(i.output,n));break;case"shape":C=new o(await async function(i,n){const o=S[i.shape];if(null==o)return console.error(`No shape with type ${i.shape}`),new e;const s=T(i.params??{}),r=o.geometry(s),l=null!=i.material?await n.getMaterial(i.material):function(){const t=V(new p("instanceColor")).rgb,e=V(new a("particleData")).x;return new c({color:v({color:t}).rgb.rgba(e),transparent:!0})}();return new t.Mesh(r,l)}(i.output,n));break;case"mesh":C=new o(await async function(i,n){if(null==i.assetId)return console.warn("Can't use mesh as particle without asset id"),new e;const o=await n.getMesh(i.assetId),s=await n.getAsset(i.assetId),r=[];if(null!=s.materialAssignments)for(const e of s.materialAssignments)o.traverse((i=>{i instanceof t.Mesh&&i.material instanceof t.Material&&i.material.color instanceof t.Color&&(i.material.name!=e.name&&null!=e.name||"#"+i.material.color.getHexString()!==e.color||r.push(n.getMaterial(e.materialId).then((t=>i.material=t))))}));return await Promise.all(r),o.traverse((t=>{})),o}(i.output,n));break;case"trail":C=new o({type:"trail",taper:i.output.taper,headGeometry:null,dragTexture:!1,color:i.output.color,colorEnd:i.output.colorEnd,length:i.output.length,opacityStart:i.output.opacityStart,opacityEnd:i.output.opacityEnd,bloom:i.output.bloom});break;default:console.error("Failed to create particly system body: "+JSON.stringify(i))}const F=new X;F.parent=s,F.setRate(m),F._space=i.output.space;const q=await Promise.all(i.initializers.filter((t=>null!=J[t.type])).map((async t=>{const e=J[t.type],i=await T(t.params??{});return e.build(i)})));q.push(C,new Q),F.addInitializers(q);const Y=await Promise.all(i.behaviours.filter((t=>null!=G[t.type])).map((async t=>{const e=G[t.type],i=await T(t.params??{});return e.build(i)})));Y.push(new O),F.addBehaviours(Y);for(const t of i.children){const e=await L(t,n,s),i=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=F.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&F.childEmitters.splice(e,1),i.release(t)},t})),o=F.eventDispatcher,r=new Map;F.bindEmitterEvent=!0,o.addEventListener("PARTICLE_DEAD",(t=>{const e=r.get(t.id);if(null!=e){const t=F.childEmitters.findIndex((t=>t.id===e.id));null!=t&&e.stopEmit()}})),o.addEventListener("PARTICLE_CREATED",(t=>{const e=i.get();e.age=0,e.totalEmitTimes=-1,e.particles.length=0,e.currentEmitTime=0,e.cID=0,F.childEmitters.push(e),r.set(t.id,e),e.parentParticle=t,e.emit()}))}return F}const N=(new t.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");class K extends c{get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new t.Color(e)}}class O extends n{initialize(e){if(e.body instanceof t.Mesh){const t=e.body.material;t instanceof c&&(null!=t.uniforms[C]||null!=t.uniforms[F])&&(e.body.material=t.clone())}}mutate(e,i,n){if(this.energize(e,i),e.target instanceof t.Mesh){const t=e.target.material;t instanceof c&&(null!=t.uniforms[C]&&(t.uniforms[C].value=this.energy),null!=t.uniforms[F]&&(t.uniforms[F].value=e.velocity))}}}class X extends s{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(t){if(!this.isEmitting&&0===this.particles.length)return;this.age+=t,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(t),this.integrate(t);let e=this.particles.length;for(;e--;){const t=this.particles[e];t.dead&&(this.parent&&this.parent.dispatch("PARTICLE_DEAD",t),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",t),this.parent.pool.expire(t.reset()),this.particles.splice(e,1))}if(this.updateEmitterBehaviours(t),this.isEmitting||0!==this.particles.length)for(const e of this.childEmitters)null!=e.parentParticle?e.position.copy(e.parentParticle.position):e.setPosition(this.position),e.update(t);else this.onExpired()}clone(){const t=new X;return t.setRate(this.rate.clone()),t.behaviours=this.behaviours,t.initializers=this.initializers,t._space=this._space,t.body=this.body,t.parent=this.parent,t}setParentRecursive(t){this.parent=t,this.childEmitters.forEach((e=>e.setParentRecursive(t)))}}export class EmitterPool{constructor(t){this.creator=t,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(t){this.instances.push(t)}dispose(){this.instances.length=0}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
package/dist/rendering.js CHANGED
@@ -1,4 +1,4 @@
1
- var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Mesh as r,Matrix4 as n,Material as a,ShaderMaterial as o,Color as h,PerspectiveCamera as l,ShaderChunk as d}from"three";import{EffectComposer as c,UnrealBloomPass as m,VRButton as p}from"three-stdlib";import{RenderPass as u}from"three-stdlib";import{ShaderPass as g}from"three-stdlib";import{FXAAShader as f}from"three-stdlib";import{CSMShader as v,CSMUtil as w}from"./csm.js";import{GammaCorrectionShader as x}from"three-stdlib";import{Reflector as b}from"three-stdlib";import{depthUniformName as C,resolutionUniformName as P,supportsDepthTextureExtension as S,nearUniformName as R,farUniformName as M}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as y}from"./shader-nodes/time.js";import{OutlinePass as T}from"./utils/three/outline-pass.js";import W from"./utils/three/stats.js";import{findFirstVisibleObject as L}from"./utils/three/traverse.js";import{DepthPass as E}from"./utils/three/depth-pass.js";import{Service as H}from"typedi";import{CSM as B}from"three/examples/jsm/csm/CSM.js";import{GPUStatsPanel as D}from"three/examples/jsm/utils/GPUStatsPanel.js";(new s.Layers).set(9);const F=new s.MeshBasicMaterial({color:"black"}),j=new s.MeshDepthMaterial;j.depthPacking=s.RGBADepthPacking,j.blending=s.NoBlending,d.lights_pars_begin=v.lights_pars_begin(5);const V=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let z=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=V?.5:1,this.maxPixelRatio=V?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=W(),this._showStats=!1,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new h,this.hadBloom=!1,this.bloomStoredMaterials={},null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(p.createButton(this.renderer)),this.composer=new c(this.renderer);var r=t.clientWidth/t.clientHeight;const n=new s.PerspectiveCamera(45,r,.5,800);n.layers.enable(19),this.setCamera(n),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=S(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container);const a=new u(this.scene,this.camera);this.composer.addPass(a);const o=new m(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);o.threshold=0,o.strength=.9,o.radius=1,this.renderer.info.autoReset=!1;const l=new c(this.renderer);l.renderToScreen=!1,l.addPass(a),l.addPass(o),this.bloomComposer=l;const d=new g(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:l.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(d.needsSwap=!0,this.composer.addPass(d),this.outlinePass=new T(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new g(f);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}var v=new g(x);v.clear=!1,this.composer.addPass(v)}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof T?t.renderCamera=e:t instanceof E&&(t.camera=e)})),null==this.csm?this.csm=new B({maxFar:250,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"logarithmic"}):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}loop(e,t=!1){const i=this.stats,o=i.addPanel(new W.Panel("Calls","#83f","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new D(this.renderer.getContext()),i.addPanel(h)),i.showPanel(0),this.showStats=t;let l=10;const d=()=>{const e=this.renderer.info.render.calls;e>l&&(l=e,setTimeout((()=>l=10),5e3)),o.update(e,l)};performance.now();s.Ray.prototype.intersectTriangle;const c=[],m=[];let p=0;const u=new n,g=new n,f=t=>{const n=this.renderer.getContext();if(this.paused&&this.running&&n.drawingBufferHeight>1)return void setTimeout((()=>f(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let o=(t*=.001)-p;if(p=t,u.copy(this.camera.matrixWorld),o>1){let t=o;for(;t>.05;)e(O),t-=O;e(t)}else e(o);if(this.onLoopCallbacks.forEach((e=>e(o))),this.camera?.updateMatrixWorld(),g.copy(this.camera.matrixWorld),g.equals(u)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),c.length=0,m.length=0,this.scene.traverseVisible((e=>{(e instanceof r||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[C])?(e.visible=!1,c.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof b||(e instanceof r||e instanceof s.Sprite)&&function(e){if(e.material instanceof a)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e))&&(e.visible=!1,m.push(e)),e instanceof r&&e.material?.uniforms&&null!=e.material?.uniforms[y]&&(e.material.uniforms[y].value=t)})),c.length>0){if(this.scene.overrideMaterial=j,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}c.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0));try{!this.paused&&this.running&&(h?.startQuery(),this.render(o),h?.endQuery(),this.showStats&&d(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(f)}),1e3/this.fpsCap):requestAnimationFrame(f))};!0===this.options.enableXR?this.renderer.setAnimationLoop(f):requestAnimationFrame(f)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=L(this.scene,(e=>e instanceof r&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){e.isMesh&&e.visible&&!0!==e.material.userData.hasBloom&&(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=F:e.visible=!1)}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof o&&(e.uniforms[C].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[P]&&e.uniforms[P].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof l&&(e.uniforms[R].value=this.camera.near,e.uniforms[M].value=this.camera.far))}};z=e=t([H(),i("design:paramtypes",[HTMLElement,Object])],z);export{z as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const O=.05;
1
+ var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Mesh as r,Matrix4 as n,Material as a,ShaderMaterial as o,Color as h,PerspectiveCamera as l,ShaderChunk as d}from"three";import{EffectComposer as c,UnrealBloomPass as m,VRButton as p}from"three-stdlib";import{RenderPass as u}from"three-stdlib";import{ShaderPass as g}from"three-stdlib";import{FXAAShader as f}from"three-stdlib";import{CSMShader as v,CSMUtil as w}from"./csm.js";import{GammaCorrectionShader as x}from"three-stdlib";import{Reflector as b}from"three-stdlib";import{depthUniformName as C,resolutionUniformName as P,supportsDepthTextureExtension as S,nearUniformName as R,farUniformName as M}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as y}from"./shader-nodes/time.js";import{OutlinePass as T}from"./utils/three/outline-pass.js";import W from"./utils/three/stats.js";import{findFirstVisibleObject as L}from"./utils/three/traverse.js";import{DepthPass as E}from"./utils/three/depth-pass.js";import{Service as H}from"typedi";import{CSM as B}from"three/examples/jsm/csm/CSM.js";import{GPUStatsPanel as D}from"three/examples/jsm/utils/GPUStatsPanel.js";(new s.Layers).set(9);const F=new s.MeshBasicMaterial({color:"black"}),j=new s.MeshDepthMaterial;j.depthPacking=s.RGBADepthPacking,j.blending=s.NoBlending;const V=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let z=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=V?.5:1,this.maxPixelRatio=V?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=W(),this._showStats=!1,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new h,this.hadBloom=!1,this.bloomStoredMaterials={},null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(p.createButton(this.renderer)),this.composer=new c(this.renderer);var r=t.clientWidth/t.clientHeight;const n=new s.PerspectiveCamera(45,r,.5,800);n.layers.enable(19),this.setCamera(n),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=S(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container);const a=new u(this.scene,this.camera);this.composer.addPass(a);const o=new m(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);o.threshold=0,o.strength=.9,o.radius=1,this.renderer.info.autoReset=!1;const l=new c(this.renderer);l.renderToScreen=!1,l.addPass(a),l.addPass(o),this.bloomComposer=l;const d=new g(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:l.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(d.needsSwap=!0,this.composer.addPass(d),this.outlinePass=new T(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new g(f);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}var v=new g(x);v.clear=!1,this.composer.addPass(v)}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof T?t.renderCamera=e:t instanceof E&&(t.camera=e)})),null==this.csm?(this.csm=new B({maxFar:250,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"logarithmic"}),d.lights_fragment_begin=v.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}loop(e,t=!1){const i=this.stats,o=i.addPanel(new W.Panel("Calls","#83f","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new D(this.renderer.getContext()),i.addPanel(h)),i.showPanel(0),this.showStats=t;let l=10;const d=()=>{const e=this.renderer.info.render.calls;e>l&&(l=e,setTimeout((()=>l=10),5e3)),o.update(e,l)};performance.now();s.Ray.prototype.intersectTriangle;const c=[],m=[];let p=0;const u=new n,g=new n,f=t=>{const n=this.renderer.getContext();if(this.paused&&this.running&&n.drawingBufferHeight>1)return void setTimeout((()=>f(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let o=(t*=.001)-p;if(p=t,u.copy(this.camera.matrixWorld),o>1){let t=o;for(;t>.05;)e(O),t-=O;e(t)}else e(o);if(this.onLoopCallbacks.forEach((e=>e(o))),this.camera?.updateMatrixWorld(),g.copy(this.camera.matrixWorld),g.equals(u)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),c.length=0,m.length=0,this.scene.traverseVisible((e=>{(e instanceof r||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[C])?(e.visible=!1,c.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof b||(e instanceof r||e instanceof s.Sprite)&&function(e){if(e.material instanceof a)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e))&&(e.visible=!1,m.push(e)),e instanceof r&&e.material?.uniforms&&null!=e.material?.uniforms[y]&&(e.material.uniforms[y].value=t)})),c.length>0){if(this.scene.overrideMaterial=j,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}c.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0));try{!this.paused&&this.running&&(h?.startQuery(),this.render(o),h?.endQuery(),this.showStats&&d(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(f)}),1e3/this.fpsCap):requestAnimationFrame(f))};!0===this.options.enableXR?this.renderer.setAnimationLoop(f):requestAnimationFrame(f)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=L(this.scene,(e=>e instanceof r&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){e.isMesh&&e.visible&&!0!==e.material.userData.hasBloom&&(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=F:e.visible=!1)}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof o&&(e.uniforms[C].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[P]&&e.uniforms[P].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof l&&(e.uniforms[R].value=this.camera.near,e.uniforms[M].value=this.camera.far))}};z=e=t([H(),i("design:paramtypes",[HTMLElement,Object])],z);export{z as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const O=.05;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -12,6 +12,7 @@ export declare class AssetResourceLoader {
12
12
  private fbxLoader;
13
13
  private objLoader;
14
14
  private textureLoader;
15
+ private tgaLoader;
15
16
  private _textureLoader;
16
17
  private audioLoader;
17
18
  protected onError(error: unknown): void;
@@ -1,4 +1,4 @@
1
- import{AudioLoader as e,Group as t,LoadingManager as a,Mesh as s,Object3D as i,TextureLoader as r}from"three";import{GLTFLoader as n,MTLLoader as o,OBJLoader as h}from"three-stdlib";import{FBXLoader as c}from"three-stdlib";import{cloneMesh as l}from"../utils/mesh.js";import{pathJoin as d}from"../utils/files.js";import{Subject as m,firstValueFrom as p}from"rxjs";import{importCollisionShapes as u}from"./collision/collision-shape-import.js";import*as f from"three";import{iterateMaterials as g}from"../utils/materials.js";const w=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new a,this.glbLoader=new n(this.loadingManager),this.fbxLoader=new c(this.loadingManager),this.objLoader=new h(this.loadingManager),this.textureLoader=new r(this.loadingManager),this._textureLoader=new f.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.makeReady=new m,this.ready=p(this.makeReady),this.collisionShapeCache=new Map}setDataDir(e){this.basePath=d(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return d(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}async getTexture(e){return null==e?null:(await this.ready,this.textureCache.has(e.id)||await this.textureLoader.loadAsync(this.getUri(e.fileKey)).then((t=>(t.wrapS=L(e.texture?.wrapS),t.wrapT=L(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0,this.textureCache.set(e.id,t),t))),this.textureCache.get(e.id))}async getMesh(e){if(await this.ready,!w.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new t,animations:[]};if(!this.cache.has(e.fileKey))try{this.cache.set(e.fileKey,await this.loadMesh(e))}catch(e){return this.onError(e),{scene:new t,animations:[]}}const a=l(this.cache.get(e.fileKey).scene),i=this.cache.get(e.fileKey).animations;a.traverse((e=>{e instanceof s&&e.material instanceof Array&&(e.material=e.material.slice())}));const r=this.computeCollisionShapes(e,a),n=new AssetMeshInstance;n.add(a),n.collisionShapes=r,n.animations=i;const o=!!e.receiveShadow??!0,h=!!e.castShadow??!1;return a.traverse((e=>{e.castShadow=h,e.receiveShadow=o})),{scene:n,animations:i}}async getAudio(e){return await this.ready,this.audioLoader.loadAsync(this.getUri(e.fileKey))}computeCollisionShapes(e,t){const a=e.id+e.mesh?.collisions?.shapeType;return this.collisionShapeCache.has(a)||this.collisionShapeCache.set(a,u(t,e)),this.collisionShapeCache.get(a)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then((e=>(e.scene=function(e,t){let a=!1;if(t.traverseVisible((e=>{b.test(e.name)&&(a=!0)})),!a)return t;const s=new f.LOD,i=[t];for(;i.length>0;){const e=i.shift(),t=e.name.match(b);if(null!=t){const a=parseInt(t[1]);0===a?s.addLevel(e,0):console.warn(`Skipping LOD level ${a} for now as LOD is not fully supported`)}else i.push(...e.children)}return s}(0,e.scene),e)))}async loadByAsset(e){const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then((e=>({scene:e.scene,animations:e.animations})));case"fbx":return this.fbxLoader.loadAsync(t).then((e=>({scene:e,animations:e.animations})));case"obj":if(null!=e.materialLib){const t=new o;t.materialOptions={normalizeRGB:!1};const a=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(a)}return this.objLoader.loadAsync(t).then((e=>(y(e),e))).then((e=>({scene:e,animations:e.animations})))}}}function y(e){if(e instanceof s)for(const t of g(e.material))t instanceof f.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(y)}export class AssetMeshInstance extends i{}export function getElectronArg(e){const t=`--${e}=`,a=window.process?.argv.find((e=>e.startsWith(t)));return a?.substring(t.length)}function L(e){switch(e){case"clamp":return f.ClampToEdgeWrapping;case"repeat":return f.RepeatWrapping;case"mirror":return f.MirroredRepeatWrapping}return f.RepeatWrapping}const b=/_LOD(\d+)$/;
1
+ import{AudioLoader as e,Group as t,LoadingManager as a,Mesh as s,Object3D as i,TextureLoader as r}from"three";import{GLTFLoader as n,MTLLoader as o,OBJLoader as h}from"three-stdlib";import{FBXLoader as c}from"three-stdlib";import{cloneMesh as l}from"../utils/mesh.js";import{pathJoin as d}from"../utils/files.js";import{Subject as m,firstValueFrom as p}from"rxjs";import{importCollisionShapes as f}from"./collision/collision-shape-import.js";import*as u from"three";import{iterateMaterials as g}from"../utils/materials.js";import{TGALoader as w}from"three/examples/jsm/Addons.js";const y=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new a,this.glbLoader=new n(this.loadingManager),this.fbxLoader=new c(this.loadingManager),this.objLoader=new h(this.loadingManager),this.textureLoader=new r(this.loadingManager),this.tgaLoader=new w(this.loadingManager),this._textureLoader=new u.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.makeReady=new m,this.ready=p(this.makeReady),this.collisionShapeCache=new Map}setDataDir(e){this.basePath=d(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return d(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}async getTexture(e){return null==e?null:(await this.ready,this.textureCache.has(e.id)||await(e.fileKey.endsWith("tga")?this.tgaLoader:this.textureLoader).loadAsync(this.getUri(e.fileKey)).then((t=>(t.wrapS=x(e.texture?.wrapS),t.wrapT=x(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0,this.textureCache.set(e.id,t),t))),this.textureCache.get(e.id))}async getMesh(e){if(await this.ready,!y.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new t,animations:[]};if(!this.cache.has(e.fileKey))try{this.cache.set(e.fileKey,await this.loadMesh(e))}catch(e){return this.onError(e),{scene:new t,animations:[]}}const a=l(this.cache.get(e.fileKey).scene),i=this.cache.get(e.fileKey).animations;a.traverse((e=>{e instanceof s&&e.material instanceof Array&&(e.material=e.material.slice())}));const r=this.computeCollisionShapes(e,a),n=new AssetMeshInstance;n.add(a),n.collisionShapes=r,n.animations=i;const o=e.receiveShadow??!0,h=e.castShadow??!1;return a.traverse((e=>{e.castShadow=h,e.receiveShadow=o})),{scene:n,animations:i}}async getAudio(e){return await this.ready,this.audioLoader.loadAsync(this.getUri(e.fileKey))}computeCollisionShapes(e,t){const a=e.id+e.mesh?.collisions?.shapeType;return this.collisionShapeCache.has(a)||this.collisionShapeCache.set(a,f(t,e)),this.collisionShapeCache.get(a)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then((e=>(e.scene=function(e,t){let a=!1;if(t.traverseVisible((e=>{b.test(e.name)&&(a=!0)})),!a)return t;const s=new u.LOD,i=[t];for(;i.length>0;){const e=i.shift(),t=e.name.match(b);if(null!=t){const a=parseInt(t[1]);0===a?s.addLevel(e,0):console.warn(`Skipping LOD level ${a} for now as LOD is not fully supported`)}else i.push(...e.children)}return s}(0,e.scene),e)))}async loadByAsset(e){const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then((e=>({scene:e.scene,animations:e.animations})));case"fbx":return this.fbxLoader.loadAsync(t).then((e=>({scene:e,animations:e.animations})));case"obj":if(null!=e.materialLib){const t=new o;t.materialOptions={normalizeRGB:!1};const a=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(a)}return this.objLoader.loadAsync(t).then((e=>(L(e),e))).then((e=>({scene:e,animations:e.animations})))}}}function L(e){if(e instanceof s)for(const t of g(e.material))t instanceof u.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(L)}export class AssetMeshInstance extends i{}export function getElectronArg(e){const t=`--${e}=`,a=window.process?.argv.find((e=>e.startsWith(t)));return a?.substring(t.length)}function x(e){switch(e){case"clamp":return u.ClampToEdgeWrapping;case"repeat":return u.RepeatWrapping;case"mirror":return u.MirroredRepeatWrapping}return u.RepeatWrapping}const b=/_LOD(\d+)$/;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{Group as e,Mesh as a}from"three";import{Color as r}from"three";import{varyingAttributes as t,float as n,mod as o,dot as s,vec2 as c,step as i,fract as l,mix as p,rgb as d,NodeShaderMaterial as u,rgba as m,standardMaterial as f}from"three-shader-graph";import{mixColorsByLayer as L,select as h}from"../../shader-nodes/index.js";export function initLandscape(e){e.sections.y,e.sectionSize,e.sections.x,e.sectionSize;return new LandscapeGroup}export function createLandscapeDefaultMaterial(){const e=t.uv,a=n(10),h=n(7),x=o(s(c(1,1),i(c(.5,.5),l(e.multiplyScalar(a)))),n(2)),S=o(s(c(1,1),i(c(.5,.5),l(e.multiplyScalar(h.multiply(a))))),n(2)),w=p(d(new r(4473924).convertLinearToSRGB()),d(new r(5592405).convertLinearToSRGB()),x),v=p(w,w.addScalar(n(.1)),S),y=L({layerColors:[m(v).rgb(),...["#55DDE0","#33658A","#2F4858"].map((e=>new r(e).convertLinearToSRGB())).map((e=>d(e))).reverse()],enableNoise:!1}),D=new u({color:f({color:y})});return D.color=new r("#aaaaaa"),D.name="Default",D}export const defaultLandscapeMaterial=createLandscapeDefaultMaterial();export class LandscapeMesh extends a{}export class LandscapeGroup extends e{get sections(){return this.children.filter((e=>e instanceof LandscapeMesh))}}
1
+ import{Group as e,Mesh as a}from"three";import{Color as r}from"three";import{varyingAttributes as t,float as n,mod as o,dot as s,vec2 as c,step as i,fract as l,mix as p,rgb as d,NodeShaderMaterial as u,rgba as m,standardMaterial as f}from"three-shader-graph";import{mixColorsByLayer as L,select as h}from"../../shader-nodes/index.js";export function initLandscape(e){e.sections.y,e.sectionSize,e.sections.x,e.sectionSize;return new LandscapeGroup}export function createLandscapeDefaultMaterial(){const e=t.uv,a=n(10),h=n(7),x=o(s(c(1,1),i(c(.5,.5),l(e.multiplyScalar(a)))),n(2)),S=o(s(c(1,1),i(c(.5,.5),l(e.multiplyScalar(h.multiply(a))))),n(2)),w=p(d(new r(4473924).convertLinearToSRGB()),d(new r(5592405).convertLinearToSRGB()),x),v=p(w,w.addScalar(n(.1)),S),y=L({layerColors:[m(v).rgb,...["#55DDE0","#33658A","#2F4858"].map((e=>new r(e).convertLinearToSRGB())).map((e=>d(e))).reverse()],enableNoise:!1}),D=new u({color:f({color:y})});return D.color=new r("#aaaaaa"),D.name="Default",D}export const defaultLandscapeMaterial=createLandscapeDefaultMaterial();export class LandscapeMesh extends a{}export class LandscapeGroup extends e{get sections(){return this.children.filter((e=>e instanceof LandscapeMesh))}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{attributes as m,float as o,lambertMaterial as l,NodeShaderMaterial as e,rgb as r,rgba as i,select as t,sin as a,smoothstep as p,transformed as n,translateAxis as u,uniformFloat as s,uniformSampler2d as f,varyingFloat as y,varyingVec2 as c}from"../../shader-nodes/index.js";import{Vector3 as v}from"three";import{CSMUtil as d}from"../../csm.js";export function createGrassFoliageMaterial(g,w){const x=n.mvPosition.z().multiply(o(-1)),h=y(p(o(100),o(60),x)),j=m.uv.y(),z=r(11977268),B=o(.2),C=l(r(g.color)).rgb().multiplyScalar(o(.9)).add(z.multiplyScalar(y(j).multiply(B))),S=c(m.uv),b=f("map").sample(S,o(0)),F=i(C,b.x().multiply(h)),G=s("time"),L=o(.5).multiply(t(j.gt(o(0)),j.multiply(j),o(0))).multiply(a(G.multiply(o(.001)))),M=u(new v(1,0,0).normalize(),L),P=new e({color:F,transform:M,uniforms:{map:{value:g.map},time:{value:0}},transparent:!0});return P.onBeforeCompile=m=>{d.onBeforeCompile(P,m)},P.uniforms.map.value=g.map,w.onLoop((()=>{P.uniforms.time.value=performance.now()})),P}
1
+ import{attributes as m,float as o,lambertMaterial as l,NodeShaderMaterial as e,rgb as r,rgba as i,select as t,sin as a,smoothstep as p,transformed as n,translateAxis as u,uniformFloat as s,uniformSampler2d as f,varyingFloat as y,varyingVec2 as c}from"../../shader-nodes/index.js";import{Vector3 as v}from"three";import{CSMUtil as d}from"../../csm.js";export function createGrassFoliageMaterial(g,w){const x=n.mvPosition.z.multiply(o(-1)),h=y(p(o(100),o(60),x)),j=m.uv.y,z=r(11977268),B=o(.2),C=l(r(g.color)).rgb.multiplyScalar(o(.9)).add(z.multiplyScalar(y(j).multiply(B))),S=c(m.uv),b=f("map").sample(S,o(0)),F=i(C,b.x.multiply(h)),G=s("time"),L=o(.5).multiply(t(j.gt(o(0)),j.multiply(j),o(0))).multiply(a(G.multiply(o(.001)))),M=u(new v(1,0,0).normalize(),L),P=new e({color:F,transform:M,uniforms:{map:{value:g.map},time:{value:0}},transparent:!0});return P.onBeforeCompile=m=>{d.onBeforeCompile(P,m)},P.uniforms.map.value=g.map,w.onLoop((()=>{P.uniforms.time.value=performance.now()})),P}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
package/dist/scene/sky.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as e from"three";import{AmbientLight as a,FogExp2 as t}from"three";import{attributes as r,NodeShaderMaterial as o,uniforms as i,vec4 as n,varyingVec3 as s,float as h,normalize as d,rgb as c,mix as m,max as w,pow as p}from"three-shader-graph";export function basicSceneSetup(r){!function(t){new a(16777215,.5);var r=new e.HemisphereLight(16777215,273,.5*Math.PI);r.name=ambientLightName,r.position.set(0,100,0),t.add(r);new e.HemisphereLightHelper(r,10);var o=new e.DirectionalLight(16777215,.7);o.position.set(-30,50,30),o.castShadow=!0,o.shadow.mapSize.width=2048,o.shadow.mapSize.height=2048;var i=250;o.shadow.normalBias=.3,o.shadow.camera.left=-i,o.shadow.camera.right=i,o.shadow.camera.top=i,o.shadow.camera.bottom=-i,o.shadow.camera.far=500,o.shadow.bias=-5e-4;new e.DirectionalLightHelper(o,10);var n=new e.PointLight(16777215,1,50);n.castShadow=!0,n.position.set(0,40,0),n.shadow.camera.near=1,n.shadow.camera.far=60,n.shadow.bias=-.005}(r),function(e){e.fog=new t(l,f)}(r)}export const ambientLightName="default_ambient";const l=157554,f=.005;export const defaultSkyMaterial=function(){const a=h(5),t=h(.6),l=new e.Color(16777215),f=new e.Color(13431551),g=s(i.modelMatrix.multiplyVec(n(r.position,1)).xyz()),u=d(g.addScalar(a)).y(),S=w(p(w(u,h(0)),h(t)),h(0)),b=n(m(c(f),c(l),S),h(1)),y=new o({color:b.rgba()});return y.side=e.BackSide,y.depthTest=!1,y}();export function createSky(){var a=new e.SphereGeometry(300,10,15),t=new e.Mesh(a,defaultSkyMaterial);return t.renderOrder=-999,t.raycast=()=>{},t}
1
+ import*as e from"three";import{AmbientLight as a,FogExp2 as t}from"three";import{attributes as r,NodeShaderMaterial as o,uniforms as i,vec4 as n,varyingVec3 as s,float as h,normalize as d,rgb as c,mix as m,max as w,pow as p}from"three-shader-graph";export function basicSceneSetup(r){!function(t){new a(16777215,.5);var r=new e.HemisphereLight(16777215,273,.5*Math.PI);r.name=ambientLightName,r.position.set(0,100,0),t.add(r);new e.HemisphereLightHelper(r,10);var o=new e.DirectionalLight(16777215,.7);o.position.set(-30,50,30),o.castShadow=!0,o.shadow.mapSize.width=2048,o.shadow.mapSize.height=2048;var i=250;o.shadow.normalBias=.3,o.shadow.camera.left=-i,o.shadow.camera.right=i,o.shadow.camera.top=i,o.shadow.camera.bottom=-i,o.shadow.camera.far=500,o.shadow.bias=-5e-4;new e.DirectionalLightHelper(o,10);var n=new e.PointLight(16777215,1,50);n.castShadow=!0,n.position.set(0,40,0),n.shadow.camera.near=1,n.shadow.camera.far=60,n.shadow.bias=-.005}(r),function(e){e.fog=new t(l,f)}(r)}export const ambientLightName="default_ambient";const l=157554,f=.005;export const defaultSkyMaterial=function(){const a=h(5),t=h(.6),l=new e.Color(16777215),f=new e.Color(13431551),g=s(i.modelMatrix.multiplyVec(n(r.position,1)).xyz),u=d(g.addScalar(a)).y,S=w(p(w(u,h(0)),h(t)),h(0)),b=n(m(c(f),c(l),S),h(1)),y=new o({color:b.rgba});return y.side=e.BackSide,y.depthTest=!1,y}();export function createSky(){var a=new e.SphereGeometry(300,10,15),t=new e.Mesh(a,defaultSkyMaterial);return t.renderOrder=-999,t.raycast=()=>{},t}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,5 +1,5 @@
1
- import { FloatNode } from "three-shader-graph";
2
- export declare function fresnelEffect(power?: number | FloatNode): FloatNode;
1
+ import { FloatNode, Vec3Node } from "three-shader-graph";
2
+ export declare function fresnelEffect(power?: number | FloatNode, normal?: Vec3Node): FloatNode;
3
3
  /**
4
4
  * Gives a factor for how shallow the depth is where 1 is the most shallow.
5
5
  * This can be useful to for example create a highlight where an object intersects
@@ -1,4 +1,4 @@
1
- import{Vec3ExpressionNode as t,attributes as r,dot as e,float as o,normalize as n,pow as c,saturate as i,uniforms as s,varyingAttributes as a,varyingVec3 as f,vec4 as p}from"three-shader-graph";import{fragmentLinearEyeDepth as u,linearEyeDepth as m}from"./depth.js";const d=s.modelMatrix.multiplyVec(p(r.position,1));export function fresnelEffect(s=1){const a=r.normal,f=new t("cameraPosition"),p=n(f.subtract(d.xyz())),u=o(1);return c(i(u.subtract(e(a,p))),o(s))}const h=o(1).subtract(m.subtract(u).divide(m));export function edgeDepthEffect(t=1){return c(h,o(t))}
1
+ import{Vec3ExpressionNode as t,attributes as e,dot as r,float as o,normalize as c,pow as i,saturate as n,uniforms as s,varyingAttributes as a,varyingVec3 as m,vec4 as p}from"three-shader-graph";import{fragmentLinearEyeDepth as u,linearEyeDepth as f}from"./depth.js";const l=s.modelMatrix.multiplyVec(p(e.position,1)),d=s.modelMatrix.multiplyVec(p(e.normal,0)).xyz;export function fresnelEffect(e=1,s=d){const a=new t("cameraPosition"),m=c(a.subtract(l.xyz)),p=o(1);return i(n(p.subtract(r(s,m))),o(e))}const x=o(1).subtract(f.subtract(u).divide(f));export function edgeDepthEffect(t=1){return i(x,o(t))}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{attributes as r,float as t,uniforms as o,vec4 as e,varyingVec2 as a}from"three-shader-graph";const i=o.modelMatrix.multiplyVec(e(r.position,1));export function getLandscapeCoords(r){return a(i.xz().multiplyScalar(t(r)))}
1
+ import{attributes as r,float as t,uniforms as o,vec4 as e,varyingVec2 as a}from"three-shader-graph";const i=o.modelMatrix.multiplyVec(e(r.position,1));export function getLandscapeCoords(r){return a(i.xz.multiplyScalar(t(r)))}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{float as e,uniforms as o,vec4 as r,attributes as t,varyingVec2 as a,AttributeVec3Node as i,varyingVec3 as l,SimplexNoiseNode as d,select as n,mix as s,smoothstep as y}from"three-shader-graph";export var LayerMixMode;!function(e){e[e.hard=0]="hard",e[e.soft=1]="soft"}(LayerMixMode||(LayerMixMode={}));const c={enableNoise:!0,noiseScale:e(.1),noiseAmount:e(.5),decay:.3,mode:LayerMixMode.soft},u=a(o.modelMatrix.multiplyVec(r(t.position,1)).xz()),m=l(new i("material")),p=[e(0),m.x(),m.y(),m.z()];export function mixColorsByLayer(o){const r={...c,...o},t=e(r.noiseAmount).multiply(e(.1)),a=e(r.noiseScale),i=new d(u.multiplyScalar(a)).multiply(e(2)).subtract(e(1)).multiply(t),l=e(.5),m=r.enableNoise?l.add(i.multiply(e(.1))):l;if(r.mode==LayerMixMode.hard)return r.layerColors.reduce(((e,o,r)=>n(p[r].gt(m),o,e)));{const o=e(r.decay),t=e(.5),a=o.divide(e(2)),l=t.subtract(a),d=t.add(a);return r.layerColors.slice(0,p.length).reduce(((e,o,r)=>s(e,o,y(l,d,p[r].add(i)))))}}
1
+ import{float as e,uniforms as o,vec4 as r,attributes as t,varyingVec2 as a,AttributeVec3Node as i,varyingVec3 as l,SimplexNoiseNode as d,select as n,mix as s,smoothstep as y}from"three-shader-graph";export var LayerMixMode;!function(e){e[e.hard=0]="hard",e[e.soft=1]="soft"}(LayerMixMode||(LayerMixMode={}));const c={enableNoise:!0,noiseScale:e(.1),noiseAmount:e(.5),decay:.3,mode:LayerMixMode.soft},u=a(o.modelMatrix.multiplyVec(r(t.position,1)).xz),m=l(new i("material")),p=[e(0),m.x,m.y,m.z];export function mixColorsByLayer(o){const r={...c,...o},t=e(r.noiseAmount).multiply(e(.1)),a=e(r.noiseScale),i=new d(u.multiplyScalar(a)).multiply(e(2)).subtract(e(1)).multiply(t),l=e(.5),m=r.enableNoise?l.add(i.multiply(e(.1))):l;if(r.mode==LayerMixMode.hard)return r.layerColors.reduce(((e,o,r)=>n(p[r].gt(m),o,e)));{const o=e(r.decay),t=e(.5),a=o.divide(e(2)),l=t.subtract(a),d=t.add(a);return r.layerColors.slice(0,p.length).reduce(((e,o,r)=>s(e,o,y(l,d,p[r].add(i)))))}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{float as t,length as a,min as r,max as e,saturate as c,dFdx as d,dFdy as l,abs as u,ComponentsVec2Node as n,vec2 as i}from"three-shader-graph";export function rectangleFloat(t,a,e){const o=u(t.multiplyScalar(2).subtractScalar(1)).subtract(new n(a,e)),s=i(1,1).subtract(o.divide(u(d(p=o)).add(u(l(p)))));var p;return c(r(s.x(),s.y()))}export function roundedRectangleFloat(o,s,p,b){const m=e(r(r(u(b.multiply(2)),u(s)),u(p)),t(1e-5)),v=u(o.multiplyScalar(2).subtractScalar(1)).subtract(new n(s,p)).addScalar(m),S=a(e(i(0,0),v)).divide(m);return c(t(1).subtract(S).divide(u(d(y=S)).add(u(l(y)))));var y}
1
+ import{float as t,length as a,min as r,max as e,saturate as c,dFdx as d,dFdy as l,abs as u,ComponentsVec2Node as n,vec2 as i}from"three-shader-graph";export function rectangleFloat(t,a,e){const o=u(t.multiplyScalar(2).subtractScalar(1)).subtract(new n(a,e)),s=i(1,1).subtract(o.divide(u(d(p=o)).add(u(l(p)))));var p;return c(r(s.x,s.y))}export function roundedRectangleFloat(o,s,p,b){const m=e(r(r(u(b.multiply(2)),u(s)),u(p)),t(1e-5)),v=u(o.multiplyScalar(2).subtractScalar(1)).subtract(new n(s,p)).addScalar(m),S=a(e(i(0,0),v)).divide(m);return c(t(1).subtract(S).divide(u(d(y=S)).add(u(l(y)))));var y}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{select as t,length as a,ComponentsVec2Node as r,ConstantMat2Node as l,fract as d,sin as n,cos as e,vec2 as o,vec3 as u,floor as c}from"three-shader-graph";export function voronoi(i,p,m){const y=i.multiplyScalar(m),s=c(y),x=d(y),f=[-1,0,1],h=f.flatMap((t=>f.map((a=>[t,a])))).reduce(((c,[i,m])=>{const y=o(i,m),f=function(t,a){const o=new l(15.27,47.63,99.41,89.98);return t=d(n(t.multiplyMat(o)).multiplyScalar(46839.32)),new r(n(t.y().add(a)).multiply(.5).add(.5),e(t.x().add(a)).multiply(.5).add(.5))}(y.add(s),p),h=a(y.add(f).subtract(x));return t(h.lt(c.x()),u(h,f.x(),f.y()),c)}),u(8,0,0));return{noise:h.x(),cells:h.y()}}
1
+ import{select as t,length as a,ComponentsVec2Node as r,ConstantMat2Node as l,fract as d,sin as n,cos as e,vec2 as o,vec3 as u,floor as c}from"three-shader-graph";export function voronoi(i,p,m){const y=i.multiplyScalar(m),s=c(y),x=d(y),f=[-1,0,1],h=f.flatMap((t=>f.map((a=>[t,a])))).reduce(((c,[i,m])=>{const y=o(i,m),f=function(t,a){const o=new l(15.27,47.63,99.41,89.98);return t=d(n(t.multiplyMat(o)).multiplyScalar(46839.32)),new r(n(t.y.add(a)).multiply(.5).add(.5),e(t.x.add(a)).multiply(.5).add(.5))}(y.add(s),p),h=a(y.add(f).subtract(x));return t(h.lt(c.x),u(h,f.x,f.y),c)}),u(8,0,0));return{noise:h.x,cells:h.y}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.55",
3
+ "version": "0.0.56",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -94,7 +94,7 @@
94
94
  "three-csm": "^4.2.1",
95
95
  "three-mesh-bvh": "^0.7.5",
96
96
  "three-nebula": "^10.0.3",
97
- "three-shader-graph": "^0.1.31",
97
+ "three-shader-graph": "^0.2.1",
98
98
  "three-stdlib": "2.30.3",
99
99
  "ts-key-enum": "^2.0.12",
100
100
  "typedi": "^0.10.0"