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 Not Applied Correctly with obj.add_uv_mapping() on Imported Object (Issue Since v2.4.0, Working in v2.3.0) #1001

Closed
glonor opened this issue Nov 18, 2023 · 4 comments · Fixed by #1003
Labels
bug Something isn't working first answer provided

Comments

@glonor
Copy link

glonor commented Nov 18, 2023

Describe the issue

The add_uv_mapping() function does not apply the texture mapping as expected when used on an imported object without UV mapping, starting from version 2.4.0 of BlenderProc.

0

Minimal code example

import blenderproc as bproc

parser = argparse.ArgumentParser()
parser.add_argument('--model', nargs='?', help="Path to the 3D models")
parser.add_argument('--output_dir', nargs='?', help="Path to where the final files will be saved ")
parser.add_argument('--cc_textures_path', nargs='?', help="Path to the cc textures")
args = parser.parse_args()

bproc.init()        
bproc.camera.set_resolution(512, 512)

cc_textures = bproc.loader.load_ccmaterials(args.cc_textures_path)

obj = bproc.loader.load_obj(args.model)[0]

random_cc_texture = cc_textures[1]
obj.add_uv_mapping("smart", True)
obj.replace_materials(random_cc_texture) 

light = bproc.types.Light()
light.set_type("POINT")
light.set_location([5, 5, 5])
light.set_energy(1000)


poi = bproc.object.compute_poi([obj])
camera_location = [3,3,3]
rotation_matrix = bproc.camera.rotation_from_forward_vec(poi - camera_location)
cam2world_matrix = bproc.math.build_transformation_mat(camera_location, rotation_matrix)
bproc.camera.add_camera_pose(cam2world_matrix)

data = bproc.renderer.render()

bproc.writer.write_hdf5(args.output_dir, data)

Files required to run the code

# Cube.obj

# Vertices
v -1.0 -1.0 -1.0
v -1.0 -1.0  1.0
v -1.0  1.0 -1.0
v -1.0  1.0  1.0
v  1.0 -1.0 -1.0
v  1.0 -1.0  1.0
v  1.0  1.0 -1.0
v  1.0  1.0  1.0

# Faces (vertex indices only)
f 1 5 7 3
f 1 2 6 5
f 2 4 8 6
f 4 3 7 8
f 1 3 4 2
f 5 6 8 7

Expected behavior

obj.add_uv_mapping('smart', True) function should successfully apply the texture mapping to the imported object without any issues, as it did in version 2.3.0:

1

BlenderProc version

2.6.1

@glonor glonor added the question Question, not yet a bug ;) label Nov 18, 2023
@cornerfarmer
Copy link
Member

Can you please provide more details. So what code and which object do you use? What do you mean with as expected?

@glonor
Copy link
Author

glonor commented Nov 22, 2023

Edit: The original issue has been edited to include additional information.

@cornerfarmer
Copy link
Member

Thank you, this makes it way easier to reproduce the bug. Apparently, in some of the recent versions blender switched to not automatically selecting all faces in edit mode. The PR #1003 should fix that. Could you verify that the change fixes your problem?

@cornerfarmer cornerfarmer added bug Something isn't working and removed question Question, not yet a bug ;) labels Nov 23, 2023
@glonor
Copy link
Author

glonor commented Nov 23, 2023

Yes, I can confirm that the changes in the pull request #1003 have addressed the issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working first answer provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants