[BUG] Failed to load custom mesh
LexTran opened this issue · comments
Describe the bug
Hi, I was trying to use meshtaichi
to do some work, however I've reached a problem as following link says:
https://github.com/taichi-dev/meshtaichi/issues/6#issuecomment-1482326513
Warning: cell_type "tetra" is not supported by PLY format - skipping
D:\Anaconda3\envs\taichi\lib\site-packages\meshio\ply\_ply.py:380: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of
numpy, it will be understood as (type, (1,)) / '(1,)type'.
[("count", count_dtype), ("data", data_dtype * cells_per_row)]
Traceback (most recent call last):
File "E:\Work\mesh_demo.py", line 39, in <module>
theMesh = Patcher.load_mesh("sphere.ply", relations=["FV"])
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 32, in load_mesh
return ti.Mesh._create_instance(mesh2meta(meshes,
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 100, in mesh2meta
total = load_mesh_rawdata(total)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 156, in load_mesh_rawdata
m = meshio.read(filename)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\_helpers.py", line 71, in read
return _read_file(Path(filename), file_format)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\_helpers.py", line 103, in _read_file
return reader_map[file_format](str(path))
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\ply\_ply.py", line 61, in read
mesh = read_buffer(f)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\ply\_ply.py", line 144, in read_buffer
mesh = _read_binary(
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\ply\_ply.py", line 316, in _read_binary
buffer_increment, cell_data[name] = _read_binary_list(
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\ply\_ply.py", line 384, in _read_binary_list
cell_type = cell_type_from_count(cells.shape[1])
IndexError: tuple index out of range
As you can see, meshtaichi
uses meshio
to load mesh, but it cames an error.
Also I've tried to load a custom mesh generated by Blender
and I've reached another problem which seems also comes from meshio
:
Traceback (most recent call last):
File "E:\Work\WEB_mesh.py", line 8, in <module>
theMesh = Patcher.load_mesh("WEB1.obj", relations=["FV"])
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 32, in load_mesh
return ti.Mesh._create_instance(mesh2meta(meshes,
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 100, in mesh2meta
total = load_mesh_rawdata(total)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshtaichi_patcher\__init__.py", line 156, in load_mesh_rawdata
m = meshio.read(filename)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\_helpers.py", line 71, in read
return _read_file(Path(filename), file_format)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\_helpers.py", line 103, in _read_file
return reader_map[file_format](str(path))
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\obj\_obj.py", line 18, in read
mesh = read_buffer(f)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\obj\_obj.py", line 98, in read_buffer
return Mesh(points, cells, point_data=point_data, cell_data=cell_data)
File "D:\Anaconda3\envs\taichi\lib\site-packages\meshio\_mesh.py", line 166, in __init__
raise ValueError(
ValueError: len(points) = 7556, but len(point_data["obj:vt"]) = 7668
To Reproduce
I'm not sure if this would help, but I'm gonna put the code I use here:
import pygmsh
import meshio
import taichi as ti
import meshtaichi_patcher as Patcher
import numpy as np
with pygmsh.occ.Geometry() as geom:
# Define an ellipsoid with semi-axes 1, 1, 1
ellipsoid = geom.add_ellipsoid([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])
# Define a disk with radius 1 and center at origin
disk = geom.add_disk([0.0, 0.0], 1.0)
# Intersect the ellipsoid and the disk to get a spherical surface
sphere = geom.boolean_intersection([ellipsoid], [disk])
# Set the maximum characteristic length of the mesh to 0.1
geom.characteristic_length_max = 0.1
# Generate the mesh
mesh = geom.generate_mesh()
# Write the mesh to a file using meshio
meshio.write("sphere.ply", mesh)
# Plot the mesh using taichi
# load the mesh, define the relations in advance,
# F represents faces, E represents edges and V represents vertices
theMesh = Patcher.load_mesh("sphere.ply", relations=["FV"])
# define the x field, which is the position of each vertex
theMesh.verts.place({'x' : ti.math.vec3})
# transfer the data from numpy to taichi
theMesh.verts.x.from_numpy(theMesh.get_position_as_numpy())
# define a field to store the indices
display_indices = ti.field(ti.i32, shape = len(theMesh.faces) * 3)
# transfer the vertex indices of each face to the display_indices field
@ti.kernel
def init_surf_indices(mesh: ti.template(), indices: ti.template()):
for f in mesh.faces:
for j in ti.static(range(3)): # three vertices per face
indices[f * 3 + j] = mesh.faces[f][j]
init_surf_indices(theMesh, display_indices)
window = ti.ui.Window("taichimesh", (1024, 1024))
canvas = window.get_canvas()
scene = ti.ui.Scene()
camera = ti.ui.Camera()
camera.up(0, 1, 0)
camera.fov(75)
camera.position(4.5,4.5,0.6)
camera.lookat(3.8, 3.8, 0.5)
camera.fov(75)
frame = 0
paused = ti.field(int, shape=())
paused[None] = 1
while window.running:
for e in window.get_events(ti.ui.PRESS):
if e.key == ti.ui.SPACE:
paused[None] = not paused[None]
print("paused:", paused[None])
if not paused[None]:
# substep()
print(f"frame: {frame}")
frame += 1
# print("camera.curr_position",camera.curr_position)
# print("camera.curr_lookat",camera.curr_lookat)
# wasdqe can move the camera
camera.track_user_inputs(window, movement_speed=0.05, hold_key=ti.ui.RMB)
scene.set_camera(camera)
# render the mesh
scene.mesh(theMesh.verts.x, display_indices, color = (0.5,0.5,0.5))
scene.particles(theMesh.verts.x, radius=1e-2, color = (1,0.5,0.5))
scene.point_light(pos=(0.5, 1.5, 0.5), color=(1, 1, 1))
scene.ambient_light((0.5,0.5,0.5))
canvas.scene(scene)
window.show()
Diagnose
meshio==5.3.4
meshplex==0.19.1
meshtaichi-patcher==0.0.19
meshzoo==0.11.1
pygmsh==7.1.17
Did I help?
If I was able to resolve your problem, consider sponsoring my work on meshio, or buy me a coffee to say thanks.
Did you ever end up solving this? I am getting the same issue.