瀏覽代碼

DragControls: Ensure hoveroff is fired correctly. (#21376)

* added a condition to catch the case where a hovered object doesn't get hoveredoff before a different object is hoveredon.

* DragControls fix for issue #21375
tb2k 4 年之前
父節點
當前提交
4e204db854
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 9 0
      examples/js/controls/DragControls.js
  2. 9 0
      examples/jsm/controls/DragControls.js

+ 9 - 0
examples/js/controls/DragControls.js

@@ -105,6 +105,15 @@ THREE.DragControls = function ( _objects, _camera, _domElement ) {
 
 			_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( object.matrixWorld ) );
 
+			if ( _hovered !== object && _hovered !== null) {
+
+				scope.dispatchEvent( { type: 'hoveroff', object: _hovered } );
+
+				_domElement.style.cursor = 'auto';
+				_hovered = null;
+
+			}
+			
 			if ( _hovered !== object ) {
 
 				scope.dispatchEvent( { type: 'hoveron', object: object } );

+ 9 - 0
examples/jsm/controls/DragControls.js

@@ -114,6 +114,15 @@ var DragControls = function ( _objects, _camera, _domElement ) {
 
 			_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( object.matrixWorld ) );
 
+			if ( _hovered !== object && _hovered !== null) {
+
+				scope.dispatchEvent( { type: 'hoveroff', object: _hovered } );
+
+				_domElement.style.cursor = 'auto';
+				_hovered = null;
+
+			}
+			
 			if ( _hovered !== object ) {
 
 				scope.dispatchEvent( { type: 'hoveron', object: object } );