Skip to content

timklge/gd3-meshopt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gd3-meshopt

Simple GDNative bridge to the MeshOptimizer library using meshopt-rs. Using this library, LODs for ArrayMeshes can be built at runtime for procedurally generated or user-supplied geometry, e. g. voxel-based terrain. Additionally, the mesh is indexed, optimized for gpu vertex cache fetches and overdraw.

In Godot 4, the MeshImporter can be used instead of this library.

Example image

Usage

Example lives here.

var testmesh: MeshInstance = get_node("TestMesh")
var testmesh_lod0: MeshInstance = get_node("TestMesh_Lod0")
var testmesh_lod1: MeshInstance = get_node("TestMesh_Lod1")
	
var arrays: Array = testmesh.mesh.surface_get_arrays(0)
var input := {
	"vertex_positions": arrays[Mesh.ARRAY_VERTEX], # PoolVector3Array
	"vertex_normals": arrays[Mesh.ARRAY_NORMAL], # PoolVector3Array
	"vertex_coords": PoolVector2Array(), # PoolVector2Array
	"indices": arrays[Mesh.ARRAY_INDEX], # PoolIntArray
	"lods": PoolIntArray() # PoolIntArray
}

# Generate two lods with a target of 5000, 250 indices and 0.1 %, 2 % error targets
var result = meshOptimizer.simplify(input, PoolIntArray([5000, 250]), PoolRealArray([0.001, 0.02]))

# Result is a dictionary containing vertex_positions, vertex_normals, vertex_coords as above
# result["lods"] is a PoolIntArray array with length 2 with start index of the respective requested lods 
# result["indices"] contains the PoolIntArray index buffer of all lods - first the optimized original mesh, then the lods at the specified offsets 

Setup

To build, please read the instructions of the rust template wiki for setup.

If you only want to use the library, you can copy over the prebuilt gdnative library and gdnative script.

Run example

$ cargo make run

Acknowledgment

About

GDnative interface to the meshoptimizer library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published