MMDAnimationHelper.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc"> A animation helper for <a href="https://sites.google.com/view/evpvp/"><em>MMD</em></a> resources. <br /><br />
  12. [name] handles animation of MMD assets loaded by [page:MMDLoader] with MMD special features as IK, Grant, and Physics.
  13. It uses [page:CCDIKSolver] and [page:MMDPhysics] inside.
  14. </p>
  15. <h2>Code Example</h2>
  16. <code>
  17. // Instantiate a helper
  18. const helper = new MMDAnimationHelper();
  19. // Load MMD resources and add to helper
  20. new MMDLoader().loadWithAnimation(
  21. 'models/mmd/miku.pmd',
  22. 'models/mmd/dance.vmd',
  23. function ( mmd ) {
  24. helper.add( mmd.mesh, {
  25. animation: mmd.animation,
  26. physics: true
  27. } );
  28. scene.add( mmd.mesh );
  29. new THREE.AudioLoader().load(
  30. 'audios/mmd/song.mp3',
  31. function ( buffer ) {
  32. const listener = new THREE.AudioListener();
  33. const audio = new THREE.Audio( listener ).setBuffer( buffer );
  34. listener.position.z = 1;
  35. scene.add( audio );
  36. scene.add( listener );
  37. }
  38. );
  39. }
  40. );
  41. function render() {
  42. helper.update( clock.getDelta() );
  43. renderer.render( scene, camera );
  44. }
  45. </code>
  46. <h2>Examples</h2>
  47. <p>
  48. [example:webgl_loader_mmd]<br />
  49. [example:webgl_loader_mmd_pose]<br />
  50. [example:webgl_loader_mmd_audio]
  51. </p>
  52. <h2>Constructor</h2>
  53. <h3>[name]( [param:Object params] )</h3>
  54. <p>
  55. [page:Object params] — (optional)<br />
  56. <ul>
  57. <li> [page:Boolean sync] - Whether animation durations of added objects are synched. Default is true.</li>
  58. <li> [page:Number afterglow] - Default is 0.0.</li>
  59. <li> [page:Boolean resetPhysicsOnLoop] - Default is true.</li>
  60. <li> [page:Boolean pmxAnimation] - If it is set to true, the helper follows the complex and costly PMX animation system.
  61. Try this option only if your PMX model animation doesn't work well. Default is false.</li>
  62. </ul>
  63. </p>
  64. <p>
  65. Creates a new [name].
  66. </p>
  67. <h2>Properties</h2>
  68. <h3>[property:Audio audio]</h3>
  69. <p>An [page:Audio] added to helper.</p>
  70. <h3>[property:Camera camera]</h3>
  71. <p>An [page:Camera] added to helper.</p>
  72. <h3>[property:Array meshes]</h3>
  73. <p>An array of [page:SkinnedMesh] added to helper.</p>
  74. <h3>[property:WeakMap objects]</h3>
  75. <p>A [page:WeakMap] which holds animation stuffs used in helper for objects added to helper. For example, you can access [page:AnimationMixer] for an added [page:SkinnedMesh] with "helper.objects.get( mesh ).mixer"</p>
  76. <h3>[property:Function onBeforePhysics]</h3>
  77. <p>An optional callback that is executed immediately before the physicis calculation for an [page:SkinnedMesh]. This function is called with the [page:SkinnedMesh].</p>
  78. <h2>Methods</h2>
  79. <h3>[method:MMDAnimationHelper add]( [param:Object3D object], [param:Object params] )</h3>
  80. <p>
  81. [page:Object3D object] — [page:SkinnedMesh], [page:Camera], or [page:Audio]<br />
  82. [page:Object params] — (optional)<br />
  83. <ul>
  84. <li>[page:AnimationClip animation] - an [page:AnimationClip] or an array of [page:AnimationClip] set to object. Only for [page:SkinnedMesh] and [page:Camera]. Default is undefined.</li>
  85. <li>[page:Boolean physics] - Only for [page:SkinnedMesh]. A flag whether turn on physics. Default is true.</li>
  86. <li>[page:Integer warmup] - Only for [page:SkinnedMesh] and physics is true. Physics parameter. Default is 60.</li>
  87. <li>[page:Number unitStep] - Only for [page:SkinnedMesh] and physics is true. Physics parameter. Default is 1 / 65.</li>
  88. <li>[page:Integer maxStepNum] - Only for [page:SkinnedMesh] and physics is true. Physics parameter. Default is 3.</li>
  89. <li>[page:Vector3 gravity] - Only for [page:SkinnedMesh] and physics is true. Physics parameter. Default is ( 0, - 9.8 * 10, 0 ).</li>
  90. <li>[page:Number delayTime] - Only for [page:Audio]. Default is 0.0.</li>
  91. </ul>
  92. </p>
  93. <p>
  94. Add an [page:SkinnedMesh], [page:Camera], or [page:Audio] to helper and setup animation. The anmation durations of added objects are synched.
  95. If camera/audio has already been added, it'll be replaced with a new one.
  96. </p>
  97. <h3>[method:MMDAnimationHelper enable]( [param:String key], [param:Boolean enabled] )</h3>
  98. <p>
  99. [page:String key] — Allowed strings are 'animation', 'ik', 'grant', 'physics', and 'cameraAnimation'.<br />
  100. [page:Boolean enabled] — true is enable, false is disable<br />
  101. </p>
  102. <p>
  103. Enable/Disable an animation feature
  104. </p>
  105. <h3>[method:MMDAnimationHelper pose]( [param:SkinnedMesh mesh], [param:Object vpd], [param:Object params] )</h3>
  106. <p>
  107. [page:SkinnedMesh mesh] — [page:SkinnedMesh] which changes the posing. It doesn't need to be added to helper.<br />
  108. [page:Object vpd] — VPD content obtained by [page:MMDLoader].loadVPD<br />
  109. [page:Object params] — (optional)<br />
  110. <ul>
  111. <li>[page:Boolean resetPose] - Default is true.</li>
  112. <li>[page:Boolean ik] - Default is true.</li>
  113. <li>[page:Boolean grant] - Default is true.</li>
  114. </ul>
  115. </p>
  116. <p>
  117. Changes the posing of [page:SkinnedMesh] as VPD content specifies.
  118. </p>
  119. <h3>[method:MMDAnimationHelper remove]( [param:Object3D object] )</h3>
  120. <p>
  121. [page:Object3D object] — [page:SkinnedMesh], [page:Camera], or [page:Audio]<br />
  122. </p>
  123. <p>
  124. Remove an [page:SkinnedMesh], [page:Camera], or [page:Audio] from helper.
  125. </p>
  126. <h3>[method:MMDAnimationHelper update]( [param:Number delta] )</h3>
  127. <p>
  128. [page:Number delta] — number in second<br />
  129. </p>
  130. <p>
  131. Advance mixer time and update the animations of objects added to helper
  132. </p>
  133. <h2>Source</h2>
  134. <p>
  135. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/animation/MMDAnimationHelper.js examples/jsm/animation/MMDAnimationHelper.js]
  136. </p>
  137. </body>
  138. </html>