RefMesh
Overview
RefMesh is PlantGeom's reference geometry container. It stores one canonical mesh plus metadata (material, normals, optional UVs). Node geometries then reuse the same reference mesh with per-node transformations.
Why Reference Meshes?
Instead of duplicating a full mesh for every organ instance, PlantGeom stores one mesh per organ kind and transforms it at runtime. This is memory-efficient and matches OPF semantics.
Structure
A RefMesh contains:
name: reference mesh name.mesh:GeometryBasics.Mesh(triangular mesh).normals,texture_coords,material,tapermetadata.
Create a RefMesh
From Vertices and Faces
mesh_vertices = [
PlantGeom.Point3(0.0, 0.0, -0.5),
PlantGeom.Point3(1.0, 0.0, -0.5),
PlantGeom.Point3(1.0, 0.0, 0.5),
PlantGeom.Point3(0.0, 0.0, 0.5),
]
mesh_faces = [
Tri(1, 2, 3),
Tri(1, 3, 4),
]
plane = GeometryBasics.Mesh(mesh_vertices, mesh_faces)
ref_mesh = RefMesh("plane", plane, RGB(0.2, 0.7, 0.3))
plantviz(ref_mesh)From a Generated Mesh
sphere_like = GeometryBasics.Mesh(
[
PlantGeom.Point3(0.0, 0.0, 1.0),
PlantGeom.Point3(1.0, 0.0, 0.0),
PlantGeom.Point3(0.0, 1.0, 0.0),
PlantGeom.Point3(-1.0, 0.0, 0.0),
PlantGeom.Point3(0.0, -1.0, 0.0),
PlantGeom.Point3(0.0, 0.0, -1.0),
],
Tri[
Tri(1, 2, 3), Tri(1, 3, 4), Tri(1, 4, 5), Tri(1, 5, 2),
Tri(6, 3, 2), Tri(6, 4, 3), Tri(6, 5, 4), Tri(6, 2, 5),
],
)
sphere_refmesh = RefMesh("sphere_like", sphere_like, RGB(0.7, 0.4, 0.3))
plantviz(sphere_refmesh)Cylinder-like Primitive
plantviz(cylinder_refmesh)Access Properties
(name=cylinder_refmesh.name,
nvertices=nvertices(cylinder_refmesh),
nelements=nelements(cylinder_refmesh))(name = "cylinder_1", nvertices = 32, nelements = 60)Meshes.jl Interop
PlantGeom's core backend is GeometryBasics, but you can build meshes in Meshes.jl and convert them using the optional extension API:
to_geometrybasics(mesh::Meshes.SimpleMesh)to_meshes(mesh::GeometryBasics.Mesh)to_meshes(ref_mesh::RefMesh)
Build a RefMesh from Meshes.jl
using Meshes
mesh_meshes = Meshes.CylinderSurface(
Meshes.Point(0.0, 0.0, 0.0),
Meshes.Point(0.0, 0.0, 1.0),
0.2,
) |> Meshes.discretize |> Meshes.simplexify
mesh_gb = to_geometrybasics(mesh_meshes)
ref_from_meshes = RefMesh("cylinder_from_meshes", mesh_gb, RGB(0.3, 0.5, 0.8))
plantviz(ref_from_meshes)Convert Back to Meshes.jl
mesh_back = to_meshes(ref_from_meshes)
(
nverts_meshes = length(collect(Meshes.vertices(mesh_back))),
nfaces_meshes = length(collect(Meshes.elements(Meshes.topology(mesh_back)))),
)(nverts_meshes = 152, nfaces_meshes = 300)