DragControls.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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">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;Object3D></span>, camera : <span class="param-type">Camera</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"><code>objects</code></td>
  43. <td class="description last"><p>An array of draggable 3D objects.</p></td>
  44. </tr>
  45. <tr>
  46. <td class="name"><code>camera</code></td>
  47. <td class="description last"><p>The camera of the rendered scene.</p></td>
  48. </tr>
  49. <tr>
  50. <td class="name"><code>domElement</code></td>
  51. <td class="description last"><p>The HTML DOM element used for event listeners.<br/>Default is <code>null</code>.</p></td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. </div>
  56. </div>
  57. <h2 class="subsection-title">Properties</h2>
  58. <div class="member">
  59. <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>
  60. <div class="description">
  61. <p>An array of draggable 3D objects.</p>
  62. </div>
  63. </div>
  64. <div class="member">
  65. <h3 class="name" id="raycaster" translate="no">.<a href="#raycaster">raycaster</a><span class="type-signature"> : <a href="Raycaster.html">Raycaster</a></span> </h3>
  66. <div class="description">
  67. <p>The raycaster used for detecting 3D objects.</p>
  68. </div>
  69. </div>
  70. <div class="member">
  71. <h3 class="name" id="recursive" translate="no">.<a href="#recursive">recursive</a><span class="type-signature"> : boolean</span> </h3>
  72. <div class="description">
  73. <p>Whether children of draggable objects can be dragged independently from their parent.<br/>Default is <code>true</code>.</p>
  74. </div>
  75. </div>
  76. <div class="member">
  77. <h3 class="name" id="rotateSpeed" translate="no">.<a href="#rotateSpeed">rotateSpeed</a><span class="type-signature"> : number</span> </h3>
  78. <div class="description">
  79. <p>The speed at which the object will rotate when dragged in <code>rotate</code> mode.
  80. The higher the number the faster the rotation.<br/>Default is <code>1</code>.</p>
  81. </div>
  82. </div>
  83. <div class="member">
  84. <h3 class="name" id="transformGroup" translate="no">.<a href="#transformGroup">transformGroup</a><span class="type-signature"> : boolean</span> </h3>
  85. <div class="description">
  86. <p>This option only works if the <code>objects</code> array contains a single draggable group object.
  87. If set to <code>true</code>, the controls does not transform individual objects but the entire group.<br/>Default is <code>false</code>.</p>
  88. </div>
  89. </div>
  90. <h2 class="subsection-title">Events</h2>
  91. <h3 class="name name-method" id="event:drag" translate="no">.<a href="#event:drag">drag</a> </h3>
  92. <div class="method">
  93. <div class="description">
  94. <p>Fires when the user drags a 3D object.</p>
  95. </div>
  96. <h5>Type:</h5>
  97. <ul>
  98. <li>
  99. <span class="param-type">Object</span>
  100. </li>
  101. </ul>
  102. </div>
  103. <h3 class="name name-method" id="event:dragend" translate="no">.<a href="#event:dragend">dragend</a> </h3>
  104. <div class="method">
  105. <div class="description">
  106. <p>Fires when the user has finished dragging a 3D object.</p>
  107. </div>
  108. <h5>Type:</h5>
  109. <ul>
  110. <li>
  111. <span class="param-type">Object</span>
  112. </li>
  113. </ul>
  114. </div>
  115. <h3 class="name name-method" id="event:hoveroff" translate="no">.<a href="#event:hoveroff">hoveroff</a> </h3>
  116. <div class="method">
  117. <div class="description">
  118. <p>Fires when the pointer is moved out of a 3D object.</p>
  119. </div>
  120. <h5>Type:</h5>
  121. <ul>
  122. <li>
  123. <span class="param-type">Object</span>
  124. </li>
  125. </ul>
  126. </div>
  127. <h3 class="name name-method" id="event:hoveron" translate="no">.<a href="#event:hoveron">hoveron</a> </h3>
  128. <div class="method">
  129. <div class="description">
  130. <p>Fires when the pointer is moved onto a 3D object, or onto one of its children.</p>
  131. </div>
  132. <h5>Type:</h5>
  133. <ul>
  134. <li>
  135. <span class="param-type">Object</span>
  136. </li>
  137. </ul>
  138. </div>
  139. <h2 class="subsection-title">Source</h2>
  140. <p>
  141. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/DragControls.js" target="_blank" rel="noopener" translate="no">examples/jsm/controls/DragControls.js</a>
  142. </p>
  143. </article>
  144. </section>
  145. <script src="../scripts/linenumber.js"></script>
  146. <script src="../scripts/page.js"></script>
  147. </body>
  148. </html>
粤ICP备19079148号