TransformControls.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>TransformControls - 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">TransformControls</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>This class can be used to transform objects in 3D space by adapting a similar interaction model
  17. of DCC tools like Blender. Unlike other controls, it is not intended to transform the scene's camera.</p>
  18. <p><code>TransformControls</code> expects that its attached 3D object is part of the scene graph.</p></div>
  19. </header>
  20. <article>
  21. <h2 class="subsection-title">Import</h2>
  22. <p><span translate="no">TransformControls</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  23. <pre><code class="language-js">import { TransformControls } from 'three/addons/controls/TransformControls.js';</code></pre>
  24. <div class="container-overview">
  25. <h2>Constructor</h2>
  26. <h3 class="name name-method" id="TransformControls" translate="no">new <a href="#TransformControls">TransformControls</a><span class="signature">( camera : <span class="param-type">Camera</span>, domElement : <span class="param-type">HTMLElement</span> )</span> </h3>
  27. <div class="method">
  28. <div class="description">
  29. <p>Constructs a new controls instance.</p>
  30. </div>
  31. <table class="params">
  32. <tbody>
  33. <tr>
  34. <td class="name"><code>camera</code></td>
  35. <td class="description last"><p>The camera of the rendered scene.</p></td>
  36. </tr>
  37. <tr>
  38. <td class="name"><code>domElement</code></td>
  39. <td class="description last"><p>The HTML element used for event listeners.<br/>Default is <code>null</code>.</p></td>
  40. </tr>
  41. </tbody>
  42. </table>
  43. </div>
  44. </div>
  45. <h2 class="subsection-title">Properties</h2>
  46. <div class="member">
  47. <h3 class="name" id="axis" translate="no">.<a href="#axis">axis</a><span class="type-signature"> : string</span> </h3>
  48. <div class="description">
  49. <p>The current transformation axis.</p>
  50. </div>
  51. </div>
  52. <div class="member">
  53. <h3 class="name" id="camera" translate="no">.<a href="#camera">camera</a><span class="type-signature"> : <a href="Camera.html">Camera</a></span> </h3>
  54. <div class="description">
  55. <p>The camera of the rendered scene.</p>
  56. </div>
  57. </div>
  58. <div class="member">
  59. <h3 class="name" id="dragging" translate="no">.<a href="#dragging">dragging</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  60. <div class="description">
  61. <p>Whether dragging is currently performed or not.<br/>Default is <code>false</code>.</p>
  62. </div>
  63. </div>
  64. <div class="member">
  65. <h3 class="name" id="maxX" translate="no">.<a href="#maxX">maxX</a><span class="type-signature"> : number</span> </h3>
  66. <div class="description">
  67. <p>The maximum allowed X position during translation.<br/>Default is <code>Infinity</code>.</p>
  68. </div>
  69. </div>
  70. <div class="member">
  71. <h3 class="name" id="maxY" translate="no">.<a href="#maxY">maxY</a><span class="type-signature"> : number</span> </h3>
  72. <div class="description">
  73. <p>The maximum allowed Y position during translation.<br/>Default is <code>Infinity</code>.</p>
  74. </div>
  75. </div>
  76. <div class="member">
  77. <h3 class="name" id="maxZ" translate="no">.<a href="#maxZ">maxZ</a><span class="type-signature"> : number</span> </h3>
  78. <div class="description">
  79. <p>The maximum allowed Z position during translation.<br/>Default is <code>Infinity</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <h3 class="name" id="minX" translate="no">.<a href="#minX">minX</a><span class="type-signature"> : number</span> </h3>
  84. <div class="description">
  85. <p>The minimum allowed X position during translation.<br/>Default is <code>-Infinity</code>.</p>
  86. </div>
  87. </div>
  88. <div class="member">
  89. <h3 class="name" id="minY" translate="no">.<a href="#minY">minY</a><span class="type-signature"> : number</span> </h3>
  90. <div class="description">
  91. <p>The minimum allowed y position during translation.<br/>Default is <code>-Infinity</code>.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="minZ" translate="no">.<a href="#minZ">minZ</a><span class="type-signature"> : number</span> </h3>
  96. <div class="description">
  97. <p>The minimum allowed z position during translation.<br/>Default is <code>-Infinity</code>.</p>
  98. </div>
  99. </div>
  100. <div class="member">
  101. <h3 class="name" id="mode" translate="no">.<a href="#mode">mode</a><span class="type-signature"> : 'translate' | 'rotate' | 'scale'</span> </h3>
  102. <div class="description">
  103. <p>The current transformation axis.<br/>Default is <code>'translate'</code>.</p>
  104. </div>
  105. </div>
  106. <div class="member">
  107. <h3 class="name" id="rotationSnap" translate="no">.<a href="#rotationSnap">rotationSnap</a><span class="type-signature"> : number</span> </h3>
  108. <div class="description">
  109. <p>By default, 3D objects are continuously rotated. If you set this property to a numeric
  110. value (radians), you can define in which steps the 3D object should be rotated.<br/>Default is <code>null</code>.</p>
  111. </div>
  112. </div>
  113. <div class="member">
  114. <h3 class="name" id="scaleSnap" translate="no">.<a href="#scaleSnap">scaleSnap</a><span class="type-signature"> : number</span> </h3>
  115. <div class="description">
  116. <p>By default, 3D objects are continuously scaled. If you set this property to a numeric
  117. value, you can define in which steps the 3D object should be scaled.<br/>Default is <code>null</code>.</p>
  118. </div>
  119. </div>
  120. <div class="member">
  121. <h3 class="name" id="showX" translate="no">.<a href="#showX">showX</a><span class="type-signature"> : boolean</span> </h3>
  122. <div class="description">
  123. <p>Whether the x-axis helper should be visible or not.<br/>Default is <code>true</code>.</p>
  124. </div>
  125. </div>
  126. <div class="member">
  127. <h3 class="name" id="showY" translate="no">.<a href="#showY">showY</a><span class="type-signature"> : boolean</span> </h3>
  128. <div class="description">
  129. <p>Whether the y-axis helper should be visible or not.<br/>Default is <code>true</code>.</p>
  130. </div>
  131. </div>
  132. <div class="member">
  133. <h3 class="name" id="showZ" translate="no">.<a href="#showZ">showZ</a><span class="type-signature"> : boolean</span> </h3>
  134. <div class="description">
  135. <p>Whether the z-axis helper should be visible or not.<br/>Default is <code>true</code>.</p>
  136. </div>
  137. </div>
  138. <div class="member">
  139. <h3 class="name" id="size" translate="no">.<a href="#size">size</a><span class="type-signature"> : number</span> </h3>
  140. <div class="description">
  141. <p>The size of the helper UI (axes/planes).<br/>Default is <code>1</code>.</p>
  142. </div>
  143. </div>
  144. <div class="member">
  145. <h3 class="name" id="space" translate="no">.<a href="#space">space</a><span class="type-signature"> : 'world' | 'local'</span> </h3>
  146. <div class="description">
  147. <p>Defines in which coordinate space transformations should be performed.<br/>Default is <code>'world'</code>.</p>
  148. </div>
  149. </div>
  150. <div class="member">
  151. <h3 class="name" id="translationSnap" translate="no">.<a href="#translationSnap">translationSnap</a><span class="type-signature"> : number</span> </h3>
  152. <div class="description">
  153. <p>By default, 3D objects are continuously translated. If you set this property to a numeric
  154. value (world units), you can define in which steps the 3D object should be translated.<br/>Default is <code>null</code>.</p>
  155. </div>
  156. </div>
  157. <h2 class="subsection-title">Methods</h2>
  158. <h3 class="name name-method" id="attach" translate="no">.<a href="#attach">attach</a><span class="signature">( object : <span class="param-type">Object3D</span> )</span><span class="type-signature"> : <a href="TransformControls.html">TransformControls</a></span> </h3>
  159. <div class="method">
  160. <div class="description">
  161. <p>Sets the 3D object that should be transformed and ensures the controls UI is visible.</p>
  162. </div>
  163. <table class="params">
  164. <tbody>
  165. <tr>
  166. <td class="name"><code>object</code></td>
  167. <td class="description last"><p>The 3D object that should be transformed.</p></td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. <dl class="details">
  172. <dt class="tag-returns"><strong>Returns:</strong> A reference to this controls.</dt>
  173. </dl>
  174. </div>
  175. <h3 class="name name-method" id="detach" translate="no">.<a href="#detach">detach</a><span class="signature">()</span><span class="type-signature"> : <a href="TransformControls.html">TransformControls</a></span> </h3>
  176. <div class="method">
  177. <div class="description">
  178. <p>Removes the current 3D object from the controls and makes the helper UI invisible.</p>
  179. </div>
  180. <dl class="details">
  181. <dt class="tag-returns"><strong>Returns:</strong> A reference to this controls.</dt>
  182. </dl>
  183. </div>
  184. <h3 class="name name-method" id="getHelper" translate="no">.<a href="#getHelper">getHelper</a><span class="signature">()</span><span class="type-signature"> : TransformControlsRoot</span> </h3>
  185. <div class="method">
  186. <div class="description">
  187. <p>Returns the visual representation of the controls. Add the helper to your scene to
  188. visually transform the attached 3D object.</p>
  189. </div>
  190. <dl class="details">
  191. <dt class="tag-returns"><strong>Returns:</strong> The helper.</dt>
  192. </dl>
  193. </div>
  194. <h3 class="name name-method" id="getMode" translate="no">.<a href="#getMode">getMode</a><span class="signature">()</span><span class="type-signature"> : 'translate' | 'rotate' | 'scale'</span> </h3>
  195. <div class="method">
  196. <div class="description">
  197. <p>Returns the transformation mode.</p>
  198. </div>
  199. <dl class="details">
  200. <dt class="tag-returns"><strong>Returns:</strong> The transformation mode.</dt>
  201. </dl>
  202. </div>
  203. <h3 class="name name-method" id="getRaycaster" translate="no">.<a href="#getRaycaster">getRaycaster</a><span class="signature">()</span><span class="type-signature"> : <a href="Raycaster.html">Raycaster</a></span> </h3>
  204. <div class="method">
  205. <div class="description">
  206. <p>Returns the raycaster that is used for user interaction. This object is shared between all
  207. instances of <code>TransformControls</code>.</p>
  208. </div>
  209. <dl class="details">
  210. <dt class="tag-returns"><strong>Returns:</strong> The internal raycaster.</dt>
  211. </dl>
  212. </div>
  213. <h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">()</span> </h3>
  214. <div class="method">
  215. <div class="description">
  216. <p>Resets the object's position, rotation and scale to when the current transform began.</p>
  217. </div>
  218. </div>
  219. <h3 class="name name-method" id="setColors" translate="no">.<a href="#setColors">setColors</a><span class="signature">( xAxis : <span class="param-type">number | Color | string</span>, yAxis : <span class="param-type">number | Color | string</span>, zAxis : <span class="param-type">number | Color | string</span>, active : <span class="param-type">number | Color | string</span> )</span> </h3>
  220. <div class="method">
  221. <div class="description">
  222. <p>Sets the colors of the control's gizmo.</p>
  223. </div>
  224. <table class="params">
  225. <tbody>
  226. <tr>
  227. <td class="name"><code>xAxis</code></td>
  228. <td class="description last"><p>The x-axis color.</p></td>
  229. </tr>
  230. <tr>
  231. <td class="name"><code>yAxis</code></td>
  232. <td class="description last"><p>The y-axis color.</p></td>
  233. </tr>
  234. <tr>
  235. <td class="name"><code>zAxis</code></td>
  236. <td class="description last"><p>The z-axis color.</p></td>
  237. </tr>
  238. <tr>
  239. <td class="name"><code>active</code></td>
  240. <td class="description last"><p>The color for active elements.</p></td>
  241. </tr>
  242. </tbody>
  243. </table>
  244. </div>
  245. <h3 class="name name-method" id="setMode" translate="no">.<a href="#setMode">setMode</a><span class="signature">( mode : <span class="param-type">'translate' | 'rotate' | 'scale'</span> )</span> </h3>
  246. <div class="method">
  247. <div class="description">
  248. <p>Sets the given transformation mode.</p>
  249. </div>
  250. <table class="params">
  251. <tbody>
  252. <tr>
  253. <td class="name"><code>mode</code></td>
  254. <td class="description last"><p>The transformation mode to set.</p></td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. </div>
  259. <h3 class="name name-method" id="setRotationSnap" translate="no">.<a href="#setRotationSnap">setRotationSnap</a><span class="signature">( rotationSnap : <span class="param-type">number</span> )</span> </h3>
  260. <div class="method">
  261. <div class="description">
  262. <p>Sets the rotation snap.</p>
  263. </div>
  264. <table class="params">
  265. <tbody>
  266. <tr>
  267. <td class="name"><code>rotationSnap</code></td>
  268. <td class="description last"><p>The rotation snap to set.</p></td>
  269. </tr>
  270. </tbody>
  271. </table>
  272. </div>
  273. <h3 class="name name-method" id="setScaleSnap" translate="no">.<a href="#setScaleSnap">setScaleSnap</a><span class="signature">( scaleSnap : <span class="param-type">number</span> )</span> </h3>
  274. <div class="method">
  275. <div class="description">
  276. <p>Sets the scale snap.</p>
  277. </div>
  278. <table class="params">
  279. <tbody>
  280. <tr>
  281. <td class="name"><code>scaleSnap</code></td>
  282. <td class="description last"><p>The scale snap to set.</p></td>
  283. </tr>
  284. </tbody>
  285. </table>
  286. </div>
  287. <h3 class="name name-method" id="setSize" translate="no">.<a href="#setSize">setSize</a><span class="signature">( size : <span class="param-type">number</span> )</span> </h3>
  288. <div class="method">
  289. <div class="description">
  290. <p>Sets the size of the helper UI.</p>
  291. </div>
  292. <table class="params">
  293. <tbody>
  294. <tr>
  295. <td class="name"><code>size</code></td>
  296. <td class="description last"><p>The size to set.</p></td>
  297. </tr>
  298. </tbody>
  299. </table>
  300. </div>
  301. <h3 class="name name-method" id="setSpace" translate="no">.<a href="#setSpace">setSpace</a><span class="signature">( space : <span class="param-type">'world' | 'local'</span> )</span> </h3>
  302. <div class="method">
  303. <div class="description">
  304. <p>Sets the coordinate space in which transformations are applied.</p>
  305. </div>
  306. <table class="params">
  307. <tbody>
  308. <tr>
  309. <td class="name"><code>space</code></td>
  310. <td class="description last"><p>The space to set.</p></td>
  311. </tr>
  312. </tbody>
  313. </table>
  314. </div>
  315. <h3 class="name name-method" id="setTranslationSnap" translate="no">.<a href="#setTranslationSnap">setTranslationSnap</a><span class="signature">( translationSnap : <span class="param-type">number</span> )</span> </h3>
  316. <div class="method">
  317. <div class="description">
  318. <p>Sets the translation snap.</p>
  319. </div>
  320. <table class="params">
  321. <tbody>
  322. <tr>
  323. <td class="name"><code>translationSnap</code></td>
  324. <td class="description last"><p>The translation snap to set.</p></td>
  325. </tr>
  326. </tbody>
  327. </table>
  328. </div>
  329. <h2 class="subsection-title">Events</h2>
  330. <h3 class="name name-method" id="event:change" translate="no">.<a href="#event:change">change</a> </h3>
  331. <div class="method">
  332. <div class="description">
  333. <p>Fires if any type of change (object or property change) is performed. Property changes
  334. are separate events you can add event listeners to. The event type is &quot;propertyname-changed&quot;.</p>
  335. </div>
  336. <h5>Type:</h5>
  337. <ul>
  338. <li>
  339. <span class="param-type">Object</span>
  340. </li>
  341. </ul>
  342. </div>
  343. <h3 class="name name-method" id="event:mouseDown" translate="no">.<a href="#event:mouseDown">mouseDown</a> </h3>
  344. <div class="method">
  345. <div class="description">
  346. <p>Fires if a pointer (mouse/touch) becomes active.</p>
  347. </div>
  348. <h5>Type:</h5>
  349. <ul>
  350. <li>
  351. <span class="param-type">Object</span>
  352. </li>
  353. </ul>
  354. </div>
  355. <h3 class="name name-method" id="event:mouseUp" translate="no">.<a href="#event:mouseUp">mouseUp</a> </h3>
  356. <div class="method">
  357. <div class="description">
  358. <p>Fires if a pointer (mouse/touch) is no longer active.</p>
  359. </div>
  360. <h5>Type:</h5>
  361. <ul>
  362. <li>
  363. <span class="param-type">Object</span>
  364. </li>
  365. </ul>
  366. </div>
  367. <h3 class="name name-method" id="event:objectChange" translate="no">.<a href="#event:objectChange">objectChange</a> </h3>
  368. <div class="method">
  369. <div class="description">
  370. <p>Fires if the controlled 3D object is changed.</p>
  371. </div>
  372. <h5>Type:</h5>
  373. <ul>
  374. <li>
  375. <span class="param-type">Object</span>
  376. </li>
  377. </ul>
  378. </div>
  379. <h2 class="subsection-title">Source</h2>
  380. <p>
  381. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/TransformControls.js" target="_blank" rel="noopener" translate="no">examples/jsm/controls/TransformControls.js</a>
  382. </p>
  383. </article>
  384. </section>
  385. <script src="../scripts/linenumber.js"></script>
  386. <script src="../scripts/page.js"></script>
  387. </body>
  388. </html>
粤ICP备19079148号