opal-js_wrap-three 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (503) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +4 -4
  4. data/lib/opal/js_wrap/three/version.rb +1 -1
  5. data/lib-opal/js_wrap/three/WebGL.js +102 -0
  6. data/lib-opal/js_wrap/three/animation/AnimationClipCreator.js +116 -0
  7. data/lib-opal/js_wrap/three/animation/CCDIKSolver.js +436 -0
  8. data/lib-opal/js_wrap/three/animation/MMDAnimationHelper.js +941 -0
  9. data/lib-opal/js_wrap/three/animation/MMDPhysics.js +1183 -0
  10. data/lib-opal/js_wrap/three/cameras/CinematicCamera.js +204 -0
  11. data/lib-opal/js_wrap/three/controls/ArcballControls.js +2649 -0
  12. data/lib-opal/js_wrap/three/controls/DragControls.js +234 -0
  13. data/lib-opal/js_wrap/three/controls/FirstPersonControls.js +301 -0
  14. data/lib-opal/js_wrap/three/controls/FlyControls.js +357 -0
  15. data/lib-opal/js_wrap/three/controls/OrbitControls.js +908 -0
  16. data/lib-opal/js_wrap/three/controls/PointerLockControls.js +173 -0
  17. data/lib-opal/js_wrap/three/controls/TrackballControls.js +666 -0
  18. data/lib-opal/js_wrap/three/controls/TransformControls.js +1210 -0
  19. data/lib-opal/js_wrap/three/controls/experimental/CameraControls.js +860 -0
  20. data/lib-opal/js_wrap/three/csm/CSM.js +346 -0
  21. data/lib-opal/js_wrap/three/csm/CSMFrustum.js +123 -0
  22. data/lib-opal/js_wrap/three/csm/CSMHelper.js +197 -0
  23. data/lib-opal/js_wrap/three/csm/CSMShader.js +29 -0
  24. data/lib-opal/js_wrap/three/curves/CurveExtras.js +544 -0
  25. data/lib-opal/js_wrap/three/curves/NURBSCurve.js +122 -0
  26. data/lib-opal/js_wrap/three/curves/NURBSSurface.js +78 -0
  27. data/lib-opal/js_wrap/three/curves/NURBSUtils.js +413 -0
  28. data/lib-opal/js_wrap/three/deprecated/Geometry.js +1373 -0
  29. data/lib-opal/js_wrap/three/effects/AnaglyphEffect.js +113 -0
  30. data/lib-opal/js_wrap/three/effects/AsciiEffect.js +267 -0
  31. data/lib-opal/js_wrap/three/effects/OutlineEffect.js +400 -0
  32. data/lib-opal/js_wrap/three/effects/ParallaxBarrierEffect.js +90 -0
  33. data/lib-opal/js_wrap/three/effects/PeppersGhostEffect.js +160 -0
  34. data/lib-opal/js_wrap/three/effects/StereoEffect.js +63 -0
  35. data/lib-opal/js_wrap/three/environments/DebugEnvironment.js +107 -0
  36. data/lib-opal/js_wrap/three/environments/RoomEnvironment.js +166 -0
  37. data/lib-opal/js_wrap/three/exporters/ColladaExporter.js +442 -0
  38. data/lib-opal/js_wrap/three/exporters/DRACOExporter.js +205 -0
  39. data/lib-opal/js_wrap/three/exporters/GLTFExporter.js +2042 -0
  40. data/lib-opal/js_wrap/three/exporters/MMDExporter.js +189 -0
  41. data/lib-opal/js_wrap/three/exporters/OBJExporter.js +241 -0
  42. data/lib-opal/js_wrap/three/exporters/PLYExporter.js +370 -0
  43. data/lib-opal/js_wrap/three/exporters/STLExporter.js +186 -0
  44. data/lib-opal/js_wrap/three/exporters/USDZExporter.js +402 -0
  45. data/lib-opal/js_wrap/three/geometries/BoxLineGeometry.js +106 -0
  46. data/lib-opal/js_wrap/three/geometries/ConvexGeometry.js +88 -0
  47. data/lib-opal/js_wrap/three/geometries/DecalGeometry.js +302 -0
  48. data/lib-opal/js_wrap/three/geometries/LightningStrike.js +817 -0
  49. data/lib-opal/js_wrap/three/geometries/ParametricGeometries.js +280 -0
  50. data/lib-opal/js_wrap/three/geometries/ParametricGeometry.js +146 -0
  51. data/lib-opal/js_wrap/three/geometries/RoundedBoxGeometry.js +183 -0
  52. data/lib-opal/js_wrap/three/geometries/TeapotGeometry.js +352 -0
  53. data/lib-opal/js_wrap/three/geometries/TextGeometry.js +76 -0
  54. data/lib-opal/js_wrap/three/helpers/LightProbeHelper.js +95 -0
  55. data/lib-opal/js_wrap/three/helpers/PositionalAudioHelper.js +138 -0
  56. data/lib-opal/js_wrap/three/helpers/RectAreaLightHelper.js +115 -0
  57. data/lib-opal/js_wrap/three/helpers/VertexNormalsHelper.js +131 -0
  58. data/lib-opal/js_wrap/three/helpers/VertexTangentsHelper.js +118 -0
  59. data/lib-opal/js_wrap/three/interactive/HTMLMesh.js +307 -0
  60. data/lib-opal/js_wrap/three/interactive/InteractiveGroup.js +138 -0
  61. data/lib-opal/js_wrap/three/interactive/SelectionBox.js +264 -0
  62. data/lib-opal/js_wrap/three/interactive/SelectionHelper.js +88 -0
  63. data/lib-opal/js_wrap/three/libs/OimoPhysics/OimoPhysics.js +46059 -0
  64. data/lib-opal/js_wrap/three/libs/OimoPhysics/index.js +92 -0
  65. data/lib-opal/js_wrap/three/libs/chevrotain.module.min.js +6947 -0
  66. data/lib-opal/js_wrap/three/libs/ecsy.module.js +1999 -0
  67. data/lib-opal/js_wrap/three/libs/fflate.module.js +3002 -0
  68. data/lib-opal/js_wrap/three/libs/flow.module.js +3033 -0
  69. data/lib-opal/js_wrap/three/libs/ktx-parse.module.js +392 -0
  70. data/lib-opal/js_wrap/three/libs/lil-gui.module.min.js +821 -0
  71. data/lib-opal/js_wrap/three/libs/meshopt_decoder.module.js +136 -0
  72. data/lib-opal/js_wrap/three/libs/mmdparser.module.js +11022 -0
  73. data/lib-opal/js_wrap/three/libs/motion-controllers.module.js +589 -0
  74. data/lib-opal/js_wrap/three/libs/opentype.module.min.js +6132 -0
  75. data/lib-opal/js_wrap/three/libs/potpack.module.js +171 -0
  76. data/lib-opal/js_wrap/three/libs/rhino3dm/rhino3dm.js +6781 -0
  77. data/lib-opal/js_wrap/three/libs/rhino3dm/rhino3dm.module.js +6783 -0
  78. data/lib-opal/js_wrap/three/libs/stats.module.js +139 -0
  79. data/lib-opal/js_wrap/three/libs/tween.module.min.js +349 -0
  80. data/lib-opal/js_wrap/three/lights/LightProbeGenerator.js +233 -0
  81. data/lib-opal/js_wrap/three/lights/RectAreaLightUniformsLib.js +75 -0
  82. data/lib-opal/js_wrap/three/lines/Line2.js +66 -0
  83. data/lib-opal/js_wrap/three/lines/LineGeometry.js +122 -0
  84. data/lib-opal/js_wrap/three/lines/LineMaterial.js +227 -0
  85. data/lib-opal/js_wrap/three/lines/LineSegments2.js +312 -0
  86. data/lib-opal/js_wrap/three/lines/LineSegmentsGeometry.js +238 -0
  87. data/lib-opal/js_wrap/three/lines/Wireframe.js +98 -0
  88. data/lib-opal/js_wrap/three/lines/WireframeGeometry2.js +65 -0
  89. data/lib-opal/js_wrap/three/loaders/3DMLoader.js +1230 -0
  90. data/lib-opal/js_wrap/three/loaders/3MFLoader.js +1123 -0
  91. data/lib-opal/js_wrap/three/loaders/AMFLoader.js +445 -0
  92. data/lib-opal/js_wrap/three/loaders/BVHLoader.js +365 -0
  93. data/lib-opal/js_wrap/three/loaders/BasisTextureLoader.js +692 -0
  94. data/lib-opal/js_wrap/three/loaders/ColladaLoader.js +3046 -0
  95. data/lib-opal/js_wrap/three/loaders/DDSLoader.js +264 -0
  96. data/lib-opal/js_wrap/three/loaders/DRACOLoader.js +531 -0
  97. data/lib-opal/js_wrap/three/loaders/EXRLoader.js +1834 -0
  98. data/lib-opal/js_wrap/three/loaders/FBXLoader.js +3125 -0
  99. data/lib-opal/js_wrap/three/loaders/FontLoader.js +201 -0
  100. data/lib-opal/js_wrap/three/loaders/GCodeLoader.js +248 -0
  101. data/lib-opal/js_wrap/three/loaders/GLTFLoader.js +3334 -0
  102. data/lib-opal/js_wrap/three/loaders/HDRCubeTextureLoader.js +144 -0
  103. data/lib-opal/js_wrap/three/loaders/IFCLoader.js +2395 -0
  104. data/lib-opal/js_wrap/three/loaders/KMZLoader.js +142 -0
  105. data/lib-opal/js_wrap/three/loaders/KTX2Loader.js +535 -0
  106. data/lib-opal/js_wrap/three/loaders/KTXLoader.js +202 -0
  107. data/lib-opal/js_wrap/three/loaders/LDrawLoader.js +1737 -0
  108. data/lib-opal/js_wrap/three/loaders/LUT3dlLoader.js +163 -0
  109. data/lib-opal/js_wrap/three/loaders/LUTCubeLoader.js +171 -0
  110. data/lib-opal/js_wrap/three/loaders/LWOLoader.js +831 -0
  111. data/lib-opal/js_wrap/three/loaders/LogLuvLoader.js +713 -0
  112. data/lib-opal/js_wrap/three/loaders/LottieLoader.js +103 -0
  113. data/lib-opal/js_wrap/three/loaders/MD2Loader.js +258 -0
  114. data/lib-opal/js_wrap/three/loaders/MDDLoader.js +116 -0
  115. data/lib-opal/js_wrap/three/loaders/MMDLoader.js +1687 -0
  116. data/lib-opal/js_wrap/three/loaders/MTLLoader.js +465 -0
  117. data/lib-opal/js_wrap/three/loaders/NRRDLoader.js +554 -0
  118. data/lib-opal/js_wrap/three/loaders/NodeMaterialLoader.js +248 -0
  119. data/lib-opal/js_wrap/three/loaders/OBJLoader.js +673 -0
  120. data/lib-opal/js_wrap/three/loaders/PCDLoader.js +322 -0
  121. data/lib-opal/js_wrap/three/loaders/PDBLoader.js +318 -0
  122. data/lib-opal/js_wrap/three/loaders/PLYLoader.js +489 -0
  123. data/lib-opal/js_wrap/three/loaders/PRWMLoader.js +247 -0
  124. data/lib-opal/js_wrap/three/loaders/PVRLoader.js +240 -0
  125. data/lib-opal/js_wrap/three/loaders/RGBELoader.js +462 -0
  126. data/lib-opal/js_wrap/three/loaders/RGBMLoader.js +1169 -0
  127. data/lib-opal/js_wrap/three/loaders/STLLoader.js +345 -0
  128. data/lib-opal/js_wrap/three/loaders/SVGLoader.js +2162 -0
  129. data/lib-opal/js_wrap/three/loaders/TDSLoader.js +982 -0
  130. data/lib-opal/js_wrap/three/loaders/TGALoader.js +444 -0
  131. data/lib-opal/js_wrap/three/loaders/TTFLoader.js +210 -0
  132. data/lib-opal/js_wrap/three/loaders/TiltLoader.js +391 -0
  133. data/lib-opal/js_wrap/three/loaders/VOXLoader.js +272 -0
  134. data/lib-opal/js_wrap/three/loaders/VRMLLoader.js +2685 -0
  135. data/lib-opal/js_wrap/three/loaders/VRMLoader.js +103 -0
  136. data/lib-opal/js_wrap/three/loaders/VTKLoader.js +894 -0
  137. data/lib-opal/js_wrap/three/loaders/XYZLoader.js +136 -0
  138. data/lib-opal/js_wrap/three/loaders/ifc/web-ifc-api.js +60504 -0
  139. data/lib-opal/js_wrap/three/loaders/lwo/IFFParser.js +931 -0
  140. data/lib-opal/js_wrap/three/loaders/lwo/LWO2Parser.js +450 -0
  141. data/lib-opal/js_wrap/three/loaders/lwo/LWO3Parser.js +406 -0
  142. data/lib-opal/js_wrap/three/math/Capsule.js +133 -0
  143. data/lib-opal/js_wrap/three/math/ColorConverter.js +104 -0
  144. data/lib-opal/js_wrap/three/math/ConvexHull.js +924 -0
  145. data/lib-opal/js_wrap/three/math/ImprovedNoise.js +86 -0
  146. data/lib-opal/js_wrap/three/math/Lut.js +170 -0
  147. data/lib-opal/js_wrap/three/math/MeshSurfaceSampler.js +187 -0
  148. data/lib-opal/js_wrap/three/math/OBB.js +345 -0
  149. data/lib-opal/js_wrap/three/math/Octree.js +409 -0
  150. data/lib-opal/js_wrap/three/math/SimplexNoise.js +425 -0
  151. data/lib-opal/js_wrap/three/misc/ConvexObjectBreaker.js +447 -0
  152. data/lib-opal/js_wrap/three/misc/GPUComputationRenderer.js +322 -0
  153. data/lib-opal/js_wrap/three/misc/Gyroscope.js +94 -0
  154. data/lib-opal/js_wrap/three/misc/MD2Character.js +225 -0
  155. data/lib-opal/js_wrap/three/misc/MD2CharacterComplex.js +424 -0
  156. data/lib-opal/js_wrap/three/misc/MorphAnimMesh.js +109 -0
  157. data/lib-opal/js_wrap/three/misc/MorphBlendMesh.js +283 -0
  158. data/lib-opal/js_wrap/three/misc/ProgressiveLightMap.js +324 -0
  159. data/lib-opal/js_wrap/three/misc/RollerCoaster.js +489 -0
  160. data/lib-opal/js_wrap/three/misc/TubePainter.js +158 -0
  161. data/lib-opal/js_wrap/three/misc/Volume.js +427 -0
  162. data/lib-opal/js_wrap/three/misc/VolumeSlice.js +210 -0
  163. data/lib-opal/js_wrap/three/modifiers/CurveModifier.js +291 -0
  164. data/lib-opal/js_wrap/three/modifiers/EdgeSplitModifier.js +308 -0
  165. data/lib-opal/js_wrap/three/modifiers/SimplifyModifier.js +435 -0
  166. data/lib-opal/js_wrap/three/modifiers/TessellateModifier.js +264 -0
  167. data/lib-opal/js_wrap/three/node-editor/NodeEditor.js +402 -0
  168. data/lib-opal/js_wrap/three/node-editor/accessors/NormalEditor.js +80 -0
  169. data/lib-opal/js_wrap/three/node-editor/accessors/PositionEditor.js +80 -0
  170. data/lib-opal/js_wrap/three/node-editor/accessors/UVEditor.js +71 -0
  171. data/lib-opal/js_wrap/three/node-editor/display/BlendEditor.js +78 -0
  172. data/lib-opal/js_wrap/three/node-editor/inputs/ColorEditor.js +111 -0
  173. data/lib-opal/js_wrap/three/node-editor/inputs/FloatEditor.js +69 -0
  174. data/lib-opal/js_wrap/three/node-editor/inputs/SliderEditor.js +97 -0
  175. data/lib-opal/js_wrap/three/node-editor/inputs/Vector2Editor.js +73 -0
  176. data/lib-opal/js_wrap/three/node-editor/inputs/Vector3Editor.js +75 -0
  177. data/lib-opal/js_wrap/three/node-editor/inputs/Vector4Editor.js +77 -0
  178. data/lib-opal/js_wrap/three/node-editor/materials/StandardMaterialEditor.js +121 -0
  179. data/lib-opal/js_wrap/three/node-editor/math/DotEditor.js +76 -0
  180. data/lib-opal/js_wrap/three/node-editor/math/InvertEditor.js +80 -0
  181. data/lib-opal/js_wrap/three/node-editor/math/LimiterEditor.js +85 -0
  182. data/lib-opal/js_wrap/three/node-editor/math/NormalizeEditor.js +69 -0
  183. data/lib-opal/js_wrap/three/node-editor/math/OperatorEditor.js +91 -0
  184. data/lib-opal/js_wrap/three/node-editor/math/PowerEditor.js +73 -0
  185. data/lib-opal/js_wrap/three/node-editor/math/TrigonometryEditor.js +83 -0
  186. data/lib-opal/js_wrap/three/node-editor/procedural/CheckerEditor.js +69 -0
  187. data/lib-opal/js_wrap/three/node-editor/utils/OscillatorEditor.js +87 -0
  188. data/lib-opal/js_wrap/three/node-editor/utils/TimerEditor.js +89 -0
  189. data/lib-opal/js_wrap/three/nodes/Nodes.js +481 -0
  190. data/lib-opal/js_wrap/three/nodes/accessors/CameraNode.js +222 -0
  191. data/lib-opal/js_wrap/three/nodes/accessors/ColorsNode.js +99 -0
  192. data/lib-opal/js_wrap/three/nodes/accessors/LightNode.js +100 -0
  193. data/lib-opal/js_wrap/three/nodes/accessors/NormalNode.js +152 -0
  194. data/lib-opal/js_wrap/three/nodes/accessors/PositionNode.js +163 -0
  195. data/lib-opal/js_wrap/three/nodes/accessors/ReflectNode.js +161 -0
  196. data/lib-opal/js_wrap/three/nodes/accessors/ResolutionNode.js +99 -0
  197. data/lib-opal/js_wrap/three/nodes/accessors/ScreenUVNode.js +101 -0
  198. data/lib-opal/js_wrap/three/nodes/accessors/UVNode.js +105 -0
  199. data/lib-opal/js_wrap/three/nodes/core/AttributeNode.js +106 -0
  200. data/lib-opal/js_wrap/three/nodes/core/ConstNode.js +149 -0
  201. data/lib-opal/js_wrap/three/nodes/core/ExpressionNode.js +57 -0
  202. data/lib-opal/js_wrap/three/nodes/core/FunctionCallNode.js +138 -0
  203. data/lib-opal/js_wrap/three/nodes/core/FunctionNode.js +259 -0
  204. data/lib-opal/js_wrap/three/nodes/core/InputNode.js +124 -0
  205. data/lib-opal/js_wrap/three/nodes/core/Node.js +193 -0
  206. data/lib-opal/js_wrap/three/nodes/core/NodeBuilder.js +782 -0
  207. data/lib-opal/js_wrap/three/nodes/core/NodeFrame.js +69 -0
  208. data/lib-opal/js_wrap/three/nodes/core/NodeLib.js +56 -0
  209. data/lib-opal/js_wrap/three/nodes/core/NodeUniform.js +53 -0
  210. data/lib-opal/js_wrap/three/nodes/core/NodeUtils.js +60 -0
  211. data/lib-opal/js_wrap/three/nodes/core/StructNode.js +131 -0
  212. data/lib-opal/js_wrap/three/nodes/core/TempNode.js +160 -0
  213. data/lib-opal/js_wrap/three/nodes/core/VarNode.js +105 -0
  214. data/lib-opal/js_wrap/three/nodes/effects/BlurNode.js +160 -0
  215. data/lib-opal/js_wrap/three/nodes/effects/ColorAdjustmentNode.js +139 -0
  216. data/lib-opal/js_wrap/three/nodes/effects/LuminanceNode.js +106 -0
  217. data/lib-opal/js_wrap/three/nodes/inputs/BoolNode.js +95 -0
  218. data/lib-opal/js_wrap/three/nodes/inputs/ColorNode.js +99 -0
  219. data/lib-opal/js_wrap/three/nodes/inputs/CubeTextureNode.js +136 -0
  220. data/lib-opal/js_wrap/three/nodes/inputs/FloatNode.js +95 -0
  221. data/lib-opal/js_wrap/three/nodes/inputs/IntNode.js +95 -0
  222. data/lib-opal/js_wrap/three/nodes/inputs/Matrix3Node.js +102 -0
  223. data/lib-opal/js_wrap/three/nodes/inputs/Matrix4Node.js +102 -0
  224. data/lib-opal/js_wrap/three/nodes/inputs/PropertyNode.js +85 -0
  225. data/lib-opal/js_wrap/three/nodes/inputs/RTTNode.js +164 -0
  226. data/lib-opal/js_wrap/three/nodes/inputs/ReflectorNode.js +111 -0
  227. data/lib-opal/js_wrap/three/nodes/inputs/ScreenNode.js +69 -0
  228. data/lib-opal/js_wrap/three/nodes/inputs/TextureNode.js +140 -0
  229. data/lib-opal/js_wrap/three/nodes/inputs/Vector2Node.js +98 -0
  230. data/lib-opal/js_wrap/three/nodes/inputs/Vector3Node.js +99 -0
  231. data/lib-opal/js_wrap/three/nodes/inputs/Vector4Node.js +100 -0
  232. data/lib-opal/js_wrap/three/nodes/materials/BasicNodeMaterial.js +63 -0
  233. data/lib-opal/js_wrap/three/nodes/materials/MeshStandardNodeMaterial.js +63 -0
  234. data/lib-opal/js_wrap/three/nodes/materials/NodeMaterial.js +202 -0
  235. data/lib-opal/js_wrap/three/nodes/materials/PhongNodeMaterial.js +63 -0
  236. data/lib-opal/js_wrap/three/nodes/materials/SpriteNodeMaterial.js +63 -0
  237. data/lib-opal/js_wrap/three/nodes/materials/StandardNodeMaterial.js +63 -0
  238. data/lib-opal/js_wrap/three/nodes/materials/nodes/BasicNode.js +146 -0
  239. data/lib-opal/js_wrap/three/nodes/materials/nodes/MeshStandardNode.js +133 -0
  240. data/lib-opal/js_wrap/three/nodes/materials/nodes/PhongNode.js +273 -0
  241. data/lib-opal/js_wrap/three/nodes/materials/nodes/RawNode.js +101 -0
  242. data/lib-opal/js_wrap/three/nodes/materials/nodes/SpriteNode.js +176 -0
  243. data/lib-opal/js_wrap/three/nodes/materials/nodes/StandardNode.js +397 -0
  244. data/lib-opal/js_wrap/three/nodes/math/CondNode.js +151 -0
  245. data/lib-opal/js_wrap/three/nodes/math/MathNode.js +266 -0
  246. data/lib-opal/js_wrap/three/nodes/math/OperatorNode.js +120 -0
  247. data/lib-opal/js_wrap/three/nodes/misc/BumpMapNode.js +139 -0
  248. data/lib-opal/js_wrap/three/nodes/misc/NormalMapNode.js +122 -0
  249. data/lib-opal/js_wrap/three/nodes/misc/TextureCubeNode.js +107 -0
  250. data/lib-opal/js_wrap/three/nodes/misc/TextureCubeUVNode.js +191 -0
  251. data/lib-opal/js_wrap/three/nodes/postprocessing/NodePass.js +117 -0
  252. data/lib-opal/js_wrap/three/nodes/postprocessing/NodePostProcessing.js +128 -0
  253. data/lib-opal/js_wrap/three/nodes/procedural/CheckerNode.js +104 -0
  254. data/lib-opal/js_wrap/three/nodes/procedural/Fractal3DNode.js +121 -0
  255. data/lib-opal/js_wrap/three/nodes/procedural/Noise2DNode.js +115 -0
  256. data/lib-opal/js_wrap/three/nodes/procedural/Noise3DNode.js +112 -0
  257. data/lib-opal/js_wrap/three/nodes/utils/BypassNode.js +115 -0
  258. data/lib-opal/js_wrap/three/nodes/utils/ColorSpaceNode.js +214 -0
  259. data/lib-opal/js_wrap/three/nodes/utils/JoinNode.js +138 -0
  260. data/lib-opal/js_wrap/three/nodes/utils/MaxMIPLevelNode.js +88 -0
  261. data/lib-opal/js_wrap/three/nodes/utils/RemapNode.js +117 -0
  262. data/lib-opal/js_wrap/three/nodes/utils/SpecularMIPLevelNode.js +121 -0
  263. data/lib-opal/js_wrap/three/nodes/utils/SubSlotNode.js +112 -0
  264. data/lib-opal/js_wrap/three/nodes/utils/SwitchNode.js +129 -0
  265. data/lib-opal/js_wrap/three/nodes/utils/TimerNode.js +126 -0
  266. data/lib-opal/js_wrap/three/nodes/utils/UVTransformNode.js +104 -0
  267. data/lib-opal/js_wrap/three/nodes/utils/VelocityNode.js +181 -0
  268. data/lib-opal/js_wrap/three/objects/Lensflare.js +285 -0
  269. data/lib-opal/js_wrap/three/objects/LightningStorm.js +238 -0
  270. data/lib-opal/js_wrap/three/objects/MarchingCubes.js +667 -0
  271. data/lib-opal/js_wrap/three/objects/Reflector.js +205 -0
  272. data/lib-opal/js_wrap/three/objects/ReflectorForSSRPass.js +288 -0
  273. data/lib-opal/js_wrap/three/objects/ReflectorRTT.js +63 -0
  274. data/lib-opal/js_wrap/three/objects/Refractor.js +243 -0
  275. data/lib-opal/js_wrap/three/objects/ShadowMesh.js +100 -0
  276. data/lib-opal/js_wrap/three/objects/Sky.js +107 -0
  277. data/lib-opal/js_wrap/three/objects/Water.js +246 -0
  278. data/lib-opal/js_wrap/three/objects/Water2.js +238 -0
  279. data/lib-opal/js_wrap/three/offscreen/jank.js +51 -0
  280. data/lib-opal/js_wrap/three/offscreen/offscreen.js +24 -0
  281. data/lib-opal/js_wrap/three/offscreen/scene.js +99 -0
  282. data/lib-opal/js_wrap/three/physics/AmmoPhysics.js +266 -0
  283. data/lib-opal/js_wrap/three/physics/OimoPhysics.js +214 -0
  284. data/lib-opal/js_wrap/three/postprocessing/AdaptiveToneMappingPass.js +307 -0
  285. data/lib-opal/js_wrap/three/postprocessing/AfterimagePass.js +116 -0
  286. data/lib-opal/js_wrap/three/postprocessing/BloomPass.js +132 -0
  287. data/lib-opal/js_wrap/three/postprocessing/BokehPass.js +143 -0
  288. data/lib-opal/js_wrap/three/postprocessing/ClearPass.js +85 -0
  289. data/lib-opal/js_wrap/three/postprocessing/CubeTexturePass.js +104 -0
  290. data/lib-opal/js_wrap/three/postprocessing/DotScreenPass.js +90 -0
  291. data/lib-opal/js_wrap/three/postprocessing/EffectComposer.js +272 -0
  292. data/lib-opal/js_wrap/three/postprocessing/FilmPass.js +91 -0
  293. data/lib-opal/js_wrap/three/postprocessing/GlitchPass.js +140 -0
  294. data/lib-opal/js_wrap/three/postprocessing/HalftonePass.js +108 -0
  295. data/lib-opal/js_wrap/three/postprocessing/LUTPass.js +132 -0
  296. data/lib-opal/js_wrap/three/postprocessing/MaskPass.js +142 -0
  297. data/lib-opal/js_wrap/three/postprocessing/OutlinePass.js +480 -0
  298. data/lib-opal/js_wrap/three/postprocessing/Pass.js +101 -0
  299. data/lib-opal/js_wrap/three/postprocessing/RenderPass.js +109 -0
  300. data/lib-opal/js_wrap/three/postprocessing/SAOPass.js +384 -0
  301. data/lib-opal/js_wrap/three/postprocessing/SMAAPass.js +199 -0
  302. data/lib-opal/js_wrap/three/postprocessing/SSAARenderPass.js +186 -0
  303. data/lib-opal/js_wrap/three/postprocessing/SSAOPass.js +388 -0
  304. data/lib-opal/js_wrap/three/postprocessing/SSRPass.js +537 -0
  305. data/lib-opal/js_wrap/three/postprocessing/SSRrPass.js +481 -0
  306. data/lib-opal/js_wrap/three/postprocessing/SavePass.js +96 -0
  307. data/lib-opal/js_wrap/three/postprocessing/ShaderPass.js +98 -0
  308. data/lib-opal/js_wrap/three/postprocessing/TAARenderPass.js +159 -0
  309. data/lib-opal/js_wrap/three/postprocessing/TexturePass.js +91 -0
  310. data/lib-opal/js_wrap/three/postprocessing/UnrealBloomPass.js +335 -0
  311. data/lib-opal/js_wrap/three/renderers/CSS2DRenderer.js +213 -0
  312. data/lib-opal/js_wrap/three/renderers/CSS3DRenderer.js +277 -0
  313. data/lib-opal/js_wrap/three/renderers/Projector.js +733 -0
  314. data/lib-opal/js_wrap/three/renderers/SVGRenderer.js +470 -0
  315. data/lib-opal/js_wrap/three/renderers/nodes/Nodes.js +531 -0
  316. data/lib-opal/js_wrap/three/renderers/nodes/ShaderNode.js +386 -0
  317. data/lib-opal/js_wrap/three/renderers/nodes/accessors/CameraNode.js +114 -0
  318. data/lib-opal/js_wrap/three/renderers/nodes/accessors/MaterialNode.js +140 -0
  319. data/lib-opal/js_wrap/three/renderers/nodes/accessors/MaterialReferenceNode.js +79 -0
  320. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ModelNode.js +62 -0
  321. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ModelViewProjectionNode.js +80 -0
  322. data/lib-opal/js_wrap/three/renderers/nodes/accessors/NormalNode.js +113 -0
  323. data/lib-opal/js_wrap/three/renderers/nodes/accessors/Object3DNode.js +136 -0
  324. data/lib-opal/js_wrap/three/renderers/nodes/accessors/PointUVNode.js +70 -0
  325. data/lib-opal/js_wrap/three/renderers/nodes/accessors/PositionNode.js +117 -0
  326. data/lib-opal/js_wrap/three/renderers/nodes/accessors/ReferenceNode.js +124 -0
  327. data/lib-opal/js_wrap/three/renderers/nodes/accessors/SkinningNode.js +129 -0
  328. data/lib-opal/js_wrap/three/renderers/nodes/accessors/UVNode.js +77 -0
  329. data/lib-opal/js_wrap/three/renderers/nodes/core/ArrayInputNode.js +74 -0
  330. data/lib-opal/js_wrap/three/renderers/nodes/core/AttributeNode.js +97 -0
  331. data/lib-opal/js_wrap/three/renderers/nodes/core/BypassNode.js +84 -0
  332. data/lib-opal/js_wrap/three/renderers/nodes/core/CodeNode.js +131 -0
  333. data/lib-opal/js_wrap/three/renderers/nodes/core/ContextNode.js +84 -0
  334. data/lib-opal/js_wrap/three/renderers/nodes/core/ExpressionNode.js +81 -0
  335. data/lib-opal/js_wrap/three/renderers/nodes/core/FunctionCallNode.js +123 -0
  336. data/lib-opal/js_wrap/three/renderers/nodes/core/FunctionNode.js +126 -0
  337. data/lib-opal/js_wrap/three/renderers/nodes/core/InputNode.js +103 -0
  338. data/lib-opal/js_wrap/three/renderers/nodes/core/Node.js +120 -0
  339. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeAttribute.js +37 -0
  340. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeBuilder.js +650 -0
  341. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeCode.js +42 -0
  342. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFrame.js +70 -0
  343. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFunction.js +55 -0
  344. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeFunctionInput.js +44 -0
  345. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeKeywords.js +117 -0
  346. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeParser.js +46 -0
  347. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeUniform.js +55 -0
  348. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeVar.js +37 -0
  349. data/lib-opal/js_wrap/three/renderers/nodes/core/NodeVary.js +37 -0
  350. data/lib-opal/js_wrap/three/renderers/nodes/core/PropertyNode.js +90 -0
  351. data/lib-opal/js_wrap/three/renderers/nodes/core/TempNode.js +89 -0
  352. data/lib-opal/js_wrap/three/renderers/nodes/core/VarNode.js +101 -0
  353. data/lib-opal/js_wrap/three/renderers/nodes/core/VaryNode.js +101 -0
  354. data/lib-opal/js_wrap/three/renderers/nodes/core/constants.js +42 -0
  355. data/lib-opal/js_wrap/three/renderers/nodes/display/ColorSpaceNode.js +165 -0
  356. data/lib-opal/js_wrap/three/renderers/nodes/display/NormalMapNode.js +120 -0
  357. data/lib-opal/js_wrap/three/renderers/nodes/functions/BSDFs.js +133 -0
  358. data/lib-opal/js_wrap/three/renderers/nodes/inputs/BufferNode.js +78 -0
  359. data/lib-opal/js_wrap/three/renderers/nodes/inputs/ColorNode.js +67 -0
  360. data/lib-opal/js_wrap/three/renderers/nodes/inputs/FloatNode.js +67 -0
  361. data/lib-opal/js_wrap/three/renderers/nodes/inputs/IntNode.js +67 -0
  362. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Matrix3Node.js +67 -0
  363. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Matrix4Node.js +67 -0
  364. data/lib-opal/js_wrap/three/renderers/nodes/inputs/TextureNode.js +120 -0
  365. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector2Node.js +67 -0
  366. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector3Node.js +67 -0
  367. data/lib-opal/js_wrap/three/renderers/nodes/inputs/Vector4Node.js +67 -0
  368. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightContextNode.js +103 -0
  369. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightNode.js +115 -0
  370. data/lib-opal/js_wrap/three/renderers/nodes/lights/LightsNode.js +117 -0
  371. data/lib-opal/js_wrap/three/renderers/nodes/materials/LineBasicNodeMaterial.js +82 -0
  372. data/lib-opal/js_wrap/three/renderers/nodes/materials/Materials.js +49 -0
  373. data/lib-opal/js_wrap/three/renderers/nodes/materials/MeshBasicNodeMaterial.js +82 -0
  374. data/lib-opal/js_wrap/three/renderers/nodes/materials/MeshStandardNodeMaterial.js +96 -0
  375. data/lib-opal/js_wrap/three/renderers/nodes/materials/PointsNodeMaterial.js +84 -0
  376. data/lib-opal/js_wrap/three/renderers/nodes/math/CondNode.js +98 -0
  377. data/lib-opal/js_wrap/three/renderers/nodes/math/MathNode.js +255 -0
  378. data/lib-opal/js_wrap/three/renderers/nodes/math/OperatorNode.js +163 -0
  379. data/lib-opal/js_wrap/three/renderers/nodes/parsers/GLSLNodeFunction.js +158 -0
  380. data/lib-opal/js_wrap/three/renderers/nodes/parsers/GLSLNodeParser.js +68 -0
  381. data/lib-opal/js_wrap/three/renderers/nodes/parsers/WGSLNodeFunction.js +126 -0
  382. data/lib-opal/js_wrap/three/renderers/nodes/parsers/WGSLNodeParser.js +68 -0
  383. data/lib-opal/js_wrap/three/renderers/nodes/procedural/CheckerNode.js +84 -0
  384. data/lib-opal/js_wrap/three/renderers/nodes/utils/ArrayElementNode.js +79 -0
  385. data/lib-opal/js_wrap/three/renderers/nodes/utils/ConvertNode.js +82 -0
  386. data/lib-opal/js_wrap/three/renderers/nodes/utils/JoinNode.js +88 -0
  387. data/lib-opal/js_wrap/three/renderers/nodes/utils/OscNode.js +105 -0
  388. data/lib-opal/js_wrap/three/renderers/nodes/utils/SplitNode.js +96 -0
  389. data/lib-opal/js_wrap/three/renderers/nodes/utils/SpriteSheetUVNode.js +98 -0
  390. data/lib-opal/js_wrap/three/renderers/nodes/utils/TimerNode.js +93 -0
  391. data/lib-opal/js_wrap/three/renderers/webgl/nodes/SlotNode.js +72 -0
  392. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLNodeBuilder.js +463 -0
  393. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLNodes.js +62 -0
  394. data/lib-opal/js_wrap/three/renderers/webgl/nodes/WebGLPhysicalContextNode.js +95 -0
  395. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPU.js +62 -0
  396. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUAttributes.js +118 -0
  397. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBackground.js +109 -0
  398. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBinding.js +52 -0
  399. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBindings.js +254 -0
  400. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUBufferUtils.js +39 -0
  401. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUComputePipelines.js +82 -0
  402. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUGeometries.js +84 -0
  403. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUInfo.js +86 -0
  404. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUObjects.js +64 -0
  405. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUProgrammableStage.js +46 -0
  406. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUProperties.js +63 -0
  407. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderLists.js +180 -0
  408. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderPipeline.js +662 -0
  409. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderPipelines.js +275 -0
  410. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPURenderer.js +883 -0
  411. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUSampledTexture.js +139 -0
  412. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUSampler.js +76 -0
  413. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUStorageBuffer.js +69 -0
  414. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextureRenderer.js +64 -0
  415. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextureUtils.js +125 -0
  416. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUTextures.js +681 -0
  417. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniform.js +237 -0
  418. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniformBuffer.js +90 -0
  419. data/lib-opal/js_wrap/three/renderers/webgpu/WebGPUUniformsGroup.js +294 -0
  420. data/lib-opal/js_wrap/three/renderers/webgpu/constants.js +263 -0
  421. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeBuilder.js +619 -0
  422. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeSampledTexture.js +67 -0
  423. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeSampler.js +71 -0
  424. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeUniform.js +229 -0
  425. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +68 -0
  426. data/lib-opal/js_wrap/three/renderers/webgpu/nodes/WebGPUNodes.js +106 -0
  427. data/lib-opal/js_wrap/three/shaders/ACESFilmicToneMappingShader.js +45 -0
  428. data/lib-opal/js_wrap/three/shaders/AfterimageShader.js +46 -0
  429. data/lib-opal/js_wrap/three/shaders/BasicShader.js +34 -0
  430. data/lib-opal/js_wrap/three/shaders/BleachBypassShader.js +43 -0
  431. data/lib-opal/js_wrap/three/shaders/BlendShader.js +47 -0
  432. data/lib-opal/js_wrap/three/shaders/BokehShader.js +65 -0
  433. data/lib-opal/js_wrap/three/shaders/BokehShader2.js +125 -0
  434. data/lib-opal/js_wrap/three/shaders/BrightnessContrastShader.js +47 -0
  435. data/lib-opal/js_wrap/three/shaders/ColorCorrectionShader.js +47 -0
  436. data/lib-opal/js_wrap/three/shaders/ColorifyShader.js +41 -0
  437. data/lib-opal/js_wrap/three/shaders/ConvolutionShader.js +75 -0
  438. data/lib-opal/js_wrap/three/shaders/CopyShader.js +41 -0
  439. data/lib-opal/js_wrap/three/shaders/DOFMipMapShader.js +49 -0
  440. data/lib-opal/js_wrap/three/shaders/DepthLimitedBlurShader.js +95 -0
  441. data/lib-opal/js_wrap/three/shaders/DigitalGlitch.js +79 -0
  442. data/lib-opal/js_wrap/three/shaders/DotScreenShader.js +52 -0
  443. data/lib-opal/js_wrap/three/shaders/FXAAShader.js +78 -0
  444. data/lib-opal/js_wrap/three/shaders/FilmShader.js +69 -0
  445. data/lib-opal/js_wrap/three/shaders/FocusShader.js +52 -0
  446. data/lib-opal/js_wrap/three/shaders/FreiChenShader.js +44 -0
  447. data/lib-opal/js_wrap/three/shaders/GammaCorrectionShader.js +39 -0
  448. data/lib-opal/js_wrap/three/shaders/GodRaysShader.js +140 -0
  449. data/lib-opal/js_wrap/three/shaders/HalftoneShader.js +77 -0
  450. data/lib-opal/js_wrap/three/shaders/HorizontalBlurShader.js +47 -0
  451. data/lib-opal/js_wrap/three/shaders/HorizontalTiltShiftShader.js +49 -0
  452. data/lib-opal/js_wrap/three/shaders/HueSaturationShader.js +47 -0
  453. data/lib-opal/js_wrap/three/shaders/KaleidoShader.js +50 -0
  454. data/lib-opal/js_wrap/three/shaders/LuminosityHighPassShader.js +52 -0
  455. data/lib-opal/js_wrap/three/shaders/LuminosityShader.js +39 -0
  456. data/lib-opal/js_wrap/three/shaders/MMDToonShader.js +48 -0
  457. data/lib-opal/js_wrap/three/shaders/MirrorShader.js +44 -0
  458. data/lib-opal/js_wrap/three/shaders/NormalMapShader.js +48 -0
  459. data/lib-opal/js_wrap/three/shaders/PixelShader.js +44 -0
  460. data/lib-opal/js_wrap/three/shaders/RGBShiftShader.js +50 -0
  461. data/lib-opal/js_wrap/three/shaders/SAOShader.js +85 -0
  462. data/lib-opal/js_wrap/three/shaders/SMAAShader.js +95 -0
  463. data/lib-opal/js_wrap/three/shaders/SSAOShader.js +113 -0
  464. data/lib-opal/js_wrap/three/shaders/SSRShader.js +126 -0
  465. data/lib-opal/js_wrap/three/shaders/SSRrShader.js +106 -0
  466. data/lib-opal/js_wrap/three/shaders/SepiaShader.js +43 -0
  467. data/lib-opal/js_wrap/three/shaders/SobelOperatorShader.js +44 -0
  468. data/lib-opal/js_wrap/three/shaders/SubsurfaceScatteringShader.js +64 -0
  469. data/lib-opal/js_wrap/three/shaders/TechnicolorShader.js +41 -0
  470. data/lib-opal/js_wrap/three/shaders/ToneMapShader.js +53 -0
  471. data/lib-opal/js_wrap/three/shaders/ToonShader.js +148 -0
  472. data/lib-opal/js_wrap/three/shaders/TriangleBlurShader.js +47 -0
  473. data/lib-opal/js_wrap/three/shaders/UnpackDepthRGBAShader.js +42 -0
  474. data/lib-opal/js_wrap/three/shaders/VerticalBlurShader.js +47 -0
  475. data/lib-opal/js_wrap/three/shaders/VerticalTiltShiftShader.js +49 -0
  476. data/lib-opal/js_wrap/three/shaders/VignetteShader.js +46 -0
  477. data/lib-opal/js_wrap/three/shaders/VolumeShader.js +55 -0
  478. data/lib-opal/js_wrap/three/shaders/WaterRefractionShader.js +46 -0
  479. data/lib-opal/js_wrap/three/textures/FlakesTexture.js +61 -0
  480. data/lib-opal/js_wrap/three/utils/BufferGeometryUtils.js +683 -0
  481. data/lib-opal/js_wrap/three/utils/CameraUtils.js +97 -0
  482. data/lib-opal/js_wrap/three/utils/GPUStatsPanel.js +154 -0
  483. data/lib-opal/js_wrap/three/utils/GeometryCompressionUtils.js +468 -0
  484. data/lib-opal/js_wrap/three/utils/GeometryUtils.js +192 -0
  485. data/lib-opal/js_wrap/three/utils/PackedPhongMaterial.js +77 -0
  486. data/lib-opal/js_wrap/three/utils/RoughnessMipmapper.js +169 -0
  487. data/lib-opal/js_wrap/three/utils/SceneUtils.js +62 -0
  488. data/lib-opal/js_wrap/three/utils/ShadowMapViewer.js +182 -0
  489. data/lib-opal/js_wrap/three/utils/SkeletonUtils.js +400 -0
  490. data/lib-opal/js_wrap/three/utils/UVsDebug.js +132 -0
  491. data/lib-opal/js_wrap/three/utils/WorkerPool.js +130 -0
  492. data/lib-opal/js_wrap/three/webxr/ARButton.js +203 -0
  493. data/lib-opal/js_wrap/three/webxr/OculusHandModel.js +131 -0
  494. data/lib-opal/js_wrap/three/webxr/OculusHandPointerModel.js +328 -0
  495. data/lib-opal/js_wrap/three/webxr/Text2D.js +54 -0
  496. data/lib-opal/js_wrap/three/webxr/VRButton.js +181 -0
  497. data/lib-opal/js_wrap/three/webxr/XRControllerModelFactory.js +266 -0
  498. data/lib-opal/js_wrap/three/webxr/XREstimatedLight.js +221 -0
  499. data/lib-opal/js_wrap/three/webxr/XRHandMeshModel.js +93 -0
  500. data/lib-opal/js_wrap/three/webxr/XRHandModelFactory.js +127 -0
  501. data/lib-opal/js_wrap/three/webxr/XRHandPrimitiveModel.js +85 -0
  502. data/opal-js_wrap-three.gemspec +4 -4
  503. metadata +502 -5
@@ -0,0 +1,3334 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "three"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("three"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.three);
11
+ global.GLTFLoader = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.GLTFLoader = void 0;
20
+
21
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
22
+
23
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+
25
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
26
+
27
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
28
+
29
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
30
+
31
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
+
33
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
34
+
35
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
36
+
37
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
38
+
39
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
+
41
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
42
+
43
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
44
+
45
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
46
+
47
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
48
+
49
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
50
+
51
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
52
+
53
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
54
+
55
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
56
+
57
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
58
+
59
+ var GLTFLoader = /*#__PURE__*/function (_Loader) {
60
+ _inherits(GLTFLoader, _Loader);
61
+
62
+ var _super = _createSuper(GLTFLoader);
63
+
64
+ function GLTFLoader(manager) {
65
+ var _this;
66
+
67
+ _classCallCheck(this, GLTFLoader);
68
+
69
+ _this = _super.call(this, manager);
70
+ _this.dracoLoader = null;
71
+ _this.ktx2Loader = null;
72
+ _this.meshoptDecoder = null;
73
+ _this.pluginCallbacks = [];
74
+
75
+ _this.register(function (parser) {
76
+ return new GLTFMaterialsClearcoatExtension(parser);
77
+ });
78
+
79
+ _this.register(function (parser) {
80
+ return new GLTFTextureBasisUExtension(parser);
81
+ });
82
+
83
+ _this.register(function (parser) {
84
+ return new GLTFTextureWebPExtension(parser);
85
+ });
86
+
87
+ _this.register(function (parser) {
88
+ return new GLTFMaterialsSheenExtension(parser);
89
+ });
90
+
91
+ _this.register(function (parser) {
92
+ return new GLTFMaterialsTransmissionExtension(parser);
93
+ });
94
+
95
+ _this.register(function (parser) {
96
+ return new GLTFMaterialsVolumeExtension(parser);
97
+ });
98
+
99
+ _this.register(function (parser) {
100
+ return new GLTFMaterialsIorExtension(parser);
101
+ });
102
+
103
+ _this.register(function (parser) {
104
+ return new GLTFMaterialsSpecularExtension(parser);
105
+ });
106
+
107
+ _this.register(function (parser) {
108
+ return new GLTFLightsExtension(parser);
109
+ });
110
+
111
+ _this.register(function (parser) {
112
+ return new GLTFMeshoptCompression(parser);
113
+ });
114
+
115
+ return _this;
116
+ }
117
+
118
+ _createClass(GLTFLoader, [{
119
+ key: "load",
120
+ value: function load(url, onLoad, onProgress, onError) {
121
+ var scope = this;
122
+ var resourcePath;
123
+
124
+ if (this.resourcePath !== '') {
125
+ resourcePath = this.resourcePath;
126
+ } else if (this.path !== '') {
127
+ resourcePath = this.path;
128
+ } else {
129
+ resourcePath = _three.LoaderUtils.extractUrlBase(url);
130
+ } // Tells the LoadingManager to track an extra item, which resolves after
131
+ // the model is fully loaded. This means the count of items loaded will
132
+ // be incorrect, but ensures manager.onLoad() does not fire early.
133
+
134
+
135
+ this.manager.itemStart(url);
136
+
137
+ var _onError = function _onError(e) {
138
+ if (onError) {
139
+ onError(e);
140
+ } else {
141
+ console.error(e);
142
+ }
143
+
144
+ scope.manager.itemError(url);
145
+ scope.manager.itemEnd(url);
146
+ };
147
+
148
+ var loader = new _three.FileLoader(this.manager);
149
+ loader.setPath(this.path);
150
+ loader.setResponseType('arraybuffer');
151
+ loader.setRequestHeader(this.requestHeader);
152
+ loader.setWithCredentials(this.withCredentials);
153
+ loader.load(url, function (data) {
154
+ try {
155
+ scope.parse(data, resourcePath, function (gltf) {
156
+ onLoad(gltf);
157
+ scope.manager.itemEnd(url);
158
+ }, _onError);
159
+ } catch (e) {
160
+ _onError(e);
161
+ }
162
+ }, onProgress, _onError);
163
+ }
164
+ }, {
165
+ key: "setDRACOLoader",
166
+ value: function setDRACOLoader(dracoLoader) {
167
+ this.dracoLoader = dracoLoader;
168
+ return this;
169
+ }
170
+ }, {
171
+ key: "setDDSLoader",
172
+ value: function setDDSLoader() {
173
+ throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
174
+ }
175
+ }, {
176
+ key: "setKTX2Loader",
177
+ value: function setKTX2Loader(ktx2Loader) {
178
+ this.ktx2Loader = ktx2Loader;
179
+ return this;
180
+ }
181
+ }, {
182
+ key: "setMeshoptDecoder",
183
+ value: function setMeshoptDecoder(meshoptDecoder) {
184
+ this.meshoptDecoder = meshoptDecoder;
185
+ return this;
186
+ }
187
+ }, {
188
+ key: "register",
189
+ value: function register(callback) {
190
+ if (this.pluginCallbacks.indexOf(callback) === -1) {
191
+ this.pluginCallbacks.push(callback);
192
+ }
193
+
194
+ return this;
195
+ }
196
+ }, {
197
+ key: "unregister",
198
+ value: function unregister(callback) {
199
+ if (this.pluginCallbacks.indexOf(callback) !== -1) {
200
+ this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
201
+ }
202
+
203
+ return this;
204
+ }
205
+ }, {
206
+ key: "parse",
207
+ value: function parse(data, path, onLoad, onError) {
208
+ var content;
209
+ var extensions = {};
210
+ var plugins = {};
211
+
212
+ if (typeof data === 'string') {
213
+ content = data;
214
+ } else {
215
+ var magic = _three.LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
216
+
217
+ if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
218
+ try {
219
+ extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
220
+ } catch (error) {
221
+ if (onError) onError(error);
222
+ return;
223
+ }
224
+
225
+ content = extensions[EXTENSIONS.KHR_BINARY_GLTF].content;
226
+ } else {
227
+ content = _three.LoaderUtils.decodeText(new Uint8Array(data));
228
+ }
229
+ }
230
+
231
+ var json = JSON.parse(content);
232
+
233
+ if (json.asset === undefined || json.asset.version[0] < 2) {
234
+ if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.'));
235
+ return;
236
+ }
237
+
238
+ var parser = new GLTFParser(json, {
239
+ path: path || this.resourcePath || '',
240
+ crossOrigin: this.crossOrigin,
241
+ requestHeader: this.requestHeader,
242
+ manager: this.manager,
243
+ ktx2Loader: this.ktx2Loader,
244
+ meshoptDecoder: this.meshoptDecoder
245
+ });
246
+ parser.fileLoader.setRequestHeader(this.requestHeader);
247
+
248
+ for (var i = 0; i < this.pluginCallbacks.length; i++) {
249
+ var plugin = this.pluginCallbacks[i](parser);
250
+ plugins[plugin.name] = plugin; // Workaround to avoid determining as unknown extension
251
+ // in addUnknownExtensionsToUserData().
252
+ // Remove this workaround if we move all the existing
253
+ // extension handlers to plugin system
254
+
255
+ extensions[plugin.name] = true;
256
+ }
257
+
258
+ if (json.extensionsUsed) {
259
+ for (var _i = 0; _i < json.extensionsUsed.length; ++_i) {
260
+ var extensionName = json.extensionsUsed[_i];
261
+ var extensionsRequired = json.extensionsRequired || [];
262
+
263
+ switch (extensionName) {
264
+ case EXTENSIONS.KHR_MATERIALS_UNLIT:
265
+ extensions[extensionName] = new GLTFMaterialsUnlitExtension();
266
+ break;
267
+
268
+ case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
269
+ extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
270
+ break;
271
+
272
+ case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
273
+ extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
274
+ break;
275
+
276
+ case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
277
+ extensions[extensionName] = new GLTFTextureTransformExtension();
278
+ break;
279
+
280
+ case EXTENSIONS.KHR_MESH_QUANTIZATION:
281
+ extensions[extensionName] = new GLTFMeshQuantizationExtension();
282
+ break;
283
+
284
+ default:
285
+ if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === undefined) {
286
+ console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
287
+ }
288
+
289
+ }
290
+ }
291
+ }
292
+
293
+ parser.setExtensions(extensions);
294
+ parser.setPlugins(plugins);
295
+ parser.parse(onLoad, onError);
296
+ }
297
+ }, {
298
+ key: "parseAsync",
299
+ value: function parseAsync(data, path) {
300
+ var scope = this;
301
+ return new Promise(function (resolve, reject) {
302
+ scope.parse(data, path, resolve, reject);
303
+ });
304
+ }
305
+ }]);
306
+
307
+ return GLTFLoader;
308
+ }(_three.Loader);
309
+ /* GLTFREGISTRY */
310
+
311
+
312
+ _exports.GLTFLoader = GLTFLoader;
313
+
314
+ function GLTFRegistry() {
315
+ var objects = {};
316
+ return {
317
+ get: function get(key) {
318
+ return objects[key];
319
+ },
320
+ add: function add(key, object) {
321
+ objects[key] = object;
322
+ },
323
+ remove: function remove(key) {
324
+ delete objects[key];
325
+ },
326
+ removeAll: function removeAll() {
327
+ objects = {};
328
+ }
329
+ };
330
+ }
331
+ /*********************************/
332
+
333
+ /********** EXTENSIONS ***********/
334
+
335
+ /*********************************/
336
+
337
+
338
+ var EXTENSIONS = {
339
+ KHR_BINARY_GLTF: 'KHR_binary_glTF',
340
+ KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
341
+ KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
342
+ KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
343
+ KHR_MATERIALS_IOR: 'KHR_materials_ior',
344
+ KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
345
+ KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
346
+ KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
347
+ KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
348
+ KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
349
+ KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
350
+ KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
351
+ KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
352
+ KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
353
+ EXT_TEXTURE_WEBP: 'EXT_texture_webp',
354
+ EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
355
+ };
356
+ /**
357
+ * Punctual Lights Extension
358
+ *
359
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
360
+ */
361
+
362
+ var GLTFLightsExtension = /*#__PURE__*/function () {
363
+ function GLTFLightsExtension(parser) {
364
+ _classCallCheck(this, GLTFLightsExtension);
365
+
366
+ this.parser = parser;
367
+ this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL; // Object3D instance caches
368
+
369
+ this.cache = {
370
+ refs: {},
371
+ uses: {}
372
+ };
373
+ }
374
+
375
+ _createClass(GLTFLightsExtension, [{
376
+ key: "_markDefs",
377
+ value: function _markDefs() {
378
+ var parser = this.parser;
379
+ var nodeDefs = this.parser.json.nodes || [];
380
+
381
+ for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
382
+ var nodeDef = nodeDefs[nodeIndex];
383
+
384
+ if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== undefined) {
385
+ parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
386
+ }
387
+ }
388
+ }
389
+ }, {
390
+ key: "_loadLight",
391
+ value: function _loadLight(lightIndex) {
392
+ var parser = this.parser;
393
+ var cacheKey = 'light:' + lightIndex;
394
+ var dependency = parser.cache.get(cacheKey);
395
+ if (dependency) return dependency;
396
+ var json = parser.json;
397
+ var extensions = json.extensions && json.extensions[this.name] || {};
398
+ var lightDefs = extensions.lights || [];
399
+ var lightDef = lightDefs[lightIndex];
400
+ var lightNode;
401
+ var color = new _three.Color(0xffffff);
402
+ if (lightDef.color !== undefined) color.fromArray(lightDef.color);
403
+ var range = lightDef.range !== undefined ? lightDef.range : 0;
404
+
405
+ switch (lightDef.type) {
406
+ case 'directional':
407
+ lightNode = new _three.DirectionalLight(color);
408
+ lightNode.target.position.set(0, 0, -1);
409
+ lightNode.add(lightNode.target);
410
+ break;
411
+
412
+ case 'point':
413
+ lightNode = new _three.PointLight(color);
414
+ lightNode.distance = range;
415
+ break;
416
+
417
+ case 'spot':
418
+ lightNode = new _three.SpotLight(color);
419
+ lightNode.distance = range; // Handle spotlight properties.
420
+
421
+ lightDef.spot = lightDef.spot || {};
422
+ lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
423
+ lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
424
+ lightNode.angle = lightDef.spot.outerConeAngle;
425
+ lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
426
+ lightNode.target.position.set(0, 0, -1);
427
+ lightNode.add(lightNode.target);
428
+ break;
429
+
430
+ default:
431
+ throw new Error('THREE.GLTFLoader: Unexpected light type: ' + lightDef.type);
432
+ } // Some lights (e.g. spot) default to a position other than the origin. Reset the position
433
+ // here, because node-level parsing will only override position if explicitly specified.
434
+
435
+
436
+ lightNode.position.set(0, 0, 0);
437
+ lightNode.decay = 2;
438
+ if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
439
+ lightNode.name = parser.createUniqueName(lightDef.name || 'light_' + lightIndex);
440
+ dependency = Promise.resolve(lightNode);
441
+ parser.cache.add(cacheKey, dependency);
442
+ return dependency;
443
+ }
444
+ }, {
445
+ key: "createNodeAttachment",
446
+ value: function createNodeAttachment(nodeIndex) {
447
+ var self = this;
448
+ var parser = this.parser;
449
+ var json = parser.json;
450
+ var nodeDef = json.nodes[nodeIndex];
451
+ var lightDef = nodeDef.extensions && nodeDef.extensions[this.name] || {};
452
+ var lightIndex = lightDef.light;
453
+ if (lightIndex === undefined) return null;
454
+ return this._loadLight(lightIndex).then(function (light) {
455
+ return parser._getNodeRef(self.cache, lightIndex, light);
456
+ });
457
+ }
458
+ }]);
459
+
460
+ return GLTFLightsExtension;
461
+ }();
462
+ /**
463
+ * Unlit Materials Extension
464
+ *
465
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
466
+ */
467
+
468
+
469
+ var GLTFMaterialsUnlitExtension = /*#__PURE__*/function () {
470
+ function GLTFMaterialsUnlitExtension() {
471
+ _classCallCheck(this, GLTFMaterialsUnlitExtension);
472
+
473
+ this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
474
+ }
475
+
476
+ _createClass(GLTFMaterialsUnlitExtension, [{
477
+ key: "getMaterialType",
478
+ value: function getMaterialType() {
479
+ return _three.MeshBasicMaterial;
480
+ }
481
+ }, {
482
+ key: "extendParams",
483
+ value: function extendParams(materialParams, materialDef, parser) {
484
+ var pending = [];
485
+ materialParams.color = new _three.Color(1.0, 1.0, 1.0);
486
+ materialParams.opacity = 1.0;
487
+ var metallicRoughness = materialDef.pbrMetallicRoughness;
488
+
489
+ if (metallicRoughness) {
490
+ if (Array.isArray(metallicRoughness.baseColorFactor)) {
491
+ var array = metallicRoughness.baseColorFactor;
492
+ materialParams.color.fromArray(array);
493
+ materialParams.opacity = array[3];
494
+ }
495
+
496
+ if (metallicRoughness.baseColorTexture !== undefined) {
497
+ pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
498
+ }
499
+ }
500
+
501
+ return Promise.all(pending);
502
+ }
503
+ }]);
504
+
505
+ return GLTFMaterialsUnlitExtension;
506
+ }();
507
+ /**
508
+ * Clearcoat Materials Extension
509
+ *
510
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
511
+ */
512
+
513
+
514
+ var GLTFMaterialsClearcoatExtension = /*#__PURE__*/function () {
515
+ function GLTFMaterialsClearcoatExtension(parser) {
516
+ _classCallCheck(this, GLTFMaterialsClearcoatExtension);
517
+
518
+ this.parser = parser;
519
+ this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
520
+ }
521
+
522
+ _createClass(GLTFMaterialsClearcoatExtension, [{
523
+ key: "getMaterialType",
524
+ value: function getMaterialType(materialIndex) {
525
+ var parser = this.parser;
526
+ var materialDef = parser.json.materials[materialIndex];
527
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
528
+ return _three.MeshPhysicalMaterial;
529
+ }
530
+ }, {
531
+ key: "extendMaterialParams",
532
+ value: function extendMaterialParams(materialIndex, materialParams) {
533
+ var parser = this.parser;
534
+ var materialDef = parser.json.materials[materialIndex];
535
+
536
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
537
+ return Promise.resolve();
538
+ }
539
+
540
+ var pending = [];
541
+ var extension = materialDef.extensions[this.name];
542
+
543
+ if (extension.clearcoatFactor !== undefined) {
544
+ materialParams.clearcoat = extension.clearcoatFactor;
545
+ }
546
+
547
+ if (extension.clearcoatTexture !== undefined) {
548
+ pending.push(parser.assignTexture(materialParams, 'clearcoatMap', extension.clearcoatTexture));
549
+ }
550
+
551
+ if (extension.clearcoatRoughnessFactor !== undefined) {
552
+ materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
553
+ }
554
+
555
+ if (extension.clearcoatRoughnessTexture !== undefined) {
556
+ pending.push(parser.assignTexture(materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture));
557
+ }
558
+
559
+ if (extension.clearcoatNormalTexture !== undefined) {
560
+ pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
561
+
562
+ if (extension.clearcoatNormalTexture.scale !== undefined) {
563
+ var scale = extension.clearcoatNormalTexture.scale;
564
+ materialParams.clearcoatNormalScale = new _three.Vector2(scale, scale);
565
+ }
566
+ }
567
+
568
+ return Promise.all(pending);
569
+ }
570
+ }]);
571
+
572
+ return GLTFMaterialsClearcoatExtension;
573
+ }();
574
+ /**
575
+ * Sheen Materials Extension
576
+ *
577
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
578
+ */
579
+
580
+
581
+ var GLTFMaterialsSheenExtension = /*#__PURE__*/function () {
582
+ function GLTFMaterialsSheenExtension(parser) {
583
+ _classCallCheck(this, GLTFMaterialsSheenExtension);
584
+
585
+ this.parser = parser;
586
+ this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
587
+ }
588
+
589
+ _createClass(GLTFMaterialsSheenExtension, [{
590
+ key: "getMaterialType",
591
+ value: function getMaterialType(materialIndex) {
592
+ var parser = this.parser;
593
+ var materialDef = parser.json.materials[materialIndex];
594
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
595
+ return _three.MeshPhysicalMaterial;
596
+ }
597
+ }, {
598
+ key: "extendMaterialParams",
599
+ value: function extendMaterialParams(materialIndex, materialParams) {
600
+ var parser = this.parser;
601
+ var materialDef = parser.json.materials[materialIndex];
602
+
603
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
604
+ return Promise.resolve();
605
+ }
606
+
607
+ var pending = [];
608
+ materialParams.sheenColor = new _three.Color(0, 0, 0);
609
+ materialParams.sheenRoughness = 0;
610
+ materialParams.sheen = 1;
611
+ var extension = materialDef.extensions[this.name];
612
+
613
+ if (extension.sheenColorFactor !== undefined) {
614
+ materialParams.sheenColor.fromArray(extension.sheenColorFactor);
615
+ }
616
+
617
+ if (extension.sheenRoughnessFactor !== undefined) {
618
+ materialParams.sheenRoughness = extension.sheenRoughnessFactor;
619
+ }
620
+
621
+ if (extension.sheenColorTexture !== undefined) {
622
+ pending.push(parser.assignTexture(materialParams, 'sheenColorMap', extension.sheenColorTexture));
623
+ }
624
+
625
+ if (extension.sheenRoughnessTexture !== undefined) {
626
+ pending.push(parser.assignTexture(materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture));
627
+ }
628
+
629
+ return Promise.all(pending);
630
+ }
631
+ }]);
632
+
633
+ return GLTFMaterialsSheenExtension;
634
+ }();
635
+ /**
636
+ * Transmission Materials Extension
637
+ *
638
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
639
+ * Draft: https://github.com/KhronosGroup/glTF/pull/1698
640
+ */
641
+
642
+
643
+ var GLTFMaterialsTransmissionExtension = /*#__PURE__*/function () {
644
+ function GLTFMaterialsTransmissionExtension(parser) {
645
+ _classCallCheck(this, GLTFMaterialsTransmissionExtension);
646
+
647
+ this.parser = parser;
648
+ this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
649
+ }
650
+
651
+ _createClass(GLTFMaterialsTransmissionExtension, [{
652
+ key: "getMaterialType",
653
+ value: function getMaterialType(materialIndex) {
654
+ var parser = this.parser;
655
+ var materialDef = parser.json.materials[materialIndex];
656
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
657
+ return _three.MeshPhysicalMaterial;
658
+ }
659
+ }, {
660
+ key: "extendMaterialParams",
661
+ value: function extendMaterialParams(materialIndex, materialParams) {
662
+ var parser = this.parser;
663
+ var materialDef = parser.json.materials[materialIndex];
664
+
665
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
666
+ return Promise.resolve();
667
+ }
668
+
669
+ var pending = [];
670
+ var extension = materialDef.extensions[this.name];
671
+
672
+ if (extension.transmissionFactor !== undefined) {
673
+ materialParams.transmission = extension.transmissionFactor;
674
+ }
675
+
676
+ if (extension.transmissionTexture !== undefined) {
677
+ pending.push(parser.assignTexture(materialParams, 'transmissionMap', extension.transmissionTexture));
678
+ }
679
+
680
+ return Promise.all(pending);
681
+ }
682
+ }]);
683
+
684
+ return GLTFMaterialsTransmissionExtension;
685
+ }();
686
+ /**
687
+ * Materials Volume Extension
688
+ *
689
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
690
+ */
691
+
692
+
693
+ var GLTFMaterialsVolumeExtension = /*#__PURE__*/function () {
694
+ function GLTFMaterialsVolumeExtension(parser) {
695
+ _classCallCheck(this, GLTFMaterialsVolumeExtension);
696
+
697
+ this.parser = parser;
698
+ this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
699
+ }
700
+
701
+ _createClass(GLTFMaterialsVolumeExtension, [{
702
+ key: "getMaterialType",
703
+ value: function getMaterialType(materialIndex) {
704
+ var parser = this.parser;
705
+ var materialDef = parser.json.materials[materialIndex];
706
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
707
+ return _three.MeshPhysicalMaterial;
708
+ }
709
+ }, {
710
+ key: "extendMaterialParams",
711
+ value: function extendMaterialParams(materialIndex, materialParams) {
712
+ var parser = this.parser;
713
+ var materialDef = parser.json.materials[materialIndex];
714
+
715
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
716
+ return Promise.resolve();
717
+ }
718
+
719
+ var pending = [];
720
+ var extension = materialDef.extensions[this.name];
721
+ materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
722
+
723
+ if (extension.thicknessTexture !== undefined) {
724
+ pending.push(parser.assignTexture(materialParams, 'thicknessMap', extension.thicknessTexture));
725
+ }
726
+
727
+ materialParams.attenuationDistance = extension.attenuationDistance || 0;
728
+ var colorArray = extension.attenuationColor || [1, 1, 1];
729
+ materialParams.attenuationColor = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
730
+ return Promise.all(pending);
731
+ }
732
+ }]);
733
+
734
+ return GLTFMaterialsVolumeExtension;
735
+ }();
736
+ /**
737
+ * Materials ior Extension
738
+ *
739
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
740
+ */
741
+
742
+
743
+ var GLTFMaterialsIorExtension = /*#__PURE__*/function () {
744
+ function GLTFMaterialsIorExtension(parser) {
745
+ _classCallCheck(this, GLTFMaterialsIorExtension);
746
+
747
+ this.parser = parser;
748
+ this.name = EXTENSIONS.KHR_MATERIALS_IOR;
749
+ }
750
+
751
+ _createClass(GLTFMaterialsIorExtension, [{
752
+ key: "getMaterialType",
753
+ value: function getMaterialType(materialIndex) {
754
+ var parser = this.parser;
755
+ var materialDef = parser.json.materials[materialIndex];
756
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
757
+ return _three.MeshPhysicalMaterial;
758
+ }
759
+ }, {
760
+ key: "extendMaterialParams",
761
+ value: function extendMaterialParams(materialIndex, materialParams) {
762
+ var parser = this.parser;
763
+ var materialDef = parser.json.materials[materialIndex];
764
+
765
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
766
+ return Promise.resolve();
767
+ }
768
+
769
+ var extension = materialDef.extensions[this.name];
770
+ materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
771
+ return Promise.resolve();
772
+ }
773
+ }]);
774
+
775
+ return GLTFMaterialsIorExtension;
776
+ }();
777
+ /**
778
+ * Materials specular Extension
779
+ *
780
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
781
+ */
782
+
783
+
784
+ var GLTFMaterialsSpecularExtension = /*#__PURE__*/function () {
785
+ function GLTFMaterialsSpecularExtension(parser) {
786
+ _classCallCheck(this, GLTFMaterialsSpecularExtension);
787
+
788
+ this.parser = parser;
789
+ this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
790
+ }
791
+
792
+ _createClass(GLTFMaterialsSpecularExtension, [{
793
+ key: "getMaterialType",
794
+ value: function getMaterialType(materialIndex) {
795
+ var parser = this.parser;
796
+ var materialDef = parser.json.materials[materialIndex];
797
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
798
+ return _three.MeshPhysicalMaterial;
799
+ }
800
+ }, {
801
+ key: "extendMaterialParams",
802
+ value: function extendMaterialParams(materialIndex, materialParams) {
803
+ var parser = this.parser;
804
+ var materialDef = parser.json.materials[materialIndex];
805
+
806
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
807
+ return Promise.resolve();
808
+ }
809
+
810
+ var pending = [];
811
+ var extension = materialDef.extensions[this.name];
812
+ materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
813
+
814
+ if (extension.specularTexture !== undefined) {
815
+ pending.push(parser.assignTexture(materialParams, 'specularIntensityMap', extension.specularTexture));
816
+ }
817
+
818
+ var colorArray = extension.specularColorFactor || [1, 1, 1];
819
+ materialParams.specularColor = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
820
+
821
+ if (extension.specularColorTexture !== undefined) {
822
+ pending.push(parser.assignTexture(materialParams, 'specularColorMap', extension.specularColorTexture).then(function (texture) {
823
+ texture.encoding = _three.sRGBEncoding;
824
+ }));
825
+ }
826
+
827
+ return Promise.all(pending);
828
+ }
829
+ }]);
830
+
831
+ return GLTFMaterialsSpecularExtension;
832
+ }();
833
+ /**
834
+ * BasisU Texture Extension
835
+ *
836
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
837
+ */
838
+
839
+
840
+ var GLTFTextureBasisUExtension = /*#__PURE__*/function () {
841
+ function GLTFTextureBasisUExtension(parser) {
842
+ _classCallCheck(this, GLTFTextureBasisUExtension);
843
+
844
+ this.parser = parser;
845
+ this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
846
+ }
847
+
848
+ _createClass(GLTFTextureBasisUExtension, [{
849
+ key: "loadTexture",
850
+ value: function loadTexture(textureIndex) {
851
+ var parser = this.parser;
852
+ var json = parser.json;
853
+ var textureDef = json.textures[textureIndex];
854
+
855
+ if (!textureDef.extensions || !textureDef.extensions[this.name]) {
856
+ return null;
857
+ }
858
+
859
+ var extension = textureDef.extensions[this.name];
860
+ var source = json.images[extension.source];
861
+ var loader = parser.options.ktx2Loader;
862
+
863
+ if (!loader) {
864
+ if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
865
+ throw new Error('THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures');
866
+ } else {
867
+ // Assumes that the extension is optional and that a fallback texture is present
868
+ return null;
869
+ }
870
+ }
871
+
872
+ return parser.loadTextureImage(textureIndex, source, loader);
873
+ }
874
+ }]);
875
+
876
+ return GLTFTextureBasisUExtension;
877
+ }();
878
+ /**
879
+ * WebP Texture Extension
880
+ *
881
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
882
+ */
883
+
884
+
885
+ var GLTFTextureWebPExtension = /*#__PURE__*/function () {
886
+ function GLTFTextureWebPExtension(parser) {
887
+ _classCallCheck(this, GLTFTextureWebPExtension);
888
+
889
+ this.parser = parser;
890
+ this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
891
+ this.isSupported = null;
892
+ }
893
+
894
+ _createClass(GLTFTextureWebPExtension, [{
895
+ key: "loadTexture",
896
+ value: function loadTexture(textureIndex) {
897
+ var name = this.name;
898
+ var parser = this.parser;
899
+ var json = parser.json;
900
+ var textureDef = json.textures[textureIndex];
901
+
902
+ if (!textureDef.extensions || !textureDef.extensions[name]) {
903
+ return null;
904
+ }
905
+
906
+ var extension = textureDef.extensions[name];
907
+ var source = json.images[extension.source];
908
+ var loader = parser.textureLoader;
909
+
910
+ if (source.uri) {
911
+ var handler = parser.options.manager.getHandler(source.uri);
912
+ if (handler !== null) loader = handler;
913
+ }
914
+
915
+ return this.detectSupport().then(function (isSupported) {
916
+ if (isSupported) return parser.loadTextureImage(textureIndex, source, loader);
917
+
918
+ if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
919
+ throw new Error('THREE.GLTFLoader: WebP required by asset but unsupported.');
920
+ } // Fall back to PNG or JPEG.
921
+
922
+
923
+ return parser.loadTexture(textureIndex);
924
+ });
925
+ }
926
+ }, {
927
+ key: "detectSupport",
928
+ value: function detectSupport() {
929
+ if (!this.isSupported) {
930
+ this.isSupported = new Promise(function (resolve) {
931
+ var image = new Image(); // Lossy test image. Support for lossy images doesn't guarantee support for all
932
+ // WebP images, unfortunately.
933
+
934
+ image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
935
+
936
+ image.onload = image.onerror = function () {
937
+ resolve(image.height === 1);
938
+ };
939
+ });
940
+ }
941
+
942
+ return this.isSupported;
943
+ }
944
+ }]);
945
+
946
+ return GLTFTextureWebPExtension;
947
+ }();
948
+ /**
949
+ * meshopt BufferView Compression Extension
950
+ *
951
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
952
+ */
953
+
954
+
955
+ var GLTFMeshoptCompression = /*#__PURE__*/function () {
956
+ function GLTFMeshoptCompression(parser) {
957
+ _classCallCheck(this, GLTFMeshoptCompression);
958
+
959
+ this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
960
+ this.parser = parser;
961
+ }
962
+
963
+ _createClass(GLTFMeshoptCompression, [{
964
+ key: "loadBufferView",
965
+ value: function loadBufferView(index) {
966
+ var json = this.parser.json;
967
+ var bufferView = json.bufferViews[index];
968
+
969
+ if (bufferView.extensions && bufferView.extensions[this.name]) {
970
+ var extensionDef = bufferView.extensions[this.name];
971
+ var buffer = this.parser.getDependency('buffer', extensionDef.buffer);
972
+ var decoder = this.parser.options.meshoptDecoder;
973
+
974
+ if (!decoder || !decoder.supported) {
975
+ if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
976
+ throw new Error('THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files');
977
+ } else {
978
+ // Assumes that the extension is optional and that fallback buffer data is present
979
+ return null;
980
+ }
981
+ }
982
+
983
+ return Promise.all([buffer, decoder.ready]).then(function (res) {
984
+ var byteOffset = extensionDef.byteOffset || 0;
985
+ var byteLength = extensionDef.byteLength || 0;
986
+ var count = extensionDef.count;
987
+ var stride = extensionDef.byteStride;
988
+ var result = new ArrayBuffer(count * stride);
989
+ var source = new Uint8Array(res[0], byteOffset, byteLength);
990
+ decoder.decodeGltfBuffer(new Uint8Array(result), count, stride, source, extensionDef.mode, extensionDef.filter);
991
+ return result;
992
+ });
993
+ } else {
994
+ return null;
995
+ }
996
+ }
997
+ }]);
998
+
999
+ return GLTFMeshoptCompression;
1000
+ }();
1001
+ /* BINARY EXTENSION */
1002
+
1003
+
1004
+ var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
1005
+ var BINARY_EXTENSION_HEADER_LENGTH = 12;
1006
+ var BINARY_EXTENSION_CHUNK_TYPES = {
1007
+ JSON: 0x4E4F534A,
1008
+ BIN: 0x004E4942
1009
+ };
1010
+
1011
+ var GLTFBinaryExtension = /*#__PURE__*/_createClass(function GLTFBinaryExtension(data) {
1012
+ _classCallCheck(this, GLTFBinaryExtension);
1013
+
1014
+ this.name = EXTENSIONS.KHR_BINARY_GLTF;
1015
+ this.content = null;
1016
+ this.body = null;
1017
+ var headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
1018
+ this.header = {
1019
+ magic: _three.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
1020
+ version: headerView.getUint32(4, true),
1021
+ length: headerView.getUint32(8, true)
1022
+ };
1023
+
1024
+ if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
1025
+ throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.');
1026
+ } else if (this.header.version < 2.0) {
1027
+ throw new Error('THREE.GLTFLoader: Legacy binary file detected.');
1028
+ }
1029
+
1030
+ var chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
1031
+ var chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
1032
+ var chunkIndex = 0;
1033
+
1034
+ while (chunkIndex < chunkContentsLength) {
1035
+ var chunkLength = chunkView.getUint32(chunkIndex, true);
1036
+ chunkIndex += 4;
1037
+ var chunkType = chunkView.getUint32(chunkIndex, true);
1038
+ chunkIndex += 4;
1039
+
1040
+ if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
1041
+ var contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
1042
+ this.content = _three.LoaderUtils.decodeText(contentArray);
1043
+ } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
1044
+ var byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
1045
+ this.body = data.slice(byteOffset, byteOffset + chunkLength);
1046
+ } // Clients must ignore chunks with unknown types.
1047
+
1048
+
1049
+ chunkIndex += chunkLength;
1050
+ }
1051
+
1052
+ if (this.content === null) {
1053
+ throw new Error('THREE.GLTFLoader: JSON content not found.');
1054
+ }
1055
+ });
1056
+ /**
1057
+ * DRACO Mesh Compression Extension
1058
+ *
1059
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
1060
+ */
1061
+
1062
+
1063
+ var GLTFDracoMeshCompressionExtension = /*#__PURE__*/function () {
1064
+ function GLTFDracoMeshCompressionExtension(json, dracoLoader) {
1065
+ _classCallCheck(this, GLTFDracoMeshCompressionExtension);
1066
+
1067
+ if (!dracoLoader) {
1068
+ throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.');
1069
+ }
1070
+
1071
+ this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
1072
+ this.json = json;
1073
+ this.dracoLoader = dracoLoader;
1074
+ this.dracoLoader.preload();
1075
+ }
1076
+
1077
+ _createClass(GLTFDracoMeshCompressionExtension, [{
1078
+ key: "decodePrimitive",
1079
+ value: function decodePrimitive(primitive, parser) {
1080
+ var json = this.json;
1081
+ var dracoLoader = this.dracoLoader;
1082
+ var bufferViewIndex = primitive.extensions[this.name].bufferView;
1083
+ var gltfAttributeMap = primitive.extensions[this.name].attributes;
1084
+ var threeAttributeMap = {};
1085
+ var attributeNormalizedMap = {};
1086
+ var attributeTypeMap = {};
1087
+
1088
+ for (var attributeName in gltfAttributeMap) {
1089
+ var threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
1090
+ threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
1091
+ }
1092
+
1093
+ for (var _attributeName in primitive.attributes) {
1094
+ var _threeAttributeName = ATTRIBUTES[_attributeName] || _attributeName.toLowerCase();
1095
+
1096
+ if (gltfAttributeMap[_attributeName] !== undefined) {
1097
+ var accessorDef = json.accessors[primitive.attributes[_attributeName]];
1098
+ var componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
1099
+ attributeTypeMap[_threeAttributeName] = componentType;
1100
+ attributeNormalizedMap[_threeAttributeName] = accessorDef.normalized === true;
1101
+ }
1102
+ }
1103
+
1104
+ return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {
1105
+ return new Promise(function (resolve) {
1106
+ dracoLoader.decodeDracoFile(bufferView, function (geometry) {
1107
+ for (var _attributeName2 in geometry.attributes) {
1108
+ var attribute = geometry.attributes[_attributeName2];
1109
+ var normalized = attributeNormalizedMap[_attributeName2];
1110
+ if (normalized !== undefined) attribute.normalized = normalized;
1111
+ }
1112
+
1113
+ resolve(geometry);
1114
+ }, threeAttributeMap, attributeTypeMap);
1115
+ });
1116
+ });
1117
+ }
1118
+ }]);
1119
+
1120
+ return GLTFDracoMeshCompressionExtension;
1121
+ }();
1122
+ /**
1123
+ * Texture Transform Extension
1124
+ *
1125
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
1126
+ */
1127
+
1128
+
1129
+ var GLTFTextureTransformExtension = /*#__PURE__*/function () {
1130
+ function GLTFTextureTransformExtension() {
1131
+ _classCallCheck(this, GLTFTextureTransformExtension);
1132
+
1133
+ this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
1134
+ }
1135
+
1136
+ _createClass(GLTFTextureTransformExtension, [{
1137
+ key: "extendTexture",
1138
+ value: function extendTexture(texture, transform) {
1139
+ if (transform.texCoord !== undefined) {
1140
+ console.warn('THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.');
1141
+ }
1142
+
1143
+ if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
1144
+ // See https://github.com/mrdoob/three.js/issues/21819.
1145
+ return texture;
1146
+ }
1147
+
1148
+ texture = texture.clone();
1149
+
1150
+ if (transform.offset !== undefined) {
1151
+ texture.offset.fromArray(transform.offset);
1152
+ }
1153
+
1154
+ if (transform.rotation !== undefined) {
1155
+ texture.rotation = transform.rotation;
1156
+ }
1157
+
1158
+ if (transform.scale !== undefined) {
1159
+ texture.repeat.fromArray(transform.scale);
1160
+ }
1161
+
1162
+ texture.needsUpdate = true;
1163
+ return texture;
1164
+ }
1165
+ }]);
1166
+
1167
+ return GLTFTextureTransformExtension;
1168
+ }();
1169
+ /**
1170
+ * Specular-Glossiness Extension
1171
+ *
1172
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness
1173
+ */
1174
+
1175
+ /**
1176
+ * A sub class of StandardMaterial with some of the functionality
1177
+ * changed via the `onBeforeCompile` callback
1178
+ * @pailhead
1179
+ */
1180
+
1181
+
1182
+ var GLTFMeshStandardSGMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
1183
+ _inherits(GLTFMeshStandardSGMaterial, _MeshStandardMaterial);
1184
+
1185
+ var _super2 = _createSuper(GLTFMeshStandardSGMaterial);
1186
+
1187
+ function GLTFMeshStandardSGMaterial(params) {
1188
+ var _this2;
1189
+
1190
+ _classCallCheck(this, GLTFMeshStandardSGMaterial);
1191
+
1192
+ _this2 = _super2.call(this);
1193
+ _this2.isGLTFSpecularGlossinessMaterial = true; //various chunks that need replacing
1194
+
1195
+ var specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
1196
+ var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
1197
+ var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' texelSpecular = sRGBToLinear( texelSpecular );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
1198
+ var glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
1199
+ var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
1200
+ var uniforms = {
1201
+ specular: {
1202
+ value: new _three.Color().setHex(0xffffff)
1203
+ },
1204
+ glossiness: {
1205
+ value: 1
1206
+ },
1207
+ specularMap: {
1208
+ value: null
1209
+ },
1210
+ glossinessMap: {
1211
+ value: null
1212
+ }
1213
+ };
1214
+ _this2._extraUniforms = uniforms;
1215
+
1216
+ _this2.onBeforeCompile = function (shader) {
1217
+ for (var uniformName in uniforms) {
1218
+ shader.uniforms[uniformName] = uniforms[uniformName];
1219
+ }
1220
+
1221
+ shader.fragmentShader = shader.fragmentShader.replace('uniform float roughness;', 'uniform vec3 specular;').replace('uniform float metalness;', 'uniform float glossiness;').replace('#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk).replace('#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk).replace('#include <roughnessmap_fragment>', specularMapFragmentChunk).replace('#include <metalnessmap_fragment>', glossinessMapFragmentChunk).replace('#include <lights_physical_fragment>', lightPhysicalFragmentChunk);
1222
+ };
1223
+
1224
+ Object.defineProperties(_assertThisInitialized(_this2), {
1225
+ specular: {
1226
+ get: function get() {
1227
+ return uniforms.specular.value;
1228
+ },
1229
+ set: function set(v) {
1230
+ uniforms.specular.value = v;
1231
+ }
1232
+ },
1233
+ specularMap: {
1234
+ get: function get() {
1235
+ return uniforms.specularMap.value;
1236
+ },
1237
+ set: function set(v) {
1238
+ uniforms.specularMap.value = v;
1239
+
1240
+ if (v) {
1241
+ this.defines.USE_SPECULARMAP = ''; // USE_UV is set by the renderer for specular maps
1242
+ } else {
1243
+ delete this.defines.USE_SPECULARMAP;
1244
+ }
1245
+ }
1246
+ },
1247
+ glossiness: {
1248
+ get: function get() {
1249
+ return uniforms.glossiness.value;
1250
+ },
1251
+ set: function set(v) {
1252
+ uniforms.glossiness.value = v;
1253
+ }
1254
+ },
1255
+ glossinessMap: {
1256
+ get: function get() {
1257
+ return uniforms.glossinessMap.value;
1258
+ },
1259
+ set: function set(v) {
1260
+ uniforms.glossinessMap.value = v;
1261
+
1262
+ if (v) {
1263
+ this.defines.USE_GLOSSINESSMAP = '';
1264
+ this.defines.USE_UV = '';
1265
+ } else {
1266
+ delete this.defines.USE_GLOSSINESSMAP;
1267
+ delete this.defines.USE_UV;
1268
+ }
1269
+ }
1270
+ }
1271
+ });
1272
+ delete _this2.metalness;
1273
+ delete _this2.roughness;
1274
+ delete _this2.metalnessMap;
1275
+ delete _this2.roughnessMap;
1276
+
1277
+ _this2.setValues(params);
1278
+
1279
+ return _this2;
1280
+ }
1281
+
1282
+ _createClass(GLTFMeshStandardSGMaterial, [{
1283
+ key: "copy",
1284
+ value: function copy(source) {
1285
+ _get(_getPrototypeOf(GLTFMeshStandardSGMaterial.prototype), "copy", this).call(this, source);
1286
+
1287
+ this.specularMap = source.specularMap;
1288
+ this.specular.copy(source.specular);
1289
+ this.glossinessMap = source.glossinessMap;
1290
+ this.glossiness = source.glossiness;
1291
+ delete this.metalness;
1292
+ delete this.roughness;
1293
+ delete this.metalnessMap;
1294
+ delete this.roughnessMap;
1295
+ return this;
1296
+ }
1297
+ }]);
1298
+
1299
+ return GLTFMeshStandardSGMaterial;
1300
+ }(_three.MeshStandardMaterial);
1301
+
1302
+ var GLTFMaterialsPbrSpecularGlossinessExtension = /*#__PURE__*/function () {
1303
+ function GLTFMaterialsPbrSpecularGlossinessExtension() {
1304
+ _classCallCheck(this, GLTFMaterialsPbrSpecularGlossinessExtension);
1305
+
1306
+ this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
1307
+ this.specularGlossinessParams = ['color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity', 'refractionRatio'];
1308
+ }
1309
+
1310
+ _createClass(GLTFMaterialsPbrSpecularGlossinessExtension, [{
1311
+ key: "getMaterialType",
1312
+ value: function getMaterialType() {
1313
+ return GLTFMeshStandardSGMaterial;
1314
+ }
1315
+ }, {
1316
+ key: "extendParams",
1317
+ value: function extendParams(materialParams, materialDef, parser) {
1318
+ var pbrSpecularGlossiness = materialDef.extensions[this.name];
1319
+ materialParams.color = new _three.Color(1.0, 1.0, 1.0);
1320
+ materialParams.opacity = 1.0;
1321
+ var pending = [];
1322
+
1323
+ if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
1324
+ var array = pbrSpecularGlossiness.diffuseFactor;
1325
+ materialParams.color.fromArray(array);
1326
+ materialParams.opacity = array[3];
1327
+ }
1328
+
1329
+ if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
1330
+ pending.push(parser.assignTexture(materialParams, 'map', pbrSpecularGlossiness.diffuseTexture));
1331
+ }
1332
+
1333
+ materialParams.emissive = new _three.Color(0.0, 0.0, 0.0);
1334
+ materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
1335
+ materialParams.specular = new _three.Color(1.0, 1.0, 1.0);
1336
+
1337
+ if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
1338
+ materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
1339
+ }
1340
+
1341
+ if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
1342
+ var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
1343
+ pending.push(parser.assignTexture(materialParams, 'glossinessMap', specGlossMapDef));
1344
+ pending.push(parser.assignTexture(materialParams, 'specularMap', specGlossMapDef));
1345
+ }
1346
+
1347
+ return Promise.all(pending);
1348
+ }
1349
+ }, {
1350
+ key: "createMaterial",
1351
+ value: function createMaterial(materialParams) {
1352
+ var material = new GLTFMeshStandardSGMaterial(materialParams);
1353
+ material.fog = true;
1354
+ material.color = materialParams.color;
1355
+ material.map = materialParams.map === undefined ? null : materialParams.map;
1356
+ material.lightMap = null;
1357
+ material.lightMapIntensity = 1.0;
1358
+ material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
1359
+ material.aoMapIntensity = 1.0;
1360
+ material.emissive = materialParams.emissive;
1361
+ material.emissiveIntensity = 1.0;
1362
+ material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
1363
+ material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
1364
+ material.bumpScale = 1;
1365
+ material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
1366
+ material.normalMapType = _three.TangentSpaceNormalMap;
1367
+ if (materialParams.normalScale) material.normalScale = materialParams.normalScale;
1368
+ material.displacementMap = null;
1369
+ material.displacementScale = 1;
1370
+ material.displacementBias = 0;
1371
+ material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
1372
+ material.specular = materialParams.specular;
1373
+ material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
1374
+ material.glossiness = materialParams.glossiness;
1375
+ material.alphaMap = null;
1376
+ material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
1377
+ material.envMapIntensity = 1.0;
1378
+ material.refractionRatio = 0.98;
1379
+ return material;
1380
+ }
1381
+ }]);
1382
+
1383
+ return GLTFMaterialsPbrSpecularGlossinessExtension;
1384
+ }();
1385
+ /**
1386
+ * Mesh Quantization Extension
1387
+ *
1388
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1389
+ */
1390
+
1391
+
1392
+ var GLTFMeshQuantizationExtension = /*#__PURE__*/_createClass(function GLTFMeshQuantizationExtension() {
1393
+ _classCallCheck(this, GLTFMeshQuantizationExtension);
1394
+
1395
+ this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
1396
+ });
1397
+ /*********************************/
1398
+
1399
+ /********** INTERPOLATION ********/
1400
+
1401
+ /*********************************/
1402
+ // Spline Interpolation
1403
+ // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1404
+
1405
+
1406
+ var GLTFCubicSplineInterpolant = /*#__PURE__*/function (_Interpolant) {
1407
+ _inherits(GLTFCubicSplineInterpolant, _Interpolant);
1408
+
1409
+ var _super3 = _createSuper(GLTFCubicSplineInterpolant);
1410
+
1411
+ function GLTFCubicSplineInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
1412
+ _classCallCheck(this, GLTFCubicSplineInterpolant);
1413
+
1414
+ return _super3.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
1415
+ }
1416
+
1417
+ _createClass(GLTFCubicSplineInterpolant, [{
1418
+ key: "copySampleValue_",
1419
+ value: function copySampleValue_(index) {
1420
+ // Copies a sample value to the result buffer. See description of glTF
1421
+ // CUBICSPLINE values layout in interpolate_() function below.
1422
+ var result = this.resultBuffer,
1423
+ values = this.sampleValues,
1424
+ valueSize = this.valueSize,
1425
+ offset = index * valueSize * 3 + valueSize;
1426
+
1427
+ for (var i = 0; i !== valueSize; i++) {
1428
+ result[i] = values[offset + i];
1429
+ }
1430
+
1431
+ return result;
1432
+ }
1433
+ }]);
1434
+
1435
+ return GLTFCubicSplineInterpolant;
1436
+ }(_three.Interpolant);
1437
+
1438
+ GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1439
+ GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1440
+
1441
+ GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
1442
+ var result = this.resultBuffer;
1443
+ var values = this.sampleValues;
1444
+ var stride = this.valueSize;
1445
+ var stride2 = stride * 2;
1446
+ var stride3 = stride * 3;
1447
+ var td = t1 - t0;
1448
+ var p = (t - t0) / td;
1449
+ var pp = p * p;
1450
+ var ppp = pp * p;
1451
+ var offset1 = i1 * stride3;
1452
+ var offset0 = offset1 - stride3;
1453
+ var s2 = -2 * ppp + 3 * pp;
1454
+ var s3 = ppp - pp;
1455
+ var s0 = 1 - s2;
1456
+ var s1 = s3 - pp + p; // Layout of keyframe output values for CUBICSPLINE animations:
1457
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1458
+
1459
+ for (var i = 0; i !== stride; i++) {
1460
+ var p0 = values[offset0 + i + stride]; // splineVertex_k
1461
+
1462
+ var m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
1463
+
1464
+ var p1 = values[offset1 + i + stride]; // splineVertex_k+1
1465
+
1466
+ var m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
1467
+
1468
+ result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1469
+ }
1470
+
1471
+ return result;
1472
+ };
1473
+
1474
+ var _q = new _three.Quaternion();
1475
+
1476
+ var GLTFCubicSplineQuaternionInterpolant = /*#__PURE__*/function (_GLTFCubicSplineInter) {
1477
+ _inherits(GLTFCubicSplineQuaternionInterpolant, _GLTFCubicSplineInter);
1478
+
1479
+ var _super4 = _createSuper(GLTFCubicSplineQuaternionInterpolant);
1480
+
1481
+ function GLTFCubicSplineQuaternionInterpolant() {
1482
+ _classCallCheck(this, GLTFCubicSplineQuaternionInterpolant);
1483
+
1484
+ return _super4.apply(this, arguments);
1485
+ }
1486
+
1487
+ _createClass(GLTFCubicSplineQuaternionInterpolant, [{
1488
+ key: "interpolate_",
1489
+ value: function interpolate_(i1, t0, t, t1) {
1490
+ var result = _get(_getPrototypeOf(GLTFCubicSplineQuaternionInterpolant.prototype), "interpolate_", this).call(this, i1, t0, t, t1);
1491
+
1492
+ _q.fromArray(result).normalize().toArray(result);
1493
+
1494
+ return result;
1495
+ }
1496
+ }]);
1497
+
1498
+ return GLTFCubicSplineQuaternionInterpolant;
1499
+ }(GLTFCubicSplineInterpolant);
1500
+ /*********************************/
1501
+
1502
+ /********** INTERNALS ************/
1503
+
1504
+ /*********************************/
1505
+
1506
+ /* CONSTANTS */
1507
+
1508
+
1509
+ var WEBGL_CONSTANTS = {
1510
+ FLOAT: 5126,
1511
+ //FLOAT_MAT2: 35674,
1512
+ FLOAT_MAT3: 35675,
1513
+ FLOAT_MAT4: 35676,
1514
+ FLOAT_VEC2: 35664,
1515
+ FLOAT_VEC3: 35665,
1516
+ FLOAT_VEC4: 35666,
1517
+ LINEAR: 9729,
1518
+ REPEAT: 10497,
1519
+ SAMPLER_2D: 35678,
1520
+ POINTS: 0,
1521
+ LINES: 1,
1522
+ LINE_LOOP: 2,
1523
+ LINE_STRIP: 3,
1524
+ TRIANGLES: 4,
1525
+ TRIANGLE_STRIP: 5,
1526
+ TRIANGLE_FAN: 6,
1527
+ UNSIGNED_BYTE: 5121,
1528
+ UNSIGNED_SHORT: 5123
1529
+ };
1530
+ var WEBGL_COMPONENT_TYPES = {
1531
+ 5120: Int8Array,
1532
+ 5121: Uint8Array,
1533
+ 5122: Int16Array,
1534
+ 5123: Uint16Array,
1535
+ 5125: Uint32Array,
1536
+ 5126: Float32Array
1537
+ };
1538
+ var WEBGL_FILTERS = {
1539
+ 9728: _three.NearestFilter,
1540
+ 9729: _three.LinearFilter,
1541
+ 9984: _three.NearestMipmapNearestFilter,
1542
+ 9985: _three.LinearMipmapNearestFilter,
1543
+ 9986: _three.NearestMipmapLinearFilter,
1544
+ 9987: _three.LinearMipmapLinearFilter
1545
+ };
1546
+ var WEBGL_WRAPPINGS = {
1547
+ 33071: _three.ClampToEdgeWrapping,
1548
+ 33648: _three.MirroredRepeatWrapping,
1549
+ 10497: _three.RepeatWrapping
1550
+ };
1551
+ var WEBGL_TYPE_SIZES = {
1552
+ 'SCALAR': 1,
1553
+ 'VEC2': 2,
1554
+ 'VEC3': 3,
1555
+ 'VEC4': 4,
1556
+ 'MAT2': 4,
1557
+ 'MAT3': 9,
1558
+ 'MAT4': 16
1559
+ };
1560
+ var ATTRIBUTES = {
1561
+ POSITION: 'position',
1562
+ NORMAL: 'normal',
1563
+ TANGENT: 'tangent',
1564
+ TEXCOORD_0: 'uv',
1565
+ TEXCOORD_1: 'uv2',
1566
+ COLOR_0: 'color',
1567
+ WEIGHTS_0: 'skinWeight',
1568
+ JOINTS_0: 'skinIndex'
1569
+ };
1570
+ var PATH_PROPERTIES = {
1571
+ scale: 'scale',
1572
+ translation: 'position',
1573
+ rotation: 'quaternion',
1574
+ weights: 'morphTargetInfluences'
1575
+ };
1576
+ var INTERPOLATION = {
1577
+ CUBICSPLINE: undefined,
1578
+ // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
1579
+ // keyframe track will be initialized with a default interpolation type, then modified.
1580
+ LINEAR: _three.InterpolateLinear,
1581
+ STEP: _three.InterpolateDiscrete
1582
+ };
1583
+ var ALPHA_MODES = {
1584
+ OPAQUE: 'OPAQUE',
1585
+ MASK: 'MASK',
1586
+ BLEND: 'BLEND'
1587
+ };
1588
+ /**
1589
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1590
+ */
1591
+
1592
+ function createDefaultMaterial(cache) {
1593
+ if (cache['DefaultMaterial'] === undefined) {
1594
+ cache['DefaultMaterial'] = new _three.MeshStandardMaterial({
1595
+ color: 0xFFFFFF,
1596
+ emissive: 0x000000,
1597
+ metalness: 1,
1598
+ roughness: 1,
1599
+ transparent: false,
1600
+ depthTest: true,
1601
+ side: _three.FrontSide
1602
+ });
1603
+ }
1604
+
1605
+ return cache['DefaultMaterial'];
1606
+ }
1607
+
1608
+ function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
1609
+ // Add unknown glTF extensions to an object's userData.
1610
+ for (var name in objectDef.extensions) {
1611
+ if (knownExtensions[name] === undefined) {
1612
+ object.userData.gltfExtensions = object.userData.gltfExtensions || {};
1613
+ object.userData.gltfExtensions[name] = objectDef.extensions[name];
1614
+ }
1615
+ }
1616
+ }
1617
+ /**
1618
+ * @param {Object3D|Material|BufferGeometry} object
1619
+ * @param {GLTF.definition} gltfDef
1620
+ */
1621
+
1622
+
1623
+ function assignExtrasToUserData(object, gltfDef) {
1624
+ if (gltfDef.extras !== undefined) {
1625
+ if (typeof gltfDef.extras === 'object') {
1626
+ Object.assign(object.userData, gltfDef.extras);
1627
+ } else {
1628
+ console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
1629
+ }
1630
+ }
1631
+ }
1632
+ /**
1633
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
1634
+ *
1635
+ * @param {BufferGeometry} geometry
1636
+ * @param {Array<GLTF.Target>} targets
1637
+ * @param {GLTFParser} parser
1638
+ * @return {Promise<BufferGeometry>}
1639
+ */
1640
+
1641
+
1642
+ function addMorphTargets(geometry, targets, parser) {
1643
+ var hasMorphPosition = false;
1644
+ var hasMorphNormal = false;
1645
+
1646
+ for (var i = 0, il = targets.length; i < il; i++) {
1647
+ var target = targets[i];
1648
+ if (target.POSITION !== undefined) hasMorphPosition = true;
1649
+ if (target.NORMAL !== undefined) hasMorphNormal = true;
1650
+ if (hasMorphPosition && hasMorphNormal) break;
1651
+ }
1652
+
1653
+ if (!hasMorphPosition && !hasMorphNormal) return Promise.resolve(geometry);
1654
+ var pendingPositionAccessors = [];
1655
+ var pendingNormalAccessors = [];
1656
+
1657
+ for (var _i2 = 0, _il = targets.length; _i2 < _il; _i2++) {
1658
+ var _target = targets[_i2];
1659
+
1660
+ if (hasMorphPosition) {
1661
+ var pendingAccessor = _target.POSITION !== undefined ? parser.getDependency('accessor', _target.POSITION) : geometry.attributes.position;
1662
+ pendingPositionAccessors.push(pendingAccessor);
1663
+ }
1664
+
1665
+ if (hasMorphNormal) {
1666
+ var _pendingAccessor = _target.NORMAL !== undefined ? parser.getDependency('accessor', _target.NORMAL) : geometry.attributes.normal;
1667
+
1668
+ pendingNormalAccessors.push(_pendingAccessor);
1669
+ }
1670
+ }
1671
+
1672
+ return Promise.all([Promise.all(pendingPositionAccessors), Promise.all(pendingNormalAccessors)]).then(function (accessors) {
1673
+ var morphPositions = accessors[0];
1674
+ var morphNormals = accessors[1];
1675
+ if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
1676
+ if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
1677
+ geometry.morphTargetsRelative = true;
1678
+ return geometry;
1679
+ });
1680
+ }
1681
+ /**
1682
+ * @param {Mesh} mesh
1683
+ * @param {GLTF.Mesh} meshDef
1684
+ */
1685
+
1686
+
1687
+ function updateMorphTargets(mesh, meshDef) {
1688
+ mesh.updateMorphTargets();
1689
+
1690
+ if (meshDef.weights !== undefined) {
1691
+ for (var i = 0, il = meshDef.weights.length; i < il; i++) {
1692
+ mesh.morphTargetInfluences[i] = meshDef.weights[i];
1693
+ }
1694
+ } // .extras has user-defined data, so check that .extras.targetNames is an array.
1695
+
1696
+
1697
+ if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
1698
+ var targetNames = meshDef.extras.targetNames;
1699
+
1700
+ if (mesh.morphTargetInfluences.length === targetNames.length) {
1701
+ mesh.morphTargetDictionary = {};
1702
+
1703
+ for (var _i3 = 0, _il2 = targetNames.length; _i3 < _il2; _i3++) {
1704
+ mesh.morphTargetDictionary[targetNames[_i3]] = _i3;
1705
+ }
1706
+ } else {
1707
+ console.warn('THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.');
1708
+ }
1709
+ }
1710
+ }
1711
+
1712
+ function createPrimitiveKey(primitiveDef) {
1713
+ var dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1714
+ var geometryKey;
1715
+
1716
+ if (dracoExtension) {
1717
+ geometryKey = 'draco:' + dracoExtension.bufferView + ':' + dracoExtension.indices + ':' + createAttributesKey(dracoExtension.attributes);
1718
+ } else {
1719
+ geometryKey = primitiveDef.indices + ':' + createAttributesKey(primitiveDef.attributes) + ':' + primitiveDef.mode;
1720
+ }
1721
+
1722
+ return geometryKey;
1723
+ }
1724
+
1725
+ function createAttributesKey(attributes) {
1726
+ var attributesKey = '';
1727
+ var keys = Object.keys(attributes).sort();
1728
+
1729
+ for (var i = 0, il = keys.length; i < il; i++) {
1730
+ attributesKey += keys[i] + ':' + attributes[keys[i]] + ';';
1731
+ }
1732
+
1733
+ return attributesKey;
1734
+ }
1735
+
1736
+ function getNormalizedComponentScale(constructor) {
1737
+ // Reference:
1738
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
1739
+ switch (constructor) {
1740
+ case Int8Array:
1741
+ return 1 / 127;
1742
+
1743
+ case Uint8Array:
1744
+ return 1 / 255;
1745
+
1746
+ case Int16Array:
1747
+ return 1 / 32767;
1748
+
1749
+ case Uint16Array:
1750
+ return 1 / 65535;
1751
+
1752
+ default:
1753
+ throw new Error('THREE.GLTFLoader: Unsupported normalized accessor component type.');
1754
+ }
1755
+ }
1756
+ /* GLTF PARSER */
1757
+
1758
+
1759
+ var GLTFParser = /*#__PURE__*/function () {
1760
+ function GLTFParser() {
1761
+ var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1762
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1763
+
1764
+ _classCallCheck(this, GLTFParser);
1765
+
1766
+ this.json = json;
1767
+ this.extensions = {};
1768
+ this.plugins = {};
1769
+ this.options = options; // loader object cache
1770
+
1771
+ this.cache = new GLTFRegistry(); // associations between Three.js objects and glTF elements
1772
+
1773
+ this.associations = new Map(); // BufferGeometry caching
1774
+
1775
+ this.primitiveCache = {}; // Object3D instance caches
1776
+
1777
+ this.meshCache = {
1778
+ refs: {},
1779
+ uses: {}
1780
+ };
1781
+ this.cameraCache = {
1782
+ refs: {},
1783
+ uses: {}
1784
+ };
1785
+ this.lightCache = {
1786
+ refs: {},
1787
+ uses: {}
1788
+ };
1789
+ this.textureCache = {}; // Track node names, to ensure no duplicates
1790
+
1791
+ this.nodeNamesUsed = {}; // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
1792
+ // expensive work of uploading a texture to the GPU off the main thread.
1793
+
1794
+ if (typeof createImageBitmap !== 'undefined' && /Firefox/.test(navigator.userAgent) === false) {
1795
+ this.textureLoader = new _three.ImageBitmapLoader(this.options.manager);
1796
+ } else {
1797
+ this.textureLoader = new _three.TextureLoader(this.options.manager);
1798
+ }
1799
+
1800
+ this.textureLoader.setCrossOrigin(this.options.crossOrigin);
1801
+ this.textureLoader.setRequestHeader(this.options.requestHeader);
1802
+ this.fileLoader = new _three.FileLoader(this.options.manager);
1803
+ this.fileLoader.setResponseType('arraybuffer');
1804
+
1805
+ if (this.options.crossOrigin === 'use-credentials') {
1806
+ this.fileLoader.setWithCredentials(true);
1807
+ }
1808
+ }
1809
+
1810
+ _createClass(GLTFParser, [{
1811
+ key: "setExtensions",
1812
+ value: function setExtensions(extensions) {
1813
+ this.extensions = extensions;
1814
+ }
1815
+ }, {
1816
+ key: "setPlugins",
1817
+ value: function setPlugins(plugins) {
1818
+ this.plugins = plugins;
1819
+ }
1820
+ }, {
1821
+ key: "parse",
1822
+ value: function parse(onLoad, onError) {
1823
+ var parser = this;
1824
+ var json = this.json;
1825
+ var extensions = this.extensions; // Clear the loader cache
1826
+
1827
+ this.cache.removeAll(); // Mark the special nodes/meshes in json for efficient parse
1828
+
1829
+ this._invokeAll(function (ext) {
1830
+ return ext._markDefs && ext._markDefs();
1831
+ });
1832
+
1833
+ Promise.all(this._invokeAll(function (ext) {
1834
+ return ext.beforeRoot && ext.beforeRoot();
1835
+ })).then(function () {
1836
+ return Promise.all([parser.getDependencies('scene'), parser.getDependencies('animation'), parser.getDependencies('camera')]);
1837
+ }).then(function (dependencies) {
1838
+ var result = {
1839
+ scene: dependencies[0][json.scene || 0],
1840
+ scenes: dependencies[0],
1841
+ animations: dependencies[1],
1842
+ cameras: dependencies[2],
1843
+ asset: json.asset,
1844
+ parser: parser,
1845
+ userData: {}
1846
+ };
1847
+ addUnknownExtensionsToUserData(extensions, result, json);
1848
+ assignExtrasToUserData(result, json);
1849
+ Promise.all(parser._invokeAll(function (ext) {
1850
+ return ext.afterRoot && ext.afterRoot(result);
1851
+ })).then(function () {
1852
+ onLoad(result);
1853
+ });
1854
+ }).catch(onError);
1855
+ }
1856
+ /**
1857
+ * Marks the special nodes/meshes in json for efficient parse.
1858
+ */
1859
+
1860
+ }, {
1861
+ key: "_markDefs",
1862
+ value: function _markDefs() {
1863
+ var nodeDefs = this.json.nodes || [];
1864
+ var skinDefs = this.json.skins || [];
1865
+ var meshDefs = this.json.meshes || []; // Nothing in the node definition indicates whether it is a Bone or an
1866
+ // Object3D. Use the skins' joint references to mark bones.
1867
+
1868
+ for (var skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
1869
+ var joints = skinDefs[skinIndex].joints;
1870
+
1871
+ for (var i = 0, il = joints.length; i < il; i++) {
1872
+ nodeDefs[joints[i]].isBone = true;
1873
+ }
1874
+ } // Iterate over all nodes, marking references to shared resources,
1875
+ // as well as skeleton joints.
1876
+
1877
+
1878
+ for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
1879
+ var nodeDef = nodeDefs[nodeIndex];
1880
+
1881
+ if (nodeDef.mesh !== undefined) {
1882
+ this._addNodeRef(this.meshCache, nodeDef.mesh); // Nothing in the mesh definition indicates whether it is
1883
+ // a SkinnedMesh or Mesh. Use the node's mesh reference
1884
+ // to mark SkinnedMesh if node has skin.
1885
+
1886
+
1887
+ if (nodeDef.skin !== undefined) {
1888
+ meshDefs[nodeDef.mesh].isSkinnedMesh = true;
1889
+ }
1890
+ }
1891
+
1892
+ if (nodeDef.camera !== undefined) {
1893
+ this._addNodeRef(this.cameraCache, nodeDef.camera);
1894
+ }
1895
+ }
1896
+ }
1897
+ /**
1898
+ * Counts references to shared node / Object3D resources. These resources
1899
+ * can be reused, or "instantiated", at multiple nodes in the scene
1900
+ * hierarchy. Mesh, Camera, and Light instances are instantiated and must
1901
+ * be marked. Non-scenegraph resources (like Materials, Geometries, and
1902
+ * Textures) can be reused directly and are not marked here.
1903
+ *
1904
+ * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
1905
+ */
1906
+
1907
+ }, {
1908
+ key: "_addNodeRef",
1909
+ value: function _addNodeRef(cache, index) {
1910
+ if (index === undefined) return;
1911
+
1912
+ if (cache.refs[index] === undefined) {
1913
+ cache.refs[index] = cache.uses[index] = 0;
1914
+ }
1915
+
1916
+ cache.refs[index]++;
1917
+ }
1918
+ /** Returns a reference to a shared resource, cloning it if necessary. */
1919
+
1920
+ }, {
1921
+ key: "_getNodeRef",
1922
+ value: function _getNodeRef(cache, index, object) {
1923
+ var _this3 = this;
1924
+
1925
+ if (cache.refs[index] <= 1) return object;
1926
+ var ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
1927
+ // original object from being lost.
1928
+
1929
+ var updateMappings = function updateMappings(original, clone) {
1930
+ var mappings = _this3.associations.get(original);
1931
+
1932
+ if (mappings != null) {
1933
+ _this3.associations.set(clone, mappings);
1934
+ }
1935
+
1936
+ var _iterator = _createForOfIteratorHelper(original.children.entries()),
1937
+ _step;
1938
+
1939
+ try {
1940
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1941
+ var _step$value = _slicedToArray(_step.value, 2),
1942
+ i = _step$value[0],
1943
+ child = _step$value[1];
1944
+
1945
+ updateMappings(child, clone.children[i]);
1946
+ }
1947
+ } catch (err) {
1948
+ _iterator.e(err);
1949
+ } finally {
1950
+ _iterator.f();
1951
+ }
1952
+ };
1953
+
1954
+ updateMappings(object, ref);
1955
+ ref.name += '_instance_' + cache.uses[index]++;
1956
+ return ref;
1957
+ }
1958
+ }, {
1959
+ key: "_invokeOne",
1960
+ value: function _invokeOne(func) {
1961
+ var extensions = Object.values(this.plugins);
1962
+ extensions.push(this);
1963
+
1964
+ for (var i = 0; i < extensions.length; i++) {
1965
+ var result = func(extensions[i]);
1966
+ if (result) return result;
1967
+ }
1968
+
1969
+ return null;
1970
+ }
1971
+ }, {
1972
+ key: "_invokeAll",
1973
+ value: function _invokeAll(func) {
1974
+ var extensions = Object.values(this.plugins);
1975
+ extensions.unshift(this);
1976
+ var pending = [];
1977
+
1978
+ for (var i = 0; i < extensions.length; i++) {
1979
+ var result = func(extensions[i]);
1980
+ if (result) pending.push(result);
1981
+ }
1982
+
1983
+ return pending;
1984
+ }
1985
+ /**
1986
+ * Requests the specified dependency asynchronously, with caching.
1987
+ * @param {string} type
1988
+ * @param {number} index
1989
+ * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
1990
+ */
1991
+
1992
+ }, {
1993
+ key: "getDependency",
1994
+ value: function getDependency(type, index) {
1995
+ var cacheKey = type + ':' + index;
1996
+ var dependency = this.cache.get(cacheKey);
1997
+
1998
+ if (!dependency) {
1999
+ switch (type) {
2000
+ case 'scene':
2001
+ dependency = this.loadScene(index);
2002
+ break;
2003
+
2004
+ case 'node':
2005
+ dependency = this.loadNode(index);
2006
+ break;
2007
+
2008
+ case 'mesh':
2009
+ dependency = this._invokeOne(function (ext) {
2010
+ return ext.loadMesh && ext.loadMesh(index);
2011
+ });
2012
+ break;
2013
+
2014
+ case 'accessor':
2015
+ dependency = this.loadAccessor(index);
2016
+ break;
2017
+
2018
+ case 'bufferView':
2019
+ dependency = this._invokeOne(function (ext) {
2020
+ return ext.loadBufferView && ext.loadBufferView(index);
2021
+ });
2022
+ break;
2023
+
2024
+ case 'buffer':
2025
+ dependency = this.loadBuffer(index);
2026
+ break;
2027
+
2028
+ case 'material':
2029
+ dependency = this._invokeOne(function (ext) {
2030
+ return ext.loadMaterial && ext.loadMaterial(index);
2031
+ });
2032
+ break;
2033
+
2034
+ case 'texture':
2035
+ dependency = this._invokeOne(function (ext) {
2036
+ return ext.loadTexture && ext.loadTexture(index);
2037
+ });
2038
+ break;
2039
+
2040
+ case 'skin':
2041
+ dependency = this.loadSkin(index);
2042
+ break;
2043
+
2044
+ case 'animation':
2045
+ dependency = this.loadAnimation(index);
2046
+ break;
2047
+
2048
+ case 'camera':
2049
+ dependency = this.loadCamera(index);
2050
+ break;
2051
+
2052
+ default:
2053
+ throw new Error('Unknown type: ' + type);
2054
+ }
2055
+
2056
+ this.cache.add(cacheKey, dependency);
2057
+ }
2058
+
2059
+ return dependency;
2060
+ }
2061
+ /**
2062
+ * Requests all dependencies of the specified type asynchronously, with caching.
2063
+ * @param {string} type
2064
+ * @return {Promise<Array<Object>>}
2065
+ */
2066
+
2067
+ }, {
2068
+ key: "getDependencies",
2069
+ value: function getDependencies(type) {
2070
+ var dependencies = this.cache.get(type);
2071
+
2072
+ if (!dependencies) {
2073
+ var parser = this;
2074
+ var defs = this.json[type + (type === 'mesh' ? 'es' : 's')] || [];
2075
+ dependencies = Promise.all(defs.map(function (def, index) {
2076
+ return parser.getDependency(type, index);
2077
+ }));
2078
+ this.cache.add(type, dependencies);
2079
+ }
2080
+
2081
+ return dependencies;
2082
+ }
2083
+ /**
2084
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2085
+ * @param {number} bufferIndex
2086
+ * @return {Promise<ArrayBuffer>}
2087
+ */
2088
+
2089
+ }, {
2090
+ key: "loadBuffer",
2091
+ value: function loadBuffer(bufferIndex) {
2092
+ var bufferDef = this.json.buffers[bufferIndex];
2093
+ var loader = this.fileLoader;
2094
+
2095
+ if (bufferDef.type && bufferDef.type !== 'arraybuffer') {
2096
+ throw new Error('THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.');
2097
+ } // If present, GLB container is required to be the first buffer.
2098
+
2099
+
2100
+ if (bufferDef.uri === undefined && bufferIndex === 0) {
2101
+ return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
2102
+ }
2103
+
2104
+ var options = this.options;
2105
+ return new Promise(function (resolve, reject) {
2106
+ loader.load(_three.LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
2107
+ reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
2108
+ });
2109
+ });
2110
+ }
2111
+ /**
2112
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2113
+ * @param {number} bufferViewIndex
2114
+ * @return {Promise<ArrayBuffer>}
2115
+ */
2116
+
2117
+ }, {
2118
+ key: "loadBufferView",
2119
+ value: function loadBufferView(bufferViewIndex) {
2120
+ var bufferViewDef = this.json.bufferViews[bufferViewIndex];
2121
+ return this.getDependency('buffer', bufferViewDef.buffer).then(function (buffer) {
2122
+ var byteLength = bufferViewDef.byteLength || 0;
2123
+ var byteOffset = bufferViewDef.byteOffset || 0;
2124
+ return buffer.slice(byteOffset, byteOffset + byteLength);
2125
+ });
2126
+ }
2127
+ /**
2128
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
2129
+ * @param {number} accessorIndex
2130
+ * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
2131
+ */
2132
+
2133
+ }, {
2134
+ key: "loadAccessor",
2135
+ value: function loadAccessor(accessorIndex) {
2136
+ var parser = this;
2137
+ var json = this.json;
2138
+ var accessorDef = this.json.accessors[accessorIndex];
2139
+
2140
+ if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
2141
+ // Ignore empty accessors, which may be used to declare runtime
2142
+ // information about attributes coming from another source (e.g. Draco
2143
+ // compression extension).
2144
+ return Promise.resolve(null);
2145
+ }
2146
+
2147
+ var pendingBufferViews = [];
2148
+
2149
+ if (accessorDef.bufferView !== undefined) {
2150
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.bufferView));
2151
+ } else {
2152
+ pendingBufferViews.push(null);
2153
+ }
2154
+
2155
+ if (accessorDef.sparse !== undefined) {
2156
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.indices.bufferView));
2157
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.values.bufferView));
2158
+ }
2159
+
2160
+ return Promise.all(pendingBufferViews).then(function (bufferViews) {
2161
+ var bufferView = bufferViews[0];
2162
+ var itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
2163
+ var TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
2164
+
2165
+ var elementBytes = TypedArray.BYTES_PER_ELEMENT;
2166
+ var itemBytes = elementBytes * itemSize;
2167
+ var byteOffset = accessorDef.byteOffset || 0;
2168
+ var byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[accessorDef.bufferView].byteStride : undefined;
2169
+ var normalized = accessorDef.normalized === true;
2170
+ var array, bufferAttribute; // The buffer is not interleaved if the stride is the item size in bytes.
2171
+
2172
+ if (byteStride && byteStride !== itemBytes) {
2173
+ // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
2174
+ // This makes sure that IBA.count reflects accessor.count properly
2175
+ var ibSlice = Math.floor(byteOffset / byteStride);
2176
+ var ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
2177
+ var ib = parser.cache.get(ibCacheKey);
2178
+
2179
+ if (!ib) {
2180
+ array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes); // Integer parameters to IB/IBA are in array elements, not bytes.
2181
+
2182
+ ib = new _three.InterleavedBuffer(array, byteStride / elementBytes);
2183
+ parser.cache.add(ibCacheKey, ib);
2184
+ }
2185
+
2186
+ bufferAttribute = new _three.InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
2187
+ } else {
2188
+ if (bufferView === null) {
2189
+ array = new TypedArray(accessorDef.count * itemSize);
2190
+ } else {
2191
+ array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
2192
+ }
2193
+
2194
+ bufferAttribute = new _three.BufferAttribute(array, itemSize, normalized);
2195
+ } // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
2196
+
2197
+
2198
+ if (accessorDef.sparse !== undefined) {
2199
+ var itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
2200
+ var TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
2201
+ var byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
2202
+ var byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
2203
+ var sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
2204
+ var sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
2205
+
2206
+ if (bufferView !== null) {
2207
+ // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
2208
+ bufferAttribute = new _three.BufferAttribute(bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized);
2209
+ }
2210
+
2211
+ for (var i = 0, il = sparseIndices.length; i < il; i++) {
2212
+ var index = sparseIndices[i];
2213
+ bufferAttribute.setX(index, sparseValues[i * itemSize]);
2214
+ if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
2215
+ if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
2216
+ if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
2217
+ if (itemSize >= 5) throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.');
2218
+ }
2219
+ }
2220
+
2221
+ return bufferAttribute;
2222
+ });
2223
+ }
2224
+ /**
2225
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
2226
+ * @param {number} textureIndex
2227
+ * @return {Promise<THREE.Texture>}
2228
+ */
2229
+
2230
+ }, {
2231
+ key: "loadTexture",
2232
+ value: function loadTexture(textureIndex) {
2233
+ var json = this.json;
2234
+ var options = this.options;
2235
+ var textureDef = json.textures[textureIndex];
2236
+ var source = json.images[textureDef.source];
2237
+ var loader = this.textureLoader;
2238
+
2239
+ if (source.uri) {
2240
+ var handler = options.manager.getHandler(source.uri);
2241
+ if (handler !== null) loader = handler;
2242
+ }
2243
+
2244
+ return this.loadTextureImage(textureIndex, source, loader);
2245
+ }
2246
+ }, {
2247
+ key: "loadTextureImage",
2248
+ value: function loadTextureImage(textureIndex, source, loader) {
2249
+ var parser = this;
2250
+ var json = this.json;
2251
+ var options = this.options;
2252
+ var textureDef = json.textures[textureIndex];
2253
+ var cacheKey = (source.uri || source.bufferView) + ':' + textureDef.sampler;
2254
+
2255
+ if (this.textureCache[cacheKey]) {
2256
+ // See https://github.com/mrdoob/three.js/issues/21559.
2257
+ return this.textureCache[cacheKey];
2258
+ }
2259
+
2260
+ var URL = self.URL || self.webkitURL;
2261
+ var sourceURI = source.uri || '';
2262
+ var isObjectURL = false;
2263
+
2264
+ if (source.bufferView !== undefined) {
2265
+ // Load binary image data from bufferView, if provided.
2266
+ sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
2267
+ isObjectURL = true;
2268
+ var blob = new Blob([bufferView], {
2269
+ type: source.mimeType
2270
+ });
2271
+ sourceURI = URL.createObjectURL(blob);
2272
+ return sourceURI;
2273
+ });
2274
+ } else if (source.uri === undefined) {
2275
+ throw new Error('THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView');
2276
+ }
2277
+
2278
+ var promise = Promise.resolve(sourceURI).then(function (sourceURI) {
2279
+ return new Promise(function (resolve, reject) {
2280
+ var onLoad = resolve;
2281
+
2282
+ if (loader.isImageBitmapLoader === true) {
2283
+ onLoad = function onLoad(imageBitmap) {
2284
+ var texture = new _three.Texture(imageBitmap);
2285
+ texture.needsUpdate = true;
2286
+ resolve(texture);
2287
+ };
2288
+ }
2289
+
2290
+ loader.load(_three.LoaderUtils.resolveURL(sourceURI, options.path), onLoad, undefined, reject);
2291
+ });
2292
+ }).then(function (texture) {
2293
+ // Clean up resources and configure Texture.
2294
+ if (isObjectURL === true) {
2295
+ URL.revokeObjectURL(sourceURI);
2296
+ }
2297
+
2298
+ texture.flipY = false;
2299
+ if (textureDef.name) texture.name = textureDef.name;
2300
+ var samplers = json.samplers || {};
2301
+ var sampler = samplers[textureDef.sampler] || {};
2302
+ texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || _three.LinearFilter;
2303
+ texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || _three.LinearMipmapLinearFilter;
2304
+ texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || _three.RepeatWrapping;
2305
+ texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || _three.RepeatWrapping;
2306
+ parser.associations.set(texture, {
2307
+ textures: textureIndex
2308
+ });
2309
+ return texture;
2310
+ }).catch(function () {
2311
+ console.error('THREE.GLTFLoader: Couldn\'t load texture', sourceURI);
2312
+ return null;
2313
+ });
2314
+ this.textureCache[cacheKey] = promise;
2315
+ return promise;
2316
+ }
2317
+ /**
2318
+ * Asynchronously assigns a texture to the given material parameters.
2319
+ * @param {Object} materialParams
2320
+ * @param {string} mapName
2321
+ * @param {Object} mapDef
2322
+ * @return {Promise<Texture>}
2323
+ */
2324
+
2325
+ }, {
2326
+ key: "assignTexture",
2327
+ value: function assignTexture(materialParams, mapName, mapDef) {
2328
+ var parser = this;
2329
+ return this.getDependency('texture', mapDef.index).then(function (texture) {
2330
+ // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
2331
+ // However, we will copy UV set 0 to UV set 1 on demand for aoMap
2332
+ if (mapDef.texCoord !== undefined && mapDef.texCoord != 0 && !(mapName === 'aoMap' && mapDef.texCoord == 1)) {
2333
+ console.warn('THREE.GLTFLoader: Custom UV set ' + mapDef.texCoord + ' for texture ' + mapName + ' not yet supported.');
2334
+ }
2335
+
2336
+ if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
2337
+ var transform = mapDef.extensions !== undefined ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : undefined;
2338
+
2339
+ if (transform) {
2340
+ var gltfReference = parser.associations.get(texture);
2341
+ texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
2342
+ parser.associations.set(texture, gltfReference);
2343
+ }
2344
+ }
2345
+
2346
+ materialParams[mapName] = texture;
2347
+ return texture;
2348
+ });
2349
+ }
2350
+ /**
2351
+ * Assigns final material to a Mesh, Line, or Points instance. The instance
2352
+ * already has a material (generated from the glTF material options alone)
2353
+ * but reuse of the same glTF material may require multiple threejs materials
2354
+ * to accommodate different primitive types, defines, etc. New materials will
2355
+ * be created if necessary, and reused from a cache.
2356
+ * @param {Object3D} mesh Mesh, Line, or Points instance.
2357
+ */
2358
+
2359
+ }, {
2360
+ key: "assignFinalMaterial",
2361
+ value: function assignFinalMaterial(mesh) {
2362
+ var geometry = mesh.geometry;
2363
+ var material = mesh.material;
2364
+ var useDerivativeTangents = geometry.attributes.tangent === undefined;
2365
+ var useVertexColors = geometry.attributes.color !== undefined;
2366
+ var useFlatShading = geometry.attributes.normal === undefined;
2367
+
2368
+ if (mesh.isPoints) {
2369
+ var cacheKey = 'PointsMaterial:' + material.uuid;
2370
+ var pointsMaterial = this.cache.get(cacheKey);
2371
+
2372
+ if (!pointsMaterial) {
2373
+ pointsMaterial = new _three.PointsMaterial();
2374
+
2375
+ _three.Material.prototype.copy.call(pointsMaterial, material);
2376
+
2377
+ pointsMaterial.color.copy(material.color);
2378
+ pointsMaterial.map = material.map;
2379
+ pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
2380
+
2381
+ this.cache.add(cacheKey, pointsMaterial);
2382
+ }
2383
+
2384
+ material = pointsMaterial;
2385
+ } else if (mesh.isLine) {
2386
+ var _cacheKey = 'LineBasicMaterial:' + material.uuid;
2387
+
2388
+ var lineMaterial = this.cache.get(_cacheKey);
2389
+
2390
+ if (!lineMaterial) {
2391
+ lineMaterial = new _three.LineBasicMaterial();
2392
+
2393
+ _three.Material.prototype.copy.call(lineMaterial, material);
2394
+
2395
+ lineMaterial.color.copy(material.color);
2396
+ this.cache.add(_cacheKey, lineMaterial);
2397
+ }
2398
+
2399
+ material = lineMaterial;
2400
+ } // Clone the material if it will be modified
2401
+
2402
+
2403
+ if (useDerivativeTangents || useVertexColors || useFlatShading) {
2404
+ var _cacheKey2 = 'ClonedMaterial:' + material.uuid + ':';
2405
+
2406
+ if (material.isGLTFSpecularGlossinessMaterial) _cacheKey2 += 'specular-glossiness:';
2407
+ if (useDerivativeTangents) _cacheKey2 += 'derivative-tangents:';
2408
+ if (useVertexColors) _cacheKey2 += 'vertex-colors:';
2409
+ if (useFlatShading) _cacheKey2 += 'flat-shading:';
2410
+ var cachedMaterial = this.cache.get(_cacheKey2);
2411
+
2412
+ if (!cachedMaterial) {
2413
+ cachedMaterial = material.clone();
2414
+ if (useVertexColors) cachedMaterial.vertexColors = true;
2415
+ if (useFlatShading) cachedMaterial.flatShading = true;
2416
+
2417
+ if (useDerivativeTangents) {
2418
+ // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2419
+ if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
2420
+ if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
2421
+ }
2422
+
2423
+ this.cache.add(_cacheKey2, cachedMaterial);
2424
+ this.associations.set(cachedMaterial, this.associations.get(material));
2425
+ }
2426
+
2427
+ material = cachedMaterial;
2428
+ } // workarounds for mesh and geometry
2429
+
2430
+
2431
+ if (material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined) {
2432
+ geometry.setAttribute('uv2', geometry.attributes.uv);
2433
+ }
2434
+
2435
+ mesh.material = material;
2436
+ }
2437
+ }, {
2438
+ key: "getMaterialType",
2439
+ value: function
2440
+ /* materialIndex */
2441
+ getMaterialType() {
2442
+ return _three.MeshStandardMaterial;
2443
+ }
2444
+ /**
2445
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
2446
+ * @param {number} materialIndex
2447
+ * @return {Promise<Material>}
2448
+ */
2449
+
2450
+ }, {
2451
+ key: "loadMaterial",
2452
+ value: function loadMaterial(materialIndex) {
2453
+ var parser = this;
2454
+ var json = this.json;
2455
+ var extensions = this.extensions;
2456
+ var materialDef = json.materials[materialIndex];
2457
+ var materialType;
2458
+ var materialParams = {};
2459
+ var materialExtensions = materialDef.extensions || {};
2460
+ var pending = [];
2461
+
2462
+ if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
2463
+ var sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
2464
+ materialType = sgExtension.getMaterialType();
2465
+ pending.push(sgExtension.extendParams(materialParams, materialDef, parser));
2466
+ } else if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
2467
+ var kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
2468
+ materialType = kmuExtension.getMaterialType();
2469
+ pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
2470
+ } else {
2471
+ // Specification:
2472
+ // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
2473
+ var metallicRoughness = materialDef.pbrMetallicRoughness || {};
2474
+ materialParams.color = new _three.Color(1.0, 1.0, 1.0);
2475
+ materialParams.opacity = 1.0;
2476
+
2477
+ if (Array.isArray(metallicRoughness.baseColorFactor)) {
2478
+ var array = metallicRoughness.baseColorFactor;
2479
+ materialParams.color.fromArray(array);
2480
+ materialParams.opacity = array[3];
2481
+ }
2482
+
2483
+ if (metallicRoughness.baseColorTexture !== undefined) {
2484
+ pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
2485
+ }
2486
+
2487
+ materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
2488
+ materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
2489
+
2490
+ if (metallicRoughness.metallicRoughnessTexture !== undefined) {
2491
+ pending.push(parser.assignTexture(materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture));
2492
+ pending.push(parser.assignTexture(materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture));
2493
+ }
2494
+
2495
+ materialType = this._invokeOne(function (ext) {
2496
+ return ext.getMaterialType && ext.getMaterialType(materialIndex);
2497
+ });
2498
+ pending.push(Promise.all(this._invokeAll(function (ext) {
2499
+ return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
2500
+ })));
2501
+ }
2502
+
2503
+ if (materialDef.doubleSided === true) {
2504
+ materialParams.side = _three.DoubleSide;
2505
+ }
2506
+
2507
+ var alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
2508
+
2509
+ if (alphaMode === ALPHA_MODES.BLEND) {
2510
+ materialParams.transparent = true; // See: https://github.com/mrdoob/three.js/issues/17706
2511
+
2512
+ materialParams.depthWrite = false;
2513
+ } else {
2514
+ materialParams.format = _three.RGBFormat;
2515
+ materialParams.transparent = false;
2516
+
2517
+ if (alphaMode === ALPHA_MODES.MASK) {
2518
+ materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
2519
+ }
2520
+ }
2521
+
2522
+ if (materialDef.normalTexture !== undefined && materialType !== _three.MeshBasicMaterial) {
2523
+ pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
2524
+ materialParams.normalScale = new _three.Vector2(1, 1);
2525
+
2526
+ if (materialDef.normalTexture.scale !== undefined) {
2527
+ var scale = materialDef.normalTexture.scale;
2528
+ materialParams.normalScale.set(scale, scale);
2529
+ }
2530
+ }
2531
+
2532
+ if (materialDef.occlusionTexture !== undefined && materialType !== _three.MeshBasicMaterial) {
2533
+ pending.push(parser.assignTexture(materialParams, 'aoMap', materialDef.occlusionTexture));
2534
+
2535
+ if (materialDef.occlusionTexture.strength !== undefined) {
2536
+ materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
2537
+ }
2538
+ }
2539
+
2540
+ if (materialDef.emissiveFactor !== undefined && materialType !== _three.MeshBasicMaterial) {
2541
+ materialParams.emissive = new _three.Color().fromArray(materialDef.emissiveFactor);
2542
+ }
2543
+
2544
+ if (materialDef.emissiveTexture !== undefined && materialType !== _three.MeshBasicMaterial) {
2545
+ pending.push(parser.assignTexture(materialParams, 'emissiveMap', materialDef.emissiveTexture));
2546
+ }
2547
+
2548
+ return Promise.all(pending).then(function () {
2549
+ var material;
2550
+
2551
+ if (materialType === GLTFMeshStandardSGMaterial) {
2552
+ material = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(materialParams);
2553
+ } else {
2554
+ material = new materialType(materialParams);
2555
+ }
2556
+
2557
+ if (materialDef.name) material.name = materialDef.name; // baseColorTexture, emissiveTexture, and specularGlossinessTexture use sRGB encoding.
2558
+
2559
+ if (material.map) material.map.encoding = _three.sRGBEncoding;
2560
+ if (material.emissiveMap) material.emissiveMap.encoding = _three.sRGBEncoding;
2561
+ assignExtrasToUserData(material, materialDef);
2562
+ parser.associations.set(material, {
2563
+ materials: materialIndex
2564
+ });
2565
+ if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
2566
+ return material;
2567
+ });
2568
+ }
2569
+ /** When Object3D instances are targeted by animation, they need unique names. */
2570
+
2571
+ }, {
2572
+ key: "createUniqueName",
2573
+ value: function createUniqueName(originalName) {
2574
+ var sanitizedName = _three.PropertyBinding.sanitizeNodeName(originalName || '');
2575
+
2576
+ var name = sanitizedName;
2577
+
2578
+ for (var i = 1; this.nodeNamesUsed[name]; ++i) {
2579
+ name = sanitizedName + '_' + i;
2580
+ }
2581
+
2582
+ this.nodeNamesUsed[name] = true;
2583
+ return name;
2584
+ }
2585
+ /**
2586
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
2587
+ *
2588
+ * Creates BufferGeometries from primitives.
2589
+ *
2590
+ * @param {Array<GLTF.Primitive>} primitives
2591
+ * @return {Promise<Array<BufferGeometry>>}
2592
+ */
2593
+
2594
+ }, {
2595
+ key: "loadGeometries",
2596
+ value: function loadGeometries(primitives) {
2597
+ var parser = this;
2598
+ var extensions = this.extensions;
2599
+ var cache = this.primitiveCache;
2600
+
2601
+ function createDracoPrimitive(primitive) {
2602
+ return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function (geometry) {
2603
+ return addPrimitiveAttributes(geometry, primitive, parser);
2604
+ });
2605
+ }
2606
+
2607
+ var pending = [];
2608
+
2609
+ for (var i = 0, il = primitives.length; i < il; i++) {
2610
+ var primitive = primitives[i];
2611
+ var cacheKey = createPrimitiveKey(primitive); // See if we've already created this geometry
2612
+
2613
+ var cached = cache[cacheKey];
2614
+
2615
+ if (cached) {
2616
+ // Use the cached geometry if it exists
2617
+ pending.push(cached.promise);
2618
+ } else {
2619
+ var geometryPromise = void 0;
2620
+
2621
+ if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
2622
+ // Use DRACO geometry if available
2623
+ geometryPromise = createDracoPrimitive(primitive);
2624
+ } else {
2625
+ // Otherwise create a new geometry
2626
+ geometryPromise = addPrimitiveAttributes(new _three.BufferGeometry(), primitive, parser);
2627
+ } // Cache this geometry
2628
+
2629
+
2630
+ cache[cacheKey] = {
2631
+ primitive: primitive,
2632
+ promise: geometryPromise
2633
+ };
2634
+ pending.push(geometryPromise);
2635
+ }
2636
+ }
2637
+
2638
+ return Promise.all(pending);
2639
+ }
2640
+ /**
2641
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
2642
+ * @param {number} meshIndex
2643
+ * @return {Promise<Group|Mesh|SkinnedMesh>}
2644
+ */
2645
+
2646
+ }, {
2647
+ key: "loadMesh",
2648
+ value: function loadMesh(meshIndex) {
2649
+ var parser = this;
2650
+ var json = this.json;
2651
+ var extensions = this.extensions;
2652
+ var meshDef = json.meshes[meshIndex];
2653
+ var primitives = meshDef.primitives;
2654
+ var pending = [];
2655
+
2656
+ for (var i = 0, il = primitives.length; i < il; i++) {
2657
+ var material = primitives[i].material === undefined ? createDefaultMaterial(this.cache) : this.getDependency('material', primitives[i].material);
2658
+ pending.push(material);
2659
+ }
2660
+
2661
+ pending.push(parser.loadGeometries(primitives));
2662
+ return Promise.all(pending).then(function (results) {
2663
+ var materials = results.slice(0, results.length - 1);
2664
+ var geometries = results[results.length - 1];
2665
+ var meshes = [];
2666
+
2667
+ for (var _i4 = 0, _il3 = geometries.length; _i4 < _il3; _i4++) {
2668
+ var geometry = geometries[_i4];
2669
+ var primitive = primitives[_i4]; // 1. create Mesh
2670
+
2671
+ var mesh = void 0;
2672
+ var _material = materials[_i4];
2673
+
2674
+ if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === undefined) {
2675
+ // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
2676
+ mesh = meshDef.isSkinnedMesh === true ? new _three.SkinnedMesh(geometry, _material) : new _three.Mesh(geometry, _material);
2677
+
2678
+ if (mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized) {
2679
+ // we normalize floating point skin weight array to fix malformed assets (see #15319)
2680
+ // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
2681
+ mesh.normalizeSkinWeights();
2682
+ }
2683
+
2684
+ if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
2685
+ mesh.geometry = toTrianglesDrawMode(mesh.geometry, _three.TriangleStripDrawMode);
2686
+ } else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
2687
+ mesh.geometry = toTrianglesDrawMode(mesh.geometry, _three.TriangleFanDrawMode);
2688
+ }
2689
+ } else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
2690
+ mesh = new _three.LineSegments(geometry, _material);
2691
+ } else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
2692
+ mesh = new _three.Line(geometry, _material);
2693
+ } else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
2694
+ mesh = new _three.LineLoop(geometry, _material);
2695
+ } else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
2696
+ mesh = new _three.Points(geometry, _material);
2697
+ } else {
2698
+ throw new Error('THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode);
2699
+ }
2700
+
2701
+ if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
2702
+ updateMorphTargets(mesh, meshDef);
2703
+ }
2704
+
2705
+ mesh.name = parser.createUniqueName(meshDef.name || 'mesh_' + meshIndex);
2706
+ assignExtrasToUserData(mesh, meshDef);
2707
+ if (primitive.extensions) addUnknownExtensionsToUserData(extensions, mesh, primitive);
2708
+ parser.assignFinalMaterial(mesh);
2709
+ meshes.push(mesh);
2710
+ }
2711
+
2712
+ for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
2713
+ parser.associations.set(meshes[_i5], {
2714
+ meshes: meshIndex,
2715
+ primitives: _i5
2716
+ });
2717
+ }
2718
+
2719
+ if (meshes.length === 1) {
2720
+ return meshes[0];
2721
+ }
2722
+
2723
+ var group = new _three.Group();
2724
+ parser.associations.set(group, {
2725
+ meshes: meshIndex
2726
+ });
2727
+
2728
+ for (var _i6 = 0, _il5 = meshes.length; _i6 < _il5; _i6++) {
2729
+ group.add(meshes[_i6]);
2730
+ }
2731
+
2732
+ return group;
2733
+ });
2734
+ }
2735
+ /**
2736
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
2737
+ * @param {number} cameraIndex
2738
+ * @return {Promise<THREE.Camera>}
2739
+ */
2740
+
2741
+ }, {
2742
+ key: "loadCamera",
2743
+ value: function loadCamera(cameraIndex) {
2744
+ var camera;
2745
+ var cameraDef = this.json.cameras[cameraIndex];
2746
+ var params = cameraDef[cameraDef.type];
2747
+
2748
+ if (!params) {
2749
+ console.warn('THREE.GLTFLoader: Missing camera parameters.');
2750
+ return;
2751
+ }
2752
+
2753
+ if (cameraDef.type === 'perspective') {
2754
+ camera = new _three.PerspectiveCamera(_three.MathUtils.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
2755
+ } else if (cameraDef.type === 'orthographic') {
2756
+ camera = new _three.OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
2757
+ }
2758
+
2759
+ if (cameraDef.name) camera.name = this.createUniqueName(cameraDef.name);
2760
+ assignExtrasToUserData(camera, cameraDef);
2761
+ return Promise.resolve(camera);
2762
+ }
2763
+ /**
2764
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
2765
+ * @param {number} skinIndex
2766
+ * @return {Promise<Object>}
2767
+ */
2768
+
2769
+ }, {
2770
+ key: "loadSkin",
2771
+ value: function loadSkin(skinIndex) {
2772
+ var skinDef = this.json.skins[skinIndex];
2773
+ var skinEntry = {
2774
+ joints: skinDef.joints
2775
+ };
2776
+
2777
+ if (skinDef.inverseBindMatrices === undefined) {
2778
+ return Promise.resolve(skinEntry);
2779
+ }
2780
+
2781
+ return this.getDependency('accessor', skinDef.inverseBindMatrices).then(function (accessor) {
2782
+ skinEntry.inverseBindMatrices = accessor;
2783
+ return skinEntry;
2784
+ });
2785
+ }
2786
+ /**
2787
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
2788
+ * @param {number} animationIndex
2789
+ * @return {Promise<AnimationClip>}
2790
+ */
2791
+
2792
+ }, {
2793
+ key: "loadAnimation",
2794
+ value: function loadAnimation(animationIndex) {
2795
+ var json = this.json;
2796
+ var animationDef = json.animations[animationIndex];
2797
+ var pendingNodes = [];
2798
+ var pendingInputAccessors = [];
2799
+ var pendingOutputAccessors = [];
2800
+ var pendingSamplers = [];
2801
+ var pendingTargets = [];
2802
+
2803
+ for (var i = 0, il = animationDef.channels.length; i < il; i++) {
2804
+ var channel = animationDef.channels[i];
2805
+ var sampler = animationDef.samplers[channel.sampler];
2806
+ var target = channel.target;
2807
+ var name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
2808
+
2809
+ var input = animationDef.parameters !== undefined ? animationDef.parameters[sampler.input] : sampler.input;
2810
+ var output = animationDef.parameters !== undefined ? animationDef.parameters[sampler.output] : sampler.output;
2811
+ pendingNodes.push(this.getDependency('node', name));
2812
+ pendingInputAccessors.push(this.getDependency('accessor', input));
2813
+ pendingOutputAccessors.push(this.getDependency('accessor', output));
2814
+ pendingSamplers.push(sampler);
2815
+ pendingTargets.push(target);
2816
+ }
2817
+
2818
+ return Promise.all([Promise.all(pendingNodes), Promise.all(pendingInputAccessors), Promise.all(pendingOutputAccessors), Promise.all(pendingSamplers), Promise.all(pendingTargets)]).then(function (dependencies) {
2819
+ var nodes = dependencies[0];
2820
+ var inputAccessors = dependencies[1];
2821
+ var outputAccessors = dependencies[2];
2822
+ var samplers = dependencies[3];
2823
+ var targets = dependencies[4];
2824
+ var tracks = [];
2825
+
2826
+ var _loop = function _loop(_i7, _il6) {
2827
+ var node = nodes[_i7];
2828
+ var inputAccessor = inputAccessors[_i7];
2829
+ var outputAccessor = outputAccessors[_i7];
2830
+ var sampler = samplers[_i7];
2831
+ var target = targets[_i7];
2832
+ if (node === undefined) return "continue";
2833
+ node.updateMatrix();
2834
+ node.matrixAutoUpdate = true;
2835
+ var TypedKeyframeTrack = void 0;
2836
+
2837
+ switch (PATH_PROPERTIES[target.path]) {
2838
+ case PATH_PROPERTIES.weights:
2839
+ TypedKeyframeTrack = _three.NumberKeyframeTrack;
2840
+ break;
2841
+
2842
+ case PATH_PROPERTIES.rotation:
2843
+ TypedKeyframeTrack = _three.QuaternionKeyframeTrack;
2844
+ break;
2845
+
2846
+ case PATH_PROPERTIES.position:
2847
+ case PATH_PROPERTIES.scale:
2848
+ default:
2849
+ TypedKeyframeTrack = _three.VectorKeyframeTrack;
2850
+ break;
2851
+ }
2852
+
2853
+ var targetName = node.name ? node.name : node.uuid;
2854
+ var interpolation = sampler.interpolation !== undefined ? INTERPOLATION[sampler.interpolation] : _three.InterpolateLinear;
2855
+ var targetNames = [];
2856
+
2857
+ if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
2858
+ node.traverse(function (object) {
2859
+ if (object.morphTargetInfluences) {
2860
+ targetNames.push(object.name ? object.name : object.uuid);
2861
+ }
2862
+ });
2863
+ } else {
2864
+ targetNames.push(targetName);
2865
+ }
2866
+
2867
+ var outputArray = outputAccessor.array;
2868
+
2869
+ if (outputAccessor.normalized) {
2870
+ var scale = getNormalizedComponentScale(outputArray.constructor);
2871
+ var scaled = new Float32Array(outputArray.length);
2872
+
2873
+ for (var j = 0, jl = outputArray.length; j < jl; j++) {
2874
+ scaled[j] = outputArray[j] * scale;
2875
+ }
2876
+
2877
+ outputArray = scaled;
2878
+ }
2879
+
2880
+ for (var _j = 0, _jl = targetNames.length; _j < _jl; _j++) {
2881
+ var track = new TypedKeyframeTrack(targetNames[_j] + '.' + PATH_PROPERTIES[target.path], inputAccessor.array, outputArray, interpolation); // Override interpolation with custom factory method.
2882
+
2883
+ if (sampler.interpolation === 'CUBICSPLINE') {
2884
+ track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
2885
+ // A CUBICSPLINE keyframe in glTF has three output values for each input value,
2886
+ // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2887
+ // must be divided by three to get the interpolant's sampleSize argument.
2888
+ var interpolantType = this instanceof _three.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2889
+ return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
2890
+ }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2891
+
2892
+
2893
+ track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
2894
+ }
2895
+
2896
+ tracks.push(track);
2897
+ }
2898
+ };
2899
+
2900
+ for (var _i7 = 0, _il6 = nodes.length; _i7 < _il6; _i7++) {
2901
+ var _ret = _loop(_i7, _il6);
2902
+
2903
+ if (_ret === "continue") continue;
2904
+ }
2905
+
2906
+ var name = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
2907
+ return new _three.AnimationClip(name, undefined, tracks);
2908
+ });
2909
+ }
2910
+ }, {
2911
+ key: "createNodeMesh",
2912
+ value: function createNodeMesh(nodeIndex) {
2913
+ var json = this.json;
2914
+ var parser = this;
2915
+ var nodeDef = json.nodes[nodeIndex];
2916
+ if (nodeDef.mesh === undefined) return null;
2917
+ return parser.getDependency('mesh', nodeDef.mesh).then(function (mesh) {
2918
+ var node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh); // if weights are provided on the node, override weights on the mesh.
2919
+
2920
+
2921
+ if (nodeDef.weights !== undefined) {
2922
+ node.traverse(function (o) {
2923
+ if (!o.isMesh) return;
2924
+
2925
+ for (var i = 0, il = nodeDef.weights.length; i < il; i++) {
2926
+ o.morphTargetInfluences[i] = nodeDef.weights[i];
2927
+ }
2928
+ });
2929
+ }
2930
+
2931
+ return node;
2932
+ });
2933
+ }
2934
+ /**
2935
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
2936
+ * @param {number} nodeIndex
2937
+ * @return {Promise<Object3D>}
2938
+ */
2939
+
2940
+ }, {
2941
+ key: "loadNode",
2942
+ value: function loadNode(nodeIndex) {
2943
+ var json = this.json;
2944
+ var extensions = this.extensions;
2945
+ var parser = this;
2946
+ var nodeDef = json.nodes[nodeIndex]; // reserve node's name before its dependencies, so the root has the intended name.
2947
+
2948
+ var nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : '';
2949
+ return function () {
2950
+ var pending = [];
2951
+
2952
+ var meshPromise = parser._invokeOne(function (ext) {
2953
+ return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
2954
+ });
2955
+
2956
+ if (meshPromise) {
2957
+ pending.push(meshPromise);
2958
+ }
2959
+
2960
+ if (nodeDef.camera !== undefined) {
2961
+ pending.push(parser.getDependency('camera', nodeDef.camera).then(function (camera) {
2962
+ return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
2963
+ }));
2964
+ }
2965
+
2966
+ parser._invokeAll(function (ext) {
2967
+ return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
2968
+ }).forEach(function (promise) {
2969
+ pending.push(promise);
2970
+ });
2971
+
2972
+ return Promise.all(pending);
2973
+ }().then(function (objects) {
2974
+ var node; // .isBone isn't in glTF spec. See ._markDefs
2975
+
2976
+ if (nodeDef.isBone === true) {
2977
+ node = new _three.Bone();
2978
+ } else if (objects.length > 1) {
2979
+ node = new _three.Group();
2980
+ } else if (objects.length === 1) {
2981
+ node = objects[0];
2982
+ } else {
2983
+ node = new _three.Object3D();
2984
+ }
2985
+
2986
+ if (node !== objects[0]) {
2987
+ for (var i = 0, il = objects.length; i < il; i++) {
2988
+ node.add(objects[i]);
2989
+ }
2990
+ }
2991
+
2992
+ if (nodeDef.name) {
2993
+ node.userData.name = nodeDef.name;
2994
+ node.name = nodeName;
2995
+ }
2996
+
2997
+ assignExtrasToUserData(node, nodeDef);
2998
+ if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
2999
+
3000
+ if (nodeDef.matrix !== undefined) {
3001
+ var matrix = new _three.Matrix4();
3002
+ matrix.fromArray(nodeDef.matrix);
3003
+ node.applyMatrix4(matrix);
3004
+ } else {
3005
+ if (nodeDef.translation !== undefined) {
3006
+ node.position.fromArray(nodeDef.translation);
3007
+ }
3008
+
3009
+ if (nodeDef.rotation !== undefined) {
3010
+ node.quaternion.fromArray(nodeDef.rotation);
3011
+ }
3012
+
3013
+ if (nodeDef.scale !== undefined) {
3014
+ node.scale.fromArray(nodeDef.scale);
3015
+ }
3016
+ }
3017
+
3018
+ if (!parser.associations.has(node)) {
3019
+ parser.associations.set(node, {});
3020
+ }
3021
+
3022
+ parser.associations.get(node).nodes = nodeIndex;
3023
+ return node;
3024
+ });
3025
+ }
3026
+ /**
3027
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
3028
+ * @param {number} sceneIndex
3029
+ * @return {Promise<Group>}
3030
+ */
3031
+
3032
+ }, {
3033
+ key: "loadScene",
3034
+ value: function loadScene(sceneIndex) {
3035
+ var json = this.json;
3036
+ var extensions = this.extensions;
3037
+ var sceneDef = this.json.scenes[sceneIndex];
3038
+ var parser = this; // Loader returns Group, not Scene.
3039
+ // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
3040
+
3041
+ var scene = new _three.Group();
3042
+ if (sceneDef.name) scene.name = parser.createUniqueName(sceneDef.name);
3043
+ assignExtrasToUserData(scene, sceneDef);
3044
+ if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
3045
+ var nodeIds = sceneDef.nodes || [];
3046
+ var pending = [];
3047
+
3048
+ for (var i = 0, il = nodeIds.length; i < il; i++) {
3049
+ pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
3050
+ }
3051
+
3052
+ return Promise.all(pending).then(function () {
3053
+ // Removes dangling associations, associations that reference a node that
3054
+ // didn't make it into the scene.
3055
+ var reduceAssociations = function reduceAssociations(node) {
3056
+ var reducedAssociations = new Map();
3057
+
3058
+ var _iterator2 = _createForOfIteratorHelper(parser.associations),
3059
+ _step2;
3060
+
3061
+ try {
3062
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3063
+ var _step2$value = _slicedToArray(_step2.value, 2),
3064
+ key = _step2$value[0],
3065
+ value = _step2$value[1];
3066
+
3067
+ if (key instanceof _three.Material || key instanceof _three.Texture) {
3068
+ reducedAssociations.set(key, value);
3069
+ }
3070
+ }
3071
+ } catch (err) {
3072
+ _iterator2.e(err);
3073
+ } finally {
3074
+ _iterator2.f();
3075
+ }
3076
+
3077
+ node.traverse(function (node) {
3078
+ var mappings = parser.associations.get(node);
3079
+
3080
+ if (mappings != null) {
3081
+ reducedAssociations.set(node, mappings);
3082
+ }
3083
+ });
3084
+ return reducedAssociations;
3085
+ };
3086
+
3087
+ parser.associations = reduceAssociations(scene);
3088
+ return scene;
3089
+ });
3090
+ }
3091
+ }]);
3092
+
3093
+ return GLTFParser;
3094
+ }();
3095
+
3096
+ function buildNodeHierarchy(nodeId, parentObject, json, parser) {
3097
+ var nodeDef = json.nodes[nodeId];
3098
+ return parser.getDependency('node', nodeId).then(function (node) {
3099
+ if (nodeDef.skin === undefined) return node; // build skeleton here as well
3100
+
3101
+ var skinEntry;
3102
+ return parser.getDependency('skin', nodeDef.skin).then(function (skin) {
3103
+ skinEntry = skin;
3104
+ var pendingJoints = [];
3105
+
3106
+ for (var i = 0, il = skinEntry.joints.length; i < il; i++) {
3107
+ pendingJoints.push(parser.getDependency('node', skinEntry.joints[i]));
3108
+ }
3109
+
3110
+ return Promise.all(pendingJoints);
3111
+ }).then(function (jointNodes) {
3112
+ node.traverse(function (mesh) {
3113
+ if (!mesh.isMesh) return;
3114
+ var bones = [];
3115
+ var boneInverses = [];
3116
+
3117
+ for (var j = 0, jl = jointNodes.length; j < jl; j++) {
3118
+ var jointNode = jointNodes[j];
3119
+
3120
+ if (jointNode) {
3121
+ bones.push(jointNode);
3122
+ var mat = new _three.Matrix4();
3123
+
3124
+ if (skinEntry.inverseBindMatrices !== undefined) {
3125
+ mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
3126
+ }
3127
+
3128
+ boneInverses.push(mat);
3129
+ } else {
3130
+ console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[j]);
3131
+ }
3132
+ }
3133
+
3134
+ mesh.bind(new _three.Skeleton(bones, boneInverses), mesh.matrixWorld);
3135
+ });
3136
+ return node;
3137
+ });
3138
+ }).then(function (node) {
3139
+ // build node hierachy
3140
+ parentObject.add(node);
3141
+ var pending = [];
3142
+
3143
+ if (nodeDef.children) {
3144
+ var children = nodeDef.children;
3145
+
3146
+ for (var i = 0, il = children.length; i < il; i++) {
3147
+ var child = children[i];
3148
+ pending.push(buildNodeHierarchy(child, node, json, parser));
3149
+ }
3150
+ }
3151
+
3152
+ return Promise.all(pending);
3153
+ });
3154
+ }
3155
+ /**
3156
+ * @param {BufferGeometry} geometry
3157
+ * @param {GLTF.Primitive} primitiveDef
3158
+ * @param {GLTFParser} parser
3159
+ */
3160
+
3161
+
3162
+ function computeBounds(geometry, primitiveDef, parser) {
3163
+ var attributes = primitiveDef.attributes;
3164
+ var box = new _three.Box3();
3165
+
3166
+ if (attributes.POSITION !== undefined) {
3167
+ var accessor = parser.json.accessors[attributes.POSITION];
3168
+ var min = accessor.min;
3169
+ var max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3170
+
3171
+ if (min !== undefined && max !== undefined) {
3172
+ box.set(new _three.Vector3(min[0], min[1], min[2]), new _three.Vector3(max[0], max[1], max[2]));
3173
+
3174
+ if (accessor.normalized) {
3175
+ var boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
3176
+ box.min.multiplyScalar(boxScale);
3177
+ box.max.multiplyScalar(boxScale);
3178
+ }
3179
+ } else {
3180
+ console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
3181
+ return;
3182
+ }
3183
+ } else {
3184
+ return;
3185
+ }
3186
+
3187
+ var targets = primitiveDef.targets;
3188
+
3189
+ if (targets !== undefined) {
3190
+ var maxDisplacement = new _three.Vector3();
3191
+ var vector = new _three.Vector3();
3192
+
3193
+ for (var i = 0, il = targets.length; i < il; i++) {
3194
+ var target = targets[i];
3195
+
3196
+ if (target.POSITION !== undefined) {
3197
+ var _accessor = parser.json.accessors[target.POSITION];
3198
+ var _min = _accessor.min;
3199
+ var _max = _accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3200
+
3201
+ if (_min !== undefined && _max !== undefined) {
3202
+ // we need to get max of absolute components because target weight is [-1,1]
3203
+ vector.setX(Math.max(Math.abs(_min[0]), Math.abs(_max[0])));
3204
+ vector.setY(Math.max(Math.abs(_min[1]), Math.abs(_max[1])));
3205
+ vector.setZ(Math.max(Math.abs(_min[2]), Math.abs(_max[2])));
3206
+
3207
+ if (_accessor.normalized) {
3208
+ var _boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[_accessor.componentType]);
3209
+
3210
+ vector.multiplyScalar(_boxScale);
3211
+ } // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
3212
+ // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
3213
+ // are used to implement key-frame animations and as such only two are active at a time - this results in very large
3214
+ // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
3215
+
3216
+
3217
+ maxDisplacement.max(vector);
3218
+ } else {
3219
+ console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
3220
+ }
3221
+ }
3222
+ } // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
3223
+
3224
+
3225
+ box.expandByVector(maxDisplacement);
3226
+ }
3227
+
3228
+ geometry.boundingBox = box;
3229
+ var sphere = new _three.Sphere();
3230
+ box.getCenter(sphere.center);
3231
+ sphere.radius = box.min.distanceTo(box.max) / 2;
3232
+ geometry.boundingSphere = sphere;
3233
+ }
3234
+ /**
3235
+ * @param {BufferGeometry} geometry
3236
+ * @param {GLTF.Primitive} primitiveDef
3237
+ * @param {GLTFParser} parser
3238
+ * @return {Promise<BufferGeometry>}
3239
+ */
3240
+
3241
+
3242
+ function addPrimitiveAttributes(geometry, primitiveDef, parser) {
3243
+ var attributes = primitiveDef.attributes;
3244
+ var pending = [];
3245
+
3246
+ function assignAttributeAccessor(accessorIndex, attributeName) {
3247
+ return parser.getDependency('accessor', accessorIndex).then(function (accessor) {
3248
+ geometry.setAttribute(attributeName, accessor);
3249
+ });
3250
+ }
3251
+
3252
+ for (var gltfAttributeName in attributes) {
3253
+ var threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase(); // Skip attributes already provided by e.g. Draco extension.
3254
+
3255
+ if (threeAttributeName in geometry.attributes) continue;
3256
+ pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
3257
+ }
3258
+
3259
+ if (primitiveDef.indices !== undefined && !geometry.index) {
3260
+ var accessor = parser.getDependency('accessor', primitiveDef.indices).then(function (accessor) {
3261
+ geometry.setIndex(accessor);
3262
+ });
3263
+ pending.push(accessor);
3264
+ }
3265
+
3266
+ assignExtrasToUserData(geometry, primitiveDef);
3267
+ computeBounds(geometry, primitiveDef, parser);
3268
+ return Promise.all(pending).then(function () {
3269
+ return primitiveDef.targets !== undefined ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
3270
+ });
3271
+ }
3272
+ /**
3273
+ * @param {BufferGeometry} geometry
3274
+ * @param {Number} drawMode
3275
+ * @return {BufferGeometry}
3276
+ */
3277
+
3278
+
3279
+ function toTrianglesDrawMode(geometry, drawMode) {
3280
+ var index = geometry.getIndex(); // generate index if not present
3281
+
3282
+ if (index === null) {
3283
+ var indices = [];
3284
+ var position = geometry.getAttribute('position');
3285
+
3286
+ if (position !== undefined) {
3287
+ for (var i = 0; i < position.count; i++) {
3288
+ indices.push(i);
3289
+ }
3290
+
3291
+ geometry.setIndex(indices);
3292
+ index = geometry.getIndex();
3293
+ } else {
3294
+ console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.');
3295
+ return geometry;
3296
+ }
3297
+ } //
3298
+
3299
+
3300
+ var numberOfTriangles = index.count - 2;
3301
+ var newIndices = [];
3302
+
3303
+ if (drawMode === _three.TriangleFanDrawMode) {
3304
+ // gl.TRIANGLE_FAN
3305
+ for (var _i8 = 1; _i8 <= numberOfTriangles; _i8++) {
3306
+ newIndices.push(index.getX(0));
3307
+ newIndices.push(index.getX(_i8));
3308
+ newIndices.push(index.getX(_i8 + 1));
3309
+ }
3310
+ } else {
3311
+ // gl.TRIANGLE_STRIP
3312
+ for (var _i9 = 0; _i9 < numberOfTriangles; _i9++) {
3313
+ if (_i9 % 2 === 0) {
3314
+ newIndices.push(index.getX(_i9));
3315
+ newIndices.push(index.getX(_i9 + 1));
3316
+ newIndices.push(index.getX(_i9 + 2));
3317
+ } else {
3318
+ newIndices.push(index.getX(_i9 + 2));
3319
+ newIndices.push(index.getX(_i9 + 1));
3320
+ newIndices.push(index.getX(_i9));
3321
+ }
3322
+ }
3323
+ }
3324
+
3325
+ if (newIndices.length / 3 !== numberOfTriangles) {
3326
+ console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.');
3327
+ } // build final geometry
3328
+
3329
+
3330
+ var newGeometry = geometry.clone();
3331
+ newGeometry.setIndex(newIndices);
3332
+ return newGeometry;
3333
+ }
3334
+ });