Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragControls: Add mouseButtons #29072

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/examples/en/controls/DragControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ <h3>[property:Boolean enabled]</h3>
Whether or not the controls are enabled.
</p>

<h3>[property:Object mouseButtons]</h3>
<p>
This object contains references to the mouse button used by the controls.
<code>
controls.mouseButtons = {
LEFT: true,
MIDDLE: true,
RIGHT: true
}
</code>
</p>

<h3>[property:Boolean recursive]</h3>
<p>
Whether children of draggable objects can be dragged independently from their parent. Default is `true`.
Expand Down
21 changes: 19 additions & 2 deletions docs/examples/zh/controls/DragControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,31 @@ <h3>[property:Boolean enabled]</h3>
是否启用控制器。
</p>

<h3>[property:Object mouseButtons]</h3>
<p>
鼠标事件中允许响应的按键。
<code>
controls.mouseButtons = {
LEFT: true,
MIDDLE: true,
RIGHT: true
}
</code>
</p>

<h3>[property:Boolean recursive]</h3>
<p>
可拖动对象的子对象是否可以独立于其父对象进行拖动。默认值为 `true`。
</p>

<h3>[property:Boolean transformGroup]</h3>
<p>
当[page:DragControls.objects]数组包含一个单个可拖拽的组对象时该选项生效。如果设置为`true`,[name]会转换整个组对象,而不对单个对象做转换。默认值为`false`。
</p>

<h3>[property:String mode]</h3>
<p>
The current transformation mode. Possible values are `translate`, and `rotate`. Default is `translate`.
当前的变换模式,该值可以是 `translate` `rotate`。 默认值为 `translate`
</p>

<h2>方法</h2>
Expand Down Expand Up @@ -143,7 +160,7 @@ <h3>[method:Raycaster getRaycaster] ()</h3>

<h3>[method:undefined setObjects] ( [param:Array objects] )</h3>
<p>
Sets an array of draggable objects by overwriting the existing one.
通过覆盖现有数组来设置可拖动对象数组。
</p>

<h2>源代码</h2>
Expand Down
80 changes: 79 additions & 1 deletion examples/jsm/controls/DragControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DragControls extends EventDispatcher {

this.rotateSpeed = 1;

//
this.mouseButtons = { LEFT: true, MIDDLE: true, RIGHT: true };
puxiao marked this conversation as resolved.
Show resolved Hide resolved

const scope = this;

Expand Down Expand Up @@ -89,6 +89,45 @@ class DragControls extends EventDispatcher {

if ( scope.enabled === false ) return;

if ( event.pointerType === 'mouse' ) {

switch ( event.buttons ) {

case 1:

if ( scope.mouseButtons.LEFT !== true ) {

return;

}

break;
case 2:

if ( scope.mouseButtons.RIGHT !== true ) {

return;

}

break;
case 4:

if ( scope.mouseButtons.MIDDLE !== true ) {

return;

}

break;
default:

break;

}

}

updatePointer( event );

_raycaster.setFromCamera( _pointer, _camera );
Expand Down Expand Up @@ -175,6 +214,45 @@ class DragControls extends EventDispatcher {

if ( scope.enabled === false ) return;

if ( event.pointerType === 'mouse' ) {

switch ( event.button ) {

case 0:

if ( scope.mouseButtons.LEFT !== true ) {

return;

}

break;
case 1:

if ( scope.mouseButtons.MIDDLE !== true ) {

return;

}

break;
case 2:

if ( scope.mouseButtons.RIGHT !== true ) {

return;

}

break;
default:

break;

}

}

updatePointer( event );

_intersections.length = 0;
Expand Down