2
0

DragControls.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. [page:EventDispatcher] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. This class can be used to provide a drag'n'drop interaction.
  14. </p>
  15. <h2>Import</h2>
  16. <p>
  17. [name] is an add-on, and must be imported explicitly.
  18. See [link:#manual/introduction/Installation Installation / Addons].
  19. </p>
  20. <code>
  21. import { DragControls } from 'three/addons/controls/DragControls.js';
  22. </code>
  23. <h2>Code Example</h2>
  24. <code>
  25. const controls = new DragControls( objects, camera, renderer.domElement );
  26. // add event listener to highlight dragged objects
  27. controls.addEventListener( 'dragstart', function ( event ) {
  28. event.object.material.emissive.set( 0xaaaaaa );
  29. } );
  30. controls.addEventListener( 'dragend', function ( event ) {
  31. event.object.material.emissive.set( 0x000000 );
  32. } );
  33. </code>
  34. <h2>Examples</h2>
  35. <p>[example:misc_controls_drag misc / controls / drag ]</p>
  36. <h2>Constructor</h2>
  37. <h3>[name]( [param:Array objects], [param:Camera camera], [param:HTMLDOMElement domElement] )</h3>
  38. <p>
  39. [page:Array objects]: An array of draggable 3D objects.
  40. </p>
  41. <p>
  42. [page:Camera camera]: The camera of the rendered scene.
  43. </p>
  44. <p>
  45. [page:HTMLDOMElement domElement]: The HTML element used for event listeners.
  46. </p>
  47. <p>
  48. Creates a new instance of [name].
  49. </p>
  50. <h2>Events</h2>
  51. <h3>dragstart</h3>
  52. <p>
  53. Fires when the user starts to drag a 3D object.
  54. </p>
  55. <h3>drag</h3>
  56. <p>
  57. Fires when the user drags a 3D object.
  58. </p>
  59. <h3>dragend</h3>
  60. <p>
  61. Fires when the user has finished dragging a 3D object.
  62. </p>
  63. <h3>hoveron</h3>
  64. <p>
  65. Fires when the pointer is moved onto a 3D object, or onto one of its children.
  66. </p>
  67. <h3>hoveroff</h3>
  68. <p>
  69. Fires when the pointer is moved out of a 3D object.
  70. </p>
  71. <h2>Properties</h2>
  72. <h3>[property:Boolean enabled]</h3>
  73. <p>
  74. Whether or not the controls are enabled.
  75. </p>
  76. <h3>[property:Boolean recursive]</h3>
  77. <p>
  78. Whether children of draggable objects can be dragged independently from their parent. Default is `true`.
  79. </p>
  80. <h3>[property:Boolean transformGroup]</h3>
  81. <p>
  82. This option only works if the [page:DragControls.objects] array contains a single draggable group object.
  83. If set to `true`, [name] does not transform individual objects but the entire group. Default is `false`.
  84. </p>
  85. <h3>[property:String mode]</h3>
  86. <p>
  87. The current transformation mode. Possible values are `translate`, and `rotate`. Default is `translate`.
  88. </p>
  89. <h3>[property:Float rotateSpeed]</h3>
  90. <p>
  91. The speed at which the object will rotate when dragged in `rotate` mode. The higher the number the faster the rotation. Default is `1`.
  92. </p>
  93. <h2>Methods</h2>
  94. <p>See the base [page:EventDispatcher] class for common methods.</p>
  95. <h3>[method:undefined activate] ()</h3>
  96. <p>
  97. Adds the event listeners of the controls.
  98. </p>
  99. <h3>[method:undefined deactivate] ()</h3>
  100. <p>
  101. Removes the event listeners of the controls.
  102. </p>
  103. <h3>[method:undefined dispose] ()</h3>
  104. <p>
  105. Should be called if the controls is no longer required.
  106. </p>
  107. <h3>[method:Array getObjects] ()</h3>
  108. <p>
  109. Returns the array of draggable objects.
  110. </p>
  111. <h3>[method:Raycaster getRaycaster] ()</h3>
  112. <p>
  113. Returns the internal [page:Raycaster] instance that is used for intersection tests.
  114. </p>
  115. <h3>[method:undefined setObjects] ( [param:Array objects] )</h3>
  116. <p>
  117. Sets an array of draggable objects by overwriting the existing one.
  118. </p>
  119. <h2>Source</h2>
  120. <p>
  121. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/DragControls.js examples/jsm/controls/DragControls.js]
  122. </p>
  123. </body>
  124. </html>