DragControls.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>DragControls - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Controls.html">Controls</a> → </p>
  13. <h1 translate="no">DragControls</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This class can be used to provide a drag'n'drop interaction.</p></div>
  17. <h2>Code Example</h2>
  18. <div translate="no"><pre><code class="language-js">const controls = new DragControls( objects, camera, renderer.domElement );
  19. // add event listener to highlight dragged objects
  20. controls.addEventListener( 'dragstart', function ( event ) {
  21. event.object.material.emissive.set( 0xaaaaaa );
  22. } );
  23. controls.addEventListener( 'dragend', function ( event ) {
  24. event.object.material.emissive.set( 0x000000 );
  25. } );
  26. </code></pre></div>
  27. </header>
  28. <article>
  29. <h2 class="subsection-title">Import</h2>
  30. <p><span translate="no">DragControls</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank" rel="noopener">Installation#Addons</a>.</p>
  31. <pre><code class="language-js">import { DragControls } from 'three/addons/controls/DragControls.js';</code></pre>
  32. <div class="container-overview">
  33. <h2>Constructor</h2>
  34. <h3 class="name name-method" id="DragControls" translate="no">new <a href="#DragControls">DragControls</a><span class="signature">( objects : <span class="param-type">Array.&lt;<a href="Object3D.html">Object3D</a>></span>, camera : <span class="param-type"><a href="Camera.html">Camera</a></span>, domElement : <span class="param-type">HTMLElement</span> )</span> </h3>
  35. <div class="method">
  36. <div class="description">
  37. <p>Constructs a new controls instance.</p>
  38. </div>
  39. <table class="params">
  40. <tbody>
  41. <tr>
  42. <td class="name">
  43. <strong>objects</strong>
  44. </td>
  45. <td class="description last">
  46. <p>An array of draggable 3D objects.</p>
  47. </td>
  48. </tr>
  49. <tr>
  50. <td class="name">
  51. <strong>camera</strong>
  52. </td>
  53. <td class="description last">
  54. <p>The camera of the rendered scene.</p>
  55. </td>
  56. </tr>
  57. <tr>
  58. <td class="name">
  59. <strong>domElement</strong>
  60. </td>
  61. <td class="description last">
  62. <p>The HTML DOM element used for event listeners.</p>
  63. <p>Default is <code>null</code>.</p>
  64. </td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. </div>
  69. </div>
  70. <h2 class="subsection-title">Properties</h2>
  71. <div class="member">
  72. <h3 class="name" id="objects" translate="no">.<a href="#objects">objects</a><span class="type-signature"> : Array.&lt;<a href="Object3D.html">Object3D</a>></span> </h3>
  73. <div class="description">
  74. <p>An array of draggable 3D objects.</p>
  75. </div>
  76. </div>
  77. <div class="member">
  78. <h3 class="name" id="raycaster" translate="no">.<a href="#raycaster">raycaster</a><span class="type-signature"> : <a href="Raycaster.html">Raycaster</a></span> </h3>
  79. <div class="description">
  80. <p>The raycaster used for detecting 3D objects.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="recursive" translate="no">.<a href="#recursive">recursive</a><span class="type-signature"> : boolean</span> </h3>
  85. <div class="description">
  86. <p>Whether children of draggable objects can be dragged independently from their parent.</p>
  87. <p>Default is <code>true</code>.</p>
  88. </div>
  89. </div>
  90. <div class="member">
  91. <h3 class="name" id="rotateSpeed" translate="no">.<a href="#rotateSpeed">rotateSpeed</a><span class="type-signature"> : number</span> </h3>
  92. <div class="description">
  93. <p>The speed at which the object will rotate when dragged in <code>rotate</code> mode.
  94. The higher the number the faster the rotation.</p>
  95. <p>Default is <code>1</code>.</p>
  96. </div>
  97. </div>
  98. <div class="member">
  99. <h3 class="name" id="transformGroup" translate="no">.<a href="#transformGroup">transformGroup</a><span class="type-signature"> : boolean</span> </h3>
  100. <div class="description">
  101. <p>This option only works if the <code>objects</code> array contains a single draggable group object.
  102. If set to <code>true</code>, the controls does not transform individual objects but the entire group.</p>
  103. <p>Default is <code>false</code>.</p>
  104. </div>
  105. </div>
  106. <h2 class="subsection-title">Events</h2>
  107. <h3 class="name name-method" id="event:drag" translate="no">.<a href="#event:drag">drag</a> </h3>
  108. <div class="method">
  109. <div class="description">
  110. <p>Fires when the user drags a 3D object.</p>
  111. </div>
  112. <h5>Type:</h5>
  113. <ul>
  114. <li>
  115. <span class="param-type">Object</span>
  116. </li>
  117. </ul>
  118. </div>
  119. <h3 class="name name-method" id="event:dragend" translate="no">.<a href="#event:dragend">dragend</a> </h3>
  120. <div class="method">
  121. <div class="description">
  122. <p>Fires when the user has finished dragging a 3D object.</p>
  123. </div>
  124. <h5>Type:</h5>
  125. <ul>
  126. <li>
  127. <span class="param-type">Object</span>
  128. </li>
  129. </ul>
  130. </div>
  131. <h3 class="name name-method" id="event:hoveroff" translate="no">.<a href="#event:hoveroff">hoveroff</a> </h3>
  132. <div class="method">
  133. <div class="description">
  134. <p>Fires when the pointer is moved out of a 3D object.</p>
  135. </div>
  136. <h5>Type:</h5>
  137. <ul>
  138. <li>
  139. <span class="param-type">Object</span>
  140. </li>
  141. </ul>
  142. </div>
  143. <h3 class="name name-method" id="event:hoveron" translate="no">.<a href="#event:hoveron">hoveron</a> </h3>
  144. <div class="method">
  145. <div class="description">
  146. <p>Fires when the pointer is moved onto a 3D object, or onto one of its children.</p>
  147. </div>
  148. <h5>Type:</h5>
  149. <ul>
  150. <li>
  151. <span class="param-type">Object</span>
  152. </li>
  153. </ul>
  154. </div>
  155. <h2 class="subsection-title">Source</h2>
  156. <p>
  157. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/DragControls.js" translate="no" target="_blank" rel="noopener">examples/jsm/controls/DragControls.js</a>
  158. </p>
  159. </article>
  160. </section>
  161. <script src="../scripts/linenumber.js"></script>
  162. <script src="../scripts/page.js"></script>
  163. </body>
  164. </html>
粤ICP备19079148号