-
Notifications
You must be signed in to change notification settings - Fork 18
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
Ask for example: mesh interoperation through vertices and faces with other libraries #91
Comments
Hello, Of course it is possible to numpy arrays. madcad meshes are using To ease the conversion to unstructured dtypes (which are more common), there is functions >>> cube = mc.brick(width=vec3(1))
# extract points
>>> print(cube.points)
typedlist([dvec3( 0.5, -0.5, -0.5 ), ...])
# convert it to structured numpy
>>> np.asarray(cube.points)
array([( 0.5, -0.5, -0.5), ...],
dtype=[('f0', '<f8'), ('f1', '<f8'), ('f2', '<f8')])
# convert it to unstructured numpy
>>> mc.typedlist_to_numpy(cube.points, 'f8')
array([[ 0.5, -0.5, -0.5], ...], dtype=float64) Now to convert a whole mesh from and to other libraries formats, you will need to cast the foreign mesh from/to numpy arrays yourself. madcad does not provide conversions into other libraries proper data formats. import madcad, pymesh
from madcad.mesh import numpy_to_typedlist, typedlist_to_numpy
# assuming you have data from pymesh
pymesh_source = pymesh.load_mesh("cube.obj")
pymadcad_object = madcad.Mesh(numpy_to_typedlist(pymesh_source.vertices, vec3), numpy_to_typedlist(pymesh_source.faces, uvec3))
pymesh_back = pymesh.form_mesh(typedlist_to_numpy(pymadcad_object.points, 'f4'), typedlist_to_numpy(pymadcad_object.faces, 'u4')) edit: forgot dtypes in pymesh conversions |
Great. Thank you Jimy! |
I think such conversion is easy enough to not write an example program in folder |
I tried to convert open3d mesh to madcad mesh without success. ` import open3d as o3d import numpy as np vertices = np.asarray( o3d_mesh.vertices,dtype=np.float32) mc_mesh = mc.Mesh(mc.mesh.numpy_to_typedlist(vertices, dtype=np.float32), mc.mesh.numpy_to_typedlist(faces), dtype=np.uint) mc.show([mc_mesh]) `
|
you should try the triple backticks |
Hello,
Just wonder if it is possible to construct a madcad mesh with just numpy array vertices and numpy array faces, and also back to numpy array vertices and numpy array faces from madcad mesh.
Thanks
The text was updated successfully, but these errors were encountered: