ChrisWu1997 / PQ-NET

code for our CVPR 2020 paper "PQ-NET: A Generative Part Seq2Seq Network for 3D Shapes"
MIT License
116 stars 19 forks source link

Cannot assembly the object using the transformations provided #9

Closed ennauata closed 3 years ago

ennauata commented 3 years ago

Hello, I've been trying to add the object parts in a scene one by one using the transformations provided in the .h5 files but I usually get some misplaced parts. I might be missing something, so would appreciate if you could share some thoughts on this. Thanks a lot!

Code I'm using:

# unpack data
parts_voxel = np.array(data_dict['parts_voxel_scaled64'])
translations = np.array(data_dict['translations'])
scales = np.array(data_dict['scales'])

# transform 
scene = trimesh.Scene()
for parts, t, s in zip(parts_voxel, translations, scales):

    vertices, triangles = mcubes.marching_cubes(parts, 0)
    mesh = trimesh.Trimesh(vertices, triangles)
    mesh.apply_scale([s, s, s])
    mesh.apply_translation(t)
    scene.add_geometry(mesh)
    scene.show()

image image

Yishun99 commented 3 years ago

Hi @ennauata , I also encounter such problem, how did you solve it? Thanks.

ChrisWu1997 commented 3 years ago

The problem here is that we defined translations as the global position of the center point of the part. So you need to first put the part into local frame where its center becomes (0, 0, 0). Adding one line to the above code should solve this issue:

# unpack data
parts_voxel = np.array(data_dict['parts_voxel_scaled64'])
translations = np.array(data_dict['translations'])
scales = np.array(data_dict['scales'])

# transform 
scene = trimesh.Scene()
for parts, t, s in zip(parts_voxel, translations, scales):

    vertices, triangles = mcubes.marching_cubes(parts, 0)
    mesh = trimesh.Trimesh(vertices, triangles)
        mesh.apply_translation((-32, -32, -32))  # this line moves part so that its center lies in (0, 0, 0)
    mesh.apply_scale([s, s, s])
    mesh.apply_translation(t)
    scene.add_geometry(mesh)
    scene.show()
ennauata commented 3 years ago

Yes, I solved by translating the center of the of the cuboid to (0, 0, 0).

mesh.apply_translation((-32, -32, -32))

Yishun99 commented 3 years ago

Thank you very much.

CRISZJ commented 3 years ago

Yes, I solved by translating the center of the of the cuboid to (0, 0, 0).

mesh.apply_translation((-32, -32, -32))

Could you please provide the completed code about this problem? thanks

ChrisWu1997 commented 3 years ago

Yes, I solved by translating the center of the of the cuboid to (0, 0, 0). mesh.apply_translation((-32, -32, -32))

Could you please provide the completed code about this problem? thanks

There is a copy of complete code above. Does that solve your problem?

duzhenjiang113 commented 3 years ago

imageI divided the data into voxel and bouding-box. Among them, the bounding-box consists of six-dimensional data composed of translation and size*scale. Then I used a unified center point (0,0,0), and then put them together to get this situation.