@anov/3d 0.0.4-alpha.1 → 0.0.4-alpha13

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 (588) hide show
  1. package/README.md +1 -144
  2. package/dist/applicationApi.d.ts +34 -0
  3. package/dist/{core/cssRenderer.js → applicationApi.js} +53 -21
  4. package/dist/environment/index.d.ts +27 -0
  5. package/dist/environment/index.js +84 -0
  6. package/dist/environment/time/index.d.ts +12 -0
  7. package/dist/environment/time/index.js +27 -0
  8. package/dist/environment/weather/type.d.ts +15 -0
  9. package/dist/environment/weather/type.js +27 -0
  10. package/dist/hooksManager.d.ts +2 -0
  11. package/dist/hooksManager.js +15 -0
  12. package/dist/index.d.ts +15 -3
  13. package/dist/index.js +38 -5
  14. package/dist/messageStatus.d.ts +49 -0
  15. package/dist/messageStatus.js +50 -0
  16. package/dist/utils/index.d.ts +11 -50
  17. package/dist/utils/index.js +29 -92
  18. package/dist/utils/messageFn.d.ts +12 -0
  19. package/dist/utils/messageFn.js +33 -0
  20. package/package.json +8 -24
  21. package/dist/commonEnu.d.ts +0 -5
  22. package/dist/commonEnu.js +0 -6
  23. package/dist/core/camera.d.ts +0 -32
  24. package/dist/core/camera.js +0 -74
  25. package/dist/core/control/transformControls.d.ts +0 -12
  26. package/dist/core/control/transformControls.js +0 -72
  27. package/dist/core/cssRenderer.d.ts +0 -17
  28. package/dist/core/events.d.ts +0 -16
  29. package/dist/core/events.js +0 -38
  30. package/dist/core/global/global.d.ts +0 -27
  31. package/dist/core/global/global.js +0 -72
  32. package/dist/core/global/globalControl.d.ts +0 -17
  33. package/dist/core/global/globalControl.js +0 -62
  34. package/dist/core/group.d.ts +0 -57
  35. package/dist/core/group.js +0 -157
  36. package/dist/core/line.d.ts +0 -13
  37. package/dist/core/line.js +0 -83
  38. package/dist/core/mesh.d.ts +0 -59
  39. package/dist/core/mesh.js +0 -180
  40. package/dist/core/model.d.ts +0 -30
  41. package/dist/core/model.js +0 -109
  42. package/dist/core/scene.d.ts +0 -175
  43. package/dist/core/scene.js +0 -381
  44. package/dist/core/use/useScene.d.ts +0 -10
  45. package/dist/core/use/useScene.js +0 -14
  46. package/dist/core/use/useframe.d.ts +0 -6
  47. package/dist/core/use/useframe.js +0 -11
  48. package/dist/export.d.ts +0 -40
  49. package/dist/export.js +0 -36
  50. package/dist/threeCell.d.ts +0 -8
  51. package/dist/threeCell.js +0 -16
  52. package/dist/type.d.ts +0 -3
  53. package/dist/type.js +0 -1
  54. package/dist/utils/createElement.d.ts +0 -103
  55. package/dist/utils/createElement.js +0 -145
  56. package/dist/utils/createLabel.d.ts +0 -2
  57. package/dist/utils/createLabel.js +0 -4
  58. package/dist/utils/line.d.ts +0 -0
  59. package/dist/utils/line.js +0 -0
  60. package/dist/utils/move.d.ts +0 -48
  61. package/dist/utils/move.js +0 -149
  62. package/examples/fonts/LICENSE +0 -13
  63. package/examples/fonts/README.md +0 -11
  64. package/examples/fonts/droid/NOTICE +0 -190
  65. package/examples/fonts/droid/README.txt +0 -18
  66. package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
  67. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
  68. package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
  69. package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
  70. package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
  71. package/examples/fonts/gentilis_bold.typeface.json +0 -1
  72. package/examples/fonts/gentilis_regular.typeface.json +0 -1
  73. package/examples/fonts/helvetiker_bold.typeface.json +0 -1
  74. package/examples/fonts/helvetiker_regular.typeface.json +0 -1
  75. package/examples/fonts/optimer_bold.typeface.json +0 -1
  76. package/examples/fonts/optimer_regular.typeface.json +0 -1
  77. package/examples/fonts/ttf/README.md +0 -9
  78. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  79. package/examples/jsm/animation/AnimationClipCreator.js +0 -116
  80. package/examples/jsm/animation/CCDIKSolver.js +0 -482
  81. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  82. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  83. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  84. package/examples/jsm/capabilities/WebGL.js +0 -91
  85. package/examples/jsm/capabilities/WebGPU.js +0 -53
  86. package/examples/jsm/controls/ArcballControls.js +0 -3224
  87. package/examples/jsm/controls/DragControls.js +0 -220
  88. package/examples/jsm/controls/FirstPersonControls.js +0 -325
  89. package/examples/jsm/controls/FlyControls.js +0 -300
  90. package/examples/jsm/controls/MapControls.js +0 -28
  91. package/examples/jsm/controls/OrbitControls.js +0 -1388
  92. package/examples/jsm/controls/PointerLockControls.js +0 -162
  93. package/examples/jsm/controls/TrackballControls.js +0 -828
  94. package/examples/jsm/controls/TransformControls.js +0 -1557
  95. package/examples/jsm/csm/CSM.js +0 -384
  96. package/examples/jsm/csm/CSMFrustum.js +0 -152
  97. package/examples/jsm/csm/CSMHelper.js +0 -193
  98. package/examples/jsm/csm/CSMShader.js +0 -252
  99. package/examples/jsm/curves/CurveExtras.js +0 -422
  100. package/examples/jsm/curves/NURBSCurve.js +0 -80
  101. package/examples/jsm/curves/NURBSSurface.js +0 -52
  102. package/examples/jsm/curves/NURBSUtils.js +0 -487
  103. package/examples/jsm/effects/AnaglyphEffect.js +0 -154
  104. package/examples/jsm/effects/AsciiEffect.js +0 -263
  105. package/examples/jsm/effects/OutlineEffect.js +0 -539
  106. package/examples/jsm/effects/ParallaxBarrierEffect.js +0 -119
  107. package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
  108. package/examples/jsm/effects/StereoEffect.js +0 -55
  109. package/examples/jsm/environments/DebugEnvironment.js +0 -52
  110. package/examples/jsm/environments/RoomEnvironment.js +0 -148
  111. package/examples/jsm/exporters/DRACOExporter.js +0 -267
  112. package/examples/jsm/exporters/EXRExporter.js +0 -501
  113. package/examples/jsm/exporters/GLTFExporter.js +0 -3161
  114. package/examples/jsm/exporters/KTX2Exporter.js +0 -292
  115. package/examples/jsm/exporters/MMDExporter.js +0 -217
  116. package/examples/jsm/exporters/OBJExporter.js +0 -284
  117. package/examples/jsm/exporters/PLYExporter.js +0 -528
  118. package/examples/jsm/exporters/STLExporter.js +0 -199
  119. package/examples/jsm/exporters/USDZExporter.js +0 -711
  120. package/examples/jsm/geometries/BoxLineGeometry.js +0 -69
  121. package/examples/jsm/geometries/ConvexGeometry.js +0 -53
  122. package/examples/jsm/geometries/DecalGeometry.js +0 -356
  123. package/examples/jsm/geometries/ParametricGeometries.js +0 -254
  124. package/examples/jsm/geometries/ParametricGeometry.js +0 -139
  125. package/examples/jsm/geometries/RoundedBoxGeometry.js +0 -155
  126. package/examples/jsm/geometries/TeapotGeometry.js +0 -704
  127. package/examples/jsm/geometries/TextGeometry.js +0 -57
  128. package/examples/jsm/helpers/LightProbeHelper.js +0 -130
  129. package/examples/jsm/helpers/OctreeHelper.js +0 -73
  130. package/examples/jsm/helpers/PositionalAudioHelper.js +0 -109
  131. package/examples/jsm/helpers/RectAreaLightHelper.js +0 -85
  132. package/examples/jsm/helpers/VertexNormalsHelper.js +0 -96
  133. package/examples/jsm/helpers/VertexTangentsHelper.js +0 -88
  134. package/examples/jsm/helpers/ViewHelper.js +0 -333
  135. package/examples/jsm/interactive/HTMLMesh.js +0 -565
  136. package/examples/jsm/interactive/InteractiveGroup.js +0 -116
  137. package/examples/jsm/interactive/SelectionBox.js +0 -227
  138. package/examples/jsm/interactive/SelectionHelper.js +0 -104
  139. package/examples/jsm/libs/ammo.wasm.js +0 -822
  140. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  141. package/examples/jsm/libs/basis/README.md +0 -46
  142. package/examples/jsm/libs/basis/basis_transcoder.js +0 -21
  143. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  144. package/examples/jsm/libs/chevrotain.module.min.js +0 -141
  145. package/examples/jsm/libs/draco/README.md +0 -32
  146. package/examples/jsm/libs/draco/draco_decoder.js +0 -34
  147. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  148. package/examples/jsm/libs/draco/draco_encoder.js +0 -33
  149. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +0 -117
  150. package/examples/jsm/libs/draco/gltf/draco_decoder.js +0 -33
  151. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  152. package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
  153. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +0 -116
  154. package/examples/jsm/libs/ecsy.module.js +0 -1792
  155. package/examples/jsm/libs/fflate.module.js +0 -2474
  156. package/examples/jsm/libs/ktx-parse.module.js +0 -1
  157. package/examples/jsm/libs/lil-gui.module.min.js +0 -8
  158. package/examples/jsm/libs/lottie_canvas.module.js +0 -14844
  159. package/examples/jsm/libs/meshopt_decoder.module.js +0 -178
  160. package/examples/jsm/libs/mikktspace.module.js +0 -128
  161. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  162. package/examples/jsm/libs/motion-controllers.module.js +0 -397
  163. package/examples/jsm/libs/opentype.module.js +0 -14568
  164. package/examples/jsm/libs/potpack.module.js +0 -125
  165. package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
  166. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
  167. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  168. package/examples/jsm/libs/stats.module.js +0 -167
  169. package/examples/jsm/libs/tween.module.js +0 -803
  170. package/examples/jsm/libs/utif.module.js +0 -1579
  171. package/examples/jsm/libs/zstddec.module.js +0 -1
  172. package/examples/jsm/lights/IESSpotLight.js +0 -25
  173. package/examples/jsm/lights/LightProbeGenerator.js +0 -252
  174. package/examples/jsm/lights/RectAreaLightUniformsLib.js +0 -79
  175. package/examples/jsm/lines/Line2.js +0 -19
  176. package/examples/jsm/lines/LineGeometry.js +0 -79
  177. package/examples/jsm/lines/LineMaterial.js +0 -702
  178. package/examples/jsm/lines/LineSegments2.js +0 -361
  179. package/examples/jsm/lines/LineSegmentsGeometry.js +0 -241
  180. package/examples/jsm/lines/Wireframe.js +0 -56
  181. package/examples/jsm/lines/WireframeGeometry2.js +0 -24
  182. package/examples/jsm/loaders/3DMLoader.js +0 -1497
  183. package/examples/jsm/loaders/3MFLoader.js +0 -1478
  184. package/examples/jsm/loaders/AMFLoader.js +0 -521
  185. package/examples/jsm/loaders/BVHLoader.js +0 -437
  186. package/examples/jsm/loaders/ColladaLoader.js +0 -4122
  187. package/examples/jsm/loaders/DDSLoader.js +0 -274
  188. package/examples/jsm/loaders/DRACOLoader.js +0 -612
  189. package/examples/jsm/loaders/EXRLoader.js +0 -2309
  190. package/examples/jsm/loaders/FBXLoader.js +0 -4142
  191. package/examples/jsm/loaders/FontLoader.js +0 -183
  192. package/examples/jsm/loaders/GCodeLoader.js +0 -261
  193. package/examples/jsm/loaders/GLTFLoader.js +0 -4576
  194. package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -115
  195. package/examples/jsm/loaders/IESLoader.js +0 -337
  196. package/examples/jsm/loaders/KMZLoader.js +0 -130
  197. package/examples/jsm/loaders/KTX2Loader.js +0 -868
  198. package/examples/jsm/loaders/KTXLoader.js +0 -176
  199. package/examples/jsm/loaders/LDrawLoader.js +0 -2464
  200. package/examples/jsm/loaders/LUT3dlLoader.js +0 -151
  201. package/examples/jsm/loaders/LUTCubeLoader.js +0 -153
  202. package/examples/jsm/loaders/LWOLoader.js +0 -1052
  203. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  204. package/examples/jsm/loaders/LottieLoader.js +0 -77
  205. package/examples/jsm/loaders/MD2Loader.js +0 -399
  206. package/examples/jsm/loaders/MDDLoader.js +0 -102
  207. package/examples/jsm/loaders/MMDLoader.js +0 -2273
  208. package/examples/jsm/loaders/MTLLoader.js +0 -567
  209. package/examples/jsm/loaders/MaterialXLoader.js +0 -734
  210. package/examples/jsm/loaders/NRRDLoader.js +0 -699
  211. package/examples/jsm/loaders/OBJLoader.js +0 -905
  212. package/examples/jsm/loaders/PCDLoader.js +0 -467
  213. package/examples/jsm/loaders/PDBLoader.js +0 -232
  214. package/examples/jsm/loaders/PLYLoader.js +0 -771
  215. package/examples/jsm/loaders/PVRLoader.js +0 -251
  216. package/examples/jsm/loaders/RGBELoader.js +0 -468
  217. package/examples/jsm/loaders/RGBMLoader.js +0 -1065
  218. package/examples/jsm/loaders/STLLoader.js +0 -403
  219. package/examples/jsm/loaders/SVGLoader.js +0 -3172
  220. package/examples/jsm/loaders/TDSLoader.js +0 -1124
  221. package/examples/jsm/loaders/TGALoader.js +0 -517
  222. package/examples/jsm/loaders/TIFFLoader.js +0 -36
  223. package/examples/jsm/loaders/TTFLoader.js +0 -214
  224. package/examples/jsm/loaders/TiltLoader.js +0 -520
  225. package/examples/jsm/loaders/USDZLoader.js +0 -633
  226. package/examples/jsm/loaders/VOXLoader.js +0 -311
  227. package/examples/jsm/loaders/VRMLLoader.js +0 -3533
  228. package/examples/jsm/loaders/VTKLoader.js +0 -1163
  229. package/examples/jsm/loaders/XYZLoader.js +0 -106
  230. package/examples/jsm/loaders/lwo/IFFParser.js +0 -1218
  231. package/examples/jsm/loaders/lwo/LWO2Parser.js +0 -414
  232. package/examples/jsm/loaders/lwo/LWO3Parser.js +0 -373
  233. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -420
  234. package/examples/jsm/math/Capsule.js +0 -137
  235. package/examples/jsm/math/ColorConverter.js +0 -36
  236. package/examples/jsm/math/ConvexHull.js +0 -1271
  237. package/examples/jsm/math/ImprovedNoise.js +0 -71
  238. package/examples/jsm/math/Lut.js +0 -204
  239. package/examples/jsm/math/MeshSurfaceSampler.js +0 -250
  240. package/examples/jsm/math/OBB.js +0 -423
  241. package/examples/jsm/math/Octree.js +0 -462
  242. package/examples/jsm/math/SimplexNoise.js +0 -444
  243. package/examples/jsm/misc/ConvexObjectBreaker.js +0 -519
  244. package/examples/jsm/misc/GPUComputationRenderer.js +0 -446
  245. package/examples/jsm/misc/Gyroscope.js +0 -66
  246. package/examples/jsm/misc/MD2Character.js +0 -276
  247. package/examples/jsm/misc/MD2CharacterComplex.js +0 -576
  248. package/examples/jsm/misc/MorphAnimMesh.js +0 -75
  249. package/examples/jsm/misc/MorphBlendMesh.js +0 -322
  250. package/examples/jsm/misc/ProgressiveLightMap.js +0 -323
  251. package/examples/jsm/misc/RollerCoaster.js +0 -566
  252. package/examples/jsm/misc/TubePainter.js +0 -205
  253. package/examples/jsm/misc/Volume.js +0 -473
  254. package/examples/jsm/misc/VolumeSlice.js +0 -229
  255. package/examples/jsm/modifiers/CurveModifier.js +0 -326
  256. package/examples/jsm/modifiers/EdgeSplitModifier.js +0 -279
  257. package/examples/jsm/modifiers/SimplifyModifier.js +0 -525
  258. package/examples/jsm/modifiers/TessellateModifier.js +0 -307
  259. package/examples/jsm/nodes/Nodes.js +0 -171
  260. package/examples/jsm/nodes/accessors/BitangentNode.js +0 -89
  261. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +0 -99
  262. package/examples/jsm/nodes/accessors/BufferNode.js +0 -30
  263. package/examples/jsm/nodes/accessors/CameraNode.js +0 -98
  264. package/examples/jsm/nodes/accessors/CubeTextureNode.js +0 -103
  265. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -77
  266. package/examples/jsm/nodes/accessors/InstanceNode.js +0 -71
  267. package/examples/jsm/nodes/accessors/MaterialNode.js +0 -267
  268. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +0 -39
  269. package/examples/jsm/nodes/accessors/ModelNode.js +0 -34
  270. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +0 -29
  271. package/examples/jsm/nodes/accessors/MorphNode.js +0 -70
  272. package/examples/jsm/nodes/accessors/NormalNode.js +0 -96
  273. package/examples/jsm/nodes/accessors/Object3DNode.js +0 -150
  274. package/examples/jsm/nodes/accessors/PointUVNode.js +0 -26
  275. package/examples/jsm/nodes/accessors/PositionNode.js +0 -104
  276. package/examples/jsm/nodes/accessors/ReferenceNode.js +0 -72
  277. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +0 -35
  278. package/examples/jsm/nodes/accessors/SceneNode.js +0 -52
  279. package/examples/jsm/nodes/accessors/SkinningNode.js +0 -93
  280. package/examples/jsm/nodes/accessors/StorageBufferNode.js +0 -27
  281. package/examples/jsm/nodes/accessors/TangentNode.js +0 -103
  282. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +0 -94
  283. package/examples/jsm/nodes/accessors/TextureNode.js +0 -271
  284. package/examples/jsm/nodes/accessors/TextureSizeNode.js +0 -35
  285. package/examples/jsm/nodes/accessors/UVNode.js +0 -47
  286. package/examples/jsm/nodes/accessors/UserDataNode.js +0 -29
  287. package/examples/jsm/nodes/code/CodeNode.js +0 -78
  288. package/examples/jsm/nodes/code/ExpressionNode.js +0 -37
  289. package/examples/jsm/nodes/code/FunctionCallNode.js +0 -96
  290. package/examples/jsm/nodes/code/FunctionNode.js +0 -127
  291. package/examples/jsm/nodes/code/ScriptableNode.js +0 -488
  292. package/examples/jsm/nodes/code/ScriptableValueNode.js +0 -167
  293. package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
  294. package/examples/jsm/nodes/core/AttributeNode.js +0 -102
  295. package/examples/jsm/nodes/core/BypassNode.js +0 -45
  296. package/examples/jsm/nodes/core/CacheNode.js +0 -46
  297. package/examples/jsm/nodes/core/ConstNode.js +0 -32
  298. package/examples/jsm/nodes/core/ContextNode.js +0 -61
  299. package/examples/jsm/nodes/core/IndexNode.js +0 -66
  300. package/examples/jsm/nodes/core/InputNode.js +0 -83
  301. package/examples/jsm/nodes/core/LightingModel.js +0 -15
  302. package/examples/jsm/nodes/core/Node.js +0 -454
  303. package/examples/jsm/nodes/core/NodeAttribute.js +0 -15
  304. package/examples/jsm/nodes/core/NodeBuilder.js +0 -1016
  305. package/examples/jsm/nodes/core/NodeCache.js +0 -26
  306. package/examples/jsm/nodes/core/NodeCode.js +0 -15
  307. package/examples/jsm/nodes/core/NodeFrame.js +0 -110
  308. package/examples/jsm/nodes/core/NodeFunction.js +0 -22
  309. package/examples/jsm/nodes/core/NodeFunctionInput.js +0 -17
  310. package/examples/jsm/nodes/core/NodeKeywords.js +0 -80
  311. package/examples/jsm/nodes/core/NodeParser.js +0 -11
  312. package/examples/jsm/nodes/core/NodeUniform.js +0 -28
  313. package/examples/jsm/nodes/core/NodeUtils.js +0 -212
  314. package/examples/jsm/nodes/core/NodeVar.js +0 -14
  315. package/examples/jsm/nodes/core/NodeVarying.js +0 -17
  316. package/examples/jsm/nodes/core/PropertyNode.js +0 -61
  317. package/examples/jsm/nodes/core/StackNode.js +0 -99
  318. package/examples/jsm/nodes/core/TempNode.js +0 -58
  319. package/examples/jsm/nodes/core/UniformNode.js +0 -61
  320. package/examples/jsm/nodes/core/VarNode.js +0 -87
  321. package/examples/jsm/nodes/core/VaryingNode.js +0 -69
  322. package/examples/jsm/nodes/core/constants.js +0 -27
  323. package/examples/jsm/nodes/display/BlendModeNode.js +0 -99
  324. package/examples/jsm/nodes/display/BumpMapNode.js +0 -77
  325. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +0 -100
  326. package/examples/jsm/nodes/display/ColorSpaceNode.js +0 -108
  327. package/examples/jsm/nodes/display/FrontFacingNode.js +0 -27
  328. package/examples/jsm/nodes/display/NormalMapNode.js +0 -106
  329. package/examples/jsm/nodes/display/PosterizeNode.js +0 -32
  330. package/examples/jsm/nodes/display/ToneMappingNode.js +0 -141
  331. package/examples/jsm/nodes/display/ViewportDepthNode.js +0 -69
  332. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +0 -34
  333. package/examples/jsm/nodes/display/ViewportNode.js +0 -115
  334. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +0 -31
  335. package/examples/jsm/nodes/display/ViewportTextureNode.js +0 -75
  336. package/examples/jsm/nodes/fog/FogExp2Node.js +0 -35
  337. package/examples/jsm/nodes/fog/FogNode.js +0 -37
  338. package/examples/jsm/nodes/fog/FogRangeNode.js +0 -34
  339. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +0 -40
  340. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +0 -9
  341. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +0 -43
  342. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +0 -29
  343. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +0 -18
  344. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +0 -13
  345. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +0 -16
  346. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +0 -13
  347. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +0 -20
  348. package/examples/jsm/nodes/functions/PhongLightingModel.js +0 -67
  349. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +0 -343
  350. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +0 -13
  351. package/examples/jsm/nodes/functions/material/getRoughness.js +0 -18
  352. package/examples/jsm/nodes/geometry/RangeNode.js +0 -104
  353. package/examples/jsm/nodes/gpgpu/ComputeNode.js +0 -85
  354. package/examples/jsm/nodes/lighting/AONode.js +0 -27
  355. package/examples/jsm/nodes/lighting/AmbientLightNode.js +0 -27
  356. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +0 -184
  357. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +0 -40
  358. package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -191
  359. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +0 -55
  360. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +0 -39
  361. package/examples/jsm/nodes/lighting/LightNode.js +0 -57
  362. package/examples/jsm/nodes/lighting/LightUtils.js +0 -17
  363. package/examples/jsm/nodes/lighting/LightingContextNode.js +0 -102
  364. package/examples/jsm/nodes/lighting/LightingNode.js +0 -21
  365. package/examples/jsm/nodes/lighting/LightsNode.js +0 -128
  366. package/examples/jsm/nodes/lighting/PointLightNode.js +0 -68
  367. package/examples/jsm/nodes/lighting/SpotLightNode.js +0 -89
  368. package/examples/jsm/nodes/loaders/NodeLoader.js +0 -108
  369. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +0 -59
  370. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +0 -70
  371. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -28
  372. package/examples/jsm/nodes/materials/Materials.js +0 -12
  373. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -27
  374. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +0 -34
  375. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  376. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -65
  377. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +0 -128
  378. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +0 -80
  379. package/examples/jsm/nodes/materials/NodeMaterial.js +0 -536
  380. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -49
  381. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -103
  382. package/examples/jsm/nodes/materialx/DISCLAIMER.md +0 -199
  383. package/examples/jsm/nodes/materialx/MaterialXNodes.js +0 -68
  384. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +0 -56
  385. package/examples/jsm/nodes/materialx/lib/mx_noise.js +0 -618
  386. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +0 -19
  387. package/examples/jsm/nodes/math/CondNode.js +0 -86
  388. package/examples/jsm/nodes/math/MathNode.js +0 -359
  389. package/examples/jsm/nodes/math/OperatorNode.js +0 -269
  390. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +0 -152
  391. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +0 -14
  392. package/examples/jsm/nodes/procedural/CheckerNode.js +0 -42
  393. package/examples/jsm/nodes/shadernode/ShaderNode.js +0 -420
  394. package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -33
  395. package/examples/jsm/nodes/utils/ConvertNode.js +0 -65
  396. package/examples/jsm/nodes/utils/DiscardNode.js +0 -26
  397. package/examples/jsm/nodes/utils/EquirectUVNode.js +0 -33
  398. package/examples/jsm/nodes/utils/JoinNode.js +0 -51
  399. package/examples/jsm/nodes/utils/LoopNode.js +0 -186
  400. package/examples/jsm/nodes/utils/MatcapUVNode.js +0 -30
  401. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +0 -46
  402. package/examples/jsm/nodes/utils/OscNode.js +0 -81
  403. package/examples/jsm/nodes/utils/PackingNode.js +0 -55
  404. package/examples/jsm/nodes/utils/RemapNode.js +0 -42
  405. package/examples/jsm/nodes/utils/RotateUVNode.js +0 -43
  406. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  407. package/examples/jsm/nodes/utils/SplitNode.js +0 -104
  408. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +0 -41
  409. package/examples/jsm/nodes/utils/TimerNode.js +0 -94
  410. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +0 -62
  411. package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
  412. package/examples/jsm/objects/Lensflare.js +0 -377
  413. package/examples/jsm/objects/MarchingCubes.js +0 -1176
  414. package/examples/jsm/objects/Reflector.js +0 -264
  415. package/examples/jsm/objects/ReflectorForSSRPass.js +0 -349
  416. package/examples/jsm/objects/Refractor.js +0 -324
  417. package/examples/jsm/objects/ShadowMesh.js +0 -80
  418. package/examples/jsm/objects/Sky.js +0 -219
  419. package/examples/jsm/objects/Water.js +0 -330
  420. package/examples/jsm/objects/Water2.js +0 -358
  421. package/examples/jsm/offscreen/jank.js +0 -45
  422. package/examples/jsm/offscreen/offscreen.js +0 -8
  423. package/examples/jsm/offscreen/scene.js +0 -86
  424. package/examples/jsm/physics/AmmoPhysics.js +0 -285
  425. package/examples/jsm/physics/RapierPhysics.js +0 -199
  426. package/examples/jsm/postprocessing/AfterimagePass.js +0 -104
  427. package/examples/jsm/postprocessing/BloomPass.js +0 -172
  428. package/examples/jsm/postprocessing/BokehPass.js +0 -140
  429. package/examples/jsm/postprocessing/ClearPass.js +0 -46
  430. package/examples/jsm/postprocessing/CubeTexturePass.js +0 -85
  431. package/examples/jsm/postprocessing/DotScreenPass.js +0 -65
  432. package/examples/jsm/postprocessing/EffectComposer.js +0 -231
  433. package/examples/jsm/postprocessing/FilmPass.js +0 -66
  434. package/examples/jsm/postprocessing/GlitchPass.js +0 -128
  435. package/examples/jsm/postprocessing/HalftonePass.js +0 -79
  436. package/examples/jsm/postprocessing/LUTPass.js +0 -173
  437. package/examples/jsm/postprocessing/MaskPass.js +0 -104
  438. package/examples/jsm/postprocessing/OutlinePass.js +0 -654
  439. package/examples/jsm/postprocessing/OutputPass.js +0 -91
  440. package/examples/jsm/postprocessing/Pass.js +0 -84
  441. package/examples/jsm/postprocessing/RenderPass.js +0 -81
  442. package/examples/jsm/postprocessing/RenderPixelatedPass.js +0 -235
  443. package/examples/jsm/postprocessing/SAOPass.js +0 -411
  444. package/examples/jsm/postprocessing/SMAAPass.js +0 -201
  445. package/examples/jsm/postprocessing/SSAARenderPass.js +0 -228
  446. package/examples/jsm/postprocessing/SSAOPass.js +0 -440
  447. package/examples/jsm/postprocessing/SSRPass.js +0 -641
  448. package/examples/jsm/postprocessing/SavePass.js +0 -79
  449. package/examples/jsm/postprocessing/ShaderPass.js +0 -77
  450. package/examples/jsm/postprocessing/TAARenderPass.js +0 -189
  451. package/examples/jsm/postprocessing/TexturePass.js +0 -67
  452. package/examples/jsm/postprocessing/UnrealBloomPass.js +0 -415
  453. package/examples/jsm/renderers/CSS2DRenderer.js +0 -215
  454. package/examples/jsm/renderers/CSS3DRenderer.js +0 -335
  455. package/examples/jsm/renderers/Projector.js +0 -918
  456. package/examples/jsm/renderers/SVGRenderer.js +0 -553
  457. package/examples/jsm/renderers/common/Animation.js +0 -58
  458. package/examples/jsm/renderers/common/Attributes.js +0 -75
  459. package/examples/jsm/renderers/common/Backend.js +0 -162
  460. package/examples/jsm/renderers/common/Background.js +0 -136
  461. package/examples/jsm/renderers/common/Binding.js +0 -19
  462. package/examples/jsm/renderers/common/Bindings.js +0 -165
  463. package/examples/jsm/renderers/common/Buffer.js +0 -38
  464. package/examples/jsm/renderers/common/BufferUtils.js +0 -33
  465. package/examples/jsm/renderers/common/ChainMap.js +0 -89
  466. package/examples/jsm/renderers/common/ComputePipeline.js +0 -17
  467. package/examples/jsm/renderers/common/Constants.js +0 -14
  468. package/examples/jsm/renderers/common/CubeRenderTarget.js +0 -65
  469. package/examples/jsm/renderers/common/DataMap.js +0 -54
  470. package/examples/jsm/renderers/common/Geometries.js +0 -215
  471. package/examples/jsm/renderers/common/Info.js +0 -73
  472. package/examples/jsm/renderers/common/Pipeline.js +0 -13
  473. package/examples/jsm/renderers/common/Pipelines.js +0 -370
  474. package/examples/jsm/renderers/common/ProgrammableStage.js +0 -18
  475. package/examples/jsm/renderers/common/RenderContext.js +0 -38
  476. package/examples/jsm/renderers/common/RenderContexts.js +0 -49
  477. package/examples/jsm/renderers/common/RenderList.js +0 -178
  478. package/examples/jsm/renderers/common/RenderLists.js +0 -38
  479. package/examples/jsm/renderers/common/RenderObject.js +0 -129
  480. package/examples/jsm/renderers/common/RenderObjects.js +0 -95
  481. package/examples/jsm/renderers/common/RenderPipeline.js +0 -16
  482. package/examples/jsm/renderers/common/Renderer.js +0 -895
  483. package/examples/jsm/renderers/common/SampledTexture.js +0 -80
  484. package/examples/jsm/renderers/common/Sampler.js +0 -18
  485. package/examples/jsm/renderers/common/StorageBuffer.js +0 -17
  486. package/examples/jsm/renderers/common/Textures.js +0 -218
  487. package/examples/jsm/renderers/common/Uniform.js +0 -140
  488. package/examples/jsm/renderers/common/UniformBuffer.js +0 -15
  489. package/examples/jsm/renderers/common/UniformsGroup.js +0 -299
  490. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +0 -39
  491. package/examples/jsm/renderers/common/nodes/NodeSampler.js +0 -21
  492. package/examples/jsm/renderers/common/nodes/NodeUniform.js +0 -135
  493. package/examples/jsm/renderers/common/nodes/Nodes.js +0 -330
  494. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +0 -340
  495. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +0 -26
  496. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +0 -764
  497. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +0 -49
  498. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +0 -844
  499. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +0 -32
  500. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +0 -902
  501. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +0 -104
  502. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +0 -14
  503. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +0 -274
  504. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +0 -223
  505. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +0 -324
  506. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +0 -533
  507. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
  508. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +0 -964
  509. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +0 -92
  510. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +0 -87
  511. package/examples/jsm/shaders/AfterimageShader.js +0 -56
  512. package/examples/jsm/shaders/BasicShader.js +0 -27
  513. package/examples/jsm/shaders/BleachBypassShader.js +0 -62
  514. package/examples/jsm/shaders/BlendShader.js +0 -47
  515. package/examples/jsm/shaders/BokehShader.js +0 -143
  516. package/examples/jsm/shaders/BokehShader2.js +0 -393
  517. package/examples/jsm/shaders/BrightnessContrastShader.js +0 -54
  518. package/examples/jsm/shaders/ColorCorrectionShader.js +0 -50
  519. package/examples/jsm/shaders/ColorifyShader.js +0 -51
  520. package/examples/jsm/shaders/ConvolutionShader.js +0 -103
  521. package/examples/jsm/shaders/CopyShader.js +0 -45
  522. package/examples/jsm/shaders/DOFMipMapShader.js +0 -54
  523. package/examples/jsm/shaders/DepthLimitedBlurShader.js +0 -166
  524. package/examples/jsm/shaders/DigitalGlitch.js +0 -101
  525. package/examples/jsm/shaders/DotScreenShader.js +0 -70
  526. package/examples/jsm/shaders/ExposureShader.js +0 -44
  527. package/examples/jsm/shaders/FXAAShader.js +0 -286
  528. package/examples/jsm/shaders/FilmShader.js +0 -102
  529. package/examples/jsm/shaders/FocusShader.js +0 -87
  530. package/examples/jsm/shaders/FreiChenShader.js +0 -94
  531. package/examples/jsm/shaders/GammaCorrectionShader.js +0 -43
  532. package/examples/jsm/shaders/GodRaysShader.js +0 -313
  533. package/examples/jsm/shaders/HalftoneShader.js +0 -310
  534. package/examples/jsm/shaders/HorizontalBlurShader.js +0 -59
  535. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +0 -61
  536. package/examples/jsm/shaders/HueSaturationShader.js +0 -65
  537. package/examples/jsm/shaders/KaleidoShader.js +0 -56
  538. package/examples/jsm/shaders/LuminosityHighPassShader.js +0 -64
  539. package/examples/jsm/shaders/LuminosityShader.js +0 -46
  540. package/examples/jsm/shaders/MMDToonShader.js +0 -132
  541. package/examples/jsm/shaders/MirrorShader.js +0 -54
  542. package/examples/jsm/shaders/NormalMapShader.js +0 -53
  543. package/examples/jsm/shaders/OutputShader.js +0 -78
  544. package/examples/jsm/shaders/RGBShiftShader.js +0 -54
  545. package/examples/jsm/shaders/SAOShader.js +0 -188
  546. package/examples/jsm/shaders/SMAAShader.js +0 -460
  547. package/examples/jsm/shaders/SSAOShader.js +0 -288
  548. package/examples/jsm/shaders/SSRShader.js +0 -364
  549. package/examples/jsm/shaders/SepiaShader.js +0 -52
  550. package/examples/jsm/shaders/SobelOperatorShader.js +0 -90
  551. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +0 -88
  552. package/examples/jsm/shaders/TechnicolorShader.js +0 -43
  553. package/examples/jsm/shaders/ToonShader.js +0 -326
  554. package/examples/jsm/shaders/TriangleBlurShader.js +0 -72
  555. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +0 -45
  556. package/examples/jsm/shaders/VelocityShader.js +0 -128
  557. package/examples/jsm/shaders/VerticalBlurShader.js +0 -59
  558. package/examples/jsm/shaders/VerticalTiltShiftShader.js +0 -61
  559. package/examples/jsm/shaders/VignetteShader.js +0 -51
  560. package/examples/jsm/shaders/VolumeShader.js +0 -289
  561. package/examples/jsm/shaders/WaterRefractionShader.js +0 -93
  562. package/examples/jsm/textures/FlakesTexture.js +0 -40
  563. package/examples/jsm/utils/BufferGeometryUtils.js +0 -1373
  564. package/examples/jsm/utils/CameraUtils.js +0 -73
  565. package/examples/jsm/utils/GPUStatsPanel.js +0 -128
  566. package/examples/jsm/utils/GeometryCompressionUtils.js +0 -639
  567. package/examples/jsm/utils/GeometryUtils.js +0 -221
  568. package/examples/jsm/utils/LDrawUtils.js +0 -202
  569. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  570. package/examples/jsm/utils/SceneUtils.js +0 -254
  571. package/examples/jsm/utils/ShadowMapViewer.js +0 -210
  572. package/examples/jsm/utils/SkeletonUtils.js +0 -413
  573. package/examples/jsm/utils/TextureUtils.js +0 -86
  574. package/examples/jsm/utils/UVsDebug.js +0 -165
  575. package/examples/jsm/utils/WorkerPool.js +0 -102
  576. package/examples/jsm/webxr/ARButton.js +0 -208
  577. package/examples/jsm/webxr/OculusHandModel.js +0 -109
  578. package/examples/jsm/webxr/OculusHandPointerModel.js +0 -413
  579. package/examples/jsm/webxr/Text2D.js +0 -38
  580. package/examples/jsm/webxr/VRButton.js +0 -200
  581. package/examples/jsm/webxr/XRButton.js +0 -198
  582. package/examples/jsm/webxr/XRControllerModelFactory.js +0 -299
  583. package/examples/jsm/webxr/XREstimatedLight.js +0 -223
  584. package/examples/jsm/webxr/XRHandMeshModel.js +0 -112
  585. package/examples/jsm/webxr/XRHandModelFactory.js +0 -105
  586. package/examples/jsm/webxr/XRHandPrimitiveModel.js +0 -103
  587. package/examples/jsm/webxr/XRPlanes.js +0 -100
  588. package/lib/3d.min.js +0 -1
@@ -1,3161 +0,0 @@
1
- import {
2
- BufferAttribute,
3
- ClampToEdgeWrapping,
4
- Color,
5
- DoubleSide,
6
- InterpolateDiscrete,
7
- InterpolateLinear,
8
- NoColorSpace,
9
- LinearFilter,
10
- LinearMipmapLinearFilter,
11
- LinearMipmapNearestFilter,
12
- MathUtils,
13
- Matrix4,
14
- MirroredRepeatWrapping,
15
- NearestFilter,
16
- NearestMipmapLinearFilter,
17
- NearestMipmapNearestFilter,
18
- PropertyBinding,
19
- RGBAFormat,
20
- RepeatWrapping,
21
- Scene,
22
- Source,
23
- SRGBColorSpace,
24
- CompressedTexture,
25
- Vector3
26
- } from 'three';
27
- import { decompress } from './../utils/TextureUtils.js';
28
-
29
-
30
- /**
31
- * The KHR_mesh_quantization extension allows these extra attribute component types
32
- *
33
- * @see https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md#extending-mesh-attributes
34
- */
35
- const KHR_mesh_quantization_ExtraAttrTypes = {
36
- POSITION: [
37
- 'byte',
38
- 'byte normalized',
39
- 'unsigned byte',
40
- 'unsigned byte normalized',
41
- 'short',
42
- 'short normalized',
43
- 'unsigned short',
44
- 'unsigned short normalized',
45
- ],
46
- NORMAL: [
47
- 'byte normalized',
48
- 'short normalized',
49
- ],
50
- TANGENT: [
51
- 'byte normalized',
52
- 'short normalized',
53
- ],
54
- TEXCOORD: [
55
- 'byte',
56
- 'byte normalized',
57
- 'unsigned byte',
58
- 'short',
59
- 'short normalized',
60
- 'unsigned short',
61
- ],
62
- };
63
-
64
-
65
- class GLTFExporter {
66
-
67
- constructor() {
68
-
69
- this.pluginCallbacks = [];
70
-
71
- this.register( function ( writer ) {
72
-
73
- return new GLTFLightExtension( writer );
74
-
75
- } );
76
-
77
- this.register( function ( writer ) {
78
-
79
- return new GLTFMaterialsUnlitExtension( writer );
80
-
81
- } );
82
-
83
- this.register( function ( writer ) {
84
-
85
- return new GLTFMaterialsTransmissionExtension( writer );
86
-
87
- } );
88
-
89
- this.register( function ( writer ) {
90
-
91
- return new GLTFMaterialsVolumeExtension( writer );
92
-
93
- } );
94
-
95
- this.register( function ( writer ) {
96
-
97
- return new GLTFMaterialsIorExtension( writer );
98
-
99
- } );
100
-
101
- this.register( function ( writer ) {
102
-
103
- return new GLTFMaterialsSpecularExtension( writer );
104
-
105
- } );
106
-
107
- this.register( function ( writer ) {
108
-
109
- return new GLTFMaterialsClearcoatExtension( writer );
110
-
111
- } );
112
-
113
- this.register( function ( writer ) {
114
-
115
- return new GLTFMaterialsIridescenceExtension( writer );
116
-
117
- } );
118
-
119
- this.register( function ( writer ) {
120
-
121
- return new GLTFMaterialsSheenExtension( writer );
122
-
123
- } );
124
-
125
- this.register( function ( writer ) {
126
-
127
- return new GLTFMaterialsAnisotropyExtension( writer );
128
-
129
- } );
130
-
131
- this.register( function ( writer ) {
132
-
133
- return new GLTFMaterialsEmissiveStrengthExtension( writer );
134
-
135
- } );
136
-
137
- }
138
-
139
- register( callback ) {
140
-
141
- if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
142
-
143
- this.pluginCallbacks.push( callback );
144
-
145
- }
146
-
147
- return this;
148
-
149
- }
150
-
151
- unregister( callback ) {
152
-
153
- if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
154
-
155
- this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
156
-
157
- }
158
-
159
- return this;
160
-
161
- }
162
-
163
- /**
164
- * Parse scenes and generate GLTF output
165
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
166
- * @param {Function} onDone Callback on completed
167
- * @param {Function} onError Callback on errors
168
- * @param {Object} options options
169
- */
170
- parse( input, onDone, onError, options ) {
171
-
172
- const writer = new GLTFWriter();
173
- const plugins = [];
174
-
175
- for ( let i = 0, il = this.pluginCallbacks.length; i < il; i ++ ) {
176
-
177
- plugins.push( this.pluginCallbacks[ i ]( writer ) );
178
-
179
- }
180
-
181
- writer.setPlugins( plugins );
182
- writer.write( input, onDone, options ).catch( onError );
183
-
184
- }
185
-
186
- parseAsync( input, options ) {
187
-
188
- const scope = this;
189
-
190
- return new Promise( function ( resolve, reject ) {
191
-
192
- scope.parse( input, resolve, reject, options );
193
-
194
- } );
195
-
196
- }
197
-
198
- }
199
-
200
- //------------------------------------------------------------------------------
201
- // Constants
202
- //------------------------------------------------------------------------------
203
-
204
- const WEBGL_CONSTANTS = {
205
- POINTS: 0x0000,
206
- LINES: 0x0001,
207
- LINE_LOOP: 0x0002,
208
- LINE_STRIP: 0x0003,
209
- TRIANGLES: 0x0004,
210
- TRIANGLE_STRIP: 0x0005,
211
- TRIANGLE_FAN: 0x0006,
212
-
213
- BYTE: 0x1400,
214
- UNSIGNED_BYTE: 0x1401,
215
- SHORT: 0x1402,
216
- UNSIGNED_SHORT: 0x1403,
217
- INT: 0x1404,
218
- UNSIGNED_INT: 0x1405,
219
- FLOAT: 0x1406,
220
-
221
- ARRAY_BUFFER: 0x8892,
222
- ELEMENT_ARRAY_BUFFER: 0x8893,
223
-
224
- NEAREST: 0x2600,
225
- LINEAR: 0x2601,
226
- NEAREST_MIPMAP_NEAREST: 0x2700,
227
- LINEAR_MIPMAP_NEAREST: 0x2701,
228
- NEAREST_MIPMAP_LINEAR: 0x2702,
229
- LINEAR_MIPMAP_LINEAR: 0x2703,
230
-
231
- CLAMP_TO_EDGE: 33071,
232
- MIRRORED_REPEAT: 33648,
233
- REPEAT: 10497
234
- };
235
-
236
- const KHR_MESH_QUANTIZATION = 'KHR_mesh_quantization';
237
-
238
- const THREE_TO_WEBGL = {};
239
-
240
- THREE_TO_WEBGL[ NearestFilter ] = WEBGL_CONSTANTS.NEAREST;
241
- THREE_TO_WEBGL[ NearestMipmapNearestFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
242
- THREE_TO_WEBGL[ NearestMipmapLinearFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
243
- THREE_TO_WEBGL[ LinearFilter ] = WEBGL_CONSTANTS.LINEAR;
244
- THREE_TO_WEBGL[ LinearMipmapNearestFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
245
- THREE_TO_WEBGL[ LinearMipmapLinearFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
246
-
247
- THREE_TO_WEBGL[ ClampToEdgeWrapping ] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
248
- THREE_TO_WEBGL[ RepeatWrapping ] = WEBGL_CONSTANTS.REPEAT;
249
- THREE_TO_WEBGL[ MirroredRepeatWrapping ] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
250
-
251
- const PATH_PROPERTIES = {
252
- scale: 'scale',
253
- position: 'translation',
254
- quaternion: 'rotation',
255
- morphTargetInfluences: 'weights'
256
- };
257
-
258
- const DEFAULT_SPECULAR_COLOR = new Color();
259
-
260
- // GLB constants
261
- // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
262
-
263
- const GLB_HEADER_BYTES = 12;
264
- const GLB_HEADER_MAGIC = 0x46546C67;
265
- const GLB_VERSION = 2;
266
-
267
- const GLB_CHUNK_PREFIX_BYTES = 8;
268
- const GLB_CHUNK_TYPE_JSON = 0x4E4F534A;
269
- const GLB_CHUNK_TYPE_BIN = 0x004E4942;
270
-
271
- //------------------------------------------------------------------------------
272
- // Utility functions
273
- //------------------------------------------------------------------------------
274
-
275
- /**
276
- * Compare two arrays
277
- * @param {Array} array1 Array 1 to compare
278
- * @param {Array} array2 Array 2 to compare
279
- * @return {Boolean} Returns true if both arrays are equal
280
- */
281
- function equalArray( array1, array2 ) {
282
-
283
- return ( array1.length === array2.length ) && array1.every( function ( element, index ) {
284
-
285
- return element === array2[ index ];
286
-
287
- } );
288
-
289
- }
290
-
291
- /**
292
- * Converts a string to an ArrayBuffer.
293
- * @param {string} text
294
- * @return {ArrayBuffer}
295
- */
296
- function stringToArrayBuffer( text ) {
297
-
298
- return new TextEncoder().encode( text ).buffer;
299
-
300
- }
301
-
302
- /**
303
- * Is identity matrix
304
- *
305
- * @param {Matrix4} matrix
306
- * @returns {Boolean} Returns true, if parameter is identity matrix
307
- */
308
- function isIdentityMatrix( matrix ) {
309
-
310
- return equalArray( matrix.elements, [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] );
311
-
312
- }
313
-
314
- /**
315
- * Get the min and max vectors from the given attribute
316
- * @param {BufferAttribute} attribute Attribute to find the min/max in range from start to start + count
317
- * @param {Integer} start
318
- * @param {Integer} count
319
- * @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components)
320
- */
321
- function getMinMax( attribute, start, count ) {
322
-
323
- const output = {
324
-
325
- min: new Array( attribute.itemSize ).fill( Number.POSITIVE_INFINITY ),
326
- max: new Array( attribute.itemSize ).fill( Number.NEGATIVE_INFINITY )
327
-
328
- };
329
-
330
- for ( let i = start; i < start + count; i ++ ) {
331
-
332
- for ( let a = 0; a < attribute.itemSize; a ++ ) {
333
-
334
- let value;
335
-
336
- if ( attribute.itemSize > 4 ) {
337
-
338
- // no support for interleaved data for itemSize > 4
339
-
340
- value = attribute.array[ i * attribute.itemSize + a ];
341
-
342
- } else {
343
-
344
- if ( a === 0 ) value = attribute.getX( i );
345
- else if ( a === 1 ) value = attribute.getY( i );
346
- else if ( a === 2 ) value = attribute.getZ( i );
347
- else if ( a === 3 ) value = attribute.getW( i );
348
-
349
- if ( attribute.normalized === true ) {
350
-
351
- value = MathUtils.normalize( value, attribute.array );
352
-
353
- }
354
-
355
- }
356
-
357
- output.min[ a ] = Math.min( output.min[ a ], value );
358
- output.max[ a ] = Math.max( output.max[ a ], value );
359
-
360
- }
361
-
362
- }
363
-
364
- return output;
365
-
366
- }
367
-
368
- /**
369
- * Get the required size + padding for a buffer, rounded to the next 4-byte boundary.
370
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment
371
- *
372
- * @param {Integer} bufferSize The size the original buffer.
373
- * @returns {Integer} new buffer size with required padding.
374
- *
375
- */
376
- function getPaddedBufferSize( bufferSize ) {
377
-
378
- return Math.ceil( bufferSize / 4 ) * 4;
379
-
380
- }
381
-
382
- /**
383
- * Returns a buffer aligned to 4-byte boundary.
384
- *
385
- * @param {ArrayBuffer} arrayBuffer Buffer to pad
386
- * @param {Integer} paddingByte (Optional)
387
- * @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer
388
- */
389
- function getPaddedArrayBuffer( arrayBuffer, paddingByte = 0 ) {
390
-
391
- const paddedLength = getPaddedBufferSize( arrayBuffer.byteLength );
392
-
393
- if ( paddedLength !== arrayBuffer.byteLength ) {
394
-
395
- const array = new Uint8Array( paddedLength );
396
- array.set( new Uint8Array( arrayBuffer ) );
397
-
398
- if ( paddingByte !== 0 ) {
399
-
400
- for ( let i = arrayBuffer.byteLength; i < paddedLength; i ++ ) {
401
-
402
- array[ i ] = paddingByte;
403
-
404
- }
405
-
406
- }
407
-
408
- return array.buffer;
409
-
410
- }
411
-
412
- return arrayBuffer;
413
-
414
- }
415
-
416
- function getCanvas() {
417
-
418
- if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) {
419
-
420
- return new OffscreenCanvas( 1, 1 );
421
-
422
- }
423
-
424
- return document.createElement( 'canvas' );
425
-
426
- }
427
-
428
- function getToBlobPromise( canvas, mimeType ) {
429
-
430
- if ( canvas.toBlob !== undefined ) {
431
-
432
- return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
433
-
434
- }
435
-
436
- let quality;
437
-
438
- // Blink's implementation of convertToBlob seems to default to a quality level of 100%
439
- // Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
440
- if ( mimeType === 'image/jpeg' ) {
441
-
442
- quality = 0.92;
443
-
444
- } else if ( mimeType === 'image/webp' ) {
445
-
446
- quality = 0.8;
447
-
448
- }
449
-
450
- return canvas.convertToBlob( {
451
-
452
- type: mimeType,
453
- quality: quality
454
-
455
- } );
456
-
457
- }
458
-
459
- /**
460
- * Writer
461
- */
462
- class GLTFWriter {
463
-
464
- constructor() {
465
-
466
- this.plugins = [];
467
-
468
- this.options = {};
469
- this.pending = [];
470
- this.buffers = [];
471
-
472
- this.byteOffset = 0;
473
- this.buffers = [];
474
- this.nodeMap = new Map();
475
- this.skins = [];
476
-
477
- this.extensionsUsed = {};
478
- this.extensionsRequired = {};
479
-
480
- this.uids = new Map();
481
- this.uid = 0;
482
-
483
- this.json = {
484
- asset: {
485
- version: '2.0',
486
- generator: 'THREE.GLTFExporter'
487
- }
488
- };
489
-
490
- this.cache = {
491
- meshes: new Map(),
492
- attributes: new Map(),
493
- attributesNormalized: new Map(),
494
- materials: new Map(),
495
- textures: new Map(),
496
- images: new Map()
497
- };
498
-
499
- }
500
-
501
- setPlugins( plugins ) {
502
-
503
- this.plugins = plugins;
504
-
505
- }
506
-
507
- /**
508
- * Parse scenes and generate GLTF output
509
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
510
- * @param {Function} onDone Callback on completed
511
- * @param {Object} options options
512
- */
513
- async write( input, onDone, options = {} ) {
514
-
515
- this.options = Object.assign( {
516
- // default options
517
- binary: false,
518
- trs: false,
519
- onlyVisible: true,
520
- maxTextureSize: Infinity,
521
- animations: [],
522
- includeCustomExtensions: false
523
- }, options );
524
-
525
- if ( this.options.animations.length > 0 ) {
526
-
527
- // Only TRS properties, and not matrices, may be targeted by animation.
528
- this.options.trs = true;
529
-
530
- }
531
-
532
- this.processInput( input );
533
-
534
- await Promise.all( this.pending );
535
-
536
- const writer = this;
537
- const buffers = writer.buffers;
538
- const json = writer.json;
539
- options = writer.options;
540
-
541
- const extensionsUsed = writer.extensionsUsed;
542
- const extensionsRequired = writer.extensionsRequired;
543
-
544
- // Merge buffers.
545
- const blob = new Blob( buffers, { type: 'application/octet-stream' } );
546
-
547
- // Declare extensions.
548
- const extensionsUsedList = Object.keys( extensionsUsed );
549
- const extensionsRequiredList = Object.keys( extensionsRequired );
550
-
551
- if ( extensionsUsedList.length > 0 ) json.extensionsUsed = extensionsUsedList;
552
- if ( extensionsRequiredList.length > 0 ) json.extensionsRequired = extensionsRequiredList;
553
-
554
- // Update bytelength of the single buffer.
555
- if ( json.buffers && json.buffers.length > 0 ) json.buffers[ 0 ].byteLength = blob.size;
556
-
557
- if ( options.binary === true ) {
558
-
559
- // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
560
-
561
- const reader = new FileReader();
562
- reader.readAsArrayBuffer( blob );
563
- reader.onloadend = function () {
564
-
565
- // Binary chunk.
566
- const binaryChunk = getPaddedArrayBuffer( reader.result );
567
- const binaryChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
568
- binaryChunkPrefix.setUint32( 0, binaryChunk.byteLength, true );
569
- binaryChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_BIN, true );
570
-
571
- // JSON chunk.
572
- const jsonChunk = getPaddedArrayBuffer( stringToArrayBuffer( JSON.stringify( json ) ), 0x20 );
573
- const jsonChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
574
- jsonChunkPrefix.setUint32( 0, jsonChunk.byteLength, true );
575
- jsonChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_JSON, true );
576
-
577
- // GLB header.
578
- const header = new ArrayBuffer( GLB_HEADER_BYTES );
579
- const headerView = new DataView( header );
580
- headerView.setUint32( 0, GLB_HEADER_MAGIC, true );
581
- headerView.setUint32( 4, GLB_VERSION, true );
582
- const totalByteLength = GLB_HEADER_BYTES
583
- + jsonChunkPrefix.byteLength + jsonChunk.byteLength
584
- + binaryChunkPrefix.byteLength + binaryChunk.byteLength;
585
- headerView.setUint32( 8, totalByteLength, true );
586
-
587
- const glbBlob = new Blob( [
588
- header,
589
- jsonChunkPrefix,
590
- jsonChunk,
591
- binaryChunkPrefix,
592
- binaryChunk
593
- ], { type: 'application/octet-stream' } );
594
-
595
- const glbReader = new FileReader();
596
- glbReader.readAsArrayBuffer( glbBlob );
597
- glbReader.onloadend = function () {
598
-
599
- onDone( glbReader.result );
600
-
601
- };
602
-
603
- };
604
-
605
- } else {
606
-
607
- if ( json.buffers && json.buffers.length > 0 ) {
608
-
609
- const reader = new FileReader();
610
- reader.readAsDataURL( blob );
611
- reader.onloadend = function () {
612
-
613
- const base64data = reader.result;
614
- json.buffers[ 0 ].uri = base64data;
615
- onDone( json );
616
-
617
- };
618
-
619
- } else {
620
-
621
- onDone( json );
622
-
623
- }
624
-
625
- }
626
-
627
-
628
- }
629
-
630
- /**
631
- * Serializes a userData.
632
- *
633
- * @param {THREE.Object3D|THREE.Material} object
634
- * @param {Object} objectDef
635
- */
636
- serializeUserData( object, objectDef ) {
637
-
638
- if ( Object.keys( object.userData ).length === 0 ) return;
639
-
640
- const options = this.options;
641
- const extensionsUsed = this.extensionsUsed;
642
-
643
- try {
644
-
645
- const json = JSON.parse( JSON.stringify( object.userData ) );
646
-
647
- if ( options.includeCustomExtensions && json.gltfExtensions ) {
648
-
649
- if ( objectDef.extensions === undefined ) objectDef.extensions = {};
650
-
651
- for ( const extensionName in json.gltfExtensions ) {
652
-
653
- objectDef.extensions[ extensionName ] = json.gltfExtensions[ extensionName ];
654
- extensionsUsed[ extensionName ] = true;
655
-
656
- }
657
-
658
- delete json.gltfExtensions;
659
-
660
- }
661
-
662
- if ( Object.keys( json ).length > 0 ) objectDef.extras = json;
663
-
664
- } catch ( error ) {
665
-
666
- console.warn( 'THREE.GLTFExporter: userData of \'' + object.name + '\' ' +
667
- 'won\'t be serialized because of JSON.stringify error - ' + error.message );
668
-
669
- }
670
-
671
- }
672
-
673
- /**
674
- * Returns ids for buffer attributes.
675
- * @param {Object} object
676
- * @return {Integer}
677
- */
678
- getUID( attribute, isRelativeCopy = false ) {
679
-
680
- if ( this.uids.has( attribute ) === false ) {
681
-
682
- const uids = new Map();
683
-
684
- uids.set( true, this.uid ++ );
685
- uids.set( false, this.uid ++ );
686
-
687
- this.uids.set( attribute, uids );
688
-
689
- }
690
-
691
- const uids = this.uids.get( attribute );
692
-
693
- return uids.get( isRelativeCopy );
694
-
695
- }
696
-
697
- /**
698
- * Checks if normal attribute values are normalized.
699
- *
700
- * @param {BufferAttribute} normal
701
- * @returns {Boolean}
702
- */
703
- isNormalizedNormalAttribute( normal ) {
704
-
705
- const cache = this.cache;
706
-
707
- if ( cache.attributesNormalized.has( normal ) ) return false;
708
-
709
- const v = new Vector3();
710
-
711
- for ( let i = 0, il = normal.count; i < il; i ++ ) {
712
-
713
- // 0.0005 is from glTF-validator
714
- if ( Math.abs( v.fromBufferAttribute( normal, i ).length() - 1.0 ) > 0.0005 ) return false;
715
-
716
- }
717
-
718
- return true;
719
-
720
- }
721
-
722
- /**
723
- * Creates normalized normal buffer attribute.
724
- *
725
- * @param {BufferAttribute} normal
726
- * @returns {BufferAttribute}
727
- *
728
- */
729
- createNormalizedNormalAttribute( normal ) {
730
-
731
- const cache = this.cache;
732
-
733
- if ( cache.attributesNormalized.has( normal ) ) return cache.attributesNormalized.get( normal );
734
-
735
- const attribute = normal.clone();
736
- const v = new Vector3();
737
-
738
- for ( let i = 0, il = attribute.count; i < il; i ++ ) {
739
-
740
- v.fromBufferAttribute( attribute, i );
741
-
742
- if ( v.x === 0 && v.y === 0 && v.z === 0 ) {
743
-
744
- // if values can't be normalized set (1, 0, 0)
745
- v.setX( 1.0 );
746
-
747
- } else {
748
-
749
- v.normalize();
750
-
751
- }
752
-
753
- attribute.setXYZ( i, v.x, v.y, v.z );
754
-
755
- }
756
-
757
- cache.attributesNormalized.set( normal, attribute );
758
-
759
- return attribute;
760
-
761
- }
762
-
763
- /**
764
- * Applies a texture transform, if present, to the map definition. Requires
765
- * the KHR_texture_transform extension.
766
- *
767
- * @param {Object} mapDef
768
- * @param {THREE.Texture} texture
769
- */
770
- applyTextureTransform( mapDef, texture ) {
771
-
772
- let didTransform = false;
773
- const transformDef = {};
774
-
775
- if ( texture.offset.x !== 0 || texture.offset.y !== 0 ) {
776
-
777
- transformDef.offset = texture.offset.toArray();
778
- didTransform = true;
779
-
780
- }
781
-
782
- if ( texture.rotation !== 0 ) {
783
-
784
- transformDef.rotation = texture.rotation;
785
- didTransform = true;
786
-
787
- }
788
-
789
- if ( texture.repeat.x !== 1 || texture.repeat.y !== 1 ) {
790
-
791
- transformDef.scale = texture.repeat.toArray();
792
- didTransform = true;
793
-
794
- }
795
-
796
- if ( didTransform ) {
797
-
798
- mapDef.extensions = mapDef.extensions || {};
799
- mapDef.extensions[ 'KHR_texture_transform' ] = transformDef;
800
- this.extensionsUsed[ 'KHR_texture_transform' ] = true;
801
-
802
- }
803
-
804
- }
805
-
806
- buildMetalRoughTexture( metalnessMap, roughnessMap ) {
807
-
808
- if ( metalnessMap === roughnessMap ) return metalnessMap;
809
-
810
- function getEncodingConversion( map ) {
811
-
812
- if ( map.colorSpace === SRGBColorSpace ) {
813
-
814
- return function SRGBToLinear( c ) {
815
-
816
- return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
817
-
818
- };
819
-
820
- }
821
-
822
- return function LinearToLinear( c ) {
823
-
824
- return c;
825
-
826
- };
827
-
828
- }
829
-
830
- console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
831
-
832
- if ( metalnessMap instanceof CompressedTexture ) {
833
-
834
- metalnessMap = decompress( metalnessMap );
835
-
836
- }
837
-
838
- if ( roughnessMap instanceof CompressedTexture ) {
839
-
840
- roughnessMap = decompress( roughnessMap );
841
-
842
- }
843
-
844
- const metalness = metalnessMap ? metalnessMap.image : null;
845
- const roughness = roughnessMap ? roughnessMap.image : null;
846
-
847
- const width = Math.max( metalness ? metalness.width : 0, roughness ? roughness.width : 0 );
848
- const height = Math.max( metalness ? metalness.height : 0, roughness ? roughness.height : 0 );
849
-
850
- const canvas = getCanvas();
851
- canvas.width = width;
852
- canvas.height = height;
853
-
854
- const context = canvas.getContext( '2d' );
855
- context.fillStyle = '#00ffff';
856
- context.fillRect( 0, 0, width, height );
857
-
858
- const composite = context.getImageData( 0, 0, width, height );
859
-
860
- if ( metalness ) {
861
-
862
- context.drawImage( metalness, 0, 0, width, height );
863
-
864
- const convert = getEncodingConversion( metalnessMap );
865
- const data = context.getImageData( 0, 0, width, height ).data;
866
-
867
- for ( let i = 2; i < data.length; i += 4 ) {
868
-
869
- composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
870
-
871
- }
872
-
873
- }
874
-
875
- if ( roughness ) {
876
-
877
- context.drawImage( roughness, 0, 0, width, height );
878
-
879
- const convert = getEncodingConversion( roughnessMap );
880
- const data = context.getImageData( 0, 0, width, height ).data;
881
-
882
- for ( let i = 1; i < data.length; i += 4 ) {
883
-
884
- composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
885
-
886
- }
887
-
888
- }
889
-
890
- context.putImageData( composite, 0, 0 );
891
-
892
- //
893
-
894
- const reference = metalnessMap || roughnessMap;
895
-
896
- const texture = reference.clone();
897
-
898
- texture.source = new Source( canvas );
899
- texture.colorSpace = NoColorSpace;
900
- texture.channel = ( metalnessMap || roughnessMap ).channel;
901
-
902
- if ( metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel ) {
903
-
904
- console.warn( 'THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.' );
905
-
906
- }
907
-
908
- return texture;
909
-
910
- }
911
-
912
- /**
913
- * Process a buffer to append to the default one.
914
- * @param {ArrayBuffer} buffer
915
- * @return {Integer}
916
- */
917
- processBuffer( buffer ) {
918
-
919
- const json = this.json;
920
- const buffers = this.buffers;
921
-
922
- if ( ! json.buffers ) json.buffers = [ { byteLength: 0 } ];
923
-
924
- // All buffers are merged before export.
925
- buffers.push( buffer );
926
-
927
- return 0;
928
-
929
- }
930
-
931
- /**
932
- * Process and generate a BufferView
933
- * @param {BufferAttribute} attribute
934
- * @param {number} componentType
935
- * @param {number} start
936
- * @param {number} count
937
- * @param {number} target (Optional) Target usage of the BufferView
938
- * @return {Object}
939
- */
940
- processBufferView( attribute, componentType, start, count, target ) {
941
-
942
- const json = this.json;
943
-
944
- if ( ! json.bufferViews ) json.bufferViews = [];
945
-
946
- // Create a new dataview and dump the attribute's array into it
947
-
948
- let componentSize;
949
-
950
- switch ( componentType ) {
951
-
952
- case WEBGL_CONSTANTS.BYTE:
953
- case WEBGL_CONSTANTS.UNSIGNED_BYTE:
954
-
955
- componentSize = 1;
956
-
957
- break;
958
-
959
- case WEBGL_CONSTANTS.SHORT:
960
- case WEBGL_CONSTANTS.UNSIGNED_SHORT:
961
-
962
- componentSize = 2;
963
-
964
- break;
965
-
966
- default:
967
-
968
- componentSize = 4;
969
-
970
- }
971
-
972
- const byteLength = getPaddedBufferSize( count * attribute.itemSize * componentSize );
973
- const dataView = new DataView( new ArrayBuffer( byteLength ) );
974
- let offset = 0;
975
-
976
- for ( let i = start; i < start + count; i ++ ) {
977
-
978
- for ( let a = 0; a < attribute.itemSize; a ++ ) {
979
-
980
- let value;
981
-
982
- if ( attribute.itemSize > 4 ) {
983
-
984
- // no support for interleaved data for itemSize > 4
985
-
986
- value = attribute.array[ i * attribute.itemSize + a ];
987
-
988
- } else {
989
-
990
- if ( a === 0 ) value = attribute.getX( i );
991
- else if ( a === 1 ) value = attribute.getY( i );
992
- else if ( a === 2 ) value = attribute.getZ( i );
993
- else if ( a === 3 ) value = attribute.getW( i );
994
-
995
- if ( attribute.normalized === true ) {
996
-
997
- value = MathUtils.normalize( value, attribute.array );
998
-
999
- }
1000
-
1001
- }
1002
-
1003
- if ( componentType === WEBGL_CONSTANTS.FLOAT ) {
1004
-
1005
- dataView.setFloat32( offset, value, true );
1006
-
1007
- } else if ( componentType === WEBGL_CONSTANTS.INT ) {
1008
-
1009
- dataView.setInt32( offset, value, true );
1010
-
1011
- } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_INT ) {
1012
-
1013
- dataView.setUint32( offset, value, true );
1014
-
1015
- } else if ( componentType === WEBGL_CONSTANTS.SHORT ) {
1016
-
1017
- dataView.setInt16( offset, value, true );
1018
-
1019
- } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ) {
1020
-
1021
- dataView.setUint16( offset, value, true );
1022
-
1023
- } else if ( componentType === WEBGL_CONSTANTS.BYTE ) {
1024
-
1025
- dataView.setInt8( offset, value );
1026
-
1027
- } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) {
1028
-
1029
- dataView.setUint8( offset, value );
1030
-
1031
- }
1032
-
1033
- offset += componentSize;
1034
-
1035
- }
1036
-
1037
- }
1038
-
1039
- const bufferViewDef = {
1040
-
1041
- buffer: this.processBuffer( dataView.buffer ),
1042
- byteOffset: this.byteOffset,
1043
- byteLength: byteLength
1044
-
1045
- };
1046
-
1047
- if ( target !== undefined ) bufferViewDef.target = target;
1048
-
1049
- if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {
1050
-
1051
- // Only define byteStride for vertex attributes.
1052
- bufferViewDef.byteStride = attribute.itemSize * componentSize;
1053
-
1054
- }
1055
-
1056
- this.byteOffset += byteLength;
1057
-
1058
- json.bufferViews.push( bufferViewDef );
1059
-
1060
- // @TODO Merge bufferViews where possible.
1061
- const output = {
1062
-
1063
- id: json.bufferViews.length - 1,
1064
- byteLength: 0
1065
-
1066
- };
1067
-
1068
- return output;
1069
-
1070
- }
1071
-
1072
- /**
1073
- * Process and generate a BufferView from an image Blob.
1074
- * @param {Blob} blob
1075
- * @return {Promise<Integer>}
1076
- */
1077
- processBufferViewImage( blob ) {
1078
-
1079
- const writer = this;
1080
- const json = writer.json;
1081
-
1082
- if ( ! json.bufferViews ) json.bufferViews = [];
1083
-
1084
- return new Promise( function ( resolve ) {
1085
-
1086
- const reader = new FileReader();
1087
- reader.readAsArrayBuffer( blob );
1088
- reader.onloadend = function () {
1089
-
1090
- const buffer = getPaddedArrayBuffer( reader.result );
1091
-
1092
- const bufferViewDef = {
1093
- buffer: writer.processBuffer( buffer ),
1094
- byteOffset: writer.byteOffset,
1095
- byteLength: buffer.byteLength
1096
- };
1097
-
1098
- writer.byteOffset += buffer.byteLength;
1099
- resolve( json.bufferViews.push( bufferViewDef ) - 1 );
1100
-
1101
- };
1102
-
1103
- } );
1104
-
1105
- }
1106
-
1107
- /**
1108
- * Process attribute to generate an accessor
1109
- * @param {BufferAttribute} attribute Attribute to process
1110
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
1111
- * @param {Integer} start (Optional)
1112
- * @param {Integer} count (Optional)
1113
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
1114
- */
1115
- processAccessor( attribute, geometry, start, count ) {
1116
-
1117
- const json = this.json;
1118
-
1119
- const types = {
1120
-
1121
- 1: 'SCALAR',
1122
- 2: 'VEC2',
1123
- 3: 'VEC3',
1124
- 4: 'VEC4',
1125
- 9: 'MAT3',
1126
- 16: 'MAT4'
1127
-
1128
- };
1129
-
1130
- let componentType;
1131
-
1132
- // Detect the component type of the attribute array
1133
- if ( attribute.array.constructor === Float32Array ) {
1134
-
1135
- componentType = WEBGL_CONSTANTS.FLOAT;
1136
-
1137
- } else if ( attribute.array.constructor === Int32Array ) {
1138
-
1139
- componentType = WEBGL_CONSTANTS.INT;
1140
-
1141
- } else if ( attribute.array.constructor === Uint32Array ) {
1142
-
1143
- componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
1144
-
1145
- } else if ( attribute.array.constructor === Int16Array ) {
1146
-
1147
- componentType = WEBGL_CONSTANTS.SHORT;
1148
-
1149
- } else if ( attribute.array.constructor === Uint16Array ) {
1150
-
1151
- componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
1152
-
1153
- } else if ( attribute.array.constructor === Int8Array ) {
1154
-
1155
- componentType = WEBGL_CONSTANTS.BYTE;
1156
-
1157
- } else if ( attribute.array.constructor === Uint8Array ) {
1158
-
1159
- componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
1160
-
1161
- } else {
1162
-
1163
- throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type: ' + attribute.array.constructor.name );
1164
-
1165
- }
1166
-
1167
- if ( start === undefined ) start = 0;
1168
- if ( count === undefined ) count = attribute.count;
1169
-
1170
- // Skip creating an accessor if the attribute doesn't have data to export
1171
- if ( count === 0 ) return null;
1172
-
1173
- const minMax = getMinMax( attribute, start, count );
1174
- let bufferViewTarget;
1175
-
1176
- // If geometry isn't provided, don't infer the target usage of the bufferView. For
1177
- // animation samplers, target must not be set.
1178
- if ( geometry !== undefined ) {
1179
-
1180
- bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
1181
-
1182
- }
1183
-
1184
- const bufferView = this.processBufferView( attribute, componentType, start, count, bufferViewTarget );
1185
-
1186
- const accessorDef = {
1187
-
1188
- bufferView: bufferView.id,
1189
- byteOffset: bufferView.byteOffset,
1190
- componentType: componentType,
1191
- count: count,
1192
- max: minMax.max,
1193
- min: minMax.min,
1194
- type: types[ attribute.itemSize ]
1195
-
1196
- };
1197
-
1198
- if ( attribute.normalized === true ) accessorDef.normalized = true;
1199
- if ( ! json.accessors ) json.accessors = [];
1200
-
1201
- return json.accessors.push( accessorDef ) - 1;
1202
-
1203
- }
1204
-
1205
- /**
1206
- * Process image
1207
- * @param {Image} image to process
1208
- * @param {Integer} format of the image (RGBAFormat)
1209
- * @param {Boolean} flipY before writing out the image
1210
- * @param {String} mimeType export format
1211
- * @return {Integer} Index of the processed texture in the "images" array
1212
- */
1213
- processImage( image, format, flipY, mimeType = 'image/png' ) {
1214
-
1215
- if ( image !== null ) {
1216
-
1217
- const writer = this;
1218
- const cache = writer.cache;
1219
- const json = writer.json;
1220
- const options = writer.options;
1221
- const pending = writer.pending;
1222
-
1223
- if ( ! cache.images.has( image ) ) cache.images.set( image, {} );
1224
-
1225
- const cachedImages = cache.images.get( image );
1226
-
1227
- const key = mimeType + ':flipY/' + flipY.toString();
1228
-
1229
- if ( cachedImages[ key ] !== undefined ) return cachedImages[ key ];
1230
-
1231
- if ( ! json.images ) json.images = [];
1232
-
1233
- const imageDef = { mimeType: mimeType };
1234
-
1235
- const canvas = getCanvas();
1236
-
1237
- canvas.width = Math.min( image.width, options.maxTextureSize );
1238
- canvas.height = Math.min( image.height, options.maxTextureSize );
1239
-
1240
- const ctx = canvas.getContext( '2d' );
1241
-
1242
- if ( flipY === true ) {
1243
-
1244
- ctx.translate( 0, canvas.height );
1245
- ctx.scale( 1, - 1 );
1246
-
1247
- }
1248
-
1249
- if ( image.data !== undefined ) { // THREE.DataTexture
1250
-
1251
- if ( format !== RGBAFormat ) {
1252
-
1253
- console.error( 'GLTFExporter: Only RGBAFormat is supported.', format );
1254
-
1255
- }
1256
-
1257
- if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
1258
-
1259
- console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
1260
-
1261
- }
1262
-
1263
- const data = new Uint8ClampedArray( image.height * image.width * 4 );
1264
-
1265
- for ( let i = 0; i < data.length; i += 4 ) {
1266
-
1267
- data[ i + 0 ] = image.data[ i + 0 ];
1268
- data[ i + 1 ] = image.data[ i + 1 ];
1269
- data[ i + 2 ] = image.data[ i + 2 ];
1270
- data[ i + 3 ] = image.data[ i + 3 ];
1271
-
1272
- }
1273
-
1274
- ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
1275
-
1276
- } else {
1277
-
1278
- ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
1279
-
1280
- }
1281
-
1282
- if ( options.binary === true ) {
1283
-
1284
- pending.push(
1285
-
1286
- getToBlobPromise( canvas, mimeType )
1287
- .then( blob => writer.processBufferViewImage( blob ) )
1288
- .then( bufferViewIndex => {
1289
-
1290
- imageDef.bufferView = bufferViewIndex;
1291
-
1292
- } )
1293
-
1294
- );
1295
-
1296
- } else {
1297
-
1298
- if ( canvas.toDataURL !== undefined ) {
1299
-
1300
- imageDef.uri = canvas.toDataURL( mimeType );
1301
-
1302
- } else {
1303
-
1304
- pending.push(
1305
-
1306
- getToBlobPromise( canvas, mimeType )
1307
- .then( blob => new FileReader().readAsDataURL( blob ) )
1308
- .then( dataURL => {
1309
-
1310
- imageDef.uri = dataURL;
1311
-
1312
- } )
1313
-
1314
- );
1315
-
1316
- }
1317
-
1318
- }
1319
-
1320
- const index = json.images.push( imageDef ) - 1;
1321
- cachedImages[ key ] = index;
1322
- return index;
1323
-
1324
- } else {
1325
-
1326
- throw new Error( 'THREE.GLTFExporter: No valid image data found. Unable to process texture.' );
1327
-
1328
- }
1329
-
1330
- }
1331
-
1332
- /**
1333
- * Process sampler
1334
- * @param {Texture} map Texture to process
1335
- * @return {Integer} Index of the processed texture in the "samplers" array
1336
- */
1337
- processSampler( map ) {
1338
-
1339
- const json = this.json;
1340
-
1341
- if ( ! json.samplers ) json.samplers = [];
1342
-
1343
- const samplerDef = {
1344
- magFilter: THREE_TO_WEBGL[ map.magFilter ],
1345
- minFilter: THREE_TO_WEBGL[ map.minFilter ],
1346
- wrapS: THREE_TO_WEBGL[ map.wrapS ],
1347
- wrapT: THREE_TO_WEBGL[ map.wrapT ]
1348
- };
1349
-
1350
- return json.samplers.push( samplerDef ) - 1;
1351
-
1352
- }
1353
-
1354
- /**
1355
- * Process texture
1356
- * @param {Texture} map Map to process
1357
- * @return {Integer} Index of the processed texture in the "textures" array
1358
- */
1359
- processTexture( map ) {
1360
-
1361
- const writer = this;
1362
- const options = writer.options;
1363
- const cache = this.cache;
1364
- const json = this.json;
1365
-
1366
- if ( cache.textures.has( map ) ) return cache.textures.get( map );
1367
-
1368
- if ( ! json.textures ) json.textures = [];
1369
-
1370
- // make non-readable textures (e.g. CompressedTexture) readable by blitting them into a new texture
1371
- if ( map instanceof CompressedTexture ) {
1372
-
1373
- map = decompress( map, options.maxTextureSize );
1374
-
1375
- }
1376
-
1377
- let mimeType = map.userData.mimeType;
1378
-
1379
- if ( mimeType === 'image/webp' ) mimeType = 'image/png';
1380
-
1381
- const textureDef = {
1382
- sampler: this.processSampler( map ),
1383
- source: this.processImage( map.image, map.format, map.flipY, mimeType )
1384
- };
1385
-
1386
- if ( map.name ) textureDef.name = map.name;
1387
-
1388
- this._invokeAll( function ( ext ) {
1389
-
1390
- ext.writeTexture && ext.writeTexture( map, textureDef );
1391
-
1392
- } );
1393
-
1394
- const index = json.textures.push( textureDef ) - 1;
1395
- cache.textures.set( map, index );
1396
- return index;
1397
-
1398
- }
1399
-
1400
- /**
1401
- * Process material
1402
- * @param {THREE.Material} material Material to process
1403
- * @return {Integer|null} Index of the processed material in the "materials" array
1404
- */
1405
- processMaterial( material ) {
1406
-
1407
- const cache = this.cache;
1408
- const json = this.json;
1409
-
1410
- if ( cache.materials.has( material ) ) return cache.materials.get( material );
1411
-
1412
- if ( material.isShaderMaterial ) {
1413
-
1414
- console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' );
1415
- return null;
1416
-
1417
- }
1418
-
1419
- if ( ! json.materials ) json.materials = [];
1420
-
1421
- // @QUESTION Should we avoid including any attribute that has the default value?
1422
- const materialDef = { pbrMetallicRoughness: {} };
1423
-
1424
- if ( material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true ) {
1425
-
1426
- console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' );
1427
-
1428
- }
1429
-
1430
- // pbrMetallicRoughness.baseColorFactor
1431
- const color = material.color.toArray().concat( [ material.opacity ] );
1432
-
1433
- if ( ! equalArray( color, [ 1, 1, 1, 1 ] ) ) {
1434
-
1435
- materialDef.pbrMetallicRoughness.baseColorFactor = color;
1436
-
1437
- }
1438
-
1439
- if ( material.isMeshStandardMaterial ) {
1440
-
1441
- materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
1442
- materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
1443
-
1444
- } else {
1445
-
1446
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
1447
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
1448
-
1449
- }
1450
-
1451
- // pbrMetallicRoughness.metallicRoughnessTexture
1452
- if ( material.metalnessMap || material.roughnessMap ) {
1453
-
1454
- const metalRoughTexture = this.buildMetalRoughTexture( material.metalnessMap, material.roughnessMap );
1455
-
1456
- const metalRoughMapDef = {
1457
- index: this.processTexture( metalRoughTexture ),
1458
- channel: metalRoughTexture.channel
1459
- };
1460
- this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
1461
- materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
1462
-
1463
- }
1464
-
1465
- // pbrMetallicRoughness.baseColorTexture
1466
- if ( material.map ) {
1467
-
1468
- const baseColorMapDef = {
1469
- index: this.processTexture( material.map ),
1470
- texCoord: material.map.channel
1471
- };
1472
- this.applyTextureTransform( baseColorMapDef, material.map );
1473
- materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
1474
-
1475
- }
1476
-
1477
- if ( material.emissive ) {
1478
-
1479
- const emissive = material.emissive;
1480
- const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b );
1481
-
1482
- if ( maxEmissiveComponent > 0 ) {
1483
-
1484
- materialDef.emissiveFactor = material.emissive.toArray();
1485
-
1486
- }
1487
-
1488
- // emissiveTexture
1489
- if ( material.emissiveMap ) {
1490
-
1491
- const emissiveMapDef = {
1492
- index: this.processTexture( material.emissiveMap ),
1493
- texCoord: material.emissiveMap.channel
1494
- };
1495
- this.applyTextureTransform( emissiveMapDef, material.emissiveMap );
1496
- materialDef.emissiveTexture = emissiveMapDef;
1497
-
1498
- }
1499
-
1500
- }
1501
-
1502
- // normalTexture
1503
- if ( material.normalMap ) {
1504
-
1505
- const normalMapDef = {
1506
- index: this.processTexture( material.normalMap ),
1507
- texCoord: material.normalMap.channel
1508
- };
1509
-
1510
- if ( material.normalScale && material.normalScale.x !== 1 ) {
1511
-
1512
- // glTF normal scale is univariate. Ignore `y`, which may be flipped.
1513
- // Context: https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
1514
- normalMapDef.scale = material.normalScale.x;
1515
-
1516
- }
1517
-
1518
- this.applyTextureTransform( normalMapDef, material.normalMap );
1519
- materialDef.normalTexture = normalMapDef;
1520
-
1521
- }
1522
-
1523
- // occlusionTexture
1524
- if ( material.aoMap ) {
1525
-
1526
- const occlusionMapDef = {
1527
- index: this.processTexture( material.aoMap ),
1528
- texCoord: material.aoMap.channel
1529
- };
1530
-
1531
- if ( material.aoMapIntensity !== 1.0 ) {
1532
-
1533
- occlusionMapDef.strength = material.aoMapIntensity;
1534
-
1535
- }
1536
-
1537
- this.applyTextureTransform( occlusionMapDef, material.aoMap );
1538
- materialDef.occlusionTexture = occlusionMapDef;
1539
-
1540
- }
1541
-
1542
- // alphaMode
1543
- if ( material.transparent ) {
1544
-
1545
- materialDef.alphaMode = 'BLEND';
1546
-
1547
- } else {
1548
-
1549
- if ( material.alphaTest > 0.0 ) {
1550
-
1551
- materialDef.alphaMode = 'MASK';
1552
- materialDef.alphaCutoff = material.alphaTest;
1553
-
1554
- }
1555
-
1556
- }
1557
-
1558
- // doubleSided
1559
- if ( material.side === DoubleSide ) materialDef.doubleSided = true;
1560
- if ( material.name !== '' ) materialDef.name = material.name;
1561
-
1562
- this.serializeUserData( material, materialDef );
1563
-
1564
- this._invokeAll( function ( ext ) {
1565
-
1566
- ext.writeMaterial && ext.writeMaterial( material, materialDef );
1567
-
1568
- } );
1569
-
1570
- const index = json.materials.push( materialDef ) - 1;
1571
- cache.materials.set( material, index );
1572
- return index;
1573
-
1574
- }
1575
-
1576
- /**
1577
- * Process mesh
1578
- * @param {THREE.Mesh} mesh Mesh to process
1579
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
1580
- */
1581
- processMesh( mesh ) {
1582
-
1583
- const cache = this.cache;
1584
- const json = this.json;
1585
-
1586
- const meshCacheKeyParts = [ mesh.geometry.uuid ];
1587
-
1588
- if ( Array.isArray( mesh.material ) ) {
1589
-
1590
- for ( let i = 0, l = mesh.material.length; i < l; i ++ ) {
1591
-
1592
- meshCacheKeyParts.push( mesh.material[ i ].uuid );
1593
-
1594
- }
1595
-
1596
- } else {
1597
-
1598
- meshCacheKeyParts.push( mesh.material.uuid );
1599
-
1600
- }
1601
-
1602
- const meshCacheKey = meshCacheKeyParts.join( ':' );
1603
-
1604
- if ( cache.meshes.has( meshCacheKey ) ) return cache.meshes.get( meshCacheKey );
1605
-
1606
- const geometry = mesh.geometry;
1607
-
1608
- let mode;
1609
-
1610
- // Use the correct mode
1611
- if ( mesh.isLineSegments ) {
1612
-
1613
- mode = WEBGL_CONSTANTS.LINES;
1614
-
1615
- } else if ( mesh.isLineLoop ) {
1616
-
1617
- mode = WEBGL_CONSTANTS.LINE_LOOP;
1618
-
1619
- } else if ( mesh.isLine ) {
1620
-
1621
- mode = WEBGL_CONSTANTS.LINE_STRIP;
1622
-
1623
- } else if ( mesh.isPoints ) {
1624
-
1625
- mode = WEBGL_CONSTANTS.POINTS;
1626
-
1627
- } else {
1628
-
1629
- mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
1630
-
1631
- }
1632
-
1633
- const meshDef = {};
1634
- const attributes = {};
1635
- const primitives = [];
1636
- const targets = [];
1637
-
1638
- // Conversion between attributes names in threejs and gltf spec
1639
- const nameConversion = {
1640
- uv: 'TEXCOORD_0',
1641
- uv1: 'TEXCOORD_1',
1642
- color: 'COLOR_0',
1643
- skinWeight: 'WEIGHTS_0',
1644
- skinIndex: 'JOINTS_0'
1645
- };
1646
-
1647
- const originalNormal = geometry.getAttribute( 'normal' );
1648
-
1649
- if ( originalNormal !== undefined && ! this.isNormalizedNormalAttribute( originalNormal ) ) {
1650
-
1651
- console.warn( 'THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.' );
1652
-
1653
- geometry.setAttribute( 'normal', this.createNormalizedNormalAttribute( originalNormal ) );
1654
-
1655
- }
1656
-
1657
- // @QUESTION Detect if .vertexColors = true?
1658
- // For every attribute create an accessor
1659
- let modifiedAttribute = null;
1660
-
1661
- for ( let attributeName in geometry.attributes ) {
1662
-
1663
- // Ignore morph target attributes, which are exported later.
1664
- if ( attributeName.slice( 0, 5 ) === 'morph' ) continue;
1665
-
1666
- const attribute = geometry.attributes[ attributeName ];
1667
- attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
1668
-
1669
- // Prefix all geometry attributes except the ones specifically
1670
- // listed in the spec; non-spec attributes are considered custom.
1671
- const validVertexAttributes =
1672
- /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
1673
-
1674
- if ( ! validVertexAttributes.test( attributeName ) ) attributeName = '_' + attributeName;
1675
-
1676
- if ( cache.attributes.has( this.getUID( attribute ) ) ) {
1677
-
1678
- attributes[ attributeName ] = cache.attributes.get( this.getUID( attribute ) );
1679
- continue;
1680
-
1681
- }
1682
-
1683
- // JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT.
1684
- modifiedAttribute = null;
1685
- const array = attribute.array;
1686
-
1687
- if ( attributeName === 'JOINTS_0' &&
1688
- ! ( array instanceof Uint16Array ) &&
1689
- ! ( array instanceof Uint8Array ) ) {
1690
-
1691
- console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' );
1692
- modifiedAttribute = new BufferAttribute( new Uint16Array( array ), attribute.itemSize, attribute.normalized );
1693
-
1694
- }
1695
-
1696
- const accessor = this.processAccessor( modifiedAttribute || attribute, geometry );
1697
-
1698
- if ( accessor !== null ) {
1699
-
1700
- if ( ! attributeName.startsWith( '_' ) ) {
1701
-
1702
- this.detectMeshQuantization( attributeName, attribute );
1703
-
1704
- }
1705
-
1706
- attributes[ attributeName ] = accessor;
1707
- cache.attributes.set( this.getUID( attribute ), accessor );
1708
-
1709
- }
1710
-
1711
- }
1712
-
1713
- if ( originalNormal !== undefined ) geometry.setAttribute( 'normal', originalNormal );
1714
-
1715
- // Skip if no exportable attributes found
1716
- if ( Object.keys( attributes ).length === 0 ) return null;
1717
-
1718
- // Morph targets
1719
- if ( mesh.morphTargetInfluences !== undefined && mesh.morphTargetInfluences.length > 0 ) {
1720
-
1721
- const weights = [];
1722
- const targetNames = [];
1723
- const reverseDictionary = {};
1724
-
1725
- if ( mesh.morphTargetDictionary !== undefined ) {
1726
-
1727
- for ( const key in mesh.morphTargetDictionary ) {
1728
-
1729
- reverseDictionary[ mesh.morphTargetDictionary[ key ] ] = key;
1730
-
1731
- }
1732
-
1733
- }
1734
-
1735
- for ( let i = 0; i < mesh.morphTargetInfluences.length; ++ i ) {
1736
-
1737
- const target = {};
1738
- let warned = false;
1739
-
1740
- for ( const attributeName in geometry.morphAttributes ) {
1741
-
1742
- // glTF 2.0 morph supports only POSITION/NORMAL/TANGENT.
1743
- // Three.js doesn't support TANGENT yet.
1744
-
1745
- if ( attributeName !== 'position' && attributeName !== 'normal' ) {
1746
-
1747
- if ( ! warned ) {
1748
-
1749
- console.warn( 'GLTFExporter: Only POSITION and NORMAL morph are supported.' );
1750
- warned = true;
1751
-
1752
- }
1753
-
1754
- continue;
1755
-
1756
- }
1757
-
1758
- const attribute = geometry.morphAttributes[ attributeName ][ i ];
1759
- const gltfAttributeName = attributeName.toUpperCase();
1760
-
1761
- // Three.js morph attribute has absolute values while the one of glTF has relative values.
1762
- //
1763
- // glTF 2.0 Specification:
1764
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets
1765
-
1766
- const baseAttribute = geometry.attributes[ attributeName ];
1767
-
1768
- if ( cache.attributes.has( this.getUID( attribute, true ) ) ) {
1769
-
1770
- target[ gltfAttributeName ] = cache.attributes.get( this.getUID( attribute, true ) );
1771
- continue;
1772
-
1773
- }
1774
-
1775
- // Clones attribute not to override
1776
- const relativeAttribute = attribute.clone();
1777
-
1778
- if ( ! geometry.morphTargetsRelative ) {
1779
-
1780
- for ( let j = 0, jl = attribute.count; j < jl; j ++ ) {
1781
-
1782
- for ( let a = 0; a < attribute.itemSize; a ++ ) {
1783
-
1784
- if ( a === 0 ) relativeAttribute.setX( j, attribute.getX( j ) - baseAttribute.getX( j ) );
1785
- if ( a === 1 ) relativeAttribute.setY( j, attribute.getY( j ) - baseAttribute.getY( j ) );
1786
- if ( a === 2 ) relativeAttribute.setZ( j, attribute.getZ( j ) - baseAttribute.getZ( j ) );
1787
- if ( a === 3 ) relativeAttribute.setW( j, attribute.getW( j ) - baseAttribute.getW( j ) );
1788
-
1789
- }
1790
-
1791
- }
1792
-
1793
- }
1794
-
1795
- target[ gltfAttributeName ] = this.processAccessor( relativeAttribute, geometry );
1796
- cache.attributes.set( this.getUID( baseAttribute, true ), target[ gltfAttributeName ] );
1797
-
1798
- }
1799
-
1800
- targets.push( target );
1801
-
1802
- weights.push( mesh.morphTargetInfluences[ i ] );
1803
-
1804
- if ( mesh.morphTargetDictionary !== undefined ) targetNames.push( reverseDictionary[ i ] );
1805
-
1806
- }
1807
-
1808
- meshDef.weights = weights;
1809
-
1810
- if ( targetNames.length > 0 ) {
1811
-
1812
- meshDef.extras = {};
1813
- meshDef.extras.targetNames = targetNames;
1814
-
1815
- }
1816
-
1817
- }
1818
-
1819
- const isMultiMaterial = Array.isArray( mesh.material );
1820
-
1821
- if ( isMultiMaterial && geometry.groups.length === 0 ) return null;
1822
-
1823
- const materials = isMultiMaterial ? mesh.material : [ mesh.material ];
1824
- const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ];
1825
-
1826
- for ( let i = 0, il = groups.length; i < il; i ++ ) {
1827
-
1828
- const primitive = {
1829
- mode: mode,
1830
- attributes: attributes,
1831
- };
1832
-
1833
- this.serializeUserData( geometry, primitive );
1834
-
1835
- if ( targets.length > 0 ) primitive.targets = targets;
1836
-
1837
- if ( geometry.index !== null ) {
1838
-
1839
- let cacheKey = this.getUID( geometry.index );
1840
-
1841
- if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) {
1842
-
1843
- cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count;
1844
-
1845
- }
1846
-
1847
- if ( cache.attributes.has( cacheKey ) ) {
1848
-
1849
- primitive.indices = cache.attributes.get( cacheKey );
1850
-
1851
- } else {
1852
-
1853
- primitive.indices = this.processAccessor( geometry.index, geometry, groups[ i ].start, groups[ i ].count );
1854
- cache.attributes.set( cacheKey, primitive.indices );
1855
-
1856
- }
1857
-
1858
- if ( primitive.indices === null ) delete primitive.indices;
1859
-
1860
- }
1861
-
1862
- const material = this.processMaterial( materials[ groups[ i ].materialIndex ] );
1863
-
1864
- if ( material !== null ) primitive.material = material;
1865
-
1866
- primitives.push( primitive );
1867
-
1868
- }
1869
-
1870
- meshDef.primitives = primitives;
1871
-
1872
- if ( ! json.meshes ) json.meshes = [];
1873
-
1874
- this._invokeAll( function ( ext ) {
1875
-
1876
- ext.writeMesh && ext.writeMesh( mesh, meshDef );
1877
-
1878
- } );
1879
-
1880
- const index = json.meshes.push( meshDef ) - 1;
1881
- cache.meshes.set( meshCacheKey, index );
1882
- return index;
1883
-
1884
- }
1885
-
1886
- /**
1887
- * If a vertex attribute with a
1888
- * [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
1889
- * is used, it is checked whether it is a valid data type according to the
1890
- * [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
1891
- * extension.
1892
- * In this case the extension is automatically added to the list of used extensions.
1893
- *
1894
- * @param {string} attributeName
1895
- * @param {THREE.BufferAttribute} attribute
1896
- */
1897
- detectMeshQuantization( attributeName, attribute ) {
1898
-
1899
- if ( this.extensionsUsed[ KHR_MESH_QUANTIZATION ] ) return;
1900
-
1901
- let attrType = undefined;
1902
-
1903
- switch ( attribute.array.constructor ) {
1904
-
1905
- case Int8Array:
1906
-
1907
- attrType = 'byte';
1908
-
1909
- break;
1910
-
1911
- case Uint8Array:
1912
-
1913
- attrType = 'unsigned byte';
1914
-
1915
- break;
1916
-
1917
- case Int16Array:
1918
-
1919
- attrType = 'short';
1920
-
1921
- break;
1922
-
1923
- case Uint16Array:
1924
-
1925
- attrType = 'unsigned short';
1926
-
1927
- break;
1928
-
1929
- default:
1930
-
1931
- return;
1932
-
1933
- }
1934
-
1935
- if ( attribute.normalized ) attrType += ' normalized';
1936
-
1937
- const attrNamePrefix = attributeName.split( '_', 1 )[ 0 ];
1938
-
1939
- if ( KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ] && KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ].includes( attrType ) ) {
1940
-
1941
- this.extensionsUsed[ KHR_MESH_QUANTIZATION ] = true;
1942
- this.extensionsRequired[ KHR_MESH_QUANTIZATION ] = true;
1943
-
1944
- }
1945
-
1946
- }
1947
-
1948
- /**
1949
- * Process camera
1950
- * @param {THREE.Camera} camera Camera to process
1951
- * @return {Integer} Index of the processed mesh in the "camera" array
1952
- */
1953
- processCamera( camera ) {
1954
-
1955
- const json = this.json;
1956
-
1957
- if ( ! json.cameras ) json.cameras = [];
1958
-
1959
- const isOrtho = camera.isOrthographicCamera;
1960
-
1961
- const cameraDef = {
1962
- type: isOrtho ? 'orthographic' : 'perspective'
1963
- };
1964
-
1965
- if ( isOrtho ) {
1966
-
1967
- cameraDef.orthographic = {
1968
- xmag: camera.right * 2,
1969
- ymag: camera.top * 2,
1970
- zfar: camera.far <= 0 ? 0.001 : camera.far,
1971
- znear: camera.near < 0 ? 0 : camera.near
1972
- };
1973
-
1974
- } else {
1975
-
1976
- cameraDef.perspective = {
1977
- aspectRatio: camera.aspect,
1978
- yfov: MathUtils.degToRad( camera.fov ),
1979
- zfar: camera.far <= 0 ? 0.001 : camera.far,
1980
- znear: camera.near < 0 ? 0 : camera.near
1981
- };
1982
-
1983
- }
1984
-
1985
- // Question: Is saving "type" as name intentional?
1986
- if ( camera.name !== '' ) cameraDef.name = camera.type;
1987
-
1988
- return json.cameras.push( cameraDef ) - 1;
1989
-
1990
- }
1991
-
1992
- /**
1993
- * Creates glTF animation entry from AnimationClip object.
1994
- *
1995
- * Status:
1996
- * - Only properties listed in PATH_PROPERTIES may be animated.
1997
- *
1998
- * @param {THREE.AnimationClip} clip
1999
- * @param {THREE.Object3D} root
2000
- * @return {number|null}
2001
- */
2002
- processAnimation( clip, root ) {
2003
-
2004
- const json = this.json;
2005
- const nodeMap = this.nodeMap;
2006
-
2007
- if ( ! json.animations ) json.animations = [];
2008
-
2009
- clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip.clone(), root );
2010
-
2011
- const tracks = clip.tracks;
2012
- const channels = [];
2013
- const samplers = [];
2014
-
2015
- for ( let i = 0; i < tracks.length; ++ i ) {
2016
-
2017
- const track = tracks[ i ];
2018
- const trackBinding = PropertyBinding.parseTrackName( track.name );
2019
- let trackNode = PropertyBinding.findNode( root, trackBinding.nodeName );
2020
- const trackProperty = PATH_PROPERTIES[ trackBinding.propertyName ];
2021
-
2022
- if ( trackBinding.objectName === 'bones' ) {
2023
-
2024
- if ( trackNode.isSkinnedMesh === true ) {
2025
-
2026
- trackNode = trackNode.skeleton.getBoneByName( trackBinding.objectIndex );
2027
-
2028
- } else {
2029
-
2030
- trackNode = undefined;
2031
-
2032
- }
2033
-
2034
- }
2035
-
2036
- if ( ! trackNode || ! trackProperty ) {
2037
-
2038
- console.warn( 'THREE.GLTFExporter: Could not export animation track "%s".', track.name );
2039
- return null;
2040
-
2041
- }
2042
-
2043
- const inputItemSize = 1;
2044
- let outputItemSize = track.values.length / track.times.length;
2045
-
2046
- if ( trackProperty === PATH_PROPERTIES.morphTargetInfluences ) {
2047
-
2048
- outputItemSize /= trackNode.morphTargetInfluences.length;
2049
-
2050
- }
2051
-
2052
- let interpolation;
2053
-
2054
- // @TODO export CubicInterpolant(InterpolateSmooth) as CUBICSPLINE
2055
-
2056
- // Detecting glTF cubic spline interpolant by checking factory method's special property
2057
- // GLTFCubicSplineInterpolant is a custom interpolant and track doesn't return
2058
- // valid value from .getInterpolation().
2059
- if ( track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true ) {
2060
-
2061
- interpolation = 'CUBICSPLINE';
2062
-
2063
- // itemSize of CUBICSPLINE keyframe is 9
2064
- // (VEC3 * 3: inTangent, splineVertex, and outTangent)
2065
- // but needs to be stored as VEC3 so dividing by 3 here.
2066
- outputItemSize /= 3;
2067
-
2068
- } else if ( track.getInterpolation() === InterpolateDiscrete ) {
2069
-
2070
- interpolation = 'STEP';
2071
-
2072
- } else {
2073
-
2074
- interpolation = 'LINEAR';
2075
-
2076
- }
2077
-
2078
- samplers.push( {
2079
- input: this.processAccessor( new BufferAttribute( track.times, inputItemSize ) ),
2080
- output: this.processAccessor( new BufferAttribute( track.values, outputItemSize ) ),
2081
- interpolation: interpolation
2082
- } );
2083
-
2084
- channels.push( {
2085
- sampler: samplers.length - 1,
2086
- target: {
2087
- node: nodeMap.get( trackNode ),
2088
- path: trackProperty
2089
- }
2090
- } );
2091
-
2092
- }
2093
-
2094
- json.animations.push( {
2095
- name: clip.name || 'clip_' + json.animations.length,
2096
- samplers: samplers,
2097
- channels: channels
2098
- } );
2099
-
2100
- return json.animations.length - 1;
2101
-
2102
- }
2103
-
2104
- /**
2105
- * @param {THREE.Object3D} object
2106
- * @return {number|null}
2107
- */
2108
- processSkin( object ) {
2109
-
2110
- const json = this.json;
2111
- const nodeMap = this.nodeMap;
2112
-
2113
- const node = json.nodes[ nodeMap.get( object ) ];
2114
-
2115
- const skeleton = object.skeleton;
2116
-
2117
- if ( skeleton === undefined ) return null;
2118
-
2119
- const rootJoint = object.skeleton.bones[ 0 ];
2120
-
2121
- if ( rootJoint === undefined ) return null;
2122
-
2123
- const joints = [];
2124
- const inverseBindMatrices = new Float32Array( skeleton.bones.length * 16 );
2125
- const temporaryBoneInverse = new Matrix4();
2126
-
2127
- for ( let i = 0; i < skeleton.bones.length; ++ i ) {
2128
-
2129
- joints.push( nodeMap.get( skeleton.bones[ i ] ) );
2130
- temporaryBoneInverse.copy( skeleton.boneInverses[ i ] );
2131
- temporaryBoneInverse.multiply( object.bindMatrix ).toArray( inverseBindMatrices, i * 16 );
2132
-
2133
- }
2134
-
2135
- if ( json.skins === undefined ) json.skins = [];
2136
-
2137
- json.skins.push( {
2138
- inverseBindMatrices: this.processAccessor( new BufferAttribute( inverseBindMatrices, 16 ) ),
2139
- joints: joints,
2140
- skeleton: nodeMap.get( rootJoint )
2141
- } );
2142
-
2143
- const skinIndex = node.skin = json.skins.length - 1;
2144
-
2145
- return skinIndex;
2146
-
2147
- }
2148
-
2149
- /**
2150
- * Process Object3D node
2151
- * @param {THREE.Object3D} node Object3D to processNode
2152
- * @return {Integer} Index of the node in the nodes list
2153
- */
2154
- processNode( object ) {
2155
-
2156
- const json = this.json;
2157
- const options = this.options;
2158
- const nodeMap = this.nodeMap;
2159
-
2160
- if ( ! json.nodes ) json.nodes = [];
2161
-
2162
- const nodeDef = {};
2163
-
2164
- if ( options.trs ) {
2165
-
2166
- const rotation = object.quaternion.toArray();
2167
- const position = object.position.toArray();
2168
- const scale = object.scale.toArray();
2169
-
2170
- if ( ! equalArray( rotation, [ 0, 0, 0, 1 ] ) ) {
2171
-
2172
- nodeDef.rotation = rotation;
2173
-
2174
- }
2175
-
2176
- if ( ! equalArray( position, [ 0, 0, 0 ] ) ) {
2177
-
2178
- nodeDef.translation = position;
2179
-
2180
- }
2181
-
2182
- if ( ! equalArray( scale, [ 1, 1, 1 ] ) ) {
2183
-
2184
- nodeDef.scale = scale;
2185
-
2186
- }
2187
-
2188
- } else {
2189
-
2190
- if ( object.matrixAutoUpdate ) {
2191
-
2192
- object.updateMatrix();
2193
-
2194
- }
2195
-
2196
- if ( isIdentityMatrix( object.matrix ) === false ) {
2197
-
2198
- nodeDef.matrix = object.matrix.elements;
2199
-
2200
- }
2201
-
2202
- }
2203
-
2204
- // We don't export empty strings name because it represents no-name in Three.js.
2205
- if ( object.name !== '' ) nodeDef.name = String( object.name );
2206
-
2207
- this.serializeUserData( object, nodeDef );
2208
-
2209
- if ( object.isMesh || object.isLine || object.isPoints ) {
2210
-
2211
- const meshIndex = this.processMesh( object );
2212
-
2213
- if ( meshIndex !== null ) nodeDef.mesh = meshIndex;
2214
-
2215
- } else if ( object.isCamera ) {
2216
-
2217
- nodeDef.camera = this.processCamera( object );
2218
-
2219
- }
2220
-
2221
- if ( object.isSkinnedMesh ) this.skins.push( object );
2222
-
2223
- if ( object.children.length > 0 ) {
2224
-
2225
- const children = [];
2226
-
2227
- for ( let i = 0, l = object.children.length; i < l; i ++ ) {
2228
-
2229
- const child = object.children[ i ];
2230
-
2231
- if ( child.visible || options.onlyVisible === false ) {
2232
-
2233
- const nodeIndex = this.processNode( child );
2234
-
2235
- if ( nodeIndex !== null ) children.push( nodeIndex );
2236
-
2237
- }
2238
-
2239
- }
2240
-
2241
- if ( children.length > 0 ) nodeDef.children = children;
2242
-
2243
- }
2244
-
2245
- this._invokeAll( function ( ext ) {
2246
-
2247
- ext.writeNode && ext.writeNode( object, nodeDef );
2248
-
2249
- } );
2250
-
2251
- const nodeIndex = json.nodes.push( nodeDef ) - 1;
2252
- nodeMap.set( object, nodeIndex );
2253
- return nodeIndex;
2254
-
2255
- }
2256
-
2257
- /**
2258
- * Process Scene
2259
- * @param {Scene} node Scene to process
2260
- */
2261
- processScene( scene ) {
2262
-
2263
- const json = this.json;
2264
- const options = this.options;
2265
-
2266
- if ( ! json.scenes ) {
2267
-
2268
- json.scenes = [];
2269
- json.scene = 0;
2270
-
2271
- }
2272
-
2273
- const sceneDef = {};
2274
-
2275
- if ( scene.name !== '' ) sceneDef.name = scene.name;
2276
-
2277
- json.scenes.push( sceneDef );
2278
-
2279
- const nodes = [];
2280
-
2281
- for ( let i = 0, l = scene.children.length; i < l; i ++ ) {
2282
-
2283
- const child = scene.children[ i ];
2284
-
2285
- if ( child.visible || options.onlyVisible === false ) {
2286
-
2287
- const nodeIndex = this.processNode( child );
2288
-
2289
- if ( nodeIndex !== null ) nodes.push( nodeIndex );
2290
-
2291
- }
2292
-
2293
- }
2294
-
2295
- if ( nodes.length > 0 ) sceneDef.nodes = nodes;
2296
-
2297
- this.serializeUserData( scene, sceneDef );
2298
-
2299
- }
2300
-
2301
- /**
2302
- * Creates a Scene to hold a list of objects and parse it
2303
- * @param {Array} objects List of objects to process
2304
- */
2305
- processObjects( objects ) {
2306
-
2307
- const scene = new Scene();
2308
- scene.name = 'AuxScene';
2309
-
2310
- for ( let i = 0; i < objects.length; i ++ ) {
2311
-
2312
- // We push directly to children instead of calling `add` to prevent
2313
- // modify the .parent and break its original scene and hierarchy
2314
- scene.children.push( objects[ i ] );
2315
-
2316
- }
2317
-
2318
- this.processScene( scene );
2319
-
2320
- }
2321
-
2322
- /**
2323
- * @param {THREE.Object3D|Array<THREE.Object3D>} input
2324
- */
2325
- processInput( input ) {
2326
-
2327
- const options = this.options;
2328
-
2329
- input = input instanceof Array ? input : [ input ];
2330
-
2331
- this._invokeAll( function ( ext ) {
2332
-
2333
- ext.beforeParse && ext.beforeParse( input );
2334
-
2335
- } );
2336
-
2337
- const objectsWithoutScene = [];
2338
-
2339
- for ( let i = 0; i < input.length; i ++ ) {
2340
-
2341
- if ( input[ i ] instanceof Scene ) {
2342
-
2343
- this.processScene( input[ i ] );
2344
-
2345
- } else {
2346
-
2347
- objectsWithoutScene.push( input[ i ] );
2348
-
2349
- }
2350
-
2351
- }
2352
-
2353
- if ( objectsWithoutScene.length > 0 ) this.processObjects( objectsWithoutScene );
2354
-
2355
- for ( let i = 0; i < this.skins.length; ++ i ) {
2356
-
2357
- this.processSkin( this.skins[ i ] );
2358
-
2359
- }
2360
-
2361
- for ( let i = 0; i < options.animations.length; ++ i ) {
2362
-
2363
- this.processAnimation( options.animations[ i ], input[ 0 ] );
2364
-
2365
- }
2366
-
2367
- this._invokeAll( function ( ext ) {
2368
-
2369
- ext.afterParse && ext.afterParse( input );
2370
-
2371
- } );
2372
-
2373
- }
2374
-
2375
- _invokeAll( func ) {
2376
-
2377
- for ( let i = 0, il = this.plugins.length; i < il; i ++ ) {
2378
-
2379
- func( this.plugins[ i ] );
2380
-
2381
- }
2382
-
2383
- }
2384
-
2385
- }
2386
-
2387
- /**
2388
- * Punctual Lights Extension
2389
- *
2390
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
2391
- */
2392
- class GLTFLightExtension {
2393
-
2394
- constructor( writer ) {
2395
-
2396
- this.writer = writer;
2397
- this.name = 'KHR_lights_punctual';
2398
-
2399
- }
2400
-
2401
- writeNode( light, nodeDef ) {
2402
-
2403
- if ( ! light.isLight ) return;
2404
-
2405
- if ( ! light.isDirectionalLight && ! light.isPointLight && ! light.isSpotLight ) {
2406
-
2407
- console.warn( 'THREE.GLTFExporter: Only directional, point, and spot lights are supported.', light );
2408
- return;
2409
-
2410
- }
2411
-
2412
- const writer = this.writer;
2413
- const json = writer.json;
2414
- const extensionsUsed = writer.extensionsUsed;
2415
-
2416
- const lightDef = {};
2417
-
2418
- if ( light.name ) lightDef.name = light.name;
2419
-
2420
- lightDef.color = light.color.toArray();
2421
-
2422
- lightDef.intensity = light.intensity;
2423
-
2424
- if ( light.isDirectionalLight ) {
2425
-
2426
- lightDef.type = 'directional';
2427
-
2428
- } else if ( light.isPointLight ) {
2429
-
2430
- lightDef.type = 'point';
2431
-
2432
- if ( light.distance > 0 ) lightDef.range = light.distance;
2433
-
2434
- } else if ( light.isSpotLight ) {
2435
-
2436
- lightDef.type = 'spot';
2437
-
2438
- if ( light.distance > 0 ) lightDef.range = light.distance;
2439
-
2440
- lightDef.spot = {};
2441
- lightDef.spot.innerConeAngle = ( light.penumbra - 1.0 ) * light.angle * - 1.0;
2442
- lightDef.spot.outerConeAngle = light.angle;
2443
-
2444
- }
2445
-
2446
- if ( light.decay !== undefined && light.decay !== 2 ) {
2447
-
2448
- console.warn( 'THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, '
2449
- + 'and expects light.decay=2.' );
2450
-
2451
- }
2452
-
2453
- if ( light.target
2454
- && ( light.target.parent !== light
2455
- || light.target.position.x !== 0
2456
- || light.target.position.y !== 0
2457
- || light.target.position.z !== - 1 ) ) {
2458
-
2459
- console.warn( 'THREE.GLTFExporter: Light direction may be lost. For best results, '
2460
- + 'make light.target a child of the light with position 0,0,-1.' );
2461
-
2462
- }
2463
-
2464
- if ( ! extensionsUsed[ this.name ] ) {
2465
-
2466
- json.extensions = json.extensions || {};
2467
- json.extensions[ this.name ] = { lights: [] };
2468
- extensionsUsed[ this.name ] = true;
2469
-
2470
- }
2471
-
2472
- const lights = json.extensions[ this.name ].lights;
2473
- lights.push( lightDef );
2474
-
2475
- nodeDef.extensions = nodeDef.extensions || {};
2476
- nodeDef.extensions[ this.name ] = { light: lights.length - 1 };
2477
-
2478
- }
2479
-
2480
- }
2481
-
2482
- /**
2483
- * Unlit Materials Extension
2484
- *
2485
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
2486
- */
2487
- class GLTFMaterialsUnlitExtension {
2488
-
2489
- constructor( writer ) {
2490
-
2491
- this.writer = writer;
2492
- this.name = 'KHR_materials_unlit';
2493
-
2494
- }
2495
-
2496
- writeMaterial( material, materialDef ) {
2497
-
2498
- if ( ! material.isMeshBasicMaterial ) return;
2499
-
2500
- const writer = this.writer;
2501
- const extensionsUsed = writer.extensionsUsed;
2502
-
2503
- materialDef.extensions = materialDef.extensions || {};
2504
- materialDef.extensions[ this.name ] = {};
2505
-
2506
- extensionsUsed[ this.name ] = true;
2507
-
2508
- materialDef.pbrMetallicRoughness.metallicFactor = 0.0;
2509
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
2510
-
2511
- }
2512
-
2513
- }
2514
-
2515
- /**
2516
- * Clearcoat Materials Extension
2517
- *
2518
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
2519
- */
2520
- class GLTFMaterialsClearcoatExtension {
2521
-
2522
- constructor( writer ) {
2523
-
2524
- this.writer = writer;
2525
- this.name = 'KHR_materials_clearcoat';
2526
-
2527
- }
2528
-
2529
- writeMaterial( material, materialDef ) {
2530
-
2531
- if ( ! material.isMeshPhysicalMaterial || material.clearcoat === 0 ) return;
2532
-
2533
- const writer = this.writer;
2534
- const extensionsUsed = writer.extensionsUsed;
2535
-
2536
- const extensionDef = {};
2537
-
2538
- extensionDef.clearcoatFactor = material.clearcoat;
2539
-
2540
- if ( material.clearcoatMap ) {
2541
-
2542
- const clearcoatMapDef = {
2543
- index: writer.processTexture( material.clearcoatMap ),
2544
- texCoord: material.clearcoatMap.channel
2545
- };
2546
- writer.applyTextureTransform( clearcoatMapDef, material.clearcoatMap );
2547
- extensionDef.clearcoatTexture = clearcoatMapDef;
2548
-
2549
- }
2550
-
2551
- extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
2552
-
2553
- if ( material.clearcoatRoughnessMap ) {
2554
-
2555
- const clearcoatRoughnessMapDef = {
2556
- index: writer.processTexture( material.clearcoatRoughnessMap ),
2557
- texCoord: material.clearcoatRoughnessMap.channel
2558
- };
2559
- writer.applyTextureTransform( clearcoatRoughnessMapDef, material.clearcoatRoughnessMap );
2560
- extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
2561
-
2562
- }
2563
-
2564
- if ( material.clearcoatNormalMap ) {
2565
-
2566
- const clearcoatNormalMapDef = {
2567
- index: writer.processTexture( material.clearcoatNormalMap ),
2568
- texCoord: material.clearcoatNormalMap.channel
2569
- };
2570
- writer.applyTextureTransform( clearcoatNormalMapDef, material.clearcoatNormalMap );
2571
- extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
2572
-
2573
- }
2574
-
2575
- materialDef.extensions = materialDef.extensions || {};
2576
- materialDef.extensions[ this.name ] = extensionDef;
2577
-
2578
- extensionsUsed[ this.name ] = true;
2579
-
2580
-
2581
- }
2582
-
2583
- }
2584
-
2585
- /**
2586
- * Iridescence Materials Extension
2587
- *
2588
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
2589
- */
2590
- class GLTFMaterialsIridescenceExtension {
2591
-
2592
- constructor( writer ) {
2593
-
2594
- this.writer = writer;
2595
- this.name = 'KHR_materials_iridescence';
2596
-
2597
- }
2598
-
2599
- writeMaterial( material, materialDef ) {
2600
-
2601
- if ( ! material.isMeshPhysicalMaterial || material.iridescence === 0 ) return;
2602
-
2603
- const writer = this.writer;
2604
- const extensionsUsed = writer.extensionsUsed;
2605
-
2606
- const extensionDef = {};
2607
-
2608
- extensionDef.iridescenceFactor = material.iridescence;
2609
-
2610
- if ( material.iridescenceMap ) {
2611
-
2612
- const iridescenceMapDef = {
2613
- index: writer.processTexture( material.iridescenceMap ),
2614
- texCoord: material.iridescenceMap.channel
2615
- };
2616
- writer.applyTextureTransform( iridescenceMapDef, material.iridescenceMap );
2617
- extensionDef.iridescenceTexture = iridescenceMapDef;
2618
-
2619
- }
2620
-
2621
- extensionDef.iridescenceIor = material.iridescenceIOR;
2622
- extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[ 0 ];
2623
- extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[ 1 ];
2624
-
2625
- if ( material.iridescenceThicknessMap ) {
2626
-
2627
- const iridescenceThicknessMapDef = {
2628
- index: writer.processTexture( material.iridescenceThicknessMap ),
2629
- texCoord: material.iridescenceThicknessMap.channel
2630
- };
2631
- writer.applyTextureTransform( iridescenceThicknessMapDef, material.iridescenceThicknessMap );
2632
- extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
2633
-
2634
- }
2635
-
2636
- materialDef.extensions = materialDef.extensions || {};
2637
- materialDef.extensions[ this.name ] = extensionDef;
2638
-
2639
- extensionsUsed[ this.name ] = true;
2640
-
2641
- }
2642
-
2643
- }
2644
-
2645
- /**
2646
- * Transmission Materials Extension
2647
- *
2648
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
2649
- */
2650
- class GLTFMaterialsTransmissionExtension {
2651
-
2652
- constructor( writer ) {
2653
-
2654
- this.writer = writer;
2655
- this.name = 'KHR_materials_transmission';
2656
-
2657
- }
2658
-
2659
- writeMaterial( material, materialDef ) {
2660
-
2661
- if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2662
-
2663
- const writer = this.writer;
2664
- const extensionsUsed = writer.extensionsUsed;
2665
-
2666
- const extensionDef = {};
2667
-
2668
- extensionDef.transmissionFactor = material.transmission;
2669
-
2670
- if ( material.transmissionMap ) {
2671
-
2672
- const transmissionMapDef = {
2673
- index: writer.processTexture( material.transmissionMap ),
2674
- texCoord: material.transmissionMap.channel
2675
- };
2676
- writer.applyTextureTransform( transmissionMapDef, material.transmissionMap );
2677
- extensionDef.transmissionTexture = transmissionMapDef;
2678
-
2679
- }
2680
-
2681
- materialDef.extensions = materialDef.extensions || {};
2682
- materialDef.extensions[ this.name ] = extensionDef;
2683
-
2684
- extensionsUsed[ this.name ] = true;
2685
-
2686
- }
2687
-
2688
- }
2689
-
2690
- /**
2691
- * Materials Volume Extension
2692
- *
2693
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
2694
- */
2695
- class GLTFMaterialsVolumeExtension {
2696
-
2697
- constructor( writer ) {
2698
-
2699
- this.writer = writer;
2700
- this.name = 'KHR_materials_volume';
2701
-
2702
- }
2703
-
2704
- writeMaterial( material, materialDef ) {
2705
-
2706
- if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2707
-
2708
- const writer = this.writer;
2709
- const extensionsUsed = writer.extensionsUsed;
2710
-
2711
- const extensionDef = {};
2712
-
2713
- extensionDef.thicknessFactor = material.thickness;
2714
-
2715
- if ( material.thicknessMap ) {
2716
-
2717
- const thicknessMapDef = {
2718
- index: writer.processTexture( material.thicknessMap ),
2719
- texCoord: material.thicknessMap.channel
2720
- };
2721
- writer.applyTextureTransform( thicknessMapDef, material.thicknessMap );
2722
- extensionDef.thicknessTexture = thicknessMapDef;
2723
-
2724
- }
2725
-
2726
- extensionDef.attenuationDistance = material.attenuationDistance;
2727
- extensionDef.attenuationColor = material.attenuationColor.toArray();
2728
-
2729
- materialDef.extensions = materialDef.extensions || {};
2730
- materialDef.extensions[ this.name ] = extensionDef;
2731
-
2732
- extensionsUsed[ this.name ] = true;
2733
-
2734
- }
2735
-
2736
- }
2737
-
2738
- /**
2739
- * Materials ior Extension
2740
- *
2741
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
2742
- */
2743
- class GLTFMaterialsIorExtension {
2744
-
2745
- constructor( writer ) {
2746
-
2747
- this.writer = writer;
2748
- this.name = 'KHR_materials_ior';
2749
-
2750
- }
2751
-
2752
- writeMaterial( material, materialDef ) {
2753
-
2754
- if ( ! material.isMeshPhysicalMaterial || material.ior === 1.5 ) return;
2755
-
2756
- const writer = this.writer;
2757
- const extensionsUsed = writer.extensionsUsed;
2758
-
2759
- const extensionDef = {};
2760
-
2761
- extensionDef.ior = material.ior;
2762
-
2763
- materialDef.extensions = materialDef.extensions || {};
2764
- materialDef.extensions[ this.name ] = extensionDef;
2765
-
2766
- extensionsUsed[ this.name ] = true;
2767
-
2768
- }
2769
-
2770
- }
2771
-
2772
- /**
2773
- * Materials specular Extension
2774
- *
2775
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
2776
- */
2777
- class GLTFMaterialsSpecularExtension {
2778
-
2779
- constructor( writer ) {
2780
-
2781
- this.writer = writer;
2782
- this.name = 'KHR_materials_specular';
2783
-
2784
- }
2785
-
2786
- writeMaterial( material, materialDef ) {
2787
-
2788
- if ( ! material.isMeshPhysicalMaterial || ( material.specularIntensity === 1.0 &&
2789
- material.specularColor.equals( DEFAULT_SPECULAR_COLOR ) &&
2790
- ! material.specularIntensityMap && ! material.specularColorTexture ) ) return;
2791
-
2792
- const writer = this.writer;
2793
- const extensionsUsed = writer.extensionsUsed;
2794
-
2795
- const extensionDef = {};
2796
-
2797
- if ( material.specularIntensityMap ) {
2798
-
2799
- const specularIntensityMapDef = {
2800
- index: writer.processTexture( material.specularIntensityMap ),
2801
- texCoord: material.specularIntensityMap.channel
2802
- };
2803
- writer.applyTextureTransform( specularIntensityMapDef, material.specularIntensityMap );
2804
- extensionDef.specularTexture = specularIntensityMapDef;
2805
-
2806
- }
2807
-
2808
- if ( material.specularColorMap ) {
2809
-
2810
- const specularColorMapDef = {
2811
- index: writer.processTexture( material.specularColorMap ),
2812
- texCoord: material.specularColorMap.channel
2813
- };
2814
- writer.applyTextureTransform( specularColorMapDef, material.specularColorMap );
2815
- extensionDef.specularColorTexture = specularColorMapDef;
2816
-
2817
- }
2818
-
2819
- extensionDef.specularFactor = material.specularIntensity;
2820
- extensionDef.specularColorFactor = material.specularColor.toArray();
2821
-
2822
- materialDef.extensions = materialDef.extensions || {};
2823
- materialDef.extensions[ this.name ] = extensionDef;
2824
-
2825
- extensionsUsed[ this.name ] = true;
2826
-
2827
- }
2828
-
2829
- }
2830
-
2831
- /**
2832
- * Sheen Materials Extension
2833
- *
2834
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
2835
- */
2836
- class GLTFMaterialsSheenExtension {
2837
-
2838
- constructor( writer ) {
2839
-
2840
- this.writer = writer;
2841
- this.name = 'KHR_materials_sheen';
2842
-
2843
- }
2844
-
2845
- writeMaterial( material, materialDef ) {
2846
-
2847
- if ( ! material.isMeshPhysicalMaterial || material.sheen == 0.0 ) return;
2848
-
2849
- const writer = this.writer;
2850
- const extensionsUsed = writer.extensionsUsed;
2851
-
2852
- const extensionDef = {};
2853
-
2854
- if ( material.sheenRoughnessMap ) {
2855
-
2856
- const sheenRoughnessMapDef = {
2857
- index: writer.processTexture( material.sheenRoughnessMap ),
2858
- texCoord: material.sheenRoughnessMap.channel
2859
- };
2860
- writer.applyTextureTransform( sheenRoughnessMapDef, material.sheenRoughnessMap );
2861
- extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
2862
-
2863
- }
2864
-
2865
- if ( material.sheenColorMap ) {
2866
-
2867
- const sheenColorMapDef = {
2868
- index: writer.processTexture( material.sheenColorMap ),
2869
- texCoord: material.sheenColorMap.channel
2870
- };
2871
- writer.applyTextureTransform( sheenColorMapDef, material.sheenColorMap );
2872
- extensionDef.sheenColorTexture = sheenColorMapDef;
2873
-
2874
- }
2875
-
2876
- extensionDef.sheenRoughnessFactor = material.sheenRoughness;
2877
- extensionDef.sheenColorFactor = material.sheenColor.toArray();
2878
-
2879
- materialDef.extensions = materialDef.extensions || {};
2880
- materialDef.extensions[ this.name ] = extensionDef;
2881
-
2882
- extensionsUsed[ this.name ] = true;
2883
-
2884
- }
2885
-
2886
- }
2887
-
2888
- /**
2889
- * Anisotropy Materials Extension
2890
- *
2891
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_anisotropy
2892
- */
2893
- class GLTFMaterialsAnisotropyExtension {
2894
-
2895
- constructor( writer ) {
2896
-
2897
- this.writer = writer;
2898
- this.name = 'KHR_materials_anisotropy';
2899
-
2900
- }
2901
-
2902
- writeMaterial( material, materialDef ) {
2903
-
2904
- if ( ! material.isMeshPhysicalMaterial || material.anisotropy == 0.0 ) return;
2905
-
2906
- const writer = this.writer;
2907
- const extensionsUsed = writer.extensionsUsed;
2908
-
2909
- const extensionDef = {};
2910
-
2911
- if ( material.anisotropyMap ) {
2912
-
2913
- const anisotropyMapDef = { index: writer.processTexture( material.anisotropyMap ) };
2914
- writer.applyTextureTransform( anisotropyMapDef, material.anisotropyMap );
2915
- extensionDef.anisotropyTexture = anisotropyMapDef;
2916
-
2917
- }
2918
-
2919
- extensionDef.anisotropyStrength = material.anisotropy;
2920
- extensionDef.anisotropyRotation = material.anisotropyRotation;
2921
-
2922
- materialDef.extensions = materialDef.extensions || {};
2923
- materialDef.extensions[ this.name ] = extensionDef;
2924
-
2925
- extensionsUsed[ this.name ] = true;
2926
-
2927
- }
2928
-
2929
- }
2930
-
2931
- /**
2932
- * Materials Emissive Strength Extension
2933
- *
2934
- * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
2935
- */
2936
- class GLTFMaterialsEmissiveStrengthExtension {
2937
-
2938
- constructor( writer ) {
2939
-
2940
- this.writer = writer;
2941
- this.name = 'KHR_materials_emissive_strength';
2942
-
2943
- }
2944
-
2945
- writeMaterial( material, materialDef ) {
2946
-
2947
- if ( ! material.isMeshStandardMaterial || material.emissiveIntensity === 1.0 ) return;
2948
-
2949
- const writer = this.writer;
2950
- const extensionsUsed = writer.extensionsUsed;
2951
-
2952
- const extensionDef = {};
2953
-
2954
- extensionDef.emissiveStrength = material.emissiveIntensity;
2955
-
2956
- materialDef.extensions = materialDef.extensions || {};
2957
- materialDef.extensions[ this.name ] = extensionDef;
2958
-
2959
- extensionsUsed[ this.name ] = true;
2960
-
2961
- }
2962
-
2963
- }
2964
-
2965
- /**
2966
- * Static utility functions
2967
- */
2968
- GLTFExporter.Utils = {
2969
-
2970
- insertKeyframe: function ( track, time ) {
2971
-
2972
- const tolerance = 0.001; // 1ms
2973
- const valueSize = track.getValueSize();
2974
-
2975
- const times = new track.TimeBufferType( track.times.length + 1 );
2976
- const values = new track.ValueBufferType( track.values.length + valueSize );
2977
- const interpolant = track.createInterpolant( new track.ValueBufferType( valueSize ) );
2978
-
2979
- let index;
2980
-
2981
- if ( track.times.length === 0 ) {
2982
-
2983
- times[ 0 ] = time;
2984
-
2985
- for ( let i = 0; i < valueSize; i ++ ) {
2986
-
2987
- values[ i ] = 0;
2988
-
2989
- }
2990
-
2991
- index = 0;
2992
-
2993
- } else if ( time < track.times[ 0 ] ) {
2994
-
2995
- if ( Math.abs( track.times[ 0 ] - time ) < tolerance ) return 0;
2996
-
2997
- times[ 0 ] = time;
2998
- times.set( track.times, 1 );
2999
-
3000
- values.set( interpolant.evaluate( time ), 0 );
3001
- values.set( track.values, valueSize );
3002
-
3003
- index = 0;
3004
-
3005
- } else if ( time > track.times[ track.times.length - 1 ] ) {
3006
-
3007
- if ( Math.abs( track.times[ track.times.length - 1 ] - time ) < tolerance ) {
3008
-
3009
- return track.times.length - 1;
3010
-
3011
- }
3012
-
3013
- times[ times.length - 1 ] = time;
3014
- times.set( track.times, 0 );
3015
-
3016
- values.set( track.values, 0 );
3017
- values.set( interpolant.evaluate( time ), track.values.length );
3018
-
3019
- index = times.length - 1;
3020
-
3021
- } else {
3022
-
3023
- for ( let i = 0; i < track.times.length; i ++ ) {
3024
-
3025
- if ( Math.abs( track.times[ i ] - time ) < tolerance ) return i;
3026
-
3027
- if ( track.times[ i ] < time && track.times[ i + 1 ] > time ) {
3028
-
3029
- times.set( track.times.slice( 0, i + 1 ), 0 );
3030
- times[ i + 1 ] = time;
3031
- times.set( track.times.slice( i + 1 ), i + 2 );
3032
-
3033
- values.set( track.values.slice( 0, ( i + 1 ) * valueSize ), 0 );
3034
- values.set( interpolant.evaluate( time ), ( i + 1 ) * valueSize );
3035
- values.set( track.values.slice( ( i + 1 ) * valueSize ), ( i + 2 ) * valueSize );
3036
-
3037
- index = i + 1;
3038
-
3039
- break;
3040
-
3041
- }
3042
-
3043
- }
3044
-
3045
- }
3046
-
3047
- track.times = times;
3048
- track.values = values;
3049
-
3050
- return index;
3051
-
3052
- },
3053
-
3054
- mergeMorphTargetTracks: function ( clip, root ) {
3055
-
3056
- const tracks = [];
3057
- const mergedTracks = {};
3058
- const sourceTracks = clip.tracks;
3059
-
3060
- for ( let i = 0; i < sourceTracks.length; ++ i ) {
3061
-
3062
- let sourceTrack = sourceTracks[ i ];
3063
- const sourceTrackBinding = PropertyBinding.parseTrackName( sourceTrack.name );
3064
- const sourceTrackNode = PropertyBinding.findNode( root, sourceTrackBinding.nodeName );
3065
-
3066
- if ( sourceTrackBinding.propertyName !== 'morphTargetInfluences' || sourceTrackBinding.propertyIndex === undefined ) {
3067
-
3068
- // Tracks that don't affect morph targets, or that affect all morph targets together, can be left as-is.
3069
- tracks.push( sourceTrack );
3070
- continue;
3071
-
3072
- }
3073
-
3074
- if ( sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete
3075
- && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear ) {
3076
-
3077
- if ( sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
3078
-
3079
- // This should never happen, because glTF morph target animations
3080
- // affect all targets already.
3081
- throw new Error( 'THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.' );
3082
-
3083
- }
3084
-
3085
- console.warn( 'THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.' );
3086
-
3087
- sourceTrack = sourceTrack.clone();
3088
- sourceTrack.setInterpolation( InterpolateLinear );
3089
-
3090
- }
3091
-
3092
- const targetCount = sourceTrackNode.morphTargetInfluences.length;
3093
- const targetIndex = sourceTrackNode.morphTargetDictionary[ sourceTrackBinding.propertyIndex ];
3094
-
3095
- if ( targetIndex === undefined ) {
3096
-
3097
- throw new Error( 'THREE.GLTFExporter: Morph target name not found: ' + sourceTrackBinding.propertyIndex );
3098
-
3099
- }
3100
-
3101
- let mergedTrack;
3102
-
3103
- // If this is the first time we've seen this object, create a new
3104
- // track to store merged keyframe data for each morph target.
3105
- if ( mergedTracks[ sourceTrackNode.uuid ] === undefined ) {
3106
-
3107
- mergedTrack = sourceTrack.clone();
3108
-
3109
- const values = new mergedTrack.ValueBufferType( targetCount * mergedTrack.times.length );
3110
-
3111
- for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
3112
-
3113
- values[ j * targetCount + targetIndex ] = mergedTrack.values[ j ];
3114
-
3115
- }
3116
-
3117
- // We need to take into consideration the intended target node
3118
- // of our original un-merged morphTarget animation.
3119
- mergedTrack.name = ( sourceTrackBinding.nodeName || '' ) + '.morphTargetInfluences';
3120
- mergedTrack.values = values;
3121
-
3122
- mergedTracks[ sourceTrackNode.uuid ] = mergedTrack;
3123
- tracks.push( mergedTrack );
3124
-
3125
- continue;
3126
-
3127
- }
3128
-
3129
- const sourceInterpolant = sourceTrack.createInterpolant( new sourceTrack.ValueBufferType( 1 ) );
3130
-
3131
- mergedTrack = mergedTracks[ sourceTrackNode.uuid ];
3132
-
3133
- // For every existing keyframe of the merged track, write a (possibly
3134
- // interpolated) value from the source track.
3135
- for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
3136
-
3137
- mergedTrack.values[ j * targetCount + targetIndex ] = sourceInterpolant.evaluate( mergedTrack.times[ j ] );
3138
-
3139
- }
3140
-
3141
- // For every existing keyframe of the source track, write a (possibly
3142
- // new) keyframe to the merged track. Values from the previous loop may
3143
- // be written again, but keyframes are de-duplicated.
3144
- for ( let j = 0; j < sourceTrack.times.length; j ++ ) {
3145
-
3146
- const keyframeIndex = this.insertKeyframe( mergedTrack, sourceTrack.times[ j ] );
3147
- mergedTrack.values[ keyframeIndex * targetCount + targetIndex ] = sourceTrack.values[ j ];
3148
-
3149
- }
3150
-
3151
- }
3152
-
3153
- clip.tracks = tracks;
3154
-
3155
- return clip;
3156
-
3157
- }
3158
-
3159
- };
3160
-
3161
- export { GLTFExporter };