1
0

TransformControls.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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" rel="noopener">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"><a href="Camera.html">Camera</a></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">
  35. <strong>camera</strong>
  36. </td>
  37. <td class="description last">
  38. <p>The camera of the rendered scene.</p>
  39. </td>
  40. </tr>
  41. <tr>
  42. <td class="name">
  43. <strong>domElement</strong>
  44. </td>
  45. <td class="description last">
  46. <p>The HTML element used for event listeners.</p>
  47. <p>Default is <code>null</code>.</p>
  48. </td>
  49. </tr>
  50. </tbody>
  51. </table>
  52. </div>
  53. </div>
  54. <h2 class="subsection-title">Properties</h2>
  55. <div class="member">
  56. <h3 class="name" id="axis" translate="no">.<a href="#axis">axis</a><span class="type-signature"> : string</span> </h3>
  57. <div class="description">
  58. <p>The current transformation axis.</p>
  59. </div>
  60. </div>
  61. <div class="member">
  62. <h3 class="name" id="camera" translate="no">.<a href="#camera">camera</a><span class="type-signature"> : <a href="Camera.html">Camera</a></span> </h3>
  63. <div class="description">
  64. <p>The camera of the rendered scene.</p>
  65. </div>
  66. </div>
  67. <div class="member">
  68. <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>
  69. <div class="description">
  70. <p>Whether dragging is currently performed or not.</p>
  71. <p>Default is <code>false</code>.</p>
  72. </div>
  73. </div>
  74. <div class="member">
  75. <h3 class="name" id="maxX" translate="no">.<a href="#maxX">maxX</a><span class="type-signature"> : number</span> </h3>
  76. <div class="description">
  77. <p>The maximum allowed X position during translation.</p>
  78. <p>Default is <code>Infinity</code>.</p>
  79. </div>
  80. </div>
  81. <div class="member">
  82. <h3 class="name" id="maxY" translate="no">.<a href="#maxY">maxY</a><span class="type-signature"> : number</span> </h3>
  83. <div class="description">
  84. <p>The maximum allowed Y position during translation.</p>
  85. <p>Default is <code>Infinity</code>.</p>
  86. </div>
  87. </div>
  88. <div class="member">
  89. <h3 class="name" id="maxZ" translate="no">.<a href="#maxZ">maxZ</a><span class="type-signature"> : number</span> </h3>
  90. <div class="description">
  91. <p>The maximum allowed Z position during translation.</p>
  92. <p>Default is <code>Infinity</code>.</p>
  93. </div>
  94. </div>
  95. <div class="member">
  96. <h3 class="name" id="minX" translate="no">.<a href="#minX">minX</a><span class="type-signature"> : number</span> </h3>
  97. <div class="description">
  98. <p>The minimum allowed X position during translation.</p>
  99. <p>Default is <code>-Infinity</code>.</p>
  100. </div>
  101. </div>
  102. <div class="member">
  103. <h3 class="name" id="minY" translate="no">.<a href="#minY">minY</a><span class="type-signature"> : number</span> </h3>
  104. <div class="description">
  105. <p>The minimum allowed y position during translation.</p>
  106. <p>Default is <code>-Infinity</code>.</p>
  107. </div>
  108. </div>
  109. <div class="member">
  110. <h3 class="name" id="minZ" translate="no">.<a href="#minZ">minZ</a><span class="type-signature"> : number</span> </h3>
  111. <div class="description">
  112. <p>The minimum allowed z position during translation.</p>
  113. <p>Default is <code>-Infinity</code>.</p>
  114. </div>
  115. </div>
  116. <div class="member">
  117. <h3 class="name" id="mode" translate="no">.<a href="#mode">mode</a><span class="type-signature"> : 'translate' | 'rotate' | 'scale'</span> </h3>
  118. <div class="description">
  119. <p>The current transformation axis.</p>
  120. <p>Default is <code>'translate'</code>.</p>
  121. </div>
  122. </div>
  123. <div class="member">
  124. <h3 class="name" id="rotationSnap" translate="no">.<a href="#rotationSnap">rotationSnap</a><span class="type-signature"> : number</span> </h3>
  125. <div class="description">
  126. <p>By default, 3D objects are continuously rotated. If you set this property to a numeric
  127. value (radians), you can define in which steps the 3D object should be rotated.</p>
  128. <p>Default is <code>null</code>.</p>
  129. </div>
  130. </div>
  131. <div class="member">
  132. <h3 class="name" id="scaleSnap" translate="no">.<a href="#scaleSnap">scaleSnap</a><span class="type-signature"> : number</span> </h3>
  133. <div class="description">
  134. <p>By default, 3D objects are continuously scaled. If you set this property to a numeric
  135. value, you can define in which steps the 3D object should be scaled.</p>
  136. <p>Default is <code>null</code>.</p>
  137. </div>
  138. </div>
  139. <div class="member">
  140. <h3 class="name" id="showX" translate="no">.<a href="#showX">showX</a><span class="type-signature"> : boolean</span> </h3>
  141. <div class="description">
  142. <p>Whether the x-axis helper should be visible or not.</p>
  143. <p>Default is <code>true</code>.</p>
  144. </div>
  145. </div>
  146. <div class="member">
  147. <h3 class="name" id="showY" translate="no">.<a href="#showY">showY</a><span class="type-signature"> : boolean</span> </h3>
  148. <div class="description">
  149. <p>Whether the y-axis helper should be visible or not.</p>
  150. <p>Default is <code>true</code>.</p>
  151. </div>
  152. </div>
  153. <div class="member">
  154. <h3 class="name" id="showZ" translate="no">.<a href="#showZ">showZ</a><span class="type-signature"> : boolean</span> </h3>
  155. <div class="description">
  156. <p>Whether the z-axis helper should be visible or not.</p>
  157. <p>Default is <code>true</code>.</p>
  158. </div>
  159. </div>
  160. <div class="member">
  161. <h3 class="name" id="size" translate="no">.<a href="#size">size</a><span class="type-signature"> : number</span> </h3>
  162. <div class="description">
  163. <p>The size of the helper UI (axes/planes).</p>
  164. <p>Default is <code>1</code>.</p>
  165. </div>
  166. </div>
  167. <div class="member">
  168. <h3 class="name" id="space" translate="no">.<a href="#space">space</a><span class="type-signature"> : 'world' | 'local'</span> </h3>
  169. <div class="description">
  170. <p>Defines in which coordinate space transformations should be performed.</p>
  171. <p>Default is <code>'world'</code>.</p>
  172. </div>
  173. </div>
  174. <div class="member">
  175. <h3 class="name" id="translationSnap" translate="no">.<a href="#translationSnap">translationSnap</a><span class="type-signature"> : number</span> </h3>
  176. <div class="description">
  177. <p>By default, 3D objects are continuously translated. If you set this property to a numeric
  178. value (world units), you can define in which steps the 3D object should be translated.</p>
  179. <p>Default is <code>null</code>.</p>
  180. </div>
  181. </div>
  182. <h2 class="subsection-title">Methods</h2>
  183. <h3 class="name name-method" id="attach" translate="no">.<a href="#attach">attach</a><span class="signature">( object : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span><span class="type-signature"> : <a href="TransformControls.html">TransformControls</a></span> </h3>
  184. <div class="method">
  185. <div class="description">
  186. <p>Sets the 3D object that should be transformed and ensures the controls UI is visible.</p>
  187. </div>
  188. <table class="params">
  189. <tbody>
  190. <tr>
  191. <td class="name">
  192. <strong>object</strong>
  193. </td>
  194. <td class="description last">
  195. <p>The 3D object that should be transformed.</p>
  196. </td>
  197. </tr>
  198. </tbody>
  199. </table>
  200. <dl class="details">
  201. <dt class="tag-returns"><strong>Returns:</strong> A reference to this controls.</dt>
  202. </dl>
  203. </div>
  204. <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>
  205. <div class="method">
  206. <div class="description">
  207. <p>Removes the current 3D object from the controls and makes the helper UI invisible.</p>
  208. </div>
  209. <dl class="details">
  210. <dt class="tag-returns"><strong>Returns:</strong> A reference to this controls.</dt>
  211. </dl>
  212. </div>
  213. <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>
  214. <div class="method">
  215. <div class="description">
  216. <p>Returns the visual representation of the controls. Add the helper to your scene to
  217. visually transform the attached 3D object.</p>
  218. </div>
  219. <dl class="details">
  220. <dt class="tag-returns"><strong>Returns:</strong> The helper.</dt>
  221. </dl>
  222. </div>
  223. <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>
  224. <div class="method">
  225. <div class="description">
  226. <p>Returns the transformation mode.</p>
  227. </div>
  228. <dl class="details">
  229. <dt class="tag-returns"><strong>Returns:</strong> The transformation mode.</dt>
  230. </dl>
  231. </div>
  232. <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>
  233. <div class="method">
  234. <div class="description">
  235. <p>Returns the raycaster that is used for user interaction. This object is shared between all
  236. instances of <code>TransformControls</code>.</p>
  237. </div>
  238. <dl class="details">
  239. <dt class="tag-returns"><strong>Returns:</strong> The internal raycaster.</dt>
  240. </dl>
  241. </div>
  242. <h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">()</span> </h3>
  243. <div class="method">
  244. <div class="description">
  245. <p>Resets the object's position, rotation and scale to when the current transform began.</p>
  246. </div>
  247. </div>
  248. <h3 class="name name-method" id="setColors" translate="no">.<a href="#setColors">setColors</a><span class="signature">( xAxis : <span class="param-type">number | <a href="Color.html">Color</a> | string</span>, yAxis : <span class="param-type">number | <a href="Color.html">Color</a> | string</span>, zAxis : <span class="param-type">number | <a href="Color.html">Color</a> | string</span>, active : <span class="param-type">number | <a href="Color.html">Color</a> | string</span> )</span> </h3>
  249. <div class="method">
  250. <div class="description">
  251. <p>Sets the colors of the control's gizmo.</p>
  252. </div>
  253. <table class="params">
  254. <tbody>
  255. <tr>
  256. <td class="name">
  257. <strong>xAxis</strong>
  258. </td>
  259. <td class="description last">
  260. <p>The x-axis color.</p>
  261. </td>
  262. </tr>
  263. <tr>
  264. <td class="name">
  265. <strong>yAxis</strong>
  266. </td>
  267. <td class="description last">
  268. <p>The y-axis color.</p>
  269. </td>
  270. </tr>
  271. <tr>
  272. <td class="name">
  273. <strong>zAxis</strong>
  274. </td>
  275. <td class="description last">
  276. <p>The z-axis color.</p>
  277. </td>
  278. </tr>
  279. <tr>
  280. <td class="name">
  281. <strong>active</strong>
  282. </td>
  283. <td class="description last">
  284. <p>The color for active elements.</p>
  285. </td>
  286. </tr>
  287. </tbody>
  288. </table>
  289. </div>
  290. <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>
  291. <div class="method">
  292. <div class="description">
  293. <p>Sets the given transformation mode.</p>
  294. </div>
  295. <table class="params">
  296. <tbody>
  297. <tr>
  298. <td class="name">
  299. <strong>mode</strong>
  300. </td>
  301. <td class="description last">
  302. <p>The transformation mode to set.</p>
  303. </td>
  304. </tr>
  305. </tbody>
  306. </table>
  307. </div>
  308. <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>
  309. <div class="method">
  310. <div class="description">
  311. <p>Sets the rotation snap.</p>
  312. </div>
  313. <table class="params">
  314. <tbody>
  315. <tr>
  316. <td class="name">
  317. <strong>rotationSnap</strong>
  318. </td>
  319. <td class="description last">
  320. <p>The rotation snap to set.</p>
  321. </td>
  322. </tr>
  323. </tbody>
  324. </table>
  325. </div>
  326. <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>
  327. <div class="method">
  328. <div class="description">
  329. <p>Sets the scale snap.</p>
  330. </div>
  331. <table class="params">
  332. <tbody>
  333. <tr>
  334. <td class="name">
  335. <strong>scaleSnap</strong>
  336. </td>
  337. <td class="description last">
  338. <p>The scale snap to set.</p>
  339. </td>
  340. </tr>
  341. </tbody>
  342. </table>
  343. </div>
  344. <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>
  345. <div class="method">
  346. <div class="description">
  347. <p>Sets the size of the helper UI.</p>
  348. </div>
  349. <table class="params">
  350. <tbody>
  351. <tr>
  352. <td class="name">
  353. <strong>size</strong>
  354. </td>
  355. <td class="description last">
  356. <p>The size to set.</p>
  357. </td>
  358. </tr>
  359. </tbody>
  360. </table>
  361. </div>
  362. <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>
  363. <div class="method">
  364. <div class="description">
  365. <p>Sets the coordinate space in which transformations are applied.</p>
  366. </div>
  367. <table class="params">
  368. <tbody>
  369. <tr>
  370. <td class="name">
  371. <strong>space</strong>
  372. </td>
  373. <td class="description last">
  374. <p>The space to set.</p>
  375. </td>
  376. </tr>
  377. </tbody>
  378. </table>
  379. </div>
  380. <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>
  381. <div class="method">
  382. <div class="description">
  383. <p>Sets the translation snap.</p>
  384. </div>
  385. <table class="params">
  386. <tbody>
  387. <tr>
  388. <td class="name">
  389. <strong>translationSnap</strong>
  390. </td>
  391. <td class="description last">
  392. <p>The translation snap to set.</p>
  393. </td>
  394. </tr>
  395. </tbody>
  396. </table>
  397. </div>
  398. <h2 class="subsection-title">Events</h2>
  399. <h3 class="name name-method" id="event:change" translate="no">.<a href="#event:change">change</a> </h3>
  400. <div class="method">
  401. <div class="description">
  402. <p>Fires if any type of change (object or property change) is performed. Property changes
  403. are separate events you can add event listeners to. The event type is &quot;propertyname-changed&quot;.</p>
  404. </div>
  405. <h5>Type:</h5>
  406. <ul>
  407. <li>
  408. <span class="param-type">Object</span>
  409. </li>
  410. </ul>
  411. </div>
  412. <h3 class="name name-method" id="event:mouseDown" translate="no">.<a href="#event:mouseDown">mouseDown</a> </h3>
  413. <div class="method">
  414. <div class="description">
  415. <p>Fires if a pointer (mouse/touch) becomes active.</p>
  416. </div>
  417. <h5>Type:</h5>
  418. <ul>
  419. <li>
  420. <span class="param-type">Object</span>
  421. </li>
  422. </ul>
  423. </div>
  424. <h3 class="name name-method" id="event:mouseUp" translate="no">.<a href="#event:mouseUp">mouseUp</a> </h3>
  425. <div class="method">
  426. <div class="description">
  427. <p>Fires if a pointer (mouse/touch) is no longer active.</p>
  428. </div>
  429. <h5>Type:</h5>
  430. <ul>
  431. <li>
  432. <span class="param-type">Object</span>
  433. </li>
  434. </ul>
  435. </div>
  436. <h3 class="name name-method" id="event:objectChange" translate="no">.<a href="#event:objectChange">objectChange</a> </h3>
  437. <div class="method">
  438. <div class="description">
  439. <p>Fires if the controlled 3D object is changed.</p>
  440. </div>
  441. <h5>Type:</h5>
  442. <ul>
  443. <li>
  444. <span class="param-type">Object</span>
  445. </li>
  446. </ul>
  447. </div>
  448. <h2 class="subsection-title">Source</h2>
  449. <p>
  450. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/TransformControls.js" translate="no" target="_blank" rel="noopener">examples/jsm/controls/TransformControls.js</a>
  451. </p>
  452. </article>
  453. </section>
  454. <script src="../scripts/linenumber.js"></script>
  455. <script src="../scripts/page.js"></script>
  456. </body>
  457. </html>
粤ICP备19079148号