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

Exception: Invalid texture coordinates: (0.017; -0.0634) #35

Open
Franz362100 opened this issue Nov 22, 2022 · 7 comments
Open

Exception: Invalid texture coordinates: (0.017; -0.0634) #35

Franz362100 opened this issue Nov 22, 2022 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Franz362100
Copy link

I used the obj data exported by 3dmax, and the following error occurred.

!> Exception: Invalid texture coordinates: (0.017; -0.0634)

@pierotofy pierotofy added bug Something isn't working help wanted Extra attention is needed labels Nov 22, 2022
@STILLMOREzzz
Copy link

I have also encountered a similar problem, which is caused by the use of udim. I still don't know how to deal with this problem.
!> Exception: Invalid texture coordinates: (2.6630 0.2584)

@phoenixbf
Copy link

phoenixbf commented Feb 2, 2023

Hi, I have encountered the same problem. Maybe a possible fix could be clamping the uv coords parsed in Obj2Tiles.Library/MeshUtils.cs in [0,1]?

if (vtx.X < 0 || vtx.Y < 0 || vtx.X > 1 || vtx.Y > 1)
  throw new Exception("Invalid texture coordinates: " + vtx);

@phoenixbf
Copy link

any updates?
The process completely stops on several OBJs. Maybe it is sufficient to clamp uv coords instead of halting completely the process

@yashchauhan28
Copy link

This error is due to non-normalized UV coordinates. You can create a custom script or use Blender for this.

@pronitdas
Copy link

`import bpy

def normalize_uvs(mesh):
print(f"Processing object: {mesh.name}")

# Ensure the object is in object mode
bpy.ops.object.mode_set(mode='OBJECT')

# Get the UV layer
if mesh.data.uv_layers.active is None:
    print(f"No UV map found for object {mesh.name}")
    return

uv_layer = mesh.data.uv_layers.active.data

# Calculate the bounds of the UV coordinates
uvs = [uv.uv for uv in uv_layer]
min_uv = uvs[0].copy()
max_uv = uvs[0].copy()

for uv in uvs:
    min_uv.x = min(min_uv.x, uv.x)
    min_uv.y = min(min_uv.y, uv.y)
    max_uv.x = max(max_uv.x, uv.x)
    max_uv.y = max(max_uv.y, uv.y)

print(f"Min UV: {min_uv}, Max UV: {max_uv}")

# Calculate the scale to normalize the UVs
uv_scale = max_uv - min_uv

for uv in uvs:
    uv.x = (uv.x - min_uv.x) / uv_scale.x
    uv.y = (uv.y - min_uv.y) / uv_scale.y

print(f"UVs normalized for object {mesh.name}")

Loop over all selected objects

for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
normalize_uvs(obj)

print("UV normalization complete.")
`

used this to get away with the error. but the textures messed up a bit.

@amiuhle
Copy link

amiuhle commented Nov 3, 2024

#62 seems to have fixed this for me.

@jqntn
Copy link

jqntn commented Nov 21, 2024

#62 only fixed half the issue :/ Hope this gets fixed soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants