-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
CSS2DRenderer: Support Rotation #33474
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
Open
WestLangley
wants to merge
2
commits into
mrdoob:dev
Choose a base branch
from
WestLangley:dev-css2Drenderer_rotation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−10
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,14 +46,23 @@ class CSS2DObject extends Object3D { | |
| this.element.setAttribute( 'draggable', false ); | ||
|
|
||
| /** | ||
| * The 3D objects center point. | ||
| * `( 0, 0 )` is the lower left, `( 1, 1 )` is the top right. | ||
| * The object's anchor point, and the point around which the object rotates. | ||
| * A value of `(0.5, 0.5)` corresponds to the midpoint of the object. A value | ||
| * of `(0, 0)` corresponds to the upper left corner of the object. | ||
| * | ||
| * @type {Vector2} | ||
| * @default (0.5,0.5) | ||
| */ | ||
| this.center = new Vector2( 0.5, 0.5 ); | ||
|
|
||
| /** | ||
| * The object's angle of rotation, counterclockwise, in radians. | ||
| * | ||
| * @type {number} | ||
| * @default 0 | ||
| */ | ||
| this.rotationAngle = 0; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use |
||
|
|
||
| this.addEventListener( 'removed', function () { | ||
|
|
||
| this.traverse( function ( object ) { | ||
|
|
@@ -97,8 +106,7 @@ const _a = new Vector3(); | |
| const _b = new Vector3(); | ||
|
|
||
| /** | ||
| * This renderer is a simplified version of {@link CSS3DRenderer}. The only transformation that is | ||
| * supported is translation. | ||
| * This renderer is a simplified version of {@link CSS3DRenderer}. | ||
| * | ||
| * The renderer is very useful if you want to combine HTML based labels with 3D objects. Here too, | ||
| * the respective DOM elements are wrapped into an instance of {@link CSS2DObject} and added to the | ||
|
|
@@ -235,7 +243,20 @@ class CSS2DRenderer { | |
|
|
||
| object.onBeforeRender( _this, scene, camera ); | ||
|
|
||
| element.style.transform = 'translate(' + ( - 100 * object.center.x ) + '%,' + ( - 100 * object.center.y ) + '%)' + 'translate(' + ( _vector.x * _widthHalf + _widthHalf ) + 'px,' + ( - _vector.y * _heightHalf + _heightHalf ) + 'px)'; | ||
| // pivot point | ||
| const cx = 100 * object.center.x; | ||
| const cy = 100 * object.center.y; | ||
| element.style.transformOrigin = `${cx}% ${cy}%`; | ||
|
|
||
| // angle of rotation, counter-clockwise convention | ||
| const angle = - object.rotationAngle; | ||
|
|
||
| // coordinates | ||
| const tx = _vector.x * _widthHalf + _widthHalf; | ||
| const ty = -_vector.y * _heightHalf + _heightHalf; | ||
|
|
||
| // transform | ||
| element.style.transform = `translate(${-cx}%, ${-cy}%) translate(${tx}px, ${ty}px) rotate(${angle}rad)`; | ||
|
|
||
| if ( element.parentNode !== domElement ) { | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I did not change the implementation of the "center" API. (0, 0) was always the upper-left, not the lower-left, in this renderer.
The upper-left/lower-left convention is not consistent in three.js, and perhaps it would be advisable to agree to a convention going forward.