@luma.gl/gltf 9.1.0-alpha.10 → 9.1.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -51,6 +51,13 @@ var __exports__ = (() => {
51
51
  }
52
52
  });
53
53
 
54
+ // external-global-plugin:@luma.gl/shadertools
55
+ var require_shadertools = __commonJS({
56
+ "external-global-plugin:@luma.gl/shadertools"(exports, module) {
57
+ module.exports = globalThis.luma;
58
+ }
59
+ });
60
+
54
61
  // bundle.ts
55
62
  var bundle_exports = {};
56
63
  __export(bundle_exports, {
@@ -3574,571 +3581,7 @@ var __exports__ = (() => {
3574
3581
 
3575
3582
  // src/gltf/create-gltf-model.ts
3576
3583
  var import_core4 = __toESM(require_core(), 1);
3577
-
3578
- // ../shadertools/src/modules-webgl1/lighting/lights/lights-glsl.ts
3579
- var lightingShader = (
3580
- /* glsl */
3581
- `#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
3582
-
3583
- struct AmbientLight {
3584
- vec3 color;
3585
- };
3586
-
3587
- struct PointLight {
3588
- vec3 color;
3589
- vec3 position;
3590
-
3591
- // Constant-Linear-Exponential
3592
- vec3 attenuation;
3593
- };
3594
-
3595
- struct DirectionalLight {
3596
- vec3 color;
3597
- vec3 direction;
3598
- };
3599
-
3600
- uniform AmbientLight lighting_uAmbientLight;
3601
- uniform PointLight lighting_uPointLight[MAX_LIGHTS];
3602
- uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
3603
- uniform int lighting_uPointLightCount;
3604
- uniform int lighting_uDirectionalLightCount;
3605
-
3606
- uniform bool lighting_uEnabled;
3607
-
3608
- float getPointLightAttenuation(PointLight pointLight, float distance) {
3609
- return pointLight.attenuation.x
3610
- + pointLight.attenuation.y * distance
3611
- + pointLight.attenuation.z * distance * distance;
3612
- }
3613
-
3614
- #endif
3615
- `
3616
- );
3617
-
3618
- // ../shadertools/src/modules-webgl1/lighting/lights/lights.ts
3619
- var INITIAL_MODULE_OPTIONS = {
3620
- lightSources: {}
3621
- };
3622
- function convertColor(colorDef = {}) {
3623
- const { color = [0, 0, 0], intensity = 1 } = colorDef;
3624
- return color.map((component) => component * intensity / 255);
3625
- }
3626
- function getLightSourceUniforms({
3627
- ambientLight,
3628
- pointLights = [],
3629
- directionalLights = []
3630
- }) {
3631
- const lightSourceUniforms = {};
3632
- if (ambientLight) {
3633
- lightSourceUniforms["lighting_uAmbientLight.color"] = convertColor(ambientLight);
3634
- } else {
3635
- lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
3636
- }
3637
- pointLights.forEach((pointLight, index) => {
3638
- lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor(pointLight);
3639
- lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
3640
- lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [
3641
- 1,
3642
- 0,
3643
- 0
3644
- ];
3645
- });
3646
- lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
3647
- directionalLights.forEach((directionalLight, index) => {
3648
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor(directionalLight);
3649
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
3650
- });
3651
- lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
3652
- return lightSourceUniforms;
3653
- }
3654
- function getUniforms(opts = INITIAL_MODULE_OPTIONS) {
3655
- if ("lightSources" in opts) {
3656
- const { ambientLight, pointLights, directionalLights } = opts.lightSources || {};
3657
- const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
3658
- if (!hasLights) {
3659
- return { lighting_uEnabled: false };
3660
- }
3661
- return Object.assign(
3662
- {},
3663
- getLightSourceUniforms({ ambientLight, pointLights, directionalLights }),
3664
- {
3665
- lighting_uEnabled: true
3666
- }
3667
- );
3668
- }
3669
- if ("lights" in opts) {
3670
- const lightSources = { pointLights: [], directionalLights: [] };
3671
- for (const light of opts.lights || []) {
3672
- switch (light.type) {
3673
- case "ambient":
3674
- lightSources.ambientLight = light;
3675
- break;
3676
- case "directional":
3677
- lightSources.directionalLights?.push(light);
3678
- break;
3679
- case "point":
3680
- lightSources.pointLights?.push(light);
3681
- break;
3682
- default:
3683
- }
3684
- }
3685
- return getUniforms({ lightSources });
3686
- }
3687
- return {};
3688
- }
3689
- var lights = {
3690
- name: "lights",
3691
- vs: lightingShader,
3692
- fs: lightingShader,
3693
- getUniforms,
3694
- defines: {
3695
- MAX_LIGHTS: 3
3696
- }
3697
- };
3698
-
3699
- // ../shadertools/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts
3700
- var vs = (
3701
- /* glsl */
3702
- `uniform mat4 u_MVPMatrix;
3703
- uniform mat4 u_ModelMatrix;
3704
- uniform mat4 u_NormalMatrix;
3705
-
3706
- out vec3 pbr_vPosition;
3707
- out vec2 pbr_vUV;
3708
-
3709
- #ifdef HAS_NORMALS
3710
- # ifdef HAS_TANGENTS
3711
- out mat3 pbr_vTBN;
3712
- # else
3713
- out vec3 pbr_vNormal;
3714
- # endif
3715
- #endif
3716
-
3717
- void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
3718
- {
3719
- vec4 pos = u_ModelMatrix * position;
3720
- pbr_vPosition = vec3(pos.xyz) / pos.w;
3721
-
3722
- #ifdef HAS_NORMALS
3723
- #ifdef HAS_TANGENTS
3724
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
3725
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
3726
- vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
3727
- pbr_vTBN = mat3(tangentW, bitangentW, normalW);
3728
- #else // HAS_TANGENTS != 1
3729
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
3730
- #endif
3731
- #endif
3732
-
3733
- #ifdef HAS_UV
3734
- pbr_vUV = uv;
3735
- #else
3736
- pbr_vUV = vec2(0.,0.);
3737
- #endif
3738
- }
3739
- `
3740
- );
3741
-
3742
- // ../shadertools/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts
3743
- var fs = (
3744
- /* glsl */
3745
- `precision highp float;
3746
-
3747
- uniform bool pbr_uUnlit;
3748
-
3749
- #ifdef USE_IBL
3750
- uniform samplerCube u_DiffuseEnvSampler;
3751
- uniform samplerCube u_SpecularEnvSampler;
3752
- uniform sampler2D u_brdfLUT;
3753
- uniform vec2 u_ScaleIBLAmbient;
3754
- #endif
3755
-
3756
- #ifdef HAS_BASECOLORMAP
3757
- uniform sampler2D u_BaseColorSampler;
3758
- #endif
3759
- #ifdef HAS_NORMALMAP
3760
- uniform sampler2D u_NormalSampler;
3761
- uniform float u_NormalScale;
3762
- #endif
3763
- #ifdef HAS_EMISSIVEMAP
3764
- uniform sampler2D u_EmissiveSampler;
3765
- uniform vec3 u_EmissiveFactor;
3766
- #endif
3767
- #ifdef HAS_METALROUGHNESSMAP
3768
- uniform sampler2D u_MetallicRoughnessSampler;
3769
- #endif
3770
- #ifdef HAS_OCCLUSIONMAP
3771
- uniform sampler2D u_OcclusionSampler;
3772
- uniform float u_OcclusionStrength;
3773
- #endif
3774
-
3775
- #ifdef ALPHA_CUTOFF
3776
- uniform float u_AlphaCutoff;
3777
- #endif
3778
-
3779
- uniform vec2 u_MetallicRoughnessValues;
3780
- uniform vec4 u_BaseColorFactor;
3781
-
3782
- uniform vec3 u_Camera;
3783
-
3784
- // debugging flags used for shader output of intermediate PBR variables
3785
- #ifdef PBR_DEBUG
3786
- uniform vec4 u_ScaleDiffBaseMR;
3787
- uniform vec4 u_ScaleFGDSpec;
3788
- #endif
3789
-
3790
- in vec3 pbr_vPosition;
3791
-
3792
- in vec2 pbr_vUV;
3793
-
3794
- #ifdef HAS_NORMALS
3795
- #ifdef HAS_TANGENTS
3796
- in mat3 pbr_vTBN;
3797
- #else
3798
- in vec3 pbr_vNormal;
3799
- #endif
3800
- #endif
3801
-
3802
- // Encapsulate the various inputs used by the various functions in the shading equation
3803
- // We store values in this struct to simplify the integration of alternative implementations
3804
- // of the shading terms, outlined in the Readme.MD Appendix.
3805
- struct PBRInfo
3806
- {
3807
- float NdotL; // cos angle between normal and light direction
3808
- float NdotV; // cos angle between normal and view direction
3809
- float NdotH; // cos angle between normal and half vector
3810
- float LdotH; // cos angle between light direction and half vector
3811
- float VdotH; // cos angle between view direction and half vector
3812
- float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
3813
- float metalness; // metallic value at the surface
3814
- vec3 reflectance0; // full reflectance color (normal incidence angle)
3815
- vec3 reflectance90; // reflectance color at grazing angle
3816
- float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
3817
- vec3 diffuseColor; // color contribution from diffuse lighting
3818
- vec3 specularColor; // color contribution from specular lighting
3819
- vec3 n; // normal at surface point
3820
- vec3 v; // vector from surface point to camera
3821
- };
3822
-
3823
- const float M_PI = 3.141592653589793;
3824
- const float c_MinRoughness = 0.04;
3825
-
3826
- vec4 SRGBtoLINEAR(vec4 srgbIn)
3827
- {
3828
- #ifdef MANUAL_SRGB
3829
- #ifdef SRGB_FAST_APPROXIMATION
3830
- vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
3831
- #else //SRGB_FAST_APPROXIMATION
3832
- vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
3833
- vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
3834
- #endif //SRGB_FAST_APPROXIMATION
3835
- return vec4(linOut,srgbIn.w);;
3836
- #else //MANUAL_SRGB
3837
- return srgbIn;
3838
- #endif //MANUAL_SRGB
3839
- }
3840
-
3841
- // Find the normal for this fragment, pulling either from a predefined normal map
3842
- // or from the interpolated mesh normal and tangent attributes.
3843
- vec3 getNormal()
3844
- {
3845
- // Retrieve the tangent space matrix
3846
- #ifndef HAS_TANGENTS
3847
- vec3 pos_dx = dFdx(pbr_vPosition);
3848
- vec3 pos_dy = dFdy(pbr_vPosition);
3849
- vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
3850
- vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
3851
- vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
3852
-
3853
- #ifdef HAS_NORMALS
3854
- vec3 ng = normalize(pbr_vNormal);
3855
- #else
3856
- vec3 ng = cross(pos_dx, pos_dy);
3857
- #endif
3858
-
3859
- t = normalize(t - ng * dot(ng, t));
3860
- vec3 b = normalize(cross(ng, t));
3861
- mat3 tbn = mat3(t, b, ng);
3862
- #else // HAS_TANGENTS
3863
- mat3 tbn = pbr_vTBN;
3864
- #endif
3865
-
3866
- #ifdef HAS_NORMALMAP
3867
- vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
3868
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
3869
- #else
3870
- // The tbn matrix is linearly interpolated, so we need to re-normalize
3871
- vec3 n = normalize(tbn[2].xyz);
3872
- #endif
3873
-
3874
- return n;
3875
- }
3876
-
3877
- // Calculation of the lighting contribution from an optional Image Based Light source.
3878
- // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
3879
- // See our README.md on Environment Maps [3] for additional discussion.
3880
- #ifdef USE_IBL
3881
- vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
3882
- {
3883
- float mipCount = 9.0; // resolution of 512x512
3884
- float lod = (pbrInputs.perceptualRoughness * mipCount);
3885
- // retrieve a scale and bias to F0. See [1], Figure 3
3886
- vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
3887
- vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
3888
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
3889
-
3890
- #ifdef USE_TEX_LOD
3891
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
3892
- #else
3893
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
3894
- #endif
3895
-
3896
- vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
3897
- vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
3898
-
3899
- // For presentation, this allows us to disable IBL terms
3900
- diffuse *= u_ScaleIBLAmbient.x;
3901
- specular *= u_ScaleIBLAmbient.y;
3902
-
3903
- return diffuse + specular;
3904
- }
3905
- #endif
3906
-
3907
- // Basic Lambertian diffuse
3908
- // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
3909
- // See also [1], Equation 1
3910
- vec3 diffuse(PBRInfo pbrInputs)
3911
- {
3912
- return pbrInputs.diffuseColor / M_PI;
3913
- }
3914
-
3915
- // The following equation models the Fresnel reflectance term of the spec equation (aka F())
3916
- // Implementation of fresnel from [4], Equation 15
3917
- vec3 specularReflection(PBRInfo pbrInputs)
3918
- {
3919
- return pbrInputs.reflectance0 +
3920
- (pbrInputs.reflectance90 - pbrInputs.reflectance0) *
3921
- pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
3922
- }
3923
-
3924
- // This calculates the specular geometric attenuation (aka G()),
3925
- // where rougher material will reflect less light back to the viewer.
3926
- // This implementation is based on [1] Equation 4, and we adopt their modifications to
3927
- // alphaRoughness as input as originally proposed in [2].
3928
- float geometricOcclusion(PBRInfo pbrInputs)
3929
- {
3930
- float NdotL = pbrInputs.NdotL;
3931
- float NdotV = pbrInputs.NdotV;
3932
- float r = pbrInputs.alphaRoughness;
3933
-
3934
- float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
3935
- float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
3936
- return attenuationL * attenuationV;
3937
- }
3938
-
3939
- // The following equation(s) model the distribution of microfacet normals across
3940
- // the area being drawn (aka D())
3941
- // Implementation from "Average Irregularity Representation of a Roughened Surface
3942
- // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
3943
- // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
3944
- // from EPIC Games [1], Equation 3.
3945
- float microfacetDistribution(PBRInfo pbrInputs)
3946
- {
3947
- float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
3948
- float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
3949
- return roughnessSq / (M_PI * f * f);
3950
- }
3951
-
3952
- void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
3953
- pbrInputs.NdotL = 1.0;
3954
- pbrInputs.NdotH = 0.0;
3955
- pbrInputs.LdotH = 0.0;
3956
- pbrInputs.VdotH = 1.0;
3957
- }
3958
-
3959
- void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
3960
- vec3 n = pbrInputs.n;
3961
- vec3 v = pbrInputs.v;
3962
- vec3 l = normalize(lightDirection); // Vector from surface point to light
3963
- vec3 h = normalize(l+v); // Half vector between both l and v
3964
-
3965
- pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
3966
- pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
3967
- pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
3968
- pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
3969
- }
3970
-
3971
- void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
3972
- vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
3973
- PBRInfo_setDirectionalLight(pbrInputs, light_direction);
3974
- }
3975
-
3976
- vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
3977
- // Calculate the shading terms for the microfacet specular shading model
3978
- vec3 F = specularReflection(pbrInputs);
3979
- float G = geometricOcclusion(pbrInputs);
3980
- float D = microfacetDistribution(pbrInputs);
3981
-
3982
- // Calculation of analytical lighting contribution
3983
- vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
3984
- vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
3985
- // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
3986
- return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
3987
- }
3988
-
3989
- vec4 pbr_filterColor(vec4 colorUnused)
3990
- {
3991
- // The albedo may be defined from a base texture or a flat color
3992
- #ifdef HAS_BASECOLORMAP
3993
- vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
3994
- #else
3995
- vec4 baseColor = u_BaseColorFactor;
3996
- #endif
3997
-
3998
- #ifdef ALPHA_CUTOFF
3999
- if (baseColor.a < u_AlphaCutoff) {
4000
- discard;
4001
- }
4002
- #endif
4003
-
4004
- vec3 color = vec3(0, 0, 0);
4005
-
4006
- if(pbr_uUnlit){
4007
- color.rgb = baseColor.rgb;
4008
- }
4009
- else{
4010
- // Metallic and Roughness material properties are packed together
4011
- // In glTF, these factors can be specified by fixed scalar values
4012
- // or from a metallic-roughness map
4013
- float perceptualRoughness = u_MetallicRoughnessValues.y;
4014
- float metallic = u_MetallicRoughnessValues.x;
4015
- #ifdef HAS_METALROUGHNESSMAP
4016
- // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
4017
- // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
4018
- vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
4019
- perceptualRoughness = mrSample.g * perceptualRoughness;
4020
- metallic = mrSample.b * metallic;
4021
- #endif
4022
- perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
4023
- metallic = clamp(metallic, 0.0, 1.0);
4024
- // Roughness is authored as perceptual roughness; as is convention,
4025
- // convert to material roughness by squaring the perceptual roughness [2].
4026
- float alphaRoughness = perceptualRoughness * perceptualRoughness;
4027
-
4028
- vec3 f0 = vec3(0.04);
4029
- vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
4030
- diffuseColor *= 1.0 - metallic;
4031
- vec3 specularColor = mix(f0, baseColor.rgb, metallic);
4032
-
4033
- // Compute reflectance.
4034
- float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
4035
-
4036
- // For typical incident reflectance range (between 4% to 100%) set the grazing
4037
- // reflectance to 100% for typical fresnel effect.
4038
- // For very low reflectance range on highly diffuse objects (below 4%),
4039
- // incrementally reduce grazing reflecance to 0%.
4040
- float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
4041
- vec3 specularEnvironmentR0 = specularColor.rgb;
4042
- vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
4043
-
4044
- vec3 n = getNormal(); // normal at surface point
4045
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
4046
-
4047
- float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
4048
- vec3 reflection = -normalize(reflect(v, n));
4049
-
4050
- PBRInfo pbrInputs = PBRInfo(
4051
- 0.0, // NdotL
4052
- NdotV,
4053
- 0.0, // NdotH
4054
- 0.0, // LdotH
4055
- 0.0, // VdotH
4056
- perceptualRoughness,
4057
- metallic,
4058
- specularEnvironmentR0,
4059
- specularEnvironmentR90,
4060
- alphaRoughness,
4061
- diffuseColor,
4062
- specularColor,
4063
- n,
4064
- v
4065
- );
4066
-
4067
- #ifdef USE_LIGHTS
4068
- // Apply ambient light
4069
- PBRInfo_setAmbientLight(pbrInputs);
4070
- color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
4071
-
4072
- // Apply directional light
4073
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
4074
- if (i < lighting_uDirectionalLightCount) {
4075
- PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
4076
- color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
4077
- }
4078
- }
4079
-
4080
- // Apply point light
4081
- for(int i = 0; i < lighting_uPointLightCount; i++) {
4082
- if (i < lighting_uPointLightCount) {
4083
- PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
4084
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
4085
- color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
4086
- }
4087
- }
4088
- #endif
4089
-
4090
- // Calculate lighting contribution from image based lighting source (IBL)
4091
- #ifdef USE_IBL
4092
- color += getIBLContribution(pbrInputs, n, reflection);
4093
- #endif
4094
-
4095
- // Apply optional PBR terms for additional (optional) shading
4096
- #ifdef HAS_OCCLUSIONMAP
4097
- float ao = texture(u_OcclusionSampler, pbr_vUV).r;
4098
- color = mix(color, color * ao, u_OcclusionStrength);
4099
- #endif
4100
-
4101
- #ifdef HAS_EMISSIVEMAP
4102
- vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
4103
- color += emissive;
4104
- #endif
4105
-
4106
- // This section uses mix to override final color for reference app visualization
4107
- // of various parameters in the lighting equation.
4108
- #ifdef PBR_DEBUG
4109
- // TODO: Figure out how to debug multiple lights
4110
-
4111
- // color = mix(color, F, u_ScaleFGDSpec.x);
4112
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
4113
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
4114
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
4115
-
4116
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
4117
- color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
4118
- color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
4119
- color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
4120
- #endif
4121
-
4122
- }
4123
-
4124
- return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
4125
- }
4126
- `
4127
- );
4128
-
4129
- // ../shadertools/src/modules-webgl1/lighting/pbr/pbr.ts
4130
- var pbr = {
4131
- name: "pbr",
4132
- vs,
4133
- fs,
4134
- defines: {
4135
- LIGHTING_FRAGMENT: 1
4136
- },
4137
- dependencies: [lights],
4138
- getUniforms: (props) => props
4139
- };
4140
-
4141
- // src/gltf/create-gltf-model.ts
3584
+ var import_shadertools = __toESM(require_shadertools(), 1);
4142
3585
  var import_engine2 = __toESM(require_engine(), 1);
4143
3586
  var SHADER = (
4144
3587
  /* WGSL */
@@ -4189,7 +3632,7 @@ layout(0) positions: vec4; // in vec4 POSITION;
4189
3632
  }
4190
3633
  `
4191
3634
  );
4192
- var vs2 = (
3635
+ var vs = (
4193
3636
  /* glsl */
4194
3637
  `#version 300 es
4195
3638
 
@@ -4232,7 +3675,7 @@ layout(0) positions: vec4; // in vec4 POSITION;
4232
3675
  }
4233
3676
  `
4234
3677
  );
4235
- var fs2 = (
3678
+ var fs = (
4236
3679
  /* glsl */
4237
3680
  `#version 300 es
4238
3681
  out vec4 fragmentColor;
@@ -4257,12 +3700,12 @@ layout(0) positions: vec4; // in vec4 POSITION;
4257
3700
  const modelProps = {
4258
3701
  id,
4259
3702
  source: SHADER,
4260
- vs: vs2,
4261
- fs: fs2,
3703
+ vs,
3704
+ fs,
4262
3705
  geometry,
4263
3706
  topology: geometry.topology,
4264
3707
  vertexCount,
4265
- modules: [pbr],
3708
+ modules: [import_shadertools.pbr],
4266
3709
  ...modelOptions,
4267
3710
  bindings: { ...parsedMaterial.bindings, ...modelOptions.bindings },
4268
3711
  defines: { ...parsedMaterial.defines, ...modelOptions.defines },
package/dist/dist.min.js CHANGED
@@ -4,459 +4,7 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- var __exports__=(()=>{var Rn=Object.create;var ot=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var In=Object.getOwnPropertyNames;var bn=Object.getPrototypeOf,Nn=Object.prototype.hasOwnProperty;var Qt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wn=(e,t)=>{for(var n in t)ot(e,n,{get:t[n],enumerable:!0})},st=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of In(t))!Nn.call(e,s)&&s!==n&&ot(e,s,{get:()=>t[s],enumerable:!(r=vn(t,s))||r.enumerable});return e},it=(e,t,n)=>(st(e,t,"default"),n&&st(n,t,"default")),U=(e,t,n)=>(n=e!=null?Rn(bn(e)):{},st(t||!e||!e.__esModule?ot(n,"default",{value:e,enumerable:!0}):n,e)),On=e=>st(ot({},"__esModule",{value:!0}),e);var j=Qt((Qr,Zt)=>{Zt.exports=globalThis.luma});var at=Qt((Jr,te)=>{te.exports=globalThis.luma});var rt={};wn(rt,{GLTFAnimator:()=>W,createScenegraphsFromGLTF:()=>Ln,loadPBREnvironment:()=>de,parsePBRMaterial:()=>ct});it(rt,U(j(),1));var Jt=U(j(),1),C;(function(e){e[e.FUNC_ADD=32774]="FUNC_ADD",e[e.ONE=1]="ONE",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",e[e.LINEAR=9729]="LINEAR",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL"})(C||(C={}));function ct(e,t,n,r){let s={defines:{MANUAL_SRGB:1,SRGB_FAST_APPROXIMATION:1},bindings:{},uniforms:{u_Camera:[0,0,0],u_MetallicRoughnessValues:[1,1]},parameters:{},glParameters:{},generatedTextures:[]};s.defines.USE_TEX_LOD=1;let{imageBasedLightingEnvironment:o}=r;return o&&(s.bindings.u_DiffuseEnvSampler=o.diffuseEnvSampler.texture,s.bindings.u_SpecularEnvSampler=o.specularEnvSampler.texture,s.bindings.u_brdfLUT=o.brdfLutTexture.texture,s.uniforms.u_ScaleIBLAmbient=[1,1]),r?.pbrDebug&&(s.defines.PBR_DEBUG=1,s.uniforms.u_ScaleDiffBaseMR=[0,0,0,0],s.uniforms.u_ScaleFGDSpec=[0,0,0,0]),n.NORMAL&&(s.defines.HAS_NORMALS=1),n.TANGENT&&r?.useTangents&&(s.defines.HAS_TANGENTS=1),n.TEXCOORD_0&&(s.defines.HAS_UV=1),r?.imageBasedLightingEnvironment&&(s.defines.USE_IBL=1),r?.lights&&(s.defines.USE_LIGHTS=1),t&&Pn(e,t,s),s}function Pn(e,t,n){if(n.uniforms.pbr_uUnlit=Boolean(t.unlit),t.pbrMetallicRoughness&&Cn(e,t.pbrMetallicRoughness,n),t.normalTexture){K(e,t.normalTexture,"u_NormalSampler","HAS_NORMALMAP",n);let{scale:r=1}=t.normalTexture;n.uniforms.u_NormalScale=r}if(t.occlusionTexture){K(e,t.occlusionTexture,"u_OcclusionSampler","HAS_OCCLUSIONMAP",n);let{strength:r=1}=t.occlusionTexture;n.uniforms.u_OcclusionStrength=r}switch(t.emissiveTexture&&(K(e,t.emissiveTexture,"u_EmissiveSampler","HAS_EMISSIVEMAP",n),n.uniforms.u_EmissiveFactor=t.emissiveFactor||[0,0,0]),t.alphaMode){case"MASK":let{alphaCutoff:r=.5}=t;n.defines.ALPHA_CUTOFF=1,n.uniforms.u_AlphaCutoff=r;break;case"BLEND":Jt.log.warn("glTF BLEND alphaMode might not work well because it requires mesh sorting")(),n.parameters.blendColorOperation="add",n.parameters.blendColorSrcFactor="src-alpha",n.parameters.blendColorDstFactor="one-minus-src-alpha",n.parameters.blendAlphaOperation="add",n.parameters.blendAlphaSrcFactor="one",n.parameters.blendAlphaDstFactor="one-minus-src-alpha",n.glParameters.blend=!0,n.glParameters.blendEquation=C.FUNC_ADD,n.glParameters.blendFunc=[C.SRC_ALPHA,C.ONE_MINUS_SRC_ALPHA,C.ONE,C.ONE_MINUS_SRC_ALPHA];break}}function Cn(e,t,n){t.baseColorTexture&&K(e,t.baseColorTexture,"u_BaseColorSampler","HAS_BASECOLORMAP",n),n.uniforms.u_BaseColorFactor=t.baseColorFactor||[1,1,1,1],t.metallicRoughnessTexture&&K(e,t.metallicRoughnessTexture,"u_MetallicRoughnessSampler","HAS_METALROUGHNESSMAP",n);let{metallicFactor:r=1,roughnessFactor:s=1}=t;n.uniforms.u_MetallicRoughnessValues=[r,s]}function K(e,t,n,r=null,s){let o=t?.texture?.sampler?.parameters||{},i=t.texture.source.image,c,a={};i.compressed?(c=i,a={[C.TEXTURE_MIN_FILTER]:i.data.length>1?C.LINEAR_MIPMAP_NEAREST:C.LINEAR}):c={data:i};let l=e.createTexture({id:t.uniformName||t.id,parameters:{...o,...a},pixelStore:{[C.UNPACK_FLIP_Y_WEBGL]:!1},...c});s.bindings[n]=l,r&&(s.defines[r]=1),s.generatedTextures.push(l)}var Pt=U(at(),1);function V(e,t){if(!e)throw new Error(t||"loader assertion failed.")}var B={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Bn=B.self||B.window||B.global||{},zn=B.window||B.self||B.global||{},Fn=B.global||B.self||B.window||{},kn=B.document||{};var Tt=Boolean(typeof process!="object"||String(process)!=="[object process]"||process.browser);var ee=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),Dn=ee&&parseFloat(ee[1])||0;var Un="",ne={};function Lt(e){for(let t in ne)if(e.startsWith(t)){let n=ne[t];e=e.replace(t,n)}return!e.startsWith("http://")&&!e.startsWith("https://")&&(e=`${Un}${e}`),e}var re="4.2.1";var Vn=globalThis.loaders?.parseImageNode,Rt=typeof Image<"u",vt=typeof ImageBitmap<"u",qn=Boolean(Vn),It=Tt?!0:qn;function se(e){switch(e){case"auto":return vt||Rt||It;case"imagebitmap":return vt;case"image":return Rt;case"data":return It;default:throw new Error(`@loaders.gl/images: image ${e} not supported in this environment`)}}function oe(){if(vt)return"imagebitmap";if(Rt)return"image";if(It)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}function ie(e){let t=Gn(e);if(!t)throw new Error("Not an image");return t}function bt(e){return lt(e)}function lt(e){switch(ie(e)){case"data":return e;case"image":case"imagebitmap":let t=document.createElement("canvas"),n=t.getContext("2d");if(!n)throw new Error("getImageData");return t.width=e.width,t.height=e.height,n.drawImage(e,0,0),n.getImageData(0,0,e.width,e.height);default:throw new Error("getImageData")}}function Gn(e){return typeof ImageBitmap<"u"&&e instanceof ImageBitmap?"imagebitmap":typeof Image<"u"&&e instanceof Image?"image":e&&typeof e=="object"&&e.data&&e.width&&e.height?"data":null}var Hn=/^data:image\/svg\+xml/,Yn=/\.svg((\?|#).*)?$/;function ft(e){return e&&(Hn.test(e)||Yn.test(e))}function ce(e,t){if(ft(t)){let r=new TextDecoder().decode(e);try{typeof unescape=="function"&&typeof encodeURIComponent=="function"&&(r=unescape(encodeURIComponent(r)))}catch(o){throw new Error(o.message)}return`data:image/svg+xml;base64,${btoa(r)}`}return Nt(e,t)}function Nt(e,t){if(ft(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(e)])}async function ht(e,t,n){let r=ce(e,n),s=self.URL||self.webkitURL,o=typeof r!="string"&&s.createObjectURL(r);try{return await Wn(o||r,t)}finally{o&&s.revokeObjectURL(o)}}async function Wn(e,t){let n=new Image;return n.src=e,t.image&&t.image.decode&&n.decode?(await n.decode(),n):await new Promise((r,s)=>{try{n.onload=()=>r(n),n.onerror=o=>{let i=o instanceof Error?o.message:"error";s(new Error(i))}}catch(o){s(o)}})}var $n={},ae=!0;async function le(e,t,n){let r;ft(n)?r=await ht(e,t,n):r=Nt(e,n);let s=t&&t.imagebitmap;return await Xn(r,s)}async function Xn(e,t=null){if((jn(t)||!ae)&&(t=null),t)try{return await createImageBitmap(e,t)}catch(n){console.warn(n),ae=!1}return await createImageBitmap(e)}function jn(e){for(let t in e||$n)return!1;return!0}function fe(e){return!Jn(e,"ftyp",4)||!(e[8]&96)?null:Kn(e)}function Kn(e){switch(Qn(e,8,12).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}}function Qn(e,t,n){return String.fromCharCode(...e.slice(t,n))}function Zn(e){return[...e].map(t=>t.charCodeAt(0))}function Jn(e,t,n=0){let r=Zn(t);for(let s=0;s<r.length;++s)if(r[s]!==e[s+n])return!1;return!0}var z=!1,Q=!0;function pt(e){let t=Z(e);return er(t)||sr(t)||nr(t)||rr(t)||tr(t)}function tr(e){let t=new Uint8Array(e instanceof DataView?e.buffer:e),n=fe(t);return n?{mimeType:n.mimeType,width:0,height:0}:null}function er(e){let t=Z(e);return t.byteLength>=24&&t.getUint32(0,z)===2303741511?{mimeType:"image/png",width:t.getUint32(16,z),height:t.getUint32(20,z)}:null}function nr(e){let t=Z(e);return t.byteLength>=10&&t.getUint32(0,z)===1195984440?{mimeType:"image/gif",width:t.getUint16(6,Q),height:t.getUint16(8,Q)}:null}function rr(e){let t=Z(e);return t.byteLength>=14&&t.getUint16(0,z)===16973&&t.getUint32(2,Q)===t.byteLength?{mimeType:"image/bmp",width:t.getUint32(18,Q),height:t.getUint32(22,Q)}:null}function sr(e){let t=Z(e);if(!(t.byteLength>=3&&t.getUint16(0,z)===65496&&t.getUint8(2)===255))return null;let{tableMarkers:r,sofMarkers:s}=or(),o=2;for(;o+9<t.byteLength;){let i=t.getUint16(o,z);if(s.has(i))return{mimeType:"image/jpeg",height:t.getUint16(o+5,z),width:t.getUint16(o+7,z)};if(!r.has(i))return null;o+=2,o+=t.getUint16(o,z)}return null}function or(){let e=new Set([65499,65476,65484,65501,65534]);for(let n=65504;n<65520;++n)e.add(n);return{tableMarkers:e,sofMarkers:new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502])}}function Z(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}async function he(e,t){let{mimeType:n}=pt(e)||{},r=globalThis.loaders?.parseImageNode;return V(r),await r(e,n)}async function pe(e,t,n){t=t||{};let s=(t.image||{}).type||"auto",{url:o}=n||{},i=ir(s),c;switch(i){case"imagebitmap":c=await le(e,t,o);break;case"image":c=await ht(e,t,o);break;case"data":c=await he(e,t);break;default:V(!1)}return s==="data"&&(c=lt(c)),c}function ir(e){switch(e){case"auto":case"data":return oe();default:return se(e),e}}var cr=["png","jpg","jpeg","gif","webp","bmp","ico","svg","avif"],ar=["image/png","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],lr={image:{type:"auto",decode:!0}},mt={dataType:null,batchType:null,id:"image",module:"images",name:"Images",version:re,mimeTypes:ar,extensions:cr,parse:pe,tests:[e=>Boolean(pt(new DataView(e)))],options:lr};function xt(e,t,n){let r=typeof e=="function"?e({...t,...n}):e,s=t.baseUrl;return s&&(r=s[s.length-1]==="/"?`${s}${r}`:`${s}/${r}`),Lt(r)}var fr=e=>e&&typeof e=="object";async function me(e,t,n={}){return await wt(e,t,n)}async function wt(e,t,n){return Array.isArray(e)?await pr(e,t,n):fr(e)?await hr(e,t,n):await t(e,n)}async function hr(e,t,n){let r=[],s={};for(let o in e){let i=e[o],c=wt(i,t,n).then(a=>{s[o]=a});r.push(c)}return await Promise.all(r),s}async function pr(e,t,n={}){let r=e.map(s=>wt(s,t,n));return await Promise.all(r)}async function xe(e,t,n){return await me(e,r=>Ot(r,t,n))}async function Ot(e,t,n){let s=await(await fetch(e,n.fetch)).arrayBuffer();return await t(s,n)}async function J(e,t={}){let n=await mr(e,t);return await xe(n,mt.parse,t)}async function mr(e,t,n={}){let r=t&&t.image&&t.image.mipLevels||0;return r!==0?await xr(e,r,t,n):xt(e,t,n)}async function xr(e,t,n,r){let s=[];if(t==="auto"){let o=xt(e,n,{...r,lod:0}),i=await Ot(o,mt.parse,n),{width:c,height:a}=bt(i);t=gr({width:c,height:a}),s.push(o)}V(t>0);for(let o=s.length;o<t;++o){let i=xt(e,n,{...r,lod:o});s.push(i)}return s}function gr(e){return 1+Math.floor(Math.log2(Math.max(e.width,e.height)))}function de(e,t){let n=new Pt.AsyncTexture(e,{id:"brdfLUT",sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"},data:J(t.brdfLutUrl)}),r=ge(e,{id:"DiffuseEnvSampler",getTextureForFace:o=>J(t.getTexUrl("diffuse",o,0)),sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}}),s=ge(e,{id:"SpecularEnvSampler",getTextureForFace:o=>{let i=[];for(let c=0;c<=t.specularMipLevels-1;c++)i.push(J(t.getTexUrl("specular",o,c)));return i},sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}});return{brdfLutTexture:n,diffuseEnvSampler:r,specularEnvSampler:s}}var dr=[0,1,2,3,4,5];function ge(e,{id:t,getTextureForFace:n,sampler:r}){let s={};return dr.forEach(o=>{s[String(o)]=n(o)}),new Pt.AsyncTexture(e,{id:t,dimension:"cube",mipmaps:!1,sampler:r,data:s})}var $=U(at(),1);var eo=1/Math.PI*180,no=1/180*Math.PI,Mr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Mr}};var L=globalThis.mathgl.config;function Me(e,{precision:t=L.precision}={}){return e=ur(e),`${parseFloat(e.toPrecision(t))}`}function G(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ct(e,t,n){let r=L.EPSILON;n&&(L.EPSILON=n);try{if(e===t)return!0;if(G(e)&&G(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;++s)if(!Ct(e[s],t[s]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=L.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{L.EPSILON=r}}function ur(e){return Math.round(e/L.EPSILON)*L.EPSILON}var D=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+n];return this.check()}toArray(t=[],n=0){for(let r=0;r<this.ELEMENTS;++r)t[n+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:G(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(L)}formatString(t){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+Me(this[r],t);return`${t.printTypes?this.constructor.name:""}[${n}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!Ct(this[n],t[n]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==t[n])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,n,r){if(r===void 0)return this.lerp(this,t,n);for(let s=0;s<this.ELEMENTS;++s){let o=t[s],i=typeof n=="number"?n:n[s];this[s]=o+r*(i-o)}return this.check()}min(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(t[n],this[n]);return this.check()}max(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(t[n],this[n]);return this.check()}clamp(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),n[r]);return this.check()}add(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(t){if(typeof t=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;else for(let n=0;n<this.ELEMENTS&&n<t.length;++n)this[n]*=t[n];return this.check()}multiplyByScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}check(){if(L.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)t=t&&Number.isFinite(this[n]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=t;return this.check()}addScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),n);return this.check()}get elements(){return this}};function Ar(e,t){if(e.length!==t)return!1;for(let n=0;n<e.length;++n)if(!Number.isFinite(e[n]))return!1;return!0}function E(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function H(e,t,n=""){if(L.debug&&!Ar(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}function Bt(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}var gt=class extends D{get x(){return this[0]}set x(t){this[0]=E(t)}get y(){return this[1]}set y(t){this[1]=E(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let n=0;n<this.ELEMENTS;++n)t+=this[n]*this[n];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let n=0;for(let r=0;r<this.ELEMENTS;++r){let s=this[r]-t[r];n+=s*s}return E(n)}dot(t){let n=0;for(let r=0;r<this.ELEMENTS;++r)n+=this[r]*t[r];return E(n)}normalize(){let t=this.magnitude();if(t!==0)for(let n=0;n<this.ELEMENTS;++n)this[n]/=t;return this.check()}multiply(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]*=n[r];return this.check()}divide(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]/=n[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return Bt(t>=0&&t<this.ELEMENTS,"index is out of range"),E(this[t])}setComponent(t,n){return Bt(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=n,this.check()}addVectors(t,n){return this.copy(t).add(n)}subVectors(t,n){return this.copy(t).subtract(n)}multiplyVectors(t,n){return this.copy(t).multiply(n)}addScaledVector(t,n){return this.add(new this.constructor(t).multiplyScalar(n))}};var R=typeof Float32Array<"u"?Float32Array:Array;var mo=Math.PI/180;function Sr(){let e=new R(2);return R!=Float32Array&&(e[0]=0,e[1]=0),e}function Se(e,t,n){let r=t[0],s=t[1];return e[0]=n[0]*r+n[4]*s+n[12],e[1]=n[1]*r+n[5]*s+n[13],e}var xo=function(){let e=Sr();return function(t,n,r,s,o,i){let c,a;for(n||(n=2),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],o(e,e,i),t[c]=e[0],t[c+1]=e[1];return t}}();function _e(e,t,n){let r=t[0],s=t[1],o=n[3]*r+n[7]*s||1;return e[0]=(n[0]*r+n[4]*s)/o,e[1]=(n[1]*r+n[5]*s)/o,e}function ye(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[3]*r+n[7]*s+n[11]*o||1;return e[0]=(n[0]*r+n[4]*s+n[8]*o)/i,e[1]=(n[1]*r+n[5]*s+n[9]*o)/i,e[2]=(n[2]*r+n[6]*s+n[10]*o)/i,e}function Ee(e,t,n){let r=t[0],s=t[1];return e[0]=n[0]*r+n[2]*s,e[1]=n[1]*r+n[3]*s,e[2]=t[2],e[3]=t[3],e}function Te(e,t,n){let r=t[0],s=t[1],o=t[2];return e[0]=n[0]*r+n[3]*s+n[6]*o,e[1]=n[1]*r+n[4]*s+n[7]*o,e[2]=n[2]*r+n[5]*s+n[8]*o,e[3]=t[3],e}function zt(){let e=new R(3);return R!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function _r(e){let t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)}function Ft(e,t,n){let r=new R(3);return r[0]=e,r[1]=t,r[2]=n,r}function Le(e,t){let n=t[0],r=t[1],s=t[2],o=n*n+r*r+s*s;return o>0&&(o=1/Math.sqrt(o)),e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e}function Re(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function dt(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[0],c=n[1],a=n[2];return e[0]=s*a-o*c,e[1]=o*i-r*a,e[2]=r*c-s*i,e}function Mt(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[3]*r+n[7]*s+n[11]*o+n[15];return i=i||1,e[0]=(n[0]*r+n[4]*s+n[8]*o+n[12])/i,e[1]=(n[1]*r+n[5]*s+n[9]*o+n[13])/i,e[2]=(n[2]*r+n[6]*s+n[10]*o+n[14])/i,e}function ve(e,t,n){let r=n[0],s=n[1],o=n[2],i=n[3],c=t[0],a=t[1],l=t[2],f=s*l-o*a,h=o*c-r*l,p=r*a-s*c,m=s*p-o*h,x=o*f-r*p,g=r*h-s*f,d=i*2;return f*=d,h*=d,p*=d,m*=2,x*=2,g*=2,e[0]=c+f+m,e[1]=a+h+x,e[2]=l+p+g,e}var Ie=_r;var uo=function(){let e=zt();return function(t,n,r,s,o,i){let c,a;for(n||(n=3),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],o(e,e,i),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2];return t}}();var ut,Y=class extends gt{static get ZERO(){return ut||(ut=new Y(0,0,0,0),Object.freeze(ut)),ut}constructor(t=0,n=0,r=0,s=0){super(-0,-0,-0,-0),G(t)&&arguments.length===1?this.copy(t):(L.debug&&(E(t),E(n),E(r),E(s)),this[0]=t,this[1]=n,this[2]=r,this[3]=s)}set(t,n,r,s){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}fromObject(t){return L.debug&&(E(t.x),E(t.y),E(t.z),E(t.w)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t.w=this[3],t}get ELEMENTS(){return 4}get z(){return this[2]}set z(t){this[2]=E(t)}get w(){return this[3]}set w(t){this[3]=E(t)}transform(t){return Mt(this,this,t),this.check()}transformByMatrix3(t){return Te(this,this,t),this.check()}transformByMatrix2(t){return Ee(this,this,t),this.check()}transformByQuaternion(t){return ve(this,this,t),this.check()}applyMatrix4(t){return t.transform(this,this),this}};var At=class extends D{toString(){let t="[";if(L.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+n]}`}else{t+="column-major:";for(let n=0;n<this.ELEMENTS;++n)t+=` ${this[n]}`}return t+="]",t}getElementIndex(t,n){return n*this.RANK+t}getElement(t,n){return this[n*this.RANK+t]}setElement(t,n,r){return this[n*this.RANK+t]=E(r),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)n[s]=this[r+s];return n}setColumn(t,n){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)this[r+s]=n[s];return this}};function be(){let e=new R(9);return R!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function Tr(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Ne(e,t){if(e===t){let n=t[1],r=t[2],s=t[3],o=t[6],i=t[7],c=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=o,e[11]=t[14],e[12]=s,e[13]=i,e[14]=c}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function we(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=t[4],c=t[5],a=t[6],l=t[7],f=t[8],h=t[9],p=t[10],m=t[11],x=t[12],g=t[13],d=t[14],_=t[15],T=n*c-r*i,M=n*a-s*i,u=n*l-o*i,A=r*a-s*c,S=r*l-o*c,v=s*l-o*a,I=f*g-h*x,b=f*d-p*x,N=f*_-m*x,w=h*d-p*g,O=h*_-m*g,P=p*_-m*d,y=T*P-M*O+u*w+A*N-S*b+v*I;return y?(y=1/y,e[0]=(c*P-a*O+l*w)*y,e[1]=(s*O-r*P-o*w)*y,e[2]=(g*v-d*S+_*A)*y,e[3]=(p*S-h*v-m*A)*y,e[4]=(a*N-i*P-l*b)*y,e[5]=(n*P-s*N+o*b)*y,e[6]=(d*u-x*v-_*M)*y,e[7]=(f*v-p*u+m*M)*y,e[8]=(i*O-c*N+l*I)*y,e[9]=(r*N-n*O-o*I)*y,e[10]=(x*S-g*u+_*T)*y,e[11]=(h*u-f*S-m*T)*y,e[12]=(c*b-i*w-a*I)*y,e[13]=(n*w-r*b+s*I)*y,e[14]=(g*M-x*A-d*T)*y,e[15]=(f*A-h*M+p*T)*y,e):null}function Oe(e){let t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],i=e[5],c=e[6],a=e[7],l=e[8],f=e[9],h=e[10],p=e[11],m=e[12],x=e[13],g=e[14],d=e[15],_=t*i-n*o,T=t*c-r*o,M=n*c-r*i,u=l*x-f*m,A=l*g-h*m,S=f*g-h*x,v=t*S-n*A+r*u,I=o*S-i*A+c*u,b=l*M-f*T+h*_,N=m*M-x*T+g*_;return a*v-s*I+d*b-p*N}function kt(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3],c=t[4],a=t[5],l=t[6],f=t[7],h=t[8],p=t[9],m=t[10],x=t[11],g=t[12],d=t[13],_=t[14],T=t[15],M=n[0],u=n[1],A=n[2],S=n[3];return e[0]=M*r+u*c+A*h+S*g,e[1]=M*s+u*a+A*p+S*d,e[2]=M*o+u*l+A*m+S*_,e[3]=M*i+u*f+A*x+S*T,M=n[4],u=n[5],A=n[6],S=n[7],e[4]=M*r+u*c+A*h+S*g,e[5]=M*s+u*a+A*p+S*d,e[6]=M*o+u*l+A*m+S*_,e[7]=M*i+u*f+A*x+S*T,M=n[8],u=n[9],A=n[10],S=n[11],e[8]=M*r+u*c+A*h+S*g,e[9]=M*s+u*a+A*p+S*d,e[10]=M*o+u*l+A*m+S*_,e[11]=M*i+u*f+A*x+S*T,M=n[12],u=n[13],A=n[14],S=n[15],e[12]=M*r+u*c+A*h+S*g,e[13]=M*s+u*a+A*p+S*d,e[14]=M*o+u*l+A*m+S*_,e[15]=M*i+u*f+A*x+S*T,e}function Pe(e,t,n){let r=n[0],s=n[1],o=n[2],i,c,a,l,f,h,p,m,x,g,d,_;return t===e?(e[12]=t[0]*r+t[4]*s+t[8]*o+t[12],e[13]=t[1]*r+t[5]*s+t[9]*o+t[13],e[14]=t[2]*r+t[6]*s+t[10]*o+t[14],e[15]=t[3]*r+t[7]*s+t[11]*o+t[15]):(i=t[0],c=t[1],a=t[2],l=t[3],f=t[4],h=t[5],p=t[6],m=t[7],x=t[8],g=t[9],d=t[10],_=t[11],e[0]=i,e[1]=c,e[2]=a,e[3]=l,e[4]=f,e[5]=h,e[6]=p,e[7]=m,e[8]=x,e[9]=g,e[10]=d,e[11]=_,e[12]=i*r+f*s+x*o+t[12],e[13]=c*r+h*s+g*o+t[13],e[14]=a*r+p*s+d*o+t[14],e[15]=l*r+m*s+_*o+t[15]),e}function Ce(e,t,n){let r=n[0],s=n[1],o=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*s,e[5]=t[5]*s,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Be(e,t,n,r){let s=r[0],o=r[1],i=r[2],c=Math.sqrt(s*s+o*o+i*i),a,l,f,h,p,m,x,g,d,_,T,M,u,A,S,v,I,b,N,w,O,P,y,X;return c<1e-6?null:(c=1/c,s*=c,o*=c,i*=c,l=Math.sin(n),a=Math.cos(n),f=1-a,h=t[0],p=t[1],m=t[2],x=t[3],g=t[4],d=t[5],_=t[6],T=t[7],M=t[8],u=t[9],A=t[10],S=t[11],v=s*s*f+a,I=o*s*f+i*l,b=i*s*f-o*l,N=s*o*f-i*l,w=o*o*f+a,O=i*o*f+s*l,P=s*i*f+o*l,y=o*i*f-s*l,X=i*i*f+a,e[0]=h*v+g*I+M*b,e[1]=p*v+d*I+u*b,e[2]=m*v+_*I+A*b,e[3]=x*v+T*I+S*b,e[4]=h*N+g*w+M*O,e[5]=p*N+d*w+u*O,e[6]=m*N+_*w+A*O,e[7]=x*N+T*w+S*O,e[8]=h*P+g*y+M*X,e[9]=p*P+d*y+u*X,e[10]=m*P+_*y+A*X,e[11]=x*P+T*y+S*X,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function ze(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[4],i=t[5],c=t[6],a=t[7],l=t[8],f=t[9],h=t[10],p=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=o*s+l*r,e[5]=i*s+f*r,e[6]=c*s+h*r,e[7]=a*s+p*r,e[8]=l*s-o*r,e[9]=f*s-i*r,e[10]=h*s-c*r,e[11]=p*s-a*r,e}function Fe(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[0],i=t[1],c=t[2],a=t[3],l=t[8],f=t[9],h=t[10],p=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*s-l*r,e[1]=i*s-f*r,e[2]=c*s-h*r,e[3]=a*s-p*r,e[8]=o*r+l*s,e[9]=i*r+f*s,e[10]=c*r+h*s,e[11]=a*r+p*s,e}function ke(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[0],i=t[1],c=t[2],a=t[3],l=t[4],f=t[5],h=t[6],p=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*s+l*r,e[1]=i*s+f*r,e[2]=c*s+h*r,e[3]=a*s+p*r,e[4]=l*s-o*r,e[5]=f*s-i*r,e[6]=h*s-c*r,e[7]=p*s-a*r,e}function De(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n+n,c=r+r,a=s+s,l=n*i,f=r*i,h=r*c,p=s*i,m=s*c,x=s*a,g=o*i,d=o*c,_=o*a;return e[0]=1-h-x,e[1]=f+_,e[2]=p-d,e[3]=0,e[4]=f-_,e[5]=1-l-x,e[6]=m+g,e[7]=0,e[8]=p+d,e[9]=m-g,e[10]=1-l-h,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Ue(e,t,n,r,s,o,i){let c=1/(n-t),a=1/(s-r),l=1/(o-i);return e[0]=o*2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o*2*a,e[6]=0,e[7]=0,e[8]=(n+t)*c,e[9]=(s+r)*a,e[10]=(i+o)*l,e[11]=-1,e[12]=0,e[13]=0,e[14]=i*o*2*l,e[15]=0,e}function Lr(e,t,n,r,s){let o=1/Math.tan(t/2);if(e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,s!=null&&s!==1/0){let i=1/(r-s);e[10]=(s+r)*i,e[14]=2*s*r*i}else e[10]=-1,e[14]=-2*r;return e}var Ve=Lr;function Rr(e,t,n,r,s,o,i){let c=1/(t-n),a=1/(r-s),l=1/(o-i);return e[0]=-2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*c,e[13]=(s+r)*a,e[14]=(i+o)*l,e[15]=1,e}var qe=Rr;function Ge(e,t,n,r){let s,o,i,c,a,l,f,h,p,m,x=t[0],g=t[1],d=t[2],_=r[0],T=r[1],M=r[2],u=n[0],A=n[1],S=n[2];return Math.abs(x-u)<1e-6&&Math.abs(g-A)<1e-6&&Math.abs(d-S)<1e-6?Tr(e):(h=x-u,p=g-A,m=d-S,s=1/Math.sqrt(h*h+p*p+m*m),h*=s,p*=s,m*=s,o=T*m-M*p,i=M*h-_*m,c=_*p-T*h,s=Math.sqrt(o*o+i*i+c*c),s?(s=1/s,o*=s,i*=s,c*=s):(o=0,i=0,c=0),a=p*c-m*i,l=m*o-h*c,f=h*i-p*o,s=Math.sqrt(a*a+l*l+f*f),s?(s=1/s,a*=s,l*=s,f*=s):(a=0,l=0,f=0),e[0]=o,e[1]=a,e[2]=h,e[3]=0,e[4]=i,e[5]=l,e[6]=p,e[7]=0,e[8]=c,e[9]=f,e[10]=m,e[11]=0,e[12]=-(o*x+i*g+c*d),e[13]=-(a*x+l*g+f*d),e[14]=-(h*x+p*g+m*d),e[15]=1,e)}function vr(){let e=new R(4);return R!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function He(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e}function Ye(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e}function We(e){let t=e[0],n=e[1],r=e[2],s=e[3];return Math.sqrt(t*t+n*n+r*r+s*s)}function $e(e){let t=e[0],n=e[1],r=e[2],s=e[3];return t*t+n*n+r*r+s*s}function Xe(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n*n+r*r+s*s+o*o;return i>0&&(i=1/Math.sqrt(i)),e[0]=n*i,e[1]=r*i,e[2]=s*i,e[3]=o*i,e}function je(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function Ke(e,t,n,r){let s=t[0],o=t[1],i=t[2],c=t[3];return e[0]=s+r*(n[0]-s),e[1]=o+r*(n[1]-o),e[2]=i+r*(n[2]-i),e[3]=c+r*(n[3]-c),e}function Qe(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3];return e[0]=n[0]*r+n[4]*s+n[8]*o+n[12]*i,e[1]=n[1]*r+n[5]*s+n[9]*o+n[13]*i,e[2]=n[2]*r+n[6]*s+n[10]*o+n[14]*i,e[3]=n[3]*r+n[7]*s+n[11]*o+n[15]*i,e}function Ze(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[0],c=n[1],a=n[2],l=n[3],f=l*r+c*o-a*s,h=l*s+a*r-i*o,p=l*o+i*s-c*r,m=-i*r-c*s-a*o;return e[0]=f*l+m*-i+h*-a-p*-c,e[1]=h*l+m*-c+p*-i-f*-a,e[2]=p*l+m*-a+f*-c-h*-i,e[3]=t[3],e}var No=function(){let e=vr();return function(t,n,r,s,o,i){let c,a;for(n||(n=4),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],e[3]=t[c+3],o(e,e,i),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2],t[c+3]=e[3];return t}}();var Vt;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(Vt||(Vt={}));var br=45*Math.PI/180,Nr=1,Dt=.1,Ut=500,wr=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),k=class extends At{static get IDENTITY(){return Pr()}static get ZERO(){return Or()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Vt}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,n,r,s,o,i,c,a,l,f,h,p,m,x,g,d){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this[4]=o,this[5]=i,this[6]=c,this[7]=a,this[8]=l,this[9]=f,this[10]=h,this[11]=p,this[12]=m,this[13]=x,this[14]=g,this[15]=d,this.check()}setRowMajor(t,n,r,s,o,i,c,a,l,f,h,p,m,x,g,d){return this[0]=t,this[1]=o,this[2]=l,this[3]=m,this[4]=n,this[5]=i,this[6]=f,this[7]=x,this[8]=r,this[9]=c,this[10]=h,this[11]=g,this[12]=s,this[13]=a,this[14]=p,this[15]=d,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(wr)}fromObject(t){return this.check()}fromQuaternion(t){return De(this,t),this.check()}frustum(t){let{left:n,right:r,bottom:s,top:o,near:i=Dt,far:c=Ut}=t;return c===1/0?Cr(this,n,r,s,o,i):Ue(this,n,r,s,o,i,c),this.check()}lookAt(t){let{eye:n,center:r=[0,0,0],up:s=[0,1,0]}=t;return Ge(this,n,r,s),this.check()}ortho(t){let{left:n,right:r,bottom:s,top:o,near:i=Dt,far:c=Ut}=t;return qe(this,n,r,s,o,i,c),this.check()}orthographic(t){let{fovy:n=br,aspect:r=Nr,focalDistance:s=1,near:o=Dt,far:i=Ut}=t;Je(n);let c=n/2,a=s*Math.tan(c),l=a*r;return this.ortho({left:-l,right:l,bottom:-a,top:a,near:o,far:i})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:r=1,near:s=.1,far:o=500}=t;return Je(n),Ve(this,n,r,s,o),this.check()}determinant(){return Oe(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),s=1/r[0],o=1/r[1],i=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*o,t[2]=this[2]*i,t[3]=0,t[4]=this[4]*s,t[5]=this[5]*o,t[6]=this[6]*i,t[7]=0,t[8]=this[8]*s,t[9]=this[9]*o,t[10]=this[10]*i,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),s=1/r[0],o=1/r[1],i=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*o,t[2]=this[2]*i,t[3]=this[4]*s,t[4]=this[5]*o,t[5]=this[6]*i,t[6]=this[8]*s,t[7]=this[9]*o,t[8]=this[10]*i,t}transpose(){return Ne(this,this),this.check()}invert(){return we(this,this),this.check()}multiplyLeft(t){return kt(this,t,this),this.check()}multiplyRight(t){return kt(this,this,t),this.check()}rotateX(t){return ze(this,this,t),this.check()}rotateY(t){return Fe(this,this,t),this.check()}rotateZ(t){return ke(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return Be(this,this,t,n),this.check()}scale(t){return Ce(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Pe(this,this,t),this.check()}transform(t,n){return t.length===4?(n=Qe(n||[-0,-0,-0,-0],t,this),H(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:r}=t,s;switch(r){case 2:s=Se(n||[-0,-0],t,this);break;case 3:s=Mt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return H(s,t.length),s}transformAsVector(t,n){let r;switch(t.length){case 2:r=_e(n||[-0,-0],t,this);break;case 3:r=ye(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return H(r,t.length),r}transformPoint(t,n){return this.transformAsPoint(t,n)}transformVector(t,n){return this.transformAsPoint(t,n)}transformDirection(t,n){return this.transformAsVector(t,n)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,n,r){return this.identity().translate([t,n,r])}},St,_t;function Or(){return St||(St=new k([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(St)),St}function Pr(){return _t||(_t=new k,Object.freeze(_t)),_t}function Je(e){if(e>Math.PI*2)throw Error("expected radians")}function Cr(e,t,n,r,s,o){let i=2*o/(n-t),c=2*o/(s-r),a=(n+t)/(n-t),l=(s+r)/(s-r),f=-1,h=-1,p=-2*o;return e[0]=i,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=c,e[6]=0,e[7]=0,e[8]=a,e[9]=l,e[10]=f,e[11]=h,e[12]=0,e[13]=0,e[14]=p,e[15]=0,e}function tn(){let e=new R(4);return R!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function en(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function qt(e,t,n){n=n*.5;let r=Math.sin(n);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(n),e}function Gt(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3],c=n[0],a=n[1],l=n[2],f=n[3];return e[0]=r*f+i*c+s*l-o*a,e[1]=s*f+i*a+o*c-r*l,e[2]=o*f+i*l+r*a-s*c,e[3]=i*f-r*c-s*a-o*l,e}function nn(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a+i*c,e[1]=s*a+o*c,e[2]=o*a-s*c,e[3]=i*a-r*c,e}function rn(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a-o*c,e[1]=s*a+i*c,e[2]=o*a+r*c,e[3]=i*a-s*c,e}function sn(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a+s*c,e[1]=s*a-r*c,e[2]=o*a+i*c,e[3]=i*a-o*c,e}function on(e,t){let n=t[0],r=t[1],s=t[2];return e[0]=n,e[1]=r,e[2]=s,e[3]=Math.sqrt(Math.abs(1-n*n-r*r-s*s)),e}function et(e,t,n,r){let s=t[0],o=t[1],i=t[2],c=t[3],a=n[0],l=n[1],f=n[2],h=n[3],p,m,x,g,d;return p=s*a+o*l+i*f+c*h,p<0&&(p=-p,a=-a,l=-l,f=-f,h=-h),1-p>1e-6?(m=Math.acos(p),d=Math.sin(m),x=Math.sin((1-r)*m)/d,g=Math.sin(r*m)/d):(x=1-r,g=r),e[0]=x*s+g*a,e[1]=x*o+g*l,e[2]=x*i+g*f,e[3]=x*c+g*h,e}function cn(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n*n+r*r+s*s+o*o,c=i?1/i:0;return e[0]=-n*c,e[1]=-r*c,e[2]=-s*c,e[3]=o*c,e}function an(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Ht(e,t){let n=t[0]+t[4]+t[8],r;if(n>0)r=Math.sqrt(n+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{let s=0;t[4]>t[0]&&(s=1),t[8]>t[s*3+s]&&(s=2);let o=(s+1)%3,i=(s+2)%3;r=Math.sqrt(t[s*3+s]-t[o*3+o]-t[i*3+i]+1),e[s]=.5*r,r=.5/r,e[3]=(t[o*3+i]-t[i*3+o])*r,e[o]=(t[o*3+s]+t[s*3+o])*r,e[i]=(t[i*3+s]+t[s*3+i])*r}return e}var ln=He;var fn=Ye,hn=je,pn=Ke,mn=We;var xn=$e;var gn=Xe;var dn=function(){let e=zt(),t=Ft(1,0,0),n=Ft(0,1,0);return function(r,s,o){let i=Re(s,o);return i<-.999999?(dt(e,t,s),Ie(e)<1e-6&&dt(e,n,s),Le(e,e),qt(r,e,Math.PI),r):i>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(dt(e,s,o),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+i,gn(r,r))}}(),Ho=function(){let e=tn(),t=tn();return function(n,r,s,o,i,c){return et(e,r,i,c),et(t,s,o,c),et(n,e,t,2*c*(1-c)),n}}(),Yo=function(){let e=be();return function(t,n,r,s){return e[0]=r[0],e[3]=r[1],e[6]=r[2],e[1]=s[0],e[4]=s[1],e[7]=s[2],e[2]=-n[0],e[5]=-n[1],e[8]=-n[2],gn(t,Ht(t,e))}}();var Br=[0,0,0,1],nt=class extends D{constructor(t=0,n=0,r=0,s=1){super(-0,-0,-0,-0),Array.isArray(t)&&arguments.length===1?this.copy(t):this.set(t,n,r,s)}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}set(t,n,r,s){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this.check()}fromObject(t){return this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this.check()}fromMatrix3(t){return Ht(this,t),this.check()}fromAxisRotation(t,n){return qt(this,t,n),this.check()}identity(){return en(this),this.check()}setAxisAngle(t,n){return this.fromAxisRotation(t,n)}get ELEMENTS(){return 4}get x(){return this[0]}set x(t){this[0]=E(t)}get y(){return this[1]}set y(t){this[1]=E(t)}get z(){return this[2]}set z(t){this[2]=E(t)}get w(){return this[3]}set w(t){this[3]=E(t)}len(){return mn(this)}lengthSquared(){return xn(this)}dot(t){return hn(this,t)}rotationTo(t,n){return dn(this,t,n),this.check()}add(t){return ln(this,this,t),this.check()}calculateW(){return on(this,this),this.check()}conjugate(){return an(this,this),this.check()}invert(){return cn(this,this),this.check()}lerp(t,n,r){return r===void 0?this.lerp(this,t,n):(pn(this,t,n,r),this.check())}multiplyRight(t){return Gt(this,this,t),this.check()}multiplyLeft(t){return Gt(this,t,this),this.check()}normalize(){let t=this.len(),n=t>0?1/t:0;return this[0]=this[0]*n,this[1]=this[1]*n,this[2]=this[2]*n,this[3]=this[3]*n,t===0&&(this[3]=1),this.check()}rotateX(t){return nn(this,this,t),this.check()}rotateY(t){return rn(this,this,t),this.check()}rotateZ(t){return sn(this,this,t),this.check()}scale(t){return fn(this,this,t),this.check()}slerp(t,n,r){let s,o,i;switch(arguments.length){case 1:({start:s=Br,target:o,ratio:i}=t);break;case 2:s=this,o=t,i=n;break;default:s=t,o=n,i=r}return et(this,s,o,i),this.check()}transformVector4(t,n=new Y){return Ze(n,t,this),H(n,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(t,n){return this.setAxisAngle(t,n)}premultiply(t){return this.multiplyLeft(t)}multiply(t){return this.multiplyRight(t)}};var Wt=U(j(),1);var zr={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Fr={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},$t=class{name;startTime=0;playing=!0;speed=1;channels=[];constructor(t){Object.assign(this,t)}animate(t){if(!this.playing)return;let r=(t/1e3-this.startTime)*this.speed;this.channels.forEach(({sampler:s,target:o,path:i})=>{Gr(r,s,o,i),Dr(o,o._node)})}},W=class{animations;constructor(t){this.animations=t.animations.map((n,r)=>{let s=n.name||`Animation-${r}`,o=n.samplers.map(({input:c,interpolation:a="LINEAR",output:l})=>({input:Mn(t.accessors[c]),interpolation:a,output:Mn(t.accessors[l])})),i=n.channels.map(({sampler:c,target:a})=>({sampler:o[c],target:t.nodes[a.node],path:a.path}));return new $t({name:s,channels:i})})}animate(t){this.setTime(t)}setTime(t){this.animations.forEach(n=>n.animate(t))}getAnimations(){return this.animations}};function Mn(e){if(!e._animation){let t=Fr[e.componentType],n=zr[e.type],r=n*e.count,{buffer:s,byteOffset:o}=e.bufferView.data,i=new t(s,o+(e.byteOffset||0),r);if(n===1)e._animation=Array.from(i);else{let c=[];for(let a=0;a<i.length;a+=n)c.push(Array.from(i.slice(a,a+n)));e._animation=c}}return e._animation}var kr=new k;function Dr(e,t){if(t.matrix.identity(),e.translation&&t.matrix.translate(e.translation),e.rotation){let n=kr.fromQuaternion(e.rotation);t.matrix.multiplyRight(n)}e.scale&&t.matrix.scale(e.scale)}var Yt=new nt;function Ur(e,t,n,r,s){if(t==="rotation"){Yt.slerp({start:n,target:r,ratio:s});for(let o=0;o<Yt.length;o++)e[t][o]=Yt[o]}else for(let o=0;o<n.length;o++)e[t][o]=s*r[o]+(1-s)*n[o]}function Vr(e,t,{p0:n,outTangent0:r,inTangent1:s,p1:o,tDiff:i,ratio:c}){for(let a=0;a<e[t].length;a++){let l=r[a]*i,f=s[a]*i;e[t][a]=(2*Math.pow(c,3)-3*Math.pow(c,2)+1)*n[a]+(Math.pow(c,3)-2*Math.pow(c,2)+c)*l+(-2*Math.pow(c,3)+3*Math.pow(c,2))*o[a]+(Math.pow(c,3)-Math.pow(c,2))*f}}function qr(e,t,n){for(let r=0;r<n.length;r++)e[t][r]=n[r]}function Gr(e,{input:t,interpolation:n,output:r},s,o){let i=t[t.length-1],c=e%i,a=t.findIndex(p=>p>=c),l=Math.max(0,a-1);if(!Array.isArray(s[o]))switch(o){case"translation":s[o]=[0,0,0];break;case"rotation":s[o]=[0,0,0,1];break;case"scale":s[o]=[1,1,1];break;default:Wt.log.warn(`Bad animation path ${o}`)()}let f=t[l],h=t[a];switch(n){case"STEP":qr(s,o,r[l]);break;case"LINEAR":if(h>f){let p=(c-f)/(h-f);Ur(s,o,r[l],r[a],p)}break;case"CUBICSPLINE":if(h>f){let p=(c-f)/(h-f),m=h-f,x=r[3*l+1],g=r[3*l+2],d=r[3*a+0],_=r[3*a+1];Vr(s,o,{p0:x,outTangent0:g,inTangent1:d,p1:_,tDiff:m,ratio:p})}break;default:Wt.log.warn(`Interpolation ${n} not supported`)();break}}var yn=U(j(),1);var Xt=`#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
8
-
9
- struct AmbientLight {
10
- vec3 color;
11
- };
12
-
13
- struct PointLight {
14
- vec3 color;
15
- vec3 position;
16
-
17
- // Constant-Linear-Exponential
18
- vec3 attenuation;
19
- };
20
-
21
- struct DirectionalLight {
22
- vec3 color;
23
- vec3 direction;
24
- };
25
-
26
- uniform AmbientLight lighting_uAmbientLight;
27
- uniform PointLight lighting_uPointLight[MAX_LIGHTS];
28
- uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
29
- uniform int lighting_uPointLightCount;
30
- uniform int lighting_uDirectionalLightCount;
31
-
32
- uniform bool lighting_uEnabled;
33
-
34
- float getPointLightAttenuation(PointLight pointLight, float distance) {
35
- return pointLight.attenuation.x
36
- + pointLight.attenuation.y * distance
37
- + pointLight.attenuation.z * distance * distance;
38
- }
39
-
40
- #endif
41
- `;var Hr={lightSources:{}};function jt(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(r=>r*n/255)}function Yr({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){let r={};return e?r["lighting_uAmbientLight.color"]=jt(e):r["lighting_uAmbientLight.color"]=[0,0,0],t.forEach((s,o)=>{r[`lighting_uPointLight[${o}].color`]=jt(s),r[`lighting_uPointLight[${o}].position`]=s.position,r[`lighting_uPointLight[${o}].attenuation`]=s.attenuation||[1,0,0]}),r.lighting_uPointLightCount=t.length,n.forEach((s,o)=>{r[`lighting_uDirectionalLight[${o}].color`]=jt(s),r[`lighting_uDirectionalLight[${o}].direction`]=s.direction}),r.lighting_uDirectionalLightCount=n.length,r}function un(e=Hr){if("lightSources"in e){let{ambientLight:t,pointLights:n,directionalLights:r}=e.lightSources||{};return t||n&&n.length>0||r&&r.length>0?Object.assign({},Yr({ambientLight:t,pointLights:n,directionalLights:r}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in e){let t={pointLights:[],directionalLights:[]};for(let n of e.lights||[])switch(n.type){case"ambient":t.ambientLight=n;break;case"directional":t.directionalLights?.push(n);break;case"point":t.pointLights?.push(n);break;default:}return un({lightSources:t})}return{}}var An={name:"lights",vs:Xt,fs:Xt,getUniforms:un,defines:{MAX_LIGHTS:3}};var Sn=`uniform mat4 u_MVPMatrix;
42
- uniform mat4 u_ModelMatrix;
43
- uniform mat4 u_NormalMatrix;
44
-
45
- out vec3 pbr_vPosition;
46
- out vec2 pbr_vUV;
47
-
48
- #ifdef HAS_NORMALS
49
- # ifdef HAS_TANGENTS
50
- out mat3 pbr_vTBN;
51
- # else
52
- out vec3 pbr_vNormal;
53
- # endif
54
- #endif
55
-
56
- void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
57
- {
58
- vec4 pos = u_ModelMatrix * position;
59
- pbr_vPosition = vec3(pos.xyz) / pos.w;
60
-
61
- #ifdef HAS_NORMALS
62
- #ifdef HAS_TANGENTS
63
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
64
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
65
- vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
66
- pbr_vTBN = mat3(tangentW, bitangentW, normalW);
67
- #else // HAS_TANGENTS != 1
68
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
69
- #endif
70
- #endif
71
-
72
- #ifdef HAS_UV
73
- pbr_vUV = uv;
74
- #else
75
- pbr_vUV = vec2(0.,0.);
76
- #endif
77
- }
78
- `;var _n=`precision highp float;
79
-
80
- uniform bool pbr_uUnlit;
81
-
82
- #ifdef USE_IBL
83
- uniform samplerCube u_DiffuseEnvSampler;
84
- uniform samplerCube u_SpecularEnvSampler;
85
- uniform sampler2D u_brdfLUT;
86
- uniform vec2 u_ScaleIBLAmbient;
87
- #endif
88
-
89
- #ifdef HAS_BASECOLORMAP
90
- uniform sampler2D u_BaseColorSampler;
91
- #endif
92
- #ifdef HAS_NORMALMAP
93
- uniform sampler2D u_NormalSampler;
94
- uniform float u_NormalScale;
95
- #endif
96
- #ifdef HAS_EMISSIVEMAP
97
- uniform sampler2D u_EmissiveSampler;
98
- uniform vec3 u_EmissiveFactor;
99
- #endif
100
- #ifdef HAS_METALROUGHNESSMAP
101
- uniform sampler2D u_MetallicRoughnessSampler;
102
- #endif
103
- #ifdef HAS_OCCLUSIONMAP
104
- uniform sampler2D u_OcclusionSampler;
105
- uniform float u_OcclusionStrength;
106
- #endif
107
-
108
- #ifdef ALPHA_CUTOFF
109
- uniform float u_AlphaCutoff;
110
- #endif
111
-
112
- uniform vec2 u_MetallicRoughnessValues;
113
- uniform vec4 u_BaseColorFactor;
114
-
115
- uniform vec3 u_Camera;
116
-
117
- // debugging flags used for shader output of intermediate PBR variables
118
- #ifdef PBR_DEBUG
119
- uniform vec4 u_ScaleDiffBaseMR;
120
- uniform vec4 u_ScaleFGDSpec;
121
- #endif
122
-
123
- in vec3 pbr_vPosition;
124
-
125
- in vec2 pbr_vUV;
126
-
127
- #ifdef HAS_NORMALS
128
- #ifdef HAS_TANGENTS
129
- in mat3 pbr_vTBN;
130
- #else
131
- in vec3 pbr_vNormal;
132
- #endif
133
- #endif
134
-
135
- // Encapsulate the various inputs used by the various functions in the shading equation
136
- // We store values in this struct to simplify the integration of alternative implementations
137
- // of the shading terms, outlined in the Readme.MD Appendix.
138
- struct PBRInfo
139
- {
140
- float NdotL; // cos angle between normal and light direction
141
- float NdotV; // cos angle between normal and view direction
142
- float NdotH; // cos angle between normal and half vector
143
- float LdotH; // cos angle between light direction and half vector
144
- float VdotH; // cos angle between view direction and half vector
145
- float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
146
- float metalness; // metallic value at the surface
147
- vec3 reflectance0; // full reflectance color (normal incidence angle)
148
- vec3 reflectance90; // reflectance color at grazing angle
149
- float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
150
- vec3 diffuseColor; // color contribution from diffuse lighting
151
- vec3 specularColor; // color contribution from specular lighting
152
- vec3 n; // normal at surface point
153
- vec3 v; // vector from surface point to camera
154
- };
155
-
156
- const float M_PI = 3.141592653589793;
157
- const float c_MinRoughness = 0.04;
158
-
159
- vec4 SRGBtoLINEAR(vec4 srgbIn)
160
- {
161
- #ifdef MANUAL_SRGB
162
- #ifdef SRGB_FAST_APPROXIMATION
163
- vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
164
- #else //SRGB_FAST_APPROXIMATION
165
- vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
166
- vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
167
- #endif //SRGB_FAST_APPROXIMATION
168
- return vec4(linOut,srgbIn.w);;
169
- #else //MANUAL_SRGB
170
- return srgbIn;
171
- #endif //MANUAL_SRGB
172
- }
173
-
174
- // Find the normal for this fragment, pulling either from a predefined normal map
175
- // or from the interpolated mesh normal and tangent attributes.
176
- vec3 getNormal()
177
- {
178
- // Retrieve the tangent space matrix
179
- #ifndef HAS_TANGENTS
180
- vec3 pos_dx = dFdx(pbr_vPosition);
181
- vec3 pos_dy = dFdy(pbr_vPosition);
182
- vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
183
- vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
184
- vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
185
-
186
- #ifdef HAS_NORMALS
187
- vec3 ng = normalize(pbr_vNormal);
188
- #else
189
- vec3 ng = cross(pos_dx, pos_dy);
190
- #endif
191
-
192
- t = normalize(t - ng * dot(ng, t));
193
- vec3 b = normalize(cross(ng, t));
194
- mat3 tbn = mat3(t, b, ng);
195
- #else // HAS_TANGENTS
196
- mat3 tbn = pbr_vTBN;
197
- #endif
198
-
199
- #ifdef HAS_NORMALMAP
200
- vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
201
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
202
- #else
203
- // The tbn matrix is linearly interpolated, so we need to re-normalize
204
- vec3 n = normalize(tbn[2].xyz);
205
- #endif
206
-
207
- return n;
208
- }
209
-
210
- // Calculation of the lighting contribution from an optional Image Based Light source.
211
- // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
212
- // See our README.md on Environment Maps [3] for additional discussion.
213
- #ifdef USE_IBL
214
- vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
215
- {
216
- float mipCount = 9.0; // resolution of 512x512
217
- float lod = (pbrInputs.perceptualRoughness * mipCount);
218
- // retrieve a scale and bias to F0. See [1], Figure 3
219
- vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
220
- vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
221
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
222
-
223
- #ifdef USE_TEX_LOD
224
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
225
- #else
226
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
227
- #endif
228
-
229
- vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
230
- vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
231
-
232
- // For presentation, this allows us to disable IBL terms
233
- diffuse *= u_ScaleIBLAmbient.x;
234
- specular *= u_ScaleIBLAmbient.y;
235
-
236
- return diffuse + specular;
237
- }
238
- #endif
239
-
240
- // Basic Lambertian diffuse
241
- // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
242
- // See also [1], Equation 1
243
- vec3 diffuse(PBRInfo pbrInputs)
244
- {
245
- return pbrInputs.diffuseColor / M_PI;
246
- }
247
-
248
- // The following equation models the Fresnel reflectance term of the spec equation (aka F())
249
- // Implementation of fresnel from [4], Equation 15
250
- vec3 specularReflection(PBRInfo pbrInputs)
251
- {
252
- return pbrInputs.reflectance0 +
253
- (pbrInputs.reflectance90 - pbrInputs.reflectance0) *
254
- pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
255
- }
256
-
257
- // This calculates the specular geometric attenuation (aka G()),
258
- // where rougher material will reflect less light back to the viewer.
259
- // This implementation is based on [1] Equation 4, and we adopt their modifications to
260
- // alphaRoughness as input as originally proposed in [2].
261
- float geometricOcclusion(PBRInfo pbrInputs)
262
- {
263
- float NdotL = pbrInputs.NdotL;
264
- float NdotV = pbrInputs.NdotV;
265
- float r = pbrInputs.alphaRoughness;
266
-
267
- float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
268
- float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
269
- return attenuationL * attenuationV;
270
- }
271
-
272
- // The following equation(s) model the distribution of microfacet normals across
273
- // the area being drawn (aka D())
274
- // Implementation from "Average Irregularity Representation of a Roughened Surface
275
- // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
276
- // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
277
- // from EPIC Games [1], Equation 3.
278
- float microfacetDistribution(PBRInfo pbrInputs)
279
- {
280
- float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
281
- float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
282
- return roughnessSq / (M_PI * f * f);
283
- }
284
-
285
- void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
286
- pbrInputs.NdotL = 1.0;
287
- pbrInputs.NdotH = 0.0;
288
- pbrInputs.LdotH = 0.0;
289
- pbrInputs.VdotH = 1.0;
290
- }
291
-
292
- void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
293
- vec3 n = pbrInputs.n;
294
- vec3 v = pbrInputs.v;
295
- vec3 l = normalize(lightDirection); // Vector from surface point to light
296
- vec3 h = normalize(l+v); // Half vector between both l and v
297
-
298
- pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
299
- pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
300
- pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
301
- pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
302
- }
303
-
304
- void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
305
- vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
306
- PBRInfo_setDirectionalLight(pbrInputs, light_direction);
307
- }
308
-
309
- vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
310
- // Calculate the shading terms for the microfacet specular shading model
311
- vec3 F = specularReflection(pbrInputs);
312
- float G = geometricOcclusion(pbrInputs);
313
- float D = microfacetDistribution(pbrInputs);
314
-
315
- // Calculation of analytical lighting contribution
316
- vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
317
- vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
318
- // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
319
- return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
320
- }
321
-
322
- vec4 pbr_filterColor(vec4 colorUnused)
323
- {
324
- // The albedo may be defined from a base texture or a flat color
325
- #ifdef HAS_BASECOLORMAP
326
- vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
327
- #else
328
- vec4 baseColor = u_BaseColorFactor;
329
- #endif
330
-
331
- #ifdef ALPHA_CUTOFF
332
- if (baseColor.a < u_AlphaCutoff) {
333
- discard;
334
- }
335
- #endif
336
-
337
- vec3 color = vec3(0, 0, 0);
338
-
339
- if(pbr_uUnlit){
340
- color.rgb = baseColor.rgb;
341
- }
342
- else{
343
- // Metallic and Roughness material properties are packed together
344
- // In glTF, these factors can be specified by fixed scalar values
345
- // or from a metallic-roughness map
346
- float perceptualRoughness = u_MetallicRoughnessValues.y;
347
- float metallic = u_MetallicRoughnessValues.x;
348
- #ifdef HAS_METALROUGHNESSMAP
349
- // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
350
- // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
351
- vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
352
- perceptualRoughness = mrSample.g * perceptualRoughness;
353
- metallic = mrSample.b * metallic;
354
- #endif
355
- perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
356
- metallic = clamp(metallic, 0.0, 1.0);
357
- // Roughness is authored as perceptual roughness; as is convention,
358
- // convert to material roughness by squaring the perceptual roughness [2].
359
- float alphaRoughness = perceptualRoughness * perceptualRoughness;
360
-
361
- vec3 f0 = vec3(0.04);
362
- vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
363
- diffuseColor *= 1.0 - metallic;
364
- vec3 specularColor = mix(f0, baseColor.rgb, metallic);
365
-
366
- // Compute reflectance.
367
- float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
368
-
369
- // For typical incident reflectance range (between 4% to 100%) set the grazing
370
- // reflectance to 100% for typical fresnel effect.
371
- // For very low reflectance range on highly diffuse objects (below 4%),
372
- // incrementally reduce grazing reflecance to 0%.
373
- float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
374
- vec3 specularEnvironmentR0 = specularColor.rgb;
375
- vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
376
-
377
- vec3 n = getNormal(); // normal at surface point
378
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
379
-
380
- float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
381
- vec3 reflection = -normalize(reflect(v, n));
382
-
383
- PBRInfo pbrInputs = PBRInfo(
384
- 0.0, // NdotL
385
- NdotV,
386
- 0.0, // NdotH
387
- 0.0, // LdotH
388
- 0.0, // VdotH
389
- perceptualRoughness,
390
- metallic,
391
- specularEnvironmentR0,
392
- specularEnvironmentR90,
393
- alphaRoughness,
394
- diffuseColor,
395
- specularColor,
396
- n,
397
- v
398
- );
399
-
400
- #ifdef USE_LIGHTS
401
- // Apply ambient light
402
- PBRInfo_setAmbientLight(pbrInputs);
403
- color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
404
-
405
- // Apply directional light
406
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
407
- if (i < lighting_uDirectionalLightCount) {
408
- PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
409
- color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
410
- }
411
- }
412
-
413
- // Apply point light
414
- for(int i = 0; i < lighting_uPointLightCount; i++) {
415
- if (i < lighting_uPointLightCount) {
416
- PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
417
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
418
- color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
419
- }
420
- }
421
- #endif
422
-
423
- // Calculate lighting contribution from image based lighting source (IBL)
424
- #ifdef USE_IBL
425
- color += getIBLContribution(pbrInputs, n, reflection);
426
- #endif
427
-
428
- // Apply optional PBR terms for additional (optional) shading
429
- #ifdef HAS_OCCLUSIONMAP
430
- float ao = texture(u_OcclusionSampler, pbr_vUV).r;
431
- color = mix(color, color * ao, u_OcclusionStrength);
432
- #endif
433
-
434
- #ifdef HAS_EMISSIVEMAP
435
- vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
436
- color += emissive;
437
- #endif
438
-
439
- // This section uses mix to override final color for reference app visualization
440
- // of various parameters in the lighting equation.
441
- #ifdef PBR_DEBUG
442
- // TODO: Figure out how to debug multiple lights
443
-
444
- // color = mix(color, F, u_ScaleFGDSpec.x);
445
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
446
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
447
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
448
-
449
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
450
- color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
451
- color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
452
- color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
453
- #endif
454
-
455
- }
456
-
457
- return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
458
- }
459
- `;var Kt={name:"pbr",vs:Sn,fs:_n,defines:{LIGHTING_FRAGMENT:1},dependencies:[An],getUniforms:e=>e};var yt=U(at(),1);var Wr=`
7
+ var __exports__=(()=>{var Se=Object.create;var it=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var Ot=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),Le=(n,t)=>{for(var e in t)it(n,e,{get:t[e],enumerable:!0})},st=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oe(t))!Ne.call(n,s)&&s!==e&&it(n,s,{get:()=>t[s],enumerable:!(r=we(t,s))||r.enumerable});return n},ct=(n,t,e)=>(st(n,t,"default"),e&&st(e,t,"default")),B=(n,t,e)=>(e=n!=null?Se(Re(n)):{},st(t||!n||!n.__esModule?it(e,"default",{value:n,enumerable:!0}):e,n)),_e=n=>st(it({},"__esModule",{value:!0}),n);var j=Ot((Wr,jt)=>{jt.exports=globalThis.luma});var at=Ot((Hr,Qt)=>{Qt.exports=globalThis.luma});var ge=Ot((Qi,Me)=>{Me.exports=globalThis.luma});var rt={};Le(rt,{GLTFAnimator:()=>G,createScenegraphsFromGLTF:()=>Ee,loadPBREnvironment:()=>mn,parsePBRMaterial:()=>ot});ct(rt,B(j(),1));var Kt=B(j(),1),z;(function(n){n[n.FUNC_ADD=32774]="FUNC_ADD",n[n.ONE=1]="ONE",n[n.SRC_ALPHA=770]="SRC_ALPHA",n[n.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",n[n.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",n[n.LINEAR=9729]="LINEAR",n[n.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",n[n.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL"})(z||(z={}));function ot(n,t,e,r){let s={defines:{MANUAL_SRGB:1,SRGB_FAST_APPROXIMATION:1},bindings:{},uniforms:{u_Camera:[0,0,0],u_MetallicRoughnessValues:[1,1]},parameters:{},glParameters:{},generatedTextures:[]};s.defines.USE_TEX_LOD=1;let{imageBasedLightingEnvironment:i}=r;return i&&(s.bindings.u_DiffuseEnvSampler=i.diffuseEnvSampler.texture,s.bindings.u_SpecularEnvSampler=i.specularEnvSampler.texture,s.bindings.u_brdfLUT=i.brdfLutTexture.texture,s.uniforms.u_ScaleIBLAmbient=[1,1]),r?.pbrDebug&&(s.defines.PBR_DEBUG=1,s.uniforms.u_ScaleDiffBaseMR=[0,0,0,0],s.uniforms.u_ScaleFGDSpec=[0,0,0,0]),e.NORMAL&&(s.defines.HAS_NORMALS=1),e.TANGENT&&r?.useTangents&&(s.defines.HAS_TANGENTS=1),e.TEXCOORD_0&&(s.defines.HAS_UV=1),r?.imageBasedLightingEnvironment&&(s.defines.USE_IBL=1),r?.lights&&(s.defines.USE_LIGHTS=1),t&&Ie(n,t,s),s}function Ie(n,t,e){if(e.uniforms.pbr_uUnlit=Boolean(t.unlit),t.pbrMetallicRoughness&&Pe(n,t.pbrMetallicRoughness,e),t.normalTexture){K(n,t.normalTexture,"u_NormalSampler","HAS_NORMALMAP",e);let{scale:r=1}=t.normalTexture;e.uniforms.u_NormalScale=r}if(t.occlusionTexture){K(n,t.occlusionTexture,"u_OcclusionSampler","HAS_OCCLUSIONMAP",e);let{strength:r=1}=t.occlusionTexture;e.uniforms.u_OcclusionStrength=r}switch(t.emissiveTexture&&(K(n,t.emissiveTexture,"u_EmissiveSampler","HAS_EMISSIVEMAP",e),e.uniforms.u_EmissiveFactor=t.emissiveFactor||[0,0,0]),t.alphaMode){case"MASK":let{alphaCutoff:r=.5}=t;e.defines.ALPHA_CUTOFF=1,e.uniforms.u_AlphaCutoff=r;break;case"BLEND":Kt.log.warn("glTF BLEND alphaMode might not work well because it requires mesh sorting")(),e.parameters.blendColorOperation="add",e.parameters.blendColorSrcFactor="src-alpha",e.parameters.blendColorDstFactor="one-minus-src-alpha",e.parameters.blendAlphaOperation="add",e.parameters.blendAlphaSrcFactor="one",e.parameters.blendAlphaDstFactor="one-minus-src-alpha",e.glParameters.blend=!0,e.glParameters.blendEquation=z.FUNC_ADD,e.glParameters.blendFunc=[z.SRC_ALPHA,z.ONE_MINUS_SRC_ALPHA,z.ONE,z.ONE_MINUS_SRC_ALPHA];break}}function Pe(n,t,e){t.baseColorTexture&&K(n,t.baseColorTexture,"u_BaseColorSampler","HAS_BASECOLORMAP",e),e.uniforms.u_BaseColorFactor=t.baseColorFactor||[1,1,1,1],t.metallicRoughnessTexture&&K(n,t.metallicRoughnessTexture,"u_MetallicRoughnessSampler","HAS_METALROUGHNESSMAP",e);let{metallicFactor:r=1,roughnessFactor:s=1}=t;e.uniforms.u_MetallicRoughnessValues=[r,s]}function K(n,t,e,r=null,s){let i=t?.texture?.sampler?.parameters||{},c=t.texture.source.image,o,a={};c.compressed?(o=c,a={[z.TEXTURE_MIN_FILTER]:c.data.length>1?z.LINEAR_MIPMAP_NEAREST:z.LINEAR}):o={data:c};let h=n.createTexture({id:t.uniformName||t.id,parameters:{...i,...a},pixelStore:{[z.UNPACK_FLIP_Y_WEBGL]:!1},...o});s.bindings[e]=h,r&&(s.defines[r]=1),s.generatedTextures.push(h)}var zt=B(at(),1);function V(n,t){if(!n)throw new Error(t||"loader assertion failed.")}var b={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},ve=b.self||b.window||b.global||{},ue=b.window||b.self||b.global||{},ke=b.global||b.self||b.window||{},ze=b.document||{};var Rt=Boolean(typeof process!="object"||String(process)!=="[object process]"||process.browser);var Zt=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),be=Zt&&parseFloat(Zt[1])||0;var qe="",Jt={};function Nt(n){for(let t in Jt)if(n.startsWith(t)){let e=Jt[t];n=n.replace(t,e)}return!n.startsWith("http://")&&!n.startsWith("https://")&&(n=`${qe}${n}`),n}var tn="4.2.1";var Fe=globalThis.loaders?.parseImageNode,Lt=typeof Image<"u",_t=typeof ImageBitmap<"u",Ce=Boolean(Fe),It=Rt?!0:Ce;function nn(n){switch(n){case"auto":return _t||Lt||It;case"imagebitmap":return _t;case"image":return Lt;case"data":return It;default:throw new Error(`@loaders.gl/images: image ${n} not supported in this environment`)}}function en(){if(_t)return"imagebitmap";if(Lt)return"image";if(It)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}function rn(n){let t=Be(n);if(!t)throw new Error("Not an image");return t}function Pt(n){return ht(n)}function ht(n){switch(rn(n)){case"data":return n;case"image":case"imagebitmap":let t=document.createElement("canvas"),e=t.getContext("2d");if(!e)throw new Error("getImageData");return t.width=n.width,t.height=n.height,e.drawImage(n,0,0),e.getImageData(0,0,n.width,n.height);default:throw new Error("getImageData")}}function Be(n){return typeof ImageBitmap<"u"&&n instanceof ImageBitmap?"imagebitmap":typeof Image<"u"&&n instanceof Image?"image":n&&typeof n=="object"&&n.data&&n.width&&n.height?"data":null}var Ue=/^data:image\/svg\+xml/,Ve=/\.svg((\?|#).*)?$/;function ft(n){return n&&(Ue.test(n)||Ve.test(n))}function sn(n,t){if(ft(t)){let r=new TextDecoder().decode(n);try{typeof unescape=="function"&&typeof encodeURIComponent=="function"&&(r=unescape(encodeURIComponent(r)))}catch(i){throw new Error(i.message)}return`data:image/svg+xml;base64,${btoa(r)}`}return vt(n,t)}function vt(n,t){if(ft(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(n)])}async function lt(n,t,e){let r=sn(n,e),s=self.URL||self.webkitURL,i=typeof r!="string"&&s.createObjectURL(r);try{return await De(i||r,t)}finally{i&&s.revokeObjectURL(i)}}async function De(n,t){let e=new Image;return e.src=n,t.image&&t.image.decode&&e.decode?(await e.decode(),e):await new Promise((r,s)=>{try{e.onload=()=>r(e),e.onerror=i=>{let c=i instanceof Error?i.message:"error";s(new Error(c))}}catch(i){s(i)}})}var Ye={},cn=!0;async function on(n,t,e){let r;ft(e)?r=await lt(n,t,e):r=vt(n,e);let s=t&&t.imagebitmap;return await $e(r,s)}async function $e(n,t=null){if((We(t)||!cn)&&(t=null),t)try{return await createImageBitmap(n,t)}catch(e){console.warn(e),cn=!1}return await createImageBitmap(n)}function We(n){for(let t in n||Ye)return!1;return!0}function an(n){return!je(n,"ftyp",4)||!(n[8]&96)?null:Ge(n)}function Ge(n){switch(He(n,8,12).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}}function He(n,t,e){return String.fromCharCode(...n.slice(t,e))}function Xe(n){return[...n].map(t=>t.charCodeAt(0))}function je(n,t,e=0){let r=Xe(t);for(let s=0;s<r.length;++s)if(r[s]!==n[s+e])return!1;return!0}var q=!1,Q=!0;function pt(n){let t=Z(n);return Qe(t)||tr(t)||Ze(t)||Je(t)||Ke(t)}function Ke(n){let t=new Uint8Array(n instanceof DataView?n.buffer:n),e=an(t);return e?{mimeType:e.mimeType,width:0,height:0}:null}function Qe(n){let t=Z(n);return t.byteLength>=24&&t.getUint32(0,q)===2303741511?{mimeType:"image/png",width:t.getUint32(16,q),height:t.getUint32(20,q)}:null}function Ze(n){let t=Z(n);return t.byteLength>=10&&t.getUint32(0,q)===1195984440?{mimeType:"image/gif",width:t.getUint16(6,Q),height:t.getUint16(8,Q)}:null}function Je(n){let t=Z(n);return t.byteLength>=14&&t.getUint16(0,q)===16973&&t.getUint32(2,Q)===t.byteLength?{mimeType:"image/bmp",width:t.getUint32(18,Q),height:t.getUint32(22,Q)}:null}function tr(n){let t=Z(n);if(!(t.byteLength>=3&&t.getUint16(0,q)===65496&&t.getUint8(2)===255))return null;let{tableMarkers:r,sofMarkers:s}=nr(),i=2;for(;i+9<t.byteLength;){let c=t.getUint16(i,q);if(s.has(c))return{mimeType:"image/jpeg",height:t.getUint16(i+5,q),width:t.getUint16(i+7,q)};if(!r.has(c))return null;i+=2,i+=t.getUint16(i,q)}return null}function nr(){let n=new Set([65499,65476,65484,65501,65534]);for(let e=65504;e<65520;++e)n.add(e);return{tableMarkers:n,sofMarkers:new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502])}}function Z(n){if(n instanceof DataView)return n;if(ArrayBuffer.isView(n))return new DataView(n.buffer);if(n instanceof ArrayBuffer)return new DataView(n);throw new Error("toDataView")}async function hn(n,t){let{mimeType:e}=pt(n)||{},r=globalThis.loaders?.parseImageNode;return V(r),await r(n,e)}async function fn(n,t,e){t=t||{};let s=(t.image||{}).type||"auto",{url:i}=e||{},c=er(s),o;switch(c){case"imagebitmap":o=await on(n,t,i);break;case"image":o=await lt(n,t,i);break;case"data":o=await hn(n,t);break;default:V(!1)}return s==="data"&&(o=ht(o)),o}function er(n){switch(n){case"auto":case"data":return en();default:return nn(n),n}}var rr=["png","jpg","jpeg","gif","webp","bmp","ico","svg","avif"],sr=["image/png","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],ir={image:{type:"auto",decode:!0}},xt={dataType:null,batchType:null,id:"image",module:"images",name:"Images",version:tn,mimeTypes:sr,extensions:rr,parse:fn,tests:[n=>Boolean(pt(new DataView(n)))],options:ir};function mt(n,t,e){let r=typeof n=="function"?n({...t,...e}):n,s=t.baseUrl;return s&&(r=s[s.length-1]==="/"?`${s}${r}`:`${s}/${r}`),Nt(r)}var cr=n=>n&&typeof n=="object";async function ln(n,t,e={}){return await ut(n,t,e)}async function ut(n,t,e){return Array.isArray(n)?await ar(n,t,e):cr(n)?await or(n,t,e):await t(n,e)}async function or(n,t,e){let r=[],s={};for(let i in n){let c=n[i],o=ut(c,t,e).then(a=>{s[i]=a});r.push(o)}return await Promise.all(r),s}async function ar(n,t,e={}){let r=n.map(s=>ut(s,t,e));return await Promise.all(r)}async function pn(n,t,e){return await ln(n,r=>kt(r,t,e))}async function kt(n,t,e){let s=await(await fetch(n,e.fetch)).arrayBuffer();return await t(s,e)}async function J(n,t={}){let e=await hr(n,t);return await pn(e,xt.parse,t)}async function hr(n,t,e={}){let r=t&&t.image&&t.image.mipLevels||0;return r!==0?await fr(n,r,t,e):mt(n,t,e)}async function fr(n,t,e,r){let s=[];if(t==="auto"){let i=mt(n,e,{...r,lod:0}),c=await kt(i,xt.parse,e),{width:o,height:a}=Pt(c);t=lr({width:o,height:a}),s.push(i)}V(t>0);for(let i=s.length;i<t;++i){let c=mt(n,e,{...r,lod:i});s.push(c)}return s}function lr(n){return 1+Math.floor(Math.log2(Math.max(n.width,n.height)))}function mn(n,t){let e=new zt.AsyncTexture(n,{id:"brdfLUT",sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"},data:J(t.brdfLutUrl)}),r=xn(n,{id:"DiffuseEnvSampler",getTextureForFace:i=>J(t.getTexUrl("diffuse",i,0)),sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}}),s=xn(n,{id:"SpecularEnvSampler",getTextureForFace:i=>{let c=[];for(let o=0;o<=t.specularMipLevels-1;o++)c.push(J(t.getTexUrl("specular",i,o)));return c},sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}});return{brdfLutTexture:e,diffuseEnvSampler:r,specularEnvSampler:s}}var pr=[0,1,2,3,4,5];function xn(n,{id:t,getTextureForFace:e,sampler:r}){let s={};return pr.forEach(i=>{s[String(i)]=e(i)}),new zt.AsyncTexture(n,{id:t,dimension:"cube",mipmaps:!1,sampler:r,data:s})}var H=B(at(),1);var js=1/Math.PI*180,Ks=1/180*Math.PI,xr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...xr}};var R=globalThis.mathgl.config;function Mn(n,{precision:t=R.precision}={}){return n=mr(n),`${parseFloat(n.toPrecision(t))}`}function Y(n){return Array.isArray(n)||ArrayBuffer.isView(n)&&!(n instanceof DataView)}function bt(n,t,e){let r=R.EPSILON;e&&(R.EPSILON=e);try{if(n===t)return!0;if(Y(n)&&Y(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;++s)if(!bt(n[s],t[s]))return!1;return!0}return n&&n.equals?n.equals(t):t&&t.equals?t.equals(n):typeof n=="number"&&typeof t=="number"?Math.abs(n-t)<=R.EPSILON*Math.max(1,Math.abs(n),Math.abs(t)):!1}finally{R.EPSILON=r}}function mr(n){return Math.round(n/R.EPSILON)*R.EPSILON}var U=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+e];return this.check()}toArray(t=[],e=0){for(let r=0;r<this.ELEMENTS;++r)t[e+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:Y(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(R)}formatString(t){let e="";for(let r=0;r<this.ELEMENTS;++r)e+=(r>0?", ":"")+Mn(this[r],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!bt(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,r){if(r===void 0)return this.lerp(this,t,e);for(let s=0;s<this.ELEMENTS;++s){let i=t[s],c=typeof e=="number"?e:e[s];this[s]=i+r*(c-i)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),e[r]);return this.check()}add(...t){for(let e of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=e[r];return this.check()}subtract(...t){for(let e of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=e[r];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if(R.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),e);return this.check()}get elements(){return this}};function Mr(n,t){if(n.length!==t)return!1;for(let e=0;e<n.length;++e)if(!Number.isFinite(n[e]))return!1;return!0}function w(n){if(!Number.isFinite(n))throw new Error(`Invalid number ${JSON.stringify(n)}`);return n}function $(n,t,e=""){if(R.debug&&!Mr(n,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return n}function qt(n,t){if(!n)throw new Error(`math.gl assertion ${t}`)}var Mt=class extends U{get x(){return this[0]}set x(t){this[0]=w(t)}get y(){return this[1]}set y(t){this[1]=w(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let r=0;r<this.ELEMENTS;++r){let s=this[r]-t[r];e+=s*s}return w(e)}dot(t){let e=0;for(let r=0;r<this.ELEMENTS;++r)e+=this[r]*t[r];return w(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let r=0;r<this.ELEMENTS;++r)this[r]*=e[r];return this.check()}divide(...t){for(let e of t)for(let r=0;r<this.ELEMENTS;++r)this[r]/=e[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return qt(t>=0&&t<this.ELEMENTS,"index is out of range"),w(this[t])}setComponent(t,e){return qt(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=e,this.check()}addVectors(t,e){return this.copy(t).add(e)}subVectors(t,e){return this.copy(t).subtract(e)}multiplyVectors(t,e){return this.copy(t).multiply(e)}addScaledVector(t,e){return this.add(new this.constructor(t).multiplyScalar(e))}};var N=typeof Float32Array<"u"?Float32Array:Array;var oi=Math.PI/180;function gr(){let n=new N(2);return N!=Float32Array&&(n[0]=0,n[1]=0),n}function yn(n,t,e){let r=t[0],s=t[1];return n[0]=e[0]*r+e[4]*s+e[12],n[1]=e[1]*r+e[5]*s+e[13],n}var ai=function(){let n=gr();return function(t,e,r,s,i,c){let o,a;for(e||(e=2),r||(r=0),s?a=Math.min(s*e+r,t.length):a=t.length,o=r;o<a;o+=e)n[0]=t[o],n[1]=t[o+1],i(n,n,c),t[o]=n[0],t[o+1]=n[1];return t}}();function An(n,t,e){let r=t[0],s=t[1],i=e[3]*r+e[7]*s||1;return n[0]=(e[0]*r+e[4]*s)/i,n[1]=(e[1]*r+e[5]*s)/i,n}function Tn(n,t,e){let r=t[0],s=t[1],i=t[2],c=e[3]*r+e[7]*s+e[11]*i||1;return n[0]=(e[0]*r+e[4]*s+e[8]*i)/c,n[1]=(e[1]*r+e[5]*s+e[9]*i)/c,n[2]=(e[2]*r+e[6]*s+e[10]*i)/c,n}function En(n,t,e){let r=t[0],s=t[1];return n[0]=e[0]*r+e[2]*s,n[1]=e[1]*r+e[3]*s,n[2]=t[2],n[3]=t[3],n}function Sn(n,t,e){let r=t[0],s=t[1],i=t[2];return n[0]=e[0]*r+e[3]*s+e[6]*i,n[1]=e[1]*r+e[4]*s+e[7]*i,n[2]=e[2]*r+e[5]*s+e[8]*i,n[3]=t[3],n}function Ft(){let n=new N(3);return N!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n}function dr(n){let t=n[0],e=n[1],r=n[2];return Math.sqrt(t*t+e*e+r*r)}function Ct(n,t,e){let r=new N(3);return r[0]=n,r[1]=t,r[2]=e,r}function wn(n,t){let e=t[0],r=t[1],s=t[2],i=e*e+r*r+s*s;return i>0&&(i=1/Math.sqrt(i)),n[0]=t[0]*i,n[1]=t[1]*i,n[2]=t[2]*i,n}function On(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]}function gt(n,t,e){let r=t[0],s=t[1],i=t[2],c=e[0],o=e[1],a=e[2];return n[0]=s*a-i*o,n[1]=i*c-r*a,n[2]=r*o-s*c,n}function dt(n,t,e){let r=t[0],s=t[1],i=t[2],c=e[3]*r+e[7]*s+e[11]*i+e[15];return c=c||1,n[0]=(e[0]*r+e[4]*s+e[8]*i+e[12])/c,n[1]=(e[1]*r+e[5]*s+e[9]*i+e[13])/c,n[2]=(e[2]*r+e[6]*s+e[10]*i+e[14])/c,n}function Rn(n,t,e){let r=e[0],s=e[1],i=e[2],c=e[3],o=t[0],a=t[1],h=t[2],f=s*h-i*a,l=i*o-r*h,p=r*a-s*o,x=s*p-i*l,m=i*f-r*p,M=r*l-s*f,g=c*2;return f*=g,l*=g,p*=g,x*=2,m*=2,M*=2,n[0]=o+f+x,n[1]=a+l+m,n[2]=h+p+M,n}var Nn=dr;var li=function(){let n=Ft();return function(t,e,r,s,i,c){let o,a;for(e||(e=3),r||(r=0),s?a=Math.min(s*e+r,t.length):a=t.length,o=r;o<a;o+=e)n[0]=t[o],n[1]=t[o+1],n[2]=t[o+2],i(n,n,c),t[o]=n[0],t[o+1]=n[1],t[o+2]=n[2];return t}}();var yt,W=class extends Mt{static get ZERO(){return yt||(yt=new W(0,0,0,0),Object.freeze(yt)),yt}constructor(t=0,e=0,r=0,s=0){super(-0,-0,-0,-0),Y(t)&&arguments.length===1?this.copy(t):(R.debug&&(w(t),w(e),w(r),w(s)),this[0]=t,this[1]=e,this[2]=r,this[3]=s)}set(t,e,r,s){return this[0]=t,this[1]=e,this[2]=r,this[3]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}fromObject(t){return R.debug&&(w(t.x),w(t.y),w(t.z),w(t.w)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t.w=this[3],t}get ELEMENTS(){return 4}get z(){return this[2]}set z(t){this[2]=w(t)}get w(){return this[3]}set w(t){this[3]=w(t)}transform(t){return dt(this,this,t),this.check()}transformByMatrix3(t){return Sn(this,this,t),this.check()}transformByMatrix2(t){return En(this,this,t),this.check()}transformByQuaternion(t){return Rn(this,this,t),this.check()}applyMatrix4(t){return t.transform(this,this),this}};var At=class extends U{toString(){let t="[";if(R.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,r){return this[e*this.RANK+t]=w(r),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)e[s]=this[r+s];return e}setColumn(t,e){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)this[r+s]=e[s];return this}};function Ln(){let n=new N(9);return N!=Float32Array&&(n[1]=0,n[2]=0,n[3]=0,n[5]=0,n[6]=0,n[7]=0),n[0]=1,n[4]=1,n[8]=1,n}function Tr(n){return n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=1,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function _n(n,t){if(n===t){let e=t[1],r=t[2],s=t[3],i=t[6],c=t[7],o=t[11];n[1]=t[4],n[2]=t[8],n[3]=t[12],n[4]=e,n[6]=t[9],n[7]=t[13],n[8]=r,n[9]=i,n[11]=t[14],n[12]=s,n[13]=c,n[14]=o}else n[0]=t[0],n[1]=t[4],n[2]=t[8],n[3]=t[12],n[4]=t[1],n[5]=t[5],n[6]=t[9],n[7]=t[13],n[8]=t[2],n[9]=t[6],n[10]=t[10],n[11]=t[14],n[12]=t[3],n[13]=t[7],n[14]=t[11],n[15]=t[15];return n}function In(n,t){let e=t[0],r=t[1],s=t[2],i=t[3],c=t[4],o=t[5],a=t[6],h=t[7],f=t[8],l=t[9],p=t[10],x=t[11],m=t[12],M=t[13],g=t[14],E=t[15],O=e*o-r*c,d=e*a-s*c,y=e*h-i*c,A=r*a-s*o,T=r*h-i*o,L=s*h-i*a,_=f*M-l*m,I=f*g-p*m,P=f*E-x*m,v=l*g-p*M,u=l*E-x*M,k=p*E-x*g,S=O*k-d*u+y*v+A*P-T*I+L*_;return S?(S=1/S,n[0]=(o*k-a*u+h*v)*S,n[1]=(s*u-r*k-i*v)*S,n[2]=(M*L-g*T+E*A)*S,n[3]=(p*T-l*L-x*A)*S,n[4]=(a*P-c*k-h*I)*S,n[5]=(e*k-s*P+i*I)*S,n[6]=(g*y-m*L-E*d)*S,n[7]=(f*L-p*y+x*d)*S,n[8]=(c*u-o*P+h*_)*S,n[9]=(r*P-e*u-i*_)*S,n[10]=(m*T-M*y+E*O)*S,n[11]=(l*y-f*T-x*O)*S,n[12]=(o*I-c*v-a*_)*S,n[13]=(e*v-r*I+s*_)*S,n[14]=(M*d-m*A-g*O)*S,n[15]=(f*A-l*d+p*O)*S,n):null}function Pn(n){let t=n[0],e=n[1],r=n[2],s=n[3],i=n[4],c=n[5],o=n[6],a=n[7],h=n[8],f=n[9],l=n[10],p=n[11],x=n[12],m=n[13],M=n[14],g=n[15],E=t*c-e*i,O=t*o-r*i,d=e*o-r*c,y=h*m-f*x,A=h*M-l*x,T=f*M-l*m,L=t*T-e*A+r*y,_=i*T-c*A+o*y,I=h*d-f*O+l*E,P=x*d-m*O+M*E;return a*L-s*_+g*I-p*P}function Bt(n,t,e){let r=t[0],s=t[1],i=t[2],c=t[3],o=t[4],a=t[5],h=t[6],f=t[7],l=t[8],p=t[9],x=t[10],m=t[11],M=t[12],g=t[13],E=t[14],O=t[15],d=e[0],y=e[1],A=e[2],T=e[3];return n[0]=d*r+y*o+A*l+T*M,n[1]=d*s+y*a+A*p+T*g,n[2]=d*i+y*h+A*x+T*E,n[3]=d*c+y*f+A*m+T*O,d=e[4],y=e[5],A=e[6],T=e[7],n[4]=d*r+y*o+A*l+T*M,n[5]=d*s+y*a+A*p+T*g,n[6]=d*i+y*h+A*x+T*E,n[7]=d*c+y*f+A*m+T*O,d=e[8],y=e[9],A=e[10],T=e[11],n[8]=d*r+y*o+A*l+T*M,n[9]=d*s+y*a+A*p+T*g,n[10]=d*i+y*h+A*x+T*E,n[11]=d*c+y*f+A*m+T*O,d=e[12],y=e[13],A=e[14],T=e[15],n[12]=d*r+y*o+A*l+T*M,n[13]=d*s+y*a+A*p+T*g,n[14]=d*i+y*h+A*x+T*E,n[15]=d*c+y*f+A*m+T*O,n}function vn(n,t,e){let r=e[0],s=e[1],i=e[2],c,o,a,h,f,l,p,x,m,M,g,E;return t===n?(n[12]=t[0]*r+t[4]*s+t[8]*i+t[12],n[13]=t[1]*r+t[5]*s+t[9]*i+t[13],n[14]=t[2]*r+t[6]*s+t[10]*i+t[14],n[15]=t[3]*r+t[7]*s+t[11]*i+t[15]):(c=t[0],o=t[1],a=t[2],h=t[3],f=t[4],l=t[5],p=t[6],x=t[7],m=t[8],M=t[9],g=t[10],E=t[11],n[0]=c,n[1]=o,n[2]=a,n[3]=h,n[4]=f,n[5]=l,n[6]=p,n[7]=x,n[8]=m,n[9]=M,n[10]=g,n[11]=E,n[12]=c*r+f*s+m*i+t[12],n[13]=o*r+l*s+M*i+t[13],n[14]=a*r+p*s+g*i+t[14],n[15]=h*r+x*s+E*i+t[15]),n}function un(n,t,e){let r=e[0],s=e[1],i=e[2];return n[0]=t[0]*r,n[1]=t[1]*r,n[2]=t[2]*r,n[3]=t[3]*r,n[4]=t[4]*s,n[5]=t[5]*s,n[6]=t[6]*s,n[7]=t[7]*s,n[8]=t[8]*i,n[9]=t[9]*i,n[10]=t[10]*i,n[11]=t[11]*i,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}function kn(n,t,e,r){let s=r[0],i=r[1],c=r[2],o=Math.sqrt(s*s+i*i+c*c),a,h,f,l,p,x,m,M,g,E,O,d,y,A,T,L,_,I,P,v,u,k,S,X;return o<1e-6?null:(o=1/o,s*=o,i*=o,c*=o,h=Math.sin(e),a=Math.cos(e),f=1-a,l=t[0],p=t[1],x=t[2],m=t[3],M=t[4],g=t[5],E=t[6],O=t[7],d=t[8],y=t[9],A=t[10],T=t[11],L=s*s*f+a,_=i*s*f+c*h,I=c*s*f-i*h,P=s*i*f-c*h,v=i*i*f+a,u=c*i*f+s*h,k=s*c*f+i*h,S=i*c*f-s*h,X=c*c*f+a,n[0]=l*L+M*_+d*I,n[1]=p*L+g*_+y*I,n[2]=x*L+E*_+A*I,n[3]=m*L+O*_+T*I,n[4]=l*P+M*v+d*u,n[5]=p*P+g*v+y*u,n[6]=x*P+E*v+A*u,n[7]=m*P+O*v+T*u,n[8]=l*k+M*S+d*X,n[9]=p*k+g*S+y*X,n[10]=x*k+E*S+A*X,n[11]=m*k+O*S+T*X,t!==n&&(n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15]),n)}function zn(n,t,e){let r=Math.sin(e),s=Math.cos(e),i=t[4],c=t[5],o=t[6],a=t[7],h=t[8],f=t[9],l=t[10],p=t[11];return t!==n&&(n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15]),n[4]=i*s+h*r,n[5]=c*s+f*r,n[6]=o*s+l*r,n[7]=a*s+p*r,n[8]=h*s-i*r,n[9]=f*s-c*r,n[10]=l*s-o*r,n[11]=p*s-a*r,n}function bn(n,t,e){let r=Math.sin(e),s=Math.cos(e),i=t[0],c=t[1],o=t[2],a=t[3],h=t[8],f=t[9],l=t[10],p=t[11];return t!==n&&(n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15]),n[0]=i*s-h*r,n[1]=c*s-f*r,n[2]=o*s-l*r,n[3]=a*s-p*r,n[8]=i*r+h*s,n[9]=c*r+f*s,n[10]=o*r+l*s,n[11]=a*r+p*s,n}function qn(n,t,e){let r=Math.sin(e),s=Math.cos(e),i=t[0],c=t[1],o=t[2],a=t[3],h=t[4],f=t[5],l=t[6],p=t[7];return t!==n&&(n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15]),n[0]=i*s+h*r,n[1]=c*s+f*r,n[2]=o*s+l*r,n[3]=a*s+p*r,n[4]=h*s-i*r,n[5]=f*s-c*r,n[6]=l*s-o*r,n[7]=p*s-a*r,n}function Fn(n,t){let e=t[0],r=t[1],s=t[2],i=t[3],c=e+e,o=r+r,a=s+s,h=e*c,f=r*c,l=r*o,p=s*c,x=s*o,m=s*a,M=i*c,g=i*o,E=i*a;return n[0]=1-l-m,n[1]=f+E,n[2]=p-g,n[3]=0,n[4]=f-E,n[5]=1-h-m,n[6]=x+M,n[7]=0,n[8]=p+g,n[9]=x-M,n[10]=1-h-l,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function Cn(n,t,e,r,s,i,c){let o=1/(e-t),a=1/(s-r),h=1/(i-c);return n[0]=i*2*o,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i*2*a,n[6]=0,n[7]=0,n[8]=(e+t)*o,n[9]=(s+r)*a,n[10]=(c+i)*h,n[11]=-1,n[12]=0,n[13]=0,n[14]=c*i*2*h,n[15]=0,n}function Er(n,t,e,r,s){let i=1/Math.tan(t/2);if(n[0]=i/e,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[11]=-1,n[12]=0,n[13]=0,n[15]=0,s!=null&&s!==1/0){let c=1/(r-s);n[10]=(s+r)*c,n[14]=2*s*r*c}else n[10]=-1,n[14]=-2*r;return n}var Bn=Er;function Sr(n,t,e,r,s,i,c){let o=1/(t-e),a=1/(r-s),h=1/(i-c);return n[0]=-2*o,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=-2*a,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=2*h,n[11]=0,n[12]=(t+e)*o,n[13]=(s+r)*a,n[14]=(c+i)*h,n[15]=1,n}var Un=Sr;function Vn(n,t,e,r){let s,i,c,o,a,h,f,l,p,x,m=t[0],M=t[1],g=t[2],E=r[0],O=r[1],d=r[2],y=e[0],A=e[1],T=e[2];return Math.abs(m-y)<1e-6&&Math.abs(M-A)<1e-6&&Math.abs(g-T)<1e-6?Tr(n):(l=m-y,p=M-A,x=g-T,s=1/Math.sqrt(l*l+p*p+x*x),l*=s,p*=s,x*=s,i=O*x-d*p,c=d*l-E*x,o=E*p-O*l,s=Math.sqrt(i*i+c*c+o*o),s?(s=1/s,i*=s,c*=s,o*=s):(i=0,c=0,o=0),a=p*o-x*c,h=x*i-l*o,f=l*c-p*i,s=Math.sqrt(a*a+h*h+f*f),s?(s=1/s,a*=s,h*=s,f*=s):(a=0,h=0,f=0),n[0]=i,n[1]=a,n[2]=l,n[3]=0,n[4]=c,n[5]=h,n[6]=p,n[7]=0,n[8]=o,n[9]=f,n[10]=x,n[11]=0,n[12]=-(i*m+c*M+o*g),n[13]=-(a*m+h*M+f*g),n[14]=-(l*m+p*M+x*g),n[15]=1,n)}function wr(){let n=new N(4);return N!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0,n[3]=0),n}function Dn(n,t,e){return n[0]=t[0]+e[0],n[1]=t[1]+e[1],n[2]=t[2]+e[2],n[3]=t[3]+e[3],n}function Yn(n,t,e){return n[0]=t[0]*e,n[1]=t[1]*e,n[2]=t[2]*e,n[3]=t[3]*e,n}function $n(n){let t=n[0],e=n[1],r=n[2],s=n[3];return Math.sqrt(t*t+e*e+r*r+s*s)}function Wn(n){let t=n[0],e=n[1],r=n[2],s=n[3];return t*t+e*e+r*r+s*s}function Gn(n,t){let e=t[0],r=t[1],s=t[2],i=t[3],c=e*e+r*r+s*s+i*i;return c>0&&(c=1/Math.sqrt(c)),n[0]=e*c,n[1]=r*c,n[2]=s*c,n[3]=i*c,n}function Hn(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]+n[3]*t[3]}function Xn(n,t,e,r){let s=t[0],i=t[1],c=t[2],o=t[3];return n[0]=s+r*(e[0]-s),n[1]=i+r*(e[1]-i),n[2]=c+r*(e[2]-c),n[3]=o+r*(e[3]-o),n}function jn(n,t,e){let r=t[0],s=t[1],i=t[2],c=t[3];return n[0]=e[0]*r+e[4]*s+e[8]*i+e[12]*c,n[1]=e[1]*r+e[5]*s+e[9]*i+e[13]*c,n[2]=e[2]*r+e[6]*s+e[10]*i+e[14]*c,n[3]=e[3]*r+e[7]*s+e[11]*i+e[15]*c,n}function Kn(n,t,e){let r=t[0],s=t[1],i=t[2],c=e[0],o=e[1],a=e[2],h=e[3],f=h*r+o*i-a*s,l=h*s+a*r-c*i,p=h*i+c*s-o*r,x=-c*r-o*s-a*i;return n[0]=f*h+x*-c+l*-a-p*-o,n[1]=l*h+x*-o+p*-c-f*-a,n[2]=p*h+x*-a+f*-o-l*-c,n[3]=t[3],n}var wi=function(){let n=wr();return function(t,e,r,s,i,c){let o,a;for(e||(e=4),r||(r=0),s?a=Math.min(s*e+r,t.length):a=t.length,o=r;o<a;o+=e)n[0]=t[o],n[1]=t[o+1],n[2]=t[o+2],n[3]=t[o+3],i(n,n,c),t[o]=n[0],t[o+1]=n[1],t[o+2]=n[2],t[o+3]=n[3];return t}}();var Dt;(function(n){n[n.COL0ROW0=0]="COL0ROW0",n[n.COL0ROW1=1]="COL0ROW1",n[n.COL0ROW2=2]="COL0ROW2",n[n.COL0ROW3=3]="COL0ROW3",n[n.COL1ROW0=4]="COL1ROW0",n[n.COL1ROW1=5]="COL1ROW1",n[n.COL1ROW2=6]="COL1ROW2",n[n.COL1ROW3=7]="COL1ROW3",n[n.COL2ROW0=8]="COL2ROW0",n[n.COL2ROW1=9]="COL2ROW1",n[n.COL2ROW2=10]="COL2ROW2",n[n.COL2ROW3=11]="COL2ROW3",n[n.COL3ROW0=12]="COL3ROW0",n[n.COL3ROW1=13]="COL3ROW1",n[n.COL3ROW2=14]="COL3ROW2",n[n.COL3ROW3=15]="COL3ROW3"})(Dt||(Dt={}));var Rr=45*Math.PI/180,Nr=1,Ut=.1,Vt=500,Lr=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),C=class extends At{static get IDENTITY(){return Ir()}static get ZERO(){return _r()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Dt}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,r,s,i,c,o,a,h,f,l,p,x,m,M,g){return this[0]=t,this[1]=e,this[2]=r,this[3]=s,this[4]=i,this[5]=c,this[6]=o,this[7]=a,this[8]=h,this[9]=f,this[10]=l,this[11]=p,this[12]=x,this[13]=m,this[14]=M,this[15]=g,this.check()}setRowMajor(t,e,r,s,i,c,o,a,h,f,l,p,x,m,M,g){return this[0]=t,this[1]=i,this[2]=h,this[3]=x,this[4]=e,this[5]=c,this[6]=f,this[7]=m,this[8]=r,this[9]=o,this[10]=l,this[11]=M,this[12]=s,this[13]=a,this[14]=p,this[15]=g,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(Lr)}fromObject(t){return this.check()}fromQuaternion(t){return Fn(this,t),this.check()}frustum(t){let{left:e,right:r,bottom:s,top:i,near:c=Ut,far:o=Vt}=t;return o===1/0?Pr(this,e,r,s,i,c):Cn(this,e,r,s,i,c,o),this.check()}lookAt(t){let{eye:e,center:r=[0,0,0],up:s=[0,1,0]}=t;return Vn(this,e,r,s),this.check()}ortho(t){let{left:e,right:r,bottom:s,top:i,near:c=Ut,far:o=Vt}=t;return Un(this,e,r,s,i,c,o),this.check()}orthographic(t){let{fovy:e=Rr,aspect:r=Nr,focalDistance:s=1,near:i=Ut,far:c=Vt}=t;Qn(e);let o=e/2,a=s*Math.tan(o),h=a*r;return this.ortho({left:-h,right:h,bottom:-a,top:a,near:i,far:c})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:r=1,near:s=.1,far:i=500}=t;return Qn(e),Bn(this,e,r,s,i),this.check()}determinant(){return Pn(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let r=this.getScale(e),s=1/r[0],i=1/r[1],c=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*i,t[2]=this[2]*c,t[3]=0,t[4]=this[4]*s,t[5]=this[5]*i,t[6]=this[6]*c,t[7]=0,t[8]=this[8]*s,t[9]=this[9]*i,t[10]=this[10]*c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let r=this.getScale(e),s=1/r[0],i=1/r[1],c=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*i,t[2]=this[2]*c,t[3]=this[4]*s,t[4]=this[5]*i,t[5]=this[6]*c,t[6]=this[8]*s,t[7]=this[9]*i,t[8]=this[10]*c,t}transpose(){return _n(this,this),this.check()}invert(){return In(this,this),this.check()}multiplyLeft(t){return Bt(this,t,this),this.check()}multiplyRight(t){return Bt(this,this,t),this.check()}rotateX(t){return zn(this,this,t),this.check()}rotateY(t){return bn(this,this,t),this.check()}rotateZ(t){return qn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return kn(this,this,t,e),this.check()}scale(t){return un(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return vn(this,this,t),this.check()}transform(t,e){return t.length===4?(e=jn(e||[-0,-0,-0,-0],t,this),$(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:r}=t,s;switch(r){case 2:s=yn(e||[-0,-0],t,this);break;case 3:s=dt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return $(s,t.length),s}transformAsVector(t,e){let r;switch(t.length){case 2:r=An(e||[-0,-0],t,this);break;case 3:r=Tn(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return $(r,t.length),r}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,r){return this.identity().translate([t,e,r])}},Tt,Et;function _r(){return Tt||(Tt=new C([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Tt)),Tt}function Ir(){return Et||(Et=new C,Object.freeze(Et)),Et}function Qn(n){if(n>Math.PI*2)throw Error("expected radians")}function Pr(n,t,e,r,s,i){let c=2*i/(e-t),o=2*i/(s-r),a=(e+t)/(e-t),h=(s+r)/(s-r),f=-1,l=-1,p=-2*i;return n[0]=c,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=o,n[6]=0,n[7]=0,n[8]=a,n[9]=h,n[10]=f,n[11]=l,n[12]=0,n[13]=0,n[14]=p,n[15]=0,n}function Zn(){let n=new N(4);return N!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n[3]=1,n}function Jn(n){return n[0]=0,n[1]=0,n[2]=0,n[3]=1,n}function Yt(n,t,e){e=e*.5;let r=Math.sin(e);return n[0]=r*t[0],n[1]=r*t[1],n[2]=r*t[2],n[3]=Math.cos(e),n}function $t(n,t,e){let r=t[0],s=t[1],i=t[2],c=t[3],o=e[0],a=e[1],h=e[2],f=e[3];return n[0]=r*f+c*o+s*h-i*a,n[1]=s*f+c*a+i*o-r*h,n[2]=i*f+c*h+r*a-s*o,n[3]=c*f-r*o-s*a-i*h,n}function te(n,t,e){e*=.5;let r=t[0],s=t[1],i=t[2],c=t[3],o=Math.sin(e),a=Math.cos(e);return n[0]=r*a+c*o,n[1]=s*a+i*o,n[2]=i*a-s*o,n[3]=c*a-r*o,n}function ne(n,t,e){e*=.5;let r=t[0],s=t[1],i=t[2],c=t[3],o=Math.sin(e),a=Math.cos(e);return n[0]=r*a-i*o,n[1]=s*a+c*o,n[2]=i*a+r*o,n[3]=c*a-s*o,n}function ee(n,t,e){e*=.5;let r=t[0],s=t[1],i=t[2],c=t[3],o=Math.sin(e),a=Math.cos(e);return n[0]=r*a+s*o,n[1]=s*a-r*o,n[2]=i*a+c*o,n[3]=c*a-i*o,n}function re(n,t){let e=t[0],r=t[1],s=t[2];return n[0]=e,n[1]=r,n[2]=s,n[3]=Math.sqrt(Math.abs(1-e*e-r*r-s*s)),n}function nt(n,t,e,r){let s=t[0],i=t[1],c=t[2],o=t[3],a=e[0],h=e[1],f=e[2],l=e[3],p,x,m,M,g;return p=s*a+i*h+c*f+o*l,p<0&&(p=-p,a=-a,h=-h,f=-f,l=-l),1-p>1e-6?(x=Math.acos(p),g=Math.sin(x),m=Math.sin((1-r)*x)/g,M=Math.sin(r*x)/g):(m=1-r,M=r),n[0]=m*s+M*a,n[1]=m*i+M*h,n[2]=m*c+M*f,n[3]=m*o+M*l,n}function se(n,t){let e=t[0],r=t[1],s=t[2],i=t[3],c=e*e+r*r+s*s+i*i,o=c?1/c:0;return n[0]=-e*o,n[1]=-r*o,n[2]=-s*o,n[3]=i*o,n}function ie(n,t){return n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n[3]=t[3],n}function Wt(n,t){let e=t[0]+t[4]+t[8],r;if(e>0)r=Math.sqrt(e+1),n[3]=.5*r,r=.5/r,n[0]=(t[5]-t[7])*r,n[1]=(t[6]-t[2])*r,n[2]=(t[1]-t[3])*r;else{let s=0;t[4]>t[0]&&(s=1),t[8]>t[s*3+s]&&(s=2);let i=(s+1)%3,c=(s+2)%3;r=Math.sqrt(t[s*3+s]-t[i*3+i]-t[c*3+c]+1),n[s]=.5*r,r=.5/r,n[3]=(t[i*3+c]-t[c*3+i])*r,n[i]=(t[i*3+s]+t[s*3+i])*r,n[c]=(t[c*3+s]+t[s*3+c])*r}return n}var ce=Dn;var oe=Yn,ae=Hn,he=Xn,fe=$n;var le=Wn;var pe=Gn;var xe=function(){let n=Ft(),t=Ct(1,0,0),e=Ct(0,1,0);return function(r,s,i){let c=On(s,i);return c<-.999999?(gt(n,t,s),Nn(n)<1e-6&&gt(n,e,s),wn(n,n),Yt(r,n,Math.PI),r):c>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(gt(n,s,i),r[0]=n[0],r[1]=n[1],r[2]=n[2],r[3]=1+c,pe(r,r))}}(),Fi=function(){let n=Zn(),t=Zn();return function(e,r,s,i,c,o){return nt(n,r,c,o),nt(t,s,i,o),nt(e,n,t,2*o*(1-o)),e}}(),Ci=function(){let n=Ln();return function(t,e,r,s){return n[0]=r[0],n[3]=r[1],n[6]=r[2],n[1]=s[0],n[4]=s[1],n[7]=s[2],n[2]=-e[0],n[5]=-e[1],n[8]=-e[2],pe(t,Wt(t,n))}}();var vr=[0,0,0,1],et=class extends U{constructor(t=0,e=0,r=0,s=1){super(-0,-0,-0,-0),Array.isArray(t)&&arguments.length===1?this.copy(t):this.set(t,e,r,s)}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}set(t,e,r,s){return this[0]=t,this[1]=e,this[2]=r,this[3]=s,this.check()}fromObject(t){return this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this.check()}fromMatrix3(t){return Wt(this,t),this.check()}fromAxisRotation(t,e){return Yt(this,t,e),this.check()}identity(){return Jn(this),this.check()}setAxisAngle(t,e){return this.fromAxisRotation(t,e)}get ELEMENTS(){return 4}get x(){return this[0]}set x(t){this[0]=w(t)}get y(){return this[1]}set y(t){this[1]=w(t)}get z(){return this[2]}set z(t){this[2]=w(t)}get w(){return this[3]}set w(t){this[3]=w(t)}len(){return fe(this)}lengthSquared(){return le(this)}dot(t){return ae(this,t)}rotationTo(t,e){return xe(this,t,e),this.check()}add(t){return ce(this,this,t),this.check()}calculateW(){return re(this,this),this.check()}conjugate(){return ie(this,this),this.check()}invert(){return se(this,this),this.check()}lerp(t,e,r){return r===void 0?this.lerp(this,t,e):(he(this,t,e,r),this.check())}multiplyRight(t){return $t(this,this,t),this.check()}multiplyLeft(t){return $t(this,t,this),this.check()}normalize(){let t=this.len(),e=t>0?1/t:0;return this[0]=this[0]*e,this[1]=this[1]*e,this[2]=this[2]*e,this[3]=this[3]*e,t===0&&(this[3]=1),this.check()}rotateX(t){return te(this,this,t),this.check()}rotateY(t){return ne(this,this,t),this.check()}rotateZ(t){return ee(this,this,t),this.check()}scale(t){return oe(this,this,t),this.check()}slerp(t,e,r){let s,i,c;switch(arguments.length){case 1:({start:s=vr,target:i,ratio:c}=t);break;case 2:s=this,i=t,c=e;break;default:s=t,i=e,c=r}return nt(this,s,i,c),this.check()}transformVector4(t,e=new W){return Kn(e,t,this),$(e,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(t,e){return this.setAxisAngle(t,e)}premultiply(t){return this.multiplyLeft(t)}multiply(t){return this.multiplyRight(t)}};var Ht=B(j(),1);var ur={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},kr={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Xt=class{name;startTime=0;playing=!0;speed=1;channels=[];constructor(t){Object.assign(this,t)}animate(t){if(!this.playing)return;let r=(t/1e3-this.startTime)*this.speed;this.channels.forEach(({sampler:s,target:i,path:c})=>{Br(r,s,i,c),br(i,i._node)})}},G=class{animations;constructor(t){this.animations=t.animations.map((e,r)=>{let s=e.name||`Animation-${r}`,i=e.samplers.map(({input:o,interpolation:a="LINEAR",output:h})=>({input:me(t.accessors[o]),interpolation:a,output:me(t.accessors[h])})),c=e.channels.map(({sampler:o,target:a})=>({sampler:i[o],target:t.nodes[a.node],path:a.path}));return new Xt({name:s,channels:c})})}animate(t){this.setTime(t)}setTime(t){this.animations.forEach(e=>e.animate(t))}getAnimations(){return this.animations}};function me(n){if(!n._animation){let t=kr[n.componentType],e=ur[n.type],r=e*n.count,{buffer:s,byteOffset:i}=n.bufferView.data,c=new t(s,i+(n.byteOffset||0),r);if(e===1)n._animation=Array.from(c);else{let o=[];for(let a=0;a<c.length;a+=e)o.push(Array.from(c.slice(a,a+e)));n._animation=o}}return n._animation}var zr=new C;function br(n,t){if(t.matrix.identity(),n.translation&&t.matrix.translate(n.translation),n.rotation){let e=zr.fromQuaternion(n.rotation);t.matrix.multiplyRight(e)}n.scale&&t.matrix.scale(n.scale)}var Gt=new et;function qr(n,t,e,r,s){if(t==="rotation"){Gt.slerp({start:e,target:r,ratio:s});for(let i=0;i<Gt.length;i++)n[t][i]=Gt[i]}else for(let i=0;i<e.length;i++)n[t][i]=s*r[i]+(1-s)*e[i]}function Fr(n,t,{p0:e,outTangent0:r,inTangent1:s,p1:i,tDiff:c,ratio:o}){for(let a=0;a<n[t].length;a++){let h=r[a]*c,f=s[a]*c;n[t][a]=(2*Math.pow(o,3)-3*Math.pow(o,2)+1)*e[a]+(Math.pow(o,3)-2*Math.pow(o,2)+o)*h+(-2*Math.pow(o,3)+3*Math.pow(o,2))*i[a]+(Math.pow(o,3)-Math.pow(o,2))*f}}function Cr(n,t,e){for(let r=0;r<e.length;r++)n[t][r]=e[r]}function Br(n,{input:t,interpolation:e,output:r},s,i){let c=t[t.length-1],o=n%c,a=t.findIndex(p=>p>=o),h=Math.max(0,a-1);if(!Array.isArray(s[i]))switch(i){case"translation":s[i]=[0,0,0];break;case"rotation":s[i]=[0,0,0,1];break;case"scale":s[i]=[1,1,1];break;default:Ht.log.warn(`Bad animation path ${i}`)()}let f=t[h],l=t[a];switch(e){case"STEP":Cr(s,i,r[h]);break;case"LINEAR":if(l>f){let p=(o-f)/(l-f);qr(s,i,r[h],r[a],p)}break;case"CUBICSPLINE":if(l>f){let p=(o-f)/(l-f),x=l-f,m=r[3*h+1],M=r[3*h+2],g=r[3*a+0],E=r[3*a+1];Fr(s,i,{p0:m,outTangent0:M,inTangent1:g,p1:E,tDiff:x,ratio:p})}break;default:Ht.log.warn(`Interpolation ${e} not supported`)();break}}var de=B(j(),1),ye=B(ge(),1),St=B(at(),1);var Ur=`
460
8
  layout(0) positions: vec4; // in vec4 POSITION;
461
9
 
462
10
  #ifdef HAS_NORMALS
@@ -501,7 +49,7 @@ layout(0) positions: vec4; // in vec4 POSITION;
501
49
  vec3 pos = pbr_vPosition;
502
50
  fragmentColor = pbr_filterColor(vec4(1.0));
503
51
  }
504
- `,$r=`#version 300 es
52
+ `,Vr=`#version 300 es
505
53
 
506
54
  // in vec4 POSITION;
507
55
  in vec4 positions;
@@ -540,13 +88,13 @@ layout(0) positions: vec4; // in vec4 POSITION;
540
88
  pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
541
89
  gl_Position = u_MVPMatrix * positions;
542
90
  }
543
- `,Xr=`#version 300 es
91
+ `,Dr=`#version 300 es
544
92
  out vec4 fragmentColor;
545
93
 
546
94
  void main(void) {
547
95
  vec3 pos = pbr_vPosition;
548
96
  fragmentColor = pbr_filterColor(vec4(1.0));
549
97
  }
550
- `;function En(e,t){let{id:n,geometry:r,material:s,vertexCount:o,materialOptions:i,modelOptions:c}=t,a=ct(e,s,r.attributes,i);yn.log.info(4,"createGLTFModel defines: ",a.defines)();let l=[],f={depthWriteEnabled:!0,depthCompare:"less",depthFormat:"depth24plus",cullMode:"back"},h={id:n,source:Wr,vs:$r,fs:Xr,geometry:r,topology:r.topology,vertexCount:o,modules:[Kt],...c,bindings:{...a.bindings,...c.bindings},defines:{...a.defines,...c.defines},parameters:{...f,...a.parameters,...c.parameters},uniforms:{...a.uniforms,...c.uniforms}},p=new yt.Model(e,h);return new yt.ModelNode({managedResources:l,model:p})}var q;(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(q||(q={}));function Tn(e){switch(e){case q.POINTS:return"point-list";case q.LINES:return"line-list";case q.LINE_STRIP:return"line-strip";case q.TRIANGLES:return"triangle-list";case q.TRIANGLE_STRIP:return"triangle-strip";default:throw new Error(String(e))}}var jr={modelOptions:{},pbrDebug:!1,imageBasedLightingEnvironment:null,lights:!0,useTangents:!1},Et=class{device;options;gltf;constructor(t,n={}){this.device=t,this.options={...jr,...n}}instantiate(t){return this.gltf=t,(t.scenes||[]).map(r=>this.createScene(r))}createAnimator(){return Array.isArray(this.gltf.animations)?new W(this.gltf):null}createScene(t){let r=(t.nodes||[]).map(o=>this.createNode(o));return new $.GroupNode({id:t.name||t.id,children:r})}createNode(t){if(!t._node){let r=(t.children||[]).map(o=>this.createNode(o));t.mesh&&r.push(this.createMesh(t.mesh));let s=new $.GroupNode({id:t.name||t.id,children:r});if(t.matrix)s.setMatrix(t.matrix);else{if(s.matrix.identity(),t.translation&&s.matrix.translate(t.translation),t.rotation){let o=new k().fromQuaternion(t.rotation);s.matrix.multiplyRight(o)}t.scale&&s.matrix.scale(t.scale)}t._node=s}return t._node}createMesh(t){if(!t._mesh){let r=(t.primitives||[]).map((o,i)=>this.createPrimitive(o,i,t)),s=new $.GroupNode({id:t.name||t.id,children:r});t._mesh=s}return t._mesh}createPrimitive(t,n,r){let s=t.name||`${r.name||r.id}-primitive-${n}`,o=Tn(t.mode||4),i=t.indices?t.indices.count:this.getVertexCount(t.attributes),c=En(this.device,{id:s,geometry:this.createGeometry(s,t,o),material:t.material,materialOptions:this.options,modelOptions:this.options.modelOptions,vertexCount:i});return c.bounds=[t.attributes.POSITION.min,t.attributes.POSITION.max],c}getVertexCount(t){throw new Error("getVertexCount not implemented")}createGeometry(t,n,r){let s={};for(let[o,i]of Object.entries(n.attributes)){let{components:c,size:a,value:l}=i;s[o]={size:a??c,value:l}}return new $.Geometry({id:t,topology:r,indices:n.indices.value,attributes:s})}createBuffer(t,n){t.bufferView||(t.bufferView={});let{bufferView:r}=t;return r.lumaBuffers||(r.lumaBuffers={}),r.lumaBuffers[n]||(r.lumaBuffers[n]=this.device.createBuffer({id:`from-${r.id}`,data:r.data||t.value})),r.lumaBuffers[n]}createSampler(t){return t}needsPOT(){return!1}};function Ln(e,t,n){let r=new Et(e,n),s=r.instantiate(t),o=r.createAnimator();return{scenes:s,animator:o}}return On(rt);})();
98
+ `;function Ae(n,t){let{id:e,geometry:r,material:s,vertexCount:i,materialOptions:c,modelOptions:o}=t,a=ot(n,s,r.attributes,c);de.log.info(4,"createGLTFModel defines: ",a.defines)();let h=[],f={depthWriteEnabled:!0,depthCompare:"less",depthFormat:"depth24plus",cullMode:"back"},l={id:e,source:Ur,vs:Vr,fs:Dr,geometry:r,topology:r.topology,vertexCount:i,modules:[ye.pbr],...o,bindings:{...a.bindings,...o.bindings},defines:{...a.defines,...o.defines},parameters:{...f,...a.parameters,...o.parameters},uniforms:{...a.uniforms,...o.uniforms}},p=new St.Model(n,l);return new St.ModelNode({managedResources:h,model:p})}var D;(function(n){n[n.POINTS=0]="POINTS",n[n.LINES=1]="LINES",n[n.LINE_LOOP=2]="LINE_LOOP",n[n.LINE_STRIP=3]="LINE_STRIP",n[n.TRIANGLES=4]="TRIANGLES",n[n.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",n[n.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(D||(D={}));function Te(n){switch(n){case D.POINTS:return"point-list";case D.LINES:return"line-list";case D.LINE_STRIP:return"line-strip";case D.TRIANGLES:return"triangle-list";case D.TRIANGLE_STRIP:return"triangle-strip";default:throw new Error(String(n))}}var Yr={modelOptions:{},pbrDebug:!1,imageBasedLightingEnvironment:null,lights:!0,useTangents:!1},wt=class{device;options;gltf;constructor(t,e={}){this.device=t,this.options={...Yr,...e}}instantiate(t){return this.gltf=t,(t.scenes||[]).map(r=>this.createScene(r))}createAnimator(){return Array.isArray(this.gltf.animations)?new G(this.gltf):null}createScene(t){let r=(t.nodes||[]).map(i=>this.createNode(i));return new H.GroupNode({id:t.name||t.id,children:r})}createNode(t){if(!t._node){let r=(t.children||[]).map(i=>this.createNode(i));t.mesh&&r.push(this.createMesh(t.mesh));let s=new H.GroupNode({id:t.name||t.id,children:r});if(t.matrix)s.setMatrix(t.matrix);else{if(s.matrix.identity(),t.translation&&s.matrix.translate(t.translation),t.rotation){let i=new C().fromQuaternion(t.rotation);s.matrix.multiplyRight(i)}t.scale&&s.matrix.scale(t.scale)}t._node=s}return t._node}createMesh(t){if(!t._mesh){let r=(t.primitives||[]).map((i,c)=>this.createPrimitive(i,c,t)),s=new H.GroupNode({id:t.name||t.id,children:r});t._mesh=s}return t._mesh}createPrimitive(t,e,r){let s=t.name||`${r.name||r.id}-primitive-${e}`,i=Te(t.mode||4),c=t.indices?t.indices.count:this.getVertexCount(t.attributes),o=Ae(this.device,{id:s,geometry:this.createGeometry(s,t,i),material:t.material,materialOptions:this.options,modelOptions:this.options.modelOptions,vertexCount:c});return o.bounds=[t.attributes.POSITION.min,t.attributes.POSITION.max],o}getVertexCount(t){throw new Error("getVertexCount not implemented")}createGeometry(t,e,r){let s={};for(let[i,c]of Object.entries(e.attributes)){let{components:o,size:a,value:h}=c;s[i]={size:a??o,value:h}}return new H.Geometry({id:t,topology:r,indices:e.indices.value,attributes:s})}createBuffer(t,e){t.bufferView||(t.bufferView={});let{bufferView:r}=t;return r.lumaBuffers||(r.lumaBuffers={}),r.lumaBuffers[e]||(r.lumaBuffers[e]=this.device.createBuffer({id:`from-${r.id}`,data:r.data||t.value})),r.lumaBuffers[e]}createSampler(t){return t}needsPOT(){return!1}};function Ee(n,t,e){let r=new wt(n,e),s=r.instantiate(t),i=r.createAnimator();return{scenes:s,animator:i}}return _e(rt);})();
551
99
  return __exports__;
552
100
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/gltf",
3
- "version": "9.1.0-alpha.10",
3
+ "version": "9.1.0-alpha.13",
4
4
  "description": "glTF support for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,14 +40,14 @@
40
40
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
41
41
  },
42
42
  "peerDependencies": {
43
- "@luma.gl/core": "^9.0.0-beta",
44
- "@luma.gl/engine": "^9.0.0-beta"
43
+ "@luma.gl/core": "9.1.0-alpha.10",
44
+ "@luma.gl/engine": "9.1.0-alpha.10",
45
+ "@luma.gl/shadertools": "9.1.0-alpha.10"
45
46
  },
46
47
  "dependencies": {
47
48
  "@loaders.gl/core": "^4.2.0",
48
49
  "@loaders.gl/textures": "^4.2.0",
49
- "@luma.gl/shadertools": "9.1.0-alpha.10",
50
- "@math.gl/core": "^4.0.0"
50
+ "@math.gl/core": "4.1.0-alpha.3"
51
51
  },
52
- "gitHead": "f419cdc284e87b553df60af49d2888ac7dbbf288"
52
+ "gitHead": "c2c641d67a5aec97467de13b0e3d8f9307ba03c2"
53
53
  }