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.
Files changed (370) hide show
  1. package/VERSION-FILE +1 -1
  2. package/dist/esm/foundation/core/MemoryManager.d.ts +19 -0
  3. package/dist/esm/foundation/core/MemoryManager.js +2 -2
  4. package/dist/esm/foundation/definitions/ShaderSemantics.d.ts +1 -0
  5. package/dist/esm/foundation/definitions/ShaderSemantics.js +2 -2
  6. package/dist/esm/foundation/helpers/Shadow/ShadowSystem.js +1 -1
  7. package/dist/esm/foundation/helpers/materials/createNodeBasedRaymarchingMaterials.js +1 -1
  8. package/dist/esm/foundation/helpers/materials/nodeBasedMaterialCommon.js +1 -1
  9. package/dist/esm/foundation/importer/DrcPointCloudImporter.js +1 -1
  10. package/dist/esm/foundation/importer/Gltf2Importer.d.ts +2 -1
  11. package/dist/esm/foundation/importer/Gltf2Importer.js +1 -1
  12. package/dist/esm/foundation/importer/GltfImporter.js +1 -1
  13. package/dist/esm/foundation/importer/RhodoniteImportExtension.js +1 -1
  14. package/dist/esm/foundation/importer/Vrm0xImporter.js +1 -1
  15. package/dist/esm/foundation/importer/VrmImporter.js +1 -1
  16. package/dist/esm/foundation/materials/contents/CustomMaterialContent.js +1 -1
  17. package/dist/esm/foundation/materials/contents/MToon0xMaterialContent.js +11 -11
  18. package/dist/esm/foundation/materials/contents/MToon1MaterialContent.js +6 -6
  19. package/dist/esm/foundation/materials/core/AbstractMaterialContent.js +1 -1
  20. package/dist/esm/foundation/materials/core/Material.d.ts +7 -2
  21. package/dist/esm/foundation/materials/core/Material.js +1 -1
  22. package/dist/esm/foundation/materials/core/ShaderityUtilityWebGL.js +2 -2
  23. package/dist/esm/foundation/materials/core/ShaderityUtilityWebGPU.js +2 -2
  24. package/dist/esm/foundation/memory/Accessor.js +6 -6
  25. package/dist/esm/foundation/memory/BufferView.js +1 -1
  26. package/dist/esm/foundation/misc/PngDecoder.d.ts +18 -0
  27. package/dist/esm/foundation/misc/PngDecoder.js +1 -0
  28. package/dist/esm/foundation/renderer/RenderPass.d.ts +7 -0
  29. package/dist/esm/foundation/renderer/RenderPass.js +1 -1
  30. package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +2 -1
  31. package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.js +1 -1
  32. package/dist/esm/foundation/system/Engine.js +1 -1
  33. package/dist/esm/foundation/textures/CubeTexture.d.ts +11 -2
  34. package/dist/esm/foundation/textures/CubeTexture.js +1 -1
  35. package/dist/esm/foundation/textures/RenderTargetTexture2DArray.js +1 -1
  36. package/dist/esm/foundation/textures/RenderTargetTextureCube.d.ts +6 -0
  37. package/dist/esm/foundation/textures/RenderTargetTextureCube.js +1 -1
  38. package/dist/esm/version.js +1 -1
  39. package/dist/esm/webgl/MultiDraw.js +1 -1
  40. package/dist/esm/webgl/MultiDrawRepository.js +1 -1
  41. package/dist/esm/webgl/WebGLResourceRepository.d.ts +5 -0
  42. package/dist/esm/webgl/WebGLResourceRepository.js +3 -3
  43. package/dist/esm/webgl/WebGLStereoUtil.js +1 -1
  44. package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +19 -14
  45. package/dist/esm/webgl/WebGLStrategyWebGL2.js +67 -67
  46. package/dist/esm/webgl/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.glsl.js +2 -1
  47. package/dist/esm/webgl/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.glsl.js +1 -0
  48. package/dist/esm/webgl/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -0
  49. package/dist/esm/webgl/shaderity_shaders/common/iblDefinition.glsl.js +11 -5
  50. package/dist/esm/webgl/shaders/nodes/BlockBeginShader.js +1 -1
  51. package/dist/esm/webgl/shaders/nodes/BlockEndShader.js +1 -1
  52. package/dist/esm/webgl/shaders/nodes/ConstantVariableShader.js +5 -5
  53. package/dist/esm/webgl/shaders/nodes/RaymarchObjectIdUniform.js +3 -3
  54. package/dist/esm/webgl/shaders/nodes/SdApplyWorldMatrix.js +3 -3
  55. package/dist/esm/webgl/shaders/nodes/Texture2DShader.js +14 -14
  56. package/dist/esm/webgl/shaders/nodes/UniformDataShader.js +13 -13
  57. package/dist/esm/webgpu/GpuCullingRegistry.js +1 -1
  58. package/dist/esm/webgpu/GpuDeformRegistry.js +1 -1
  59. package/dist/esm/webgpu/WebGpuGpuTimer.js +1 -1
  60. package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +6 -0
  61. package/dist/esm/webgpu/WebGpuResourceRepository.js +5 -5
  62. package/dist/esm/webgpu/WebGpuStrategyBasic.js +2 -2
  63. package/dist/esm/webgpu/WebGpuVertexDeformer.js +1 -1
  64. package/dist/esm/webgpu/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.wgsl.js +1 -0
  65. package/dist/esm/webgpu/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.wgsl.js +1 -0
  66. package/dist/esm/webgpu/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +1 -0
  67. package/dist/esm/webgpu/shaderity_shaders/common/iblDefinition.wgsl.js +10 -4
  68. package/dist/esmdev/foundation/core/MemoryManager.d.ts +19 -0
  69. package/dist/esmdev/foundation/core/MemoryManager.js +28 -3
  70. package/dist/esmdev/foundation/core/RnObject.js +37 -37
  71. package/dist/esmdev/foundation/definitions/Blend.js +3 -3
  72. package/dist/esmdev/foundation/definitions/ComponentType.js +7 -7
  73. package/dist/esmdev/foundation/definitions/CompositionType.js +50 -50
  74. package/dist/esmdev/foundation/definitions/CompressionTextureType.js +6 -6
  75. package/dist/esmdev/foundation/definitions/ShaderSemantics.d.ts +1 -0
  76. package/dist/esmdev/foundation/definitions/ShaderSemantics.js +12 -7
  77. package/dist/esmdev/foundation/definitions/TextureFormat.js +3 -3
  78. package/dist/esmdev/foundation/definitions/TextureParameter.js +3 -3
  79. package/dist/esmdev/foundation/definitions/VertexAttribute.js +30 -30
  80. package/dist/esmdev/foundation/enhanced_js_objects/Array.js +2 -2
  81. package/dist/esmdev/foundation/exporter/Gltf2Exporter.js +106 -106
  82. package/dist/esmdev/foundation/geometry/ComplexVertexAttribute.js +18 -18
  83. package/dist/esmdev/foundation/geometry/Frustum.js +39 -39
  84. package/dist/esmdev/foundation/geometry/Mesh.js +205 -205
  85. package/dist/esmdev/foundation/geometry/Primitive.js +124 -124
  86. package/dist/esmdev/foundation/geometry/SimpleVertexAttribute.js +7 -7
  87. package/dist/esmdev/foundation/geometry/shapes/Cylinder.js +3 -3
  88. package/dist/esmdev/foundation/geometry/shapes/Joint.js +33 -33
  89. package/dist/esmdev/foundation/gizmos/AABBGizmo.js +12 -12
  90. package/dist/esmdev/foundation/gizmos/CapsuleColliderGizmo.js +23 -23
  91. package/dist/esmdev/foundation/gizmos/Gizmo.js +23 -23
  92. package/dist/esmdev/foundation/gizmos/JointGizmo.js +35 -35
  93. package/dist/esmdev/foundation/gizmos/LightGizmo.js +23 -23
  94. package/dist/esmdev/foundation/gizmos/LocatorGizmo.js +22 -22
  95. package/dist/esmdev/foundation/gizmos/RotationGizmo.js +197 -197
  96. package/dist/esmdev/foundation/gizmos/ScaleGizmo.js +129 -129
  97. package/dist/esmdev/foundation/gizmos/ShapeGizmo.js +43 -43
  98. package/dist/esmdev/foundation/gizmos/SphereColliderGizmo.js +24 -24
  99. package/dist/esmdev/foundation/gizmos/TranslationGizmo.js +129 -129
  100. package/dist/esmdev/foundation/helpers/BloomHelper.js +28 -28
  101. package/dist/esmdev/foundation/helpers/GaussianBlurHelper.js +18 -18
  102. package/dist/esmdev/foundation/helpers/Shadow/PointShadowMap.js +11 -11
  103. package/dist/esmdev/foundation/helpers/Shadow/ShadowMap.js +5 -5
  104. package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.js +111 -111
  105. package/dist/esmdev/foundation/helpers/materials/createNodeBasedRaymarchingMaterials.js +10 -1
  106. package/dist/esmdev/foundation/helpers/materials/nodeBasedMaterialCommon.js +11 -1
  107. package/dist/esmdev/foundation/importer/AnimationAssigner.js +44 -44
  108. package/dist/esmdev/foundation/importer/DrcPointCloudImporter.js +27 -27
  109. package/dist/esmdev/foundation/importer/Gltf2Importer.d.ts +2 -1
  110. package/dist/esmdev/foundation/importer/Gltf2Importer.js +21 -17
  111. package/dist/esmdev/foundation/importer/GltfImporter.js +22 -22
  112. package/dist/esmdev/foundation/importer/ModelConverter.js +131 -131
  113. package/dist/esmdev/foundation/importer/RhodoniteImportExtension.js +6 -6
  114. package/dist/esmdev/foundation/importer/Vrm0xImporter.js +48 -48
  115. package/dist/esmdev/foundation/importer/VrmImporter.js +10 -10
  116. package/dist/esmdev/foundation/materials/contents/CustomMaterialContent.js +37 -28
  117. package/dist/esmdev/foundation/materials/contents/DepthEncodeMaterialContent.js +2 -2
  118. package/dist/esmdev/foundation/materials/contents/MToon0xMaterialContent.js +145 -137
  119. package/dist/esmdev/foundation/materials/contents/MToon1MaterialContent.js +27 -19
  120. package/dist/esmdev/foundation/materials/contents/ShadowMapDecodeClassicMaterialContent.js +5 -5
  121. package/dist/esmdev/foundation/materials/contents/VarianceShadowMapDecodeClassicMaterialContent.js +4 -4
  122. package/dist/esmdev/foundation/materials/core/AbstractMaterialContent.js +47 -47
  123. package/dist/esmdev/foundation/materials/core/AbstractShaderNode.js +25 -25
  124. package/dist/esmdev/foundation/materials/core/DummyTextures.js +3 -3
  125. package/dist/esmdev/foundation/materials/core/Material.d.ts +7 -2
  126. package/dist/esmdev/foundation/materials/core/Material.js +113 -99
  127. package/dist/esmdev/foundation/materials/core/MaterialRepository.js +51 -51
  128. package/dist/esmdev/foundation/materials/core/ShaderGraphResolver.js +38 -38
  129. package/dist/esmdev/foundation/materials/core/ShaderHandler.js +4 -4
  130. package/dist/esmdev/foundation/materials/core/ShaderityUtilityWebGL.js +14 -14
  131. package/dist/esmdev/foundation/materials/core/ShaderityUtilityWebGPU.js +15 -15
  132. package/dist/esmdev/foundation/materials/nodes/AbsShaderNode.js +13 -13
  133. package/dist/esmdev/foundation/materials/nodes/AcosShaderNode.js +13 -13
  134. package/dist/esmdev/foundation/materials/nodes/AddShaderNode.js +18 -18
  135. package/dist/esmdev/foundation/materials/nodes/AlphaTestShaderNode.js +5 -5
  136. package/dist/esmdev/foundation/materials/nodes/AndShaderNode.js +6 -6
  137. package/dist/esmdev/foundation/materials/nodes/Atan2ShaderNode.js +15 -15
  138. package/dist/esmdev/foundation/materials/nodes/AttributeColorShaderNode.js +1 -1
  139. package/dist/esmdev/foundation/materials/nodes/AttributeInstanceIdsShaderNode.js +1 -1
  140. package/dist/esmdev/foundation/materials/nodes/AttributeJointShaderNode.js +1 -1
  141. package/dist/esmdev/foundation/materials/nodes/AttributeNormalShaderNode.js +1 -1
  142. package/dist/esmdev/foundation/materials/nodes/AttributePositionShaderNode.js +2 -2
  143. package/dist/esmdev/foundation/materials/nodes/AttributeTangentShaderNode.js +1 -1
  144. package/dist/esmdev/foundation/materials/nodes/AttributeTexcoordShaderNode.js +2 -2
  145. package/dist/esmdev/foundation/materials/nodes/AttributeWeightShaderNode.js +1 -1
  146. package/dist/esmdev/foundation/materials/nodes/BlockBeginShaderNode.js +11 -11
  147. package/dist/esmdev/foundation/materials/nodes/BlockEndShaderNode.js +6 -6
  148. package/dist/esmdev/foundation/materials/nodes/BranchShaderNode.js +15 -15
  149. package/dist/esmdev/foundation/materials/nodes/CalcBitangentShaderNode.js +7 -7
  150. package/dist/esmdev/foundation/materials/nodes/CastToFloatShaderNode.js +13 -13
  151. package/dist/esmdev/foundation/materials/nodes/ClampShaderNode.js +15 -15
  152. package/dist/esmdev/foundation/materials/nodes/ClassicShaderNode.js +11 -11
  153. package/dist/esmdev/foundation/materials/nodes/ConstantScalarVariableShaderNode.js +1 -1
  154. package/dist/esmdev/foundation/materials/nodes/ConstantVariableShaderNode.js +5 -5
  155. package/dist/esmdev/foundation/materials/nodes/ConstantVector2VariableShaderNode.js +1 -1
  156. package/dist/esmdev/foundation/materials/nodes/ConstantVector3VariableShaderNode.js +1 -1
  157. package/dist/esmdev/foundation/materials/nodes/ConstantVector4VariableShaderNode.js +1 -1
  158. package/dist/esmdev/foundation/materials/nodes/CosShaderNode.js +13 -13
  159. package/dist/esmdev/foundation/materials/nodes/DiscardShaderNode.js +2 -2
  160. package/dist/esmdev/foundation/materials/nodes/DotProductShaderNode.js +10 -10
  161. package/dist/esmdev/foundation/materials/nodes/EqualShaderNode.js +10 -10
  162. package/dist/esmdev/foundation/materials/nodes/FlatShaderNode.js +5 -5
  163. package/dist/esmdev/foundation/materials/nodes/GreaterOrEqualShaderNode.js +10 -10
  164. package/dist/esmdev/foundation/materials/nodes/GreaterShaderNode.js +3 -3
  165. package/dist/esmdev/foundation/materials/nodes/GreaterThanShaderNode.js +10 -10
  166. package/dist/esmdev/foundation/materials/nodes/LengthShaderNode.js +13 -13
  167. package/dist/esmdev/foundation/materials/nodes/LessOrEqualShaderNode.js +10 -10
  168. package/dist/esmdev/foundation/materials/nodes/LessThanShaderNode.js +10 -10
  169. package/dist/esmdev/foundation/materials/nodes/MergeVectorShaderNode.js +19 -19
  170. package/dist/esmdev/foundation/materials/nodes/MinShaderNode.js +18 -18
  171. package/dist/esmdev/foundation/materials/nodes/MultiplyShaderNode.js +21 -21
  172. package/dist/esmdev/foundation/materials/nodes/NormalMatrixShaderNode.js +1 -1
  173. package/dist/esmdev/foundation/materials/nodes/NormalizeShaderNode.js +9 -9
  174. package/dist/esmdev/foundation/materials/nodes/NotEqualShaderNode.js +10 -10
  175. package/dist/esmdev/foundation/materials/nodes/OrShaderNode.js +6 -6
  176. package/dist/esmdev/foundation/materials/nodes/OutColorShaderNode.js +2 -2
  177. package/dist/esmdev/foundation/materials/nodes/OutPositionShaderNode.js +2 -2
  178. package/dist/esmdev/foundation/materials/nodes/PbrAnisotropyPropsShaderNode.js +5 -5
  179. package/dist/esmdev/foundation/materials/nodes/PbrAnisotropyRotationShaderNode.js +3 -3
  180. package/dist/esmdev/foundation/materials/nodes/PbrBaseColorPropsShaderNode.js +5 -5
  181. package/dist/esmdev/foundation/materials/nodes/PbrClearcoatPropsShaderNode.js +7 -7
  182. package/dist/esmdev/foundation/materials/nodes/PbrDiffuseTransmissionPropsShaderNode.js +6 -6
  183. package/dist/esmdev/foundation/materials/nodes/PbrEmissivePropsShaderNode.js +5 -5
  184. package/dist/esmdev/foundation/materials/nodes/PbrIridescencePropsShaderNode.js +8 -8
  185. package/dist/esmdev/foundation/materials/nodes/PbrMetallicRoughnessPropsShaderNode.js +6 -6
  186. package/dist/esmdev/foundation/materials/nodes/PbrNormalPropsShaderNode.js +11 -11
  187. package/dist/esmdev/foundation/materials/nodes/PbrOcclusionPropsShaderNode.js +4 -4
  188. package/dist/esmdev/foundation/materials/nodes/PbrShaderShaderNode.js +21 -21
  189. package/dist/esmdev/foundation/materials/nodes/PbrSheenPropsShaderNode.js +6 -6
  190. package/dist/esmdev/foundation/materials/nodes/PbrSpecularPropsShaderNode.js +6 -6
  191. package/dist/esmdev/foundation/materials/nodes/PbrTransmissionPropsShaderNode.js +4 -4
  192. package/dist/esmdev/foundation/materials/nodes/PbrVolumePropsShaderNode.js +6 -6
  193. package/dist/esmdev/foundation/materials/nodes/PremultipliedAlphaShaderNode.js +4 -4
  194. package/dist/esmdev/foundation/materials/nodes/ProcessGeometryShaderNode.js +22 -22
  195. package/dist/esmdev/foundation/materials/nodes/ProjectionMatrixShaderNode.js +1 -1
  196. package/dist/esmdev/foundation/materials/nodes/Random_HashPRNGShaderNode.js +12 -12
  197. package/dist/esmdev/foundation/materials/nodes/Random_SinHashShaderNode.js +12 -12
  198. package/dist/esmdev/foundation/materials/nodes/RemapShaderNode.js +17 -17
  199. package/dist/esmdev/foundation/materials/nodes/SinShaderNode.js +13 -13
  200. package/dist/esmdev/foundation/materials/nodes/SmoothStepShaderNode.js +15 -15
  201. package/dist/esmdev/foundation/materials/nodes/SplitVectorShaderNode.js +17 -17
  202. package/dist/esmdev/foundation/materials/nodes/StepShaderNode.js +14 -14
  203. package/dist/esmdev/foundation/materials/nodes/TanShaderNode.js +13 -13
  204. package/dist/esmdev/foundation/materials/nodes/Texture2DShaderNode.js +16 -16
  205. package/dist/esmdev/foundation/materials/nodes/TimeShaderNode.js +1 -1
  206. package/dist/esmdev/foundation/materials/nodes/TransformShaderNode.js +10 -10
  207. package/dist/esmdev/foundation/materials/nodes/UniformDataShaderNode.js +5 -5
  208. package/dist/esmdev/foundation/materials/nodes/ViewMatrixShaderNode.js +1 -1
  209. package/dist/esmdev/foundation/materials/nodes/WireframeMaterialNode.js +3 -3
  210. package/dist/esmdev/foundation/materials/nodes/WorldMatrixShaderNode.js +1 -1
  211. package/dist/esmdev/foundation/materials/nodes/raymarching/BendXYShaderNode.js +4 -4
  212. package/dist/esmdev/foundation/materials/nodes/raymarching/BendXZShaderNode.js +4 -4
  213. package/dist/esmdev/foundation/materials/nodes/raymarching/BendYXShaderNode.js +4 -4
  214. package/dist/esmdev/foundation/materials/nodes/raymarching/BendYZShaderNode.js +4 -4
  215. package/dist/esmdev/foundation/materials/nodes/raymarching/BendZXShaderNode.js +4 -4
  216. package/dist/esmdev/foundation/materials/nodes/raymarching/BendZYShaderNode.js +4 -4
  217. package/dist/esmdev/foundation/materials/nodes/raymarching/InitialPositionShaderNode.js +1 -1
  218. package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothIntersectionShaderNode.js +5 -5
  219. package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothSubtractionShaderNode.js +5 -5
  220. package/dist/esmdev/foundation/materials/nodes/raymarching/OpSmoothUnionShaderNode.js +5 -5
  221. package/dist/esmdev/foundation/materials/nodes/raymarching/OpSubtractionShaderNode.js +6 -6
  222. package/dist/esmdev/foundation/materials/nodes/raymarching/OpUnionShaderNode.js +6 -6
  223. package/dist/esmdev/foundation/materials/nodes/raymarching/OutDistanceShaderNode.js +15 -15
  224. package/dist/esmdev/foundation/materials/nodes/raymarching/OutShadingColorShaderNode.js +2 -2
  225. package/dist/esmdev/foundation/materials/nodes/raymarching/OutUnionShaderNode.js +15 -15
  226. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchCameraPositionShaderNode.js +2 -2
  227. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitDistanceShaderNode.js +2 -2
  228. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitNormalShaderNode.js +2 -2
  229. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchHitPositionShaderNode.js +2 -2
  230. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchObjectIdShaderNode.js +2 -2
  231. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchObjectIdUniformShaderNode.js +4 -4
  232. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchRayDirectionShaderNode.js +2 -2
  233. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchTBNShaderNode.js +2 -2
  234. package/dist/esmdev/foundation/materials/nodes/raymarching/RaymarchViewDirectionShaderNode.js +2 -2
  235. package/dist/esmdev/foundation/materials/nodes/raymarching/SdApplyTransformShaderNode.js +9 -9
  236. package/dist/esmdev/foundation/materials/nodes/raymarching/SdApplyWorldMatrixShaderNode.js +5 -5
  237. package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarXShaderNode.js +3 -3
  238. package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarYShaderNode.js +3 -3
  239. package/dist/esmdev/foundation/materials/nodes/raymarching/SdBarZShaderNode.js +3 -3
  240. package/dist/esmdev/foundation/materials/nodes/raymarching/SdBoxShaderNode.js +3 -3
  241. package/dist/esmdev/foundation/materials/nodes/raymarching/SdCapsuleShaderNode.js +5 -5
  242. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatShaderNode.js +4 -4
  243. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatXShaderNode.js +4 -4
  244. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatXYShaderNode.js +4 -4
  245. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatYShaderNode.js +4 -4
  246. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatYZShaderNode.js +4 -4
  247. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatZShaderNode.js +4 -4
  248. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRepeatZXShaderNode.js +4 -4
  249. package/dist/esmdev/foundation/materials/nodes/raymarching/SdRoundBoxShaderNode.js +4 -4
  250. package/dist/esmdev/foundation/materials/nodes/raymarching/SdSphereShaderNode.js +3 -3
  251. package/dist/esmdev/foundation/materials/nodes/raymarching/SdTorusShaderNode.js +4 -4
  252. package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeXShaderNode.js +3 -3
  253. package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeYShaderNode.js +3 -3
  254. package/dist/esmdev/foundation/materials/nodes/raymarching/SdTubeZShaderNode.js +3 -3
  255. package/dist/esmdev/foundation/materials/nodes/raymarching/TwistXShaderNode.js +4 -4
  256. package/dist/esmdev/foundation/materials/nodes/raymarching/TwistYShaderNode.js +4 -4
  257. package/dist/esmdev/foundation/materials/nodes/raymarching/TwistZShaderNode.js +4 -4
  258. package/dist/esmdev/foundation/math/AABB.js +120 -120
  259. package/dist/esmdev/foundation/math/AnimatedQuaternion.js +53 -53
  260. package/dist/esmdev/foundation/math/AnimatedScalar.js +54 -54
  261. package/dist/esmdev/foundation/math/AnimatedValueEvaluationState.js +18 -18
  262. package/dist/esmdev/foundation/math/AnimatedVector2.js +54 -54
  263. package/dist/esmdev/foundation/math/AnimatedVector3.js +54 -54
  264. package/dist/esmdev/foundation/math/AnimatedVector4.js +54 -54
  265. package/dist/esmdev/foundation/math/AnimatedVectorN.js +54 -54
  266. package/dist/esmdev/foundation/math/IdentityMatrix33.js +2 -2
  267. package/dist/esmdev/foundation/math/IdentityMatrix44.js +2 -2
  268. package/dist/esmdev/foundation/math/MathClassUtil.js +3 -3
  269. package/dist/esmdev/foundation/math/Quaternion.js +13 -13
  270. package/dist/esmdev/foundation/math/Transform3D.js +72 -72
  271. package/dist/esmdev/foundation/math/shapes/MathSphere.js +7 -7
  272. package/dist/esmdev/foundation/memory/Accessor.js +369 -369
  273. package/dist/esmdev/foundation/memory/Buffer.js +39 -39
  274. package/dist/esmdev/foundation/memory/BufferView.js +29 -29
  275. package/dist/esmdev/foundation/misc/DataUtil.js +2 -2
  276. package/dist/esmdev/foundation/misc/EnumIO.js +8 -8
  277. package/dist/esmdev/foundation/misc/Logger.js +14 -14
  278. package/dist/esmdev/foundation/misc/PngDecoder.d.ts +18 -0
  279. package/dist/esmdev/foundation/misc/PngDecoder.js +113 -0
  280. package/dist/esmdev/foundation/misc/RnPromise.js +14 -14
  281. package/dist/esmdev/foundation/misc/Time.js +23 -23
  282. package/dist/esmdev/foundation/misc/WeakOption.js +14 -14
  283. package/dist/esmdev/foundation/misc/cache/Cache.js +2 -2
  284. package/dist/esmdev/foundation/misc/cache/SymbolWeakMap.js +8 -8
  285. package/dist/esmdev/foundation/physics/PhysicsWorldQuery.js +10 -10
  286. package/dist/esmdev/foundation/physics/Rapier/RapierCharacterControllerStrategy.js +186 -186
  287. package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsStrategy.js +221 -221
  288. package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsWorldQueryStrategy.js +3 -3
  289. package/dist/esmdev/foundation/physics/VRMSpring/CapsuleCollider.js +36 -36
  290. package/dist/esmdev/foundation/physics/VRMSpring/SphereCollider.js +26 -26
  291. package/dist/esmdev/foundation/physics/VRMSpring/VRMSpringBone.js +6 -6
  292. package/dist/esmdev/foundation/physics/VRMSpring/VRMSpringBonePhysicsStrategy.js +39 -39
  293. package/dist/esmdev/foundation/renderer/Expression.js +6 -6
  294. package/dist/esmdev/foundation/renderer/Frame.js +6 -6
  295. package/dist/esmdev/foundation/renderer/FrameBuffer.js +25 -25
  296. package/dist/esmdev/foundation/renderer/RenderPass.d.ts +7 -0
  297. package/dist/esmdev/foundation/renderer/RenderPass.js +94 -86
  298. package/dist/esmdev/foundation/renderer/TemporalAA/PreviousFrameDataTracker.js +6 -6
  299. package/dist/esmdev/foundation/renderer/TemporalAA/TemporalAASystem.js +75 -75
  300. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.js +146 -146
  301. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystemStub.js +3 -3
  302. package/dist/esmdev/foundation/renderer/pipelines/DeferredRenderPipeline.js +4 -4
  303. package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +2 -1
  304. package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.js +420 -420
  305. package/dist/esmdev/foundation/system/Engine.js +209 -209
  306. package/dist/esmdev/foundation/system/EventPubSub.js +8 -8
  307. package/dist/esmdev/foundation/system/InputManager.js +56 -56
  308. package/dist/esmdev/foundation/system/ModuleManager.js +3 -3
  309. package/dist/esmdev/foundation/textures/AbstractTexture.js +48 -48
  310. package/dist/esmdev/foundation/textures/CubeTexture.d.ts +11 -2
  311. package/dist/esmdev/foundation/textures/CubeTexture.js +47 -36
  312. package/dist/esmdev/foundation/textures/RenderBuffer.js +11 -11
  313. package/dist/esmdev/foundation/textures/RenderTargetTexture.js +24 -24
  314. package/dist/esmdev/foundation/textures/RenderTargetTexture2DArray.js +35 -35
  315. package/dist/esmdev/foundation/textures/RenderTargetTextureCube.d.ts +6 -0
  316. package/dist/esmdev/foundation/textures/RenderTargetTextureCube.js +25 -19
  317. package/dist/esmdev/foundation/textures/Sampler.js +24 -24
  318. package/dist/esmdev/foundation/textures/Texture.js +83 -83
  319. package/dist/esmdev/foundation/textures/TextureArray.js +8 -8
  320. package/dist/esmdev/foundation/textures/TextureDataFloat.js +26 -26
  321. package/dist/esmdev/foundation/textures/VideoTexture.js +24 -24
  322. package/dist/esmdev/version.js +2 -2
  323. package/dist/esmdev/webgl/InstanceSidTable.js +62 -62
  324. package/dist/esmdev/webgl/MultiDraw.js +2 -2
  325. package/dist/esmdev/webgl/MultiDrawRepository.js +30 -30
  326. package/dist/esmdev/webgl/WebGLContextWrapper.js +146 -146
  327. package/dist/esmdev/webgl/WebGLGpuTimer.js +30 -30
  328. package/dist/esmdev/webgl/WebGLResourceRepository.d.ts +5 -0
  329. package/dist/esmdev/webgl/WebGLResourceRepository.js +368 -307
  330. package/dist/esmdev/webgl/WebGLStereoUtil.js +39 -39
  331. package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +19 -14
  332. package/dist/esmdev/webgl/WebGLStrategyWebGL2.js +294 -280
  333. package/dist/esmdev/webgl/debug/ShaderParameterDebugger.js +4 -4
  334. package/dist/esmdev/webgl/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.glsl.js +2 -2
  335. package/dist/esmdev/webgl/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.glsl.js +2 -2
  336. package/dist/esmdev/webgl/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -2
  337. package/dist/esmdev/webgl/shaderity_shaders/common/iblDefinition.glsl.js +2 -2
  338. package/dist/esmdev/webgl/shaders/RaymarchingShaderPart.js +4 -4
  339. package/dist/esmdev/webgl/shaders/RaymarchingShadowShaderPart.js +14 -14
  340. package/dist/esmdev/webgl/shaders/StandardShaderPart.js +3 -3
  341. package/dist/esmdev/webgl/shaders/nodes/BlockBeginShader.js +10 -10
  342. package/dist/esmdev/webgl/shaders/nodes/BlockEndShader.js +10 -10
  343. package/dist/esmdev/webgl/shaders/nodes/ConstantVariableShader.js +21 -21
  344. package/dist/esmdev/webgl/shaders/nodes/OutDistance.js +12 -12
  345. package/dist/esmdev/webgl/shaders/nodes/OutUnion.js +9 -9
  346. package/dist/esmdev/webgl/shaders/nodes/RaymarchObjectIdUniform.js +8 -8
  347. package/dist/esmdev/webgl/shaders/nodes/SdApplyTransform.js +9 -9
  348. package/dist/esmdev/webgl/shaders/nodes/SdApplyWorldMatrix.js +8 -8
  349. package/dist/esmdev/webgl/shaders/nodes/Texture2DShader.js +23 -23
  350. package/dist/esmdev/webgl/shaders/nodes/UniformDataShader.js +23 -23
  351. package/dist/esmdev/webgl/textureLoader/KTX2TextureLoader.js +24 -24
  352. package/dist/esmdev/webgpu/GpuCullingRegistry.js +91 -91
  353. package/dist/esmdev/webgpu/GpuDeformRegistry.js +53 -53
  354. package/dist/esmdev/webgpu/RangeAllocator.js +16 -16
  355. package/dist/esmdev/webgpu/WebGpuBufferArena.js +21 -21
  356. package/dist/esmdev/webgpu/WebGpuDeviceWrapper.js +7 -7
  357. package/dist/esmdev/webgpu/WebGpuGpuCulling.js +198 -198
  358. package/dist/esmdev/webgpu/WebGpuGpuTimer.js +51 -51
  359. package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.js +36 -36
  360. package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +6 -0
  361. package/dist/esmdev/webgpu/WebGpuResourceRepository.js +655 -593
  362. package/dist/esmdev/webgpu/WebGpuStrategyBasic.js +123 -123
  363. package/dist/esmdev/webgpu/WebGpuVertexDeformer.js +128 -128
  364. package/dist/esmdev/webgpu/shaderity_shaders/MToon0xSingleShader/MToon0xSingleShader.frag.wgsl.js +2 -2
  365. package/dist/esmdev/webgpu/shaderity_shaders/MToon1SingleShader/MToon1SingleShader.frag.wgsl.js +2 -2
  366. package/dist/esmdev/webgpu/shaderity_shaders/PbrSingleShader/PbrSingleShader.frag.js +2 -2
  367. package/dist/esmdev/webgpu/shaderity_shaders/common/iblDefinition.wgsl.js +2 -2
  368. package/dist/esmdev/xr/WebARSystem.js +69 -69
  369. package/dist/esmdev/xr/WebXRSystem.js +151 -151
  370. package/package.json +2 -1
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal PNG decoder for the RGB9_E5 cubemap faces.
3
+ *
4
+ * The browser PNG decoders do not expose the RGBA bytes directly (a 2D canvas premultiplies alpha and the
5
+ * ImageBitmap path does not hand out the pixel data), and the alpha channel of an RGB9_E5 PNG carries the
6
+ * high byte of the packed word. The files are 8-bit RGBA, non-interlaced PNGs, so a small decoder using the
7
+ * platform DecompressionStream is enough and keeps the packed bytes intact.
8
+ */
9
+ export declare function decodePngToRgba8(bytes: Uint8Array): Promise<{
10
+ width: number;
11
+ height: number;
12
+ data: Uint8Array;
13
+ }>;
14
+ /**
15
+ * Converts the hdrpng.js RGB9_E5 PNG byte layout (R[31:23], G[22:14], B[13:5], E[4:0], stored little-endian)
16
+ * to the native UNSIGNED_INT_5_9_9_9_REV / rgb9e5ufloat layout (E[31:27], B[26:18], G[17:9], R[8:0]).
17
+ */
18
+ export declare function convertHdrpngRgb9E5ToNative(rgba: Uint8Array, pixelCount: number): Uint32Array;
@@ -0,0 +1 @@
1
+ async function S(t){let s=new DataView(t.buffer,t.byteOffset,t.byteLength),h=[137,80,78,71,13,10,26,10];for(let r=0;r<h.length;r++)if(t[r]!==h[r])throw new Error("Not a PNG file");let e=8,n=0,a=0,l=0,p=0,U=0,D=[],P=0;for(;e<t.length;){let r=s.getUint32(e),i=String.fromCharCode(t[e+4],t[e+5],t[e+6],t[e+7]),o=t.subarray(e+8,e+8+r);if(i==="IHDR")n=s.getUint32(e+8),a=s.getUint32(e+12),l=t[e+16],p=t[e+17],U=t[e+20];else if(i==="IDAT")D.push(o),P+=o.length;else if(i==="IEND")break;e+=12+r}if(l!==8||p!==6||U!==0)throw new Error(`Unsupported PNG format (bitDepth ${l}, colorType ${p})`);let T=new Uint8Array(P),E=0;for(let r of D)T.set(r,E),E+=r.length;if(typeof DecompressionStream=="undefined")throw new Error("DecompressionStream is required to decode RGB9_E5 PNG files");let R=new Blob([T]).stream().pipeThrough(new DecompressionStream("deflate")),b=new Uint8Array(await new Response(R).arrayBuffer()),d=4,c=n*d,v=a*(c+1);if(b.length<v)throw new Error("Truncated PNG image data");let u=new Uint8Array(c*a),N=0;for(let r=0;r<a;r++){let i=b[N++];for(let o=0;o<c;o++){let w=b[N++],k=r*c+o,g=o>=d?u[k-d]:0,m=r>0?u[k-c]:0,y=o>=d&&r>0?u[k-c-d]:0,f;switch(i){case 0:f=w;break;case 1:f=w+g;break;case 2:f=w+m;break;case 3:f=w+(g+m>>1);break;case 4:{let A=g+m-y,G=Math.abs(A-g),x=Math.abs(A-m),L=Math.abs(A-y),M=G<=x&&G<=L?g:x<=L?m:y;f=w+M;break}default:throw new Error(`Unsupported PNG filter type ${i}`)}u[k]=f&255}}return{width:n,height:a,data:u}}function B(t,s){let h=new Uint32Array(s);for(let e=0;e<s;e++){let n=t[e*4]|t[e*4+1]<<8|t[e*4+2]<<16|t[e*4+3]<<24,a=n&31,l=n>>>23&511,p=n>>>14&511,U=n>>>5&511;h[e]=(a<<27)+(U<<18)+(p<<9)+l}return h}export{B as convertHdrpngRgb9E5ToNative,S as decodePngToRgba8};
@@ -241,6 +241,13 @@ export declare class RenderPass extends RnObject {
241
241
  /**
242
242
  * Removes all entities from this render pass and clears related collections.
243
243
  * This effectively empties the render pass of all renderable content.
244
+ *
245
+ * @remarks
246
+ * `__sceneGraphDirectlyAdded` must be cleared together with the other collections:
247
+ * `addEntities` appends to it on every call, and `processAuto`-style callers call
248
+ * `clearEntities` + `addEntities` once per frame. Leaving it untouched makes it grow
249
+ * by the entity count every frame (keeping every scene graph it ever saw alive) and
250
+ * makes `sceneTopLevelGraphComponents` retain the roots of previously cleared entities.
244
251
  */
245
252
  clearEntities(): void;
246
253
  /**
@@ -1 +1 @@
1
- import{flattenHierarchy as c}from"../components/SceneGraph/SceneGraphOps.js";import{WellKnownComponentTIDs as d}from"../components/WellKnownComponentTIDs.js";import{RnObject as f}from"../core/RnObject.js";import{PrimitiveMode as l}from"../definitions/PrimitiveMode.js";import{Primitive as R}from"../geometry/Primitive.js";import{MutableVector4 as h}from"../math/MutableVector4.js";import{Vector4 as p}from"../math/Vector4.js";var s=class s extends f{constructor(e){super();this.Gp=[];this.WR=[];this.bR=[];this._R=[];this.vR=[];this.yR=new Map;this.toClearColorBuffer=!1;this.toClearDepthBuffer=!0;this.toClearStencilBuffer=!1;this.isDepthTest=!0;this.depthWriteMask=!0;this.clearColor=p.fromCopyArray([1,1,1,1]);this.clearDepth=1;this.clearStencil=0;this._drawVertexNumberForBufferLessRendering=0;this._primitiveModeForBufferLessRendering=l.Triangles;this.isVrRendering=!0;this.isOutputForVr=!1;this._lastOpaqueIndex=-1;this._lastTranslucentIndex=-1;this._lastBlendWithZWriteIndex=-1;this._lastBlendWithoutZWriteIndex=-1;this._lastPrimitiveUids=[];this._lastPrimitives=null;this._lastTransformComponentsUpdateCount=-1;this._lastCameraControllerComponentsUpdateCount=-1;this._lastSceneGraphComponentsUpdateCount=-1;this._lastMultiDrawGroupVersion=-1;this._renderedSomethingBefore=!0;this._isChangedSortRenderResult=!1;this._toRenderOpaquePrimitives=!0;this._toRenderTranslucentPrimitives=!0;this._toRenderBlendWithZWritePrimitives=!0;this._toRenderBlendWithoutZWritePrimitives=!0;this.toRenderEffekseerEffects=!1;this.i=e,this._dummyPrimitiveForBufferLessRendering=new R(e),this.IR=++s.qu}setToRenderOpaquePrimitives(e){this._toRenderOpaquePrimitives=e,this.ER()}setToRenderBlendWithoutZWritePrimitives(e){this._toRenderBlendWithoutZWritePrimitives=e,this.ER()}setToRenderBlendWithZWritePrimitives(e){this._toRenderBlendWithZWritePrimitives=e,this.ER()}setToRenderTranslucentPrimitives(e){this._toRenderTranslucentPrimitives=e,this.ER()}isBufferLessRenderingMode(){return this._drawVertexNumberForBufferLessRendering>0}setBufferLessRendering(e,t,i){this._primitiveModeForBufferLessRendering=e,this._drawVertexNumberForBufferLessRendering=t,this.kp=i,this._renderedSomethingBefore=!0}setBufferLessFullScreenRendering(e){this._primitiveModeForBufferLessRendering=l.Triangles,this._drawVertexNumberForBufferLessRendering=3,this.kp=e,this._renderedSomethingBefore=!0}clone(){var t,i;let e=new s(this.i);return e.tryToSetUniqueName(`${this.uniqueName}_cloned`,!0),e.Gp=this.Gp.concat(),e.WR=this.WR.concat(),e.bR=this.bR.concat(),e._R=this._R.concat(),e.vR=this.vR.concat(),e.mR=this.mR,e.BR=this.BR,e.CR=this.CR,e.gR=(t=this.gR)==null?void 0:t.clone(),e.toClearColorBuffer=this.toClearColorBuffer,e.toClearDepthBuffer=this.toClearDepthBuffer,e.toClearStencilBuffer=this.toClearStencilBuffer,e.isDepthTest=this.isDepthTest,e.clearColor=this.clearColor.clone(),e.clearDepth=this.clearDepth,e.clearStencil=this.clearStencil,e.cameraComponent=this.cameraComponent,e.kp=this.kp,e.yR=new Map(this.yR),e.isVrRendering=this.isVrRendering,e.isOutputForVr=this.isOutputForVr,e._toRenderOpaquePrimitives=this._toRenderOpaquePrimitives,e._toRenderTranslucentPrimitives=this._toRenderTranslucentPrimitives,e._toRenderBlendWithoutZWritePrimitives=this._toRenderBlendWithoutZWritePrimitives,e.FR=this.FR,e.MR=this.MR,e.PR=(i=this.PR)==null?void 0:i.concat(),e._lastOpaqueIndex=this._lastOpaqueIndex,e._lastTranslucentIndex=this._lastTranslucentIndex,e._lastBlendWithZWriteIndex=this._lastBlendWithZWriteIndex,e._lastBlendWithoutZWriteIndex=this._lastBlendWithoutZWriteIndex,e._lastPrimitiveUids=this._lastPrimitiveUids.concat(),e._lastTransformComponentsUpdateCount=this._lastTransformComponentsUpdateCount,e._lastCameraControllerComponentsUpdateCount=this._lastCameraControllerComponentsUpdateCount,e._lastSceneGraphComponentsUpdateCount=this._lastSceneGraphComponentsUpdateCount,e._renderedSomethingBefore=this._renderedSomethingBefore,e._isChangedSortRenderResult=this._isChangedSortRenderResult,e}setPreRenderFunction(e){this.FR=e}setPostRenderFunction(e){this.MR=e}doPreRender(){this.FR!=null&&this.FR()}doPostRender(){this.MR!=null&&this.MR()}addEntities(e){for(let t of e){if(t===void 0)continue;let i=t.getSceneGraph();this.WR.push(i);let n=c(i,!1).map(a=>a.entity).filter(a=>a!=null),r=this.Gp.concat(n).reduce((a,u)=>(a.set(u.entityUID,u),a),new Map);this.Gp=Array.from(r.values())}this.ER(),this.bR=[],this.xR()}ER(){this._R=[],this.vR=[],this.UR()}get entities(){return this.Gp}clearEntities(){this._R=[],this.vR=[],this.bR=[],this.Gp=[]}xR(){let e=i=>(i.parent&&e(i.parent),i);this.bR=this.WR.map(i=>e(i));let t=new Set(this.bR);this.bR=Array.from(t)}UR(){this._R=[],this.vR=[];for(let e of this.Gp){let t=e.getComponentByComponentTID(d.MeshComponentTID);if(t!=null&&t.mesh!=null){if(this._R.push(t),!this._toRenderOpaquePrimitives&&t.mesh.isExistOpaque()||!this._toRenderTranslucentPrimitives&&t.mesh.isExistTranslucent()||!this._toRenderBlendWithZWritePrimitives&&t.mesh.isExistBlendWithZWrite()||!this._toRenderBlendWithoutZWritePrimitives&&t.mesh.isExistBlendWithoutZWrite())continue;this.vR.push(t)}}}get meshComponents(){return this._R}get _optimizedMeshComponents(){return this.vR}get sceneTopLevelGraphComponents(){return this.bR}setFramebuffer(e){this.mR=e,e!=null?this.setViewport(p.fromCopyArray([0,0,e.width,e.height])):this.gR=void 0}setRenderTargetColorAttachments(e){this.PR=e}getRenderTargetColorAttachments(){return this.PR}getFramebuffer(){return this.mR}removeFramebuffer(){this.mR=void 0}setViewport(e){this.gR!=null?this.gR.copyComponents(e):this.gR=h.fromCopyArray([e.x,e.y,e.z,e.w])}getViewport(){let e=this.gR;return e!=null&&(e=s.GR.copyComponents(e)),e}setScissorRect(e){if(e==null){this.SR=void 0;return}this.SR={x:Math.floor(e.x),y:Math.floor(e.y),width:Math.max(0,Math.floor(e.width)),height:Math.max(0,Math.floor(e.height))}}getScissorRect(){return this.SR}setResolveFramebuffer(e){this.BR=e}getResolveFramebuffer(){return this.BR}setResolveFramebuffer2(e){this.CR=e}getResolveFramebuffer2(){return this.CR}_copyFramebufferToResolveFramebuffersWebGL(){this.TR(this.BR),this.TR(this.CR)}TR(e){if(e==null)return;let t=this.i.webglResourceRepository,i=t.getWebGLResource(this.mR.cgApiResourceUid),o=t.getWebGLResource(e.cgApiResourceUid);if(i==null||o==null)return;let r=t.currentWebGLContextWrapper.getRawContextAsWebGL2();r.bindFramebuffer(r.READ_FRAMEBUFFER,i),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,o),r.blitFramebuffer(0,0,this.mR.width,this.mR.height,0,0,e.width,e.height,r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT,r.NEAREST),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null)}_copyResolve1ToResolve2WebGpu(){var i,o;let e=(i=this.BR)!=null?i:this.mR;if(e==null||this.CR==null)return;let t=this.i.webGpuResourceRepository;for(let n=0;n<e.colorAttachments.length;n++)e.colorAttachments[n]==null||this.CR.colorAttachments[n]==null||!(e.colorAttachments[n]._textureResourceUid>=0)||((o=e.colorAttachments[n].sampleCount)!=null?o:1)>1||this.CR.colorAttachments[n]._textureResourceUid===-1||t.copyTextureData(e.colorAttachments[n]._textureResourceUid,this.CR.colorAttachments[n]._textureResourceUid)}setMaterialForPrimitive(e,t){this.yR.set(t.objectUID,new WeakRef(e))}setMaterial(e){this.kp=e}get material(){return this.kp}_getMaterialOf(e){var t;return(t=this.yR.get(e.objectUID))==null?void 0:t.deref()}getAppropriateMaterial(e){let t=this.yR.size!==0?this._getMaterialOf(e):void 0;return t!=null||(this.kp!=null?t=this.kp:t=e.material),t}get renderPassUID(){return this.IR}};s.GR=h.zero(),s.qu=-1;var m=s;export{m as RenderPass};
1
+ import{flattenHierarchy as c}from"../components/SceneGraph/SceneGraphOps.js";import{WellKnownComponentTIDs as d}from"../components/WellKnownComponentTIDs.js";import{RnObject as f}from"../core/RnObject.js";import{PrimitiveMode as l}from"../definitions/PrimitiveMode.js";import{Primitive as R}from"../geometry/Primitive.js";import{MutableVector4 as h}from"../math/MutableVector4.js";import{Vector4 as p}from"../math/Vector4.js";var s=class s extends f{constructor(e){super();this.Gp=[];this.yR=[];this.bR=[];this._R=[];this.vR=[];this.FR=new Map;this.toClearColorBuffer=!1;this.toClearDepthBuffer=!0;this.toClearStencilBuffer=!1;this.isDepthTest=!0;this.depthWriteMask=!0;this.clearColor=p.fromCopyArray([1,1,1,1]);this.clearDepth=1;this.clearStencil=0;this._drawVertexNumberForBufferLessRendering=0;this._primitiveModeForBufferLessRendering=l.Triangles;this.isVrRendering=!0;this.isOutputForVr=!1;this._lastOpaqueIndex=-1;this._lastTranslucentIndex=-1;this._lastBlendWithZWriteIndex=-1;this._lastBlendWithoutZWriteIndex=-1;this._lastPrimitiveUids=[];this._lastPrimitives=null;this._lastTransformComponentsUpdateCount=-1;this._lastCameraControllerComponentsUpdateCount=-1;this._lastSceneGraphComponentsUpdateCount=-1;this._lastMultiDrawGroupVersion=-1;this._renderedSomethingBefore=!0;this._isChangedSortRenderResult=!1;this._toRenderOpaquePrimitives=!0;this._toRenderTranslucentPrimitives=!0;this._toRenderBlendWithZWritePrimitives=!0;this._toRenderBlendWithoutZWritePrimitives=!0;this.toRenderEffekseerEffects=!1;this.i=e,this._dummyPrimitiveForBufferLessRendering=new R(e),this.IR=++s.qu}setToRenderOpaquePrimitives(e){this._toRenderOpaquePrimitives=e,this.WR()}setToRenderBlendWithoutZWritePrimitives(e){this._toRenderBlendWithoutZWritePrimitives=e,this.WR()}setToRenderBlendWithZWritePrimitives(e){this._toRenderBlendWithZWritePrimitives=e,this.WR()}setToRenderTranslucentPrimitives(e){this._toRenderTranslucentPrimitives=e,this.WR()}isBufferLessRenderingMode(){return this._drawVertexNumberForBufferLessRendering>0}setBufferLessRendering(e,t,i){this._primitiveModeForBufferLessRendering=e,this._drawVertexNumberForBufferLessRendering=t,this.kp=i,this._renderedSomethingBefore=!0}setBufferLessFullScreenRendering(e){this._primitiveModeForBufferLessRendering=l.Triangles,this._drawVertexNumberForBufferLessRendering=3,this.kp=e,this._renderedSomethingBefore=!0}clone(){var t,i;let e=new s(this.i);return e.tryToSetUniqueName(`${this.uniqueName}_cloned`,!0),e.Gp=this.Gp.concat(),e.yR=this.yR.concat(),e.bR=this.bR.concat(),e._R=this._R.concat(),e.vR=this.vR.concat(),e.mR=this.mR,e.BR=this.BR,e.CR=this.CR,e.gR=(t=this.gR)==null?void 0:t.clone(),e.toClearColorBuffer=this.toClearColorBuffer,e.toClearDepthBuffer=this.toClearDepthBuffer,e.toClearStencilBuffer=this.toClearStencilBuffer,e.isDepthTest=this.isDepthTest,e.clearColor=this.clearColor.clone(),e.clearDepth=this.clearDepth,e.clearStencil=this.clearStencil,e.cameraComponent=this.cameraComponent,e.kp=this.kp,e.FR=new Map(this.FR),e.isVrRendering=this.isVrRendering,e.isOutputForVr=this.isOutputForVr,e._toRenderOpaquePrimitives=this._toRenderOpaquePrimitives,e._toRenderTranslucentPrimitives=this._toRenderTranslucentPrimitives,e._toRenderBlendWithoutZWritePrimitives=this._toRenderBlendWithoutZWritePrimitives,e.MR=this.MR,e.ER=this.ER,e.PR=(i=this.PR)==null?void 0:i.concat(),e._lastOpaqueIndex=this._lastOpaqueIndex,e._lastTranslucentIndex=this._lastTranslucentIndex,e._lastBlendWithZWriteIndex=this._lastBlendWithZWriteIndex,e._lastBlendWithoutZWriteIndex=this._lastBlendWithoutZWriteIndex,e._lastPrimitiveUids=this._lastPrimitiveUids.concat(),e._lastTransformComponentsUpdateCount=this._lastTransformComponentsUpdateCount,e._lastCameraControllerComponentsUpdateCount=this._lastCameraControllerComponentsUpdateCount,e._lastSceneGraphComponentsUpdateCount=this._lastSceneGraphComponentsUpdateCount,e._renderedSomethingBefore=this._renderedSomethingBefore,e._isChangedSortRenderResult=this._isChangedSortRenderResult,e}setPreRenderFunction(e){this.MR=e}setPostRenderFunction(e){this.ER=e}doPreRender(){this.MR!=null&&this.MR()}doPostRender(){this.ER!=null&&this.ER()}addEntities(e){for(let t of e){if(t===void 0)continue;let i=t.getSceneGraph();this.yR.push(i);let n=c(i,!1).map(a=>a.entity).filter(a=>a!=null),r=this.Gp.concat(n).reduce((a,u)=>(a.set(u.entityUID,u),a),new Map);this.Gp=Array.from(r.values())}this.WR(),this.bR=[],this.xR()}WR(){this._R=[],this.vR=[],this.UR()}get entities(){return this.Gp}clearEntities(){this._R=[],this.vR=[],this.bR=[],this.yR=[],this.Gp=[]}xR(){let e=i=>(i.parent&&e(i.parent),i);this.bR=this.yR.map(i=>e(i));let t=new Set(this.bR);this.bR=Array.from(t)}UR(){this._R=[],this.vR=[];for(let e of this.Gp){let t=e.getComponentByComponentTID(d.MeshComponentTID);if(t!=null&&t.mesh!=null){if(this._R.push(t),!this._toRenderOpaquePrimitives&&t.mesh.isExistOpaque()||!this._toRenderTranslucentPrimitives&&t.mesh.isExistTranslucent()||!this._toRenderBlendWithZWritePrimitives&&t.mesh.isExistBlendWithZWrite()||!this._toRenderBlendWithoutZWritePrimitives&&t.mesh.isExistBlendWithoutZWrite())continue;this.vR.push(t)}}}get meshComponents(){return this._R}get _optimizedMeshComponents(){return this.vR}get sceneTopLevelGraphComponents(){return this.bR}setFramebuffer(e){this.mR=e,e!=null?this.setViewport(p.fromCopyArray([0,0,e.width,e.height])):this.gR=void 0}setRenderTargetColorAttachments(e){this.PR=e}getRenderTargetColorAttachments(){return this.PR}getFramebuffer(){return this.mR}removeFramebuffer(){this.mR=void 0}setViewport(e){this.gR!=null?this.gR.copyComponents(e):this.gR=h.fromCopyArray([e.x,e.y,e.z,e.w])}getViewport(){let e=this.gR;return e!=null&&(e=s.GR.copyComponents(e)),e}setScissorRect(e){if(e==null){this.SR=void 0;return}this.SR={x:Math.floor(e.x),y:Math.floor(e.y),width:Math.max(0,Math.floor(e.width)),height:Math.max(0,Math.floor(e.height))}}getScissorRect(){return this.SR}setResolveFramebuffer(e){this.BR=e}getResolveFramebuffer(){return this.BR}setResolveFramebuffer2(e){this.CR=e}getResolveFramebuffer2(){return this.CR}_copyFramebufferToResolveFramebuffersWebGL(){this.TR(this.BR),this.TR(this.CR)}TR(e){if(e==null)return;let t=this.i.webglResourceRepository,i=t.getWebGLResource(this.mR.cgApiResourceUid),o=t.getWebGLResource(e.cgApiResourceUid);if(i==null||o==null)return;let r=t.currentWebGLContextWrapper.getRawContextAsWebGL2();r.bindFramebuffer(r.READ_FRAMEBUFFER,i),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,o),r.blitFramebuffer(0,0,this.mR.width,this.mR.height,0,0,e.width,e.height,r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT,r.NEAREST),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null)}_copyResolve1ToResolve2WebGpu(){var i,o;let e=(i=this.BR)!=null?i:this.mR;if(e==null||this.CR==null)return;let t=this.i.webGpuResourceRepository;for(let n=0;n<e.colorAttachments.length;n++)e.colorAttachments[n]==null||this.CR.colorAttachments[n]==null||!(e.colorAttachments[n]._textureResourceUid>=0)||((o=e.colorAttachments[n].sampleCount)!=null?o:1)>1||this.CR.colorAttachments[n]._textureResourceUid===-1||t.copyTextureData(e.colorAttachments[n]._textureResourceUid,this.CR.colorAttachments[n]._textureResourceUid)}setMaterialForPrimitive(e,t){this.FR.set(t.objectUID,new WeakRef(e))}setMaterial(e){this.kp=e}get material(){return this.kp}_getMaterialOf(e){var t;return(t=this.FR.get(e.objectUID))==null?void 0:t.deref()}getAppropriateMaterial(e){let t=this.FR.size!==0?this._getMaterialOf(e):void 0;return t!=null||(this.kp!=null?t=this.kp:t=e.material),t}get renderPassUID(){return this.IR}};s.GR=h.zero(),s.qu=-1;var m=s;export{m as RenderPass};
@@ -353,7 +353,8 @@ export declare class ForwardRenderPipeline extends RnObject {
353
353
  * The diffuse texture provides ambient lighting, while the specular texture provides
354
354
  * reflections and specular highlights.
355
355
  *
356
- * The sheen texture is optional and used for materials with fabric-like properties.
356
+ * The sheen texture is optional and used for materials with fabric-like properties. Omitting it clears
357
+ * a previously set sheen texture, so switching to an IBL without sheen falls back to the specular cube.
357
358
  *
358
359
  * @example
359
360
  * ```typescript
@@ -1 +1 @@
1
- import{CameraComponent as q}from"../../components/Camera/CameraComponent.js";import{RaymarchingComponent as C}from"../../components/Raymarching/RaymarchingComponent.js";import{RnObject as H}from"../../core/RnObject.js";import{ComponentType as z,CompositionType as G,PixelFormat as $,ToneMappingType as v}from"../../definitions/index.js";import{ShaderSemantics as I}from"../../definitions/ShaderSemantics.js";import{TextureFormat as R}from"../../definitions/TextureFormat.js";import{TextureParameter as w}from"../../definitions/TextureParameter.js";import{Bloom as Z}from"../../helpers/BloomHelper.js";import{collectRrnJson as J,createNodeBasedRaymarchingComponentShadowMaterial as V,createNodeBasedRaymarchingShadowMaterial as O,RAYMARCHING_COMPONENT_WORLD_MATRIX_SEMANTIC as U}from"../../helpers/materials/createNodeBasedRaymarchingMaterials.js";import{createToneMappingMaterial as K}from"../../helpers/materials/createToneMappingMaterial.js";import{RenderableHelper as F}from"../../helpers/RenderableHelper.js";import{RenderPassHelper as X}from"../../helpers/RenderPassHelper.js";import{ShadowSystem as Q}from"../../helpers/Shadow/ShadowSystem.js";import{Scalar as A}from"../../math/Scalar.js";import{Vector2 as ee}from"../../math/Vector2.js";import{Vector3 as S}from"../../math/Vector3.js";import{Vector4 as N}from"../../math/Vector4.js";import{MiscUtil as k}from"../../misc/index.js";import{Is as g}from"../../misc/Is.js";import{Logger as te}from"../../misc/Logger.js";import{Err as L,Ok as W}from"../../misc/Result.js";import{Sampler as re}from"../../textures/Sampler.js";import{Expression as M}from"../Expression.js";import{Frame as ie}from"../Frame.js";import{RenderPass as P}from"../RenderPass.js";import{_getTemporalAACamera as se,TemporalAASystem as ne}from"../TemporalAA/TemporalAASystem.js";var _=Object.freeze(S.fromCopy3(-1e20,-1e20,-1e20)),D=Object.freeze(S.fromCopy3(1e20,1e20,1e20)),j=class extends H{constructor(e){super();this.sm=0;this.TT=0;this.jR=!1;this.gT=!1;this.Xx=!1;this.wR=!1;this.HR=1024;this.hp=[];this.WT=new M;this.BT=[];this.OR=0;this.kR=1;this.LR=1;this.YR=new Map;this.Zx=new Map;this.wT=new Map;this.qR=-1;this.HT=new Map;this.KR=v.GT_ToneMap;this.$R=[];this.QR=[];this.GT=new Map;this.VT=!1;this.FT=new Map;this.OT=new Map;this.i=e,this.zR=new Z(e)}Lb(){this.yT!=null&&(this.yT.destroy3DAPIResources(),this.yT=void 0),this.IT!=null&&(this.IT.destroy3DAPIResources(),this.IT=void 0),this.PT!=null&&(this.PT.destroy3DAPIResources(),this.PT=void 0),this.MT!=null&&(this.MT.destroy3DAPIResources(),this.MT=void 0),this.RT!=null&&(this.RT.destroy3DAPIResources(),this.RT=void 0),this.zR.destroy3DAPIResources(),this.Yx!=null&&(this.Yx.destroy3DAPIResources(),this.Yx=void 0),this.bT=void 0,this.YT=void 0,this.qT=void 0,this.zT=void 0,this.kT=void 0,this.AT=void 0,this.DT=void 0,this.vT=void 0,this.GT.clear(),this.VT=!1,this.FT.clear(),this.OT.clear(),this.wT.clear(),this.HT.clear(),this.YR.clear()}async setup(e,t,{isShadow:r=!1,isBloom:i=!1,shadowMapSize:s=1024,isSimple:n=!1,isTemporalAA:a=!1}={}){if(this.sm=e,this.TT=t,this.gT=i,this.jR=r,this.Xx=n,this.wR=a,this.HR=s,this.bT!=null)return new L({message:"Already setup",error:void 0});let o=new ie;if(this.bT=o,!this.Xx){let l=new re(this.i,{wrapS:w.Repeat,wrapT:w.Repeat,minFilter:w.LinearMipmapLinear,magFilter:w.Linear});l.create(),this.jT=l,this.Wb(e,t),r&&(this.ST=new Q(this.i,s)),this.RT!=null&&!k.isMobile()&&(this.YT=this.Yb(this.RT)),this.yT!=null&&(this.VR=this.qb(this.yT),this.qT=this.zb(this.yT));let T=this.$b(),h=T.getColorAttachedRenderTargetTexture(0);if(this.db()&&(this.Yx=new ne(this.i,e,t,T.getColorAttachedRenderTargetTexture(0)),h=this.Yx.outputTexture),i){let c=h,{bloomExpression:m,bloomedRenderTarget:p}=this.zR.createBloomExpression({textureToBloom:c,parameters:{}});this.zT=m,h=p}let d=this.Xb(h);this.kT=d}this.DR=this.jb(),this.hp.length>0&&this.setExpressions(this.hp);let[u,f]=this.Hb();return this.AT=u,this._T=f,this.CT(),new W}XR(){return this.yT!=null?this.UT:this.RT}$b(){return this.yT!=null?this.IT:this.MT}LT(){var e;return this.yT!=null?this.yT:(e=this.PT)!=null?e:this.MT}db(){var e;return!this.wR||this.Xx?!1:!((e=this.i._webXRSystemIfEnabled)!=null&&e.isWebXRMode)}setExpressions(e,t={isTransmission:!0}){let r=e.map(i=>i.clone());if(this.Zb(e,{isTransmission:t.isTransmission}),t.isTransmission&&this.Jb(r),this.ST!=null){let i=this.hp.flatMap(s=>s.renderPasses.flatMap(n=>n.entities));this.$R=this.ST.getExpressions(i,this.Rb(),this.Pb())}this.CT()}setGizmoExpression(e){this.WT=e}startRenderLoop(e){return this.bT==null?new L({message:"not initialized.",error:void 0}):(this.JR=e,this.CT(),this.i.startRenderLoop(()=>{let t=this.ST;if(t!=null){let r=this.QR,i=this.Rb();t.isLightChanged()&&(this.$R=t.getExpressions(r,i,this.Pb()),this.CT()),t.setDepthBiasPV(r,i)}this.Kb(),this.Fb(),e(this.bT)}),new W)}draw(){this.Fb(),this.JR(this.bT)}get isTemporalAA(){return this.Yx!=null}resetTemporalAAHistory(){var e;(e=this.Yx)==null||e.resetHistory()}set temporalAACurrentFrameWeight(e){this.Yx!=null&&(this.Yx.currentFrameWeight=e)}get temporalAACurrentFrameWeight(){var e,t;return(t=(e=this.Yx)==null?void 0:e.currentFrameWeight)!=null?t:.1}set temporalAAStaticFrameWeight(e){this.Yx!=null&&(this.Yx.staticFrameWeight=e)}get temporalAAStaticFrameWeight(){var e,t;return(t=(e=this.Yx)==null?void 0:e.staticFrameWeight)!=null?t:.04}_setTemporalAAVarianceClipGamma(e){this.Yx!=null&&(this.Yx.varianceClipGamma=e)}Fb(){if(this.Yx==null)return;let e=this.hp.flatMap(t=>t.renderPasses);this.Yx.prepareFrame(se(this.i,e))}setNeedsShadowMapRefresh(){var e;(e=this.ST)==null||e.setNeedsRefresh()}resize(e,t){if(this.bT==null)return new L({message:"not initialized.",error:void 0});let r=this.i._webXRSystemIfEnabled;if(g.exist(r)&&(r!=null&&r.isWebXRMode)&&(e=r.getCanvasWidthForVr(),t=r.getCanvasHeightForVr()),e<=0||t<=0){let s=this.sm,n=this.TT;if(s<=0||n<=0){let[a,o]=this.i.getCanvasSize();s=a,n=o}(s<=0||n<=0)&&(s=1,n=1),te.default.warn(`ForwardRenderPipeline.resize received non-positive dimensions (${e}x${t}). Falling back to ${s}x${n}.`),e=s,t=n}let i=this.getRaymarchingMaterial();return this.i.resizeCanvas(e,t),this.Lb(),this.setup(e,t,{isShadow:this.jR,isBloom:this.gT,shadowMapSize:this.HR,isSimple:this.Xx,isTemporalAA:this.wR}),i!=null&&this.setRaymarchingMaterial(i),new W}setIBLTextures(e,t,r){this.$T=e,this.XT=t,g.exist(r)&&(this.ET=r),this.wb(),this.Db(),this.NT(),this.CT()}getInitialExpression(){return this.DR}getToneMappingExpression(){return this.kT}setDiffuseIBLContribution(e){this.kR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.diffuseCubeMapContribution=e)}for(let t of this.BT)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.diffuseCubeMapContribution=e)}}setSpecularIBLContribution(e){this.LR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.specularCubeMapContribution=e)}for(let t of this.BT)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.specularCubeMapContribution=e)}}setIBLRotation(e){this.OR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.rotationOfCubeMap=e)}}Zb(e,t={isTransmission:!0}){for(let r of e)for(let i of r.renderPasses)if(i.setToRenderOpaquePrimitives(!0),i.setToRenderBlendWithZWritePrimitives(!0),i.setToRenderBlendWithoutZWritePrimitives(!0),t.isTransmission?i.setToRenderTranslucentPrimitives(!1):i.setToRenderTranslucentPrimitives(!0),i.toClearDepthBuffer=!1,!this.Xx){let s=this.LT();s!=null&&(i.setFramebuffer(s),this.PT!=null?(i.setResolveFramebuffer(this.MT),i.setResolveFramebuffer2(this.RT)):this.yT==null&&(i.setResolveFramebuffer(void 0),i.setResolveFramebuffer2(this.RT)))}this.hp=e,this.wb()}Jb(e){for(let t of e){t.tryToSetUniqueName("modelTransparentForTransmission",!0);for(let r of t.renderPasses)if(r.setToRenderOpaquePrimitives(!1),r.setToRenderTranslucentPrimitives(!0),r.setToRenderBlendWithZWritePrimitives(!1),r.setToRenderBlendWithoutZWritePrimitives(!1),r.toClearDepthBuffer=!1,r.toClearColorBuffer=!1,!this.Xx){r.setFramebuffer(this.LT()),this.PT!=null?r.setResolveFramebuffer(this.MT):r.setResolveFramebuffer(void 0);for(let i of r.entities){let s=i.tryToGetMesh();if(g.exist(s)){let n=s.mesh;if(g.exist(n))for(let a=0;a<n.getPrimitiveNumber();a++)n.getPrimitiveAt(a).material.setTextureParameter("backBufferTexture",this.XR().getColorAttachedRenderTargetTexture(0),this.jT)}}}}this.BT=e,this.Db()}refreshBackBufferTextureOnTransparentMaterials(){var r;if(this.Xx)return;let e=(r=this.XR())==null?void 0:r.getColorAttachedRenderTargetTexture(0),t=this.jT;if(!(e==null||t==null))for(let i of this.BT)for(let s of i.renderPasses)for(let n of s.entities){let a=n.tryToGetMesh();if(g.exist(a)){let o=a.mesh;if(g.exist(o))for(let u=0;u<o.getPrimitiveNumber();u++)o.getPrimitiveAt(u).material.setTextureParameter("backBufferTexture",e,t)}}}jb(){let e=new M;e.tryToSetUniqueName("Initial",!0);let t=new P(this.i);if(t.clearColor=N.fromCopyArray4([0,0,0,0]),t.toClearColorBuffer=!0,t.toClearDepthBuffer=!0,t.isOutputForVr=!0,t.tryToSetUniqueName("InitialRenderPass",!0),e.addRenderPasses([t]),!this.Xx){let r=new P(this.i);r.clearColor=N.fromCopyArray4([0,0,0,0]),r.toClearColorBuffer=!0,r.toClearDepthBuffer=!0,r.setFramebuffer(this.LT()),r.tryToSetUniqueName("InitialRenderPassForFrameBuffer",!0),e.addRenderPasses([r])}return e}Wb(e,t){let r=this.i._webXRSystemIfEnabled,i=this.i.cgApiResourceRepository;if(g.exist(r)&&(r!=null&&r.isWebXRMode)&&i.isSupportMultiViewVRRendering(this.i)){let s=F.createFrameBufferTextureArrayForMultiView(this.i,{width:e/2,height:t,arrayLength:2,level:0,internalFormat:this.gT?R.R11F_G11F_B10F:R.RGBA8,format:this.gT?$.RGB:$.RGBA,type:this.gT?z.Float:z.UnsignedByte});s.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiView",!0);let n=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});n.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiViewBlit",!0);let a=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});a.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiViewBlitBackBuffer",!0),this.yT=s,this.IT=n,this.UT=a,this.PT=void 0,this.MT=void 0,this.RT=void 0}else{console.log(`canvasWidth: ${e}, canvasHeight: ${t}`);let s;this.db()||(s=F.createFrameBufferMSAA(this.i,{width:e,height:t,colorBufferNum:1,colorFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],sampleCountMSAA:4,depthBufferFormat:R.Depth32F}),s.tryToSetUniqueName("FramebufferTargetOfToneMappingMsaa",!0));let n=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!0,depthTextureFormat:R.Depth32F});n.tryToSetUniqueName("FramebufferTargetOfToneMappingResolve",!0);let a=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});a.tryToSetUniqueName("FramebufferTargetOfToneMappingResolveForReference",!0),this.yT=void 0,this.IT=void 0,this.UT=void 0,this.PT=s,this.MT=n,this.RT=a}}Yb(e){let t=new M;t.tryToSetUniqueName("GenerateMipmaps",!0);let r=new P(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("GenerateMipmaps",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(function(){e.getColorAttachedRenderTargetTexture(0).generateMipmaps()}),t}qb(e){let t=new M;t.tryToSetUniqueName("MultiViewBlitBackBuffer",!0);let r=new P(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("MultiViewBlitBackBuffer",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(()=>{if(this.UT!=null&&!k.isMobile()){let i=this.UT.colorAttachments[0];e.colorAttachments[0].blitToTexture2dFromTexture2dArrayFake(i),i.generateMipmaps()}}),t}zb(e){let t=new M;t.tryToSetUniqueName("MultiViewBlit",!0);let r=new P(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("MultiViewBlit",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(()=>{if(this.IT!=null){let i=this.IT.colorAttachments[0];e.colorAttachments[0].blitToTexture2dFromTexture2dArrayFake(i)}}),t}Xb(e){let t=new M,r=K(this.i);this.ZR=r,this.setToneMappingType(this.KR);let i=X.createScreenDrawRenderPassWithBaseColorTexture(this.i,r,e);i.tryToSetUniqueName("renderPassToneMapping",!0),i.toClearColorBuffer=!1,i.toClearDepthBuffer=!1,i.isDepthTest=!1,i.clearColor=N.fromCopyArray4([0,0,0,0]),i.isVrRendering=!1,i.isOutputForVr=!1;let s=X.createScreenDrawRenderPassWithBaseColorTexture(this.i,r,e);return s.tryToSetUniqueName("renderPassToneMappingVr",!0),s.toClearColorBuffer=!1,s.toClearDepthBuffer=!1,s.isDepthTest=!1,s.clearColor=N.fromCopyArray4([0,0,0,0]),s.isVrRendering=!1,s.isOutputForVr=!0,t.addRenderPasses([i,s]),t}mM(e){return F.createFrameBuffer(this.i,{width:e,height:e,textureNum:1,textureFormats:[R.RG32F],createDepthBuffer:!0,depthTextureFormat:R.Depth32F})}wb(){for(let e of this.hp)for(let t of e.renderPasses)for(let r of t.entities){let i=r.tryToGetMeshRenderer();g.exist(i)&&i.setIBLCubeMap(this.$T,this.XT,this.ET)}}Db(){for(let e of this.BT)for(let t of e.renderPasses)for(let r of t.entities){let i=r.tryToGetMeshRenderer();g.exist(i)&&i.setIBLCubeMap(this.$T,this.XT,this.ET)}}setToneMappingType(e){let t=this.ZR;t!=null&&(this.KR=e,t.removeShaderDefine("RN_USE_KHRONOS_PBR_NEUTRAL"),t.removeShaderDefine("RN_USE_REINHARD"),t.removeShaderDefine("RN_USE_GT_TONEMAP"),t.removeShaderDefine("RN_USE_ACES_NARKOWICZ"),t.removeShaderDefine("RN_USE_ACES_HILL"),t.removeShaderDefine("RN_USE_ACES_HILL_EXPOSURE_BOOST"),e===v.KhronosPbrNeutral?t.addShaderDefine("RN_USE_KHRONOS_PBR_NEUTRAL"):e===v.Reinhard?t.addShaderDefine("RN_USE_REINHARD"):e===v.GT_ToneMap?t.addShaderDefine("RN_USE_GT_TONEMAP"):e===v.ACES_Narkowicz?t.addShaderDefine("RN_USE_ACES_NARKOWICZ"):e===v.ACES_Hill?t.addShaderDefine("RN_USE_ACES_HILL"):e===v.ACES_Hill_Exposure_Boost&&t.addShaderDefine("RN_USE_ACES_HILL_EXPOSURE_BOOST"))}Hb(){let e=new M;e.tryToSetUniqueName("Raymarching",!0);let t=new P(this.i);return t.toClearDepthBuffer=!1,t.isDepthTest=!0,this.Gb(t),t.setPreRenderFunction(()=>this.Qb(t)),e.addRenderPasses([t]),t.tryToSetUniqueName("Raymarching",!0),[e,t]}Gb(e){var r;let t=this.LT();e.setFramebuffer(t),t!=null&&this.PT!=null?(e.setResolveFramebuffer(this.MT),e.setResolveFramebuffer2((r=this.RT)!=null?r:void 0)):(e.setResolveFramebuffer(void 0),e.setResolveFramebuffer2(t!=null?this.RT:void 0))}Qb(e){this.NT(),this.ZT();let t=e.material;if(t==null)return;let r=this.i.componentRepository.getComponentsWithType(C),i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,u=Number.NEGATIVE_INFINITY,f=r.length>0;for(let l of r){let T=l.entity.tryToGetSceneGraph();T!=null&&(t.setParameter(`worldMatrix_${l.componentSID}`,T.matrixInner),t.setParameter(`raymarchObjectId_${l.componentSID}`,A.fromCopyNumber(l.componentSID)));let h=this.JT(l);if(h==null){f=!1;continue}i=Math.min(i,h.min.x),s=Math.min(s,h.min.y),n=Math.min(n,h.min.z),a=Math.max(a,h.max.x),o=Math.max(o,h.max.y),u=Math.max(u,h.max.z)}f?(t.setParameter("raymarchAabbMin",S.fromCopy3(i,s,n)),t.setParameter("raymarchAabbMax",S.fromCopy3(a,o,u))):(t.setParameter("raymarchAabbMin",_),t.setParameter("raymarchAabbMax",D))}setRaymarchingComponentMaterial(e,t){var r;this.Zx.set(e.componentSID,t),this.NT(),this.ZT(),(r=this.ST)==null||r.applyShadowParametersToMaterials([t]),this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT()}getRaymarchingComponentMaterial(e){return this.Zx.get(e.componentSID)}removeRaymarchingComponentMaterial(e){this.Zx.delete(e.componentSID)&&(this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT())}setRaymarchingMaterial(e){var t,r;(t=this._T)==null||t.setBufferLessFullScreenRendering(e),this.NT(),this.ZT(),(r=this.ST)==null||r.applyShadowParametersToMaterials([e]),this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT()}eM(){let e=[],t=new Set;if(this.qR=-1,this.Zx.size>0)for(let r of this.KT()){let i=r.componentSID,s=this.Zx.get(i);if(s==null)continue;t.add(i);let n=this.wT.get(i);n==null&&(n=new P(this.i),n.toClearDepthBuffer=!1,n.isDepthTest=!0,n.setPreRenderFunction(()=>this.tM(i)),n.tryToSetUniqueName(`Raymarching_${i}`,!0),this.wT.set(i,n)),n.setBufferLessFullScreenRendering(s),this.Gb(n),e.length===0&&(this.qR=i),e.push(n)}for(let r of[...this.wT.keys()])t.has(r)||this.wT.delete(r);for(let r of[...this.Zx.keys()])!t.has(r)&&this.i.componentRepository.getComponent(C,r)==null&&this.Zx.delete(r);return e}tM(e){var n,a,o;e===this.qR&&(this.NT(),this.ZT());let t=this.Zx.get(e),r=this.i.componentRepository.getComponent(C,e),i=r==null?void 0:r.entity.tryToGetSceneGraph();if(t==null||r==null||i==null)return;t.setParameter(U,i.matrixInner);let s=this.JT(r);t.setParameter("raymarchAabbMin",(n=s==null?void 0:s.min)!=null?n:_),t.setParameter("raymarchAabbMax",(a=s==null?void 0:s.max)!=null?a:D),(o=this.wT.get(e))==null||o.setScissorRect(this.rM(s))}JT(e){let t=e.entity.tryToGetSceneGraph();if(t==null)return null;let r=t.matrixInner,i=[r.m00,r.m01,r.m02,r.m03,r.m10,r.m11,r.m12,r.m13,r.m20,r.m21,r.m22,r.m23,r.m30,r.m31,r.m32,r.m33],s=C.getAABBVersion(this.i),n=e.componentSID,a=this.HT.get(n);if(a!=null&&a.aabbVersion===s&&a.matrix.length===i.length&&a.matrix.every((f,l)=>f===i[l]))return a.aabb;let o=e.calcWorldAABB();if(o==null)return this.HT.delete(n),null;let u={min:S.fromCopy3(o.minPoint.x,o.minPoint.y,o.minPoint.z),max:S.fromCopy3(o.maxPoint.x,o.maxPoint.y,o.maxPoint.z)};return this.HT.set(n,{aabbVersion:s,matrix:i,aabb:u}),u}rM(e){if(e==null||this.sm<=0||this.TT<=0)return;let t=this.i.componentRepository.getComponent(q,q.getCurrent(this.i));if(t==null)return;let r=t.viewProjectionMatrix,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let c=0;c<8;c++){let m=(c&1)===0?e.min.x:e.max.x,p=(c&2)===0?e.min.y:e.max.y,x=(c&4)===0?e.min.z:e.max.z,y=r.multiplyVector(N.fromCopy4(m,p,x,1));if(y.w<=0)return;let E=y.x/y.w,B=y.y/y.w,b=(E*.5+.5)*this.sm,Y=(-B*.5+.5)*this.TT;i=Math.min(i,b),s=Math.min(s,Y),n=Math.max(n,b),a=Math.max(a,Y)}let o=2,u=Math.max(0,Math.floor(i)-o),f=Math.max(0,Math.floor(s)-o),l=Math.min(this.sm,Math.ceil(n)+o),T=Math.min(this.TT,Math.ceil(a)+o),h=l-u,d=T-f;if(h<=0||d<=0)return{x:0,y:0,width:1,height:1};if(!(u===0&&f===0&&h===this.sm&&d===this.TT))return{x:u,y:f,width:h,height:d}}QT(){let e=[];for(let r of this.Zx.values())e.push(r);let t=this.getRaymarchingMaterial();return t!=null&&e.push(t),e}iM(){let e=new M;e.tryToSetUniqueName("Raymarching",!0);let t=this.eM();return t.length>0?e.addRenderPasses(t):this._T!=null&&this._T.material!=null&&e.addRenderPasses([this._T]),e}refreshRaymarchingShadowMaterial(){let e=this.vT,t=new Map(this.FT);if(this.DT=void 0,this.vT=void 0,this.GT.clear(),this.FT.clear(),this.OT.clear(),this.VT=this.Zx.size>0,!(this.ST==null||this.i.config.maxLightNumber<=0)){if(this.VT)for(let r of this.KT()){let i=r.componentSID;if(!r.castShadow||!this.Zx.has(i))continue;let s=V(this.i,r,"regular",t.get(i));s!=null&&this.FT.set(i,s)}else{let r=J(this.i,{castShadowOnly:!0});if(r.nodes.length>0){let i=r;this.DT=i,this.vT=O(this.i,i,"regular",e)}}this.ST.invalidateShadowVolumeFitting(),this.ST.setNeedsRefresh()}}KT(){let e=this.i.componentRepository.getComponentsWithType(C).slice();return e.sort((t,r)=>t.componentSID-r.componentSID),e}getRaymarchingShadowMaterial(){return this.vT}getRaymarchingComponentShadowMaterial(e){return this.FT.get(e.componentSID)}Pb(){return{hasCaster:()=>this.VT?this.FT.size>0:this.DT!=null&&this.vT!=null,createPasses:e=>this.sM(e),updatePointLightFarPlane:(e,t)=>this.nM(e,t)}}aM(e,t,r){let i=this.GT.get(e);if(i==null){let n=this.DT;if(n==null)return;let a=O(this.i,n,"paraboloidFront"),o=O(this.i,n,"paraboloidBack");if(a==null||o==null)return;i={front:a,back:o},this.GT.set(e,i)}let s=A.fromCopyNumber(t);return i.front.setParameter("lightIndex",s),i.back.setParameter("lightIndex",s),this.NR(i,r),i}NR(e,t){let r=A.fromCopyNumber(t);e.front.setParameter("shadowFarPlane",r),e.back.setParameter("shadowFarPlane",r)}oM(e,t,r,i){let s=this.OT.get(e);s==null&&(s=new Map,this.OT.set(e,s));let n=s.get(i.componentSID);if(n==null){let o=V(this.i,i,"paraboloidFront"),u=V(this.i,i,"paraboloidBack");if(o==null||u==null)return;n={front:o,back:u},s.set(i.componentSID,n)}let a=A.fromCopyNumber(t);return n.front.setParameter("lightIndex",a),n.back.setParameter("lightIndex",a),this.NR(n,r),n}nM(e,t){let r=this.GT.get(e);r!=null&&this.NR(r,t);let i=this.OT.get(e);if(i!=null)for(let s of i.values())this.NR(s,t)}sM(e){let{lightComponent:t,kind:r,shadowSlot:i,farPlane:s}=e;if(this.VT){let a=[];for(let o of this.KT()){let u=o.componentSID;if(!o.castShadow||!this.Zx.has(u))continue;let f;if(r==="regular")f=this.FT.get(u);else{let l=this.oM(i,t.componentSID,s!=null?s:1e3,o);f=r==="paraboloidFront"?l==null?void 0:l.front:l==null?void 0:l.back}f!=null&&a.push(this.Ub(f,e))}return a}let n;if(r==="regular")n=this.vT;else{let a=this.aM(i,t.componentSID,s!=null?s:1e3);n=r==="paraboloidFront"?a==null?void 0:a.front:a==null?void 0:a.back}return n==null?[]:[this.Ub(n,e)]}Ub(e,{lightEntity:t,framebuffer:r,kind:i}){let s=new P(this.i);return s.isVrRendering=!1,s.setBufferLessFullScreenRendering(e),s.setFramebuffer(r),s.toClearColorBuffer=!1,s.toClearDepthBuffer=!1,s.isDepthTest=!0,s.depthWriteMask=!0,i==="regular"&&(s.cameraComponent=t.getCamera()),s.tryToSetUniqueName(`RaymarchingShadow_${i}`,!0),s}Kb(){if(this.VT){this.hM();return}if(this.DT==null)return;let e=[];this.vT!=null&&e.push(this.vT);for(let m of this.GT.values())e.push(m.front,m.back);let t=this.Zx,r=this.getRaymarchingMaterial(),i=t.size>0?t.values().next().value:r,s=(m,p,x)=>{if(i!=null)if(G.isTexture(x.compositionType)){let y=i.getTextureParameter(p);y!=null&&m.setTextureParameter(p,y[1],y[2])}else{let y=i.getParameter(p);y!=null&&m.setParameter(p,y)}},n=this.i.componentRepository.getComponentsWithType(C),a=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,T=Number.NEGATIVE_INFINITY,h=!1;for(let m of n){if(!m.castShadow)continue;h=!0;let p=this.JT(m);if(p==null){h=!1;break}a=Math.min(a,p.min.x),o=Math.min(o,p.min.y),u=Math.min(u,p.min.z),f=Math.max(f,p.max.x),l=Math.max(l,p.max.y),T=Math.max(T,p.max.z)}let d=h?S.fromCopy3(a,o,u):_,c=h?S.fromCopy3(f,l,T):D;for(let m of e){m.setParameter("raymarchAabbMin",d),m.setParameter("raymarchAabbMax",c);for(let p of m.fieldsInfoArray){let x=p.semantic;if(x.startsWith("worldMatrix_")||x.startsWith("raymarchObjectId_")||x==="raymarchAabbMin"||x==="raymarchAabbMax"||x==="lightIndex"||x==="shadowFarPlane")continue;let y=/^(.*)_(\d+)$/.exec(x),E=y!=null?t.get(Number(y[2])):void 0;if(E!=null){let B=y[1];if(G.isTexture(p.compositionType)){let b=E.getTextureParameter(B);b!=null&&m.setTextureParameter(x,b[1],b[2])}else{let b=E.getParameter(B);b!=null&&m.setParameter(x,b)}}else s(m,x,p)}for(let p of n){if(!p.castShadow)continue;let x=p.entity.tryToGetSceneGraph();x!=null&&m.setParameter(`worldMatrix_${p.componentSID}`,x.matrixInner),m.setParameter(`raymarchObjectId_${p.componentSID}`,A.fromCopyNumber(p.componentSID))}}}hM(){var e,t;for(let r of this.KT()){let i=r.componentSID;if(!r.castShadow)continue;let s=this.Zx.get(i);if(s==null)continue;let n=[],a=this.FT.get(i);a!=null&&n.push(a);for(let h of this.OT.values()){let d=h.get(i);d!=null&&n.push(d.front,d.back)}if(n.length===0)continue;let o=r.entity.tryToGetSceneGraph(),u=o==null?void 0:o.matrixInner,f=this.JT(r),l=(e=f==null?void 0:f.min)!=null?e:_,T=(t=f==null?void 0:f.max)!=null?t:D;for(let h of n){u!=null&&h.setParameter(U,u),h.setParameter("raymarchAabbMin",l),h.setParameter("raymarchAabbMax",T);for(let d of h.fieldsInfoArray){let c=d.semantic;if(!(c===U||c==="raymarchAabbMin"||c==="raymarchAabbMax"||c==="lightIndex"||c==="shadowFarPlane"))if(G.isTexture(d.compositionType)){let m=s.getTextureParameter(c);m!=null&&h.setTextureParameter(c,m[1],m[2])}else{let m=s.getParameter(c);m!=null&&h.setParameter(c,m)}}}}}Rb(){return this.QT()}getRaymarchingMaterial(){var e;return(e=this._T)==null?void 0:e.material}NT(){for(let e of this.QT())this.uM(e)}uM(e){var u,f,l,T,h,d;let t=e.getTextureParameter(I.DiffuseEnvTexture.str),r=e.getTextureParameter(I.SpecularEnvTexture.str);if(t==null||r==null)return;let i=e.getTextureParameter(I.SheenEnvTexture.str),s=this.$T,n=this.XT;if(s==null||n==null)return;let a=`${s.objectUID}:${s.isTextureReady}:${n.objectUID}:${n.isTextureReady}:${(f=(u=this.ET)==null?void 0:u.objectUID)!=null?f:-1}:${(T=(l=this.ET)==null?void 0:l.isTextureReady)!=null?T:!1}:${this.OR}:${this.kR}:${this.LR}`;if(a===this.YR.get(e.objectUID))return;this.YR.set(e.objectUID,a);let o=t[2];if(s.isTextureReady&&e.setTextureParameter(I.DiffuseEnvTexture.str,s,o),n.isTextureReady&&(e.setTextureParameter(I.SpecularEnvTexture.str,n,o),i!=null)){let c=(h=this.ET)!=null&&h.isTextureReady?this.ET:n,m=(d=i[2])!=null?d:o;e.setTextureParameter(I.SheenEnvTexture.str,c,m)}e.setParameter("iblParameter",N.fromCopy4(n.mipmapLevelNumber,this.kR,this.LR,this.OR)),e.setParameter("hdriFormat",ee.fromCopy2(s.hdriFormat.index,n.hdriFormat.index))}fM(){return this.QT().some(e=>e.isShaderDefine("RN_USE_TRANSMISSION"))}ZT(){var r;if(this.Xx)return;let e=(r=this.XR())==null?void 0:r.getColorAttachedRenderTargetTexture(0),t=this.jT;if(!(e==null||t==null))for(let i of this.QT())i.setTextureParameter(I.BackBufferTexture.str,e,t)}CT(){let e=this.bT;if(e==null){console.log("Frame is not set.");return}if(e.clearExpressions(),e.addExpression(this.DR),this.AT=this.iM(),!this.Xx)for(let i of this.$R)e.addExpression(i);let t=this.fM();!t&&this.AT!=null&&e.addExpression(this.AT);for(let i of this.hp)this.Xx?i.renderPasses.forEach(s=>{s.isOutputForVr=!0}):i.renderPasses.forEach(s=>{s.isOutputForVr=!1}),e.addExpression(i);!this.Xx&&this.YT!=null&&!k.isMobile()&&e.addExpression(this.YT),!this.Xx&&this.VR!=null&&e.addExpression(this.VR),t&&this.AT!=null&&e.addExpression(this.AT);for(let i of this.BT)this.Xx?i.renderPasses.forEach(s=>{s.isOutputForVr=!0}):i.renderPasses.forEach(s=>{s.isOutputForVr=!1}),e.addExpression(i);if(this.WT.renderPasses.length>0){if(!this.Xx){let i=this.LT();if(i!=null)for(let s of this.WT.renderPasses)s.setFramebuffer(i),this.PT!=null&&s.setResolveFramebuffer(this.MT)}e.addExpression(this.WT)}let r=this.hp.flatMap(i=>i.renderPasses.flatMap(s=>s.entities));this.QR=r,this.Yx!=null&&(this.Yx.setEntities(r),e.addExpression(this.Yx.expression)),!this.Xx&&this.qT!=null&&e.addExpression(this.qT),!this.Xx&&this.gT&&this.zT!=null&&e.addExpression(this.zT),!this.Xx&&this.kT!=null&&e.addExpression(this.kT)}};export{j as ForwardRenderPipeline};
1
+ import{CameraComponent as q}from"../../components/Camera/CameraComponent.js";import{RaymarchingComponent as C}from"../../components/Raymarching/RaymarchingComponent.js";import{RnObject as H}from"../../core/RnObject.js";import{ComponentType as z,CompositionType as G,PixelFormat as $,ToneMappingType as v}from"../../definitions/index.js";import{ShaderSemantics as I}from"../../definitions/ShaderSemantics.js";import{TextureFormat as R}from"../../definitions/TextureFormat.js";import{TextureParameter as w}from"../../definitions/TextureParameter.js";import{Bloom as Z}from"../../helpers/BloomHelper.js";import{collectRrnJson as J,createNodeBasedRaymarchingComponentShadowMaterial as V,createNodeBasedRaymarchingShadowMaterial as O,RAYMARCHING_COMPONENT_WORLD_MATRIX_SEMANTIC as U}from"../../helpers/materials/createNodeBasedRaymarchingMaterials.js";import{createToneMappingMaterial as K}from"../../helpers/materials/createToneMappingMaterial.js";import{RenderableHelper as F}from"../../helpers/RenderableHelper.js";import{RenderPassHelper as X}from"../../helpers/RenderPassHelper.js";import{ShadowSystem as Q}from"../../helpers/Shadow/ShadowSystem.js";import{Scalar as A}from"../../math/Scalar.js";import{Vector2 as ee}from"../../math/Vector2.js";import{Vector3 as P}from"../../math/Vector3.js";import{Vector4 as N}from"../../math/Vector4.js";import{MiscUtil as k}from"../../misc/index.js";import{Is as g}from"../../misc/Is.js";import{Logger as te}from"../../misc/Logger.js";import{Err as L,Ok as W}from"../../misc/Result.js";import{Sampler as re}from"../../textures/Sampler.js";import{Expression as M}from"../Expression.js";import{Frame as ie}from"../Frame.js";import{RenderPass as S}from"../RenderPass.js";import{_getTemporalAACamera as se,TemporalAASystem as ne}from"../TemporalAA/TemporalAASystem.js";var _=Object.freeze(P.fromCopy3(-1e20,-1e20,-1e20)),D=Object.freeze(P.fromCopy3(1e20,1e20,1e20)),j=class extends H{constructor(e){super();this.sm=0;this.TT=0;this.jR=!1;this.gT=!1;this.Xx=!1;this.wR=!1;this.HR=1024;this.hp=[];this.WT=new M;this.BT=[];this.OR=0;this.kR=1;this.LR=1;this.YR=new Map;this.Zx=new Map;this.wT=new Map;this.qR=-1;this.HT=new Map;this.KR=v.GT_ToneMap;this.$R=[];this.QR=[];this.GT=new Map;this.VT=!1;this.FT=new Map;this.OT=new Map;this.i=e,this.zR=new Z(e)}Wb(){this.yT!=null&&(this.yT.destroy3DAPIResources(),this.yT=void 0),this.IT!=null&&(this.IT.destroy3DAPIResources(),this.IT=void 0),this.ST!=null&&(this.ST.destroy3DAPIResources(),this.ST=void 0),this.MT!=null&&(this.MT.destroy3DAPIResources(),this.MT=void 0),this.RT!=null&&(this.RT.destroy3DAPIResources(),this.RT=void 0),this.zR.destroy3DAPIResources(),this.Yx!=null&&(this.Yx.destroy3DAPIResources(),this.Yx=void 0),this.bT=void 0,this.YT=void 0,this.qT=void 0,this.zT=void 0,this.kT=void 0,this.AT=void 0,this.DT=void 0,this.vT=void 0,this.GT.clear(),this.VT=!1,this.FT.clear(),this.OT.clear(),this.wT.clear(),this.HT.clear(),this.YR.clear()}async setup(e,t,{isShadow:r=!1,isBloom:i=!1,shadowMapSize:s=1024,isSimple:n=!1,isTemporalAA:a=!1}={}){if(this.sm=e,this.TT=t,this.gT=i,this.jR=r,this.Xx=n,this.wR=a,this.HR=s,this.bT!=null)return new L({message:"Already setup",error:void 0});let o=new ie;if(this.bT=o,!this.Xx){let l=new re(this.i,{wrapS:w.Repeat,wrapT:w.Repeat,minFilter:w.LinearMipmapLinear,magFilter:w.Linear});l.create(),this.jT=l,this.Yb(e,t),r&&(this.PT=new Q(this.i,s)),this.RT!=null&&!k.isMobile()&&(this.YT=this.qb(this.RT)),this.yT!=null&&(this.VR=this.zb(this.yT),this.qT=this.$b(this.yT));let T=this.Xb(),h=T.getColorAttachedRenderTargetTexture(0);if(this.db()&&(this.Yx=new ne(this.i,e,t,T.getColorAttachedRenderTargetTexture(0)),h=this.Yx.outputTexture),i){let c=h,{bloomExpression:m,bloomedRenderTarget:p}=this.zR.createBloomExpression({textureToBloom:c,parameters:{}});this.zT=m,h=p}let d=this.jb(h);this.kT=d}this.DR=this.Hb(),this.hp.length>0&&this.setExpressions(this.hp);let[u,f]=this.Zb();return this.AT=u,this._T=f,this.CT(),new W}XR(){return this.yT!=null?this.UT:this.RT}Xb(){return this.yT!=null?this.IT:this.MT}LT(){var e;return this.yT!=null?this.yT:(e=this.ST)!=null?e:this.MT}db(){var e;return!this.wR||this.Xx?!1:!((e=this.i._webXRSystemIfEnabled)!=null&&e.isWebXRMode)}setExpressions(e,t={isTransmission:!0}){let r=e.map(i=>i.clone());if(this.Jb(e,{isTransmission:t.isTransmission}),t.isTransmission&&this.Kb(r),this.PT!=null){let i=this.hp.flatMap(s=>s.renderPasses.flatMap(n=>n.entities));this.$R=this.PT.getExpressions(i,this.Rb(),this.Pb())}this.CT()}setGizmoExpression(e){this.WT=e}startRenderLoop(e){return this.bT==null?new L({message:"not initialized.",error:void 0}):(this.JR=e,this.CT(),this.i.startRenderLoop(()=>{let t=this.PT;if(t!=null){let r=this.QR,i=this.Rb();t.isLightChanged()&&(this.$R=t.getExpressions(r,i,this.Pb()),this.CT()),t.setDepthBiasPV(r,i)}this.Qb(),this.Fb(),e(this.bT)}),new W)}draw(){this.Fb(),this.JR(this.bT)}get isTemporalAA(){return this.Yx!=null}resetTemporalAAHistory(){var e;(e=this.Yx)==null||e.resetHistory()}set temporalAACurrentFrameWeight(e){this.Yx!=null&&(this.Yx.currentFrameWeight=e)}get temporalAACurrentFrameWeight(){var e,t;return(t=(e=this.Yx)==null?void 0:e.currentFrameWeight)!=null?t:.1}set temporalAAStaticFrameWeight(e){this.Yx!=null&&(this.Yx.staticFrameWeight=e)}get temporalAAStaticFrameWeight(){var e,t;return(t=(e=this.Yx)==null?void 0:e.staticFrameWeight)!=null?t:.04}_setTemporalAAVarianceClipGamma(e){this.Yx!=null&&(this.Yx.varianceClipGamma=e)}Fb(){if(this.Yx==null)return;let e=this.hp.flatMap(t=>t.renderPasses);this.Yx.prepareFrame(se(this.i,e))}setNeedsShadowMapRefresh(){var e;(e=this.PT)==null||e.setNeedsRefresh()}resize(e,t){if(this.bT==null)return new L({message:"not initialized.",error:void 0});let r=this.i._webXRSystemIfEnabled;if(g.exist(r)&&(r!=null&&r.isWebXRMode)&&(e=r.getCanvasWidthForVr(),t=r.getCanvasHeightForVr()),e<=0||t<=0){let s=this.sm,n=this.TT;if(s<=0||n<=0){let[a,o]=this.i.getCanvasSize();s=a,n=o}(s<=0||n<=0)&&(s=1,n=1),te.default.warn(`ForwardRenderPipeline.resize received non-positive dimensions (${e}x${t}). Falling back to ${s}x${n}.`),e=s,t=n}let i=this.getRaymarchingMaterial();return this.i.resizeCanvas(e,t),this.Wb(),this.setup(e,t,{isShadow:this.jR,isBloom:this.gT,shadowMapSize:this.HR,isSimple:this.Xx,isTemporalAA:this.wR}),i!=null&&this.setRaymarchingMaterial(i),new W}setIBLTextures(e,t,r){this.$T=e,this.XT=t,this.ET=r,this.wb(),this.Db(),this.NT(),this.CT()}getInitialExpression(){return this.DR}getToneMappingExpression(){return this.kT}setDiffuseIBLContribution(e){this.kR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.diffuseCubeMapContribution=e)}for(let t of this.BT)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.diffuseCubeMapContribution=e)}}setSpecularIBLContribution(e){this.LR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.specularCubeMapContribution=e)}for(let t of this.BT)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.specularCubeMapContribution=e)}}setIBLRotation(e){this.OR=e,this.NT();for(let t of this.hp)for(let r of t.renderPasses)for(let i of r.entities){let s=i.tryToGetMeshRenderer();g.exist(s)&&(s.rotationOfCubeMap=e)}}Jb(e,t={isTransmission:!0}){for(let r of e)for(let i of r.renderPasses)if(i.setToRenderOpaquePrimitives(!0),i.setToRenderBlendWithZWritePrimitives(!0),i.setToRenderBlendWithoutZWritePrimitives(!0),t.isTransmission?i.setToRenderTranslucentPrimitives(!1):i.setToRenderTranslucentPrimitives(!0),i.toClearDepthBuffer=!1,!this.Xx){let s=this.LT();s!=null&&(i.setFramebuffer(s),this.ST!=null?(i.setResolveFramebuffer(this.MT),i.setResolveFramebuffer2(this.RT)):this.yT==null&&(i.setResolveFramebuffer(void 0),i.setResolveFramebuffer2(this.RT)))}this.hp=e,this.wb()}Kb(e){for(let t of e){t.tryToSetUniqueName("modelTransparentForTransmission",!0);for(let r of t.renderPasses)if(r.setToRenderOpaquePrimitives(!1),r.setToRenderTranslucentPrimitives(!0),r.setToRenderBlendWithZWritePrimitives(!1),r.setToRenderBlendWithoutZWritePrimitives(!1),r.toClearDepthBuffer=!1,r.toClearColorBuffer=!1,!this.Xx){r.setFramebuffer(this.LT()),this.ST!=null?r.setResolveFramebuffer(this.MT):r.setResolveFramebuffer(void 0);for(let i of r.entities){let s=i.tryToGetMesh();if(g.exist(s)){let n=s.mesh;if(g.exist(n))for(let a=0;a<n.getPrimitiveNumber();a++)n.getPrimitiveAt(a).material.setTextureParameter("backBufferTexture",this.XR().getColorAttachedRenderTargetTexture(0),this.jT)}}}}this.BT=e,this.Db()}refreshBackBufferTextureOnTransparentMaterials(){var r;if(this.Xx)return;let e=(r=this.XR())==null?void 0:r.getColorAttachedRenderTargetTexture(0),t=this.jT;if(!(e==null||t==null))for(let i of this.BT)for(let s of i.renderPasses)for(let n of s.entities){let a=n.tryToGetMesh();if(g.exist(a)){let o=a.mesh;if(g.exist(o))for(let u=0;u<o.getPrimitiveNumber();u++)o.getPrimitiveAt(u).material.setTextureParameter("backBufferTexture",e,t)}}}Hb(){let e=new M;e.tryToSetUniqueName("Initial",!0);let t=new S(this.i);if(t.clearColor=N.fromCopyArray4([0,0,0,0]),t.toClearColorBuffer=!0,t.toClearDepthBuffer=!0,t.isOutputForVr=!0,t.tryToSetUniqueName("InitialRenderPass",!0),e.addRenderPasses([t]),!this.Xx){let r=new S(this.i);r.clearColor=N.fromCopyArray4([0,0,0,0]),r.toClearColorBuffer=!0,r.toClearDepthBuffer=!0,r.setFramebuffer(this.LT()),r.tryToSetUniqueName("InitialRenderPassForFrameBuffer",!0),e.addRenderPasses([r])}return e}Yb(e,t){let r=this.i._webXRSystemIfEnabled,i=this.i.cgApiResourceRepository;if(g.exist(r)&&(r!=null&&r.isWebXRMode)&&i.isSupportMultiViewVRRendering(this.i)){let s=F.createFrameBufferTextureArrayForMultiView(this.i,{width:e/2,height:t,arrayLength:2,level:0,internalFormat:this.gT?R.R11F_G11F_B10F:R.RGBA8,format:this.gT?$.RGB:$.RGBA,type:this.gT?z.Float:z.UnsignedByte});s.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiView",!0);let n=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});n.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiViewBlit",!0);let a=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});a.tryToSetUniqueName("FramebufferTargetOfToneMappingMultiViewBlitBackBuffer",!0),this.yT=s,this.IT=n,this.UT=a,this.ST=void 0,this.MT=void 0,this.RT=void 0}else{console.log(`canvasWidth: ${e}, canvasHeight: ${t}`);let s;this.db()||(s=F.createFrameBufferMSAA(this.i,{width:e,height:t,colorBufferNum:1,colorFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],sampleCountMSAA:4,depthBufferFormat:R.Depth32F}),s.tryToSetUniqueName("FramebufferTargetOfToneMappingMsaa",!0));let n=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!0,depthTextureFormat:R.Depth32F});n.tryToSetUniqueName("FramebufferTargetOfToneMappingResolve",!0);let a=F.createFrameBuffer(this.i,{width:e,height:t,textureNum:1,textureFormats:[this.gT?R.R11F_G11F_B10F:R.RGBA8],createDepthBuffer:!1});a.tryToSetUniqueName("FramebufferTargetOfToneMappingResolveForReference",!0),this.yT=void 0,this.IT=void 0,this.UT=void 0,this.ST=s,this.MT=n,this.RT=a}}qb(e){let t=new M;t.tryToSetUniqueName("GenerateMipmaps",!0);let r=new S(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("GenerateMipmaps",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(function(){e.getColorAttachedRenderTargetTexture(0).generateMipmaps()}),t}zb(e){let t=new M;t.tryToSetUniqueName("MultiViewBlitBackBuffer",!0);let r=new S(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("MultiViewBlitBackBuffer",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(()=>{if(this.UT!=null&&!k.isMobile()){let i=this.UT.colorAttachments[0];e.colorAttachments[0].blitToTexture2dFromTexture2dArrayFake(i),i.generateMipmaps()}}),t}$b(e){let t=new M;t.tryToSetUniqueName("MultiViewBlit",!0);let r=new S(this.i);return t.addRenderPasses([r]),r.tryToSetUniqueName("MultiViewBlit",!0),r.toClearDepthBuffer=!1,r.setPostRenderFunction(()=>{if(this.IT!=null){let i=this.IT.colorAttachments[0];e.colorAttachments[0].blitToTexture2dFromTexture2dArrayFake(i)}}),t}jb(e){let t=new M,r=K(this.i);this.ZR=r,this.setToneMappingType(this.KR);let i=X.createScreenDrawRenderPassWithBaseColorTexture(this.i,r,e);i.tryToSetUniqueName("renderPassToneMapping",!0),i.toClearColorBuffer=!1,i.toClearDepthBuffer=!1,i.isDepthTest=!1,i.clearColor=N.fromCopyArray4([0,0,0,0]),i.isVrRendering=!1,i.isOutputForVr=!1;let s=X.createScreenDrawRenderPassWithBaseColorTexture(this.i,r,e);return s.tryToSetUniqueName("renderPassToneMappingVr",!0),s.toClearColorBuffer=!1,s.toClearDepthBuffer=!1,s.isDepthTest=!1,s.clearColor=N.fromCopyArray4([0,0,0,0]),s.isVrRendering=!1,s.isOutputForVr=!0,t.addRenderPasses([i,s]),t}lM(e){return F.createFrameBuffer(this.i,{width:e,height:e,textureNum:1,textureFormats:[R.RG32F],createDepthBuffer:!0,depthTextureFormat:R.Depth32F})}wb(){for(let e of this.hp)for(let t of e.renderPasses)for(let r of t.entities){let i=r.tryToGetMeshRenderer();g.exist(i)&&i.setIBLCubeMap(this.$T,this.XT,this.ET)}}Db(){for(let e of this.BT)for(let t of e.renderPasses)for(let r of t.entities){let i=r.tryToGetMeshRenderer();g.exist(i)&&i.setIBLCubeMap(this.$T,this.XT,this.ET)}}setToneMappingType(e){let t=this.ZR;t!=null&&(this.KR=e,t.removeShaderDefine("RN_USE_KHRONOS_PBR_NEUTRAL"),t.removeShaderDefine("RN_USE_REINHARD"),t.removeShaderDefine("RN_USE_GT_TONEMAP"),t.removeShaderDefine("RN_USE_ACES_NARKOWICZ"),t.removeShaderDefine("RN_USE_ACES_HILL"),t.removeShaderDefine("RN_USE_ACES_HILL_EXPOSURE_BOOST"),e===v.KhronosPbrNeutral?t.addShaderDefine("RN_USE_KHRONOS_PBR_NEUTRAL"):e===v.Reinhard?t.addShaderDefine("RN_USE_REINHARD"):e===v.GT_ToneMap?t.addShaderDefine("RN_USE_GT_TONEMAP"):e===v.ACES_Narkowicz?t.addShaderDefine("RN_USE_ACES_NARKOWICZ"):e===v.ACES_Hill?t.addShaderDefine("RN_USE_ACES_HILL"):e===v.ACES_Hill_Exposure_Boost&&t.addShaderDefine("RN_USE_ACES_HILL_EXPOSURE_BOOST"))}Zb(){let e=new M;e.tryToSetUniqueName("Raymarching",!0);let t=new S(this.i);return t.toClearDepthBuffer=!1,t.isDepthTest=!0,this.Gb(t),t.setPreRenderFunction(()=>this.eM(t)),e.addRenderPasses([t]),t.tryToSetUniqueName("Raymarching",!0),[e,t]}Gb(e){var r;let t=this.LT();e.setFramebuffer(t),t!=null&&this.ST!=null?(e.setResolveFramebuffer(this.MT),e.setResolveFramebuffer2((r=this.RT)!=null?r:void 0)):(e.setResolveFramebuffer(void 0),e.setResolveFramebuffer2(t!=null?this.RT:void 0))}eM(e){this.NT(),this.ZT();let t=e.material;if(t==null)return;let r=this.i.componentRepository.getComponentsWithType(C),i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,u=Number.NEGATIVE_INFINITY,f=r.length>0;for(let l of r){let T=l.entity.tryToGetSceneGraph();T!=null&&(t.setParameter(`worldMatrix_${l.componentSID}`,T.matrixInner),t.setParameter(`raymarchObjectId_${l.componentSID}`,A.fromCopyNumber(l.componentSID)));let h=this.JT(l);if(h==null){f=!1;continue}i=Math.min(i,h.min.x),s=Math.min(s,h.min.y),n=Math.min(n,h.min.z),a=Math.max(a,h.max.x),o=Math.max(o,h.max.y),u=Math.max(u,h.max.z)}f?(t.setParameter("raymarchAabbMin",P.fromCopy3(i,s,n)),t.setParameter("raymarchAabbMax",P.fromCopy3(a,o,u))):(t.setParameter("raymarchAabbMin",_),t.setParameter("raymarchAabbMax",D))}setRaymarchingComponentMaterial(e,t){var r;this.Zx.set(e.componentSID,t),this.NT(),this.ZT(),(r=this.PT)==null||r.applyShadowParametersToMaterials([t]),this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT()}getRaymarchingComponentMaterial(e){return this.Zx.get(e.componentSID)}removeRaymarchingComponentMaterial(e){this.Zx.delete(e.componentSID)&&(this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT())}setRaymarchingMaterial(e){var t,r;(t=this._T)==null||t.setBufferLessFullScreenRendering(e),this.NT(),this.ZT(),(r=this.PT)==null||r.applyShadowParametersToMaterials([e]),this.refreshRaymarchingShadowMaterial(),this.bT!=null&&this.CT()}tM(){let e=[],t=new Set;if(this.qR=-1,this.Zx.size>0)for(let r of this.KT()){let i=r.componentSID,s=this.Zx.get(i);if(s==null)continue;t.add(i);let n=this.wT.get(i);n==null&&(n=new S(this.i),n.toClearDepthBuffer=!1,n.isDepthTest=!0,n.setPreRenderFunction(()=>this.rM(i)),n.tryToSetUniqueName(`Raymarching_${i}`,!0),this.wT.set(i,n)),n.setBufferLessFullScreenRendering(s),this.Gb(n),e.length===0&&(this.qR=i),e.push(n)}for(let r of[...this.wT.keys()])t.has(r)||this.wT.delete(r);for(let r of[...this.Zx.keys()])!t.has(r)&&this.i.componentRepository.getComponent(C,r)==null&&this.Zx.delete(r);return e}rM(e){var n,a,o;e===this.qR&&(this.NT(),this.ZT());let t=this.Zx.get(e),r=this.i.componentRepository.getComponent(C,e),i=r==null?void 0:r.entity.tryToGetSceneGraph();if(t==null||r==null||i==null)return;t.setParameter(U,i.matrixInner);let s=this.JT(r);t.setParameter("raymarchAabbMin",(n=s==null?void 0:s.min)!=null?n:_),t.setParameter("raymarchAabbMax",(a=s==null?void 0:s.max)!=null?a:D),(o=this.wT.get(e))==null||o.setScissorRect(this.iM(s))}JT(e){let t=e.entity.tryToGetSceneGraph();if(t==null)return null;let r=t.matrixInner,i=[r.m00,r.m01,r.m02,r.m03,r.m10,r.m11,r.m12,r.m13,r.m20,r.m21,r.m22,r.m23,r.m30,r.m31,r.m32,r.m33],s=C.getAABBVersion(this.i),n=e.componentSID,a=this.HT.get(n);if(a!=null&&a.aabbVersion===s&&a.matrix.length===i.length&&a.matrix.every((f,l)=>f===i[l]))return a.aabb;let o=e.calcWorldAABB();if(o==null)return this.HT.delete(n),null;let u={min:P.fromCopy3(o.minPoint.x,o.minPoint.y,o.minPoint.z),max:P.fromCopy3(o.maxPoint.x,o.maxPoint.y,o.maxPoint.z)};return this.HT.set(n,{aabbVersion:s,matrix:i,aabb:u}),u}iM(e){if(e==null||this.sm<=0||this.TT<=0)return;let t=this.i.componentRepository.getComponent(q,q.getCurrent(this.i));if(t==null)return;let r=t.viewProjectionMatrix,i=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let c=0;c<8;c++){let m=(c&1)===0?e.min.x:e.max.x,p=(c&2)===0?e.min.y:e.max.y,x=(c&4)===0?e.min.z:e.max.z,y=r.multiplyVector(N.fromCopy4(m,p,x,1));if(y.w<=0)return;let E=y.x/y.w,B=y.y/y.w,b=(E*.5+.5)*this.sm,Y=(-B*.5+.5)*this.TT;i=Math.min(i,b),s=Math.min(s,Y),n=Math.max(n,b),a=Math.max(a,Y)}let o=2,u=Math.max(0,Math.floor(i)-o),f=Math.max(0,Math.floor(s)-o),l=Math.min(this.sm,Math.ceil(n)+o),T=Math.min(this.TT,Math.ceil(a)+o),h=l-u,d=T-f;if(h<=0||d<=0)return{x:0,y:0,width:1,height:1};if(!(u===0&&f===0&&h===this.sm&&d===this.TT))return{x:u,y:f,width:h,height:d}}QT(){let e=[];for(let r of this.Zx.values())e.push(r);let t=this.getRaymarchingMaterial();return t!=null&&e.push(t),e}sM(){let e=new M;e.tryToSetUniqueName("Raymarching",!0);let t=this.tM();return t.length>0?e.addRenderPasses(t):this._T!=null&&this._T.material!=null&&e.addRenderPasses([this._T]),e}refreshRaymarchingShadowMaterial(){let e=this.vT,t=new Map(this.FT);if(this.DT=void 0,this.vT=void 0,this.GT.clear(),this.FT.clear(),this.OT.clear(),this.VT=this.Zx.size>0,!(this.PT==null||this.i.config.maxLightNumber<=0)){if(this.VT)for(let r of this.KT()){let i=r.componentSID;if(!r.castShadow||!this.Zx.has(i))continue;let s=V(this.i,r,"regular",t.get(i));s!=null&&this.FT.set(i,s)}else{let r=J(this.i,{castShadowOnly:!0});if(r.nodes.length>0){let i=r;this.DT=i,this.vT=O(this.i,i,"regular",e)}}this.PT.invalidateShadowVolumeFitting(),this.PT.setNeedsRefresh()}}KT(){let e=this.i.componentRepository.getComponentsWithType(C).slice();return e.sort((t,r)=>t.componentSID-r.componentSID),e}getRaymarchingShadowMaterial(){return this.vT}getRaymarchingComponentShadowMaterial(e){return this.FT.get(e.componentSID)}Pb(){return{hasCaster:()=>this.VT?this.FT.size>0:this.DT!=null&&this.vT!=null,createPasses:e=>this.nM(e),updatePointLightFarPlane:(e,t)=>this.aM(e,t)}}oM(e,t,r){let i=this.GT.get(e);if(i==null){let n=this.DT;if(n==null)return;let a=O(this.i,n,"paraboloidFront"),o=O(this.i,n,"paraboloidBack");if(a==null||o==null)return;i={front:a,back:o},this.GT.set(e,i)}let s=A.fromCopyNumber(t);return i.front.setParameter("lightIndex",s),i.back.setParameter("lightIndex",s),this.NR(i,r),i}NR(e,t){let r=A.fromCopyNumber(t);e.front.setParameter("shadowFarPlane",r),e.back.setParameter("shadowFarPlane",r)}hM(e,t,r,i){let s=this.OT.get(e);s==null&&(s=new Map,this.OT.set(e,s));let n=s.get(i.componentSID);if(n==null){let o=V(this.i,i,"paraboloidFront"),u=V(this.i,i,"paraboloidBack");if(o==null||u==null)return;n={front:o,back:u},s.set(i.componentSID,n)}let a=A.fromCopyNumber(t);return n.front.setParameter("lightIndex",a),n.back.setParameter("lightIndex",a),this.NR(n,r),n}aM(e,t){let r=this.GT.get(e);r!=null&&this.NR(r,t);let i=this.OT.get(e);if(i!=null)for(let s of i.values())this.NR(s,t)}nM(e){let{lightComponent:t,kind:r,shadowSlot:i,farPlane:s}=e;if(this.VT){let a=[];for(let o of this.KT()){let u=o.componentSID;if(!o.castShadow||!this.Zx.has(u))continue;let f;if(r==="regular")f=this.FT.get(u);else{let l=this.hM(i,t.componentSID,s!=null?s:1e3,o);f=r==="paraboloidFront"?l==null?void 0:l.front:l==null?void 0:l.back}f!=null&&a.push(this.Lb(f,e))}return a}let n;if(r==="regular")n=this.vT;else{let a=this.oM(i,t.componentSID,s!=null?s:1e3);n=r==="paraboloidFront"?a==null?void 0:a.front:a==null?void 0:a.back}return n==null?[]:[this.Lb(n,e)]}Lb(e,{lightEntity:t,framebuffer:r,kind:i}){let s=new S(this.i);return s.isVrRendering=!1,s.setBufferLessFullScreenRendering(e),s.setFramebuffer(r),s.toClearColorBuffer=!1,s.toClearDepthBuffer=!1,s.isDepthTest=!0,s.depthWriteMask=!0,i==="regular"&&(s.cameraComponent=t.getCamera()),s.tryToSetUniqueName(`RaymarchingShadow_${i}`,!0),s}Qb(){if(this.VT){this.uM();return}if(this.DT==null)return;let e=[];this.vT!=null&&e.push(this.vT);for(let m of this.GT.values())e.push(m.front,m.back);let t=this.Zx,r=this.getRaymarchingMaterial(),i=t.size>0?t.values().next().value:r,s=(m,p,x)=>{if(i!=null)if(G.isTexture(x.compositionType)){let y=i.getTextureParameter(p);y!=null&&m.setTextureParameter(p,y[1],y[2])}else{let y=i.getParameter(p);y!=null&&m.setParameter(p,y)}},n=this.i.componentRepository.getComponentsWithType(C),a=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,T=Number.NEGATIVE_INFINITY,h=!1;for(let m of n){if(!m.castShadow)continue;h=!0;let p=this.JT(m);if(p==null){h=!1;break}a=Math.min(a,p.min.x),o=Math.min(o,p.min.y),u=Math.min(u,p.min.z),f=Math.max(f,p.max.x),l=Math.max(l,p.max.y),T=Math.max(T,p.max.z)}let d=h?P.fromCopy3(a,o,u):_,c=h?P.fromCopy3(f,l,T):D;for(let m of e){m.setParameter("raymarchAabbMin",d),m.setParameter("raymarchAabbMax",c);for(let p of m.fieldsInfoArray){let x=p.semantic;if(x.startsWith("worldMatrix_")||x.startsWith("raymarchObjectId_")||x==="raymarchAabbMin"||x==="raymarchAabbMax"||x==="lightIndex"||x==="shadowFarPlane")continue;let y=/^(.*)_(\d+)$/.exec(x),E=y!=null?t.get(Number(y[2])):void 0;if(E!=null){let B=y[1];if(G.isTexture(p.compositionType)){let b=E.getTextureParameter(B);b!=null&&m.setTextureParameter(x,b[1],b[2])}else{let b=E.getParameter(B);b!=null&&m.setParameter(x,b)}}else s(m,x,p)}for(let p of n){if(!p.castShadow)continue;let x=p.entity.tryToGetSceneGraph();x!=null&&m.setParameter(`worldMatrix_${p.componentSID}`,x.matrixInner),m.setParameter(`raymarchObjectId_${p.componentSID}`,A.fromCopyNumber(p.componentSID))}}}uM(){var e,t;for(let r of this.KT()){let i=r.componentSID;if(!r.castShadow)continue;let s=this.Zx.get(i);if(s==null)continue;let n=[],a=this.FT.get(i);a!=null&&n.push(a);for(let h of this.OT.values()){let d=h.get(i);d!=null&&n.push(d.front,d.back)}if(n.length===0)continue;let o=r.entity.tryToGetSceneGraph(),u=o==null?void 0:o.matrixInner,f=this.JT(r),l=(e=f==null?void 0:f.min)!=null?e:_,T=(t=f==null?void 0:f.max)!=null?t:D;for(let h of n){u!=null&&h.setParameter(U,u),h.setParameter("raymarchAabbMin",l),h.setParameter("raymarchAabbMax",T);for(let d of h.fieldsInfoArray){let c=d.semantic;if(!(c===U||c==="raymarchAabbMin"||c==="raymarchAabbMax"||c==="lightIndex"||c==="shadowFarPlane"))if(G.isTexture(d.compositionType)){let m=s.getTextureParameter(c);m!=null&&h.setTextureParameter(c,m[1],m[2])}else{let m=s.getParameter(c);m!=null&&h.setParameter(c,m)}}}}}Rb(){return this.QT()}getRaymarchingMaterial(){var e;return(e=this._T)==null?void 0:e.material}NT(){for(let e of this.QT())this.fM(e)}fM(e){var u,f,l,T,h,d;let t=e.getTextureParameter(I.DiffuseEnvTexture.str),r=e.getTextureParameter(I.SpecularEnvTexture.str);if(t==null||r==null)return;let i=e.getTextureParameter(I.SheenEnvTexture.str),s=this.$T,n=this.XT;if(s==null||n==null)return;let a=`${s.objectUID}:${s.isTextureReady}:${n.objectUID}:${n.isTextureReady}:${(f=(u=this.ET)==null?void 0:u.objectUID)!=null?f:-1}:${(T=(l=this.ET)==null?void 0:l.isTextureReady)!=null?T:!1}:${this.OR}:${this.kR}:${this.LR}:${n.iblMipLevelSkip}`;if(a===this.YR.get(e.objectUID))return;this.YR.set(e.objectUID,a);let o=t[2];if(s.isTextureReady&&e.setTextureParameter(I.DiffuseEnvTexture.str,s,o),n.isTextureReady&&(e.setTextureParameter(I.SpecularEnvTexture.str,n,o),i!=null)){let c=(h=this.ET)!=null&&h.isTextureReady?this.ET:n,m=(d=i[2])!=null?d:o;e.setTextureParameter(I.SheenEnvTexture.str,c,m)}e.setParameter("iblParameter",N.fromCopy4(n.mipmapLevelNumber,this.kR,this.LR,this.OR)),e.setParameter("iblMipLevelSkip",n.iblMipLevelSkip),e.setParameter("hdriFormat",ee.fromCopy2(s.hdriFormat.index,n.hdriFormat.index))}mM(){return this.QT().some(e=>e.isShaderDefine("RN_USE_TRANSMISSION"))}ZT(){var r;if(this.Xx)return;let e=(r=this.XR())==null?void 0:r.getColorAttachedRenderTargetTexture(0),t=this.jT;if(!(e==null||t==null))for(let i of this.QT())i.setTextureParameter(I.BackBufferTexture.str,e,t)}CT(){let e=this.bT;if(e==null){console.log("Frame is not set.");return}if(e.clearExpressions(),e.addExpression(this.DR),this.AT=this.sM(),!this.Xx)for(let i of this.$R)e.addExpression(i);let t=this.mM();!t&&this.AT!=null&&e.addExpression(this.AT);for(let i of this.hp)this.Xx?i.renderPasses.forEach(s=>{s.isOutputForVr=!0}):i.renderPasses.forEach(s=>{s.isOutputForVr=!1}),e.addExpression(i);!this.Xx&&this.YT!=null&&!k.isMobile()&&e.addExpression(this.YT),!this.Xx&&this.VR!=null&&e.addExpression(this.VR),t&&this.AT!=null&&e.addExpression(this.AT);for(let i of this.BT)this.Xx?i.renderPasses.forEach(s=>{s.isOutputForVr=!0}):i.renderPasses.forEach(s=>{s.isOutputForVr=!1}),e.addExpression(i);if(this.WT.renderPasses.length>0){if(!this.Xx){let i=this.LT();if(i!=null)for(let s of this.WT.renderPasses)s.setFramebuffer(i),this.ST!=null&&s.setResolveFramebuffer(this.MT)}e.addExpression(this.WT)}let r=this.hp.flatMap(i=>i.renderPasses.flatMap(s=>s.entities));this.QR=r,this.Yx!=null&&(this.Yx.setEntities(r),e.addExpression(this.Yx.expression)),!this.Xx&&this.qT!=null&&e.addExpression(this.qT),!this.Xx&&this.gT&&this.zT!=null&&e.addExpression(this.zT),!this.Xx&&this.kT!=null&&e.addExpression(this.kT)}};export{j as ForwardRenderPipeline};
@@ -1 +1 @@
1
- import{VERSION as B}from"../../version.js";import{CameraComponent as G}from"../components/Camera/CameraComponent.js";import{createCameraEntity as V}from"../components/Camera/createCameraEntity.js";import{LightComponent as E}from"../components/Light/LightComponent.js";import{MeshComponent as j}from"../components/Mesh/MeshComponent.js";import{MeshRendererComponent as P}from"../components/MeshRenderer/MeshRendererComponent.js";import{SceneGraphComponent as S}from"../components/SceneGraph/SceneGraphComponent.js";import{SkeletalComponent as J}from"../components/Skeletal/SkeletalComponent.js";import{TransformComponent as _}from"../components/Transform/TransformComponent.js";import{WellKnownComponentTIDs as k}from"../components/WellKnownComponentTIDs.js";import{Component as I}from"../core/Component.js";import{ComponentMemoryRegistry as H}from"../core/ComponentMemoryRegistry.js";import{ComponentRepository as y}from"../core/ComponentRepository.js";import{_getComponentRuntimeHooks as F}from"../core/ComponentRuntimeHooks.js";import{Config as X}from"../core/Config.js";import{EntityRepository as K}from"../core/EntityRepository.js";import{GlobalDataRepository as Q}from"../core/GlobalDataRepository.js";import{MemoryManager as Y}from"../core/MemoryManager.js";import{CameraType as Z}from"../definitions/CameraType.js";import{ProcessApproach as d}from"../definitions/ProcessApproach.js";import{ProcessStage as M}from"../definitions/ProcessStage.js";import{Primitive as A}from"../geometry/Primitive.js";import{DummyTextures as ee}from"../materials/core/DummyTextures.js";import{Vector3 as te}from"../math/Vector3.js";import{Vector4 as re}from"../math/Vector4.js";import{Is as L}from"../misc/Is.js";import{Logger as N}from"../misc/Logger.js";import{Time as T}from"../misc/Time.js";import{_getPhysicsBackend as se}from"../physics/PhysicsBackend.js";import{CGAPIResourceRepository as O}from"../renderer/CGAPIResourceRepository.js";import{Expression as ie}from"../renderer/Expression.js";import{Frame as oe}from"../renderer/Frame.js";import{LightClusterSystemStub as ne}from"../renderer/lightCluster/LightClusterSystemStub.js";import{RenderPass as $}from"../renderer/RenderPass.js";import{EngineState as ae}from"./EngineState.js";import{ModuleManager as U}from"./ModuleManager.js";import{WebGLGpuTimer as pe}from"../../webgl/WebGLGpuTimer.js";import{_cleanupWebGLStatesCacheForEngine as ue}from"../../webgl/WebGLStrategyCommonMethod.js";import{RnObject as ce}from"../core/RnObject.js";import{_cleanupGizmosForEngine as fe}from"../gizmos/GizmoRegistry.js";import{_cleanupRenderPassHelperForEngine as he}from"../helpers/RenderPassHelper.js";import{AbstractMaterialContent as de}from"../materials/core/AbstractMaterialContent.js";import{MaterialRepository as me}from"../materials/core/MaterialRepository.js";var m=class m extends ce{constructor(e,t,s,i,r){super();this.tC=d.None;this.oC=new ae;this.nC=0;this.pC=-1;this.WC=[];this.cC=new ne;this.wC=!1;this.o=!1;this.dC=-1;this.nr=-1;this.mC=-1;this.or=-1;this._C=0;this.LC=!1;this.BC=new Map;this.lC=!1;this.DC=-1;this.fC=i!=null?i:new X,this.xC=new N,this.xC.logLevel=this.fC.logLevel,this.DC=m.UC,this.tC=e,this.rC=t,this.GC=new H,this.uC=new y(this),this.Na=new K(this),this.EC=new me,this.of=Y.createInstanceIfNotCreated(this,s),r!=null&&this.SC(r),this.yC=Q.init(this),m.UC++}get engineUid(){return this.DC}static getEngine(e){let t=m.TC.get(e);if(!L.not.exist(t))return t}destroy(){this.stopRenderLoop(),this.RC=void 0,this.WC=[],this.Lb()}Lb(){var t,s;this.o=!0,this.EC._makeShaderInvalidateToAllMaterials();let e=this.Na._getEntities();for(let i of e)this.Na.deleteEntity(i.entityUID);if(L.exist(this.hC)&&(this.hC.destroy(),this.hC=void 0),L.exist(this.sC)){this.sC.clearCache();try{let i=this.sC.getWebGpuDeviceWrapper();i&&i.context.unconfigure()}catch{}}L.exist(this.of)&&(this.of.destroy(),this.of=void 0),this.XC(),_._cleanupForEngine(this),S._cleanupForEngine(this),G._cleanupForEngine(this),E._cleanupForEngine(this),P._cleanupForEngine(this),(t=se())==null||t.cleanupForEngine(this),fe(this),de._cleanupForEngine(this),he(this),ue(this),(s=this.aC)==null||s.destroy(),this.aC=void 0,this.GC.destroy(),this.gC=void 0,this.bC=void 0,this.nC=0,this.dC=-1,this.nr=-1,this.mC=-1,m.TC.delete(this.objectUID),this.unregister()}startRenderLoop(e,...t){this.RC=e,this.WC=t,this.pC!==-1&&this.stopRenderLoop();let s=this.FC();this.vC=s;let i=s.requestAnimationFrame.bind(s),r=this.eC,c=this.iC,u=t.length>0,n=u?[0,...t]:[],p=u?o=>{n[0]=o,e.apply(e,n)}:o=>{e.call(e,o)},a=((o,l)=>{r!=null&&r.isReadyForWebXR?(r._preRender(o,l),p(o),r._postRender()):c!=null&&c.isReadyForWebAR?(c._preRender(o,l),p(o),c._postRender()):p(o),this.pC=i(a)});this.pC=i(a)}FC(){let e=window,t=this.eC,s=this.iC;return t!=null&&t.requestedToEnterWebXR?e=t.xrSession:s!=null&&s.requestedToEnterWebAR&&(e=s.arSession),L.not.exist(e)?window:e}stopRenderLoop(){var t;let e=(t=this.vC)!=null?t:this.FC();this.pC!==-1&&e.cancelAnimationFrame(this.pC),this.pC=-1,this.vC=void 0}restartRenderLoop(){this.RC!=null&&this.startRenderLoop(this.RC,...this.WC)}processAuto(e=re.fromCopy4(0,0,0,1)){if(L.not.exist(this.gC)){let s=new ie,i=new $(this);i.toClearColorBuffer=!0,i.toClearDepthBuffer=!0,i.clearColor=e;let r=new $(this);s.addRenderPasses([i,r]),this.gC=s,this.bC=r}this.bC.clearEntities();let t=this.Na._getEntities();this.bC.addEntities(t),this.process([this.gC])}process(e){let t=this.lC;t&&this.NC(),T._processBegin(this),this.OC(),!this.wC&&E.getUpdateCount(this)>0&&this._requestLightClusterSystem();let s=e;e instanceof oe&&(s=e.expressions),G.getCurrent(this)===I.InvalidObjectUID&&m.createCamera(this);let i=this.yC.getValue("time",0);i._v[0]=T.timeFromSystemStart,this.processApproach===d.WebGPU?this._processWebGPU(s):this._processWebGL(s),T._processEnd(),t&&this.$C()}get gpuTimerEnabled(){return this.lC}set gpuTimerEnabled(e){this.lC=e}get isGpuTimerSupported(){var e,t;return this.tC===d.WebGPU?this.webGpuResourceRepository._getGpuTimer().isSupported:(t=(e=this.MC())==null?void 0:e.isSupported)!=null?t:!1}get gpuTimeMilliseconds(){var e,t;if(this.lC)return this.tC===d.WebGPU?(e=this.sC)==null?void 0:e._getGpuTimer().lastGpuTimeMilliseconds:(t=this.aC)==null?void 0:t.lastGpuTimeMilliseconds}get gpuPassTimesMilliseconds(){var e;if(!(!this.lC||this.tC!==d.WebGPU))return(e=this.sC)==null?void 0:e._getGpuTimer().lastPassGpuTimesMilliseconds}MC(){var e;if(this.aC==null){let t=(e=this.CC)==null?void 0:e.currentWebGLContextWrapper;if(t==null)return;this.aC=new pe(t.getRawContextAsWebGL2())}return this.aC}NC(){var e,t;this.tC===d.WebGPU?(e=this.sC)==null||e._getGpuTimer().beginFrame():(t=this.MC())==null||t.begin()}$C(){var e,t;this.tC===d.WebGPU?(e=this.sC)==null||e._getGpuTimer().endFrame():(t=this.aC)==null||t.end()}zC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,hasAnyEffekseerComponents:c,deferredEffekseerRenderJobs:u}){t.doPreRender();let n;if(c&&t.toRenderEffekseerEffects){n=[];let h=t.entities;for(let f=0;f<h.length;f++){let g=h[f].tryToGetEffekseer();g!=null&&n.push(g)}n.length===0&&(n=void 0)}let p=n!=null,a=p?e.getEffekseerRenderPassOptions(this,t,r):void 0,o=t.toRenderEffekseerEffects&&p,l=o&&t.getResolveFramebuffer()!=null&&u!=null;if(o&&a!=null)for(let h of n)h.prepareWebGPURendering(a);if(l&&u.push({renderPass:t,displayIdx:r,renderPassOptions:a,effekseerComponents:n}),e.clearFrameBuffer(this,t,r),this.qC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,shouldKeepRenderPassForEffekseer:o&&!l}),o&&!l){let h=e.getOrCreateRenderPassEncoderForEffekseerExternalRendering(this,t,r);if(h!=null)for(let f of n)f.$renderWebGPU(h,a,r);e.endRenderPassEncoderForExternalRendering()}return t._copyResolve1ToResolve2WebGpu(),t.doPostRender(),o}VC({webGpuResourceRepository:e,currentRenderPass:t,deferredEffekseerRenderJobs:s,displayIdx:i}){if(s.length===0)return;let r=t.getResolveFramebuffer();if(r!=null)for(let c of s){if(c.displayIdx!==i||c.renderPass.getResolveFramebuffer()!==r)continue;let u=e.getOrCreateRenderPassEncoderForEffekseerExternalRendering(this,c.renderPass,i);if(u!=null)for(let n of c.effekseerComponents)n.$renderWebGPU(u,c.renderPassOptions,i);e.endRenderPassEncoderForExternalRendering(),c.renderPass._copyResolve1ToResolve2WebGpu()}}qC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,shouldKeepRenderPassForEffekseer:c}){var a;let u,n=t._renderedSomethingBefore;if(n&&(c?(u=e.renderWithRenderBundleAndKeepRenderPass(this,t,r),n=u==null):n=!e.renderWithRenderBundle(this,t,r),(a=this.oC).webgpuRenderBundleMode||(a.webgpuRenderBundleMode=n)),!n)return u;e.createRenderBundleEncoder(this,t,r);let p=P.common_$render({renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,engine:this});if(t._renderedSomethingBefore=p,!p)return u;if(c)return e.finishRenderBundleEncoderAndKeepRenderPass(this,t,r);e.finishRenderBundleEncoder(this,t,r)}_processWebGPU(e){var r,c;let t=this.uC.getComponentTIDs(),s=this.webGpuResourceRepository,i=this.eC;for(let u of I._processStages){if(u===M.Render){this.cC.update(e),P.common_$prerender(this);let n=(r=i==null?void 0:i.isWebXRMode)!=null?r:!1,p=(c=i==null?void 0:i.isMultiView())!=null?c:!1,a=this.oC.xrPoseWebGPU,o=n&&!p&&a!=null?a.views.length:1,l=this.uC.hasAnyComponent(k.EffekseerComponentTID),h=o>1,f=h?new Map:void 0,g=h?new Map:void 0;for(let b=0;b<o;b++){let C=l?[]:void 0,x=!1;for(let D of e)for(let R of D.renderPasses){let v=R.renderPassUID,w=f==null?void 0:f.get(v),W;w===void 0?(w=this.nC,R._isChangedSortRenderResult=!1,W=P.sort_$render(this,R),f!=null&&(f.set(v,w),g.set(v,W))):W=g.get(v);let q=this.zC({webGpuResourceRepository:s,renderPass:R,renderPassTickCount:w,primitiveUids:W,displayIdx:b,hasAnyEffekseerComponents:l,deferredEffekseerRenderJobs:C});x||(x=q),C!=null&&C.length>0&&this.VC({webGpuResourceRepository:s,currentRenderPass:R,deferredEffekseerRenderJobs:C,displayIdx:b}),b===o-1&&(f==null||f.delete(v),g==null||g.delete(v),this.nC++)}b<o-1&&x&&s.flush()}s.flush()}else if(!this.oC.webgpuRenderBundleMode||this.AC()||_.getUpdateCount(this)!==this.nr||G.getCurrentCameraUpdateCount(this)!==this.dC||A.getPrimitiveCount()!==this.mC||E.getUpdateCount(this)!==this.or){let n=`common_${u.methodName}`;for(let p of t){let a=y.getComponentClass(p),o=a[n];o&&o({processApproach:this.tC,renderPass:void 0,processStage:u,renderPassTickCount:this.nC,displayIdx:0,engine:this}),a.process(this,a,u)}}u===M.Logic&&S._updateTransformGizmosByCameraChange(this)}this.dC=G.getCurrentCameraUpdateCount(this),this.kC(),this.nr=_.getUpdateCount(this),this.mC=A.getPrimitiveCount(),this.or=E.getUpdateCount(this)}OC(){var e;for(let t of F())(e=t.beginFrame)==null||e.call(t,this)}AC(){var e;for(let t of F())if(((e=t.isDirty)==null?void 0:e.call(t,this))===!0)return!0;return!1}kC(){var e;for(let t of F())(e=t.markUpdated)==null||e.call(t,this)}XC(){var e;for(let t of F())(e=t.cleanup)==null||e.call(t,this)}_processWebGL(e){let t=this.webglResourceRepository,s=this.uC.getComponentTIDs(),i=this.uC.getRenderingComponentTIDs();for(let r of I._processStages){let u=`common_${r.methodName}`;if(r===M.Render){t.getMultiDrawRepository(this).rebuildDirtyGroups(),this.cC.update(e),P.common_$prerender(this);for(let n of e)for(let p of i){let a=y.getComponentClass(p);for(let o of n.renderPasses){typeof spector!="undefined"&&spector.setMarker(`| ${n.uniqueName}: ${o.uniqueName}#`),o.doPreRender(),t.switchDepthTest(o.isDepthTest),this.bindFramebufferWebGL(o),this.setViewportForNormalRendering(o),this.setScissorForNormalRendering(o),p===k.MeshRendererComponentTID&&this.rC.clearFrameBuffer(this,o),o._isChangedSortRenderResult=!1;let l=P.sort_$render(this,o);if(o._renderedSomethingBefore){let f=a[u];if(f){let g=f({processApproach:this.tC,renderPass:o,processStage:r,renderPassTickCount:this.nC,primitiveUids:l,displayIdx:0,engine:this});o._renderedSomethingBefore=g}}if(p===k.EffekseerComponentTID&&o.entities.length>0){let f=this.webglResourceRepository,g=f.getCurrentTexture2DBindingsForEffekseer();f.setWebGLStateToDefaultForEffekseer();for(let b of o.entities){let C=b.tryToGetEffekseer();C!=null&&C.$render()}f.restoreTexture2DBindingsForEffekseer(g)}this.nC++,o._copyFramebufferToResolveFramebuffersWebGL(),o.doPostRender()}}}else if(this.AC()||_.getUpdateCount(this)!==this.nr||G.getCurrentCameraUpdateCount(this)!==this.dC||A.getPrimitiveCount()!==this.mC||E.getUpdateCount(this)!==this.or)for(let n of s){let p=y.getComponentClass(n),a=p[u];a&&a({processApproach:this.tC,renderPass:void 0,processStage:r,renderPassTickCount:this.nC,displayIdx:0,engine:this}),p.process(this,p,r)}r===M.Logic&&S._updateTransformGizmosByCameraChange(this)}this.dC=G.getCurrentCameraUpdateCount(this),this.kC(),this.nr=_.getUpdateCount(this),this.mC=A.getPrimitiveCount(),this.or=E.getUpdateCount(this)}static get processTime(){return T.lastTimeTimeIntervalInMilliseconds}static get timeAtProcessBegin(){return T.timeAtProcessBeginMilliseconds}static get timeAtProcessEnd(){return T.timeAtProcessEndMilliseconds}static createCamera(e){let t=V(e,!0);t.getTransform().localPosition=te.fromCopyArray([0,0,1]),t.getCamera().type=Z.Orthographic,t.getCamera().zNear=.1,t.getCamera().zFar=1e4;let s=e.cgApiResourceRepository,[i,r]=s.getCanvasSize();t.getCamera().xMag=i/r,t.getCamera().yMag=1}setViewportForNormalRendering(e){let t=this.eC,s=this.iC;(!(t!=null&&t.isWebXRMode)||!e.isVrRendering)&&!(s!=null&&s.isWebARMode)&&this.rC.setViewport(this,e.getViewport())}setScissorForNormalRendering(e){let t=this.eC,s=this.iC,i=this.rC;(!(t!=null&&t.isWebXRMode)||!e.isVrRendering)&&!(s!=null&&s.isWebARMode)?i.setScissorRect(e):i.setScissorRect(void 0)}bindFramebufferWebGL(e){let t=this.eC,s=this.iC;if(t!=null&&t.isWebXRMode&&e.isOutputForVr){let r=this.rC.currentWebGLContextWrapper.getRawContext();r.bindFramebuffer(r.FRAMEBUFFER,t.framebuffer)}else if(s!=null&&s.isWebARMode){let r=this.rC.currentWebGLContextWrapper.getRawContext();r.bindFramebuffer(r.FRAMEBUFFER,s.framebuffer)}else this.rC.bindFramebuffer(e.getFramebuffer()),this.rC.setDrawTargets(e)}jC(){console.log(`%cRhodonite%cWeb3D Library%c %cversion%c${B.version}%c %cbranch%c${B.branch}%c %cmode%c${this.tC.str}`,"font-weight: bold; padding: 4px 8px; border-radius: 6px 0px 0px 6px; background: linear-gradient(to right, #ff0084 0%,#ff0022 100%);","padding: 4px; border-radius: 0px 6px 6px 0px; background: linear-gradient(to right, #8400ff 0%,#4400ff 100%);","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: firebrick; padding: 4px; border-radius: 0px 6px 6px 0px","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: green; padding: 4px; border-radius: 0px 6px 6px 0px","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: blue; padding: 4px; border-radius: 0px 6px 6px 0px")}static JC(){y._ensureComponentClassRegistered(_),y._ensureComponentClassRegistered(S),y._ensureComponentClassRegistered(j),y._ensureComponentClassRegistered(P),y._ensureComponentClassRegistered(G),y._ensureComponentClassRegistered(E),y._ensureComponentClassRegistered(J)}static async init(e){var n,p,a,o,l;if(e.approach!==d.None&&e.approach!==d.WebGL2&&e.approach!==d.WebGPU){let h=(p=(n=e.approach)==null?void 0:n.str)!=null?p:String(e.approach);throw new Error(`Unsupported process approach "${h}". The "Uniform" and "DataTexture" modes were removed. Use ProcessApproach.WebGL2 ("WebGL2") or ProcessApproach.WebGPU ("WebGPU").`)}if(e.approach===d.WebGL2&&typeof __RN_WEBGL__!="undefined"&&!__RN_WEBGL__)throw new Error("ProcessApproach.WebGL2 is unavailable: this build was bundled with __RN_WEBGL__ = false.");if(e.approach===d.WebGPU&&typeof __RN_WEBGPU__!="undefined"&&!__RN_WEBGPU__)throw new Error("ProcessApproach.WebGPU is unavailable: this build was bundled with __RN_WEBGPU__ = false.");m.JC();let t=((a=e.xr)!=null?a:m._loadXRByDefault)?await U.getInstance().loadModule("xr"):void 0,s=0,i;if(e.approach===d.WebGPU){let R=function(W){b.features.has(W)&&D.push(W)};var u=R;await U.getInstance().loadModule("webgpu");let h=O.getWebGpuResourceRepository(),g=U.getInstance().getModule("webgpu").WebGpuDeviceWrapper,b=await navigator.gpu.requestAdapter({xrCompatible:!0}),{maxBufferSize:C,maxStorageBufferBindingSize:x}=b.limits,D=[];R("float32-filterable"),R("rg11b10ufloat-renderable"),R("texture-compression-bc"),R("texture-compression-etc2"),R("texture-compression-astc"),R("timestamp-query");let v=await b.requestDevice({requiredFeatures:D,requiredLimits:{maxStorageBufferBindingSize:x,maxBufferSize:C}});s=x;let w=new g(e.canvas,b,v);h.addWebGpuDeviceWrapper(w),h.recreateSystemDepthTexture(),h.createBindGroupLayoutForDrawParameters(),i=h}else e.approach===d.WebGL2?(await U.getInstance().loadModule("webgl"),i=O.getWebGLResourceRepository(),i.generateWebGLContext((o=e.config)!=null?o:new X,e.canvas,!0,e.webglOption),i.switchDepthTest(!0),s=i.currentWebGLContextWrapper.getMaxTextureSize()**2*4*4):s=1024**2*4*4;let r=new m(e.approach,i,s,e.config,t);return r.oC.currentProcessApproach=e.approach,r.fC.eventTargetDom=(l=r.fC.eventTargetDom)!=null?l:e.canvas,e.approach===d.WebGPU&&(r.sC=i),e.approach===d.WebGL2&&(r.CC=i),r.rC=i,e.notToDisplayRnInfoAtInit!==!0&&r.jC(),r.yC.initialize(e.approach),e.canvas!=null&&e.approach===d.WebGL2&&(e.canvas.addEventListener("webglcontextlost",(h=>{h.preventDefault(),r.stopRenderLoop(),r.logger.error("WebGL context lost occurred.")}).bind(this)),e.canvas.addEventListener("webglcontextrestored",()=>{r.logger.error("WebGL context restored."),r.restartRenderLoop()})),r.hC=await ee.init(r),r.oC.viewportAspectRatio=e.canvas!=null?e.canvas.width/e.canvas.height:1,r}get processApproach(){return this.tC}resizeCanvas(e,t){this.cgApiResourceRepository.resizeCanvas(e,t),this.oC.viewportAspectRatio=e/t}getCanvasSize(){return this.cgApiResourceRepository.getCanvasSize()}getCurrentWebGLContextWrapper(){return this.rC.currentWebGLContextWrapper}get entityRepository(){return this.Na}get componentRepository(){return this.uC}get componentMemoryRegistry(){return this.GC}get webXRSystem(){if(this.eC==null)throw new Error(m.IC);return this.eC}get webARSystem(){if(this.iC==null)throw new Error(m.IC);return this.iC}get isXREnabled(){return this.eC!=null}get _webXRSystemIfEnabled(){return this.eC}get _webARSystemIfEnabled(){return this.iC}async enableXR(){if(this.eC==null){let e=await U.getInstance().loadModule("xr");this.eC==null&&this.SC(e)}return this.eC}SC(e){this.eC=e.WebXRSystem.init(this),this.iC=e.WebARSystem.init(this)}get memoryManager(){return this.of}get globalDataRepository(){return this.yC}_requestLightClusterSystem(){this.o||this.PC!=null||(this.PC=import("../renderer/lightCluster/LightClusterSystem.js").then(({LightClusterSystem:e})=>{this.o||(this.cC=new e(this),this.wC=!0)}).catch(e=>{N.default.warn(`Failed to load the light cluster system: ${e}`)}))}async _ensureLightClusterSystem(){return this._requestLightClusterSystem(),await this.PC,this.cC}get lightClusterSystem(){return this.cC}get materialRepository(){return this.EC}get webglResourceRepository(){return this.CC}get cgApiResourceRepository(){return this.rC}get webGpuResourceRepository(){return this.sC}get dummyTextures(){return this.hC}get engineState(){return this.oC}get config(){return this.fC}get _gpuInstanceDataVersion(){return this._C}_markGpuInstanceDataDirty(){this._C++}get _isPreviousMorphWeightsEnabled(){return this.LC}_enablePreviousMorphWeights(){this.LC=!0}get logger(){return this.xC}get shaderProgramCache(){return this.BC}};m._loadXRByDefault=!1,m.TC=new Map,m.UC=0,m.IC="The XR support is not enabled. Initialize the engine with Engine.init({ xr: true }) or call await engine.enableXR() first. The default Rn namespace export enables it automatically.";var z=m;export{z as Engine};
1
+ import{VERSION as B}from"../../version.js";import{CameraComponent as G}from"../components/Camera/CameraComponent.js";import{createCameraEntity as V}from"../components/Camera/createCameraEntity.js";import{LightComponent as E}from"../components/Light/LightComponent.js";import{MeshComponent as j}from"../components/Mesh/MeshComponent.js";import{MeshRendererComponent as P}from"../components/MeshRenderer/MeshRendererComponent.js";import{SceneGraphComponent as S}from"../components/SceneGraph/SceneGraphComponent.js";import{SkeletalComponent as J}from"../components/Skeletal/SkeletalComponent.js";import{TransformComponent as _}from"../components/Transform/TransformComponent.js";import{WellKnownComponentTIDs as k}from"../components/WellKnownComponentTIDs.js";import{Component as I}from"../core/Component.js";import{ComponentMemoryRegistry as H}from"../core/ComponentMemoryRegistry.js";import{ComponentRepository as y}from"../core/ComponentRepository.js";import{_getComponentRuntimeHooks as F}from"../core/ComponentRuntimeHooks.js";import{Config as X}from"../core/Config.js";import{EntityRepository as K}from"../core/EntityRepository.js";import{GlobalDataRepository as Q}from"../core/GlobalDataRepository.js";import{MemoryManager as Y}from"../core/MemoryManager.js";import{CameraType as Z}from"../definitions/CameraType.js";import{ProcessApproach as d}from"../definitions/ProcessApproach.js";import{ProcessStage as M}from"../definitions/ProcessStage.js";import{Primitive as A}from"../geometry/Primitive.js";import{DummyTextures as ee}from"../materials/core/DummyTextures.js";import{Vector3 as te}from"../math/Vector3.js";import{Vector4 as re}from"../math/Vector4.js";import{Is as L}from"../misc/Is.js";import{Logger as N}from"../misc/Logger.js";import{Time as T}from"../misc/Time.js";import{_getPhysicsBackend as se}from"../physics/PhysicsBackend.js";import{CGAPIResourceRepository as O}from"../renderer/CGAPIResourceRepository.js";import{Expression as ie}from"../renderer/Expression.js";import{Frame as oe}from"../renderer/Frame.js";import{LightClusterSystemStub as ne}from"../renderer/lightCluster/LightClusterSystemStub.js";import{RenderPass as $}from"../renderer/RenderPass.js";import{EngineState as ae}from"./EngineState.js";import{ModuleManager as U}from"./ModuleManager.js";import{WebGLGpuTimer as pe}from"../../webgl/WebGLGpuTimer.js";import{_cleanupWebGLStatesCacheForEngine as ue}from"../../webgl/WebGLStrategyCommonMethod.js";import{RnObject as ce}from"../core/RnObject.js";import{_cleanupGizmosForEngine as fe}from"../gizmos/GizmoRegistry.js";import{_cleanupRenderPassHelperForEngine as he}from"../helpers/RenderPassHelper.js";import{AbstractMaterialContent as de}from"../materials/core/AbstractMaterialContent.js";import{MaterialRepository as me}from"../materials/core/MaterialRepository.js";var m=class m extends ce{constructor(e,t,s,i,r){super();this.tC=d.None;this.oC=new ae;this.nC=0;this.pC=-1;this.WC=[];this.cC=new ne;this.wC=!1;this.o=!1;this.dC=-1;this.nr=-1;this.mC=-1;this.or=-1;this._C=0;this.LC=!1;this.BC=new Map;this.lC=!1;this.DC=-1;this.fC=i!=null?i:new X,this.xC=new N,this.xC.logLevel=this.fC.logLevel,this.DC=m.UC,this.tC=e,this.rC=t,this.GC=new H,this.uC=new y(this),this.Na=new K(this),this.EC=new me,this.of=Y.createInstanceIfNotCreated(this,s),r!=null&&this.SC(r),this.yC=Q.init(this),m.UC++}get engineUid(){return this.DC}static getEngine(e){let t=m.TC.get(e);if(!L.not.exist(t))return t}destroy(){this.stopRenderLoop(),this.RC=void 0,this.WC=[],this.Wb()}Wb(){var t,s;this.o=!0,this.EC._makeShaderInvalidateToAllMaterials();let e=this.Na._getEntities();for(let i of e)this.Na.deleteEntity(i.entityUID);if(L.exist(this.hC)&&(this.hC.destroy(),this.hC=void 0),L.exist(this.sC)){this.sC.clearCache();try{let i=this.sC.getWebGpuDeviceWrapper();i&&i.context.unconfigure()}catch{}}L.exist(this.of)&&(this.of.destroy(),this.of=void 0),this.XC(),_._cleanupForEngine(this),S._cleanupForEngine(this),G._cleanupForEngine(this),E._cleanupForEngine(this),P._cleanupForEngine(this),(t=se())==null||t.cleanupForEngine(this),fe(this),de._cleanupForEngine(this),he(this),ue(this),(s=this.aC)==null||s.destroy(),this.aC=void 0,this.GC.destroy(),this.gC=void 0,this.bC=void 0,this.nC=0,this.dC=-1,this.nr=-1,this.mC=-1,m.TC.delete(this.objectUID),this.unregister()}startRenderLoop(e,...t){this.RC=e,this.WC=t,this.pC!==-1&&this.stopRenderLoop();let s=this.FC();this.vC=s;let i=s.requestAnimationFrame.bind(s),r=this.eC,c=this.iC,u=t.length>0,n=u?[0,...t]:[],p=u?o=>{n[0]=o,e.apply(e,n)}:o=>{e.call(e,o)},a=((o,l)=>{r!=null&&r.isReadyForWebXR?(r._preRender(o,l),p(o),r._postRender()):c!=null&&c.isReadyForWebAR?(c._preRender(o,l),p(o),c._postRender()):p(o),this.pC=i(a)});this.pC=i(a)}FC(){let e=window,t=this.eC,s=this.iC;return t!=null&&t.requestedToEnterWebXR?e=t.xrSession:s!=null&&s.requestedToEnterWebAR&&(e=s.arSession),L.not.exist(e)?window:e}stopRenderLoop(){var t;let e=(t=this.vC)!=null?t:this.FC();this.pC!==-1&&e.cancelAnimationFrame(this.pC),this.pC=-1,this.vC=void 0}restartRenderLoop(){this.RC!=null&&this.startRenderLoop(this.RC,...this.WC)}processAuto(e=re.fromCopy4(0,0,0,1)){if(L.not.exist(this.gC)){let s=new ie,i=new $(this);i.toClearColorBuffer=!0,i.toClearDepthBuffer=!0,i.clearColor=e;let r=new $(this);s.addRenderPasses([i,r]),this.gC=s,this.bC=r}this.bC.clearEntities();let t=this.Na._getEntities();this.bC.addEntities(t),this.process([this.gC])}process(e){let t=this.lC;t&&this.NC(),T._processBegin(this),this.OC(),!this.wC&&E.getUpdateCount(this)>0&&this._requestLightClusterSystem();let s=e;e instanceof oe&&(s=e.expressions),G.getCurrent(this)===I.InvalidObjectUID&&m.createCamera(this);let i=this.yC.getValue("time",0);i._v[0]=T.timeFromSystemStart,this.processApproach===d.WebGPU?this._processWebGPU(s):this._processWebGL(s),T._processEnd(),t&&this.$C()}get gpuTimerEnabled(){return this.lC}set gpuTimerEnabled(e){this.lC=e}get isGpuTimerSupported(){var e,t;return this.tC===d.WebGPU?this.webGpuResourceRepository._getGpuTimer().isSupported:(t=(e=this.MC())==null?void 0:e.isSupported)!=null?t:!1}get gpuTimeMilliseconds(){var e,t;if(this.lC)return this.tC===d.WebGPU?(e=this.sC)==null?void 0:e._getGpuTimer().lastGpuTimeMilliseconds:(t=this.aC)==null?void 0:t.lastGpuTimeMilliseconds}get gpuPassTimesMilliseconds(){var e;if(!(!this.lC||this.tC!==d.WebGPU))return(e=this.sC)==null?void 0:e._getGpuTimer().lastPassGpuTimesMilliseconds}MC(){var e;if(this.aC==null){let t=(e=this.CC)==null?void 0:e.currentWebGLContextWrapper;if(t==null)return;this.aC=new pe(t.getRawContextAsWebGL2())}return this.aC}NC(){var e,t;this.tC===d.WebGPU?(e=this.sC)==null||e._getGpuTimer().beginFrame():(t=this.MC())==null||t.begin()}$C(){var e,t;this.tC===d.WebGPU?(e=this.sC)==null||e._getGpuTimer().endFrame():(t=this.aC)==null||t.end()}zC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,hasAnyEffekseerComponents:c,deferredEffekseerRenderJobs:u}){t.doPreRender();let n;if(c&&t.toRenderEffekseerEffects){n=[];let h=t.entities;for(let f=0;f<h.length;f++){let g=h[f].tryToGetEffekseer();g!=null&&n.push(g)}n.length===0&&(n=void 0)}let p=n!=null,a=p?e.getEffekseerRenderPassOptions(this,t,r):void 0,o=t.toRenderEffekseerEffects&&p,l=o&&t.getResolveFramebuffer()!=null&&u!=null;if(o&&a!=null)for(let h of n)h.prepareWebGPURendering(a);if(l&&u.push({renderPass:t,displayIdx:r,renderPassOptions:a,effekseerComponents:n}),e.clearFrameBuffer(this,t,r),this.qC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,shouldKeepRenderPassForEffekseer:o&&!l}),o&&!l){let h=e.getOrCreateRenderPassEncoderForEffekseerExternalRendering(this,t,r);if(h!=null)for(let f of n)f.$renderWebGPU(h,a,r);e.endRenderPassEncoderForExternalRendering()}return t._copyResolve1ToResolve2WebGpu(),t.doPostRender(),o}VC({webGpuResourceRepository:e,currentRenderPass:t,deferredEffekseerRenderJobs:s,displayIdx:i}){if(s.length===0)return;let r=t.getResolveFramebuffer();if(r!=null)for(let c of s){if(c.displayIdx!==i||c.renderPass.getResolveFramebuffer()!==r)continue;let u=e.getOrCreateRenderPassEncoderForEffekseerExternalRendering(this,c.renderPass,i);if(u!=null)for(let n of c.effekseerComponents)n.$renderWebGPU(u,c.renderPassOptions,i);e.endRenderPassEncoderForExternalRendering(),c.renderPass._copyResolve1ToResolve2WebGpu()}}qC({webGpuResourceRepository:e,renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,shouldKeepRenderPassForEffekseer:c}){var a;let u,n=t._renderedSomethingBefore;if(n&&(c?(u=e.renderWithRenderBundleAndKeepRenderPass(this,t,r),n=u==null):n=!e.renderWithRenderBundle(this,t,r),(a=this.oC).webgpuRenderBundleMode||(a.webgpuRenderBundleMode=n)),!n)return u;e.createRenderBundleEncoder(this,t,r);let p=P.common_$render({renderPass:t,renderPassTickCount:s,primitiveUids:i,displayIdx:r,engine:this});if(t._renderedSomethingBefore=p,!p)return u;if(c)return e.finishRenderBundleEncoderAndKeepRenderPass(this,t,r);e.finishRenderBundleEncoder(this,t,r)}_processWebGPU(e){var r,c;let t=this.uC.getComponentTIDs(),s=this.webGpuResourceRepository,i=this.eC;for(let u of I._processStages){if(u===M.Render){this.cC.update(e),P.common_$prerender(this);let n=(r=i==null?void 0:i.isWebXRMode)!=null?r:!1,p=(c=i==null?void 0:i.isMultiView())!=null?c:!1,a=this.oC.xrPoseWebGPU,o=n&&!p&&a!=null?a.views.length:1,l=this.uC.hasAnyComponent(k.EffekseerComponentTID),h=o>1,f=h?new Map:void 0,g=h?new Map:void 0;for(let b=0;b<o;b++){let C=l?[]:void 0,x=!1;for(let D of e)for(let R of D.renderPasses){let v=R.renderPassUID,w=f==null?void 0:f.get(v),W;w===void 0?(w=this.nC,R._isChangedSortRenderResult=!1,W=P.sort_$render(this,R),f!=null&&(f.set(v,w),g.set(v,W))):W=g.get(v);let q=this.zC({webGpuResourceRepository:s,renderPass:R,renderPassTickCount:w,primitiveUids:W,displayIdx:b,hasAnyEffekseerComponents:l,deferredEffekseerRenderJobs:C});x||(x=q),C!=null&&C.length>0&&this.VC({webGpuResourceRepository:s,currentRenderPass:R,deferredEffekseerRenderJobs:C,displayIdx:b}),b===o-1&&(f==null||f.delete(v),g==null||g.delete(v),this.nC++)}b<o-1&&x&&s.flush()}s.flush()}else if(!this.oC.webgpuRenderBundleMode||this.AC()||_.getUpdateCount(this)!==this.nr||G.getCurrentCameraUpdateCount(this)!==this.dC||A.getPrimitiveCount()!==this.mC||E.getUpdateCount(this)!==this.or){let n=`common_${u.methodName}`;for(let p of t){let a=y.getComponentClass(p),o=a[n];o&&o({processApproach:this.tC,renderPass:void 0,processStage:u,renderPassTickCount:this.nC,displayIdx:0,engine:this}),a.process(this,a,u)}}u===M.Logic&&S._updateTransformGizmosByCameraChange(this)}this.dC=G.getCurrentCameraUpdateCount(this),this.kC(),this.nr=_.getUpdateCount(this),this.mC=A.getPrimitiveCount(),this.or=E.getUpdateCount(this)}OC(){var e;for(let t of F())(e=t.beginFrame)==null||e.call(t,this)}AC(){var e;for(let t of F())if(((e=t.isDirty)==null?void 0:e.call(t,this))===!0)return!0;return!1}kC(){var e;for(let t of F())(e=t.markUpdated)==null||e.call(t,this)}XC(){var e;for(let t of F())(e=t.cleanup)==null||e.call(t,this)}_processWebGL(e){let t=this.webglResourceRepository,s=this.uC.getComponentTIDs(),i=this.uC.getRenderingComponentTIDs();for(let r of I._processStages){let u=`common_${r.methodName}`;if(r===M.Render){t.getMultiDrawRepository(this).rebuildDirtyGroups(),this.cC.update(e),P.common_$prerender(this);for(let n of e)for(let p of i){let a=y.getComponentClass(p);for(let o of n.renderPasses){typeof spector!="undefined"&&spector.setMarker(`| ${n.uniqueName}: ${o.uniqueName}#`),o.doPreRender(),t.switchDepthTest(o.isDepthTest),this.bindFramebufferWebGL(o),this.setViewportForNormalRendering(o),this.setScissorForNormalRendering(o),p===k.MeshRendererComponentTID&&this.rC.clearFrameBuffer(this,o),o._isChangedSortRenderResult=!1;let l=P.sort_$render(this,o);if(o._renderedSomethingBefore){let f=a[u];if(f){let g=f({processApproach:this.tC,renderPass:o,processStage:r,renderPassTickCount:this.nC,primitiveUids:l,displayIdx:0,engine:this});o._renderedSomethingBefore=g}}if(p===k.EffekseerComponentTID&&o.entities.length>0){let f=this.webglResourceRepository,g=f.getCurrentTexture2DBindingsForEffekseer();f.setWebGLStateToDefaultForEffekseer();for(let b of o.entities){let C=b.tryToGetEffekseer();C!=null&&C.$render()}f.restoreTexture2DBindingsForEffekseer(g)}this.nC++,o._copyFramebufferToResolveFramebuffersWebGL(),o.doPostRender()}}}else if(this.AC()||_.getUpdateCount(this)!==this.nr||G.getCurrentCameraUpdateCount(this)!==this.dC||A.getPrimitiveCount()!==this.mC||E.getUpdateCount(this)!==this.or)for(let n of s){let p=y.getComponentClass(n),a=p[u];a&&a({processApproach:this.tC,renderPass:void 0,processStage:r,renderPassTickCount:this.nC,displayIdx:0,engine:this}),p.process(this,p,r)}r===M.Logic&&S._updateTransformGizmosByCameraChange(this)}this.dC=G.getCurrentCameraUpdateCount(this),this.kC(),this.nr=_.getUpdateCount(this),this.mC=A.getPrimitiveCount(),this.or=E.getUpdateCount(this)}static get processTime(){return T.lastTimeTimeIntervalInMilliseconds}static get timeAtProcessBegin(){return T.timeAtProcessBeginMilliseconds}static get timeAtProcessEnd(){return T.timeAtProcessEndMilliseconds}static createCamera(e){let t=V(e,!0);t.getTransform().localPosition=te.fromCopyArray([0,0,1]),t.getCamera().type=Z.Orthographic,t.getCamera().zNear=.1,t.getCamera().zFar=1e4;let s=e.cgApiResourceRepository,[i,r]=s.getCanvasSize();t.getCamera().xMag=i/r,t.getCamera().yMag=1}setViewportForNormalRendering(e){let t=this.eC,s=this.iC;(!(t!=null&&t.isWebXRMode)||!e.isVrRendering)&&!(s!=null&&s.isWebARMode)&&this.rC.setViewport(this,e.getViewport())}setScissorForNormalRendering(e){let t=this.eC,s=this.iC,i=this.rC;(!(t!=null&&t.isWebXRMode)||!e.isVrRendering)&&!(s!=null&&s.isWebARMode)?i.setScissorRect(e):i.setScissorRect(void 0)}bindFramebufferWebGL(e){let t=this.eC,s=this.iC;if(t!=null&&t.isWebXRMode&&e.isOutputForVr){let r=this.rC.currentWebGLContextWrapper.getRawContext();r.bindFramebuffer(r.FRAMEBUFFER,t.framebuffer)}else if(s!=null&&s.isWebARMode){let r=this.rC.currentWebGLContextWrapper.getRawContext();r.bindFramebuffer(r.FRAMEBUFFER,s.framebuffer)}else this.rC.bindFramebuffer(e.getFramebuffer()),this.rC.setDrawTargets(e)}jC(){console.log(`%cRhodonite%cWeb3D Library%c %cversion%c${B.version}%c %cbranch%c${B.branch}%c %cmode%c${this.tC.str}`,"font-weight: bold; padding: 4px 8px; border-radius: 6px 0px 0px 6px; background: linear-gradient(to right, #ff0084 0%,#ff0022 100%);","padding: 4px; border-radius: 0px 6px 6px 0px; background: linear-gradient(to right, #8400ff 0%,#4400ff 100%);","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: firebrick; padding: 4px; border-radius: 0px 6px 6px 0px","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: green; padding: 4px; border-radius: 0px 6px 6px 0px","","background: #666; padding: 4px; border-radius: 6px 0px 0px 6px","background: blue; padding: 4px; border-radius: 0px 6px 6px 0px")}static JC(){y._ensureComponentClassRegistered(_),y._ensureComponentClassRegistered(S),y._ensureComponentClassRegistered(j),y._ensureComponentClassRegistered(P),y._ensureComponentClassRegistered(G),y._ensureComponentClassRegistered(E),y._ensureComponentClassRegistered(J)}static async init(e){var n,p,a,o,l;if(e.approach!==d.None&&e.approach!==d.WebGL2&&e.approach!==d.WebGPU){let h=(p=(n=e.approach)==null?void 0:n.str)!=null?p:String(e.approach);throw new Error(`Unsupported process approach "${h}". The "Uniform" and "DataTexture" modes were removed. Use ProcessApproach.WebGL2 ("WebGL2") or ProcessApproach.WebGPU ("WebGPU").`)}if(e.approach===d.WebGL2&&typeof __RN_WEBGL__!="undefined"&&!__RN_WEBGL__)throw new Error("ProcessApproach.WebGL2 is unavailable: this build was bundled with __RN_WEBGL__ = false.");if(e.approach===d.WebGPU&&typeof __RN_WEBGPU__!="undefined"&&!__RN_WEBGPU__)throw new Error("ProcessApproach.WebGPU is unavailable: this build was bundled with __RN_WEBGPU__ = false.");m.JC();let t=((a=e.xr)!=null?a:m._loadXRByDefault)?await U.getInstance().loadModule("xr"):void 0,s=0,i;if(e.approach===d.WebGPU){let R=function(W){b.features.has(W)&&D.push(W)};var u=R;await U.getInstance().loadModule("webgpu");let h=O.getWebGpuResourceRepository(),g=U.getInstance().getModule("webgpu").WebGpuDeviceWrapper,b=await navigator.gpu.requestAdapter({xrCompatible:!0}),{maxBufferSize:C,maxStorageBufferBindingSize:x}=b.limits,D=[];R("float32-filterable"),R("rg11b10ufloat-renderable"),R("texture-compression-bc"),R("texture-compression-etc2"),R("texture-compression-astc"),R("timestamp-query");let v=await b.requestDevice({requiredFeatures:D,requiredLimits:{maxStorageBufferBindingSize:x,maxBufferSize:C}});s=x;let w=new g(e.canvas,b,v);h.addWebGpuDeviceWrapper(w),h.recreateSystemDepthTexture(),h.createBindGroupLayoutForDrawParameters(),i=h}else e.approach===d.WebGL2?(await U.getInstance().loadModule("webgl"),i=O.getWebGLResourceRepository(),i.generateWebGLContext((o=e.config)!=null?o:new X,e.canvas,!0,e.webglOption),i.switchDepthTest(!0),s=i.currentWebGLContextWrapper.getMaxTextureSize()**2*4*4):s=1024**2*4*4;let r=new m(e.approach,i,s,e.config,t);return r.oC.currentProcessApproach=e.approach,r.fC.eventTargetDom=(l=r.fC.eventTargetDom)!=null?l:e.canvas,e.approach===d.WebGPU&&(r.sC=i),e.approach===d.WebGL2&&(r.CC=i),r.rC=i,e.notToDisplayRnInfoAtInit!==!0&&r.jC(),r.yC.initialize(e.approach),e.canvas!=null&&e.approach===d.WebGL2&&(e.canvas.addEventListener("webglcontextlost",(h=>{h.preventDefault(),r.stopRenderLoop(),r.logger.error("WebGL context lost occurred.")}).bind(this)),e.canvas.addEventListener("webglcontextrestored",()=>{r.logger.error("WebGL context restored."),r.restartRenderLoop()})),r.hC=await ee.init(r),r.oC.viewportAspectRatio=e.canvas!=null?e.canvas.width/e.canvas.height:1,r}get processApproach(){return this.tC}resizeCanvas(e,t){this.cgApiResourceRepository.resizeCanvas(e,t),this.oC.viewportAspectRatio=e/t}getCanvasSize(){return this.cgApiResourceRepository.getCanvasSize()}getCurrentWebGLContextWrapper(){return this.rC.currentWebGLContextWrapper}get entityRepository(){return this.Na}get componentRepository(){return this.uC}get componentMemoryRegistry(){return this.GC}get webXRSystem(){if(this.eC==null)throw new Error(m.IC);return this.eC}get webARSystem(){if(this.iC==null)throw new Error(m.IC);return this.iC}get isXREnabled(){return this.eC!=null}get _webXRSystemIfEnabled(){return this.eC}get _webARSystemIfEnabled(){return this.iC}async enableXR(){if(this.eC==null){let e=await U.getInstance().loadModule("xr");this.eC==null&&this.SC(e)}return this.eC}SC(e){this.eC=e.WebXRSystem.init(this),this.iC=e.WebARSystem.init(this)}get memoryManager(){return this.of}get globalDataRepository(){return this.yC}_requestLightClusterSystem(){this.o||this.PC!=null||(this.PC=import("../renderer/lightCluster/LightClusterSystem.js").then(({LightClusterSystem:e})=>{this.o||(this.cC=new e(this),this.wC=!0)}).catch(e=>{N.default.warn(`Failed to load the light cluster system: ${e}`)}))}async _ensureLightClusterSystem(){return this._requestLightClusterSystem(),await this.PC,this.cC}get lightClusterSystem(){return this.cC}get materialRepository(){return this.EC}get webglResourceRepository(){return this.CC}get cgApiResourceRepository(){return this.rC}get webGpuResourceRepository(){return this.sC}get dummyTextures(){return this.hC}get engineState(){return this.oC}get config(){return this.fC}get _gpuInstanceDataVersion(){return this._C}_markGpuInstanceDataDirty(){this._C++}get _isPreviousMorphWeightsEnabled(){return this.LC}_enablePreviousMorphWeights(){this.LC=!0}get logger(){return this.xC}get shaderProgramCache(){return this.BC}};m._loadXRByDefault=!1,m.TC=new Map,m.UC=0,m.IC="The XR support is not enabled. Initialize the engine with Engine.init({ xr: true }) or call await engine.enableXR() first. The default Rn namespace export enables it automatically.";var z=m;export{z as Engine};
@@ -26,6 +26,12 @@ import { AbstractTexture } from './AbstractTexture';
26
26
  export declare class CubeTexture extends AbstractTexture implements Disposable {
27
27
  /** The number of mipmap levels for this cube texture */
28
28
  mipmapLevelNumber: number;
29
+ /**
30
+ * The number of lowest specular IBL mip levels the runtime does not sample.
31
+ * The default is 0 (sample the whole chain), which keeps the behavior of applications that predate the
32
+ * mip-skip technique. Assets baked with scripts/prefilter-ibl.mjs set this to 4 (or 1 for compact output).
33
+ */
34
+ iblMipLevelSkip: number;
29
35
  /** The HDRI format used for this cube texture */
30
36
  hdriFormat: import("..").EnumIO;
31
37
  /**
@@ -63,11 +69,12 @@ export declare class CubeTexture extends AbstractTexture implements Disposable {
63
69
  * });
64
70
  * ```
65
71
  */
66
- loadTextureImages({ baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, }: {
72
+ loadTextureImages({ baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, iblMipLevelSkip, }: {
67
73
  baseUrl: string;
68
74
  mipmapLevelNumber: number;
69
75
  isNamePosNeg: boolean;
70
76
  hdriFormat: HdriFormatEnum;
77
+ iblMipLevelSkip?: number;
71
78
  }): Promise<void>;
72
79
  /**
73
80
  * Loads cube texture from Basis compressed texture data.
@@ -240,6 +247,7 @@ export declare class CubeTexture extends AbstractTexture implements Disposable {
240
247
  * @param options.mipmapLevelNumber - Number of mipmap levels to generate
241
248
  * @param options.isNamePosNeg - Whether to use positive/negative naming convention
242
249
  * @param options.hdriFormat - The HDRI format to use for the texture
250
+ * @param options.iblMipLevelSkip - Lowest specular IBL mip levels not sampled (default 0; set 4 for mip-skip bakes)
243
251
  * @returns Promise that resolves to a loaded CubeTexture instance
244
252
  *
245
253
  * @example
@@ -252,10 +260,11 @@ export declare class CubeTexture extends AbstractTexture implements Disposable {
252
260
  * });
253
261
  * ```
254
262
  */
255
- static loadFromUrl(engine: Engine, { baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, }: {
263
+ static loadFromUrl(engine: Engine, { baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, iblMipLevelSkip, }: {
256
264
  baseUrl: string;
257
265
  mipmapLevelNumber: number;
258
266
  isNamePosNeg: boolean;
259
267
  hdriFormat: HdriFormatEnum;
268
+ iblMipLevelSkip?: number;
260
269
  }): Promise<CubeTexture>;
261
270
  }
@@ -1 +1 @@
1
- import{HdriFormat as x}from"../definitions/HdriFormat.js";import{ProcessApproach as m}from"../definitions/ProcessApproach.js";import{TextureParameter as p}from"../definitions/TextureParameter.js";import{Logger as n}from"../misc/Logger.js";import{CGAPIResourceRepository as d}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as A}from"./AbstractTexture.js";var u=class u extends A{constructor(){super(...arguments);this.mipmapLevelNumber=1;this.hdriFormat=x.LDR_SRGB}uA(e,t){this._textureResourceUid=e,u.managedRegistry.register(this,{textureResourceUid:e,engine:this.i,uniqueName:t},this)}async loadTextureImages({baseUrl:e,mipmapLevelNumber:t,isNamePosNeg:r,hdriFormat:i}){this.mI=!0,this.mipmapLevelNumber=t,this.hdriFormat=i;let s=this.i.cgApiResourceRepository,[o,c,l,a]=await s.createCubeTextureFromFiles(this.i,e,t,r,i);this.uA(o,this.uniqueName),this._recommendedTextureSampler=c,this._samplerResourceUid=c._samplerResourceUid,this.sm=l,this.TT=a,this.i.engineState.currentProcessApproach===m.WebGPU&&(this._textureViewResourceUid=s.createTextureViewCube(this._textureResourceUid)),this.aI=!0}loadTextureImagesFromBasis(e,{magFilter:t=p.Linear,minFilter:r=p.LinearMipmapLinear,wrapS:i=p.Repeat,wrapT:s=p.Repeat}={}){this.mI=!0,typeof BASIS=="undefined"&&n.default.error("Failed to call BASIS() function. Please check to import basis_transcoder.js."),BASIS().then(o=>{let{initializeBasis:c}=o;c();let l=o.BasisFile,a=new l(e);if(!a.startTranscoding()){n.default.error("failed to start transcoding."),a.close(),a.delete();return}let g=this.i.webglResourceRepository,{resourceHandle:y,width:R,height:b}=g.createCubeTextureFromBasis(a,{magFilter:t,minFilter:r,wrapS:i,wrapT:s});this.uA(y,this.uniqueName),this.sm=R,this.TT=b,this.aI=!0,a.close(),a.delete()})}load1x1Texture(e="rgba(0,0,0,1)"){let t=document.createElement("canvas");t.width=1,t.height=1;let r=t.getContext("2d");if(r==null){n.default.error("Failed to get canvas context.");return}r.fillStyle=e,r.fillRect(0,0,1,1);let i=this.i.cgApiResourceRepository,[s,o]=i.createCubeTexture(this.i,1,[{posX:t,negX:t,posY:t,negY:t,posZ:t,negZ:t}],1,1);this.uA(s,this.uniqueName),this._recommendedTextureSampler=o,this._samplerResourceUid=o._samplerResourceUid,this.sm=1,this.TT=1,this.i.engineState.currentProcessApproach===m.WebGPU&&(this._textureViewResourceUid=i.createTextureViewCube(this._textureResourceUid)),this.aI=!0}generateTextureFromTypedArrays(e,t,r){let i=this.i.webglResourceRepository,[s,o]=i.createCubeTexture(this.i,e.length,e,t,r);this._recommendedTextureSampler=o,this.uA(s,this.uniqueName),this.sm=t,this.TT=r,this.aI=!0,this.mI=!0}importWebGLTextureDirectly(e,t=0,r=0){this.sm=t,this.TT=r;let s=this.i.webglResourceRepository.setWebGLTextureDirectly(e);this.uA(s,this.uniqueName),this.mI=!0,this.aI=!0}static cA(e,t){e.cgApiResourceRepository.deleteTexture(t)}destroy3DAPIResources(){u.cA(this.i,this._textureResourceUid),this._textureResourceUid=d.InvalidCGAPIResourceUid,this._samplerResourceUid=d.InvalidCGAPIResourceUid,this._recommendedTextureSampler&&this._recommendedTextureSampler.destroy(),this.aI=!1,this.mI=!1}[Symbol.dispose](){n.default.debug("[Symbol.dispose] is called"),this.destroy()}async getCubeFacePixelData(e){if(e<0||e>5)throw new Error(`Invalid face index: ${e}. Must be between 0 and 5.`);return await this.i.cgApiResourceRepository.getCubeTexturePixelData(this._textureResourceUid,this.sm,this.TT,e)}async getAllCubeFacePixelData(){let[e,t,r,i,s,o]=await Promise.all([this.getCubeFacePixelData(0),this.getCubeFacePixelData(1),this.getCubeFacePixelData(2),this.getCubeFacePixelData(3),this.getCubeFacePixelData(4),this.getCubeFacePixelData(5)]);return{posX:e,negX:t,posY:r,negY:i,posZ:s,negZ:o}}destroy(){this.destroy3DAPIResources(),this.unregister(),u.managedRegistry.unregister(this)}static async loadFromUrl(e,{baseUrl:t,mipmapLevelNumber:r,isNamePosNeg:i,hdriFormat:s}){let o=new u(e);return await o.loadTextureImages({baseUrl:t,mipmapLevelNumber:r,isNamePosNeg:i,hdriFormat:s}),o}};u.managedRegistry=new FinalizationRegistry(e=>{n.default.info(`WebGL/WebGPU cube texture "${e.uniqueName}" was automatically released along with GC. But explicit release is recommended.`),u.cA(e.engine,e.textureResourceUid)});var h=u;export{h as CubeTexture};
1
+ import{HdriFormat as x}from"../definitions/HdriFormat.js";import{ProcessApproach as d}from"../definitions/ProcessApproach.js";import{TextureParameter as l}from"../definitions/TextureParameter.js";import{Logger as c}from"../misc/Logger.js";import{CGAPIResourceRepository as h}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as A}from"./AbstractTexture.js";var u=class u extends A{constructor(){super(...arguments);this.mipmapLevelNumber=1;this.iblMipLevelSkip=0;this.hdriFormat=x.LDR_SRGB}uA(e,t){this._textureResourceUid=e,u.managedRegistry.register(this,{textureResourceUid:e,engine:this.i,uniqueName:t},this)}async loadTextureImages({baseUrl:e,mipmapLevelNumber:t,isNamePosNeg:r,hdriFormat:i,iblMipLevelSkip:o=0}){this.mI=!0,this.mipmapLevelNumber=t,this.hdriFormat=i,this.iblMipLevelSkip=o;let s=this.i.cgApiResourceRepository,[n,p,a,m]=await s.createCubeTextureFromFiles(this.i,e,t,r,i);this.uA(n,this.uniqueName),this._recommendedTextureSampler=p,this._samplerResourceUid=p._samplerResourceUid,this.sm=a,this.TT=m,this.i.engineState.currentProcessApproach===d.WebGPU&&(this._textureViewResourceUid=s.createTextureViewCube(this._textureResourceUid)),this.aI=!0}loadTextureImagesFromBasis(e,{magFilter:t=l.Linear,minFilter:r=l.LinearMipmapLinear,wrapS:i=l.Repeat,wrapT:o=l.Repeat}={}){this.mI=!0,typeof BASIS=="undefined"&&c.default.error("Failed to call BASIS() function. Please check to import basis_transcoder.js."),BASIS().then(s=>{let{initializeBasis:n}=s;n();let p=s.BasisFile,a=new p(e);if(!a.startTranscoding()){c.default.error("failed to start transcoding."),a.close(),a.delete();return}let m=this.i.webglResourceRepository,{resourceHandle:y,width:R,height:b}=m.createCubeTextureFromBasis(a,{magFilter:t,minFilter:r,wrapS:i,wrapT:o});this.uA(y,this.uniqueName),this.sm=R,this.TT=b,this.aI=!0,a.close(),a.delete()})}load1x1Texture(e="rgba(0,0,0,1)"){let t=document.createElement("canvas");t.width=1,t.height=1;let r=t.getContext("2d");if(r==null){c.default.error("Failed to get canvas context.");return}r.fillStyle=e,r.fillRect(0,0,1,1);let i=this.i.cgApiResourceRepository,[o,s]=i.createCubeTexture(this.i,1,[{posX:t,negX:t,posY:t,negY:t,posZ:t,negZ:t}],1,1);this.uA(o,this.uniqueName),this._recommendedTextureSampler=s,this._samplerResourceUid=s._samplerResourceUid,this.sm=1,this.TT=1,this.i.engineState.currentProcessApproach===d.WebGPU&&(this._textureViewResourceUid=i.createTextureViewCube(this._textureResourceUid)),this.aI=!0}generateTextureFromTypedArrays(e,t,r){let i=this.i.webglResourceRepository,[o,s]=i.createCubeTexture(this.i,e.length,e,t,r);this._recommendedTextureSampler=s,this.uA(o,this.uniqueName),this.sm=t,this.TT=r,this.aI=!0,this.mI=!0}importWebGLTextureDirectly(e,t=0,r=0){this.sm=t,this.TT=r;let o=this.i.webglResourceRepository.setWebGLTextureDirectly(e);this.uA(o,this.uniqueName),this.mI=!0,this.aI=!0}static cA(e,t){e.cgApiResourceRepository.deleteTexture(t)}destroy3DAPIResources(){u.cA(this.i,this._textureResourceUid),this._textureResourceUid=h.InvalidCGAPIResourceUid,this._samplerResourceUid=h.InvalidCGAPIResourceUid,this._recommendedTextureSampler&&this._recommendedTextureSampler.destroy(),this.aI=!1,this.mI=!1}[Symbol.dispose](){c.default.debug("[Symbol.dispose] is called"),this.destroy()}async getCubeFacePixelData(e){if(e<0||e>5)throw new Error(`Invalid face index: ${e}. Must be between 0 and 5.`);return await this.i.cgApiResourceRepository.getCubeTexturePixelData(this._textureResourceUid,this.sm,this.TT,e)}async getAllCubeFacePixelData(){let[e,t,r,i,o,s]=await Promise.all([this.getCubeFacePixelData(0),this.getCubeFacePixelData(1),this.getCubeFacePixelData(2),this.getCubeFacePixelData(3),this.getCubeFacePixelData(4),this.getCubeFacePixelData(5)]);return{posX:e,negX:t,posY:r,negY:i,posZ:o,negZ:s}}destroy(){this.destroy3DAPIResources(),this.unregister(),u.managedRegistry.unregister(this)}static async loadFromUrl(e,{baseUrl:t,mipmapLevelNumber:r,isNamePosNeg:i,hdriFormat:o,iblMipLevelSkip:s=0}){let n=new u(e);return await n.loadTextureImages({baseUrl:t,mipmapLevelNumber:r,isNamePosNeg:i,hdriFormat:o,iblMipLevelSkip:s}),n}};u.managedRegistry=new FinalizationRegistry(e=>{c.default.info(`WebGL/WebGPU cube texture "${e.uniqueName}" was automatically released along with GC. But explicit release is recommended.`),u.cA(e.engine,e.textureResourceUid)});var g=u;export{g as CubeTexture};
@@ -1 +1 @@
1
- import{ComponentType as h}from"../definitions/ComponentType.js";import{PixelFormat as p}from"../definitions/PixelFormat.js";import{ProcessApproach as c}from"../definitions/ProcessApproach.js";import{TextureFormat as d}from"../definitions/TextureFormat.js";import{Vector4 as R}from"../math/Vector4.js";import{CGAPIResourceRepository as m}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as y}from"./AbstractTexture.js";var n=class extends y{constructor(){super(...arguments);this.Ib=0}create({width:e,height:t,level:i=0,internalFormat:r=d.RGB8,format:s=p.RGBA,type:a=h.UnsignedByte,arrayLength:o}){this.sm=e,this.TT=t,this.pI=i,this.cI=r,this.dI=s,this.Qe=a,this.Ib=o,this.yA()}set _fbo(e){this.RA=e}get fbo(){return this.RA}get arrayLength(){return this.Ib}yA(){let e=this.i.cgApiResourceRepository,t=e.createRenderTargetTextureArray({width:this.sm,height:this.TT,level:this.pI,internalFormat:this.cI,format:this.dI,type:this.Qe,arrayLength:this.Ib});this._textureResourceUid=t,this.i.engineState.currentProcessApproach===c.WebGPU&&(this._textureViewResourceUid=e.createTextureView2dArray(this._textureResourceUid,this.Ib),this._textureViewAsRenderTargetResourceUid=e.createTextureView2dArrayAsRenderTarget(this._textureResourceUid,0,0))}changeRenderTargetLayerWebGPU(e){if(this.i.engineState.currentProcessApproach===c.WebGPU){let t=this.i.cgApiResourceRepository;this._textureViewAsRenderTargetResourceUid=t.createTextureView2dArrayAsRenderTarget(this._textureResourceUid,e,0)}}resize(e,t){this.destroy3DAPIResources(),this.sm=e,this.TT=t,this.yA()}destroy3DAPIResources(){return this.i.cgApiResourceRepository.deleteTexture(this._textureResourceUid),this._textureResourceUid=m.InvalidCGAPIResourceUid,!0}async getTexturePixelData(){return this.i.cgApiResourceRepository.getTexturePixelData(this._textureResourceUid,this.sm,this.TT,this.RA.framebufferUID,this.RA.whichColorAttachment(this))}async downloadTexturePixelData(){let e=await this.getTexturePixelData(),t=document.createElement("canvas");t.width=this.sm,t.height=this.TT;let i=t.getContext("2d");if(!(e.buffer instanceof ArrayBuffer))throw new Error("SharedArrayBuffer is not supported when downloading texture pixel data.");let r=new Uint8ClampedArray(e.buffer,e.byteOffset,e.byteLength/Uint8ClampedArray.BYTES_PER_ELEMENT),s=new ImageData(r,this.sm,this.TT);i.putImageData(s,this.sm,this.TT);let a=t.toDataURL("image/png"),o=document.createElement("a"),u=document.createEvent("MouseEvent");o.href=a,o.download="texture.png",u.initEvent("click",!0,!0),o.dispatchEvent(u)}async getPixelValueAt(e,t,i){let r=i;return r||(r=await this.getTexturePixelData()),R.fromCopyArray([r[(t*this.width+e)*4+0],r[(t*this.width+e)*4+1],r[(t*this.width+e)*4+2],r[(t*this.width+e)*4+3]])}generateMipmaps(){this.i.cgApiResourceRepository.generateMipmaps2d(this._textureResourceUid,this.width,this.height)}blitToTexture2dFromTexture2dArray(e){if(this.Ib===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArray(this._textureResourceUid,e.RA.cgApiResourceUid,e.width,e.height)}blitToTexture2dFromTexture2dArrayFake(e){if(this.Ib===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArrayFake(this._textureResourceUid,e.RA.cgApiResourceUid,e.width,e.height)}blitToTexture2dFromTexture2dArray2(e){if(this.Ib===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArray2(this._textureResourceUid,e._textureResourceUid,e.width/2,e.height)}createCubeTextureViewAsRenderTarget(e,t){}};export{n as RenderTargetTexture2DArray};
1
+ import{ComponentType as h}from"../definitions/ComponentType.js";import{PixelFormat as p}from"../definitions/PixelFormat.js";import{ProcessApproach as c}from"../definitions/ProcessApproach.js";import{TextureFormat as d}from"../definitions/TextureFormat.js";import{Vector4 as R}from"../math/Vector4.js";import{CGAPIResourceRepository as m}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as y}from"./AbstractTexture.js";var n=class extends y{constructor(){super(...arguments);this.Bb=0}create({width:e,height:t,level:i=0,internalFormat:r=d.RGB8,format:s=p.RGBA,type:a=h.UnsignedByte,arrayLength:o}){this.sm=e,this.TT=t,this.pI=i,this.cI=r,this.dI=s,this.Qe=a,this.Bb=o,this.yA()}set _fbo(e){this.RA=e}get fbo(){return this.RA}get arrayLength(){return this.Bb}yA(){let e=this.i.cgApiResourceRepository,t=e.createRenderTargetTextureArray({width:this.sm,height:this.TT,level:this.pI,internalFormat:this.cI,format:this.dI,type:this.Qe,arrayLength:this.Bb});this._textureResourceUid=t,this.i.engineState.currentProcessApproach===c.WebGPU&&(this._textureViewResourceUid=e.createTextureView2dArray(this._textureResourceUid,this.Bb),this._textureViewAsRenderTargetResourceUid=e.createTextureView2dArrayAsRenderTarget(this._textureResourceUid,0,0))}changeRenderTargetLayerWebGPU(e){if(this.i.engineState.currentProcessApproach===c.WebGPU){let t=this.i.cgApiResourceRepository;this._textureViewAsRenderTargetResourceUid=t.createTextureView2dArrayAsRenderTarget(this._textureResourceUid,e,0)}}resize(e,t){this.destroy3DAPIResources(),this.sm=e,this.TT=t,this.yA()}destroy3DAPIResources(){return this.i.cgApiResourceRepository.deleteTexture(this._textureResourceUid),this._textureResourceUid=m.InvalidCGAPIResourceUid,!0}async getTexturePixelData(){return this.i.cgApiResourceRepository.getTexturePixelData(this._textureResourceUid,this.sm,this.TT,this.RA.framebufferUID,this.RA.whichColorAttachment(this))}async downloadTexturePixelData(){let e=await this.getTexturePixelData(),t=document.createElement("canvas");t.width=this.sm,t.height=this.TT;let i=t.getContext("2d");if(!(e.buffer instanceof ArrayBuffer))throw new Error("SharedArrayBuffer is not supported when downloading texture pixel data.");let r=new Uint8ClampedArray(e.buffer,e.byteOffset,e.byteLength/Uint8ClampedArray.BYTES_PER_ELEMENT),s=new ImageData(r,this.sm,this.TT);i.putImageData(s,this.sm,this.TT);let a=t.toDataURL("image/png"),o=document.createElement("a"),u=document.createEvent("MouseEvent");o.href=a,o.download="texture.png",u.initEvent("click",!0,!0),o.dispatchEvent(u)}async getPixelValueAt(e,t,i){let r=i;return r||(r=await this.getTexturePixelData()),R.fromCopyArray([r[(t*this.width+e)*4+0],r[(t*this.width+e)*4+1],r[(t*this.width+e)*4+2],r[(t*this.width+e)*4+3]])}generateMipmaps(){this.i.cgApiResourceRepository.generateMipmaps2d(this._textureResourceUid,this.width,this.height)}blitToTexture2dFromTexture2dArray(e){if(this.Bb===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArray(this._textureResourceUid,e.RA.cgApiResourceUid,e.width,e.height)}blitToTexture2dFromTexture2dArrayFake(e){if(this.Bb===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArrayFake(this._textureResourceUid,e.RA.cgApiResourceUid,e.width,e.height)}blitToTexture2dFromTexture2dArray2(e){if(this.Bb===0)return;this.i.webglResourceRepository.blitToTexture2dFromTexture2dArray2(this._textureResourceUid,e._textureResourceUid,e.width/2,e.height)}createCubeTextureViewAsRenderTarget(e,t){}};export{n as RenderTargetTexture2DArray};
@@ -22,6 +22,12 @@ export declare class RenderTargetTextureCube extends AbstractTexture implements
22
22
  private __fbo?;
23
23
  hdriFormat: import("..").EnumIO;
24
24
  _textureViewAsRenderTargetResourceUid: number;
25
+ /**
26
+ * The number of lowest specular IBL mip levels the runtime does not sample.
27
+ * The default is 0 (sample the whole chain); set this to the value used by the prefilter bake
28
+ * (4 for the mip-skip bake).
29
+ */
30
+ iblMipLevelSkip: number;
25
31
  /**
26
32
  * Creates and initializes the cube render target texture with the specified parameters.
27
33
  * This method sets up the internal texture resources and calculates mip levels if not provided.
@@ -1 +1 @@
1
- import{HdriFormat as c}from"../definitions/HdriFormat.js";import{ProcessApproach as i}from"../definitions/ProcessApproach.js";import{TextureFormat as R}from"../definitions/TextureFormat.js";import{CGAPIResourceRepository as a}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as h}from"./AbstractTexture.js";var o=class extends h{constructor(){super(...arguments);this.hdriFormat=c.HDR_LINEAR;this._textureViewAsRenderTargetResourceUid=-1}create({width:e,height:t,mipLevelCount:r,format:s}){this.sm=e,this.TT=t,this.uI=r!=null?r:Math.floor(Math.log2(Math.max(e,t)))+1;let{format:u,type:p}=R.getPixelFormatAndComponentTypeFromTextureFormat(s);this.cI=s,this.dI=u,this.Qe=p,this.fA()}fA(){let e=this.i.cgApiResourceRepository,t=e.createRenderTargetTextureCube({width:this.sm,height:this.TT,mipLevelCount:this.uI,format:this.cI});this._textureResourceUid=t,this.i.engineState.currentProcessApproach===i.WebGPU&&(this._textureViewResourceUid=e.createTextureViewCube(this._textureResourceUid),this._textureViewAsRenderTargetResourceUid=e.createCubeTextureViewAsRenderTarget(this._textureResourceUid,0,0))}generateMipmaps(){this.i.cgApiResourceRepository.generateMipmapsCube(this._textureResourceUid,this.width,this.height)}resize(e,t){this.destroy3DAPIResources(),this.sm=e,this.TT=t,this.fA()}destroy3DAPIResources(){return this.i.cgApiResourceRepository.deleteTexture(this._textureResourceUid),this._textureResourceUid=a.InvalidCGAPIResourceUid,!0}createCubeTextureViewAsRenderTarget(e,t){if(this.i.engineState.currentProcessApproach===i.WebGPU){let r=this.i.webGpuResourceRepository;this._textureViewAsRenderTargetResourceUid=r.createCubeTextureViewAsRenderTarget(this._textureResourceUid,e,t)}}set _fbo(e){this.RA=e}get fbo(){return this.RA}get mipmapLevelNumber(){return this.uI}setIsTextureReady(){this.aI=!0}};export{o as RenderTargetTextureCube};
1
+ import{HdriFormat as c}from"../definitions/HdriFormat.js";import{ProcessApproach as i}from"../definitions/ProcessApproach.js";import{TextureFormat as R}from"../definitions/TextureFormat.js";import{CGAPIResourceRepository as a}from"../renderer/CGAPIResourceRepository.js";import{AbstractTexture as h}from"./AbstractTexture.js";var o=class extends h{constructor(){super(...arguments);this.hdriFormat=c.HDR_LINEAR;this._textureViewAsRenderTargetResourceUid=-1;this.iblMipLevelSkip=0}create({width:e,height:t,mipLevelCount:r,format:s}){this.sm=e,this.TT=t,this.uI=r!=null?r:Math.floor(Math.log2(Math.max(e,t)))+1;let{format:u,type:p}=R.getPixelFormatAndComponentTypeFromTextureFormat(s);this.cI=s,this.dI=u,this.Qe=p,this.fA()}fA(){let e=this.i.cgApiResourceRepository,t=e.createRenderTargetTextureCube({width:this.sm,height:this.TT,mipLevelCount:this.uI,format:this.cI});this._textureResourceUid=t,this.i.engineState.currentProcessApproach===i.WebGPU&&(this._textureViewResourceUid=e.createTextureViewCube(this._textureResourceUid),this._textureViewAsRenderTargetResourceUid=e.createCubeTextureViewAsRenderTarget(this._textureResourceUid,0,0))}generateMipmaps(){this.i.cgApiResourceRepository.generateMipmapsCube(this._textureResourceUid,this.width,this.height)}resize(e,t){this.destroy3DAPIResources(),this.sm=e,this.TT=t,this.fA()}destroy3DAPIResources(){return this.i.cgApiResourceRepository.deleteTexture(this._textureResourceUid),this._textureResourceUid=a.InvalidCGAPIResourceUid,!0}createCubeTextureViewAsRenderTarget(e,t){if(this.i.engineState.currentProcessApproach===i.WebGPU){let r=this.i.webGpuResourceRepository;this._textureViewAsRenderTargetResourceUid=r.createCubeTextureViewAsRenderTarget(this._textureResourceUid,e,t)}}set _fbo(e){this.RA=e}get fbo(){return this.RA}get mipmapLevelNumber(){return this.uI}setIsTextureReady(){this.aI=!0}};export{o as RenderTargetTextureCube};
@@ -1 +1 @@
1
- var r={version:"v0.26.0-1-g0df3359c4-dirty",branch:"main"};var t=r;export{t as VERSION};
1
+ var r={version:"v0.27.0-1-g6b206dda3-dirty",branch:"main"};var t=r;export{t as VERSION};
@@ -1 +1 @@
1
- import{VertexAttribute as z}from"../foundation/definitions/VertexAttribute.js";var g=class g{constructor({key:t,sourceBuffer:r,indexed:u,primitiveMode:e,attributes:o}){this.entries=[];this.totalVertexCount=0;this.totalIndexCount=0;this.version=0;this.uid=++g.lM,this.key=t,this.sourceBuffer=r,this.indexed=u,this.primitiveMode=e,this.attributes=o}};g.lM=0;var S=g,k=new WeakMap,G=0;function H(n){let t=k.get(n);return t==null&&(t=++G,k.set(n,t)),t}var _=(n,t)=>n.attributeAccessors[t].bufferView.buffer;function O(n){if(n.targets.length>0||n.mesh==null)return null;let t=n.attributeAccessors;if(t.length===0)return null;let r=_(n,0),u=n.indicesAccessor,e=n.getVertexCountAsVerticesBased();if(e===0)return null;for(let i of t)if(i.elementCount!==e)return null;let o=n.attributeSemantics,a="";for(let i=0;i<t.length;i++){let s=t[i];a+=`${o[i]}#${s.componentType.index}#${s.compositionType.index}#${s.normalized?1:0}#${s.actualByteStride},`}let l=u!=null;return`${H(r)}#${l?1:0}#${n.primitiveMode.index}#${t.length}#${a}`}function W(n){let t=[],r=n.attributeAccessors,u=n.attributeSemantics;for(let e=0;e<r.length;e++){let o=r[e],a=z.fromString(u[e].split(".")[0]);t.push({semantic:u[e],slot:e,componentType:o.componentType,compositionType:o.compositionType,normalized:o.normalized,byteStride:o.actualByteStride,isIntegerType:a.isIntegerType})}return t}function Y(n){let t=new Map;for(let u of n){let e=O(u);if(e==null)continue;let o=t.get(e);o==null&&(o=[],t.set(e,o)),o.push(u)}let r=[];for(let[u,e]of t){if(e.length<2)continue;let o=e[0],a=o.indicesAccessor!=null,l=W(o),i=_(o,0),s=new S({key:u,sourceBuffer:i,indexed:a,primitiveMode:o.primitiveMode,attributes:l}),c=0,m=0;for(let d of e)c+=d.getVertexCountAsVerticesBased(),a&&(m+=d.indicesAccessor.elementCount);if(c>4294967295)continue;let p=l.map(d=>new Uint8Array(c*d.byteStride)),M=a?new Uint32Array(m):void 0,C=new Uint32Array(c),w=new Uint32Array(c),y=0,h=0;for(let d of e){let B=d.mesh,$=B._ensureInstanceSidBase(),b=d.getVertexCountAsVerticesBased(),P=d.attributeAccessors;for(let f=0;f<P.length;f++){let T=l[f],U=P[f].getUint8Array(),E=y*T.byteStride,K=Math.min(U.length,b*T.byteStride);p[f].set(U.subarray(0,K),E)}C.fill($,y,y+b);let V=d.material.materialSID;w.fill(V,y,y+b);let v=d.indicesAccessor,I=a?v.elementCount:0;if(a&&M!=null)for(let f=0;f<I;f++)M[h+f]=v.getScalar(f,{})+y;let R={primitive:d,primitiveUid:d.primitiveUid,mesh:B,vertexOffset:y,vertexCount:b,indexCount:I,indexByteOffset:h*4,materialSid:V};s.entries.push(R),y+=b,h+=I}s.totalVertexCount=c,s.totalIndexCount=m,s.counts=new Int32Array(s.entries.length),s.offsets=new Int32Array(s.entries.length),s.instanceCounts=new Int32Array(s.entries.length),s.firsts=new Int32Array(s.entries.length),s.vertexCounts=new Int32Array(s.entries.length),s.materialSids=w,r.push({group:s,attributeBytes:p,mergedIndices:M,instanceBases:C,materialSids:w})}return r}function j(n){var u,e;let t=n.mesh,r=t==null?void 0:t.meshEntitiesInner[0];return(e=(u=r==null?void 0:r.getMeshRenderer())==null?void 0:u.getFingerPrintId())!=null?e:0}function L(n,t,r){let u=n._multiDrawGroup;if(u==null)return null;let e=t===n.material,o=e?t._getMultiDrawStateKey():`${t.materialUID}|${t._getMultiDrawStateKey()}`;return`${u.uid}|${e?1:0}|${o}|${r}|${n.primitiveMode.index}|${n.getRenderIndexBitSize()}|${n.hasIndices()?1:0}`}var A=new WeakMap,x=new Map,F=0,D=0,J=65536;function q(n,t,r){let u=n._multiDrawGroup;if(u==null)return null;let e=t===n.material,o=n.primitiveMode.index,a=n.getRenderIndexBitSize(),l=n.hasIndices(),i=A.get(n);if(i!=null&&i.generation===D&&i.groupUid===u.uid&&i.materialUid===t.materialUID&&i.materialStateVersion===t.stateVersion&&i.meshRendererFingerPrintId===r&&i.mode===o&&i.indexBitSize===a&&i.indexed===l&&i.isPerVertexMaterial===e)return i.keyId;let s=L(n,t,r);if(s==null)return A.delete(n),null;let c=x.get(s);return c==null&&(x.size>=J&&(x.clear(),D++),c=++F,x.set(s,c)),A.set(n,{groupUid:u.uid,materialUid:t.materialUID,materialStateVersion:t.stateVersion,meshRendererFingerPrintId:r,mode:o,indexBitSize:a,indexed:l,isPerVertexMaterial:e,keyId:c,generation:D}),c}function N(n,t,r,u){let e=[];if(r>0&&n>t||r<0&&n<t)return e;let o=n;for(;;){let a=u(o),l=1,i=o+r;for(;(r>0?i<=t:i>=t)&&u(i)===a;)l++,i+=r;if(e.push({startIndex:o,count:l,step:r,key:a}),r>0&&i>t||r<0&&i<t)break;o=i}return e}function Q(n,t,r,u,e){var s,c;if(e.count=0,r>0&&n>t||r<0&&n<t)return e;let o=Math.abs(t-n)+1;if(e.starts.length<o){let m=Math.max(e.starts.length*2,64);for(;m<o;)m*=2;e.starts=new Int32Array(m),e.counts=new Int32Array(m),e.keys=new Int32Array(m)}let a=n,l=(s=u(n))!=null?s:-1,i=1;for(let m=n+r;r>0?m<=t:m>=t;m+=r){let p=(c=u(m))!=null?c:-1;if(p===l){i++;continue}e.starts[e.count]=a,e.counts[e.count]=i,e.keys[e.count]=l,e.count++,a=m,l=p,i=1}return e.starts[e.count]=a,e.counts[e.count]=i,e.keys[e.count]=l,e.count++,e}export{S as MultiDrawGroup,Y as buildMultiDrawGroups,H as getBufferId,W as getMultiDrawAttributes,q as getMultiDrawStateKeyId,j as getPrimitiveMeshRendererFingerPrintId,O as makeMultiDrawGroupKey,L as makeMultiDrawRenderStateKey,N as planMultiDrawRuns,Q as planMultiDrawRunsInto};
1
+ import{VertexAttribute as z}from"../foundation/definitions/VertexAttribute.js";var g=class g{constructor({key:t,sourceBuffer:r,indexed:u,primitiveMode:e,attributes:o}){this.entries=[];this.totalVertexCount=0;this.totalIndexCount=0;this.version=0;this.uid=++g.cM,this.key=t,this.sourceBuffer=r,this.indexed=u,this.primitiveMode=e,this.attributes=o}};g.cM=0;var S=g,k=new WeakMap,G=0;function H(n){let t=k.get(n);return t==null&&(t=++G,k.set(n,t)),t}var _=(n,t)=>n.attributeAccessors[t].bufferView.buffer;function O(n){if(n.targets.length>0||n.mesh==null)return null;let t=n.attributeAccessors;if(t.length===0)return null;let r=_(n,0),u=n.indicesAccessor,e=n.getVertexCountAsVerticesBased();if(e===0)return null;for(let i of t)if(i.elementCount!==e)return null;let o=n.attributeSemantics,a="";for(let i=0;i<t.length;i++){let s=t[i];a+=`${o[i]}#${s.componentType.index}#${s.compositionType.index}#${s.normalized?1:0}#${s.actualByteStride},`}let l=u!=null;return`${H(r)}#${l?1:0}#${n.primitiveMode.index}#${t.length}#${a}`}function W(n){let t=[],r=n.attributeAccessors,u=n.attributeSemantics;for(let e=0;e<r.length;e++){let o=r[e],a=z.fromString(u[e].split(".")[0]);t.push({semantic:u[e],slot:e,componentType:o.componentType,compositionType:o.compositionType,normalized:o.normalized,byteStride:o.actualByteStride,isIntegerType:a.isIntegerType})}return t}function Y(n){let t=new Map;for(let u of n){let e=O(u);if(e==null)continue;let o=t.get(e);o==null&&(o=[],t.set(e,o)),o.push(u)}let r=[];for(let[u,e]of t){if(e.length<2)continue;let o=e[0],a=o.indicesAccessor!=null,l=W(o),i=_(o,0),s=new S({key:u,sourceBuffer:i,indexed:a,primitiveMode:o.primitiveMode,attributes:l}),c=0,m=0;for(let d of e)c+=d.getVertexCountAsVerticesBased(),a&&(m+=d.indicesAccessor.elementCount);if(c>4294967295)continue;let p=l.map(d=>new Uint8Array(c*d.byteStride)),M=a?new Uint32Array(m):void 0,C=new Uint32Array(c),w=new Uint32Array(c),y=0,h=0;for(let d of e){let B=d.mesh,$=B._ensureInstanceSidBase(),b=d.getVertexCountAsVerticesBased(),P=d.attributeAccessors;for(let f=0;f<P.length;f++){let T=l[f],U=P[f].getUint8Array(),E=y*T.byteStride,K=Math.min(U.length,b*T.byteStride);p[f].set(U.subarray(0,K),E)}C.fill($,y,y+b);let V=d.material.materialSID;w.fill(V,y,y+b);let v=d.indicesAccessor,I=a?v.elementCount:0;if(a&&M!=null)for(let f=0;f<I;f++)M[h+f]=v.getScalar(f,{})+y;let R={primitive:d,primitiveUid:d.primitiveUid,mesh:B,vertexOffset:y,vertexCount:b,indexCount:I,indexByteOffset:h*4,materialSid:V};s.entries.push(R),y+=b,h+=I}s.totalVertexCount=c,s.totalIndexCount=m,s.counts=new Int32Array(s.entries.length),s.offsets=new Int32Array(s.entries.length),s.instanceCounts=new Int32Array(s.entries.length),s.firsts=new Int32Array(s.entries.length),s.vertexCounts=new Int32Array(s.entries.length),s.materialSids=w,r.push({group:s,attributeBytes:p,mergedIndices:M,instanceBases:C,materialSids:w})}return r}function j(n){var u,e;let t=n.mesh,r=t==null?void 0:t.meshEntitiesInner[0];return(e=(u=r==null?void 0:r.getMeshRenderer())==null?void 0:u.getFingerPrintId())!=null?e:0}function L(n,t,r){let u=n._multiDrawGroup;if(u==null)return null;let e=t===n.material,o=e?t._getMultiDrawStateKey():`${t.materialUID}|${t._getMultiDrawStateKey()}`;return`${u.uid}|${e?1:0}|${o}|${r}|${n.primitiveMode.index}|${n.getRenderIndexBitSize()}|${n.hasIndices()?1:0}`}var A=new WeakMap,x=new Map,F=0,D=0,J=65536;function q(n,t,r){let u=n._multiDrawGroup;if(u==null)return null;let e=t===n.material,o=n.primitiveMode.index,a=n.getRenderIndexBitSize(),l=n.hasIndices(),i=A.get(n);if(i!=null&&i.generation===D&&i.groupUid===u.uid&&i.materialUid===t.materialUID&&i.materialStateVersion===t.stateVersion&&i.meshRendererFingerPrintId===r&&i.mode===o&&i.indexBitSize===a&&i.indexed===l&&i.isPerVertexMaterial===e)return i.keyId;let s=L(n,t,r);if(s==null)return A.delete(n),null;let c=x.get(s);return c==null&&(x.size>=J&&(x.clear(),D++),c=++F,x.set(s,c)),A.set(n,{groupUid:u.uid,materialUid:t.materialUID,materialStateVersion:t.stateVersion,meshRendererFingerPrintId:r,mode:o,indexBitSize:a,indexed:l,isPerVertexMaterial:e,keyId:c,generation:D}),c}function N(n,t,r,u){let e=[];if(r>0&&n>t||r<0&&n<t)return e;let o=n;for(;;){let a=u(o),l=1,i=o+r;for(;(r>0?i<=t:i>=t)&&u(i)===a;)l++,i+=r;if(e.push({startIndex:o,count:l,step:r,key:a}),r>0&&i>t||r<0&&i<t)break;o=i}return e}function Q(n,t,r,u,e){var s,c;if(e.count=0,r>0&&n>t||r<0&&n<t)return e;let o=Math.abs(t-n)+1;if(e.starts.length<o){let m=Math.max(e.starts.length*2,64);for(;m<o;)m*=2;e.starts=new Int32Array(m),e.counts=new Int32Array(m),e.keys=new Int32Array(m)}let a=n,l=(s=u(n))!=null?s:-1,i=1;for(let m=n+r;r>0?m<=t:m>=t;m+=r){let p=(c=u(m))!=null?c:-1;if(p===l){i++;continue}e.starts[e.count]=a,e.counts[e.count]=i,e.keys[e.count]=l,e.count++,a=m,l=p,i=1}return e.starts[e.count]=a,e.counts[e.count]=i,e.keys[e.count]=l,e.count++,e}export{S as MultiDrawGroup,Y as buildMultiDrawGroups,H as getBufferId,W as getMultiDrawAttributes,q as getMultiDrawStateKeyId,j as getPrimitiveMeshRendererFingerPrintId,O as makeMultiDrawGroupKey,L as makeMultiDrawRenderStateKey,N as planMultiDrawRuns,Q as planMultiDrawRunsInto};
@@ -1 +1 @@
1
- import{ProcessApproach as h}from"../foundation/definitions/ProcessApproach.js";import{VertexAttribute as p}from"../foundation/definitions/VertexAttribute.js";import{Primitive as m}from"../foundation/geometry/Primitive.js";import{buildMultiDrawGroups as v}from"./MultiDraw.js";var f=class{constructor(t){this.eV=new Map;this.tV=!0;this.Mb=0;this.rV=new Set;this.iV=!0;this.i=t}get version(){return this.Mb}hasVaoHandle(t){var e;for(let i of this.eV.values())if(((e=i.vertexHandles)==null?void 0:e.vaoHandle)===t)return!0;return!1}get groups(){return this.eV}markDirty(){this.iV=!0,this.tV=!0}markDirtyForMesh(t){this.rV.add(t),this.tV=!0}rebuildDirtyGroups(){if(!this.tV)return;this.tV=!1;let t=this.iV;this.iV=!1;let e=this.i,i=e.webglResourceRepository,d=e.config.isMultiDrawEnabled&&h.isWebGL2Approach(e.engineState.currentProcessApproach)&&i.isInstanceSidTextureCapable;if(this.aV(),!d){this.rV.clear(),this.Mb++;return}let n=[],o=new Set;m.forEachPrimitive(r=>{if(r._engine!==e)return;n.push(r);let a=r.mesh;a!=null&&o.add(a)});let c=v(n),l=new Set;for(let r of c){let a=r.group;this.sV(r);for(let s=0;s<a.entries.length;s++){let u=a.entries[s];u.primitive.delete3DAPIVertexData(),u.primitive._setMultiDrawGroup(a,s),l.add(u.primitive)}this.eV.set(a.key,a)}for(let r of o)r.updateVariationVBO();for(let r of n)if(!l.has(r))if(r.vertexHandles==null)r.create3DAPIVertexData();else{let a=r.mesh;(t||a!=null&&this.rV.has(a))&&r.update3DAPIVertexData()}for(let r of o)r.updateVAO();this.rV.clear(),this.Mb++}invalidateAll(){this.aV(),this.tV=!0}aV(){let t=this.i.webglResourceRepository;for(let e of this.eV.values()){for(let i of e.entries)i.mesh._clearMultiDrawVaoUids(),i.primitive._multiDrawGroup===e&&i.primitive._clearMultiDrawGroup();e.genericMaterialSidVaoHandle!=null&&(t.deleteVertexArray(e.genericMaterialSidVaoHandle),e.genericMaterialSidVaoHandle=void 0),e.vertexHandles!=null&&(t.deleteVertexDataResources(e.vertexHandles),e.vertexHandles=void 0),e.instanceBaseVboHandle!=null&&(t.deleteVertexBuffer(e.instanceBaseVboHandle),e.instanceBaseVboHandle=void 0),e.materialSidVboHandle!=null&&(t.deleteVertexBuffer(e.materialSidVboHandle),e.materialSidVboHandle=void 0)}this.eV.clear()}sV(t){let e=this.i.webglResourceRepository,i=t.group,d=t.attributeBytes.map(s=>e.createVertexBufferFromTypedArray(s)),n=t.mergedIndices!=null?e.createIndexBufferFromTypedArray(t.mergedIndices):void 0,o=e.createVertexBufferFromTypedArray(t.instanceBases),c=e.createVertexBufferFromTypedArray(t.materialSids),l=e.createVertexArray(),r=e.createVertexArray(),a=[];for(let s=0;s<p.AttributeTypeNumber;s++)a[s]=!1;for(let s of i.attributes){let u=p.toAttributeSlotFromJoinedString(s.semantic);a[u]=!0}i.vertexHandles={vaoHandle:l,iboHandle:n,vboHandles:d,attributesFlags:a,setComplete:!1},i.instanceBaseVboHandle=o,i.materialSidVboHandle=c,i.genericMaterialSidVaoHandle=r,i.version++,e.setMultiDrawVertexDataToPipeline(i,l,!0),e.setMultiDrawVertexDataToPipeline(i,r,!1)}};export{f as MultiDrawRepository};
1
+ import{ProcessApproach as h}from"../foundation/definitions/ProcessApproach.js";import{VertexAttribute as p}from"../foundation/definitions/VertexAttribute.js";import{Primitive as m}from"../foundation/geometry/Primitive.js";import{buildMultiDrawGroups as v}from"./MultiDraw.js";var f=class{constructor(t){this.eV=new Map;this.tV=!0;this.Nb=0;this.rV=new Set;this.iV=!0;this.i=t}get version(){return this.Nb}hasVaoHandle(t){var e;for(let i of this.eV.values())if(((e=i.vertexHandles)==null?void 0:e.vaoHandle)===t)return!0;return!1}get groups(){return this.eV}markDirty(){this.iV=!0,this.tV=!0}markDirtyForMesh(t){this.rV.add(t),this.tV=!0}rebuildDirtyGroups(){if(!this.tV)return;this.tV=!1;let t=this.iV;this.iV=!1;let e=this.i,i=e.webglResourceRepository,d=e.config.isMultiDrawEnabled&&h.isWebGL2Approach(e.engineState.currentProcessApproach)&&i.isInstanceSidTextureCapable;if(this.aV(),!d){this.rV.clear(),this.Nb++;return}let n=[],o=new Set;m.forEachPrimitive(r=>{if(r._engine!==e)return;n.push(r);let a=r.mesh;a!=null&&o.add(a)});let c=v(n),l=new Set;for(let r of c){let a=r.group;this.sV(r);for(let s=0;s<a.entries.length;s++){let u=a.entries[s];u.primitive.delete3DAPIVertexData(),u.primitive._setMultiDrawGroup(a,s),l.add(u.primitive)}this.eV.set(a.key,a)}for(let r of o)r.updateVariationVBO();for(let r of n)if(!l.has(r))if(r.vertexHandles==null)r.create3DAPIVertexData();else{let a=r.mesh;(t||a!=null&&this.rV.has(a))&&r.update3DAPIVertexData()}for(let r of o)r.updateVAO();this.rV.clear(),this.Nb++}invalidateAll(){this.aV(),this.tV=!0}aV(){let t=this.i.webglResourceRepository;for(let e of this.eV.values()){for(let i of e.entries)i.mesh._clearMultiDrawVaoUids(),i.primitive._multiDrawGroup===e&&i.primitive._clearMultiDrawGroup();e.genericMaterialSidVaoHandle!=null&&(t.deleteVertexArray(e.genericMaterialSidVaoHandle),e.genericMaterialSidVaoHandle=void 0),e.vertexHandles!=null&&(t.deleteVertexDataResources(e.vertexHandles),e.vertexHandles=void 0),e.instanceBaseVboHandle!=null&&(t.deleteVertexBuffer(e.instanceBaseVboHandle),e.instanceBaseVboHandle=void 0),e.materialSidVboHandle!=null&&(t.deleteVertexBuffer(e.materialSidVboHandle),e.materialSidVboHandle=void 0)}this.eV.clear()}sV(t){let e=this.i.webglResourceRepository,i=t.group,d=t.attributeBytes.map(s=>e.createVertexBufferFromTypedArray(s)),n=t.mergedIndices!=null?e.createIndexBufferFromTypedArray(t.mergedIndices):void 0,o=e.createVertexBufferFromTypedArray(t.instanceBases),c=e.createVertexBufferFromTypedArray(t.materialSids),l=e.createVertexArray(),r=e.createVertexArray(),a=[];for(let s=0;s<p.AttributeTypeNumber;s++)a[s]=!1;for(let s of i.attributes){let u=p.toAttributeSlotFromJoinedString(s.semantic);a[u]=!0}i.vertexHandles={vaoHandle:l,iboHandle:n,vboHandles:d,attributesFlags:a,setComplete:!1},i.instanceBaseVboHandle=o,i.materialSidVboHandle=c,i.genericMaterialSidVaoHandle=r,i.version++,e.setMultiDrawVertexDataToPipeline(i,l,!0),e.setMultiDrawVertexDataToPipeline(i,r,!1)}};export{f as MultiDrawRepository};
@@ -855,6 +855,11 @@ export declare class WebGLResourceRepository extends CGAPIResourceRepository imp
855
855
  * @returns the WebGLResourceHandle for the generated Cube Texture
856
856
  */
857
857
  createCubeTextureFromFiles(engine: Engine, baseUri: string, mipLevelCount: Count, isNamePosNeg: boolean, hdriFormat: HdriFormatEnum): Promise<[number, Sampler, number, number]>;
858
+ /**
859
+ * Reads back an RGB9_E5 PNG image (hdrpng.js layout, little-endian packed word) and repacks it
860
+ * to the native UNSIGNED_INT_5_9_9_9_REV layout: E[31:27], B[26:18], G[17:9], R[8:0].
861
+ */
862
+ private __decodeRgb9E5PngToNative;
858
863
  createCubeTextureFromBasis(basisFile: BasisFile, { magFilter, minFilter, wrapS, wrapT, border, }: {
859
864
  border?: number | undefined;
860
865
  magFilter?: TextureParameterEnum | undefined;