super-three 0.136.0 → 0.136.1

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 (125) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.js +1634 -1608
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +4630 -4534
  5. package/examples/js/animation/MMDPhysics.js +1 -1
  6. package/examples/js/cameras/CinematicCamera.js +2 -7
  7. package/examples/js/exporters/MMDExporter.js +1 -1
  8. package/examples/js/geometries/ConvexGeometry.js +1 -1
  9. package/examples/js/loaders/BasisTextureLoader.js +1 -0
  10. package/examples/js/loaders/EXRLoader.js +25 -19
  11. package/examples/js/loaders/GLTFLoader.js +2 -2
  12. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -2
  13. package/examples/js/loaders/LDrawLoader.js +1131 -859
  14. package/examples/js/loaders/LUT3dlLoader.js +17 -10
  15. package/examples/js/loaders/LUTCubeLoader.js +3 -4
  16. package/examples/js/loaders/RGBELoader.js +6 -6
  17. package/examples/js/loaders/RGBMLoader.js +1 -1
  18. package/examples/js/loaders/SVGLoader.js +3 -1
  19. package/examples/js/loaders/VRMLLoader.js +9 -21
  20. package/examples/js/math/ConvexHull.js +7 -13
  21. package/examples/js/misc/Volume.js +2 -2
  22. package/examples/js/modifiers/CurveModifier.js +8 -7
  23. package/examples/js/modifiers/EdgeSplitModifier.js +1 -1
  24. package/examples/js/modifiers/SimplifyModifier.js +1 -1
  25. package/examples/js/objects/Reflector.js +1 -13
  26. package/examples/js/objects/ReflectorForSSRPass.js +0 -10
  27. package/examples/js/objects/Refractor.js +1 -13
  28. package/examples/js/objects/Water.js +1 -13
  29. package/examples/js/postprocessing/GlitchPass.js +4 -5
  30. package/examples/js/postprocessing/SMAAPass.js +2 -9
  31. package/examples/js/postprocessing/SSAOPass.js +9 -21
  32. package/examples/js/postprocessing/SavePass.js +1 -5
  33. package/examples/js/shaders/DigitalGlitch.js +3 -3
  34. package/examples/js/shaders/MMDToonShader.js +0 -1
  35. package/examples/js/shaders/SSAOShader.js +1 -1
  36. package/examples/jsm/animation/MMDPhysics.js +1 -1
  37. package/examples/jsm/cameras/CinematicCamera.js +2 -5
  38. package/examples/jsm/{WebGL.js → capabilities/WebGL.js} +2 -2
  39. package/examples/jsm/{renderers/webgpu → capabilities}/WebGPU.js +1 -1
  40. package/examples/jsm/exporters/GLTFExporter.js +8 -24
  41. package/examples/jsm/exporters/MMDExporter.js +1 -1
  42. package/examples/jsm/geometries/ConvexGeometry.js +1 -1
  43. package/examples/jsm/libs/lil-gui.module.min.js +2 -2
  44. package/examples/jsm/loaders/BasisTextureLoader.js +7 -0
  45. package/examples/jsm/loaders/EXRLoader.js +22 -19
  46. package/examples/jsm/loaders/GLTFLoader.js +1 -3
  47. package/examples/jsm/loaders/HDRCubeTextureLoader.js +1 -4
  48. package/examples/jsm/loaders/LDrawLoader.js +1147 -885
  49. package/examples/jsm/loaders/LUT3dlLoader.js +17 -12
  50. package/examples/jsm/loaders/LUTCubeLoader.js +3 -5
  51. package/examples/jsm/loaders/RGBELoader.js +7 -8
  52. package/examples/jsm/loaders/RGBMLoader.js +1 -1
  53. package/examples/jsm/loaders/SVGLoader.js +6 -1
  54. package/examples/jsm/loaders/VRMLLoader.js +9 -22
  55. package/examples/jsm/math/ConvexHull.js +7 -13
  56. package/examples/jsm/misc/Volume.js +2 -2
  57. package/examples/jsm/modifiers/CurveModifier.js +9 -8
  58. package/examples/jsm/modifiers/EdgeSplitModifier.js +1 -1
  59. package/examples/jsm/modifiers/SimplifyModifier.js +1 -1
  60. package/examples/jsm/node-editor/NodeEditor.js +21 -22
  61. package/examples/jsm/nodes/utils/ColorSpaceNode.js +4 -13
  62. package/examples/jsm/objects/Lensflare.js +4 -4
  63. package/examples/jsm/objects/Reflector.js +1 -16
  64. package/examples/jsm/objects/ReflectorForSSRPass.js +0 -12
  65. package/examples/jsm/objects/Refractor.js +1 -16
  66. package/examples/jsm/objects/Water.js +1 -16
  67. package/examples/jsm/postprocessing/GlitchPass.js +7 -6
  68. package/examples/jsm/postprocessing/SMAAPass.js +2 -11
  69. package/examples/jsm/postprocessing/SSAOPass.js +13 -25
  70. package/examples/jsm/postprocessing/SavePass.js +1 -3
  71. package/examples/jsm/renderers/nodes/Nodes.js +2 -0
  72. package/examples/jsm/renderers/nodes/ShaderNode.js +58 -31
  73. package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +9 -46
  74. package/examples/jsm/renderers/nodes/inputs/TextureNode.js +5 -10
  75. package/examples/jsm/renderers/nodes/math/MathNode.js +2 -1
  76. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +1 -1
  77. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +3 -5
  78. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +1 -2
  79. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +10 -4
  80. package/examples/jsm/shaders/DigitalGlitch.js +3 -3
  81. package/examples/jsm/shaders/MMDToonShader.js +0 -1
  82. package/examples/jsm/shaders/SSAOShader.js +1 -1
  83. package/examples/jsm/utils/LDrawUtils.js +195 -0
  84. package/examples/jsm/webxr/VRButton.js +24 -0
  85. package/examples/jsm/webxr/XREstimatedLight.js +2 -0
  86. package/package.json +4 -1
  87. package/src/animation/AnimationMixer.js +1 -0
  88. package/src/cameras/CubeCamera.js +2 -0
  89. package/src/constants.js +3 -16
  90. package/src/extras/ImageUtils.js +63 -0
  91. package/src/extras/PMREMGenerator.js +32 -82
  92. package/src/loaders/MaterialLoader.js +1 -1
  93. package/src/materials/Material.js +4 -4
  94. package/src/math/Color.js +1 -1
  95. package/src/math/Quaternion.js +1 -1
  96. package/src/renderers/WebGLCubeRenderTarget.js +0 -2
  97. package/src/renderers/WebGLRenderer.js +1 -67
  98. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +0 -2
  99. package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -4
  100. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -2
  101. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
  102. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +1 -1
  103. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +2 -2
  104. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +10 -3
  105. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +1 -2
  106. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +8 -7
  107. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -3
  108. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -3
  109. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -1
  110. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -2
  111. package/src/renderers/shaders/ShaderLib.js +2 -2
  112. package/src/renderers/webgl/WebGLCubeMaps.js +0 -4
  113. package/src/renderers/webgl/WebGLCubeUVMaps.js +29 -16
  114. package/src/renderers/webgl/WebGLMorphtargets.js +12 -0
  115. package/src/renderers/webgl/WebGLProgram.js +4 -16
  116. package/src/renderers/webgl/WebGLPrograms.js +8 -47
  117. package/src/renderers/webgl/WebGLState.js +81 -0
  118. package/src/renderers/webgl/WebGLTextures.js +75 -22
  119. package/src/renderers/webgl/WebGLUtils.js +86 -28
  120. package/src/renderers/webxr/WebXRManager.js +3 -3
  121. package/src/textures/Texture.js +2 -1
  122. package/src/textures/VideoTexture.js +1 -3
  123. package/examples/js/WebGL.js +0 -90
  124. package/examples/js/utils/RoughnessMipmapper.js +0 -268
  125. package/examples/jsm/utils/RoughnessMipmapper.js +0 -288
package/build/three.js CHANGED
@@ -9,7 +9,7 @@
9
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
10
10
  }(this, (function (exports) { 'use strict';
11
11
 
12
- const REVISION = '136';
12
+ const REVISION = '137dev';
13
13
  const MOUSE = {
14
14
  LEFT: 0,
15
15
  MIDDLE: 1,
@@ -109,7 +109,6 @@
109
109
  const UnsignedShort565Type = 1019;
110
110
  const UnsignedInt248Type = 1020;
111
111
  const AlphaFormat = 1021;
112
- const RGBFormat = 1022;
113
112
  const RGBAFormat = 1023;
114
113
  const LuminanceFormat = 1024;
115
114
  const LuminanceAlphaFormat = 1025;
@@ -147,20 +146,6 @@
147
146
  const RGBA_ASTC_12x10_Format = 37820;
148
147
  const RGBA_ASTC_12x12_Format = 37821;
149
148
  const RGBA_BPTC_Format = 36492;
150
- const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
151
- const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
152
- const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
153
- const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
154
- const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
155
- const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
156
- const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
157
- const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
158
- const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
159
- const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
160
- const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
161
- const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
162
- const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
163
- const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
164
149
  const LoopOnce = 2200;
165
150
  const LoopRepeat = 2201;
166
151
  const LoopPingPong = 2202;
@@ -208,6 +193,7 @@
208
193
  const StreamCopyUsage = 35042;
209
194
  const GLSL1 = '100';
210
195
  const GLSL3 = '300 es';
196
+ const _SRGBAFormat = 1035; // fallback for WebGL 1
211
197
 
212
198
  /**
213
199
  * https://github.com/mrdoob/eventdispatcher.js/
@@ -1101,266 +1087,850 @@
1101
1087
  return document.createElementNS('http://www.w3.org/1999/xhtml', name);
1102
1088
  }
1103
1089
 
1104
- let _canvas;
1105
-
1106
- class ImageUtils {
1107
- static getDataURL(image) {
1108
- if (/^data:/i.test(image.src)) {
1109
- return image.src;
1110
- }
1111
-
1112
- if (typeof HTMLCanvasElement == 'undefined') {
1113
- return image.src;
1114
- }
1115
-
1116
- let canvas;
1090
+ const _colorKeywords = {
1091
+ 'aliceblue': 0xF0F8FF,
1092
+ 'antiquewhite': 0xFAEBD7,
1093
+ 'aqua': 0x00FFFF,
1094
+ 'aquamarine': 0x7FFFD4,
1095
+ 'azure': 0xF0FFFF,
1096
+ 'beige': 0xF5F5DC,
1097
+ 'bisque': 0xFFE4C4,
1098
+ 'black': 0x000000,
1099
+ 'blanchedalmond': 0xFFEBCD,
1100
+ 'blue': 0x0000FF,
1101
+ 'blueviolet': 0x8A2BE2,
1102
+ 'brown': 0xA52A2A,
1103
+ 'burlywood': 0xDEB887,
1104
+ 'cadetblue': 0x5F9EA0,
1105
+ 'chartreuse': 0x7FFF00,
1106
+ 'chocolate': 0xD2691E,
1107
+ 'coral': 0xFF7F50,
1108
+ 'cornflowerblue': 0x6495ED,
1109
+ 'cornsilk': 0xFFF8DC,
1110
+ 'crimson': 0xDC143C,
1111
+ 'cyan': 0x00FFFF,
1112
+ 'darkblue': 0x00008B,
1113
+ 'darkcyan': 0x008B8B,
1114
+ 'darkgoldenrod': 0xB8860B,
1115
+ 'darkgray': 0xA9A9A9,
1116
+ 'darkgreen': 0x006400,
1117
+ 'darkgrey': 0xA9A9A9,
1118
+ 'darkkhaki': 0xBDB76B,
1119
+ 'darkmagenta': 0x8B008B,
1120
+ 'darkolivegreen': 0x556B2F,
1121
+ 'darkorange': 0xFF8C00,
1122
+ 'darkorchid': 0x9932CC,
1123
+ 'darkred': 0x8B0000,
1124
+ 'darksalmon': 0xE9967A,
1125
+ 'darkseagreen': 0x8FBC8F,
1126
+ 'darkslateblue': 0x483D8B,
1127
+ 'darkslategray': 0x2F4F4F,
1128
+ 'darkslategrey': 0x2F4F4F,
1129
+ 'darkturquoise': 0x00CED1,
1130
+ 'darkviolet': 0x9400D3,
1131
+ 'deeppink': 0xFF1493,
1132
+ 'deepskyblue': 0x00BFFF,
1133
+ 'dimgray': 0x696969,
1134
+ 'dimgrey': 0x696969,
1135
+ 'dodgerblue': 0x1E90FF,
1136
+ 'firebrick': 0xB22222,
1137
+ 'floralwhite': 0xFFFAF0,
1138
+ 'forestgreen': 0x228B22,
1139
+ 'fuchsia': 0xFF00FF,
1140
+ 'gainsboro': 0xDCDCDC,
1141
+ 'ghostwhite': 0xF8F8FF,
1142
+ 'gold': 0xFFD700,
1143
+ 'goldenrod': 0xDAA520,
1144
+ 'gray': 0x808080,
1145
+ 'green': 0x008000,
1146
+ 'greenyellow': 0xADFF2F,
1147
+ 'grey': 0x808080,
1148
+ 'honeydew': 0xF0FFF0,
1149
+ 'hotpink': 0xFF69B4,
1150
+ 'indianred': 0xCD5C5C,
1151
+ 'indigo': 0x4B0082,
1152
+ 'ivory': 0xFFFFF0,
1153
+ 'khaki': 0xF0E68C,
1154
+ 'lavender': 0xE6E6FA,
1155
+ 'lavenderblush': 0xFFF0F5,
1156
+ 'lawngreen': 0x7CFC00,
1157
+ 'lemonchiffon': 0xFFFACD,
1158
+ 'lightblue': 0xADD8E6,
1159
+ 'lightcoral': 0xF08080,
1160
+ 'lightcyan': 0xE0FFFF,
1161
+ 'lightgoldenrodyellow': 0xFAFAD2,
1162
+ 'lightgray': 0xD3D3D3,
1163
+ 'lightgreen': 0x90EE90,
1164
+ 'lightgrey': 0xD3D3D3,
1165
+ 'lightpink': 0xFFB6C1,
1166
+ 'lightsalmon': 0xFFA07A,
1167
+ 'lightseagreen': 0x20B2AA,
1168
+ 'lightskyblue': 0x87CEFA,
1169
+ 'lightslategray': 0x778899,
1170
+ 'lightslategrey': 0x778899,
1171
+ 'lightsteelblue': 0xB0C4DE,
1172
+ 'lightyellow': 0xFFFFE0,
1173
+ 'lime': 0x00FF00,
1174
+ 'limegreen': 0x32CD32,
1175
+ 'linen': 0xFAF0E6,
1176
+ 'magenta': 0xFF00FF,
1177
+ 'maroon': 0x800000,
1178
+ 'mediumaquamarine': 0x66CDAA,
1179
+ 'mediumblue': 0x0000CD,
1180
+ 'mediumorchid': 0xBA55D3,
1181
+ 'mediumpurple': 0x9370DB,
1182
+ 'mediumseagreen': 0x3CB371,
1183
+ 'mediumslateblue': 0x7B68EE,
1184
+ 'mediumspringgreen': 0x00FA9A,
1185
+ 'mediumturquoise': 0x48D1CC,
1186
+ 'mediumvioletred': 0xC71585,
1187
+ 'midnightblue': 0x191970,
1188
+ 'mintcream': 0xF5FFFA,
1189
+ 'mistyrose': 0xFFE4E1,
1190
+ 'moccasin': 0xFFE4B5,
1191
+ 'navajowhite': 0xFFDEAD,
1192
+ 'navy': 0x000080,
1193
+ 'oldlace': 0xFDF5E6,
1194
+ 'olive': 0x808000,
1195
+ 'olivedrab': 0x6B8E23,
1196
+ 'orange': 0xFFA500,
1197
+ 'orangered': 0xFF4500,
1198
+ 'orchid': 0xDA70D6,
1199
+ 'palegoldenrod': 0xEEE8AA,
1200
+ 'palegreen': 0x98FB98,
1201
+ 'paleturquoise': 0xAFEEEE,
1202
+ 'palevioletred': 0xDB7093,
1203
+ 'papayawhip': 0xFFEFD5,
1204
+ 'peachpuff': 0xFFDAB9,
1205
+ 'peru': 0xCD853F,
1206
+ 'pink': 0xFFC0CB,
1207
+ 'plum': 0xDDA0DD,
1208
+ 'powderblue': 0xB0E0E6,
1209
+ 'purple': 0x800080,
1210
+ 'rebeccapurple': 0x663399,
1211
+ 'red': 0xFF0000,
1212
+ 'rosybrown': 0xBC8F8F,
1213
+ 'royalblue': 0x4169E1,
1214
+ 'saddlebrown': 0x8B4513,
1215
+ 'salmon': 0xFA8072,
1216
+ 'sandybrown': 0xF4A460,
1217
+ 'seagreen': 0x2E8B57,
1218
+ 'seashell': 0xFFF5EE,
1219
+ 'sienna': 0xA0522D,
1220
+ 'silver': 0xC0C0C0,
1221
+ 'skyblue': 0x87CEEB,
1222
+ 'slateblue': 0x6A5ACD,
1223
+ 'slategray': 0x708090,
1224
+ 'slategrey': 0x708090,
1225
+ 'snow': 0xFFFAFA,
1226
+ 'springgreen': 0x00FF7F,
1227
+ 'steelblue': 0x4682B4,
1228
+ 'tan': 0xD2B48C,
1229
+ 'teal': 0x008080,
1230
+ 'thistle': 0xD8BFD8,
1231
+ 'tomato': 0xFF6347,
1232
+ 'turquoise': 0x40E0D0,
1233
+ 'violet': 0xEE82EE,
1234
+ 'wheat': 0xF5DEB3,
1235
+ 'white': 0xFFFFFF,
1236
+ 'whitesmoke': 0xF5F5F5,
1237
+ 'yellow': 0xFFFF00,
1238
+ 'yellowgreen': 0x9ACD32
1239
+ };
1240
+ const _hslA = {
1241
+ h: 0,
1242
+ s: 0,
1243
+ l: 0
1244
+ };
1245
+ const _hslB = {
1246
+ h: 0,
1247
+ s: 0,
1248
+ l: 0
1249
+ };
1117
1250
 
1118
- if (image instanceof HTMLCanvasElement) {
1119
- canvas = image;
1120
- } else {
1121
- if (_canvas === undefined) _canvas = createElementNS('canvas');
1122
- _canvas.width = image.width;
1123
- _canvas.height = image.height;
1251
+ function hue2rgb(p, q, t) {
1252
+ if (t < 0) t += 1;
1253
+ if (t > 1) t -= 1;
1254
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
1255
+ if (t < 1 / 2) return q;
1256
+ if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
1257
+ return p;
1258
+ }
1124
1259
 
1125
- const context = _canvas.getContext('2d');
1260
+ function SRGBToLinear(c) {
1261
+ return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
1262
+ }
1126
1263
 
1127
- if (image instanceof ImageData) {
1128
- context.putImageData(image, 0, 0);
1129
- } else {
1130
- context.drawImage(image, 0, 0, image.width, image.height);
1131
- }
1264
+ function LinearToSRGB(c) {
1265
+ return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
1266
+ }
1132
1267
 
1133
- canvas = _canvas;
1268
+ class Color {
1269
+ constructor(r, g, b) {
1270
+ if (g === undefined && b === undefined) {
1271
+ // r is THREE.Color, hex or string
1272
+ return this.set(r);
1134
1273
  }
1135
1274
 
1136
- if (canvas.width > 2048 || canvas.height > 2048) {
1137
- console.warn('THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image);
1138
- return canvas.toDataURL('image/jpeg', 0.6);
1139
- } else {
1140
- return canvas.toDataURL('image/png');
1141
- }
1275
+ return this.setRGB(r, g, b);
1142
1276
  }
1143
1277
 
1144
- }
1145
-
1146
- let textureId = 0;
1147
-
1148
- class Texture extends EventDispatcher {
1149
- constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1, encoding = LinearEncoding) {
1150
- super();
1151
- Object.defineProperty(this, 'id', {
1152
- value: textureId++
1153
- });
1154
- this.uuid = generateUUID();
1155
- this.name = '';
1156
- this.image = image;
1157
- this.mipmaps = [];
1158
- this.mapping = mapping;
1159
- this.wrapS = wrapS;
1160
- this.wrapT = wrapT;
1161
- this.magFilter = magFilter;
1162
- this.minFilter = minFilter;
1163
- this.anisotropy = anisotropy;
1164
- this.format = format;
1165
- this.internalFormat = null;
1166
- this.type = type;
1167
- this.offset = new Vector2(0, 0);
1168
- this.repeat = new Vector2(1, 1);
1169
- this.center = new Vector2(0, 0);
1170
- this.rotation = 0;
1171
- this.matrixAutoUpdate = true;
1172
- this.matrix = new Matrix3();
1173
- this.generateMipmaps = true;
1174
- this.premultiplyAlpha = false;
1175
- this.flipY = true;
1176
- this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
1177
- // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
1178
- //
1179
- // Also changing the encoding after already used by a Material will not automatically make the Material
1180
- // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
1278
+ set(value) {
1279
+ if (value && value.isColor) {
1280
+ this.copy(value);
1281
+ } else if (typeof value === 'number') {
1282
+ this.setHex(value);
1283
+ } else if (typeof value === 'string') {
1284
+ this.setStyle(value);
1285
+ }
1181
1286
 
1182
- this.encoding = encoding;
1183
- this.userData = {};
1184
- this.version = 0;
1185
- this.onUpdate = null;
1186
- this.isRenderTargetTexture = false;
1287
+ return this;
1187
1288
  }
1188
1289
 
1189
- updateMatrix() {
1190
- this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
1290
+ setScalar(scalar) {
1291
+ this.r = scalar;
1292
+ this.g = scalar;
1293
+ this.b = scalar;
1294
+ return this;
1191
1295
  }
1192
1296
 
1193
- clone() {
1194
- return new this.constructor().copy(this);
1297
+ setHex(hex) {
1298
+ hex = Math.floor(hex);
1299
+ this.r = (hex >> 16 & 255) / 255;
1300
+ this.g = (hex >> 8 & 255) / 255;
1301
+ this.b = (hex & 255) / 255;
1302
+ return this;
1195
1303
  }
1196
1304
 
1197
- copy(source) {
1198
- this.name = source.name;
1199
- this.image = source.image;
1200
- this.mipmaps = source.mipmaps.slice(0);
1201
- this.mapping = source.mapping;
1202
- this.wrapS = source.wrapS;
1203
- this.wrapT = source.wrapT;
1204
- this.magFilter = source.magFilter;
1205
- this.minFilter = source.minFilter;
1206
- this.anisotropy = source.anisotropy;
1207
- this.format = source.format;
1208
- this.internalFormat = source.internalFormat;
1209
- this.type = source.type;
1210
- this.offset.copy(source.offset);
1211
- this.repeat.copy(source.repeat);
1212
- this.center.copy(source.center);
1213
- this.rotation = source.rotation;
1214
- this.matrixAutoUpdate = source.matrixAutoUpdate;
1215
- this.matrix.copy(source.matrix);
1216
- this.generateMipmaps = source.generateMipmaps;
1217
- this.premultiplyAlpha = source.premultiplyAlpha;
1218
- this.flipY = source.flipY;
1219
- this.unpackAlignment = source.unpackAlignment;
1220
- this.encoding = source.encoding;
1221
- this.userData = JSON.parse(JSON.stringify(source.userData));
1305
+ setRGB(r, g, b) {
1306
+ this.r = r;
1307
+ this.g = g;
1308
+ this.b = b;
1222
1309
  return this;
1223
1310
  }
1224
1311
 
1225
- toJSON(meta) {
1226
- const isRootObject = meta === undefined || typeof meta === 'string';
1312
+ setHSL(h, s, l) {
1313
+ // h,s,l ranges are in 0.0 - 1.0
1314
+ h = euclideanModulo(h, 1);
1315
+ s = clamp(s, 0, 1);
1316
+ l = clamp(l, 0, 1);
1227
1317
 
1228
- if (!isRootObject && meta.textures[this.uuid] !== undefined) {
1229
- return meta.textures[this.uuid];
1318
+ if (s === 0) {
1319
+ this.r = this.g = this.b = l;
1320
+ } else {
1321
+ const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
1322
+ const q = 2 * l - p;
1323
+ this.r = hue2rgb(q, p, h + 1 / 3);
1324
+ this.g = hue2rgb(q, p, h);
1325
+ this.b = hue2rgb(q, p, h - 1 / 3);
1230
1326
  }
1231
1327
 
1232
- const output = {
1233
- metadata: {
1234
- version: 4.5,
1235
- type: 'Texture',
1236
- generator: 'Texture.toJSON'
1237
- },
1238
- uuid: this.uuid,
1239
- name: this.name,
1240
- mapping: this.mapping,
1241
- repeat: [this.repeat.x, this.repeat.y],
1242
- offset: [this.offset.x, this.offset.y],
1243
- center: [this.center.x, this.center.y],
1244
- rotation: this.rotation,
1245
- wrap: [this.wrapS, this.wrapT],
1246
- format: this.format,
1247
- type: this.type,
1248
- encoding: this.encoding,
1249
- minFilter: this.minFilter,
1250
- magFilter: this.magFilter,
1251
- anisotropy: this.anisotropy,
1252
- flipY: this.flipY,
1253
- premultiplyAlpha: this.premultiplyAlpha,
1254
- unpackAlignment: this.unpackAlignment
1255
- };
1256
-
1257
- if (this.image !== undefined) {
1258
- // TODO: Move to THREE.Image
1259
- const image = this.image;
1260
-
1261
- if (image.uuid === undefined) {
1262
- image.uuid = generateUUID(); // UGH
1263
- }
1264
-
1265
- if (!isRootObject && meta.images[image.uuid] === undefined) {
1266
- let url;
1267
-
1268
- if (Array.isArray(image)) {
1269
- // process array of images e.g. CubeTexture
1270
- url = [];
1328
+ return this;
1329
+ }
1271
1330
 
1272
- for (let i = 0, l = image.length; i < l; i++) {
1273
- // check cube texture with data textures
1274
- if (image[i].isDataTexture) {
1275
- url.push(serializeImage(image[i].image));
1276
- } else {
1277
- url.push(serializeImage(image[i]));
1278
- }
1279
- }
1280
- } else {
1281
- // process single image
1282
- url = serializeImage(image);
1283
- }
1331
+ setStyle(style) {
1332
+ function handleAlpha(string) {
1333
+ if (string === undefined) return;
1284
1334
 
1285
- meta.images[image.uuid] = {
1286
- uuid: image.uuid,
1287
- url: url
1288
- };
1335
+ if (parseFloat(string) < 1) {
1336
+ console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
1289
1337
  }
1290
-
1291
- output.image = image.uuid;
1292
- }
1293
-
1294
- if (JSON.stringify(this.userData) !== '{}') output.userData = this.userData;
1295
-
1296
- if (!isRootObject) {
1297
- meta.textures[this.uuid] = output;
1298
1338
  }
1299
1339
 
1300
- return output;
1301
- }
1340
+ let m;
1302
1341
 
1303
- dispose() {
1304
- this.dispatchEvent({
1305
- type: 'dispose'
1306
- });
1307
- }
1342
+ if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
1343
+ // rgb / hsl
1344
+ let color;
1345
+ const name = m[1];
1346
+ const components = m[2];
1308
1347
 
1309
- transformUv(uv) {
1310
- if (this.mapping !== UVMapping) return uv;
1311
- uv.applyMatrix3(this.matrix);
1348
+ switch (name) {
1349
+ case 'rgb':
1350
+ case 'rgba':
1351
+ if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
1352
+ // rgb(255,0,0) rgba(255,0,0,0.5)
1353
+ this.r = Math.min(255, parseInt(color[1], 10)) / 255;
1354
+ this.g = Math.min(255, parseInt(color[2], 10)) / 255;
1355
+ this.b = Math.min(255, parseInt(color[3], 10)) / 255;
1356
+ handleAlpha(color[4]);
1357
+ return this;
1358
+ }
1312
1359
 
1313
- if (uv.x < 0 || uv.x > 1) {
1314
- switch (this.wrapS) {
1315
- case RepeatWrapping:
1316
- uv.x = uv.x - Math.floor(uv.x);
1317
- break;
1360
+ if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
1361
+ // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
1362
+ this.r = Math.min(100, parseInt(color[1], 10)) / 100;
1363
+ this.g = Math.min(100, parseInt(color[2], 10)) / 100;
1364
+ this.b = Math.min(100, parseInt(color[3], 10)) / 100;
1365
+ handleAlpha(color[4]);
1366
+ return this;
1367
+ }
1318
1368
 
1319
- case ClampToEdgeWrapping:
1320
- uv.x = uv.x < 0 ? 0 : 1;
1321
1369
  break;
1322
1370
 
1323
- case MirroredRepeatWrapping:
1324
- if (Math.abs(Math.floor(uv.x) % 2) === 1) {
1325
- uv.x = Math.ceil(uv.x) - uv.x;
1326
- } else {
1327
- uv.x = uv.x - Math.floor(uv.x);
1371
+ case 'hsl':
1372
+ case 'hsla':
1373
+ if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
1374
+ // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
1375
+ const h = parseFloat(color[1]) / 360;
1376
+ const s = parseInt(color[2], 10) / 100;
1377
+ const l = parseInt(color[3], 10) / 100;
1378
+ handleAlpha(color[4]);
1379
+ return this.setHSL(h, s, l);
1328
1380
  }
1329
1381
 
1330
1382
  break;
1331
1383
  }
1384
+ } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
1385
+ // hex color
1386
+ const hex = m[1];
1387
+ const size = hex.length;
1388
+
1389
+ if (size === 3) {
1390
+ // #ff0
1391
+ this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
1392
+ this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
1393
+ this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
1394
+ return this;
1395
+ } else if (size === 6) {
1396
+ // #ff0000
1397
+ this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
1398
+ this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
1399
+ this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
1400
+ return this;
1401
+ }
1332
1402
  }
1333
1403
 
1334
- if (uv.y < 0 || uv.y > 1) {
1335
- switch (this.wrapT) {
1336
- case RepeatWrapping:
1337
- uv.y = uv.y - Math.floor(uv.y);
1338
- break;
1404
+ if (style && style.length > 0) {
1405
+ return this.setColorName(style);
1406
+ }
1339
1407
 
1340
- case ClampToEdgeWrapping:
1341
- uv.y = uv.y < 0 ? 0 : 1;
1342
- break;
1408
+ return this;
1409
+ }
1343
1410
 
1344
- case MirroredRepeatWrapping:
1345
- if (Math.abs(Math.floor(uv.y) % 2) === 1) {
1346
- uv.y = Math.ceil(uv.y) - uv.y;
1347
- } else {
1348
- uv.y = uv.y - Math.floor(uv.y);
1349
- }
1411
+ setColorName(style) {
1412
+ // color keywords
1413
+ const hex = _colorKeywords[style.toLowerCase()];
1350
1414
 
1351
- break;
1352
- }
1415
+ if (hex !== undefined) {
1416
+ // red
1417
+ this.setHex(hex);
1418
+ } else {
1419
+ // unknown color
1420
+ console.warn('THREE.Color: Unknown color ' + style);
1353
1421
  }
1354
1422
 
1355
- if (this.flipY) {
1356
- uv.y = 1 - uv.y;
1357
- }
1423
+ return this;
1424
+ }
1358
1425
 
1359
- return uv;
1426
+ clone() {
1427
+ return new this.constructor(this.r, this.g, this.b);
1360
1428
  }
1361
1429
 
1362
- set needsUpdate(value) {
1363
- if (value === true) this.version++;
1430
+ copy(color) {
1431
+ this.r = color.r;
1432
+ this.g = color.g;
1433
+ this.b = color.b;
1434
+ return this;
1435
+ }
1436
+
1437
+ copySRGBToLinear(color) {
1438
+ this.r = SRGBToLinear(color.r);
1439
+ this.g = SRGBToLinear(color.g);
1440
+ this.b = SRGBToLinear(color.b);
1441
+ return this;
1442
+ }
1443
+
1444
+ copyLinearToSRGB(color) {
1445
+ this.r = LinearToSRGB(color.r);
1446
+ this.g = LinearToSRGB(color.g);
1447
+ this.b = LinearToSRGB(color.b);
1448
+ return this;
1449
+ }
1450
+
1451
+ convertSRGBToLinear() {
1452
+ this.copySRGBToLinear(this);
1453
+ return this;
1454
+ }
1455
+
1456
+ convertLinearToSRGB() {
1457
+ this.copyLinearToSRGB(this);
1458
+ return this;
1459
+ }
1460
+
1461
+ getHex() {
1462
+ return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
1463
+ }
1464
+
1465
+ getHexString() {
1466
+ return ('000000' + this.getHex().toString(16)).slice(-6);
1467
+ }
1468
+
1469
+ getHSL(target) {
1470
+ // h,s,l ranges are in 0.0 - 1.0
1471
+ const r = this.r,
1472
+ g = this.g,
1473
+ b = this.b;
1474
+ const max = Math.max(r, g, b);
1475
+ const min = Math.min(r, g, b);
1476
+ let hue, saturation;
1477
+ const lightness = (min + max) / 2.0;
1478
+
1479
+ if (min === max) {
1480
+ hue = 0;
1481
+ saturation = 0;
1482
+ } else {
1483
+ const delta = max - min;
1484
+ saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
1485
+
1486
+ switch (max) {
1487
+ case r:
1488
+ hue = (g - b) / delta + (g < b ? 6 : 0);
1489
+ break;
1490
+
1491
+ case g:
1492
+ hue = (b - r) / delta + 2;
1493
+ break;
1494
+
1495
+ case b:
1496
+ hue = (r - g) / delta + 4;
1497
+ break;
1498
+ }
1499
+
1500
+ hue /= 6;
1501
+ }
1502
+
1503
+ target.h = hue;
1504
+ target.s = saturation;
1505
+ target.l = lightness;
1506
+ return target;
1507
+ }
1508
+
1509
+ getStyle() {
1510
+ return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
1511
+ }
1512
+
1513
+ offsetHSL(h, s, l) {
1514
+ this.getHSL(_hslA);
1515
+ _hslA.h += h;
1516
+ _hslA.s += s;
1517
+ _hslA.l += l;
1518
+ this.setHSL(_hslA.h, _hslA.s, _hslA.l);
1519
+ return this;
1520
+ }
1521
+
1522
+ add(color) {
1523
+ this.r += color.r;
1524
+ this.g += color.g;
1525
+ this.b += color.b;
1526
+ return this;
1527
+ }
1528
+
1529
+ addColors(color1, color2) {
1530
+ this.r = color1.r + color2.r;
1531
+ this.g = color1.g + color2.g;
1532
+ this.b = color1.b + color2.b;
1533
+ return this;
1534
+ }
1535
+
1536
+ addScalar(s) {
1537
+ this.r += s;
1538
+ this.g += s;
1539
+ this.b += s;
1540
+ return this;
1541
+ }
1542
+
1543
+ sub(color) {
1544
+ this.r = Math.max(0, this.r - color.r);
1545
+ this.g = Math.max(0, this.g - color.g);
1546
+ this.b = Math.max(0, this.b - color.b);
1547
+ return this;
1548
+ }
1549
+
1550
+ multiply(color) {
1551
+ this.r *= color.r;
1552
+ this.g *= color.g;
1553
+ this.b *= color.b;
1554
+ return this;
1555
+ }
1556
+
1557
+ multiplyScalar(s) {
1558
+ this.r *= s;
1559
+ this.g *= s;
1560
+ this.b *= s;
1561
+ return this;
1562
+ }
1563
+
1564
+ lerp(color, alpha) {
1565
+ this.r += (color.r - this.r) * alpha;
1566
+ this.g += (color.g - this.g) * alpha;
1567
+ this.b += (color.b - this.b) * alpha;
1568
+ return this;
1569
+ }
1570
+
1571
+ lerpColors(color1, color2, alpha) {
1572
+ this.r = color1.r + (color2.r - color1.r) * alpha;
1573
+ this.g = color1.g + (color2.g - color1.g) * alpha;
1574
+ this.b = color1.b + (color2.b - color1.b) * alpha;
1575
+ return this;
1576
+ }
1577
+
1578
+ lerpHSL(color, alpha) {
1579
+ this.getHSL(_hslA);
1580
+ color.getHSL(_hslB);
1581
+ const h = lerp(_hslA.h, _hslB.h, alpha);
1582
+ const s = lerp(_hslA.s, _hslB.s, alpha);
1583
+ const l = lerp(_hslA.l, _hslB.l, alpha);
1584
+ this.setHSL(h, s, l);
1585
+ return this;
1586
+ }
1587
+
1588
+ equals(c) {
1589
+ return c.r === this.r && c.g === this.g && c.b === this.b;
1590
+ }
1591
+
1592
+ fromArray(array, offset = 0) {
1593
+ this.r = array[offset];
1594
+ this.g = array[offset + 1];
1595
+ this.b = array[offset + 2];
1596
+ return this;
1597
+ }
1598
+
1599
+ toArray(array = [], offset = 0) {
1600
+ array[offset] = this.r;
1601
+ array[offset + 1] = this.g;
1602
+ array[offset + 2] = this.b;
1603
+ return array;
1604
+ }
1605
+
1606
+ fromBufferAttribute(attribute, index) {
1607
+ this.r = attribute.getX(index);
1608
+ this.g = attribute.getY(index);
1609
+ this.b = attribute.getZ(index);
1610
+
1611
+ if (attribute.normalized === true) {
1612
+ // assuming Uint8Array
1613
+ this.r /= 255;
1614
+ this.g /= 255;
1615
+ this.b /= 255;
1616
+ }
1617
+
1618
+ return this;
1619
+ }
1620
+
1621
+ toJSON() {
1622
+ return this.getHex();
1623
+ }
1624
+
1625
+ }
1626
+
1627
+ Color.NAMES = _colorKeywords;
1628
+ Color.prototype.isColor = true;
1629
+ Color.prototype.r = 1;
1630
+ Color.prototype.g = 1;
1631
+ Color.prototype.b = 1;
1632
+
1633
+ let _canvas;
1634
+
1635
+ class ImageUtils {
1636
+ static getDataURL(image) {
1637
+ if (/^data:/i.test(image.src)) {
1638
+ return image.src;
1639
+ }
1640
+
1641
+ if (typeof HTMLCanvasElement == 'undefined') {
1642
+ return image.src;
1643
+ }
1644
+
1645
+ let canvas;
1646
+
1647
+ if (image instanceof HTMLCanvasElement) {
1648
+ canvas = image;
1649
+ } else {
1650
+ if (_canvas === undefined) _canvas = createElementNS('canvas');
1651
+ _canvas.width = image.width;
1652
+ _canvas.height = image.height;
1653
+
1654
+ const context = _canvas.getContext('2d');
1655
+
1656
+ if (image instanceof ImageData) {
1657
+ context.putImageData(image, 0, 0);
1658
+ } else {
1659
+ context.drawImage(image, 0, 0, image.width, image.height);
1660
+ }
1661
+
1662
+ canvas = _canvas;
1663
+ }
1664
+
1665
+ if (canvas.width > 2048 || canvas.height > 2048) {
1666
+ console.warn('THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image);
1667
+ return canvas.toDataURL('image/jpeg', 0.6);
1668
+ } else {
1669
+ return canvas.toDataURL('image/png');
1670
+ }
1671
+ }
1672
+
1673
+ static sRGBToLinear(image) {
1674
+ if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
1675
+ const canvas = createElementNS('canvas');
1676
+ canvas.width = image.width;
1677
+ canvas.height = image.height;
1678
+ const context = canvas.getContext('2d');
1679
+ context.drawImage(image, 0, 0, image.width, image.height);
1680
+ const imageData = context.getImageData(0, 0, image.width, image.height);
1681
+ const data = imageData.data;
1682
+
1683
+ for (let i = 0; i < data.length; i++) {
1684
+ data[i] = SRGBToLinear(data[i] / 255) * 255;
1685
+ }
1686
+
1687
+ context.putImageData(imageData, 0, 0);
1688
+ return canvas;
1689
+ } else if (image.data) {
1690
+ const data = image.data.slice(0);
1691
+
1692
+ for (let i = 0; i < data.length; i++) {
1693
+ if (data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
1694
+ data[i] = Math.floor(SRGBToLinear(data[i] / 255) * 255);
1695
+ } else {
1696
+ // assuming float
1697
+ data[i] = SRGBToLinear(data[i]);
1698
+ }
1699
+ }
1700
+
1701
+ return {
1702
+ data: data,
1703
+ width: image.width,
1704
+ height: image.height
1705
+ };
1706
+ } else {
1707
+ console.warn('THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.');
1708
+ return image;
1709
+ }
1710
+ }
1711
+
1712
+ }
1713
+
1714
+ let textureId = 0;
1715
+
1716
+ class Texture extends EventDispatcher {
1717
+ constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1, encoding = LinearEncoding) {
1718
+ super();
1719
+ Object.defineProperty(this, 'id', {
1720
+ value: textureId++
1721
+ });
1722
+ this.uuid = generateUUID();
1723
+ this.name = '';
1724
+ this.image = image;
1725
+ this.mipmaps = [];
1726
+ this.mapping = mapping;
1727
+ this.wrapS = wrapS;
1728
+ this.wrapT = wrapT;
1729
+ this.magFilter = magFilter;
1730
+ this.minFilter = minFilter;
1731
+ this.anisotropy = anisotropy;
1732
+ this.format = format;
1733
+ this.internalFormat = null;
1734
+ this.type = type;
1735
+ this.offset = new Vector2(0, 0);
1736
+ this.repeat = new Vector2(1, 1);
1737
+ this.center = new Vector2(0, 0);
1738
+ this.rotation = 0;
1739
+ this.matrixAutoUpdate = true;
1740
+ this.matrix = new Matrix3();
1741
+ this.generateMipmaps = true;
1742
+ this.premultiplyAlpha = false;
1743
+ this.flipY = true;
1744
+ this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
1745
+ // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
1746
+ //
1747
+ // Also changing the encoding after already used by a Material will not automatically make the Material
1748
+ // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
1749
+
1750
+ this.encoding = encoding;
1751
+ this.userData = {};
1752
+ this.version = 0;
1753
+ this.onUpdate = null;
1754
+ this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
1755
+
1756
+ this.needsPMREMUpdate = false; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
1757
+ }
1758
+
1759
+ updateMatrix() {
1760
+ this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
1761
+ }
1762
+
1763
+ clone() {
1764
+ return new this.constructor().copy(this);
1765
+ }
1766
+
1767
+ copy(source) {
1768
+ this.name = source.name;
1769
+ this.image = source.image;
1770
+ this.mipmaps = source.mipmaps.slice(0);
1771
+ this.mapping = source.mapping;
1772
+ this.wrapS = source.wrapS;
1773
+ this.wrapT = source.wrapT;
1774
+ this.magFilter = source.magFilter;
1775
+ this.minFilter = source.minFilter;
1776
+ this.anisotropy = source.anisotropy;
1777
+ this.format = source.format;
1778
+ this.internalFormat = source.internalFormat;
1779
+ this.type = source.type;
1780
+ this.offset.copy(source.offset);
1781
+ this.repeat.copy(source.repeat);
1782
+ this.center.copy(source.center);
1783
+ this.rotation = source.rotation;
1784
+ this.matrixAutoUpdate = source.matrixAutoUpdate;
1785
+ this.matrix.copy(source.matrix);
1786
+ this.generateMipmaps = source.generateMipmaps;
1787
+ this.premultiplyAlpha = source.premultiplyAlpha;
1788
+ this.flipY = source.flipY;
1789
+ this.unpackAlignment = source.unpackAlignment;
1790
+ this.encoding = source.encoding;
1791
+ this.userData = JSON.parse(JSON.stringify(source.userData));
1792
+ return this;
1793
+ }
1794
+
1795
+ toJSON(meta) {
1796
+ const isRootObject = meta === undefined || typeof meta === 'string';
1797
+
1798
+ if (!isRootObject && meta.textures[this.uuid] !== undefined) {
1799
+ return meta.textures[this.uuid];
1800
+ }
1801
+
1802
+ const output = {
1803
+ metadata: {
1804
+ version: 4.5,
1805
+ type: 'Texture',
1806
+ generator: 'Texture.toJSON'
1807
+ },
1808
+ uuid: this.uuid,
1809
+ name: this.name,
1810
+ mapping: this.mapping,
1811
+ repeat: [this.repeat.x, this.repeat.y],
1812
+ offset: [this.offset.x, this.offset.y],
1813
+ center: [this.center.x, this.center.y],
1814
+ rotation: this.rotation,
1815
+ wrap: [this.wrapS, this.wrapT],
1816
+ format: this.format,
1817
+ type: this.type,
1818
+ encoding: this.encoding,
1819
+ minFilter: this.minFilter,
1820
+ magFilter: this.magFilter,
1821
+ anisotropy: this.anisotropy,
1822
+ flipY: this.flipY,
1823
+ premultiplyAlpha: this.premultiplyAlpha,
1824
+ unpackAlignment: this.unpackAlignment
1825
+ };
1826
+
1827
+ if (this.image !== undefined) {
1828
+ // TODO: Move to THREE.Image
1829
+ const image = this.image;
1830
+
1831
+ if (image.uuid === undefined) {
1832
+ image.uuid = generateUUID(); // UGH
1833
+ }
1834
+
1835
+ if (!isRootObject && meta.images[image.uuid] === undefined) {
1836
+ let url;
1837
+
1838
+ if (Array.isArray(image)) {
1839
+ // process array of images e.g. CubeTexture
1840
+ url = [];
1841
+
1842
+ for (let i = 0, l = image.length; i < l; i++) {
1843
+ // check cube texture with data textures
1844
+ if (image[i].isDataTexture) {
1845
+ url.push(serializeImage(image[i].image));
1846
+ } else {
1847
+ url.push(serializeImage(image[i]));
1848
+ }
1849
+ }
1850
+ } else {
1851
+ // process single image
1852
+ url = serializeImage(image);
1853
+ }
1854
+
1855
+ meta.images[image.uuid] = {
1856
+ uuid: image.uuid,
1857
+ url: url
1858
+ };
1859
+ }
1860
+
1861
+ output.image = image.uuid;
1862
+ }
1863
+
1864
+ if (JSON.stringify(this.userData) !== '{}') output.userData = this.userData;
1865
+
1866
+ if (!isRootObject) {
1867
+ meta.textures[this.uuid] = output;
1868
+ }
1869
+
1870
+ return output;
1871
+ }
1872
+
1873
+ dispose() {
1874
+ this.dispatchEvent({
1875
+ type: 'dispose'
1876
+ });
1877
+ }
1878
+
1879
+ transformUv(uv) {
1880
+ if (this.mapping !== UVMapping) return uv;
1881
+ uv.applyMatrix3(this.matrix);
1882
+
1883
+ if (uv.x < 0 || uv.x > 1) {
1884
+ switch (this.wrapS) {
1885
+ case RepeatWrapping:
1886
+ uv.x = uv.x - Math.floor(uv.x);
1887
+ break;
1888
+
1889
+ case ClampToEdgeWrapping:
1890
+ uv.x = uv.x < 0 ? 0 : 1;
1891
+ break;
1892
+
1893
+ case MirroredRepeatWrapping:
1894
+ if (Math.abs(Math.floor(uv.x) % 2) === 1) {
1895
+ uv.x = Math.ceil(uv.x) - uv.x;
1896
+ } else {
1897
+ uv.x = uv.x - Math.floor(uv.x);
1898
+ }
1899
+
1900
+ break;
1901
+ }
1902
+ }
1903
+
1904
+ if (uv.y < 0 || uv.y > 1) {
1905
+ switch (this.wrapT) {
1906
+ case RepeatWrapping:
1907
+ uv.y = uv.y - Math.floor(uv.y);
1908
+ break;
1909
+
1910
+ case ClampToEdgeWrapping:
1911
+ uv.y = uv.y < 0 ? 0 : 1;
1912
+ break;
1913
+
1914
+ case MirroredRepeatWrapping:
1915
+ if (Math.abs(Math.floor(uv.y) % 2) === 1) {
1916
+ uv.y = Math.ceil(uv.y) - uv.y;
1917
+ } else {
1918
+ uv.y = uv.y - Math.floor(uv.y);
1919
+ }
1920
+
1921
+ break;
1922
+ }
1923
+ }
1924
+
1925
+ if (this.flipY) {
1926
+ uv.y = 1 - uv.y;
1927
+ }
1928
+
1929
+ return uv;
1930
+ }
1931
+
1932
+ set needsUpdate(value) {
1933
+ if (value === true) this.version++;
1364
1934
  }
1365
1935
 
1366
1936
  }
@@ -2515,7 +3085,7 @@
2515
3085
  }
2516
3086
 
2517
3087
  slerpQuaternions(qa, qb, t) {
2518
- this.copy(qa).slerp(qb, t);
3088
+ return this.copy(qa).slerp(qb, t);
2519
3089
  }
2520
3090
 
2521
3091
  random() {
@@ -5637,1216 +6207,673 @@
5637
6207
  // remove metadata on each item
5638
6208
  // and return as array
5639
6209
 
5640
- function extractFromCache(cache) {
5641
- const values = [];
5642
-
5643
- for (const key in cache) {
5644
- const data = cache[key];
5645
- delete data.metadata;
5646
- values.push(data);
5647
- }
5648
-
5649
- return values;
5650
- }
5651
- }
5652
-
5653
- clone(recursive) {
5654
- return new this.constructor().copy(this, recursive);
5655
- }
5656
-
5657
- copy(source, recursive = true) {
5658
- this.name = source.name;
5659
- this.up.copy(source.up);
5660
- this.position.copy(source.position);
5661
- this.rotation.order = source.rotation.order;
5662
- this.quaternion.copy(source.quaternion);
5663
- this.scale.copy(source.scale);
5664
- this.matrix.copy(source.matrix);
5665
- this.matrixWorld.copy(source.matrixWorld);
5666
- this.matrixAutoUpdate = source.matrixAutoUpdate;
5667
- this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
5668
- this.layers.mask = source.layers.mask;
5669
- this.visible = source.visible;
5670
- this.castShadow = source.castShadow;
5671
- this.receiveShadow = source.receiveShadow;
5672
- this.frustumCulled = source.frustumCulled;
5673
- this.renderOrder = source.renderOrder;
5674
- this.userData = JSON.parse(JSON.stringify(source.userData));
5675
-
5676
- if (recursive === true) {
5677
- for (let i = 0; i < source.children.length; i++) {
5678
- const child = source.children[i];
5679
- this.add(child.clone());
5680
- }
5681
- }
5682
-
5683
- return this;
5684
- }
5685
-
5686
- }
5687
-
5688
- Object3D.DefaultUp = new Vector3(0, 1, 0);
5689
- Object3D.DefaultMatrixAutoUpdate = true;
5690
- Object3D.prototype.isObject3D = true;
5691
-
5692
- const _v0$1 = /*@__PURE__*/new Vector3();
5693
-
5694
- const _v1$3 = /*@__PURE__*/new Vector3();
5695
-
5696
- const _v2$2 = /*@__PURE__*/new Vector3();
5697
-
5698
- const _v3$1 = /*@__PURE__*/new Vector3();
5699
-
5700
- const _vab = /*@__PURE__*/new Vector3();
5701
-
5702
- const _vac = /*@__PURE__*/new Vector3();
5703
-
5704
- const _vbc = /*@__PURE__*/new Vector3();
5705
-
5706
- const _vap = /*@__PURE__*/new Vector3();
5707
-
5708
- const _vbp = /*@__PURE__*/new Vector3();
5709
-
5710
- const _vcp = /*@__PURE__*/new Vector3();
5711
-
5712
- class Triangle {
5713
- constructor(a = new Vector3(), b = new Vector3(), c = new Vector3()) {
5714
- this.a = a;
5715
- this.b = b;
5716
- this.c = c;
5717
- }
5718
-
5719
- static getNormal(a, b, c, target) {
5720
- target.subVectors(c, b);
5721
-
5722
- _v0$1.subVectors(a, b);
5723
-
5724
- target.cross(_v0$1);
5725
- const targetLengthSq = target.lengthSq();
5726
-
5727
- if (targetLengthSq > 0) {
5728
- return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
5729
- }
5730
-
5731
- return target.set(0, 0, 0);
5732
- } // static/instance method to calculate barycentric coordinates
5733
- // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
5734
-
5735
-
5736
- static getBarycoord(point, a, b, c, target) {
5737
- _v0$1.subVectors(c, a);
5738
-
5739
- _v1$3.subVectors(b, a);
5740
-
5741
- _v2$2.subVectors(point, a);
5742
-
5743
- const dot00 = _v0$1.dot(_v0$1);
5744
-
5745
- const dot01 = _v0$1.dot(_v1$3);
5746
-
5747
- const dot02 = _v0$1.dot(_v2$2);
5748
-
5749
- const dot11 = _v1$3.dot(_v1$3);
5750
-
5751
- const dot12 = _v1$3.dot(_v2$2);
5752
-
5753
- const denom = dot00 * dot11 - dot01 * dot01; // collinear or singular triangle
5754
-
5755
- if (denom === 0) {
5756
- // arbitrary location outside of triangle?
5757
- // not sure if this is the best idea, maybe should be returning undefined
5758
- return target.set(-2, -1, -1);
5759
- }
5760
-
5761
- const invDenom = 1 / denom;
5762
- const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
5763
- const v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
5764
-
5765
- return target.set(1 - u - v, v, u);
5766
- }
5767
-
5768
- static containsPoint(point, a, b, c) {
5769
- this.getBarycoord(point, a, b, c, _v3$1);
5770
- return _v3$1.x >= 0 && _v3$1.y >= 0 && _v3$1.x + _v3$1.y <= 1;
5771
- }
5772
-
5773
- static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
5774
- this.getBarycoord(point, p1, p2, p3, _v3$1);
5775
- target.set(0, 0);
5776
- target.addScaledVector(uv1, _v3$1.x);
5777
- target.addScaledVector(uv2, _v3$1.y);
5778
- target.addScaledVector(uv3, _v3$1.z);
5779
- return target;
5780
- }
5781
-
5782
- static isFrontFacing(a, b, c, direction) {
5783
- _v0$1.subVectors(c, b);
5784
-
5785
- _v1$3.subVectors(a, b); // strictly front facing
5786
-
5787
-
5788
- return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
5789
- }
5790
-
5791
- set(a, b, c) {
5792
- this.a.copy(a);
5793
- this.b.copy(b);
5794
- this.c.copy(c);
5795
- return this;
5796
- }
5797
-
5798
- setFromPointsAndIndices(points, i0, i1, i2) {
5799
- this.a.copy(points[i0]);
5800
- this.b.copy(points[i1]);
5801
- this.c.copy(points[i2]);
5802
- return this;
5803
- }
5804
-
5805
- setFromAttributeAndIndices(attribute, i0, i1, i2) {
5806
- this.a.fromBufferAttribute(attribute, i0);
5807
- this.b.fromBufferAttribute(attribute, i1);
5808
- this.c.fromBufferAttribute(attribute, i2);
5809
- return this;
5810
- }
5811
-
5812
- clone() {
5813
- return new this.constructor().copy(this);
5814
- }
5815
-
5816
- copy(triangle) {
5817
- this.a.copy(triangle.a);
5818
- this.b.copy(triangle.b);
5819
- this.c.copy(triangle.c);
5820
- return this;
5821
- }
5822
-
5823
- getArea() {
5824
- _v0$1.subVectors(this.c, this.b);
5825
-
5826
- _v1$3.subVectors(this.a, this.b);
5827
-
5828
- return _v0$1.cross(_v1$3).length() * 0.5;
5829
- }
5830
-
5831
- getMidpoint(target) {
5832
- return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
5833
- }
5834
-
5835
- getNormal(target) {
5836
- return Triangle.getNormal(this.a, this.b, this.c, target);
5837
- }
5838
-
5839
- getPlane(target) {
5840
- return target.setFromCoplanarPoints(this.a, this.b, this.c);
5841
- }
5842
-
5843
- getBarycoord(point, target) {
5844
- return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
5845
- }
5846
-
5847
- getUV(point, uv1, uv2, uv3, target) {
5848
- return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
5849
- }
5850
-
5851
- containsPoint(point) {
5852
- return Triangle.containsPoint(point, this.a, this.b, this.c);
5853
- }
5854
-
5855
- isFrontFacing(direction) {
5856
- return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
5857
- }
5858
-
5859
- intersectsBox(box) {
5860
- return box.intersectsTriangle(this);
5861
- }
5862
-
5863
- closestPointToPoint(p, target) {
5864
- const a = this.a,
5865
- b = this.b,
5866
- c = this.c;
5867
- let v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
5868
- // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
5869
- // under the accompanying license; see chapter 5.1.5 for detailed explanation.
5870
- // basically, we're distinguishing which of the voronoi regions of the triangle
5871
- // the point lies in with the minimum amount of redundant computation.
5872
-
5873
- _vab.subVectors(b, a);
5874
-
5875
- _vac.subVectors(c, a);
5876
-
5877
- _vap.subVectors(p, a);
5878
-
5879
- const d1 = _vab.dot(_vap);
5880
-
5881
- const d2 = _vac.dot(_vap);
5882
-
5883
- if (d1 <= 0 && d2 <= 0) {
5884
- // vertex region of A; barycentric coords (1, 0, 0)
5885
- return target.copy(a);
5886
- }
5887
-
5888
- _vbp.subVectors(p, b);
5889
-
5890
- const d3 = _vab.dot(_vbp);
5891
-
5892
- const d4 = _vac.dot(_vbp);
5893
-
5894
- if (d3 >= 0 && d4 <= d3) {
5895
- // vertex region of B; barycentric coords (0, 1, 0)
5896
- return target.copy(b);
5897
- }
5898
-
5899
- const vc = d1 * d4 - d3 * d2;
5900
-
5901
- if (vc <= 0 && d1 >= 0 && d3 <= 0) {
5902
- v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
5903
-
5904
- return target.copy(a).addScaledVector(_vab, v);
5905
- }
5906
-
5907
- _vcp.subVectors(p, c);
5908
-
5909
- const d5 = _vab.dot(_vcp);
5910
-
5911
- const d6 = _vac.dot(_vcp);
5912
-
5913
- if (d6 >= 0 && d5 <= d6) {
5914
- // vertex region of C; barycentric coords (0, 0, 1)
5915
- return target.copy(c);
5916
- }
5917
-
5918
- const vb = d5 * d2 - d1 * d6;
5919
-
5920
- if (vb <= 0 && d2 >= 0 && d6 <= 0) {
5921
- w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
5922
-
5923
- return target.copy(a).addScaledVector(_vac, w);
5924
- }
5925
-
5926
- const va = d3 * d6 - d5 * d4;
5927
-
5928
- if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
5929
- _vbc.subVectors(c, b);
5930
-
5931
- w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
5932
-
5933
- return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
5934
- } // face region
5935
-
5936
-
5937
- const denom = 1 / (va + vb + vc); // u = va * denom
5938
-
5939
- v = vb * denom;
5940
- w = vc * denom;
5941
- return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
5942
- }
5943
-
5944
- equals(triangle) {
5945
- return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
5946
- }
5947
-
5948
- }
5949
-
5950
- let materialId = 0;
5951
-
5952
- class Material extends EventDispatcher {
5953
- constructor() {
5954
- super();
5955
- Object.defineProperty(this, 'id', {
5956
- value: materialId++
5957
- });
5958
- this.uuid = generateUUID();
5959
- this.name = '';
5960
- this.type = 'Material';
5961
- this.fog = true;
5962
- this.blending = NormalBlending;
5963
- this.side = FrontSide;
5964
- this.vertexColors = false;
5965
- this.opacity = 1;
5966
- this.format = RGBAFormat;
5967
- this.transparent = false;
5968
- this.blendSrc = SrcAlphaFactor;
5969
- this.blendDst = OneMinusSrcAlphaFactor;
5970
- this.blendEquation = AddEquation;
5971
- this.blendSrcAlpha = null;
5972
- this.blendDstAlpha = null;
5973
- this.blendEquationAlpha = null;
5974
- this.depthFunc = LessEqualDepth;
5975
- this.depthTest = true;
5976
- this.depthWrite = true;
5977
- this.stencilWriteMask = 0xff;
5978
- this.stencilFunc = AlwaysStencilFunc;
5979
- this.stencilRef = 0;
5980
- this.stencilFuncMask = 0xff;
5981
- this.stencilFail = KeepStencilOp;
5982
- this.stencilZFail = KeepStencilOp;
5983
- this.stencilZPass = KeepStencilOp;
5984
- this.stencilWrite = false;
5985
- this.clippingPlanes = null;
5986
- this.clipIntersection = false;
5987
- this.clipShadows = false;
5988
- this.shadowSide = null;
5989
- this.colorWrite = true;
5990
- this.precision = null; // override the renderer's default precision for this material
5991
-
5992
- this.polygonOffset = false;
5993
- this.polygonOffsetFactor = 0;
5994
- this.polygonOffsetUnits = 0;
5995
- this.dithering = false;
5996
- this.alphaToCoverage = false;
5997
- this.premultipliedAlpha = false;
5998
- this.visible = true;
5999
- this.toneMapped = true;
6000
- this.userData = {};
6001
- this.version = 0;
6002
- this._alphaTest = 0;
6003
- }
6004
-
6005
- get alphaTest() {
6006
- return this._alphaTest;
6007
- }
6008
-
6009
- set alphaTest(value) {
6010
- if (this._alphaTest > 0 !== value > 0) {
6011
- this.version++;
6012
- }
6013
-
6014
- this._alphaTest = value;
6015
- }
6016
-
6017
- onBuild() {}
6018
-
6019
- onBeforeRender() {}
6020
-
6021
- onBeforeCompile() {}
6022
-
6023
- customProgramCacheKey() {
6024
- return this.onBeforeCompile.toString();
6025
- }
6026
-
6027
- setValues(values) {
6028
- if (values === undefined) return;
6029
-
6030
- for (const key in values) {
6031
- const newValue = values[key];
6032
-
6033
- if (newValue === undefined) {
6034
- console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
6035
- continue;
6036
- } // for backward compatability if shading is set in the constructor
6037
-
6038
-
6039
- if (key === 'shading') {
6040
- console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
6041
- this.flatShading = newValue === FlatShading ? true : false;
6042
- continue;
6043
- }
6044
-
6045
- const currentValue = this[key];
6046
-
6047
- if (currentValue === undefined) {
6048
- console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
6049
- continue;
6050
- }
6051
-
6052
- if (currentValue && currentValue.isColor) {
6053
- currentValue.set(newValue);
6054
- } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
6055
- currentValue.copy(newValue);
6056
- } else {
6057
- this[key] = newValue;
6058
- }
6059
- }
6060
- }
6061
-
6062
- toJSON(meta) {
6063
- const isRoot = meta === undefined || typeof meta === 'string';
6064
-
6065
- if (isRoot) {
6066
- meta = {
6067
- textures: {},
6068
- images: {}
6069
- };
6070
- }
6071
-
6072
- const data = {
6073
- metadata: {
6074
- version: 4.5,
6075
- type: 'Material',
6076
- generator: 'Material.toJSON'
6077
- }
6078
- }; // standard Material serialization
6079
-
6080
- data.uuid = this.uuid;
6081
- data.type = this.type;
6082
- if (this.name !== '') data.name = this.name;
6083
- if (this.color && this.color.isColor) data.color = this.color.getHex();
6084
- if (this.roughness !== undefined) data.roughness = this.roughness;
6085
- if (this.metalness !== undefined) data.metalness = this.metalness;
6086
- if (this.sheen !== undefined) data.sheen = this.sheen;
6087
- if (this.sheenColor && this.sheenColor.isColor) data.sheenColor = this.sheenColor.getHex();
6088
- if (this.sheenRoughness !== undefined) data.sheenRoughness = this.sheenRoughness;
6089
- if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
6090
- if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
6091
- if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
6092
- if (this.specularIntensity !== undefined) data.specularIntensity = this.specularIntensity;
6093
- if (this.specularColor && this.specularColor.isColor) data.specularColor = this.specularColor.getHex();
6094
- if (this.shininess !== undefined) data.shininess = this.shininess;
6095
- if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
6096
- if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
6097
-
6098
- if (this.clearcoatMap && this.clearcoatMap.isTexture) {
6099
- data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
6100
- }
6101
-
6102
- if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
6103
- data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
6104
- }
6105
-
6106
- if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
6107
- data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
6108
- data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
6109
- }
6110
-
6111
- if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
6112
- if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
6113
- if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
6114
-
6115
- if (this.lightMap && this.lightMap.isTexture) {
6116
- data.lightMap = this.lightMap.toJSON(meta).uuid;
6117
- data.lightMapIntensity = this.lightMapIntensity;
6118
- }
6119
-
6120
- if (this.aoMap && this.aoMap.isTexture) {
6121
- data.aoMap = this.aoMap.toJSON(meta).uuid;
6122
- data.aoMapIntensity = this.aoMapIntensity;
6123
- }
6124
-
6125
- if (this.bumpMap && this.bumpMap.isTexture) {
6126
- data.bumpMap = this.bumpMap.toJSON(meta).uuid;
6127
- data.bumpScale = this.bumpScale;
6128
- }
6129
-
6130
- if (this.normalMap && this.normalMap.isTexture) {
6131
- data.normalMap = this.normalMap.toJSON(meta).uuid;
6132
- data.normalMapType = this.normalMapType;
6133
- data.normalScale = this.normalScale.toArray();
6134
- }
6135
-
6136
- if (this.displacementMap && this.displacementMap.isTexture) {
6137
- data.displacementMap = this.displacementMap.toJSON(meta).uuid;
6138
- data.displacementScale = this.displacementScale;
6139
- data.displacementBias = this.displacementBias;
6140
- }
6141
-
6142
- if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
6143
- if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
6144
- if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
6145
- if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
6146
- if (this.specularIntensityMap && this.specularIntensityMap.isTexture) data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid;
6147
- if (this.specularColorMap && this.specularColorMap.isTexture) data.specularColorMap = this.specularColorMap.toJSON(meta).uuid;
6148
-
6149
- if (this.envMap && this.envMap.isTexture) {
6150
- data.envMap = this.envMap.toJSON(meta).uuid;
6151
- if (this.combine !== undefined) data.combine = this.combine;
6152
- }
6153
-
6154
- if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
6155
- if (this.reflectivity !== undefined) data.reflectivity = this.reflectivity;
6156
- if (this.refractionRatio !== undefined) data.refractionRatio = this.refractionRatio;
6157
-
6158
- if (this.gradientMap && this.gradientMap.isTexture) {
6159
- data.gradientMap = this.gradientMap.toJSON(meta).uuid;
6160
- }
6161
-
6162
- if (this.transmission !== undefined) data.transmission = this.transmission;
6163
- if (this.transmissionMap && this.transmissionMap.isTexture) data.transmissionMap = this.transmissionMap.toJSON(meta).uuid;
6164
- if (this.thickness !== undefined) data.thickness = this.thickness;
6165
- if (this.thicknessMap && this.thicknessMap.isTexture) data.thicknessMap = this.thicknessMap.toJSON(meta).uuid;
6166
- if (this.attenuationDistance !== undefined) data.attenuationDistance = this.attenuationDistance;
6167
- if (this.attenuationColor !== undefined) data.attenuationColor = this.attenuationColor.getHex();
6168
- if (this.size !== undefined) data.size = this.size;
6169
- if (this.shadowSide !== null) data.shadowSide = this.shadowSide;
6170
- if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
6171
- if (this.blending !== NormalBlending) data.blending = this.blending;
6172
- if (this.side !== FrontSide) data.side = this.side;
6173
- if (this.vertexColors) data.vertexColors = true;
6174
- if (this.opacity < 1) data.opacity = this.opacity;
6175
- if (this.format !== RGBAFormat) data.format = this.format;
6176
- if (this.transparent === true) data.transparent = this.transparent;
6177
- data.depthFunc = this.depthFunc;
6178
- data.depthTest = this.depthTest;
6179
- data.depthWrite = this.depthWrite;
6180
- data.colorWrite = this.colorWrite;
6181
- data.stencilWrite = this.stencilWrite;
6182
- data.stencilWriteMask = this.stencilWriteMask;
6183
- data.stencilFunc = this.stencilFunc;
6184
- data.stencilRef = this.stencilRef;
6185
- data.stencilFuncMask = this.stencilFuncMask;
6186
- data.stencilFail = this.stencilFail;
6187
- data.stencilZFail = this.stencilZFail;
6188
- data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
6189
-
6190
- if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
6191
- if (this.polygonOffset === true) data.polygonOffset = true;
6192
- if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
6193
- if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
6194
- if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
6195
- if (this.dashSize !== undefined) data.dashSize = this.dashSize;
6196
- if (this.gapSize !== undefined) data.gapSize = this.gapSize;
6197
- if (this.scale !== undefined) data.scale = this.scale;
6198
- if (this.dithering === true) data.dithering = true;
6199
- if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
6200
- if (this.alphaToCoverage === true) data.alphaToCoverage = this.alphaToCoverage;
6201
- if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
6202
- if (this.wireframe === true) data.wireframe = this.wireframe;
6203
- if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
6204
- if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
6205
- if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
6206
- if (this.flatShading === true) data.flatShading = this.flatShading;
6207
- if (this.visible === false) data.visible = false;
6208
- if (this.toneMapped === false) data.toneMapped = false;
6209
- if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
6210
-
6211
- function extractFromCache(cache) {
6212
- const values = [];
6213
-
6214
- for (const key in cache) {
6215
- const data = cache[key];
6216
- delete data.metadata;
6217
- values.push(data);
6218
- }
6219
-
6220
- return values;
6221
- }
6222
-
6223
- if (isRoot) {
6224
- const textures = extractFromCache(meta.textures);
6225
- const images = extractFromCache(meta.images);
6226
- if (textures.length > 0) data.textures = textures;
6227
- if (images.length > 0) data.images = images;
6228
- }
6229
-
6230
- return data;
6231
- }
6232
-
6233
- clone() {
6234
- return new this.constructor().copy(this);
6235
- }
6236
-
6237
- copy(source) {
6238
- this.name = source.name;
6239
- this.fog = source.fog;
6240
- this.blending = source.blending;
6241
- this.side = source.side;
6242
- this.vertexColors = source.vertexColors;
6243
- this.opacity = source.opacity;
6244
- this.format = source.format;
6245
- this.transparent = source.transparent;
6246
- this.blendSrc = source.blendSrc;
6247
- this.blendDst = source.blendDst;
6248
- this.blendEquation = source.blendEquation;
6249
- this.blendSrcAlpha = source.blendSrcAlpha;
6250
- this.blendDstAlpha = source.blendDstAlpha;
6251
- this.blendEquationAlpha = source.blendEquationAlpha;
6252
- this.depthFunc = source.depthFunc;
6253
- this.depthTest = source.depthTest;
6254
- this.depthWrite = source.depthWrite;
6255
- this.stencilWriteMask = source.stencilWriteMask;
6256
- this.stencilFunc = source.stencilFunc;
6257
- this.stencilRef = source.stencilRef;
6258
- this.stencilFuncMask = source.stencilFuncMask;
6259
- this.stencilFail = source.stencilFail;
6260
- this.stencilZFail = source.stencilZFail;
6261
- this.stencilZPass = source.stencilZPass;
6262
- this.stencilWrite = source.stencilWrite;
6263
- const srcPlanes = source.clippingPlanes;
6264
- let dstPlanes = null;
6265
-
6266
- if (srcPlanes !== null) {
6267
- const n = srcPlanes.length;
6268
- dstPlanes = new Array(n);
6269
-
6270
- for (let i = 0; i !== n; ++i) {
6271
- dstPlanes[i] = srcPlanes[i].clone();
6272
- }
6273
- }
6274
-
6275
- this.clippingPlanes = dstPlanes;
6276
- this.clipIntersection = source.clipIntersection;
6277
- this.clipShadows = source.clipShadows;
6278
- this.shadowSide = source.shadowSide;
6279
- this.colorWrite = source.colorWrite;
6280
- this.precision = source.precision;
6281
- this.polygonOffset = source.polygonOffset;
6282
- this.polygonOffsetFactor = source.polygonOffsetFactor;
6283
- this.polygonOffsetUnits = source.polygonOffsetUnits;
6284
- this.dithering = source.dithering;
6285
- this.alphaTest = source.alphaTest;
6286
- this.alphaToCoverage = source.alphaToCoverage;
6287
- this.premultipliedAlpha = source.premultipliedAlpha;
6288
- this.visible = source.visible;
6289
- this.toneMapped = source.toneMapped;
6290
- this.userData = JSON.parse(JSON.stringify(source.userData));
6291
- return this;
6292
- }
6293
-
6294
- dispose() {
6295
- this.dispatchEvent({
6296
- type: 'dispose'
6297
- });
6298
- }
6299
-
6300
- set needsUpdate(value) {
6301
- if (value === true) this.version++;
6302
- }
6303
-
6304
- }
6305
-
6306
- Material.prototype.isMaterial = true;
6307
-
6308
- const _colorKeywords = {
6309
- 'aliceblue': 0xF0F8FF,
6310
- 'antiquewhite': 0xFAEBD7,
6311
- 'aqua': 0x00FFFF,
6312
- 'aquamarine': 0x7FFFD4,
6313
- 'azure': 0xF0FFFF,
6314
- 'beige': 0xF5F5DC,
6315
- 'bisque': 0xFFE4C4,
6316
- 'black': 0x000000,
6317
- 'blanchedalmond': 0xFFEBCD,
6318
- 'blue': 0x0000FF,
6319
- 'blueviolet': 0x8A2BE2,
6320
- 'brown': 0xA52A2A,
6321
- 'burlywood': 0xDEB887,
6322
- 'cadetblue': 0x5F9EA0,
6323
- 'chartreuse': 0x7FFF00,
6324
- 'chocolate': 0xD2691E,
6325
- 'coral': 0xFF7F50,
6326
- 'cornflowerblue': 0x6495ED,
6327
- 'cornsilk': 0xFFF8DC,
6328
- 'crimson': 0xDC143C,
6329
- 'cyan': 0x00FFFF,
6330
- 'darkblue': 0x00008B,
6331
- 'darkcyan': 0x008B8B,
6332
- 'darkgoldenrod': 0xB8860B,
6333
- 'darkgray': 0xA9A9A9,
6334
- 'darkgreen': 0x006400,
6335
- 'darkgrey': 0xA9A9A9,
6336
- 'darkkhaki': 0xBDB76B,
6337
- 'darkmagenta': 0x8B008B,
6338
- 'darkolivegreen': 0x556B2F,
6339
- 'darkorange': 0xFF8C00,
6340
- 'darkorchid': 0x9932CC,
6341
- 'darkred': 0x8B0000,
6342
- 'darksalmon': 0xE9967A,
6343
- 'darkseagreen': 0x8FBC8F,
6344
- 'darkslateblue': 0x483D8B,
6345
- 'darkslategray': 0x2F4F4F,
6346
- 'darkslategrey': 0x2F4F4F,
6347
- 'darkturquoise': 0x00CED1,
6348
- 'darkviolet': 0x9400D3,
6349
- 'deeppink': 0xFF1493,
6350
- 'deepskyblue': 0x00BFFF,
6351
- 'dimgray': 0x696969,
6352
- 'dimgrey': 0x696969,
6353
- 'dodgerblue': 0x1E90FF,
6354
- 'firebrick': 0xB22222,
6355
- 'floralwhite': 0xFFFAF0,
6356
- 'forestgreen': 0x228B22,
6357
- 'fuchsia': 0xFF00FF,
6358
- 'gainsboro': 0xDCDCDC,
6359
- 'ghostwhite': 0xF8F8FF,
6360
- 'gold': 0xFFD700,
6361
- 'goldenrod': 0xDAA520,
6362
- 'gray': 0x808080,
6363
- 'green': 0x008000,
6364
- 'greenyellow': 0xADFF2F,
6365
- 'grey': 0x808080,
6366
- 'honeydew': 0xF0FFF0,
6367
- 'hotpink': 0xFF69B4,
6368
- 'indianred': 0xCD5C5C,
6369
- 'indigo': 0x4B0082,
6370
- 'ivory': 0xFFFFF0,
6371
- 'khaki': 0xF0E68C,
6372
- 'lavender': 0xE6E6FA,
6373
- 'lavenderblush': 0xFFF0F5,
6374
- 'lawngreen': 0x7CFC00,
6375
- 'lemonchiffon': 0xFFFACD,
6376
- 'lightblue': 0xADD8E6,
6377
- 'lightcoral': 0xF08080,
6378
- 'lightcyan': 0xE0FFFF,
6379
- 'lightgoldenrodyellow': 0xFAFAD2,
6380
- 'lightgray': 0xD3D3D3,
6381
- 'lightgreen': 0x90EE90,
6382
- 'lightgrey': 0xD3D3D3,
6383
- 'lightpink': 0xFFB6C1,
6384
- 'lightsalmon': 0xFFA07A,
6385
- 'lightseagreen': 0x20B2AA,
6386
- 'lightskyblue': 0x87CEFA,
6387
- 'lightslategray': 0x778899,
6388
- 'lightslategrey': 0x778899,
6389
- 'lightsteelblue': 0xB0C4DE,
6390
- 'lightyellow': 0xFFFFE0,
6391
- 'lime': 0x00FF00,
6392
- 'limegreen': 0x32CD32,
6393
- 'linen': 0xFAF0E6,
6394
- 'magenta': 0xFF00FF,
6395
- 'maroon': 0x800000,
6396
- 'mediumaquamarine': 0x66CDAA,
6397
- 'mediumblue': 0x0000CD,
6398
- 'mediumorchid': 0xBA55D3,
6399
- 'mediumpurple': 0x9370DB,
6400
- 'mediumseagreen': 0x3CB371,
6401
- 'mediumslateblue': 0x7B68EE,
6402
- 'mediumspringgreen': 0x00FA9A,
6403
- 'mediumturquoise': 0x48D1CC,
6404
- 'mediumvioletred': 0xC71585,
6405
- 'midnightblue': 0x191970,
6406
- 'mintcream': 0xF5FFFA,
6407
- 'mistyrose': 0xFFE4E1,
6408
- 'moccasin': 0xFFE4B5,
6409
- 'navajowhite': 0xFFDEAD,
6410
- 'navy': 0x000080,
6411
- 'oldlace': 0xFDF5E6,
6412
- 'olive': 0x808000,
6413
- 'olivedrab': 0x6B8E23,
6414
- 'orange': 0xFFA500,
6415
- 'orangered': 0xFF4500,
6416
- 'orchid': 0xDA70D6,
6417
- 'palegoldenrod': 0xEEE8AA,
6418
- 'palegreen': 0x98FB98,
6419
- 'paleturquoise': 0xAFEEEE,
6420
- 'palevioletred': 0xDB7093,
6421
- 'papayawhip': 0xFFEFD5,
6422
- 'peachpuff': 0xFFDAB9,
6423
- 'peru': 0xCD853F,
6424
- 'pink': 0xFFC0CB,
6425
- 'plum': 0xDDA0DD,
6426
- 'powderblue': 0xB0E0E6,
6427
- 'purple': 0x800080,
6428
- 'rebeccapurple': 0x663399,
6429
- 'red': 0xFF0000,
6430
- 'rosybrown': 0xBC8F8F,
6431
- 'royalblue': 0x4169E1,
6432
- 'saddlebrown': 0x8B4513,
6433
- 'salmon': 0xFA8072,
6434
- 'sandybrown': 0xF4A460,
6435
- 'seagreen': 0x2E8B57,
6436
- 'seashell': 0xFFF5EE,
6437
- 'sienna': 0xA0522D,
6438
- 'silver': 0xC0C0C0,
6439
- 'skyblue': 0x87CEEB,
6440
- 'slateblue': 0x6A5ACD,
6441
- 'slategray': 0x708090,
6442
- 'slategrey': 0x708090,
6443
- 'snow': 0xFFFAFA,
6444
- 'springgreen': 0x00FF7F,
6445
- 'steelblue': 0x4682B4,
6446
- 'tan': 0xD2B48C,
6447
- 'teal': 0x008080,
6448
- 'thistle': 0xD8BFD8,
6449
- 'tomato': 0xFF6347,
6450
- 'turquoise': 0x40E0D0,
6451
- 'violet': 0xEE82EE,
6452
- 'wheat': 0xF5DEB3,
6453
- 'white': 0xFFFFFF,
6454
- 'whitesmoke': 0xF5F5F5,
6455
- 'yellow': 0xFFFF00,
6456
- 'yellowgreen': 0x9ACD32
6457
- };
6458
- const _hslA = {
6459
- h: 0,
6460
- s: 0,
6461
- l: 0
6462
- };
6463
- const _hslB = {
6464
- h: 0,
6465
- s: 0,
6466
- l: 0
6467
- };
6468
-
6469
- function hue2rgb(p, q, t) {
6470
- if (t < 0) t += 1;
6471
- if (t > 1) t -= 1;
6472
- if (t < 1 / 6) return p + (q - p) * 6 * t;
6473
- if (t < 1 / 2) return q;
6474
- if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
6475
- return p;
6476
- }
6210
+ function extractFromCache(cache) {
6211
+ const values = [];
6477
6212
 
6478
- function SRGBToLinear(c) {
6479
- return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
6480
- }
6213
+ for (const key in cache) {
6214
+ const data = cache[key];
6215
+ delete data.metadata;
6216
+ values.push(data);
6217
+ }
6481
6218
 
6482
- function LinearToSRGB(c) {
6483
- return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
6484
- }
6219
+ return values;
6220
+ }
6221
+ }
6485
6222
 
6486
- class Color {
6487
- constructor(r, g, b) {
6488
- if (g === undefined && b === undefined) {
6489
- // r is THREE.Color, hex or string
6490
- return this.set(r);
6223
+ clone(recursive) {
6224
+ return new this.constructor().copy(this, recursive);
6225
+ }
6226
+
6227
+ copy(source, recursive = true) {
6228
+ this.name = source.name;
6229
+ this.up.copy(source.up);
6230
+ this.position.copy(source.position);
6231
+ this.rotation.order = source.rotation.order;
6232
+ this.quaternion.copy(source.quaternion);
6233
+ this.scale.copy(source.scale);
6234
+ this.matrix.copy(source.matrix);
6235
+ this.matrixWorld.copy(source.matrixWorld);
6236
+ this.matrixAutoUpdate = source.matrixAutoUpdate;
6237
+ this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
6238
+ this.layers.mask = source.layers.mask;
6239
+ this.visible = source.visible;
6240
+ this.castShadow = source.castShadow;
6241
+ this.receiveShadow = source.receiveShadow;
6242
+ this.frustumCulled = source.frustumCulled;
6243
+ this.renderOrder = source.renderOrder;
6244
+ this.userData = JSON.parse(JSON.stringify(source.userData));
6245
+
6246
+ if (recursive === true) {
6247
+ for (let i = 0; i < source.children.length; i++) {
6248
+ const child = source.children[i];
6249
+ this.add(child.clone());
6250
+ }
6491
6251
  }
6492
6252
 
6493
- return this.setRGB(r, g, b);
6253
+ return this;
6494
6254
  }
6495
6255
 
6496
- set(value) {
6497
- if (value && value.isColor) {
6498
- this.copy(value);
6499
- } else if (typeof value === 'number') {
6500
- this.setHex(value);
6501
- } else if (typeof value === 'string') {
6502
- this.setStyle(value);
6256
+ }
6257
+
6258
+ Object3D.DefaultUp = new Vector3(0, 1, 0);
6259
+ Object3D.DefaultMatrixAutoUpdate = true;
6260
+ Object3D.prototype.isObject3D = true;
6261
+
6262
+ const _v0$1 = /*@__PURE__*/new Vector3();
6263
+
6264
+ const _v1$3 = /*@__PURE__*/new Vector3();
6265
+
6266
+ const _v2$2 = /*@__PURE__*/new Vector3();
6267
+
6268
+ const _v3$1 = /*@__PURE__*/new Vector3();
6269
+
6270
+ const _vab = /*@__PURE__*/new Vector3();
6271
+
6272
+ const _vac = /*@__PURE__*/new Vector3();
6273
+
6274
+ const _vbc = /*@__PURE__*/new Vector3();
6275
+
6276
+ const _vap = /*@__PURE__*/new Vector3();
6277
+
6278
+ const _vbp = /*@__PURE__*/new Vector3();
6279
+
6280
+ const _vcp = /*@__PURE__*/new Vector3();
6281
+
6282
+ class Triangle {
6283
+ constructor(a = new Vector3(), b = new Vector3(), c = new Vector3()) {
6284
+ this.a = a;
6285
+ this.b = b;
6286
+ this.c = c;
6287
+ }
6288
+
6289
+ static getNormal(a, b, c, target) {
6290
+ target.subVectors(c, b);
6291
+
6292
+ _v0$1.subVectors(a, b);
6293
+
6294
+ target.cross(_v0$1);
6295
+ const targetLengthSq = target.lengthSq();
6296
+
6297
+ if (targetLengthSq > 0) {
6298
+ return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
6299
+ }
6300
+
6301
+ return target.set(0, 0, 0);
6302
+ } // static/instance method to calculate barycentric coordinates
6303
+ // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
6304
+
6305
+
6306
+ static getBarycoord(point, a, b, c, target) {
6307
+ _v0$1.subVectors(c, a);
6308
+
6309
+ _v1$3.subVectors(b, a);
6310
+
6311
+ _v2$2.subVectors(point, a);
6312
+
6313
+ const dot00 = _v0$1.dot(_v0$1);
6314
+
6315
+ const dot01 = _v0$1.dot(_v1$3);
6316
+
6317
+ const dot02 = _v0$1.dot(_v2$2);
6318
+
6319
+ const dot11 = _v1$3.dot(_v1$3);
6320
+
6321
+ const dot12 = _v1$3.dot(_v2$2);
6322
+
6323
+ const denom = dot00 * dot11 - dot01 * dot01; // collinear or singular triangle
6324
+
6325
+ if (denom === 0) {
6326
+ // arbitrary location outside of triangle?
6327
+ // not sure if this is the best idea, maybe should be returning undefined
6328
+ return target.set(-2, -1, -1);
6503
6329
  }
6504
6330
 
6331
+ const invDenom = 1 / denom;
6332
+ const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
6333
+ const v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
6334
+
6335
+ return target.set(1 - u - v, v, u);
6336
+ }
6337
+
6338
+ static containsPoint(point, a, b, c) {
6339
+ this.getBarycoord(point, a, b, c, _v3$1);
6340
+ return _v3$1.x >= 0 && _v3$1.y >= 0 && _v3$1.x + _v3$1.y <= 1;
6341
+ }
6342
+
6343
+ static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
6344
+ this.getBarycoord(point, p1, p2, p3, _v3$1);
6345
+ target.set(0, 0);
6346
+ target.addScaledVector(uv1, _v3$1.x);
6347
+ target.addScaledVector(uv2, _v3$1.y);
6348
+ target.addScaledVector(uv3, _v3$1.z);
6349
+ return target;
6350
+ }
6351
+
6352
+ static isFrontFacing(a, b, c, direction) {
6353
+ _v0$1.subVectors(c, b);
6354
+
6355
+ _v1$3.subVectors(a, b); // strictly front facing
6356
+
6357
+
6358
+ return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
6359
+ }
6360
+
6361
+ set(a, b, c) {
6362
+ this.a.copy(a);
6363
+ this.b.copy(b);
6364
+ this.c.copy(c);
6505
6365
  return this;
6506
6366
  }
6507
6367
 
6508
- setScalar(scalar) {
6509
- this.r = scalar;
6510
- this.g = scalar;
6511
- this.b = scalar;
6368
+ setFromPointsAndIndices(points, i0, i1, i2) {
6369
+ this.a.copy(points[i0]);
6370
+ this.b.copy(points[i1]);
6371
+ this.c.copy(points[i2]);
6512
6372
  return this;
6513
6373
  }
6514
6374
 
6515
- setHex(hex) {
6516
- hex = Math.floor(hex);
6517
- this.r = (hex >> 16 & 255) / 255;
6518
- this.g = (hex >> 8 & 255) / 255;
6519
- this.b = (hex & 255) / 255;
6375
+ setFromAttributeAndIndices(attribute, i0, i1, i2) {
6376
+ this.a.fromBufferAttribute(attribute, i0);
6377
+ this.b.fromBufferAttribute(attribute, i1);
6378
+ this.c.fromBufferAttribute(attribute, i2);
6520
6379
  return this;
6521
6380
  }
6522
6381
 
6523
- setRGB(r, g, b) {
6524
- this.r = r;
6525
- this.g = g;
6526
- this.b = b;
6382
+ clone() {
6383
+ return new this.constructor().copy(this);
6384
+ }
6385
+
6386
+ copy(triangle) {
6387
+ this.a.copy(triangle.a);
6388
+ this.b.copy(triangle.b);
6389
+ this.c.copy(triangle.c);
6527
6390
  return this;
6528
6391
  }
6529
6392
 
6530
- setHSL(h, s, l) {
6531
- // h,s,l ranges are in 0.0 - 1.0
6532
- h = euclideanModulo(h, 1);
6533
- s = clamp(s, 0, 1);
6534
- l = clamp(l, 0, 1);
6393
+ getArea() {
6394
+ _v0$1.subVectors(this.c, this.b);
6535
6395
 
6536
- if (s === 0) {
6537
- this.r = this.g = this.b = l;
6538
- } else {
6539
- const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
6540
- const q = 2 * l - p;
6541
- this.r = hue2rgb(q, p, h + 1 / 3);
6542
- this.g = hue2rgb(q, p, h);
6543
- this.b = hue2rgb(q, p, h - 1 / 3);
6544
- }
6396
+ _v1$3.subVectors(this.a, this.b);
6545
6397
 
6546
- return this;
6398
+ return _v0$1.cross(_v1$3).length() * 0.5;
6547
6399
  }
6548
6400
 
6549
- setStyle(style) {
6550
- function handleAlpha(string) {
6551
- if (string === undefined) return;
6401
+ getMidpoint(target) {
6402
+ return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
6403
+ }
6552
6404
 
6553
- if (parseFloat(string) < 1) {
6554
- console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
6555
- }
6405
+ getNormal(target) {
6406
+ return Triangle.getNormal(this.a, this.b, this.c, target);
6407
+ }
6408
+
6409
+ getPlane(target) {
6410
+ return target.setFromCoplanarPoints(this.a, this.b, this.c);
6411
+ }
6412
+
6413
+ getBarycoord(point, target) {
6414
+ return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
6415
+ }
6416
+
6417
+ getUV(point, uv1, uv2, uv3, target) {
6418
+ return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
6419
+ }
6420
+
6421
+ containsPoint(point) {
6422
+ return Triangle.containsPoint(point, this.a, this.b, this.c);
6423
+ }
6424
+
6425
+ isFrontFacing(direction) {
6426
+ return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
6427
+ }
6428
+
6429
+ intersectsBox(box) {
6430
+ return box.intersectsTriangle(this);
6431
+ }
6432
+
6433
+ closestPointToPoint(p, target) {
6434
+ const a = this.a,
6435
+ b = this.b,
6436
+ c = this.c;
6437
+ let v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
6438
+ // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
6439
+ // under the accompanying license; see chapter 5.1.5 for detailed explanation.
6440
+ // basically, we're distinguishing which of the voronoi regions of the triangle
6441
+ // the point lies in with the minimum amount of redundant computation.
6442
+
6443
+ _vab.subVectors(b, a);
6444
+
6445
+ _vac.subVectors(c, a);
6446
+
6447
+ _vap.subVectors(p, a);
6448
+
6449
+ const d1 = _vab.dot(_vap);
6450
+
6451
+ const d2 = _vac.dot(_vap);
6452
+
6453
+ if (d1 <= 0 && d2 <= 0) {
6454
+ // vertex region of A; barycentric coords (1, 0, 0)
6455
+ return target.copy(a);
6556
6456
  }
6557
6457
 
6558
- let m;
6458
+ _vbp.subVectors(p, b);
6559
6459
 
6560
- if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
6561
- // rgb / hsl
6562
- let color;
6563
- const name = m[1];
6564
- const components = m[2];
6460
+ const d3 = _vab.dot(_vbp);
6565
6461
 
6566
- switch (name) {
6567
- case 'rgb':
6568
- case 'rgba':
6569
- if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
6570
- // rgb(255,0,0) rgba(255,0,0,0.5)
6571
- this.r = Math.min(255, parseInt(color[1], 10)) / 255;
6572
- this.g = Math.min(255, parseInt(color[2], 10)) / 255;
6573
- this.b = Math.min(255, parseInt(color[3], 10)) / 255;
6574
- handleAlpha(color[4]);
6575
- return this;
6576
- }
6462
+ const d4 = _vac.dot(_vbp);
6577
6463
 
6578
- if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
6579
- // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
6580
- this.r = Math.min(100, parseInt(color[1], 10)) / 100;
6581
- this.g = Math.min(100, parseInt(color[2], 10)) / 100;
6582
- this.b = Math.min(100, parseInt(color[3], 10)) / 100;
6583
- handleAlpha(color[4]);
6584
- return this;
6585
- }
6464
+ if (d3 >= 0 && d4 <= d3) {
6465
+ // vertex region of B; barycentric coords (0, 1, 0)
6466
+ return target.copy(b);
6467
+ }
6586
6468
 
6587
- break;
6469
+ const vc = d1 * d4 - d3 * d2;
6588
6470
 
6589
- case 'hsl':
6590
- case 'hsla':
6591
- if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
6592
- // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
6593
- const h = parseFloat(color[1]) / 360;
6594
- const s = parseInt(color[2], 10) / 100;
6595
- const l = parseInt(color[3], 10) / 100;
6596
- handleAlpha(color[4]);
6597
- return this.setHSL(h, s, l);
6598
- }
6471
+ if (vc <= 0 && d1 >= 0 && d3 <= 0) {
6472
+ v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
6599
6473
 
6600
- break;
6601
- }
6602
- } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
6603
- // hex color
6604
- const hex = m[1];
6605
- const size = hex.length;
6474
+ return target.copy(a).addScaledVector(_vab, v);
6475
+ }
6606
6476
 
6607
- if (size === 3) {
6608
- // #ff0
6609
- this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
6610
- this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
6611
- this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
6612
- return this;
6613
- } else if (size === 6) {
6614
- // #ff0000
6615
- this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
6616
- this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
6617
- this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
6618
- return this;
6619
- }
6477
+ _vcp.subVectors(p, c);
6478
+
6479
+ const d5 = _vab.dot(_vcp);
6480
+
6481
+ const d6 = _vac.dot(_vcp);
6482
+
6483
+ if (d6 >= 0 && d5 <= d6) {
6484
+ // vertex region of C; barycentric coords (0, 0, 1)
6485
+ return target.copy(c);
6620
6486
  }
6621
6487
 
6622
- if (style && style.length > 0) {
6623
- return this.setColorName(style);
6488
+ const vb = d5 * d2 - d1 * d6;
6489
+
6490
+ if (vb <= 0 && d2 >= 0 && d6 <= 0) {
6491
+ w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
6492
+
6493
+ return target.copy(a).addScaledVector(_vac, w);
6624
6494
  }
6625
6495
 
6626
- return this;
6496
+ const va = d3 * d6 - d5 * d4;
6497
+
6498
+ if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
6499
+ _vbc.subVectors(c, b);
6500
+
6501
+ w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
6502
+
6503
+ return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
6504
+ } // face region
6505
+
6506
+
6507
+ const denom = 1 / (va + vb + vc); // u = va * denom
6508
+
6509
+ v = vb * denom;
6510
+ w = vc * denom;
6511
+ return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
6627
6512
  }
6628
6513
 
6629
- setColorName(style) {
6630
- // color keywords
6631
- const hex = _colorKeywords[style.toLowerCase()];
6514
+ equals(triangle) {
6515
+ return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
6516
+ }
6632
6517
 
6633
- if (hex !== undefined) {
6634
- // red
6635
- this.setHex(hex);
6636
- } else {
6637
- // unknown color
6638
- console.warn('THREE.Color: Unknown color ' + style);
6639
- }
6518
+ }
6640
6519
 
6641
- return this;
6520
+ let materialId = 0;
6521
+
6522
+ class Material extends EventDispatcher {
6523
+ constructor() {
6524
+ super();
6525
+ Object.defineProperty(this, 'id', {
6526
+ value: materialId++
6527
+ });
6528
+ this.uuid = generateUUID();
6529
+ this.name = '';
6530
+ this.type = 'Material';
6531
+ this.fog = true;
6532
+ this.blending = NormalBlending;
6533
+ this.side = FrontSide;
6534
+ this.vertexColors = false;
6535
+ this.opacity = 1;
6536
+ this.transparent = false;
6537
+ this.blendSrc = SrcAlphaFactor;
6538
+ this.blendDst = OneMinusSrcAlphaFactor;
6539
+ this.blendEquation = AddEquation;
6540
+ this.blendSrcAlpha = null;
6541
+ this.blendDstAlpha = null;
6542
+ this.blendEquationAlpha = null;
6543
+ this.depthFunc = LessEqualDepth;
6544
+ this.depthTest = true;
6545
+ this.depthWrite = true;
6546
+ this.stencilWriteMask = 0xff;
6547
+ this.stencilFunc = AlwaysStencilFunc;
6548
+ this.stencilRef = 0;
6549
+ this.stencilFuncMask = 0xff;
6550
+ this.stencilFail = KeepStencilOp;
6551
+ this.stencilZFail = KeepStencilOp;
6552
+ this.stencilZPass = KeepStencilOp;
6553
+ this.stencilWrite = false;
6554
+ this.clippingPlanes = null;
6555
+ this.clipIntersection = false;
6556
+ this.clipShadows = false;
6557
+ this.shadowSide = null;
6558
+ this.colorWrite = true;
6559
+ this.alphaWrite = true;
6560
+ this.precision = null; // override the renderer's default precision for this material
6561
+
6562
+ this.polygonOffset = false;
6563
+ this.polygonOffsetFactor = 0;
6564
+ this.polygonOffsetUnits = 0;
6565
+ this.dithering = false;
6566
+ this.alphaToCoverage = false;
6567
+ this.premultipliedAlpha = false;
6568
+ this.visible = true;
6569
+ this.toneMapped = true;
6570
+ this.userData = {};
6571
+ this.version = 0;
6572
+ this._alphaTest = 0;
6642
6573
  }
6643
6574
 
6644
- clone() {
6645
- return new this.constructor(this.r, this.g, this.b);
6575
+ get alphaTest() {
6576
+ return this._alphaTest;
6646
6577
  }
6647
6578
 
6648
- copy(color) {
6649
- this.r = color.r;
6650
- this.g = color.g;
6651
- this.b = color.b;
6652
- return this;
6579
+ set alphaTest(value) {
6580
+ if (this._alphaTest > 0 !== value > 0) {
6581
+ this.version++;
6582
+ }
6583
+
6584
+ this._alphaTest = value;
6653
6585
  }
6654
6586
 
6655
- copySRGBToLinear(color) {
6656
- this.r = SRGBToLinear(color.r);
6657
- this.g = SRGBToLinear(color.g);
6658
- this.b = SRGBToLinear(color.b);
6659
- return this;
6587
+ onBuild() {}
6588
+
6589
+ onBeforeRender() {}
6590
+
6591
+ onBeforeCompile() {}
6592
+
6593
+ customProgramCacheKey() {
6594
+ return this.onBeforeCompile.toString();
6660
6595
  }
6661
6596
 
6662
- copyLinearToSRGB(color) {
6663
- this.r = LinearToSRGB(color.r);
6664
- this.g = LinearToSRGB(color.g);
6665
- this.b = LinearToSRGB(color.b);
6666
- return this;
6597
+ setValues(values) {
6598
+ if (values === undefined) return;
6599
+
6600
+ for (const key in values) {
6601
+ const newValue = values[key];
6602
+
6603
+ if (newValue === undefined) {
6604
+ console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
6605
+ continue;
6606
+ } // for backward compatability if shading is set in the constructor
6607
+
6608
+
6609
+ if (key === 'shading') {
6610
+ console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
6611
+ this.flatShading = newValue === FlatShading ? true : false;
6612
+ continue;
6613
+ }
6614
+
6615
+ const currentValue = this[key];
6616
+
6617
+ if (currentValue === undefined) {
6618
+ console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
6619
+ continue;
6620
+ }
6621
+
6622
+ if (currentValue && currentValue.isColor) {
6623
+ currentValue.set(newValue);
6624
+ } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
6625
+ currentValue.copy(newValue);
6626
+ } else {
6627
+ this[key] = newValue;
6628
+ }
6629
+ }
6667
6630
  }
6668
6631
 
6669
- convertSRGBToLinear() {
6670
- this.copySRGBToLinear(this);
6671
- return this;
6672
- }
6632
+ toJSON(meta) {
6633
+ const isRoot = meta === undefined || typeof meta === 'string';
6673
6634
 
6674
- convertLinearToSRGB() {
6675
- this.copyLinearToSRGB(this);
6676
- return this;
6677
- }
6635
+ if (isRoot) {
6636
+ meta = {
6637
+ textures: {},
6638
+ images: {}
6639
+ };
6640
+ }
6678
6641
 
6679
- getHex() {
6680
- return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
6681
- }
6642
+ const data = {
6643
+ metadata: {
6644
+ version: 4.5,
6645
+ type: 'Material',
6646
+ generator: 'Material.toJSON'
6647
+ }
6648
+ }; // standard Material serialization
6682
6649
 
6683
- getHexString() {
6684
- return ('000000' + this.getHex().toString(16)).slice(-6);
6685
- }
6650
+ data.uuid = this.uuid;
6651
+ data.type = this.type;
6652
+ if (this.name !== '') data.name = this.name;
6653
+ if (this.color && this.color.isColor) data.color = this.color.getHex();
6654
+ if (this.roughness !== undefined) data.roughness = this.roughness;
6655
+ if (this.metalness !== undefined) data.metalness = this.metalness;
6656
+ if (this.sheen !== undefined) data.sheen = this.sheen;
6657
+ if (this.sheenColor && this.sheenColor.isColor) data.sheenColor = this.sheenColor.getHex();
6658
+ if (this.sheenRoughness !== undefined) data.sheenRoughness = this.sheenRoughness;
6659
+ if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
6660
+ if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
6661
+ if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
6662
+ if (this.specularIntensity !== undefined) data.specularIntensity = this.specularIntensity;
6663
+ if (this.specularColor && this.specularColor.isColor) data.specularColor = this.specularColor.getHex();
6664
+ if (this.shininess !== undefined) data.shininess = this.shininess;
6665
+ if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
6666
+ if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
6686
6667
 
6687
- getHSL(target) {
6688
- // h,s,l ranges are in 0.0 - 1.0
6689
- const r = this.r,
6690
- g = this.g,
6691
- b = this.b;
6692
- const max = Math.max(r, g, b);
6693
- const min = Math.min(r, g, b);
6694
- let hue, saturation;
6695
- const lightness = (min + max) / 2.0;
6668
+ if (this.clearcoatMap && this.clearcoatMap.isTexture) {
6669
+ data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
6670
+ }
6696
6671
 
6697
- if (min === max) {
6698
- hue = 0;
6699
- saturation = 0;
6700
- } else {
6701
- const delta = max - min;
6702
- saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
6672
+ if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
6673
+ data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
6674
+ }
6703
6675
 
6704
- switch (max) {
6705
- case r:
6706
- hue = (g - b) / delta + (g < b ? 6 : 0);
6707
- break;
6676
+ if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
6677
+ data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
6678
+ data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
6679
+ }
6708
6680
 
6709
- case g:
6710
- hue = (b - r) / delta + 2;
6711
- break;
6681
+ if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
6682
+ if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
6683
+ if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
6712
6684
 
6713
- case b:
6714
- hue = (r - g) / delta + 4;
6715
- break;
6716
- }
6685
+ if (this.lightMap && this.lightMap.isTexture) {
6686
+ data.lightMap = this.lightMap.toJSON(meta).uuid;
6687
+ data.lightMapIntensity = this.lightMapIntensity;
6688
+ }
6717
6689
 
6718
- hue /= 6;
6690
+ if (this.aoMap && this.aoMap.isTexture) {
6691
+ data.aoMap = this.aoMap.toJSON(meta).uuid;
6692
+ data.aoMapIntensity = this.aoMapIntensity;
6719
6693
  }
6720
6694
 
6721
- target.h = hue;
6722
- target.s = saturation;
6723
- target.l = lightness;
6724
- return target;
6725
- }
6695
+ if (this.bumpMap && this.bumpMap.isTexture) {
6696
+ data.bumpMap = this.bumpMap.toJSON(meta).uuid;
6697
+ data.bumpScale = this.bumpScale;
6698
+ }
6726
6699
 
6727
- getStyle() {
6728
- return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
6729
- }
6700
+ if (this.normalMap && this.normalMap.isTexture) {
6701
+ data.normalMap = this.normalMap.toJSON(meta).uuid;
6702
+ data.normalMapType = this.normalMapType;
6703
+ data.normalScale = this.normalScale.toArray();
6704
+ }
6730
6705
 
6731
- offsetHSL(h, s, l) {
6732
- this.getHSL(_hslA);
6733
- _hslA.h += h;
6734
- _hslA.s += s;
6735
- _hslA.l += l;
6736
- this.setHSL(_hslA.h, _hslA.s, _hslA.l);
6737
- return this;
6738
- }
6706
+ if (this.displacementMap && this.displacementMap.isTexture) {
6707
+ data.displacementMap = this.displacementMap.toJSON(meta).uuid;
6708
+ data.displacementScale = this.displacementScale;
6709
+ data.displacementBias = this.displacementBias;
6710
+ }
6739
6711
 
6740
- add(color) {
6741
- this.r += color.r;
6742
- this.g += color.g;
6743
- this.b += color.b;
6744
- return this;
6745
- }
6712
+ if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
6713
+ if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
6714
+ if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
6715
+ if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
6716
+ if (this.specularIntensityMap && this.specularIntensityMap.isTexture) data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid;
6717
+ if (this.specularColorMap && this.specularColorMap.isTexture) data.specularColorMap = this.specularColorMap.toJSON(meta).uuid;
6746
6718
 
6747
- addColors(color1, color2) {
6748
- this.r = color1.r + color2.r;
6749
- this.g = color1.g + color2.g;
6750
- this.b = color1.b + color2.b;
6751
- return this;
6752
- }
6719
+ if (this.envMap && this.envMap.isTexture) {
6720
+ data.envMap = this.envMap.toJSON(meta).uuid;
6721
+ if (this.combine !== undefined) data.combine = this.combine;
6722
+ }
6753
6723
 
6754
- addScalar(s) {
6755
- this.r += s;
6756
- this.g += s;
6757
- this.b += s;
6758
- return this;
6759
- }
6724
+ if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
6725
+ if (this.reflectivity !== undefined) data.reflectivity = this.reflectivity;
6726
+ if (this.refractionRatio !== undefined) data.refractionRatio = this.refractionRatio;
6760
6727
 
6761
- sub(color) {
6762
- this.r = Math.max(0, this.r - color.r);
6763
- this.g = Math.max(0, this.g - color.g);
6764
- this.b = Math.max(0, this.b - color.b);
6765
- return this;
6766
- }
6728
+ if (this.gradientMap && this.gradientMap.isTexture) {
6729
+ data.gradientMap = this.gradientMap.toJSON(meta).uuid;
6730
+ }
6767
6731
 
6768
- multiply(color) {
6769
- this.r *= color.r;
6770
- this.g *= color.g;
6771
- this.b *= color.b;
6772
- return this;
6773
- }
6732
+ if (this.transmission !== undefined) data.transmission = this.transmission;
6733
+ if (this.transmissionMap && this.transmissionMap.isTexture) data.transmissionMap = this.transmissionMap.toJSON(meta).uuid;
6734
+ if (this.thickness !== undefined) data.thickness = this.thickness;
6735
+ if (this.thicknessMap && this.thicknessMap.isTexture) data.thicknessMap = this.thicknessMap.toJSON(meta).uuid;
6736
+ if (this.attenuationDistance !== undefined) data.attenuationDistance = this.attenuationDistance;
6737
+ if (this.attenuationColor !== undefined) data.attenuationColor = this.attenuationColor.getHex();
6738
+ if (this.size !== undefined) data.size = this.size;
6739
+ if (this.shadowSide !== null) data.shadowSide = this.shadowSide;
6740
+ if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
6741
+ if (this.blending !== NormalBlending) data.blending = this.blending;
6742
+ if (this.side !== FrontSide) data.side = this.side;
6743
+ if (this.vertexColors) data.vertexColors = true;
6744
+ if (this.opacity < 1) data.opacity = this.opacity;
6745
+ if (this.transparent === true) data.transparent = this.transparent;
6746
+ data.depthFunc = this.depthFunc;
6747
+ data.depthTest = this.depthTest;
6748
+ data.depthWrite = this.depthWrite;
6749
+ data.colorWrite = this.colorWrite;
6750
+ data.alphaWrite = this.alphaWrite;
6751
+ data.stencilWrite = this.stencilWrite;
6752
+ data.stencilWriteMask = this.stencilWriteMask;
6753
+ data.stencilFunc = this.stencilFunc;
6754
+ data.stencilRef = this.stencilRef;
6755
+ data.stencilFuncMask = this.stencilFuncMask;
6756
+ data.stencilFail = this.stencilFail;
6757
+ data.stencilZFail = this.stencilZFail;
6758
+ data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
6774
6759
 
6775
- multiplyScalar(s) {
6776
- this.r *= s;
6777
- this.g *= s;
6778
- this.b *= s;
6779
- return this;
6780
- }
6760
+ if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
6761
+ if (this.polygonOffset === true) data.polygonOffset = true;
6762
+ if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
6763
+ if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
6764
+ if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
6765
+ if (this.dashSize !== undefined) data.dashSize = this.dashSize;
6766
+ if (this.gapSize !== undefined) data.gapSize = this.gapSize;
6767
+ if (this.scale !== undefined) data.scale = this.scale;
6768
+ if (this.dithering === true) data.dithering = true;
6769
+ if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
6770
+ if (this.alphaToCoverage === true) data.alphaToCoverage = this.alphaToCoverage;
6771
+ if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
6772
+ if (this.wireframe === true) data.wireframe = this.wireframe;
6773
+ if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
6774
+ if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
6775
+ if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
6776
+ if (this.flatShading === true) data.flatShading = this.flatShading;
6777
+ if (this.visible === false) data.visible = false;
6778
+ if (this.toneMapped === false) data.toneMapped = false;
6779
+ if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
6781
6780
 
6782
- lerp(color, alpha) {
6783
- this.r += (color.r - this.r) * alpha;
6784
- this.g += (color.g - this.g) * alpha;
6785
- this.b += (color.b - this.b) * alpha;
6786
- return this;
6787
- }
6781
+ function extractFromCache(cache) {
6782
+ const values = [];
6788
6783
 
6789
- lerpColors(color1, color2, alpha) {
6790
- this.r = color1.r + (color2.r - color1.r) * alpha;
6791
- this.g = color1.g + (color2.g - color1.g) * alpha;
6792
- this.b = color1.b + (color2.b - color1.b) * alpha;
6793
- return this;
6794
- }
6784
+ for (const key in cache) {
6785
+ const data = cache[key];
6786
+ delete data.metadata;
6787
+ values.push(data);
6788
+ }
6795
6789
 
6796
- lerpHSL(color, alpha) {
6797
- this.getHSL(_hslA);
6798
- color.getHSL(_hslB);
6799
- const h = lerp(_hslA.h, _hslB.h, alpha);
6800
- const s = lerp(_hslA.s, _hslB.s, alpha);
6801
- const l = lerp(_hslA.l, _hslB.l, alpha);
6802
- this.setHSL(h, s, l);
6803
- return this;
6804
- }
6790
+ return values;
6791
+ }
6805
6792
 
6806
- equals(c) {
6807
- return c.r === this.r && c.g === this.g && c.b === this.b;
6808
- }
6793
+ if (isRoot) {
6794
+ const textures = extractFromCache(meta.textures);
6795
+ const images = extractFromCache(meta.images);
6796
+ if (textures.length > 0) data.textures = textures;
6797
+ if (images.length > 0) data.images = images;
6798
+ }
6809
6799
 
6810
- fromArray(array, offset = 0) {
6811
- this.r = array[offset];
6812
- this.g = array[offset + 1];
6813
- this.b = array[offset + 2];
6814
- return this;
6800
+ return data;
6815
6801
  }
6816
6802
 
6817
- toArray(array = [], offset = 0) {
6818
- array[offset] = this.r;
6819
- array[offset + 1] = this.g;
6820
- array[offset + 2] = this.b;
6821
- return array;
6803
+ clone() {
6804
+ return new this.constructor().copy(this);
6822
6805
  }
6823
6806
 
6824
- fromBufferAttribute(attribute, index) {
6825
- this.r = attribute.getX(index);
6826
- this.g = attribute.getY(index);
6827
- this.b = attribute.getZ(index);
6807
+ copy(source) {
6808
+ this.name = source.name;
6809
+ this.fog = source.fog;
6810
+ this.blending = source.blending;
6811
+ this.side = source.side;
6812
+ this.vertexColors = source.vertexColors;
6813
+ this.opacity = source.opacity;
6814
+ this.transparent = source.transparent;
6815
+ this.blendSrc = source.blendSrc;
6816
+ this.blendDst = source.blendDst;
6817
+ this.blendEquation = source.blendEquation;
6818
+ this.blendSrcAlpha = source.blendSrcAlpha;
6819
+ this.blendDstAlpha = source.blendDstAlpha;
6820
+ this.blendEquationAlpha = source.blendEquationAlpha;
6821
+ this.depthFunc = source.depthFunc;
6822
+ this.depthTest = source.depthTest;
6823
+ this.depthWrite = source.depthWrite;
6824
+ this.stencilWriteMask = source.stencilWriteMask;
6825
+ this.stencilFunc = source.stencilFunc;
6826
+ this.stencilRef = source.stencilRef;
6827
+ this.stencilFuncMask = source.stencilFuncMask;
6828
+ this.stencilFail = source.stencilFail;
6829
+ this.stencilZFail = source.stencilZFail;
6830
+ this.stencilZPass = source.stencilZPass;
6831
+ this.stencilWrite = source.stencilWrite;
6832
+ const srcPlanes = source.clippingPlanes;
6833
+ let dstPlanes = null;
6828
6834
 
6829
- if (attribute.normalized === true) {
6830
- // assuming Uint8Array
6831
- this.r /= 255;
6832
- this.g /= 255;
6833
- this.b /= 255;
6835
+ if (srcPlanes !== null) {
6836
+ const n = srcPlanes.length;
6837
+ dstPlanes = new Array(n);
6838
+
6839
+ for (let i = 0; i !== n; ++i) {
6840
+ dstPlanes[i] = srcPlanes[i].clone();
6841
+ }
6834
6842
  }
6835
6843
 
6844
+ this.clippingPlanes = dstPlanes;
6845
+ this.clipIntersection = source.clipIntersection;
6846
+ this.clipShadows = source.clipShadows;
6847
+ this.shadowSide = source.shadowSide;
6848
+ this.colorWrite = source.colorWrite;
6849
+ this.alphaWrite = source.alphaWrite;
6850
+ this.precision = source.precision;
6851
+ this.polygonOffset = source.polygonOffset;
6852
+ this.polygonOffsetFactor = source.polygonOffsetFactor;
6853
+ this.polygonOffsetUnits = source.polygonOffsetUnits;
6854
+ this.dithering = source.dithering;
6855
+ this.alphaTest = source.alphaTest;
6856
+ this.alphaToCoverage = source.alphaToCoverage;
6857
+ this.premultipliedAlpha = source.premultipliedAlpha;
6858
+ this.visible = source.visible;
6859
+ this.toneMapped = source.toneMapped;
6860
+ this.userData = JSON.parse(JSON.stringify(source.userData));
6836
6861
  return this;
6837
6862
  }
6838
6863
 
6839
- toJSON() {
6840
- return this.getHex();
6864
+ dispose() {
6865
+ this.dispatchEvent({
6866
+ type: 'dispose'
6867
+ });
6868
+ }
6869
+
6870
+ set needsUpdate(value) {
6871
+ if (value === true) this.version++;
6841
6872
  }
6842
6873
 
6843
6874
  }
6844
6875
 
6845
- Color.NAMES = _colorKeywords;
6846
- Color.prototype.isColor = true;
6847
- Color.prototype.r = 1;
6848
- Color.prototype.g = 1;
6849
- Color.prototype.b = 1;
6876
+ Material.prototype.isMaterial = true;
6850
6877
 
6851
6878
  /**
6852
6879
  * parameters = {
@@ -9011,6 +9038,7 @@
9011
9038
  renderer.render(scene, cameraNZ);
9012
9039
  renderer.setRenderTarget(currentRenderTarget);
9013
9040
  renderer.xr.enabled = currentXrEnabled;
9041
+ renderTarget.texture.needsPMREMUpdate = true;
9014
9042
  }
9015
9043
 
9016
9044
  }
@@ -9054,7 +9082,6 @@
9054
9082
  this.texture.isRenderTargetTexture = true;
9055
9083
  this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
9056
9084
  this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
9057
- this.texture._needsFlipEnvMap = false;
9058
9085
  }
9059
9086
 
9060
9087
  fromEquirectangularTexture(renderer, texture) {
@@ -9672,15 +9699,15 @@
9672
9699
 
9673
9700
  var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
9674
9701
 
9675
- var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
9702
+ var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
9676
9703
 
9677
9704
  var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
9678
9705
 
9679
9706
  var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
9680
9707
 
9681
- var encodings_pars_fragment = "vec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}";
9708
+ var encodings_pars_fragment = "vec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}";
9682
9709
 
9683
- var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
9710
+ var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
9684
9711
 
9685
9712
  var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
9686
9713
 
@@ -9700,7 +9727,7 @@
9700
9727
 
9701
9728
  var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
9702
9729
 
9703
- var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tlightMapIrradiance *= PI;\n\t#endif\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif";
9730
+ var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tlightMapIrradiance *= PI;\n\t#endif\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif";
9704
9731
 
9705
9732
  var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
9706
9733
 
@@ -9718,13 +9745,13 @@
9718
9745
 
9719
9746
  var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
9720
9747
 
9721
- var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\t#ifdef SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULARINTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n\t\t#endif\n\t\t#ifdef USE_SPECULARCOLORMAP\n\t\t\tspecularColorFactor *= specularColorMapTexelToLinear( texture2D( specularColorMap, vUv ) ).rgb;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tmaterial.sheenColor *= sheenColorMapTexelToLinear( texture2D( sheenColorMap, vUv ) ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;\n\t#endif\n#endif";
9748
+ var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\t#ifdef SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULARINTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n\t\t#endif\n\t\t#ifdef USE_SPECULARCOLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vUv ).rgb;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;\n\t#endif\n#endif";
9722
9749
 
9723
9750
  var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = vec3( 0.0 );\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\tvec3 FssEss = specularColor * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometry.normal, geometry.viewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tcomputeMultiscattering( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
9724
9751
 
9725
9752
  var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef USE_CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
9726
9753
 
9727
- var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometry.normal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";
9754
+ var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometry.normal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";
9728
9755
 
9729
9756
  var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
9730
9757
 
@@ -9736,11 +9763,11 @@
9736
9763
 
9737
9764
  var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
9738
9765
 
9739
- var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
9766
+ var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";
9740
9767
 
9741
9768
  var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
9742
9769
 
9743
- var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
9770
+ var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
9744
9771
 
9745
9772
  var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
9746
9773
 
@@ -9814,7 +9841,7 @@
9814
9841
 
9815
9842
  var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tfloat transmissionAlpha = 1.0;\n\tfloat transmissionFactor = transmission;\n\tfloat thicknessFactor = thickness;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\ttransmissionFactor *= texture2D( transmissionMap, vUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tthicknessFactor *= texture2D( thicknessMap, vUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmission = getIBLVolumeRefraction(\n\t\tn, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,\n\t\tattenuationColor, attenuationDistance );\n\ttotalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );\n\ttransmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );\n#endif";
9816
9843
 
9817
- var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tvec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( float roughness, float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {\n\t\tfloat framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\treturn texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#else\n\t\t\treturn texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#endif\n\t}\n\tvec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {\n\t\tif ( attenuationDistance == 0.0 ) {\n\t\t\treturn radiance;\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance * radiance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,\n\t\tvec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,\n\t\tvec3 attenuationColor, float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n\t}\n#endif";
9844
+ var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\treturn texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#else\n\t\t\treturn texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#endif\n\t}\n\tvec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( attenuationDistance == 0.0 ) {\n\t\t\treturn radiance;\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance * radiance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n\t}\n#endif";
9818
9845
 
9819
9846
  var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
9820
9847
 
@@ -9831,7 +9858,7 @@
9831
9858
  var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
9832
9859
 
9833
9860
  const vertex$g = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
9834
- const fragment$g = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
9861
+ const fragment$g = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tgl_FragColor = texture2D( t2D, vUv );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
9835
9862
 
9836
9863
  const vertex$f = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
9837
9864
  const fragment$f = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
@@ -9843,19 +9870,19 @@
9843
9870
  const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
9844
9871
 
9845
9872
  const vertex$c = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
9846
- const fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
9873
+ const fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
9847
9874
 
9848
9875
  const vertex$b = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
9849
9876
  const fragment$b = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
9850
9877
 
9851
9878
  const vertex$a = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
9852
- const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
9879
+ const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
9853
9880
 
9854
9881
  const vertex$9 = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
9855
9882
  const fragment$9 = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
9856
9883
 
9857
9884
  const vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
9858
- const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
9885
+ const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
9859
9886
 
9860
9887
  const vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
9861
9888
  const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
@@ -10503,7 +10530,7 @@
10503
10530
  value: null
10504
10531
  },
10505
10532
  sheenRoughness: {
10506
- value: 0
10533
+ value: 1
10507
10534
  },
10508
10535
  sheenRoughnessMap: {
10509
10536
  value: null
@@ -10533,7 +10560,7 @@
10533
10560
  value: new Color(0x000000)
10534
10561
  },
10535
10562
  specularIntensity: {
10536
- value: 0
10563
+ value: 1
10537
10564
  },
10538
10565
  specularIntensityMap: {
10539
10566
  value: null
@@ -11339,11 +11366,9 @@
11339
11366
  const image = texture.image;
11340
11367
 
11341
11368
  if (image && image.height > 0) {
11342
- const currentRenderTarget = renderer.getRenderTarget();
11343
11369
  const renderTarget = new WebGLCubeRenderTarget(image.height / 2);
11344
11370
  renderTarget.fromEquirectangularTexture(renderer, texture);
11345
11371
  cubemaps.set(texture, renderTarget);
11346
- renderer.setRenderTarget(currentRenderTarget);
11347
11372
  texture.addEventListener('dispose', onTextureDispose);
11348
11373
  return mapTextureMapping(renderTarget.texture, texture.mapping);
11349
11374
  } else {
@@ -11499,10 +11524,6 @@
11499
11524
  // samples and exit early, but not recompile the shader.
11500
11525
 
11501
11526
  const MAX_SAMPLES = 20;
11502
- const ENCODINGS = {
11503
- [LinearEncoding]: 0,
11504
- [sRGBEncoding]: 1
11505
- };
11506
11527
 
11507
11528
  const _flatCamera = /*@__PURE__*/new OrthographicCamera();
11508
11529
 
@@ -11579,8 +11600,8 @@
11579
11600
  */
11580
11601
 
11581
11602
 
11582
- fromEquirectangular(equirectangular) {
11583
- return this._fromTexture(equirectangular);
11603
+ fromEquirectangular(equirectangular, renderTarget = null) {
11604
+ return this._fromTexture(equirectangular, renderTarget);
11584
11605
  }
11585
11606
  /**
11586
11607
  * Generates a PMREM from an cubemap texture, which can be either LDR
@@ -11589,8 +11610,8 @@
11589
11610
  */
11590
11611
 
11591
11612
 
11592
- fromCubemap(cubemap) {
11593
- return this._fromTexture(cubemap);
11613
+ fromCubemap(cubemap, renderTarget = null) {
11614
+ return this._fromTexture(cubemap, renderTarget);
11594
11615
  }
11595
11616
  /**
11596
11617
  * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
@@ -11628,6 +11649,7 @@
11628
11649
  dispose() {
11629
11650
  this._blurMaterial.dispose();
11630
11651
 
11652
+ if (this._pingPongRenderTarget !== null) this._pingPongRenderTarget.dispose();
11631
11653
  if (this._cubemapShader !== null) this._cubemapShader.dispose();
11632
11654
  if (this._equirectShader !== null) this._equirectShader.dispose();
11633
11655
 
@@ -11638,8 +11660,6 @@
11638
11660
 
11639
11661
 
11640
11662
  _cleanup(outputTarget) {
11641
- this._pingPongRenderTarget.dispose();
11642
-
11643
11663
  this._renderer.setRenderTarget(_oldTarget);
11644
11664
 
11645
11665
  outputTarget.scissorTest = false;
@@ -11647,10 +11667,10 @@
11647
11667
  _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
11648
11668
  }
11649
11669
 
11650
- _fromTexture(texture) {
11670
+ _fromTexture(texture, renderTarget) {
11651
11671
  _oldTarget = this._renderer.getRenderTarget();
11652
11672
 
11653
- const cubeUVRenderTarget = this._allocateTargets(texture);
11673
+ const cubeUVRenderTarget = renderTarget || this._allocateTargets(texture);
11654
11674
 
11655
11675
  this._textureToCubeUV(texture, cubeUVRenderTarget);
11656
11676
 
@@ -11676,7 +11696,11 @@
11676
11696
  const cubeUVRenderTarget = _createRenderTarget(params);
11677
11697
 
11678
11698
  cubeUVRenderTarget.depthBuffer = texture ? false : true;
11679
- this._pingPongRenderTarget = _createRenderTarget(params);
11699
+
11700
+ if (this._pingPongRenderTarget === null) {
11701
+ this._pingPongRenderTarget = _createRenderTarget(params);
11702
+ }
11703
+
11680
11704
  return cubeUVRenderTarget;
11681
11705
  }
11682
11706
 
@@ -11722,10 +11746,10 @@
11722
11746
  for (let i = 0; i < 6; i++) {
11723
11747
  const col = i % 3;
11724
11748
 
11725
- if (col == 0) {
11749
+ if (col === 0) {
11726
11750
  cubeCamera.up.set(0, upSign[i], 0);
11727
11751
  cubeCamera.lookAt(forwardSign[i], 0, 0);
11728
- } else if (col == 1) {
11752
+ } else if (col === 1) {
11729
11753
  cubeCamera.up.set(0, 0, upSign[i]);
11730
11754
  cubeCamera.lookAt(0, forwardSign[i], 0);
11731
11755
  } else {
@@ -11751,24 +11775,18 @@
11751
11775
  scene.background = background;
11752
11776
  }
11753
11777
 
11754
- _setEncoding(uniform, texture) {
11755
- if (this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding) {
11756
- uniform.value = ENCODINGS[LinearEncoding];
11757
- } else {
11758
- uniform.value = ENCODINGS[texture.encoding];
11759
- }
11760
- }
11761
-
11762
11778
  _textureToCubeUV(texture, cubeUVRenderTarget) {
11763
11779
  const renderer = this._renderer;
11764
11780
  const isCubeTexture = texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping;
11765
11781
 
11766
11782
  if (isCubeTexture) {
11767
- if (this._cubemapShader == null) {
11783
+ if (this._cubemapShader === null) {
11768
11784
  this._cubemapShader = _getCubemapShader();
11769
11785
  }
11786
+
11787
+ this._cubemapShader.uniforms.flipEnvMap.value = texture.isRenderTargetTexture === false ? -1 : 1;
11770
11788
  } else {
11771
- if (this._equirectShader == null) {
11789
+ if (this._equirectShader === null) {
11772
11790
  this._equirectShader = _getEquirectShader();
11773
11791
  }
11774
11792
  }
@@ -11782,8 +11800,6 @@
11782
11800
  uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
11783
11801
  }
11784
11802
 
11785
- this._setEncoding(uniforms['inputEncoding'], texture);
11786
-
11787
11803
  _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
11788
11804
 
11789
11805
  renderer.setRenderTarget(cubeUVRenderTarget);
@@ -11850,7 +11866,7 @@
11850
11866
  const weight = Math.exp(-x * x / 2);
11851
11867
  weights.push(weight);
11852
11868
 
11853
- if (i == 0) {
11869
+ if (i === 0) {
11854
11870
  sum += weight;
11855
11871
  } else if (i < samples) {
11856
11872
  sum += 2 * weight;
@@ -11899,7 +11915,7 @@
11899
11915
 
11900
11916
  if (i > LOD_MAX - LOD_MIN) {
11901
11917
  sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
11902
- } else if (i == 0) {
11918
+ } else if (i === 0) {
11903
11919
  sigma = 0;
11904
11920
  }
11905
11921
 
@@ -12009,8 +12025,6 @@
12009
12025
  uniform float mipInt;
12010
12026
  uniform vec3 poleAxis;
12011
12027
 
12012
- ${_getEncodings()}
12013
-
12014
12028
  #define ENVMAP_TYPE_CUBE_UV
12015
12029
  #include <cube_uv_reflection_fragment>
12016
12030
 
@@ -12074,9 +12088,6 @@
12074
12088
  },
12075
12089
  'texelSize': {
12076
12090
  value: texelSize
12077
- },
12078
- 'inputEncoding': {
12079
- value: ENCODINGS[LinearEncoding]
12080
12091
  }
12081
12092
  },
12082
12093
  vertexShader: _getCommonVertexShader(),
@@ -12092,8 +12103,6 @@
12092
12103
  uniform sampler2D envMap;
12093
12104
  uniform vec2 texelSize;
12094
12105
 
12095
- ${_getEncodings()}
12096
-
12097
12106
  #include <common>
12098
12107
 
12099
12108
  void main() {
@@ -12105,13 +12114,13 @@
12105
12114
 
12106
12115
  vec2 f = fract( uv / texelSize - 0.5 );
12107
12116
  uv -= f * texelSize;
12108
- vec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
12117
+ vec3 tl = texture2D ( envMap, uv ).rgb;
12109
12118
  uv.x += texelSize.x;
12110
- vec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
12119
+ vec3 tr = texture2D ( envMap, uv ).rgb;
12111
12120
  uv.y += texelSize.y;
12112
- vec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
12121
+ vec3 br = texture2D ( envMap, uv ).rgb;
12113
12122
  uv.x -= texelSize.x;
12114
- vec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
12123
+ vec3 bl = texture2D ( envMap, uv ).rgb;
12115
12124
 
12116
12125
  vec3 tm = mix( tl, tr, f.x );
12117
12126
  vec3 bm = mix( bl, br, f.x );
@@ -12133,8 +12142,8 @@
12133
12142
  'envMap': {
12134
12143
  value: null
12135
12144
  },
12136
- 'inputEncoding': {
12137
- value: ENCODINGS[LinearEncoding]
12145
+ 'flipEnvMap': {
12146
+ value: -1
12138
12147
  }
12139
12148
  },
12140
12149
  vertexShader: _getCommonVertexShader(),
@@ -12145,15 +12154,15 @@
12145
12154
  precision mediump float;
12146
12155
  precision mediump int;
12147
12156
 
12157
+ uniform float flipEnvMap;
12158
+
12148
12159
  varying vec3 vOutputDirection;
12149
12160
 
12150
12161
  uniform samplerCube envMap;
12151
12162
 
12152
- ${_getEncodings()}
12153
-
12154
12163
  void main() {
12155
12164
 
12156
- gl_FragColor = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) );
12165
+ gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
12157
12166
 
12158
12167
  }
12159
12168
  `,
@@ -12228,66 +12237,40 @@
12228
12237
  );
12229
12238
  }
12230
12239
 
12231
- function _getEncodings() {
12232
- return (
12233
- /* glsl */
12234
- `
12235
-
12236
- uniform int inputEncoding;
12237
-
12238
- #include <encodings_pars_fragment>
12239
-
12240
- vec4 inputTexelToLinear( vec4 value ) {
12241
-
12242
- if ( inputEncoding == 0 ) {
12243
-
12244
- return value;
12245
-
12246
- } else {
12247
-
12248
- return sRGBToLinear( value );
12249
-
12250
- }
12251
-
12252
- }
12253
-
12254
- vec4 envMapTexelToLinear( vec4 color ) {
12255
-
12256
- return inputTexelToLinear( color );
12257
-
12258
- }
12259
- `
12260
- );
12261
- }
12262
-
12263
12240
  function WebGLCubeUVMaps(renderer) {
12264
12241
  let cubeUVmaps = new WeakMap();
12265
12242
  let pmremGenerator = null;
12266
12243
 
12267
12244
  function get(texture) {
12268
- if (texture && texture.isTexture && texture.isRenderTargetTexture === false) {
12245
+ if (texture && texture.isTexture) {
12269
12246
  const mapping = texture.mapping;
12270
12247
  const isEquirectMap = mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping;
12271
- const isCubeMap = mapping === CubeReflectionMapping || mapping === CubeRefractionMapping;
12248
+ const isCubeMap = mapping === CubeReflectionMapping || mapping === CubeRefractionMapping; // equirect/cube map to cubeUV conversion
12272
12249
 
12273
12250
  if (isEquirectMap || isCubeMap) {
12274
- // equirect/cube map to cubeUV conversion
12275
- if (cubeUVmaps.has(texture)) {
12276
- return cubeUVmaps.get(texture).texture;
12251
+ if (texture.isRenderTargetTexture && texture.needsPMREMUpdate === true) {
12252
+ texture.needsPMREMUpdate = false;
12253
+ let renderTarget = cubeUVmaps.get(texture);
12254
+ if (pmremGenerator === null) pmremGenerator = new PMREMGenerator(renderer);
12255
+ renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture, renderTarget) : pmremGenerator.fromCubemap(texture, renderTarget);
12256
+ cubeUVmaps.set(texture, renderTarget);
12257
+ return renderTarget.texture;
12277
12258
  } else {
12278
- const image = texture.image;
12279
-
12280
- if (isEquirectMap && image && image.height > 0 || isCubeMap && image && isCubeTextureComplete(image)) {
12281
- const currentRenderTarget = renderer.getRenderTarget();
12282
- if (pmremGenerator === null) pmremGenerator = new PMREMGenerator(renderer);
12283
- const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture) : pmremGenerator.fromCubemap(texture);
12284
- cubeUVmaps.set(texture, renderTarget);
12285
- renderer.setRenderTarget(currentRenderTarget);
12286
- texture.addEventListener('dispose', onTextureDispose);
12287
- return renderTarget.texture;
12259
+ if (cubeUVmaps.has(texture)) {
12260
+ return cubeUVmaps.get(texture).texture;
12288
12261
  } else {
12289
- // image not yet ready. try the conversion next frame
12290
- return null;
12262
+ const image = texture.image;
12263
+
12264
+ if (isEquirectMap && image && image.height > 0 || isCubeMap && image && isCubeTextureComplete(image)) {
12265
+ if (pmremGenerator === null) pmremGenerator = new PMREMGenerator(renderer);
12266
+ const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture) : pmremGenerator.fromCubemap(texture);
12267
+ cubeUVmaps.set(texture, renderTarget);
12268
+ texture.addEventListener('dispose', onTextureDispose);
12269
+ return renderTarget.texture;
12270
+ } else {
12271
+ // image not yet ready. try the conversion next frame
12272
+ return null;
12273
+ }
12291
12274
  }
12292
12275
  }
12293
12276
  }
@@ -12748,6 +12731,14 @@
12748
12731
  size: new Vector2(width, height)
12749
12732
  };
12750
12733
  morphTextures.set(geometry, entry);
12734
+
12735
+ function disposeTexture() {
12736
+ texture.dispose();
12737
+ morphTextures.delete(geometry);
12738
+ geometry.removeEventListener('dispose', disposeTexture);
12739
+ }
12740
+
12741
+ geometry.addEventListener('dispose', disposeTexture);
12751
12742
  } //
12752
12743
 
12753
12744
 
@@ -13770,11 +13761,6 @@
13770
13761
  return type.toUpperCase() + '\n\n' + errors + '\n\n' + addLineNumbers(gl.getShaderSource(shader));
13771
13762
  }
13772
13763
 
13773
- function getTexelDecodingFunction(functionName, encoding) {
13774
- const components = getEncodingComponents(encoding);
13775
- return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
13776
- }
13777
-
13778
13764
  function getTexelEncodingFunction(functionName, encoding) {
13779
13765
  const components = getEncodingComponents(encoding);
13780
13766
  return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
@@ -14020,9 +14006,9 @@
14020
14006
  }
14021
14007
  } else {
14022
14008
  prefixVertex = [generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.instancing ? '#define USE_INSTANCING' : '', parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '', parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '', '#define MAX_BONES ' + parameters.maxBones, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.specularIntensityMap ? '#define USE_SPECULARINTENSITYMAP' : '', parameters.specularColorMap ? '#define USE_SPECULARCOLORMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.transmission ? '#define USE_TRANSMISSION' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '', parameters.sheenColorMap ? '#define USE_SHEENCOLORMAP' : '', parameters.sheenRoughnessMap ? '#define USE_SHEENROUGHNESSMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors ? '#define USE_COLOR' : '', parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.skinning ? '#define USE_SKINNING' : '', parameters.useVertexTexture ? '#define BONE_TEXTURE' : '', parameters.morphTargets ? '#define USE_MORPHTARGETS' : '', parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '', parameters.morphTargets && parameters.isWebGL2 ? '#define MORPHTARGETS_TEXTURE' : '', parameters.morphTargets && parameters.isWebGL2 ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', 'uniform mat4 modelMatrix;', 'uniform mat4 modelViewMatrix;', 'uniform mat4 projectionMatrix;', 'uniform mat4 viewMatrix;', 'uniform mat3 normalMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', '#ifdef USE_INSTANCING', ' attribute mat4 instanceMatrix;', '#endif', '#ifdef USE_INSTANCING_COLOR', ' attribute vec3 instanceColor;', '#endif', 'attribute vec3 position;', 'attribute vec3 normal;', 'attribute vec2 uv;', '#ifdef USE_TANGENT', ' attribute vec4 tangent;', '#endif', '#if defined( USE_COLOR_ALPHA )', ' attribute vec4 color;', '#elif defined( USE_COLOR )', ' attribute vec3 color;', '#endif', '#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )', ' attribute vec3 morphTarget0;', ' attribute vec3 morphTarget1;', ' attribute vec3 morphTarget2;', ' attribute vec3 morphTarget3;', ' #ifdef USE_MORPHNORMALS', ' attribute vec3 morphNormal0;', ' attribute vec3 morphNormal1;', ' attribute vec3 morphNormal2;', ' attribute vec3 morphNormal3;', ' #else', ' attribute vec3 morphTarget4;', ' attribute vec3 morphTarget5;', ' attribute vec3 morphTarget6;', ' attribute vec3 morphTarget7;', ' #endif', '#endif', '#ifdef USE_SKINNING', ' attribute vec4 skinIndex;', ' attribute vec4 skinWeight;', '#endif', '\n'].filter(filterEmptyLine).join('\n');
14023
- prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapTypeDefine : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.envMap ? '#define ' + envMapBlendingDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoat ? '#define USE_CLEARCOAT' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.specularIntensityMap ? '#define USE_SPECULARINTENSITYMAP' : '', parameters.specularColorMap ? '#define USE_SPECULARCOLORMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.alphaTest ? '#define USE_ALPHATEST' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.sheenColorMap ? '#define USE_SHEENCOLORMAP' : '', parameters.sheenRoughnessMap ? '#define USE_SHEENROUGHNESSMAP' : '', parameters.transmission ? '#define USE_TRANSMISSION' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '', parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '', 'uniform mat4 viewMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', parameters.toneMapping !== NoToneMapping ? '#define TONE_MAPPING' : '', parameters.toneMapping !== NoToneMapping ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
14024
- parameters.toneMapping !== NoToneMapping ? getToneMappingFunction('toneMapping', parameters.toneMapping) : '', parameters.dithering ? '#define DITHERING' : '', parameters.format === RGBFormat ? '#define OPAQUE' : '', ShaderChunk['encodings_pars_fragment'], // this code is required here because it is used by the various encoding/decoding function defined below
14025
- parameters.map ? getTexelDecodingFunction('mapTexelToLinear', parameters.mapEncoding) : '', parameters.matcap ? getTexelDecodingFunction('matcapTexelToLinear', parameters.matcapEncoding) : '', parameters.envMap ? getTexelDecodingFunction('envMapTexelToLinear', parameters.envMapEncoding) : '', parameters.emissiveMap ? getTexelDecodingFunction('emissiveMapTexelToLinear', parameters.emissiveMapEncoding) : '', parameters.specularColorMap ? getTexelDecodingFunction('specularColorMapTexelToLinear', parameters.specularColorMapEncoding) : '', parameters.sheenColorMap ? getTexelDecodingFunction('sheenColorMapTexelToLinear', parameters.sheenColorMapEncoding) : '', parameters.lightMap ? getTexelDecodingFunction('lightMapTexelToLinear', parameters.lightMapEncoding) : '', getTexelEncodingFunction('linearToOutputTexel', parameters.outputEncoding), parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', '\n'].filter(filterEmptyLine).join('\n');
14009
+ prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapTypeDefine : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.envMap ? '#define ' + envMapBlendingDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoat ? '#define USE_CLEARCOAT' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.specularIntensityMap ? '#define USE_SPECULARINTENSITYMAP' : '', parameters.specularColorMap ? '#define USE_SPECULARCOLORMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.alphaTest ? '#define USE_ALPHATEST' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.sheenColorMap ? '#define USE_SHEENCOLORMAP' : '', parameters.sheenRoughnessMap ? '#define USE_SHEENROUGHNESSMAP' : '', parameters.transmission ? '#define USE_TRANSMISSION' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '', parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '', parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '', 'uniform mat4 viewMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', parameters.toneMapping !== NoToneMapping ? '#define TONE_MAPPING' : '', parameters.toneMapping !== NoToneMapping ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
14010
+ parameters.toneMapping !== NoToneMapping ? getToneMappingFunction('toneMapping', parameters.toneMapping) : '', parameters.dithering ? '#define DITHERING' : '', parameters.alphaWrite ? '' : '#define OPAQUE', ShaderChunk['encodings_pars_fragment'], // this code is required here because it is used by the various encoding/decoding function defined below
14011
+ getTexelEncodingFunction('linearToOutputTexel', parameters.outputEncoding), parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', '\n'].filter(filterEmptyLine).join('\n');
14026
14012
  }
14027
14013
 
14028
14014
  vertexShader = resolveIncludes(vertexShader);
@@ -14282,25 +14268,6 @@
14282
14268
  }
14283
14269
  }
14284
14270
 
14285
- function getTextureEncodingFromMap(map) {
14286
- let encoding;
14287
-
14288
- if (map && map.isTexture) {
14289
- encoding = map.encoding;
14290
- } else if (map && map.isWebGLRenderTarget) {
14291
- console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
14292
- encoding = map.texture.encoding;
14293
- } else {
14294
- encoding = LinearEncoding;
14295
- }
14296
-
14297
- if (isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding) {
14298
- encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
14299
- }
14300
-
14301
- return encoding;
14302
- }
14303
-
14304
14271
  function getParameters(material, lights, shadows, scene, object) {
14305
14272
  const fog = scene.fog;
14306
14273
  const environment = material.isMeshStandardMaterial ? scene.environment : null;
@@ -14353,24 +14320,20 @@
14353
14320
  instancing: object.isInstancedMesh === true,
14354
14321
  instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
14355
14322
  supportsVertexTextures: vertexTextures,
14356
- outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
14323
+ outputEncoding: currentRenderTarget !== null ? currentRenderTarget.texture.encoding : renderer.outputEncoding,
14357
14324
  map: !!material.map,
14358
- mapEncoding: getTextureEncodingFromMap(material.map),
14359
14325
  matcap: !!material.matcap,
14360
- matcapEncoding: getTextureEncodingFromMap(material.matcap),
14361
14326
  envMap: !!envMap,
14362
14327
  envMapMode: envMap && envMap.mapping,
14363
- envMapEncoding: getTextureEncodingFromMap(envMap),
14364
14328
  envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
14365
14329
  lightMap: !!material.lightMap,
14366
- lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
14367
14330
  aoMap: !!material.aoMap,
14368
14331
  emissiveMap: !!material.emissiveMap,
14369
- emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
14370
14332
  bumpMap: !!material.bumpMap,
14371
14333
  normalMap: !!material.normalMap,
14372
14334
  objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
14373
14335
  tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
14336
+ decodeVideoTexture: !!material.map && material.map.isVideoTexture === true && material.map.encoding === sRGBEncoding,
14374
14337
  clearcoat: useClearcoat,
14375
14338
  clearcoatMap: useClearcoat && !!material.clearcoatMap,
14376
14339
  clearcoatRoughnessMap: useClearcoat && !!material.clearcoatRoughnessMap,
@@ -14381,13 +14344,12 @@
14381
14344
  specularMap: !!material.specularMap,
14382
14345
  specularIntensityMap: !!material.specularIntensityMap,
14383
14346
  specularColorMap: !!material.specularColorMap,
14384
- specularColorMapEncoding: getTextureEncodingFromMap(material.specularColorMap),
14385
14347
  alphaMap: !!material.alphaMap,
14386
14348
  alphaTest: useAlphaTest,
14349
+ alphaWrite: material.alphaWrite || material.transparent,
14387
14350
  gradientMap: !!material.gradientMap,
14388
14351
  sheen: material.sheen > 0,
14389
14352
  sheenColorMap: !!material.sheenColorMap,
14390
- sheenColorMapEncoding: getTextureEncodingFromMap(material.sheenColorMap),
14391
14353
  sheenRoughnessMap: !!material.sheenRoughnessMap,
14392
14354
  transmission: material.transmission > 0,
14393
14355
  transmissionMap: !!material.transmissionMap,
@@ -14420,7 +14382,6 @@
14420
14382
  numSpotLightShadows: lights.spotShadowMap.length,
14421
14383
  numClippingPlanes: clipping.numPlanes,
14422
14384
  numClipIntersection: clipping.numIntersection,
14423
- format: material.format,
14424
14385
  dithering: material.dithering,
14425
14386
  shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
14426
14387
  shadowMapType: renderer.shadowMap.type,
@@ -14473,12 +14434,7 @@
14473
14434
  function getProgramCacheKeyParameters(array, parameters) {
14474
14435
  array.push(parameters.precision);
14475
14436
  array.push(parameters.outputEncoding);
14476
- array.push(parameters.mapEncoding);
14477
- array.push(parameters.matcapEncoding);
14478
14437
  array.push(parameters.envMapMode);
14479
- array.push(parameters.envMapEncoding);
14480
- array.push(parameters.lightMapEncoding);
14481
- array.push(parameters.emissiveMapEncoding);
14482
14438
  array.push(parameters.combine);
14483
14439
  array.push(parameters.vertexUvs);
14484
14440
  array.push(parameters.fogExp2);
@@ -14497,9 +14453,7 @@
14497
14453
  array.push(parameters.toneMapping);
14498
14454
  array.push(parameters.numClippingPlanes);
14499
14455
  array.push(parameters.numClipIntersection);
14500
- array.push(parameters.format);
14501
- array.push(parameters.specularColorMapEncoding);
14502
- array.push(parameters.sheenColorMapEncoding);
14456
+ array.push(parameters.alphaWrite);
14503
14457
  }
14504
14458
 
14505
14459
  function getProgramCacheKeyBooleans(array, parameters) {
@@ -14563,6 +14517,7 @@
14563
14517
  if (parameters.sheen) _programLayers.enable(19);
14564
14518
  if (parameters.sheenColorMap) _programLayers.enable(20);
14565
14519
  if (parameters.sheenRoughnessMap) _programLayers.enable(21);
14520
+ if (parameters.decodeVideoTexture) _programLayers.enable(22);
14566
14521
  array.push(_programLayers.mask);
14567
14522
  }
14568
14523
 
@@ -15876,6 +15831,8 @@
15876
15831
  const stencilBuffer = new StencilBuffer();
15877
15832
  let enabledCapabilities = {};
15878
15833
  let currentBoundFramebuffers = {};
15834
+ let currentDrawbuffers = new WeakMap();
15835
+ let defaultDrawbuffers = [];
15879
15836
  let currentProgram = null;
15880
15837
  let currentBlendingEnabled = false;
15881
15838
  let currentBlending = null;
@@ -15976,6 +15933,51 @@
15976
15933
  return false;
15977
15934
  }
15978
15935
 
15936
+ function drawBuffers(renderTarget, framebuffer) {
15937
+ let drawBuffers = defaultDrawbuffers;
15938
+ let needsUpdate = false;
15939
+
15940
+ if (renderTarget) {
15941
+ drawBuffers = currentDrawbuffers.get(framebuffer);
15942
+
15943
+ if (drawBuffers === undefined) {
15944
+ drawBuffers = [];
15945
+ currentDrawbuffers.set(framebuffer, drawBuffers);
15946
+ }
15947
+
15948
+ if (renderTarget.isWebGLMultipleRenderTargets) {
15949
+ const textures = renderTarget.texture;
15950
+
15951
+ if (drawBuffers.length !== textures.length || drawBuffers[0] !== gl.COLOR_ATTACHMENT0) {
15952
+ for (let i = 0, il = textures.length; i < il; i++) {
15953
+ drawBuffers[i] = gl.COLOR_ATTACHMENT0 + i;
15954
+ }
15955
+
15956
+ drawBuffers.length = textures.length;
15957
+ needsUpdate = true;
15958
+ }
15959
+ } else {
15960
+ if (drawBuffers[0] !== gl.COLOR_ATTACHMENT0) {
15961
+ drawBuffers[0] = gl.COLOR_ATTACHMENT0;
15962
+ needsUpdate = true;
15963
+ }
15964
+ }
15965
+ } else {
15966
+ if (drawBuffers[0] !== gl.BACK) {
15967
+ drawBuffers[0] = gl.BACK;
15968
+ needsUpdate = true;
15969
+ }
15970
+ }
15971
+
15972
+ if (needsUpdate) {
15973
+ if (capabilities.isWebGL2) {
15974
+ gl.drawBuffers(drawBuffers);
15975
+ } else {
15976
+ extensions.get('WEBGL_draw_buffers').drawBuffersWEBGL(drawBuffers);
15977
+ }
15978
+ }
15979
+ }
15980
+
15979
15981
  function useProgram(program) {
15980
15982
  if (currentProgram !== program) {
15981
15983
  gl.useProgram(program);
@@ -16369,6 +16371,8 @@
16369
16371
  currentTextureSlot = null;
16370
16372
  currentBoundTextures = {};
16371
16373
  currentBoundFramebuffers = {};
16374
+ currentDrawbuffers = new WeakMap();
16375
+ defaultDrawbuffers = [];
16372
16376
  currentProgram = null;
16373
16377
  currentBlendingEnabled = false;
16374
16378
  currentBlending = null;
@@ -16400,6 +16404,7 @@
16400
16404
  enable: enable,
16401
16405
  disable: disable,
16402
16406
  bindFramebuffer: bindFramebuffer,
16407
+ drawBuffers: drawBuffers,
16403
16408
  useProgram: useProgram,
16404
16409
  setBlending: setBlending,
16405
16410
  setMaterial: setMaterial,
@@ -16505,7 +16510,7 @@
16505
16510
  _gl.generateMipmap(target);
16506
16511
  }
16507
16512
 
16508
- function getInternalFormat(internalFormatName, glFormat, glType, encoding) {
16513
+ function getInternalFormat(internalFormatName, glFormat, glType, encoding, isVideoTexture = false) {
16509
16514
  if (isWebGL2 === false) return glFormat;
16510
16515
 
16511
16516
  if (internalFormatName !== null) {
@@ -16530,7 +16535,7 @@
16530
16535
  if (glFormat === _gl.RGBA) {
16531
16536
  if (glType === _gl.FLOAT) internalFormat = _gl.RGBA32F;
16532
16537
  if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RGBA16F;
16533
- if (glType === _gl.UNSIGNED_BYTE) internalFormat = encoding === sRGBEncoding ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
16538
+ if (glType === _gl.UNSIGNED_BYTE) internalFormat = encoding === sRGBEncoding && isVideoTexture === false ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
16534
16539
  }
16535
16540
 
16536
16541
  if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) {
@@ -16806,11 +16811,12 @@
16806
16811
  _gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, _gl.NONE);
16807
16812
 
16808
16813
  const needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo$1(texture.image) === false;
16809
- const image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
16814
+ let image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
16815
+ image = verifyColorSpace(texture, image);
16810
16816
  const supportsMips = isPowerOfTwo$1(image) || isWebGL2,
16811
- glFormat = utils.convert(texture.format);
16817
+ glFormat = utils.convert(texture.format, texture.encoding);
16812
16818
  let glType = utils.convert(texture.type),
16813
- glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
16819
+ glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding, texture.isVideoTexture);
16814
16820
  setTextureParameters(textureType, texture, supportsMips);
16815
16821
  let mipmap;
16816
16822
  const mipmaps = texture.mipmaps;
@@ -16909,7 +16915,7 @@
16909
16915
  for (let i = 0, il = mipmaps.length; i < il; i++) {
16910
16916
  mipmap = mipmaps[i];
16911
16917
 
16912
- if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
16918
+ if (texture.format !== RGBAFormat) {
16913
16919
  if (glFormat !== null) {
16914
16920
  if (useTexStorage) {
16915
16921
  state.compressedTexSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data);
@@ -17019,11 +17025,13 @@
17019
17025
  } else {
17020
17026
  cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
17021
17027
  }
17028
+
17029
+ cubeImage[i] = verifyColorSpace(texture, cubeImage[i]);
17022
17030
  }
17023
17031
 
17024
17032
  const image = cubeImage[0],
17025
17033
  supportsMips = isPowerOfTwo$1(image) || isWebGL2,
17026
- glFormat = utils.convert(texture.format),
17034
+ glFormat = utils.convert(texture.format, texture.encoding),
17027
17035
  glType = utils.convert(texture.type),
17028
17036
  glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
17029
17037
  const useTexStorage = isWebGL2 && texture.isVideoTexture !== true;
@@ -17043,7 +17051,7 @@
17043
17051
  for (let j = 0; j < mipmaps.length; j++) {
17044
17052
  const mipmap = mipmaps[j];
17045
17053
 
17046
- if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
17054
+ if (texture.format !== RGBAFormat) {
17047
17055
  if (glFormat !== null) {
17048
17056
  if (useTexStorage) {
17049
17057
  state.compressedTexSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data);
@@ -17123,7 +17131,7 @@
17123
17131
 
17124
17132
 
17125
17133
  function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget) {
17126
- const glFormat = utils.convert(texture.format);
17134
+ const glFormat = utils.convert(texture.format, texture.encoding);
17127
17135
  const glType = utils.convert(texture.type);
17128
17136
  const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
17129
17137
  const renderTargetProperties = properties.get(renderTarget);
@@ -17192,7 +17200,7 @@
17192
17200
  } else {
17193
17201
  // Use the first texture for MRT so far
17194
17202
  const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[0] : renderTarget.texture;
17195
- const glFormat = utils.convert(texture.format);
17203
+ const glFormat = utils.convert(texture.format, texture.encoding);
17196
17204
  const glType = utils.convert(texture.type);
17197
17205
  const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
17198
17206
  const samples = getRenderTargetSamples(renderTarget);
@@ -17308,13 +17316,7 @@
17308
17316
  const isCube = renderTarget.isWebGLCubeRenderTarget === true;
17309
17317
  const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true;
17310
17318
  const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
17311
- const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
17312
-
17313
- if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
17314
- texture.format = RGBAFormat;
17315
- console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
17316
- } // Setup framebuffer
17317
-
17319
+ const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; // Setup framebuffer
17318
17320
 
17319
17321
  if (isCube) {
17320
17322
  renderTargetProperties.__webglFramebuffer = [];
@@ -17347,7 +17349,7 @@
17347
17349
 
17348
17350
  _gl.bindRenderbuffer(_gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer);
17349
17351
 
17350
- const glFormat = utils.convert(texture.format);
17352
+ const glFormat = utils.convert(texture.format, texture.encoding);
17351
17353
  const glType = utils.convert(texture.type);
17352
17354
  const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
17353
17355
  const samples = getRenderTargetSamples(renderTarget);
@@ -17503,6 +17505,40 @@
17503
17505
 
17504
17506
  texture.update();
17505
17507
  }
17508
+ }
17509
+
17510
+ function verifyColorSpace(texture, image) {
17511
+ const encoding = texture.encoding;
17512
+ const format = texture.format;
17513
+ const type = texture.type;
17514
+ if (texture.isCompressedTexture === true || texture.format === _SRGBAFormat) return image;
17515
+
17516
+ if (encoding !== LinearEncoding) {
17517
+ // sRGB
17518
+ if (encoding === sRGBEncoding && texture.isVideoTexture !== true) {
17519
+ if (isWebGL2 === false) {
17520
+ // in WebGL 1, try to use EXT_sRGB extension and unsized formats
17521
+ if (extensions.has('EXT_sRGB') === true && format === RGBAFormat) {
17522
+ texture.format = _SRGBAFormat; // it's not possible to generate mips in WebGL 1 with this extension
17523
+
17524
+ texture.minFilter = LinearFilter;
17525
+ texture.generateMipmaps = false;
17526
+ } else {
17527
+ // slow fallback (CPU decode)
17528
+ image = ImageUtils.sRGBToLinear(image);
17529
+ }
17530
+ } else {
17531
+ // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format
17532
+ if (format !== RGBAFormat || type !== UnsignedByteType) {
17533
+ console.warn('THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.');
17534
+ }
17535
+ }
17536
+ } else {
17537
+ console.error('THREE.WebGLTextures: Unsupported texture encoding:', encoding);
17538
+ }
17539
+ }
17540
+
17541
+ return image;
17506
17542
  } // backwards compatibility
17507
17543
 
17508
17544
 
@@ -17555,7 +17591,7 @@
17555
17591
  function WebGLUtils(gl, extensions, capabilities) {
17556
17592
  const isWebGL2 = capabilities.isWebGL2;
17557
17593
 
17558
- function convert(p) {
17594
+ function convert(p, encoding = null) {
17559
17595
  let extension;
17560
17596
  if (p === UnsignedByteType) return gl.UNSIGNED_BYTE;
17561
17597
  if (p === UnsignedShort4444Type) return gl.UNSIGNED_SHORT_4_4_4_4;
@@ -17580,32 +17616,56 @@
17580
17616
  }
17581
17617
 
17582
17618
  if (p === AlphaFormat) return gl.ALPHA;
17583
- if (p === RGBFormat) return gl.RGB;
17584
17619
  if (p === RGBAFormat) return gl.RGBA;
17585
17620
  if (p === LuminanceFormat) return gl.LUMINANCE;
17586
17621
  if (p === LuminanceAlphaFormat) return gl.LUMINANCE_ALPHA;
17587
17622
  if (p === DepthFormat) return gl.DEPTH_COMPONENT;
17588
17623
  if (p === DepthStencilFormat) return gl.DEPTH_STENCIL;
17589
- if (p === RedFormat) return gl.RED; // WebGL2 formats.
17624
+ if (p === RedFormat) return gl.RED; // WebGL 1 sRGB fallback
17625
+
17626
+ if (p === _SRGBAFormat) {
17627
+ extension = extensions.get('EXT_sRGB');
17628
+
17629
+ if (extension !== null) {
17630
+ return extension.SRGB_ALPHA_EXT;
17631
+ } else {
17632
+ return null;
17633
+ }
17634
+ } // WebGL2 formats.
17635
+
17590
17636
 
17591
17637
  if (p === RedIntegerFormat) return gl.RED_INTEGER;
17592
17638
  if (p === RGFormat) return gl.RG;
17593
17639
  if (p === RGIntegerFormat) return gl.RG_INTEGER;
17594
17640
  if (p === RGBIntegerFormat) return gl.RGB_INTEGER;
17595
- if (p === RGBAIntegerFormat) return gl.RGBA_INTEGER;
17641
+ if (p === RGBAIntegerFormat) return gl.RGBA_INTEGER; // S3TC
17596
17642
 
17597
17643
  if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
17598
- extension = extensions.get('WEBGL_compressed_texture_s3tc');
17599
-
17600
- if (extension !== null) {
17601
- if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
17602
- if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
17603
- if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
17604
- if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
17644
+ if (encoding === sRGBEncoding) {
17645
+ extension = extensions.get('WEBGL_compressed_texture_s3tc_srgb');
17646
+
17647
+ if (extension !== null) {
17648
+ if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT;
17649
+ if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
17650
+ if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
17651
+ if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
17652
+ } else {
17653
+ return null;
17654
+ }
17605
17655
  } else {
17606
- return null;
17656
+ extension = extensions.get('WEBGL_compressed_texture_s3tc');
17657
+
17658
+ if (extension !== null) {
17659
+ if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
17660
+ if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
17661
+ if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
17662
+ if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
17663
+ } else {
17664
+ return null;
17665
+ }
17607
17666
  }
17608
- }
17667
+ } // PVRTC
17668
+
17609
17669
 
17610
17670
  if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
17611
17671
  extension = extensions.get('WEBGL_compressed_texture_pvrtc');
@@ -17618,7 +17678,8 @@
17618
17678
  } else {
17619
17679
  return null;
17620
17680
  }
17621
- }
17681
+ } // ETC1
17682
+
17622
17683
 
17623
17684
  if (p === RGB_ETC1_Format) {
17624
17685
  extension = extensions.get('WEBGL_compressed_texture_etc1');
@@ -17628,38 +17689,55 @@
17628
17689
  } else {
17629
17690
  return null;
17630
17691
  }
17631
- }
17692
+ } // ETC2
17693
+
17632
17694
 
17633
17695
  if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
17634
17696
  extension = extensions.get('WEBGL_compressed_texture_etc');
17635
17697
 
17636
17698
  if (extension !== null) {
17637
- if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
17638
- if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
17699
+ if (p === RGB_ETC2_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
17700
+ if (p === RGBA_ETC2_EAC_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
17701
+ } else {
17702
+ return null;
17639
17703
  }
17640
- }
17704
+ } // ASTC
17641
17705
 
17642
- if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format || p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format || p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format || p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format || p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format || p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format) {
17706
+
17707
+ if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format) {
17643
17708
  extension = extensions.get('WEBGL_compressed_texture_astc');
17644
17709
 
17645
17710
  if (extension !== null) {
17646
- // TODO Complete?
17647
- return p;
17711
+ if (p === RGBA_ASTC_4x4_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR;
17712
+ if (p === RGBA_ASTC_5x4_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR;
17713
+ if (p === RGBA_ASTC_5x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR;
17714
+ if (p === RGBA_ASTC_6x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR;
17715
+ if (p === RGBA_ASTC_6x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR;
17716
+ if (p === RGBA_ASTC_8x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR;
17717
+ if (p === RGBA_ASTC_8x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR;
17718
+ if (p === RGBA_ASTC_8x8_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR;
17719
+ if (p === RGBA_ASTC_10x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR;
17720
+ if (p === RGBA_ASTC_10x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR;
17721
+ if (p === RGBA_ASTC_10x8_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR;
17722
+ if (p === RGBA_ASTC_10x10_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR;
17723
+ if (p === RGBA_ASTC_12x10_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR;
17724
+ if (p === RGBA_ASTC_12x12_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR;
17648
17725
  } else {
17649
17726
  return null;
17650
17727
  }
17651
- }
17728
+ } // BPTC
17729
+
17652
17730
 
17653
17731
  if (p === RGBA_BPTC_Format) {
17654
17732
  extension = extensions.get('EXT_texture_compression_bptc');
17655
17733
 
17656
17734
  if (extension !== null) {
17657
- // TODO Complete?
17658
- return p;
17735
+ if (p === RGBA_BPTC_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT;
17659
17736
  } else {
17660
17737
  return null;
17661
17738
  }
17662
- }
17739
+ } //
17740
+
17663
17741
 
17664
17742
  if (p === UnsignedInt248Type) {
17665
17743
  if (isWebGL2) return gl.UNSIGNED_INT_24_8;
@@ -18498,7 +18576,7 @@
18498
18576
  }
18499
18577
 
18500
18578
  const projectionlayerInit = {
18501
- colorFormat: attributes.alpha || isMultisample ? gl.RGBA8 : gl.RGB8,
18579
+ colorFormat: renderer.outputEncoding === sRGBEncoding ? gl.SRGB8_ALPHA8 : gl.RGBA8,
18502
18580
  depthFormat: glDepthFormat,
18503
18581
  scaleFactor: framebufferScaleFactor
18504
18582
  };
@@ -18520,7 +18598,7 @@
18520
18598
  });
18521
18599
  } else {
18522
18600
  newRenderTarget = new WebGLRenderTarget(glProjLayer.textureWidth, glProjLayer.textureHeight, {
18523
- format: attributes.alpha ? RGBAFormat : RGBFormat,
18601
+ format: RGBAFormat,
18524
18602
  type: UnsignedByteType,
18525
18603
  depthTexture: new DepthTexture(glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat),
18526
18604
  stencilBuffer: attributes.stencil,
@@ -19431,9 +19509,7 @@
19431
19509
 
19432
19510
  const _scissor = new Vector4(0, 0, _width, _height);
19433
19511
 
19434
- let _scissorTest = false; //
19435
-
19436
- const _currentDrawBuffers = []; // frustum
19512
+ let _scissorTest = false; // frustum
19437
19513
 
19438
19514
  const _frustum = new Frustum(); // clipping
19439
19515
 
@@ -19537,7 +19613,6 @@
19537
19613
  extensions.init(capabilities);
19538
19614
  utils = new WebGLUtils(_gl, extensions, capabilities);
19539
19615
  state = new WebGLState(_gl, extensions, capabilities);
19540
- _currentDrawBuffers[0] = _gl.BACK;
19541
19616
  info = new WebGLInfo(_gl);
19542
19617
  properties = new WebGLProperties();
19543
19618
  textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
@@ -20620,42 +20695,7 @@
20620
20695
  const framebufferBound = state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
20621
20696
 
20622
20697
  if (framebufferBound && capabilities.drawBuffers && useDefaultFramebuffer) {
20623
- let needsUpdate = false;
20624
-
20625
- if (renderTarget) {
20626
- if (renderTarget.isWebGLMultipleRenderTargets) {
20627
- const textures = renderTarget.texture;
20628
-
20629
- if (_currentDrawBuffers.length !== textures.length || _currentDrawBuffers[0] !== _gl.COLOR_ATTACHMENT0) {
20630
- for (let i = 0, il = textures.length; i < il; i++) {
20631
- _currentDrawBuffers[i] = _gl.COLOR_ATTACHMENT0 + i;
20632
- }
20633
-
20634
- _currentDrawBuffers.length = textures.length;
20635
- needsUpdate = true;
20636
- }
20637
- } else {
20638
- if (_currentDrawBuffers.length !== 1 || _currentDrawBuffers[0] !== _gl.COLOR_ATTACHMENT0) {
20639
- _currentDrawBuffers[0] = _gl.COLOR_ATTACHMENT0;
20640
- _currentDrawBuffers.length = 1;
20641
- needsUpdate = true;
20642
- }
20643
- }
20644
- } else {
20645
- if (_currentDrawBuffers.length !== 1 || _currentDrawBuffers[0] !== _gl.BACK) {
20646
- _currentDrawBuffers[0] = _gl.BACK;
20647
- _currentDrawBuffers.length = 1;
20648
- needsUpdate = true;
20649
- }
20650
- }
20651
-
20652
- if (needsUpdate) {
20653
- if (capabilities.isWebGL2) {
20654
- _gl.drawBuffers(_currentDrawBuffers);
20655
- } else {
20656
- extensions.get('WEBGL_draw_buffers').drawBuffersWEBGL(_currentDrawBuffers);
20657
- }
20658
- }
20698
+ state.drawBuffers(renderTarget, framebuffer);
20659
20699
  }
20660
20700
 
20661
20701
  state.viewport(_currentViewport);
@@ -22457,7 +22497,6 @@
22457
22497
  class VideoTexture extends Texture {
22458
22498
  constructor(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
22459
22499
  super(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
22460
- this.format = format !== undefined ? format : RGBFormat;
22461
22500
  this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
22462
22501
  this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
22463
22502
  this.generateMipmaps = false;
@@ -29922,12 +29961,12 @@
29922
29961
  if (json.side !== undefined) material.side = json.side;
29923
29962
  if (json.shadowSide !== undefined) material.shadowSide = json.shadowSide;
29924
29963
  if (json.opacity !== undefined) material.opacity = json.opacity;
29925
- if (json.format !== undefined) material.format = json.format;
29926
29964
  if (json.transparent !== undefined) material.transparent = json.transparent;
29927
29965
  if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
29928
29966
  if (json.depthTest !== undefined) material.depthTest = json.depthTest;
29929
29967
  if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
29930
29968
  if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
29969
+ if (json.alphaWrite !== undefined) material.alphaWrite = json.alphaWrite;
29931
29970
  if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
29932
29971
  if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
29933
29972
  if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
@@ -33269,6 +33308,7 @@
33269
33308
  let binding = bindingsByName[trackName];
33270
33309
 
33271
33310
  if (binding !== undefined) {
33311
+ ++binding.referenceCount;
33272
33312
  bindings[i] = binding;
33273
33313
  } else {
33274
33314
  binding = bindings[i];
@@ -36953,7 +36993,6 @@
36953
36993
  exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
36954
36994
  exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
36955
36995
  exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
36956
- exports.RGBFormat = RGBFormat;
36957
36996
  exports.RGBIntegerFormat = RGBIntegerFormat;
36958
36997
  exports.RGB_ETC1_Format = RGB_ETC1_Format;
36959
36998
  exports.RGB_ETC2_Format = RGB_ETC2_Format;
@@ -36974,20 +37013,6 @@
36974
37013
  exports.ReverseSubtractEquation = ReverseSubtractEquation;
36975
37014
  exports.RingBufferGeometry = RingGeometry;
36976
37015
  exports.RingGeometry = RingGeometry;
36977
- exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
36978
- exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
36979
- exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
36980
- exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
36981
- exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
36982
- exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
36983
- exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
36984
- exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
36985
- exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
36986
- exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
36987
- exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
36988
- exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
36989
- exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
36990
- exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
36991
37016
  exports.Scene = Scene;
36992
37017
  exports.SceneUtils = SceneUtils;
36993
37018
  exports.ShaderChunk = ShaderChunk;
@@ -37087,6 +37112,7 @@
37087
37112
  exports.ZeroFactor = ZeroFactor;
37088
37113
  exports.ZeroSlopeEnding = ZeroSlopeEnding;
37089
37114
  exports.ZeroStencilOp = ZeroStencilOp;
37115
+ exports._SRGBAFormat = _SRGBAFormat;
37090
37116
  exports.sRGBEncoding = sRGBEncoding;
37091
37117
 
37092
37118
  Object.defineProperty(exports, '__esModule', { value: true });