@@ -19,7 +19,9 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
1919 var _mouse = new THREE . Vector2 ( ) ;
2020 var _offset = new THREE . Vector3 ( ) ;
2121 var _intersection = new THREE . Vector3 ( ) ;
22-
22+ var _worldPosition = new THREE . Vector3 ( ) ;
23+ var _inverseMatrix = new THREE . Matrix4 ( ) ;
24+
2325 var _selected = null , _hovered = null ;
2426
2527 //
@@ -71,7 +73,7 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
7173
7274 if ( _raycaster . ray . intersectPlane ( _plane , _intersection ) ) {
7375
74- _selected . position . copy ( _intersection . sub ( _offset ) ) ;
76+ _selected . position . copy ( _intersection . sub ( _offset ) . applyMatrix4 ( _inverseMatrix ) ) ;
7577
7678 }
7779
@@ -89,7 +91,7 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
8991
9092 var object = intersects [ 0 ] . object ;
9193
92- _plane . setFromNormalAndCoplanarPoint ( _camera . getWorldDirection ( _plane . normal ) , object . position ) ;
94+ _plane . setFromNormalAndCoplanarPoint ( _camera . getWorldDirection ( _plane . normal ) , _worldPosition . setFromMatrixPosition ( object . matrixWorld ) ) ;
9395
9496 if ( _hovered !== object ) {
9597
@@ -129,7 +131,8 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
129131
130132 if ( _raycaster . ray . intersectPlane ( _plane , _intersection ) ) {
131133
132- _offset . copy ( _intersection ) . sub ( _selected . position ) ;
134+ _inverseMatrix . getInverse ( _selected . parent . matrixWorld ) ;
135+ _offset . copy ( _intersection ) . sub ( _worldPosition . setFromMatrixPosition ( _selected . matrixWorld ) ) ;
133136
134137 }
135138
@@ -174,7 +177,7 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
174177
175178 if ( _raycaster . ray . intersectPlane ( _plane , _intersection ) ) {
176179
177- _selected . position . copy ( _intersection . sub ( _offset ) ) ;
180+ _selected . position . copy ( _intersection . sub ( _offset ) . applyMatrix4 ( _inverseMatrix ) ) ;
178181
179182 }
180183
@@ -204,11 +207,12 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
204207
205208 _selected = intersects [ 0 ] . object ;
206209
207- _plane . setFromNormalAndCoplanarPoint ( _camera . getWorldDirection ( _plane . normal ) , _selected . position ) ;
210+ _plane . setFromNormalAndCoplanarPoint ( _camera . getWorldDirection ( _plane . normal ) , _worldPosition . setFromMatrixPosition ( _selected . matrixWorld ) ) ;
208211
209212 if ( _raycaster . ray . intersectPlane ( _plane , _intersection ) ) {
210213
211- _offset . copy ( _intersection ) . sub ( _selected . position ) ;
214+ _inverseMatrix . getInverse ( _selected . parent . matrixWorld ) ;
215+ _offset . copy ( _intersection ) . sub ( _worldPosition . setFromMatrixPosition ( _selected . matrixWorld ) ) ;
212216
213217 }
214218
0 commit comments