Comments (4)
Hello, @aradhyamathur and @Caenorst. I have also been working on creating a function to convert Mesh to SDF using Kaolin. Following the advice of @aradhyamathur to apply torch.sqrt, I was able to solve the problem observed in the converted model. I am grateful for this valuable advice.
Here, I am sharing the function I developed. I hope it will be helpful to others who may face similar issues.
def mesh_to_sdf(obj_path, grid_size=64, batch_size=1):
if torch.cuda.is_available():
device = 'cuda'
else:
raise RuntimeError("CUDA is not available. Kernel error will occur without CUDA. Exiting.")
mesh = kal.io.obj.import_mesh(obj_path).to(device)
vertices = mesh.vertices
faces = mesh.faces
axis = torch.linspace(-0.5, 0.5, grid_size) # range of x, y, z axis
x, y, z = torch.meshgrid(axis, axis, axis)
grid_points = torch.stack([x, y, z], dim=-1).reshape(-1, 3).to(device)
grid_points_batch = grid_points.unsqueeze(0).repeat(batch_size, 1, 1)
vertices_batch = vertices.unsqueeze(0).repeat(batch_size, 1, 1)
face_vertices = kal.ops.mesh.index_vertices_by_faces(vertices_batch, faces)
squared_distance, _, _ = kal.metrics.trianglemesh.point_to_mesh_distance(grid_points_batch, face_vertices)
distance = torch.sqrt(squared_distance)
sign = kal.ops.mesh.check_sign(vertices_batch, faces, grid_points_batch)
sign_num = torch.where(sign, torch.tensor(-1.0).to(device), torch.tensor(1.0).to(device))
sdf = distance * sign_num
sdf_field = sdf.reshape(batch_size, 1, grid_size, grid_size, grid_size)
return sdf_field
from kaolin.
Hi @aradhyamathur , you can actually compute sdf by combining check_sign and point_to_mesh_distance. Please be careful to apply torch.sqrt
to point_to_mesh_distance
as the output is squared
from kaolin.
@maeda56 this assumes the bounds of the mesh to be in the range of [-0.5, 0.5] right ? should it be based on the grid of the bounds of the mesh or are the vertices always normalized for the mesh you use.
from kaolin.
@aradhyamathur Yes, this function targets meshes that fit within the range of [-0.5, 0.5] on all axes, x, y, and z. And before I use this function, I perform a normalization process to ensure they conform to the prescribed size.
from kaolin.
Related Issues (20)
- Nvdiffrast not installed automatically? HOT 2
- RuntimeError: "packed_rasterize_forward_cuda" not implemented for 'Half'
- Cannot render a mesh which only contains vertices and faces. no uvmap. HOT 1
- conflict with bpy
- Runtime with flexicubes
- Request for CPU-Only Wheels for Non-GPU Dependent Modules HOT 3
- use DMTeT on UDF field?
- Invitation to Your First Open Source Project Organization HOT 1
- About orthographic projection matrix HOT 2
- KNN Operation
- Operations for SPC aggregation and subdivision HOT 3
- How to calculate spc dual point coordinates. HOT 2
- Any suggestion about rendering transparent part? HOT 3
- Python3.11 builds HOT 1
- How to render shadow on the ground?
- Asking support for linear layer in spc features.
- Asking support for multiple-gpu training of structed point cloud class HOT 1
- No module named 'dmtet_network'
- [F glutil.cpp:338] eglInitialize() failed Aborted (core dumped) when render with kaolin and nvdiffrast
- ERROR: Failed building wheel for kaolin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaolin.