huxingyi / simpleuv

Automatic UV Unwrapping Library for Dust3D
https://github.com/huxingyi/dust3d
MIT License
83 stars 18 forks source link

Support for texel size as input parameter #1

Open reduz opened 5 years ago

reduz commented 5 years ago

For game engines, you often need to specify what a texel size will be in world coordinates (as in, meters or centimeters), then the unwrapper not only unwraps but decides what the texture size should be in order to make sure texels are the specified size.

huxingyi commented 5 years ago

Hi @reduz Currently the packing is pack to a square area, which means the same size with with and height, and the final texture coords is normalized to 0.0 ~ 1.0; So I guess you can multiply to what size you want. Unless you want specify the ratio of texture width and height. Maybe need a new api such as setPackRatio(float ratio).

reduz commented 5 years ago

The problem with this is the padding between the elements. If you know the right texel size, you can do proper padding in the packer (since the actual sizes are known). Otherwise I may scale the texture but padding will be wrong.

huxingyi commented 5 years ago

Ok, after I read the code in xatlas, I got what you mean. I will add this parameter for specify the texel size in the following days.

huxingyi commented 5 years ago

The texel size api is ready: https://github.com/huxingyi/simpleuv/blob/8375bb416a8a8bba9ef7fca65635ceaed0c19b72/simpleuv/uvunwrapper.h#L16

I also removed the Qt dependence.

reduz commented 5 years ago

@huxingyi Amazing, thanks!

@JFonS since you are working on the new Lightmapper in Godot, want to give this a spin?

reduz commented 5 years ago

@huxingyi btw I see you allow setting texel size, but how do you actually obtain the texture size back?

huxingyi commented 5 years ago

https://github.com/huxingyi/simpleuv/blob/8375bb416a8a8bba9ef7fca65635ceaed0c19b72/simpleuv/uvunwrapper.h#L21

This can be used to fetch the actual square size, width and height are the same.

reduz commented 5 years ago

oh i see, looks great

FSSRepo commented 4 years ago

Hello, may you help to use this library please, some example please. I want to contact with you.

huxingyi commented 4 years ago

Hi @FSSRepo Please see the example here: https://github.com/huxingyi/dust3d/blob/610bc978a8021ee34be33ca45ff90fb14ef444de/src/uvunwrap.cpp#L58

FSSRepo commented 4 years ago

Thank you, :), I hope it works