From 9a8c4c6141d1621a3c444ed81d7f87e47aa51133 Mon Sep 17 00:00:00 2001 From: narenjoriona <147404925+narenjoriona@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:43:07 +0400 Subject: [PATCH 1/4] Update DragControls.js Fixed Group drag and drop issue. Existing code can drag only one group now we can drag multiple group in scene. --- examples/jsm/controls/DragControls.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/jsm/controls/DragControls.js b/examples/jsm/controls/DragControls.js index bd21ef1a97f164..81b5ec5ba78815 100644 --- a/examples/jsm/controls/DragControls.js +++ b/examples/jsm/controls/DragControls.js @@ -177,8 +177,20 @@ class DragControls extends EventDispatcher { _raycaster.intersectObjects( _objects, scope.recursive, _intersections ); if ( _intersections.length > 0 ) { - - _selected = ( scope.transformGroup === true ) ? _objects[ 0 ] : _intersections[ 0 ].object; + let mainGroup = null; + if(scope.transformGroup === true){ + + function getparent(obj){ + + if(obj.parent.type === 'Scene'){ + mainGroup = obj; + }else{ + getparent(obj.parent) + } + } + getparent( _intersections[ 0 ].object); + } + _selected = ( scope.transformGroup === true ) ? mainGroup : _intersections[ 0 ].object; _plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) ); From c163afbbbaea719370129668d96c1e7690089f98 Mon Sep 17 00:00:00 2001 From: narenjoriona <147404925+narenjoriona@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:17:48 +0400 Subject: [PATCH 2/4] Added new updateObject function for dynamically update objects --- examples/jsm/controls/DragControls.js | 44 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/examples/jsm/controls/DragControls.js b/examples/jsm/controls/DragControls.js index 81b5ec5ba78815..cac0879ceca4f1 100644 --- a/examples/jsm/controls/DragControls.js +++ b/examples/jsm/controls/DragControls.js @@ -30,7 +30,7 @@ class DragControls extends EventDispatcher { _domElement.style.touchAction = 'none'; // disable touch scroll let _selected = null, _hovered = null; - + const _intersections = []; this.mode = 'translate'; @@ -73,6 +73,10 @@ class DragControls extends EventDispatcher { } + function updateObject(_newObject){ //array of object + _objects = _newObject + } + function getRaycaster() { return _raycaster; @@ -177,20 +181,18 @@ class DragControls extends EventDispatcher { _raycaster.intersectObjects( _objects, scope.recursive, _intersections ); if ( _intersections.length > 0 ) { - let mainGroup = null; - if(scope.transformGroup === true){ - - function getparent(obj){ - - if(obj.parent.type === 'Scene'){ - mainGroup = obj; - }else{ - getparent(obj.parent) - } - } - getparent( _intersections[ 0 ].object); - } - _selected = ( scope.transformGroup === true ) ? mainGroup : _intersections[ 0 ].object; + + if ( scope.transformGroup === true ) { + + // look for the outermost group in the object's upper hierarchy + + _selected = findGroup( _intersections[ 0 ].object ); + + } else { + + _selected = _intersections[ 0 ].object; + + } _plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) ); @@ -246,6 +248,16 @@ class DragControls extends EventDispatcher { } + function findGroup( obj, group = null ) { + + if ( obj.isGroup ) group = obj; + + if ( obj.parent === null ) return group; + + return findGroup( obj.parent, group ); + + } + activate(); // API @@ -259,9 +271,11 @@ class DragControls extends EventDispatcher { this.dispose = dispose; this.getObjects = getObjects; this.getRaycaster = getRaycaster; + this.updateObject = updateObject; } } + export { DragControls }; From 0f32c7679426fff05cbaefbbab3818300d339729 Mon Sep 17 00:00:00 2001 From: narenjoriona <147404925+narenjoriona@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:33:30 +0400 Subject: [PATCH 3/4] function name updated as per review comment --- examples/jsm/controls/DragControls.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsm/controls/DragControls.js b/examples/jsm/controls/DragControls.js index cac0879ceca4f1..eed4ba871c71f1 100644 --- a/examples/jsm/controls/DragControls.js +++ b/examples/jsm/controls/DragControls.js @@ -73,8 +73,8 @@ class DragControls extends EventDispatcher { } - function updateObject(_newObject){ //array of object - _objects = _newObject + function setObjects(object){ //array of object + _objects = object } function getRaycaster() { From 3b8a400caee012b7095b0c7d39e391679b00db40 Mon Sep 17 00:00:00 2001 From: narenjoriona <147404925+narenjoriona@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:35:15 +0400 Subject: [PATCH 4/4] Update function name --- examples/jsm/controls/DragControls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/controls/DragControls.js b/examples/jsm/controls/DragControls.js index eed4ba871c71f1..3b9e84f271ea84 100644 --- a/examples/jsm/controls/DragControls.js +++ b/examples/jsm/controls/DragControls.js @@ -271,7 +271,7 @@ class DragControls extends EventDispatcher { this.dispose = dispose; this.getObjects = getObjects; this.getRaycaster = getRaycaster; - this.updateObject = updateObject; + this.setObjects = setObjects; }