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