-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Sprite: Add center property #12931
Sprite: Add center property #12931
Conversation
Cool! 👍 |
@mrdoob Can we discuss this? I am open to alternative APIs... I think being able to anchor a sprite at a point other than its center is a nice feature. Since all sprites share the same geometry, we can't translate the geometry itself, but instead make the adjustment in the vertex shader -- just as we do when we rotate a sprite. |
Looks good! Instead of |
Also I would set it to |
I will definitely maintain backwards compatibility. But currently, the center is ( 0, 0 ); lower left Is ( - 0.5, - 0.5 ). This is because the sprite geometry is centered a the origin. What we are specifying, in effect, is a translation of the geometry. This is obviously different than CSS. |
Ah, I see... Yeah, I don't think that's very intuitive. I was thinking that by renaming it to |
We can name it We could name it |
I think 0,0 would be top-left. When dealing with 2D concepts I think it's more intuitive to think 0,0 being top-left. At least that way |
We can declare ( 0.5, 0.5 ) to be the center of the sprite, as it is for textures. But ( 0, 0 ) is the lower-left for textures (since these are uv coordinates). https://threejs.org/examples/webgl_materials_texture_rotation.html |
I see... Okay, let's do that. |
Done! |
Sweet! Thanks! |
Hmmm, I guess we should add this to a example? |
This feature was added to an existing example in this PR. |
Oh, true... |
Hmm... I just tried adding: spriteTL.rotation += 0.01;
spriteTR.rotation += 0.01;
spriteBL.rotation += 0.01;
spriteBR.rotation += 0.01; And I noticed/remembered that the |
Hmm... Maybe a new example is required... |
It can be handy when used with text labels -- not for rotating them necessarily, but for adjusting the anchor point. |
As discussed in #12878.
The nomenclature or API can be changed, but I think this is a long-overdue feature that is useful in positioning sprites -- and in particular, text sprites.
Sprites can now be left-, center-, or right-justified relative to the sprite's position.
Sprites now rotate around, and scale relative to, their pivot.