rhodonite 0.26.0 → 0.27.0
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/VERSION-FILE +1 -1
- package/dist/esm/foundation/core/MemoryManager.d.ts +19 -0
- package/dist/esm/foundation/core/MemoryManager.js +2 -2
- package/dist/esm/foundation/definitions/ShaderSemantics.d.ts +1 -0
- package/dist/esm/foundation/definitions/ShaderSemantics.js +2 -2
- package/dist/esm/foundation/helpers/Shadow/ShadowSystem.js +1 -1
- package/dist/esm/foundation/helpers/materials/createNodeBasedRaymarchingMaterials.js +1 -1
- package/dist/esm/foundation/helpers/materials/nodeBasedMaterialCommon.js +1 -1
- package/dist/esm/foundation/importer/DrcPointCloudImporter.js +1 -1
- package/dist/esm/foundation/importer/Gltf2Importer.d.ts +2 -1
- package/dist/esm/foundation/importer/Gltf2Importer.js +1 -1
- package/dist/esm/foundation/importer/GltfImporter.js +1 -1
- package/dist/esm/foundation/importer/RhodoniteImportExtension.js +1 -1
- package/dist/esm/foundation/importer/Vrm0xImporter.js +1 -1
- package/dist/esm/foundation/importer/VrmImporter.js +1 -1
- package/dist/esm/foundation/materials/contents/CustomMaterialContent.js +1 -1
- package/dist/esm/foundation/materials/contents/MToon0xMaterialContent.js +11 -11
- package/dist/esm/foundation/materials/contents/MToon1MaterialContent.js +6 -6
- package/dist/esm/foundation/materials/core/AbstractMaterialContent.js +1 -1
- package/dist/esm/foundation/materials/core/Material.d.ts +7 -2
- package/dist/esm/foundation/materials/core/Material.js +1 -1
- package/dist/esm/foundation/materials/core/ShaderityUtilityWebGL.js +2 -2
- package/dist/esm/foundation/materials/core/ShaderityUtilityWebGPU.js +2 -2
- package/dist/esm/foundation/memory/Accessor.js +6 -6
- package/dist/esm/foundation/memory/BufferView.js +1 -1
- package/dist/esm/foundation/misc/PngDecoder.d.ts +18 -0
- package/dist/esm/foundation/misc/PngDecoder.js +1 -0
- package/dist/esm/foundation/renderer/RenderPass.d.ts +7 -0
- package/dist/esm/foundation/renderer/RenderPass.js +1 -1
- package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +2 -1
- package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.js +1 -1
- package/dist/esm/foundation/system/Engine.js +1 -1
- package/dist/esm/foundation/textures/CubeTexture.d.ts +11 -2
- package/dist/esm/foundation/textures/CubeTexture.js +1 -1
- package/dist/esm/foundation/textures/RenderTargetTexture2DArray.js +1 -1
- package/dist/esm/foundation/textures/RenderTargetTextureCube.d.ts +6 -0
- package/dist/esm/foundation/textures/RenderTargetTextureCube.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/webgl/MultiDraw.js +1 -1
- package/dist/esm/webgl/MultiDrawRepository.js +1 -1
- package/dist/esm/webgl/WebGLResourceRepository.d.ts +5 -0
- package/dist/esm/webgl/WebGLResourceRepository.js +3 -3
- package/dist/esm/webgl/WebGLStereoUtil.js +1 -1
- package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +19 -14
- package/dist/esm/webgl/WebGLStrategyWebGL2.js +67 -67
- package/dist/esm/webgl/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.glsl.js +2 -1
- package/dist/esm/webgl/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.glsl.js +1 -0
- package/dist/esm/webgl/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -0
- package/dist/esm/webgl/shaderity_shaders/common/iblDefinition.glsl.js +11 -5
- package/dist/esm/webgl/shaders/nodes/BlockBeginShader.js +1 -1
- package/dist/esm/webgl/shaders/nodes/BlockEndShader.js +1 -1
- package/dist/esm/webgl/shaders/nodes/ConstantVariableShader.js +5 -5
- package/dist/esm/webgl/shaders/nodes/RaymarchObjectIdUniform.js +3 -3
- package/dist/esm/webgl/shaders/nodes/SdApplyWorldMatrix.js +3 -3
- package/dist/esm/webgl/shaders/nodes/Texture2DShader.js +14 -14
- package/dist/esm/webgl/shaders/nodes/UniformDataShader.js +13 -13
- package/dist/esm/webgpu/GpuCullingRegistry.js +1 -1
- package/dist/esm/webgpu/GpuDeformRegistry.js +1 -1
- package/dist/esm/webgpu/WebGpuGpuTimer.js +1 -1
- package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +6 -0
- package/dist/esm/webgpu/WebGpuResourceRepository.js +5 -5
- package/dist/esm/webgpu/WebGpuStrategyBasic.js +2 -2
- package/dist/esm/webgpu/WebGpuVertexDeformer.js +1 -1
- package/dist/esm/webgpu/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.wgsl.js +1 -0
- package/dist/esm/webgpu/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.wgsl.js +1 -0
- package/dist/esm/webgpu/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +1 -0
- package/dist/esm/webgpu/shaderity_shaders/common/iblDefinition.wgsl.js +10 -4
- package/dist/esmdev/foundation/core/MemoryManager.d.ts +19 -0
- package/dist/esmdev/foundation/core/MemoryManager.js +28 -3
- package/dist/esmdev/foundation/core/RnObject.js +37 -37
- package/dist/esmdev/foundation/definitions/Blend.js +3 -3
- package/dist/esmdev/foundation/definitions/ComponentType.js +7 -7
- package/dist/esmdev/foundation/definitions/CompositionType.js +50 -50
- package/dist/esmdev/foundation/definitions/CompressionTextureType.js +6 -6
- package/dist/esmdev/foundation/definitions/ShaderSemantics.d.ts +1 -0
- package/dist/esmdev/foundation/definitions/ShaderSemantics.js +12 -7
- package/dist/esmdev/foundation/definitions/TextureFormat.js +3 -3
- package/dist/esmdev/foundation/definitions/TextureParameter.js +3 -3
- package/dist/esmdev/foundation/definitions/VertexAttribute.js +30 -30
- package/dist/esmdev/foundation/enhanced_js_objects/Array.js +2 -2
- package/dist/esmdev/foundation/exporter/Gltf2Exporter.js +106 -106
- package/dist/esmdev/foundation/geometry/ComplexVertexAttribute.js +18 -18
- package/dist/esmdev/foundation/geometry/Frustum.js +39 -39
- package/dist/esmdev/foundation/geometry/Mesh.js +205 -205
- package/dist/esmdev/foundation/geometry/Primitive.js +124 -124
- package/dist/esmdev/foundation/geometry/SimpleVertexAttribute.js +7 -7
- package/dist/esmdev/foundation/geometry/shapes/Cylinder.js +3 -3
- package/dist/esmdev/foundation/geometry/shapes/Joint.js +33 -33
- package/dist/esmdev/foundation/gizmos/AABBGizmo.js +12 -12
- package/dist/esmdev/foundation/gizmos/CapsuleColliderGizmo.js +23 -23
- package/dist/esmdev/foundation/gizmos/Gizmo.js +23 -23
- package/dist/esmdev/foundation/gizmos/JointGizmo.js +35 -35
- package/dist/esmdev/foundation/gizmos/LightGizmo.js +23 -23
- package/dist/esmdev/foundation/gizmos/LocatorGizmo.js +22 -22
- package/dist/esmdev/foundation/gizmos/RotationGizmo.js +197 -197
- package/dist/esmdev/foundation/gizmos/ScaleGizmo.js +129 -129
- package/dist/esmdev/foundation/gizmos/ShapeGizmo.js +43 -43
- package/dist/esmdev/foundation/gizmos/SphereColliderGizmo.js +24 -24
- package/dist/esmdev/foundation/gizmos/TranslationGizmo.js +129 -129
- package/dist/esmdev/foundation/helpers/BloomHelper.js +28 -28
- package/dist/esmdev/foundation/helpers/GaussianBlurHelper.js +18 -18
- package/dist/esmdev/foundation/helpers/Shadow/PointShadowMap.js +11 -11
- package/dist/esmdev/foundation/helpers/Shadow/ShadowMap.js +5 -5
- package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.js +111 -111
- package/dist/esmdev/foundation/helpers/materials/createNodeBasedRaymarchingMaterials.js +10 -1
- package/dist/esmdev/foundation/helpers/materials/nodeBasedMaterialCommon.js +11 -1
- package/dist/esmdev/foundation/importer/AnimationAssigner.js +44 -44
- package/dist/esmdev/foundation/importer/DrcPointCloudImporter.js +27 -27
- package/dist/esmdev/foundation/importer/Gltf2Importer.d.ts +2 -1
- package/dist/esmdev/foundation/importer/Gltf2Importer.js +21 -17
- package/dist/esmdev/foundation/importer/GltfImporter.js +22 -22
- package/dist/esmdev/foundation/importer/ModelConverter.js +131 -131
- package/dist/esmdev/foundation/importer/RhodoniteImportExtension.js +6 -6
- package/dist/esmdev/foundation/importer/Vrm0xImporter.js +48 -48
- package/dist/esmdev/foundation/importer/VrmImporter.js +10 -10
- package/dist/esmdev/foundation/materials/contents/CustomMaterialContent.js +37 -28
- package/dist/esmdev/foundation/materials/contents/DepthEncodeMaterialContent.js +2 -2
- package/dist/esmdev/foundation/materials/contents/MToon0xMaterialContent.js +145 -137
- package/dist/esmdev/foundation/materials/contents/MToon1MaterialContent.js +27 -19
- package/dist/esmdev/foundation/materials/contents/ShadowMapDecodeClassicMaterialContent.js +5 -5
- package/dist/esmdev/foundation/materials/contents/VarianceShadowMapDecodeClassicMaterialContent.js +4 -4
- package/dist/esmdev/foundation/materials/core/AbstractMaterialContent.js +47 -47
- package/dist/esmdev/foundation/materials/core/AbstractShaderNode.js +25 -25
- package/dist/esmdev/foundation/materials/core/DummyTextures.js +3 -3
- package/dist/esmdev/foundation/materials/core/Material.d.ts +7 -2
- package/dist/esmdev/foundation/materials/core/Material.js +113 -99
- package/dist/esmdev/foundation/materials/core/MaterialRepository.js +51 -51
- package/dist/esmdev/foundation/materials/core/ShaderGraphResolver.js +38 -38
- package/dist/esmdev/foundation/materials/core/ShaderHandler.js +4 -4
- package/dist/esmdev/foundation/materials/core/ShaderityUtilityWebGL.js +14 -14
- package/dist/esmdev/foundation/materials/core/ShaderityUtilityWebGPU.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/AbsShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/AcosShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/AddShaderNode.js +18 -18
- package/dist/esmdev/foundation/materials/nodes/AlphaTestShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/AndShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/Atan2ShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/AttributeColorShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/AttributeInstanceIdsShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/AttributeJointShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/AttributeNormalShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/AttributePositionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/AttributeTangentShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/AttributeTexcoordShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/AttributeWeightShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/BlockBeginShaderNode.js +11 -11
- package/dist/esmdev/foundation/materials/nodes/BlockEndShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/BranchShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/CalcBitangentShaderNode.js +7 -7
- package/dist/esmdev/foundation/materials/nodes/CastToFloatShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/ClampShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/ClassicShaderNode.js +11 -11
- package/dist/esmdev/foundation/materials/nodes/ConstantScalarVariableShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/ConstantVariableShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/ConstantVector2VariableShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/ConstantVector3VariableShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/ConstantVector4VariableShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/CosShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/DiscardShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/DotProductShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/EqualShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/FlatShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/GreaterOrEqualShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/GreaterShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/GreaterThanShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/LengthShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/LessOrEqualShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/LessThanShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/MergeVectorShaderNode.js +19 -19
- package/dist/esmdev/foundation/materials/nodes/MinShaderNode.js +18 -18
- package/dist/esmdev/foundation/materials/nodes/MultiplyShaderNode.js +21 -21
- package/dist/esmdev/foundation/materials/nodes/NormalMatrixShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/NormalizeShaderNode.js +9 -9
- package/dist/esmdev/foundation/materials/nodes/NotEqualShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/OrShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/OutColorShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/OutPositionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/PbrAnisotropyPropsShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/PbrAnisotropyRotationShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/PbrBaseColorPropsShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/PbrClearcoatPropsShaderNode.js +7 -7
- package/dist/esmdev/foundation/materials/nodes/PbrDiffuseTransmissionPropsShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/PbrEmissivePropsShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/PbrIridescencePropsShaderNode.js +8 -8
- package/dist/esmdev/foundation/materials/nodes/PbrMetallicRoughnessPropsShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/PbrNormalPropsShaderNode.js +11 -11
- package/dist/esmdev/foundation/materials/nodes/PbrOcclusionPropsShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/PbrShaderShaderNode.js +21 -21
- package/dist/esmdev/foundation/materials/nodes/PbrSheenPropsShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/PbrSpecularPropsShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/PbrTransmissionPropsShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/PbrVolumePropsShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/PremultipliedAlphaShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/ProcessGeometryShaderNode.js +22 -22
- package/dist/esmdev/foundation/materials/nodes/ProjectionMatrixShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/Random_HashPRNGShaderNode.js +12 -12
- package/dist/esmdev/foundation/materials/nodes/Random_SinHashShaderNode.js +12 -12
- package/dist/esmdev/foundation/materials/nodes/RemapShaderNode.js +17 -17
- package/dist/esmdev/foundation/materials/nodes/SinShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/SmoothStepShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/SplitVectorShaderNode.js +17 -17
- package/dist/esmdev/foundation/materials/nodes/StepShaderNode.js +14 -14
- package/dist/esmdev/foundation/materials/nodes/TanShaderNode.js +13 -13
- package/dist/esmdev/foundation/materials/nodes/Texture2DShaderNode.js +16 -16
- package/dist/esmdev/foundation/materials/nodes/TimeShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/TransformShaderNode.js +10 -10
- package/dist/esmdev/foundation/materials/nodes/UniformDataShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/ViewMatrixShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/WireframeMaterialNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/WorldMatrixShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendXYShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendXZShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendYXShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendYZShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendZXShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/BendZYShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/InitialPositionShaderNode.js +1 -1
- package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothIntersectionShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothSubtractionShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothUnionShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/raymarching/OpSubtractionShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/raymarching/OpUnionShaderNode.js +6 -6
- package/dist/esmdev/foundation/materials/nodes/raymarching/OutDistanceShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/raymarching/OutShadingColorShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/OutUnionShaderNode.js +15 -15
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchCameraPositionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitDistanceShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitNormalShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitPositionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchObjectIdShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchObjectIdUniformShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchRayDirectionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchTBNShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchViewDirectionShaderNode.js +2 -2
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdApplyTransformShaderNode.js +9 -9
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdApplyWorldMatrixShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarXShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarYShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarZShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdBoxShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdCapsuleShaderNode.js +5 -5
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatXShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatXYShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatYShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatYZShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatZShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatZXShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdRoundBoxShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdSphereShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdTorusShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeXShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeYShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeZShaderNode.js +3 -3
- package/dist/esmdev/foundation/materials/nodes/raymarching/TwistXShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/TwistYShaderNode.js +4 -4
- package/dist/esmdev/foundation/materials/nodes/raymarching/TwistZShaderNode.js +4 -4
- package/dist/esmdev/foundation/math/AABB.js +120 -120
- package/dist/esmdev/foundation/math/AnimatedQuaternion.js +53 -53
- package/dist/esmdev/foundation/math/AnimatedScalar.js +54 -54
- package/dist/esmdev/foundation/math/AnimatedValueEvaluationState.js +18 -18
- package/dist/esmdev/foundation/math/AnimatedVector2.js +54 -54
- package/dist/esmdev/foundation/math/AnimatedVector3.js +54 -54
- package/dist/esmdev/foundation/math/AnimatedVector4.js +54 -54
- package/dist/esmdev/foundation/math/AnimatedVectorN.js +54 -54
- package/dist/esmdev/foundation/math/IdentityMatrix33.js +2 -2
- package/dist/esmdev/foundation/math/IdentityMatrix44.js +2 -2
- package/dist/esmdev/foundation/math/MathClassUtil.js +3 -3
- package/dist/esmdev/foundation/math/Quaternion.js +13 -13
- package/dist/esmdev/foundation/math/Transform3D.js +72 -72
- package/dist/esmdev/foundation/math/shapes/MathSphere.js +7 -7
- package/dist/esmdev/foundation/memory/Accessor.js +369 -369
- package/dist/esmdev/foundation/memory/Buffer.js +39 -39
- package/dist/esmdev/foundation/memory/BufferView.js +29 -29
- package/dist/esmdev/foundation/misc/DataUtil.js +2 -2
- package/dist/esmdev/foundation/misc/EnumIO.js +8 -8
- package/dist/esmdev/foundation/misc/Logger.js +14 -14
- package/dist/esmdev/foundation/misc/PngDecoder.d.ts +18 -0
- package/dist/esmdev/foundation/misc/PngDecoder.js +113 -0
- package/dist/esmdev/foundation/misc/RnPromise.js +14 -14
- package/dist/esmdev/foundation/misc/Time.js +23 -23
- package/dist/esmdev/foundation/misc/WeakOption.js +14 -14
- package/dist/esmdev/foundation/misc/cache/Cache.js +2 -2
- package/dist/esmdev/foundation/misc/cache/SymbolWeakMap.js +8 -8
- package/dist/esmdev/foundation/physics/PhysicsWorldQuery.js +10 -10
- package/dist/esmdev/foundation/physics/Rapier/RapierCharacterControllerStrategy.js +186 -186
- package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsStrategy.js +221 -221
- package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsWorldQueryStrategy.js +3 -3
- package/dist/esmdev/foundation/physics/VRMSpring/CapsuleCollider.js +36 -36
- package/dist/esmdev/foundation/physics/VRMSpring/SphereCollider.js +26 -26
- package/dist/esmdev/foundation/physics/VRMSpring/VRMSpringBone.js +6 -6
- package/dist/esmdev/foundation/physics/VRMSpring/VRMSpringBonePhysicsStrategy.js +39 -39
- package/dist/esmdev/foundation/renderer/Expression.js +6 -6
- package/dist/esmdev/foundation/renderer/Frame.js +6 -6
- package/dist/esmdev/foundation/renderer/FrameBuffer.js +25 -25
- package/dist/esmdev/foundation/renderer/RenderPass.d.ts +7 -0
- package/dist/esmdev/foundation/renderer/RenderPass.js +94 -86
- package/dist/esmdev/foundation/renderer/TemporalAA/PreviousFrameDataTracker.js +6 -6
- package/dist/esmdev/foundation/renderer/TemporalAA/TemporalAASystem.js +75 -75
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.js +146 -146
- package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystemStub.js +3 -3
- package/dist/esmdev/foundation/renderer/pipelines/DeferredRenderPipeline.js +4 -4
- package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +2 -1
- package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.js +420 -420
- package/dist/esmdev/foundation/system/Engine.js +209 -209
- package/dist/esmdev/foundation/system/EventPubSub.js +8 -8
- package/dist/esmdev/foundation/system/InputManager.js +56 -56
- package/dist/esmdev/foundation/system/ModuleManager.js +3 -3
- package/dist/esmdev/foundation/textures/AbstractTexture.js +48 -48
- package/dist/esmdev/foundation/textures/CubeTexture.d.ts +11 -2
- package/dist/esmdev/foundation/textures/CubeTexture.js +47 -36
- package/dist/esmdev/foundation/textures/RenderBuffer.js +11 -11
- package/dist/esmdev/foundation/textures/RenderTargetTexture.js +24 -24
- package/dist/esmdev/foundation/textures/RenderTargetTexture2DArray.js +35 -35
- package/dist/esmdev/foundation/textures/RenderTargetTextureCube.d.ts +6 -0
- package/dist/esmdev/foundation/textures/RenderTargetTextureCube.js +25 -19
- package/dist/esmdev/foundation/textures/Sampler.js +24 -24
- package/dist/esmdev/foundation/textures/Texture.js +83 -83
- package/dist/esmdev/foundation/textures/TextureArray.js +8 -8
- package/dist/esmdev/foundation/textures/TextureDataFloat.js +26 -26
- package/dist/esmdev/foundation/textures/VideoTexture.js +24 -24
- package/dist/esmdev/version.js +2 -2
- package/dist/esmdev/webgl/InstanceSidTable.js +62 -62
- package/dist/esmdev/webgl/MultiDraw.js +2 -2
- package/dist/esmdev/webgl/MultiDrawRepository.js +30 -30
- package/dist/esmdev/webgl/WebGLContextWrapper.js +146 -146
- package/dist/esmdev/webgl/WebGLGpuTimer.js +30 -30
- package/dist/esmdev/webgl/WebGLResourceRepository.d.ts +5 -0
- package/dist/esmdev/webgl/WebGLResourceRepository.js +368 -307
- package/dist/esmdev/webgl/WebGLStereoUtil.js +39 -39
- package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +19 -14
- package/dist/esmdev/webgl/WebGLStrategyWebGL2.js +294 -280
- package/dist/esmdev/webgl/debug/ShaderParameterDebugger.js +4 -4
- package/dist/esmdev/webgl/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.glsl.js +2 -2
- package/dist/esmdev/webgl/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.glsl.js +2 -2
- package/dist/esmdev/webgl/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -2
- package/dist/esmdev/webgl/shaderity_shaders/common/iblDefinition.glsl.js +2 -2
- package/dist/esmdev/webgl/shaders/RaymarchingShaderPart.js +4 -4
- package/dist/esmdev/webgl/shaders/RaymarchingShadowShaderPart.js +14 -14
- package/dist/esmdev/webgl/shaders/StandardShaderPart.js +3 -3
- package/dist/esmdev/webgl/shaders/nodes/BlockBeginShader.js +10 -10
- package/dist/esmdev/webgl/shaders/nodes/BlockEndShader.js +10 -10
- package/dist/esmdev/webgl/shaders/nodes/ConstantVariableShader.js +21 -21
- package/dist/esmdev/webgl/shaders/nodes/OutDistance.js +12 -12
- package/dist/esmdev/webgl/shaders/nodes/OutUnion.js +9 -9
- package/dist/esmdev/webgl/shaders/nodes/RaymarchObjectIdUniform.js +8 -8
- package/dist/esmdev/webgl/shaders/nodes/SdApplyTransform.js +9 -9
- package/dist/esmdev/webgl/shaders/nodes/SdApplyWorldMatrix.js +8 -8
- package/dist/esmdev/webgl/shaders/nodes/Texture2DShader.js +23 -23
- package/dist/esmdev/webgl/shaders/nodes/UniformDataShader.js +23 -23
- package/dist/esmdev/webgl/textureLoader/KTX2TextureLoader.js +24 -24
- package/dist/esmdev/webgpu/GpuCullingRegistry.js +91 -91
- package/dist/esmdev/webgpu/GpuDeformRegistry.js +53 -53
- package/dist/esmdev/webgpu/RangeAllocator.js +16 -16
- package/dist/esmdev/webgpu/WebGpuBufferArena.js +21 -21
- package/dist/esmdev/webgpu/WebGpuDeviceWrapper.js +7 -7
- package/dist/esmdev/webgpu/WebGpuGpuCulling.js +198 -198
- package/dist/esmdev/webgpu/WebGpuGpuTimer.js +51 -51
- package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.js +36 -36
- package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +6 -0
- package/dist/esmdev/webgpu/WebGpuResourceRepository.js +655 -593
- package/dist/esmdev/webgpu/WebGpuStrategyBasic.js +123 -123
- package/dist/esmdev/webgpu/WebGpuVertexDeformer.js +128 -128
- package/dist/esmdev/webgpu/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.wgsl.js +2 -2
- package/dist/esmdev/webgpu/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.wgsl.js +2 -2
- package/dist/esmdev/webgpu/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -2
- package/dist/esmdev/webgpu/shaderity_shaders/common/iblDefinition.wgsl.js +2 -2
- package/dist/esmdev/xr/WebARSystem.js +69 -69
- package/dist/esmdev/xr/WebXRSystem.js +151 -151
- package/package.json +2 -1
package/VERSION-FILE
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
v0.
|
|
1
|
+
v0.27.0-1-g6b206dda3-dirty
|
|
2
2
|
main
|
|
@@ -48,8 +48,27 @@ export declare class MemoryManager {
|
|
|
48
48
|
* @returns The Buffer instance (existing or newly created)
|
|
49
49
|
*/
|
|
50
50
|
createOrGetBuffer(bufferUse: BufferUseEnum, requireIndexOfTheBufferLayer?: Index): Buffer;
|
|
51
|
+
/**
|
|
52
|
+
* Checks whether a buffer use takes part in the GPU data layout, where buffers are addressed
|
|
53
|
+
* by their layer index (for example the byte offsets of the WebGL data texture).
|
|
54
|
+
* @param bufferUse - The type of buffer to check
|
|
55
|
+
* @returns True when buffers of this use are registered as layers of the buffer use
|
|
56
|
+
*/
|
|
57
|
+
private static __isLayerAddressedBufferUse;
|
|
51
58
|
/**
|
|
52
59
|
* Creates a buffer on-demand with custom size and alignment for a specific object.
|
|
60
|
+
*
|
|
61
|
+
* Only buffer uses that take part in the GPU data layout (`GPUInstanceData` and
|
|
62
|
+
* `GPUVertexData`) are registered as a new layer of the buffer use. The renderer addresses those
|
|
63
|
+
* layers by index (the data texture byte offsets), so they stay registered until the engine is
|
|
64
|
+
* destroyed.
|
|
65
|
+
*
|
|
66
|
+
* Any other buffer use (for example `CPUGeneric` geometry data) is not part of the GPU layout.
|
|
67
|
+
* Such a buffer is returned without being registered, so it is owned by the BufferViews and
|
|
68
|
+
* Accessors created from it and is reclaimed by the garbage collector together with the object
|
|
69
|
+
* that holds them. Registering them used to keep the vertex data of every primitive alive for
|
|
70
|
+
* the whole session even after the primitive was destroyed (issue #1846).
|
|
71
|
+
*
|
|
53
72
|
* @param bufferUse - The type of buffer to create
|
|
54
73
|
* @param size - The size of the buffer in bytes
|
|
55
74
|
* @param byteAlign - The byte alignment requirement for the buffer
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BufferUse as
|
|
2
|
-
`);let e=t=>{let n=this.getLayerCountOfTheBufferUsage(t);for(let r=0;r<n;r++){let f=this.getBuffer(t,r);f!=null&&console.log(`${t.str} ${r}: ${f.takenSizeInByte} byte of ${f.byteLength} bytes. (${f.takenSizeInByte/f.byteLength*100} %) `)}};e(
|
|
1
|
+
import{BufferUse as i}from"../definitions/BufferUse.js";import{Buffer as c}from"../memory/Buffer.js";import{DataUtil as m}from"../misc/DataUtil.js";import{MiscUtil as d}from"../misc/MiscUtil.js";var h=class g{constructor(e,t){this.Bf=new Map;this.gf=new Map;this.lf=0;this.Uf=[8/32];this.i=e,this.Of=e.config.bufferSizeDivisionRatiosForGPUInstanceDataUsage,this.lf=t}static createInstanceIfNotCreated(e,t){return new g(e,t)}Mf(e){return e+(e%4===0?0:4-e%4)}Ef(e){let t=this.getLayerCountOfTheBufferUsage(e),n=this.lf*1/16;e===i.GPUInstanceData?n=this.lf*this.Of[t]:e===i.GPUVertexData&&(n=this.lf*this.Uf[t]);let r=Math.floor(n/16)*16,f=new ArrayBuffer(r),s=4;(e===i.GPUInstanceData||e===i.GPUVertexData)&&(s=16);let a=new c({byteLength:f.byteLength,buffer:f,name:e.str,byteAlign:s,bufferUsage:e,indexOfTheBufferUsage:t}),u=this.Bf.get(e);return u==null&&(u=new Map,this.Bf.set(e,u)),u.set(t,a),this.incrementCountOfTheBufferUsage(e),a}getBuffer(e,t){let n=this.Bf.get(e);if(n==null)return;let r=t!=null?t:this.getActiveBufferLayerIndexOfTheBufferUsage(e);return n.get(r)}createOrGetBuffer(e,t=0){let n=this.getLayerCountOfTheBufferUsage(e);if(t>=n)return this.Ef(e);let r=this.getBuffer(e,Math.min(t,n-1));return r!=null?r:this.Ef(e)}static Lf(e){return e===i.GPUInstanceData||e===i.GPUVertexData}createBufferOnDemand(e,t,n){let r=m.addPaddingBytes(t,n),f=new ArrayBuffer(r),s=g.Lf(e),a=s?this.getLayerCountOfTheBufferUsage(e):0,u=new c({byteLength:f.byteLength,buffer:f,name:e.toString(),byteAlign:n,bufferUsage:e,indexOfTheBufferUsage:a});if(!s)return u;let o=this.Bf.get(e);return o==null&&(o=new Map,this.Bf.set(e,o)),o.set(a,u),this.incrementCountOfTheBufferUsage(e),u}getActiveBufferLayerIndexOfTheBufferUsage(e){return this.getLayerCountOfTheBufferUsage(e)-1}getLayerCountOfTheBufferUsage(e){let t=this.gf.get(e);return t!=null?t:(this.gf.set(e,0),0)}incrementCountOfTheBufferUsage(e){let t=this.gf.get(e);if(t==null){this.gf.set(e,1);return}this.gf.set(e,t+1)}getSizesOfTheBuffers(e){let t=[],n=this.getLayerCountOfTheBufferUsage(e);for(let r=0;r<n;r++){let f=this.getBuffer(e,r);f!=null&&t.push(f.byteLength)}return t}getBuffers(e){let t=[],n=this.getLayerCountOfTheBufferUsage(e);for(let r=0;r<n;r++){let f=this.getBuffer(e,r);f!=null&&t.push(f)}return t}getByteOffsetOfExistingBuffers(e,t){return this.getSizesOfTheBuffers(e).slice(0,t).reduce((f,s)=>f+s,0)}readFloat32Array(e,t,n){if(t<0||n<=0)return null;let r=this.getBuffers(e),f=t,s=0,a=new Float32Array(n);for(let u of r){let o=u.byteLength;if(f>=o){f-=o;continue}let l=Math.floor((o-f)/4),B=Math.min(l,n-s);if(B>0){let y=Math.floor(f/4)*4,p=new Float32Array(u.getArrayBuffer(),y,B);a.set(p,s),s+=B}if(f=0,s>=n)break}return s>=n?a:null}printMemoryUsage(){console.log(`Memory Usage in Memory Manager
|
|
2
|
+
`);let e=t=>{let n=this.getLayerCountOfTheBufferUsage(t);for(let r=0;r<n;r++){let f=this.getBuffer(t,r);f!=null&&console.log(`${t.str} ${r}: ${f.takenSizeInByte} byte of ${f.byteLength} bytes. (${f.takenSizeInByte/f.byteLength*100} %) `)}};e(i.CPUGeneric),e(i.GPUInstanceData),e(i.GPUVertexData)}dumpBuffer(e){let t=this.getLayerCountOfTheBufferUsage(e);for(let n=0;n<t;n++){let r=this.getBuffer(e,n);r!=null&&d.downloadArrayBuffer(e.str+n,r.getArrayBuffer())}}destroy(){this.Bf.clear(),this.gf.clear()}};export{h as MemoryManager};
|
|
@@ -63,6 +63,7 @@ export declare const ShaderSemantics: Readonly<{
|
|
|
63
63
|
SheenEnvTexture: ShaderSemanticsEnum;
|
|
64
64
|
InverseEnvironment: ShaderSemanticsEnum;
|
|
65
65
|
IBLParameter: ShaderSemanticsEnum;
|
|
66
|
+
IBLMipLevelSkip: ShaderSemanticsEnum;
|
|
66
67
|
ViewPosition: ShaderSemanticsEnum;
|
|
67
68
|
Wireframe: ShaderSemanticsEnum;
|
|
68
69
|
DiffuseColorFactor: ShaderSemanticsEnum;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{_from as
|
|
1
|
+
import{_from as Gt,_fromString as $t,_fromStringCaseSensitively as zt,EnumClass as Vt}from"../misc/EnumIO.js";import{CompositionType as m}from"./CompositionType.js";var n=class n extends Vt{constructor({str:t}){super({index:++n.nc*n._scale,str:t,noCheckStrUnique:!0}),n.sc[this.index]=this}static getShaderSemanticByIndex(t){return this.sc[Math.abs(t)-Math.abs(t)%this._scale]}static isNonArrayShaderSemanticIndex(t){return t>=this._scale}static isArrayAndZeroIndexShaderSemanticIndex(t){return t<0&&Math.abs(t)%n._scale===0}static isArrayAndNonZeroIndexShaderSemanticIndex(t){return t<0&&Math.abs(t)%n._scale!==0}static getIndexCount(){return n.nc}};n.nc=-1,n._scale=1e4,n.sc=[];var e=n,S=new e({str:"worldMatrix"}),d=new e({str:"viewMatrix"}),h=new e({str:"isBillboard"}),l=new e({str:"enableViewMatrix"}),x=new e({str:"projectionMatrix"}),T=new e({str:"normalMatrix"}),w=new e({str:"boneMatrix"}),p=new e({str:"baseColorFactor"}),E=new e({str:"baseColorTexture"}),g=new e({str:"normalTexture"}),f=new e({str:"metallicRoughnessTexture"}),C=new e({str:"occlusionTexture"}),I=new e({str:"emissiveFactor"}),y=new e({str:"emissiveTexture"}),R=new e({str:"lightNumber"}),b=new e({str:"lightPosition"}),v=new e({str:"lightDirection"}),M=new e({str:"lightIntensity"}),F=new e({str:"lightProperty"}),P=new e({str:"metallicRoughnessFactor"}),k=new e({str:"brdfLutTexture"}),B=new e({str:"diffuseEnvTexture"}),N=new e({str:"specularEnvTexture"}),D=new e({str:"sheenEnvTexture"}),L=new e({str:"inverseEnvironment"}),O=new e({str:"iblParameter"}),A=new e({str:"iblMipLevelSkip"}),G=new e({str:"viewPosition"}),$=new e({str:"wireframe"}),z=new e({str:"diffuseColorFactor"}),V=new e({str:"diffuseColorTexture"}),_=new e({str:"shininess"}),H=new e({str:"shadingModel"}),j=new e({str:"skinningMode"}),Q=new e({str:"generalTexture"}),W=new e({str:"boneQuaternion"}),U=new e({str:"boneTranslateScale"}),K=new e({str:"boneTranslatePackedQuat"}),Z=new e({str:"boneScalePackedQuat"}),q=new e({str:"boneCompressedChunk"}),J=new e({str:"boneCompressedInfo"}),X=new e({str:"pointSize"}),Y=new e({str:"colorEnvTexture"}),ee=new e({str:"pointDistanceAttenuation"}),te=new e({str:"hdriFormat"}),ne=new e({str:"screenInfo"}),re=new e({str:"depthTexture"}),se=new e({str:"lightViewProjectionMatrix"}),ae=new e({str:"anisotropy"}),oe=new e({str:"clearcoatParameter"}),ie=new e({str:"sheenColorFactor"}),ce=new e({str:"sheenColorTexture"}),ue=new e({str:"sheenRoughnessFactor"}),me=new e({str:"sheenRoughnessTexture"}),Se=new e({str:"sheenLutTexture"}),de=new e({str:"specularGlossinessFactor"}),he=new e({str:"specularGlossinessTexture"}),le=new e({str:"entityUID"}),xe=new e({str:"morphTargetNumber"}),Te=new e({str:"dataTextureMorphOffsetPosition"}),we=new e({str:"morphWeights"}),pe=new e({str:"currentComponentSIDs"}),Ee=new e({str:"alphaCutoff"}),ge=new e({str:"alphaTexture"}),fe=new e({str:"makeOutputSrgb"}),_t=new e({str:"framebufferSize"}),Ce=new e({str:"clearCoatFactor"}),Ie=new e({str:"clearCoatTexture"}),ye=new e({str:"clearCoatRoughnessFactor"}),Re=new e({str:"clearCoatRoughnessTexture"}),be=new e({str:"clearCoatNormalTexture"}),ve=new e({str:"transmissionFactor"}),Me=new e({str:"transmissionTexture"}),Fe=new e({str:"backBufferTexture"}),Pe=new e({str:"backBufferTextureSize"}),ke=new e({str:"thicknessFactor"}),Be=new e({str:"thicknessTexture"}),Ne=new e({str:"attenuationDistance"}),De=new e({str:"attenuationColor"}),Le=new e({str:"isOutputHDR"}),Oe=new e({str:"baseColorTextureTransform"}),Ae=new e({str:"baseColorTextureRotation"}),Ge=new e({str:"normalTextureTransform"}),$e=new e({str:"normalTextureRotation"}),ze=new e({str:"metallicRoughnessTextureTransform"}),Ve=new e({str:"metallicRoughnessTextureRotation"}),_e=new e({str:"normalTexcoordIndex"}),He=new e({str:"baseColorTexcoordIndex"}),je=new e({str:"metallicRoughnessTexcoordIndex"}),Qe=new e({str:"occlusionTexcoordIndex"}),We=new e({str:"occlusionTextureTransform"}),Ue=new e({str:"occlusionTextureRotation"}),Ke=new e({str:"emissiveTexcoordIndex"}),Ze=new e({str:"emissiveTextureTransform"}),qe=new e({str:"emissiveTextureRotation"}),Je=new e({str:"normalScale"}),Xe=new e({str:"occlusionStrength"}),Ye=new e({str:"envRotation"}),et=new e({str:"envHdriFormat"}),tt=new e({str:"vrState"}),nt=new e({str:"enableLinearToSrgb"}),rt=new e({str:"specularFactor"}),st=new e({str:"specularTexture"}),at=new e({str:"specularColorFactor"}),ot=new e({str:"specularColorTexture"}),it=new e({str:"ior"}),ct=new e({str:"depthBiasPV"}),ut=new e({str:"clearCoatTextureTransform"}),mt=new e({str:"clearCoatTextureRotation"}),St=new e({str:"clearCoatRoughnessTextureTransform"}),dt=new e({str:"clearCoatRoughnessTextureRotation"}),ht=new e({str:"clearCoatNormalTextureTransform"}),lt=new e({str:"clearCoatNormalTextureRotation"}),xt=new e({str:"clearCoatTexcoordIndex"}),Tt=new e({str:"clearCoatRoughnessTexcoordIndex"}),wt=new e({str:"clearCoatNormalTexcoordIndex"}),pt=new e({str:"iridescenceFactor"}),Et=new e({str:"iridescenceTexture"}),gt=new e({str:"iridescenceIor"}),ft=new e({str:"iridescenceThicknessMinimum"}),Ct=new e({str:"iridescenceThicknessMaximum"}),It=new e({str:"iridescenceThicknessTexture"}),yt=new e({str:"gaussianKernelSize"}),Rt=new e({str:"gaussianRatio"}),bt=new e({str:"isHorizontal"}),vt=new e({str:"anisotropyStrength"}),Mt=new e({str:"anisotropyRotation"}),Ft=new e({str:"anisotropyTexture"}),Pt=new e({str:"emissiveStrength"}),kt=new e({str:"time"}),Bt=new e({str:"cubeMapFaceId"}),Nt=new e({str:"roughness"}),Dt=new e({str:"distributionType"}),i=[S,d,h,l,x,T,w,p,E,g,f,C,I,y,R,b,v,M,F,P,k,B,N,D,L,O,A,G,$,z,V,_,H,j,Q,W,U,K,Z,q,J,X,Y,ee,te,ne,re,se,ae,oe,ie,ce,ue,me,Se,de,he,le,xe,Te,we,pe,Ee,ge,fe,Ce,Ie,ye,Re,be,ve,Me,Fe,Pe,ke,Be,Ne,De,Le,Oe,Ae,Ge,$e,ze,Ve,_e,He,je,Qe,We,Ue,Ke,Ze,qe,Je,Xe,Ye,et,tt,nt,rt,st,at,ot,it,ct,ut,mt,St,dt,ht,lt,xt,Tt,wt,pt,Et,gt,ft,Ct,It,yt,Rt,bt,vt,Mt,Ft,Pt,kt,Bt,Nt,Dt];function Ht(r){return Gt({typeList:i,index:r})}function jt(r){return $t({typeList:i,str:r})}function Qt(r){return zt({typeList:i,str:r})}function qt(r){return r.index}function Wt(r,t,a){return Lt(r,a)}function Lt(r,t){let a=t.compositionType.getGlslStr(t.componentType),s=t.semantic,Ot=t.compositionType.getGlslStr(t.componentType),c="";t.arrayLength&&(c=`[${t.arrayLength}]`);let At=` uniform ${Ot} u_${s}${c};
|
|
2
2
|
`,o="";m.isArray(t.compositionType)?(s.match(/\[.+?\]/)?s=s.replace(/\[.+?\]/g,"[i]"):s+="[i]",o+=`
|
|
3
3
|
${a} val;
|
|
4
4
|
int i = int(index);
|
|
@@ -7,4 +7,4 @@ import{_from as At,_fromString as Gt,_fromStringCaseSensitively as $t,EnumClass
|
|
|
7
7
|
${a} get_${t.semantic}(uint instanceId, uint index) {
|
|
8
8
|
${o}
|
|
9
9
|
}
|
|
10
|
-
`),`${
|
|
10
|
+
`),`${At}${u}`}var Jt=Object.freeze({from:Ht,fromString:jt,fromStringCaseSensitively:Qt,getShaderPropertyOfMaterial:Wt,getShaderPropertyOfGlobalDataRepository:Lt,WorldMatrix:S,ViewMatrix:d,IsBillboard:h,EnableViewMatrix:l,ProjectionMatrix:x,NormalMatrix:T,BoneMatrix:w,BaseColorFactor:p,BaseColorTexture:E,NormalTexture:g,MetallicRoughnessTexture:f,OcclusionTexture:C,EmissiveFactor:I,EmissiveTexture:y,LightNumber:R,LightPosition:b,LightDirection:v,LightIntensity:M,LightProperty:F,MetallicRoughnessFactor:P,BrdfLutTexture:k,DiffuseEnvTexture:B,SpecularEnvTexture:N,SheenEnvTexture:D,InverseEnvironment:L,IBLParameter:O,IBLMipLevelSkip:A,ViewPosition:G,Wireframe:$,DiffuseColorFactor:z,DiffuseColorTexture:V,Shininess:_,ShadingModel:H,SkinningMode:j,GeneralTexture:Q,BoneQuaternion:W,BoneTranslateScale:U,BoneTranslatePackedQuat:K,BoneScalePackedQuat:Z,BoneCompressedChunk:q,BoneCompressedInfo:J,PointSize:X,ColorEnvTexture:Y,PointDistanceAttenuation:ee,HDRIFormat:te,ScreenInfo:ne,DepthTexture:re,LightViewProjectionMatrix:se,Anisotropy:ae,ClearCoatParameter:oe,SheenColorFactor:ie,SheenColorTexture:ce,SheenRoughnessFactor:ue,SheenRoughnessTexture:me,SheenLutTexture:Se,SpecularGlossinessFactor:de,SpecularGlossinessTexture:he,ClearCoatFactor:Ce,ClearCoatTexture:Ie,ClearCoatRoughnessFactor:ye,ClearCoatRoughnessTexture:Re,ClearCoatNormalTexture:be,TransmissionFactor:ve,TransmissionTexture:Me,BackBufferTexture:Fe,BackBufferTextureSize:Pe,ThicknessFactor:ke,ThicknessTexture:Be,AttenuationDistance:Ne,AttenuationColor:De,EntityUID:le,MorphTargetNumber:xe,DataTextureMorphOffsetPosition:Te,MorphWeights:we,CurrentComponentSIDs:pe,AlphaCutoff:Ee,AlphaTexture:ge,MakeOutputSrgb:fe,FramebufferSize:_t,IsOutputHDR:Le,BaseColorTextureTransform:Oe,BaseColorTextureRotation:Ae,NormalTextureTransform:Ge,NormalTextureRotation:$e,MetallicRoughnessTextureTransform:ze,MetallicRoughnessTextureRotation:Ve,NormalTexcoordIndex:_e,BaseColorTexcoordIndex:He,MetallicRoughnessTexcoordIndex:je,OcclusionTexcoordIndex:Qe,OcclusionTextureTransform:We,OcclusionTextureRotation:Ue,EmissiveTexcoordIndex:Ke,EmissiveTextureTransform:Ze,EmissiveTextureRotation:qe,NormalScale:Je,OcclusionStrength:Xe,envRotation:Ye,EnvHdriFormat:et,VrState:tt,EnableLinearToSrgb:nt,SpecularFactor:rt,SpecularTexture:st,SpecularColorFactor:at,SpecularColorTexture:ot,Ior:it,DepthBiasPV:ct,ClearCoatTextureTransform:ut,ClearCoatTextureRotation:mt,ClearCoatRoughnessTextureTransform:St,ClearCoatRoughnessTextureRotation:dt,ClearCoatNormalTextureTransform:ht,ClearCoatNormalTextureRotation:lt,ClearCoatTexcoordIndex:xt,ClearCoatRoughnessTexcoordIndex:Tt,ClearCoatNormalTexcoordIndex:wt,IridescenceFactor:pt,IridescenceTexture:Et,IridescenceIor:gt,IridescenceThicknessMinimum:ft,IridescenceThicknessMaximum:Ct,IridescenceThicknessTexture:It,GaussianKernelSize:yt,GaussianRatio:Rt,IsHorizontal:bt,AnisotropyStrength:vt,AnisotropyRotation:Mt,AnisotropyTexture:Ft,EmissiveStrength:Pt,Time:kt,CubeMapFaceId:Bt,Roughness:Nt,DistributionType:Dt});export{Jt as ShaderSemantics,e as ShaderSemanticsClass,qt as _getPropertyIndex2};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LightComponent as S}from"../../components/Light/LightComponent.js";import{RaymarchingComponent as T}from"../../components/Raymarching/RaymarchingComponent.js";import{TransformComponent as D}from"../../components/Transform/index.js";import{ComponentType as B}from"../../definitions/ComponentType.js";import{LightType as x}from"../../definitions/LightType.js";import{PixelFormat as G}from"../../definitions/PixelFormat.js";import{TextureFormat as C}from"../../definitions/TextureFormat.js";import{TextureParameter as L}from"../../definitions/TextureParameter.js";import{AABB as F}from"../../math/AABB.js";import{Matrix44 as k}from"../../math/Matrix44.js";import{VectorN as w}from"../../math/VectorN.js";import{Logger as _}from"../../misc/Logger.js";import{Expression as I}from"../../renderer/Expression.js";import{Sampler as z}from"../../textures/Sampler.js";import{attachLightShadowCamera as W}from"../EntityHelper.js";import{GaussianBlur as U}from"../GaussianBlurHelper.js";import{RenderableHelper as R}from"../RenderableHelper.js";import{PointShadowMap as q}from"./PointShadowMap.js";import{ShadowMap as O}from"./ShadowMap.js";var M=class M{constructor(n,h){this.Vm=[];this.Um=[];this.qm=[];this.Om=[];this.bf=!1;this.jm=0;this.Vf=[];this.Km=-1;this.wf=-1;this.Pf=-1;this.Zm=-1;this.Hm=new F;this.Xm=!1;this.Jm=[];this.zm=[];this.i=n,this.Nm=new O(n),this.vm=new q(n),this.Wm=new U(n);let[a,e]=R.createFrameBufferTextureArray(n,{width:h,height:h,arrayLength:n.config.maxLightNumberOrOne,level:0,internalFormat:C.RG16F,format:G.RG,type:B.Float});this.Ym=a;let[i,r]=R.createFrameBufferTextureArray(n,{width:h,height:h,arrayLength:n.config.maxLightNumberOrOne,level:0,internalFormat:C.RGBA16F,format:G.RGBA,type:B.Float});this.xf=i}getExpressions(n,h=[],a){var m,c,f,u;if(this.Ff=a,this.i.config.maxLightNumber<=0)return[];this.vf(n),this.Gf(n);let e=n.filter(M.Qm),i=[],r=new Array(this.i.config.maxLightNumber).fill(-1),t=new Array(this.i.config.maxLightNumber).fill(1e3),l=0,g=0,o=this.i.componentRepository.getComponentsWithType(S);this.Vm.length=o.length,this.Um.length=o.length,this.qm.length=o.length,this.Om.length=o.length,this.Df(o,e.length>0||((m=a==null?void 0:a.hasCaster())!=null?m:!1));for(let s of o)s._shadowSlot>=0&&W(this.i,s.entity);for(let s=0;s<o.length;s++){let p=o[s];this.Vm[s]=p.type,this.Um[s]=p.enable,this.qm[s]=p.castShadow,this.Om[s]=p.componentSID;let y=p._shadowSlot;if(!(y<0)){if(p.type===x.Point){let d=this.If(p,n),b=new I,P=this.vm.getRenderPasses(e,p.entity,y,d),E=(c=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.vm.getShadowMomentFramebuffer(),kind:"paraboloidFront",shadowSlot:y,farPlane:d}))!=null?c:[],A=(f=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.vm.getShadowMomentFramebuffer(),kind:"paraboloidBack",shadowSlot:y,farPlane:d}))!=null?f:[];b.addRenderPasses([P[0],...E,P[1],...A]),i.push(b);let{blurExpression:v,blurredRenderTarget:V,renderPassesBlurred:j}=this.Wm.createGaussianBlurExpression({textureToBlur:this.vm.getShadowMomentFramebuffer().getColorAttachedRenderTargetTexture(0),parameters:{blurPassLevel:3,gaussianKernelSize:5,gaussianVariance:5,synthesizeCoefficient:[1/4,1/4,1/4,1/4,1/4,1/4],isReduceBuffer:!0,textureFormat:C.RGBA16F,outputFrameBuffer:this.xf,outputFrameBufferLayerIndex:g}});this.kf(V,n,h),i.push(v),r[y]=g,t[y]=d,g++}else if(p.type===x.Spot||p.type===x.Directional){let d=new I,b=this.Nm.getRenderPasses(e,p.entity),P=(u=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.Nm.getShadowMomentFramebuffer(),kind:"regular",shadowSlot:y}))!=null?u:[];d.addRenderPasses([...b,...P]),i.push(d);let{blurExpression:E,blurredRenderTarget:A,renderPassesBlurred:v}=this.Wm.createGaussianBlurExpression({textureToBlur:this.Nm.getShadowMomentFramebuffer().getColorAttachedRenderTargetTexture(0),parameters:{blurPassLevel:3,gaussianKernelSize:5,gaussianVariance:5,synthesizeCoefficient:[1/4,1/4,1/4,1/4,1/4,1/4],isReduceBuffer:!0,textureFormat:C.RG16F,outputFrameBuffer:this.Ym,outputFrameBufferLayerIndex:l}});this._f(A,n,h),i.push(E),r[y]=l,l++}}}return this.Jm=r,this.Wf(n,r,h),this.zm=t,this.zf(n,t,h),i}Df(n,h){let a=this.i.config.maxLightNumber,e=new Array(a).fill(!1),i=r=>h&&r.enable&&r.castShadow&&(r.type===x.Point||r.type===x.Spot||r.type===x.Directional);for(let r of n){let t=r.componentSID;i(r)&&t<a?(r._shadowSlot=t,e[t]=!0):r._shadowSlot=-1}for(let r of n){if(!i(r)||r.componentSID<a)continue;let t=e.indexOf(!1);if(t<0){this.bf||(_.default.warn(`ShadowSystem: More than Config.maxLightNumber (${a}) lights cast shadows. The other lights do not cast shadows.`),this.bf=!0);continue}r._shadowSlot=t,e[t]=!0}}_f(n,h,a=[]){let e=new z(this.i,{minFilter:L.Linear,magFilter:L.Linear,wrapS:L.ClampToEdge,wrapT:L.ClampToEdge});e.create();for(let i of h){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setTextureParameter("depthTexture",n,e)}for(let i of a)i.setTextureParameter("depthTexture",n,e);this.km={texture:n,sampler:e}}kf(n,h,a=[]){let e=new z(this.i,{minFilter:L.Linear,magFilter:L.Linear,wrapS:L.ClampToEdge,wrapT:L.ClampToEdge});e.create();for(let i of h){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++){let l=r.mesh.getPrimitiveAt(t);l.material.setTextureParameter("paraboloidDepthTexture",n,e),l.material.setParameter("pointLightShadowMapUvScale",.93)}}for(let i of a)i.setTextureParameter("paraboloidDepthTexture",n,e),i.setParameter("pointLightShadowMapUvScale",.93);this._m={texture:n,sampler:e}}Wf(n,h,a=[]){let e=new w(new Int32Array(h));for(let i of n){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setParameter("depthTextureIndexList",e)}for(let i of a)i.setParameter("depthTextureIndexList",e)}If(n,h){let a=n.pointLightShadowFarPlane;if(a>0)return a;if(n.range>0)return n.range;let e=this.qf(n,h),i=n._lightPropertyForGpu._v[1];return i>0?Math.min(e,i):e}qf(n,h){let a=n._lightPositionForGpu._v,e={x:a[0],y:a[1],z:a[2]},i=0,r=h.filter(l=>M.Qm(l)&&!M.Rf(l));for(let l of r){let g=l.getSceneGraph();if(!g.isVisible)continue;let o=g.worldMergedAABB;if(o!=null&&!o.isVanilla()){let m=o.minPoint,c=o.maxPoint,f=Math.max(Math.abs(e.x-m.x),Math.abs(e.x-c.x)),u=Math.max(Math.abs(e.y-m.y),Math.abs(e.y-c.y)),s=Math.max(Math.abs(e.z-m.z),Math.abs(e.z-c.z));i=Math.max(i,f*f+u*u+s*s)}else{let m=g.worldPosition,c=m.x-e.x,f=m.y-e.y,u=m.z-e.z;i=Math.max(i,c*c+f*f+u*u)}}let t=this.i.componentRepository.getComponentsWithType(T);for(let l of t){let g=l.entity.tryToGetSceneGraph();if(g==null||!g.isVisible)continue;let o=l.calcWorldAABB();if(o==null||o.isVanilla())continue;let m=o.minPoint,c=o.maxPoint,f=Math.max(Math.abs(e.x-m.x),Math.abs(e.x-c.x)),u=Math.max(Math.abs(e.y-m.y),Math.abs(e.y-c.y)),s=Math.max(Math.abs(e.z-m.z),Math.abs(e.z-c.z));i=Math.max(i,f*f+u*u+s*s)}return i<=0?1e3:Math.sqrt(i)*1.05+.1}updatePointLightFarPlanes(n,h=[]){var l,g;if(this.i.config.maxLightNumber<=0)return;let e=this.i.componentRepository.getComponentsWithType(S).filter(o=>o.type===x.Point&&o.enable&&o.castShadow&&o._shadowSlot>=0);if(e.length===0)return;let i=this.i.config.maxLightNumber,r=new Array(i).fill(1e3);for(let o of e)r[o._shadowSlot]=this.If(o,n);let t=this.zm.length!==i;if(!t){for(let o=0;o<i;o++)if(Math.abs(r[o]-this.zm[o])>1e-4){t=!0;break}}if(t){for(let o of e){let m=o._shadowSlot;this.vm.setFarPlane(m,r[m]),(g=(l=this.Ff)==null?void 0:l.updatePointLightFarPlane)==null||g.call(l,m,r[m])}this.zm=r,this.zf(n,r,h)}}zf(n,h,a=[]){let e=new w(new Float32Array(h));for(let i of n){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setParameter("pointLightFarPlane",e)}for(let i of a)i.setParameter("pointLightFarPlane",e)}Gf(n){let a=this.i.componentRepository.getComponentsWithType(S).filter(i=>i.type===x.Spot&&i.enable&&i.castShadow);if(a.length===0)return;let e=n.filter(i=>M.Qm(i)&&!M.Rf(i));for(let i of a){let r=i._lightPositionForGpu._v,t={x:r[0],y:r[1],z:r[2]},l=Number.MAX_VALUE;for(let m of e){let c=m.getSceneGraph(),f=c.worldMergedAABB,u;if(f!=null&&!f.isVanilla()){let s=f.minPoint,p=f.maxPoint;if(s.x<=t.x&&t.x<=p.x&&s.y<=t.y&&t.y<=p.y&&s.z<=t.z&&t.z<=p.z)continue;let y=t.x<s.x?s.x-t.x:t.x>p.x?t.x-p.x:0,d=t.y<s.y?s.y-t.y:t.y>p.y?t.y-p.y:0,b=t.z<s.z?s.z-t.z:t.z>p.z?t.z-p.z:0;u=y*y+d*d+b*b}else{let s=c.worldPosition,p=s.x-t.x,y=s.y-t.y,d=s.z-t.z;u=p*p+y*y+d*d}u<l&&(l=u)}let g=this.i.componentRepository.getComponentsWithType(T);for(let m of g){let c=m.entity.tryToGetSceneGraph();if(c==null||!c.isVisible||m.entity.getTagValue("type")==="background-assets")continue;let f=c.worldMergedAABB;if(f.isVanilla())continue;let u=f.minPoint,s=f.maxPoint;if(u.x<=t.x&&t.x<=s.x&&u.y<=t.y&&t.y<=s.y&&u.z<=t.z&&t.z<=s.z)continue;let p=t.x<u.x?u.x-t.x:t.x>s.x?t.x-s.x:0,y=t.y<u.y?u.y-t.y:t.y>s.y?t.y-s.y:0,d=t.z<u.z?u.z-t.z:t.z>s.z?t.z-s.z:0,b=p*p+y*y+d*d;b<l&&(l=b)}let o=.1;if(i.range>0&&Number.isFinite(l)){let m=Math.min(i.range*.05,1);o=Math.max(.01,Math.min(Math.sqrt(l)*.5,m))}i._setShadowZNearForSpotLightAuto(o)}}static Rf(n){try{let h=n.getLight;return typeof h=="function"&&h.call(n)!=null}catch{return!1}}setDepthBiasPV(n,h=[]){if(this.i.config.maxLightNumber<=0)return;this.vf(n),this.Gf(n),this.updatePointLightFarPlanes(n,h);let a=this.i.config.maxLightNumber*16,e=this.Lf,i=this.Sf,r=this.Tf;e==null||i==null||r==null||e.length!==a?(e=new Float32Array(a),i=new w(e),r=new Float32Array(a),this.Lf=e,this.Sf=i,this.Tf=r,this.jm++):r.fill(0);let t=this.i.componentRepository._getComponents(S);if(t!=null){let o=this.i.config.maxLightNumber;for(let m=0;m<t.length;m++){let c=t[m];if(c==null)continue;let f=c._shadowSlot;if(!(f<0||f>=o)&&(c.type===x.Directional||c.type===x.Spot)){let s=c.entity.tryToGetCamera();if(s!=null){let p=s.biasViewProjectionMatrix;r.set(p._v,f*16)}}}}for(let o=0;o<a;o++)if(r[o]!==e[o]){e.set(r),this.jm++;break}let l=this.jm,g=this.Vf;for(let o=0;o<n.length;o++){let m=n[o].tryToGetMesh(),c=m==null?void 0:m.mesh;if(c!=null){let f=c.getPrimitiveNumber();for(let u=0;u<f;u++){let s=c.getPrimitiveAt(u).material,p=s.materialUID;g[p]!==l&&(s.setParameter("depthBiasPV",i),s._allFieldsInfo.has("depthBiasPV")&&(g[p]=l))}}}for(let o of h){let m=o.materialUID;g[m]!==l&&(o.setParameter("depthBiasPV",i),o._allFieldsInfo.has("depthBiasPV")&&(g[m]=l))}}applyShadowParametersToMaterials(n){if(this.i.config.maxLightNumber<=0)return;let h=new w(new Int32Array(this.Jm.length>0?this.Jm:new Array(this.i.config.maxLightNumber).fill(-1))),a=new w(new Float32Array(this.zm.length>0?this.zm:new Array(this.i.config.maxLightNumber).fill(1e3)));for(let e of n)e.setParameter("depthTextureIndexList",h),e.setParameter("pointLightFarPlane",a),this.km!=null&&e.setTextureParameter("depthTexture",this.km.texture,this.km.sampler),this._m!=null&&(e.setTextureParameter("paraboloidDepthTexture",this._m.texture,this._m.sampler),e.setParameter("pointLightShadowMapUvScale",.93))}static Qm(n){return n.getTagValue("type")!=="background-assets"}vf(n){let h=D.getUpdateCount(this.i),a=this.jf(),e=T.getAABBVersion(this.i);if(h===this.Km&&n.length===this.wf&&a===this.Pf&&e===this.Zm){this.Nf(this.Hm);return}let i=n.filter(l=>{if(!l.getSceneGraph().isVisible)return!1;let o=l.tryToGetMesh();return!(o==null||o.mesh==null||typeof l.matchTag=="function"&&l.matchTag("type","background-assets"))}),r=i.length>0?i:n,t=new F;for(let l of r){let g=l.getSceneGraph().worldMergedAABBWithSkeletal;t.mergeAABB(g)}this.Kf(t),!t.isVanilla()&&(this.Km=h,this.wf=n.length,this.Pf=a,this.Zm=e,this.Hm.copyComponents(t),this.Nf(this.Hm))}invalidateShadowVolumeFitting(){this.Km=-1,this.Zm=-1}jf(){return this.i.componentRepository.getComponentsWithType(T).length}Kf(n){let h=this.i.componentRepository.getComponentsWithType(T);for(let a of h){let e=a.entity.tryToGetSceneGraph();if(e==null||!e.isVisible||a.entity.getTagValue("type")==="background-assets")continue;let i=e.worldMergedAABBWithSkeletal;i.isVanilla()||n.mergeAABB(i)}}Nf(n){let e=this.i.componentRepository._getComponents(S);if(e!=null)for(let i=0;i<e.length;i++){let r=e[i];if(r==null||!(r.enable&&r.castShadow)||r.type!==x.Directional)continue;let l=r.entity.getSceneGraph().matrixInner,g=k.invert(l);F.multiplyMatrixTo(g,n,M.Af);let o=M.Af,m=o.minPoint,c=o.maxPoint,f=Math.max(-c.z,0),u=Math.max(-m.z,f+.001),s=Math.max(f/1.25,.01),p=Math.max(u*1.25,s+.01),d=Math.max(Math.abs(m.x),Math.abs(c.x),Math.abs(m.y),Math.abs(c.y),1)*1.15;r.shadowAreaSizeForDirectionalLight=d,r.shadowZNearForDirectionalLight=s,r.range=p}}isLightChanged(){if(this.Xm)return this.Xm=!1,!0;let n=this.i.componentRepository.getComponentsWithType(S);if(this.Vm.length!==n.length)return!0;for(let h=0;h<n.length;h++){let a=n[h];if(this.Vm[h]!==a.type||this.Um[h]!==a.enable||this.qm[h]!==a.castShadow||this.Om[h]!==a.componentSID)return!0}return!1}setNeedsRefresh(){this.Xm=!0}};M.Af=new F;var N=M;export{N as ShadowSystem};
|
|
1
|
+
import{LightComponent as S}from"../../components/Light/LightComponent.js";import{RaymarchingComponent as T}from"../../components/Raymarching/RaymarchingComponent.js";import{TransformComponent as D}from"../../components/Transform/index.js";import{ComponentType as B}from"../../definitions/ComponentType.js";import{LightType as x}from"../../definitions/LightType.js";import{PixelFormat as G}from"../../definitions/PixelFormat.js";import{TextureFormat as C}from"../../definitions/TextureFormat.js";import{TextureParameter as L}from"../../definitions/TextureParameter.js";import{AABB as F}from"../../math/AABB.js";import{Matrix44 as k}from"../../math/Matrix44.js";import{VectorN as w}from"../../math/VectorN.js";import{Logger as _}from"../../misc/Logger.js";import{Expression as I}from"../../renderer/Expression.js";import{Sampler as z}from"../../textures/Sampler.js";import{attachLightShadowCamera as W}from"../EntityHelper.js";import{GaussianBlur as U}from"../GaussianBlurHelper.js";import{RenderableHelper as R}from"../RenderableHelper.js";import{PointShadowMap as q}from"./PointShadowMap.js";import{ShadowMap as O}from"./ShadowMap.js";var M=class M{constructor(n,h){this.Vm=[];this.Um=[];this.qm=[];this.Om=[];this.bf=!1;this.jm=0;this.Df=[];this.Km=-1;this.Pf=-1;this.Ff=-1;this.Zm=-1;this.Hm=new F;this.Xm=!1;this.Jm=[];this.zm=[];this.i=n,this.Nm=new O(n),this.vm=new q(n),this.Wm=new U(n);let[a,e]=R.createFrameBufferTextureArray(n,{width:h,height:h,arrayLength:n.config.maxLightNumberOrOne,level:0,internalFormat:C.RG16F,format:G.RG,type:B.Float});this.Ym=a;let[i,r]=R.createFrameBufferTextureArray(n,{width:h,height:h,arrayLength:n.config.maxLightNumberOrOne,level:0,internalFormat:C.RGBA16F,format:G.RGBA,type:B.Float});this.xf=i}getExpressions(n,h=[],a){var m,c,f,u;if(this.Af=a,this.i.config.maxLightNumber<=0)return[];this.Gf(n),this.If(n);let e=n.filter(M.Qm),i=[],r=new Array(this.i.config.maxLightNumber).fill(-1),t=new Array(this.i.config.maxLightNumber).fill(1e3),l=0,g=0,o=this.i.componentRepository.getComponentsWithType(S);this.Vm.length=o.length,this.Um.length=o.length,this.qm.length=o.length,this.Om.length=o.length,this.kf(o,e.length>0||((m=a==null?void 0:a.hasCaster())!=null?m:!1));for(let s of o)s._shadowSlot>=0&&W(this.i,s.entity);for(let s=0;s<o.length;s++){let p=o[s];this.Vm[s]=p.type,this.Um[s]=p.enable,this.qm[s]=p.castShadow,this.Om[s]=p.componentSID;let y=p._shadowSlot;if(!(y<0)){if(p.type===x.Point){let d=this.zf(p,n),b=new I,P=this.vm.getRenderPasses(e,p.entity,y,d),E=(c=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.vm.getShadowMomentFramebuffer(),kind:"paraboloidFront",shadowSlot:y,farPlane:d}))!=null?c:[],A=(f=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.vm.getShadowMomentFramebuffer(),kind:"paraboloidBack",shadowSlot:y,farPlane:d}))!=null?f:[];b.addRenderPasses([P[0],...E,P[1],...A]),i.push(b);let{blurExpression:v,blurredRenderTarget:V,renderPassesBlurred:j}=this.Wm.createGaussianBlurExpression({textureToBlur:this.vm.getShadowMomentFramebuffer().getColorAttachedRenderTargetTexture(0),parameters:{blurPassLevel:3,gaussianKernelSize:5,gaussianVariance:5,synthesizeCoefficient:[1/4,1/4,1/4,1/4,1/4,1/4],isReduceBuffer:!0,textureFormat:C.RGBA16F,outputFrameBuffer:this.xf,outputFrameBufferLayerIndex:g}});this._f(V,n,h),i.push(v),r[y]=g,t[y]=d,g++}else if(p.type===x.Spot||p.type===x.Directional){let d=new I,b=this.Nm.getRenderPasses(e,p.entity),P=(u=a==null?void 0:a.createPasses({lightComponent:p,lightEntity:p.entity,framebuffer:this.Nm.getShadowMomentFramebuffer(),kind:"regular",shadowSlot:y}))!=null?u:[];d.addRenderPasses([...b,...P]),i.push(d);let{blurExpression:E,blurredRenderTarget:A,renderPassesBlurred:v}=this.Wm.createGaussianBlurExpression({textureToBlur:this.Nm.getShadowMomentFramebuffer().getColorAttachedRenderTargetTexture(0),parameters:{blurPassLevel:3,gaussianKernelSize:5,gaussianVariance:5,synthesizeCoefficient:[1/4,1/4,1/4,1/4,1/4,1/4],isReduceBuffer:!0,textureFormat:C.RG16F,outputFrameBuffer:this.Ym,outputFrameBufferLayerIndex:l}});this.Wf(A,n,h),i.push(E),r[y]=l,l++}}}return this.Jm=r,this.qf(n,r,h),this.zm=t,this.Rf(n,t,h),i}kf(n,h){let a=this.i.config.maxLightNumber,e=new Array(a).fill(!1),i=r=>h&&r.enable&&r.castShadow&&(r.type===x.Point||r.type===x.Spot||r.type===x.Directional);for(let r of n){let t=r.componentSID;i(r)&&t<a?(r._shadowSlot=t,e[t]=!0):r._shadowSlot=-1}for(let r of n){if(!i(r)||r.componentSID<a)continue;let t=e.indexOf(!1);if(t<0){this.bf||(_.default.warn(`ShadowSystem: More than Config.maxLightNumber (${a}) lights cast shadows. The other lights do not cast shadows.`),this.bf=!0);continue}r._shadowSlot=t,e[t]=!0}}Wf(n,h,a=[]){let e=new z(this.i,{minFilter:L.Linear,magFilter:L.Linear,wrapS:L.ClampToEdge,wrapT:L.ClampToEdge});e.create();for(let i of h){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setTextureParameter("depthTexture",n,e)}for(let i of a)i.setTextureParameter("depthTexture",n,e);this.km={texture:n,sampler:e}}_f(n,h,a=[]){let e=new z(this.i,{minFilter:L.Linear,magFilter:L.Linear,wrapS:L.ClampToEdge,wrapT:L.ClampToEdge});e.create();for(let i of h){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++){let l=r.mesh.getPrimitiveAt(t);l.material.setTextureParameter("paraboloidDepthTexture",n,e),l.material.setParameter("pointLightShadowMapUvScale",.93)}}for(let i of a)i.setTextureParameter("paraboloidDepthTexture",n,e),i.setParameter("pointLightShadowMapUvScale",.93);this._m={texture:n,sampler:e}}qf(n,h,a=[]){let e=new w(new Int32Array(h));for(let i of n){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setParameter("depthTextureIndexList",e)}for(let i of a)i.setParameter("depthTextureIndexList",e)}zf(n,h){let a=n.pointLightShadowFarPlane;if(a>0)return a;if(n.range>0)return n.range;let e=this.jf(n,h),i=n._lightPropertyForGpu._v[1];return i>0?Math.min(e,i):e}jf(n,h){let a=n._lightPositionForGpu._v,e={x:a[0],y:a[1],z:a[2]},i=0,r=h.filter(l=>M.Qm(l)&&!M.Nf(l));for(let l of r){let g=l.getSceneGraph();if(!g.isVisible)continue;let o=g.worldMergedAABB;if(o!=null&&!o.isVanilla()){let m=o.minPoint,c=o.maxPoint,f=Math.max(Math.abs(e.x-m.x),Math.abs(e.x-c.x)),u=Math.max(Math.abs(e.y-m.y),Math.abs(e.y-c.y)),s=Math.max(Math.abs(e.z-m.z),Math.abs(e.z-c.z));i=Math.max(i,f*f+u*u+s*s)}else{let m=g.worldPosition,c=m.x-e.x,f=m.y-e.y,u=m.z-e.z;i=Math.max(i,c*c+f*f+u*u)}}let t=this.i.componentRepository.getComponentsWithType(T);for(let l of t){let g=l.entity.tryToGetSceneGraph();if(g==null||!g.isVisible)continue;let o=l.calcWorldAABB();if(o==null||o.isVanilla())continue;let m=o.minPoint,c=o.maxPoint,f=Math.max(Math.abs(e.x-m.x),Math.abs(e.x-c.x)),u=Math.max(Math.abs(e.y-m.y),Math.abs(e.y-c.y)),s=Math.max(Math.abs(e.z-m.z),Math.abs(e.z-c.z));i=Math.max(i,f*f+u*u+s*s)}return i<=0?1e3:Math.sqrt(i)*1.05+.1}updatePointLightFarPlanes(n,h=[]){var l,g;if(this.i.config.maxLightNumber<=0)return;let e=this.i.componentRepository.getComponentsWithType(S).filter(o=>o.type===x.Point&&o.enable&&o.castShadow&&o._shadowSlot>=0);if(e.length===0)return;let i=this.i.config.maxLightNumber,r=new Array(i).fill(1e3);for(let o of e)r[o._shadowSlot]=this.zf(o,n);let t=this.zm.length!==i;if(!t){for(let o=0;o<i;o++)if(Math.abs(r[o]-this.zm[o])>1e-4){t=!0;break}}if(t){for(let o of e){let m=o._shadowSlot;this.vm.setFarPlane(m,r[m]),(g=(l=this.Af)==null?void 0:l.updatePointLightFarPlane)==null||g.call(l,m,r[m])}this.zm=r,this.Rf(n,r,h)}}Rf(n,h,a=[]){let e=new w(new Float32Array(h));for(let i of n){let r=i.tryToGetMesh();if(r!=null&&r.mesh!=null)for(let t=0;t<r.mesh.getPrimitiveNumber();t++)r.mesh.getPrimitiveAt(t).material.setParameter("pointLightFarPlane",e)}for(let i of a)i.setParameter("pointLightFarPlane",e)}If(n){let a=this.i.componentRepository.getComponentsWithType(S).filter(i=>i.type===x.Spot&&i.enable&&i.castShadow);if(a.length===0)return;let e=n.filter(i=>M.Qm(i)&&!M.Nf(i));for(let i of a){let r=i._lightPositionForGpu._v,t={x:r[0],y:r[1],z:r[2]},l=Number.MAX_VALUE;for(let m of e){let c=m.getSceneGraph(),f=c.worldMergedAABB,u;if(f!=null&&!f.isVanilla()){let s=f.minPoint,p=f.maxPoint;if(s.x<=t.x&&t.x<=p.x&&s.y<=t.y&&t.y<=p.y&&s.z<=t.z&&t.z<=p.z)continue;let y=t.x<s.x?s.x-t.x:t.x>p.x?t.x-p.x:0,d=t.y<s.y?s.y-t.y:t.y>p.y?t.y-p.y:0,b=t.z<s.z?s.z-t.z:t.z>p.z?t.z-p.z:0;u=y*y+d*d+b*b}else{let s=c.worldPosition,p=s.x-t.x,y=s.y-t.y,d=s.z-t.z;u=p*p+y*y+d*d}u<l&&(l=u)}let g=this.i.componentRepository.getComponentsWithType(T);for(let m of g){let c=m.entity.tryToGetSceneGraph();if(c==null||!c.isVisible||m.entity.getTagValue("type")==="background-assets")continue;let f=c.worldMergedAABB;if(f.isVanilla())continue;let u=f.minPoint,s=f.maxPoint;if(u.x<=t.x&&t.x<=s.x&&u.y<=t.y&&t.y<=s.y&&u.z<=t.z&&t.z<=s.z)continue;let p=t.x<u.x?u.x-t.x:t.x>s.x?t.x-s.x:0,y=t.y<u.y?u.y-t.y:t.y>s.y?t.y-s.y:0,d=t.z<u.z?u.z-t.z:t.z>s.z?t.z-s.z:0,b=p*p+y*y+d*d;b<l&&(l=b)}let o=.1;if(i.range>0&&Number.isFinite(l)){let m=Math.min(i.range*.05,1);o=Math.max(.01,Math.min(Math.sqrt(l)*.5,m))}i._setShadowZNearForSpotLightAuto(o)}}static Nf(n){try{let h=n.getLight;return typeof h=="function"&&h.call(n)!=null}catch{return!1}}setDepthBiasPV(n,h=[]){if(this.i.config.maxLightNumber<=0)return;this.Gf(n),this.If(n),this.updatePointLightFarPlanes(n,h);let a=this.i.config.maxLightNumber*16,e=this.Sf,i=this.Tf,r=this.wf;e==null||i==null||r==null||e.length!==a?(e=new Float32Array(a),i=new w(e),r=new Float32Array(a),this.Sf=e,this.Tf=i,this.wf=r,this.jm++):r.fill(0);let t=this.i.componentRepository._getComponents(S);if(t!=null){let o=this.i.config.maxLightNumber;for(let m=0;m<t.length;m++){let c=t[m];if(c==null)continue;let f=c._shadowSlot;if(!(f<0||f>=o)&&(c.type===x.Directional||c.type===x.Spot)){let s=c.entity.tryToGetCamera();if(s!=null){let p=s.biasViewProjectionMatrix;r.set(p._v,f*16)}}}}for(let o=0;o<a;o++)if(r[o]!==e[o]){e.set(r),this.jm++;break}let l=this.jm,g=this.Df;for(let o=0;o<n.length;o++){let m=n[o].tryToGetMesh(),c=m==null?void 0:m.mesh;if(c!=null){let f=c.getPrimitiveNumber();for(let u=0;u<f;u++){let s=c.getPrimitiveAt(u).material,p=s.materialUID;g[p]!==l&&(s.setParameter("depthBiasPV",i),s._allFieldsInfo.has("depthBiasPV")&&(g[p]=l))}}}for(let o of h){let m=o.materialUID;g[m]!==l&&(o.setParameter("depthBiasPV",i),o._allFieldsInfo.has("depthBiasPV")&&(g[m]=l))}}applyShadowParametersToMaterials(n){if(this.i.config.maxLightNumber<=0)return;let h=new w(new Int32Array(this.Jm.length>0?this.Jm:new Array(this.i.config.maxLightNumber).fill(-1))),a=new w(new Float32Array(this.zm.length>0?this.zm:new Array(this.i.config.maxLightNumber).fill(1e3)));for(let e of n)e.setParameter("depthTextureIndexList",h),e.setParameter("pointLightFarPlane",a),this.km!=null&&e.setTextureParameter("depthTexture",this.km.texture,this.km.sampler),this._m!=null&&(e.setTextureParameter("paraboloidDepthTexture",this._m.texture,this._m.sampler),e.setParameter("pointLightShadowMapUvScale",.93))}static Qm(n){return n.getTagValue("type")!=="background-assets"}Gf(n){let h=D.getUpdateCount(this.i),a=this.Kf(),e=T.getAABBVersion(this.i);if(h===this.Km&&n.length===this.Pf&&a===this.Ff&&e===this.Zm){this.Vf(this.Hm);return}let i=n.filter(l=>{if(!l.getSceneGraph().isVisible)return!1;let o=l.tryToGetMesh();return!(o==null||o.mesh==null||typeof l.matchTag=="function"&&l.matchTag("type","background-assets"))}),r=i.length>0?i:n,t=new F;for(let l of r){let g=l.getSceneGraph().worldMergedAABBWithSkeletal;t.mergeAABB(g)}this.Zf(t),!t.isVanilla()&&(this.Km=h,this.Pf=n.length,this.Ff=a,this.Zm=e,this.Hm.copyComponents(t),this.Vf(this.Hm))}invalidateShadowVolumeFitting(){this.Km=-1,this.Zm=-1}Kf(){return this.i.componentRepository.getComponentsWithType(T).length}Zf(n){let h=this.i.componentRepository.getComponentsWithType(T);for(let a of h){let e=a.entity.tryToGetSceneGraph();if(e==null||!e.isVisible||a.entity.getTagValue("type")==="background-assets")continue;let i=e.worldMergedAABBWithSkeletal;i.isVanilla()||n.mergeAABB(i)}}Vf(n){let e=this.i.componentRepository._getComponents(S);if(e!=null)for(let i=0;i<e.length;i++){let r=e[i];if(r==null||!(r.enable&&r.castShadow)||r.type!==x.Directional)continue;let l=r.entity.getSceneGraph().matrixInner,g=k.invert(l);F.multiplyMatrixTo(g,n,M.vf);let o=M.vf,m=o.minPoint,c=o.maxPoint,f=Math.max(-c.z,0),u=Math.max(-m.z,f+.001),s=Math.max(f/1.25,.01),p=Math.max(u*1.25,s+.01),d=Math.max(Math.abs(m.x),Math.abs(c.x),Math.abs(m.y),Math.abs(c.y),1)*1.15;r.shadowAreaSizeForDirectionalLight=d,r.shadowZNearForDirectionalLight=s,r.range=p}}isLightChanged(){if(this.Xm)return this.Xm=!1,!0;let n=this.i.componentRepository.getComponentsWithType(S);if(this.Vm.length!==n.length)return!0;for(let h=0;h<n.length;h++){let a=n[h];if(this.Vm[h]!==a.type||this.Um[h]!==a.enable||this.qm[h]!==a.castShadow||this.Om[h]!==a.componentSID)return!0}return!1}setNeedsRefresh(){this.Xm=!0}};M.vf=new F;var N=M;export{N as ShadowSystem};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{RaymarchingShaderPart as oe}from"../../../webgl/shaders/RaymarchingShaderPart.js";import{RaymarchingShadowShaderPart as ne}from"../../../webgl/shaders/RaymarchingShadowShaderPart.js";import{WellKnownComponentTIDs as ae}from"../../components/WellKnownComponentTIDs.js";import{TextureParameter as F}from"../../definitions/index.js";import{ComponentType as p}from"../../definitions/ComponentType.js";import{CompositionType as u}from"../../definitions/CompositionType.js";import{ShaderType as d}from"../../definitions/ShaderType.js";import{ShaderGraphResolver as G}from"../../materials/core/ShaderGraphResolver.js";import{Matrix44 as ie}from"../../math/Matrix44.js";import{Scalar as x}from"../../math/Scalar.js";import{Vector2 as Z}from"../../math/Vector2.js";import{Vector3 as U}from"../../math/Vector3.js";import{Vector4 as _}from"../../math/Vector4.js";import{getSharedSampler as re}from"../../textures/Sampler.js";import{addBackBufferTextureSemanticInfo as te,addPbrSheenSemanticInfo as se,buildTextureSemanticInfo as H,reuseOrRecreateCustomMaterial as q}from"./nodeBasedMaterialCommon.js";function me(n){n.push({semantic:"raymarchingBaseColor",componentType:p.Float,compositionType:u.Vec4,stage:d.PixelShader,initialValue:_.fromCopy4(.8,.8,.8,1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingMetallic",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(0),min:0,max:1}),n.push({semantic:"raymarchingRoughness",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(.5),min:0,max:1}),n.push({semantic:"raymarchingEmissive",componentType:p.Float,compositionType:u.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(0,0,0),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingEmissiveStrength",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingIor",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(1.5),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingSpecularWeight",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingSpecularColor",componentType:p.Float,compositionType:u.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(1,1,1),min:0,max:Number.MAX_VALUE})}function ce(n,a){let e=re(n,{minFilter:F.LinearMipmapLinear,magFilter:F.Linear,wrapS:F.ClampToEdge,wrapT:F.ClampToEdge,wrapR:F.ClampToEdge}),t=d.VertexAndPixelShader;a.push({semantic:"diffuseEnvTexture",componentType:p.Int,compositionType:u.TextureCube,stage:t,initialValue:[-1,n.dummyTextures.dummyBlackCubeTexture,e],min:0,max:Number.MAX_VALUE}),a.push({semantic:"specularEnvTexture",componentType:p.Int,compositionType:u.TextureCube,stage:t,initialValue:[-1,n.dummyTextures.dummyBlackCubeTexture,e],min:0,max:Number.MAX_VALUE}),a.push({semantic:"inverseEnvironment",componentType:p.Bool,compositionType:u.Scalar,stage:t,initialValue:x.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),a.push({semantic:"iblParameter",componentType:p.Float,compositionType:u.Vec4,stage:t,initialValue:_.fromCopy4(1,0,0,0),min:0,max:Number.MAX_VALUE}),a.push({semantic:"hdriFormat",componentType:p.Int,compositionType:u.Vec2,stage:t,initialValue:Z.fromCopy2(0,0),min:0,max:Number.MAX_VALUE})}function z(n){var t,s,i,r,l,T,P,I,g,A,h,b,R,N,M,E,y,f,o,c,V,C,O,L,w,X,D,B,$,j,J,W,k,K;let a=[],e=new Set;for(let m of n.nodes){if(m.name==="SdApplyWorldMatrix"&&m.controls.name.value){if(e.has(m.controls.name.value))continue;e.add(m.controls.name.value),a.push({semantic:m.controls.name.value,componentType:p.Float,compositionType:u.Mat4,stage:d.PixelShader,initialValue:ie.fromCopy16RowMajor(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),min:0,max:Number.MAX_VALUE})}if(m.name==="RaymarchObjectIdUniform"&&((s=(t=m.controls)==null?void 0:t.name)!=null&&s.value)){if(e.has(m.controls.name.value))continue;e.add(m.controls.name.value),a.push({semantic:m.controls.name.value,componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(0),min:0,max:Number.MAX_VALUE})}let S=(r=(i=m.controls)==null?void 0:i.name)==null?void 0:r.value;typeof S=="string"&&S.length>0&&(m.name==="UniformScalarFloat"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber((P=(T=(l=m.controls)==null?void 0:l.initialValue)==null?void 0:T.value)!=null?P:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector2Float"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:p.Float,compositionType:u.Vec2,stage:d.PixelShader,initialValue:Z.fromCopy2((A=(g=(I=m.controls)==null?void 0:I.initialX)==null?void 0:g.value)!=null?A:0,(R=(b=(h=m.controls)==null?void 0:h.initialY)==null?void 0:b.value)!=null?R:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector3Float"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:p.Float,compositionType:u.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3((E=(M=(N=m.controls)==null?void 0:N.initialX)==null?void 0:M.value)!=null?E:0,(o=(f=(y=m.controls)==null?void 0:y.initialY)==null?void 0:f.value)!=null?o:0,(C=(V=(c=m.controls)==null?void 0:c.initialZ)==null?void 0:V.value)!=null?C:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector4Float"&&!e.has(S)&&(e.add(S),a.push({semantic:S,componentType:p.Float,compositionType:u.Vec4,stage:d.PixelShader,initialValue:_.fromCopy4((w=(L=(O=m.controls)==null?void 0:O.initialX)==null?void 0:L.value)!=null?w:0,(B=(D=(X=m.controls)==null?void 0:X.initialY)==null?void 0:D.value)!=null?B:0,(J=(j=($=m.controls)==null?void 0:$.initialZ)==null?void 0:j.value)!=null?J:0,(K=(k=(W=m.controls)==null?void 0:W.initialW)==null?void 0:k.value)!=null?K:1),min:0,max:Number.MAX_VALUE})))}return a}function Q(n){n.push({semantic:"raymarchAabbMin",componentType:p.Float,compositionType:u.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(-1e20,-1e20,-1e20),min:-Number.MAX_VALUE,max:Number.MAX_VALUE}),n.push({semantic:"raymarchAabbMax",componentType:p.Float,compositionType:u.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(1e20,1e20,1e20),min:-Number.MAX_VALUE,max:Number.MAX_VALUE})}function le(n){let a=n.nodes,e=n.connections;if(a==null||e==null)return{useNormalTexture:!1,isOcclusion:!1,isClearcoat:!1,isSheen:!1,isIridescence:!1,isAnisotropy:!1,isDiffuseTransmission:!1,isSpecular:!1,isTransmission:!1,isVolume:!1,isDispersion:!1};let t=y=>a.find(f=>f.name===y),s=(y,f)=>e.find(o=>o.to.id===y&&o.to.portName===f),i=t("PbrShader"),r=t("PbrNormalProps"),l=(y,f)=>{var c;if(i==null)return!1;let o=s(i.id,f);return o==null?!1:((c=a.find(V=>V.id===o.from.id))==null?void 0:c.name)===y},T=(()=>{var o;if(i==null||r==null)return!1;let y=s(r.id,"normalTexture");if(y==null)return!1;let f=a.find(c=>c.id===y.from.id);return(f==null?void 0:f.name)!=="Texture2D"?!1:((o=s(i.id,"normalInWorld"))==null?void 0:o.from.id)===r.id})(),P=l("PbrOcclusionProps","occlusionProps"),I=l("PbrClearcoatProps","clearcoatProps"),g=l("PbrSheenProps","sheenProps"),A=l("PbrIridescenceProps","iridescenceProps"),h=l("PbrAnisotropyProps","anisotropyProps"),b=l("PbrDiffuseTransmissionProps","diffuseTransmissionProps"),R=l("PbrSpecularProps","specularProps"),N=l("PbrVolumeProps","volumeProps"),M=i!=null&&s(i.id,"transmission")!=null,E=i!=null&&s(i.id,"dispersion")!=null;return{useNormalTexture:T,isOcclusion:P,isClearcoat:I,isSheen:g,isIridescence:A,isAnisotropy:h,isDiffuseTransmission:b,isSpecular:R,isTransmission:M,isVolume:N,isDispersion:E}}function pe(n,a,e){let t=new oe,s=G.generateShaderCodeFromJson(n,a,t);if(!s)return;let i=z(a);Q(i),ce(n,i),me(i),i.push(...H(n,s.textureInfos));let r=le(a);r.isSheen&&se(n,i,{sheenEnvIsInternalSetting:!1}),r.isTransmission&&(i.some(T=>T.semantic==="backBufferTexture")||te(n,i,d.PixelShader));let l=q(n,s.vertexShader,s.pixelShader,{isLighting:!0,isPbr:!0,isShadow:!0,useNormalTexture:r.useNormalTexture,isOcclusion:r.isOcclusion,isClearcoat:r.isClearcoat,isSheen:r.isSheen,isIridescence:r.isIridescence,isAnisotropy:r.isAnisotropy,isDiffuseTransmission:r.isDiffuseTransmission,isSpecular:r.isSpecular,isTransmission:r.isTransmission,isVolume:r.isVolume,isDispersion:r.isDispersion,additionalShaderSemanticInfo:i},e);return l.shaderNodeJson=a,{material:l,hasPbrShaderNode:!1,hasClassicShaderNode:!1}}function Me(n,a,e){let t=v(n,a,"regular",e==null?void 0:e.regular),s=v(n,a,"paraboloidFront",e==null?void 0:e.paraboloidFront),i=v(n,a,"paraboloidBack",e==null?void 0:e.paraboloidBack);if(!(t==null||s==null||i==null))return{regular:t,paraboloidFront:s,paraboloidBack:i}}function v(n,a,e,t){let s=new ne(e),i=G.generateShaderCodeFromJson(n,a,s,["outDistance","outUnion"]);if(!i)return;let r=z(a);Q(r),r.push(...H(n,i.textureInfos)),e!=="regular"&&(r.push({semantic:"lightIndex",componentType:p.Int,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),r.push({semantic:"shadowFarPlane",componentType:p.Float,compositionType:u.Scalar,stage:d.PixelShader,initialValue:x.fromCopyNumber(1e3),min:0,max:Number.MAX_VALUE}));let l=q(n,i.vertexShader,i.pixelShader,{isLighting:!1,isPbr:!1,isShadow:!1,additionalShaderSemanticInfo:r},t);return e==="paraboloidFront"?l.colorWriteMask=[!0,!0,!1,!1]:e==="paraboloidBack"?l.colorWriteMask=[!1,!1,!0,!0]:l.colorWriteMask=[!0,!0,!1,!1],l.shaderNodeJson=a,l}function Ie(n,{castShadowOnly:a=!1}={}){var s,i,r,l,T,P;let e={nodes:[],connections:[]},t=n.componentRepository.getComponentsWithTID(ae.RaymarchingComponentTID);for(let I of t){let g=I;if(a&&!g.castShadow)continue;let A=g.rrnJson,h=`comp${g.componentSID}_`,b=A.nodes.map(o=>{let c={...o,id:`${h}${o.id}`};if(o.inputs){c.inputs={};for(let[V,C]of Object.entries(o.inputs))c.inputs[V]={...C,id:`${h}${C.id}`}}if(o.outputs){c.outputs={};for(let[V,C]of Object.entries(o.outputs))c.outputs[V]={...C,id:`${h}${C.id}`}}return c}),R=new Set(["UniformScalarFloat","UniformVector2Float","UniformVector3Float","UniformVector4Float"]);for(let o of b)if(R.has(o.name)){let c=(i=(s=o.controls)==null?void 0:s.name)==null?void 0:i.value;typeof c=="string"&&c.length>0&&(o.controls={...(r=o.controls)!=null?r:{},name:{value:`${c}_${g.componentSID}`}})}let N=A.connections.map(o=>({...o,id:`${h}${o.id}`,from:{...o.from,id:`${h}${o.from.id}`},to:{...o.to,id:`${h}${o.to.id}`}})),M=`${h}__raymarchObjectId`,E=`${h}__raymarchObjectIdOut`,y=b.filter(o=>(o.name==="OutUnion"||o.name==="OutDistance")&&!N.some(c=>c.to.id===o.id&&c.to.portName==="objectId"));if(y.length>0){b.push({id:M,name:"RaymarchObjectIdUniform",outputs:{out1:{id:E,label:"Out Object Id",socket:{name:"Scalar<float>"}}},inputs:{},controls:{name:{value:`raymarchObjectId_${g.componentSID}`}},position:{x:0,y:0}});for(let o of y)N.push({id:`${h}__raymarchObjectId_${o.id}`,from:{id:M,portName:"out1"},to:{id:o.id,portName:"objectId"}})}let f=[];for(let o of b)if(o.name==="SdApplyWorldMatrix"){let c=(T=(l=o.controls)==null?void 0:l.name)==null?void 0:T.value;typeof c=="string"&&c.length>0&&f.push(c)}if(f.length>0)for(let o of b)o.name!=="OutUnion"&&o.name!=="OutDistance"||(o.controls={...(P=o.controls)!=null?P:{},distanceCorrectionMatrices:{value:[...f]}});e.nodes.push(...b),e.connections.push(...N)}return e}var Y="raymarchingWorldMatrix";function ee(n){var t,s;let a=JSON.parse(JSON.stringify(n.rrnJson)),e=!1;for(let i of a.nodes)i.name==="SdApplyWorldMatrix"&&(i.controls={...(t=i.controls)!=null?t:{},name:{value:Y}},e=!0);if(e)for(let i of a.nodes)(i.name==="OutUnion"||i.name==="OutDistance")&&(i.controls={...(s=i.controls)!=null?s:{},distanceCorrectionMatrices:{value:[Y]}});return a}function Re(n,a,e){let t=ee(a);return pe(n,t,e)}function Ee(n,a,e,t){let s=ee(a);return v(n,s,e,t)}export{Y as RAYMARCHING_COMPONENT_WORLD_MATRIX_SEMANTIC,Q as addRaymarchingAabbSemanticInfo,z as addRaymarchingComponentSemanticsInfo,ce as addRaymarchingPbrIblSemanticInfo,me as addRaymarchingPbrSemanticInfo,Ie as collectRrnJson,Re as createNodeBasedRaymarchingComponentMaterial,Ee as createNodeBasedRaymarchingComponentShadowMaterial,pe as createNodeBasedRaymarchingCustomMaterial,v as createNodeBasedRaymarchingShadowMaterial,Me as createNodeBasedRaymarchingShadowMaterials,ee as createRaymarchingComponentShaderJson,le as detectRaymarchingPbrFeatures};
|
|
1
|
+
import{RaymarchingShaderPart as oe}from"../../../webgl/shaders/RaymarchingShaderPart.js";import{RaymarchingShadowShaderPart as ne}from"../../../webgl/shaders/RaymarchingShadowShaderPart.js";import{WellKnownComponentTIDs as ae}from"../../components/WellKnownComponentTIDs.js";import{TextureParameter as F}from"../../definitions/index.js";import{ComponentType as l}from"../../definitions/ComponentType.js";import{CompositionType as p}from"../../definitions/CompositionType.js";import{ShaderType as d}from"../../definitions/ShaderType.js";import{ShaderGraphResolver as G}from"../../materials/core/ShaderGraphResolver.js";import{Matrix44 as ie}from"../../math/Matrix44.js";import{Scalar as g}from"../../math/Scalar.js";import{Vector2 as Z}from"../../math/Vector2.js";import{Vector3 as U}from"../../math/Vector3.js";import{Vector4 as _}from"../../math/Vector4.js";import{getSharedSampler as re}from"../../textures/Sampler.js";import{addBackBufferTextureSemanticInfo as te,addPbrSheenSemanticInfo as se,buildTextureSemanticInfo as H,reuseOrRecreateCustomMaterial as q}from"./nodeBasedMaterialCommon.js";function me(n){n.push({semantic:"raymarchingBaseColor",componentType:l.Float,compositionType:p.Vec4,stage:d.PixelShader,initialValue:_.fromCopy4(.8,.8,.8,1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingMetallic",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(0),min:0,max:1}),n.push({semantic:"raymarchingRoughness",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(.5),min:0,max:1}),n.push({semantic:"raymarchingEmissive",componentType:l.Float,compositionType:p.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(0,0,0),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingEmissiveStrength",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingIor",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(1.5),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingSpecularWeight",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(1),min:0,max:Number.MAX_VALUE}),n.push({semantic:"raymarchingSpecularColor",componentType:l.Float,compositionType:p.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(1,1,1),min:0,max:Number.MAX_VALUE})}function ce(n,a){let e=re(n,{minFilter:F.LinearMipmapLinear,magFilter:F.Linear,wrapS:F.ClampToEdge,wrapT:F.ClampToEdge,wrapR:F.ClampToEdge}),t=d.VertexAndPixelShader;a.push({semantic:"diffuseEnvTexture",componentType:l.Int,compositionType:p.TextureCube,stage:t,initialValue:[-1,n.dummyTextures.dummyBlackCubeTexture,e],min:0,max:Number.MAX_VALUE}),a.push({semantic:"specularEnvTexture",componentType:l.Int,compositionType:p.TextureCube,stage:t,initialValue:[-1,n.dummyTextures.dummyBlackCubeTexture,e],min:0,max:Number.MAX_VALUE}),a.push({semantic:"inverseEnvironment",componentType:l.Bool,compositionType:p.Scalar,stage:t,initialValue:g.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),a.push({semantic:"iblParameter",componentType:l.Float,compositionType:p.Vec4,stage:t,initialValue:_.fromCopy4(1,0,0,0),min:0,max:Number.MAX_VALUE}),a.push({semantic:"iblMipLevelSkip",componentType:l.Float,compositionType:p.Scalar,stage:t,initialValue:g.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),a.push({semantic:"hdriFormat",componentType:l.Int,compositionType:p.Vec2,stage:t,initialValue:Z.fromCopy2(0,0),min:0,max:Number.MAX_VALUE})}function z(n){var t,s,i,r,u,T,P,E,x,A,h,b,R,N,M,I,y,f,o,c,V,C,O,L,w,X,D,B,$,j,J,k,W,K;let a=[],e=new Set;for(let m of n.nodes){if(m.name==="SdApplyWorldMatrix"&&m.controls.name.value){if(e.has(m.controls.name.value))continue;e.add(m.controls.name.value),a.push({semantic:m.controls.name.value,componentType:l.Float,compositionType:p.Mat4,stage:d.PixelShader,initialValue:ie.fromCopy16RowMajor(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),min:0,max:Number.MAX_VALUE})}if(m.name==="RaymarchObjectIdUniform"&&((s=(t=m.controls)==null?void 0:t.name)!=null&&s.value)){if(e.has(m.controls.name.value))continue;e.add(m.controls.name.value),a.push({semantic:m.controls.name.value,componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(0),min:0,max:Number.MAX_VALUE})}let S=(r=(i=m.controls)==null?void 0:i.name)==null?void 0:r.value;typeof S=="string"&&S.length>0&&(m.name==="UniformScalarFloat"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber((P=(T=(u=m.controls)==null?void 0:u.initialValue)==null?void 0:T.value)!=null?P:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector2Float"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:l.Float,compositionType:p.Vec2,stage:d.PixelShader,initialValue:Z.fromCopy2((A=(x=(E=m.controls)==null?void 0:E.initialX)==null?void 0:x.value)!=null?A:0,(R=(b=(h=m.controls)==null?void 0:h.initialY)==null?void 0:b.value)!=null?R:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector3Float"&&!e.has(S)?(e.add(S),a.push({semantic:S,componentType:l.Float,compositionType:p.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3((I=(M=(N=m.controls)==null?void 0:N.initialX)==null?void 0:M.value)!=null?I:0,(o=(f=(y=m.controls)==null?void 0:y.initialY)==null?void 0:f.value)!=null?o:0,(C=(V=(c=m.controls)==null?void 0:c.initialZ)==null?void 0:V.value)!=null?C:0),min:0,max:Number.MAX_VALUE})):m.name==="UniformVector4Float"&&!e.has(S)&&(e.add(S),a.push({semantic:S,componentType:l.Float,compositionType:p.Vec4,stage:d.PixelShader,initialValue:_.fromCopy4((w=(L=(O=m.controls)==null?void 0:O.initialX)==null?void 0:L.value)!=null?w:0,(B=(D=(X=m.controls)==null?void 0:X.initialY)==null?void 0:D.value)!=null?B:0,(J=(j=($=m.controls)==null?void 0:$.initialZ)==null?void 0:j.value)!=null?J:0,(K=(W=(k=m.controls)==null?void 0:k.initialW)==null?void 0:W.value)!=null?K:1),min:0,max:Number.MAX_VALUE})))}return a}function Q(n){n.push({semantic:"raymarchAabbMin",componentType:l.Float,compositionType:p.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(-1e20,-1e20,-1e20),min:-Number.MAX_VALUE,max:Number.MAX_VALUE}),n.push({semantic:"raymarchAabbMax",componentType:l.Float,compositionType:p.Vec3,stage:d.PixelShader,initialValue:U.fromCopy3(1e20,1e20,1e20),min:-Number.MAX_VALUE,max:Number.MAX_VALUE})}function le(n){let a=n.nodes,e=n.connections;if(a==null||e==null)return{useNormalTexture:!1,isOcclusion:!1,isClearcoat:!1,isSheen:!1,isIridescence:!1,isAnisotropy:!1,isDiffuseTransmission:!1,isSpecular:!1,isTransmission:!1,isVolume:!1,isDispersion:!1};let t=y=>a.find(f=>f.name===y),s=(y,f)=>e.find(o=>o.to.id===y&&o.to.portName===f),i=t("PbrShader"),r=t("PbrNormalProps"),u=(y,f)=>{var c;if(i==null)return!1;let o=s(i.id,f);return o==null?!1:((c=a.find(V=>V.id===o.from.id))==null?void 0:c.name)===y},T=(()=>{var o;if(i==null||r==null)return!1;let y=s(r.id,"normalTexture");if(y==null)return!1;let f=a.find(c=>c.id===y.from.id);return(f==null?void 0:f.name)!=="Texture2D"?!1:((o=s(i.id,"normalInWorld"))==null?void 0:o.from.id)===r.id})(),P=u("PbrOcclusionProps","occlusionProps"),E=u("PbrClearcoatProps","clearcoatProps"),x=u("PbrSheenProps","sheenProps"),A=u("PbrIridescenceProps","iridescenceProps"),h=u("PbrAnisotropyProps","anisotropyProps"),b=u("PbrDiffuseTransmissionProps","diffuseTransmissionProps"),R=u("PbrSpecularProps","specularProps"),N=u("PbrVolumeProps","volumeProps"),M=i!=null&&s(i.id,"transmission")!=null,I=i!=null&&s(i.id,"dispersion")!=null;return{useNormalTexture:T,isOcclusion:P,isClearcoat:E,isSheen:x,isIridescence:A,isAnisotropy:h,isDiffuseTransmission:b,isSpecular:R,isTransmission:M,isVolume:N,isDispersion:I}}function pe(n,a,e){let t=new oe,s=G.generateShaderCodeFromJson(n,a,t);if(!s)return;let i=z(a);Q(i),ce(n,i),me(i),i.push(...H(n,s.textureInfos));let r=le(a);r.isSheen&&se(n,i,{sheenEnvIsInternalSetting:!1}),r.isTransmission&&(i.some(T=>T.semantic==="backBufferTexture")||te(n,i,d.PixelShader));let u=q(n,s.vertexShader,s.pixelShader,{isLighting:!0,isPbr:!0,isShadow:!0,useNormalTexture:r.useNormalTexture,isOcclusion:r.isOcclusion,isClearcoat:r.isClearcoat,isSheen:r.isSheen,isIridescence:r.isIridescence,isAnisotropy:r.isAnisotropy,isDiffuseTransmission:r.isDiffuseTransmission,isSpecular:r.isSpecular,isTransmission:r.isTransmission,isVolume:r.isVolume,isDispersion:r.isDispersion,additionalShaderSemanticInfo:i},e);return u.shaderNodeJson=a,{material:u,hasPbrShaderNode:!1,hasClassicShaderNode:!1}}function Me(n,a,e){let t=v(n,a,"regular",e==null?void 0:e.regular),s=v(n,a,"paraboloidFront",e==null?void 0:e.paraboloidFront),i=v(n,a,"paraboloidBack",e==null?void 0:e.paraboloidBack);if(!(t==null||s==null||i==null))return{regular:t,paraboloidFront:s,paraboloidBack:i}}function v(n,a,e,t){let s=new ne(e),i=G.generateShaderCodeFromJson(n,a,s,["outDistance","outUnion"]);if(!i)return;let r=z(a);Q(r),r.push(...H(n,i.textureInfos)),e!=="regular"&&(r.push({semantic:"lightIndex",componentType:l.Int,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),r.push({semantic:"shadowFarPlane",componentType:l.Float,compositionType:p.Scalar,stage:d.PixelShader,initialValue:g.fromCopyNumber(1e3),min:0,max:Number.MAX_VALUE}));let u=q(n,i.vertexShader,i.pixelShader,{isLighting:!1,isPbr:!1,isShadow:!1,additionalShaderSemanticInfo:r},t);return e==="paraboloidFront"?u.colorWriteMask=[!0,!0,!1,!1]:e==="paraboloidBack"?u.colorWriteMask=[!1,!1,!0,!0]:u.colorWriteMask=[!0,!0,!1,!1],u.shaderNodeJson=a,u}function Ee(n,{castShadowOnly:a=!1}={}){var s,i,r,u,T,P;let e={nodes:[],connections:[]},t=n.componentRepository.getComponentsWithTID(ae.RaymarchingComponentTID);for(let E of t){let x=E;if(a&&!x.castShadow)continue;let A=x.rrnJson,h=`comp${x.componentSID}_`,b=A.nodes.map(o=>{let c={...o,id:`${h}${o.id}`};if(o.inputs){c.inputs={};for(let[V,C]of Object.entries(o.inputs))c.inputs[V]={...C,id:`${h}${C.id}`}}if(o.outputs){c.outputs={};for(let[V,C]of Object.entries(o.outputs))c.outputs[V]={...C,id:`${h}${C.id}`}}return c}),R=new Set(["UniformScalarFloat","UniformVector2Float","UniformVector3Float","UniformVector4Float"]);for(let o of b)if(R.has(o.name)){let c=(i=(s=o.controls)==null?void 0:s.name)==null?void 0:i.value;typeof c=="string"&&c.length>0&&(o.controls={...(r=o.controls)!=null?r:{},name:{value:`${c}_${x.componentSID}`}})}let N=A.connections.map(o=>({...o,id:`${h}${o.id}`,from:{...o.from,id:`${h}${o.from.id}`},to:{...o.to,id:`${h}${o.to.id}`}})),M=`${h}__raymarchObjectId`,I=`${h}__raymarchObjectIdOut`,y=b.filter(o=>(o.name==="OutUnion"||o.name==="OutDistance")&&!N.some(c=>c.to.id===o.id&&c.to.portName==="objectId"));if(y.length>0){b.push({id:M,name:"RaymarchObjectIdUniform",outputs:{out1:{id:I,label:"Out Object Id",socket:{name:"Scalar<float>"}}},inputs:{},controls:{name:{value:`raymarchObjectId_${x.componentSID}`}},position:{x:0,y:0}});for(let o of y)N.push({id:`${h}__raymarchObjectId_${o.id}`,from:{id:M,portName:"out1"},to:{id:o.id,portName:"objectId"}})}let f=[];for(let o of b)if(o.name==="SdApplyWorldMatrix"){let c=(T=(u=o.controls)==null?void 0:u.name)==null?void 0:T.value;typeof c=="string"&&c.length>0&&f.push(c)}if(f.length>0)for(let o of b)o.name!=="OutUnion"&&o.name!=="OutDistance"||(o.controls={...(P=o.controls)!=null?P:{},distanceCorrectionMatrices:{value:[...f]}});e.nodes.push(...b),e.connections.push(...N)}return e}var Y="raymarchingWorldMatrix";function ee(n){var t,s;let a=JSON.parse(JSON.stringify(n.rrnJson)),e=!1;for(let i of a.nodes)i.name==="SdApplyWorldMatrix"&&(i.controls={...(t=i.controls)!=null?t:{},name:{value:Y}},e=!0);if(e)for(let i of a.nodes)(i.name==="OutUnion"||i.name==="OutDistance")&&(i.controls={...(s=i.controls)!=null?s:{},distanceCorrectionMatrices:{value:[Y]}});return a}function Re(n,a,e){let t=ee(a);return pe(n,t,e)}function Ie(n,a,e,t){let s=ee(a);return v(n,s,e,t)}export{Y as RAYMARCHING_COMPONENT_WORLD_MATRIX_SEMANTIC,Q as addRaymarchingAabbSemanticInfo,z as addRaymarchingComponentSemanticsInfo,ce as addRaymarchingPbrIblSemanticInfo,me as addRaymarchingPbrSemanticInfo,Ee as collectRrnJson,Re as createNodeBasedRaymarchingComponentMaterial,Ie as createNodeBasedRaymarchingComponentShadowMaterial,pe as createNodeBasedRaymarchingCustomMaterial,v as createNodeBasedRaymarchingShadowMaterial,Me as createNodeBasedRaymarchingShadowMaterials,ee as createRaymarchingComponentShaderJson,le as detectRaymarchingPbrFeatures};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ProcessApproach as
|
|
1
|
+
import{ProcessApproach as b,TextureParameter as r}from"../../definitions/index.js";import{ComponentType as m}from"../../definitions/ComponentType.js";import{CompositionType as n}from"../../definitions/CompositionType.js";import{ShaderType as s}from"../../definitions/ShaderType.js";import{CustomMaterialContent as L}from"../../materials/contents/CustomMaterialContent.js";import{Scalar as h}from"../../math/Scalar.js";import{Vector2 as R}from"../../math/Vector2.js";import{Vector4 as U}from"../../math/Vector4.js";import{VectorN as x}from"../../math/VectorN.js";import{DataUtil as V}from"../../misc/DataUtil.js";import{getSharedSampler as d}from"../../textures/Sampler.js";import{reuseOrRecreateMaterial as M}from"./createMaterial.js";function Y(t,i,o,e={},u){var y,f,N,_,g,A,I;let p=`Custom_${V.toCRC32(i+o)}`,a=u?new Set(u.getShaderDefines()):new Set;e.isPbr?a.add("RN_USE_PBR"):a.delete("RN_USE_PBR");let l=e.additionalShaderSemanticInfo?[...e.additionalShaderSemanticInfo]:[];if(e.isLighting)if(a.add("RN_IS_LIGHTING"),e.isShadow&&t.config.maxLightNumber>0){a.add("RN_USE_SHADOW_MAPPING");let c=d(t,{minFilter:r.Linear,magFilter:r.Linear,wrapS:r.ClampToEdge,wrapT:r.ClampToEdge});l.push({semantic:"depthTexture",componentType:m.Int,compositionType:n.Texture2DArray,stage:s.VertexAndPixelShader,initialValue:[-1,t.dummyTextures.dummyDepthMomentTextureArray,c],min:0,max:Number.MAX_VALUE}),l.push({semantic:"paraboloidDepthTexture",componentType:m.Int,compositionType:n.Texture2DArray,stage:s.VertexAndPixelShader,initialValue:[-1,t.dummyTextures.dummyDepthMomentTextureArray,c],min:0,max:Number.MAX_VALUE}),l.push({semantic:"depthTextureIndexList",componentType:m.Int,compositionType:n.ScalarArray,arrayLength:t.config.maxLightNumber,stage:s.VertexAndPixelShader,initialValue:new x(new Int32Array(t.config.maxLightNumber)),min:0,max:Number.MAX_VALUE}),l.push({semantic:"depthBiasPV",componentType:m.Float,compositionType:n.Mat4Array,arrayLength:t.config.maxLightNumber,stage:s.VertexAndPixelShader,initialValue:new x(new Float32Array(t.config.maxLightNumber*16)),min:0,max:Number.MAX_VALUE}),l.push({semantic:"pointLightFarPlane",componentType:m.Float,compositionType:n.ScalarArray,arrayLength:t.config.maxLightNumber,stage:s.VertexAndPixelShader,initialValue:new x(new Float32Array(t.config.maxLightNumber).fill(1e3)),min:0,max:Number.MAX_VALUE}),l.push({semantic:"pointLightShadowMapUvScale",componentType:m.Float,compositionType:n.Scalar,stage:s.VertexAndPixelShader,initialValue:h.fromCopyNumber(.93),min:0,max:Number.MAX_VALUE})}else a.delete("RN_USE_SHADOW_MAPPING");else a.delete("RN_IS_LIGHTING"),a.delete("RN_USE_SHADOW_MAPPING");e.isSkinning&&a.add("RN_IS_SKINNING"),e.isMorphing&&a.add("RN_IS_MORPHING"),e.isOcclusion?a.add("RN_USE_OCCLUSION_TEXTURE"):a.delete("RN_USE_OCCLUSION_TEXTURE"),e.useNormalTexture?a.add("RN_USE_NORMAL_TEXTURE"):a.delete("RN_USE_NORMAL_TEXTURE"),e.isSpecular?a.add("RN_USE_SPECULAR"):a.delete("RN_USE_SPECULAR"),e.isSheen?a.add("RN_USE_SHEEN"):a.delete("RN_USE_SHEEN"),e.isIridescence?a.add("RN_USE_IRIDESCENCE"):a.delete("RN_USE_IRIDESCENCE"),e.isClearcoat?a.add("RN_USE_CLEARCOAT"):a.delete("RN_USE_CLEARCOAT"),e.isTransmission?a.add("RN_USE_TRANSMISSION"):a.delete("RN_USE_TRANSMISSION"),e.isVolume?a.add("RN_USE_VOLUME"):a.delete("RN_USE_VOLUME"),e.isAnisotropy?a.add("RN_USE_ANISOTROPY"):a.delete("RN_USE_ANISOTROPY"),e.isDiffuseTransmission?a.add("RN_USE_DIFFUSE_TRANSMISSION"):a.delete("RN_USE_DIFFUSE_TRANSMISSION"),e.isDispersion?a.add("RN_USE_DISPERSION"):a.delete("RN_USE_DISPERSION");let T;t.engineState.currentProcessApproach===b.WebGPU?T=new L(t,{name:p,isSkinning:(y=e.isSkinning)!=null?y:!0,isLighting:(f=e.isLighting)!=null?f:!0,isMorphing:(N=e.isMorphing)!=null?N:!0,vertexShaderWebGpu:{code:i,shaderStage:"vertex",isFragmentShader:!1},pixelShaderWebGpu:{code:o,shaderStage:"fragment",isFragmentShader:!0},additionalShaderSemanticInfo:l,definitions:Array.from(a)}):T=new L(t,{name:p,isSkinning:(_=e.isSkinning)!=null?_:!0,isLighting:(g=e.isLighting)!=null?g:!0,isMorphing:(A=e.isMorphing)!=null?A:!0,vertexShader:{code:i,shaderStage:"vertex",isFragmentShader:!1},pixelShader:{code:o,shaderStage:"fragment",isFragmentShader:!0},additionalShaderSemanticInfo:l,definitions:Array.from(a)});let E=M(t,T,(I=e.maxInstancesNumber)!=null?I:1,u);for(let c of a)E.addShaderDefine(c);return E}function q(t,i){let o=[],e=d(t,{minFilter:r.LinearMipmapLinear,magFilter:r.Linear,wrapS:r.Repeat,wrapT:r.Repeat});for(let u of i){let S;switch(u.stage){case"Vertex":S=s.VertexShader;break;case"Fragment":S=s.PixelShader;break;default:S=s.VertexAndPixelShader;break}let p=t.dummyTextures.dummyWhiteTexture;switch(u.defaultTexture){case"dummyBlackTexture":p=t.dummyTextures.dummyBlackTexture;break;case"dummyBlueTexture":p=t.dummyTextures.dummyBlueTexture;break;default:p=t.dummyTextures.dummyWhiteTexture;break}o.push({semantic:u.name,componentType:m.Int,compositionType:n.Texture2D,stage:S,initialValue:[-1,p,e],min:0,max:Number.MAX_VALUE})}return o}function K(t,i){let o=d(t,{minFilter:r.LinearMipmapLinear,magFilter:r.Linear,wrapS:r.ClampToEdge,wrapT:r.ClampToEdge,wrapR:r.ClampToEdge}),e=s.VertexAndPixelShader;i.push({semantic:"diffuseEnvTexture",componentType:m.Int,compositionType:n.TextureCube,stage:e,initialValue:[-1,t.dummyTextures.dummyBlackCubeTexture,o],min:0,max:Number.MAX_VALUE,isInternalSetting:!0}),i.push({semantic:"specularEnvTexture",componentType:m.Int,compositionType:n.TextureCube,stage:e,initialValue:[-1,t.dummyTextures.dummyBlackCubeTexture,o],min:0,max:Number.MAX_VALUE,isInternalSetting:!0}),i.push({semantic:"inverseEnvironment",componentType:m.Bool,compositionType:n.Scalar,stage:e,initialValue:h.fromCopyNumber(0),min:0,max:Number.MAX_VALUE}),i.push({semantic:"iblParameter",componentType:m.Float,compositionType:n.Vec4,stage:e,initialValue:U.fromCopy4(1,1,1,1),min:0,max:Number.MAX_VALUE,isInternalSetting:!0}),i.push({semantic:"iblMipLevelSkip",componentType:m.Float,compositionType:n.Scalar,stage:e,initialValue:h.fromCopyNumber(0),min:0,max:Number.MAX_VALUE,isInternalSetting:!0}),i.push({semantic:"hdriFormat",componentType:m.Int,compositionType:n.Vec2,stage:e,initialValue:R.fromCopy2(0,0),min:0,max:Number.MAX_VALUE,isInternalSetting:!0}),C(t,i,e)}function C(t,i,o){let e=d(t,{minFilter:r.LinearMipmapLinear,magFilter:r.Linear,wrapS:r.ClampToEdge,wrapT:r.ClampToEdge});i.push({semantic:"backBufferTexture",componentType:m.Int,compositionType:n.Texture2D,stage:o,initialValue:[-1,t.dummyTextures.dummyBlackTexture,e],min:0,max:Number.MAX_VALUE})}function $(t,i,{sheenEnvIsInternalSetting:o=!0}={}){t.dummyTextures.requestSheenLutTexture();let e=d(t,{minFilter:r.Linear,magFilter:r.Linear,wrapS:r.ClampToEdge,wrapT:r.ClampToEdge});i.push({semantic:"sheenLutTexture",componentType:m.Int,compositionType:n.Texture2D,stage:s.VertexAndPixelShader,initialValue:[-1,t.dummyTextures.sheenLutTexture,e],min:0,max:Number.MAX_VALUE});let u=d(t,{minFilter:r.LinearMipmapLinear,magFilter:r.Linear,wrapS:r.ClampToEdge,wrapT:r.ClampToEdge,wrapR:r.ClampToEdge});i.push({semantic:"sheenEnvTexture",componentType:m.Int,compositionType:n.TextureCube,stage:s.VertexAndPixelShader,isInternalSetting:o,initialValue:[-1,t.dummyTextures.dummyBlackCubeTexture,u],min:0,max:Number.MAX_VALUE})}export{C as addBackBufferTextureSemanticInfo,K as addPbrIblSemanticInfo,$ as addPbrSheenSemanticInfo,q as buildTextureSemanticInfo,Y as reuseOrRecreateCustomMaterial};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CompositionType as A}from"../definitions/CompositionType.js";import{PrimitiveMode as V}from"../definitions/PrimitiveMode.js";import{VertexAttribute as O}from"../definitions/VertexAttribute.js";import{Primitive as D}from"../geometry/Primitive.js";import{createClassicUberMaterial as I}from"../helpers/materials/createClassicUberMaterial.js";import{DataUtil as y}from"../misc/DataUtil.js";import{Is as _}from"../misc/Is.js";import{Logger as b}from"../misc/Logger.js";import{ifDefinedThen as T,ifUndefinedThen as M}from"../misc/MiscUtil.js";import{Err as B,Ok as g}from"../misc/Result.js";import{RnPromise as x}from"../misc/RnPromise.js";var R=class v{constructor(){}async importPointCloud(t,e){let r=`${t.substring(0,t.lastIndexOf("/"))}/`,n=y.createDefaultGltfOptions();if(e!=null&&e.files){for(let o in e.files)if(y.getExtension(o)==="drc"){let l=await this.$f(e.files[o],n,r,e);return new g(l)}}let s=await y.fetchArrayBuffer(t);if(s.isErr())return new B({message:"fetchArrayBuffer failed",error:s});let i=await this.$f(s.get(),n,r,e);return new g(i)}importArrayBuffer(t,e,r){let n=`${t.substring(0,t.lastIndexOf("/"))}/`,s=y.createDefaultGltfOptions();return this.$f(e,s,n,r).catch(i=>{b.default.error(`__loadFromArrayBuffer error: ${i}`)})}async vd(t,e,r,n){let s=new DataView(t,0,20),i=!0,o=s.getUint32(0,i),c;if(o!==1179937895){let l=y.arrayBufferToString(t),m=JSON.parse(l);c=await this._loadAsTextJson(m,n,e,r).catch(f=>{b.default.error(`this.__loadAsTextJson error: ${f}`)})}else c=await this._loadAsBinaryJson(s,i,t,n,e,r).catch(l=>{b.default.error(`this.__loadAsBinaryJson error: ${l}`)});return c}_getOptions(t,e,r){var n,s;if((s=(n=e.asset)==null?void 0:n.extras)!=null&&s.rnLoaderOptions)for(let i in e.asset.extras.rnLoaderOptions)t[i]=e.asset.extras.rnLoaderOptions[i];for(let i in r)t[i]=r[i];return r!=null&&r.loaderExtensionName&&typeof r.loaderExtensionName=="string"&&(Rn[r.loaderExtensionName]!=null?t.loaderExtension=Rn[r.loaderExtensionName].getInstance():(b.default.error(`${r.loaderExtensionName} not found!`),t.loaderExtension=void 0)),t}async _loadAsBinaryJson(t,e,r,n,s,i){let o=t.getUint32(12,e);if(t.getUint32(16,e)!==1313821514)throw new Error("invalid chunkType of chunk0 in this binary glTF file.");let l=new Uint8Array(r,20,o),m=y.uint8ArrayToString(l),f=JSON.parse(m);n=this._getOptions(s,f,n);let a=new Uint8Array(r,20+o+8);f.asset.extras===void 0&&(f.asset.extras={fileType:"glTF",version:"2"}),this._mergeExtendedJson(f,n.extendedJson),f.asset.extras.rnLoaderOptions=n;try{await this._loadInner(a,i,f,n)}catch(u){b.default.error(`this._loadInner error in _loadAsBinaryJson: ${u}`)}return f}async _loadAsTextJson(t,e,r,n){t.asset.extras===void 0&&(t.asset.extras={fileType:"glTF",version:"2"}),e=this._getOptions(r,t,e),this._mergeExtendedJson(t,e.extendedJson),t.asset.extras.rnLoaderOptions=e;try{await this._loadInner(void 0,n,t,e)}catch(s){b.default.error(`this._loadInner error in _loadAsTextJson: ${s}`)}return t}_loadInner(t,e,r,n){let s=[],i={shaders:[],buffers:[],images:[]};return s.push(this._loadResources(t,e,r,n,i)),s.push(new Promise(o=>{this._loadJsonContent(r,n),o()})),Promise.all(s)}_loadJsonContent(t,e){this._loadDependenciesOfScenes(t),this._loadDependenciesOfNodes(t),this._loadDependenciesOfMeshes(t),this._loadDependenciesOfMaterials(t),this._loadDependenciesOfTextures(t),this._loadDependenciesOfJoints(t),this._loadDependenciesOfAnimations(t),this._loadDependenciesOfAccessors(t),this._loadDependenciesOfBufferViews(t),t.asset.extras===void 0&&(t.asset.extras={})}_loadDependenciesOfScenes(t){for(let e of t.scenes)for(let r in e.nodes)e.nodesObjects[r]=t.nodes[e.nodes[r]]}_loadDependenciesOfNodes(t){for(let e of t.nodes){if(e.children){_.not.exist(e.childrenObjects)&&(e.childrenObjects=[]);for(let r in e.children)e.childrenObjects[r]=t.nodes[e.children[r]]}e.mesh!==void 0&&t.meshes!==void 0&&(e.meshObject=t.meshes[e.mesh]),e.skin!==void 0&&t.skins!==void 0&&(e.skinObject=t.skins[e.skin],e.meshObject.extras===void 0&&(e.meshObject.extras={}),e.meshObject.extras._skin=e.skin),e.camera!==void 0&&t.cameras!==void 0&&(e.cameraObject=t.cameras[e.camera]),e.extensions!==void 0&&t.extensions!==void 0&&t.extensions.KHR_lights_punctual!==void 0&&(e.extensions.KHR_lights_punctual.lightIndex=e.extensions.KHR_lights_punctual.light,e.extensions.KHR_lights_punctual.light=t.extensions.KHR_lights_punctual.lights[e.extensions.KHR_lights_punctual.lightIndex])}}_loadDependenciesOfMeshes(t){for(let e of t.meshes)for(let r of e.primitives){r.material!==void 0&&(r.materialObject=t.materials[r.material]);for(let n in r.attributes){let s=r.attributes[n],i=t.accessors[s];i.extras={},r.attributesObjects[n]=i}if(r.indices!=null&&(r.indicesObject=t.accessors[r.indices]),r.targets!=null){r.targetsObjects=[];for(let n of r.targets){let s={};for(let i in n){let o=n[i];if(o>=0){let c=t.accessors[o];c.extras={},s[i]=c}}r.targetsObjects.push(s)}}}}_checkRnGltfLoaderOptionsExist(t){var e;return!!((e=t.asset.extras)!=null&&e.rnLoaderOptions)}_loadDependenciesOfMaterials(t){if(t.textures||(t.textures=[]),t.materials)for(let e of t.materials){if(e.pbrMetallicRoughness){let o=e.pbrMetallicRoughness.baseColorTexture;o!==void 0&&(o.texture=t.textures[o.index]);let c=e.pbrMetallicRoughness.metallicRoughnessTexture;c!==void 0&&(c.texture=t.textures[c.index])}let r=e.normalTexture;r!==void 0&&(r.texture=t.textures[r.index]);let n=e.occlusionTexture;n!==void 0&&(n.texture=t.textures[n.index]);let s=e.emissiveTexture;s!==void 0&&(s.texture=t.textures[s.index]);let i=this._checkRnGltfLoaderOptionsExist(t)?t.asset.extras.rnLoaderOptions.loaderExtension:void 0;i!=null&&i.setTextures&&i.setTextures(t,e)}}_loadDependenciesOfTextures(t){if(t.textures)for(let e of t.textures)T(r=>{e.samplerObject=t.samplers[r]},e.sampler),e.source!==void 0&&(e.sourceObject=t.images[e.source])}_loadDependenciesOfJoints(t){if(t.skins){for(let e of t.skins)if(_.exist(e.skeleton)){e.skeletonObject=t.nodes[e.skeleton],T(r=>{e.inverseBindMatricesObject=t.accessors[r]},e.inverseBindMatrices),M(()=>{e.skeletonObject=t.nodes[e.joints[0]]},e.skeleton),e.jointsObjects=[];for(let r of e.joints)e.jointsObjects.push(t.nodes[r])}}}_loadDependenciesOfAnimations(t){if(t.animations)for(let e of t.animations){for(let r of e.channels)r.samplerObject=e.samplers[r.sampler],r.target.nodeObject=t.nodes[r.target.node];for(let r of e.channels)if(_.exist(r.samplerObject)&&(r.samplerObject.inputObject=t.accessors[r.samplerObject.input],r.samplerObject.outputObject=t.accessors[r.samplerObject.output],r.samplerObject.outputObject.extras===void 0&&(r.samplerObject.outputObject.extras={}),r.target.path==="rotation"&&(r.samplerObject.outputObject.extras.quaternionIfVec4=!0),r.target.path==="weights")){let n=r.samplerObject.outputObject.count/r.samplerObject.inputObject.count;r.samplerObject.outputObject.extras.weightsArrayLength=n}}}_loadDependenciesOfAccessors(t){for(let e of t.accessors)if(e.bufferView==null&&(e.bufferView=0),e.bufferViewObject=t.bufferViews[e.bufferView],e.sparse!=null){let r=e.sparse;r.indices.bufferViewObject=t.bufferViews[r.indices.bufferView],r.values.bufferViewObject=t.bufferViews[r.values.bufferView]}}_loadDependenciesOfBufferViews(t){for(let e of t.bufferViews)e.buffer!==void 0&&(e.bufferObject=t.buffers[e.buffer])}_mergeExtendedJson(t,e){let r=null;if(e instanceof ArrayBuffer){let n=y.arrayBufferToString(e);r=JSON.parse(n)}else typeof e=="string"?r=JSON.parse(e):typeof e=="object"&&(r=e);Object.assign(t,r)}_loadResources(t,e,r,n,s){var c,l;let i=[],o;for(let m in r.buffers){let f=r.buffers[m],a,u;f.uri&&(a=f.uri.split("/"),u=a[a.length-1]),typeof f.uri=="undefined"?o=new x(d=>{s.buffers[m]=t,f.buffer=t,d(t.buffer)}):f.uri.match(/^data:application\/(.*);base64,/)?o=new x(d=>{let p=y.dataUriToArrayBuffer(f.uri);s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)}):(c=n.files)!=null&&c[u]?o=new x(d=>{let p=n.files[u];s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)}):o=new x(y.loadResourceAsync(e+f.uri,!0,(d,p)=>{s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)},(d,p)=>{})),f.bufferPromise=o,i.push(o)}for(let m in r.images){let f=m,a=r.images[f],u;if(typeof a.uri=="undefined"){let p=y.createUint8ArrayFromBufferViewInfo(r,a.bufferView,t);u=y.createBlobImageUriFromUint8Array(p,a.mimeType)}else{let p=a.uri,h=p.split("/"),w=h[h.length-1];if((l=n.files)!=null&&l[w]){let j=n.files[w];u=y.createBlobImageUriFromUint8Array(new Uint8Array(j),a.mimeType)}else p.match(/^data:/)?u=p:u=e+p}let d=y.createImageFromUri(u,a.mimeType).then(p=>{p.crossOrigin="Anonymous",s.images[f]=p,a.image=p});i.push(d)}return Promise.all(i).catch(m=>{b.default.error(`Promise.all error: ${m}`)})}static getInstance(){return this.rc||(this.rc=new v),this.rc}$f(t,e,r,n){return this.Xf(t).then(s=>{let i=JSON.stringify(s),o=JSON.parse(i);return this._loadAsTextJson(o,n,e,r).catch(c=>{b.default.error(`this.__loadAsTextJson error: ${c}`)})})}Xf(t){let e=new DracoDecoderModule,r=new e.Decoder,n=this.Hf(e,r,t);if(n==null)throw new Error("invalid dracoGeometry.");if(n.geometryType!==e.POINT_CLOUD)throw new Error("invalid geometryType of drc file.");if(r.GetAttributeId(n,e.POSITION)===-1)throw e.destroy(r),e.destroy(n),new Error("Draco: No position attribute found.");let i=["POSITION","NORMAL","COLOR","TEX_COORD","GENERIC"],o=n.num_points(),c=[],l=[],m=0;for(let a=0;a<i.length;a++){let u=r.GetAttributeId(n,e[i[a]]);if(u===-1){i.splice(a,1),a--;continue}let d=r.GetAttribute(n,u),p=new e.DracoFloat32Array;r.GetAttributeFloatForAllPoints(n,d,p),c[a]=p;let h=d.num_components();l[a]=h,i[a]==="COLOR"?m+=o*4:m+=o*h}let f=new Float32Array(m);for(let a=0,u=0;a<i.length;a++){if(i[a]==="COLOR"&&l[a]===3)for(let d=0;d<o;u+=4,d+=3)f[u]=c[a].GetValue(d),f[u+1]=c[a].GetValue(d+1),f[u+2]=c[a].GetValue(d+2),f[u+3]=1;else if(i[a]==="TEX_COORD")for(let d=0;d<o;u+=2,d++)f[u]=c[a].GetValue(2*d),f[u+1]=1-c[a].GetValue(2*d+1);else for(let d=0;d<o*l[a];u++,d++)f[u]=c[a].GetValue(d);e.destroy(c[a])}return e.destroy(r),e.destroy(n),this.Yf(f,o,i,l)}async Yf(t,e,r,n){let s={asset:{version:"2.0"},extensionsUsed:["KHR_materials_unlit"],extensionsRequired:["KHR_materials_unlit"],nodes:[{name:"Node",mesh:0}],scenes:[{nodes:[0]}],materials:[{name:"point-cloud_material",pbrMetallicRoughness:{baseColorFactor:[1,1,1,1]},extensions:{KHR_materials_unlit:{}}}]};return await this.Zf(t.buffer,s),this.Qf(e,r,n,s),this.Jf(r,s),new Promise((i,o)=>{i(s)})}Zf(t,e){return this.bd(t).then(r=>{e.buffers=[{name:"input",byteLength:t.byteLength,uri:r}]}).catch(r=>{b.default.error(`this.__convertBufferToURI error: ${r}`)})}bd(t){return new Promise((e,r)=>{let n=new Blob([t],{type:"application/octet-stream"}),s=new FileReader;s.onload=()=>{e(s.result)},s.onerror=()=>{r(s.error)},s.readAsDataURL(n)})}Qf(t,e,r,n){let s=[],i=[],o=0;for(let c=0,l=0;c<e.length;l++){let m=r[c],f;m===1?f="SCALAR":f=`VEC${m}`;let a=0,u=e[c];for(;c<e.length&&(s.push({name:`point-cloud_${u}_${c}`,componentType:5126,count:t,type:f,bufferView:l,byteOffset:a}),e[c]==="COLOR"?a+=t*4*4:a+=t*m*4,c++,u===e[c]););i[l]={name:`bufferView_${u}`,buffer:0,byteLength:a,byteOffset:o,byteStride:m*4,target:34962},o+=a}n.accessors=s,n.bufferViews=i}Jf(t,e){let r={};for(let s=0;s<t.length;s++)t[s]==="TEX_COORD"?r.TEXCOORD_0=s:t[s]==="GENERIC"?r.TANGENT=s:r[t[s]]=s;let n={name:"Node-Mesh",primitives:[{mode:0,material:0,attributes:r}]};e.meshes=[n]}async importPointCloudToPrimitive(t,e){let r=await y.fetchArrayBuffer(e);return this.Od(t,r.unwrapForce())}Od(t,e){let r=new DracoDecoderModule,n=new r.Decoder,s=this.Hf(r,n,e);if(s==null)throw new Error("invalid dracoGeometry.");if(s.geometryType!==r.POINT_CLOUD)throw new Error("invalid geometryType of drc file.");let i=[],o=[],c=[];this.xd(r,n,s,i,o,c),this._d(r,n,s,i,o,c),this.wd(r,n,s,i,o,c),this.Td(r,n,s,i,o,c);let l=D.createPrimitive(t,{attributeSemantics:o,attributes:c,material:I(t,{isSkinning:!1,isLighting:!0}),primitiveMode:V.Points});return r.destroy(n),r.destroy(s),l}Hf(t,e,r){let n=new t.DecoderBuffer;n.Init(new Int8Array(r),r.byteLength);let s=e.GetEncodedGeometryType(n),i,o;if(s===t.TRIANGULAR_MESH?(i=new t.Mesh,o=e.DecodeBufferToMesh(n,i)):s===t.POINT_CLOUD?(i=new t.PointCloud,o=e.DecodeBufferToPointCloud(n,i)):b.default.error("Unknown geometry type."),i.geometryType=s,!o.ok()||i.ptr===0){let c="Decoding failed: ";c+=o.error_msg(),b.default.error(c),t.destroy(e),t.destroy(i);return}return t.destroy(n),i}xd(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.POSITION);if(o===-1)throw t.destroy(e),t.destroy(r),new Error("Draco: No position attribute found.");let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*3,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec3),s.push(O.Position.XYZ),i.push(a),t.destroy(l),a}_d(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.COLOR);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let m=r.num_points(),f=c.num_components(),a=m*4,u=new Float32Array(a);for(let d=0;d<a;d+=f)u[d]=l.GetValue(d),u[d+1]=l.GetValue(d+1),u[d+2]=l.GetValue(d+2),f===4?u[d+3]=l.GetValue(d+3):u[d+3]=1;return n.push(A.Vec3),s.push(O.Color0.XYZ),i.push(u),t.destroy(l),u}wd(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.NORMAL);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*3,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec3),s.push(O.Normal.XYZ),i.push(a),t.destroy(l),a}Td(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.TEX_COORD);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*2,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec2),s.push(O.Texcoord0.XY),i.push(a),t.destroy(l),a}};export{R as DrcPointCloudImporter};
|
|
1
|
+
import{CompositionType as A}from"../definitions/CompositionType.js";import{PrimitiveMode as V}from"../definitions/PrimitiveMode.js";import{VertexAttribute as O}from"../definitions/VertexAttribute.js";import{Primitive as D}from"../geometry/Primitive.js";import{createClassicUberMaterial as I}from"../helpers/materials/createClassicUberMaterial.js";import{DataUtil as y}from"../misc/DataUtil.js";import{Is as _}from"../misc/Is.js";import{Logger as b}from"../misc/Logger.js";import{ifDefinedThen as T,ifUndefinedThen as M}from"../misc/MiscUtil.js";import{Err as B,Ok as g}from"../misc/Result.js";import{RnPromise as x}from"../misc/RnPromise.js";var R=class v{constructor(){}async importPointCloud(t,e){let r=`${t.substring(0,t.lastIndexOf("/"))}/`,n=y.createDefaultGltfOptions();if(e!=null&&e.files){for(let o in e.files)if(y.getExtension(o)==="drc"){let l=await this.$f(e.files[o],n,r,e);return new g(l)}}let s=await y.fetchArrayBuffer(t);if(s.isErr())return new B({message:"fetchArrayBuffer failed",error:s});let i=await this.$f(s.get(),n,r,e);return new g(i)}importArrayBuffer(t,e,r){let n=`${t.substring(0,t.lastIndexOf("/"))}/`,s=y.createDefaultGltfOptions();return this.$f(e,s,n,r).catch(i=>{b.default.error(`__loadFromArrayBuffer error: ${i}`)})}async jd(t,e,r,n){let s=new DataView(t,0,20),i=!0,o=s.getUint32(0,i),c;if(o!==1179937895){let l=y.arrayBufferToString(t),m=JSON.parse(l);c=await this._loadAsTextJson(m,n,e,r).catch(f=>{b.default.error(`this.__loadAsTextJson error: ${f}`)})}else c=await this._loadAsBinaryJson(s,i,t,n,e,r).catch(l=>{b.default.error(`this.__loadAsBinaryJson error: ${l}`)});return c}_getOptions(t,e,r){var n,s;if((s=(n=e.asset)==null?void 0:n.extras)!=null&&s.rnLoaderOptions)for(let i in e.asset.extras.rnLoaderOptions)t[i]=e.asset.extras.rnLoaderOptions[i];for(let i in r)t[i]=r[i];return r!=null&&r.loaderExtensionName&&typeof r.loaderExtensionName=="string"&&(Rn[r.loaderExtensionName]!=null?t.loaderExtension=Rn[r.loaderExtensionName].getInstance():(b.default.error(`${r.loaderExtensionName} not found!`),t.loaderExtension=void 0)),t}async _loadAsBinaryJson(t,e,r,n,s,i){let o=t.getUint32(12,e);if(t.getUint32(16,e)!==1313821514)throw new Error("invalid chunkType of chunk0 in this binary glTF file.");let l=new Uint8Array(r,20,o),m=y.uint8ArrayToString(l),f=JSON.parse(m);n=this._getOptions(s,f,n);let a=new Uint8Array(r,20+o+8);f.asset.extras===void 0&&(f.asset.extras={fileType:"glTF",version:"2"}),this._mergeExtendedJson(f,n.extendedJson),f.asset.extras.rnLoaderOptions=n;try{await this._loadInner(a,i,f,n)}catch(u){b.default.error(`this._loadInner error in _loadAsBinaryJson: ${u}`)}return f}async _loadAsTextJson(t,e,r,n){t.asset.extras===void 0&&(t.asset.extras={fileType:"glTF",version:"2"}),e=this._getOptions(r,t,e),this._mergeExtendedJson(t,e.extendedJson),t.asset.extras.rnLoaderOptions=e;try{await this._loadInner(void 0,n,t,e)}catch(s){b.default.error(`this._loadInner error in _loadAsTextJson: ${s}`)}return t}_loadInner(t,e,r,n){let s=[],i={shaders:[],buffers:[],images:[]};return s.push(this._loadResources(t,e,r,n,i)),s.push(new Promise(o=>{this._loadJsonContent(r,n),o()})),Promise.all(s)}_loadJsonContent(t,e){this._loadDependenciesOfScenes(t),this._loadDependenciesOfNodes(t),this._loadDependenciesOfMeshes(t),this._loadDependenciesOfMaterials(t),this._loadDependenciesOfTextures(t),this._loadDependenciesOfJoints(t),this._loadDependenciesOfAnimations(t),this._loadDependenciesOfAccessors(t),this._loadDependenciesOfBufferViews(t),t.asset.extras===void 0&&(t.asset.extras={})}_loadDependenciesOfScenes(t){for(let e of t.scenes)for(let r in e.nodes)e.nodesObjects[r]=t.nodes[e.nodes[r]]}_loadDependenciesOfNodes(t){for(let e of t.nodes){if(e.children){_.not.exist(e.childrenObjects)&&(e.childrenObjects=[]);for(let r in e.children)e.childrenObjects[r]=t.nodes[e.children[r]]}e.mesh!==void 0&&t.meshes!==void 0&&(e.meshObject=t.meshes[e.mesh]),e.skin!==void 0&&t.skins!==void 0&&(e.skinObject=t.skins[e.skin],e.meshObject.extras===void 0&&(e.meshObject.extras={}),e.meshObject.extras._skin=e.skin),e.camera!==void 0&&t.cameras!==void 0&&(e.cameraObject=t.cameras[e.camera]),e.extensions!==void 0&&t.extensions!==void 0&&t.extensions.KHR_lights_punctual!==void 0&&(e.extensions.KHR_lights_punctual.lightIndex=e.extensions.KHR_lights_punctual.light,e.extensions.KHR_lights_punctual.light=t.extensions.KHR_lights_punctual.lights[e.extensions.KHR_lights_punctual.lightIndex])}}_loadDependenciesOfMeshes(t){for(let e of t.meshes)for(let r of e.primitives){r.material!==void 0&&(r.materialObject=t.materials[r.material]);for(let n in r.attributes){let s=r.attributes[n],i=t.accessors[s];i.extras={},r.attributesObjects[n]=i}if(r.indices!=null&&(r.indicesObject=t.accessors[r.indices]),r.targets!=null){r.targetsObjects=[];for(let n of r.targets){let s={};for(let i in n){let o=n[i];if(o>=0){let c=t.accessors[o];c.extras={},s[i]=c}}r.targetsObjects.push(s)}}}}_checkRnGltfLoaderOptionsExist(t){var e;return!!((e=t.asset.extras)!=null&&e.rnLoaderOptions)}_loadDependenciesOfMaterials(t){if(t.textures||(t.textures=[]),t.materials)for(let e of t.materials){if(e.pbrMetallicRoughness){let o=e.pbrMetallicRoughness.baseColorTexture;o!==void 0&&(o.texture=t.textures[o.index]);let c=e.pbrMetallicRoughness.metallicRoughnessTexture;c!==void 0&&(c.texture=t.textures[c.index])}let r=e.normalTexture;r!==void 0&&(r.texture=t.textures[r.index]);let n=e.occlusionTexture;n!==void 0&&(n.texture=t.textures[n.index]);let s=e.emissiveTexture;s!==void 0&&(s.texture=t.textures[s.index]);let i=this._checkRnGltfLoaderOptionsExist(t)?t.asset.extras.rnLoaderOptions.loaderExtension:void 0;i!=null&&i.setTextures&&i.setTextures(t,e)}}_loadDependenciesOfTextures(t){if(t.textures)for(let e of t.textures)T(r=>{e.samplerObject=t.samplers[r]},e.sampler),e.source!==void 0&&(e.sourceObject=t.images[e.source])}_loadDependenciesOfJoints(t){if(t.skins){for(let e of t.skins)if(_.exist(e.skeleton)){e.skeletonObject=t.nodes[e.skeleton],T(r=>{e.inverseBindMatricesObject=t.accessors[r]},e.inverseBindMatrices),M(()=>{e.skeletonObject=t.nodes[e.joints[0]]},e.skeleton),e.jointsObjects=[];for(let r of e.joints)e.jointsObjects.push(t.nodes[r])}}}_loadDependenciesOfAnimations(t){if(t.animations)for(let e of t.animations){for(let r of e.channels)r.samplerObject=e.samplers[r.sampler],r.target.nodeObject=t.nodes[r.target.node];for(let r of e.channels)if(_.exist(r.samplerObject)&&(r.samplerObject.inputObject=t.accessors[r.samplerObject.input],r.samplerObject.outputObject=t.accessors[r.samplerObject.output],r.samplerObject.outputObject.extras===void 0&&(r.samplerObject.outputObject.extras={}),r.target.path==="rotation"&&(r.samplerObject.outputObject.extras.quaternionIfVec4=!0),r.target.path==="weights")){let n=r.samplerObject.outputObject.count/r.samplerObject.inputObject.count;r.samplerObject.outputObject.extras.weightsArrayLength=n}}}_loadDependenciesOfAccessors(t){for(let e of t.accessors)if(e.bufferView==null&&(e.bufferView=0),e.bufferViewObject=t.bufferViews[e.bufferView],e.sparse!=null){let r=e.sparse;r.indices.bufferViewObject=t.bufferViews[r.indices.bufferView],r.values.bufferViewObject=t.bufferViews[r.values.bufferView]}}_loadDependenciesOfBufferViews(t){for(let e of t.bufferViews)e.buffer!==void 0&&(e.bufferObject=t.buffers[e.buffer])}_mergeExtendedJson(t,e){let r=null;if(e instanceof ArrayBuffer){let n=y.arrayBufferToString(e);r=JSON.parse(n)}else typeof e=="string"?r=JSON.parse(e):typeof e=="object"&&(r=e);Object.assign(t,r)}_loadResources(t,e,r,n,s){var c,l;let i=[],o;for(let m in r.buffers){let f=r.buffers[m],a,u;f.uri&&(a=f.uri.split("/"),u=a[a.length-1]),typeof f.uri=="undefined"?o=new x(d=>{s.buffers[m]=t,f.buffer=t,d(t.buffer)}):f.uri.match(/^data:application\/(.*);base64,/)?o=new x(d=>{let p=y.dataUriToArrayBuffer(f.uri);s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)}):(c=n.files)!=null&&c[u]?o=new x(d=>{let p=n.files[u];s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)}):o=new x(y.loadResourceAsync(e+f.uri,!0,(d,p)=>{s.buffers[m]=new Uint8Array(p),f.buffer=new Uint8Array(p),d(p)},(d,p)=>{})),f.bufferPromise=o,i.push(o)}for(let m in r.images){let f=m,a=r.images[f],u;if(typeof a.uri=="undefined"){let p=y.createUint8ArrayFromBufferViewInfo(r,a.bufferView,t);u=y.createBlobImageUriFromUint8Array(p,a.mimeType)}else{let p=a.uri,h=p.split("/"),w=h[h.length-1];if((l=n.files)!=null&&l[w]){let j=n.files[w];u=y.createBlobImageUriFromUint8Array(new Uint8Array(j),a.mimeType)}else p.match(/^data:/)?u=p:u=e+p}let d=y.createImageFromUri(u,a.mimeType).then(p=>{p.crossOrigin="Anonymous",s.images[f]=p,a.image=p});i.push(d)}return Promise.all(i).catch(m=>{b.default.error(`Promise.all error: ${m}`)})}static getInstance(){return this.rc||(this.rc=new v),this.rc}$f(t,e,r,n){return this.Xf(t).then(s=>{let i=JSON.stringify(s),o=JSON.parse(i);return this._loadAsTextJson(o,n,e,r).catch(c=>{b.default.error(`this.__loadAsTextJson error: ${c}`)})})}Xf(t){let e=new DracoDecoderModule,r=new e.Decoder,n=this.Hf(e,r,t);if(n==null)throw new Error("invalid dracoGeometry.");if(n.geometryType!==e.POINT_CLOUD)throw new Error("invalid geometryType of drc file.");if(r.GetAttributeId(n,e.POSITION)===-1)throw e.destroy(r),e.destroy(n),new Error("Draco: No position attribute found.");let i=["POSITION","NORMAL","COLOR","TEX_COORD","GENERIC"],o=n.num_points(),c=[],l=[],m=0;for(let a=0;a<i.length;a++){let u=r.GetAttributeId(n,e[i[a]]);if(u===-1){i.splice(a,1),a--;continue}let d=r.GetAttribute(n,u),p=new e.DracoFloat32Array;r.GetAttributeFloatForAllPoints(n,d,p),c[a]=p;let h=d.num_components();l[a]=h,i[a]==="COLOR"?m+=o*4:m+=o*h}let f=new Float32Array(m);for(let a=0,u=0;a<i.length;a++){if(i[a]==="COLOR"&&l[a]===3)for(let d=0;d<o;u+=4,d+=3)f[u]=c[a].GetValue(d),f[u+1]=c[a].GetValue(d+1),f[u+2]=c[a].GetValue(d+2),f[u+3]=1;else if(i[a]==="TEX_COORD")for(let d=0;d<o;u+=2,d++)f[u]=c[a].GetValue(2*d),f[u+1]=1-c[a].GetValue(2*d+1);else for(let d=0;d<o*l[a];u++,d++)f[u]=c[a].GetValue(d);e.destroy(c[a])}return e.destroy(r),e.destroy(n),this.Yf(f,o,i,l)}async Yf(t,e,r,n){let s={asset:{version:"2.0"},extensionsUsed:["KHR_materials_unlit"],extensionsRequired:["KHR_materials_unlit"],nodes:[{name:"Node",mesh:0}],scenes:[{nodes:[0]}],materials:[{name:"point-cloud_material",pbrMetallicRoughness:{baseColorFactor:[1,1,1,1]},extensions:{KHR_materials_unlit:{}}}]};return await this.Qf(t.buffer,s),this.Jf(e,r,n,s),this.bd(r,s),new Promise((i,o)=>{i(s)})}Qf(t,e){return this.Od(t).then(r=>{e.buffers=[{name:"input",byteLength:t.byteLength,uri:r}]}).catch(r=>{b.default.error(`this.__convertBufferToURI error: ${r}`)})}Od(t){return new Promise((e,r)=>{let n=new Blob([t],{type:"application/octet-stream"}),s=new FileReader;s.onload=()=>{e(s.result)},s.onerror=()=>{r(s.error)},s.readAsDataURL(n)})}Jf(t,e,r,n){let s=[],i=[],o=0;for(let c=0,l=0;c<e.length;l++){let m=r[c],f;m===1?f="SCALAR":f=`VEC${m}`;let a=0,u=e[c];for(;c<e.length&&(s.push({name:`point-cloud_${u}_${c}`,componentType:5126,count:t,type:f,bufferView:l,byteOffset:a}),e[c]==="COLOR"?a+=t*4*4:a+=t*m*4,c++,u===e[c]););i[l]={name:`bufferView_${u}`,buffer:0,byteLength:a,byteOffset:o,byteStride:m*4,target:34962},o+=a}n.accessors=s,n.bufferViews=i}bd(t,e){let r={};for(let s=0;s<t.length;s++)t[s]==="TEX_COORD"?r.TEXCOORD_0=s:t[s]==="GENERIC"?r.TANGENT=s:r[t[s]]=s;let n={name:"Node-Mesh",primitives:[{mode:0,material:0,attributes:r}]};e.meshes=[n]}async importPointCloudToPrimitive(t,e){let r=await y.fetchArrayBuffer(e);return this.xd(t,r.unwrapForce())}xd(t,e){let r=new DracoDecoderModule,n=new r.Decoder,s=this.Hf(r,n,e);if(s==null)throw new Error("invalid dracoGeometry.");if(s.geometryType!==r.POINT_CLOUD)throw new Error("invalid geometryType of drc file.");let i=[],o=[],c=[];this._d(r,n,s,i,o,c),this.wd(r,n,s,i,o,c),this.Td(r,n,s,i,o,c),this.vd(r,n,s,i,o,c);let l=D.createPrimitive(t,{attributeSemantics:o,attributes:c,material:I(t,{isSkinning:!1,isLighting:!0}),primitiveMode:V.Points});return r.destroy(n),r.destroy(s),l}Hf(t,e,r){let n=new t.DecoderBuffer;n.Init(new Int8Array(r),r.byteLength);let s=e.GetEncodedGeometryType(n),i,o;if(s===t.TRIANGULAR_MESH?(i=new t.Mesh,o=e.DecodeBufferToMesh(n,i)):s===t.POINT_CLOUD?(i=new t.PointCloud,o=e.DecodeBufferToPointCloud(n,i)):b.default.error("Unknown geometry type."),i.geometryType=s,!o.ok()||i.ptr===0){let c="Decoding failed: ";c+=o.error_msg(),b.default.error(c),t.destroy(e),t.destroy(i);return}return t.destroy(n),i}_d(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.POSITION);if(o===-1)throw t.destroy(e),t.destroy(r),new Error("Draco: No position attribute found.");let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*3,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec3),s.push(O.Position.XYZ),i.push(a),t.destroy(l),a}wd(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.COLOR);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let m=r.num_points(),f=c.num_components(),a=m*4,u=new Float32Array(a);for(let d=0;d<a;d+=f)u[d]=l.GetValue(d),u[d+1]=l.GetValue(d+1),u[d+2]=l.GetValue(d+2),f===4?u[d+3]=l.GetValue(d+3):u[d+3]=1;return n.push(A.Vec3),s.push(O.Color0.XYZ),i.push(u),t.destroy(l),u}Td(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.NORMAL);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*3,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec3),s.push(O.Normal.XYZ),i.push(a),t.destroy(l),a}vd(t,e,r,n,s,i){let o=e.GetAttributeId(r,t.TEX_COORD);if(o===-1)return null;let c=e.GetAttribute(r,o),l=new t.DracoFloat32Array;e.GetAttributeFloatForAllPoints(r,c,l);let f=r.num_points()*2,a=new Float32Array(f);for(let u=0;u<f;u+=1)a[u]=l.GetValue(u);return n.push(A.Vec2),s.push(O.Texcoord0.XY),i.push(a),t.destroy(l),a}};export{R as DrcPointCloudImporter};
|
|
@@ -180,7 +180,8 @@ export declare class Gltf2Importer {
|
|
|
180
180
|
private static _loadVRMCExtensions;
|
|
181
181
|
/**
|
|
182
182
|
* Resolves dependencies for glTF textures including samplers and image sources.
|
|
183
|
-
* Handles KHR_texture_basisu
|
|
183
|
+
* Handles the KHR_texture_basisu (Basis Universal) and EXT_texture_webp extensions,
|
|
184
|
+
* both of which keep the image index in the texture extension instead of in `source`.
|
|
184
185
|
*
|
|
185
186
|
* @param gltfJson - The glTF JSON data containing textures
|
|
186
187
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DataUtil as h}from"../misc/DataUtil.js";import{Is as l}from"../misc/Is.js";import{Logger as O}from"../misc/Logger.js";import{ifDefinedThen as A}from"../misc/MiscUtil.js";import{Err as T,Ok as w}from"../misc/Result.js";import{RnPromise as b}from"../misc/RnPromise.js";var M=class{constructor(){}static async importFromUrl(e,r){var s;let t=await h.fetchArrayBuffer(e);if(t.isErr())throw t.getRnError();return(await this._importGltfOrGlbFromArrayBuffers(t.get(),(s=r==null?void 0:r.files)!=null?s:{},r,e)).unwrapForce()}static async importFromArrayBuffers(e,r){for(let t in e){let i=h.getExtension(t);if(i==="gltf"||i==="glb"||i==="rnb")return(await this._importGltfOrGlbFromArrayBuffers(e[t],e,r)).unwrapForce()}throw new Error("no gltf or glb file found")}static async _importGltfOrGlbFromArrayBuffers(e,r,t,i){if(new DataView(e,0,20).getUint32(0,!0)!==1179937895){let a=h.arrayBufferToString(e),o=JSON.parse(a);try{let f=await this._importGltf(o,r,t,i);return new w(f)}catch{return new T({message:"this.__importGltf error",error:void 0})}}else try{let a=await this._importGlb(e,r,t);return new w(a)}catch{return new T({message:"this.importGlb error",error:void 0})}}static _getOptions(e,r,t){var i,s;if(((s=(i=r.asset)==null?void 0:i.extras)==null?void 0:s.rnLoaderOptions)!=null)for(let n in r.asset.extras.rnLoaderOptions)e[n]=r.asset.extras.rnLoaderOptions[n];for(let n in t)e[n]=t[n];return t!=null&&t.loaderExtensionName&&typeof t.loaderExtensionName=="string"&&(Rn[t.loaderExtensionName]!=null?e.loaderExtension=Rn[t.loaderExtensionName].getInstance():(O.default.error(`${t.loaderExtensionName} not found!`),e.loaderExtension=void 0)),e}static async _importGlb(e,r,t){let i=new DataView(e,0,20);if(i.getUint32(4,!0)!==2)throw new Error("invalid version field in this binary glTF file.");let n=i.getUint32(12,!0);if(i.getUint32(16,!0)!==1313821514)throw new Error("invalid chunkType of chunk0 in this binary glTF file.");let o=new Uint8Array(e,20,n),f=h.uint8ArrayToString(o),u=JSON.parse(f),c=h.createDefaultGltfOptions();t=this._getOptions(c,u,t);let p=new Uint8Array(e,20+n+8);u.asset.extras===void 0&&(u.asset.extras={fileType:"glTF",version:"2"}),this._mergeExtendedJson(u,t.extendedJson),u.asset.extras.rnLoaderOptions=t;try{await this._loadInner(u,r,t,p)}catch(d){O.default.info(`this._loadInner error in _loadAsBinaryJson: ${d}`)}return u}static async _importGltf(e,r,t,i,s){let n=`${i==null?void 0:i.substring(0,i==null?void 0:i.lastIndexOf("/"))}/`;e.asset.extras===void 0&&(e.asset.extras={fileType:"glTF",version:"2"});let a=h.createDefaultGltfOptions();t=this._getOptions(a,e,t),this._mergeExtendedJson(e,t.extendedJson),e.asset.extras.rnLoaderOptions=t;try{await this._loadInner(e,r,t,void 0,n,s)}catch(o){O.default.error(`this._loadInner error in _loadAsTextJson: ${o}`)}return e}static _loadInner(e,r,t,i,s,n){this._normalizeOptionalArrays(e);let a=[];return a.push(this._loadResources(i,e,r,t,s,n)),a.push(new b(o=>{this._loadJsonContent(e),o()})),b.all(a)}static _normalizeOptionalArrays(e){var r,t,i,s,n,a,o,f,u,c,p,d,m,x,R,y,_;(r=e.accessors)!=null||(e.accessors=[]),(t=e.animations)!=null||(e.animations=[]),(i=e.buffers)!=null||(e.buffers=[]),(s=e.bufferViews)!=null||(e.bufferViews=[]),(n=e.cameras)!=null||(e.cameras=[]),(a=e.images)!=null||(e.images=[]),(o=e.materials)!=null||(e.materials=[]),(f=e.meshes)!=null||(e.meshes=[]),(u=e.nodes)!=null||(e.nodes=[]),(c=e.samplers)!=null||(e.samplers=[]),(p=e.skins)!=null||(e.skins=[]),(d=e.textures)!=null||(e.textures=[]),(m=e.extensionsUsed)!=null||(e.extensionsUsed=[]),(x=e.extensionsRequired)!=null||(e.extensionsRequired=[]),(R=e.extensions)!=null||(e.extensions={}),(y=e.scenes)!=null||(e.scenes=[{nodes:[]}]),(_=e.scene)!=null||(e.scene=0)}static _loadJsonContent(e){this._loadDependenciesOfScenes(e),this._loadDependenciesOfNodes(e),this._loadDependenciesOfMeshes(e),this._loadDependenciesOfMaterials(e),this._loadDependenciesOfTextures(e),this._loadDependenciesOfJoints(e),this._loadDependenciesOfAnimations(e),this._loadDependenciesOfAccessors(e),this._loadDependenciesOfBufferViews(e),e.asset.extras===void 0&&(e.asset.extras={})}static _loadDependenciesOfScenes(e){for(let r of e.scenes){l.undefined(r.nodesObjects)&&(r.nodesObjects=[]);for(let t of r.nodes)r.nodesObjects[t]=e.nodes[r.nodes[t]]}}static _loadDependenciesOfNodes(e){var r,t;for(let i in e.nodes){let s=e.nodes[i];if(s.childrenObjects=(r=s.childrenObjects)!=null?r:[],s.children)for(let n of s.children)s.childrenObjects[n]=e.nodes[n],e.nodes[n].parent=Number.parseInt(i,10),e.nodes[n].parentObject=s;s.mesh!==void 0&&e.meshes!==void 0&&(s.meshObject=e.meshes[s.mesh]),s.skin!==void 0&&e.skins!==void 0&&(s.skinObject=e.skins[s.skin],l.exist(s.skinObject)&&(l.not.exist((t=s.meshObject)==null?void 0:t.extras)&&(s.meshObject.extras={}),s.meshObject.extras._skin=s.skin)),s.camera!==void 0&&e.cameras!==void 0&&(s.cameraObject=e.cameras[s.camera]),s.extensions!==void 0&&s.extensions.KHR_lights_punctual!==void 0&&e.extensions!==void 0&&e.extensions.KHR_lights_punctual!==void 0&&(s.extensions.KHR_lights_punctual.lightIndex=s.extensions.KHR_lights_punctual.light,s.extensions.KHR_lights_punctual.light=e.extensions.KHR_lights_punctual.lights[s.extensions.KHR_lights_punctual.lightIndex])}}static _loadDependenciesOfMeshes(e){var r;if(!l.not.exist(e.meshes))for(let t of e.meshes)for(let i of t.primitives){if(i.material!==void 0&&(i.materialObject=e.materials[i.material]),((r=i.extensions)==null?void 0:r.KHR_materials_variants)!=null){i.materialVariants=[];let s=i.extensions.KHR_materials_variants.mappings,n=e.extensions.KHR_materials_variants.variants;for(let a of s){let o=a.variants.map(u=>n[u].name),f={materialObject:e.materials[a.material],material:a.material,variants:o};i.materialVariants.push(f)}}i.attributesObjects={};for(let s in i.attributes){let n=i.attributes[s],a=e.accessors[n];a.extras={},i.attributesObjects[s]=a}if(i.indices!=null&&(i.indicesObject=e.accessors[i.indices]),i.targets!=null){i.targetsObjects=[];for(let s of i.targets){let n={};for(let a in s){let o=s[a];if(o>=0){let f=e.accessors[o];f.extras={},n[a]=f}}i.targetsObjects.push(n)}}}}static _checkRnGltfLoaderOptionsExist(e){var r;return!!((r=e.asset.extras)!=null&&r.rnLoaderOptions)}static _loadDependenciesOfMaterials(e){if(e.textures||(e.textures=[]),e.materials)for(let r of e.materials)this._loadBasicMaterialTextures(e,r),this._loadMaterialExtensions(e,r)}static _loadBasicMaterialTextures(e,r){if(r.pbrMetallicRoughness){let a=r.pbrMetallicRoughness.baseColorTexture;a!==void 0&&(a.texture=e.textures[a.index]);let o=r.pbrMetallicRoughness.metallicRoughnessTexture;o!==void 0&&(o.texture=e.textures[o.index])}let t=r.normalTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.occlusionTexture;i!==void 0&&(i.texture=e.textures[i.index]);let s=r.emissiveTexture;s!==void 0&&(s.texture=e.textures[s.index]);let n=this._checkRnGltfLoaderOptionsExist(e)?e.asset.extras.rnLoaderOptions.loaderExtension:void 0;n!=null&&n.setTextures&&n.setTextures(e,r)}static _loadMaterialExtensions(e,r){if(l.exist(r.extensions)){let t=r.extensions;this._loadKHRExtensions(e,t),this._loadVRMCExtensions(e,t)}}static _loadKHRExtensions(e,r){if(l.exist(r.KHR_materials_clearcoat)){let t=r.KHR_materials_clearcoat.clearcoatTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_clearcoat.clearcoatRoughnessTexture;i!==void 0&&(i.texture=e.textures[i.index]);let s=r.KHR_materials_clearcoat.clearcoatNormalTexture;s!==void 0&&(s.texture=e.textures[s.index])}if(l.exist(r.KHR_materials_transmission)){let t=r.KHR_materials_transmission.transmissionTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_volume)){let t=r.KHR_materials_volume.thicknessTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_sheen)){let t=r.KHR_materials_sheen.sheenColorTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_sheen.sheenRoughnessTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_specular)){let t=r.KHR_materials_specular.specularTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_specular.specularColorTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_iridescence)){let t=r.KHR_materials_iridescence.iridescenceTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_iridescence.iridescenceThicknessTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_anisotropy)){let t=r.KHR_materials_anisotropy.anisotropyTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_diffuse_transmission)){let t=r.KHR_materials_diffuse_transmission.diffuseTransmissionTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_diffuse_transmission.diffuseTransmissionColorTexture;i!==void 0&&(i.texture=e.textures[i.index])}}static _loadVRMCExtensions(e,r){if(l.exist(r.VRMC_materials_mtoon)){let t=r.VRMC_materials_mtoon,i=t.shadeMultiplyTexture;i!=null&&(i.texture=e.textures[i.index]);let s=t.shadingShiftTexture;s!=null&&(s.texture=e.textures[s.index]);let n=t.matcapTexture;n!=null&&(n.texture=e.textures[n.index]);let a=t.rimMultiplyTexture;a!=null&&(a.texture=e.textures[a.index]);let o=t.outlineWidthMultiplyTexture;o!=null&&(o.texture=e.textures[o.index]);let f=t.uvAnimationMaskTexture;f!=null&&(f.texture=e.textures[f.index])}}static _loadDependenciesOfTextures(e){var r,t;if(e.textures)for(let i of e.textures)A(s=>{i.samplerObject=e.samplers[s]},i.sampler),((t=(r=i.extensions)==null?void 0:r.KHR_texture_basisu)==null?void 0:t.source)!=null?(i.extensions.KHR_texture_basisu.fallbackSourceIndex=i.source,i.source=i.extensions.KHR_texture_basisu.source,i.sourceObject=e.images[i.source]):i.source!==void 0&&(i.sourceObject=e.images[i.source])}static _loadDependenciesOfJoints(e){if(e.skins)for(let r of e.skins){r.skeletonObject=e.nodes[r.skeleton],r.inverseBindMatricesObject=e.accessors[r.inverseBindMatrices],l.not.exist(r.skeleton)&&(r.skeleton=r.joints[0],r.skeletonObject=e.nodes[r.skeleton]),r.jointsObjects=[];for(let t of r.joints)r.jointsObjects.push(e.nodes[t])}}static _loadDependenciesOfAnimations(e){if(e.animations){for(let r of e.animations)for(let t of r.channels)if(l.exist(t.sampler)){if(t.samplerObject=r.samplers[t.sampler],t.target.nodeObject=e.nodes[t.target.node],t.samplerObject.inputObject=e.accessors[t.samplerObject.input],t.samplerObject.outputObject=e.accessors[t.samplerObject.output],l.undefined(t.samplerObject.outputObject.extras)&&(t.samplerObject.outputObject.extras={}),t.target.path==="weights"){let i=t.samplerObject.outputObject.count/t.samplerObject.inputObject.count;t.samplerObject.interpolation==="CUBICSPLINE"&&(i=t.samplerObject.outputObject.count/t.samplerObject.inputObject.count/3),t.samplerObject.outputObject.extras.weightsArrayLength=i}t.target.path==="rotation"&&(t.samplerObject.outputObject.extras.quaternionIfVec4=!0)}}}static _loadDependenciesOfAccessors(e){for(let r of e.accessors)if(r.bufferView!=null&&(r.bufferViewObject=e.bufferViews[r.bufferView]),l.exist(r.sparse)){let t=r.sparse;l.exist(t)&&l.exist(t.indices)&&l.exist(t.values)&&(t.indices.bufferViewObject=e.bufferViews[t.indices.bufferView],t.values.bufferViewObject=e.bufferViews[t.values.bufferView])}}static _loadDependenciesOfBufferViews(e){for(let r of e.bufferViews)r.buffer!==void 0&&(r.bufferObject=e.buffers[r.buffer])}static _mergeExtendedJson(e,r){let t=null;if(r instanceof ArrayBuffer){let i=h.arrayBufferToString(r);t=JSON.parse(i)}else typeof r=="string"?t=JSON.parse(r):typeof r=="object"&&(t=r);Object.assign(e,t)}static _loadResources(e,r,t,i,s,n){var u;let a=[],o;for(let c of r.buffers){let p="";if(c.uri){let d=c.uri.split("/");p=d[d.length-1]}typeof c.uri=="undefined"?o=new b(d=>{c.buffer=e,d(e)}):c.uri.match(/^data:application\/(.*);base64,/)?o=new b(d=>{let m=h.dataUriToArrayBuffer(c.uri);c.buffer=new Uint8Array(m),d(m)}):t&&this.Md(t,p)?o=new b(d=>{let m=this.jd(t,p),x=t[m];c.buffer=new Uint8Array(x),d(x)}):o=new b(h.loadResourceAsync(s+c.uri,!0,(d,m)=>{c.buffer=new Uint8Array(m),d(m)},(d,m)=>{d(`HTTP Error Status:${m}`)})),c.bufferPromise=o,a.push(o)}for(let c of(u=r.images)!=null?u:[])if(c.uri==null)if(l.exist(e)){let p=h.createUint8ArrayFromBufferViewInfo(r,c.bufferView,e),d=h.createBlobImageUriFromUint8Array(p,c.mimeType);a.push(this.Bd(d,c,t))}else{let d=r.bufferViews[c.bufferView].bufferObject;if(l.not.exist(d)){O.default.error("gltf2BufferView.bufferObject not found");continue}let m=d.bufferPromise,x=new b(y=>{m.then(_=>{let v=h.createUint8ArrayFromBufferViewInfo(r,c.bufferView,_),j=h.createBlobImageUriFromUint8Array(v,c.mimeType);this.Bd(j,c,t).then(()=>{y(_)})})}),R=a.indexOf(m);a[R]=x,d.bufferPromise=x}else{let p=c.uri,d=p.split("/"),m=d[d.length-1],x;if(t&&this.Md(t,m)){let R=this.jd(t,m),y=t[R];x=h.createBlobImageUriFromUint8Array(new Uint8Array(y),c.mimeType)}else p.match(/^data:/)?x=p:x=s+p;a.push(this.Bd(x,c,t))}let f=this.kd(r,t,s);for(let c of f)a.push(c);return b.all(a,n).catch(c=>{O.default.error(`Promise.all error: ${c}`)})}static kd(e,r,t){var n,a,o;let i=[],s="RHODONITE_materials_node";if(!((n=e.extensionsUsed)!=null&&n.includes(s)))return i;for(let f of(a=e.materials)!=null?a:[]){let u=(o=f.extensions)==null?void 0:o[s];if(!(u!=null&&u.uri))continue;let c=u.uri,p=c.split("/"),d=p[p.length-1],m;if(c.match(/^data:application\/json;base64,/))m=new b(x=>{let R=h.arrayBufferToString(h.dataUriToArrayBuffer(c));u.shaderNodeJson=JSON.parse(R),x(u.shaderNodeJson)});else if(r&&this.Md(r,d))m=new b(x=>{let R=this.jd(r,d),y=r[R],_=h.arrayBufferToString(y);u.shaderNodeJson=JSON.parse(_),x(u.shaderNodeJson)});else{let x=t?t+c:c;m=new b((R,y)=>{fetch(x).then(_=>{if(!_.ok)throw new Error(`HTTP Error Status: ${_.status}`);return _.json()}).then(_=>{u.shaderNodeJson=_,R(_)}).catch(_=>{O.default.error(`Failed to load .rmn file: ${x}, ${_}`),y(_)})})}i.push(m)}return i}static Md(e,r){for(let t in e){let i=t.split("/");if(i[i.length-1]===r)return!0}return!1}static jd(e,r){for(let t in e){let i=t.split("/");if(i[i.length-1]===r)return t}}static Bd(e,r,t){var s,n;let i;return e.match(/basis$/)?i=new b(a=>{fetch(e,{mode:"cors"}).then(o=>{o.arrayBuffer().then(f=>{let u=new Uint8Array(f);r.basis=u,a(r)})})}):(s=r.uri)!=null&&s.match(/basis$/)?i=new b(a=>{r.basis=new Uint8Array(t[r.uri]),a(r)}):e.match(/\.ktx2$/)||e.match(/^data:image\/ktx2/)||r.bufferView!=null&&r.mimeType==="image/ktx2"?i=new b(a=>{fetch(e,{mode:"cors"}).then(o=>{o.arrayBuffer().then(f=>{let u=new Uint8Array(f);r.ktx2=u,a(r)})})}):(n=r.uri)!=null&&n.match(/ktx2$/)?i=new b(a=>{r.ktx2=new Uint8Array(t[r.uri]),a(r)}):i=new b(async a=>{let o=await h.createImageFromUri(e,r.mimeType);o.crossOrigin="Anonymous",r.image=o,a(r)}),i}};export{M as Gltf2Importer};
|
|
1
|
+
import{DataUtil as h}from"../misc/DataUtil.js";import{Is as l}from"../misc/Is.js";import{Logger as y}from"../misc/Logger.js";import{ifDefinedThen as A}from"../misc/MiscUtil.js";import{Err as T,Ok as w}from"../misc/Result.js";import{RnPromise as b}from"../misc/RnPromise.js";var M=class{constructor(){}static async importFromUrl(e,r){var s;let t=await h.fetchArrayBuffer(e);if(t.isErr())throw t.getRnError();return(await this._importGltfOrGlbFromArrayBuffers(t.get(),(s=r==null?void 0:r.files)!=null?s:{},r,e)).unwrapForce()}static async importFromArrayBuffers(e,r){for(let t in e){let i=h.getExtension(t);if(i==="gltf"||i==="glb"||i==="rnb")return(await this._importGltfOrGlbFromArrayBuffers(e[t],e,r)).unwrapForce()}throw new Error("no gltf or glb file found")}static async _importGltfOrGlbFromArrayBuffers(e,r,t,i){if(new DataView(e,0,20).getUint32(0,!0)!==1179937895){let n=h.arrayBufferToString(e),o=JSON.parse(n);try{let f=await this._importGltf(o,r,t,i);return new w(f)}catch{return new T({message:"this.__importGltf error",error:void 0})}}else try{let n=await this._importGlb(e,r,t);return new w(n)}catch{return new T({message:"this.importGlb error",error:void 0})}}static _getOptions(e,r,t){var i,s;if(((s=(i=r.asset)==null?void 0:i.extras)==null?void 0:s.rnLoaderOptions)!=null)for(let a in r.asset.extras.rnLoaderOptions)e[a]=r.asset.extras.rnLoaderOptions[a];for(let a in t)e[a]=t[a];return t!=null&&t.loaderExtensionName&&typeof t.loaderExtensionName=="string"&&(Rn[t.loaderExtensionName]!=null?e.loaderExtension=Rn[t.loaderExtensionName].getInstance():(y.default.error(`${t.loaderExtensionName} not found!`),e.loaderExtension=void 0)),e}static async _importGlb(e,r,t){let i=new DataView(e,0,20);if(i.getUint32(4,!0)!==2)throw new Error("invalid version field in this binary glTF file.");let a=i.getUint32(12,!0);if(i.getUint32(16,!0)!==1313821514)throw new Error("invalid chunkType of chunk0 in this binary glTF file.");let o=new Uint8Array(e,20,a),f=h.uint8ArrayToString(o),u=JSON.parse(f),c=h.createDefaultGltfOptions();t=this._getOptions(c,u,t);let p=new Uint8Array(e,20+a+8);u.asset.extras===void 0&&(u.asset.extras={fileType:"glTF",version:"2"}),this._mergeExtendedJson(u,t.extendedJson),u.asset.extras.rnLoaderOptions=t;try{await this._loadInner(u,r,t,p)}catch(d){y.default.info(`this._loadInner error in _loadAsBinaryJson: ${d}`)}return u}static async _importGltf(e,r,t,i,s){let a=`${i==null?void 0:i.substring(0,i==null?void 0:i.lastIndexOf("/"))}/`;e.asset.extras===void 0&&(e.asset.extras={fileType:"glTF",version:"2"});let n=h.createDefaultGltfOptions();t=this._getOptions(n,e,t),this._mergeExtendedJson(e,t.extendedJson),e.asset.extras.rnLoaderOptions=t;try{await this._loadInner(e,r,t,void 0,a,s)}catch(o){y.default.error(`this._loadInner error in _loadAsTextJson: ${o}`)}return e}static _loadInner(e,r,t,i,s,a){this._normalizeOptionalArrays(e);let n=[];return n.push(this._loadResources(i,e,r,t,s,a)),n.push(new b(o=>{this._loadJsonContent(e),o()})),b.all(n)}static _normalizeOptionalArrays(e){var r,t,i,s,a,n,o,f,u,c,p,d,m,x,R,O,_;(r=e.accessors)!=null||(e.accessors=[]),(t=e.animations)!=null||(e.animations=[]),(i=e.buffers)!=null||(e.buffers=[]),(s=e.bufferViews)!=null||(e.bufferViews=[]),(a=e.cameras)!=null||(e.cameras=[]),(n=e.images)!=null||(e.images=[]),(o=e.materials)!=null||(e.materials=[]),(f=e.meshes)!=null||(e.meshes=[]),(u=e.nodes)!=null||(e.nodes=[]),(c=e.samplers)!=null||(e.samplers=[]),(p=e.skins)!=null||(e.skins=[]),(d=e.textures)!=null||(e.textures=[]),(m=e.extensionsUsed)!=null||(e.extensionsUsed=[]),(x=e.extensionsRequired)!=null||(e.extensionsRequired=[]),(R=e.extensions)!=null||(e.extensions={}),(O=e.scenes)!=null||(e.scenes=[{nodes:[]}]),(_=e.scene)!=null||(e.scene=0)}static _loadJsonContent(e){this._loadDependenciesOfScenes(e),this._loadDependenciesOfNodes(e),this._loadDependenciesOfMeshes(e),this._loadDependenciesOfMaterials(e),this._loadDependenciesOfTextures(e),this._loadDependenciesOfJoints(e),this._loadDependenciesOfAnimations(e),this._loadDependenciesOfAccessors(e),this._loadDependenciesOfBufferViews(e),e.asset.extras===void 0&&(e.asset.extras={})}static _loadDependenciesOfScenes(e){for(let r of e.scenes){l.undefined(r.nodesObjects)&&(r.nodesObjects=[]);for(let t of r.nodes)r.nodesObjects[t]=e.nodes[r.nodes[t]]}}static _loadDependenciesOfNodes(e){var r,t;for(let i in e.nodes){let s=e.nodes[i];if(s.childrenObjects=(r=s.childrenObjects)!=null?r:[],s.children)for(let a of s.children)s.childrenObjects[a]=e.nodes[a],e.nodes[a].parent=Number.parseInt(i,10),e.nodes[a].parentObject=s;s.mesh!==void 0&&e.meshes!==void 0&&(s.meshObject=e.meshes[s.mesh]),s.skin!==void 0&&e.skins!==void 0&&(s.skinObject=e.skins[s.skin],l.exist(s.skinObject)&&(l.not.exist((t=s.meshObject)==null?void 0:t.extras)&&(s.meshObject.extras={}),s.meshObject.extras._skin=s.skin)),s.camera!==void 0&&e.cameras!==void 0&&(s.cameraObject=e.cameras[s.camera]),s.extensions!==void 0&&s.extensions.KHR_lights_punctual!==void 0&&e.extensions!==void 0&&e.extensions.KHR_lights_punctual!==void 0&&(s.extensions.KHR_lights_punctual.lightIndex=s.extensions.KHR_lights_punctual.light,s.extensions.KHR_lights_punctual.light=e.extensions.KHR_lights_punctual.lights[s.extensions.KHR_lights_punctual.lightIndex])}}static _loadDependenciesOfMeshes(e){var r;if(!l.not.exist(e.meshes))for(let t of e.meshes)for(let i of t.primitives){if(i.material!==void 0&&(i.materialObject=e.materials[i.material]),((r=i.extensions)==null?void 0:r.KHR_materials_variants)!=null){i.materialVariants=[];let s=i.extensions.KHR_materials_variants.mappings,a=e.extensions.KHR_materials_variants.variants;for(let n of s){let o=n.variants.map(u=>a[u].name),f={materialObject:e.materials[n.material],material:n.material,variants:o};i.materialVariants.push(f)}}i.attributesObjects={};for(let s in i.attributes){let a=i.attributes[s],n=e.accessors[a];n.extras={},i.attributesObjects[s]=n}if(i.indices!=null&&(i.indicesObject=e.accessors[i.indices]),i.targets!=null){i.targetsObjects=[];for(let s of i.targets){let a={};for(let n in s){let o=s[n];if(o>=0){let f=e.accessors[o];f.extras={},a[n]=f}}i.targetsObjects.push(a)}}}}static _checkRnGltfLoaderOptionsExist(e){var r;return!!((r=e.asset.extras)!=null&&r.rnLoaderOptions)}static _loadDependenciesOfMaterials(e){if(e.textures||(e.textures=[]),e.materials)for(let r of e.materials)this._loadBasicMaterialTextures(e,r),this._loadMaterialExtensions(e,r)}static _loadBasicMaterialTextures(e,r){if(r.pbrMetallicRoughness){let n=r.pbrMetallicRoughness.baseColorTexture;n!==void 0&&(n.texture=e.textures[n.index]);let o=r.pbrMetallicRoughness.metallicRoughnessTexture;o!==void 0&&(o.texture=e.textures[o.index])}let t=r.normalTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.occlusionTexture;i!==void 0&&(i.texture=e.textures[i.index]);let s=r.emissiveTexture;s!==void 0&&(s.texture=e.textures[s.index]);let a=this._checkRnGltfLoaderOptionsExist(e)?e.asset.extras.rnLoaderOptions.loaderExtension:void 0;a!=null&&a.setTextures&&a.setTextures(e,r)}static _loadMaterialExtensions(e,r){if(l.exist(r.extensions)){let t=r.extensions;this._loadKHRExtensions(e,t),this._loadVRMCExtensions(e,t)}}static _loadKHRExtensions(e,r){if(l.exist(r.KHR_materials_clearcoat)){let t=r.KHR_materials_clearcoat.clearcoatTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_clearcoat.clearcoatRoughnessTexture;i!==void 0&&(i.texture=e.textures[i.index]);let s=r.KHR_materials_clearcoat.clearcoatNormalTexture;s!==void 0&&(s.texture=e.textures[s.index])}if(l.exist(r.KHR_materials_transmission)){let t=r.KHR_materials_transmission.transmissionTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_volume)){let t=r.KHR_materials_volume.thicknessTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_sheen)){let t=r.KHR_materials_sheen.sheenColorTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_sheen.sheenRoughnessTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_specular)){let t=r.KHR_materials_specular.specularTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_specular.specularColorTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_iridescence)){let t=r.KHR_materials_iridescence.iridescenceTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_iridescence.iridescenceThicknessTexture;i!==void 0&&(i.texture=e.textures[i.index])}if(l.exist(r.KHR_materials_anisotropy)){let t=r.KHR_materials_anisotropy.anisotropyTexture;t!==void 0&&(t.texture=e.textures[t.index])}if(l.exist(r.KHR_materials_diffuse_transmission)){let t=r.KHR_materials_diffuse_transmission.diffuseTransmissionTexture;t!==void 0&&(t.texture=e.textures[t.index]);let i=r.KHR_materials_diffuse_transmission.diffuseTransmissionColorTexture;i!==void 0&&(i.texture=e.textures[i.index])}}static _loadVRMCExtensions(e,r){if(l.exist(r.VRMC_materials_mtoon)){let t=r.VRMC_materials_mtoon,i=t.shadeMultiplyTexture;i!=null&&(i.texture=e.textures[i.index]);let s=t.shadingShiftTexture;s!=null&&(s.texture=e.textures[s.index]);let a=t.matcapTexture;a!=null&&(a.texture=e.textures[a.index]);let n=t.rimMultiplyTexture;n!=null&&(n.texture=e.textures[n.index]);let o=t.outlineWidthMultiplyTexture;o!=null&&(o.texture=e.textures[o.index]);let f=t.uvAnimationMaskTexture;f!=null&&(f.texture=e.textures[f.index])}}static _loadDependenciesOfTextures(e){var r,t,i,s;if(e.textures)for(let a of e.textures)A(n=>{a.samplerObject=e.samplers[n]},a.sampler),((t=(r=a.extensions)==null?void 0:r.KHR_texture_basisu)==null?void 0:t.source)!=null?(a.extensions.KHR_texture_basisu.fallbackSourceIndex=a.source,a.source=a.extensions.KHR_texture_basisu.source,a.sourceObject=e.images[a.source]):((s=(i=a.extensions)==null?void 0:i.EXT_texture_webp)==null?void 0:s.source)!=null?(a.source=a.extensions.EXT_texture_webp.source,a.sourceObject=e.images[a.source]):a.source!==void 0&&(a.sourceObject=e.images[a.source])}static _loadDependenciesOfJoints(e){if(e.skins)for(let r of e.skins){r.skeletonObject=e.nodes[r.skeleton],r.inverseBindMatricesObject=e.accessors[r.inverseBindMatrices],l.not.exist(r.skeleton)&&(r.skeleton=r.joints[0],r.skeletonObject=e.nodes[r.skeleton]),r.jointsObjects=[];for(let t of r.joints)r.jointsObjects.push(e.nodes[t])}}static _loadDependenciesOfAnimations(e){if(e.animations){for(let r of e.animations)for(let t of r.channels)if(l.exist(t.sampler)){if(t.samplerObject=r.samplers[t.sampler],t.target.nodeObject=e.nodes[t.target.node],t.samplerObject.inputObject=e.accessors[t.samplerObject.input],t.samplerObject.outputObject=e.accessors[t.samplerObject.output],l.undefined(t.samplerObject.outputObject.extras)&&(t.samplerObject.outputObject.extras={}),t.target.path==="weights"){let i=t.samplerObject.outputObject.count/t.samplerObject.inputObject.count;t.samplerObject.interpolation==="CUBICSPLINE"&&(i=t.samplerObject.outputObject.count/t.samplerObject.inputObject.count/3),t.samplerObject.outputObject.extras.weightsArrayLength=i}t.target.path==="rotation"&&(t.samplerObject.outputObject.extras.quaternionIfVec4=!0)}}}static _loadDependenciesOfAccessors(e){for(let r of e.accessors)if(r.bufferView!=null&&(r.bufferViewObject=e.bufferViews[r.bufferView]),l.exist(r.sparse)){let t=r.sparse;l.exist(t)&&l.exist(t.indices)&&l.exist(t.values)&&(t.indices.bufferViewObject=e.bufferViews[t.indices.bufferView],t.values.bufferViewObject=e.bufferViews[t.values.bufferView])}}static _loadDependenciesOfBufferViews(e){for(let r of e.bufferViews)r.buffer!==void 0&&(r.bufferObject=e.buffers[r.buffer])}static _mergeExtendedJson(e,r){let t=null;if(r instanceof ArrayBuffer){let i=h.arrayBufferToString(r);t=JSON.parse(i)}else typeof r=="string"?t=JSON.parse(r):typeof r=="object"&&(t=r);Object.assign(e,t)}static _loadResources(e,r,t,i,s,a){var u;let n=[],o;for(let c of r.buffers){let p="";if(c.uri){let d=c.uri.split("/");p=d[d.length-1]}typeof c.uri=="undefined"?o=new b(d=>{c.buffer=e,d(e)}):c.uri.match(/^data:application\/(.*);base64,/)?o=new b(d=>{let m=h.dataUriToArrayBuffer(c.uri);c.buffer=new Uint8Array(m),d(m)}):t&&this.Md(t,p)?o=new b(d=>{let m=this.Bd(t,p),x=t[m];c.buffer=new Uint8Array(x),d(x)}):o=new b(h.loadResourceAsync(s+c.uri,!0,(d,m)=>{c.buffer=new Uint8Array(m),d(m)},(d,m)=>{d(`HTTP Error Status:${m}`)})),c.bufferPromise=o,n.push(o)}for(let c of(u=r.images)!=null?u:[])if(c.uri==null)if(l.exist(e)){let p=h.createUint8ArrayFromBufferViewInfo(r,c.bufferView,e),d=h.createBlobImageUriFromUint8Array(p,c.mimeType);n.push(this.kd(d,c,t))}else{let d=r.bufferViews[c.bufferView].bufferObject;if(l.not.exist(d)){y.default.error("gltf2BufferView.bufferObject not found");continue}let m=d.bufferPromise,x=new b(O=>{m.then(_=>{let v=h.createUint8ArrayFromBufferViewInfo(r,c.bufferView,_),j=h.createBlobImageUriFromUint8Array(v,c.mimeType);this.kd(j,c,t).then(()=>{O(_)})})}),R=n.indexOf(m);n[R]=x,d.bufferPromise=x}else{let p=c.uri,d=p.split("/"),m=d[d.length-1],x;if(t&&this.Md(t,m)){let R=this.Bd(t,m),O=t[R];x=h.createBlobImageUriFromUint8Array(new Uint8Array(O),c.mimeType)}else p.match(/^data:/)?x=p:x=s+p;n.push(this.kd(x,c,t))}let f=this.Hd(r,t,s);for(let c of f)n.push(c);return b.all(n,a).catch(c=>{y.default.error(`Promise.all error: ${c}`)})}static Hd(e,r,t){var a,n,o;let i=[],s="RHODONITE_materials_node";if(!((a=e.extensionsUsed)!=null&&a.includes(s)))return i;for(let f of(n=e.materials)!=null?n:[]){let u=(o=f.extensions)==null?void 0:o[s];if(!(u!=null&&u.uri))continue;let c=u.uri,p=c.split("/"),d=p[p.length-1],m;if(c.match(/^data:application\/json;base64,/))m=new b(x=>{let R=h.arrayBufferToString(h.dataUriToArrayBuffer(c));u.shaderNodeJson=JSON.parse(R),x(u.shaderNodeJson)});else if(r&&this.Md(r,d))m=new b(x=>{let R=this.Bd(r,d),O=r[R],_=h.arrayBufferToString(O);u.shaderNodeJson=JSON.parse(_),x(u.shaderNodeJson)});else{let x=t?t+c:c;m=new b((R,O)=>{fetch(x).then(_=>{if(!_.ok)throw new Error(`HTTP Error Status: ${_.status}`);return _.json()}).then(_=>{u.shaderNodeJson=_,R(_)}).catch(_=>{y.default.error(`Failed to load .rmn file: ${x}, ${_}`),O(_)})})}i.push(m)}return i}static Md(e,r){for(let t in e){let i=t.split("/");if(i[i.length-1]===r)return!0}return!1}static Bd(e,r){for(let t in e){let i=t.split("/");if(i[i.length-1]===r)return t}}static kd(e,r,t){var s,a;let i;return e.match(/basis$/)?i=new b(n=>{fetch(e,{mode:"cors"}).then(o=>{o.arrayBuffer().then(f=>{let u=new Uint8Array(f);r.basis=u,n(r)})})}):(s=r.uri)!=null&&s.match(/basis$/)?i=new b(n=>{r.basis=new Uint8Array(t[r.uri]),n(r)}):e.match(/\.ktx2$/)||e.match(/^data:image\/ktx2/)||r.bufferView!=null&&r.mimeType==="image/ktx2"?i=new b(n=>{fetch(e,{mode:"cors"}).then(o=>{o.arrayBuffer().then(f=>{let u=new Uint8Array(f);r.ktx2=u,n(r)})})}):(a=r.uri)!=null&&a.match(/ktx2$/)?i=new b(n=>{r.ktx2=new Uint8Array(t[r.uri]),n(r)}):i=new b(async n=>{let o=await h.createImageFromUri(e,r.mimeType);o.crossOrigin="Anonymous",r.image=o,n(r)}),i}};export{M as Gltf2Importer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FileType as c}from"../definitions/FileType.js";import{DataUtil as d}from"../misc/DataUtil.js";import{assertIsErr as x,Err as g,Ok as u}from"../misc/Result.js";import{Expression as E}from"../renderer/Expression.js";import{RenderPass as h}from"../renderer/RenderPass.js";import{detectFormatByArrayBuffers as G}from"./FormatDetector.js";import{Gltf2Importer as w}from"./Gltf2Importer.js";import{ModelConverter as R}from"./ModelConverter.js";import{Vrm0xImporter as O}from"./Vrm0xImporter.js";import{VrmImporter as T}from"./VrmImporter.js";var v=class{constructor(){}static async importFromUrl(r,a,e,t){return new Promise((m,l)=>{(async()=>{var i;e=this.Ed(e);let n=((i=e.expression)==null?void 0:i.renderPasses)||[];n.length===0&&n.push(new h(r));let f=await d.fetchArrayBuffer(a);if(f.isErr()){l(f.getRnError());return}if(e.files[a]=f.get(),await this.Gd(r,a,n,e,a,t),e!=null&&e.cameraComponent)for(let o of n)o.cameraComponent=e.cameraComponent;let s=this.Cd(n,e);m(s)})().catch(l)})}static async importFromArrayBuffers(r,a,e,t){return new Promise((m,l)=>{(async()=>{var s;e=this.Ed(e);let n=((s=e.expression)==null?void 0:s.renderPasses)||[];n.length===0&&n.push(new h(r));for(let i in a){let o=d.getExtension(i);this.Ld(o)&&await this.Gd(r,i,n,e,i,t)}if(e!=null&&e.cameraComponent)for(let i of n)i.cameraComponent=e.cameraComponent;let f=this.Cd(n,e);m(f)})().catch(l)})}static Ed(r){if(r==null)r=d.createDefaultGltfOptions();else{r.files==null&&(r.files={});for(let a in r.files){if(a.match(/.*\.vrm$/)==null)continue;let e=a.split(".vrm")[0];if(e){let t=r.files[a];r.files[`${e}.glb`]=t,delete r.files[a]}}Array.isArray(r.defaultMaterialHelperArgumentArray)===!1?r.defaultMaterialHelperArgumentArray=[{}]:r.defaultMaterialHelperArgumentArray[0].isMorphing===!1&&(r.maxMorphTargetNumber=0)}return r}static Cd(r,a){var t;let e=(t=a.expression)!=null?t:new E;return e.renderPasses!==r&&(e.clearRenderPasses(),e.addRenderPasses(r)),e}static Ld(r){return r==="gltf"||r==="glb"||r==="rnb"||r==="vrm"||r==="drc"}static Fd(r){return new DataView(r,0,20).getUint32(0,!0)===1179937895}static Id(r){return new DataView(r,0,20).getUint32(4,!0)}static Ud(r){var a,e;return((e=(a=r.asset)==null?void 0:a.version)==null?void 0:e.charAt(0))==="2"?2:1}static async Gd(r,a,e,t,p,m){let l=t.fileType,n=this.Dd(a,t,l),f=t.files[a];switch(t.Pd=!1,n){case c.Gltf:{let s=d.arrayBufferToString(f),i=JSON.parse(s),y=await w._importGltf(i,t.files,t,a,m),P=await R.convertToRhodoniteObject(r,y);return e[0].addEntities([P]),t.__importedType="gltf2",new u}case c.GltfBinary:{let i=await w._importGlb(f,t.files,t),o=await R.convertToRhodoniteObject(r,i);return e[0].addEntities([o]),t.__importedType="glb2",new u}case c.Draco:{let{DrcPointCloudImporter:s}=await import("./DrcPointCloudImporter.js"),o=await s.getInstance().importArrayBuffer(p,f,t);if(o==null)return new g({message:"importArrayBuffer error is occurred",error:void 0});t.__importedType="draco";let y=await R.convertToRhodoniteObject(r,o);return e[0].addEntities([y]),new u}case c.VRM:{t.Pd=!0;let s=await w._importGltfOrGlbFromArrayBuffers(f,t.files,t);if(s.isOk()){let i=s.get();return i.extensionsUsed.indexOf("VRMC_vrm")>=0?(t.Pd=!1,i.asset.extras.rnLoaderOptions.Pd=!1,t.__importedType="vrm1",await T.
|
|
1
|
+
import{FileType as c}from"../definitions/FileType.js";import{DataUtil as d}from"../misc/DataUtil.js";import{assertIsErr as x,Err as g,Ok as u}from"../misc/Result.js";import{Expression as E}from"../renderer/Expression.js";import{RenderPass as h}from"../renderer/RenderPass.js";import{detectFormatByArrayBuffers as G}from"./FormatDetector.js";import{Gltf2Importer as w}from"./Gltf2Importer.js";import{ModelConverter as R}from"./ModelConverter.js";import{Vrm0xImporter as O}from"./Vrm0xImporter.js";import{VrmImporter as T}from"./VrmImporter.js";var v=class{constructor(){}static async importFromUrl(r,a,e,t){return new Promise((m,l)=>{(async()=>{var i;e=this.Ed(e);let n=((i=e.expression)==null?void 0:i.renderPasses)||[];n.length===0&&n.push(new h(r));let f=await d.fetchArrayBuffer(a);if(f.isErr()){l(f.getRnError());return}if(e.files[a]=f.get(),await this.Gd(r,a,n,e,a,t),e!=null&&e.cameraComponent)for(let o of n)o.cameraComponent=e.cameraComponent;let s=this.Cd(n,e);m(s)})().catch(l)})}static async importFromArrayBuffers(r,a,e,t){return new Promise((m,l)=>{(async()=>{var s;e=this.Ed(e);let n=((s=e.expression)==null?void 0:s.renderPasses)||[];n.length===0&&n.push(new h(r));for(let i in a){let o=d.getExtension(i);this.Ld(o)&&await this.Gd(r,i,n,e,i,t)}if(e!=null&&e.cameraComponent)for(let i of n)i.cameraComponent=e.cameraComponent;let f=this.Cd(n,e);m(f)})().catch(l)})}static Ed(r){if(r==null)r=d.createDefaultGltfOptions();else{r.files==null&&(r.files={});for(let a in r.files){if(a.match(/.*\.vrm$/)==null)continue;let e=a.split(".vrm")[0];if(e){let t=r.files[a];r.files[`${e}.glb`]=t,delete r.files[a]}}Array.isArray(r.defaultMaterialHelperArgumentArray)===!1?r.defaultMaterialHelperArgumentArray=[{}]:r.defaultMaterialHelperArgumentArray[0].isMorphing===!1&&(r.maxMorphTargetNumber=0)}return r}static Cd(r,a){var t;let e=(t=a.expression)!=null?t:new E;return e.renderPasses!==r&&(e.clearRenderPasses(),e.addRenderPasses(r)),e}static Ld(r){return r==="gltf"||r==="glb"||r==="rnb"||r==="vrm"||r==="drc"}static Fd(r){return new DataView(r,0,20).getUint32(0,!0)===1179937895}static Id(r){return new DataView(r,0,20).getUint32(4,!0)}static Ud(r){var a,e;return((e=(a=r.asset)==null?void 0:a.version)==null?void 0:e.charAt(0))==="2"?2:1}static async Gd(r,a,e,t,p,m){let l=t.fileType,n=this.Dd(a,t,l),f=t.files[a];switch(t.Pd=!1,n){case c.Gltf:{let s=d.arrayBufferToString(f),i=JSON.parse(s),y=await w._importGltf(i,t.files,t,a,m),P=await R.convertToRhodoniteObject(r,y);return e[0].addEntities([P]),t.__importedType="gltf2",new u}case c.GltfBinary:{let i=await w._importGlb(f,t.files,t),o=await R.convertToRhodoniteObject(r,i);return e[0].addEntities([o]),t.__importedType="glb2",new u}case c.Draco:{let{DrcPointCloudImporter:s}=await import("./DrcPointCloudImporter.js"),o=await s.getInstance().importArrayBuffer(p,f,t);if(o==null)return new g({message:"importArrayBuffer error is occurred",error:void 0});t.__importedType="draco";let y=await R.convertToRhodoniteObject(r,o);return e[0].addEntities([y]),new u}case c.VRM:{t.Pd=!0;let s=await w._importGltfOrGlbFromArrayBuffers(f,t.files,t);if(s.isOk()){let i=s.get();return i.extensionsUsed.indexOf("VRMC_vrm")>=0?(t.Pd=!1,i.asset.extras.rnLoaderOptions.Pd=!1,t.__importedType="vrm1",await T.Sd(r,i,e)):i.extensionsUsed.indexOf("VRM")>=0&&(t.__importedType="vrm0x",await O.$d(r,i,e)),new u}return x(s),new g({message:s.getRnError().message,error:void 0})}default:return new g({message:"detect invalid format",error:void 0})}}static Dd(r,a,e){return e!=null?c.fromString(e):G({[r]:a.files[r]})}};export{v as GltfImporter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EffekseerComponent as h}from"../../effekseer/EffekseerComponent.js";import{AnimationComponent as I,WellKnownComponentTIDs as b}from"../components/index.js";import{AnimationInterpolation as T}from"../definitions/index.js";import{AnimatedScalar as O}from"../math/AnimatedScalar.js";import{Scalar as R}from"../math/Scalar.js";import{Vector2 as k}from"../math/Vector2.js";import{Vector3 as S}from"../math/Vector3.js";import{Vector4 as A}from"../math/Vector4.js";import{DataUtil as _}from"../misc/DataUtil.js";import{Is as m}from"../misc/Is.js";import{Logger as E}from"../misc/Logger.js";var y,M,x=class{static importBillboard(e,r){if(!(m.not.exist(e.extensionsUsed)||e.extensionsUsed.indexOf("RHODONITE_billboard")===-1))for(let a in e.nodes){let d=r[a],f=e.nodes[a],n=d.getSceneGraph();f.extensions!==void 0&&f.extensions.RHODONITE_billboard!==void 0&&f.extensions.RHODONITE_billboard.isBillboard===!0&&(n.isBillboard=!0)}}static async preloadNodeBasedMaterialSupport(e){var o;((o=e.materials)==null?void 0:o.some(a=>this.hasNodeBasedMaterialExtension(a)))===!0&&await this.Xd()}static async Xd(){y==null&&(M==null&&(M=import("../helpers/materials/createNodeBasedCustomMaterial.js").then(e=>{y=e.createNodeBasedCustomMaterial})),await M)}static createNodeBasedMaterial(e,r,o,a,d,f){var l;let t=(l=o.extensions)==null?void 0:l["RHODONITE_materials_node"];if(!(t!=null&&t.shaderNodeJson)){E.default.warn("RHODONITE_materials_node: No shader node JSON loaded for material");return}let s=y;if(s==null){E.default.error("RHODONITE_materials_node: Node-based material support is not loaded. Import the model through the ModelConverter, or await RhodoniteImportExtension.preloadNodeBasedMaterialSupport() before creating materials.");return}let i=s(e,t.shaderNodeJson,{...f,maxInstancesNumber:1});if(!i){E.default.error("RHODONITE_materials_node: Failed to create node-based material");return}let p=i.material;return t.uniforms&&this
|
|
1
|
+
import{EffekseerComponent as h}from"../../effekseer/EffekseerComponent.js";import{AnimationComponent as I,WellKnownComponentTIDs as b}from"../components/index.js";import{AnimationInterpolation as T}from"../definitions/index.js";import{AnimatedScalar as O}from"../math/AnimatedScalar.js";import{Scalar as R}from"../math/Scalar.js";import{Vector2 as k}from"../math/Vector2.js";import{Vector3 as S}from"../math/Vector3.js";import{Vector4 as A}from"../math/Vector4.js";import{DataUtil as _}from"../misc/DataUtil.js";import{Is as m}from"../misc/Is.js";import{Logger as E}from"../misc/Logger.js";var y,M,x=class{static importBillboard(e,r){if(!(m.not.exist(e.extensionsUsed)||e.extensionsUsed.indexOf("RHODONITE_billboard")===-1))for(let a in e.nodes){let d=r[a],f=e.nodes[a],n=d.getSceneGraph();f.extensions!==void 0&&f.extensions.RHODONITE_billboard!==void 0&&f.extensions.RHODONITE_billboard.isBillboard===!0&&(n.isBillboard=!0)}}static async preloadNodeBasedMaterialSupport(e){var o;((o=e.materials)==null?void 0:o.some(a=>this.hasNodeBasedMaterialExtension(a)))===!0&&await this.Xd()}static async Xd(){y==null&&(M==null&&(M=import("../helpers/materials/createNodeBasedCustomMaterial.js").then(e=>{y=e.createNodeBasedCustomMaterial})),await M)}static createNodeBasedMaterial(e,r,o,a,d,f){var l;let t=(l=o.extensions)==null?void 0:l["RHODONITE_materials_node"];if(!(t!=null&&t.shaderNodeJson)){E.default.warn("RHODONITE_materials_node: No shader node JSON loaded for material");return}let s=y;if(s==null){E.default.error("RHODONITE_materials_node: Node-based material support is not loaded. Import the model through the ModelConverter, or await RhodoniteImportExtension.preloadNodeBasedMaterialSupport() before creating materials.");return}let i=s(e,t.shaderNodeJson,{...f,maxInstancesNumber:1});if(!i){E.default.error("RHODONITE_materials_node: Failed to create node-based material");return}let p=i.material;return t.uniforms&&this.Jd(p,t.uniforms,r,a,d),p}static hasNodeBasedMaterialExtension(e){var a;if(!e)return!1;let o=(a=e.extensions)==null?void 0:a["RHODONITE_materials_node"];return m.exist(o)&&m.exist(o.shaderNodeJson)}static Kd(e){return typeof e=="object"&&e!==null&&"index"in e&&typeof e.index=="number"}static Jd(e,r,o,a,d){var f;for(let[n,t]of Object.entries(r))try{if(this.Kd(t)){let s=t.index,i=(f=o.textures)==null?void 0:f[s];if(i!=null){let p=i.source,l=i.sampler,u=p!=null?a[p]:void 0,c=l!=null?d[l]:void 0;u&&e.setTextureParameter(n,u,c)}}else if(typeof t=="number")e.setParameter(n,R.fromCopyNumber(t));else if(Array.isArray(t))switch(t.length){case 2:e.setParameter(n,k.fromCopyArray2(t));break;case 3:e.setParameter(n,S.fromCopyArray3(t));break;case 4:e.setParameter(n,A.fromCopyArray4(t));break;default:E.default.warn(`RHODONITE_materials_node: Unsupported uniform array length ${t.length} for '${n}'`)}}catch(s){E.default.warn(`RHODONITE_materials_node: Failed to set uniform '${n}': ${s}`)}}static importEffect(e,r,o){if(m.not.exist(r.extensions)||m.not.exist(r.extensions.RHODONITE_effekseer)||r.extensionsUsed.indexOf("RHODONITE_effekseer")===-1)return;let d=o.getTagValue("rnEntities"),f=r.extensions.RHODONITE_effekseer.effects;for(let n of f){let t=d[n.node],s=e.entityRepository.addComponentToEntity(h,t),i=s.getEffekseer();i.playJustAfterLoaded=!0,i.isLoop=!0,m.exist(n.bufferView)?r.buffers[0].bufferPromise.then(l=>{let u=_.createUint8ArrayFromBufferViewInfo(r,n.bufferView,l);i.arrayBuffer=u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength),i.type="efkpkg"}):m.exist(n.uri)?(i.uri=n.uri,i.type="efk"):E.default.error("No real effect data."),C(e,s,n)}}};function C(N,e,r){let o=e.getComponentByComponentTID(b.EffekseerComponentTID);if(m.exist(o)&&(o.playJustAfterLoaded=!0,o.isLoop=!0,m.exist(r.timelines))){let a=r.timelines;for(let d of a){let f=d.values,n=d.name,t=f.map(c=>({input:c.input,event:c.event})),s=e.tryToGetAnimation(),i;m.not.exist(s)&&(i=N.entityRepository.addComponentToEntity(I,e)),s=i.getAnimation();let p=new Map,l=m.exist(n)?n:"Default";p.set(l,{input:new Float32Array(t.map(c=>c.input)),output:new Float32Array(t.map(c=>c.event==="play"?1:0)),outputComponentN:1,interpolationMethod:T.Step});let u=new O(p,l);s.setAnimation("effekseer",u)}}}export{x as RhodoniteImportExtension};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PhysicsComponent as E}from"../components/Physics/PhysicsComponent.js";import{VrmComponent as T}from"../components/Vrm/VrmComponent.js";import{TextureParameter as y}from"../definitions/index.js";import{Vector3 as S}from"../math/Vector3.js";import{Is as _}from"../misc/Is.js";import{Ok as G}from"../misc/Result.js";import{SphereCollider as O}from"../physics/VRMSpring/SphereCollider.js";import{VRMColliderGroup as v}from"../physics/VRMSpring/VRMColliderGroup.js";import{VRMSpring as w}from"../physics/VRMSpring/VRMSpring.js";import{VRMSpringBone as P}from"../physics/VRMSpring/VRMSpringBone.js";import{VRMSpringBonePhysicsStrategy as C}from"../physics/VRMSpring/VRMSpringBonePhysicsStrategy.js";import{RenderPass as b}from"../renderer/RenderPass.js";import{Sampler as A}from"../textures/Sampler.js";import{Texture as R}from"../textures/Texture.js";import{Gltf2Importer as M}from"./Gltf2Importer.js";import{ModelConverter as h}from"./ModelConverter.js";var V=class l{constructor(){}static async importFromUrl(t,e,i){var c,d;i=this._getOptions(i);let n=await M.importFromUrl(e,i),o=await l._createTextures(t,n),r=l._createSamplers(t,n),a=(d=(c=n.asset.extras)==null?void 0:c.rnLoaderOptions)==null?void 0:d.defaultMaterialHelperArgumentArray;_.exist(a)&&(a[0].textures=o,a[0].samplers=r),l._initializeMaterialProperties(n,o.length);let m,p=await h.convertToRhodoniteObject(t,n);if(l._existOutlineMaterial(n.extensions.VRM)){_.exist(a)&&(a[0].isOutline=!0);let x=await h.convertToRhodoniteObject(t,n);m=[p,x]}else m=[p];return l._readSpringBone(t,n),l._readVRMHumanoidInfo(n,p),new G(m)}static async importJsonOfVRM(t,e){e=this._getOptions(e);let i=await M.importFromUrl(t,e);return l._readVRMHumanoidInfo(i),i}static async
|
|
1
|
+
import{PhysicsComponent as E}from"../components/Physics/PhysicsComponent.js";import{VrmComponent as T}from"../components/Vrm/VrmComponent.js";import{TextureParameter as y}from"../definitions/index.js";import{Vector3 as S}from"../math/Vector3.js";import{Is as _}from"../misc/Is.js";import{Ok as G}from"../misc/Result.js";import{SphereCollider as O}from"../physics/VRMSpring/SphereCollider.js";import{VRMColliderGroup as v}from"../physics/VRMSpring/VRMColliderGroup.js";import{VRMSpring as w}from"../physics/VRMSpring/VRMSpring.js";import{VRMSpringBone as P}from"../physics/VRMSpring/VRMSpringBone.js";import{VRMSpringBonePhysicsStrategy as C}from"../physics/VRMSpring/VRMSpringBonePhysicsStrategy.js";import{RenderPass as b}from"../renderer/RenderPass.js";import{Sampler as A}from"../textures/Sampler.js";import{Texture as R}from"../textures/Texture.js";import{Gltf2Importer as M}from"./Gltf2Importer.js";import{ModelConverter as h}from"./ModelConverter.js";var V=class l{constructor(){}static async importFromUrl(t,e,i){var c,d;i=this._getOptions(i);let n=await M.importFromUrl(e,i),o=await l._createTextures(t,n),r=l._createSamplers(t,n),a=(d=(c=n.asset.extras)==null?void 0:c.rnLoaderOptions)==null?void 0:d.defaultMaterialHelperArgumentArray;_.exist(a)&&(a[0].textures=o,a[0].samplers=r),l._initializeMaterialProperties(n,o.length);let m,p=await h.convertToRhodoniteObject(t,n);if(l._existOutlineMaterial(n.extensions.VRM)){_.exist(a)&&(a[0].isOutline=!0);let x=await h.convertToRhodoniteObject(t,n);m=[p,x]}else m=[p];return l._readSpringBone(t,n),l._readVRMHumanoidInfo(n,p),new G(m)}static async importJsonOfVRM(t,e){e=this._getOptions(e);let i=await M.importFromUrl(t,e);return l._readVRMHumanoidInfo(i),i}static async $d(t,e,i){var p,u,c,d,x,g;let s=(u=(p=e.asset.extras)==null?void 0:p.rnLoaderOptions)==null?void 0:u.defaultMaterialHelperArgumentArray,n=await this._createTextures(t,e),o=this._createSamplers(t,e);_.exist(s)&&(s[0].textures=(c=s[0].textures)!=null?c:n,s[0].samplers=(d=s[0].samplers)!=null?d:o,s[0].isLighting=(x=s[0].isLighting)!=null?x:!0),this._initializeMaterialProperties(e,n.length);let r;if(this._existOutlineMaterial(e.extensions.VRM)){i[1]=(g=i[1])!=null?g:new b(t);let f=i[1];f.toClearColorBuffer=!1,f.toClearDepthBuffer=!1,e.extensions.VRM.rnExtension={renderPassOutline:f},r=await h.convertToRhodoniteObject(t,e),f.addEntities([r])}else r=await h.convertToRhodoniteObject(t,e);let m=i[0];m.tryToSetUniqueName("VRM Main RenderPass",!0),m.addEntities([r]),this._readSpringBone(t,e),this._readVRMHumanoidInfo(e,r),this._readBlendShapeGroup(e,r),r.localEulerAngles=S.fromCopyArray([0,Math.PI,0])}static _readBlendShapeGroup(t,e){let i=[],s=t.extensions.VRM.blendShapeMaster.blendShapeGroups;for(let o of s){let r={name:o.presetName==="unknown"?o.name:o.presetName,isBinary:o.isBinary,binds:o.binds.map(a=>{for(let m=0;m<t.nodes.length;m++)if(t.nodes[m].mesh===a.mesh)return{entityIdx:t.extras.rnEntities[m].entityUID,blendShapeIdx:a.index,weight:a.weight/100};throw new Error("Not Found node in blendShapeGroup Process")})};i.push(r)}let n=e.engine.entityRepository.addComponentToEntity(T,e);n.getVrm().setVrmExpressions(i),n.getVrm()._version="0.x"}static _readVRMHumanoidInfo(t,e){let i=t.extensions.VRM.humanoid.humanBones,s=new Map;for(let n of i){s.set(n.bone,n.node);let o=t.nodes[n.node];n.name=o.name}e!=null&&e.tryToSetTag({tag:"humanoid_map_name_nodeId",value:s})}static _readSpringBone(t,e){let i=[];for(let n in e.extensions.VRM.secondaryAnimation.colliderGroups){let o=e.extensions.VRM.secondaryAnimation.colliderGroups[n],r=new v;i.push(r);let a=[],m=e.asset.extras.rnEntities[o.node].getSceneGraph();for(let p of o.colliders){let u=new O(t,S.fromCopyArray([p.offset.x,p.offset.y,-p.offset.z]),p.radius,m);a.push(u)}r.sphereColliders=a}let s=[];for(let n of e.extensions.VRM.secondaryAnimation.boneGroups){if(n.bones==null||n.bones.length===0)continue;let o=n.bones[0],r=e.asset.extras.rnEntities[o],a=new w(r.getSceneGraph());a.tryToSetUniqueName(n.comment,!0),a.colliderGroups=n.colliderGroups.map(p=>i[p]);let m=[];for(let p in n.bones){let u=n.bones[p],c=e.asset.extras.rnEntities[u];this.zd(a,c,n,m)}n.center!=null&&n.center!==-1&&(a.center=e.asset.extras.rnEntities[n.center].getSceneGraph()),s.push(a)}for(let n of s)this.qd(n,n.rootBone)}static zd(t,e,i,s){let o=e.getSceneGraph().children;if(!s.includes(e)){let r=new P(e);r.dragForce=i.dragForce,r.stiffnessForce=i.stiffiness,r.gravityPower=i.gravityPower,r.gravityDir=S.fromCopyArray([i.gravityDir.x,i.gravityDir.y,i.gravityDir.z]),r.hitRadius=i.hitRadius,t.bones.push(r),s.push(e)}for(let r of o)this.zd(t,r.entity,i,s)}static qd(t,e){let i=e.entity,n=i.engine.entityRepository.addComponentToEntity(E,i).getPhysics(),o=new C;o.setSpring(t),n.setStrategy(o)}static async _createTextures(t,e){e.textures||(e.textures=[]);let i=e.textures,s=[];for(let r=0;r<i.length;r++){let a=await h._createTexture(t,i[r].sourceObject,e);s[r]=a}let n=new R(t);await n.generate1x1TextureFrom(),n.markAsDummyTexture(),s.push(n);let o=new R(t);return await o.generate1x1TextureFrom("rgba(0, 0, 0, 1)"),o.markAsDummyTexture(),s.push(o),s}static _createSamplers(t,e){e.textures||(e.textures=[]);let i=e.textures,s=[];for(let o=0;o<i.length;o++){let r=h._createSampler(t,i[o].samplerObject);s[o]=r}let n=new A(t,{wrapS:y.ClampToEdge,wrapT:y.ClampToEdge,minFilter:y.Linear,magFilter:y.Linear});return n.create(),s.push(n),s.push(n),s}static _existOutlineMaterial(t){let e=t.materialProperties;if(e!=null){for(let i of e)if(i.floatProperties._OutlineWidthMode!==0)return!0}return!1}static _initializeMaterialProperties(t,e){let i=t.extensions.VRM.materialProperties;for(let s of i)if(s.shader==="VRM/MToon"){this.Zd(t,e);break}}static Zd(t,e){let i=t.extensions.VRM.materialProperties,s=e-2,n=e-1;for(let o=0;o<i.length;o++){let r=i[o].floatProperties;this.Wd(r,"_BlendMode",0),this.Wd(r,"_BumpScale",1),this.Wd(r,"_CullMode",2),this.Wd(r,"_Cutoff",.5),this.Wd(r,"_DebugMode",0),this.Wd(r,"_DstBlend",0),this.Wd(r,"_IndirectLightIntensity",.1),this.Wd(r,"_LightColorAttenuation",0),this.Wd(r,"_OutlineColorMode",0),this.Wd(r,"_OutlineCullMode",1),this.Wd(r,"_OutlineLightingMix",1),this.Wd(r,"_OutlineScaledMaxDistance",1),this.Wd(r,"_OutlineWidth",.5),this.Wd(r,"_OutlineWidthMode",0),this.Wd(r,"_ReceiveShadowRate",1),this.Wd(r,"_RimFresnelPower",1),this.Wd(r,"_RimLift",0),this.Wd(r,"_RimLightingMix",0),this.Wd(r,"_ShadeShift",0),this.Wd(r,"_ShadeToony",.9),this.Wd(r,"_ShadingGradeRate",1),this.Wd(r,"_SrcBlend",1),this.Wd(r,"_ZWrite",1);let a=i[o].vectorProperties;this.Wd(a,"_Color",[1,1,1,1]),this.Wd(a,"_EmissionColor",[0,0,0]),this.Wd(a,"_OutlineColor",[0,0,0,1]),this.Wd(a,"_ShadeColor",[.97,.81,.86,1]),this.Wd(a,"_RimColor",[0,0,0]);let m=i[o].textureProperties;this.Wd(m,"_BumpMap",s),this.Wd(m,"_EmissionMap",n),this.Wd(m,"_MainTex",s),this.Wd(m,"_OutlineWidthTexture",s),this.Wd(m,"_ReceiveShadowTexture",s),this.Wd(m,"_RimTexture",n),this.Wd(m,"_ShadeTexture",s),this.Wd(m,"_ShadingGradeTexture",s),this.Wd(m,"_SphereAdd",n)}for(let o=0;o<t.materials.length;o++){let r=t.materials[o];r.extras==null&&(r.extras={}),r.extras.vrm0xMaterialProperty=i[o]}}static Wd(t,e,i){t[e]==null&&(t[e]=i)}static _getOptions(t){if(t!=null){for(let e in t.files){let i=e.split(".vrm")[0];if(i){let s=t.files[e];t.files[`${i}.glb`]=s,delete t.files[e]}}t.Pd=!0,t.defaultMaterialHelperArgumentArray==null&&(t.defaultMaterialHelperArgumentArray=[{}]),t.defaultMaterialHelperArgumentArray[0].isMorphing||(t.maxMorphTargetNumber=0)}else t={files:{},loaderExtension:void 0,defaultMaterialHelperName:void 0,defaultMaterialHelperArgumentArray:[{isLighting:!0,isMorphing:!0,isSkinning:!0}],statesOfElements:[{targets:[],states:{enable:[],functions:{}},isTransparent:!0,opacity:1,isTextureImageToLoadPreMultipliedAlpha:!1}],Pd:!0,__importedType:"vrm0x"};return t}};export{V as Vrm0xImporter};
|