-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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: Refactor API. #29079
DragControls: Refactor API. #29079
Conversation
Do you think it is appropriate to add saveState():xxx, setState(xxx), and reset() to Controls? |
Not all controls support these methods so I would revisit this after all classes has been updated. If we add these methods to the |
I think we should move |
Sounds good! |
|
||
} | ||
|
||
connect() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 What do you think about being able to pass the dom element here?
That way the code could look like this:
const controls = new OrbitControls( camera );
controls.connect( renderer.domElement );
I guess we'll need to do a bit of management though:
connect( element ) {
if ( this.domElement !== element ) {
this.disconnect();
}
this.domElement = element;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a convenient feature, I guess it's fine.
That said, domElement
is public so devs can basically achieve the same without further changes to the control classes. However, the additional management code in connect()
could prevent mistakes when devs want to exchange the DOM element (not sure how common this use case is though).
|
||
class Controls extends EventDispatcher { | ||
|
||
constructor( object, domElement ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor( object, domElement = null )
maybe?
Right now it's undefined
by default but subclasses set it to null
...
Related issue: #29072, #20575
Description
This PR refactors the API of
DragControls
.THREE.Controls
is introduced which defines a basic control interface.DragControls
is now derived from this class.connect()
method.domElement
is now optional. If required, an instance ofDragControls
can now be created without a DOM element. When the element is set at a later point, a manual call ofconnect()
configures the event listeners.