@anov/3d 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/README.md +142 -1
  2. package/dist/core/camera.d.ts +31 -4
  3. package/dist/core/camera.js +62 -52
  4. package/dist/core/control/transformControls.d.ts +12 -0
  5. package/dist/core/control/transformControls.js +72 -0
  6. package/dist/core/cssRenderer.d.ts +17 -0
  7. package/dist/core/cssRenderer.js +36 -0
  8. package/dist/core/global/global.d.ts +27 -0
  9. package/dist/core/global/global.js +72 -0
  10. package/dist/core/global/globalControl.d.ts +17 -0
  11. package/dist/core/global/globalControl.js +62 -0
  12. package/dist/core/group.d.ts +51 -6
  13. package/dist/core/group.js +124 -16
  14. package/dist/core/line.d.ts +13 -0
  15. package/dist/core/line.js +83 -0
  16. package/dist/core/mesh.d.ts +12 -7
  17. package/dist/core/mesh.js +57 -56
  18. package/dist/core/model.d.ts +11 -3
  19. package/dist/core/model.js +34 -7
  20. package/dist/core/scene.d.ts +84 -25
  21. package/dist/core/scene.js +207 -53
  22. package/dist/core/use/useScene.d.ts +10 -0
  23. package/dist/core/use/useScene.js +14 -0
  24. package/dist/core/use/useframe.d.ts +6 -0
  25. package/dist/core/use/useframe.js +11 -0
  26. package/dist/export.d.ts +41 -0
  27. package/dist/export.js +37 -0
  28. package/dist/index.d.ts +3 -6
  29. package/dist/index.js +5 -6
  30. package/dist/threeCell.d.ts +8 -0
  31. package/dist/threeCell.js +16 -0
  32. package/dist/type.d.ts +4 -3
  33. package/dist/utils/createElement.d.ts +103 -0
  34. package/dist/utils/createElement.js +145 -0
  35. package/dist/utils/createLabel.d.ts +2 -0
  36. package/dist/utils/createLabel.js +4 -0
  37. package/dist/utils/index.d.ts +36 -0
  38. package/dist/utils/index.js +76 -0
  39. package/dist/utils/line.d.ts +0 -0
  40. package/dist/utils/line.js +0 -0
  41. package/dist/utils/move.d.ts +48 -0
  42. package/dist/utils/move.js +149 -0
  43. package/examples/fonts/LICENSE +13 -0
  44. package/examples/fonts/README.md +11 -0
  45. package/examples/fonts/droid/NOTICE +190 -0
  46. package/examples/fonts/droid/README.txt +18 -0
  47. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  48. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  49. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  50. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  51. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  52. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  53. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  54. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  55. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  56. package/examples/fonts/optimer_bold.typeface.json +1 -0
  57. package/examples/fonts/optimer_regular.typeface.json +1 -0
  58. package/examples/fonts/ttf/README.md +9 -0
  59. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  60. package/examples/jsm/animation/AnimationClipCreator.js +116 -0
  61. package/examples/jsm/animation/CCDIKSolver.js +482 -0
  62. package/examples/jsm/animation/MMDAnimationHelper.js +1207 -0
  63. package/examples/jsm/animation/MMDPhysics.js +1406 -0
  64. package/examples/jsm/cameras/CinematicCamera.js +208 -0
  65. package/examples/jsm/capabilities/WebGL.js +91 -0
  66. package/examples/jsm/capabilities/WebGPU.js +53 -0
  67. package/examples/jsm/controls/ArcballControls.js +3224 -0
  68. package/examples/jsm/controls/DragControls.js +220 -0
  69. package/examples/jsm/controls/FirstPersonControls.js +325 -0
  70. package/examples/jsm/controls/FlyControls.js +300 -0
  71. package/examples/jsm/controls/MapControls.js +28 -0
  72. package/examples/jsm/controls/OrbitControls.js +1388 -0
  73. package/examples/jsm/controls/PointerLockControls.js +162 -0
  74. package/examples/jsm/controls/TrackballControls.js +828 -0
  75. package/examples/jsm/controls/TransformControls.js +1557 -0
  76. package/examples/jsm/csm/CSM.js +384 -0
  77. package/examples/jsm/csm/CSMFrustum.js +152 -0
  78. package/examples/jsm/csm/CSMHelper.js +193 -0
  79. package/examples/jsm/csm/CSMShader.js +252 -0
  80. package/examples/jsm/curves/CurveExtras.js +422 -0
  81. package/examples/jsm/curves/NURBSCurve.js +80 -0
  82. package/examples/jsm/curves/NURBSSurface.js +52 -0
  83. package/examples/jsm/curves/NURBSUtils.js +487 -0
  84. package/examples/jsm/effects/AnaglyphEffect.js +154 -0
  85. package/examples/jsm/effects/AsciiEffect.js +263 -0
  86. package/examples/jsm/effects/OutlineEffect.js +539 -0
  87. package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -0
  88. package/examples/jsm/effects/PeppersGhostEffect.js +153 -0
  89. package/examples/jsm/effects/StereoEffect.js +55 -0
  90. package/examples/jsm/environments/DebugEnvironment.js +52 -0
  91. package/examples/jsm/environments/RoomEnvironment.js +148 -0
  92. package/examples/jsm/exporters/DRACOExporter.js +267 -0
  93. package/examples/jsm/exporters/EXRExporter.js +501 -0
  94. package/examples/jsm/exporters/GLTFExporter.js +3161 -0
  95. package/examples/jsm/exporters/KTX2Exporter.js +292 -0
  96. package/examples/jsm/exporters/MMDExporter.js +217 -0
  97. package/examples/jsm/exporters/OBJExporter.js +284 -0
  98. package/examples/jsm/exporters/PLYExporter.js +528 -0
  99. package/examples/jsm/exporters/STLExporter.js +199 -0
  100. package/examples/jsm/exporters/USDZExporter.js +711 -0
  101. package/examples/jsm/geometries/BoxLineGeometry.js +69 -0
  102. package/examples/jsm/geometries/ConvexGeometry.js +53 -0
  103. package/examples/jsm/geometries/DecalGeometry.js +356 -0
  104. package/examples/jsm/geometries/ParametricGeometries.js +254 -0
  105. package/examples/jsm/geometries/ParametricGeometry.js +139 -0
  106. package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -0
  107. package/examples/jsm/geometries/TeapotGeometry.js +704 -0
  108. package/examples/jsm/geometries/TextGeometry.js +57 -0
  109. package/examples/jsm/helpers/LightProbeHelper.js +130 -0
  110. package/examples/jsm/helpers/OctreeHelper.js +73 -0
  111. package/examples/jsm/helpers/PositionalAudioHelper.js +109 -0
  112. package/examples/jsm/helpers/RectAreaLightHelper.js +85 -0
  113. package/examples/jsm/helpers/VertexNormalsHelper.js +96 -0
  114. package/examples/jsm/helpers/VertexTangentsHelper.js +88 -0
  115. package/examples/jsm/helpers/ViewHelper.js +333 -0
  116. package/examples/jsm/interactive/HTMLMesh.js +565 -0
  117. package/examples/jsm/interactive/InteractiveGroup.js +116 -0
  118. package/examples/jsm/interactive/SelectionBox.js +227 -0
  119. package/examples/jsm/interactive/SelectionHelper.js +104 -0
  120. package/examples/jsm/libs/ammo.wasm.js +822 -0
  121. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  122. package/examples/jsm/libs/basis/README.md +46 -0
  123. package/examples/jsm/libs/basis/basis_transcoder.js +21 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  125. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  126. package/examples/jsm/libs/draco/README.md +32 -0
  127. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  128. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  129. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  130. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  131. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  132. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  133. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  135. package/examples/jsm/libs/ecsy.module.js +1792 -0
  136. package/examples/jsm/libs/fflate.module.js +2474 -0
  137. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  138. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  139. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  140. package/examples/jsm/libs/meshopt_decoder.module.js +178 -0
  141. package/examples/jsm/libs/mikktspace.module.js +128 -0
  142. package/examples/jsm/libs/mmdparser.module.js +11530 -0
  143. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  144. package/examples/jsm/libs/opentype.module.js +14568 -0
  145. package/examples/jsm/libs/potpack.module.js +125 -0
  146. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  149. package/examples/jsm/libs/stats.module.js +167 -0
  150. package/examples/jsm/libs/tween.module.js +803 -0
  151. package/examples/jsm/libs/utif.module.js +1579 -0
  152. package/examples/jsm/libs/zstddec.module.js +1 -0
  153. package/examples/jsm/lights/IESSpotLight.js +25 -0
  154. package/examples/jsm/lights/LightProbeGenerator.js +252 -0
  155. package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -0
  156. package/examples/jsm/lines/Line2.js +19 -0
  157. package/examples/jsm/lines/LineGeometry.js +79 -0
  158. package/examples/jsm/lines/LineMaterial.js +702 -0
  159. package/examples/jsm/lines/LineSegments2.js +361 -0
  160. package/examples/jsm/lines/LineSegmentsGeometry.js +241 -0
  161. package/examples/jsm/lines/Wireframe.js +56 -0
  162. package/examples/jsm/lines/WireframeGeometry2.js +24 -0
  163. package/examples/jsm/loaders/3DMLoader.js +1497 -0
  164. package/examples/jsm/loaders/3MFLoader.js +1478 -0
  165. package/examples/jsm/loaders/AMFLoader.js +521 -0
  166. package/examples/jsm/loaders/BVHLoader.js +437 -0
  167. package/examples/jsm/loaders/ColladaLoader.js +4122 -0
  168. package/examples/jsm/loaders/DDSLoader.js +274 -0
  169. package/examples/jsm/loaders/DRACOLoader.js +612 -0
  170. package/examples/jsm/loaders/EXRLoader.js +2309 -0
  171. package/examples/jsm/loaders/FBXLoader.js +4142 -0
  172. package/examples/jsm/loaders/FontLoader.js +183 -0
  173. package/examples/jsm/loaders/GCodeLoader.js +261 -0
  174. package/examples/jsm/loaders/GLTFLoader.js +4576 -0
  175. package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -0
  176. package/examples/jsm/loaders/IESLoader.js +337 -0
  177. package/examples/jsm/loaders/KMZLoader.js +130 -0
  178. package/examples/jsm/loaders/KTX2Loader.js +868 -0
  179. package/examples/jsm/loaders/KTXLoader.js +176 -0
  180. package/examples/jsm/loaders/LDrawLoader.js +2464 -0
  181. package/examples/jsm/loaders/LUT3dlLoader.js +151 -0
  182. package/examples/jsm/loaders/LUTCubeLoader.js +153 -0
  183. package/examples/jsm/loaders/LWOLoader.js +1052 -0
  184. package/examples/jsm/loaders/LogLuvLoader.js +606 -0
  185. package/examples/jsm/loaders/LottieLoader.js +77 -0
  186. package/examples/jsm/loaders/MD2Loader.js +399 -0
  187. package/examples/jsm/loaders/MDDLoader.js +102 -0
  188. package/examples/jsm/loaders/MMDLoader.js +2273 -0
  189. package/examples/jsm/loaders/MTLLoader.js +567 -0
  190. package/examples/jsm/loaders/MaterialXLoader.js +734 -0
  191. package/examples/jsm/loaders/NRRDLoader.js +699 -0
  192. package/examples/jsm/loaders/OBJLoader.js +905 -0
  193. package/examples/jsm/loaders/PCDLoader.js +467 -0
  194. package/examples/jsm/loaders/PDBLoader.js +232 -0
  195. package/examples/jsm/loaders/PLYLoader.js +771 -0
  196. package/examples/jsm/loaders/PVRLoader.js +251 -0
  197. package/examples/jsm/loaders/RGBELoader.js +468 -0
  198. package/examples/jsm/loaders/RGBMLoader.js +1065 -0
  199. package/examples/jsm/loaders/STLLoader.js +403 -0
  200. package/examples/jsm/loaders/SVGLoader.js +3172 -0
  201. package/examples/jsm/loaders/TDSLoader.js +1124 -0
  202. package/examples/jsm/loaders/TGALoader.js +517 -0
  203. package/examples/jsm/loaders/TIFFLoader.js +36 -0
  204. package/examples/jsm/loaders/TTFLoader.js +214 -0
  205. package/examples/jsm/loaders/TiltLoader.js +520 -0
  206. package/examples/jsm/loaders/USDZLoader.js +633 -0
  207. package/examples/jsm/loaders/VOXLoader.js +311 -0
  208. package/examples/jsm/loaders/VRMLLoader.js +3533 -0
  209. package/examples/jsm/loaders/VTKLoader.js +1163 -0
  210. package/examples/jsm/loaders/XYZLoader.js +106 -0
  211. package/examples/jsm/loaders/lwo/IFFParser.js +1218 -0
  212. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  213. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  214. package/examples/jsm/materials/MeshGouraudMaterial.js +420 -0
  215. package/examples/jsm/math/Capsule.js +137 -0
  216. package/examples/jsm/math/ColorConverter.js +36 -0
  217. package/examples/jsm/math/ConvexHull.js +1271 -0
  218. package/examples/jsm/math/ImprovedNoise.js +71 -0
  219. package/examples/jsm/math/Lut.js +204 -0
  220. package/examples/jsm/math/MeshSurfaceSampler.js +250 -0
  221. package/examples/jsm/math/OBB.js +423 -0
  222. package/examples/jsm/math/Octree.js +462 -0
  223. package/examples/jsm/math/SimplexNoise.js +444 -0
  224. package/examples/jsm/misc/ConvexObjectBreaker.js +519 -0
  225. package/examples/jsm/misc/GPUComputationRenderer.js +446 -0
  226. package/examples/jsm/misc/Gyroscope.js +66 -0
  227. package/examples/jsm/misc/MD2Character.js +276 -0
  228. package/examples/jsm/misc/MD2CharacterComplex.js +576 -0
  229. package/examples/jsm/misc/MorphAnimMesh.js +75 -0
  230. package/examples/jsm/misc/MorphBlendMesh.js +322 -0
  231. package/examples/jsm/misc/ProgressiveLightMap.js +323 -0
  232. package/examples/jsm/misc/RollerCoaster.js +566 -0
  233. package/examples/jsm/misc/TubePainter.js +205 -0
  234. package/examples/jsm/misc/Volume.js +473 -0
  235. package/examples/jsm/misc/VolumeSlice.js +229 -0
  236. package/examples/jsm/modifiers/CurveModifier.js +326 -0
  237. package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -0
  238. package/examples/jsm/modifiers/SimplifyModifier.js +525 -0
  239. package/examples/jsm/modifiers/TessellateModifier.js +307 -0
  240. package/examples/jsm/nodes/Nodes.js +171 -0
  241. package/examples/jsm/nodes/accessors/BitangentNode.js +89 -0
  242. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +99 -0
  243. package/examples/jsm/nodes/accessors/BufferNode.js +30 -0
  244. package/examples/jsm/nodes/accessors/CameraNode.js +98 -0
  245. package/examples/jsm/nodes/accessors/CubeTextureNode.js +103 -0
  246. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +77 -0
  247. package/examples/jsm/nodes/accessors/InstanceNode.js +71 -0
  248. package/examples/jsm/nodes/accessors/MaterialNode.js +267 -0
  249. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +39 -0
  250. package/examples/jsm/nodes/accessors/ModelNode.js +34 -0
  251. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +29 -0
  252. package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
  253. package/examples/jsm/nodes/accessors/NormalNode.js +96 -0
  254. package/examples/jsm/nodes/accessors/Object3DNode.js +150 -0
  255. package/examples/jsm/nodes/accessors/PointUVNode.js +26 -0
  256. package/examples/jsm/nodes/accessors/PositionNode.js +104 -0
  257. package/examples/jsm/nodes/accessors/ReferenceNode.js +72 -0
  258. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -0
  259. package/examples/jsm/nodes/accessors/SceneNode.js +52 -0
  260. package/examples/jsm/nodes/accessors/SkinningNode.js +93 -0
  261. package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
  262. package/examples/jsm/nodes/accessors/TangentNode.js +103 -0
  263. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
  264. package/examples/jsm/nodes/accessors/TextureNode.js +271 -0
  265. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
  266. package/examples/jsm/nodes/accessors/UVNode.js +47 -0
  267. package/examples/jsm/nodes/accessors/UserDataNode.js +29 -0
  268. package/examples/jsm/nodes/code/CodeNode.js +78 -0
  269. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  270. package/examples/jsm/nodes/code/FunctionCallNode.js +96 -0
  271. package/examples/jsm/nodes/code/FunctionNode.js +127 -0
  272. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  273. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  274. package/examples/jsm/nodes/core/ArrayUniformNode.js +26 -0
  275. package/examples/jsm/nodes/core/AttributeNode.js +102 -0
  276. package/examples/jsm/nodes/core/BypassNode.js +45 -0
  277. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  278. package/examples/jsm/nodes/core/ConstNode.js +32 -0
  279. package/examples/jsm/nodes/core/ContextNode.js +61 -0
  280. package/examples/jsm/nodes/core/IndexNode.js +66 -0
  281. package/examples/jsm/nodes/core/InputNode.js +83 -0
  282. package/examples/jsm/nodes/core/LightingModel.js +15 -0
  283. package/examples/jsm/nodes/core/Node.js +454 -0
  284. package/examples/jsm/nodes/core/NodeAttribute.js +15 -0
  285. package/examples/jsm/nodes/core/NodeBuilder.js +1016 -0
  286. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  287. package/examples/jsm/nodes/core/NodeCode.js +15 -0
  288. package/examples/jsm/nodes/core/NodeFrame.js +110 -0
  289. package/examples/jsm/nodes/core/NodeFunction.js +22 -0
  290. package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -0
  291. package/examples/jsm/nodes/core/NodeKeywords.js +80 -0
  292. package/examples/jsm/nodes/core/NodeParser.js +11 -0
  293. package/examples/jsm/nodes/core/NodeUniform.js +28 -0
  294. package/examples/jsm/nodes/core/NodeUtils.js +212 -0
  295. package/examples/jsm/nodes/core/NodeVar.js +14 -0
  296. package/examples/jsm/nodes/core/NodeVarying.js +17 -0
  297. package/examples/jsm/nodes/core/PropertyNode.js +61 -0
  298. package/examples/jsm/nodes/core/StackNode.js +99 -0
  299. package/examples/jsm/nodes/core/TempNode.js +58 -0
  300. package/examples/jsm/nodes/core/UniformNode.js +61 -0
  301. package/examples/jsm/nodes/core/VarNode.js +87 -0
  302. package/examples/jsm/nodes/core/VaryingNode.js +69 -0
  303. package/examples/jsm/nodes/core/constants.js +27 -0
  304. package/examples/jsm/nodes/display/BlendModeNode.js +99 -0
  305. package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
  306. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +100 -0
  307. package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -0
  308. package/examples/jsm/nodes/display/FrontFacingNode.js +27 -0
  309. package/examples/jsm/nodes/display/NormalMapNode.js +106 -0
  310. package/examples/jsm/nodes/display/PosterizeNode.js +32 -0
  311. package/examples/jsm/nodes/display/ToneMappingNode.js +141 -0
  312. package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
  313. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
  314. package/examples/jsm/nodes/display/ViewportNode.js +115 -0
  315. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -0
  316. package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -0
  317. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  318. package/examples/jsm/nodes/fog/FogNode.js +37 -0
  319. package/examples/jsm/nodes/fog/FogRangeNode.js +34 -0
  320. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -0
  321. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  322. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
  323. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +29 -0
  324. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +18 -0
  325. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  326. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -0
  327. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
  328. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +20 -0
  329. package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -0
  330. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +343 -0
  331. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -0
  332. package/examples/jsm/nodes/functions/material/getRoughness.js +18 -0
  333. package/examples/jsm/nodes/geometry/RangeNode.js +104 -0
  334. package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -0
  335. package/examples/jsm/nodes/lighting/AONode.js +27 -0
  336. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  337. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +184 -0
  338. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -0
  339. package/examples/jsm/nodes/lighting/EnvironmentNode.js +191 -0
  340. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -0
  341. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  342. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  343. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  344. package/examples/jsm/nodes/lighting/LightingContextNode.js +102 -0
  345. package/examples/jsm/nodes/lighting/LightingNode.js +21 -0
  346. package/examples/jsm/nodes/lighting/LightsNode.js +128 -0
  347. package/examples/jsm/nodes/lighting/PointLightNode.js +68 -0
  348. package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -0
  349. package/examples/jsm/nodes/loaders/NodeLoader.js +108 -0
  350. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -0
  351. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -0
  352. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -0
  353. package/examples/jsm/nodes/materials/Materials.js +12 -0
  354. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +27 -0
  355. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
  356. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -0
  357. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -0
  358. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +128 -0
  359. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -0
  360. package/examples/jsm/nodes/materials/NodeMaterial.js +536 -0
  361. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +49 -0
  362. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +103 -0
  363. package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
  364. package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -0
  365. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
  366. package/examples/jsm/nodes/materialx/lib/mx_noise.js +618 -0
  367. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +19 -0
  368. package/examples/jsm/nodes/math/CondNode.js +86 -0
  369. package/examples/jsm/nodes/math/MathNode.js +359 -0
  370. package/examples/jsm/nodes/math/OperatorNode.js +269 -0
  371. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -0
  372. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -0
  373. package/examples/jsm/nodes/procedural/CheckerNode.js +42 -0
  374. package/examples/jsm/nodes/shadernode/ShaderNode.js +420 -0
  375. package/examples/jsm/nodes/utils/ArrayElementNode.js +33 -0
  376. package/examples/jsm/nodes/utils/ConvertNode.js +65 -0
  377. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  378. package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -0
  379. package/examples/jsm/nodes/utils/JoinNode.js +51 -0
  380. package/examples/jsm/nodes/utils/LoopNode.js +186 -0
  381. package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -0
  382. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -0
  383. package/examples/jsm/nodes/utils/OscNode.js +81 -0
  384. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  385. package/examples/jsm/nodes/utils/RemapNode.js +42 -0
  386. package/examples/jsm/nodes/utils/RotateUVNode.js +43 -0
  387. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  388. package/examples/jsm/nodes/utils/SplitNode.js +104 -0
  389. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -0
  390. package/examples/jsm/nodes/utils/TimerNode.js +94 -0
  391. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -0
  392. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  393. package/examples/jsm/objects/Lensflare.js +377 -0
  394. package/examples/jsm/objects/MarchingCubes.js +1176 -0
  395. package/examples/jsm/objects/Reflector.js +264 -0
  396. package/examples/jsm/objects/ReflectorForSSRPass.js +349 -0
  397. package/examples/jsm/objects/Refractor.js +324 -0
  398. package/examples/jsm/objects/ShadowMesh.js +80 -0
  399. package/examples/jsm/objects/Sky.js +219 -0
  400. package/examples/jsm/objects/Water.js +330 -0
  401. package/examples/jsm/objects/Water2.js +358 -0
  402. package/examples/jsm/offscreen/jank.js +45 -0
  403. package/examples/jsm/offscreen/offscreen.js +8 -0
  404. package/examples/jsm/offscreen/scene.js +86 -0
  405. package/examples/jsm/physics/AmmoPhysics.js +285 -0
  406. package/examples/jsm/physics/RapierPhysics.js +199 -0
  407. package/examples/jsm/postprocessing/AfterimagePass.js +104 -0
  408. package/examples/jsm/postprocessing/BloomPass.js +172 -0
  409. package/examples/jsm/postprocessing/BokehPass.js +140 -0
  410. package/examples/jsm/postprocessing/ClearPass.js +46 -0
  411. package/examples/jsm/postprocessing/CubeTexturePass.js +85 -0
  412. package/examples/jsm/postprocessing/DotScreenPass.js +65 -0
  413. package/examples/jsm/postprocessing/EffectComposer.js +231 -0
  414. package/examples/jsm/postprocessing/FilmPass.js +66 -0
  415. package/examples/jsm/postprocessing/GlitchPass.js +128 -0
  416. package/examples/jsm/postprocessing/HalftonePass.js +79 -0
  417. package/examples/jsm/postprocessing/LUTPass.js +173 -0
  418. package/examples/jsm/postprocessing/MaskPass.js +104 -0
  419. package/examples/jsm/postprocessing/OutlinePass.js +654 -0
  420. package/examples/jsm/postprocessing/OutputPass.js +91 -0
  421. package/examples/jsm/postprocessing/Pass.js +84 -0
  422. package/examples/jsm/postprocessing/RenderPass.js +81 -0
  423. package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -0
  424. package/examples/jsm/postprocessing/SAOPass.js +411 -0
  425. package/examples/jsm/postprocessing/SMAAPass.js +201 -0
  426. package/examples/jsm/postprocessing/SSAARenderPass.js +228 -0
  427. package/examples/jsm/postprocessing/SSAOPass.js +440 -0
  428. package/examples/jsm/postprocessing/SSRPass.js +641 -0
  429. package/examples/jsm/postprocessing/SavePass.js +79 -0
  430. package/examples/jsm/postprocessing/ShaderPass.js +77 -0
  431. package/examples/jsm/postprocessing/TAARenderPass.js +189 -0
  432. package/examples/jsm/postprocessing/TexturePass.js +67 -0
  433. package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -0
  434. package/examples/jsm/renderers/CSS2DRenderer.js +215 -0
  435. package/examples/jsm/renderers/CSS3DRenderer.js +335 -0
  436. package/examples/jsm/renderers/Projector.js +918 -0
  437. package/examples/jsm/renderers/SVGRenderer.js +553 -0
  438. package/examples/jsm/renderers/common/Animation.js +58 -0
  439. package/examples/jsm/renderers/common/Attributes.js +75 -0
  440. package/examples/jsm/renderers/common/Backend.js +162 -0
  441. package/examples/jsm/renderers/common/Background.js +136 -0
  442. package/examples/jsm/renderers/common/Binding.js +19 -0
  443. package/examples/jsm/renderers/common/Bindings.js +165 -0
  444. package/examples/jsm/renderers/common/Buffer.js +38 -0
  445. package/examples/jsm/renderers/common/BufferUtils.js +33 -0
  446. package/examples/jsm/renderers/common/ChainMap.js +89 -0
  447. package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
  448. package/examples/jsm/renderers/common/Constants.js +14 -0
  449. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
  450. package/examples/jsm/renderers/common/DataMap.js +54 -0
  451. package/examples/jsm/renderers/common/Geometries.js +215 -0
  452. package/examples/jsm/renderers/common/Info.js +73 -0
  453. package/examples/jsm/renderers/common/Pipeline.js +13 -0
  454. package/examples/jsm/renderers/common/Pipelines.js +370 -0
  455. package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
  456. package/examples/jsm/renderers/common/RenderContext.js +38 -0
  457. package/examples/jsm/renderers/common/RenderContexts.js +49 -0
  458. package/examples/jsm/renderers/common/RenderList.js +178 -0
  459. package/examples/jsm/renderers/common/RenderLists.js +38 -0
  460. package/examples/jsm/renderers/common/RenderObject.js +129 -0
  461. package/examples/jsm/renderers/common/RenderObjects.js +95 -0
  462. package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
  463. package/examples/jsm/renderers/common/Renderer.js +895 -0
  464. package/examples/jsm/renderers/common/SampledTexture.js +80 -0
  465. package/examples/jsm/renderers/common/Sampler.js +18 -0
  466. package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
  467. package/examples/jsm/renderers/common/Textures.js +218 -0
  468. package/examples/jsm/renderers/common/Uniform.js +140 -0
  469. package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
  470. package/examples/jsm/renderers/common/UniformsGroup.js +299 -0
  471. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +39 -0
  472. package/examples/jsm/renderers/common/nodes/NodeSampler.js +21 -0
  473. package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -0
  474. package/examples/jsm/renderers/common/nodes/Nodes.js +330 -0
  475. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
  476. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +26 -0
  477. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +764 -0
  478. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +49 -0
  479. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +844 -0
  480. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +32 -0
  481. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +902 -0
  482. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -0
  483. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -0
  484. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +274 -0
  485. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +223 -0
  486. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -0
  487. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +533 -0
  488. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +163 -0
  489. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +964 -0
  490. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +92 -0
  491. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +87 -0
  492. package/examples/jsm/shaders/AfterimageShader.js +56 -0
  493. package/examples/jsm/shaders/BasicShader.js +27 -0
  494. package/examples/jsm/shaders/BleachBypassShader.js +62 -0
  495. package/examples/jsm/shaders/BlendShader.js +47 -0
  496. package/examples/jsm/shaders/BokehShader.js +143 -0
  497. package/examples/jsm/shaders/BokehShader2.js +393 -0
  498. package/examples/jsm/shaders/BrightnessContrastShader.js +54 -0
  499. package/examples/jsm/shaders/ColorCorrectionShader.js +50 -0
  500. package/examples/jsm/shaders/ColorifyShader.js +51 -0
  501. package/examples/jsm/shaders/ConvolutionShader.js +103 -0
  502. package/examples/jsm/shaders/CopyShader.js +45 -0
  503. package/examples/jsm/shaders/DOFMipMapShader.js +54 -0
  504. package/examples/jsm/shaders/DepthLimitedBlurShader.js +166 -0
  505. package/examples/jsm/shaders/DigitalGlitch.js +101 -0
  506. package/examples/jsm/shaders/DotScreenShader.js +70 -0
  507. package/examples/jsm/shaders/ExposureShader.js +44 -0
  508. package/examples/jsm/shaders/FXAAShader.js +286 -0
  509. package/examples/jsm/shaders/FilmShader.js +102 -0
  510. package/examples/jsm/shaders/FocusShader.js +87 -0
  511. package/examples/jsm/shaders/FreiChenShader.js +94 -0
  512. package/examples/jsm/shaders/GammaCorrectionShader.js +43 -0
  513. package/examples/jsm/shaders/GodRaysShader.js +313 -0
  514. package/examples/jsm/shaders/HalftoneShader.js +310 -0
  515. package/examples/jsm/shaders/HorizontalBlurShader.js +59 -0
  516. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +61 -0
  517. package/examples/jsm/shaders/HueSaturationShader.js +65 -0
  518. package/examples/jsm/shaders/KaleidoShader.js +56 -0
  519. package/examples/jsm/shaders/LuminosityHighPassShader.js +64 -0
  520. package/examples/jsm/shaders/LuminosityShader.js +46 -0
  521. package/examples/jsm/shaders/MMDToonShader.js +132 -0
  522. package/examples/jsm/shaders/MirrorShader.js +54 -0
  523. package/examples/jsm/shaders/NormalMapShader.js +53 -0
  524. package/examples/jsm/shaders/OutputShader.js +78 -0
  525. package/examples/jsm/shaders/RGBShiftShader.js +54 -0
  526. package/examples/jsm/shaders/SAOShader.js +188 -0
  527. package/examples/jsm/shaders/SMAAShader.js +460 -0
  528. package/examples/jsm/shaders/SSAOShader.js +288 -0
  529. package/examples/jsm/shaders/SSRShader.js +364 -0
  530. package/examples/jsm/shaders/SepiaShader.js +52 -0
  531. package/examples/jsm/shaders/SobelOperatorShader.js +90 -0
  532. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +88 -0
  533. package/examples/jsm/shaders/TechnicolorShader.js +43 -0
  534. package/examples/jsm/shaders/ToonShader.js +326 -0
  535. package/examples/jsm/shaders/TriangleBlurShader.js +72 -0
  536. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +45 -0
  537. package/examples/jsm/shaders/VelocityShader.js +128 -0
  538. package/examples/jsm/shaders/VerticalBlurShader.js +59 -0
  539. package/examples/jsm/shaders/VerticalTiltShiftShader.js +61 -0
  540. package/examples/jsm/shaders/VignetteShader.js +51 -0
  541. package/examples/jsm/shaders/VolumeShader.js +289 -0
  542. package/examples/jsm/shaders/WaterRefractionShader.js +93 -0
  543. package/examples/jsm/textures/FlakesTexture.js +40 -0
  544. package/examples/jsm/utils/BufferGeometryUtils.js +1373 -0
  545. package/examples/jsm/utils/CameraUtils.js +73 -0
  546. package/examples/jsm/utils/GPUStatsPanel.js +128 -0
  547. package/examples/jsm/utils/GeometryCompressionUtils.js +639 -0
  548. package/examples/jsm/utils/GeometryUtils.js +221 -0
  549. package/examples/jsm/utils/LDrawUtils.js +202 -0
  550. package/examples/jsm/utils/PackedPhongMaterial.js +178 -0
  551. package/examples/jsm/utils/SceneUtils.js +254 -0
  552. package/examples/jsm/utils/ShadowMapViewer.js +210 -0
  553. package/examples/jsm/utils/SkeletonUtils.js +413 -0
  554. package/examples/jsm/utils/TextureUtils.js +86 -0
  555. package/examples/jsm/utils/UVsDebug.js +165 -0
  556. package/examples/jsm/utils/WorkerPool.js +102 -0
  557. package/examples/jsm/webxr/ARButton.js +208 -0
  558. package/examples/jsm/webxr/OculusHandModel.js +109 -0
  559. package/examples/jsm/webxr/OculusHandPointerModel.js +413 -0
  560. package/examples/jsm/webxr/Text2D.js +38 -0
  561. package/examples/jsm/webxr/VRButton.js +200 -0
  562. package/examples/jsm/webxr/XRButton.js +198 -0
  563. package/examples/jsm/webxr/XRControllerModelFactory.js +299 -0
  564. package/examples/jsm/webxr/XREstimatedLight.js +223 -0
  565. package/examples/jsm/webxr/XRHandMeshModel.js +112 -0
  566. package/examples/jsm/webxr/XRHandModelFactory.js +105 -0
  567. package/examples/jsm/webxr/XRHandPrimitiveModel.js +103 -0
  568. package/examples/jsm/webxr/XRPlanes.js +100 -0
  569. package/lib/3d.min.js +1 -0
  570. package/package.json +25 -12
@@ -0,0 +1,2273 @@
1
+ import {
2
+ AddOperation,
3
+ AnimationClip,
4
+ Bone,
5
+ BufferGeometry,
6
+ Color,
7
+ CustomBlending,
8
+ TangentSpaceNormalMap,
9
+ DoubleSide,
10
+ DstAlphaFactor,
11
+ Euler,
12
+ FileLoader,
13
+ Float32BufferAttribute,
14
+ FrontSide,
15
+ Interpolant,
16
+ Loader,
17
+ LoaderUtils,
18
+ UniformsUtils,
19
+ ShaderMaterial,
20
+ MultiplyOperation,
21
+ NearestFilter,
22
+ NumberKeyframeTrack,
23
+ OneMinusSrcAlphaFactor,
24
+ Quaternion,
25
+ QuaternionKeyframeTrack,
26
+ RepeatWrapping,
27
+ Skeleton,
28
+ SkinnedMesh,
29
+ SrcAlphaFactor,
30
+ TextureLoader,
31
+ Uint16BufferAttribute,
32
+ Vector3,
33
+ VectorKeyframeTrack,
34
+ RGB_S3TC_DXT1_Format,
35
+ RGB_PVRTC_4BPPV1_Format,
36
+ RGB_PVRTC_2BPPV1_Format,
37
+ RGB_ETC1_Format,
38
+ RGB_ETC2_Format
39
+ } from 'three';
40
+ import { MMDToonShader } from '../shaders/MMDToonShader.js';
41
+ import { TGALoader } from '../loaders/TGALoader.js';
42
+ import { MMDParser } from '../libs/mmdparser.module.js';
43
+
44
+ /**
45
+ * Dependencies
46
+ * - mmd-parser https://github.com/takahirox/mmd-parser
47
+ * - TGALoader
48
+ * - OutlineEffect
49
+ *
50
+ * MMDLoader creates Three.js Objects from MMD resources as
51
+ * PMD, PMX, VMD, and VPD files.
52
+ *
53
+ * PMD/PMX is a model data format, VMD is a motion data format
54
+ * VPD is a posing data format used in MMD(Miku Miku Dance).
55
+ *
56
+ * MMD official site
57
+ * - https://sites.google.com/view/evpvp/
58
+ *
59
+ * PMD, VMD format (in Japanese)
60
+ * - http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4
61
+ *
62
+ * PMX format
63
+ * - https://gist.github.com/felixjones/f8a06bd48f9da9a4539f
64
+ *
65
+ * TODO
66
+ * - light motion in vmd support.
67
+ * - SDEF support.
68
+ * - uv/material/bone morphing support.
69
+ * - more precise grant skinning support.
70
+ * - shadow support.
71
+ */
72
+
73
+ /**
74
+ * @param {THREE.LoadingManager} manager
75
+ */
76
+ class MMDLoader extends Loader {
77
+
78
+ constructor( manager ) {
79
+
80
+ super( manager );
81
+
82
+ this.loader = new FileLoader( this.manager );
83
+
84
+ this.parser = null; // lazy generation
85
+ this.meshBuilder = new MeshBuilder( this.manager );
86
+ this.animationBuilder = new AnimationBuilder();
87
+
88
+ }
89
+
90
+ /**
91
+ * @param {string} animationPath
92
+ * @return {MMDLoader}
93
+ */
94
+ setAnimationPath( animationPath ) {
95
+
96
+ this.animationPath = animationPath;
97
+ return this;
98
+
99
+ }
100
+
101
+ // Load MMD assets as Three.js Object
102
+
103
+ /**
104
+ * Loads Model file (.pmd or .pmx) as a SkinnedMesh.
105
+ *
106
+ * @param {string} url - url to Model(.pmd or .pmx) file
107
+ * @param {function} onLoad
108
+ * @param {function} onProgress
109
+ * @param {function} onError
110
+ */
111
+ load( url, onLoad, onProgress, onError ) {
112
+
113
+ const builder = this.meshBuilder.setCrossOrigin( this.crossOrigin );
114
+
115
+ // resource path
116
+
117
+ let resourcePath;
118
+
119
+ if ( this.resourcePath !== '' ) {
120
+
121
+ resourcePath = this.resourcePath;
122
+
123
+ } else if ( this.path !== '' ) {
124
+
125
+ resourcePath = this.path;
126
+
127
+ } else {
128
+
129
+ resourcePath = LoaderUtils.extractUrlBase( url );
130
+
131
+ }
132
+
133
+ const modelExtension = this._extractExtension( url ).toLowerCase();
134
+
135
+ // Should I detect by seeing header?
136
+ if ( modelExtension !== 'pmd' && modelExtension !== 'pmx' ) {
137
+
138
+ if ( onError ) onError( new Error( 'THREE.MMDLoader: Unknown model file extension .' + modelExtension + '.' ) );
139
+
140
+ return;
141
+
142
+ }
143
+
144
+ this[ modelExtension === 'pmd' ? 'loadPMD' : 'loadPMX' ]( url, function ( data ) {
145
+
146
+ onLoad( builder.build( data, resourcePath, onProgress, onError ) );
147
+
148
+ }, onProgress, onError );
149
+
150
+ }
151
+
152
+ /**
153
+ * Loads Motion file(s) (.vmd) as a AnimationClip.
154
+ * If two or more files are specified, they'll be merged.
155
+ *
156
+ * @param {string|Array<string>} url - url(s) to animation(.vmd) file(s)
157
+ * @param {SkinnedMesh|THREE.Camera} object - tracks will be fitting to this object
158
+ * @param {function} onLoad
159
+ * @param {function} onProgress
160
+ * @param {function} onError
161
+ */
162
+ loadAnimation( url, object, onLoad, onProgress, onError ) {
163
+
164
+ const builder = this.animationBuilder;
165
+
166
+ this.loadVMD( url, function ( vmd ) {
167
+
168
+ onLoad( object.isCamera
169
+ ? builder.buildCameraAnimation( vmd )
170
+ : builder.build( vmd, object ) );
171
+
172
+ }, onProgress, onError );
173
+
174
+ }
175
+
176
+ /**
177
+ * Loads mode file and motion file(s) as an object containing
178
+ * a SkinnedMesh and a AnimationClip.
179
+ * Tracks of AnimationClip are fitting to the model.
180
+ *
181
+ * @param {string} modelUrl - url to Model(.pmd or .pmx) file
182
+ * @param {string|Array{string}} vmdUrl - url(s) to animation(.vmd) file
183
+ * @param {function} onLoad
184
+ * @param {function} onProgress
185
+ * @param {function} onError
186
+ */
187
+ loadWithAnimation( modelUrl, vmdUrl, onLoad, onProgress, onError ) {
188
+
189
+ const scope = this;
190
+
191
+ this.load( modelUrl, function ( mesh ) {
192
+
193
+ scope.loadAnimation( vmdUrl, mesh, function ( animation ) {
194
+
195
+ onLoad( {
196
+ mesh: mesh,
197
+ animation: animation
198
+ } );
199
+
200
+ }, onProgress, onError );
201
+
202
+ }, onProgress, onError );
203
+
204
+ }
205
+
206
+ // Load MMD assets as Object data parsed by MMDParser
207
+
208
+ /**
209
+ * Loads .pmd file as an Object.
210
+ *
211
+ * @param {string} url - url to .pmd file
212
+ * @param {function} onLoad
213
+ * @param {function} onProgress
214
+ * @param {function} onError
215
+ */
216
+ loadPMD( url, onLoad, onProgress, onError ) {
217
+
218
+ const parser = this._getParser();
219
+
220
+ this.loader
221
+ .setMimeType( undefined )
222
+ .setPath( this.path )
223
+ .setResponseType( 'arraybuffer' )
224
+ .setRequestHeader( this.requestHeader )
225
+ .setWithCredentials( this.withCredentials )
226
+ .load( url, function ( buffer ) {
227
+
228
+ try {
229
+
230
+ onLoad( parser.parsePmd( buffer, true ) );
231
+
232
+ } catch ( e ) {
233
+
234
+ if ( onError ) onError( e );
235
+
236
+ }
237
+
238
+ }, onProgress, onError );
239
+
240
+ }
241
+
242
+ /**
243
+ * Loads .pmx file as an Object.
244
+ *
245
+ * @param {string} url - url to .pmx file
246
+ * @param {function} onLoad
247
+ * @param {function} onProgress
248
+ * @param {function} onError
249
+ */
250
+ loadPMX( url, onLoad, onProgress, onError ) {
251
+
252
+ const parser = this._getParser();
253
+
254
+ this.loader
255
+ .setMimeType( undefined )
256
+ .setPath( this.path )
257
+ .setResponseType( 'arraybuffer' )
258
+ .setRequestHeader( this.requestHeader )
259
+ .setWithCredentials( this.withCredentials )
260
+ .load( url, function ( buffer ) {
261
+
262
+ try {
263
+
264
+ onLoad( parser.parsePmx( buffer, true ) );
265
+
266
+ } catch ( e ) {
267
+
268
+ if ( onError ) onError( e );
269
+
270
+ }
271
+
272
+ }, onProgress, onError );
273
+
274
+ }
275
+
276
+ /**
277
+ * Loads .vmd file as an Object. If two or more files are specified
278
+ * they'll be merged.
279
+ *
280
+ * @param {string|Array<string>} url - url(s) to .vmd file(s)
281
+ * @param {function} onLoad
282
+ * @param {function} onProgress
283
+ * @param {function} onError
284
+ */
285
+ loadVMD( url, onLoad, onProgress, onError ) {
286
+
287
+ const urls = Array.isArray( url ) ? url : [ url ];
288
+
289
+ const vmds = [];
290
+ const vmdNum = urls.length;
291
+
292
+ const parser = this._getParser();
293
+
294
+ this.loader
295
+ .setMimeType( undefined )
296
+ .setPath( this.animationPath )
297
+ .setResponseType( 'arraybuffer' )
298
+ .setRequestHeader( this.requestHeader )
299
+ .setWithCredentials( this.withCredentials );
300
+
301
+ for ( let i = 0, il = urls.length; i < il; i ++ ) {
302
+
303
+ this.loader.load( urls[ i ], function ( buffer ) {
304
+
305
+ try {
306
+
307
+ vmds.push( parser.parseVmd( buffer, true ) );
308
+
309
+ if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
310
+
311
+ } catch ( e ) {
312
+
313
+ if ( onError ) onError( e );
314
+
315
+ }
316
+
317
+ }, onProgress, onError );
318
+
319
+ }
320
+
321
+ }
322
+
323
+ /**
324
+ * Loads .vpd file as an Object.
325
+ *
326
+ * @param {string} url - url to .vpd file
327
+ * @param {boolean} isUnicode
328
+ * @param {function} onLoad
329
+ * @param {function} onProgress
330
+ * @param {function} onError
331
+ */
332
+ loadVPD( url, isUnicode, onLoad, onProgress, onError ) {
333
+
334
+ const parser = this._getParser();
335
+
336
+ this.loader
337
+ .setMimeType( isUnicode ? undefined : 'text/plain; charset=shift_jis' )
338
+ .setPath( this.animationPath )
339
+ .setResponseType( 'text' )
340
+ .setRequestHeader( this.requestHeader )
341
+ .setWithCredentials( this.withCredentials )
342
+ .load( url, function ( text ) {
343
+
344
+ try {
345
+
346
+ onLoad( parser.parseVpd( text, true ) );
347
+
348
+ } catch ( e ) {
349
+
350
+ if ( onError ) onError( e );
351
+
352
+ }
353
+
354
+ }, onProgress, onError );
355
+
356
+ }
357
+
358
+ // private methods
359
+
360
+ _extractExtension( url ) {
361
+
362
+ const index = url.lastIndexOf( '.' );
363
+ return index < 0 ? '' : url.slice( index + 1 );
364
+
365
+ }
366
+
367
+ _getParser() {
368
+
369
+ if ( this.parser === null ) {
370
+
371
+ this.parser = new MMDParser.Parser();
372
+
373
+ }
374
+
375
+ return this.parser;
376
+
377
+ }
378
+
379
+ }
380
+
381
+ // Utilities
382
+
383
+ /*
384
+ * base64 encoded defalut toon textures toon00.bmp - toon10.bmp.
385
+ * We don't need to request external toon image files.
386
+ */
387
+ const DEFAULT_TOON_TEXTURES = [
388
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
389
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/bWiiMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh8aBHZBl14e8wAAAABJRU5ErkJggg==',
390
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOUlEQVRYR+3WMREAMAwDsYY/yoDI7MLwIiP40+RJklfcCCBAgAABAgTqArfb/QMCCBAgQIAAgbbAB3z/e0F3js2cAAAAAElFTkSuQmCC',
391
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAN0lEQVRYR+3WQREAMBACsZ5/B5ilMvgEBTt5cW37hjsBBAgQIECAwFwgyfYPCCBAgAABAgTWAh81dWyx0gFwKAAAAABJRU5ErkJggg==',
392
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAOklEQVRYR+3WoREAMAwDsWb/UQtCy9wxTOQJ/oQ8SXKKGwEECBAgQIBAXeDt7f4BAQQIECBAgEBb4AOz8Hzx7WLY4wAAAABJRU5ErkJggg==',
393
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABPUlEQVRYR+1XwW7CMAy1+f9fZOMysSEOEweEOPRNdm3HbdOyIhAcklPrOs/PLy9RygBALxzcCDQFmgJNgaZAU6Ap0BR4PwX8gsRMVLssMRH5HcpzJEaWL7EVg9F1IHRlyqQohgVr4FGUlUcMJSjcUlDw0zvjeun70cLWmneoyf7NgBTQSniBTQQSuJAZsOnnaczjIMb5hCiuHKxokCrJfVnrctyZL0PkJAJe1HMil4nxeyi3Ypfn1kX51jpPvo/JeCNC4PhVdHdJw2XjBR8brF8PEIhNVn12AgP7uHsTBguBn53MUZCqv7Lp07Pn5k1Ro+uWmUNn7D+M57rtk7aG0Vo73xyF/fbFf0bPJjDXngnGocDTdFhygZjwUQrMNrDcmZlQT50VJ/g/UwNyHpu778+yW+/ksOz/BFo54P4AsUXMfRq7XWsAAAAASUVORK5CYII=',
394
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACMElEQVRYR+2Xv4pTQRTGf2dubhLdICiii2KnYKHVolhauKWPoGAnNr6BD6CvIVaihYuI2i1ia0BY0MZGRHQXjZj/mSPnnskfNWiWZUlzJ5k7M2cm833nO5Mziej2DWWJRUoCpQKlAntSQCqgw39/iUWAGmh37jrRnVsKlgpiqmkoGVABA7E57fvY+pJDdgKqF6HzFCSADkDq+F6AHABtQ+UMVE5D7zXod7fFNhTEckTbj5XQgHzNN+5tQvc5NG7C6BNkp6D3EmpXHDR+dQAjFLchW3VS9rlw3JBh+B7ys5Cf9z0GW1C/7P32AyBAOAz1q4jGliIH3YPuBnSfQX4OGreTIgEYQb/pBDtPnEQ4CivXYPAWBk13oHrB54yA9QuSn2H4AcKRpEILDt0BUzj+RLR1V5EqjD66NPRBVpLcQwjHoHYJOhsQv6U4mnzmrIXJCFr4LDwm/xBUoboG9XX4cc9VKdYoSA2yk5NQLJaKDUjTBoveG3Z2TElTxwjNK4M3LEZgUdDdruvcXzKBpStgp2NPiWi3ks9ZXxIoFVi+AvHLdc9TqtjL3/aYjpPlrzOcEnK62Szhimdd7xX232zFDTgtxezOu3WNMRLjiKgjtOhHVMd1loynVHvOgjuIIJMaELEqhJAV/RCSLbWTcfPFakFgFlALTRRvx+ok6Hlp/Q+v3fmx90bMyUzaEAhmM3KvHlXTL5DxnbGf/1M8RNNACLL5MNtPxP/mypJAqcDSFfgFhpYqWUzhTEAAAAAASUVORK5CYII=',
395
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
396
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
397
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII=',
398
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVRYR+3QQREAAAzCsOFfNJPBJ1XQS9r2hsUAAQIECBAgQIAAAQIECBAgsBZ4MUx/ofm2I/kAAAAASUVORK5CYII='
399
+ ];
400
+
401
+ const NON_ALPHA_CHANNEL_FORMATS = [
402
+ RGB_S3TC_DXT1_Format,
403
+ RGB_PVRTC_4BPPV1_Format,
404
+ RGB_PVRTC_2BPPV1_Format,
405
+ RGB_ETC1_Format,
406
+ RGB_ETC2_Format
407
+ ];
408
+
409
+ // Builders. They build Three.js object from Object data parsed by MMDParser.
410
+
411
+ /**
412
+ * @param {THREE.LoadingManager} manager
413
+ */
414
+ class MeshBuilder {
415
+
416
+ constructor( manager ) {
417
+
418
+ this.crossOrigin = 'anonymous';
419
+ this.geometryBuilder = new GeometryBuilder();
420
+ this.materialBuilder = new MaterialBuilder( manager );
421
+
422
+ }
423
+
424
+ /**
425
+ * @param {string} crossOrigin
426
+ * @return {MeshBuilder}
427
+ */
428
+ setCrossOrigin( crossOrigin ) {
429
+
430
+ this.crossOrigin = crossOrigin;
431
+ return this;
432
+
433
+ }
434
+
435
+ /**
436
+ * @param {Object} data - parsed PMD/PMX data
437
+ * @param {string} resourcePath
438
+ * @param {function} onProgress
439
+ * @param {function} onError
440
+ * @return {SkinnedMesh}
441
+ */
442
+ build( data, resourcePath, onProgress, onError ) {
443
+
444
+ const geometry = this.geometryBuilder.build( data );
445
+ const material = this.materialBuilder
446
+ .setCrossOrigin( this.crossOrigin )
447
+ .setResourcePath( resourcePath )
448
+ .build( data, geometry, onProgress, onError );
449
+
450
+ const mesh = new SkinnedMesh( geometry, material );
451
+
452
+ const skeleton = new Skeleton( initBones( mesh ) );
453
+ mesh.bind( skeleton );
454
+
455
+ // console.log( mesh ); // for console debug
456
+
457
+ return mesh;
458
+
459
+ }
460
+
461
+ }
462
+
463
+ // TODO: Try to remove this function
464
+
465
+ function initBones( mesh ) {
466
+
467
+ const geometry = mesh.geometry;
468
+
469
+ const bones = [];
470
+
471
+ if ( geometry && geometry.bones !== undefined ) {
472
+
473
+ // first, create array of 'Bone' objects from geometry data
474
+
475
+ for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
476
+
477
+ const gbone = geometry.bones[ i ];
478
+
479
+ // create new 'Bone' object
480
+
481
+ const bone = new Bone();
482
+ bones.push( bone );
483
+
484
+ // apply values
485
+
486
+ bone.name = gbone.name;
487
+ bone.position.fromArray( gbone.pos );
488
+ bone.quaternion.fromArray( gbone.rotq );
489
+ if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
490
+
491
+ }
492
+
493
+ // second, create bone hierarchy
494
+
495
+ for ( let i = 0, il = geometry.bones.length; i < il; i ++ ) {
496
+
497
+ const gbone = geometry.bones[ i ];
498
+
499
+ if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
500
+
501
+ // subsequent bones in the hierarchy
502
+
503
+ bones[ gbone.parent ].add( bones[ i ] );
504
+
505
+ } else {
506
+
507
+ // topmost bone, immediate child of the skinned mesh
508
+
509
+ mesh.add( bones[ i ] );
510
+
511
+ }
512
+
513
+ }
514
+
515
+ }
516
+
517
+ // now the bones are part of the scene graph and children of the skinned mesh.
518
+ // let's update the corresponding matrices
519
+
520
+ mesh.updateMatrixWorld( true );
521
+
522
+ return bones;
523
+
524
+ }
525
+
526
+ //
527
+
528
+ class GeometryBuilder {
529
+
530
+ /**
531
+ * @param {Object} data - parsed PMD/PMX data
532
+ * @return {BufferGeometry}
533
+ */
534
+ build( data ) {
535
+
536
+ // for geometry
537
+ const positions = [];
538
+ const uvs = [];
539
+ const normals = [];
540
+
541
+ const indices = [];
542
+
543
+ const groups = [];
544
+
545
+ const bones = [];
546
+ const skinIndices = [];
547
+ const skinWeights = [];
548
+
549
+ const morphTargets = [];
550
+ const morphPositions = [];
551
+
552
+ const iks = [];
553
+ const grants = [];
554
+
555
+ const rigidBodies = [];
556
+ const constraints = [];
557
+
558
+ // for work
559
+ let offset = 0;
560
+ const boneTypeTable = {};
561
+
562
+ // positions, normals, uvs, skinIndices, skinWeights
563
+
564
+ for ( let i = 0; i < data.metadata.vertexCount; i ++ ) {
565
+
566
+ const v = data.vertices[ i ];
567
+
568
+ for ( let j = 0, jl = v.position.length; j < jl; j ++ ) {
569
+
570
+ positions.push( v.position[ j ] );
571
+
572
+ }
573
+
574
+ for ( let j = 0, jl = v.normal.length; j < jl; j ++ ) {
575
+
576
+ normals.push( v.normal[ j ] );
577
+
578
+ }
579
+
580
+ for ( let j = 0, jl = v.uv.length; j < jl; j ++ ) {
581
+
582
+ uvs.push( v.uv[ j ] );
583
+
584
+ }
585
+
586
+ for ( let j = 0; j < 4; j ++ ) {
587
+
588
+ skinIndices.push( v.skinIndices.length - 1 >= j ? v.skinIndices[ j ] : 0.0 );
589
+
590
+ }
591
+
592
+ for ( let j = 0; j < 4; j ++ ) {
593
+
594
+ skinWeights.push( v.skinWeights.length - 1 >= j ? v.skinWeights[ j ] : 0.0 );
595
+
596
+ }
597
+
598
+ }
599
+
600
+ // indices
601
+
602
+ for ( let i = 0; i < data.metadata.faceCount; i ++ ) {
603
+
604
+ const face = data.faces[ i ];
605
+
606
+ for ( let j = 0, jl = face.indices.length; j < jl; j ++ ) {
607
+
608
+ indices.push( face.indices[ j ] );
609
+
610
+ }
611
+
612
+ }
613
+
614
+ // groups
615
+
616
+ for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
617
+
618
+ const material = data.materials[ i ];
619
+
620
+ groups.push( {
621
+ offset: offset * 3,
622
+ count: material.faceCount * 3
623
+ } );
624
+
625
+ offset += material.faceCount;
626
+
627
+ }
628
+
629
+ // bones
630
+
631
+ for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
632
+
633
+ const body = data.rigidBodies[ i ];
634
+ let value = boneTypeTable[ body.boneIndex ];
635
+
636
+ // keeps greater number if already value is set without any special reasons
637
+ value = value === undefined ? body.type : Math.max( body.type, value );
638
+
639
+ boneTypeTable[ body.boneIndex ] = value;
640
+
641
+ }
642
+
643
+ for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
644
+
645
+ const boneData = data.bones[ i ];
646
+
647
+ const bone = {
648
+ index: i,
649
+ transformationClass: boneData.transformationClass,
650
+ parent: boneData.parentIndex,
651
+ name: boneData.name,
652
+ pos: boneData.position.slice( 0, 3 ),
653
+ rotq: [ 0, 0, 0, 1 ],
654
+ scl: [ 1, 1, 1 ],
655
+ rigidBodyType: boneTypeTable[ i ] !== undefined ? boneTypeTable[ i ] : - 1
656
+ };
657
+
658
+ if ( bone.parent !== - 1 ) {
659
+
660
+ bone.pos[ 0 ] -= data.bones[ bone.parent ].position[ 0 ];
661
+ bone.pos[ 1 ] -= data.bones[ bone.parent ].position[ 1 ];
662
+ bone.pos[ 2 ] -= data.bones[ bone.parent ].position[ 2 ];
663
+
664
+ }
665
+
666
+ bones.push( bone );
667
+
668
+ }
669
+
670
+ // iks
671
+
672
+ // TODO: remove duplicated codes between PMD and PMX
673
+ if ( data.metadata.format === 'pmd' ) {
674
+
675
+ for ( let i = 0; i < data.metadata.ikCount; i ++ ) {
676
+
677
+ const ik = data.iks[ i ];
678
+
679
+ const param = {
680
+ target: ik.target,
681
+ effector: ik.effector,
682
+ iteration: ik.iteration,
683
+ maxAngle: ik.maxAngle * 4,
684
+ links: []
685
+ };
686
+
687
+ for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
688
+
689
+ const link = {};
690
+ link.index = ik.links[ j ].index;
691
+ link.enabled = true;
692
+
693
+ if ( data.bones[ link.index ].name.indexOf( 'ひざ' ) >= 0 ) {
694
+
695
+ link.limitation = new Vector3( 1.0, 0.0, 0.0 );
696
+
697
+ }
698
+
699
+ param.links.push( link );
700
+
701
+ }
702
+
703
+ iks.push( param );
704
+
705
+ }
706
+
707
+ } else {
708
+
709
+ for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
710
+
711
+ const ik = data.bones[ i ].ik;
712
+
713
+ if ( ik === undefined ) continue;
714
+
715
+ const param = {
716
+ target: i,
717
+ effector: ik.effector,
718
+ iteration: ik.iteration,
719
+ maxAngle: ik.maxAngle,
720
+ links: []
721
+ };
722
+
723
+ for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
724
+
725
+ const link = {};
726
+ link.index = ik.links[ j ].index;
727
+ link.enabled = true;
728
+
729
+ if ( ik.links[ j ].angleLimitation === 1 ) {
730
+
731
+ // Revert if rotationMin/Max doesn't work well
732
+ // link.limitation = new Vector3( 1.0, 0.0, 0.0 );
733
+
734
+ const rotationMin = ik.links[ j ].lowerLimitationAngle;
735
+ const rotationMax = ik.links[ j ].upperLimitationAngle;
736
+
737
+ // Convert Left to Right coordinate by myself because
738
+ // MMDParser doesn't convert. It's a MMDParser's bug
739
+
740
+ const tmp1 = - rotationMax[ 0 ];
741
+ const tmp2 = - rotationMax[ 1 ];
742
+ rotationMax[ 0 ] = - rotationMin[ 0 ];
743
+ rotationMax[ 1 ] = - rotationMin[ 1 ];
744
+ rotationMin[ 0 ] = tmp1;
745
+ rotationMin[ 1 ] = tmp2;
746
+
747
+ link.rotationMin = new Vector3().fromArray( rotationMin );
748
+ link.rotationMax = new Vector3().fromArray( rotationMax );
749
+
750
+ }
751
+
752
+ param.links.push( link );
753
+
754
+ }
755
+
756
+ iks.push( param );
757
+
758
+ // Save the reference even from bone data for efficiently
759
+ // simulating PMX animation system
760
+ bones[ i ].ik = param;
761
+
762
+ }
763
+
764
+ }
765
+
766
+ // grants
767
+
768
+ if ( data.metadata.format === 'pmx' ) {
769
+
770
+ // bone index -> grant entry map
771
+ const grantEntryMap = {};
772
+
773
+ for ( let i = 0; i < data.metadata.boneCount; i ++ ) {
774
+
775
+ const boneData = data.bones[ i ];
776
+ const grant = boneData.grant;
777
+
778
+ if ( grant === undefined ) continue;
779
+
780
+ const param = {
781
+ index: i,
782
+ parentIndex: grant.parentIndex,
783
+ ratio: grant.ratio,
784
+ isLocal: grant.isLocal,
785
+ affectRotation: grant.affectRotation,
786
+ affectPosition: grant.affectPosition,
787
+ transformationClass: boneData.transformationClass
788
+ };
789
+
790
+ grantEntryMap[ i ] = { parent: null, children: [], param: param, visited: false };
791
+
792
+ }
793
+
794
+ const rootEntry = { parent: null, children: [], param: null, visited: false };
795
+
796
+ // Build a tree representing grant hierarchy
797
+
798
+ for ( const boneIndex in grantEntryMap ) {
799
+
800
+ const grantEntry = grantEntryMap[ boneIndex ];
801
+ const parentGrantEntry = grantEntryMap[ grantEntry.parentIndex ] || rootEntry;
802
+
803
+ grantEntry.parent = parentGrantEntry;
804
+ parentGrantEntry.children.push( grantEntry );
805
+
806
+ }
807
+
808
+ // Sort grant parameters from parents to children because
809
+ // grant uses parent's transform that parent's grant is already applied
810
+ // so grant should be applied in order from parents to children
811
+
812
+ function traverse( entry ) {
813
+
814
+ if ( entry.param ) {
815
+
816
+ grants.push( entry.param );
817
+
818
+ // Save the reference even from bone data for efficiently
819
+ // simulating PMX animation system
820
+ bones[ entry.param.index ].grant = entry.param;
821
+
822
+ }
823
+
824
+ entry.visited = true;
825
+
826
+ for ( let i = 0, il = entry.children.length; i < il; i ++ ) {
827
+
828
+ const child = entry.children[ i ];
829
+
830
+ // Cut off a loop if exists. (Is a grant loop invalid?)
831
+ if ( ! child.visited ) traverse( child );
832
+
833
+ }
834
+
835
+ }
836
+
837
+ traverse( rootEntry );
838
+
839
+ }
840
+
841
+ // morph
842
+
843
+ function updateAttributes( attribute, morph, ratio ) {
844
+
845
+ for ( let i = 0; i < morph.elementCount; i ++ ) {
846
+
847
+ const element = morph.elements[ i ];
848
+
849
+ let index;
850
+
851
+ if ( data.metadata.format === 'pmd' ) {
852
+
853
+ index = data.morphs[ 0 ].elements[ element.index ].index;
854
+
855
+ } else {
856
+
857
+ index = element.index;
858
+
859
+ }
860
+
861
+ attribute.array[ index * 3 + 0 ] += element.position[ 0 ] * ratio;
862
+ attribute.array[ index * 3 + 1 ] += element.position[ 1 ] * ratio;
863
+ attribute.array[ index * 3 + 2 ] += element.position[ 2 ] * ratio;
864
+
865
+ }
866
+
867
+ }
868
+
869
+ for ( let i = 0; i < data.metadata.morphCount; i ++ ) {
870
+
871
+ const morph = data.morphs[ i ];
872
+ const params = { name: morph.name };
873
+
874
+ const attribute = new Float32BufferAttribute( data.metadata.vertexCount * 3, 3 );
875
+ attribute.name = morph.name;
876
+
877
+ for ( let j = 0; j < data.metadata.vertexCount * 3; j ++ ) {
878
+
879
+ attribute.array[ j ] = positions[ j ];
880
+
881
+ }
882
+
883
+ if ( data.metadata.format === 'pmd' ) {
884
+
885
+ if ( i !== 0 ) {
886
+
887
+ updateAttributes( attribute, morph, 1.0 );
888
+
889
+ }
890
+
891
+ } else {
892
+
893
+ if ( morph.type === 0 ) { // group
894
+
895
+ for ( let j = 0; j < morph.elementCount; j ++ ) {
896
+
897
+ const morph2 = data.morphs[ morph.elements[ j ].index ];
898
+ const ratio = morph.elements[ j ].ratio;
899
+
900
+ if ( morph2.type === 1 ) {
901
+
902
+ updateAttributes( attribute, morph2, ratio );
903
+
904
+ } else {
905
+
906
+ // TODO: implement
907
+
908
+ }
909
+
910
+ }
911
+
912
+ } else if ( morph.type === 1 ) { // vertex
913
+
914
+ updateAttributes( attribute, morph, 1.0 );
915
+
916
+ } else if ( morph.type === 2 ) { // bone
917
+
918
+ // TODO: implement
919
+
920
+ } else if ( morph.type === 3 ) { // uv
921
+
922
+ // TODO: implement
923
+
924
+ } else if ( morph.type === 4 ) { // additional uv1
925
+
926
+ // TODO: implement
927
+
928
+ } else if ( morph.type === 5 ) { // additional uv2
929
+
930
+ // TODO: implement
931
+
932
+ } else if ( morph.type === 6 ) { // additional uv3
933
+
934
+ // TODO: implement
935
+
936
+ } else if ( morph.type === 7 ) { // additional uv4
937
+
938
+ // TODO: implement
939
+
940
+ } else if ( morph.type === 8 ) { // material
941
+
942
+ // TODO: implement
943
+
944
+ }
945
+
946
+ }
947
+
948
+ morphTargets.push( params );
949
+ morphPositions.push( attribute );
950
+
951
+ }
952
+
953
+ // rigid bodies from rigidBodies field.
954
+
955
+ for ( let i = 0; i < data.metadata.rigidBodyCount; i ++ ) {
956
+
957
+ const rigidBody = data.rigidBodies[ i ];
958
+ const params = {};
959
+
960
+ for ( const key in rigidBody ) {
961
+
962
+ params[ key ] = rigidBody[ key ];
963
+
964
+ }
965
+
966
+ /*
967
+ * RigidBody position parameter in PMX seems global position
968
+ * while the one in PMD seems offset from corresponding bone.
969
+ * So unify being offset.
970
+ */
971
+ if ( data.metadata.format === 'pmx' ) {
972
+
973
+ if ( params.boneIndex !== - 1 ) {
974
+
975
+ const bone = data.bones[ params.boneIndex ];
976
+ params.position[ 0 ] -= bone.position[ 0 ];
977
+ params.position[ 1 ] -= bone.position[ 1 ];
978
+ params.position[ 2 ] -= bone.position[ 2 ];
979
+
980
+ }
981
+
982
+ }
983
+
984
+ rigidBodies.push( params );
985
+
986
+ }
987
+
988
+ // constraints from constraints field.
989
+
990
+ for ( let i = 0; i < data.metadata.constraintCount; i ++ ) {
991
+
992
+ const constraint = data.constraints[ i ];
993
+ const params = {};
994
+
995
+ for ( const key in constraint ) {
996
+
997
+ params[ key ] = constraint[ key ];
998
+
999
+ }
1000
+
1001
+ const bodyA = rigidBodies[ params.rigidBodyIndex1 ];
1002
+ const bodyB = rigidBodies[ params.rigidBodyIndex2 ];
1003
+
1004
+ // Refer to http://www20.atpages.jp/katwat/wp/?p=4135
1005
+ if ( bodyA.type !== 0 && bodyB.type === 2 ) {
1006
+
1007
+ if ( bodyA.boneIndex !== - 1 && bodyB.boneIndex !== - 1 &&
1008
+ data.bones[ bodyB.boneIndex ].parentIndex === bodyA.boneIndex ) {
1009
+
1010
+ bodyB.type = 1;
1011
+
1012
+ }
1013
+
1014
+ }
1015
+
1016
+ constraints.push( params );
1017
+
1018
+ }
1019
+
1020
+ // build BufferGeometry.
1021
+
1022
+ const geometry = new BufferGeometry();
1023
+
1024
+ geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
1025
+ geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
1026
+ geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
1027
+ geometry.setAttribute( 'skinIndex', new Uint16BufferAttribute( skinIndices, 4 ) );
1028
+ geometry.setAttribute( 'skinWeight', new Float32BufferAttribute( skinWeights, 4 ) );
1029
+ geometry.setIndex( indices );
1030
+
1031
+ for ( let i = 0, il = groups.length; i < il; i ++ ) {
1032
+
1033
+ geometry.addGroup( groups[ i ].offset, groups[ i ].count, i );
1034
+
1035
+ }
1036
+
1037
+ geometry.bones = bones;
1038
+
1039
+ geometry.morphTargets = morphTargets;
1040
+ geometry.morphAttributes.position = morphPositions;
1041
+ geometry.morphTargetsRelative = false;
1042
+
1043
+ geometry.userData.MMD = {
1044
+ bones: bones,
1045
+ iks: iks,
1046
+ grants: grants,
1047
+ rigidBodies: rigidBodies,
1048
+ constraints: constraints,
1049
+ format: data.metadata.format
1050
+ };
1051
+
1052
+ geometry.computeBoundingSphere();
1053
+
1054
+ return geometry;
1055
+
1056
+ }
1057
+
1058
+ }
1059
+
1060
+ //
1061
+
1062
+ /**
1063
+ * @param {THREE.LoadingManager} manager
1064
+ */
1065
+ class MaterialBuilder {
1066
+
1067
+ constructor( manager ) {
1068
+
1069
+ this.manager = manager;
1070
+
1071
+ this.textureLoader = new TextureLoader( this.manager );
1072
+ this.tgaLoader = null; // lazy generation
1073
+
1074
+ this.crossOrigin = 'anonymous';
1075
+ this.resourcePath = undefined;
1076
+
1077
+ }
1078
+
1079
+ /**
1080
+ * @param {string} crossOrigin
1081
+ * @return {MaterialBuilder}
1082
+ */
1083
+ setCrossOrigin( crossOrigin ) {
1084
+
1085
+ this.crossOrigin = crossOrigin;
1086
+ return this;
1087
+
1088
+ }
1089
+
1090
+ /**
1091
+ * @param {string} resourcePath
1092
+ * @return {MaterialBuilder}
1093
+ */
1094
+ setResourcePath( resourcePath ) {
1095
+
1096
+ this.resourcePath = resourcePath;
1097
+ return this;
1098
+
1099
+ }
1100
+
1101
+ /**
1102
+ * @param {Object} data - parsed PMD/PMX data
1103
+ * @param {BufferGeometry} geometry - some properties are dependend on geometry
1104
+ * @param {function} onProgress
1105
+ * @param {function} onError
1106
+ * @return {Array<MMDToonMaterial>}
1107
+ */
1108
+ build( data, geometry /*, onProgress, onError */ ) {
1109
+
1110
+ const materials = [];
1111
+
1112
+ const textures = {};
1113
+
1114
+ this.textureLoader.setCrossOrigin( this.crossOrigin );
1115
+
1116
+ // materials
1117
+
1118
+ for ( let i = 0; i < data.metadata.materialCount; i ++ ) {
1119
+
1120
+ const material = data.materials[ i ];
1121
+
1122
+ const params = { userData: { MMD: {} } };
1123
+
1124
+ if ( material.name !== undefined ) params.name = material.name;
1125
+
1126
+ /*
1127
+ * Color
1128
+ *
1129
+ * MMD MMDToonMaterial
1130
+ * ambient - emissive * a
1131
+ * (a = 1.0 without map texture or 0.2 with map texture)
1132
+ *
1133
+ * MMDToonMaterial doesn't have ambient. Set it to emissive instead.
1134
+ * It'll be too bright if material has map texture so using coef 0.2.
1135
+ */
1136
+ params.diffuse = new Color().fromArray( material.diffuse );
1137
+ params.opacity = material.diffuse[ 3 ];
1138
+ params.specular = new Color().fromArray( material.specular );
1139
+ params.shininess = material.shininess;
1140
+ params.emissive = new Color().fromArray( material.ambient );
1141
+ params.transparent = params.opacity !== 1.0;
1142
+
1143
+ params.diffuse.convertSRGBToLinear();
1144
+ params.specular.convertSRGBToLinear();
1145
+ params.emissive.convertSRGBToLinear();
1146
+
1147
+ //
1148
+
1149
+ params.fog = true;
1150
+
1151
+ // blend
1152
+
1153
+ params.blending = CustomBlending;
1154
+ params.blendSrc = SrcAlphaFactor;
1155
+ params.blendDst = OneMinusSrcAlphaFactor;
1156
+ params.blendSrcAlpha = SrcAlphaFactor;
1157
+ params.blendDstAlpha = DstAlphaFactor;
1158
+
1159
+ // side
1160
+
1161
+ if ( data.metadata.format === 'pmx' && ( material.flag & 0x1 ) === 1 ) {
1162
+
1163
+ params.side = DoubleSide;
1164
+
1165
+ } else {
1166
+
1167
+ params.side = params.opacity === 1.0 ? FrontSide : DoubleSide;
1168
+
1169
+ }
1170
+
1171
+ if ( data.metadata.format === 'pmd' ) {
1172
+
1173
+ // map, matcap
1174
+
1175
+ if ( material.fileName ) {
1176
+
1177
+ const fileName = material.fileName;
1178
+ const fileNames = fileName.split( '*' );
1179
+
1180
+ // fileNames[ 0 ]: mapFileName
1181
+ // fileNames[ 1 ]: matcapFileName( optional )
1182
+
1183
+ params.map = this._loadTexture( fileNames[ 0 ], textures );
1184
+
1185
+ if ( fileNames.length > 1 ) {
1186
+
1187
+ const extension = fileNames[ 1 ].slice( - 4 ).toLowerCase();
1188
+
1189
+ params.matcap = this._loadTexture(
1190
+ fileNames[ 1 ],
1191
+ textures
1192
+ );
1193
+
1194
+ params.matcapCombine = extension === '.sph'
1195
+ ? MultiplyOperation
1196
+ : AddOperation;
1197
+
1198
+ }
1199
+
1200
+ }
1201
+
1202
+ // gradientMap
1203
+
1204
+ const toonFileName = ( material.toonIndex === - 1 )
1205
+ ? 'toon00.bmp'
1206
+ : data.toonTextures[ material.toonIndex ].fileName;
1207
+
1208
+ params.gradientMap = this._loadTexture(
1209
+ toonFileName,
1210
+ textures,
1211
+ {
1212
+ isToonTexture: true,
1213
+ isDefaultToonTexture: this._isDefaultToonTexture( toonFileName )
1214
+ }
1215
+ );
1216
+
1217
+ // parameters for OutlineEffect
1218
+
1219
+ params.userData.outlineParameters = {
1220
+ thickness: material.edgeFlag === 1 ? 0.003 : 0.0,
1221
+ color: [ 0, 0, 0 ],
1222
+ alpha: 1.0,
1223
+ visible: material.edgeFlag === 1
1224
+ };
1225
+
1226
+ } else {
1227
+
1228
+ // map
1229
+
1230
+ if ( material.textureIndex !== - 1 ) {
1231
+
1232
+ params.map = this._loadTexture( data.textures[ material.textureIndex ], textures );
1233
+
1234
+ // Since PMX spec don't have standard to list map files except color map and env map,
1235
+ // we need to save file name for further mapping, like matching normal map file names after model loaded.
1236
+ // ref: https://gist.github.com/felixjones/f8a06bd48f9da9a4539f#texture
1237
+ params.userData.MMD.mapFileName = data.textures[ material.textureIndex ];
1238
+
1239
+ }
1240
+
1241
+ // matcap TODO: support m.envFlag === 3
1242
+
1243
+ if ( material.envTextureIndex !== - 1 && ( material.envFlag === 1 || material.envFlag == 2 ) ) {
1244
+
1245
+ params.matcap = this._loadTexture(
1246
+ data.textures[ material.envTextureIndex ],
1247
+ textures
1248
+ );
1249
+
1250
+ // Same as color map above, keep file name in userData for further usage.
1251
+ params.userData.MMD.matcapFileName = data.textures[ material.envTextureIndex ];
1252
+
1253
+ params.matcapCombine = material.envFlag === 1
1254
+ ? MultiplyOperation
1255
+ : AddOperation;
1256
+
1257
+ }
1258
+
1259
+ // gradientMap
1260
+
1261
+ let toonFileName, isDefaultToon;
1262
+
1263
+ if ( material.toonIndex === - 1 || material.toonFlag !== 0 ) {
1264
+
1265
+ toonFileName = 'toon' + ( '0' + ( material.toonIndex + 1 ) ).slice( - 2 ) + '.bmp';
1266
+ isDefaultToon = true;
1267
+
1268
+ } else {
1269
+
1270
+ toonFileName = data.textures[ material.toonIndex ];
1271
+ isDefaultToon = false;
1272
+
1273
+ }
1274
+
1275
+ params.gradientMap = this._loadTexture(
1276
+ toonFileName,
1277
+ textures,
1278
+ {
1279
+ isToonTexture: true,
1280
+ isDefaultToonTexture: isDefaultToon
1281
+ }
1282
+ );
1283
+
1284
+ // parameters for OutlineEffect
1285
+ params.userData.outlineParameters = {
1286
+ thickness: material.edgeSize / 300, // TODO: better calculation?
1287
+ color: material.edgeColor.slice( 0, 3 ),
1288
+ alpha: material.edgeColor[ 3 ],
1289
+ visible: ( material.flag & 0x10 ) !== 0 && material.edgeSize > 0.0
1290
+ };
1291
+
1292
+ }
1293
+
1294
+ if ( params.map !== undefined ) {
1295
+
1296
+ if ( ! params.transparent ) {
1297
+
1298
+ this._checkImageTransparency( params.map, geometry, i );
1299
+
1300
+ }
1301
+
1302
+ params.emissive.multiplyScalar( 0.2 );
1303
+
1304
+ }
1305
+
1306
+ materials.push( new MMDToonMaterial( params ) );
1307
+
1308
+ }
1309
+
1310
+ if ( data.metadata.format === 'pmx' ) {
1311
+
1312
+ // set transparent true if alpha morph is defined.
1313
+
1314
+ function checkAlphaMorph( elements, materials ) {
1315
+
1316
+ for ( let i = 0, il = elements.length; i < il; i ++ ) {
1317
+
1318
+ const element = elements[ i ];
1319
+
1320
+ if ( element.index === - 1 ) continue;
1321
+
1322
+ const material = materials[ element.index ];
1323
+
1324
+ if ( material.opacity !== element.diffuse[ 3 ] ) {
1325
+
1326
+ material.transparent = true;
1327
+
1328
+ }
1329
+
1330
+ }
1331
+
1332
+ }
1333
+
1334
+ for ( let i = 0, il = data.morphs.length; i < il; i ++ ) {
1335
+
1336
+ const morph = data.morphs[ i ];
1337
+ const elements = morph.elements;
1338
+
1339
+ if ( morph.type === 0 ) {
1340
+
1341
+ for ( let j = 0, jl = elements.length; j < jl; j ++ ) {
1342
+
1343
+ const morph2 = data.morphs[ elements[ j ].index ];
1344
+
1345
+ if ( morph2.type !== 8 ) continue;
1346
+
1347
+ checkAlphaMorph( morph2.elements, materials );
1348
+
1349
+ }
1350
+
1351
+ } else if ( morph.type === 8 ) {
1352
+
1353
+ checkAlphaMorph( elements, materials );
1354
+
1355
+ }
1356
+
1357
+ }
1358
+
1359
+ }
1360
+
1361
+ return materials;
1362
+
1363
+ }
1364
+
1365
+ // private methods
1366
+
1367
+ _getTGALoader() {
1368
+
1369
+ if ( this.tgaLoader === null ) {
1370
+
1371
+ if ( TGALoader === undefined ) {
1372
+
1373
+ throw new Error( 'THREE.MMDLoader: Import TGALoader' );
1374
+
1375
+ }
1376
+
1377
+ this.tgaLoader = new TGALoader( this.manager );
1378
+
1379
+ }
1380
+
1381
+ return this.tgaLoader;
1382
+
1383
+ }
1384
+
1385
+ _isDefaultToonTexture( name ) {
1386
+
1387
+ if ( name.length !== 10 ) return false;
1388
+
1389
+ return /toon(10|0[0-9])\.bmp/.test( name );
1390
+
1391
+ }
1392
+
1393
+ _loadTexture( filePath, textures, params, onProgress, onError ) {
1394
+
1395
+ params = params || {};
1396
+
1397
+ const scope = this;
1398
+
1399
+ let fullPath;
1400
+
1401
+ if ( params.isDefaultToonTexture === true ) {
1402
+
1403
+ let index;
1404
+
1405
+ try {
1406
+
1407
+ index = parseInt( filePath.match( /toon([0-9]{2})\.bmp$/ )[ 1 ] );
1408
+
1409
+ } catch ( e ) {
1410
+
1411
+ console.warn( 'THREE.MMDLoader: ' + filePath + ' seems like a '
1412
+ + 'not right default texture path. Using toon00.bmp instead.' );
1413
+
1414
+ index = 0;
1415
+
1416
+ }
1417
+
1418
+ fullPath = DEFAULT_TOON_TEXTURES[ index ];
1419
+
1420
+ } else {
1421
+
1422
+ fullPath = this.resourcePath + filePath;
1423
+
1424
+ }
1425
+
1426
+ if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];
1427
+
1428
+ let loader = this.manager.getHandler( fullPath );
1429
+
1430
+ if ( loader === null ) {
1431
+
1432
+ loader = ( filePath.slice( - 4 ).toLowerCase() === '.tga' )
1433
+ ? this._getTGALoader()
1434
+ : this.textureLoader;
1435
+
1436
+ }
1437
+
1438
+ const texture = loader.load( fullPath, function ( t ) {
1439
+
1440
+ // MMD toon texture is Axis-Y oriented
1441
+ // but Three.js gradient map is Axis-X oriented.
1442
+ // So here replaces the toon texture image with the rotated one.
1443
+ if ( params.isToonTexture === true ) {
1444
+
1445
+ t.image = scope._getRotatedImage( t.image );
1446
+
1447
+ t.magFilter = NearestFilter;
1448
+ t.minFilter = NearestFilter;
1449
+
1450
+ }
1451
+
1452
+ t.flipY = false;
1453
+ t.wrapS = RepeatWrapping;
1454
+ t.wrapT = RepeatWrapping;
1455
+
1456
+ for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
1457
+
1458
+ texture.readyCallbacks[ i ]( texture );
1459
+
1460
+ }
1461
+
1462
+ delete texture.readyCallbacks;
1463
+
1464
+ }, onProgress, onError );
1465
+
1466
+ texture.readyCallbacks = [];
1467
+
1468
+ textures[ fullPath ] = texture;
1469
+
1470
+ return texture;
1471
+
1472
+ }
1473
+
1474
+ _getRotatedImage( image ) {
1475
+
1476
+ const canvas = document.createElement( 'canvas' );
1477
+ const context = canvas.getContext( '2d' );
1478
+
1479
+ const width = image.width;
1480
+ const height = image.height;
1481
+
1482
+ canvas.width = width;
1483
+ canvas.height = height;
1484
+
1485
+ context.clearRect( 0, 0, width, height );
1486
+ context.translate( width / 2.0, height / 2.0 );
1487
+ context.rotate( 0.5 * Math.PI ); // 90.0 * Math.PI / 180.0
1488
+ context.translate( - width / 2.0, - height / 2.0 );
1489
+ context.drawImage( image, 0, 0 );
1490
+
1491
+ return context.getImageData( 0, 0, width, height );
1492
+
1493
+ }
1494
+
1495
+ // Check if the partial image area used by the texture is transparent.
1496
+ _checkImageTransparency( map, geometry, groupIndex ) {
1497
+
1498
+ map.readyCallbacks.push( function ( texture ) {
1499
+
1500
+ // Is there any efficient ways?
1501
+ function createImageData( image ) {
1502
+
1503
+ const canvas = document.createElement( 'canvas' );
1504
+ canvas.width = image.width;
1505
+ canvas.height = image.height;
1506
+
1507
+ const context = canvas.getContext( '2d' );
1508
+ context.drawImage( image, 0, 0 );
1509
+
1510
+ return context.getImageData( 0, 0, canvas.width, canvas.height );
1511
+
1512
+ }
1513
+
1514
+ function detectImageTransparency( image, uvs, indices ) {
1515
+
1516
+ const width = image.width;
1517
+ const height = image.height;
1518
+ const data = image.data;
1519
+ const threshold = 253;
1520
+
1521
+ if ( data.length / ( width * height ) !== 4 ) return false;
1522
+
1523
+ for ( let i = 0; i < indices.length; i += 3 ) {
1524
+
1525
+ const centerUV = { x: 0.0, y: 0.0 };
1526
+
1527
+ for ( let j = 0; j < 3; j ++ ) {
1528
+
1529
+ const index = indices[ i * 3 + j ];
1530
+ const uv = { x: uvs[ index * 2 + 0 ], y: uvs[ index * 2 + 1 ] };
1531
+
1532
+ if ( getAlphaByUv( image, uv ) < threshold ) return true;
1533
+
1534
+ centerUV.x += uv.x;
1535
+ centerUV.y += uv.y;
1536
+
1537
+ }
1538
+
1539
+ centerUV.x /= 3;
1540
+ centerUV.y /= 3;
1541
+
1542
+ if ( getAlphaByUv( image, centerUV ) < threshold ) return true;
1543
+
1544
+ }
1545
+
1546
+ return false;
1547
+
1548
+ }
1549
+
1550
+ /*
1551
+ * This method expects
1552
+ * texture.flipY = false
1553
+ * texture.wrapS = RepeatWrapping
1554
+ * texture.wrapT = RepeatWrapping
1555
+ * TODO: more precise
1556
+ */
1557
+ function getAlphaByUv( image, uv ) {
1558
+
1559
+ const width = image.width;
1560
+ const height = image.height;
1561
+
1562
+ let x = Math.round( uv.x * width ) % width;
1563
+ let y = Math.round( uv.y * height ) % height;
1564
+
1565
+ if ( x < 0 ) x += width;
1566
+ if ( y < 0 ) y += height;
1567
+
1568
+ const index = y * width + x;
1569
+
1570
+ return image.data[ index * 4 + 3 ];
1571
+
1572
+ }
1573
+
1574
+ if ( texture.isCompressedTexture === true ) {
1575
+
1576
+ if ( NON_ALPHA_CHANNEL_FORMATS.includes( texture.format ) ) {
1577
+
1578
+ map.transparent = false;
1579
+
1580
+ } else {
1581
+
1582
+ // any other way to check transparency of CompressedTexture?
1583
+ map.transparent = true;
1584
+
1585
+ }
1586
+
1587
+ return;
1588
+
1589
+ }
1590
+
1591
+ const imageData = texture.image.data !== undefined
1592
+ ? texture.image
1593
+ : createImageData( texture.image );
1594
+
1595
+ const group = geometry.groups[ groupIndex ];
1596
+
1597
+ if ( detectImageTransparency(
1598
+ imageData,
1599
+ geometry.attributes.uv.array,
1600
+ geometry.index.array.slice( group.start, group.start + group.count ) ) ) {
1601
+
1602
+ map.transparent = true;
1603
+
1604
+ }
1605
+
1606
+ } );
1607
+
1608
+ }
1609
+
1610
+ }
1611
+
1612
+ //
1613
+
1614
+ class AnimationBuilder {
1615
+
1616
+ /**
1617
+ * @param {Object} vmd - parsed VMD data
1618
+ * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1619
+ * @return {AnimationClip}
1620
+ */
1621
+ build( vmd, mesh ) {
1622
+
1623
+ // combine skeletal and morph animations
1624
+
1625
+ const tracks = this.buildSkeletalAnimation( vmd, mesh ).tracks;
1626
+ const tracks2 = this.buildMorphAnimation( vmd, mesh ).tracks;
1627
+
1628
+ for ( let i = 0, il = tracks2.length; i < il; i ++ ) {
1629
+
1630
+ tracks.push( tracks2[ i ] );
1631
+
1632
+ }
1633
+
1634
+ return new AnimationClip( '', - 1, tracks );
1635
+
1636
+ }
1637
+
1638
+ /**
1639
+ * @param {Object} vmd - parsed VMD data
1640
+ * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1641
+ * @return {AnimationClip}
1642
+ */
1643
+ buildSkeletalAnimation( vmd, mesh ) {
1644
+
1645
+ function pushInterpolation( array, interpolation, index ) {
1646
+
1647
+ array.push( interpolation[ index + 0 ] / 127 ); // x1
1648
+ array.push( interpolation[ index + 8 ] / 127 ); // x2
1649
+ array.push( interpolation[ index + 4 ] / 127 ); // y1
1650
+ array.push( interpolation[ index + 12 ] / 127 ); // y2
1651
+
1652
+ }
1653
+
1654
+ const tracks = [];
1655
+
1656
+ const motions = {};
1657
+ const bones = mesh.skeleton.bones;
1658
+ const boneNameDictionary = {};
1659
+
1660
+ for ( let i = 0, il = bones.length; i < il; i ++ ) {
1661
+
1662
+ boneNameDictionary[ bones[ i ].name ] = true;
1663
+
1664
+ }
1665
+
1666
+ for ( let i = 0; i < vmd.metadata.motionCount; i ++ ) {
1667
+
1668
+ const motion = vmd.motions[ i ];
1669
+ const boneName = motion.boneName;
1670
+
1671
+ if ( boneNameDictionary[ boneName ] === undefined ) continue;
1672
+
1673
+ motions[ boneName ] = motions[ boneName ] || [];
1674
+ motions[ boneName ].push( motion );
1675
+
1676
+ }
1677
+
1678
+ for ( const key in motions ) {
1679
+
1680
+ const array = motions[ key ];
1681
+
1682
+ array.sort( function ( a, b ) {
1683
+
1684
+ return a.frameNum - b.frameNum;
1685
+
1686
+ } );
1687
+
1688
+ const times = [];
1689
+ const positions = [];
1690
+ const rotations = [];
1691
+ const pInterpolations = [];
1692
+ const rInterpolations = [];
1693
+
1694
+ const basePosition = mesh.skeleton.getBoneByName( key ).position.toArray();
1695
+
1696
+ for ( let i = 0, il = array.length; i < il; i ++ ) {
1697
+
1698
+ const time = array[ i ].frameNum / 30;
1699
+ const position = array[ i ].position;
1700
+ const rotation = array[ i ].rotation;
1701
+ const interpolation = array[ i ].interpolation;
1702
+
1703
+ times.push( time );
1704
+
1705
+ for ( let j = 0; j < 3; j ++ ) positions.push( basePosition[ j ] + position[ j ] );
1706
+ for ( let j = 0; j < 4; j ++ ) rotations.push( rotation[ j ] );
1707
+ for ( let j = 0; j < 3; j ++ ) pushInterpolation( pInterpolations, interpolation, j );
1708
+
1709
+ pushInterpolation( rInterpolations, interpolation, 3 );
1710
+
1711
+ }
1712
+
1713
+ const targetName = '.bones[' + key + ']';
1714
+
1715
+ tracks.push( this._createTrack( targetName + '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
1716
+ tracks.push( this._createTrack( targetName + '.quaternion', QuaternionKeyframeTrack, times, rotations, rInterpolations ) );
1717
+
1718
+ }
1719
+
1720
+ return new AnimationClip( '', - 1, tracks );
1721
+
1722
+ }
1723
+
1724
+ /**
1725
+ * @param {Object} vmd - parsed VMD data
1726
+ * @param {SkinnedMesh} mesh - tracks will be fitting to mesh
1727
+ * @return {AnimationClip}
1728
+ */
1729
+ buildMorphAnimation( vmd, mesh ) {
1730
+
1731
+ const tracks = [];
1732
+
1733
+ const morphs = {};
1734
+ const morphTargetDictionary = mesh.morphTargetDictionary;
1735
+
1736
+ for ( let i = 0; i < vmd.metadata.morphCount; i ++ ) {
1737
+
1738
+ const morph = vmd.morphs[ i ];
1739
+ const morphName = morph.morphName;
1740
+
1741
+ if ( morphTargetDictionary[ morphName ] === undefined ) continue;
1742
+
1743
+ morphs[ morphName ] = morphs[ morphName ] || [];
1744
+ morphs[ morphName ].push( morph );
1745
+
1746
+ }
1747
+
1748
+ for ( const key in morphs ) {
1749
+
1750
+ const array = morphs[ key ];
1751
+
1752
+ array.sort( function ( a, b ) {
1753
+
1754
+ return a.frameNum - b.frameNum;
1755
+
1756
+ } );
1757
+
1758
+ const times = [];
1759
+ const values = [];
1760
+
1761
+ for ( let i = 0, il = array.length; i < il; i ++ ) {
1762
+
1763
+ times.push( array[ i ].frameNum / 30 );
1764
+ values.push( array[ i ].weight );
1765
+
1766
+ }
1767
+
1768
+ tracks.push( new NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetDictionary[ key ] + ']', times, values ) );
1769
+
1770
+ }
1771
+
1772
+ return new AnimationClip( '', - 1, tracks );
1773
+
1774
+ }
1775
+
1776
+ /**
1777
+ * @param {Object} vmd - parsed VMD data
1778
+ * @return {AnimationClip}
1779
+ */
1780
+ buildCameraAnimation( vmd ) {
1781
+
1782
+ function pushVector3( array, vec ) {
1783
+
1784
+ array.push( vec.x );
1785
+ array.push( vec.y );
1786
+ array.push( vec.z );
1787
+
1788
+ }
1789
+
1790
+ function pushQuaternion( array, q ) {
1791
+
1792
+ array.push( q.x );
1793
+ array.push( q.y );
1794
+ array.push( q.z );
1795
+ array.push( q.w );
1796
+
1797
+ }
1798
+
1799
+ function pushInterpolation( array, interpolation, index ) {
1800
+
1801
+ array.push( interpolation[ index * 4 + 0 ] / 127 ); // x1
1802
+ array.push( interpolation[ index * 4 + 1 ] / 127 ); // x2
1803
+ array.push( interpolation[ index * 4 + 2 ] / 127 ); // y1
1804
+ array.push( interpolation[ index * 4 + 3 ] / 127 ); // y2
1805
+
1806
+ }
1807
+
1808
+ const cameras = vmd.cameras === undefined ? [] : vmd.cameras.slice();
1809
+
1810
+ cameras.sort( function ( a, b ) {
1811
+
1812
+ return a.frameNum - b.frameNum;
1813
+
1814
+ } );
1815
+
1816
+ const times = [];
1817
+ const centers = [];
1818
+ const quaternions = [];
1819
+ const positions = [];
1820
+ const fovs = [];
1821
+
1822
+ const cInterpolations = [];
1823
+ const qInterpolations = [];
1824
+ const pInterpolations = [];
1825
+ const fInterpolations = [];
1826
+
1827
+ const quaternion = new Quaternion();
1828
+ const euler = new Euler();
1829
+ const position = new Vector3();
1830
+ const center = new Vector3();
1831
+
1832
+ for ( let i = 0, il = cameras.length; i < il; i ++ ) {
1833
+
1834
+ const motion = cameras[ i ];
1835
+
1836
+ const time = motion.frameNum / 30;
1837
+ const pos = motion.position;
1838
+ const rot = motion.rotation;
1839
+ const distance = motion.distance;
1840
+ const fov = motion.fov;
1841
+ const interpolation = motion.interpolation;
1842
+
1843
+ times.push( time );
1844
+
1845
+ position.set( 0, 0, - distance );
1846
+ center.set( pos[ 0 ], pos[ 1 ], pos[ 2 ] );
1847
+
1848
+ euler.set( - rot[ 0 ], - rot[ 1 ], - rot[ 2 ] );
1849
+ quaternion.setFromEuler( euler );
1850
+
1851
+ position.add( center );
1852
+ position.applyQuaternion( quaternion );
1853
+
1854
+ pushVector3( centers, center );
1855
+ pushQuaternion( quaternions, quaternion );
1856
+ pushVector3( positions, position );
1857
+
1858
+ fovs.push( fov );
1859
+
1860
+ for ( let j = 0; j < 3; j ++ ) {
1861
+
1862
+ pushInterpolation( cInterpolations, interpolation, j );
1863
+
1864
+ }
1865
+
1866
+ pushInterpolation( qInterpolations, interpolation, 3 );
1867
+
1868
+ // use the same parameter for x, y, z axis.
1869
+ for ( let j = 0; j < 3; j ++ ) {
1870
+
1871
+ pushInterpolation( pInterpolations, interpolation, 4 );
1872
+
1873
+ }
1874
+
1875
+ pushInterpolation( fInterpolations, interpolation, 5 );
1876
+
1877
+ }
1878
+
1879
+ const tracks = [];
1880
+
1881
+ // I expect an object whose name 'target' exists under THREE.Camera
1882
+ tracks.push( this._createTrack( 'target.position', VectorKeyframeTrack, times, centers, cInterpolations ) );
1883
+
1884
+ tracks.push( this._createTrack( '.quaternion', QuaternionKeyframeTrack, times, quaternions, qInterpolations ) );
1885
+ tracks.push( this._createTrack( '.position', VectorKeyframeTrack, times, positions, pInterpolations ) );
1886
+ tracks.push( this._createTrack( '.fov', NumberKeyframeTrack, times, fovs, fInterpolations ) );
1887
+
1888
+ return new AnimationClip( '', - 1, tracks );
1889
+
1890
+ }
1891
+
1892
+ // private method
1893
+
1894
+ _createTrack( node, typedKeyframeTrack, times, values, interpolations ) {
1895
+
1896
+ /*
1897
+ * optimizes here not to let KeyframeTrackPrototype optimize
1898
+ * because KeyframeTrackPrototype optimizes times and values but
1899
+ * doesn't optimize interpolations.
1900
+ */
1901
+ if ( times.length > 2 ) {
1902
+
1903
+ times = times.slice();
1904
+ values = values.slice();
1905
+ interpolations = interpolations.slice();
1906
+
1907
+ const stride = values.length / times.length;
1908
+ const interpolateStride = interpolations.length / times.length;
1909
+
1910
+ let index = 1;
1911
+
1912
+ for ( let aheadIndex = 2, endIndex = times.length; aheadIndex < endIndex; aheadIndex ++ ) {
1913
+
1914
+ for ( let i = 0; i < stride; i ++ ) {
1915
+
1916
+ if ( values[ index * stride + i ] !== values[ ( index - 1 ) * stride + i ] ||
1917
+ values[ index * stride + i ] !== values[ aheadIndex * stride + i ] ) {
1918
+
1919
+ index ++;
1920
+ break;
1921
+
1922
+ }
1923
+
1924
+ }
1925
+
1926
+ if ( aheadIndex > index ) {
1927
+
1928
+ times[ index ] = times[ aheadIndex ];
1929
+
1930
+ for ( let i = 0; i < stride; i ++ ) {
1931
+
1932
+ values[ index * stride + i ] = values[ aheadIndex * stride + i ];
1933
+
1934
+ }
1935
+
1936
+ for ( let i = 0; i < interpolateStride; i ++ ) {
1937
+
1938
+ interpolations[ index * interpolateStride + i ] = interpolations[ aheadIndex * interpolateStride + i ];
1939
+
1940
+ }
1941
+
1942
+ }
1943
+
1944
+ }
1945
+
1946
+ times.length = index + 1;
1947
+ values.length = ( index + 1 ) * stride;
1948
+ interpolations.length = ( index + 1 ) * interpolateStride;
1949
+
1950
+ }
1951
+
1952
+ const track = new typedKeyframeTrack( node, times, values );
1953
+
1954
+ track.createInterpolant = function InterpolantFactoryMethodCubicBezier( result ) {
1955
+
1956
+ return new CubicBezierInterpolation( this.times, this.values, this.getValueSize(), result, new Float32Array( interpolations ) );
1957
+
1958
+ };
1959
+
1960
+ return track;
1961
+
1962
+ }
1963
+
1964
+ }
1965
+
1966
+ // interpolation
1967
+
1968
+ class CubicBezierInterpolation extends Interpolant {
1969
+
1970
+ constructor( parameterPositions, sampleValues, sampleSize, resultBuffer, params ) {
1971
+
1972
+ super( parameterPositions, sampleValues, sampleSize, resultBuffer );
1973
+
1974
+ this.interpolationParams = params;
1975
+
1976
+ }
1977
+
1978
+ interpolate_( i1, t0, t, t1 ) {
1979
+
1980
+ const result = this.resultBuffer;
1981
+ const values = this.sampleValues;
1982
+ const stride = this.valueSize;
1983
+ const params = this.interpolationParams;
1984
+
1985
+ const offset1 = i1 * stride;
1986
+ const offset0 = offset1 - stride;
1987
+
1988
+ // No interpolation if next key frame is in one frame in 30fps.
1989
+ // This is from MMD animation spec.
1990
+ // '1.5' is for precision loss. times are Float32 in Three.js Animation system.
1991
+ const weight1 = ( ( t1 - t0 ) < 1 / 30 * 1.5 ) ? 0.0 : ( t - t0 ) / ( t1 - t0 );
1992
+
1993
+ if ( stride === 4 ) { // Quaternion
1994
+
1995
+ const x1 = params[ i1 * 4 + 0 ];
1996
+ const x2 = params[ i1 * 4 + 1 ];
1997
+ const y1 = params[ i1 * 4 + 2 ];
1998
+ const y2 = params[ i1 * 4 + 3 ];
1999
+
2000
+ const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2001
+
2002
+ Quaternion.slerpFlat( result, 0, values, offset0, values, offset1, ratio );
2003
+
2004
+ } else if ( stride === 3 ) { // Vector3
2005
+
2006
+ for ( let i = 0; i !== stride; ++ i ) {
2007
+
2008
+ const x1 = params[ i1 * 12 + i * 4 + 0 ];
2009
+ const x2 = params[ i1 * 12 + i * 4 + 1 ];
2010
+ const y1 = params[ i1 * 12 + i * 4 + 2 ];
2011
+ const y2 = params[ i1 * 12 + i * 4 + 3 ];
2012
+
2013
+ const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2014
+
2015
+ result[ i ] = values[ offset0 + i ] * ( 1 - ratio ) + values[ offset1 + i ] * ratio;
2016
+
2017
+ }
2018
+
2019
+ } else { // Number
2020
+
2021
+ const x1 = params[ i1 * 4 + 0 ];
2022
+ const x2 = params[ i1 * 4 + 1 ];
2023
+ const y1 = params[ i1 * 4 + 2 ];
2024
+ const y2 = params[ i1 * 4 + 3 ];
2025
+
2026
+ const ratio = this._calculate( x1, x2, y1, y2, weight1 );
2027
+
2028
+ result[ 0 ] = values[ offset0 ] * ( 1 - ratio ) + values[ offset1 ] * ratio;
2029
+
2030
+ }
2031
+
2032
+ return result;
2033
+
2034
+ }
2035
+
2036
+ _calculate( x1, x2, y1, y2, x ) {
2037
+
2038
+ /*
2039
+ * Cubic Bezier curves
2040
+ * https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves
2041
+ *
2042
+ * B(t) = ( 1 - t ) ^ 3 * P0
2043
+ * + 3 * ( 1 - t ) ^ 2 * t * P1
2044
+ * + 3 * ( 1 - t ) * t^2 * P2
2045
+ * + t ^ 3 * P3
2046
+ * ( 0 <= t <= 1 )
2047
+ *
2048
+ * MMD uses Cubic Bezier curves for bone and camera animation interpolation.
2049
+ * http://d.hatena.ne.jp/edvakf/20111016/1318716097
2050
+ *
2051
+ * x = ( 1 - t ) ^ 3 * x0
2052
+ * + 3 * ( 1 - t ) ^ 2 * t * x1
2053
+ * + 3 * ( 1 - t ) * t^2 * x2
2054
+ * + t ^ 3 * x3
2055
+ * y = ( 1 - t ) ^ 3 * y0
2056
+ * + 3 * ( 1 - t ) ^ 2 * t * y1
2057
+ * + 3 * ( 1 - t ) * t^2 * y2
2058
+ * + t ^ 3 * y3
2059
+ * ( x0 = 0, y0 = 0 )
2060
+ * ( x3 = 1, y3 = 1 )
2061
+ * ( 0 <= t, x1, x2, y1, y2 <= 1 )
2062
+ *
2063
+ * Here solves this equation with Bisection method,
2064
+ * https://en.wikipedia.org/wiki/Bisection_method
2065
+ * gets t, and then calculate y.
2066
+ *
2067
+ * f(t) = 3 * ( 1 - t ) ^ 2 * t * x1
2068
+ * + 3 * ( 1 - t ) * t^2 * x2
2069
+ * + t ^ 3 - x = 0
2070
+ *
2071
+ * (Another option: Newton's method
2072
+ * https://en.wikipedia.org/wiki/Newton%27s_method)
2073
+ */
2074
+
2075
+ let c = 0.5;
2076
+ let t = c;
2077
+ let s = 1.0 - t;
2078
+ const loop = 15;
2079
+ const eps = 1e-5;
2080
+ const math = Math;
2081
+
2082
+ let sst3, stt3, ttt;
2083
+
2084
+ for ( let i = 0; i < loop; i ++ ) {
2085
+
2086
+ sst3 = 3.0 * s * s * t;
2087
+ stt3 = 3.0 * s * t * t;
2088
+ ttt = t * t * t;
2089
+
2090
+ const ft = ( sst3 * x1 ) + ( stt3 * x2 ) + ( ttt ) - x;
2091
+
2092
+ if ( math.abs( ft ) < eps ) break;
2093
+
2094
+ c /= 2.0;
2095
+
2096
+ t += ( ft < 0 ) ? c : - c;
2097
+ s = 1.0 - t;
2098
+
2099
+ }
2100
+
2101
+ return ( sst3 * y1 ) + ( stt3 * y2 ) + ttt;
2102
+
2103
+ }
2104
+
2105
+ }
2106
+
2107
+ class MMDToonMaterial extends ShaderMaterial {
2108
+
2109
+ constructor( parameters ) {
2110
+
2111
+ super();
2112
+
2113
+ this.isMMDToonMaterial = true;
2114
+
2115
+ this.type = 'MMDToonMaterial';
2116
+
2117
+ this._matcapCombine = AddOperation;
2118
+ this.emissiveIntensity = 1.0;
2119
+ this.normalMapType = TangentSpaceNormalMap;
2120
+
2121
+ this.combine = MultiplyOperation;
2122
+
2123
+ this.wireframeLinecap = 'round';
2124
+ this.wireframeLinejoin = 'round';
2125
+
2126
+ this.flatShading = false;
2127
+
2128
+ this.lights = true;
2129
+
2130
+ this.vertexShader = MMDToonShader.vertexShader;
2131
+ this.fragmentShader = MMDToonShader.fragmentShader;
2132
+
2133
+ this.defines = Object.assign( {}, MMDToonShader.defines );
2134
+ Object.defineProperty( this, 'matcapCombine', {
2135
+
2136
+ get: function () {
2137
+
2138
+ return this._matcapCombine;
2139
+
2140
+ },
2141
+
2142
+ set: function ( value ) {
2143
+
2144
+ this._matcapCombine = value;
2145
+
2146
+ switch ( value ) {
2147
+
2148
+ case MultiplyOperation:
2149
+ this.defines.MATCAP_BLENDING_MULTIPLY = true;
2150
+ delete this.defines.MATCAP_BLENDING_ADD;
2151
+ break;
2152
+
2153
+ default:
2154
+ case AddOperation:
2155
+ this.defines.MATCAP_BLENDING_ADD = true;
2156
+ delete this.defines.MATCAP_BLENDING_MULTIPLY;
2157
+ break;
2158
+
2159
+ }
2160
+
2161
+ },
2162
+
2163
+ } );
2164
+
2165
+ this.uniforms = UniformsUtils.clone( MMDToonShader.uniforms );
2166
+
2167
+ // merged from MeshToon/Phong/MatcapMaterial
2168
+ const exposePropertyNames = [
2169
+ 'specular',
2170
+ 'opacity',
2171
+ 'diffuse',
2172
+
2173
+ 'map',
2174
+ 'matcap',
2175
+ 'gradientMap',
2176
+
2177
+ 'lightMap',
2178
+ 'lightMapIntensity',
2179
+
2180
+ 'aoMap',
2181
+ 'aoMapIntensity',
2182
+
2183
+ 'emissive',
2184
+ 'emissiveMap',
2185
+
2186
+ 'bumpMap',
2187
+ 'bumpScale',
2188
+
2189
+ 'normalMap',
2190
+ 'normalScale',
2191
+
2192
+ 'displacemantBias',
2193
+ 'displacemantMap',
2194
+ 'displacemantScale',
2195
+
2196
+ 'specularMap',
2197
+
2198
+ 'alphaMap',
2199
+
2200
+ 'reflectivity',
2201
+ 'refractionRatio',
2202
+ ];
2203
+ for ( const propertyName of exposePropertyNames ) {
2204
+
2205
+ Object.defineProperty( this, propertyName, {
2206
+
2207
+ get: function () {
2208
+
2209
+ return this.uniforms[ propertyName ].value;
2210
+
2211
+ },
2212
+
2213
+ set: function ( value ) {
2214
+
2215
+ this.uniforms[ propertyName ].value = value;
2216
+
2217
+ },
2218
+
2219
+ } );
2220
+
2221
+ }
2222
+
2223
+ // Special path for shininess to handle zero shininess properly
2224
+ this._shininess = 30;
2225
+ Object.defineProperty( this, 'shininess', {
2226
+
2227
+ get: function () {
2228
+
2229
+ return this._shininess;
2230
+
2231
+ },
2232
+
2233
+ set: function ( value ) {
2234
+
2235
+ this._shininess = value;
2236
+ this.uniforms.shininess.value = Math.max( this._shininess, 1e-4 ); // To prevent pow( 0.0, 0.0 )
2237
+
2238
+ },
2239
+
2240
+ } );
2241
+
2242
+ Object.defineProperty(
2243
+ this,
2244
+ 'color',
2245
+ Object.getOwnPropertyDescriptor( this, 'diffuse' )
2246
+ );
2247
+
2248
+ this.setValues( parameters );
2249
+
2250
+ }
2251
+
2252
+ copy( source ) {
2253
+
2254
+ super.copy( source );
2255
+
2256
+ this.matcapCombine = source.matcapCombine;
2257
+ this.emissiveIntensity = source.emissiveIntensity;
2258
+ this.normalMapType = source.normalMapType;
2259
+
2260
+ this.combine = source.combine;
2261
+
2262
+ this.wireframeLinecap = source.wireframeLinecap;
2263
+ this.wireframeLinejoin = source.wireframeLinejoin;
2264
+
2265
+ this.flatShading = source.flatShading;
2266
+
2267
+ return this;
2268
+
2269
+ }
2270
+
2271
+ }
2272
+
2273
+ export { MMDLoader };