Skip to content
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

Merged
merged 2 commits into from
Jan 19, 2018
Merged

Sprite: Add center property #12931

merged 2 commits into from
Jan 19, 2018

Conversation

WestLangley
Copy link
Collaborator

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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 20, 2017

Cool! 👍

@WestLangley
Copy link
Collaborator Author

@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.

@mrdoob
Copy link
Owner

mrdoob commented Jan 10, 2018

Looks good! Instead of pivot I think I would call it center though.

@mrdoob
Copy link
Owner

mrdoob commented Jan 10, 2018

Also I would set it to 0.5, 0.5 by default to maintain backwards compatibility.

@WestLangley
Copy link
Collaborator Author

Also I would set it to 0.5, 0.5 by default to maintain backwards compatibility.

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.

@mrdoob
Copy link
Owner

mrdoob commented Jan 10, 2018

Ah, I see... Yeah, I don't think that's very intuitive. I was thinking that by renaming it to center we could align the usage a bit to Texture's center.

@WestLangley
Copy link
Collaborator Author

We can name it center, and we could delcare ( 0.5, 0.5 ) to be the center of the texture, but where is ( 0, 0 ) then? -- top left as in canvas, or bottom left as in UVs? That is a bit confusing.

We could name it offset, in which case ( 0, 0 ) would be the center, ( -0.5, 0.5 ) would be the top left. (I favor this solution, I think.)

@mrdoob
Copy link
Owner

mrdoob commented Jan 12, 2018

We can name it center, and we could delcare ( 0.5, 0.5 ) to be the center of the texture, but where is ( 0, 0 ) then? -- top left as in canvas, or bottom left as in UVs? That is a bit confusing.

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 Sprite's center will match Texture's center.

@WestLangley
Copy link
Collaborator Author

I think 0,0 would be top-left. ... At least that way Sprite's center will match Texture's center.

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

@mrdoob mrdoob added this to the r90 milestone Jan 17, 2018
@mrdoob
Copy link
Owner

mrdoob commented Jan 19, 2018

I see... Okay, let's do that.

@WestLangley
Copy link
Collaborator Author

Done!

@mrdoob mrdoob merged commit 267b868 into mrdoob:dev Jan 19, 2018
@mrdoob mrdoob changed the title Add Sprite pivot property Sprite: Add center property Jan 19, 2018
@mrdoob
Copy link
Owner

mrdoob commented Jan 19, 2018

Sweet! Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Mar 1, 2018

Hmmm, I guess we should add this to a example?

@WestLangley
Copy link
Collaborator Author

Hmmm, I guess we should add this to a example?

This feature was added to an existing example in this PR.

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2018

Oh, true...
I guess the example doesn't showcase the new feature.
Let me fix that.

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2018

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 rotation is in the material 🤔

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2018

Hmm... Maybe a new example is required...

@WestLangley
Copy link
Collaborator Author

It can be handy when used with text labels -- not for rotating them necessarily, but for adjusting the anchor point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants