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

Texture: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures #1089

Open
Adolio opened this issue Oct 14, 2021 · 5 comments
Labels

Comments

@Adolio
Copy link
Contributor

Adolio commented Oct 14, 2021

Hey Daniel,

I recently discovered that the UV mapping of textures part of an atlas (with frame mode active) doesn't fully natively work. I noticed that while trying to implement a missing feature in DragonBonesAS: DragonBones/DragonBonesAS#94 - this might have been the issue the team faced when trying to implement it back then.

Please tell me if you think it's worth integrating in vanilla Starling - I can try to do a pull request then.

Workaround

Here is an utility method that supports SubTexture with the framing capability:

/**
 * Sets the texture coordinates of the vertex at the specified index to the given values.
 *
 * <p>Note: This method also supports `SubTexture` with framing.</p>
 */
public static function setTexCoords(image:Image, vertexID:int, u:Number, v:Number):void
{
	// adjust uv when the texture is a `SubTexture` and contains a frame
	if (image.texture is SubTexture)
	{
		var subTex:SubTexture = image.texture as SubTexture;
		if (subTex.frame != null)
		{
			u = (u * subTex.frame.width + subTex.frame.x) / subTex.region.width;
			v = (v * subTex.frame.height + subTex.frame.y) / subTex.region.height;
		}
	}

	// update vertex uv
	image.setTexCoords(vertexID, u, v);
}

Note: the problem with this method is the fact that if you get the coordinates afterwards you won't get the value you have set at the first place. This might be confusing... Another option would be to fix this even deeper in the rendering logic or implement the reversed logic in the getter.

@Adolio Adolio changed the title Mesh Style: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures Texture: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures Oct 14, 2021
@PrimaryFeather
Copy link
Contributor

Hey Aurélien!

You're right, this would be ideally fixed right at the core of Starling. I wasn't aware of that limitation — but, on the other hand, that frame rectangle has caused me countless headaches over the years, so it doesn't surprise me that I overlooked that here. 😉

Could you do me a favor and also post a small pseudo-unit test? I.e. some code that produces a specific output, and the values it ought to print out instead? So that I'm sure I'm looking at the right thing.

Thanks in advance!

@Adolio
Copy link
Contributor Author

Adolio commented Oct 27, 2021

Sorry for the late response Daniel.. 🙄

You're right, this would be ideally fixed right at the core of Starling. I wasn't aware of that limitation — but, on the other hand, that frame rectangle has caused me countless headaches over the years, so it doesn't surprise me that I overlooked that here. 😉

Not a big deal, you already did a massive work to hide so much complexity for us - which is really appreciated!

Could you do me a favor and also post a small pseudo-unit test? I.e. some code that produces a specific output, and the values it ought to print out instead? So that I'm sure I'm looking at the right thing.

Sure! Will do it as soon as I find the time. I also wanted to try implementing this right away in Starling but I don't have the right to access the archive you are mentioning here: https://github.com/Gamua/Starling-Framework/blob/master/tests/README.md

Can you give me access to it?

@PrimaryFeather
Copy link
Contributor

PrimaryFeather commented Oct 27, 2021

Thanks for the update, Aurélien! No worries, look into it only when you've got the time.

It's strange that you can't access that link! Google claims it should be all public.
But since there's an abundance of sharing services nowadays, anyway, I simply uploaded it here: https://web.tresorit.com/l/YCpuP#RahnBNC63NOzyYpNtIMGwg

That should work, hopefully! 😄

@MNiceback
Copy link

MNiceback commented Oct 27, 2021 via email

@PrimaryFeather
Copy link
Contributor

@maxime, you can click on the "unsubscribe" button at the bottom of every email from GitHub! I don't think it's possible for me to unsubscribe you from this list.

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

No branches or pull requests

3 participants