Git Product home page Git Product logo

voxelizer-rs's Introduction

voxelizer-rs

A Rust port of karimnaaji's C Voxelizer

This is a Rust port of karimnaaji's mesh voxelizer written in C. It is simple to use and has been carefully ported to Rust to give the most seamless experience possible.

Examples

  1. Voxelizing a mesh
let mesh = Mesh::new(vertices, colours, normals, indices);
let voxelized = mesh.voxelize(voxel_size, precision);
  1. Voxelizing a mesh into a point cloud
let mesh = Mesh::new(vertices, colours, normals, indices);
let pointcloud = mesh.voxelize_pointcloud(voxel_size, precision);
  1. Voxelizing a mesh into a texture (colour array).
let mesh = Mesh::new(vertices, colours, normals, indices);
let voxels = mesh.voxelize_texture(width, height, depth);

voxelizer-rs's People

Contributors

thearchitect4855 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

voxelizer-rs's Issues

A Potential Memory Leak Bug

After analyzing the following function:

pub fn voxelize(&self, voxel_size: Vector3, precision: f32) -> Mesh {
		let mesh = self.allocate();
		let mesh = unsafe { vx_voxelize(mesh, voxel_size.x, voxel_size.y, voxel_size.z, precision) };
		Mesh::from_vx(mesh)
	}

I noticed that the drop function of vx_mesh is not automatically called.

Below is the LLVM IR generated by llvm-dis for the voxelizer::mesh::voxelize function:

; Function Attrs: nonlazybind uwtable                                                                                           
   5108 define void @_ZN9voxelizer4Mesh8voxelize17h70fc830c707218e9E(ptr sret([96 x i8]) align 8 %_0, ptr align 8 %self, ptr align 4 %voxel_size, float %p        recision) unnamed_addr #3 !dbg !5554 {
   5109 start:                                                                                                                          
   5110   %mesh.dbg.spill2 = alloca ptr, align 8                                                                                        
   5111   %mesh.dbg.spill = alloca ptr, align 8                                                                                         
   5112   %precision.dbg.spill = alloca float, align 4                                                                                  
   5113   %self.dbg.spill = alloca ptr, align 8                                                                                         
   5114   store ptr %self, ptr %self.dbg.spill, align 8                                                                                 
   5115   call void @llvm.dbg.declare(metadata ptr %self.dbg.spill, metadata !5559, metadata !DIExpression()), !dbg !5566               
   5116   call void @llvm.dbg.declare(metadata ptr %voxel_size, metadata !5560, metadata !DIExpression()), !dbg !5567                   
   5117   store float %precision, ptr %precision.dbg.spill, align 4                                                                     
   5118   call void @llvm.dbg.declare(metadata ptr %precision.dbg.spill, metadata !5561, metadata !DIExpression()), !dbg !5568          
   5119   %mesh = call ptr @_ZN9voxelizer4Mesh8allocate17h0ee60983385d7061E(ptr align 8 %self), !dbg !5569                              
   5120   store ptr %mesh, ptr %mesh.dbg.spill, align 8, !dbg !5569                                                                     
   5121   call void @llvm.dbg.declare(metadata ptr %mesh.dbg.spill, metadata !5562, metadata !DIExpression()), !dbg !5570               
   5122   %_7 = load float, ptr %voxel_size, align 4, !dbg !5571                                                                        
   5123   %0 = getelementptr inbounds i8, ptr %voxel_size, i64 4, !dbg !5572                                                            
   5124   %_8 = load float, ptr %0, align 4, !dbg !5572                                                                                 
   5125   %1 = getelementptr inbounds i8, ptr %voxel_size, i64 8, !dbg !5573                                                            
   5126   %_9 = load float, ptr %1, align 4, !dbg !5573                                                                                 
   5127   %mesh1 = call ptr @vx_voxelize(ptr %mesh, float %_7, float %_8, float %_9, float %precision), !dbg !5574                      
   5128   store ptr %mesh1, ptr %mesh.dbg.spill2, align 8, !dbg !5574                                                                   
   5129   call void @llvm.dbg.declare(metadata ptr %mesh.dbg.spill2, metadata !5564, metadata !DIExpression()), !dbg !5575              
   5130   call void @_ZN9voxelizer4Mesh7from_vx17h2023875f2665ac52E(ptr sret([96 x i8]) align 8 %_0, ptr %mesh1), !dbg !5576            
   5131   ret void, !dbg !5577                                                                                                          
   5132 }

I believe the reason for this issue is that the return value of the vx_voxelize function is actually a raw pointer. Rust compiler does not automatically generate a drop function for raw pointers because the programmer is considered to control the lifetime of raw pointers. Consequently, the implementation of the Drop Trait for vx_mesh is not called.

I hope this clarifies the issue, and I appreciate any insights or assistance on resolving it. Thank you for your attention to this matter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.