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,3125 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "three", "../libs/fflate.module.js", "../curves/NURBSCurve.js"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("three"), require("../libs/fflate.module.js"), require("../curves/NURBSCurve.js"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.three, global.fflateModule, global.NURBSCurve);
11
+ global.FBXLoader = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three, fflate, _NURBSCurve) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.FBXLoader = void 0;
20
+ fflate = _interopRequireWildcard(fflate);
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
+
28
+ 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); } }
29
+
30
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
31
+
32
+ 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); }
33
+
34
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
35
+
36
+ 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); }; }
37
+
38
+ 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); }
39
+
40
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
41
+
42
+ 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; } }
43
+
44
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
45
+
46
+ /**
47
+ * Loader loads FBX file and generates Group representing FBX scene.
48
+ * Requires FBX file to be >= 7.0 and in ASCII or >= 6400 in Binary format
49
+ * Versions lower than this may load but will probably have errors
50
+ *
51
+ * Needs Support:
52
+ * Morph normals / blend shape normals
53
+ *
54
+ * FBX format references:
55
+ * https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
56
+ * http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_index_html (C++ SDK reference)
57
+ *
58
+ * Binary format specification:
59
+ * https://code.blender.org/2013/08/fbx-binary-file-format-specification/
60
+ */
61
+ var fbxTree;
62
+ var connections;
63
+ var sceneGraph;
64
+
65
+ var FBXLoader = /*#__PURE__*/function (_Loader) {
66
+ _inherits(FBXLoader, _Loader);
67
+
68
+ var _super = _createSuper(FBXLoader);
69
+
70
+ function FBXLoader(manager) {
71
+ _classCallCheck(this, FBXLoader);
72
+
73
+ return _super.call(this, manager);
74
+ }
75
+
76
+ _createClass(FBXLoader, [{
77
+ key: "load",
78
+ value: function load(url, onLoad, onProgress, onError) {
79
+ var scope = this;
80
+ var path = scope.path === '' ? _three.LoaderUtils.extractUrlBase(url) : scope.path;
81
+ var loader = new _three.FileLoader(this.manager);
82
+ loader.setPath(scope.path);
83
+ loader.setResponseType('arraybuffer');
84
+ loader.setRequestHeader(scope.requestHeader);
85
+ loader.setWithCredentials(scope.withCredentials);
86
+ loader.load(url, function (buffer) {
87
+ try {
88
+ onLoad(scope.parse(buffer, path));
89
+ } catch (e) {
90
+ if (onError) {
91
+ onError(e);
92
+ } else {
93
+ console.error(e);
94
+ }
95
+
96
+ scope.manager.itemError(url);
97
+ }
98
+ }, onProgress, onError);
99
+ }
100
+ }, {
101
+ key: "parse",
102
+ value: function parse(FBXBuffer, path) {
103
+ if (isFbxFormatBinary(FBXBuffer)) {
104
+ fbxTree = new BinaryParser().parse(FBXBuffer);
105
+ } else {
106
+ var FBXText = convertArrayBufferToString(FBXBuffer);
107
+
108
+ if (!isFbxFormatASCII(FBXText)) {
109
+ throw new Error('THREE.FBXLoader: Unknown format.');
110
+ }
111
+
112
+ if (getFbxVersion(FBXText) < 7000) {
113
+ throw new Error('THREE.FBXLoader: FBX version not supported, FileVersion: ' + getFbxVersion(FBXText));
114
+ }
115
+
116
+ fbxTree = new TextParser().parse(FBXText);
117
+ } // console.log( fbxTree );
118
+
119
+
120
+ var textureLoader = new _three.TextureLoader(this.manager).setPath(this.resourcePath || path).setCrossOrigin(this.crossOrigin);
121
+ return new FBXTreeParser(textureLoader, this.manager).parse(fbxTree);
122
+ }
123
+ }]);
124
+
125
+ return FBXLoader;
126
+ }(_three.Loader); // Parse the FBXTree object returned by the BinaryParser or TextParser and return a Group
127
+
128
+
129
+ _exports.FBXLoader = FBXLoader;
130
+
131
+ var FBXTreeParser = /*#__PURE__*/function () {
132
+ function FBXTreeParser(textureLoader, manager) {
133
+ _classCallCheck(this, FBXTreeParser);
134
+
135
+ this.textureLoader = textureLoader;
136
+ this.manager = manager;
137
+ }
138
+
139
+ _createClass(FBXTreeParser, [{
140
+ key: "parse",
141
+ value: function parse() {
142
+ connections = this.parseConnections();
143
+ var images = this.parseImages();
144
+ var textures = this.parseTextures(images);
145
+ var materials = this.parseMaterials(textures);
146
+ var deformers = this.parseDeformers();
147
+ var geometryMap = new GeometryParser().parse(deformers);
148
+ this.parseScene(deformers, geometryMap, materials);
149
+ return sceneGraph;
150
+ } // Parses FBXTree.Connections which holds parent-child connections between objects (e.g. material -> texture, model->geometry )
151
+ // and details the connection type
152
+
153
+ }, {
154
+ key: "parseConnections",
155
+ value: function parseConnections() {
156
+ var connectionMap = new Map();
157
+
158
+ if ('Connections' in fbxTree) {
159
+ var rawConnections = fbxTree.Connections.connections;
160
+ rawConnections.forEach(function (rawConnection) {
161
+ var fromID = rawConnection[0];
162
+ var toID = rawConnection[1];
163
+ var relationship = rawConnection[2];
164
+
165
+ if (!connectionMap.has(fromID)) {
166
+ connectionMap.set(fromID, {
167
+ parents: [],
168
+ children: []
169
+ });
170
+ }
171
+
172
+ var parentRelationship = {
173
+ ID: toID,
174
+ relationship: relationship
175
+ };
176
+ connectionMap.get(fromID).parents.push(parentRelationship);
177
+
178
+ if (!connectionMap.has(toID)) {
179
+ connectionMap.set(toID, {
180
+ parents: [],
181
+ children: []
182
+ });
183
+ }
184
+
185
+ var childRelationship = {
186
+ ID: fromID,
187
+ relationship: relationship
188
+ };
189
+ connectionMap.get(toID).children.push(childRelationship);
190
+ });
191
+ }
192
+
193
+ return connectionMap;
194
+ } // Parse FBXTree.Objects.Video for embedded image data
195
+ // These images are connected to textures in FBXTree.Objects.Textures
196
+ // via FBXTree.Connections.
197
+
198
+ }, {
199
+ key: "parseImages",
200
+ value: function parseImages() {
201
+ var images = {};
202
+ var blobs = {};
203
+
204
+ if ('Video' in fbxTree.Objects) {
205
+ var videoNodes = fbxTree.Objects.Video;
206
+
207
+ for (var nodeID in videoNodes) {
208
+ var videoNode = videoNodes[nodeID];
209
+ var id = parseInt(nodeID);
210
+ images[id] = videoNode.RelativeFilename || videoNode.Filename; // raw image data is in videoNode.Content
211
+
212
+ if ('Content' in videoNode) {
213
+ var arrayBufferContent = videoNode.Content instanceof ArrayBuffer && videoNode.Content.byteLength > 0;
214
+ var base64Content = typeof videoNode.Content === 'string' && videoNode.Content !== '';
215
+
216
+ if (arrayBufferContent || base64Content) {
217
+ var image = this.parseImage(videoNodes[nodeID]);
218
+ blobs[videoNode.RelativeFilename || videoNode.Filename] = image;
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ for (var _id in images) {
225
+ var filename = images[_id];
226
+ if (blobs[filename] !== undefined) images[_id] = blobs[filename];else images[_id] = images[_id].split('\\').pop();
227
+ }
228
+
229
+ return images;
230
+ } // Parse embedded image data in FBXTree.Video.Content
231
+
232
+ }, {
233
+ key: "parseImage",
234
+ value: function parseImage(videoNode) {
235
+ var content = videoNode.Content;
236
+ var fileName = videoNode.RelativeFilename || videoNode.Filename;
237
+ var extension = fileName.slice(fileName.lastIndexOf('.') + 1).toLowerCase();
238
+ var type;
239
+
240
+ switch (extension) {
241
+ case 'bmp':
242
+ type = 'image/bmp';
243
+ break;
244
+
245
+ case 'jpg':
246
+ case 'jpeg':
247
+ type = 'image/jpeg';
248
+ break;
249
+
250
+ case 'png':
251
+ type = 'image/png';
252
+ break;
253
+
254
+ case 'tif':
255
+ type = 'image/tiff';
256
+ break;
257
+
258
+ case 'tga':
259
+ if (this.manager.getHandler('.tga') === null) {
260
+ console.warn('FBXLoader: TGA loader not found, skipping ', fileName);
261
+ }
262
+
263
+ type = 'image/tga';
264
+ break;
265
+
266
+ default:
267
+ console.warn('FBXLoader: Image type "' + extension + '" is not supported.');
268
+ return;
269
+ }
270
+
271
+ if (typeof content === 'string') {
272
+ // ASCII format
273
+ return 'data:' + type + ';base64,' + content;
274
+ } else {
275
+ // Binary Format
276
+ var array = new Uint8Array(content);
277
+ return window.URL.createObjectURL(new Blob([array], {
278
+ type: type
279
+ }));
280
+ }
281
+ } // Parse nodes in FBXTree.Objects.Texture
282
+ // These contain details such as UV scaling, cropping, rotation etc and are connected
283
+ // to images in FBXTree.Objects.Video
284
+
285
+ }, {
286
+ key: "parseTextures",
287
+ value: function parseTextures(images) {
288
+ var textureMap = new Map();
289
+
290
+ if ('Texture' in fbxTree.Objects) {
291
+ var textureNodes = fbxTree.Objects.Texture;
292
+
293
+ for (var nodeID in textureNodes) {
294
+ var texture = this.parseTexture(textureNodes[nodeID], images);
295
+ textureMap.set(parseInt(nodeID), texture);
296
+ }
297
+ }
298
+
299
+ return textureMap;
300
+ } // Parse individual node in FBXTree.Objects.Texture
301
+
302
+ }, {
303
+ key: "parseTexture",
304
+ value: function parseTexture(textureNode, images) {
305
+ var texture = this.loadTexture(textureNode, images);
306
+ texture.ID = textureNode.id;
307
+ texture.name = textureNode.attrName;
308
+ var wrapModeU = textureNode.WrapModeU;
309
+ var wrapModeV = textureNode.WrapModeV;
310
+ var valueU = wrapModeU !== undefined ? wrapModeU.value : 0;
311
+ var valueV = wrapModeV !== undefined ? wrapModeV.value : 0; // http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a
312
+ // 0: repeat(default), 1: clamp
313
+
314
+ texture.wrapS = valueU === 0 ? _three.RepeatWrapping : _three.ClampToEdgeWrapping;
315
+ texture.wrapT = valueV === 0 ? _three.RepeatWrapping : _three.ClampToEdgeWrapping;
316
+
317
+ if ('Scaling' in textureNode) {
318
+ var values = textureNode.Scaling.value;
319
+ texture.repeat.x = values[0];
320
+ texture.repeat.y = values[1];
321
+ }
322
+
323
+ return texture;
324
+ } // load a texture specified as a blob or data URI, or via an external URL using TextureLoader
325
+
326
+ }, {
327
+ key: "loadTexture",
328
+ value: function loadTexture(textureNode, images) {
329
+ var fileName;
330
+ var currentPath = this.textureLoader.path;
331
+ var children = connections.get(textureNode.id).children;
332
+
333
+ if (children !== undefined && children.length > 0 && images[children[0].ID] !== undefined) {
334
+ fileName = images[children[0].ID];
335
+
336
+ if (fileName.indexOf('blob:') === 0 || fileName.indexOf('data:') === 0) {
337
+ this.textureLoader.setPath(undefined);
338
+ }
339
+ }
340
+
341
+ var texture;
342
+ var extension = textureNode.FileName.slice(-3).toLowerCase();
343
+
344
+ if (extension === 'tga') {
345
+ var loader = this.manager.getHandler('.tga');
346
+
347
+ if (loader === null) {
348
+ console.warn('FBXLoader: TGA loader not found, creating placeholder texture for', textureNode.RelativeFilename);
349
+ texture = new _three.Texture();
350
+ } else {
351
+ loader.setPath(this.textureLoader.path);
352
+ texture = loader.load(fileName);
353
+ }
354
+ } else if (extension === 'psd') {
355
+ console.warn('FBXLoader: PSD textures are not supported, creating placeholder texture for', textureNode.RelativeFilename);
356
+ texture = new _three.Texture();
357
+ } else {
358
+ texture = this.textureLoader.load(fileName);
359
+ }
360
+
361
+ this.textureLoader.setPath(currentPath);
362
+ return texture;
363
+ } // Parse nodes in FBXTree.Objects.Material
364
+
365
+ }, {
366
+ key: "parseMaterials",
367
+ value: function parseMaterials(textureMap) {
368
+ var materialMap = new Map();
369
+
370
+ if ('Material' in fbxTree.Objects) {
371
+ var materialNodes = fbxTree.Objects.Material;
372
+
373
+ for (var nodeID in materialNodes) {
374
+ var material = this.parseMaterial(materialNodes[nodeID], textureMap);
375
+ if (material !== null) materialMap.set(parseInt(nodeID), material);
376
+ }
377
+ }
378
+
379
+ return materialMap;
380
+ } // Parse single node in FBXTree.Objects.Material
381
+ // Materials are connected to texture maps in FBXTree.Objects.Textures
382
+ // FBX format currently only supports Lambert and Phong shading models
383
+
384
+ }, {
385
+ key: "parseMaterial",
386
+ value: function parseMaterial(materialNode, textureMap) {
387
+ var ID = materialNode.id;
388
+ var name = materialNode.attrName;
389
+ var type = materialNode.ShadingModel; // Case where FBX wraps shading model in property object.
390
+
391
+ if (typeof type === 'object') {
392
+ type = type.value;
393
+ } // Ignore unused materials which don't have any connections.
394
+
395
+
396
+ if (!connections.has(ID)) return null;
397
+ var parameters = this.parseParameters(materialNode, textureMap, ID);
398
+ var material;
399
+
400
+ switch (type.toLowerCase()) {
401
+ case 'phong':
402
+ material = new _three.MeshPhongMaterial();
403
+ break;
404
+
405
+ case 'lambert':
406
+ material = new _three.MeshLambertMaterial();
407
+ break;
408
+
409
+ default:
410
+ console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type);
411
+ material = new _three.MeshPhongMaterial();
412
+ break;
413
+ }
414
+
415
+ material.setValues(parameters);
416
+ material.name = name;
417
+ return material;
418
+ } // Parse FBX material and return parameters suitable for a three.js material
419
+ // Also parse the texture map and return any textures associated with the material
420
+
421
+ }, {
422
+ key: "parseParameters",
423
+ value: function parseParameters(materialNode, textureMap, ID) {
424
+ var parameters = {};
425
+
426
+ if (materialNode.BumpFactor) {
427
+ parameters.bumpScale = materialNode.BumpFactor.value;
428
+ }
429
+
430
+ if (materialNode.Diffuse) {
431
+ parameters.color = new _three.Color().fromArray(materialNode.Diffuse.value);
432
+ } else if (materialNode.DiffuseColor && (materialNode.DiffuseColor.type === 'Color' || materialNode.DiffuseColor.type === 'ColorRGB')) {
433
+ // The blender exporter exports diffuse here instead of in materialNode.Diffuse
434
+ parameters.color = new _three.Color().fromArray(materialNode.DiffuseColor.value);
435
+ }
436
+
437
+ if (materialNode.DisplacementFactor) {
438
+ parameters.displacementScale = materialNode.DisplacementFactor.value;
439
+ }
440
+
441
+ if (materialNode.Emissive) {
442
+ parameters.emissive = new _three.Color().fromArray(materialNode.Emissive.value);
443
+ } else if (materialNode.EmissiveColor && (materialNode.EmissiveColor.type === 'Color' || materialNode.EmissiveColor.type === 'ColorRGB')) {
444
+ // The blender exporter exports emissive color here instead of in materialNode.Emissive
445
+ parameters.emissive = new _three.Color().fromArray(materialNode.EmissiveColor.value);
446
+ }
447
+
448
+ if (materialNode.EmissiveFactor) {
449
+ parameters.emissiveIntensity = parseFloat(materialNode.EmissiveFactor.value);
450
+ }
451
+
452
+ if (materialNode.Opacity) {
453
+ parameters.opacity = parseFloat(materialNode.Opacity.value);
454
+ }
455
+
456
+ if (parameters.opacity < 1.0) {
457
+ parameters.transparent = true;
458
+ }
459
+
460
+ if (materialNode.ReflectionFactor) {
461
+ parameters.reflectivity = materialNode.ReflectionFactor.value;
462
+ }
463
+
464
+ if (materialNode.Shininess) {
465
+ parameters.shininess = materialNode.Shininess.value;
466
+ }
467
+
468
+ if (materialNode.Specular) {
469
+ parameters.specular = new _three.Color().fromArray(materialNode.Specular.value);
470
+ } else if (materialNode.SpecularColor && materialNode.SpecularColor.type === 'Color') {
471
+ // The blender exporter exports specular color here instead of in materialNode.Specular
472
+ parameters.specular = new _three.Color().fromArray(materialNode.SpecularColor.value);
473
+ }
474
+
475
+ var scope = this;
476
+ connections.get(ID).children.forEach(function (child) {
477
+ var type = child.relationship;
478
+
479
+ switch (type) {
480
+ case 'Bump':
481
+ parameters.bumpMap = scope.getTexture(textureMap, child.ID);
482
+ break;
483
+
484
+ case 'Maya|TEX_ao_map':
485
+ parameters.aoMap = scope.getTexture(textureMap, child.ID);
486
+ break;
487
+
488
+ case 'DiffuseColor':
489
+ case 'Maya|TEX_color_map':
490
+ parameters.map = scope.getTexture(textureMap, child.ID);
491
+
492
+ if (parameters.map !== undefined) {
493
+ parameters.map.encoding = _three.sRGBEncoding;
494
+ }
495
+
496
+ break;
497
+
498
+ case 'DisplacementColor':
499
+ parameters.displacementMap = scope.getTexture(textureMap, child.ID);
500
+ break;
501
+
502
+ case 'EmissiveColor':
503
+ parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
504
+
505
+ if (parameters.emissiveMap !== undefined) {
506
+ parameters.emissiveMap.encoding = _three.sRGBEncoding;
507
+ }
508
+
509
+ break;
510
+
511
+ case 'NormalMap':
512
+ case 'Maya|TEX_normal_map':
513
+ parameters.normalMap = scope.getTexture(textureMap, child.ID);
514
+ break;
515
+
516
+ case 'ReflectionColor':
517
+ parameters.envMap = scope.getTexture(textureMap, child.ID);
518
+
519
+ if (parameters.envMap !== undefined) {
520
+ parameters.envMap.mapping = _three.EquirectangularReflectionMapping;
521
+ parameters.envMap.encoding = _three.sRGBEncoding;
522
+ }
523
+
524
+ break;
525
+
526
+ case 'SpecularColor':
527
+ parameters.specularMap = scope.getTexture(textureMap, child.ID);
528
+
529
+ if (parameters.specularMap !== undefined) {
530
+ parameters.specularMap.encoding = _three.sRGBEncoding;
531
+ }
532
+
533
+ break;
534
+
535
+ case 'TransparentColor':
536
+ case 'TransparencyFactor':
537
+ parameters.alphaMap = scope.getTexture(textureMap, child.ID);
538
+ parameters.transparent = true;
539
+ break;
540
+
541
+ case 'AmbientColor':
542
+ case 'ShininessExponent': // AKA glossiness map
543
+
544
+ case 'SpecularFactor': // AKA specularLevel
545
+
546
+ case 'VectorDisplacementColor': // NOTE: Seems to be a copy of DisplacementColor
547
+
548
+ default:
549
+ console.warn('THREE.FBXLoader: %s map is not supported in three.js, skipping texture.', type);
550
+ break;
551
+ }
552
+ });
553
+ return parameters;
554
+ } // get a texture from the textureMap for use by a material.
555
+
556
+ }, {
557
+ key: "getTexture",
558
+ value: function getTexture(textureMap, id) {
559
+ // if the texture is a layered texture, just use the first layer and issue a warning
560
+ if ('LayeredTexture' in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture) {
561
+ console.warn('THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.');
562
+ id = connections.get(id).children[0].ID;
563
+ }
564
+
565
+ return textureMap.get(id);
566
+ } // Parse nodes in FBXTree.Objects.Deformer
567
+ // Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here
568
+ // Generates map of Skeleton-like objects for use later when generating and binding skeletons.
569
+
570
+ }, {
571
+ key: "parseDeformers",
572
+ value: function parseDeformers() {
573
+ var skeletons = {};
574
+ var morphTargets = {};
575
+
576
+ if ('Deformer' in fbxTree.Objects) {
577
+ var DeformerNodes = fbxTree.Objects.Deformer;
578
+
579
+ for (var nodeID in DeformerNodes) {
580
+ var deformerNode = DeformerNodes[nodeID];
581
+ var relationships = connections.get(parseInt(nodeID));
582
+
583
+ if (deformerNode.attrType === 'Skin') {
584
+ var skeleton = this.parseSkeleton(relationships, DeformerNodes);
585
+ skeleton.ID = nodeID;
586
+ if (relationships.parents.length > 1) console.warn('THREE.FBXLoader: skeleton attached to more than one geometry is not supported.');
587
+ skeleton.geometryID = relationships.parents[0].ID;
588
+ skeletons[nodeID] = skeleton;
589
+ } else if (deformerNode.attrType === 'BlendShape') {
590
+ var morphTarget = {
591
+ id: nodeID
592
+ };
593
+ morphTarget.rawTargets = this.parseMorphTargets(relationships, DeformerNodes);
594
+ morphTarget.id = nodeID;
595
+ if (relationships.parents.length > 1) console.warn('THREE.FBXLoader: morph target attached to more than one geometry is not supported.');
596
+ morphTargets[nodeID] = morphTarget;
597
+ }
598
+ }
599
+ }
600
+
601
+ return {
602
+ skeletons: skeletons,
603
+ morphTargets: morphTargets
604
+ };
605
+ } // Parse single nodes in FBXTree.Objects.Deformer
606
+ // The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster'
607
+ // Each skin node represents a skeleton and each cluster node represents a bone
608
+
609
+ }, {
610
+ key: "parseSkeleton",
611
+ value: function parseSkeleton(relationships, deformerNodes) {
612
+ var rawBones = [];
613
+ relationships.children.forEach(function (child) {
614
+ var boneNode = deformerNodes[child.ID];
615
+ if (boneNode.attrType !== 'Cluster') return;
616
+ var rawBone = {
617
+ ID: child.ID,
618
+ indices: [],
619
+ weights: [],
620
+ transformLink: new _three.Matrix4().fromArray(boneNode.TransformLink.a) // transform: new Matrix4().fromArray( boneNode.Transform.a ),
621
+ // linkMode: boneNode.Mode,
622
+
623
+ };
624
+
625
+ if ('Indexes' in boneNode) {
626
+ rawBone.indices = boneNode.Indexes.a;
627
+ rawBone.weights = boneNode.Weights.a;
628
+ }
629
+
630
+ rawBones.push(rawBone);
631
+ });
632
+ return {
633
+ rawBones: rawBones,
634
+ bones: []
635
+ };
636
+ } // The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel"
637
+
638
+ }, {
639
+ key: "parseMorphTargets",
640
+ value: function parseMorphTargets(relationships, deformerNodes) {
641
+ var rawMorphTargets = [];
642
+
643
+ for (var i = 0; i < relationships.children.length; i++) {
644
+ var child = relationships.children[i];
645
+ var morphTargetNode = deformerNodes[child.ID];
646
+ var rawMorphTarget = {
647
+ name: morphTargetNode.attrName,
648
+ initialWeight: morphTargetNode.DeformPercent,
649
+ id: morphTargetNode.id,
650
+ fullWeights: morphTargetNode.FullWeights.a
651
+ };
652
+ if (morphTargetNode.attrType !== 'BlendShapeChannel') return;
653
+ rawMorphTarget.geoID = connections.get(parseInt(child.ID)).children.filter(function (child) {
654
+ return child.relationship === undefined;
655
+ })[0].ID;
656
+ rawMorphTargets.push(rawMorphTarget);
657
+ }
658
+
659
+ return rawMorphTargets;
660
+ } // create the main Group() to be returned by the loader
661
+
662
+ }, {
663
+ key: "parseScene",
664
+ value: function parseScene(deformers, geometryMap, materialMap) {
665
+ sceneGraph = new _three.Group();
666
+ var modelMap = this.parseModels(deformers.skeletons, geometryMap, materialMap);
667
+ var modelNodes = fbxTree.Objects.Model;
668
+ var scope = this;
669
+ modelMap.forEach(function (model) {
670
+ var modelNode = modelNodes[model.ID];
671
+ scope.setLookAtProperties(model, modelNode);
672
+ var parentConnections = connections.get(model.ID).parents;
673
+ parentConnections.forEach(function (connection) {
674
+ var parent = modelMap.get(connection.ID);
675
+ if (parent !== undefined) parent.add(model);
676
+ });
677
+
678
+ if (model.parent === null) {
679
+ sceneGraph.add(model);
680
+ }
681
+ });
682
+ this.bindSkeleton(deformers.skeletons, geometryMap, modelMap);
683
+ this.createAmbientLight();
684
+ sceneGraph.traverse(function (node) {
685
+ if (node.userData.transformData) {
686
+ if (node.parent) {
687
+ node.userData.transformData.parentMatrix = node.parent.matrix;
688
+ node.userData.transformData.parentMatrixWorld = node.parent.matrixWorld;
689
+ }
690
+
691
+ var transform = generateTransform(node.userData.transformData);
692
+ node.applyMatrix4(transform);
693
+ node.updateWorldMatrix();
694
+ }
695
+ });
696
+ var animations = new AnimationParser().parse(); // if all the models where already combined in a single group, just return that
697
+
698
+ if (sceneGraph.children.length === 1 && sceneGraph.children[0].isGroup) {
699
+ sceneGraph.children[0].animations = animations;
700
+ sceneGraph = sceneGraph.children[0];
701
+ }
702
+
703
+ sceneGraph.animations = animations;
704
+ } // parse nodes in FBXTree.Objects.Model
705
+
706
+ }, {
707
+ key: "parseModels",
708
+ value: function parseModels(skeletons, geometryMap, materialMap) {
709
+ var modelMap = new Map();
710
+ var modelNodes = fbxTree.Objects.Model;
711
+
712
+ for (var nodeID in modelNodes) {
713
+ var id = parseInt(nodeID);
714
+ var node = modelNodes[nodeID];
715
+ var relationships = connections.get(id);
716
+ var model = this.buildSkeleton(relationships, skeletons, id, node.attrName);
717
+
718
+ if (!model) {
719
+ switch (node.attrType) {
720
+ case 'Camera':
721
+ model = this.createCamera(relationships);
722
+ break;
723
+
724
+ case 'Light':
725
+ model = this.createLight(relationships);
726
+ break;
727
+
728
+ case 'Mesh':
729
+ model = this.createMesh(relationships, geometryMap, materialMap);
730
+ break;
731
+
732
+ case 'NurbsCurve':
733
+ model = this.createCurve(relationships, geometryMap);
734
+ break;
735
+
736
+ case 'LimbNode':
737
+ case 'Root':
738
+ model = new _three.Bone();
739
+ break;
740
+
741
+ case 'Null':
742
+ default:
743
+ model = new _three.Group();
744
+ break;
745
+ }
746
+
747
+ model.name = node.attrName ? _three.PropertyBinding.sanitizeNodeName(node.attrName) : '';
748
+ model.ID = id;
749
+ }
750
+
751
+ this.getTransformData(model, node);
752
+ modelMap.set(id, model);
753
+ }
754
+
755
+ return modelMap;
756
+ }
757
+ }, {
758
+ key: "buildSkeleton",
759
+ value: function buildSkeleton(relationships, skeletons, id, name) {
760
+ var bone = null;
761
+ relationships.parents.forEach(function (parent) {
762
+ var _loop = function _loop(ID) {
763
+ var skeleton = skeletons[ID];
764
+ skeleton.rawBones.forEach(function (rawBone, i) {
765
+ if (rawBone.ID === parent.ID) {
766
+ var subBone = bone;
767
+ bone = new _three.Bone();
768
+ bone.matrixWorld.copy(rawBone.transformLink); // set name and id here - otherwise in cases where "subBone" is created it will not have a name / id
769
+
770
+ bone.name = name ? _three.PropertyBinding.sanitizeNodeName(name) : '';
771
+ bone.ID = id;
772
+ skeleton.bones[i] = bone; // In cases where a bone is shared between multiple meshes
773
+ // duplicate the bone here and and it as a child of the first bone
774
+
775
+ if (subBone !== null) {
776
+ bone.add(subBone);
777
+ }
778
+ }
779
+ });
780
+ };
781
+
782
+ for (var ID in skeletons) {
783
+ _loop(ID);
784
+ }
785
+ });
786
+ return bone;
787
+ } // create a PerspectiveCamera or OrthographicCamera
788
+
789
+ }, {
790
+ key: "createCamera",
791
+ value: function createCamera(relationships) {
792
+ var model;
793
+ var cameraAttribute;
794
+ relationships.children.forEach(function (child) {
795
+ var attr = fbxTree.Objects.NodeAttribute[child.ID];
796
+
797
+ if (attr !== undefined) {
798
+ cameraAttribute = attr;
799
+ }
800
+ });
801
+
802
+ if (cameraAttribute === undefined) {
803
+ model = new _three.Object3D();
804
+ } else {
805
+ var type = 0;
806
+
807
+ if (cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1) {
808
+ type = 1;
809
+ }
810
+
811
+ var nearClippingPlane = 1;
812
+
813
+ if (cameraAttribute.NearPlane !== undefined) {
814
+ nearClippingPlane = cameraAttribute.NearPlane.value / 1000;
815
+ }
816
+
817
+ var farClippingPlane = 1000;
818
+
819
+ if (cameraAttribute.FarPlane !== undefined) {
820
+ farClippingPlane = cameraAttribute.FarPlane.value / 1000;
821
+ }
822
+
823
+ var width = window.innerWidth;
824
+ var height = window.innerHeight;
825
+
826
+ if (cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined) {
827
+ width = cameraAttribute.AspectWidth.value;
828
+ height = cameraAttribute.AspectHeight.value;
829
+ }
830
+
831
+ var aspect = width / height;
832
+ var fov = 45;
833
+
834
+ if (cameraAttribute.FieldOfView !== undefined) {
835
+ fov = cameraAttribute.FieldOfView.value;
836
+ }
837
+
838
+ var focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
839
+
840
+ switch (type) {
841
+ case 0:
842
+ // Perspective
843
+ model = new _three.PerspectiveCamera(fov, aspect, nearClippingPlane, farClippingPlane);
844
+ if (focalLength !== null) model.setFocalLength(focalLength);
845
+ break;
846
+
847
+ case 1:
848
+ // Orthographic
849
+ model = new _three.OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2, nearClippingPlane, farClippingPlane);
850
+ break;
851
+
852
+ default:
853
+ console.warn('THREE.FBXLoader: Unknown camera type ' + type + '.');
854
+ model = new _three.Object3D();
855
+ break;
856
+ }
857
+ }
858
+
859
+ return model;
860
+ } // Create a DirectionalLight, PointLight or SpotLight
861
+
862
+ }, {
863
+ key: "createLight",
864
+ value: function createLight(relationships) {
865
+ var model;
866
+ var lightAttribute;
867
+ relationships.children.forEach(function (child) {
868
+ var attr = fbxTree.Objects.NodeAttribute[child.ID];
869
+
870
+ if (attr !== undefined) {
871
+ lightAttribute = attr;
872
+ }
873
+ });
874
+
875
+ if (lightAttribute === undefined) {
876
+ model = new _three.Object3D();
877
+ } else {
878
+ var type; // LightType can be undefined for Point lights
879
+
880
+ if (lightAttribute.LightType === undefined) {
881
+ type = 0;
882
+ } else {
883
+ type = lightAttribute.LightType.value;
884
+ }
885
+
886
+ var color = 0xffffff;
887
+
888
+ if (lightAttribute.Color !== undefined) {
889
+ color = new _three.Color().fromArray(lightAttribute.Color.value);
890
+ }
891
+
892
+ var intensity = lightAttribute.Intensity === undefined ? 1 : lightAttribute.Intensity.value / 100; // light disabled
893
+
894
+ if (lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0) {
895
+ intensity = 0;
896
+ }
897
+
898
+ var distance = 0;
899
+
900
+ if (lightAttribute.FarAttenuationEnd !== undefined) {
901
+ if (lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0) {
902
+ distance = 0;
903
+ } else {
904
+ distance = lightAttribute.FarAttenuationEnd.value;
905
+ }
906
+ } // TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?
907
+
908
+
909
+ var decay = 1;
910
+
911
+ switch (type) {
912
+ case 0:
913
+ // Point
914
+ model = new _three.PointLight(color, intensity, distance, decay);
915
+ break;
916
+
917
+ case 1:
918
+ // Directional
919
+ model = new _three.DirectionalLight(color, intensity);
920
+ break;
921
+
922
+ case 2:
923
+ // Spot
924
+ var angle = Math.PI / 3;
925
+
926
+ if (lightAttribute.InnerAngle !== undefined) {
927
+ angle = _three.MathUtils.degToRad(lightAttribute.InnerAngle.value);
928
+ }
929
+
930
+ var penumbra = 0;
931
+
932
+ if (lightAttribute.OuterAngle !== undefined) {
933
+ // TODO: this is not correct - FBX calculates outer and inner angle in degrees
934
+ // with OuterAngle > InnerAngle && OuterAngle <= Math.PI
935
+ // while three.js uses a penumbra between (0, 1) to attenuate the inner angle
936
+ penumbra = _three.MathUtils.degToRad(lightAttribute.OuterAngle.value);
937
+ penumbra = Math.max(penumbra, 1);
938
+ }
939
+
940
+ model = new _three.SpotLight(color, intensity, distance, angle, penumbra, decay);
941
+ break;
942
+
943
+ default:
944
+ console.warn('THREE.FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a PointLight.');
945
+ model = new _three.PointLight(color, intensity);
946
+ break;
947
+ }
948
+
949
+ if (lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1) {
950
+ model.castShadow = true;
951
+ }
952
+ }
953
+
954
+ return model;
955
+ }
956
+ }, {
957
+ key: "createMesh",
958
+ value: function createMesh(relationships, geometryMap, materialMap) {
959
+ var model;
960
+ var geometry = null;
961
+ var material = null;
962
+ var materials = []; // get geometry and materials(s) from connections
963
+
964
+ relationships.children.forEach(function (child) {
965
+ if (geometryMap.has(child.ID)) {
966
+ geometry = geometryMap.get(child.ID);
967
+ }
968
+
969
+ if (materialMap.has(child.ID)) {
970
+ materials.push(materialMap.get(child.ID));
971
+ }
972
+ });
973
+
974
+ if (materials.length > 1) {
975
+ material = materials;
976
+ } else if (materials.length > 0) {
977
+ material = materials[0];
978
+ } else {
979
+ material = new _three.MeshPhongMaterial({
980
+ color: 0xcccccc
981
+ });
982
+ materials.push(material);
983
+ }
984
+
985
+ if ('color' in geometry.attributes) {
986
+ materials.forEach(function (material) {
987
+ material.vertexColors = true;
988
+ });
989
+ }
990
+
991
+ if (geometry.FBX_Deformer) {
992
+ model = new _three.SkinnedMesh(geometry, material);
993
+ model.normalizeSkinWeights();
994
+ } else {
995
+ model = new _three.Mesh(geometry, material);
996
+ }
997
+
998
+ return model;
999
+ }
1000
+ }, {
1001
+ key: "createCurve",
1002
+ value: function createCurve(relationships, geometryMap) {
1003
+ var geometry = relationships.children.reduce(function (geo, child) {
1004
+ if (geometryMap.has(child.ID)) geo = geometryMap.get(child.ID);
1005
+ return geo;
1006
+ }, null); // FBX does not list materials for Nurbs lines, so we'll just put our own in here.
1007
+
1008
+ var material = new _three.LineBasicMaterial({
1009
+ color: 0x3300ff,
1010
+ linewidth: 1
1011
+ });
1012
+ return new _three.Line(geometry, material);
1013
+ } // parse the model node for transform data
1014
+
1015
+ }, {
1016
+ key: "getTransformData",
1017
+ value: function getTransformData(model, modelNode) {
1018
+ var transformData = {};
1019
+ if ('InheritType' in modelNode) transformData.inheritType = parseInt(modelNode.InheritType.value);
1020
+ if ('RotationOrder' in modelNode) transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value);else transformData.eulerOrder = 'ZYX';
1021
+ if ('Lcl_Translation' in modelNode) transformData.translation = modelNode.Lcl_Translation.value;
1022
+ if ('PreRotation' in modelNode) transformData.preRotation = modelNode.PreRotation.value;
1023
+ if ('Lcl_Rotation' in modelNode) transformData.rotation = modelNode.Lcl_Rotation.value;
1024
+ if ('PostRotation' in modelNode) transformData.postRotation = modelNode.PostRotation.value;
1025
+ if ('Lcl_Scaling' in modelNode) transformData.scale = modelNode.Lcl_Scaling.value;
1026
+ if ('ScalingOffset' in modelNode) transformData.scalingOffset = modelNode.ScalingOffset.value;
1027
+ if ('ScalingPivot' in modelNode) transformData.scalingPivot = modelNode.ScalingPivot.value;
1028
+ if ('RotationOffset' in modelNode) transformData.rotationOffset = modelNode.RotationOffset.value;
1029
+ if ('RotationPivot' in modelNode) transformData.rotationPivot = modelNode.RotationPivot.value;
1030
+ model.userData.transformData = transformData;
1031
+ }
1032
+ }, {
1033
+ key: "setLookAtProperties",
1034
+ value: function setLookAtProperties(model, modelNode) {
1035
+ if ('LookAtProperty' in modelNode) {
1036
+ var children = connections.get(model.ID).children;
1037
+ children.forEach(function (child) {
1038
+ if (child.relationship === 'LookAtProperty') {
1039
+ var lookAtTarget = fbxTree.Objects.Model[child.ID];
1040
+
1041
+ if ('Lcl_Translation' in lookAtTarget) {
1042
+ var pos = lookAtTarget.Lcl_Translation.value; // DirectionalLight, SpotLight
1043
+
1044
+ if (model.target !== undefined) {
1045
+ model.target.position.fromArray(pos);
1046
+ sceneGraph.add(model.target);
1047
+ } else {
1048
+ // Cameras and other Object3Ds
1049
+ model.lookAt(new _three.Vector3().fromArray(pos));
1050
+ }
1051
+ }
1052
+ }
1053
+ });
1054
+ }
1055
+ }
1056
+ }, {
1057
+ key: "bindSkeleton",
1058
+ value: function bindSkeleton(skeletons, geometryMap, modelMap) {
1059
+ var bindMatrices = this.parsePoseNodes();
1060
+
1061
+ var _loop2 = function _loop2(ID) {
1062
+ var skeleton = skeletons[ID];
1063
+ var parents = connections.get(parseInt(skeleton.ID)).parents;
1064
+ parents.forEach(function (parent) {
1065
+ if (geometryMap.has(parent.ID)) {
1066
+ var geoID = parent.ID;
1067
+ var geoRelationships = connections.get(geoID);
1068
+ geoRelationships.parents.forEach(function (geoConnParent) {
1069
+ if (modelMap.has(geoConnParent.ID)) {
1070
+ var model = modelMap.get(geoConnParent.ID);
1071
+ model.bind(new _three.Skeleton(skeleton.bones), bindMatrices[geoConnParent.ID]);
1072
+ }
1073
+ });
1074
+ }
1075
+ });
1076
+ };
1077
+
1078
+ for (var ID in skeletons) {
1079
+ _loop2(ID);
1080
+ }
1081
+ }
1082
+ }, {
1083
+ key: "parsePoseNodes",
1084
+ value: function parsePoseNodes() {
1085
+ var bindMatrices = {};
1086
+
1087
+ if ('Pose' in fbxTree.Objects) {
1088
+ var BindPoseNode = fbxTree.Objects.Pose;
1089
+
1090
+ for (var nodeID in BindPoseNode) {
1091
+ if (BindPoseNode[nodeID].attrType === 'BindPose' && BindPoseNode[nodeID].NbPoseNodes > 0) {
1092
+ var poseNodes = BindPoseNode[nodeID].PoseNode;
1093
+
1094
+ if (Array.isArray(poseNodes)) {
1095
+ poseNodes.forEach(function (poseNode) {
1096
+ bindMatrices[poseNode.Node] = new _three.Matrix4().fromArray(poseNode.Matrix.a);
1097
+ });
1098
+ } else {
1099
+ bindMatrices[poseNodes.Node] = new _three.Matrix4().fromArray(poseNodes.Matrix.a);
1100
+ }
1101
+ }
1102
+ }
1103
+ }
1104
+
1105
+ return bindMatrices;
1106
+ } // Parse ambient color in FBXTree.GlobalSettings - if it's not set to black (default), create an ambient light
1107
+
1108
+ }, {
1109
+ key: "createAmbientLight",
1110
+ value: function createAmbientLight() {
1111
+ if ('GlobalSettings' in fbxTree && 'AmbientColor' in fbxTree.GlobalSettings) {
1112
+ var ambientColor = fbxTree.GlobalSettings.AmbientColor.value;
1113
+ var r = ambientColor[0];
1114
+ var g = ambientColor[1];
1115
+ var b = ambientColor[2];
1116
+
1117
+ if (r !== 0 || g !== 0 || b !== 0) {
1118
+ var color = new _three.Color(r, g, b);
1119
+ sceneGraph.add(new _three.AmbientLight(color, 1));
1120
+ }
1121
+ }
1122
+ }
1123
+ }]);
1124
+
1125
+ return FBXTreeParser;
1126
+ }(); // parse Geometry data from FBXTree and return map of BufferGeometries
1127
+
1128
+
1129
+ var GeometryParser = /*#__PURE__*/function () {
1130
+ function GeometryParser() {
1131
+ _classCallCheck(this, GeometryParser);
1132
+ }
1133
+
1134
+ _createClass(GeometryParser, [{
1135
+ key: "parse",
1136
+ value: // Parse nodes in FBXTree.Objects.Geometry
1137
+ function parse(deformers) {
1138
+ var geometryMap = new Map();
1139
+
1140
+ if ('Geometry' in fbxTree.Objects) {
1141
+ var geoNodes = fbxTree.Objects.Geometry;
1142
+
1143
+ for (var nodeID in geoNodes) {
1144
+ var relationships = connections.get(parseInt(nodeID));
1145
+ var geo = this.parseGeometry(relationships, geoNodes[nodeID], deformers);
1146
+ geometryMap.set(parseInt(nodeID), geo);
1147
+ }
1148
+ }
1149
+
1150
+ return geometryMap;
1151
+ } // Parse single node in FBXTree.Objects.Geometry
1152
+
1153
+ }, {
1154
+ key: "parseGeometry",
1155
+ value: function parseGeometry(relationships, geoNode, deformers) {
1156
+ switch (geoNode.attrType) {
1157
+ case 'Mesh':
1158
+ return this.parseMeshGeometry(relationships, geoNode, deformers);
1159
+ break;
1160
+
1161
+ case 'NurbsCurve':
1162
+ return this.parseNurbsGeometry(geoNode);
1163
+ break;
1164
+ }
1165
+ } // Parse single node mesh geometry in FBXTree.Objects.Geometry
1166
+
1167
+ }, {
1168
+ key: "parseMeshGeometry",
1169
+ value: function parseMeshGeometry(relationships, geoNode, deformers) {
1170
+ var skeletons = deformers.skeletons;
1171
+ var morphTargets = [];
1172
+ var modelNodes = relationships.parents.map(function (parent) {
1173
+ return fbxTree.Objects.Model[parent.ID];
1174
+ }); // don't create geometry if it is not associated with any models
1175
+
1176
+ if (modelNodes.length === 0) return;
1177
+ var skeleton = relationships.children.reduce(function (skeleton, child) {
1178
+ if (skeletons[child.ID] !== undefined) skeleton = skeletons[child.ID];
1179
+ return skeleton;
1180
+ }, null);
1181
+ relationships.children.forEach(function (child) {
1182
+ if (deformers.morphTargets[child.ID] !== undefined) {
1183
+ morphTargets.push(deformers.morphTargets[child.ID]);
1184
+ }
1185
+ }); // Assume one model and get the preRotation from that
1186
+ // if there is more than one model associated with the geometry this may cause problems
1187
+
1188
+ var modelNode = modelNodes[0];
1189
+ var transformData = {};
1190
+ if ('RotationOrder' in modelNode) transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value);
1191
+ if ('InheritType' in modelNode) transformData.inheritType = parseInt(modelNode.InheritType.value);
1192
+ if ('GeometricTranslation' in modelNode) transformData.translation = modelNode.GeometricTranslation.value;
1193
+ if ('GeometricRotation' in modelNode) transformData.rotation = modelNode.GeometricRotation.value;
1194
+ if ('GeometricScaling' in modelNode) transformData.scale = modelNode.GeometricScaling.value;
1195
+ var transform = generateTransform(transformData);
1196
+ return this.genGeometry(geoNode, skeleton, morphTargets, transform);
1197
+ } // Generate a BufferGeometry from a node in FBXTree.Objects.Geometry
1198
+
1199
+ }, {
1200
+ key: "genGeometry",
1201
+ value: function genGeometry(geoNode, skeleton, morphTargets, preTransform) {
1202
+ var geo = new _three.BufferGeometry();
1203
+ if (geoNode.attrName) geo.name = geoNode.attrName;
1204
+ var geoInfo = this.parseGeoNode(geoNode, skeleton);
1205
+ var buffers = this.genBuffers(geoInfo);
1206
+ var positionAttribute = new _three.Float32BufferAttribute(buffers.vertex, 3);
1207
+ positionAttribute.applyMatrix4(preTransform);
1208
+ geo.setAttribute('position', positionAttribute);
1209
+
1210
+ if (buffers.colors.length > 0) {
1211
+ geo.setAttribute('color', new _three.Float32BufferAttribute(buffers.colors, 3));
1212
+ }
1213
+
1214
+ if (skeleton) {
1215
+ geo.setAttribute('skinIndex', new _three.Uint16BufferAttribute(buffers.weightsIndices, 4));
1216
+ geo.setAttribute('skinWeight', new _three.Float32BufferAttribute(buffers.vertexWeights, 4)); // used later to bind the skeleton to the model
1217
+
1218
+ geo.FBX_Deformer = skeleton;
1219
+ }
1220
+
1221
+ if (buffers.normal.length > 0) {
1222
+ var normalMatrix = new _three.Matrix3().getNormalMatrix(preTransform);
1223
+ var normalAttribute = new _three.Float32BufferAttribute(buffers.normal, 3);
1224
+ normalAttribute.applyNormalMatrix(normalMatrix);
1225
+ geo.setAttribute('normal', normalAttribute);
1226
+ }
1227
+
1228
+ buffers.uvs.forEach(function (uvBuffer, i) {
1229
+ // subsequent uv buffers are called 'uv1', 'uv2', ...
1230
+ var name = 'uv' + (i + 1).toString(); // the first uv buffer is just called 'uv'
1231
+
1232
+ if (i === 0) {
1233
+ name = 'uv';
1234
+ }
1235
+
1236
+ geo.setAttribute(name, new _three.Float32BufferAttribute(buffers.uvs[i], 2));
1237
+ });
1238
+
1239
+ if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
1240
+ // Convert the material indices of each vertex into rendering groups on the geometry.
1241
+ var prevMaterialIndex = buffers.materialIndex[0];
1242
+ var startIndex = 0;
1243
+ buffers.materialIndex.forEach(function (currentIndex, i) {
1244
+ if (currentIndex !== prevMaterialIndex) {
1245
+ geo.addGroup(startIndex, i - startIndex, prevMaterialIndex);
1246
+ prevMaterialIndex = currentIndex;
1247
+ startIndex = i;
1248
+ }
1249
+ }); // the loop above doesn't add the last group, do that here.
1250
+
1251
+ if (geo.groups.length > 0) {
1252
+ var lastGroup = geo.groups[geo.groups.length - 1];
1253
+ var lastIndex = lastGroup.start + lastGroup.count;
1254
+
1255
+ if (lastIndex !== buffers.materialIndex.length) {
1256
+ geo.addGroup(lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex);
1257
+ }
1258
+ } // case where there are multiple materials but the whole geometry is only
1259
+ // using one of them
1260
+
1261
+
1262
+ if (geo.groups.length === 0) {
1263
+ geo.addGroup(0, buffers.materialIndex.length, buffers.materialIndex[0]);
1264
+ }
1265
+ }
1266
+
1267
+ this.addMorphTargets(geo, geoNode, morphTargets, preTransform);
1268
+ return geo;
1269
+ }
1270
+ }, {
1271
+ key: "parseGeoNode",
1272
+ value: function parseGeoNode(geoNode, skeleton) {
1273
+ var geoInfo = {};
1274
+ geoInfo.vertexPositions = geoNode.Vertices !== undefined ? geoNode.Vertices.a : [];
1275
+ geoInfo.vertexIndices = geoNode.PolygonVertexIndex !== undefined ? geoNode.PolygonVertexIndex.a : [];
1276
+
1277
+ if (geoNode.LayerElementColor) {
1278
+ geoInfo.color = this.parseVertexColors(geoNode.LayerElementColor[0]);
1279
+ }
1280
+
1281
+ if (geoNode.LayerElementMaterial) {
1282
+ geoInfo.material = this.parseMaterialIndices(geoNode.LayerElementMaterial[0]);
1283
+ }
1284
+
1285
+ if (geoNode.LayerElementNormal) {
1286
+ geoInfo.normal = this.parseNormals(geoNode.LayerElementNormal[0]);
1287
+ }
1288
+
1289
+ if (geoNode.LayerElementUV) {
1290
+ geoInfo.uv = [];
1291
+ var i = 0;
1292
+
1293
+ while (geoNode.LayerElementUV[i]) {
1294
+ if (geoNode.LayerElementUV[i].UV) {
1295
+ geoInfo.uv.push(this.parseUVs(geoNode.LayerElementUV[i]));
1296
+ }
1297
+
1298
+ i++;
1299
+ }
1300
+ }
1301
+
1302
+ geoInfo.weightTable = {};
1303
+
1304
+ if (skeleton !== null) {
1305
+ geoInfo.skeleton = skeleton;
1306
+ skeleton.rawBones.forEach(function (rawBone, i) {
1307
+ // loop over the bone's vertex indices and weights
1308
+ rawBone.indices.forEach(function (index, j) {
1309
+ if (geoInfo.weightTable[index] === undefined) geoInfo.weightTable[index] = [];
1310
+ geoInfo.weightTable[index].push({
1311
+ id: i,
1312
+ weight: rawBone.weights[j]
1313
+ });
1314
+ });
1315
+ });
1316
+ }
1317
+
1318
+ return geoInfo;
1319
+ }
1320
+ }, {
1321
+ key: "genBuffers",
1322
+ value: function genBuffers(geoInfo) {
1323
+ var buffers = {
1324
+ vertex: [],
1325
+ normal: [],
1326
+ colors: [],
1327
+ uvs: [],
1328
+ materialIndex: [],
1329
+ vertexWeights: [],
1330
+ weightsIndices: []
1331
+ };
1332
+ var polygonIndex = 0;
1333
+ var faceLength = 0;
1334
+ var displayedWeightsWarning = false; // these will hold data for a single face
1335
+
1336
+ var facePositionIndexes = [];
1337
+ var faceNormals = [];
1338
+ var faceColors = [];
1339
+ var faceUVs = [];
1340
+ var faceWeights = [];
1341
+ var faceWeightIndices = [];
1342
+ var scope = this;
1343
+ geoInfo.vertexIndices.forEach(function (vertexIndex, polygonVertexIndex) {
1344
+ var materialIndex;
1345
+ var endOfFace = false; // Face index and vertex index arrays are combined in a single array
1346
+ // A cube with quad faces looks like this:
1347
+ // PolygonVertexIndex: *24 {
1348
+ // a: 0, 1, 3, -3, 2, 3, 5, -5, 4, 5, 7, -7, 6, 7, 1, -1, 1, 7, 5, -4, 6, 0, 2, -5
1349
+ // }
1350
+ // Negative numbers mark the end of a face - first face here is 0, 1, 3, -3
1351
+ // to find index of last vertex bit shift the index: ^ - 1
1352
+
1353
+ if (vertexIndex < 0) {
1354
+ vertexIndex = vertexIndex ^ -1; // equivalent to ( x * -1 ) - 1
1355
+
1356
+ endOfFace = true;
1357
+ }
1358
+
1359
+ var weightIndices = [];
1360
+ var weights = [];
1361
+ facePositionIndexes.push(vertexIndex * 3, vertexIndex * 3 + 1, vertexIndex * 3 + 2);
1362
+
1363
+ if (geoInfo.color) {
1364
+ var data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.color);
1365
+ faceColors.push(data[0], data[1], data[2]);
1366
+ }
1367
+
1368
+ if (geoInfo.skeleton) {
1369
+ if (geoInfo.weightTable[vertexIndex] !== undefined) {
1370
+ geoInfo.weightTable[vertexIndex].forEach(function (wt) {
1371
+ weights.push(wt.weight);
1372
+ weightIndices.push(wt.id);
1373
+ });
1374
+ }
1375
+
1376
+ if (weights.length > 4) {
1377
+ if (!displayedWeightsWarning) {
1378
+ console.warn('THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights.');
1379
+ displayedWeightsWarning = true;
1380
+ }
1381
+
1382
+ var wIndex = [0, 0, 0, 0];
1383
+ var Weight = [0, 0, 0, 0];
1384
+ weights.forEach(function (weight, weightIndex) {
1385
+ var currentWeight = weight;
1386
+ var currentIndex = weightIndices[weightIndex];
1387
+ Weight.forEach(function (comparedWeight, comparedWeightIndex, comparedWeightArray) {
1388
+ if (currentWeight > comparedWeight) {
1389
+ comparedWeightArray[comparedWeightIndex] = currentWeight;
1390
+ currentWeight = comparedWeight;
1391
+ var tmp = wIndex[comparedWeightIndex];
1392
+ wIndex[comparedWeightIndex] = currentIndex;
1393
+ currentIndex = tmp;
1394
+ }
1395
+ });
1396
+ });
1397
+ weightIndices = wIndex;
1398
+ weights = Weight;
1399
+ } // if the weight array is shorter than 4 pad with 0s
1400
+
1401
+
1402
+ while (weights.length < 4) {
1403
+ weights.push(0);
1404
+ weightIndices.push(0);
1405
+ }
1406
+
1407
+ for (var i = 0; i < 4; ++i) {
1408
+ faceWeights.push(weights[i]);
1409
+ faceWeightIndices.push(weightIndices[i]);
1410
+ }
1411
+ }
1412
+
1413
+ if (geoInfo.normal) {
1414
+ var _data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.normal);
1415
+
1416
+ faceNormals.push(_data[0], _data[1], _data[2]);
1417
+ }
1418
+
1419
+ if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
1420
+ materialIndex = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.material)[0];
1421
+ }
1422
+
1423
+ if (geoInfo.uv) {
1424
+ geoInfo.uv.forEach(function (uv, i) {
1425
+ var data = getData(polygonVertexIndex, polygonIndex, vertexIndex, uv);
1426
+
1427
+ if (faceUVs[i] === undefined) {
1428
+ faceUVs[i] = [];
1429
+ }
1430
+
1431
+ faceUVs[i].push(data[0]);
1432
+ faceUVs[i].push(data[1]);
1433
+ });
1434
+ }
1435
+
1436
+ faceLength++;
1437
+
1438
+ if (endOfFace) {
1439
+ scope.genFace(buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength);
1440
+ polygonIndex++;
1441
+ faceLength = 0; // reset arrays for the next face
1442
+
1443
+ facePositionIndexes = [];
1444
+ faceNormals = [];
1445
+ faceColors = [];
1446
+ faceUVs = [];
1447
+ faceWeights = [];
1448
+ faceWeightIndices = [];
1449
+ }
1450
+ });
1451
+ return buffers;
1452
+ } // Generate data for a single face in a geometry. If the face is a quad then split it into 2 tris
1453
+
1454
+ }, {
1455
+ key: "genFace",
1456
+ value: function genFace(buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength) {
1457
+ var _loop3 = function _loop3(i) {
1458
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[0]]);
1459
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[1]]);
1460
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[2]]);
1461
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3]]);
1462
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 1]]);
1463
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 2]]);
1464
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3]]);
1465
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 1]]);
1466
+ buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 2]]);
1467
+
1468
+ if (geoInfo.skeleton) {
1469
+ buffers.vertexWeights.push(faceWeights[0]);
1470
+ buffers.vertexWeights.push(faceWeights[1]);
1471
+ buffers.vertexWeights.push(faceWeights[2]);
1472
+ buffers.vertexWeights.push(faceWeights[3]);
1473
+ buffers.vertexWeights.push(faceWeights[(i - 1) * 4]);
1474
+ buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 1]);
1475
+ buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 2]);
1476
+ buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 3]);
1477
+ buffers.vertexWeights.push(faceWeights[i * 4]);
1478
+ buffers.vertexWeights.push(faceWeights[i * 4 + 1]);
1479
+ buffers.vertexWeights.push(faceWeights[i * 4 + 2]);
1480
+ buffers.vertexWeights.push(faceWeights[i * 4 + 3]);
1481
+ buffers.weightsIndices.push(faceWeightIndices[0]);
1482
+ buffers.weightsIndices.push(faceWeightIndices[1]);
1483
+ buffers.weightsIndices.push(faceWeightIndices[2]);
1484
+ buffers.weightsIndices.push(faceWeightIndices[3]);
1485
+ buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4]);
1486
+ buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 1]);
1487
+ buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 2]);
1488
+ buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 3]);
1489
+ buffers.weightsIndices.push(faceWeightIndices[i * 4]);
1490
+ buffers.weightsIndices.push(faceWeightIndices[i * 4 + 1]);
1491
+ buffers.weightsIndices.push(faceWeightIndices[i * 4 + 2]);
1492
+ buffers.weightsIndices.push(faceWeightIndices[i * 4 + 3]);
1493
+ }
1494
+
1495
+ if (geoInfo.color) {
1496
+ buffers.colors.push(faceColors[0]);
1497
+ buffers.colors.push(faceColors[1]);
1498
+ buffers.colors.push(faceColors[2]);
1499
+ buffers.colors.push(faceColors[(i - 1) * 3]);
1500
+ buffers.colors.push(faceColors[(i - 1) * 3 + 1]);
1501
+ buffers.colors.push(faceColors[(i - 1) * 3 + 2]);
1502
+ buffers.colors.push(faceColors[i * 3]);
1503
+ buffers.colors.push(faceColors[i * 3 + 1]);
1504
+ buffers.colors.push(faceColors[i * 3 + 2]);
1505
+ }
1506
+
1507
+ if (geoInfo.material && geoInfo.material.mappingType !== 'AllSame') {
1508
+ buffers.materialIndex.push(materialIndex);
1509
+ buffers.materialIndex.push(materialIndex);
1510
+ buffers.materialIndex.push(materialIndex);
1511
+ }
1512
+
1513
+ if (geoInfo.normal) {
1514
+ buffers.normal.push(faceNormals[0]);
1515
+ buffers.normal.push(faceNormals[1]);
1516
+ buffers.normal.push(faceNormals[2]);
1517
+ buffers.normal.push(faceNormals[(i - 1) * 3]);
1518
+ buffers.normal.push(faceNormals[(i - 1) * 3 + 1]);
1519
+ buffers.normal.push(faceNormals[(i - 1) * 3 + 2]);
1520
+ buffers.normal.push(faceNormals[i * 3]);
1521
+ buffers.normal.push(faceNormals[i * 3 + 1]);
1522
+ buffers.normal.push(faceNormals[i * 3 + 2]);
1523
+ }
1524
+
1525
+ if (geoInfo.uv) {
1526
+ geoInfo.uv.forEach(function (uv, j) {
1527
+ if (buffers.uvs[j] === undefined) buffers.uvs[j] = [];
1528
+ buffers.uvs[j].push(faceUVs[j][0]);
1529
+ buffers.uvs[j].push(faceUVs[j][1]);
1530
+ buffers.uvs[j].push(faceUVs[j][(i - 1) * 2]);
1531
+ buffers.uvs[j].push(faceUVs[j][(i - 1) * 2 + 1]);
1532
+ buffers.uvs[j].push(faceUVs[j][i * 2]);
1533
+ buffers.uvs[j].push(faceUVs[j][i * 2 + 1]);
1534
+ });
1535
+ }
1536
+ };
1537
+
1538
+ for (var i = 2; i < faceLength; i++) {
1539
+ _loop3(i);
1540
+ }
1541
+ }
1542
+ }, {
1543
+ key: "addMorphTargets",
1544
+ value: function addMorphTargets(parentGeo, parentGeoNode, morphTargets, preTransform) {
1545
+ if (morphTargets.length === 0) return;
1546
+ parentGeo.morphTargetsRelative = true;
1547
+ parentGeo.morphAttributes.position = []; // parentGeo.morphAttributes.normal = []; // not implemented
1548
+
1549
+ var scope = this;
1550
+ morphTargets.forEach(function (morphTarget) {
1551
+ morphTarget.rawTargets.forEach(function (rawTarget) {
1552
+ var morphGeoNode = fbxTree.Objects.Geometry[rawTarget.geoID];
1553
+
1554
+ if (morphGeoNode !== undefined) {
1555
+ scope.genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, rawTarget.name);
1556
+ }
1557
+ });
1558
+ });
1559
+ } // a morph geometry node is similar to a standard node, and the node is also contained
1560
+ // in FBXTree.Objects.Geometry, however it can only have attributes for position, normal
1561
+ // and a special attribute Index defining which vertices of the original geometry are affected
1562
+ // Normal and position attributes only have data for the vertices that are affected by the morph
1563
+
1564
+ }, {
1565
+ key: "genMorphGeometry",
1566
+ value: function genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, name) {
1567
+ var vertexIndices = parentGeoNode.PolygonVertexIndex !== undefined ? parentGeoNode.PolygonVertexIndex.a : [];
1568
+ var morphPositionsSparse = morphGeoNode.Vertices !== undefined ? morphGeoNode.Vertices.a : [];
1569
+ var indices = morphGeoNode.Indexes !== undefined ? morphGeoNode.Indexes.a : [];
1570
+ var length = parentGeo.attributes.position.count * 3;
1571
+ var morphPositions = new Float32Array(length);
1572
+
1573
+ for (var i = 0; i < indices.length; i++) {
1574
+ var morphIndex = indices[i] * 3;
1575
+ morphPositions[morphIndex] = morphPositionsSparse[i * 3];
1576
+ morphPositions[morphIndex + 1] = morphPositionsSparse[i * 3 + 1];
1577
+ morphPositions[morphIndex + 2] = morphPositionsSparse[i * 3 + 2];
1578
+ } // TODO: add morph normal support
1579
+
1580
+
1581
+ var morphGeoInfo = {
1582
+ vertexIndices: vertexIndices,
1583
+ vertexPositions: morphPositions
1584
+ };
1585
+ var morphBuffers = this.genBuffers(morphGeoInfo);
1586
+ var positionAttribute = new _three.Float32BufferAttribute(morphBuffers.vertex, 3);
1587
+ positionAttribute.name = name || morphGeoNode.attrName;
1588
+ positionAttribute.applyMatrix4(preTransform);
1589
+ parentGeo.morphAttributes.position.push(positionAttribute);
1590
+ } // Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists
1591
+
1592
+ }, {
1593
+ key: "parseNormals",
1594
+ value: function parseNormals(NormalNode) {
1595
+ var mappingType = NormalNode.MappingInformationType;
1596
+ var referenceType = NormalNode.ReferenceInformationType;
1597
+ var buffer = NormalNode.Normals.a;
1598
+ var indexBuffer = [];
1599
+
1600
+ if (referenceType === 'IndexToDirect') {
1601
+ if ('NormalIndex' in NormalNode) {
1602
+ indexBuffer = NormalNode.NormalIndex.a;
1603
+ } else if ('NormalsIndex' in NormalNode) {
1604
+ indexBuffer = NormalNode.NormalsIndex.a;
1605
+ }
1606
+ }
1607
+
1608
+ return {
1609
+ dataSize: 3,
1610
+ buffer: buffer,
1611
+ indices: indexBuffer,
1612
+ mappingType: mappingType,
1613
+ referenceType: referenceType
1614
+ };
1615
+ } // Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists
1616
+
1617
+ }, {
1618
+ key: "parseUVs",
1619
+ value: function parseUVs(UVNode) {
1620
+ var mappingType = UVNode.MappingInformationType;
1621
+ var referenceType = UVNode.ReferenceInformationType;
1622
+ var buffer = UVNode.UV.a;
1623
+ var indexBuffer = [];
1624
+
1625
+ if (referenceType === 'IndexToDirect') {
1626
+ indexBuffer = UVNode.UVIndex.a;
1627
+ }
1628
+
1629
+ return {
1630
+ dataSize: 2,
1631
+ buffer: buffer,
1632
+ indices: indexBuffer,
1633
+ mappingType: mappingType,
1634
+ referenceType: referenceType
1635
+ };
1636
+ } // Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
1637
+
1638
+ }, {
1639
+ key: "parseVertexColors",
1640
+ value: function parseVertexColors(ColorNode) {
1641
+ var mappingType = ColorNode.MappingInformationType;
1642
+ var referenceType = ColorNode.ReferenceInformationType;
1643
+ var buffer = ColorNode.Colors.a;
1644
+ var indexBuffer = [];
1645
+
1646
+ if (referenceType === 'IndexToDirect') {
1647
+ indexBuffer = ColorNode.ColorIndex.a;
1648
+ }
1649
+
1650
+ return {
1651
+ dataSize: 4,
1652
+ buffer: buffer,
1653
+ indices: indexBuffer,
1654
+ mappingType: mappingType,
1655
+ referenceType: referenceType
1656
+ };
1657
+ } // Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists
1658
+
1659
+ }, {
1660
+ key: "parseMaterialIndices",
1661
+ value: function parseMaterialIndices(MaterialNode) {
1662
+ var mappingType = MaterialNode.MappingInformationType;
1663
+ var referenceType = MaterialNode.ReferenceInformationType;
1664
+
1665
+ if (mappingType === 'NoMappingInformation') {
1666
+ return {
1667
+ dataSize: 1,
1668
+ buffer: [0],
1669
+ indices: [0],
1670
+ mappingType: 'AllSame',
1671
+ referenceType: referenceType
1672
+ };
1673
+ }
1674
+
1675
+ var materialIndexBuffer = MaterialNode.Materials.a; // Since materials are stored as indices, there's a bit of a mismatch between FBX and what
1676
+ // we expect.So we create an intermediate buffer that points to the index in the buffer,
1677
+ // for conforming with the other functions we've written for other data.
1678
+
1679
+ var materialIndices = [];
1680
+
1681
+ for (var i = 0; i < materialIndexBuffer.length; ++i) {
1682
+ materialIndices.push(i);
1683
+ }
1684
+
1685
+ return {
1686
+ dataSize: 1,
1687
+ buffer: materialIndexBuffer,
1688
+ indices: materialIndices,
1689
+ mappingType: mappingType,
1690
+ referenceType: referenceType
1691
+ };
1692
+ } // Generate a NurbGeometry from a node in FBXTree.Objects.Geometry
1693
+
1694
+ }, {
1695
+ key: "parseNurbsGeometry",
1696
+ value: function parseNurbsGeometry(geoNode) {
1697
+ if (_NURBSCurve.NURBSCurve === undefined) {
1698
+ console.error('THREE.FBXLoader: The loader relies on NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry.');
1699
+ return new _three.BufferGeometry();
1700
+ }
1701
+
1702
+ var order = parseInt(geoNode.Order);
1703
+
1704
+ if (isNaN(order)) {
1705
+ console.error('THREE.FBXLoader: Invalid Order %s given for geometry ID: %s', geoNode.Order, geoNode.id);
1706
+ return new _three.BufferGeometry();
1707
+ }
1708
+
1709
+ var degree = order - 1;
1710
+ var knots = geoNode.KnotVector.a;
1711
+ var controlPoints = [];
1712
+ var pointsValues = geoNode.Points.a;
1713
+
1714
+ for (var i = 0, l = pointsValues.length; i < l; i += 4) {
1715
+ controlPoints.push(new _three.Vector4().fromArray(pointsValues, i));
1716
+ }
1717
+
1718
+ var startKnot, endKnot;
1719
+
1720
+ if (geoNode.Form === 'Closed') {
1721
+ controlPoints.push(controlPoints[0]);
1722
+ } else if (geoNode.Form === 'Periodic') {
1723
+ startKnot = degree;
1724
+ endKnot = knots.length - 1 - startKnot;
1725
+
1726
+ for (var _i = 0; _i < degree; ++_i) {
1727
+ controlPoints.push(controlPoints[_i]);
1728
+ }
1729
+ }
1730
+
1731
+ var curve = new _NURBSCurve.NURBSCurve(degree, knots, controlPoints, startKnot, endKnot);
1732
+ var points = curve.getPoints(controlPoints.length * 12);
1733
+ return new _three.BufferGeometry().setFromPoints(points);
1734
+ }
1735
+ }]);
1736
+
1737
+ return GeometryParser;
1738
+ }(); // parse animation data from FBXTree
1739
+
1740
+
1741
+ var AnimationParser = /*#__PURE__*/function () {
1742
+ function AnimationParser() {
1743
+ _classCallCheck(this, AnimationParser);
1744
+ }
1745
+
1746
+ _createClass(AnimationParser, [{
1747
+ key: "parse",
1748
+ value: // take raw animation clips and turn them into three.js animation clips
1749
+ function parse() {
1750
+ var animationClips = [];
1751
+ var rawClips = this.parseClips();
1752
+
1753
+ if (rawClips !== undefined) {
1754
+ for (var key in rawClips) {
1755
+ var rawClip = rawClips[key];
1756
+ var clip = this.addClip(rawClip);
1757
+ animationClips.push(clip);
1758
+ }
1759
+ }
1760
+
1761
+ return animationClips;
1762
+ }
1763
+ }, {
1764
+ key: "parseClips",
1765
+ value: function parseClips() {
1766
+ // since the actual transformation data is stored in FBXTree.Objects.AnimationCurve,
1767
+ // if this is undefined we can safely assume there are no animations
1768
+ if (fbxTree.Objects.AnimationCurve === undefined) return undefined;
1769
+ var curveNodesMap = this.parseAnimationCurveNodes();
1770
+ this.parseAnimationCurves(curveNodesMap);
1771
+ var layersMap = this.parseAnimationLayers(curveNodesMap);
1772
+ var rawClips = this.parseAnimStacks(layersMap);
1773
+ return rawClips;
1774
+ } // parse nodes in FBXTree.Objects.AnimationCurveNode
1775
+ // each AnimationCurveNode holds data for an animation transform for a model (e.g. left arm rotation )
1776
+ // and is referenced by an AnimationLayer
1777
+
1778
+ }, {
1779
+ key: "parseAnimationCurveNodes",
1780
+ value: function parseAnimationCurveNodes() {
1781
+ var rawCurveNodes = fbxTree.Objects.AnimationCurveNode;
1782
+ var curveNodesMap = new Map();
1783
+
1784
+ for (var nodeID in rawCurveNodes) {
1785
+ var rawCurveNode = rawCurveNodes[nodeID];
1786
+
1787
+ if (rawCurveNode.attrName.match(/S|R|T|DeformPercent/) !== null) {
1788
+ var curveNode = {
1789
+ id: rawCurveNode.id,
1790
+ attr: rawCurveNode.attrName,
1791
+ curves: {}
1792
+ };
1793
+ curveNodesMap.set(curveNode.id, curveNode);
1794
+ }
1795
+ }
1796
+
1797
+ return curveNodesMap;
1798
+ } // parse nodes in FBXTree.Objects.AnimationCurve and connect them up to
1799
+ // previously parsed AnimationCurveNodes. Each AnimationCurve holds data for a single animated
1800
+ // axis ( e.g. times and values of x rotation)
1801
+
1802
+ }, {
1803
+ key: "parseAnimationCurves",
1804
+ value: function parseAnimationCurves(curveNodesMap) {
1805
+ var rawCurves = fbxTree.Objects.AnimationCurve; // TODO: Many values are identical up to roundoff error, but won't be optimised
1806
+ // e.g. position times: [0, 0.4, 0. 8]
1807
+ // position values: [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.235384487103147e-7, 93.67520904541016, -0.9982695579528809]
1808
+ // clearly, this should be optimised to
1809
+ // times: [0], positions [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809]
1810
+ // this shows up in nearly every FBX file, and generally time array is length > 100
1811
+
1812
+ for (var nodeID in rawCurves) {
1813
+ var animationCurve = {
1814
+ id: rawCurves[nodeID].id,
1815
+ times: rawCurves[nodeID].KeyTime.a.map(convertFBXTimeToSeconds),
1816
+ values: rawCurves[nodeID].KeyValueFloat.a
1817
+ };
1818
+ var relationships = connections.get(animationCurve.id);
1819
+
1820
+ if (relationships !== undefined) {
1821
+ var animationCurveID = relationships.parents[0].ID;
1822
+ var animationCurveRelationship = relationships.parents[0].relationship;
1823
+
1824
+ if (animationCurveRelationship.match(/X/)) {
1825
+ curveNodesMap.get(animationCurveID).curves['x'] = animationCurve;
1826
+ } else if (animationCurveRelationship.match(/Y/)) {
1827
+ curveNodesMap.get(animationCurveID).curves['y'] = animationCurve;
1828
+ } else if (animationCurveRelationship.match(/Z/)) {
1829
+ curveNodesMap.get(animationCurveID).curves['z'] = animationCurve;
1830
+ } else if (animationCurveRelationship.match(/d|DeformPercent/) && curveNodesMap.has(animationCurveID)) {
1831
+ curveNodesMap.get(animationCurveID).curves['morph'] = animationCurve;
1832
+ }
1833
+ }
1834
+ }
1835
+ } // parse nodes in FBXTree.Objects.AnimationLayer. Each layers holds references
1836
+ // to various AnimationCurveNodes and is referenced by an AnimationStack node
1837
+ // note: theoretically a stack can have multiple layers, however in practice there always seems to be one per stack
1838
+
1839
+ }, {
1840
+ key: "parseAnimationLayers",
1841
+ value: function parseAnimationLayers(curveNodesMap) {
1842
+ var rawLayers = fbxTree.Objects.AnimationLayer;
1843
+ var layersMap = new Map();
1844
+
1845
+ var _loop4 = function _loop4(nodeID) {
1846
+ var layerCurveNodes = [];
1847
+ var connection = connections.get(parseInt(nodeID));
1848
+
1849
+ if (connection !== undefined) {
1850
+ // all the animationCurveNodes used in the layer
1851
+ var children = connection.children;
1852
+ children.forEach(function (child, i) {
1853
+ if (curveNodesMap.has(child.ID)) {
1854
+ var curveNode = curveNodesMap.get(child.ID); // check that the curves are defined for at least one axis, otherwise ignore the curveNode
1855
+
1856
+ if (curveNode.curves.x !== undefined || curveNode.curves.y !== undefined || curveNode.curves.z !== undefined) {
1857
+ if (layerCurveNodes[i] === undefined) {
1858
+ var modelID = connections.get(child.ID).parents.filter(function (parent) {
1859
+ return parent.relationship !== undefined;
1860
+ })[0].ID;
1861
+
1862
+ if (modelID !== undefined) {
1863
+ var rawModel = fbxTree.Objects.Model[modelID.toString()];
1864
+
1865
+ if (rawModel === undefined) {
1866
+ console.warn('THREE.FBXLoader: Encountered a unused curve.', child);
1867
+ return;
1868
+ }
1869
+
1870
+ var node = {
1871
+ modelName: rawModel.attrName ? _three.PropertyBinding.sanitizeNodeName(rawModel.attrName) : '',
1872
+ ID: rawModel.id,
1873
+ initialPosition: [0, 0, 0],
1874
+ initialRotation: [0, 0, 0],
1875
+ initialScale: [1, 1, 1]
1876
+ };
1877
+ sceneGraph.traverse(function (child) {
1878
+ if (child.ID === rawModel.id) {
1879
+ node.transform = child.matrix;
1880
+ if (child.userData.transformData) node.eulerOrder = child.userData.transformData.eulerOrder;
1881
+ }
1882
+ });
1883
+ if (!node.transform) node.transform = new _three.Matrix4(); // if the animated model is pre rotated, we'll have to apply the pre rotations to every
1884
+ // animation value as well
1885
+
1886
+ if ('PreRotation' in rawModel) node.preRotation = rawModel.PreRotation.value;
1887
+ if ('PostRotation' in rawModel) node.postRotation = rawModel.PostRotation.value;
1888
+ layerCurveNodes[i] = node;
1889
+ }
1890
+ }
1891
+
1892
+ if (layerCurveNodes[i]) layerCurveNodes[i][curveNode.attr] = curveNode;
1893
+ } else if (curveNode.curves.morph !== undefined) {
1894
+ if (layerCurveNodes[i] === undefined) {
1895
+ var deformerID = connections.get(child.ID).parents.filter(function (parent) {
1896
+ return parent.relationship !== undefined;
1897
+ })[0].ID;
1898
+ var morpherID = connections.get(deformerID).parents[0].ID;
1899
+ var geoID = connections.get(morpherID).parents[0].ID; // assuming geometry is not used in more than one model
1900
+
1901
+ var _modelID = connections.get(geoID).parents[0].ID;
1902
+ var _rawModel = fbxTree.Objects.Model[_modelID];
1903
+ var _node = {
1904
+ modelName: _rawModel.attrName ? _three.PropertyBinding.sanitizeNodeName(_rawModel.attrName) : '',
1905
+ morphName: fbxTree.Objects.Deformer[deformerID].attrName
1906
+ };
1907
+ layerCurveNodes[i] = _node;
1908
+ }
1909
+
1910
+ layerCurveNodes[i][curveNode.attr] = curveNode;
1911
+ }
1912
+ }
1913
+ });
1914
+ layersMap.set(parseInt(nodeID), layerCurveNodes);
1915
+ }
1916
+ };
1917
+
1918
+ for (var nodeID in rawLayers) {
1919
+ _loop4(nodeID);
1920
+ }
1921
+
1922
+ return layersMap;
1923
+ } // parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation
1924
+ // hierarchy. Each Stack node will be used to create a AnimationClip
1925
+
1926
+ }, {
1927
+ key: "parseAnimStacks",
1928
+ value: function parseAnimStacks(layersMap) {
1929
+ var rawStacks = fbxTree.Objects.AnimationStack; // connect the stacks (clips) up to the layers
1930
+
1931
+ var rawClips = {};
1932
+
1933
+ for (var nodeID in rawStacks) {
1934
+ var children = connections.get(parseInt(nodeID)).children;
1935
+
1936
+ if (children.length > 1) {
1937
+ // it seems like stacks will always be associated with a single layer. But just in case there are files
1938
+ // where there are multiple layers per stack, we'll display a warning
1939
+ console.warn('THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.');
1940
+ }
1941
+
1942
+ var layer = layersMap.get(children[0].ID);
1943
+ rawClips[nodeID] = {
1944
+ name: rawStacks[nodeID].attrName,
1945
+ layer: layer
1946
+ };
1947
+ }
1948
+
1949
+ return rawClips;
1950
+ }
1951
+ }, {
1952
+ key: "addClip",
1953
+ value: function addClip(rawClip) {
1954
+ var tracks = [];
1955
+ var scope = this;
1956
+ rawClip.layer.forEach(function (rawTracks) {
1957
+ tracks = tracks.concat(scope.generateTracks(rawTracks));
1958
+ });
1959
+ return new _three.AnimationClip(rawClip.name, -1, tracks);
1960
+ }
1961
+ }, {
1962
+ key: "generateTracks",
1963
+ value: function generateTracks(rawTracks) {
1964
+ var tracks = [];
1965
+ var initialPosition = new _three.Vector3();
1966
+ var initialRotation = new _three.Quaternion();
1967
+ var initialScale = new _three.Vector3();
1968
+ if (rawTracks.transform) rawTracks.transform.decompose(initialPosition, initialRotation, initialScale);
1969
+ initialPosition = initialPosition.toArray();
1970
+ initialRotation = new _three.Euler().setFromQuaternion(initialRotation, rawTracks.eulerOrder).toArray();
1971
+ initialScale = initialScale.toArray();
1972
+
1973
+ if (rawTracks.T !== undefined && Object.keys(rawTracks.T.curves).length > 0) {
1974
+ var positionTrack = this.generateVectorTrack(rawTracks.modelName, rawTracks.T.curves, initialPosition, 'position');
1975
+ if (positionTrack !== undefined) tracks.push(positionTrack);
1976
+ }
1977
+
1978
+ if (rawTracks.R !== undefined && Object.keys(rawTracks.R.curves).length > 0) {
1979
+ var rotationTrack = this.generateRotationTrack(rawTracks.modelName, rawTracks.R.curves, initialRotation, rawTracks.preRotation, rawTracks.postRotation, rawTracks.eulerOrder);
1980
+ if (rotationTrack !== undefined) tracks.push(rotationTrack);
1981
+ }
1982
+
1983
+ if (rawTracks.S !== undefined && Object.keys(rawTracks.S.curves).length > 0) {
1984
+ var scaleTrack = this.generateVectorTrack(rawTracks.modelName, rawTracks.S.curves, initialScale, 'scale');
1985
+ if (scaleTrack !== undefined) tracks.push(scaleTrack);
1986
+ }
1987
+
1988
+ if (rawTracks.DeformPercent !== undefined) {
1989
+ var morphTrack = this.generateMorphTrack(rawTracks);
1990
+ if (morphTrack !== undefined) tracks.push(morphTrack);
1991
+ }
1992
+
1993
+ return tracks;
1994
+ }
1995
+ }, {
1996
+ key: "generateVectorTrack",
1997
+ value: function generateVectorTrack(modelName, curves, initialValue, type) {
1998
+ var times = this.getTimesForAllAxes(curves);
1999
+ var values = this.getKeyframeTrackValues(times, curves, initialValue);
2000
+ return new _three.VectorKeyframeTrack(modelName + '.' + type, times, values);
2001
+ }
2002
+ }, {
2003
+ key: "generateRotationTrack",
2004
+ value: function generateRotationTrack(modelName, curves, initialValue, preRotation, postRotation, eulerOrder) {
2005
+ if (curves.x !== undefined) {
2006
+ this.interpolateRotations(curves.x);
2007
+ curves.x.values = curves.x.values.map(_three.MathUtils.degToRad);
2008
+ }
2009
+
2010
+ if (curves.y !== undefined) {
2011
+ this.interpolateRotations(curves.y);
2012
+ curves.y.values = curves.y.values.map(_three.MathUtils.degToRad);
2013
+ }
2014
+
2015
+ if (curves.z !== undefined) {
2016
+ this.interpolateRotations(curves.z);
2017
+ curves.z.values = curves.z.values.map(_three.MathUtils.degToRad);
2018
+ }
2019
+
2020
+ var times = this.getTimesForAllAxes(curves);
2021
+ var values = this.getKeyframeTrackValues(times, curves, initialValue);
2022
+
2023
+ if (preRotation !== undefined) {
2024
+ preRotation = preRotation.map(_three.MathUtils.degToRad);
2025
+ preRotation.push(eulerOrder);
2026
+ preRotation = new _three.Euler().fromArray(preRotation);
2027
+ preRotation = new _three.Quaternion().setFromEuler(preRotation);
2028
+ }
2029
+
2030
+ if (postRotation !== undefined) {
2031
+ postRotation = postRotation.map(_three.MathUtils.degToRad);
2032
+ postRotation.push(eulerOrder);
2033
+ postRotation = new _three.Euler().fromArray(postRotation);
2034
+ postRotation = new _three.Quaternion().setFromEuler(postRotation).invert();
2035
+ }
2036
+
2037
+ var quaternion = new _three.Quaternion();
2038
+ var euler = new _three.Euler();
2039
+ var quaternionValues = [];
2040
+
2041
+ for (var i = 0; i < values.length; i += 3) {
2042
+ euler.set(values[i], values[i + 1], values[i + 2], eulerOrder);
2043
+ quaternion.setFromEuler(euler);
2044
+ if (preRotation !== undefined) quaternion.premultiply(preRotation);
2045
+ if (postRotation !== undefined) quaternion.multiply(postRotation);
2046
+ quaternion.toArray(quaternionValues, i / 3 * 4);
2047
+ }
2048
+
2049
+ return new _three.QuaternionKeyframeTrack(modelName + '.quaternion', times, quaternionValues);
2050
+ }
2051
+ }, {
2052
+ key: "generateMorphTrack",
2053
+ value: function generateMorphTrack(rawTracks) {
2054
+ var curves = rawTracks.DeformPercent.curves.morph;
2055
+ var values = curves.values.map(function (val) {
2056
+ return val / 100;
2057
+ });
2058
+ var morphNum = sceneGraph.getObjectByName(rawTracks.modelName).morphTargetDictionary[rawTracks.morphName];
2059
+ return new _three.NumberKeyframeTrack(rawTracks.modelName + '.morphTargetInfluences[' + morphNum + ']', curves.times, values);
2060
+ } // For all animated objects, times are defined separately for each axis
2061
+ // Here we'll combine the times into one sorted array without duplicates
2062
+
2063
+ }, {
2064
+ key: "getTimesForAllAxes",
2065
+ value: function getTimesForAllAxes(curves) {
2066
+ var times = []; // first join together the times for each axis, if defined
2067
+
2068
+ if (curves.x !== undefined) times = times.concat(curves.x.times);
2069
+ if (curves.y !== undefined) times = times.concat(curves.y.times);
2070
+ if (curves.z !== undefined) times = times.concat(curves.z.times); // then sort them
2071
+
2072
+ times = times.sort(function (a, b) {
2073
+ return a - b;
2074
+ }); // and remove duplicates
2075
+
2076
+ if (times.length > 1) {
2077
+ var targetIndex = 1;
2078
+ var lastValue = times[0];
2079
+
2080
+ for (var i = 1; i < times.length; i++) {
2081
+ var currentValue = times[i];
2082
+
2083
+ if (currentValue !== lastValue) {
2084
+ times[targetIndex] = currentValue;
2085
+ lastValue = currentValue;
2086
+ targetIndex++;
2087
+ }
2088
+ }
2089
+
2090
+ times = times.slice(0, targetIndex);
2091
+ }
2092
+
2093
+ return times;
2094
+ }
2095
+ }, {
2096
+ key: "getKeyframeTrackValues",
2097
+ value: function getKeyframeTrackValues(times, curves, initialValue) {
2098
+ var prevValue = initialValue;
2099
+ var values = [];
2100
+ var xIndex = -1;
2101
+ var yIndex = -1;
2102
+ var zIndex = -1;
2103
+ times.forEach(function (time) {
2104
+ if (curves.x) xIndex = curves.x.times.indexOf(time);
2105
+ if (curves.y) yIndex = curves.y.times.indexOf(time);
2106
+ if (curves.z) zIndex = curves.z.times.indexOf(time); // if there is an x value defined for this frame, use that
2107
+
2108
+ if (xIndex !== -1) {
2109
+ var xValue = curves.x.values[xIndex];
2110
+ values.push(xValue);
2111
+ prevValue[0] = xValue;
2112
+ } else {
2113
+ // otherwise use the x value from the previous frame
2114
+ values.push(prevValue[0]);
2115
+ }
2116
+
2117
+ if (yIndex !== -1) {
2118
+ var yValue = curves.y.values[yIndex];
2119
+ values.push(yValue);
2120
+ prevValue[1] = yValue;
2121
+ } else {
2122
+ values.push(prevValue[1]);
2123
+ }
2124
+
2125
+ if (zIndex !== -1) {
2126
+ var zValue = curves.z.values[zIndex];
2127
+ values.push(zValue);
2128
+ prevValue[2] = zValue;
2129
+ } else {
2130
+ values.push(prevValue[2]);
2131
+ }
2132
+ });
2133
+ return values;
2134
+ } // Rotations are defined as Euler angles which can have values of any size
2135
+ // These will be converted to quaternions which don't support values greater than
2136
+ // PI, so we'll interpolate large rotations
2137
+
2138
+ }, {
2139
+ key: "interpolateRotations",
2140
+ value: function interpolateRotations(curve) {
2141
+ for (var i = 1; i < curve.values.length; i++) {
2142
+ var initialValue = curve.values[i - 1];
2143
+ var valuesSpan = curve.values[i] - initialValue;
2144
+ var absoluteSpan = Math.abs(valuesSpan);
2145
+
2146
+ if (absoluteSpan >= 180) {
2147
+ var numSubIntervals = absoluteSpan / 180;
2148
+ var step = valuesSpan / numSubIntervals;
2149
+ var nextValue = initialValue + step;
2150
+ var initialTime = curve.times[i - 1];
2151
+ var timeSpan = curve.times[i] - initialTime;
2152
+ var interval = timeSpan / numSubIntervals;
2153
+ var nextTime = initialTime + interval;
2154
+ var interpolatedTimes = [];
2155
+ var interpolatedValues = [];
2156
+
2157
+ while (nextTime < curve.times[i]) {
2158
+ interpolatedTimes.push(nextTime);
2159
+ nextTime += interval;
2160
+ interpolatedValues.push(nextValue);
2161
+ nextValue += step;
2162
+ }
2163
+
2164
+ curve.times = inject(curve.times, i, interpolatedTimes);
2165
+ curve.values = inject(curve.values, i, interpolatedValues);
2166
+ }
2167
+ }
2168
+ }
2169
+ }]);
2170
+
2171
+ return AnimationParser;
2172
+ }(); // parse an FBX file in ASCII format
2173
+
2174
+
2175
+ var TextParser = /*#__PURE__*/function () {
2176
+ function TextParser() {
2177
+ _classCallCheck(this, TextParser);
2178
+ }
2179
+
2180
+ _createClass(TextParser, [{
2181
+ key: "getPrevNode",
2182
+ value: function getPrevNode() {
2183
+ return this.nodeStack[this.currentIndent - 2];
2184
+ }
2185
+ }, {
2186
+ key: "getCurrentNode",
2187
+ value: function getCurrentNode() {
2188
+ return this.nodeStack[this.currentIndent - 1];
2189
+ }
2190
+ }, {
2191
+ key: "getCurrentProp",
2192
+ value: function getCurrentProp() {
2193
+ return this.currentProp;
2194
+ }
2195
+ }, {
2196
+ key: "pushStack",
2197
+ value: function pushStack(node) {
2198
+ this.nodeStack.push(node);
2199
+ this.currentIndent += 1;
2200
+ }
2201
+ }, {
2202
+ key: "popStack",
2203
+ value: function popStack() {
2204
+ this.nodeStack.pop();
2205
+ this.currentIndent -= 1;
2206
+ }
2207
+ }, {
2208
+ key: "setCurrentProp",
2209
+ value: function setCurrentProp(val, name) {
2210
+ this.currentProp = val;
2211
+ this.currentPropName = name;
2212
+ }
2213
+ }, {
2214
+ key: "parse",
2215
+ value: function parse(text) {
2216
+ this.currentIndent = 0;
2217
+ this.allNodes = new FBXTree();
2218
+ this.nodeStack = [];
2219
+ this.currentProp = [];
2220
+ this.currentPropName = '';
2221
+ var scope = this;
2222
+ var split = text.split(/[\r\n]+/);
2223
+ split.forEach(function (line, i) {
2224
+ var matchComment = line.match(/^[\s\t]*;/);
2225
+ var matchEmpty = line.match(/^[\s\t]*$/);
2226
+ if (matchComment || matchEmpty) return;
2227
+ var matchBeginning = line.match('^\\t{' + scope.currentIndent + '}(\\w+):(.*){', '');
2228
+ var matchProperty = line.match('^\\t{' + scope.currentIndent + '}(\\w+):[\\s\\t\\r\\n](.*)');
2229
+ var matchEnd = line.match('^\\t{' + (scope.currentIndent - 1) + '}}');
2230
+
2231
+ if (matchBeginning) {
2232
+ scope.parseNodeBegin(line, matchBeginning);
2233
+ } else if (matchProperty) {
2234
+ scope.parseNodeProperty(line, matchProperty, split[++i]);
2235
+ } else if (matchEnd) {
2236
+ scope.popStack();
2237
+ } else if (line.match(/^[^\s\t}]/)) {
2238
+ // large arrays are split over multiple lines terminated with a ',' character
2239
+ // if this is encountered the line needs to be joined to the previous line
2240
+ scope.parseNodePropertyContinued(line);
2241
+ }
2242
+ });
2243
+ return this.allNodes;
2244
+ }
2245
+ }, {
2246
+ key: "parseNodeBegin",
2247
+ value: function parseNodeBegin(line, property) {
2248
+ var nodeName = property[1].trim().replace(/^"/, '').replace(/"$/, '');
2249
+ var nodeAttrs = property[2].split(',').map(function (attr) {
2250
+ return attr.trim().replace(/^"/, '').replace(/"$/, '');
2251
+ });
2252
+ var node = {
2253
+ name: nodeName
2254
+ };
2255
+ var attrs = this.parseNodeAttr(nodeAttrs);
2256
+ var currentNode = this.getCurrentNode(); // a top node
2257
+
2258
+ if (this.currentIndent === 0) {
2259
+ this.allNodes.add(nodeName, node);
2260
+ } else {
2261
+ // a subnode
2262
+ // if the subnode already exists, append it
2263
+ if (nodeName in currentNode) {
2264
+ // special case Pose needs PoseNodes as an array
2265
+ if (nodeName === 'PoseNode') {
2266
+ currentNode.PoseNode.push(node);
2267
+ } else if (currentNode[nodeName].id !== undefined) {
2268
+ currentNode[nodeName] = {};
2269
+ currentNode[nodeName][currentNode[nodeName].id] = currentNode[nodeName];
2270
+ }
2271
+
2272
+ if (attrs.id !== '') currentNode[nodeName][attrs.id] = node;
2273
+ } else if (typeof attrs.id === 'number') {
2274
+ currentNode[nodeName] = {};
2275
+ currentNode[nodeName][attrs.id] = node;
2276
+ } else if (nodeName !== 'Properties70') {
2277
+ if (nodeName === 'PoseNode') currentNode[nodeName] = [node];else currentNode[nodeName] = node;
2278
+ }
2279
+ }
2280
+
2281
+ if (typeof attrs.id === 'number') node.id = attrs.id;
2282
+ if (attrs.name !== '') node.attrName = attrs.name;
2283
+ if (attrs.type !== '') node.attrType = attrs.type;
2284
+ this.pushStack(node);
2285
+ }
2286
+ }, {
2287
+ key: "parseNodeAttr",
2288
+ value: function parseNodeAttr(attrs) {
2289
+ var id = attrs[0];
2290
+
2291
+ if (attrs[0] !== '') {
2292
+ id = parseInt(attrs[0]);
2293
+
2294
+ if (isNaN(id)) {
2295
+ id = attrs[0];
2296
+ }
2297
+ }
2298
+
2299
+ var name = '',
2300
+ type = '';
2301
+
2302
+ if (attrs.length > 1) {
2303
+ name = attrs[1].replace(/^(\w+)::/, '');
2304
+ type = attrs[2];
2305
+ }
2306
+
2307
+ return {
2308
+ id: id,
2309
+ name: name,
2310
+ type: type
2311
+ };
2312
+ }
2313
+ }, {
2314
+ key: "parseNodeProperty",
2315
+ value: function parseNodeProperty(line, property, contentLine) {
2316
+ var propName = property[1].replace(/^"/, '').replace(/"$/, '').trim();
2317
+ var propValue = property[2].replace(/^"/, '').replace(/"$/, '').trim(); // for special case: base64 image data follows "Content: ," line
2318
+ // Content: ,
2319
+ // "/9j/4RDaRXhpZgAATU0A..."
2320
+
2321
+ if (propName === 'Content' && propValue === ',') {
2322
+ propValue = contentLine.replace(/"/g, '').replace(/,$/, '').trim();
2323
+ }
2324
+
2325
+ var currentNode = this.getCurrentNode();
2326
+ var parentName = currentNode.name;
2327
+
2328
+ if (parentName === 'Properties70') {
2329
+ this.parseNodeSpecialProperty(line, propName, propValue);
2330
+ return;
2331
+ } // Connections
2332
+
2333
+
2334
+ if (propName === 'C') {
2335
+ var connProps = propValue.split(',').slice(1);
2336
+ var from = parseInt(connProps[0]);
2337
+ var to = parseInt(connProps[1]);
2338
+ var rest = propValue.split(',').slice(3);
2339
+ rest = rest.map(function (elem) {
2340
+ return elem.trim().replace(/^"/, '');
2341
+ });
2342
+ propName = 'connections';
2343
+ propValue = [from, to];
2344
+ append(propValue, rest);
2345
+
2346
+ if (currentNode[propName] === undefined) {
2347
+ currentNode[propName] = [];
2348
+ }
2349
+ } // Node
2350
+
2351
+
2352
+ if (propName === 'Node') currentNode.id = propValue; // connections
2353
+
2354
+ if (propName in currentNode && Array.isArray(currentNode[propName])) {
2355
+ currentNode[propName].push(propValue);
2356
+ } else {
2357
+ if (propName !== 'a') currentNode[propName] = propValue;else currentNode.a = propValue;
2358
+ }
2359
+
2360
+ this.setCurrentProp(currentNode, propName); // convert string to array, unless it ends in ',' in which case more will be added to it
2361
+
2362
+ if (propName === 'a' && propValue.slice(-1) !== ',') {
2363
+ currentNode.a = parseNumberArray(propValue);
2364
+ }
2365
+ }
2366
+ }, {
2367
+ key: "parseNodePropertyContinued",
2368
+ value: function parseNodePropertyContinued(line) {
2369
+ var currentNode = this.getCurrentNode();
2370
+ currentNode.a += line; // if the line doesn't end in ',' we have reached the end of the property value
2371
+ // so convert the string to an array
2372
+
2373
+ if (line.slice(-1) !== ',') {
2374
+ currentNode.a = parseNumberArray(currentNode.a);
2375
+ }
2376
+ } // parse "Property70"
2377
+
2378
+ }, {
2379
+ key: "parseNodeSpecialProperty",
2380
+ value: function parseNodeSpecialProperty(line, propName, propValue) {
2381
+ // split this
2382
+ // P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
2383
+ // into array like below
2384
+ // ["Lcl Scaling", "Lcl Scaling", "", "A", "1,1,1" ]
2385
+ var props = propValue.split('",').map(function (prop) {
2386
+ return prop.trim().replace(/^\"/, '').replace(/\s/, '_');
2387
+ });
2388
+ var innerPropName = props[0];
2389
+ var innerPropType1 = props[1];
2390
+ var innerPropType2 = props[2];
2391
+ var innerPropFlag = props[3];
2392
+ var innerPropValue = props[4]; // cast values where needed, otherwise leave as strings
2393
+
2394
+ switch (innerPropType1) {
2395
+ case 'int':
2396
+ case 'enum':
2397
+ case 'bool':
2398
+ case 'ULongLong':
2399
+ case 'double':
2400
+ case 'Number':
2401
+ case 'FieldOfView':
2402
+ innerPropValue = parseFloat(innerPropValue);
2403
+ break;
2404
+
2405
+ case 'Color':
2406
+ case 'ColorRGB':
2407
+ case 'Vector3D':
2408
+ case 'Lcl_Translation':
2409
+ case 'Lcl_Rotation':
2410
+ case 'Lcl_Scaling':
2411
+ innerPropValue = parseNumberArray(innerPropValue);
2412
+ break;
2413
+ } // CAUTION: these props must append to parent's parent
2414
+
2415
+
2416
+ this.getPrevNode()[innerPropName] = {
2417
+ 'type': innerPropType1,
2418
+ 'type2': innerPropType2,
2419
+ 'flag': innerPropFlag,
2420
+ 'value': innerPropValue
2421
+ };
2422
+ this.setCurrentProp(this.getPrevNode(), innerPropName);
2423
+ }
2424
+ }]);
2425
+
2426
+ return TextParser;
2427
+ }(); // Parse an FBX file in Binary format
2428
+
2429
+
2430
+ var BinaryParser = /*#__PURE__*/function () {
2431
+ function BinaryParser() {
2432
+ _classCallCheck(this, BinaryParser);
2433
+ }
2434
+
2435
+ _createClass(BinaryParser, [{
2436
+ key: "parse",
2437
+ value: function parse(buffer) {
2438
+ var reader = new BinaryReader(buffer);
2439
+ reader.skip(23); // skip magic 23 bytes
2440
+
2441
+ var version = reader.getUint32();
2442
+
2443
+ if (version < 6400) {
2444
+ throw new Error('THREE.FBXLoader: FBX version not supported, FileVersion: ' + version);
2445
+ }
2446
+
2447
+ var allNodes = new FBXTree();
2448
+
2449
+ while (!this.endOfContent(reader)) {
2450
+ var node = this.parseNode(reader, version);
2451
+ if (node !== null) allNodes.add(node.name, node);
2452
+ }
2453
+
2454
+ return allNodes;
2455
+ } // Check if reader has reached the end of content.
2456
+
2457
+ }, {
2458
+ key: "endOfContent",
2459
+ value: function endOfContent(reader) {
2460
+ // footer size: 160bytes + 16-byte alignment padding
2461
+ // - 16bytes: magic
2462
+ // - padding til 16-byte alignment (at least 1byte?)
2463
+ // (seems like some exporters embed fixed 15 or 16bytes?)
2464
+ // - 4bytes: magic
2465
+ // - 4bytes: version
2466
+ // - 120bytes: zero
2467
+ // - 16bytes: magic
2468
+ if (reader.size() % 16 === 0) {
2469
+ return (reader.getOffset() + 160 + 16 & ~0xf) >= reader.size();
2470
+ } else {
2471
+ return reader.getOffset() + 160 + 16 >= reader.size();
2472
+ }
2473
+ } // recursively parse nodes until the end of the file is reached
2474
+
2475
+ }, {
2476
+ key: "parseNode",
2477
+ value: function parseNode(reader, version) {
2478
+ var node = {}; // The first three data sizes depends on version.
2479
+
2480
+ var endOffset = version >= 7500 ? reader.getUint64() : reader.getUint32();
2481
+ var numProperties = version >= 7500 ? reader.getUint64() : reader.getUint32();
2482
+ version >= 7500 ? reader.getUint64() : reader.getUint32(); // the returned propertyListLen is not used
2483
+
2484
+ var nameLen = reader.getUint8();
2485
+ var name = reader.getString(nameLen); // Regards this node as NULL-record if endOffset is zero
2486
+
2487
+ if (endOffset === 0) return null;
2488
+ var propertyList = [];
2489
+
2490
+ for (var i = 0; i < numProperties; i++) {
2491
+ propertyList.push(this.parseProperty(reader));
2492
+ } // Regards the first three elements in propertyList as id, attrName, and attrType
2493
+
2494
+
2495
+ var id = propertyList.length > 0 ? propertyList[0] : '';
2496
+ var attrName = propertyList.length > 1 ? propertyList[1] : '';
2497
+ var attrType = propertyList.length > 2 ? propertyList[2] : ''; // check if this node represents just a single property
2498
+ // like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
2499
+
2500
+ node.singleProperty = numProperties === 1 && reader.getOffset() === endOffset ? true : false;
2501
+
2502
+ while (endOffset > reader.getOffset()) {
2503
+ var subNode = this.parseNode(reader, version);
2504
+ if (subNode !== null) this.parseSubNode(name, node, subNode);
2505
+ }
2506
+
2507
+ node.propertyList = propertyList; // raw property list used by parent
2508
+
2509
+ if (typeof id === 'number') node.id = id;
2510
+ if (attrName !== '') node.attrName = attrName;
2511
+ if (attrType !== '') node.attrType = attrType;
2512
+ if (name !== '') node.name = name;
2513
+ return node;
2514
+ }
2515
+ }, {
2516
+ key: "parseSubNode",
2517
+ value: function parseSubNode(name, node, subNode) {
2518
+ // special case: child node is single property
2519
+ if (subNode.singleProperty === true) {
2520
+ var value = subNode.propertyList[0];
2521
+
2522
+ if (Array.isArray(value)) {
2523
+ node[subNode.name] = subNode;
2524
+ subNode.a = value;
2525
+ } else {
2526
+ node[subNode.name] = value;
2527
+ }
2528
+ } else if (name === 'Connections' && subNode.name === 'C') {
2529
+ var array = [];
2530
+ subNode.propertyList.forEach(function (property, i) {
2531
+ // first Connection is FBX type (OO, OP, etc.). We'll discard these
2532
+ if (i !== 0) array.push(property);
2533
+ });
2534
+
2535
+ if (node.connections === undefined) {
2536
+ node.connections = [];
2537
+ }
2538
+
2539
+ node.connections.push(array);
2540
+ } else if (subNode.name === 'Properties70') {
2541
+ var keys = Object.keys(subNode);
2542
+ keys.forEach(function (key) {
2543
+ node[key] = subNode[key];
2544
+ });
2545
+ } else if (name === 'Properties70' && subNode.name === 'P') {
2546
+ var innerPropName = subNode.propertyList[0];
2547
+ var innerPropType1 = subNode.propertyList[1];
2548
+ var innerPropType2 = subNode.propertyList[2];
2549
+ var innerPropFlag = subNode.propertyList[3];
2550
+ var innerPropValue;
2551
+ if (innerPropName.indexOf('Lcl ') === 0) innerPropName = innerPropName.replace('Lcl ', 'Lcl_');
2552
+ if (innerPropType1.indexOf('Lcl ') === 0) innerPropType1 = innerPropType1.replace('Lcl ', 'Lcl_');
2553
+
2554
+ if (innerPropType1 === 'Color' || innerPropType1 === 'ColorRGB' || innerPropType1 === 'Vector' || innerPropType1 === 'Vector3D' || innerPropType1.indexOf('Lcl_') === 0) {
2555
+ innerPropValue = [subNode.propertyList[4], subNode.propertyList[5], subNode.propertyList[6]];
2556
+ } else {
2557
+ innerPropValue = subNode.propertyList[4];
2558
+ } // this will be copied to parent, see above
2559
+
2560
+
2561
+ node[innerPropName] = {
2562
+ 'type': innerPropType1,
2563
+ 'type2': innerPropType2,
2564
+ 'flag': innerPropFlag,
2565
+ 'value': innerPropValue
2566
+ };
2567
+ } else if (node[subNode.name] === undefined) {
2568
+ if (typeof subNode.id === 'number') {
2569
+ node[subNode.name] = {};
2570
+ node[subNode.name][subNode.id] = subNode;
2571
+ } else {
2572
+ node[subNode.name] = subNode;
2573
+ }
2574
+ } else {
2575
+ if (subNode.name === 'PoseNode') {
2576
+ if (!Array.isArray(node[subNode.name])) {
2577
+ node[subNode.name] = [node[subNode.name]];
2578
+ }
2579
+
2580
+ node[subNode.name].push(subNode);
2581
+ } else if (node[subNode.name][subNode.id] === undefined) {
2582
+ node[subNode.name][subNode.id] = subNode;
2583
+ }
2584
+ }
2585
+ }
2586
+ }, {
2587
+ key: "parseProperty",
2588
+ value: function parseProperty(reader) {
2589
+ var type = reader.getString(1);
2590
+ var length;
2591
+
2592
+ switch (type) {
2593
+ case 'C':
2594
+ return reader.getBoolean();
2595
+
2596
+ case 'D':
2597
+ return reader.getFloat64();
2598
+
2599
+ case 'F':
2600
+ return reader.getFloat32();
2601
+
2602
+ case 'I':
2603
+ return reader.getInt32();
2604
+
2605
+ case 'L':
2606
+ return reader.getInt64();
2607
+
2608
+ case 'R':
2609
+ length = reader.getUint32();
2610
+ return reader.getArrayBuffer(length);
2611
+
2612
+ case 'S':
2613
+ length = reader.getUint32();
2614
+ return reader.getString(length);
2615
+
2616
+ case 'Y':
2617
+ return reader.getInt16();
2618
+
2619
+ case 'b':
2620
+ case 'c':
2621
+ case 'd':
2622
+ case 'f':
2623
+ case 'i':
2624
+ case 'l':
2625
+ var arrayLength = reader.getUint32();
2626
+ var encoding = reader.getUint32(); // 0: non-compressed, 1: compressed
2627
+
2628
+ var compressedLength = reader.getUint32();
2629
+
2630
+ if (encoding === 0) {
2631
+ switch (type) {
2632
+ case 'b':
2633
+ case 'c':
2634
+ return reader.getBooleanArray(arrayLength);
2635
+
2636
+ case 'd':
2637
+ return reader.getFloat64Array(arrayLength);
2638
+
2639
+ case 'f':
2640
+ return reader.getFloat32Array(arrayLength);
2641
+
2642
+ case 'i':
2643
+ return reader.getInt32Array(arrayLength);
2644
+
2645
+ case 'l':
2646
+ return reader.getInt64Array(arrayLength);
2647
+ }
2648
+ }
2649
+
2650
+ if (typeof fflate === 'undefined') {
2651
+ console.error('THREE.FBXLoader: External library fflate.min.js required.');
2652
+ }
2653
+
2654
+ var data = fflate.unzlibSync(new Uint8Array(reader.getArrayBuffer(compressedLength))); // eslint-disable-line no-undef
2655
+
2656
+ var reader2 = new BinaryReader(data.buffer);
2657
+
2658
+ switch (type) {
2659
+ case 'b':
2660
+ case 'c':
2661
+ return reader2.getBooleanArray(arrayLength);
2662
+
2663
+ case 'd':
2664
+ return reader2.getFloat64Array(arrayLength);
2665
+
2666
+ case 'f':
2667
+ return reader2.getFloat32Array(arrayLength);
2668
+
2669
+ case 'i':
2670
+ return reader2.getInt32Array(arrayLength);
2671
+
2672
+ case 'l':
2673
+ return reader2.getInt64Array(arrayLength);
2674
+ }
2675
+
2676
+ default:
2677
+ throw new Error('THREE.FBXLoader: Unknown property type ' + type);
2678
+ }
2679
+ }
2680
+ }]);
2681
+
2682
+ return BinaryParser;
2683
+ }();
2684
+
2685
+ var BinaryReader = /*#__PURE__*/function () {
2686
+ function BinaryReader(buffer, littleEndian) {
2687
+ _classCallCheck(this, BinaryReader);
2688
+
2689
+ this.dv = new DataView(buffer);
2690
+ this.offset = 0;
2691
+ this.littleEndian = littleEndian !== undefined ? littleEndian : true;
2692
+ }
2693
+
2694
+ _createClass(BinaryReader, [{
2695
+ key: "getOffset",
2696
+ value: function getOffset() {
2697
+ return this.offset;
2698
+ }
2699
+ }, {
2700
+ key: "size",
2701
+ value: function size() {
2702
+ return this.dv.buffer.byteLength;
2703
+ }
2704
+ }, {
2705
+ key: "skip",
2706
+ value: function skip(length) {
2707
+ this.offset += length;
2708
+ } // seems like true/false representation depends on exporter.
2709
+ // true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54)
2710
+ // then sees LSB.
2711
+
2712
+ }, {
2713
+ key: "getBoolean",
2714
+ value: function getBoolean() {
2715
+ return (this.getUint8() & 1) === 1;
2716
+ }
2717
+ }, {
2718
+ key: "getBooleanArray",
2719
+ value: function getBooleanArray(size) {
2720
+ var a = [];
2721
+
2722
+ for (var i = 0; i < size; i++) {
2723
+ a.push(this.getBoolean());
2724
+ }
2725
+
2726
+ return a;
2727
+ }
2728
+ }, {
2729
+ key: "getUint8",
2730
+ value: function getUint8() {
2731
+ var value = this.dv.getUint8(this.offset);
2732
+ this.offset += 1;
2733
+ return value;
2734
+ }
2735
+ }, {
2736
+ key: "getInt16",
2737
+ value: function getInt16() {
2738
+ var value = this.dv.getInt16(this.offset, this.littleEndian);
2739
+ this.offset += 2;
2740
+ return value;
2741
+ }
2742
+ }, {
2743
+ key: "getInt32",
2744
+ value: function getInt32() {
2745
+ var value = this.dv.getInt32(this.offset, this.littleEndian);
2746
+ this.offset += 4;
2747
+ return value;
2748
+ }
2749
+ }, {
2750
+ key: "getInt32Array",
2751
+ value: function getInt32Array(size) {
2752
+ var a = [];
2753
+
2754
+ for (var i = 0; i < size; i++) {
2755
+ a.push(this.getInt32());
2756
+ }
2757
+
2758
+ return a;
2759
+ }
2760
+ }, {
2761
+ key: "getUint32",
2762
+ value: function getUint32() {
2763
+ var value = this.dv.getUint32(this.offset, this.littleEndian);
2764
+ this.offset += 4;
2765
+ return value;
2766
+ } // JavaScript doesn't support 64-bit integer so calculate this here
2767
+ // 1 << 32 will return 1 so using multiply operation instead here.
2768
+ // There's a possibility that this method returns wrong value if the value
2769
+ // is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
2770
+ // TODO: safely handle 64-bit integer
2771
+
2772
+ }, {
2773
+ key: "getInt64",
2774
+ value: function getInt64() {
2775
+ var low, high;
2776
+
2777
+ if (this.littleEndian) {
2778
+ low = this.getUint32();
2779
+ high = this.getUint32();
2780
+ } else {
2781
+ high = this.getUint32();
2782
+ low = this.getUint32();
2783
+ } // calculate negative value
2784
+
2785
+
2786
+ if (high & 0x80000000) {
2787
+ high = ~high & 0xFFFFFFFF;
2788
+ low = ~low & 0xFFFFFFFF;
2789
+ if (low === 0xFFFFFFFF) high = high + 1 & 0xFFFFFFFF;
2790
+ low = low + 1 & 0xFFFFFFFF;
2791
+ return -(high * 0x100000000 + low);
2792
+ }
2793
+
2794
+ return high * 0x100000000 + low;
2795
+ }
2796
+ }, {
2797
+ key: "getInt64Array",
2798
+ value: function getInt64Array(size) {
2799
+ var a = [];
2800
+
2801
+ for (var i = 0; i < size; i++) {
2802
+ a.push(this.getInt64());
2803
+ }
2804
+
2805
+ return a;
2806
+ } // Note: see getInt64() comment
2807
+
2808
+ }, {
2809
+ key: "getUint64",
2810
+ value: function getUint64() {
2811
+ var low, high;
2812
+
2813
+ if (this.littleEndian) {
2814
+ low = this.getUint32();
2815
+ high = this.getUint32();
2816
+ } else {
2817
+ high = this.getUint32();
2818
+ low = this.getUint32();
2819
+ }
2820
+
2821
+ return high * 0x100000000 + low;
2822
+ }
2823
+ }, {
2824
+ key: "getFloat32",
2825
+ value: function getFloat32() {
2826
+ var value = this.dv.getFloat32(this.offset, this.littleEndian);
2827
+ this.offset += 4;
2828
+ return value;
2829
+ }
2830
+ }, {
2831
+ key: "getFloat32Array",
2832
+ value: function getFloat32Array(size) {
2833
+ var a = [];
2834
+
2835
+ for (var i = 0; i < size; i++) {
2836
+ a.push(this.getFloat32());
2837
+ }
2838
+
2839
+ return a;
2840
+ }
2841
+ }, {
2842
+ key: "getFloat64",
2843
+ value: function getFloat64() {
2844
+ var value = this.dv.getFloat64(this.offset, this.littleEndian);
2845
+ this.offset += 8;
2846
+ return value;
2847
+ }
2848
+ }, {
2849
+ key: "getFloat64Array",
2850
+ value: function getFloat64Array(size) {
2851
+ var a = [];
2852
+
2853
+ for (var i = 0; i < size; i++) {
2854
+ a.push(this.getFloat64());
2855
+ }
2856
+
2857
+ return a;
2858
+ }
2859
+ }, {
2860
+ key: "getArrayBuffer",
2861
+ value: function getArrayBuffer(size) {
2862
+ var value = this.dv.buffer.slice(this.offset, this.offset + size);
2863
+ this.offset += size;
2864
+ return value;
2865
+ }
2866
+ }, {
2867
+ key: "getString",
2868
+ value: function getString(size) {
2869
+ // note: safari 9 doesn't support Uint8Array.indexOf; create intermediate array instead
2870
+ var a = [];
2871
+
2872
+ for (var i = 0; i < size; i++) {
2873
+ a[i] = this.getUint8();
2874
+ }
2875
+
2876
+ var nullByte = a.indexOf(0);
2877
+ if (nullByte >= 0) a = a.slice(0, nullByte);
2878
+ return _three.LoaderUtils.decodeText(new Uint8Array(a));
2879
+ }
2880
+ }]);
2881
+
2882
+ return BinaryReader;
2883
+ }(); // FBXTree holds a representation of the FBX data, returned by the TextParser ( FBX ASCII format)
2884
+ // and BinaryParser( FBX Binary format)
2885
+
2886
+
2887
+ var FBXTree = /*#__PURE__*/function () {
2888
+ function FBXTree() {
2889
+ _classCallCheck(this, FBXTree);
2890
+ }
2891
+
2892
+ _createClass(FBXTree, [{
2893
+ key: "add",
2894
+ value: function add(key, val) {
2895
+ this[key] = val;
2896
+ }
2897
+ }]);
2898
+
2899
+ return FBXTree;
2900
+ }(); // ************** UTILITY FUNCTIONS **************
2901
+
2902
+
2903
+ function isFbxFormatBinary(buffer) {
2904
+ var CORRECT = "Kaydara FBX Binary \0";
2905
+ return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString(buffer, 0, CORRECT.length);
2906
+ }
2907
+
2908
+ function isFbxFormatASCII(text) {
2909
+ var CORRECT = ['K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\'];
2910
+ var cursor = 0;
2911
+
2912
+ function read(offset) {
2913
+ var result = text[offset - 1];
2914
+ text = text.slice(cursor + offset);
2915
+ cursor++;
2916
+ return result;
2917
+ }
2918
+
2919
+ for (var i = 0; i < CORRECT.length; ++i) {
2920
+ var num = read(1);
2921
+
2922
+ if (num === CORRECT[i]) {
2923
+ return false;
2924
+ }
2925
+ }
2926
+
2927
+ return true;
2928
+ }
2929
+
2930
+ function getFbxVersion(text) {
2931
+ var versionRegExp = /FBXVersion: (\d+)/;
2932
+ var match = text.match(versionRegExp);
2933
+
2934
+ if (match) {
2935
+ var version = parseInt(match[1]);
2936
+ return version;
2937
+ }
2938
+
2939
+ throw new Error('THREE.FBXLoader: Cannot find the version number for the file given.');
2940
+ } // Converts FBX ticks into real time seconds.
2941
+
2942
+
2943
+ function convertFBXTimeToSeconds(time) {
2944
+ return time / 46186158000;
2945
+ }
2946
+
2947
+ var dataArray = []; // extracts the data from the correct position in the FBX array based on indexing type
2948
+
2949
+ function getData(polygonVertexIndex, polygonIndex, vertexIndex, infoObject) {
2950
+ var index;
2951
+
2952
+ switch (infoObject.mappingType) {
2953
+ case 'ByPolygonVertex':
2954
+ index = polygonVertexIndex;
2955
+ break;
2956
+
2957
+ case 'ByPolygon':
2958
+ index = polygonIndex;
2959
+ break;
2960
+
2961
+ case 'ByVertice':
2962
+ index = vertexIndex;
2963
+ break;
2964
+
2965
+ case 'AllSame':
2966
+ index = infoObject.indices[0];
2967
+ break;
2968
+
2969
+ default:
2970
+ console.warn('THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType);
2971
+ }
2972
+
2973
+ if (infoObject.referenceType === 'IndexToDirect') index = infoObject.indices[index];
2974
+ var from = index * infoObject.dataSize;
2975
+ var to = from + infoObject.dataSize;
2976
+ return slice(dataArray, infoObject.buffer, from, to);
2977
+ }
2978
+
2979
+ var tempEuler = new _three.Euler();
2980
+ var tempVec = new _three.Vector3(); // generate transformation from FBX transform data
2981
+ // ref: https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_10CDD63C_79C1_4F2D_BB28_AD2BE65A02ED_htm
2982
+ // ref: http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=cpp_ref/_transformations_2main_8cxx-example.html,topicNumber=cpp_ref__transformations_2main_8cxx_example_htmlfc10a1e1-b18d-4e72-9dc0-70d0f1959f5e
2983
+
2984
+ function generateTransform(transformData) {
2985
+ var lTranslationM = new _three.Matrix4();
2986
+ var lPreRotationM = new _three.Matrix4();
2987
+ var lRotationM = new _three.Matrix4();
2988
+ var lPostRotationM = new _three.Matrix4();
2989
+ var lScalingM = new _three.Matrix4();
2990
+ var lScalingPivotM = new _three.Matrix4();
2991
+ var lScalingOffsetM = new _three.Matrix4();
2992
+ var lRotationOffsetM = new _three.Matrix4();
2993
+ var lRotationPivotM = new _three.Matrix4();
2994
+ var lParentGX = new _three.Matrix4();
2995
+ var lParentLX = new _three.Matrix4();
2996
+ var lGlobalT = new _three.Matrix4();
2997
+ var inheritType = transformData.inheritType ? transformData.inheritType : 0;
2998
+ if (transformData.translation) lTranslationM.setPosition(tempVec.fromArray(transformData.translation));
2999
+
3000
+ if (transformData.preRotation) {
3001
+ var array = transformData.preRotation.map(_three.MathUtils.degToRad);
3002
+ array.push(transformData.eulerOrder);
3003
+ lPreRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
3004
+ }
3005
+
3006
+ if (transformData.rotation) {
3007
+ var _array = transformData.rotation.map(_three.MathUtils.degToRad);
3008
+
3009
+ _array.push(transformData.eulerOrder);
3010
+
3011
+ lRotationM.makeRotationFromEuler(tempEuler.fromArray(_array));
3012
+ }
3013
+
3014
+ if (transformData.postRotation) {
3015
+ var _array2 = transformData.postRotation.map(_three.MathUtils.degToRad);
3016
+
3017
+ _array2.push(transformData.eulerOrder);
3018
+
3019
+ lPostRotationM.makeRotationFromEuler(tempEuler.fromArray(_array2));
3020
+ lPostRotationM.invert();
3021
+ }
3022
+
3023
+ if (transformData.scale) lScalingM.scale(tempVec.fromArray(transformData.scale)); // Pivots and offsets
3024
+
3025
+ if (transformData.scalingOffset) lScalingOffsetM.setPosition(tempVec.fromArray(transformData.scalingOffset));
3026
+ if (transformData.scalingPivot) lScalingPivotM.setPosition(tempVec.fromArray(transformData.scalingPivot));
3027
+ if (transformData.rotationOffset) lRotationOffsetM.setPosition(tempVec.fromArray(transformData.rotationOffset));
3028
+ if (transformData.rotationPivot) lRotationPivotM.setPosition(tempVec.fromArray(transformData.rotationPivot)); // parent transform
3029
+
3030
+ if (transformData.parentMatrixWorld) {
3031
+ lParentLX.copy(transformData.parentMatrix);
3032
+ lParentGX.copy(transformData.parentMatrixWorld);
3033
+ }
3034
+
3035
+ var lLRM = lPreRotationM.clone().multiply(lRotationM).multiply(lPostRotationM); // Global Rotation
3036
+
3037
+ var lParentGRM = new _three.Matrix4();
3038
+ lParentGRM.extractRotation(lParentGX); // Global Shear*Scaling
3039
+
3040
+ var lParentTM = new _three.Matrix4();
3041
+ lParentTM.copyPosition(lParentGX);
3042
+ var lParentGRSM = lParentTM.clone().invert().multiply(lParentGX);
3043
+ var lParentGSM = lParentGRM.clone().invert().multiply(lParentGRSM);
3044
+ var lLSM = lScalingM;
3045
+ var lGlobalRS = new _three.Matrix4();
3046
+
3047
+ if (inheritType === 0) {
3048
+ lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM).multiply(lLSM);
3049
+ } else if (inheritType === 1) {
3050
+ lGlobalRS.copy(lParentGRM).multiply(lParentGSM).multiply(lLRM).multiply(lLSM);
3051
+ } else {
3052
+ var lParentLSM = new _three.Matrix4().scale(new _three.Vector3().setFromMatrixScale(lParentLX));
3053
+ var lParentLSM_inv = lParentLSM.clone().invert();
3054
+ var lParentGSM_noLocal = lParentGSM.clone().multiply(lParentLSM_inv);
3055
+ lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM_noLocal).multiply(lLSM);
3056
+ }
3057
+
3058
+ var lRotationPivotM_inv = lRotationPivotM.clone().invert();
3059
+ var lScalingPivotM_inv = lScalingPivotM.clone().invert(); // Calculate the local transform matrix
3060
+
3061
+ var lTransform = lTranslationM.clone().multiply(lRotationOffsetM).multiply(lRotationPivotM).multiply(lPreRotationM).multiply(lRotationM).multiply(lPostRotationM).multiply(lRotationPivotM_inv).multiply(lScalingOffsetM).multiply(lScalingPivotM).multiply(lScalingM).multiply(lScalingPivotM_inv);
3062
+ var lLocalTWithAllPivotAndOffsetInfo = new _three.Matrix4().copyPosition(lTransform);
3063
+ var lGlobalTranslation = lParentGX.clone().multiply(lLocalTWithAllPivotAndOffsetInfo);
3064
+ lGlobalT.copyPosition(lGlobalTranslation);
3065
+ lTransform = lGlobalT.clone().multiply(lGlobalRS); // from global to local
3066
+
3067
+ lTransform.premultiply(lParentGX.invert());
3068
+ return lTransform;
3069
+ } // Returns the three.js intrinsic Euler order corresponding to FBX extrinsic Euler order
3070
+ // ref: http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_euler_html
3071
+
3072
+
3073
+ function getEulerOrder(order) {
3074
+ order = order || 0;
3075
+ var enums = ['ZYX', // -> XYZ extrinsic
3076
+ 'YZX', // -> XZY extrinsic
3077
+ 'XZY', // -> YZX extrinsic
3078
+ 'ZXY', // -> YXZ extrinsic
3079
+ 'YXZ', // -> ZXY extrinsic
3080
+ 'XYZ' // -> ZYX extrinsic
3081
+ //'SphericXYZ', // not possible to support
3082
+ ];
3083
+
3084
+ if (order === 6) {
3085
+ console.warn('THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect.');
3086
+ return enums[0];
3087
+ }
3088
+
3089
+ return enums[order];
3090
+ } // Parses comma separated list of numbers and returns them an array.
3091
+ // Used internally by the TextParser
3092
+
3093
+
3094
+ function parseNumberArray(value) {
3095
+ var array = value.split(',').map(function (val) {
3096
+ return parseFloat(val);
3097
+ });
3098
+ return array;
3099
+ }
3100
+
3101
+ function convertArrayBufferToString(buffer, from, to) {
3102
+ if (from === undefined) from = 0;
3103
+ if (to === undefined) to = buffer.byteLength;
3104
+ return _three.LoaderUtils.decodeText(new Uint8Array(buffer, from, to));
3105
+ }
3106
+
3107
+ function append(a, b) {
3108
+ for (var i = 0, j = a.length, l = b.length; i < l; i++, j++) {
3109
+ a[j] = b[i];
3110
+ }
3111
+ }
3112
+
3113
+ function slice(a, b, from, to) {
3114
+ for (var i = from, j = 0; i < to; i++, j++) {
3115
+ a[j] = b[i];
3116
+ }
3117
+
3118
+ return a;
3119
+ } // inject array a2 into array a1 at index
3120
+
3121
+
3122
+ function inject(a1, index, a2) {
3123
+ return a1.slice(0, index).concat(a2).concat(a1.slice(index));
3124
+ }
3125
+ });