super-three 0.169.0 → 0.170.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/build/three.cjs +989 -1131
  2. package/build/three.module.js +990 -1128
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +121 -126
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. package/src/renderers/webvr/WebVRManager.js +0 -495
  194. package/src/renderers/webvr/WebVRUtils.js +0 -66
  195. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -26,8 +26,6 @@ import {
26
26
  Quaternion,
27
27
  REVISION
28
28
  } from 'three';
29
- import { decompress } from './../utils/TextureUtils.js';
30
-
31
29
 
32
30
  /**
33
31
  * The KHR_mesh_quantization extension allows these extra attribute component types
@@ -68,6 +66,8 @@ class GLTFExporter {
68
66
 
69
67
  constructor() {
70
68
 
69
+ this.textureUtils = null;
70
+
71
71
  this.pluginCallbacks = [];
72
72
 
73
73
  this.register( function ( writer ) {
@@ -180,6 +180,14 @@ class GLTFExporter {
180
180
 
181
181
  }
182
182
 
183
+ setTextureUtils( utils ) {
184
+
185
+ this.textureUtils = utils;
186
+
187
+ return this;
188
+
189
+ }
190
+
183
191
  /**
184
192
  * Parse scenes and generate GLTF output
185
193
  * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
@@ -199,7 +207,8 @@ class GLTFExporter {
199
207
  }
200
208
 
201
209
  writer.setPlugins( plugins );
202
- writer.write( input, onDone, options ).catch( onError );
210
+ writer.setTextureUtils( this.textureUtils );
211
+ writer.writeAsync( input, onDone, options ).catch( onError );
203
212
 
204
213
  }
205
214
 
@@ -516,6 +525,8 @@ class GLTFWriter {
516
525
  images: new Map()
517
526
  };
518
527
 
528
+ this.textureUtils = null;
529
+
519
530
  }
520
531
 
521
532
  setPlugins( plugins ) {
@@ -524,13 +535,19 @@ class GLTFWriter {
524
535
 
525
536
  }
526
537
 
538
+ setTextureUtils( utils ) {
539
+
540
+ this.textureUtils = utils;
541
+
542
+ }
543
+
527
544
  /**
528
545
  * Parse scenes and generate GLTF output
529
546
  * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
530
547
  * @param {Function} onDone Callback on completed
531
548
  * @param {Object} options options
532
549
  */
533
- async write( input, onDone, options = {} ) {
550
+ async writeAsync( input, onDone, options = {} ) {
534
551
 
535
552
  this.options = Object.assign( {
536
553
  // default options
@@ -549,7 +566,7 @@ class GLTFWriter {
549
566
 
550
567
  }
551
568
 
552
- this.processInput( input );
569
+ await this.processInputAsync( input );
553
570
 
554
571
  await Promise.all( this.pending );
555
572
 
@@ -823,7 +840,7 @@ class GLTFWriter {
823
840
 
824
841
  }
825
842
 
826
- buildMetalRoughTexture( metalnessMap, roughnessMap ) {
843
+ async buildMetalRoughTextureAsync( metalnessMap, roughnessMap ) {
827
844
 
828
845
  if ( metalnessMap === roughnessMap ) return metalnessMap;
829
846
 
@@ -847,17 +864,15 @@ class GLTFWriter {
847
864
 
848
865
  }
849
866
 
850
- console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
851
-
852
867
  if ( metalnessMap instanceof CompressedTexture ) {
853
868
 
854
- metalnessMap = decompress( metalnessMap );
869
+ metalnessMap = await this.decompressTextureAsync( metalnessMap );
855
870
 
856
871
  }
857
872
 
858
873
  if ( roughnessMap instanceof CompressedTexture ) {
859
874
 
860
- roughnessMap = decompress( roughnessMap );
875
+ roughnessMap = await this.decompressTextureAsync( roughnessMap );
861
876
 
862
877
  }
863
878
 
@@ -927,10 +942,25 @@ class GLTFWriter {
927
942
 
928
943
  }
929
944
 
945
+ console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
946
+
930
947
  return texture;
931
948
 
932
949
  }
933
950
 
951
+
952
+ async decompressTextureAsync( texture, maxTextureSize = Infinity ) {
953
+
954
+ if ( this.textureUtils === null ) {
955
+
956
+ throw new Error( 'THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.' );
957
+
958
+ }
959
+
960
+ return await this.textureUtils.decompress( texture, maxTextureSize );
961
+
962
+ }
963
+
934
964
  /**
935
965
  * Process a buffer to append to the default one.
936
966
  * @param {ArrayBuffer} buffer
@@ -1407,7 +1437,7 @@ class GLTFWriter {
1407
1437
  * @param {Texture} map Map to process
1408
1438
  * @return {Integer} Index of the processed texture in the "textures" array
1409
1439
  */
1410
- processTexture( map ) {
1440
+ async processTextureAsync( map ) {
1411
1441
 
1412
1442
  const writer = this;
1413
1443
  const options = writer.options;
@@ -1421,7 +1451,7 @@ class GLTFWriter {
1421
1451
  // make non-readable textures (e.g. CompressedTexture) readable by blitting them into a new texture
1422
1452
  if ( map instanceof CompressedTexture ) {
1423
1453
 
1424
- map = decompress( map, options.maxTextureSize );
1454
+ map = await this.decompressTextureAsync( map, options.maxTextureSize );
1425
1455
 
1426
1456
  }
1427
1457
 
@@ -1436,9 +1466,9 @@ class GLTFWriter {
1436
1466
 
1437
1467
  if ( map.name ) textureDef.name = map.name;
1438
1468
 
1439
- this._invokeAll( function ( ext ) {
1469
+ await this._invokeAllAsync( async function ( ext ) {
1440
1470
 
1441
- ext.writeTexture && ext.writeTexture( map, textureDef );
1471
+ ext.writeTexture && await ext.writeTexture( map, textureDef );
1442
1472
 
1443
1473
  } );
1444
1474
 
@@ -1453,7 +1483,7 @@ class GLTFWriter {
1453
1483
  * @param {THREE.Material} material Material to process
1454
1484
  * @return {Integer|null} Index of the processed material in the "materials" array
1455
1485
  */
1456
- processMaterial( material ) {
1486
+ async processMaterialAsync( material ) {
1457
1487
 
1458
1488
  const cache = this.cache;
1459
1489
  const json = this.json;
@@ -1494,19 +1524,19 @@ class GLTFWriter {
1494
1524
 
1495
1525
  } else {
1496
1526
 
1497
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
1498
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
1527
+ materialDef.pbrMetallicRoughness.metallicFactor = 0;
1528
+ materialDef.pbrMetallicRoughness.roughnessFactor = 1;
1499
1529
 
1500
1530
  }
1501
1531
 
1502
1532
  // pbrMetallicRoughness.metallicRoughnessTexture
1503
1533
  if ( material.metalnessMap || material.roughnessMap ) {
1504
1534
 
1505
- const metalRoughTexture = this.buildMetalRoughTexture( material.metalnessMap, material.roughnessMap );
1535
+ const metalRoughTexture = await this.buildMetalRoughTextureAsync( material.metalnessMap, material.roughnessMap );
1506
1536
 
1507
1537
  const metalRoughMapDef = {
1508
- index: this.processTexture( metalRoughTexture ),
1509
- channel: metalRoughTexture.channel
1538
+ index: await this.processTextureAsync( metalRoughTexture ),
1539
+ texCoord: metalRoughTexture.channel
1510
1540
  };
1511
1541
  this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
1512
1542
  materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
@@ -1517,7 +1547,7 @@ class GLTFWriter {
1517
1547
  if ( material.map ) {
1518
1548
 
1519
1549
  const baseColorMapDef = {
1520
- index: this.processTexture( material.map ),
1550
+ index: await this.processTextureAsync( material.map ),
1521
1551
  texCoord: material.map.channel
1522
1552
  };
1523
1553
  this.applyTextureTransform( baseColorMapDef, material.map );
@@ -1540,7 +1570,7 @@ class GLTFWriter {
1540
1570
  if ( material.emissiveMap ) {
1541
1571
 
1542
1572
  const emissiveMapDef = {
1543
- index: this.processTexture( material.emissiveMap ),
1573
+ index: await this.processTextureAsync( material.emissiveMap ),
1544
1574
  texCoord: material.emissiveMap.channel
1545
1575
  };
1546
1576
  this.applyTextureTransform( emissiveMapDef, material.emissiveMap );
@@ -1554,7 +1584,7 @@ class GLTFWriter {
1554
1584
  if ( material.normalMap ) {
1555
1585
 
1556
1586
  const normalMapDef = {
1557
- index: this.processTexture( material.normalMap ),
1587
+ index: await this.processTextureAsync( material.normalMap ),
1558
1588
  texCoord: material.normalMap.channel
1559
1589
  };
1560
1590
 
@@ -1575,7 +1605,7 @@ class GLTFWriter {
1575
1605
  if ( material.aoMap ) {
1576
1606
 
1577
1607
  const occlusionMapDef = {
1578
- index: this.processTexture( material.aoMap ),
1608
+ index: await this.processTextureAsync( material.aoMap ),
1579
1609
  texCoord: material.aoMap.channel
1580
1610
  };
1581
1611
 
@@ -1612,9 +1642,9 @@ class GLTFWriter {
1612
1642
 
1613
1643
  this.serializeUserData( material, materialDef );
1614
1644
 
1615
- this._invokeAll( function ( ext ) {
1645
+ await this._invokeAllAsync( async function ( ext ) {
1616
1646
 
1617
- ext.writeMaterial && ext.writeMaterial( material, materialDef );
1647
+ ext.writeMaterialAsync && await ext.writeMaterialAsync( material, materialDef );
1618
1648
 
1619
1649
  } );
1620
1650
 
@@ -1629,7 +1659,7 @@ class GLTFWriter {
1629
1659
  * @param {THREE.Mesh} mesh Mesh to process
1630
1660
  * @return {Integer|null} Index of the processed mesh in the "meshes" array
1631
1661
  */
1632
- processMesh( mesh ) {
1662
+ async processMeshAsync( mesh ) {
1633
1663
 
1634
1664
  const cache = this.cache;
1635
1665
  const json = this.json;
@@ -1733,7 +1763,9 @@ class GLTFWriter {
1733
1763
 
1734
1764
  }
1735
1765
 
1736
- // JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT.
1766
+ // Enforce glTF vertex attribute requirements:
1767
+ // - JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT
1768
+ // - Only custom attributes may be INT or UNSIGNED_INT
1737
1769
  modifiedAttribute = null;
1738
1770
  const array = attribute.array;
1739
1771
 
@@ -1744,6 +1776,11 @@ class GLTFWriter {
1744
1776
  console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' );
1745
1777
  modifiedAttribute = new BufferAttribute( new Uint16Array( array ), attribute.itemSize, attribute.normalized );
1746
1778
 
1779
+ } else if ( ( array instanceof Uint32Array || array instanceof Int32Array ) && ! attributeName.startsWith( '_' ) ) {
1780
+
1781
+ console.warn( `GLTFExporter: Attribute "${ attributeName }" converted to type FLOAT.` );
1782
+ modifiedAttribute = GLTFExporter.Utils.toFloat32BufferAttribute( attribute );
1783
+
1747
1784
  }
1748
1785
 
1749
1786
  const accessor = this.processAccessor( modifiedAttribute || attribute, geometry );
@@ -1930,7 +1967,7 @@ class GLTFWriter {
1930
1967
 
1931
1968
  }
1932
1969
 
1933
- const material = this.processMaterial( materials[ groups[ i ].materialIndex ] );
1970
+ const material = await this.processMaterialAsync( materials[ groups[ i ].materialIndex ] );
1934
1971
 
1935
1972
  if ( material !== null ) primitive.material = material;
1936
1973
 
@@ -1948,7 +1985,7 @@ class GLTFWriter {
1948
1985
 
1949
1986
  if ( ! json.meshes ) json.meshes = [];
1950
1987
 
1951
- this._invokeAll( function ( ext ) {
1988
+ await this._invokeAllAsync( function ( ext ) {
1952
1989
 
1953
1990
  ext.writeMesh && ext.writeMesh( mesh, meshDef );
1954
1991
 
@@ -2225,10 +2262,10 @@ class GLTFWriter {
2225
2262
 
2226
2263
  /**
2227
2264
  * Process Object3D node
2228
- * @param {THREE.Object3D} node Object3D to processNode
2265
+ * @param {THREE.Object3D} node Object3D to processNodeAsync
2229
2266
  * @return {Integer} Index of the node in the nodes list
2230
2267
  */
2231
- processNode( object ) {
2268
+ async processNodeAsync( object ) {
2232
2269
 
2233
2270
  const json = this.json;
2234
2271
  const options = this.options;
@@ -2285,7 +2322,7 @@ class GLTFWriter {
2285
2322
 
2286
2323
  if ( object.isMesh || object.isLine || object.isPoints ) {
2287
2324
 
2288
- const meshIndex = this.processMesh( object );
2325
+ const meshIndex = await this.processMeshAsync( object );
2289
2326
 
2290
2327
  if ( meshIndex !== null ) nodeDef.mesh = meshIndex;
2291
2328
 
@@ -2307,7 +2344,7 @@ class GLTFWriter {
2307
2344
 
2308
2345
  if ( child.visible || options.onlyVisible === false ) {
2309
2346
 
2310
- const nodeIndex = this.processNode( child );
2347
+ const nodeIndex = await this.processNodeAsync( child );
2311
2348
 
2312
2349
  if ( nodeIndex !== null ) children.push( nodeIndex );
2313
2350
 
@@ -2319,7 +2356,7 @@ class GLTFWriter {
2319
2356
 
2320
2357
  }
2321
2358
 
2322
- this._invokeAll( function ( ext ) {
2359
+ await this._invokeAllAsync( function ( ext ) {
2323
2360
 
2324
2361
  ext.writeNode && ext.writeNode( object, nodeDef );
2325
2362
 
@@ -2335,7 +2372,7 @@ class GLTFWriter {
2335
2372
  * Process Scene
2336
2373
  * @param {Scene} node Scene to process
2337
2374
  */
2338
- processScene( scene ) {
2375
+ async processSceneAsync( scene ) {
2339
2376
 
2340
2377
  const json = this.json;
2341
2378
  const options = this.options;
@@ -2361,7 +2398,7 @@ class GLTFWriter {
2361
2398
 
2362
2399
  if ( child.visible || options.onlyVisible === false ) {
2363
2400
 
2364
- const nodeIndex = this.processNode( child );
2401
+ const nodeIndex = await this.processNodeAsync( child );
2365
2402
 
2366
2403
  if ( nodeIndex !== null ) nodes.push( nodeIndex );
2367
2404
 
@@ -2379,7 +2416,7 @@ class GLTFWriter {
2379
2416
  * Creates a Scene to hold a list of objects and parse it
2380
2417
  * @param {Array} objects List of objects to process
2381
2418
  */
2382
- processObjects( objects ) {
2419
+ async processObjectsAsync( objects ) {
2383
2420
 
2384
2421
  const scene = new Scene();
2385
2422
  scene.name = 'AuxScene';
@@ -2392,20 +2429,20 @@ class GLTFWriter {
2392
2429
 
2393
2430
  }
2394
2431
 
2395
- this.processScene( scene );
2432
+ await this.processSceneAsync( scene );
2396
2433
 
2397
2434
  }
2398
2435
 
2399
2436
  /**
2400
2437
  * @param {THREE.Object3D|Array<THREE.Object3D>} input
2401
2438
  */
2402
- processInput( input ) {
2439
+ async processInputAsync( input ) {
2403
2440
 
2404
2441
  const options = this.options;
2405
2442
 
2406
2443
  input = input instanceof Array ? input : [ input ];
2407
2444
 
2408
- this._invokeAll( function ( ext ) {
2445
+ await this._invokeAllAsync( function ( ext ) {
2409
2446
 
2410
2447
  ext.beforeParse && ext.beforeParse( input );
2411
2448
 
@@ -2417,7 +2454,7 @@ class GLTFWriter {
2417
2454
 
2418
2455
  if ( input[ i ] instanceof Scene ) {
2419
2456
 
2420
- this.processScene( input[ i ] );
2457
+ await this.processSceneAsync( input[ i ] );
2421
2458
 
2422
2459
  } else {
2423
2460
 
@@ -2427,7 +2464,11 @@ class GLTFWriter {
2427
2464
 
2428
2465
  }
2429
2466
 
2430
- if ( objectsWithoutScene.length > 0 ) this.processObjects( objectsWithoutScene );
2467
+ if ( objectsWithoutScene.length > 0 ) {
2468
+
2469
+ await this.processObjectsAsync( objectsWithoutScene );
2470
+
2471
+ }
2431
2472
 
2432
2473
  for ( let i = 0; i < this.skins.length; ++ i ) {
2433
2474
 
@@ -2441,7 +2482,7 @@ class GLTFWriter {
2441
2482
 
2442
2483
  }
2443
2484
 
2444
- this._invokeAll( function ( ext ) {
2485
+ await this._invokeAllAsync( function ( ext ) {
2445
2486
 
2446
2487
  ext.afterParse && ext.afterParse( input );
2447
2488
 
@@ -2449,11 +2490,11 @@ class GLTFWriter {
2449
2490
 
2450
2491
  }
2451
2492
 
2452
- _invokeAll( func ) {
2493
+ async _invokeAllAsync( func ) {
2453
2494
 
2454
2495
  for ( let i = 0, il = this.plugins.length; i < il; i ++ ) {
2455
2496
 
2456
- func( this.plugins[ i ] );
2497
+ await func( this.plugins[ i ] );
2457
2498
 
2458
2499
  }
2459
2500
 
@@ -2570,7 +2611,7 @@ class GLTFMaterialsUnlitExtension {
2570
2611
 
2571
2612
  }
2572
2613
 
2573
- writeMaterial( material, materialDef ) {
2614
+ async writeMaterialAsync( material, materialDef ) {
2574
2615
 
2575
2616
  if ( ! material.isMeshBasicMaterial ) return;
2576
2617
 
@@ -2603,7 +2644,7 @@ class GLTFMaterialsClearcoatExtension {
2603
2644
 
2604
2645
  }
2605
2646
 
2606
- writeMaterial( material, materialDef ) {
2647
+ async writeMaterialAsync( material, materialDef ) {
2607
2648
 
2608
2649
  if ( ! material.isMeshPhysicalMaterial || material.clearcoat === 0 ) return;
2609
2650
 
@@ -2617,7 +2658,7 @@ class GLTFMaterialsClearcoatExtension {
2617
2658
  if ( material.clearcoatMap ) {
2618
2659
 
2619
2660
  const clearcoatMapDef = {
2620
- index: writer.processTexture( material.clearcoatMap ),
2661
+ index: await writer.processTextureAsync( material.clearcoatMap ),
2621
2662
  texCoord: material.clearcoatMap.channel
2622
2663
  };
2623
2664
  writer.applyTextureTransform( clearcoatMapDef, material.clearcoatMap );
@@ -2630,7 +2671,7 @@ class GLTFMaterialsClearcoatExtension {
2630
2671
  if ( material.clearcoatRoughnessMap ) {
2631
2672
 
2632
2673
  const clearcoatRoughnessMapDef = {
2633
- index: writer.processTexture( material.clearcoatRoughnessMap ),
2674
+ index: await writer.processTextureAsync( material.clearcoatRoughnessMap ),
2634
2675
  texCoord: material.clearcoatRoughnessMap.channel
2635
2676
  };
2636
2677
  writer.applyTextureTransform( clearcoatRoughnessMapDef, material.clearcoatRoughnessMap );
@@ -2641,7 +2682,7 @@ class GLTFMaterialsClearcoatExtension {
2641
2682
  if ( material.clearcoatNormalMap ) {
2642
2683
 
2643
2684
  const clearcoatNormalMapDef = {
2644
- index: writer.processTexture( material.clearcoatNormalMap ),
2685
+ index: await writer.processTextureAsync( material.clearcoatNormalMap ),
2645
2686
  texCoord: material.clearcoatNormalMap.channel
2646
2687
  };
2647
2688
 
@@ -2676,7 +2717,7 @@ class GLTFMaterialsDispersionExtension {
2676
2717
 
2677
2718
  }
2678
2719
 
2679
- writeMaterial( material, materialDef ) {
2720
+ async writeMaterialAsync( material, materialDef ) {
2680
2721
 
2681
2722
  if ( ! material.isMeshPhysicalMaterial || material.dispersion === 0 ) return;
2682
2723
 
@@ -2710,7 +2751,7 @@ class GLTFMaterialsIridescenceExtension {
2710
2751
 
2711
2752
  }
2712
2753
 
2713
- writeMaterial( material, materialDef ) {
2754
+ async writeMaterialAsync( material, materialDef ) {
2714
2755
 
2715
2756
  if ( ! material.isMeshPhysicalMaterial || material.iridescence === 0 ) return;
2716
2757
 
@@ -2724,7 +2765,7 @@ class GLTFMaterialsIridescenceExtension {
2724
2765
  if ( material.iridescenceMap ) {
2725
2766
 
2726
2767
  const iridescenceMapDef = {
2727
- index: writer.processTexture( material.iridescenceMap ),
2768
+ index: await writer.processTextureAsync( material.iridescenceMap ),
2728
2769
  texCoord: material.iridescenceMap.channel
2729
2770
  };
2730
2771
  writer.applyTextureTransform( iridescenceMapDef, material.iridescenceMap );
@@ -2739,7 +2780,7 @@ class GLTFMaterialsIridescenceExtension {
2739
2780
  if ( material.iridescenceThicknessMap ) {
2740
2781
 
2741
2782
  const iridescenceThicknessMapDef = {
2742
- index: writer.processTexture( material.iridescenceThicknessMap ),
2783
+ index: await writer.processTextureAsync( material.iridescenceThicknessMap ),
2743
2784
  texCoord: material.iridescenceThicknessMap.channel
2744
2785
  };
2745
2786
  writer.applyTextureTransform( iridescenceThicknessMapDef, material.iridescenceThicknessMap );
@@ -2770,7 +2811,7 @@ class GLTFMaterialsTransmissionExtension {
2770
2811
 
2771
2812
  }
2772
2813
 
2773
- writeMaterial( material, materialDef ) {
2814
+ async writeMaterialAsync( material, materialDef ) {
2774
2815
 
2775
2816
  if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2776
2817
 
@@ -2784,7 +2825,7 @@ class GLTFMaterialsTransmissionExtension {
2784
2825
  if ( material.transmissionMap ) {
2785
2826
 
2786
2827
  const transmissionMapDef = {
2787
- index: writer.processTexture( material.transmissionMap ),
2828
+ index: await writer.processTextureAsync( material.transmissionMap ),
2788
2829
  texCoord: material.transmissionMap.channel
2789
2830
  };
2790
2831
  writer.applyTextureTransform( transmissionMapDef, material.transmissionMap );
@@ -2815,7 +2856,7 @@ class GLTFMaterialsVolumeExtension {
2815
2856
 
2816
2857
  }
2817
2858
 
2818
- writeMaterial( material, materialDef ) {
2859
+ async writeMaterialAsync( material, materialDef ) {
2819
2860
 
2820
2861
  if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2821
2862
 
@@ -2829,7 +2870,7 @@ class GLTFMaterialsVolumeExtension {
2829
2870
  if ( material.thicknessMap ) {
2830
2871
 
2831
2872
  const thicknessMapDef = {
2832
- index: writer.processTexture( material.thicknessMap ),
2873
+ index: await writer.processTextureAsync( material.thicknessMap ),
2833
2874
  texCoord: material.thicknessMap.channel
2834
2875
  };
2835
2876
  writer.applyTextureTransform( thicknessMapDef, material.thicknessMap );
@@ -2868,7 +2909,7 @@ class GLTFMaterialsIorExtension {
2868
2909
 
2869
2910
  }
2870
2911
 
2871
- writeMaterial( material, materialDef ) {
2912
+ async writeMaterialAsync( material, materialDef ) {
2872
2913
 
2873
2914
  if ( ! material.isMeshPhysicalMaterial || material.ior === 1.5 ) return;
2874
2915
 
@@ -2902,7 +2943,7 @@ class GLTFMaterialsSpecularExtension {
2902
2943
 
2903
2944
  }
2904
2945
 
2905
- writeMaterial( material, materialDef ) {
2946
+ async writeMaterialAsync( material, materialDef ) {
2906
2947
 
2907
2948
  if ( ! material.isMeshPhysicalMaterial || ( material.specularIntensity === 1.0 &&
2908
2949
  material.specularColor.equals( DEFAULT_SPECULAR_COLOR ) &&
@@ -2916,7 +2957,7 @@ class GLTFMaterialsSpecularExtension {
2916
2957
  if ( material.specularIntensityMap ) {
2917
2958
 
2918
2959
  const specularIntensityMapDef = {
2919
- index: writer.processTexture( material.specularIntensityMap ),
2960
+ index: await writer.processTextureAsync( material.specularIntensityMap ),
2920
2961
  texCoord: material.specularIntensityMap.channel
2921
2962
  };
2922
2963
  writer.applyTextureTransform( specularIntensityMapDef, material.specularIntensityMap );
@@ -2927,7 +2968,7 @@ class GLTFMaterialsSpecularExtension {
2927
2968
  if ( material.specularColorMap ) {
2928
2969
 
2929
2970
  const specularColorMapDef = {
2930
- index: writer.processTexture( material.specularColorMap ),
2971
+ index: await writer.processTextureAsync( material.specularColorMap ),
2931
2972
  texCoord: material.specularColorMap.channel
2932
2973
  };
2933
2974
  writer.applyTextureTransform( specularColorMapDef, material.specularColorMap );
@@ -2961,7 +3002,7 @@ class GLTFMaterialsSheenExtension {
2961
3002
 
2962
3003
  }
2963
3004
 
2964
- writeMaterial( material, materialDef ) {
3005
+ async writeMaterialAsync( material, materialDef ) {
2965
3006
 
2966
3007
  if ( ! material.isMeshPhysicalMaterial || material.sheen == 0.0 ) return;
2967
3008
 
@@ -2973,7 +3014,7 @@ class GLTFMaterialsSheenExtension {
2973
3014
  if ( material.sheenRoughnessMap ) {
2974
3015
 
2975
3016
  const sheenRoughnessMapDef = {
2976
- index: writer.processTexture( material.sheenRoughnessMap ),
3017
+ index: await writer.processTextureAsync( material.sheenRoughnessMap ),
2977
3018
  texCoord: material.sheenRoughnessMap.channel
2978
3019
  };
2979
3020
  writer.applyTextureTransform( sheenRoughnessMapDef, material.sheenRoughnessMap );
@@ -2984,7 +3025,7 @@ class GLTFMaterialsSheenExtension {
2984
3025
  if ( material.sheenColorMap ) {
2985
3026
 
2986
3027
  const sheenColorMapDef = {
2987
- index: writer.processTexture( material.sheenColorMap ),
3028
+ index: await writer.processTextureAsync( material.sheenColorMap ),
2988
3029
  texCoord: material.sheenColorMap.channel
2989
3030
  };
2990
3031
  writer.applyTextureTransform( sheenColorMapDef, material.sheenColorMap );
@@ -3018,7 +3059,7 @@ class GLTFMaterialsAnisotropyExtension {
3018
3059
 
3019
3060
  }
3020
3061
 
3021
- writeMaterial( material, materialDef ) {
3062
+ async writeMaterialAsync( material, materialDef ) {
3022
3063
 
3023
3064
  if ( ! material.isMeshPhysicalMaterial || material.anisotropy == 0.0 ) return;
3024
3065
 
@@ -3029,7 +3070,7 @@ class GLTFMaterialsAnisotropyExtension {
3029
3070
 
3030
3071
  if ( material.anisotropyMap ) {
3031
3072
 
3032
- const anisotropyMapDef = { index: writer.processTexture( material.anisotropyMap ) };
3073
+ const anisotropyMapDef = { index: await writer.processTextureAsync( material.anisotropyMap ) };
3033
3074
  writer.applyTextureTransform( anisotropyMapDef, material.anisotropyMap );
3034
3075
  extensionDef.anisotropyTexture = anisotropyMapDef;
3035
3076
 
@@ -3061,7 +3102,7 @@ class GLTFMaterialsEmissiveStrengthExtension {
3061
3102
 
3062
3103
  }
3063
3104
 
3064
- writeMaterial( material, materialDef ) {
3105
+ async writeMaterialAsync( material, materialDef ) {
3065
3106
 
3066
3107
  if ( ! material.isMeshStandardMaterial || material.emissiveIntensity === 1.0 ) return;
3067
3108
 
@@ -3096,7 +3137,7 @@ class GLTFMaterialsBumpExtension {
3096
3137
 
3097
3138
  }
3098
3139
 
3099
- writeMaterial( material, materialDef ) {
3140
+ async writeMaterialAsync( material, materialDef ) {
3100
3141
 
3101
3142
  if ( ! material.isMeshStandardMaterial || (
3102
3143
  material.bumpScale === 1 &&
@@ -3110,7 +3151,7 @@ class GLTFMaterialsBumpExtension {
3110
3151
  if ( material.bumpMap ) {
3111
3152
 
3112
3153
  const bumpMapDef = {
3113
- index: writer.processTexture( material.bumpMap ),
3154
+ index: await writer.processTextureAsync( material.bumpMap ),
3114
3155
  texCoord: material.bumpMap.channel
3115
3156
  };
3116
3157
  writer.applyTextureTransform( bumpMapDef, material.bumpMap );
@@ -3382,6 +3423,32 @@ GLTFExporter.Utils = {
3382
3423
 
3383
3424
  return clip;
3384
3425
 
3426
+ },
3427
+
3428
+ toFloat32BufferAttribute: function ( srcAttribute ) {
3429
+
3430
+ const dstAttribute = new BufferAttribute( new Float32Array( srcAttribute.count * srcAttribute.itemSize ), srcAttribute.itemSize, false );
3431
+
3432
+ if ( ! srcAttribute.normalized && ! srcAttribute.isInterleavedBufferAttribute ) {
3433
+
3434
+ dstAttribute.array.set( srcAttribute.array );
3435
+
3436
+ return dstAttribute;
3437
+
3438
+ }
3439
+
3440
+ for ( let i = 0, il = srcAttribute.count; i < il; i ++ ) {
3441
+
3442
+ for ( let j = 0; j < srcAttribute.itemSize; j ++ ) {
3443
+
3444
+ dstAttribute.setComponent( i, j, srcAttribute.getComponent( i, j ) );
3445
+
3446
+ }
3447
+
3448
+ }
3449
+
3450
+ return dstAttribute;
3451
+
3385
3452
  }
3386
3453
 
3387
3454
  };