@needle-tools/three 0.162.2 → 0.162.3

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 (955) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +86 -86
  3. package/build/three.cjs +53266 -53266
  4. package/build/three.module.js +53266 -53266
  5. package/examples/fonts/LICENSE +13 -13
  6. package/examples/fonts/README.md +11 -11
  7. package/examples/fonts/droid/NOTICE +190 -190
  8. package/examples/fonts/droid/README.txt +18 -18
  9. package/examples/fonts/ttf/README.md +9 -9
  10. package/examples/jsm/Addons.js +295 -295
  11. package/examples/jsm/animation/AnimationClipCreator.js +116 -116
  12. package/examples/jsm/animation/CCDIKSolver.js +482 -482
  13. package/examples/jsm/animation/MMDAnimationHelper.js +1207 -1207
  14. package/examples/jsm/animation/MMDPhysics.js +1406 -1406
  15. package/examples/jsm/cameras/CinematicCamera.js +208 -208
  16. package/examples/jsm/capabilities/WebGL.js +108 -108
  17. package/examples/jsm/capabilities/WebGPU.js +57 -57
  18. package/examples/jsm/controls/ArcballControls.js +3224 -3224
  19. package/examples/jsm/controls/DragControls.js +282 -282
  20. package/examples/jsm/controls/FirstPersonControls.js +325 -325
  21. package/examples/jsm/controls/FlyControls.js +326 -326
  22. package/examples/jsm/controls/MapControls.js +28 -28
  23. package/examples/jsm/controls/OrbitControls.js +1548 -1548
  24. package/examples/jsm/controls/PointerLockControls.js +162 -162
  25. package/examples/jsm/controls/TrackballControls.js +828 -828
  26. package/examples/jsm/controls/TransformControls.js +1573 -1573
  27. package/examples/jsm/csm/CSM.js +384 -384
  28. package/examples/jsm/csm/CSMFrustum.js +152 -152
  29. package/examples/jsm/csm/CSMHelper.js +193 -193
  30. package/examples/jsm/csm/CSMShader.js +295 -295
  31. package/examples/jsm/curves/CurveExtras.js +422 -422
  32. package/examples/jsm/curves/NURBSCurve.js +80 -80
  33. package/examples/jsm/curves/NURBSSurface.js +52 -52
  34. package/examples/jsm/curves/NURBSUtils.js +542 -542
  35. package/examples/jsm/curves/NURBSVolume.js +62 -62
  36. package/examples/jsm/effects/AnaglyphEffect.js +154 -154
  37. package/examples/jsm/effects/AsciiEffect.js +263 -263
  38. package/examples/jsm/effects/OutlineEffect.js +539 -539
  39. package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -119
  40. package/examples/jsm/effects/PeppersGhostEffect.js +153 -153
  41. package/examples/jsm/effects/StereoEffect.js +55 -55
  42. package/examples/jsm/environments/DebugEnvironment.js +52 -52
  43. package/examples/jsm/environments/RoomEnvironment.js +148 -148
  44. package/examples/jsm/exporters/DRACOExporter.js +267 -267
  45. package/examples/jsm/exporters/EXRExporter.js +579 -579
  46. package/examples/jsm/exporters/GLTFExporter.js +3322 -3321
  47. package/examples/jsm/exporters/KTX2Exporter.js +292 -292
  48. package/examples/jsm/exporters/MMDExporter.js +217 -217
  49. package/examples/jsm/exporters/OBJExporter.js +284 -284
  50. package/examples/jsm/exporters/PLYExporter.js +528 -528
  51. package/examples/jsm/exporters/STLExporter.js +199 -199
  52. package/examples/jsm/exporters/USDZExporter.js +720 -720
  53. package/examples/jsm/geometries/BoxLineGeometry.js +69 -69
  54. package/examples/jsm/geometries/ConvexGeometry.js +53 -53
  55. package/examples/jsm/geometries/DecalGeometry.js +356 -356
  56. package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -174
  57. package/examples/jsm/geometries/ParametricGeometries.js +254 -254
  58. package/examples/jsm/geometries/ParametricGeometry.js +139 -139
  59. package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -155
  60. package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -144
  61. package/examples/jsm/geometries/TeapotGeometry.js +704 -704
  62. package/examples/jsm/geometries/TextGeometry.js +57 -57
  63. package/examples/jsm/helpers/LightProbeHelper.js +130 -130
  64. package/examples/jsm/helpers/OctreeHelper.js +73 -73
  65. package/examples/jsm/helpers/PositionalAudioHelper.js +109 -109
  66. package/examples/jsm/helpers/RectAreaLightHelper.js +85 -85
  67. package/examples/jsm/helpers/TextureHelper.js +237 -237
  68. package/examples/jsm/helpers/VertexNormalsHelper.js +96 -96
  69. package/examples/jsm/helpers/VertexTangentsHelper.js +88 -88
  70. package/examples/jsm/helpers/ViewHelper.js +333 -333
  71. package/examples/jsm/interactive/HTMLMesh.js +572 -572
  72. package/examples/jsm/interactive/InteractiveGroup.js +106 -106
  73. package/examples/jsm/interactive/SelectionBox.js +227 -227
  74. package/examples/jsm/interactive/SelectionHelper.js +104 -104
  75. package/examples/jsm/libs/ammo.wasm.js +822 -822
  76. package/examples/jsm/libs/basis/README.md +46 -46
  77. package/examples/jsm/libs/basis/basis_transcoder.js +21 -21
  78. package/examples/jsm/libs/chevrotain.module.min.js +141 -141
  79. package/examples/jsm/libs/draco/README.md +32 -32
  80. package/examples/jsm/libs/draco/draco_decoder.js +34 -34
  81. package/examples/jsm/libs/draco/draco_encoder.js +33 -33
  82. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -117
  83. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -33
  84. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -33
  85. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -116
  86. package/examples/jsm/libs/ecsy.module.js +1792 -1792
  87. package/examples/jsm/libs/fflate.module.js +2474 -2474
  88. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  89. package/examples/jsm/libs/lil-gui.module.min.js +8 -8
  90. package/examples/jsm/libs/lottie_canvas.module.js +14849 -14849
  91. package/examples/jsm/libs/meshopt_decoder.module.js +178 -178
  92. package/examples/jsm/libs/mikktspace.module.js +128 -128
  93. package/examples/jsm/libs/mmdparser.module.js +11530 -11530
  94. package/examples/jsm/libs/motion-controllers.module.js +397 -397
  95. package/examples/jsm/libs/opentype.module.js +14506 -14506
  96. package/examples/jsm/libs/potpack.module.js +124 -124
  97. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -21
  98. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +15 -15
  99. package/examples/jsm/libs/stats.module.js +167 -167
  100. package/examples/jsm/libs/surfaceNet.js +200 -200
  101. package/examples/jsm/libs/tween.module.js +876 -876
  102. package/examples/jsm/libs/utif.module.js +1664 -1664
  103. package/examples/jsm/libs/zstddec.module.js +1 -1
  104. package/examples/jsm/lights/IESSpotLight.js +25 -25
  105. package/examples/jsm/lights/LightProbeGenerator.js +286 -286
  106. package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -79
  107. package/examples/jsm/lines/Line2.js +19 -19
  108. package/examples/jsm/lines/LineGeometry.js +79 -79
  109. package/examples/jsm/lines/LineMaterial.js +619 -619
  110. package/examples/jsm/lines/LineSegments2.js +361 -361
  111. package/examples/jsm/lines/LineSegmentsGeometry.js +241 -241
  112. package/examples/jsm/lines/Wireframe.js +56 -56
  113. package/examples/jsm/lines/WireframeGeometry2.js +24 -24
  114. package/examples/jsm/loaders/3DMLoader.js +1764 -1764
  115. package/examples/jsm/loaders/3MFLoader.js +1478 -1478
  116. package/examples/jsm/loaders/AMFLoader.js +521 -521
  117. package/examples/jsm/loaders/BVHLoader.js +437 -437
  118. package/examples/jsm/loaders/ColladaLoader.js +4116 -4116
  119. package/examples/jsm/loaders/DDSLoader.js +318 -318
  120. package/examples/jsm/loaders/DRACOLoader.js +613 -613
  121. package/examples/jsm/loaders/EXRLoader.js +2309 -2309
  122. package/examples/jsm/loaders/FBXLoader.js +4314 -4314
  123. package/examples/jsm/loaders/FontLoader.js +183 -183
  124. package/examples/jsm/loaders/GCodeLoader.js +261 -261
  125. package/examples/jsm/loaders/GLTFLoader.js +4666 -4666
  126. package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +729 -729
  127. package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -115
  128. package/examples/jsm/loaders/IESLoader.js +337 -337
  129. package/examples/jsm/loaders/KMZLoader.js +130 -130
  130. package/examples/jsm/loaders/KTX2Loader.js +932 -932
  131. package/examples/jsm/loaders/KTXLoader.js +176 -176
  132. package/examples/jsm/loaders/LDrawLoader.js +2470 -2470
  133. package/examples/jsm/loaders/LUT3dlLoader.js +183 -183
  134. package/examples/jsm/loaders/LUTCubeLoader.js +167 -167
  135. package/examples/jsm/loaders/LUTImageLoader.js +163 -163
  136. package/examples/jsm/loaders/LWOLoader.js +1052 -1052
  137. package/examples/jsm/loaders/LogLuvLoader.js +606 -606
  138. package/examples/jsm/loaders/LottieLoader.js +77 -77
  139. package/examples/jsm/loaders/MD2Loader.js +399 -399
  140. package/examples/jsm/loaders/MDDLoader.js +102 -102
  141. package/examples/jsm/loaders/MMDLoader.js +2276 -2276
  142. package/examples/jsm/loaders/MTLLoader.js +567 -567
  143. package/examples/jsm/loaders/MaterialXLoader.js +852 -852
  144. package/examples/jsm/loaders/NRRDLoader.js +686 -686
  145. package/examples/jsm/loaders/OBJLoader.js +905 -905
  146. package/examples/jsm/loaders/PCDLoader.js +467 -467
  147. package/examples/jsm/loaders/PDBLoader.js +232 -232
  148. package/examples/jsm/loaders/PLYLoader.js +771 -771
  149. package/examples/jsm/loaders/PVRLoader.js +251 -251
  150. package/examples/jsm/loaders/RGBELoader.js +450 -450
  151. package/examples/jsm/loaders/RGBMLoader.js +1065 -1065
  152. package/examples/jsm/loaders/STLLoader.js +410 -410
  153. package/examples/jsm/loaders/SVGLoader.js +3173 -3173
  154. package/examples/jsm/loaders/TDSLoader.js +1124 -1124
  155. package/examples/jsm/loaders/TGALoader.js +517 -517
  156. package/examples/jsm/loaders/TIFFLoader.js +36 -36
  157. package/examples/jsm/loaders/TTFLoader.js +214 -214
  158. package/examples/jsm/loaders/TiltLoader.js +520 -520
  159. package/examples/jsm/loaders/USDZLoader.js +822 -822
  160. package/examples/jsm/loaders/VOXLoader.js +318 -318
  161. package/examples/jsm/loaders/VRMLLoader.js +3537 -3537
  162. package/examples/jsm/loaders/VTKLoader.js +1163 -1163
  163. package/examples/jsm/loaders/XYZLoader.js +106 -106
  164. package/examples/jsm/loaders/lwo/IFFParser.js +1214 -1214
  165. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -414
  166. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -373
  167. package/examples/jsm/materials/MeshGouraudMaterial.js +426 -426
  168. package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -144
  169. package/examples/jsm/math/Capsule.js +82 -82
  170. package/examples/jsm/math/ColorConverter.js +36 -36
  171. package/examples/jsm/math/ConvexHull.js +1271 -1271
  172. package/examples/jsm/math/ImprovedNoise.js +71 -71
  173. package/examples/jsm/math/Lut.js +204 -204
  174. package/examples/jsm/math/MeshSurfaceSampler.js +250 -250
  175. package/examples/jsm/math/OBB.js +423 -423
  176. package/examples/jsm/math/Octree.js +540 -540
  177. package/examples/jsm/math/SimplexNoise.js +444 -444
  178. package/examples/jsm/misc/ConvexObjectBreaker.js +519 -519
  179. package/examples/jsm/misc/GPUComputationRenderer.js +446 -446
  180. package/examples/jsm/misc/Gyroscope.js +66 -66
  181. package/examples/jsm/misc/MD2Character.js +276 -276
  182. package/examples/jsm/misc/MD2CharacterComplex.js +576 -576
  183. package/examples/jsm/misc/MorphAnimMesh.js +75 -75
  184. package/examples/jsm/misc/MorphBlendMesh.js +322 -322
  185. package/examples/jsm/misc/ProgressiveLightMap.js +324 -324
  186. package/examples/jsm/misc/RollerCoaster.js +566 -566
  187. package/examples/jsm/misc/Timer.js +128 -128
  188. package/examples/jsm/misc/TubePainter.js +202 -202
  189. package/examples/jsm/misc/Volume.js +473 -473
  190. package/examples/jsm/misc/VolumeSlice.js +229 -229
  191. package/examples/jsm/modifiers/CurveModifier.js +344 -344
  192. package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -279
  193. package/examples/jsm/modifiers/SimplifyModifier.js +617 -617
  194. package/examples/jsm/modifiers/TessellateModifier.js +307 -307
  195. package/examples/jsm/nodes/Nodes.js +195 -195
  196. package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -10
  197. package/examples/jsm/nodes/accessors/BitangentNode.js +89 -89
  198. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +127 -127
  199. package/examples/jsm/nodes/accessors/BufferNode.js +30 -30
  200. package/examples/jsm/nodes/accessors/CameraNode.js +119 -119
  201. package/examples/jsm/nodes/accessors/ClippingNode.js +144 -144
  202. package/examples/jsm/nodes/accessors/CubeTextureNode.js +61 -61
  203. package/examples/jsm/nodes/accessors/InstanceNode.js +71 -71
  204. package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -21
  205. package/examples/jsm/nodes/accessors/MaterialNode.js +314 -314
  206. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +41 -41
  207. package/examples/jsm/nodes/accessors/ModelNode.js +33 -33
  208. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +39 -39
  209. package/examples/jsm/nodes/accessors/MorphNode.js +245 -245
  210. package/examples/jsm/nodes/accessors/NormalNode.js +96 -96
  211. package/examples/jsm/nodes/accessors/Object3DNode.js +150 -150
  212. package/examples/jsm/nodes/accessors/PointUVNode.js +26 -26
  213. package/examples/jsm/nodes/accessors/PositionNode.js +104 -104
  214. package/examples/jsm/nodes/accessors/ReferenceNode.js +160 -160
  215. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -35
  216. package/examples/jsm/nodes/accessors/SceneNode.js +52 -52
  217. package/examples/jsm/nodes/accessors/SkinningNode.js +124 -124
  218. package/examples/jsm/nodes/accessors/StorageBufferNode.js +72 -72
  219. package/examples/jsm/nodes/accessors/TangentNode.js +109 -109
  220. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -94
  221. package/examples/jsm/nodes/accessors/TextureNode.js +367 -367
  222. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -35
  223. package/examples/jsm/nodes/accessors/TextureStoreNode.js +82 -82
  224. package/examples/jsm/nodes/accessors/UVNode.js +47 -47
  225. package/examples/jsm/nodes/accessors/UniformsNode.js +140 -140
  226. package/examples/jsm/nodes/accessors/UserDataNode.js +29 -29
  227. package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -70
  228. package/examples/jsm/nodes/code/CodeNode.js +84 -84
  229. package/examples/jsm/nodes/code/ExpressionNode.js +37 -37
  230. package/examples/jsm/nodes/code/FunctionCallNode.js +96 -96
  231. package/examples/jsm/nodes/code/FunctionNode.js +138 -138
  232. package/examples/jsm/nodes/code/ScriptableNode.js +488 -488
  233. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -167
  234. package/examples/jsm/nodes/core/AssignNode.js +128 -128
  235. package/examples/jsm/nodes/core/AttributeNode.js +108 -108
  236. package/examples/jsm/nodes/core/BypassNode.js +45 -45
  237. package/examples/jsm/nodes/core/CacheNode.js +49 -49
  238. package/examples/jsm/nodes/core/ConstNode.js +32 -32
  239. package/examples/jsm/nodes/core/ContextNode.js +61 -61
  240. package/examples/jsm/nodes/core/IndexNode.js +66 -66
  241. package/examples/jsm/nodes/core/InputNode.js +83 -83
  242. package/examples/jsm/nodes/core/LightingModel.js +17 -17
  243. package/examples/jsm/nodes/core/Node.js +493 -493
  244. package/examples/jsm/nodes/core/NodeAttribute.js +15 -15
  245. package/examples/jsm/nodes/core/NodeBuilder.js +1250 -1250
  246. package/examples/jsm/nodes/core/NodeCache.js +26 -26
  247. package/examples/jsm/nodes/core/NodeCode.js +15 -15
  248. package/examples/jsm/nodes/core/NodeFrame.js +143 -143
  249. package/examples/jsm/nodes/core/NodeFunction.js +22 -22
  250. package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -17
  251. package/examples/jsm/nodes/core/NodeKeywords.js +80 -80
  252. package/examples/jsm/nodes/core/NodeParser.js +11 -11
  253. package/examples/jsm/nodes/core/NodeUniform.js +40 -40
  254. package/examples/jsm/nodes/core/NodeUtils.js +210 -210
  255. package/examples/jsm/nodes/core/NodeVar.js +14 -14
  256. package/examples/jsm/nodes/core/NodeVarying.js +17 -17
  257. package/examples/jsm/nodes/core/OutputStructNode.js +62 -62
  258. package/examples/jsm/nodes/core/ParameterNode.js +33 -33
  259. package/examples/jsm/nodes/core/PropertyNode.js +72 -72
  260. package/examples/jsm/nodes/core/StackNode.js +89 -89
  261. package/examples/jsm/nodes/core/StructTypeNode.js +24 -24
  262. package/examples/jsm/nodes/core/TempNode.js +58 -58
  263. package/examples/jsm/nodes/core/UniformGroup.js +13 -13
  264. package/examples/jsm/nodes/core/UniformGroupNode.js +36 -36
  265. package/examples/jsm/nodes/core/UniformNode.js +80 -80
  266. package/examples/jsm/nodes/core/VarNode.js +60 -60
  267. package/examples/jsm/nodes/core/VaryingNode.js +65 -65
  268. package/examples/jsm/nodes/core/constants.js +28 -28
  269. package/examples/jsm/nodes/display/AfterImageNode.js +148 -148
  270. package/examples/jsm/nodes/display/AnamorphicNode.js +148 -148
  271. package/examples/jsm/nodes/display/BlendModeNode.js +128 -128
  272. package/examples/jsm/nodes/display/BumpMapNode.js +99 -99
  273. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +99 -99
  274. package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -108
  275. package/examples/jsm/nodes/display/FrontFacingNode.js +27 -27
  276. package/examples/jsm/nodes/display/GaussianBlurNode.js +190 -190
  277. package/examples/jsm/nodes/display/NormalMapNode.js +106 -106
  278. package/examples/jsm/nodes/display/PassNode.js +183 -183
  279. package/examples/jsm/nodes/display/PosterizeNode.js +32 -32
  280. package/examples/jsm/nodes/display/ToneMappingNode.js +184 -184
  281. package/examples/jsm/nodes/display/ViewportDepthNode.js +97 -97
  282. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +31 -31
  283. package/examples/jsm/nodes/display/ViewportNode.js +134 -134
  284. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -31
  285. package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -75
  286. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -35
  287. package/examples/jsm/nodes/fog/FogNode.js +38 -38
  288. package/examples/jsm/nodes/fog/FogRangeNode.js +34 -34
  289. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -40
  290. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -9
  291. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +57 -57
  292. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +30 -30
  293. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +23 -23
  294. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -13
  295. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -16
  296. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +21 -21
  297. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +28 -28
  298. package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -67
  299. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +393 -393
  300. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -13
  301. package/examples/jsm/nodes/functions/material/getRoughness.js +18 -18
  302. package/examples/jsm/nodes/geometry/RangeNode.js +104 -104
  303. package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -85
  304. package/examples/jsm/nodes/lighting/AONode.js +27 -27
  305. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -27
  306. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +241 -241
  307. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -40
  308. package/examples/jsm/nodes/lighting/EnvironmentNode.js +181 -181
  309. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -55
  310. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -39
  311. package/examples/jsm/nodes/lighting/LightNode.js +57 -57
  312. package/examples/jsm/nodes/lighting/LightUtils.js +17 -17
  313. package/examples/jsm/nodes/lighting/LightingContextNode.js +66 -66
  314. package/examples/jsm/nodes/lighting/LightingNode.js +21 -21
  315. package/examples/jsm/nodes/lighting/LightsNode.js +188 -188
  316. package/examples/jsm/nodes/lighting/PointLightNode.js +68 -68
  317. package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -89
  318. package/examples/jsm/nodes/loaders/NodeLoader.js +108 -108
  319. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -59
  320. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -70
  321. package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -162
  322. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +436 -436
  323. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -28
  324. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -54
  325. package/examples/jsm/nodes/materials/Materials.js +16 -16
  326. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +28 -28
  327. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -34
  328. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -40
  329. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -65
  330. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +155 -155
  331. package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -84
  332. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -80
  333. package/examples/jsm/nodes/materials/NodeMaterial.js +601 -601
  334. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +39 -39
  335. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +90 -90
  336. package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -199
  337. package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -68
  338. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +130 -130
  339. package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -1430
  340. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +29 -29
  341. package/examples/jsm/nodes/math/CondNode.js +121 -121
  342. package/examples/jsm/nodes/math/HashNode.js +34 -34
  343. package/examples/jsm/nodes/math/MathNode.js +391 -391
  344. package/examples/jsm/nodes/math/MathUtils.js +15 -15
  345. package/examples/jsm/nodes/math/OperatorNode.js +274 -274
  346. package/examples/jsm/nodes/math/TriNoise3D.js +71 -71
  347. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -152
  348. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -14
  349. package/examples/jsm/nodes/procedural/CheckerNode.js +42 -42
  350. package/examples/jsm/nodes/shadernode/ShaderNode.js +634 -634
  351. package/examples/jsm/nodes/utils/ArrayElementNode.js +35 -35
  352. package/examples/jsm/nodes/utils/ConvertNode.js +65 -65
  353. package/examples/jsm/nodes/utils/DiscardNode.js +27 -27
  354. package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -33
  355. package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -95
  356. package/examples/jsm/nodes/utils/JoinNode.js +61 -61
  357. package/examples/jsm/nodes/utils/LoopNode.js +200 -200
  358. package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -30
  359. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -46
  360. package/examples/jsm/nodes/utils/OscNode.js +81 -81
  361. package/examples/jsm/nodes/utils/PackingNode.js +55 -55
  362. package/examples/jsm/nodes/utils/ReflectorNode.js +227 -227
  363. package/examples/jsm/nodes/utils/RemapNode.js +42 -42
  364. package/examples/jsm/nodes/utils/RotateNode.js +68 -68
  365. package/examples/jsm/nodes/utils/RotateUVNode.js +35 -35
  366. package/examples/jsm/nodes/utils/SetNode.js +62 -62
  367. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -37
  368. package/examples/jsm/nodes/utils/SplitNode.js +112 -112
  369. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -41
  370. package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -91
  371. package/examples/jsm/nodes/utils/TimerNode.js +94 -94
  372. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -62
  373. package/examples/jsm/objects/GroundedSkybox.js +50 -50
  374. package/examples/jsm/objects/InstancedPoints.js +21 -21
  375. package/examples/jsm/objects/Lensflare.js +397 -397
  376. package/examples/jsm/objects/MarchingCubes.js +1176 -1176
  377. package/examples/jsm/objects/QuadMesh.js +66 -66
  378. package/examples/jsm/objects/Reflector.js +264 -264
  379. package/examples/jsm/objects/ReflectorForSSRPass.js +352 -352
  380. package/examples/jsm/objects/Refractor.js +327 -327
  381. package/examples/jsm/objects/ShadowMesh.js +80 -80
  382. package/examples/jsm/objects/Sky.js +219 -219
  383. package/examples/jsm/objects/Water.js +333 -333
  384. package/examples/jsm/objects/Water2.js +361 -361
  385. package/examples/jsm/offscreen/jank.js +45 -45
  386. package/examples/jsm/offscreen/offscreen.js +8 -8
  387. package/examples/jsm/offscreen/scene.js +86 -86
  388. package/examples/jsm/physics/AmmoPhysics.js +306 -306
  389. package/examples/jsm/physics/RapierPhysics.js +220 -220
  390. package/examples/jsm/postprocessing/AfterimagePass.js +104 -104
  391. package/examples/jsm/postprocessing/BloomPass.js +172 -172
  392. package/examples/jsm/postprocessing/BokehPass.js +141 -141
  393. package/examples/jsm/postprocessing/ClearPass.js +46 -46
  394. package/examples/jsm/postprocessing/CubeTexturePass.js +85 -85
  395. package/examples/jsm/postprocessing/DotScreenPass.js +65 -65
  396. package/examples/jsm/postprocessing/EffectComposer.js +231 -231
  397. package/examples/jsm/postprocessing/FilmPass.js +64 -64
  398. package/examples/jsm/postprocessing/GTAOPass.js +582 -582
  399. package/examples/jsm/postprocessing/GlitchPass.js +128 -128
  400. package/examples/jsm/postprocessing/HalftonePass.js +79 -79
  401. package/examples/jsm/postprocessing/LUTPass.js +174 -174
  402. package/examples/jsm/postprocessing/MaskPass.js +104 -104
  403. package/examples/jsm/postprocessing/OutlinePass.js +654 -654
  404. package/examples/jsm/postprocessing/OutputPass.js +97 -97
  405. package/examples/jsm/postprocessing/Pass.js +95 -95
  406. package/examples/jsm/postprocessing/RenderPass.js +99 -99
  407. package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -235
  408. package/examples/jsm/postprocessing/SAOPass.js +335 -335
  409. package/examples/jsm/postprocessing/SMAAPass.js +199 -199
  410. package/examples/jsm/postprocessing/SSAARenderPass.js +228 -228
  411. package/examples/jsm/postprocessing/SSAOPass.js +420 -420
  412. package/examples/jsm/postprocessing/SSRPass.js +641 -641
  413. package/examples/jsm/postprocessing/SavePass.js +79 -79
  414. package/examples/jsm/postprocessing/ShaderPass.js +77 -77
  415. package/examples/jsm/postprocessing/TAARenderPass.js +188 -188
  416. package/examples/jsm/postprocessing/TexturePass.js +67 -67
  417. package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -415
  418. package/examples/jsm/renderers/CSS2DRenderer.js +215 -215
  419. package/examples/jsm/renderers/CSS3DRenderer.js +329 -329
  420. package/examples/jsm/renderers/Projector.js +918 -918
  421. package/examples/jsm/renderers/SVGRenderer.js +556 -556
  422. package/examples/jsm/renderers/common/Animation.js +47 -47
  423. package/examples/jsm/renderers/common/Attributes.js +75 -75
  424. package/examples/jsm/renderers/common/Backend.js +195 -195
  425. package/examples/jsm/renderers/common/Background.js +134 -134
  426. package/examples/jsm/renderers/common/Binding.js +25 -25
  427. package/examples/jsm/renderers/common/Bindings.js +173 -173
  428. package/examples/jsm/renderers/common/Buffer.js +38 -38
  429. package/examples/jsm/renderers/common/BufferUtils.js +33 -33
  430. package/examples/jsm/renderers/common/ChainMap.js +89 -89
  431. package/examples/jsm/renderers/common/ClippingContext.js +165 -165
  432. package/examples/jsm/renderers/common/Color4.js +37 -37
  433. package/examples/jsm/renderers/common/ComputePipeline.js +17 -17
  434. package/examples/jsm/renderers/common/Constants.js +14 -14
  435. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -65
  436. package/examples/jsm/renderers/common/DataMap.js +54 -54
  437. package/examples/jsm/renderers/common/Geometries.js +215 -215
  438. package/examples/jsm/renderers/common/Info.js +107 -107
  439. package/examples/jsm/renderers/common/Pipeline.js +13 -13
  440. package/examples/jsm/renderers/common/Pipelines.js +322 -322
  441. package/examples/jsm/renderers/common/PostProcessing.js +25 -25
  442. package/examples/jsm/renderers/common/ProgrammableStage.js +20 -20
  443. package/examples/jsm/renderers/common/RenderContext.js +43 -43
  444. package/examples/jsm/renderers/common/RenderContexts.js +63 -63
  445. package/examples/jsm/renderers/common/RenderList.js +186 -186
  446. package/examples/jsm/renderers/common/RenderLists.js +38 -38
  447. package/examples/jsm/renderers/common/RenderObject.js +221 -221
  448. package/examples/jsm/renderers/common/RenderObjects.js +93 -93
  449. package/examples/jsm/renderers/common/RenderPipeline.js +16 -16
  450. package/examples/jsm/renderers/common/Renderer.js +1304 -1304
  451. package/examples/jsm/renderers/common/SampledTexture.js +83 -83
  452. package/examples/jsm/renderers/common/Sampler.js +18 -18
  453. package/examples/jsm/renderers/common/StorageBuffer.js +17 -17
  454. package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -17
  455. package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -17
  456. package/examples/jsm/renderers/common/StorageTexture.js +20 -20
  457. package/examples/jsm/renderers/common/Textures.js +344 -344
  458. package/examples/jsm/renderers/common/Uniform.js +140 -140
  459. package/examples/jsm/renderers/common/UniformBuffer.js +15 -15
  460. package/examples/jsm/renderers/common/UniformsGroup.js +301 -301
  461. package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +44 -44
  462. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +49 -49
  463. package/examples/jsm/renderers/common/nodes/NodeSampler.js +15 -15
  464. package/examples/jsm/renderers/common/nodes/NodeStorageBuffer.js +23 -23
  465. package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -135
  466. package/examples/jsm/renderers/common/nodes/NodeUniformBuffer.js +23 -23
  467. package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -44
  468. package/examples/jsm/renderers/common/nodes/Nodes.js +496 -496
  469. package/examples/jsm/renderers/webgl/WebGLBackend.js +1382 -1382
  470. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +804 -804
  471. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +258 -258
  472. package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -36
  473. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -11
  474. package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +36 -36
  475. package/examples/jsm/renderers/webgl/utils/WebGLState.js +738 -738
  476. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +694 -694
  477. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +285 -285
  478. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +320 -320
  479. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +26 -26
  480. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +794 -794
  481. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +51 -51
  482. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +1322 -1322
  483. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +53 -53
  484. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +1078 -1078
  485. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -104
  486. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -14
  487. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +293 -293
  488. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +244 -244
  489. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -324
  490. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +591 -591
  491. package/examples/jsm/renderers/webgpu/utils/WebGPUTexturePassUtils.js +285 -285
  492. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +1040 -1040
  493. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +93 -93
  494. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +89 -89
  495. package/examples/jsm/shaders/AfterimageShader.js +58 -58
  496. package/examples/jsm/shaders/BasicShader.js +29 -29
  497. package/examples/jsm/shaders/BleachBypassShader.js +62 -62
  498. package/examples/jsm/shaders/BlendShader.js +49 -49
  499. package/examples/jsm/shaders/BokehShader.js +145 -145
  500. package/examples/jsm/shaders/BokehShader2.js +397 -397
  501. package/examples/jsm/shaders/BrightnessContrastShader.js +56 -56
  502. package/examples/jsm/shaders/ColorCorrectionShader.js +52 -52
  503. package/examples/jsm/shaders/ColorifyShader.js +51 -51
  504. package/examples/jsm/shaders/ConvolutionShader.js +103 -103
  505. package/examples/jsm/shaders/CopyShader.js +45 -45
  506. package/examples/jsm/shaders/DOFMipMapShader.js +56 -56
  507. package/examples/jsm/shaders/DepthLimitedBlurShader.js +171 -171
  508. package/examples/jsm/shaders/DigitalGlitch.js +101 -101
  509. package/examples/jsm/shaders/DotScreenShader.js +70 -70
  510. package/examples/jsm/shaders/ExposureShader.js +44 -44
  511. package/examples/jsm/shaders/FXAAShader.js +288 -288
  512. package/examples/jsm/shaders/FilmShader.js +59 -59
  513. package/examples/jsm/shaders/FocusShader.js +89 -89
  514. package/examples/jsm/shaders/FreiChenShader.js +96 -96
  515. package/examples/jsm/shaders/GTAOShader.js +424 -424
  516. package/examples/jsm/shaders/GammaCorrectionShader.js +43 -43
  517. package/examples/jsm/shaders/GodRaysShader.js +321 -321
  518. package/examples/jsm/shaders/HalftoneShader.js +312 -312
  519. package/examples/jsm/shaders/HorizontalBlurShader.js +59 -59
  520. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +63 -63
  521. package/examples/jsm/shaders/HueSaturationShader.js +67 -67
  522. package/examples/jsm/shaders/KaleidoShader.js +58 -58
  523. package/examples/jsm/shaders/LuminosityHighPassShader.js +66 -66
  524. package/examples/jsm/shaders/LuminosityShader.js +48 -48
  525. package/examples/jsm/shaders/MMDToonShader.js +134 -134
  526. package/examples/jsm/shaders/MirrorShader.js +56 -56
  527. package/examples/jsm/shaders/NormalMapShader.js +55 -55
  528. package/examples/jsm/shaders/OutputShader.js +85 -85
  529. package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -226
  530. package/examples/jsm/shaders/RGBShiftShader.js +54 -54
  531. package/examples/jsm/shaders/SAOShader.js +179 -179
  532. package/examples/jsm/shaders/SMAAShader.js +466 -466
  533. package/examples/jsm/shaders/SSAOShader.js +300 -300
  534. package/examples/jsm/shaders/SSRShader.js +370 -370
  535. package/examples/jsm/shaders/SepiaShader.js +52 -52
  536. package/examples/jsm/shaders/SobelOperatorShader.js +92 -92
  537. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +90 -90
  538. package/examples/jsm/shaders/TechnicolorShader.js +45 -45
  539. package/examples/jsm/shaders/ToonShader.js +326 -326
  540. package/examples/jsm/shaders/TriangleBlurShader.js +74 -74
  541. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +47 -47
  542. package/examples/jsm/shaders/VelocityShader.js +130 -130
  543. package/examples/jsm/shaders/VerticalBlurShader.js +59 -59
  544. package/examples/jsm/shaders/VerticalTiltShiftShader.js +63 -63
  545. package/examples/jsm/shaders/VignetteShader.js +51 -51
  546. package/examples/jsm/shaders/VolumeShader.js +289 -289
  547. package/examples/jsm/shaders/WaterRefractionShader.js +95 -95
  548. package/examples/jsm/textures/FlakesTexture.js +40 -40
  549. package/examples/jsm/transpiler/AST.js +270 -270
  550. package/examples/jsm/transpiler/GLSLDecoder.js +941 -941
  551. package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -49
  552. package/examples/jsm/transpiler/TSLEncoder.js +715 -715
  553. package/examples/jsm/transpiler/Transpiler.js +18 -18
  554. package/examples/jsm/utils/BufferGeometryUtils.js +1371 -1371
  555. package/examples/jsm/utils/CameraUtils.js +73 -73
  556. package/examples/jsm/utils/GPUStatsPanel.js +128 -128
  557. package/examples/jsm/utils/GeometryCompressionUtils.js +639 -639
  558. package/examples/jsm/utils/GeometryUtils.js +221 -221
  559. package/examples/jsm/utils/LDrawUtils.js +202 -202
  560. package/examples/jsm/utils/PackedPhongMaterial.js +178 -178
  561. package/examples/jsm/utils/SceneUtils.js +254 -254
  562. package/examples/jsm/utils/ShadowMapViewer.js +210 -210
  563. package/examples/jsm/utils/SkeletonUtils.js +424 -424
  564. package/examples/jsm/utils/SortUtils.js +160 -160
  565. package/examples/jsm/utils/TextureUtils.js +98 -98
  566. package/examples/jsm/utils/UVsDebug.js +165 -165
  567. package/examples/jsm/utils/WorkerPool.js +102 -102
  568. package/examples/jsm/webxr/ARButton.js +232 -232
  569. package/examples/jsm/webxr/OculusHandModel.js +109 -109
  570. package/examples/jsm/webxr/OculusHandPointerModel.js +416 -416
  571. package/examples/jsm/webxr/Text2D.js +38 -38
  572. package/examples/jsm/webxr/VRButton.js +233 -233
  573. package/examples/jsm/webxr/XRButton.js +223 -223
  574. package/examples/jsm/webxr/XRControllerModelFactory.js +323 -323
  575. package/examples/jsm/webxr/XREstimatedLight.js +223 -223
  576. package/examples/jsm/webxr/XRHandMeshModel.js +116 -116
  577. package/examples/jsm/webxr/XRHandModelFactory.js +105 -105
  578. package/examples/jsm/webxr/XRHandPrimitiveModel.js +105 -105
  579. package/examples/jsm/webxr/XRPlanes.js +100 -100
  580. package/package.json +129 -129
  581. package/src/Three.Legacy.js +21 -21
  582. package/src/Three.js +183 -183
  583. package/src/animation/AnimationAction.js +700 -700
  584. package/src/animation/AnimationClip.js +473 -473
  585. package/src/animation/AnimationMixer.js +770 -770
  586. package/src/animation/AnimationObjectGroup.js +387 -387
  587. package/src/animation/AnimationUtils.js +356 -356
  588. package/src/animation/KeyframeTrack.js +462 -462
  589. package/src/animation/PropertyBinding.js +719 -719
  590. package/src/animation/PropertyMixer.js +318 -318
  591. package/src/animation/tracks/BooleanKeyframeTrack.js +19 -19
  592. package/src/animation/tracks/ColorKeyframeTrack.js +15 -15
  593. package/src/animation/tracks/NumberKeyframeTrack.js +12 -12
  594. package/src/animation/tracks/QuaternionKeyframeTrack.js +23 -23
  595. package/src/animation/tracks/StringKeyframeTrack.js +15 -15
  596. package/src/animation/tracks/VectorKeyframeTrack.js +12 -12
  597. package/src/audio/Audio.js +400 -400
  598. package/src/audio/AudioAnalyser.js +40 -40
  599. package/src/audio/AudioContext.js +25 -25
  600. package/src/audio/AudioListener.js +140 -140
  601. package/src/audio/PositionalAudio.js +146 -146
  602. package/src/cameras/ArrayCamera.js +17 -17
  603. package/src/cameras/Camera.js +69 -69
  604. package/src/cameras/CubeCamera.js +173 -173
  605. package/src/cameras/OrthographicCamera.js +136 -136
  606. package/src/cameras/PerspectiveCamera.js +268 -268
  607. package/src/cameras/StereoCamera.js +100 -100
  608. package/src/constants.js +217 -217
  609. package/src/core/BufferAttribute.js +639 -639
  610. package/src/core/BufferGeometry.js +1073 -1073
  611. package/src/core/Clock.js +74 -74
  612. package/src/core/EventDispatcher.js +87 -87
  613. package/src/core/GLBufferAttribute.js +60 -60
  614. package/src/core/InstancedBufferAttribute.js +39 -39
  615. package/src/core/InstancedBufferGeometry.js +40 -40
  616. package/src/core/InstancedInterleavedBuffer.js +48 -48
  617. package/src/core/InterleavedBuffer.js +166 -166
  618. package/src/core/InterleavedBufferAttribute.js +351 -351
  619. package/src/core/Layers.js +60 -60
  620. package/src/core/Object3D.js +1019 -1019
  621. package/src/core/Raycaster.js +124 -124
  622. package/src/core/RenderTarget.js +154 -154
  623. package/src/core/Uniform.js +17 -17
  624. package/src/core/UniformsGroup.js +98 -98
  625. package/src/extras/DataUtils.js +176 -176
  626. package/src/extras/Earcut.js +789 -789
  627. package/src/extras/ImageUtils.js +129 -129
  628. package/src/extras/PMREMGenerator.js +912 -912
  629. package/src/extras/ShapeUtils.js +92 -92
  630. package/src/extras/core/Curve.js +416 -416
  631. package/src/extras/core/CurvePath.js +255 -255
  632. package/src/extras/core/Interpolations.js +79 -79
  633. package/src/extras/core/Path.js +196 -196
  634. package/src/extras/core/Shape.js +102 -102
  635. package/src/extras/core/ShapePath.js +291 -291
  636. package/src/extras/curves/ArcCurve.js +17 -17
  637. package/src/extras/curves/CatmullRomCurve3.js +255 -255
  638. package/src/extras/curves/CubicBezierCurve.js +78 -78
  639. package/src/extras/curves/CubicBezierCurve3.js +79 -79
  640. package/src/extras/curves/Curves.js +10 -10
  641. package/src/extras/curves/EllipseCurve.js +156 -156
  642. package/src/extras/curves/LineCurve.js +92 -92
  643. package/src/extras/curves/LineCurve3.js +92 -92
  644. package/src/extras/curves/QuadraticBezierCurve.js +74 -74
  645. package/src/extras/curves/QuadraticBezierCurve3.js +75 -75
  646. package/src/extras/curves/SplineCurve.js +97 -97
  647. package/src/geometries/BoxGeometry.js +180 -180
  648. package/src/geometries/CapsuleGeometry.js +33 -33
  649. package/src/geometries/CircleGeometry.js +101 -101
  650. package/src/geometries/ConeGeometry.js +31 -31
  651. package/src/geometries/CylinderGeometry.js +286 -286
  652. package/src/geometries/DodecahedronGeometry.js +66 -66
  653. package/src/geometries/EdgesGeometry.js +152 -152
  654. package/src/geometries/ExtrudeGeometry.js +814 -814
  655. package/src/geometries/Geometries.js +21 -21
  656. package/src/geometries/IcosahedronGeometry.js +42 -42
  657. package/src/geometries/LatheGeometry.js +189 -189
  658. package/src/geometries/OctahedronGeometry.js +37 -37
  659. package/src/geometries/PlaneGeometry.js +98 -98
  660. package/src/geometries/PolyhedronGeometry.js +319 -319
  661. package/src/geometries/RingGeometry.js +128 -128
  662. package/src/geometries/ShapeGeometry.js +195 -195
  663. package/src/geometries/SphereGeometry.js +137 -137
  664. package/src/geometries/TetrahedronGeometry.js +34 -34
  665. package/src/geometries/TorusGeometry.js +120 -120
  666. package/src/geometries/TorusKnotGeometry.js +167 -167
  667. package/src/geometries/TubeGeometry.js +203 -203
  668. package/src/geometries/WireframeGeometry.js +147 -147
  669. package/src/helpers/ArrowHelper.js +114 -114
  670. package/src/helpers/AxesHelper.js +68 -68
  671. package/src/helpers/Box3Helper.js +55 -55
  672. package/src/helpers/BoxHelper.js +113 -113
  673. package/src/helpers/CameraHelper.js +269 -269
  674. package/src/helpers/DirectionalLightHelper.js +93 -93
  675. package/src/helpers/GridHelper.js +56 -56
  676. package/src/helpers/HemisphereLightHelper.js +88 -88
  677. package/src/helpers/PlaneHelper.js +63 -63
  678. package/src/helpers/PointLightHelper.js +92 -92
  679. package/src/helpers/PolarGridHelper.js +96 -96
  680. package/src/helpers/SkeletonHelper.js +128 -128
  681. package/src/helpers/SpotLightHelper.js +111 -111
  682. package/src/lights/AmbientLight.js +17 -17
  683. package/src/lights/DirectionalLight.js +43 -43
  684. package/src/lights/DirectionalLightShadow.js +16 -16
  685. package/src/lights/HemisphereLight.js +34 -34
  686. package/src/lights/Light.js +58 -58
  687. package/src/lights/LightProbe.js +47 -47
  688. package/src/lights/LightShadow.js +147 -147
  689. package/src/lights/PointLight.js +57 -57
  690. package/src/lights/PointLightShadow.js +96 -96
  691. package/src/lights/RectAreaLight.js +56 -56
  692. package/src/lights/SpotLight.js +71 -71
  693. package/src/lights/SpotLightShadow.js +50 -50
  694. package/src/loaders/AnimationLoader.js +66 -66
  695. package/src/loaders/AudioLoader.js +66 -66
  696. package/src/loaders/BufferGeometryLoader.js +217 -217
  697. package/src/loaders/Cache.js +42 -42
  698. package/src/loaders/CompressedTextureLoader.js +134 -134
  699. package/src/loaders/CubeTextureLoader.js +58 -58
  700. package/src/loaders/DataTextureLoader.js +131 -131
  701. package/src/loaders/FileLoader.js +284 -284
  702. package/src/loaders/ImageBitmapLoader.js +123 -123
  703. package/src/loaders/ImageLoader.js +91 -91
  704. package/src/loaders/Loader.js +72 -72
  705. package/src/loaders/LoaderUtils.js +75 -75
  706. package/src/loaders/LoadingManager.js +142 -142
  707. package/src/loaders/MaterialLoader.js +373 -373
  708. package/src/loaders/ObjectLoader.js +1149 -1149
  709. package/src/loaders/TextureLoader.js +41 -41
  710. package/src/materials/LineBasicMaterial.js +49 -49
  711. package/src/materials/LineDashedMaterial.js +35 -35
  712. package/src/materials/Material.js +523 -523
  713. package/src/materials/Materials.js +39 -39
  714. package/src/materials/MeshBasicMaterial.js +84 -84
  715. package/src/materials/MeshDepthMaterial.js +54 -54
  716. package/src/materials/MeshDistanceMaterial.js +43 -43
  717. package/src/materials/MeshLambertMaterial.js +119 -119
  718. package/src/materials/MeshMatcapMaterial.js +81 -81
  719. package/src/materials/MeshNormalMaterial.js +61 -61
  720. package/src/materials/MeshPhongMaterial.js +123 -123
  721. package/src/materials/MeshPhysicalMaterial.js +224 -224
  722. package/src/materials/MeshStandardMaterial.js +127 -127
  723. package/src/materials/MeshToonMaterial.js +102 -102
  724. package/src/materials/PointsMaterial.js +50 -50
  725. package/src/materials/RawShaderMaterial.js +17 -17
  726. package/src/materials/ShaderMaterial.js +189 -189
  727. package/src/materials/ShadowMaterial.js +37 -37
  728. package/src/materials/SpriteMaterial.js +54 -54
  729. package/src/math/Box2.js +204 -204
  730. package/src/math/Box3.js +534 -534
  731. package/src/math/Color.js +623 -623
  732. package/src/math/ColorManagement.js +139 -139
  733. package/src/math/Cylindrical.js +61 -61
  734. package/src/math/Euler.js +315 -315
  735. package/src/math/Frustum.js +186 -186
  736. package/src/math/Interpolant.js +241 -241
  737. package/src/math/Line3.js +115 -115
  738. package/src/math/MathUtils.js +363 -363
  739. package/src/math/Matrix3.js +388 -388
  740. package/src/math/Matrix4.js +915 -915
  741. package/src/math/Plane.js +205 -205
  742. package/src/math/Quaternion.js +686 -686
  743. package/src/math/Ray.js +493 -493
  744. package/src/math/Sphere.js +245 -245
  745. package/src/math/Spherical.js +86 -86
  746. package/src/math/SphericalHarmonics3.js +243 -243
  747. package/src/math/Triangle.js +311 -311
  748. package/src/math/Vector2.js +480 -480
  749. package/src/math/Vector3.js +724 -724
  750. package/src/math/Vector4.js +644 -644
  751. package/src/math/interpolants/CubicInterpolant.js +150 -150
  752. package/src/math/interpolants/DiscreteInterpolant.js +26 -26
  753. package/src/math/interpolants/LinearInterpolant.js +38 -38
  754. package/src/math/interpolants/QuaternionLinearInterpolant.js +39 -39
  755. package/src/objects/BatchedMesh.js +1020 -1020
  756. package/src/objects/Bone.js +17 -17
  757. package/src/objects/Group.js +17 -17
  758. package/src/objects/InstancedMesh.js +267 -267
  759. package/src/objects/LOD.js +214 -214
  760. package/src/objects/Line.js +222 -222
  761. package/src/objects/LineLoop.js +17 -17
  762. package/src/objects/LineSegments.js +55 -55
  763. package/src/objects/Mesh.js +428 -428
  764. package/src/objects/Points.js +166 -166
  765. package/src/objects/Skeleton.js +277 -277
  766. package/src/objects/SkinnedMesh.js +257 -257
  767. package/src/objects/Sprite.js +181 -181
  768. package/src/renderers/WebGL1Renderer.js +7 -7
  769. package/src/renderers/WebGL3DRenderTarget.js +22 -22
  770. package/src/renderers/WebGLArrayRenderTarget.js +22 -22
  771. package/src/renderers/WebGLCubeRenderTarget.js +146 -146
  772. package/src/renderers/WebGLRenderTarget.js +15 -15
  773. package/src/renderers/WebGLRenderer.js +2615 -2615
  774. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -7
  775. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -68
  776. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -7
  777. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -7
  778. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -16
  779. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -5
  780. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -26
  781. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -8
  782. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -19
  783. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -5
  784. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -9
  785. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -9
  786. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -33
  787. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -43
  788. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -7
  789. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -10
  790. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -21
  791. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -78
  792. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -9
  793. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -7
  794. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -7
  795. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +11 -11
  796. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +11 -11
  797. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +11 -11
  798. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +23 -23
  799. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -3
  800. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +44 -44
  801. package/src/renderers/shaders/ShaderChunk/common.glsl.js +147 -147
  802. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -186
  803. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -5
  804. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -5
  805. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -63
  806. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -9
  807. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -7
  808. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -7
  809. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -20
  810. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +9 -9
  811. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -7
  812. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +15 -15
  813. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +62 -62
  814. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -21
  815. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -22
  816. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -69
  817. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -37
  818. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -17
  819. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -19
  820. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -7
  821. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -7
  822. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -27
  823. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -120
  824. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -14
  825. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +10 -10
  826. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -8
  827. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +202 -202
  828. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +13 -13
  829. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +40 -40
  830. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -5
  831. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -28
  832. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +228 -228
  833. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -7
  834. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -32
  835. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +151 -151
  836. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +562 -562
  837. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -4
  838. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -26
  839. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -9
  840. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -9
  841. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +16 -16
  842. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +22 -22
  843. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +21 -21
  844. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +11 -11
  845. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -27
  846. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -27
  847. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -12
  848. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -7
  849. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -24
  850. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -14
  851. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +27 -27
  852. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +47 -47
  853. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +36 -36
  854. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -76
  855. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +33 -33
  856. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -14
  857. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -14
  858. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -14
  859. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -43
  860. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -11
  861. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +68 -68
  862. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +8 -8
  863. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -19
  864. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -12
  865. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -7
  866. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +314 -314
  867. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +68 -68
  868. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +68 -68
  869. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -66
  870. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -10
  871. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -25
  872. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -15
  873. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -20
  874. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -14
  875. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -7
  876. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -7
  877. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +192 -192
  878. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -36
  879. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +201 -201
  880. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -119
  881. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -145
  882. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -122
  883. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -21
  884. package/src/renderers/shaders/ShaderChunk.js +272 -272
  885. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -40
  886. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +63 -63
  887. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -36
  888. package/src/renderers/shaders/ShaderLib/depth.glsl.js +97 -97
  889. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +78 -78
  890. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -35
  891. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -76
  892. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -116
  893. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +125 -125
  894. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -112
  895. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +87 -87
  896. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +127 -127
  897. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +225 -225
  898. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +119 -119
  899. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -87
  900. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -58
  901. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +81 -81
  902. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +53 -53
  903. package/src/renderers/shaders/ShaderLib.js +360 -360
  904. package/src/renderers/shaders/UniformsLib.js +231 -231
  905. package/src/renderers/shaders/UniformsUtils.js +104 -104
  906. package/src/renderers/webgl/WebGLAnimation.js +53 -53
  907. package/src/renderers/webgl/WebGLAttributes.js +229 -229
  908. package/src/renderers/webgl/WebGLBackground.js +257 -257
  909. package/src/renderers/webgl/WebGLBindingStates.js +631 -631
  910. package/src/renderers/webgl/WebGLBufferRenderer.js +92 -92
  911. package/src/renderers/webgl/WebGLCapabilities.js +120 -120
  912. package/src/renderers/webgl/WebGLClipping.js +171 -171
  913. package/src/renderers/webgl/WebGLCubeMaps.js +99 -99
  914. package/src/renderers/webgl/WebGLCubeUVMaps.js +132 -132
  915. package/src/renderers/webgl/WebGLExtensions.js +97 -97
  916. package/src/renderers/webgl/WebGLGeometries.js +211 -211
  917. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +102 -102
  918. package/src/renderers/webgl/WebGLInfo.js +71 -71
  919. package/src/renderers/webgl/WebGLLights.js +590 -590
  920. package/src/renderers/webgl/WebGLMaterials.js +590 -590
  921. package/src/renderers/webgl/WebGLMorphtargets.js +307 -307
  922. package/src/renderers/webgl/WebGLObjects.js +92 -92
  923. package/src/renderers/webgl/WebGLProgram.js +1120 -1120
  924. package/src/renderers/webgl/WebGLPrograms.js +664 -664
  925. package/src/renderers/webgl/WebGLProperties.js +48 -48
  926. package/src/renderers/webgl/WebGLRenderLists.js +238 -238
  927. package/src/renderers/webgl/WebGLRenderStates.js +107 -107
  928. package/src/renderers/webgl/WebGLShader.js +12 -12
  929. package/src/renderers/webgl/WebGLShaderCache.js +124 -124
  930. package/src/renderers/webgl/WebGLShadowMap.js +424 -424
  931. package/src/renderers/webgl/WebGLState.js +1318 -1318
  932. package/src/renderers/webgl/WebGLTextures.js +2213 -2213
  933. package/src/renderers/webgl/WebGLUniforms.js +1156 -1156
  934. package/src/renderers/webgl/WebGLUniformsGroups.js +392 -392
  935. package/src/renderers/webgl/WebGLUtils.js +283 -283
  936. package/src/renderers/webxr/WebXRController.js +343 -343
  937. package/src/renderers/webxr/WebXRDepthSensing.js +105 -105
  938. package/src/renderers/webxr/WebXRManager.js +824 -824
  939. package/src/scenes/Fog.js +38 -38
  940. package/src/scenes/FogExp2.js +35 -35
  941. package/src/scenes/Scene.js +71 -71
  942. package/src/textures/CanvasTexture.js +17 -17
  943. package/src/textures/CompressedArrayTexture.js +18 -18
  944. package/src/textures/CompressedCubeTexture.js +19 -19
  945. package/src/textures/CompressedTexture.js +28 -28
  946. package/src/textures/CubeTexture.js +33 -33
  947. package/src/textures/Data3DTexture.js +35 -35
  948. package/src/textures/DataArrayTexture.js +27 -27
  949. package/src/textures/DataTexture.js +22 -22
  950. package/src/textures/DepthTexture.js +58 -58
  951. package/src/textures/FramebufferTexture.js +23 -23
  952. package/src/textures/Source.js +128 -128
  953. package/src/textures/Texture.js +310 -310
  954. package/src/textures/VideoTexture.js +55 -55
  955. package/src/utils.js +91 -91
@@ -1,2615 +1,2615 @@
1
- import {
2
- REVISION,
3
- BackSide,
4
- FrontSide,
5
- DoubleSide,
6
- RGBAFormat,
7
- HalfFloatType,
8
- FloatType,
9
- UnsignedByteType,
10
- NoToneMapping,
11
- LinearMipmapLinearFilter,
12
- SRGBColorSpace,
13
- LinearSRGBColorSpace,
14
- sRGBEncoding,
15
- LinearEncoding,
16
- RGBAIntegerFormat,
17
- RGIntegerFormat,
18
- RedIntegerFormat,
19
- UnsignedIntType,
20
- UnsignedShortType,
21
- UnsignedInt248Type,
22
- UnsignedShort4444Type,
23
- UnsignedShort5551Type,
24
- WebGLCoordinateSystem,
25
- DisplayP3ColorSpace,
26
- LinearDisplayP3ColorSpace
27
- } from '../constants.js';
28
- import { Color } from '../math/Color.js';
29
- import { Frustum } from '../math/Frustum.js';
30
- import { Matrix4 } from '../math/Matrix4.js';
31
- import { Vector2 } from '../math/Vector2.js';
32
- import { Vector3 } from '../math/Vector3.js';
33
- import { Vector4 } from '../math/Vector4.js';
34
- import { floorPowerOfTwo } from '../math/MathUtils.js';
35
- import { WebGLAnimation } from './webgl/WebGLAnimation.js';
36
- import { WebGLAttributes } from './webgl/WebGLAttributes.js';
37
- import { WebGLBackground } from './webgl/WebGLBackground.js';
38
- import { WebGLBindingStates } from './webgl/WebGLBindingStates.js';
39
- import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
40
- import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
41
- import { WebGLClipping } from './webgl/WebGLClipping.js';
42
- import { WebGLCubeMaps } from './webgl/WebGLCubeMaps.js';
43
- import { WebGLCubeUVMaps } from './webgl/WebGLCubeUVMaps.js';
44
- import { WebGLExtensions } from './webgl/WebGLExtensions.js';
45
- import { WebGLGeometries } from './webgl/WebGLGeometries.js';
46
- import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
47
- import { WebGLInfo } from './webgl/WebGLInfo.js';
48
- import { WebGLMorphtargets } from './webgl/WebGLMorphtargets.js';
49
- import { WebGLObjects } from './webgl/WebGLObjects.js';
50
- import { WebGLPrograms } from './webgl/WebGLPrograms.js';
51
- import { WebGLProperties } from './webgl/WebGLProperties.js';
52
- import { WebGLRenderLists } from './webgl/WebGLRenderLists.js';
53
- import { WebGLRenderStates } from './webgl/WebGLRenderStates.js';
54
- import { WebGLRenderTarget } from './WebGLRenderTarget.js';
55
- import { WebGLShadowMap } from './webgl/WebGLShadowMap.js';
56
- import { WebGLState } from './webgl/WebGLState.js';
57
- import { WebGLTextures } from './webgl/WebGLTextures.js';
58
- import { WebGLUniforms } from './webgl/WebGLUniforms.js';
59
- import { WebGLUtils } from './webgl/WebGLUtils.js';
60
- import { WebXRManager } from './webxr/WebXRManager.js';
61
- import { WebGLMaterials } from './webgl/WebGLMaterials.js';
62
- import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
63
- import { createCanvasElement } from '../utils.js';
64
- import { ColorManagement } from '../math/ColorManagement.js';
65
-
66
- class WebGLRenderer {
67
-
68
- constructor( parameters = {} ) {
69
-
70
- const {
71
- canvas = createCanvasElement(),
72
- context = null,
73
- depth = true,
74
- stencil = true,
75
- alpha = false,
76
- antialias = false,
77
- premultipliedAlpha = true,
78
- preserveDrawingBuffer = false,
79
- powerPreference = 'default',
80
- failIfMajorPerformanceCaveat = false,
81
- } = parameters;
82
-
83
- this.isWebGLRenderer = true;
84
-
85
- let _alpha;
86
-
87
- if ( context !== null ) {
88
-
89
- _alpha = context.getContextAttributes().alpha;
90
-
91
- } else {
92
-
93
- _alpha = alpha;
94
-
95
- }
96
-
97
- const uintClearColor = new Uint32Array( 4 );
98
- const intClearColor = new Int32Array( 4 );
99
-
100
- let currentRenderList = null;
101
- let currentRenderState = null;
102
-
103
- // render() can be called from within a callback triggered by another render.
104
- // We track this so that the nested render call gets its list and state isolated from the parent render call.
105
-
106
- const renderListStack = [];
107
- const renderStateStack = [];
108
-
109
- // public properties
110
-
111
- this.domElement = canvas;
112
-
113
- // Debug configuration container
114
- this.debug = {
115
-
116
- /**
117
- * Enables error checking and reporting when shader programs are being compiled
118
- * @type {boolean}
119
- */
120
- checkShaderErrors: true,
121
- /**
122
- * Callback for custom error reporting.
123
- * @type {?Function}
124
- */
125
- onShaderError: null
126
- };
127
-
128
- // clearing
129
-
130
- this.autoClear = true;
131
- this.autoClearColor = true;
132
- this.autoClearDepth = true;
133
- this.autoClearStencil = true;
134
-
135
- // scene graph
136
-
137
- this.sortObjects = true;
138
-
139
- // user-defined clipping
140
-
141
- this.clippingPlanes = [];
142
- this.localClippingEnabled = false;
143
-
144
- // physically based shading
145
-
146
- this._outputColorSpace = SRGBColorSpace;
147
-
148
- // physical lights
149
-
150
- this._useLegacyLights = false;
151
-
152
- // tone mapping
153
-
154
- this.toneMapping = NoToneMapping;
155
- this.toneMappingExposure = 1.0;
156
-
157
- // internal properties
158
-
159
- const _this = this;
160
-
161
- let _isContextLost = false;
162
-
163
- // internal state cache
164
-
165
- let _currentActiveCubeFace = 0;
166
- let _currentActiveMipmapLevel = 0;
167
- let _currentRenderTarget = null;
168
- let _currentMaterialId = - 1;
169
-
170
- let _currentCamera = null;
171
-
172
- const _currentViewport = new Vector4();
173
- const _currentScissor = new Vector4();
174
- let _currentScissorTest = null;
175
-
176
- const _currentClearColor = new Color( 0x000000 );
177
- let _currentClearAlpha = 0;
178
-
179
- //
180
-
181
- let _width = canvas.width;
182
- let _height = canvas.height;
183
-
184
- let _pixelRatio = 1;
185
- let _opaqueSort = null;
186
- let _transparentSort = null;
187
-
188
- const _viewport = new Vector4( 0, 0, _width, _height );
189
- const _scissor = new Vector4( 0, 0, _width, _height );
190
- let _scissorTest = false;
191
-
192
- // frustum
193
-
194
- const _frustum = new Frustum();
195
-
196
- // clipping
197
-
198
- let _clippingEnabled = false;
199
- let _localClippingEnabled = false;
200
-
201
- // transmission
202
-
203
- let _transmissionRenderTarget = null;
204
-
205
- // camera matrices cache
206
-
207
- const _projScreenMatrix = new Matrix4();
208
-
209
- const _vector2 = new Vector2();
210
- const _vector3 = new Vector3();
211
-
212
- const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
213
-
214
- function getTargetPixelRatio() {
215
-
216
- return _currentRenderTarget === null ? _pixelRatio : 1;
217
-
218
- }
219
-
220
- // initialize
221
-
222
- let _gl = context;
223
-
224
- function getContext( contextNames, contextAttributes ) {
225
-
226
- for ( let i = 0; i < contextNames.length; i ++ ) {
227
-
228
- const contextName = contextNames[ i ];
229
- const context = canvas.getContext( contextName, contextAttributes );
230
- if ( context !== null ) return context;
231
-
232
- }
233
-
234
- return null;
235
-
236
- }
237
-
238
- try {
239
-
240
- const contextAttributes = {
241
- alpha: true,
242
- depth,
243
- stencil,
244
- antialias,
245
- premultipliedAlpha,
246
- preserveDrawingBuffer,
247
- powerPreference,
248
- failIfMajorPerformanceCaveat,
249
- };
250
-
251
- // OffscreenCanvas does not have setAttribute, see #22811
252
- if ( 'setAttribute' in canvas ) canvas.setAttribute( 'data-engine', `three.js r${REVISION}` );
253
-
254
- // event listeners must be registered before WebGL context is created, see #12753
255
- canvas.addEventListener( 'webglcontextlost', onContextLost, false );
256
- canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
257
- canvas.addEventListener( 'webglcontextcreationerror', onContextCreationError, false );
258
-
259
- if ( _gl === null ) {
260
-
261
- const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
262
-
263
- if ( _this.isWebGL1Renderer === true ) {
264
-
265
- contextNames.shift();
266
-
267
- }
268
-
269
- _gl = getContext( contextNames, contextAttributes );
270
-
271
- if ( _gl === null ) {
272
-
273
- if ( getContext( contextNames ) ) {
274
-
275
- throw new Error( 'Error creating WebGL context with your selected attributes.' );
276
-
277
- } else {
278
-
279
- throw new Error( 'Error creating WebGL context.' );
280
-
281
- }
282
-
283
- }
284
-
285
- }
286
-
287
- if ( typeof WebGLRenderingContext !== 'undefined' && _gl instanceof WebGLRenderingContext ) { // @deprecated, r153
288
-
289
- console.warn( 'THREE.WebGLRenderer: WebGL 1 support was deprecated in r153 and will be removed in r163.' );
290
-
291
- }
292
-
293
- // Some experimental-webgl implementations do not have getShaderPrecisionFormat
294
-
295
- if ( _gl.getShaderPrecisionFormat === undefined ) {
296
-
297
- _gl.getShaderPrecisionFormat = function () {
298
-
299
- return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
300
-
301
- };
302
-
303
- }
304
-
305
- } catch ( error ) {
306
-
307
- console.error( 'THREE.WebGLRenderer: ' + error.message );
308
- throw error;
309
-
310
- }
311
-
312
- let extensions, capabilities, state, info;
313
- let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
314
- let programCache, materials, renderLists, renderStates, clipping, shadowMap;
315
-
316
- let background, morphtargets, bufferRenderer, indexedBufferRenderer;
317
-
318
- let utils, bindingStates, uniformsGroups;
319
-
320
- function initGLContext() {
321
-
322
- extensions = new WebGLExtensions( _gl );
323
-
324
- capabilities = new WebGLCapabilities( _gl, extensions, parameters );
325
-
326
- extensions.init( capabilities );
327
-
328
- utils = new WebGLUtils( _gl, extensions, capabilities );
329
-
330
- state = new WebGLState( _gl, extensions, capabilities );
331
-
332
- info = new WebGLInfo( _gl );
333
- properties = new WebGLProperties();
334
- textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
335
- cubemaps = new WebGLCubeMaps( _this );
336
- cubeuvmaps = new WebGLCubeUVMaps( _this );
337
- attributes = new WebGLAttributes( _gl, capabilities );
338
- bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
339
- geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
340
- objects = new WebGLObjects( _gl, geometries, attributes, info );
341
- morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
342
- clipping = new WebGLClipping( properties );
343
- programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
344
- materials = new WebGLMaterials( _this, properties );
345
- renderLists = new WebGLRenderLists();
346
- renderStates = new WebGLRenderStates( extensions, capabilities );
347
- background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha );
348
- shadowMap = new WebGLShadowMap( _this, objects, capabilities );
349
- uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );
350
-
351
- bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
352
- indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
353
-
354
- info.programs = programCache.programs;
355
-
356
- _this.capabilities = capabilities;
357
- _this.extensions = extensions;
358
- _this.properties = properties;
359
- _this.renderLists = renderLists;
360
- _this.shadowMap = shadowMap;
361
- _this.state = state;
362
- _this.info = info;
363
-
364
- }
365
-
366
- initGLContext();
367
-
368
- // xr
369
-
370
- const xr = new WebXRManager( _this, _gl );
371
-
372
- this.xr = xr;
373
-
374
- // API
375
-
376
- this.getContext = function () {
377
-
378
- return _gl;
379
-
380
- };
381
-
382
- this.getContextAttributes = function () {
383
-
384
- return _gl.getContextAttributes();
385
-
386
- };
387
-
388
- this.forceContextLoss = function () {
389
-
390
- const extension = extensions.get( 'WEBGL_lose_context' );
391
- if ( extension ) extension.loseContext();
392
-
393
- };
394
-
395
- this.forceContextRestore = function () {
396
-
397
- const extension = extensions.get( 'WEBGL_lose_context' );
398
- if ( extension ) extension.restoreContext();
399
-
400
- };
401
-
402
- this.getPixelRatio = function () {
403
-
404
- return _pixelRatio;
405
-
406
- };
407
-
408
- this.setPixelRatio = function ( value ) {
409
-
410
- if ( value === undefined ) return;
411
-
412
- _pixelRatio = value;
413
-
414
- this.setSize( _width, _height, false );
415
-
416
- };
417
-
418
- this.getSize = function ( target ) {
419
-
420
- return target.set( _width, _height );
421
-
422
- };
423
-
424
- this.setSize = function ( width, height, updateStyle = true ) {
425
-
426
- if ( xr.isPresenting ) {
427
-
428
- console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
429
- return;
430
-
431
- }
432
-
433
- _width = width;
434
- _height = height;
435
-
436
- canvas.width = Math.floor( width * _pixelRatio );
437
- canvas.height = Math.floor( height * _pixelRatio );
438
-
439
- if ( updateStyle === true ) {
440
-
441
- canvas.style.width = width + 'px';
442
- canvas.style.height = height + 'px';
443
-
444
- }
445
-
446
- this.setViewport( 0, 0, width, height );
447
-
448
- };
449
-
450
- this.getDrawingBufferSize = function ( target ) {
451
-
452
- return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
453
-
454
- };
455
-
456
- this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
457
-
458
- _width = width;
459
- _height = height;
460
-
461
- _pixelRatio = pixelRatio;
462
-
463
- canvas.width = Math.floor( width * pixelRatio );
464
- canvas.height = Math.floor( height * pixelRatio );
465
-
466
- this.setViewport( 0, 0, width, height );
467
-
468
- };
469
-
470
- this.getCurrentViewport = function ( target ) {
471
-
472
- return target.copy( _currentViewport );
473
-
474
- };
475
-
476
- this.getViewport = function ( target ) {
477
-
478
- return target.copy( _viewport );
479
-
480
- };
481
-
482
- this.setViewport = function ( x, y, width, height ) {
483
-
484
- if ( x.isVector4 ) {
485
-
486
- _viewport.set( x.x, x.y, x.z, x.w );
487
-
488
- } else {
489
-
490
- _viewport.set( x, y, width, height );
491
-
492
- }
493
-
494
- state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).round() );
495
-
496
- };
497
-
498
- this.getScissor = function ( target ) {
499
-
500
- return target.copy( _scissor );
501
-
502
- };
503
-
504
- this.setScissor = function ( x, y, width, height ) {
505
-
506
- if ( x.isVector4 ) {
507
-
508
- _scissor.set( x.x, x.y, x.z, x.w );
509
-
510
- } else {
511
-
512
- _scissor.set( x, y, width, height );
513
-
514
- }
515
-
516
- state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).round() );
517
-
518
- };
519
-
520
- this.getScissorTest = function () {
521
-
522
- return _scissorTest;
523
-
524
- };
525
-
526
- this.setScissorTest = function ( boolean ) {
527
-
528
- state.setScissorTest( _scissorTest = boolean );
529
-
530
- };
531
-
532
- this.setOpaqueSort = function ( method ) {
533
-
534
- _opaqueSort = method;
535
-
536
- };
537
-
538
- this.setTransparentSort = function ( method ) {
539
-
540
- _transparentSort = method;
541
-
542
- };
543
-
544
- // Clearing
545
-
546
- this.getClearColor = function ( target ) {
547
-
548
- return target.copy( background.getClearColor() );
549
-
550
- };
551
-
552
- this.setClearColor = function () {
553
-
554
- background.setClearColor.apply( background, arguments );
555
-
556
- };
557
-
558
- this.getClearAlpha = function () {
559
-
560
- return background.getClearAlpha();
561
-
562
- };
563
-
564
- this.setClearAlpha = function () {
565
-
566
- background.setClearAlpha.apply( background, arguments );
567
-
568
- };
569
-
570
- this.clear = function ( color = true, depth = true, stencil = true ) {
571
-
572
- let bits = 0;
573
-
574
- if ( color ) {
575
-
576
- // check if we're trying to clear an integer target
577
- let isIntegerFormat = false;
578
- if ( _currentRenderTarget !== null ) {
579
-
580
- const targetFormat = _currentRenderTarget.texture.format;
581
- isIntegerFormat = targetFormat === RGBAIntegerFormat ||
582
- targetFormat === RGIntegerFormat ||
583
- targetFormat === RedIntegerFormat;
584
-
585
- }
586
-
587
- // use the appropriate clear functions to clear the target if it's a signed
588
- // or unsigned integer target
589
- if ( isIntegerFormat ) {
590
-
591
- const targetType = _currentRenderTarget.texture.type;
592
- const isUnsignedType = targetType === UnsignedByteType ||
593
- targetType === UnsignedIntType ||
594
- targetType === UnsignedShortType ||
595
- targetType === UnsignedInt248Type ||
596
- targetType === UnsignedShort4444Type ||
597
- targetType === UnsignedShort5551Type;
598
-
599
- const clearColor = background.getClearColor();
600
- const a = background.getClearAlpha();
601
- const r = clearColor.r;
602
- const g = clearColor.g;
603
- const b = clearColor.b;
604
-
605
- if ( isUnsignedType ) {
606
-
607
- uintClearColor[ 0 ] = r;
608
- uintClearColor[ 1 ] = g;
609
- uintClearColor[ 2 ] = b;
610
- uintClearColor[ 3 ] = a;
611
- _gl.clearBufferuiv( _gl.COLOR, 0, uintClearColor );
612
-
613
- } else {
614
-
615
- intClearColor[ 0 ] = r;
616
- intClearColor[ 1 ] = g;
617
- intClearColor[ 2 ] = b;
618
- intClearColor[ 3 ] = a;
619
- _gl.clearBufferiv( _gl.COLOR, 0, intClearColor );
620
-
621
- }
622
-
623
- } else {
624
-
625
- bits |= _gl.COLOR_BUFFER_BIT;
626
-
627
- }
628
-
629
- }
630
-
631
- if ( depth ) bits |= _gl.DEPTH_BUFFER_BIT;
632
- if ( stencil ) {
633
-
634
- bits |= _gl.STENCIL_BUFFER_BIT;
635
- this.state.buffers.stencil.setMask( 0xffffffff );
636
-
637
- }
638
-
639
- _gl.clear( bits );
640
-
641
- };
642
-
643
- this.clearColor = function () {
644
-
645
- this.clear( true, false, false );
646
-
647
- };
648
-
649
- this.clearDepth = function () {
650
-
651
- this.clear( false, true, false );
652
-
653
- };
654
-
655
- this.clearStencil = function () {
656
-
657
- this.clear( false, false, true );
658
-
659
- };
660
-
661
- //
662
-
663
- this.dispose = function () {
664
-
665
- canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
666
- canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
667
- canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );
668
-
669
- renderLists.dispose();
670
- renderStates.dispose();
671
- properties.dispose();
672
- cubemaps.dispose();
673
- cubeuvmaps.dispose();
674
- objects.dispose();
675
- bindingStates.dispose();
676
- uniformsGroups.dispose();
677
- programCache.dispose();
678
-
679
- xr.dispose();
680
-
681
- xr.removeEventListener( 'sessionstart', onXRSessionStart );
682
- xr.removeEventListener( 'sessionend', onXRSessionEnd );
683
-
684
- if ( _transmissionRenderTarget ) {
685
-
686
- _transmissionRenderTarget.dispose();
687
- _transmissionRenderTarget = null;
688
-
689
- }
690
-
691
- animation.stop();
692
-
693
- };
694
-
695
- // Events
696
-
697
- function onContextLost( event ) {
698
-
699
- event.preventDefault();
700
-
701
- console.log( 'THREE.WebGLRenderer: Context Lost.' );
702
-
703
- _isContextLost = true;
704
-
705
- }
706
-
707
- function onContextRestore( /* event */ ) {
708
-
709
- console.log( 'THREE.WebGLRenderer: Context Restored.' );
710
-
711
- _isContextLost = false;
712
-
713
- const infoAutoReset = info.autoReset;
714
- const shadowMapEnabled = shadowMap.enabled;
715
- const shadowMapAutoUpdate = shadowMap.autoUpdate;
716
- const shadowMapNeedsUpdate = shadowMap.needsUpdate;
717
- const shadowMapType = shadowMap.type;
718
-
719
- initGLContext();
720
-
721
- info.autoReset = infoAutoReset;
722
- shadowMap.enabled = shadowMapEnabled;
723
- shadowMap.autoUpdate = shadowMapAutoUpdate;
724
- shadowMap.needsUpdate = shadowMapNeedsUpdate;
725
- shadowMap.type = shadowMapType;
726
-
727
- }
728
-
729
- function onContextCreationError( event ) {
730
-
731
- console.error( 'THREE.WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage );
732
-
733
- }
734
-
735
- function onMaterialDispose( event ) {
736
-
737
- const material = event.target;
738
-
739
- material.removeEventListener( 'dispose', onMaterialDispose );
740
-
741
- deallocateMaterial( material );
742
-
743
- }
744
-
745
- // Buffer deallocation
746
-
747
- function deallocateMaterial( material ) {
748
-
749
- releaseMaterialProgramReferences( material );
750
-
751
- properties.remove( material );
752
-
753
- }
754
-
755
-
756
- function releaseMaterialProgramReferences( material ) {
757
-
758
- const programs = properties.get( material ).programs;
759
-
760
- if ( programs !== undefined ) {
761
-
762
- programs.forEach( function ( program ) {
763
-
764
- programCache.releaseProgram( program );
765
-
766
- } );
767
-
768
- if ( material.isShaderMaterial ) {
769
-
770
- programCache.releaseShaderCache( material );
771
-
772
- }
773
-
774
- }
775
-
776
- }
777
-
778
- // Buffer rendering
779
-
780
- this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
781
-
782
- if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
783
-
784
- const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
785
-
786
- const program = setProgram( camera, scene, geometry, material, object );
787
-
788
- state.setMaterial( material, frontFaceCW );
789
-
790
- //
791
-
792
- let index = geometry.index;
793
- let rangeFactor = 1;
794
-
795
- if ( material.wireframe === true ) {
796
-
797
- index = geometries.getWireframeAttribute( geometry );
798
-
799
- if ( index === undefined ) return;
800
-
801
- rangeFactor = 2;
802
-
803
- }
804
-
805
- //
806
-
807
- const drawRange = geometry.drawRange;
808
- const position = geometry.attributes.position;
809
-
810
- let drawStart = drawRange.start * rangeFactor;
811
- let drawEnd = ( drawRange.start + drawRange.count ) * rangeFactor;
812
-
813
- if ( group !== null ) {
814
-
815
- drawStart = Math.max( drawStart, group.start * rangeFactor );
816
- drawEnd = Math.min( drawEnd, ( group.start + group.count ) * rangeFactor );
817
-
818
- }
819
-
820
- if ( index !== null ) {
821
-
822
- drawStart = Math.max( drawStart, 0 );
823
- drawEnd = Math.min( drawEnd, index.count );
824
-
825
- } else if ( position !== undefined && position !== null ) {
826
-
827
- drawStart = Math.max( drawStart, 0 );
828
- drawEnd = Math.min( drawEnd, position.count );
829
-
830
- }
831
-
832
- const drawCount = drawEnd - drawStart;
833
-
834
- if ( drawCount < 0 || drawCount === Infinity ) return;
835
-
836
- //
837
-
838
- bindingStates.setup( object, material, program, geometry, index );
839
-
840
- let attribute;
841
- let renderer = bufferRenderer;
842
-
843
- if ( index !== null ) {
844
-
845
- attribute = attributes.get( index );
846
-
847
- renderer = indexedBufferRenderer;
848
- renderer.setIndex( attribute );
849
-
850
- }
851
-
852
- //
853
-
854
- if ( object.isMesh ) {
855
-
856
- if ( material.wireframe === true ) {
857
-
858
- state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
859
- renderer.setMode( _gl.LINES );
860
-
861
- } else {
862
-
863
- renderer.setMode( _gl.TRIANGLES );
864
-
865
- }
866
-
867
- } else if ( object.isLine ) {
868
-
869
- let lineWidth = material.linewidth;
870
-
871
- if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
872
-
873
- state.setLineWidth( lineWidth * getTargetPixelRatio() );
874
-
875
- if ( object.isLineSegments ) {
876
-
877
- renderer.setMode( _gl.LINES );
878
-
879
- } else if ( object.isLineLoop ) {
880
-
881
- renderer.setMode( _gl.LINE_LOOP );
882
-
883
- } else {
884
-
885
- renderer.setMode( _gl.LINE_STRIP );
886
-
887
- }
888
-
889
- } else if ( object.isPoints ) {
890
-
891
- renderer.setMode( _gl.POINTS );
892
-
893
- } else if ( object.isSprite ) {
894
-
895
- renderer.setMode( _gl.TRIANGLES );
896
-
897
- }
898
-
899
- if ( object.isBatchedMesh ) {
900
-
901
- renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
902
-
903
- } else if ( object.isInstancedMesh ) {
904
-
905
- renderer.renderInstances( drawStart, drawCount, object.count );
906
-
907
- } else if ( geometry.isInstancedBufferGeometry ) {
908
-
909
- const maxInstanceCount = geometry._maxInstanceCount !== undefined ? geometry._maxInstanceCount : Infinity;
910
- const instanceCount = Math.min( geometry.instanceCount, maxInstanceCount );
911
-
912
- renderer.renderInstances( drawStart, drawCount, instanceCount );
913
-
914
- } else {
915
-
916
- renderer.render( drawStart, drawCount );
917
-
918
- }
919
-
920
- };
921
-
922
- // Compile
923
-
924
- function prepareMaterial( material, scene, object ) {
925
-
926
- if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
927
-
928
- material.side = BackSide;
929
- material.needsUpdate = true;
930
- getProgram( material, scene, object );
931
-
932
- material.side = FrontSide;
933
- material.needsUpdate = true;
934
- getProgram( material, scene, object );
935
-
936
- material.side = DoubleSide;
937
-
938
- } else {
939
-
940
- getProgram( material, scene, object );
941
-
942
- }
943
-
944
- }
945
-
946
- this.compile = function ( scene, camera, targetScene = null ) {
947
-
948
- if ( targetScene === null ) targetScene = scene;
949
-
950
- currentRenderState = renderStates.get( targetScene );
951
- currentRenderState.init();
952
-
953
- renderStateStack.push( currentRenderState );
954
-
955
- // gather lights from both the target scene and the new object that will be added to the scene.
956
-
957
- targetScene.traverseVisible( function ( object ) {
958
-
959
- if ( object.isLight && object.layers.test( camera.layers ) ) {
960
-
961
- currentRenderState.pushLight( object );
962
-
963
- if ( object.castShadow ) {
964
-
965
- currentRenderState.pushShadow( object );
966
-
967
- }
968
-
969
- }
970
-
971
- } );
972
-
973
- if ( scene !== targetScene ) {
974
-
975
- scene.traverseVisible( function ( object ) {
976
-
977
- if ( object.isLight && object.layers.test( camera.layers ) ) {
978
-
979
- currentRenderState.pushLight( object );
980
-
981
- if ( object.castShadow ) {
982
-
983
- currentRenderState.pushShadow( object );
984
-
985
- }
986
-
987
- }
988
-
989
- } );
990
-
991
- }
992
-
993
- currentRenderState.setupLights( _this._useLegacyLights );
994
-
995
- // Only initialize materials in the new scene, not the targetScene.
996
-
997
- const materials = new Set();
998
-
999
- scene.traverse( function ( object ) {
1000
-
1001
- const material = object.material;
1002
-
1003
- if ( material ) {
1004
-
1005
- if ( Array.isArray( material ) ) {
1006
-
1007
- for ( let i = 0; i < material.length; i ++ ) {
1008
-
1009
- const material2 = material[ i ];
1010
-
1011
- prepareMaterial( material2, targetScene, object );
1012
- materials.add( material2 );
1013
-
1014
- }
1015
-
1016
- } else {
1017
-
1018
- prepareMaterial( material, targetScene, object );
1019
- materials.add( material );
1020
-
1021
- }
1022
-
1023
- }
1024
-
1025
- } );
1026
-
1027
- renderStateStack.pop();
1028
- currentRenderState = null;
1029
-
1030
- return materials;
1031
-
1032
- };
1033
-
1034
- // compileAsync
1035
-
1036
- this.compileAsync = function ( scene, camera, targetScene = null ) {
1037
-
1038
- const materials = this.compile( scene, camera, targetScene );
1039
-
1040
- // Wait for all the materials in the new object to indicate that they're
1041
- // ready to be used before resolving the promise.
1042
-
1043
- return new Promise( ( resolve ) => {
1044
-
1045
- function checkMaterialsReady() {
1046
-
1047
- materials.forEach( function ( material ) {
1048
-
1049
- const materialProperties = properties.get( material );
1050
- const program = materialProperties.currentProgram;
1051
-
1052
- if ( program.isReady() ) {
1053
-
1054
- // remove any programs that report they're ready to use from the list
1055
- materials.delete( material );
1056
-
1057
- }
1058
-
1059
- } );
1060
-
1061
- // once the list of compiling materials is empty, call the callback
1062
-
1063
- if ( materials.size === 0 ) {
1064
-
1065
- resolve( scene );
1066
- return;
1067
-
1068
- }
1069
-
1070
- // if some materials are still not ready, wait a bit and check again
1071
-
1072
- setTimeout( checkMaterialsReady, 10 );
1073
-
1074
- }
1075
-
1076
- if ( extensions.get( 'KHR_parallel_shader_compile' ) !== null ) {
1077
-
1078
- // If we can check the compilation status of the materials without
1079
- // blocking then do so right away.
1080
-
1081
- checkMaterialsReady();
1082
-
1083
- } else {
1084
-
1085
- // Otherwise start by waiting a bit to give the materials we just
1086
- // initialized a chance to finish.
1087
-
1088
- setTimeout( checkMaterialsReady, 10 );
1089
-
1090
- }
1091
-
1092
- } );
1093
-
1094
- };
1095
-
1096
- // Animation Loop
1097
-
1098
- let onAnimationFrameCallback = null;
1099
-
1100
- function onAnimationFrame( time ) {
1101
-
1102
- if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
1103
-
1104
- }
1105
-
1106
- function onXRSessionStart() {
1107
-
1108
- animation.stop();
1109
-
1110
- }
1111
-
1112
- function onXRSessionEnd() {
1113
-
1114
- animation.start();
1115
-
1116
- }
1117
-
1118
- const animation = new WebGLAnimation();
1119
- animation.setAnimationLoop( onAnimationFrame );
1120
-
1121
- if ( typeof self !== 'undefined' ) animation.setContext( self );
1122
-
1123
- this.setAnimationLoop = function ( callback ) {
1124
-
1125
- onAnimationFrameCallback = callback;
1126
- xr.setAnimationLoop( callback );
1127
-
1128
- ( callback === null ) ? animation.stop() : animation.start();
1129
-
1130
- };
1131
-
1132
- xr.addEventListener( 'sessionstart', onXRSessionStart );
1133
- xr.addEventListener( 'sessionend', onXRSessionEnd );
1134
-
1135
- // Rendering
1136
-
1137
- this.render = function ( scene, camera ) {
1138
-
1139
- if ( camera !== undefined && camera.isCamera !== true ) {
1140
-
1141
- console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
1142
- return;
1143
-
1144
- }
1145
-
1146
- if ( _isContextLost === true ) return;
1147
-
1148
- // update scene graph
1149
-
1150
- if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
1151
-
1152
- // update camera matrices and frustum
1153
-
1154
- if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
1155
-
1156
- if ( xr.enabled === true && xr.isPresenting === true ) {
1157
-
1158
- if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
1159
-
1160
- camera = xr.getCamera(); // use XR camera for rendering
1161
-
1162
- }
1163
-
1164
- //
1165
- if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, _currentRenderTarget );
1166
-
1167
- currentRenderState = renderStates.get( scene, renderStateStack.length );
1168
- currentRenderState.init();
1169
-
1170
- renderStateStack.push( currentRenderState );
1171
-
1172
- _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
1173
- _frustum.setFromProjectionMatrix( _projScreenMatrix );
1174
-
1175
- _localClippingEnabled = this.localClippingEnabled;
1176
- _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
1177
-
1178
- currentRenderList = renderLists.get( scene, renderListStack.length );
1179
- currentRenderList.init();
1180
-
1181
- renderListStack.push( currentRenderList );
1182
-
1183
- projectObject( scene, camera, 0, _this.sortObjects );
1184
-
1185
- currentRenderList.finish();
1186
-
1187
- if ( _this.sortObjects === true ) {
1188
-
1189
- currentRenderList.sort( _opaqueSort, _transparentSort );
1190
-
1191
- }
1192
-
1193
- //
1194
-
1195
- this.info.render.frame ++;
1196
-
1197
- if ( _clippingEnabled === true ) clipping.beginShadows();
1198
-
1199
- const shadowsArray = currentRenderState.state.shadowsArray;
1200
-
1201
- shadowMap.render( shadowsArray, scene, camera );
1202
-
1203
- if ( _clippingEnabled === true ) clipping.endShadows();
1204
-
1205
- //
1206
-
1207
- if ( this.info.autoReset === true ) this.info.reset();
1208
-
1209
-
1210
- //
1211
-
1212
- if ( xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false ) {
1213
-
1214
- background.render( currentRenderList, scene );
1215
-
1216
- }
1217
-
1218
- // render scene
1219
-
1220
- currentRenderState.setupLights( _this._useLegacyLights );
1221
-
1222
- if ( camera.isArrayCamera ) {
1223
-
1224
- const cameras = camera.cameras;
1225
-
1226
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1227
-
1228
- const camera2 = cameras[ i ];
1229
-
1230
- renderScene( currentRenderList, scene, camera2, camera2.viewport );
1231
-
1232
- }
1233
-
1234
- } else {
1235
-
1236
- renderScene( currentRenderList, scene, camera );
1237
-
1238
- }
1239
-
1240
- //
1241
-
1242
- if ( _currentRenderTarget !== null ) {
1243
-
1244
- // resolve multisample renderbuffers to a single-sample texture if necessary
1245
-
1246
- textures.updateMultisampleRenderTarget( _currentRenderTarget );
1247
-
1248
- // Generate mipmap if we're using any kind of mipmap filtering
1249
-
1250
- textures.updateRenderTargetMipmap( _currentRenderTarget );
1251
-
1252
- }
1253
-
1254
- //
1255
-
1256
- if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
1257
-
1258
- // _gl.finish();
1259
-
1260
- bindingStates.resetDefaultState();
1261
- _currentMaterialId = - 1;
1262
- _currentCamera = null;
1263
-
1264
- renderStateStack.pop();
1265
-
1266
- if ( renderStateStack.length > 0 ) {
1267
-
1268
- currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
1269
-
1270
- } else {
1271
-
1272
- currentRenderState = null;
1273
-
1274
- }
1275
-
1276
- renderListStack.pop();
1277
-
1278
- if ( renderListStack.length > 0 ) {
1279
-
1280
- currentRenderList = renderListStack[ renderListStack.length - 1 ];
1281
-
1282
- } else {
1283
-
1284
- currentRenderList = null;
1285
-
1286
- }
1287
-
1288
- };
1289
-
1290
- function projectObject( object, camera, groupOrder, sortObjects ) {
1291
-
1292
- if ( object.visible === false ) return;
1293
-
1294
- const visible = object.layers.test( camera.layers );
1295
-
1296
- if ( visible ) {
1297
-
1298
- if ( object.isGroup ) {
1299
-
1300
- groupOrder = object.renderOrder;
1301
-
1302
- } else if ( object.isLOD ) {
1303
-
1304
- if ( object.autoUpdate === true ) object.update( camera );
1305
-
1306
- } else if ( object.isLight ) {
1307
-
1308
- currentRenderState.pushLight( object );
1309
-
1310
- if ( object.castShadow ) {
1311
-
1312
- currentRenderState.pushShadow( object );
1313
-
1314
- }
1315
-
1316
- } else if ( object.isSprite ) {
1317
-
1318
- if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
1319
-
1320
- if ( sortObjects ) {
1321
-
1322
- _vector3.setFromMatrixPosition( object.matrixWorld )
1323
- .applyMatrix4( _projScreenMatrix );
1324
-
1325
- }
1326
-
1327
- const geometry = objects.update( object );
1328
- const material = object.material;
1329
-
1330
- if ( material.visible ) {
1331
-
1332
- currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
1333
-
1334
- }
1335
-
1336
- }
1337
-
1338
- } else if ( object.isMesh || object.isLine || object.isPoints ) {
1339
-
1340
- if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
1341
-
1342
- const geometry = objects.update( object );
1343
- const material = object.material;
1344
-
1345
- if ( sortObjects ) {
1346
-
1347
- if ( object.boundingSphere !== undefined ) {
1348
-
1349
- if ( object.boundingSphere === null ) object.computeBoundingSphere();
1350
- _vector3.copy( object.boundingSphere.center );
1351
-
1352
- } else {
1353
-
1354
- if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
1355
- _vector3.copy( geometry.boundingSphere.center );
1356
-
1357
- }
1358
-
1359
- _vector3
1360
- .applyMatrix4( object.matrixWorld )
1361
- .applyMatrix4( _projScreenMatrix );
1362
-
1363
- }
1364
-
1365
- if ( Array.isArray( material ) ) {
1366
-
1367
- const groups = geometry.groups;
1368
-
1369
- for ( let i = 0, l = groups.length; i < l; i ++ ) {
1370
-
1371
- const group = groups[ i ];
1372
- const groupMaterial = material[ group.materialIndex ];
1373
-
1374
- if ( groupMaterial && groupMaterial.visible ) {
1375
-
1376
- currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
1377
-
1378
- }
1379
-
1380
- }
1381
-
1382
- } else if ( material.visible ) {
1383
-
1384
- currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
1385
-
1386
- }
1387
-
1388
- }
1389
-
1390
- }
1391
-
1392
- }
1393
-
1394
- const children = object.children;
1395
-
1396
- for ( let i = 0, l = children.length; i < l; i ++ ) {
1397
-
1398
- projectObject( children[ i ], camera, groupOrder, sortObjects );
1399
-
1400
- }
1401
-
1402
- }
1403
-
1404
- function renderScene( currentRenderList, scene, camera, viewport ) {
1405
-
1406
- const opaqueObjects = currentRenderList.opaque;
1407
- const transmissiveObjects = currentRenderList.transmissive;
1408
- const transparentObjects = currentRenderList.transparent;
1409
-
1410
- currentRenderState.setupLightsView( camera );
1411
-
1412
- if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera );
1413
-
1414
- if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
1415
-
1416
- if ( viewport ) state.viewport( _currentViewport.copy( viewport ) );
1417
-
1418
- if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
1419
- if ( transmissiveObjects.length > 0 ) renderObjects( transmissiveObjects, scene, camera );
1420
- if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
1421
-
1422
- // Ensure depth buffer writing is enabled so it can be cleared on next render
1423
-
1424
- state.buffers.depth.setTest( true );
1425
- state.buffers.depth.setMask( true );
1426
- state.buffers.color.setMask( true );
1427
-
1428
- state.setPolygonOffset( false );
1429
-
1430
- }
1431
-
1432
- function renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ) {
1433
-
1434
- const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
1435
-
1436
- if ( overrideMaterial !== null ) {
1437
-
1438
- return;
1439
-
1440
- }
1441
-
1442
- const isWebGL2 = capabilities.isWebGL2;
1443
-
1444
- if ( _transmissionRenderTarget === null ) {
1445
-
1446
- _transmissionRenderTarget = new WebGLRenderTarget( 1, 1, {
1447
- generateMipmaps: true,
1448
- type: extensions.has( 'EXT_color_buffer_half_float' ) ? HalfFloatType : UnsignedByteType,
1449
- minFilter: LinearMipmapLinearFilter,
1450
- samples: ( isWebGL2 ) ? 4 : 0
1451
- } );
1452
-
1453
- // debug
1454
-
1455
- /*
1456
- const geometry = new PlaneGeometry();
1457
- const material = new MeshBasicMaterial( { map: _transmissionRenderTarget.texture } );
1458
-
1459
- const mesh = new Mesh( geometry, material );
1460
- scene.add( mesh );
1461
- */
1462
-
1463
- }
1464
-
1465
- _this.getDrawingBufferSize( _vector2 );
1466
-
1467
- if ( isWebGL2 ) {
1468
-
1469
- _transmissionRenderTarget.setSize( _vector2.x, _vector2.y );
1470
-
1471
- } else {
1472
-
1473
- _transmissionRenderTarget.setSize( floorPowerOfTwo( _vector2.x ), floorPowerOfTwo( _vector2.y ) );
1474
-
1475
- }
1476
-
1477
- //
1478
-
1479
- const currentRenderTarget = _this.getRenderTarget();
1480
- _this.setRenderTarget( _transmissionRenderTarget );
1481
-
1482
- _this.getClearColor( _currentClearColor );
1483
- _currentClearAlpha = _this.getClearAlpha();
1484
- if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );
1485
-
1486
- _this.clear();
1487
-
1488
- // Turn off the features which can affect the frag color for opaque objects pass.
1489
- // Otherwise they are applied twice in opaque objects pass and transmission objects pass.
1490
- const currentToneMapping = _this.toneMapping;
1491
- _this.toneMapping = NoToneMapping;
1492
-
1493
- renderObjects( opaqueObjects, scene, camera );
1494
-
1495
- textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
1496
- textures.updateRenderTargetMipmap( _transmissionRenderTarget );
1497
-
1498
- let renderTargetNeedsUpdate = false;
1499
-
1500
- for ( let i = 0, l = transmissiveObjects.length; i < l; i ++ ) {
1501
-
1502
- const renderItem = transmissiveObjects[ i ];
1503
-
1504
- const object = renderItem.object;
1505
- const geometry = renderItem.geometry;
1506
- const material = renderItem.material;
1507
- const group = renderItem.group;
1508
-
1509
- if ( material.side === DoubleSide && object.layers.test( camera.layers ) ) {
1510
-
1511
- const currentSide = material.side;
1512
-
1513
- material.side = BackSide;
1514
- material.needsUpdate = true;
1515
-
1516
- renderObject( object, scene, camera, geometry, material, group );
1517
-
1518
- material.side = currentSide;
1519
- material.needsUpdate = true;
1520
-
1521
- renderTargetNeedsUpdate = true;
1522
-
1523
- }
1524
-
1525
- }
1526
-
1527
- if ( renderTargetNeedsUpdate === true ) {
1528
-
1529
- textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
1530
- textures.updateRenderTargetMipmap( _transmissionRenderTarget );
1531
-
1532
- }
1533
-
1534
- _this.setRenderTarget( currentRenderTarget );
1535
-
1536
- _this.setClearColor( _currentClearColor, _currentClearAlpha );
1537
-
1538
- _this.toneMapping = currentToneMapping;
1539
-
1540
- }
1541
-
1542
- function renderObjects( renderList, scene, camera ) {
1543
-
1544
- const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
1545
-
1546
- for ( let i = 0, l = renderList.length; i < l; i ++ ) {
1547
-
1548
- const renderItem = renderList[ i ];
1549
-
1550
- const object = renderItem.object;
1551
- const geometry = renderItem.geometry;
1552
- const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
1553
- const group = renderItem.group;
1554
-
1555
- if ( object.layers.test( camera.layers ) ) {
1556
-
1557
- renderObject( object, scene, camera, geometry, material, group );
1558
-
1559
- }
1560
-
1561
- }
1562
-
1563
- }
1564
-
1565
- function renderObject( object, scene, camera, geometry, material, group ) {
1566
-
1567
- object.onBeforeRender( _this, scene, camera, geometry, material, group );
1568
-
1569
- object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
1570
- object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
1571
-
1572
- material.onBeforeRender( _this, scene, camera, geometry, object, group );
1573
-
1574
- if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
1575
-
1576
- material.side = BackSide;
1577
- material.needsUpdate = true;
1578
- _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1579
-
1580
- material.side = FrontSide;
1581
- material.needsUpdate = true;
1582
- _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1583
-
1584
- material.side = DoubleSide;
1585
-
1586
- } else {
1587
-
1588
- _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1589
-
1590
- }
1591
-
1592
- object.onAfterRender( _this, scene, camera, geometry, material, group );
1593
-
1594
- }
1595
-
1596
- function getProgram( material, scene, object ) {
1597
-
1598
- if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
1599
-
1600
- const materialProperties = properties.get( material );
1601
-
1602
- const lights = currentRenderState.state.lights;
1603
- const shadowsArray = currentRenderState.state.shadowsArray;
1604
-
1605
- const lightsStateVersion = lights.state.version;
1606
-
1607
- const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
1608
- const programCacheKey = programCache.getProgramCacheKey( parameters );
1609
-
1610
- let programs = materialProperties.programs;
1611
-
1612
- // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
1613
-
1614
- materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
1615
- materialProperties.fog = scene.fog;
1616
- materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
1617
- materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
1618
-
1619
- if ( programs === undefined ) {
1620
-
1621
- // new material
1622
-
1623
- material.addEventListener( 'dispose', onMaterialDispose );
1624
-
1625
- programs = new Map();
1626
- materialProperties.programs = programs;
1627
-
1628
- }
1629
-
1630
- let program = programs.get( programCacheKey );
1631
-
1632
- if ( program !== undefined ) {
1633
-
1634
- // early out if program and light state is identical
1635
-
1636
- if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) {
1637
-
1638
- updateCommonMaterialProperties( material, parameters );
1639
-
1640
- return program;
1641
-
1642
- }
1643
-
1644
- } else {
1645
-
1646
- parameters.uniforms = programCache.getUniforms( material );
1647
-
1648
- material.onBuild( object, parameters, _this );
1649
-
1650
- material.onBeforeCompile( parameters, _this );
1651
-
1652
- program = programCache.acquireProgram( parameters, programCacheKey );
1653
- programs.set( programCacheKey, program );
1654
-
1655
- materialProperties.uniforms = parameters.uniforms;
1656
-
1657
- }
1658
-
1659
- const uniforms = materialProperties.uniforms;
1660
-
1661
- if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) {
1662
-
1663
- uniforms.clippingPlanes = clipping.uniform;
1664
-
1665
- }
1666
-
1667
- updateCommonMaterialProperties( material, parameters );
1668
-
1669
- // store the light setup it was created for
1670
-
1671
- materialProperties.needsLights = materialNeedsLights( material );
1672
- materialProperties.lightsStateVersion = lightsStateVersion;
1673
-
1674
- if ( materialProperties.needsLights ) {
1675
-
1676
- // wire up the material to this renderer's lighting state
1677
-
1678
- uniforms.ambientLightColor.value = lights.state.ambient;
1679
- uniforms.lightProbe.value = lights.state.probe;
1680
- uniforms.directionalLights.value = lights.state.directional;
1681
- uniforms.directionalLightShadows.value = lights.state.directionalShadow;
1682
- uniforms.spotLights.value = lights.state.spot;
1683
- uniforms.spotLightShadows.value = lights.state.spotShadow;
1684
- uniforms.rectAreaLights.value = lights.state.rectArea;
1685
- uniforms.ltc_1.value = lights.state.rectAreaLTC1;
1686
- uniforms.ltc_2.value = lights.state.rectAreaLTC2;
1687
- uniforms.pointLights.value = lights.state.point;
1688
- uniforms.pointLightShadows.value = lights.state.pointShadow;
1689
- uniforms.hemisphereLights.value = lights.state.hemi;
1690
-
1691
- uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
1692
- uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
1693
- uniforms.spotShadowMap.value = lights.state.spotShadowMap;
1694
- uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;
1695
- uniforms.spotLightMap.value = lights.state.spotLightMap;
1696
- uniforms.pointShadowMap.value = lights.state.pointShadowMap;
1697
- uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
1698
- // TODO (abelnation): add area lights shadow info to uniforms
1699
-
1700
- }
1701
-
1702
- materialProperties.currentProgram = program;
1703
- materialProperties.uniformsList = null;
1704
-
1705
- return program;
1706
-
1707
- }
1708
-
1709
- function getUniformList( materialProperties ) {
1710
-
1711
- if ( materialProperties.uniformsList === null ) {
1712
-
1713
- const progUniforms = materialProperties.currentProgram.getUniforms();
1714
- materialProperties.uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, materialProperties.uniforms );
1715
-
1716
- }
1717
-
1718
- return materialProperties.uniformsList;
1719
-
1720
- }
1721
-
1722
- function updateCommonMaterialProperties( material, parameters ) {
1723
-
1724
- const materialProperties = properties.get( material );
1725
-
1726
- materialProperties.outputColorSpace = parameters.outputColorSpace;
1727
- materialProperties.batching = parameters.batching;
1728
- materialProperties.instancing = parameters.instancing;
1729
- materialProperties.instancingColor = parameters.instancingColor;
1730
- materialProperties.instancingMorph = parameters.instancingMorph;
1731
- materialProperties.skinning = parameters.skinning;
1732
- materialProperties.morphTargets = parameters.morphTargets;
1733
- materialProperties.morphNormals = parameters.morphNormals;
1734
- materialProperties.morphColors = parameters.morphColors;
1735
- materialProperties.morphTargetsCount = parameters.morphTargetsCount;
1736
- materialProperties.numClippingPlanes = parameters.numClippingPlanes;
1737
- materialProperties.numIntersection = parameters.numClipIntersection;
1738
- materialProperties.vertexAlphas = parameters.vertexAlphas;
1739
- materialProperties.vertexTangents = parameters.vertexTangents;
1740
- materialProperties.toneMapping = parameters.toneMapping;
1741
-
1742
- }
1743
-
1744
- function setProgram( camera, scene, geometry, material, object ) {
1745
-
1746
- if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
1747
-
1748
- textures.resetTextureUnits();
1749
-
1750
- const fog = scene.fog;
1751
- const environment = material.isMeshStandardMaterial ? scene.environment : null;
1752
- const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace );
1753
- const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
1754
- const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
1755
- const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 );
1756
- const morphTargets = !! geometry.morphAttributes.position;
1757
- const morphNormals = !! geometry.morphAttributes.normal;
1758
- const morphColors = !! geometry.morphAttributes.color;
1759
-
1760
- let toneMapping = NoToneMapping;
1761
-
1762
- if ( material.toneMapped ) {
1763
-
1764
- if ( _currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true ) {
1765
-
1766
- toneMapping = _this.toneMapping;
1767
-
1768
- }
1769
-
1770
- }
1771
-
1772
- const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
1773
- const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;
1774
-
1775
- const materialProperties = properties.get( material );
1776
- const lights = currentRenderState.state.lights;
1777
-
1778
- if ( _clippingEnabled === true ) {
1779
-
1780
- if ( _localClippingEnabled === true || camera !== _currentCamera ) {
1781
-
1782
- const useCache =
1783
- camera === _currentCamera &&
1784
- material.id === _currentMaterialId;
1785
-
1786
- // we might want to call this function with some ClippingGroup
1787
- // object instead of the material, once it becomes feasible
1788
- // (#8465, #8379)
1789
- clipping.setState( material, camera, useCache );
1790
-
1791
- }
1792
-
1793
- }
1794
-
1795
- //
1796
-
1797
- let needsProgramChange = false;
1798
-
1799
- if ( material.version === materialProperties.__version ) {
1800
-
1801
- if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
1802
-
1803
- needsProgramChange = true;
1804
-
1805
- } else if ( materialProperties.outputColorSpace !== colorSpace ) {
1806
-
1807
- needsProgramChange = true;
1808
-
1809
- } else if ( object.isBatchedMesh && materialProperties.batching === false ) {
1810
-
1811
- needsProgramChange = true;
1812
-
1813
- } else if ( ! object.isBatchedMesh && materialProperties.batching === true ) {
1814
-
1815
- needsProgramChange = true;
1816
-
1817
- } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
1818
-
1819
- needsProgramChange = true;
1820
-
1821
- } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) {
1822
-
1823
- needsProgramChange = true;
1824
-
1825
- } else if ( object.isSkinnedMesh && materialProperties.skinning === false ) {
1826
-
1827
- needsProgramChange = true;
1828
-
1829
- } else if ( ! object.isSkinnedMesh && materialProperties.skinning === true ) {
1830
-
1831
- needsProgramChange = true;
1832
-
1833
- } else if ( object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null ) {
1834
-
1835
- needsProgramChange = true;
1836
-
1837
- } else if ( object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null ) {
1838
-
1839
- needsProgramChange = true;
1840
-
1841
- } else if ( object.isInstancedMesh && materialProperties.instancingMorph === true && object.morphTexture === null ) {
1842
-
1843
- needsProgramChange = true;
1844
-
1845
- } else if ( object.isInstancedMesh && materialProperties.instancingMorph === false && object.morphTexture !== null ) {
1846
-
1847
- needsProgramChange = true;
1848
-
1849
- } else if ( materialProperties.envMap !== envMap ) {
1850
-
1851
- needsProgramChange = true;
1852
-
1853
- } else if ( material.fog === true && materialProperties.fog !== fog ) {
1854
-
1855
- needsProgramChange = true;
1856
-
1857
- } else if ( materialProperties.numClippingPlanes !== undefined &&
1858
- ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
1859
- materialProperties.numIntersection !== clipping.numIntersection ) ) {
1860
-
1861
- needsProgramChange = true;
1862
-
1863
- } else if ( materialProperties.vertexAlphas !== vertexAlphas ) {
1864
-
1865
- needsProgramChange = true;
1866
-
1867
- } else if ( materialProperties.vertexTangents !== vertexTangents ) {
1868
-
1869
- needsProgramChange = true;
1870
-
1871
- } else if ( materialProperties.morphTargets !== morphTargets ) {
1872
-
1873
- needsProgramChange = true;
1874
-
1875
- } else if ( materialProperties.morphNormals !== morphNormals ) {
1876
-
1877
- needsProgramChange = true;
1878
-
1879
- } else if ( materialProperties.morphColors !== morphColors ) {
1880
-
1881
- needsProgramChange = true;
1882
-
1883
- } else if ( materialProperties.toneMapping !== toneMapping ) {
1884
-
1885
- needsProgramChange = true;
1886
-
1887
- } else if ( capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount ) {
1888
-
1889
- needsProgramChange = true;
1890
-
1891
- }
1892
-
1893
- } else {
1894
-
1895
- needsProgramChange = true;
1896
- materialProperties.__version = material.version;
1897
-
1898
- }
1899
-
1900
- //
1901
-
1902
- let program = materialProperties.currentProgram;
1903
-
1904
- if ( needsProgramChange === true ) {
1905
-
1906
- program = getProgram( material, scene, object );
1907
-
1908
- }
1909
-
1910
- let refreshProgram = false;
1911
- let refreshMaterial = false;
1912
- let refreshLights = false;
1913
-
1914
- const p_uniforms = program.getUniforms(),
1915
- m_uniforms = materialProperties.uniforms;
1916
-
1917
- if ( state.useProgram( program.program ) ) {
1918
-
1919
- refreshProgram = true;
1920
- refreshMaterial = true;
1921
- refreshLights = true;
1922
-
1923
- }
1924
-
1925
- if ( material.id !== _currentMaterialId ) {
1926
-
1927
- _currentMaterialId = material.id;
1928
-
1929
- refreshMaterial = true;
1930
-
1931
- }
1932
-
1933
- if ( refreshProgram || _currentCamera !== camera ) {
1934
-
1935
- // common camera uniforms
1936
-
1937
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
1938
- p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
1939
-
1940
- const uCamPos = p_uniforms.map.cameraPosition;
1941
-
1942
- if ( uCamPos !== undefined ) {
1943
-
1944
- uCamPos.setValue( _gl, _vector3.setFromMatrixPosition( camera.matrixWorld ) );
1945
-
1946
- }
1947
-
1948
- if ( capabilities.logarithmicDepthBuffer ) {
1949
-
1950
- p_uniforms.setValue( _gl, 'logDepthBufFC',
1951
- 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
1952
-
1953
- }
1954
-
1955
- // consider moving isOrthographic to UniformLib and WebGLMaterials, see https://github.com/mrdoob/three.js/pull/26467#issuecomment-1645185067
1956
-
1957
- if ( material.isMeshPhongMaterial ||
1958
- material.isMeshToonMaterial ||
1959
- material.isMeshLambertMaterial ||
1960
- material.isMeshBasicMaterial ||
1961
- material.isMeshStandardMaterial ||
1962
- material.isShaderMaterial ) {
1963
-
1964
- p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
1965
-
1966
- }
1967
-
1968
- if ( _currentCamera !== camera ) {
1969
-
1970
- _currentCamera = camera;
1971
-
1972
- // lighting uniforms depend on the camera so enforce an update
1973
- // now, in case this material supports lights - or later, when
1974
- // the next material that does gets activated:
1975
-
1976
- refreshMaterial = true; // set to true on material change
1977
- refreshLights = true; // remains set until update done
1978
-
1979
- }
1980
-
1981
- }
1982
-
1983
- // skinning and morph target uniforms must be set even if material didn't change
1984
- // auto-setting of texture unit for bone and morph texture must go before other textures
1985
- // otherwise textures used for skinning and morphing can take over texture units reserved for other material textures
1986
-
1987
- if ( object.isSkinnedMesh ) {
1988
-
1989
- p_uniforms.setOptional( _gl, object, 'bindMatrix' );
1990
- p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
1991
-
1992
- const skeleton = object.skeleton;
1993
-
1994
- if ( skeleton ) {
1995
-
1996
- if ( capabilities.floatVertexTextures ) {
1997
-
1998
- if ( skeleton.boneTexture === null ) skeleton.computeBoneTexture();
1999
-
2000
- p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
2001
-
2002
- } else {
2003
-
2004
- console.warn( 'THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required.' );
2005
-
2006
- }
2007
-
2008
- }
2009
-
2010
- }
2011
-
2012
- if ( object.isBatchedMesh ) {
2013
-
2014
- p_uniforms.setOptional( _gl, object, 'batchingTexture' );
2015
- p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );
2016
-
2017
- }
2018
-
2019
- const morphAttributes = geometry.morphAttributes;
2020
-
2021
- if ( morphAttributes.position !== undefined || morphAttributes.normal !== undefined || ( morphAttributes.color !== undefined && capabilities.isWebGL2 === true ) ) {
2022
-
2023
- morphtargets.update( object, geometry, program );
2024
-
2025
- }
2026
-
2027
- if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
2028
-
2029
- materialProperties.receiveShadow = object.receiveShadow;
2030
- p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
2031
-
2032
- }
2033
-
2034
- // https://github.com/mrdoob/three.js/pull/24467#issuecomment-1209031512
2035
-
2036
- if ( material.isMeshGouraudMaterial && material.envMap !== null ) {
2037
-
2038
- m_uniforms.envMap.value = envMap;
2039
-
2040
- m_uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1;
2041
-
2042
- }
2043
-
2044
- if ( refreshMaterial ) {
2045
-
2046
- p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
2047
-
2048
- if ( materialProperties.needsLights ) {
2049
-
2050
- // the current material requires lighting info
2051
-
2052
- // note: all lighting uniforms are always set correctly
2053
- // they simply reference the renderer's state for their
2054
- // values
2055
- //
2056
- // use the current material's .needsUpdate flags to set
2057
- // the GL state when required
2058
-
2059
- markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
2060
-
2061
- }
2062
-
2063
- // refresh uniforms common to several materials
2064
-
2065
- if ( fog && material.fog === true ) {
2066
-
2067
- materials.refreshFogUniforms( m_uniforms, fog );
2068
-
2069
- }
2070
-
2071
- materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget );
2072
-
2073
- WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
2074
-
2075
- }
2076
-
2077
- if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
2078
-
2079
- WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
2080
- material.uniformsNeedUpdate = false;
2081
-
2082
- }
2083
-
2084
- if ( material.isSpriteMaterial ) {
2085
-
2086
- p_uniforms.setValue( _gl, 'center', object.center );
2087
-
2088
- }
2089
-
2090
- // common matrices
2091
-
2092
- p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
2093
- p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
2094
- p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
2095
-
2096
- // UBOs
2097
-
2098
- if ( material.isShaderMaterial || material.isRawShaderMaterial ) {
2099
-
2100
- const groups = material.uniformsGroups;
2101
-
2102
- for ( let i = 0, l = groups.length; i < l; i ++ ) {
2103
-
2104
- if ( capabilities.isWebGL2 ) {
2105
-
2106
- const group = groups[ i ];
2107
-
2108
- uniformsGroups.update( group, program );
2109
- uniformsGroups.bind( group, program );
2110
-
2111
- } else {
2112
-
2113
- console.warn( 'THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.' );
2114
-
2115
- }
2116
-
2117
- }
2118
-
2119
- }
2120
-
2121
- return program;
2122
-
2123
- }
2124
-
2125
- // If uniforms are marked as clean, they don't need to be loaded to the GPU.
2126
-
2127
- function markUniformsLightsNeedsUpdate( uniforms, value ) {
2128
-
2129
- uniforms.ambientLightColor.needsUpdate = value;
2130
- uniforms.lightProbe.needsUpdate = value;
2131
-
2132
- uniforms.directionalLights.needsUpdate = value;
2133
- uniforms.directionalLightShadows.needsUpdate = value;
2134
- uniforms.pointLights.needsUpdate = value;
2135
- uniforms.pointLightShadows.needsUpdate = value;
2136
- uniforms.spotLights.needsUpdate = value;
2137
- uniforms.spotLightShadows.needsUpdate = value;
2138
- uniforms.rectAreaLights.needsUpdate = value;
2139
- uniforms.hemisphereLights.needsUpdate = value;
2140
-
2141
- }
2142
-
2143
- function materialNeedsLights( material ) {
2144
-
2145
- return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
2146
- material.isMeshStandardMaterial || material.isShadowMaterial ||
2147
- ( material.isShaderMaterial && material.lights === true );
2148
-
2149
- }
2150
-
2151
- this.getActiveCubeFace = function () {
2152
-
2153
- return _currentActiveCubeFace;
2154
-
2155
- };
2156
-
2157
- this.getActiveMipmapLevel = function () {
2158
-
2159
- return _currentActiveMipmapLevel;
2160
-
2161
- };
2162
-
2163
- this.getRenderTarget = function () {
2164
-
2165
- return _currentRenderTarget;
2166
-
2167
- };
2168
-
2169
- this.setRenderTargetTextures = function ( renderTarget, colorTexture, depthTexture ) {
2170
-
2171
- properties.get( renderTarget.texture ).__webglTexture = colorTexture;
2172
- properties.get( renderTarget.depthTexture ).__webglTexture = depthTexture;
2173
-
2174
- const renderTargetProperties = properties.get( renderTarget );
2175
- renderTargetProperties.__hasExternalTextures = true;
2176
-
2177
- renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
2178
-
2179
- if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) {
2180
-
2181
- // The multisample_render_to_texture extension doesn't work properly if there
2182
- // are midframe flushes and an external depth buffer. Disable use of the extension.
2183
- if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
2184
-
2185
- console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
2186
- renderTargetProperties.__useRenderToTexture = false;
2187
-
2188
- }
2189
-
2190
- }
2191
-
2192
- };
2193
-
2194
- this.setRenderTargetFramebuffer = function ( renderTarget, defaultFramebuffer ) {
2195
-
2196
- const renderTargetProperties = properties.get( renderTarget );
2197
- renderTargetProperties.__webglFramebuffer = defaultFramebuffer;
2198
- renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === undefined;
2199
-
2200
- };
2201
-
2202
- this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
2203
-
2204
- _currentRenderTarget = renderTarget;
2205
- _currentActiveCubeFace = activeCubeFace;
2206
- _currentActiveMipmapLevel = activeMipmapLevel;
2207
-
2208
- let useDefaultFramebuffer = true;
2209
- let framebuffer = null;
2210
- let isCube = false;
2211
- let isRenderTarget3D = false;
2212
-
2213
- if ( renderTarget ) {
2214
-
2215
- const renderTargetProperties = properties.get( renderTarget );
2216
-
2217
- if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) {
2218
-
2219
- // We need to make sure to rebind the framebuffer.
2220
- state.bindFramebuffer( _gl.FRAMEBUFFER, null );
2221
- useDefaultFramebuffer = false;
2222
-
2223
- } else if ( renderTargetProperties.__webglFramebuffer === undefined ) {
2224
-
2225
- textures.setupRenderTarget( renderTarget );
2226
-
2227
- } else if ( renderTargetProperties.__hasExternalTextures ) {
2228
-
2229
- // Color and depth texture must be rebound in order for the swapchain to update.
2230
- textures.rebindTextures( renderTarget, properties.get( renderTarget.texture ).__webglTexture, properties.get( renderTarget.depthTexture ).__webglTexture );
2231
-
2232
- }
2233
-
2234
- const texture = renderTarget.texture;
2235
-
2236
- if ( texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
2237
-
2238
- isRenderTarget3D = true;
2239
-
2240
- }
2241
-
2242
- const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
2243
-
2244
- if ( renderTarget.isWebGLCubeRenderTarget ) {
2245
-
2246
- if ( Array.isArray( __webglFramebuffer[ activeCubeFace ] ) ) {
2247
-
2248
- framebuffer = __webglFramebuffer[ activeCubeFace ][ activeMipmapLevel ];
2249
-
2250
- } else {
2251
-
2252
- framebuffer = __webglFramebuffer[ activeCubeFace ];
2253
-
2254
- }
2255
-
2256
- isCube = true;
2257
-
2258
- } else if ( ( capabilities.isWebGL2 && renderTarget.samples > 0 ) && textures.useMultisampledRTT( renderTarget ) === false ) {
2259
-
2260
- framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
2261
-
2262
- } else {
2263
-
2264
- if ( Array.isArray( __webglFramebuffer ) ) {
2265
-
2266
- framebuffer = __webglFramebuffer[ activeMipmapLevel ];
2267
-
2268
- } else {
2269
-
2270
- framebuffer = __webglFramebuffer;
2271
-
2272
- }
2273
-
2274
- }
2275
-
2276
- _currentViewport.copy( renderTarget.viewport );
2277
- _currentScissor.copy( renderTarget.scissor );
2278
- _currentScissorTest = renderTarget.scissorTest;
2279
-
2280
- } else {
2281
-
2282
- _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
2283
- _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
2284
- _currentScissorTest = _scissorTest;
2285
-
2286
- }
2287
-
2288
- const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2289
-
2290
- if ( framebufferBound && capabilities.drawBuffers && useDefaultFramebuffer ) {
2291
-
2292
- state.drawBuffers( renderTarget, framebuffer );
2293
-
2294
- }
2295
-
2296
- state.viewport( _currentViewport );
2297
- state.scissor( _currentScissor );
2298
- state.setScissorTest( _currentScissorTest );
2299
-
2300
- if ( isCube ) {
2301
-
2302
- const textureProperties = properties.get( renderTarget.texture );
2303
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
2304
-
2305
- } else if ( isRenderTarget3D ) {
2306
-
2307
- const textureProperties = properties.get( renderTarget.texture );
2308
- const layer = activeCubeFace || 0;
2309
- _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer );
2310
-
2311
- }
2312
-
2313
- _currentMaterialId = - 1; // reset current material to ensure correct uniform bindings
2314
-
2315
- };
2316
-
2317
- this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
2318
-
2319
- if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
2320
-
2321
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
2322
- return;
2323
-
2324
- }
2325
-
2326
- let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
2327
-
2328
- if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
2329
-
2330
- framebuffer = framebuffer[ activeCubeFaceIndex ];
2331
-
2332
- }
2333
-
2334
- if ( framebuffer ) {
2335
-
2336
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2337
-
2338
- try {
2339
-
2340
- const texture = renderTarget.texture;
2341
- const textureFormat = texture.format;
2342
- const textureType = texture.type;
2343
-
2344
- if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
2345
-
2346
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
2347
- return;
2348
-
2349
- }
2350
-
2351
- const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ) );
2352
-
2353
- if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // Edge and Chrome Mac < 52 (#9513)
2354
- ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.has( 'OES_texture_float' ) || extensions.has( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
2355
- ! halfFloatSupportedByExt ) {
2356
-
2357
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
2358
- return;
2359
-
2360
- }
2361
-
2362
- // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
2363
-
2364
- if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
2365
-
2366
- _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
2367
-
2368
- }
2369
-
2370
- } finally {
2371
-
2372
- // restore framebuffer of current render target if necessary
2373
-
2374
- const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
2375
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2376
-
2377
- }
2378
-
2379
- }
2380
-
2381
- };
2382
-
2383
- this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
2384
-
2385
- const levelScale = Math.pow( 2, - level );
2386
- const width = Math.floor( texture.image.width * levelScale );
2387
- const height = Math.floor( texture.image.height * levelScale );
2388
-
2389
- textures.setTexture2D( texture, 0 );
2390
-
2391
- _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
2392
-
2393
- state.unbindTexture();
2394
-
2395
- };
2396
-
2397
- this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
2398
-
2399
- const width = srcTexture.image.width;
2400
- const height = srcTexture.image.height;
2401
- const glFormat = utils.convert( dstTexture.format );
2402
- const glType = utils.convert( dstTexture.type );
2403
-
2404
- textures.setTexture2D( dstTexture, 0 );
2405
-
2406
- // As another texture upload may have changed pixelStorei
2407
- // parameters, make sure they are correct for the dstTexture
2408
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2409
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2410
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
2411
-
2412
- if ( srcTexture.isDataTexture ) {
2413
-
2414
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
2415
-
2416
- } else {
2417
-
2418
- if ( srcTexture.isCompressedTexture ) {
2419
-
2420
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
2421
-
2422
- } else {
2423
-
2424
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
2425
-
2426
- }
2427
-
2428
- }
2429
-
2430
- // Generate mipmaps only when copying level 0
2431
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
2432
-
2433
- state.unbindTexture();
2434
-
2435
- };
2436
-
2437
- this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
2438
-
2439
- if ( _this.isWebGL1Renderer ) {
2440
-
2441
- console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.' );
2442
- return;
2443
-
2444
- }
2445
-
2446
- const width = Math.round( sourceBox.max.x - sourceBox.min.x );
2447
- const height = Math.round( sourceBox.max.y - sourceBox.min.y );
2448
- const depth = sourceBox.max.z - sourceBox.min.z + 1;
2449
- const glFormat = utils.convert( dstTexture.format );
2450
- const glType = utils.convert( dstTexture.type );
2451
- let glTarget;
2452
-
2453
- if ( dstTexture.isData3DTexture ) {
2454
-
2455
- textures.setTexture3D( dstTexture, 0 );
2456
- glTarget = _gl.TEXTURE_3D;
2457
-
2458
- } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
2459
-
2460
- textures.setTexture2DArray( dstTexture, 0 );
2461
- glTarget = _gl.TEXTURE_2D_ARRAY;
2462
-
2463
- } else {
2464
-
2465
- console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
2466
- return;
2467
-
2468
- }
2469
-
2470
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2471
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2472
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
2473
-
2474
- const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
2475
- const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
2476
- const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
2477
- const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
2478
- const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
2479
-
2480
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
2481
-
2482
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
2483
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
2484
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
2485
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
2486
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
2487
-
2488
- if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
2489
-
2490
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
2491
-
2492
- } else {
2493
-
2494
- if ( dstTexture.isCompressedArrayTexture ) {
2495
-
2496
- _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
2497
-
2498
- } else {
2499
-
2500
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
2501
-
2502
- }
2503
-
2504
- }
2505
-
2506
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen );
2507
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );
2508
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels );
2509
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows );
2510
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages );
2511
-
2512
- // Generate mipmaps only when copying level 0
2513
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
2514
-
2515
- state.unbindTexture();
2516
-
2517
- };
2518
-
2519
- this.initTexture = function ( texture ) {
2520
-
2521
- if ( texture.isCubeTexture ) {
2522
-
2523
- textures.setTextureCube( texture, 0 );
2524
-
2525
- } else if ( texture.isData3DTexture ) {
2526
-
2527
- textures.setTexture3D( texture, 0 );
2528
-
2529
- } else if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
2530
-
2531
- textures.setTexture2DArray( texture, 0 );
2532
-
2533
- } else {
2534
-
2535
- textures.setTexture2D( texture, 0 );
2536
-
2537
- }
2538
-
2539
- state.unbindTexture();
2540
-
2541
- };
2542
-
2543
- this.resetState = function () {
2544
-
2545
- _currentActiveCubeFace = 0;
2546
- _currentActiveMipmapLevel = 0;
2547
- _currentRenderTarget = null;
2548
-
2549
- state.reset();
2550
- bindingStates.reset();
2551
-
2552
- };
2553
-
2554
- if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
2555
-
2556
- __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
2557
-
2558
- }
2559
-
2560
- }
2561
-
2562
- get coordinateSystem() {
2563
-
2564
- return WebGLCoordinateSystem;
2565
-
2566
- }
2567
-
2568
- get outputColorSpace() {
2569
-
2570
- return this._outputColorSpace;
2571
-
2572
- }
2573
-
2574
- set outputColorSpace( colorSpace ) {
2575
-
2576
- this._outputColorSpace = colorSpace;
2577
-
2578
- const gl = this.getContext();
2579
- gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace ? 'display-p3' : 'srgb';
2580
- gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? 'display-p3' : 'srgb';
2581
-
2582
- }
2583
-
2584
- get outputEncoding() { // @deprecated, r152
2585
-
2586
- console.warn( 'THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.' );
2587
- return this.outputColorSpace === SRGBColorSpace ? sRGBEncoding : LinearEncoding;
2588
-
2589
- }
2590
-
2591
- set outputEncoding( encoding ) { // @deprecated, r152
2592
-
2593
- console.warn( 'THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.' );
2594
- this.outputColorSpace = encoding === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
2595
-
2596
- }
2597
-
2598
- get useLegacyLights() { // @deprecated, r155
2599
-
2600
- console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
2601
- return this._useLegacyLights;
2602
-
2603
- }
2604
-
2605
- set useLegacyLights( value ) { // @deprecated, r155
2606
-
2607
- console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
2608
- this._useLegacyLights = value;
2609
-
2610
- }
2611
-
2612
- }
2613
-
2614
-
2615
- export { WebGLRenderer };
1
+ import {
2
+ REVISION,
3
+ BackSide,
4
+ FrontSide,
5
+ DoubleSide,
6
+ RGBAFormat,
7
+ HalfFloatType,
8
+ FloatType,
9
+ UnsignedByteType,
10
+ NoToneMapping,
11
+ LinearMipmapLinearFilter,
12
+ SRGBColorSpace,
13
+ LinearSRGBColorSpace,
14
+ sRGBEncoding,
15
+ LinearEncoding,
16
+ RGBAIntegerFormat,
17
+ RGIntegerFormat,
18
+ RedIntegerFormat,
19
+ UnsignedIntType,
20
+ UnsignedShortType,
21
+ UnsignedInt248Type,
22
+ UnsignedShort4444Type,
23
+ UnsignedShort5551Type,
24
+ WebGLCoordinateSystem,
25
+ DisplayP3ColorSpace,
26
+ LinearDisplayP3ColorSpace
27
+ } from '../constants.js';
28
+ import { Color } from '../math/Color.js';
29
+ import { Frustum } from '../math/Frustum.js';
30
+ import { Matrix4 } from '../math/Matrix4.js';
31
+ import { Vector2 } from '../math/Vector2.js';
32
+ import { Vector3 } from '../math/Vector3.js';
33
+ import { Vector4 } from '../math/Vector4.js';
34
+ import { floorPowerOfTwo } from '../math/MathUtils.js';
35
+ import { WebGLAnimation } from './webgl/WebGLAnimation.js';
36
+ import { WebGLAttributes } from './webgl/WebGLAttributes.js';
37
+ import { WebGLBackground } from './webgl/WebGLBackground.js';
38
+ import { WebGLBindingStates } from './webgl/WebGLBindingStates.js';
39
+ import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
40
+ import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
41
+ import { WebGLClipping } from './webgl/WebGLClipping.js';
42
+ import { WebGLCubeMaps } from './webgl/WebGLCubeMaps.js';
43
+ import { WebGLCubeUVMaps } from './webgl/WebGLCubeUVMaps.js';
44
+ import { WebGLExtensions } from './webgl/WebGLExtensions.js';
45
+ import { WebGLGeometries } from './webgl/WebGLGeometries.js';
46
+ import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
47
+ import { WebGLInfo } from './webgl/WebGLInfo.js';
48
+ import { WebGLMorphtargets } from './webgl/WebGLMorphtargets.js';
49
+ import { WebGLObjects } from './webgl/WebGLObjects.js';
50
+ import { WebGLPrograms } from './webgl/WebGLPrograms.js';
51
+ import { WebGLProperties } from './webgl/WebGLProperties.js';
52
+ import { WebGLRenderLists } from './webgl/WebGLRenderLists.js';
53
+ import { WebGLRenderStates } from './webgl/WebGLRenderStates.js';
54
+ import { WebGLRenderTarget } from './WebGLRenderTarget.js';
55
+ import { WebGLShadowMap } from './webgl/WebGLShadowMap.js';
56
+ import { WebGLState } from './webgl/WebGLState.js';
57
+ import { WebGLTextures } from './webgl/WebGLTextures.js';
58
+ import { WebGLUniforms } from './webgl/WebGLUniforms.js';
59
+ import { WebGLUtils } from './webgl/WebGLUtils.js';
60
+ import { WebXRManager } from './webxr/WebXRManager.js';
61
+ import { WebGLMaterials } from './webgl/WebGLMaterials.js';
62
+ import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
63
+ import { createCanvasElement } from '../utils.js';
64
+ import { ColorManagement } from '../math/ColorManagement.js';
65
+
66
+ class WebGLRenderer {
67
+
68
+ constructor( parameters = {} ) {
69
+
70
+ const {
71
+ canvas = createCanvasElement(),
72
+ context = null,
73
+ depth = true,
74
+ stencil = true,
75
+ alpha = false,
76
+ antialias = false,
77
+ premultipliedAlpha = true,
78
+ preserveDrawingBuffer = false,
79
+ powerPreference = 'default',
80
+ failIfMajorPerformanceCaveat = false,
81
+ } = parameters;
82
+
83
+ this.isWebGLRenderer = true;
84
+
85
+ let _alpha;
86
+
87
+ if ( context !== null ) {
88
+
89
+ _alpha = context.getContextAttributes().alpha;
90
+
91
+ } else {
92
+
93
+ _alpha = alpha;
94
+
95
+ }
96
+
97
+ const uintClearColor = new Uint32Array( 4 );
98
+ const intClearColor = new Int32Array( 4 );
99
+
100
+ let currentRenderList = null;
101
+ let currentRenderState = null;
102
+
103
+ // render() can be called from within a callback triggered by another render.
104
+ // We track this so that the nested render call gets its list and state isolated from the parent render call.
105
+
106
+ const renderListStack = [];
107
+ const renderStateStack = [];
108
+
109
+ // public properties
110
+
111
+ this.domElement = canvas;
112
+
113
+ // Debug configuration container
114
+ this.debug = {
115
+
116
+ /**
117
+ * Enables error checking and reporting when shader programs are being compiled
118
+ * @type {boolean}
119
+ */
120
+ checkShaderErrors: true,
121
+ /**
122
+ * Callback for custom error reporting.
123
+ * @type {?Function}
124
+ */
125
+ onShaderError: null
126
+ };
127
+
128
+ // clearing
129
+
130
+ this.autoClear = true;
131
+ this.autoClearColor = true;
132
+ this.autoClearDepth = true;
133
+ this.autoClearStencil = true;
134
+
135
+ // scene graph
136
+
137
+ this.sortObjects = true;
138
+
139
+ // user-defined clipping
140
+
141
+ this.clippingPlanes = [];
142
+ this.localClippingEnabled = false;
143
+
144
+ // physically based shading
145
+
146
+ this._outputColorSpace = SRGBColorSpace;
147
+
148
+ // physical lights
149
+
150
+ this._useLegacyLights = false;
151
+
152
+ // tone mapping
153
+
154
+ this.toneMapping = NoToneMapping;
155
+ this.toneMappingExposure = 1.0;
156
+
157
+ // internal properties
158
+
159
+ const _this = this;
160
+
161
+ let _isContextLost = false;
162
+
163
+ // internal state cache
164
+
165
+ let _currentActiveCubeFace = 0;
166
+ let _currentActiveMipmapLevel = 0;
167
+ let _currentRenderTarget = null;
168
+ let _currentMaterialId = - 1;
169
+
170
+ let _currentCamera = null;
171
+
172
+ const _currentViewport = new Vector4();
173
+ const _currentScissor = new Vector4();
174
+ let _currentScissorTest = null;
175
+
176
+ const _currentClearColor = new Color( 0x000000 );
177
+ let _currentClearAlpha = 0;
178
+
179
+ //
180
+
181
+ let _width = canvas.width;
182
+ let _height = canvas.height;
183
+
184
+ let _pixelRatio = 1;
185
+ let _opaqueSort = null;
186
+ let _transparentSort = null;
187
+
188
+ const _viewport = new Vector4( 0, 0, _width, _height );
189
+ const _scissor = new Vector4( 0, 0, _width, _height );
190
+ let _scissorTest = false;
191
+
192
+ // frustum
193
+
194
+ const _frustum = new Frustum();
195
+
196
+ // clipping
197
+
198
+ let _clippingEnabled = false;
199
+ let _localClippingEnabled = false;
200
+
201
+ // transmission
202
+
203
+ let _transmissionRenderTarget = null;
204
+
205
+ // camera matrices cache
206
+
207
+ const _projScreenMatrix = new Matrix4();
208
+
209
+ const _vector2 = new Vector2();
210
+ const _vector3 = new Vector3();
211
+
212
+ const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
213
+
214
+ function getTargetPixelRatio() {
215
+
216
+ return _currentRenderTarget === null ? _pixelRatio : 1;
217
+
218
+ }
219
+
220
+ // initialize
221
+
222
+ let _gl = context;
223
+
224
+ function getContext( contextNames, contextAttributes ) {
225
+
226
+ for ( let i = 0; i < contextNames.length; i ++ ) {
227
+
228
+ const contextName = contextNames[ i ];
229
+ const context = canvas.getContext( contextName, contextAttributes );
230
+ if ( context !== null ) return context;
231
+
232
+ }
233
+
234
+ return null;
235
+
236
+ }
237
+
238
+ try {
239
+
240
+ const contextAttributes = {
241
+ alpha: true,
242
+ depth,
243
+ stencil,
244
+ antialias,
245
+ premultipliedAlpha,
246
+ preserveDrawingBuffer,
247
+ powerPreference,
248
+ failIfMajorPerformanceCaveat,
249
+ };
250
+
251
+ // OffscreenCanvas does not have setAttribute, see #22811
252
+ if ( 'setAttribute' in canvas ) canvas.setAttribute( 'data-engine', `three.js r${REVISION}` );
253
+
254
+ // event listeners must be registered before WebGL context is created, see #12753
255
+ canvas.addEventListener( 'webglcontextlost', onContextLost, false );
256
+ canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
257
+ canvas.addEventListener( 'webglcontextcreationerror', onContextCreationError, false );
258
+
259
+ if ( _gl === null ) {
260
+
261
+ const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
262
+
263
+ if ( _this.isWebGL1Renderer === true ) {
264
+
265
+ contextNames.shift();
266
+
267
+ }
268
+
269
+ _gl = getContext( contextNames, contextAttributes );
270
+
271
+ if ( _gl === null ) {
272
+
273
+ if ( getContext( contextNames ) ) {
274
+
275
+ throw new Error( 'Error creating WebGL context with your selected attributes.' );
276
+
277
+ } else {
278
+
279
+ throw new Error( 'Error creating WebGL context.' );
280
+
281
+ }
282
+
283
+ }
284
+
285
+ }
286
+
287
+ if ( typeof WebGLRenderingContext !== 'undefined' && _gl instanceof WebGLRenderingContext ) { // @deprecated, r153
288
+
289
+ console.warn( 'THREE.WebGLRenderer: WebGL 1 support was deprecated in r153 and will be removed in r163.' );
290
+
291
+ }
292
+
293
+ // Some experimental-webgl implementations do not have getShaderPrecisionFormat
294
+
295
+ if ( _gl.getShaderPrecisionFormat === undefined ) {
296
+
297
+ _gl.getShaderPrecisionFormat = function () {
298
+
299
+ return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
300
+
301
+ };
302
+
303
+ }
304
+
305
+ } catch ( error ) {
306
+
307
+ console.error( 'THREE.WebGLRenderer: ' + error.message );
308
+ throw error;
309
+
310
+ }
311
+
312
+ let extensions, capabilities, state, info;
313
+ let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
314
+ let programCache, materials, renderLists, renderStates, clipping, shadowMap;
315
+
316
+ let background, morphtargets, bufferRenderer, indexedBufferRenderer;
317
+
318
+ let utils, bindingStates, uniformsGroups;
319
+
320
+ function initGLContext() {
321
+
322
+ extensions = new WebGLExtensions( _gl );
323
+
324
+ capabilities = new WebGLCapabilities( _gl, extensions, parameters );
325
+
326
+ extensions.init( capabilities );
327
+
328
+ utils = new WebGLUtils( _gl, extensions, capabilities );
329
+
330
+ state = new WebGLState( _gl, extensions, capabilities );
331
+
332
+ info = new WebGLInfo( _gl );
333
+ properties = new WebGLProperties();
334
+ textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
335
+ cubemaps = new WebGLCubeMaps( _this );
336
+ cubeuvmaps = new WebGLCubeUVMaps( _this );
337
+ attributes = new WebGLAttributes( _gl, capabilities );
338
+ bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
339
+ geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
340
+ objects = new WebGLObjects( _gl, geometries, attributes, info );
341
+ morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
342
+ clipping = new WebGLClipping( properties );
343
+ programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
344
+ materials = new WebGLMaterials( _this, properties );
345
+ renderLists = new WebGLRenderLists();
346
+ renderStates = new WebGLRenderStates( extensions, capabilities );
347
+ background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha );
348
+ shadowMap = new WebGLShadowMap( _this, objects, capabilities );
349
+ uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );
350
+
351
+ bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
352
+ indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
353
+
354
+ info.programs = programCache.programs;
355
+
356
+ _this.capabilities = capabilities;
357
+ _this.extensions = extensions;
358
+ _this.properties = properties;
359
+ _this.renderLists = renderLists;
360
+ _this.shadowMap = shadowMap;
361
+ _this.state = state;
362
+ _this.info = info;
363
+
364
+ }
365
+
366
+ initGLContext();
367
+
368
+ // xr
369
+
370
+ const xr = new WebXRManager( _this, _gl );
371
+
372
+ this.xr = xr;
373
+
374
+ // API
375
+
376
+ this.getContext = function () {
377
+
378
+ return _gl;
379
+
380
+ };
381
+
382
+ this.getContextAttributes = function () {
383
+
384
+ return _gl.getContextAttributes();
385
+
386
+ };
387
+
388
+ this.forceContextLoss = function () {
389
+
390
+ const extension = extensions.get( 'WEBGL_lose_context' );
391
+ if ( extension ) extension.loseContext();
392
+
393
+ };
394
+
395
+ this.forceContextRestore = function () {
396
+
397
+ const extension = extensions.get( 'WEBGL_lose_context' );
398
+ if ( extension ) extension.restoreContext();
399
+
400
+ };
401
+
402
+ this.getPixelRatio = function () {
403
+
404
+ return _pixelRatio;
405
+
406
+ };
407
+
408
+ this.setPixelRatio = function ( value ) {
409
+
410
+ if ( value === undefined ) return;
411
+
412
+ _pixelRatio = value;
413
+
414
+ this.setSize( _width, _height, false );
415
+
416
+ };
417
+
418
+ this.getSize = function ( target ) {
419
+
420
+ return target.set( _width, _height );
421
+
422
+ };
423
+
424
+ this.setSize = function ( width, height, updateStyle = true ) {
425
+
426
+ if ( xr.isPresenting ) {
427
+
428
+ console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
429
+ return;
430
+
431
+ }
432
+
433
+ _width = width;
434
+ _height = height;
435
+
436
+ canvas.width = Math.floor( width * _pixelRatio );
437
+ canvas.height = Math.floor( height * _pixelRatio );
438
+
439
+ if ( updateStyle === true ) {
440
+
441
+ canvas.style.width = width + 'px';
442
+ canvas.style.height = height + 'px';
443
+
444
+ }
445
+
446
+ this.setViewport( 0, 0, width, height );
447
+
448
+ };
449
+
450
+ this.getDrawingBufferSize = function ( target ) {
451
+
452
+ return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
453
+
454
+ };
455
+
456
+ this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
457
+
458
+ _width = width;
459
+ _height = height;
460
+
461
+ _pixelRatio = pixelRatio;
462
+
463
+ canvas.width = Math.floor( width * pixelRatio );
464
+ canvas.height = Math.floor( height * pixelRatio );
465
+
466
+ this.setViewport( 0, 0, width, height );
467
+
468
+ };
469
+
470
+ this.getCurrentViewport = function ( target ) {
471
+
472
+ return target.copy( _currentViewport );
473
+
474
+ };
475
+
476
+ this.getViewport = function ( target ) {
477
+
478
+ return target.copy( _viewport );
479
+
480
+ };
481
+
482
+ this.setViewport = function ( x, y, width, height ) {
483
+
484
+ if ( x.isVector4 ) {
485
+
486
+ _viewport.set( x.x, x.y, x.z, x.w );
487
+
488
+ } else {
489
+
490
+ _viewport.set( x, y, width, height );
491
+
492
+ }
493
+
494
+ state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).round() );
495
+
496
+ };
497
+
498
+ this.getScissor = function ( target ) {
499
+
500
+ return target.copy( _scissor );
501
+
502
+ };
503
+
504
+ this.setScissor = function ( x, y, width, height ) {
505
+
506
+ if ( x.isVector4 ) {
507
+
508
+ _scissor.set( x.x, x.y, x.z, x.w );
509
+
510
+ } else {
511
+
512
+ _scissor.set( x, y, width, height );
513
+
514
+ }
515
+
516
+ state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).round() );
517
+
518
+ };
519
+
520
+ this.getScissorTest = function () {
521
+
522
+ return _scissorTest;
523
+
524
+ };
525
+
526
+ this.setScissorTest = function ( boolean ) {
527
+
528
+ state.setScissorTest( _scissorTest = boolean );
529
+
530
+ };
531
+
532
+ this.setOpaqueSort = function ( method ) {
533
+
534
+ _opaqueSort = method;
535
+
536
+ };
537
+
538
+ this.setTransparentSort = function ( method ) {
539
+
540
+ _transparentSort = method;
541
+
542
+ };
543
+
544
+ // Clearing
545
+
546
+ this.getClearColor = function ( target ) {
547
+
548
+ return target.copy( background.getClearColor() );
549
+
550
+ };
551
+
552
+ this.setClearColor = function () {
553
+
554
+ background.setClearColor.apply( background, arguments );
555
+
556
+ };
557
+
558
+ this.getClearAlpha = function () {
559
+
560
+ return background.getClearAlpha();
561
+
562
+ };
563
+
564
+ this.setClearAlpha = function () {
565
+
566
+ background.setClearAlpha.apply( background, arguments );
567
+
568
+ };
569
+
570
+ this.clear = function ( color = true, depth = true, stencil = true ) {
571
+
572
+ let bits = 0;
573
+
574
+ if ( color ) {
575
+
576
+ // check if we're trying to clear an integer target
577
+ let isIntegerFormat = false;
578
+ if ( _currentRenderTarget !== null ) {
579
+
580
+ const targetFormat = _currentRenderTarget.texture.format;
581
+ isIntegerFormat = targetFormat === RGBAIntegerFormat ||
582
+ targetFormat === RGIntegerFormat ||
583
+ targetFormat === RedIntegerFormat;
584
+
585
+ }
586
+
587
+ // use the appropriate clear functions to clear the target if it's a signed
588
+ // or unsigned integer target
589
+ if ( isIntegerFormat ) {
590
+
591
+ const targetType = _currentRenderTarget.texture.type;
592
+ const isUnsignedType = targetType === UnsignedByteType ||
593
+ targetType === UnsignedIntType ||
594
+ targetType === UnsignedShortType ||
595
+ targetType === UnsignedInt248Type ||
596
+ targetType === UnsignedShort4444Type ||
597
+ targetType === UnsignedShort5551Type;
598
+
599
+ const clearColor = background.getClearColor();
600
+ const a = background.getClearAlpha();
601
+ const r = clearColor.r;
602
+ const g = clearColor.g;
603
+ const b = clearColor.b;
604
+
605
+ if ( isUnsignedType ) {
606
+
607
+ uintClearColor[ 0 ] = r;
608
+ uintClearColor[ 1 ] = g;
609
+ uintClearColor[ 2 ] = b;
610
+ uintClearColor[ 3 ] = a;
611
+ _gl.clearBufferuiv( _gl.COLOR, 0, uintClearColor );
612
+
613
+ } else {
614
+
615
+ intClearColor[ 0 ] = r;
616
+ intClearColor[ 1 ] = g;
617
+ intClearColor[ 2 ] = b;
618
+ intClearColor[ 3 ] = a;
619
+ _gl.clearBufferiv( _gl.COLOR, 0, intClearColor );
620
+
621
+ }
622
+
623
+ } else {
624
+
625
+ bits |= _gl.COLOR_BUFFER_BIT;
626
+
627
+ }
628
+
629
+ }
630
+
631
+ if ( depth ) bits |= _gl.DEPTH_BUFFER_BIT;
632
+ if ( stencil ) {
633
+
634
+ bits |= _gl.STENCIL_BUFFER_BIT;
635
+ this.state.buffers.stencil.setMask( 0xffffffff );
636
+
637
+ }
638
+
639
+ _gl.clear( bits );
640
+
641
+ };
642
+
643
+ this.clearColor = function () {
644
+
645
+ this.clear( true, false, false );
646
+
647
+ };
648
+
649
+ this.clearDepth = function () {
650
+
651
+ this.clear( false, true, false );
652
+
653
+ };
654
+
655
+ this.clearStencil = function () {
656
+
657
+ this.clear( false, false, true );
658
+
659
+ };
660
+
661
+ //
662
+
663
+ this.dispose = function () {
664
+
665
+ canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
666
+ canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
667
+ canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );
668
+
669
+ renderLists.dispose();
670
+ renderStates.dispose();
671
+ properties.dispose();
672
+ cubemaps.dispose();
673
+ cubeuvmaps.dispose();
674
+ objects.dispose();
675
+ bindingStates.dispose();
676
+ uniformsGroups.dispose();
677
+ programCache.dispose();
678
+
679
+ xr.dispose();
680
+
681
+ xr.removeEventListener( 'sessionstart', onXRSessionStart );
682
+ xr.removeEventListener( 'sessionend', onXRSessionEnd );
683
+
684
+ if ( _transmissionRenderTarget ) {
685
+
686
+ _transmissionRenderTarget.dispose();
687
+ _transmissionRenderTarget = null;
688
+
689
+ }
690
+
691
+ animation.stop();
692
+
693
+ };
694
+
695
+ // Events
696
+
697
+ function onContextLost( event ) {
698
+
699
+ event.preventDefault();
700
+
701
+ console.log( 'THREE.WebGLRenderer: Context Lost.' );
702
+
703
+ _isContextLost = true;
704
+
705
+ }
706
+
707
+ function onContextRestore( /* event */ ) {
708
+
709
+ console.log( 'THREE.WebGLRenderer: Context Restored.' );
710
+
711
+ _isContextLost = false;
712
+
713
+ const infoAutoReset = info.autoReset;
714
+ const shadowMapEnabled = shadowMap.enabled;
715
+ const shadowMapAutoUpdate = shadowMap.autoUpdate;
716
+ const shadowMapNeedsUpdate = shadowMap.needsUpdate;
717
+ const shadowMapType = shadowMap.type;
718
+
719
+ initGLContext();
720
+
721
+ info.autoReset = infoAutoReset;
722
+ shadowMap.enabled = shadowMapEnabled;
723
+ shadowMap.autoUpdate = shadowMapAutoUpdate;
724
+ shadowMap.needsUpdate = shadowMapNeedsUpdate;
725
+ shadowMap.type = shadowMapType;
726
+
727
+ }
728
+
729
+ function onContextCreationError( event ) {
730
+
731
+ console.error( 'THREE.WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage );
732
+
733
+ }
734
+
735
+ function onMaterialDispose( event ) {
736
+
737
+ const material = event.target;
738
+
739
+ material.removeEventListener( 'dispose', onMaterialDispose );
740
+
741
+ deallocateMaterial( material );
742
+
743
+ }
744
+
745
+ // Buffer deallocation
746
+
747
+ function deallocateMaterial( material ) {
748
+
749
+ releaseMaterialProgramReferences( material );
750
+
751
+ properties.remove( material );
752
+
753
+ }
754
+
755
+
756
+ function releaseMaterialProgramReferences( material ) {
757
+
758
+ const programs = properties.get( material ).programs;
759
+
760
+ if ( programs !== undefined ) {
761
+
762
+ programs.forEach( function ( program ) {
763
+
764
+ programCache.releaseProgram( program );
765
+
766
+ } );
767
+
768
+ if ( material.isShaderMaterial ) {
769
+
770
+ programCache.releaseShaderCache( material );
771
+
772
+ }
773
+
774
+ }
775
+
776
+ }
777
+
778
+ // Buffer rendering
779
+
780
+ this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
781
+
782
+ if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
783
+
784
+ const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
785
+
786
+ const program = setProgram( camera, scene, geometry, material, object );
787
+
788
+ state.setMaterial( material, frontFaceCW );
789
+
790
+ //
791
+
792
+ let index = geometry.index;
793
+ let rangeFactor = 1;
794
+
795
+ if ( material.wireframe === true ) {
796
+
797
+ index = geometries.getWireframeAttribute( geometry );
798
+
799
+ if ( index === undefined ) return;
800
+
801
+ rangeFactor = 2;
802
+
803
+ }
804
+
805
+ //
806
+
807
+ const drawRange = geometry.drawRange;
808
+ const position = geometry.attributes.position;
809
+
810
+ let drawStart = drawRange.start * rangeFactor;
811
+ let drawEnd = ( drawRange.start + drawRange.count ) * rangeFactor;
812
+
813
+ if ( group !== null ) {
814
+
815
+ drawStart = Math.max( drawStart, group.start * rangeFactor );
816
+ drawEnd = Math.min( drawEnd, ( group.start + group.count ) * rangeFactor );
817
+
818
+ }
819
+
820
+ if ( index !== null ) {
821
+
822
+ drawStart = Math.max( drawStart, 0 );
823
+ drawEnd = Math.min( drawEnd, index.count );
824
+
825
+ } else if ( position !== undefined && position !== null ) {
826
+
827
+ drawStart = Math.max( drawStart, 0 );
828
+ drawEnd = Math.min( drawEnd, position.count );
829
+
830
+ }
831
+
832
+ const drawCount = drawEnd - drawStart;
833
+
834
+ if ( drawCount < 0 || drawCount === Infinity ) return;
835
+
836
+ //
837
+
838
+ bindingStates.setup( object, material, program, geometry, index );
839
+
840
+ let attribute;
841
+ let renderer = bufferRenderer;
842
+
843
+ if ( index !== null ) {
844
+
845
+ attribute = attributes.get( index );
846
+
847
+ renderer = indexedBufferRenderer;
848
+ renderer.setIndex( attribute );
849
+
850
+ }
851
+
852
+ //
853
+
854
+ if ( object.isMesh ) {
855
+
856
+ if ( material.wireframe === true ) {
857
+
858
+ state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
859
+ renderer.setMode( _gl.LINES );
860
+
861
+ } else {
862
+
863
+ renderer.setMode( _gl.TRIANGLES );
864
+
865
+ }
866
+
867
+ } else if ( object.isLine ) {
868
+
869
+ let lineWidth = material.linewidth;
870
+
871
+ if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
872
+
873
+ state.setLineWidth( lineWidth * getTargetPixelRatio() );
874
+
875
+ if ( object.isLineSegments ) {
876
+
877
+ renderer.setMode( _gl.LINES );
878
+
879
+ } else if ( object.isLineLoop ) {
880
+
881
+ renderer.setMode( _gl.LINE_LOOP );
882
+
883
+ } else {
884
+
885
+ renderer.setMode( _gl.LINE_STRIP );
886
+
887
+ }
888
+
889
+ } else if ( object.isPoints ) {
890
+
891
+ renderer.setMode( _gl.POINTS );
892
+
893
+ } else if ( object.isSprite ) {
894
+
895
+ renderer.setMode( _gl.TRIANGLES );
896
+
897
+ }
898
+
899
+ if ( object.isBatchedMesh ) {
900
+
901
+ renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
902
+
903
+ } else if ( object.isInstancedMesh ) {
904
+
905
+ renderer.renderInstances( drawStart, drawCount, object.count );
906
+
907
+ } else if ( geometry.isInstancedBufferGeometry ) {
908
+
909
+ const maxInstanceCount = geometry._maxInstanceCount !== undefined ? geometry._maxInstanceCount : Infinity;
910
+ const instanceCount = Math.min( geometry.instanceCount, maxInstanceCount );
911
+
912
+ renderer.renderInstances( drawStart, drawCount, instanceCount );
913
+
914
+ } else {
915
+
916
+ renderer.render( drawStart, drawCount );
917
+
918
+ }
919
+
920
+ };
921
+
922
+ // Compile
923
+
924
+ function prepareMaterial( material, scene, object ) {
925
+
926
+ if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
927
+
928
+ material.side = BackSide;
929
+ material.needsUpdate = true;
930
+ getProgram( material, scene, object );
931
+
932
+ material.side = FrontSide;
933
+ material.needsUpdate = true;
934
+ getProgram( material, scene, object );
935
+
936
+ material.side = DoubleSide;
937
+
938
+ } else {
939
+
940
+ getProgram( material, scene, object );
941
+
942
+ }
943
+
944
+ }
945
+
946
+ this.compile = function ( scene, camera, targetScene = null ) {
947
+
948
+ if ( targetScene === null ) targetScene = scene;
949
+
950
+ currentRenderState = renderStates.get( targetScene );
951
+ currentRenderState.init();
952
+
953
+ renderStateStack.push( currentRenderState );
954
+
955
+ // gather lights from both the target scene and the new object that will be added to the scene.
956
+
957
+ targetScene.traverseVisible( function ( object ) {
958
+
959
+ if ( object.isLight && object.layers.test( camera.layers ) ) {
960
+
961
+ currentRenderState.pushLight( object );
962
+
963
+ if ( object.castShadow ) {
964
+
965
+ currentRenderState.pushShadow( object );
966
+
967
+ }
968
+
969
+ }
970
+
971
+ } );
972
+
973
+ if ( scene !== targetScene ) {
974
+
975
+ scene.traverseVisible( function ( object ) {
976
+
977
+ if ( object.isLight && object.layers.test( camera.layers ) ) {
978
+
979
+ currentRenderState.pushLight( object );
980
+
981
+ if ( object.castShadow ) {
982
+
983
+ currentRenderState.pushShadow( object );
984
+
985
+ }
986
+
987
+ }
988
+
989
+ } );
990
+
991
+ }
992
+
993
+ currentRenderState.setupLights( _this._useLegacyLights );
994
+
995
+ // Only initialize materials in the new scene, not the targetScene.
996
+
997
+ const materials = new Set();
998
+
999
+ scene.traverse( function ( object ) {
1000
+
1001
+ const material = object.material;
1002
+
1003
+ if ( material ) {
1004
+
1005
+ if ( Array.isArray( material ) ) {
1006
+
1007
+ for ( let i = 0; i < material.length; i ++ ) {
1008
+
1009
+ const material2 = material[ i ];
1010
+
1011
+ prepareMaterial( material2, targetScene, object );
1012
+ materials.add( material2 );
1013
+
1014
+ }
1015
+
1016
+ } else {
1017
+
1018
+ prepareMaterial( material, targetScene, object );
1019
+ materials.add( material );
1020
+
1021
+ }
1022
+
1023
+ }
1024
+
1025
+ } );
1026
+
1027
+ renderStateStack.pop();
1028
+ currentRenderState = null;
1029
+
1030
+ return materials;
1031
+
1032
+ };
1033
+
1034
+ // compileAsync
1035
+
1036
+ this.compileAsync = function ( scene, camera, targetScene = null ) {
1037
+
1038
+ const materials = this.compile( scene, camera, targetScene );
1039
+
1040
+ // Wait for all the materials in the new object to indicate that they're
1041
+ // ready to be used before resolving the promise.
1042
+
1043
+ return new Promise( ( resolve ) => {
1044
+
1045
+ function checkMaterialsReady() {
1046
+
1047
+ materials.forEach( function ( material ) {
1048
+
1049
+ const materialProperties = properties.get( material );
1050
+ const program = materialProperties.currentProgram;
1051
+
1052
+ if ( program.isReady() ) {
1053
+
1054
+ // remove any programs that report they're ready to use from the list
1055
+ materials.delete( material );
1056
+
1057
+ }
1058
+
1059
+ } );
1060
+
1061
+ // once the list of compiling materials is empty, call the callback
1062
+
1063
+ if ( materials.size === 0 ) {
1064
+
1065
+ resolve( scene );
1066
+ return;
1067
+
1068
+ }
1069
+
1070
+ // if some materials are still not ready, wait a bit and check again
1071
+
1072
+ setTimeout( checkMaterialsReady, 10 );
1073
+
1074
+ }
1075
+
1076
+ if ( extensions.get( 'KHR_parallel_shader_compile' ) !== null ) {
1077
+
1078
+ // If we can check the compilation status of the materials without
1079
+ // blocking then do so right away.
1080
+
1081
+ checkMaterialsReady();
1082
+
1083
+ } else {
1084
+
1085
+ // Otherwise start by waiting a bit to give the materials we just
1086
+ // initialized a chance to finish.
1087
+
1088
+ setTimeout( checkMaterialsReady, 10 );
1089
+
1090
+ }
1091
+
1092
+ } );
1093
+
1094
+ };
1095
+
1096
+ // Animation Loop
1097
+
1098
+ let onAnimationFrameCallback = null;
1099
+
1100
+ function onAnimationFrame( time ) {
1101
+
1102
+ if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
1103
+
1104
+ }
1105
+
1106
+ function onXRSessionStart() {
1107
+
1108
+ animation.stop();
1109
+
1110
+ }
1111
+
1112
+ function onXRSessionEnd() {
1113
+
1114
+ animation.start();
1115
+
1116
+ }
1117
+
1118
+ const animation = new WebGLAnimation();
1119
+ animation.setAnimationLoop( onAnimationFrame );
1120
+
1121
+ if ( typeof self !== 'undefined' ) animation.setContext( self );
1122
+
1123
+ this.setAnimationLoop = function ( callback ) {
1124
+
1125
+ onAnimationFrameCallback = callback;
1126
+ xr.setAnimationLoop( callback );
1127
+
1128
+ ( callback === null ) ? animation.stop() : animation.start();
1129
+
1130
+ };
1131
+
1132
+ xr.addEventListener( 'sessionstart', onXRSessionStart );
1133
+ xr.addEventListener( 'sessionend', onXRSessionEnd );
1134
+
1135
+ // Rendering
1136
+
1137
+ this.render = function ( scene, camera ) {
1138
+
1139
+ if ( camera !== undefined && camera.isCamera !== true ) {
1140
+
1141
+ console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
1142
+ return;
1143
+
1144
+ }
1145
+
1146
+ if ( _isContextLost === true ) return;
1147
+
1148
+ // update scene graph
1149
+
1150
+ if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
1151
+
1152
+ // update camera matrices and frustum
1153
+
1154
+ if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
1155
+
1156
+ if ( xr.enabled === true && xr.isPresenting === true ) {
1157
+
1158
+ if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
1159
+
1160
+ camera = xr.getCamera(); // use XR camera for rendering
1161
+
1162
+ }
1163
+
1164
+ //
1165
+ if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, _currentRenderTarget );
1166
+
1167
+ currentRenderState = renderStates.get( scene, renderStateStack.length );
1168
+ currentRenderState.init();
1169
+
1170
+ renderStateStack.push( currentRenderState );
1171
+
1172
+ _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
1173
+ _frustum.setFromProjectionMatrix( _projScreenMatrix );
1174
+
1175
+ _localClippingEnabled = this.localClippingEnabled;
1176
+ _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
1177
+
1178
+ currentRenderList = renderLists.get( scene, renderListStack.length );
1179
+ currentRenderList.init();
1180
+
1181
+ renderListStack.push( currentRenderList );
1182
+
1183
+ projectObject( scene, camera, 0, _this.sortObjects );
1184
+
1185
+ currentRenderList.finish();
1186
+
1187
+ if ( _this.sortObjects === true ) {
1188
+
1189
+ currentRenderList.sort( _opaqueSort, _transparentSort );
1190
+
1191
+ }
1192
+
1193
+ //
1194
+
1195
+ this.info.render.frame ++;
1196
+
1197
+ if ( _clippingEnabled === true ) clipping.beginShadows();
1198
+
1199
+ const shadowsArray = currentRenderState.state.shadowsArray;
1200
+
1201
+ shadowMap.render( shadowsArray, scene, camera );
1202
+
1203
+ if ( _clippingEnabled === true ) clipping.endShadows();
1204
+
1205
+ //
1206
+
1207
+ if ( this.info.autoReset === true ) this.info.reset();
1208
+
1209
+
1210
+ //
1211
+
1212
+ if ( xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false ) {
1213
+
1214
+ background.render( currentRenderList, scene );
1215
+
1216
+ }
1217
+
1218
+ // render scene
1219
+
1220
+ currentRenderState.setupLights( _this._useLegacyLights );
1221
+
1222
+ if ( camera.isArrayCamera ) {
1223
+
1224
+ const cameras = camera.cameras;
1225
+
1226
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1227
+
1228
+ const camera2 = cameras[ i ];
1229
+
1230
+ renderScene( currentRenderList, scene, camera2, camera2.viewport );
1231
+
1232
+ }
1233
+
1234
+ } else {
1235
+
1236
+ renderScene( currentRenderList, scene, camera );
1237
+
1238
+ }
1239
+
1240
+ //
1241
+
1242
+ if ( _currentRenderTarget !== null ) {
1243
+
1244
+ // resolve multisample renderbuffers to a single-sample texture if necessary
1245
+
1246
+ textures.updateMultisampleRenderTarget( _currentRenderTarget );
1247
+
1248
+ // Generate mipmap if we're using any kind of mipmap filtering
1249
+
1250
+ textures.updateRenderTargetMipmap( _currentRenderTarget );
1251
+
1252
+ }
1253
+
1254
+ //
1255
+
1256
+ if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
1257
+
1258
+ // _gl.finish();
1259
+
1260
+ bindingStates.resetDefaultState();
1261
+ _currentMaterialId = - 1;
1262
+ _currentCamera = null;
1263
+
1264
+ renderStateStack.pop();
1265
+
1266
+ if ( renderStateStack.length > 0 ) {
1267
+
1268
+ currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
1269
+
1270
+ } else {
1271
+
1272
+ currentRenderState = null;
1273
+
1274
+ }
1275
+
1276
+ renderListStack.pop();
1277
+
1278
+ if ( renderListStack.length > 0 ) {
1279
+
1280
+ currentRenderList = renderListStack[ renderListStack.length - 1 ];
1281
+
1282
+ } else {
1283
+
1284
+ currentRenderList = null;
1285
+
1286
+ }
1287
+
1288
+ };
1289
+
1290
+ function projectObject( object, camera, groupOrder, sortObjects ) {
1291
+
1292
+ if ( object.visible === false ) return;
1293
+
1294
+ const visible = object.layers.test( camera.layers );
1295
+
1296
+ if ( visible ) {
1297
+
1298
+ if ( object.isGroup ) {
1299
+
1300
+ groupOrder = object.renderOrder;
1301
+
1302
+ } else if ( object.isLOD ) {
1303
+
1304
+ if ( object.autoUpdate === true ) object.update( camera );
1305
+
1306
+ } else if ( object.isLight ) {
1307
+
1308
+ currentRenderState.pushLight( object );
1309
+
1310
+ if ( object.castShadow ) {
1311
+
1312
+ currentRenderState.pushShadow( object );
1313
+
1314
+ }
1315
+
1316
+ } else if ( object.isSprite ) {
1317
+
1318
+ if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
1319
+
1320
+ if ( sortObjects ) {
1321
+
1322
+ _vector3.setFromMatrixPosition( object.matrixWorld )
1323
+ .applyMatrix4( _projScreenMatrix );
1324
+
1325
+ }
1326
+
1327
+ const geometry = objects.update( object );
1328
+ const material = object.material;
1329
+
1330
+ if ( material.visible ) {
1331
+
1332
+ currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
1333
+
1334
+ }
1335
+
1336
+ }
1337
+
1338
+ } else if ( object.isMesh || object.isLine || object.isPoints ) {
1339
+
1340
+ if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
1341
+
1342
+ const geometry = objects.update( object );
1343
+ const material = object.material;
1344
+
1345
+ if ( sortObjects ) {
1346
+
1347
+ if ( object.boundingSphere !== undefined ) {
1348
+
1349
+ if ( object.boundingSphere === null ) object.computeBoundingSphere();
1350
+ _vector3.copy( object.boundingSphere.center );
1351
+
1352
+ } else {
1353
+
1354
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
1355
+ _vector3.copy( geometry.boundingSphere.center );
1356
+
1357
+ }
1358
+
1359
+ _vector3
1360
+ .applyMatrix4( object.matrixWorld )
1361
+ .applyMatrix4( _projScreenMatrix );
1362
+
1363
+ }
1364
+
1365
+ if ( Array.isArray( material ) ) {
1366
+
1367
+ const groups = geometry.groups;
1368
+
1369
+ for ( let i = 0, l = groups.length; i < l; i ++ ) {
1370
+
1371
+ const group = groups[ i ];
1372
+ const groupMaterial = material[ group.materialIndex ];
1373
+
1374
+ if ( groupMaterial && groupMaterial.visible ) {
1375
+
1376
+ currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
1377
+
1378
+ }
1379
+
1380
+ }
1381
+
1382
+ } else if ( material.visible ) {
1383
+
1384
+ currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
1385
+
1386
+ }
1387
+
1388
+ }
1389
+
1390
+ }
1391
+
1392
+ }
1393
+
1394
+ const children = object.children;
1395
+
1396
+ for ( let i = 0, l = children.length; i < l; i ++ ) {
1397
+
1398
+ projectObject( children[ i ], camera, groupOrder, sortObjects );
1399
+
1400
+ }
1401
+
1402
+ }
1403
+
1404
+ function renderScene( currentRenderList, scene, camera, viewport ) {
1405
+
1406
+ const opaqueObjects = currentRenderList.opaque;
1407
+ const transmissiveObjects = currentRenderList.transmissive;
1408
+ const transparentObjects = currentRenderList.transparent;
1409
+
1410
+ currentRenderState.setupLightsView( camera );
1411
+
1412
+ if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera );
1413
+
1414
+ if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
1415
+
1416
+ if ( viewport ) state.viewport( _currentViewport.copy( viewport ) );
1417
+
1418
+ if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
1419
+ if ( transmissiveObjects.length > 0 ) renderObjects( transmissiveObjects, scene, camera );
1420
+ if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
1421
+
1422
+ // Ensure depth buffer writing is enabled so it can be cleared on next render
1423
+
1424
+ state.buffers.depth.setTest( true );
1425
+ state.buffers.depth.setMask( true );
1426
+ state.buffers.color.setMask( true );
1427
+
1428
+ state.setPolygonOffset( false );
1429
+
1430
+ }
1431
+
1432
+ function renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ) {
1433
+
1434
+ const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
1435
+
1436
+ if ( overrideMaterial !== null ) {
1437
+
1438
+ return;
1439
+
1440
+ }
1441
+
1442
+ const isWebGL2 = capabilities.isWebGL2;
1443
+
1444
+ if ( _transmissionRenderTarget === null ) {
1445
+
1446
+ _transmissionRenderTarget = new WebGLRenderTarget( 1, 1, {
1447
+ generateMipmaps: true,
1448
+ type: extensions.has( 'EXT_color_buffer_half_float' ) ? HalfFloatType : UnsignedByteType,
1449
+ minFilter: LinearMipmapLinearFilter,
1450
+ samples: ( isWebGL2 ) ? 4 : 0
1451
+ } );
1452
+
1453
+ // debug
1454
+
1455
+ /*
1456
+ const geometry = new PlaneGeometry();
1457
+ const material = new MeshBasicMaterial( { map: _transmissionRenderTarget.texture } );
1458
+
1459
+ const mesh = new Mesh( geometry, material );
1460
+ scene.add( mesh );
1461
+ */
1462
+
1463
+ }
1464
+
1465
+ _this.getDrawingBufferSize( _vector2 );
1466
+
1467
+ if ( isWebGL2 ) {
1468
+
1469
+ _transmissionRenderTarget.setSize( _vector2.x, _vector2.y );
1470
+
1471
+ } else {
1472
+
1473
+ _transmissionRenderTarget.setSize( floorPowerOfTwo( _vector2.x ), floorPowerOfTwo( _vector2.y ) );
1474
+
1475
+ }
1476
+
1477
+ //
1478
+
1479
+ const currentRenderTarget = _this.getRenderTarget();
1480
+ _this.setRenderTarget( _transmissionRenderTarget );
1481
+
1482
+ _this.getClearColor( _currentClearColor );
1483
+ _currentClearAlpha = _this.getClearAlpha();
1484
+ if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );
1485
+
1486
+ _this.clear();
1487
+
1488
+ // Turn off the features which can affect the frag color for opaque objects pass.
1489
+ // Otherwise they are applied twice in opaque objects pass and transmission objects pass.
1490
+ const currentToneMapping = _this.toneMapping;
1491
+ _this.toneMapping = NoToneMapping;
1492
+
1493
+ renderObjects( opaqueObjects, scene, camera );
1494
+
1495
+ textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
1496
+ textures.updateRenderTargetMipmap( _transmissionRenderTarget );
1497
+
1498
+ let renderTargetNeedsUpdate = false;
1499
+
1500
+ for ( let i = 0, l = transmissiveObjects.length; i < l; i ++ ) {
1501
+
1502
+ const renderItem = transmissiveObjects[ i ];
1503
+
1504
+ const object = renderItem.object;
1505
+ const geometry = renderItem.geometry;
1506
+ const material = renderItem.material;
1507
+ const group = renderItem.group;
1508
+
1509
+ if ( material.side === DoubleSide && object.layers.test( camera.layers ) ) {
1510
+
1511
+ const currentSide = material.side;
1512
+
1513
+ material.side = BackSide;
1514
+ material.needsUpdate = true;
1515
+
1516
+ renderObject( object, scene, camera, geometry, material, group );
1517
+
1518
+ material.side = currentSide;
1519
+ material.needsUpdate = true;
1520
+
1521
+ renderTargetNeedsUpdate = true;
1522
+
1523
+ }
1524
+
1525
+ }
1526
+
1527
+ if ( renderTargetNeedsUpdate === true ) {
1528
+
1529
+ textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
1530
+ textures.updateRenderTargetMipmap( _transmissionRenderTarget );
1531
+
1532
+ }
1533
+
1534
+ _this.setRenderTarget( currentRenderTarget );
1535
+
1536
+ _this.setClearColor( _currentClearColor, _currentClearAlpha );
1537
+
1538
+ _this.toneMapping = currentToneMapping;
1539
+
1540
+ }
1541
+
1542
+ function renderObjects( renderList, scene, camera ) {
1543
+
1544
+ const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
1545
+
1546
+ for ( let i = 0, l = renderList.length; i < l; i ++ ) {
1547
+
1548
+ const renderItem = renderList[ i ];
1549
+
1550
+ const object = renderItem.object;
1551
+ const geometry = renderItem.geometry;
1552
+ const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
1553
+ const group = renderItem.group;
1554
+
1555
+ if ( object.layers.test( camera.layers ) ) {
1556
+
1557
+ renderObject( object, scene, camera, geometry, material, group );
1558
+
1559
+ }
1560
+
1561
+ }
1562
+
1563
+ }
1564
+
1565
+ function renderObject( object, scene, camera, geometry, material, group ) {
1566
+
1567
+ object.onBeforeRender( _this, scene, camera, geometry, material, group );
1568
+
1569
+ object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
1570
+ object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
1571
+
1572
+ material.onBeforeRender( _this, scene, camera, geometry, object, group );
1573
+
1574
+ if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
1575
+
1576
+ material.side = BackSide;
1577
+ material.needsUpdate = true;
1578
+ _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1579
+
1580
+ material.side = FrontSide;
1581
+ material.needsUpdate = true;
1582
+ _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1583
+
1584
+ material.side = DoubleSide;
1585
+
1586
+ } else {
1587
+
1588
+ _this.renderBufferDirect( camera, scene, geometry, material, object, group );
1589
+
1590
+ }
1591
+
1592
+ object.onAfterRender( _this, scene, camera, geometry, material, group );
1593
+
1594
+ }
1595
+
1596
+ function getProgram( material, scene, object ) {
1597
+
1598
+ if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
1599
+
1600
+ const materialProperties = properties.get( material );
1601
+
1602
+ const lights = currentRenderState.state.lights;
1603
+ const shadowsArray = currentRenderState.state.shadowsArray;
1604
+
1605
+ const lightsStateVersion = lights.state.version;
1606
+
1607
+ const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
1608
+ const programCacheKey = programCache.getProgramCacheKey( parameters );
1609
+
1610
+ let programs = materialProperties.programs;
1611
+
1612
+ // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
1613
+
1614
+ materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
1615
+ materialProperties.fog = scene.fog;
1616
+ materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
1617
+ materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
1618
+
1619
+ if ( programs === undefined ) {
1620
+
1621
+ // new material
1622
+
1623
+ material.addEventListener( 'dispose', onMaterialDispose );
1624
+
1625
+ programs = new Map();
1626
+ materialProperties.programs = programs;
1627
+
1628
+ }
1629
+
1630
+ let program = programs.get( programCacheKey );
1631
+
1632
+ if ( program !== undefined ) {
1633
+
1634
+ // early out if program and light state is identical
1635
+
1636
+ if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) {
1637
+
1638
+ updateCommonMaterialProperties( material, parameters );
1639
+
1640
+ return program;
1641
+
1642
+ }
1643
+
1644
+ } else {
1645
+
1646
+ parameters.uniforms = programCache.getUniforms( material );
1647
+
1648
+ material.onBuild( object, parameters, _this );
1649
+
1650
+ material.onBeforeCompile( parameters, _this );
1651
+
1652
+ program = programCache.acquireProgram( parameters, programCacheKey );
1653
+ programs.set( programCacheKey, program );
1654
+
1655
+ materialProperties.uniforms = parameters.uniforms;
1656
+
1657
+ }
1658
+
1659
+ const uniforms = materialProperties.uniforms;
1660
+
1661
+ if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) {
1662
+
1663
+ uniforms.clippingPlanes = clipping.uniform;
1664
+
1665
+ }
1666
+
1667
+ updateCommonMaterialProperties( material, parameters );
1668
+
1669
+ // store the light setup it was created for
1670
+
1671
+ materialProperties.needsLights = materialNeedsLights( material );
1672
+ materialProperties.lightsStateVersion = lightsStateVersion;
1673
+
1674
+ if ( materialProperties.needsLights ) {
1675
+
1676
+ // wire up the material to this renderer's lighting state
1677
+
1678
+ uniforms.ambientLightColor.value = lights.state.ambient;
1679
+ uniforms.lightProbe.value = lights.state.probe;
1680
+ uniforms.directionalLights.value = lights.state.directional;
1681
+ uniforms.directionalLightShadows.value = lights.state.directionalShadow;
1682
+ uniforms.spotLights.value = lights.state.spot;
1683
+ uniforms.spotLightShadows.value = lights.state.spotShadow;
1684
+ uniforms.rectAreaLights.value = lights.state.rectArea;
1685
+ uniforms.ltc_1.value = lights.state.rectAreaLTC1;
1686
+ uniforms.ltc_2.value = lights.state.rectAreaLTC2;
1687
+ uniforms.pointLights.value = lights.state.point;
1688
+ uniforms.pointLightShadows.value = lights.state.pointShadow;
1689
+ uniforms.hemisphereLights.value = lights.state.hemi;
1690
+
1691
+ uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
1692
+ uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
1693
+ uniforms.spotShadowMap.value = lights.state.spotShadowMap;
1694
+ uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;
1695
+ uniforms.spotLightMap.value = lights.state.spotLightMap;
1696
+ uniforms.pointShadowMap.value = lights.state.pointShadowMap;
1697
+ uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
1698
+ // TODO (abelnation): add area lights shadow info to uniforms
1699
+
1700
+ }
1701
+
1702
+ materialProperties.currentProgram = program;
1703
+ materialProperties.uniformsList = null;
1704
+
1705
+ return program;
1706
+
1707
+ }
1708
+
1709
+ function getUniformList( materialProperties ) {
1710
+
1711
+ if ( materialProperties.uniformsList === null ) {
1712
+
1713
+ const progUniforms = materialProperties.currentProgram.getUniforms();
1714
+ materialProperties.uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, materialProperties.uniforms );
1715
+
1716
+ }
1717
+
1718
+ return materialProperties.uniformsList;
1719
+
1720
+ }
1721
+
1722
+ function updateCommonMaterialProperties( material, parameters ) {
1723
+
1724
+ const materialProperties = properties.get( material );
1725
+
1726
+ materialProperties.outputColorSpace = parameters.outputColorSpace;
1727
+ materialProperties.batching = parameters.batching;
1728
+ materialProperties.instancing = parameters.instancing;
1729
+ materialProperties.instancingColor = parameters.instancingColor;
1730
+ materialProperties.instancingMorph = parameters.instancingMorph;
1731
+ materialProperties.skinning = parameters.skinning;
1732
+ materialProperties.morphTargets = parameters.morphTargets;
1733
+ materialProperties.morphNormals = parameters.morphNormals;
1734
+ materialProperties.morphColors = parameters.morphColors;
1735
+ materialProperties.morphTargetsCount = parameters.morphTargetsCount;
1736
+ materialProperties.numClippingPlanes = parameters.numClippingPlanes;
1737
+ materialProperties.numIntersection = parameters.numClipIntersection;
1738
+ materialProperties.vertexAlphas = parameters.vertexAlphas;
1739
+ materialProperties.vertexTangents = parameters.vertexTangents;
1740
+ materialProperties.toneMapping = parameters.toneMapping;
1741
+
1742
+ }
1743
+
1744
+ function setProgram( camera, scene, geometry, material, object ) {
1745
+
1746
+ if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
1747
+
1748
+ textures.resetTextureUnits();
1749
+
1750
+ const fog = scene.fog;
1751
+ const environment = material.isMeshStandardMaterial ? scene.environment : null;
1752
+ const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace );
1753
+ const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
1754
+ const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
1755
+ const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 );
1756
+ const morphTargets = !! geometry.morphAttributes.position;
1757
+ const morphNormals = !! geometry.morphAttributes.normal;
1758
+ const morphColors = !! geometry.morphAttributes.color;
1759
+
1760
+ let toneMapping = NoToneMapping;
1761
+
1762
+ if ( material.toneMapped ) {
1763
+
1764
+ if ( _currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true ) {
1765
+
1766
+ toneMapping = _this.toneMapping;
1767
+
1768
+ }
1769
+
1770
+ }
1771
+
1772
+ const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
1773
+ const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;
1774
+
1775
+ const materialProperties = properties.get( material );
1776
+ const lights = currentRenderState.state.lights;
1777
+
1778
+ if ( _clippingEnabled === true ) {
1779
+
1780
+ if ( _localClippingEnabled === true || camera !== _currentCamera ) {
1781
+
1782
+ const useCache =
1783
+ camera === _currentCamera &&
1784
+ material.id === _currentMaterialId;
1785
+
1786
+ // we might want to call this function with some ClippingGroup
1787
+ // object instead of the material, once it becomes feasible
1788
+ // (#8465, #8379)
1789
+ clipping.setState( material, camera, useCache );
1790
+
1791
+ }
1792
+
1793
+ }
1794
+
1795
+ //
1796
+
1797
+ let needsProgramChange = false;
1798
+
1799
+ if ( material.version === materialProperties.__version ) {
1800
+
1801
+ if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
1802
+
1803
+ needsProgramChange = true;
1804
+
1805
+ } else if ( materialProperties.outputColorSpace !== colorSpace ) {
1806
+
1807
+ needsProgramChange = true;
1808
+
1809
+ } else if ( object.isBatchedMesh && materialProperties.batching === false ) {
1810
+
1811
+ needsProgramChange = true;
1812
+
1813
+ } else if ( ! object.isBatchedMesh && materialProperties.batching === true ) {
1814
+
1815
+ needsProgramChange = true;
1816
+
1817
+ } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
1818
+
1819
+ needsProgramChange = true;
1820
+
1821
+ } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) {
1822
+
1823
+ needsProgramChange = true;
1824
+
1825
+ } else if ( object.isSkinnedMesh && materialProperties.skinning === false ) {
1826
+
1827
+ needsProgramChange = true;
1828
+
1829
+ } else if ( ! object.isSkinnedMesh && materialProperties.skinning === true ) {
1830
+
1831
+ needsProgramChange = true;
1832
+
1833
+ } else if ( object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null ) {
1834
+
1835
+ needsProgramChange = true;
1836
+
1837
+ } else if ( object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null ) {
1838
+
1839
+ needsProgramChange = true;
1840
+
1841
+ } else if ( object.isInstancedMesh && materialProperties.instancingMorph === true && object.morphTexture === null ) {
1842
+
1843
+ needsProgramChange = true;
1844
+
1845
+ } else if ( object.isInstancedMesh && materialProperties.instancingMorph === false && object.morphTexture !== null ) {
1846
+
1847
+ needsProgramChange = true;
1848
+
1849
+ } else if ( materialProperties.envMap !== envMap ) {
1850
+
1851
+ needsProgramChange = true;
1852
+
1853
+ } else if ( material.fog === true && materialProperties.fog !== fog ) {
1854
+
1855
+ needsProgramChange = true;
1856
+
1857
+ } else if ( materialProperties.numClippingPlanes !== undefined &&
1858
+ ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
1859
+ materialProperties.numIntersection !== clipping.numIntersection ) ) {
1860
+
1861
+ needsProgramChange = true;
1862
+
1863
+ } else if ( materialProperties.vertexAlphas !== vertexAlphas ) {
1864
+
1865
+ needsProgramChange = true;
1866
+
1867
+ } else if ( materialProperties.vertexTangents !== vertexTangents ) {
1868
+
1869
+ needsProgramChange = true;
1870
+
1871
+ } else if ( materialProperties.morphTargets !== morphTargets ) {
1872
+
1873
+ needsProgramChange = true;
1874
+
1875
+ } else if ( materialProperties.morphNormals !== morphNormals ) {
1876
+
1877
+ needsProgramChange = true;
1878
+
1879
+ } else if ( materialProperties.morphColors !== morphColors ) {
1880
+
1881
+ needsProgramChange = true;
1882
+
1883
+ } else if ( materialProperties.toneMapping !== toneMapping ) {
1884
+
1885
+ needsProgramChange = true;
1886
+
1887
+ } else if ( capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount ) {
1888
+
1889
+ needsProgramChange = true;
1890
+
1891
+ }
1892
+
1893
+ } else {
1894
+
1895
+ needsProgramChange = true;
1896
+ materialProperties.__version = material.version;
1897
+
1898
+ }
1899
+
1900
+ //
1901
+
1902
+ let program = materialProperties.currentProgram;
1903
+
1904
+ if ( needsProgramChange === true ) {
1905
+
1906
+ program = getProgram( material, scene, object );
1907
+
1908
+ }
1909
+
1910
+ let refreshProgram = false;
1911
+ let refreshMaterial = false;
1912
+ let refreshLights = false;
1913
+
1914
+ const p_uniforms = program.getUniforms(),
1915
+ m_uniforms = materialProperties.uniforms;
1916
+
1917
+ if ( state.useProgram( program.program ) ) {
1918
+
1919
+ refreshProgram = true;
1920
+ refreshMaterial = true;
1921
+ refreshLights = true;
1922
+
1923
+ }
1924
+
1925
+ if ( material.id !== _currentMaterialId ) {
1926
+
1927
+ _currentMaterialId = material.id;
1928
+
1929
+ refreshMaterial = true;
1930
+
1931
+ }
1932
+
1933
+ if ( refreshProgram || _currentCamera !== camera ) {
1934
+
1935
+ // common camera uniforms
1936
+
1937
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
1938
+ p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
1939
+
1940
+ const uCamPos = p_uniforms.map.cameraPosition;
1941
+
1942
+ if ( uCamPos !== undefined ) {
1943
+
1944
+ uCamPos.setValue( _gl, _vector3.setFromMatrixPosition( camera.matrixWorld ) );
1945
+
1946
+ }
1947
+
1948
+ if ( capabilities.logarithmicDepthBuffer ) {
1949
+
1950
+ p_uniforms.setValue( _gl, 'logDepthBufFC',
1951
+ 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
1952
+
1953
+ }
1954
+
1955
+ // consider moving isOrthographic to UniformLib and WebGLMaterials, see https://github.com/mrdoob/three.js/pull/26467#issuecomment-1645185067
1956
+
1957
+ if ( material.isMeshPhongMaterial ||
1958
+ material.isMeshToonMaterial ||
1959
+ material.isMeshLambertMaterial ||
1960
+ material.isMeshBasicMaterial ||
1961
+ material.isMeshStandardMaterial ||
1962
+ material.isShaderMaterial ) {
1963
+
1964
+ p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
1965
+
1966
+ }
1967
+
1968
+ if ( _currentCamera !== camera ) {
1969
+
1970
+ _currentCamera = camera;
1971
+
1972
+ // lighting uniforms depend on the camera so enforce an update
1973
+ // now, in case this material supports lights - or later, when
1974
+ // the next material that does gets activated:
1975
+
1976
+ refreshMaterial = true; // set to true on material change
1977
+ refreshLights = true; // remains set until update done
1978
+
1979
+ }
1980
+
1981
+ }
1982
+
1983
+ // skinning and morph target uniforms must be set even if material didn't change
1984
+ // auto-setting of texture unit for bone and morph texture must go before other textures
1985
+ // otherwise textures used for skinning and morphing can take over texture units reserved for other material textures
1986
+
1987
+ if ( object.isSkinnedMesh ) {
1988
+
1989
+ p_uniforms.setOptional( _gl, object, 'bindMatrix' );
1990
+ p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
1991
+
1992
+ const skeleton = object.skeleton;
1993
+
1994
+ if ( skeleton ) {
1995
+
1996
+ if ( capabilities.floatVertexTextures ) {
1997
+
1998
+ if ( skeleton.boneTexture === null ) skeleton.computeBoneTexture();
1999
+
2000
+ p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
2001
+
2002
+ } else {
2003
+
2004
+ console.warn( 'THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required.' );
2005
+
2006
+ }
2007
+
2008
+ }
2009
+
2010
+ }
2011
+
2012
+ if ( object.isBatchedMesh ) {
2013
+
2014
+ p_uniforms.setOptional( _gl, object, 'batchingTexture' );
2015
+ p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );
2016
+
2017
+ }
2018
+
2019
+ const morphAttributes = geometry.morphAttributes;
2020
+
2021
+ if ( morphAttributes.position !== undefined || morphAttributes.normal !== undefined || ( morphAttributes.color !== undefined && capabilities.isWebGL2 === true ) ) {
2022
+
2023
+ morphtargets.update( object, geometry, program );
2024
+
2025
+ }
2026
+
2027
+ if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
2028
+
2029
+ materialProperties.receiveShadow = object.receiveShadow;
2030
+ p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
2031
+
2032
+ }
2033
+
2034
+ // https://github.com/mrdoob/three.js/pull/24467#issuecomment-1209031512
2035
+
2036
+ if ( material.isMeshGouraudMaterial && material.envMap !== null ) {
2037
+
2038
+ m_uniforms.envMap.value = envMap;
2039
+
2040
+ m_uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1;
2041
+
2042
+ }
2043
+
2044
+ if ( refreshMaterial ) {
2045
+
2046
+ p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
2047
+
2048
+ if ( materialProperties.needsLights ) {
2049
+
2050
+ // the current material requires lighting info
2051
+
2052
+ // note: all lighting uniforms are always set correctly
2053
+ // they simply reference the renderer's state for their
2054
+ // values
2055
+ //
2056
+ // use the current material's .needsUpdate flags to set
2057
+ // the GL state when required
2058
+
2059
+ markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
2060
+
2061
+ }
2062
+
2063
+ // refresh uniforms common to several materials
2064
+
2065
+ if ( fog && material.fog === true ) {
2066
+
2067
+ materials.refreshFogUniforms( m_uniforms, fog );
2068
+
2069
+ }
2070
+
2071
+ materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget );
2072
+
2073
+ WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
2074
+
2075
+ }
2076
+
2077
+ if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
2078
+
2079
+ WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
2080
+ material.uniformsNeedUpdate = false;
2081
+
2082
+ }
2083
+
2084
+ if ( material.isSpriteMaterial ) {
2085
+
2086
+ p_uniforms.setValue( _gl, 'center', object.center );
2087
+
2088
+ }
2089
+
2090
+ // common matrices
2091
+
2092
+ p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
2093
+ p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
2094
+ p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
2095
+
2096
+ // UBOs
2097
+
2098
+ if ( material.isShaderMaterial || material.isRawShaderMaterial ) {
2099
+
2100
+ const groups = material.uniformsGroups;
2101
+
2102
+ for ( let i = 0, l = groups.length; i < l; i ++ ) {
2103
+
2104
+ if ( capabilities.isWebGL2 ) {
2105
+
2106
+ const group = groups[ i ];
2107
+
2108
+ uniformsGroups.update( group, program );
2109
+ uniformsGroups.bind( group, program );
2110
+
2111
+ } else {
2112
+
2113
+ console.warn( 'THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.' );
2114
+
2115
+ }
2116
+
2117
+ }
2118
+
2119
+ }
2120
+
2121
+ return program;
2122
+
2123
+ }
2124
+
2125
+ // If uniforms are marked as clean, they don't need to be loaded to the GPU.
2126
+
2127
+ function markUniformsLightsNeedsUpdate( uniforms, value ) {
2128
+
2129
+ uniforms.ambientLightColor.needsUpdate = value;
2130
+ uniforms.lightProbe.needsUpdate = value;
2131
+
2132
+ uniforms.directionalLights.needsUpdate = value;
2133
+ uniforms.directionalLightShadows.needsUpdate = value;
2134
+ uniforms.pointLights.needsUpdate = value;
2135
+ uniforms.pointLightShadows.needsUpdate = value;
2136
+ uniforms.spotLights.needsUpdate = value;
2137
+ uniforms.spotLightShadows.needsUpdate = value;
2138
+ uniforms.rectAreaLights.needsUpdate = value;
2139
+ uniforms.hemisphereLights.needsUpdate = value;
2140
+
2141
+ }
2142
+
2143
+ function materialNeedsLights( material ) {
2144
+
2145
+ return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
2146
+ material.isMeshStandardMaterial || material.isShadowMaterial ||
2147
+ ( material.isShaderMaterial && material.lights === true );
2148
+
2149
+ }
2150
+
2151
+ this.getActiveCubeFace = function () {
2152
+
2153
+ return _currentActiveCubeFace;
2154
+
2155
+ };
2156
+
2157
+ this.getActiveMipmapLevel = function () {
2158
+
2159
+ return _currentActiveMipmapLevel;
2160
+
2161
+ };
2162
+
2163
+ this.getRenderTarget = function () {
2164
+
2165
+ return _currentRenderTarget;
2166
+
2167
+ };
2168
+
2169
+ this.setRenderTargetTextures = function ( renderTarget, colorTexture, depthTexture ) {
2170
+
2171
+ properties.get( renderTarget.texture ).__webglTexture = colorTexture;
2172
+ properties.get( renderTarget.depthTexture ).__webglTexture = depthTexture;
2173
+
2174
+ const renderTargetProperties = properties.get( renderTarget );
2175
+ renderTargetProperties.__hasExternalTextures = true;
2176
+
2177
+ renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
2178
+
2179
+ if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) {
2180
+
2181
+ // The multisample_render_to_texture extension doesn't work properly if there
2182
+ // are midframe flushes and an external depth buffer. Disable use of the extension.
2183
+ if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
2184
+
2185
+ console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
2186
+ renderTargetProperties.__useRenderToTexture = false;
2187
+
2188
+ }
2189
+
2190
+ }
2191
+
2192
+ };
2193
+
2194
+ this.setRenderTargetFramebuffer = function ( renderTarget, defaultFramebuffer ) {
2195
+
2196
+ const renderTargetProperties = properties.get( renderTarget );
2197
+ renderTargetProperties.__webglFramebuffer = defaultFramebuffer;
2198
+ renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === undefined;
2199
+
2200
+ };
2201
+
2202
+ this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
2203
+
2204
+ _currentRenderTarget = renderTarget;
2205
+ _currentActiveCubeFace = activeCubeFace;
2206
+ _currentActiveMipmapLevel = activeMipmapLevel;
2207
+
2208
+ let useDefaultFramebuffer = true;
2209
+ let framebuffer = null;
2210
+ let isCube = false;
2211
+ let isRenderTarget3D = false;
2212
+
2213
+ if ( renderTarget ) {
2214
+
2215
+ const renderTargetProperties = properties.get( renderTarget );
2216
+
2217
+ if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) {
2218
+
2219
+ // We need to make sure to rebind the framebuffer.
2220
+ state.bindFramebuffer( _gl.FRAMEBUFFER, null );
2221
+ useDefaultFramebuffer = false;
2222
+
2223
+ } else if ( renderTargetProperties.__webglFramebuffer === undefined ) {
2224
+
2225
+ textures.setupRenderTarget( renderTarget );
2226
+
2227
+ } else if ( renderTargetProperties.__hasExternalTextures ) {
2228
+
2229
+ // Color and depth texture must be rebound in order for the swapchain to update.
2230
+ textures.rebindTextures( renderTarget, properties.get( renderTarget.texture ).__webglTexture, properties.get( renderTarget.depthTexture ).__webglTexture );
2231
+
2232
+ }
2233
+
2234
+ const texture = renderTarget.texture;
2235
+
2236
+ if ( texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
2237
+
2238
+ isRenderTarget3D = true;
2239
+
2240
+ }
2241
+
2242
+ const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
2243
+
2244
+ if ( renderTarget.isWebGLCubeRenderTarget ) {
2245
+
2246
+ if ( Array.isArray( __webglFramebuffer[ activeCubeFace ] ) ) {
2247
+
2248
+ framebuffer = __webglFramebuffer[ activeCubeFace ][ activeMipmapLevel ];
2249
+
2250
+ } else {
2251
+
2252
+ framebuffer = __webglFramebuffer[ activeCubeFace ];
2253
+
2254
+ }
2255
+
2256
+ isCube = true;
2257
+
2258
+ } else if ( ( capabilities.isWebGL2 && renderTarget.samples > 0 ) && textures.useMultisampledRTT( renderTarget ) === false ) {
2259
+
2260
+ framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
2261
+
2262
+ } else {
2263
+
2264
+ if ( Array.isArray( __webglFramebuffer ) ) {
2265
+
2266
+ framebuffer = __webglFramebuffer[ activeMipmapLevel ];
2267
+
2268
+ } else {
2269
+
2270
+ framebuffer = __webglFramebuffer;
2271
+
2272
+ }
2273
+
2274
+ }
2275
+
2276
+ _currentViewport.copy( renderTarget.viewport );
2277
+ _currentScissor.copy( renderTarget.scissor );
2278
+ _currentScissorTest = renderTarget.scissorTest;
2279
+
2280
+ } else {
2281
+
2282
+ _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
2283
+ _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
2284
+ _currentScissorTest = _scissorTest;
2285
+
2286
+ }
2287
+
2288
+ const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2289
+
2290
+ if ( framebufferBound && capabilities.drawBuffers && useDefaultFramebuffer ) {
2291
+
2292
+ state.drawBuffers( renderTarget, framebuffer );
2293
+
2294
+ }
2295
+
2296
+ state.viewport( _currentViewport );
2297
+ state.scissor( _currentScissor );
2298
+ state.setScissorTest( _currentScissorTest );
2299
+
2300
+ if ( isCube ) {
2301
+
2302
+ const textureProperties = properties.get( renderTarget.texture );
2303
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
2304
+
2305
+ } else if ( isRenderTarget3D ) {
2306
+
2307
+ const textureProperties = properties.get( renderTarget.texture );
2308
+ const layer = activeCubeFace || 0;
2309
+ _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer );
2310
+
2311
+ }
2312
+
2313
+ _currentMaterialId = - 1; // reset current material to ensure correct uniform bindings
2314
+
2315
+ };
2316
+
2317
+ this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
2318
+
2319
+ if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
2320
+
2321
+ console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
2322
+ return;
2323
+
2324
+ }
2325
+
2326
+ let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
2327
+
2328
+ if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
2329
+
2330
+ framebuffer = framebuffer[ activeCubeFaceIndex ];
2331
+
2332
+ }
2333
+
2334
+ if ( framebuffer ) {
2335
+
2336
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2337
+
2338
+ try {
2339
+
2340
+ const texture = renderTarget.texture;
2341
+ const textureFormat = texture.format;
2342
+ const textureType = texture.type;
2343
+
2344
+ if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
2345
+
2346
+ console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
2347
+ return;
2348
+
2349
+ }
2350
+
2351
+ const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ) );
2352
+
2353
+ if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // Edge and Chrome Mac < 52 (#9513)
2354
+ ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.has( 'OES_texture_float' ) || extensions.has( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
2355
+ ! halfFloatSupportedByExt ) {
2356
+
2357
+ console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
2358
+ return;
2359
+
2360
+ }
2361
+
2362
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
2363
+
2364
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
2365
+
2366
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
2367
+
2368
+ }
2369
+
2370
+ } finally {
2371
+
2372
+ // restore framebuffer of current render target if necessary
2373
+
2374
+ const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
2375
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2376
+
2377
+ }
2378
+
2379
+ }
2380
+
2381
+ };
2382
+
2383
+ this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
2384
+
2385
+ const levelScale = Math.pow( 2, - level );
2386
+ const width = Math.floor( texture.image.width * levelScale );
2387
+ const height = Math.floor( texture.image.height * levelScale );
2388
+
2389
+ textures.setTexture2D( texture, 0 );
2390
+
2391
+ _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
2392
+
2393
+ state.unbindTexture();
2394
+
2395
+ };
2396
+
2397
+ this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
2398
+
2399
+ const width = srcTexture.image.width;
2400
+ const height = srcTexture.image.height;
2401
+ const glFormat = utils.convert( dstTexture.format );
2402
+ const glType = utils.convert( dstTexture.type );
2403
+
2404
+ textures.setTexture2D( dstTexture, 0 );
2405
+
2406
+ // As another texture upload may have changed pixelStorei
2407
+ // parameters, make sure they are correct for the dstTexture
2408
+ _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2409
+ _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2410
+ _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
2411
+
2412
+ if ( srcTexture.isDataTexture ) {
2413
+
2414
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
2415
+
2416
+ } else {
2417
+
2418
+ if ( srcTexture.isCompressedTexture ) {
2419
+
2420
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
2421
+
2422
+ } else {
2423
+
2424
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
2425
+
2426
+ }
2427
+
2428
+ }
2429
+
2430
+ // Generate mipmaps only when copying level 0
2431
+ if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
2432
+
2433
+ state.unbindTexture();
2434
+
2435
+ };
2436
+
2437
+ this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
2438
+
2439
+ if ( _this.isWebGL1Renderer ) {
2440
+
2441
+ console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.' );
2442
+ return;
2443
+
2444
+ }
2445
+
2446
+ const width = Math.round( sourceBox.max.x - sourceBox.min.x );
2447
+ const height = Math.round( sourceBox.max.y - sourceBox.min.y );
2448
+ const depth = sourceBox.max.z - sourceBox.min.z + 1;
2449
+ const glFormat = utils.convert( dstTexture.format );
2450
+ const glType = utils.convert( dstTexture.type );
2451
+ let glTarget;
2452
+
2453
+ if ( dstTexture.isData3DTexture ) {
2454
+
2455
+ textures.setTexture3D( dstTexture, 0 );
2456
+ glTarget = _gl.TEXTURE_3D;
2457
+
2458
+ } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
2459
+
2460
+ textures.setTexture2DArray( dstTexture, 0 );
2461
+ glTarget = _gl.TEXTURE_2D_ARRAY;
2462
+
2463
+ } else {
2464
+
2465
+ console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
2466
+ return;
2467
+
2468
+ }
2469
+
2470
+ _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2471
+ _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2472
+ _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
2473
+
2474
+ const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
2475
+ const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
2476
+ const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
2477
+ const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
2478
+ const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
2479
+
2480
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
2481
+
2482
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
2483
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
2484
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
2485
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
2486
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
2487
+
2488
+ if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
2489
+
2490
+ _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
2491
+
2492
+ } else {
2493
+
2494
+ if ( dstTexture.isCompressedArrayTexture ) {
2495
+
2496
+ _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
2497
+
2498
+ } else {
2499
+
2500
+ _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
2501
+
2502
+ }
2503
+
2504
+ }
2505
+
2506
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen );
2507
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );
2508
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels );
2509
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows );
2510
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages );
2511
+
2512
+ // Generate mipmaps only when copying level 0
2513
+ if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
2514
+
2515
+ state.unbindTexture();
2516
+
2517
+ };
2518
+
2519
+ this.initTexture = function ( texture ) {
2520
+
2521
+ if ( texture.isCubeTexture ) {
2522
+
2523
+ textures.setTextureCube( texture, 0 );
2524
+
2525
+ } else if ( texture.isData3DTexture ) {
2526
+
2527
+ textures.setTexture3D( texture, 0 );
2528
+
2529
+ } else if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
2530
+
2531
+ textures.setTexture2DArray( texture, 0 );
2532
+
2533
+ } else {
2534
+
2535
+ textures.setTexture2D( texture, 0 );
2536
+
2537
+ }
2538
+
2539
+ state.unbindTexture();
2540
+
2541
+ };
2542
+
2543
+ this.resetState = function () {
2544
+
2545
+ _currentActiveCubeFace = 0;
2546
+ _currentActiveMipmapLevel = 0;
2547
+ _currentRenderTarget = null;
2548
+
2549
+ state.reset();
2550
+ bindingStates.reset();
2551
+
2552
+ };
2553
+
2554
+ if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
2555
+
2556
+ __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
2557
+
2558
+ }
2559
+
2560
+ }
2561
+
2562
+ get coordinateSystem() {
2563
+
2564
+ return WebGLCoordinateSystem;
2565
+
2566
+ }
2567
+
2568
+ get outputColorSpace() {
2569
+
2570
+ return this._outputColorSpace;
2571
+
2572
+ }
2573
+
2574
+ set outputColorSpace( colorSpace ) {
2575
+
2576
+ this._outputColorSpace = colorSpace;
2577
+
2578
+ const gl = this.getContext();
2579
+ gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace ? 'display-p3' : 'srgb';
2580
+ gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? 'display-p3' : 'srgb';
2581
+
2582
+ }
2583
+
2584
+ get outputEncoding() { // @deprecated, r152
2585
+
2586
+ console.warn( 'THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.' );
2587
+ return this.outputColorSpace === SRGBColorSpace ? sRGBEncoding : LinearEncoding;
2588
+
2589
+ }
2590
+
2591
+ set outputEncoding( encoding ) { // @deprecated, r152
2592
+
2593
+ console.warn( 'THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.' );
2594
+ this.outputColorSpace = encoding === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
2595
+
2596
+ }
2597
+
2598
+ get useLegacyLights() { // @deprecated, r155
2599
+
2600
+ console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
2601
+ return this._useLegacyLights;
2602
+
2603
+ }
2604
+
2605
+ set useLegacyLights( value ) { // @deprecated, r155
2606
+
2607
+ console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
2608
+ this._useLegacyLights = value;
2609
+
2610
+ }
2611
+
2612
+ }
2613
+
2614
+
2615
+ export { WebGLRenderer };