Klamp't Manual: Geometry and Appearance

August 4, 2025 ยท View on GitHub

Klamp't uses a variety of geometry types to define geometric primitives, triangulated meshes, and point clouds. Each geometry may also be associated with an Appearance.

Geometries and collision geometries

Klamp't stores Geometry datain an object's local frame.

Illustration of concepts

The notion of a collision geometry combines some underlying geometric data with transformations and collision acceleration structures. Collision geometries have a current transformation that sets where they exist in space, and is used for collision testing. Collision geometries also support an additional, nonnegative margin setting that "expands" the underlying geometry when performing collision testing. The margin does not actually affect the geometric data, but rather it changes the distance threshold that is used to consider colliding vs. noncolliding geometries.

Geometric representations

The following geometric representations are currently supported:

  • Geometric primitive (Primitive): axis-aligned boxes, oriented boxes, lines, rays, segments, triangles, planar polygons, spheres, ellipsoids, and planar circles.
  • Convex polytope (ConvexHull): A convex hull of a set of points.
  • Triangle mesh (TriangleMesh): the most common geometry representation used in video games and CAD models. Can also contain appearance data.
  • Point cloud (PointCloud): most commonly used in laser scanners and RGBD sensors. Can also contain color and other per-point properties. If the radius property is given, then each point is treated like a sphere.
  • Implicit surface voxel grid (ImplicitSurface): a volumetric representation where values < 0 are inside, 0 is the surface, and > 0 are outside. Usually a signed distance function (SDF). Can also represent other implicit functions and TSDFs for some operations (visualization, conversion, inside-outside tests).
  • Occupancy map voxel grid (OccupancyGrid): a volumetric representation where values > 0.5 (or some other value) are occupied.
  • Height map / depth map (Heightmap): an elevation map or a perspective depth map. Can also contain color and other properties.

In addition, there is a notion of a geometry Group, which can combine multiple sub-geometries.

Geometric operation support

Not all representations support all operations, and some representations yield much better performance (speed and accuracy) than others. To get optimal performance from your program, you should learn which operations are suited for which representations.

To get a better sense of how operations affect the geometries, the geometrytest.py test program in Klampt-examples can be used. This allows you to convert any two geometries into any supported format and perform various queries. Use the Actions menu to convert and switch between proximity query modes. Klampt-examples and geometrytest.py on Github.

geometrytest.py

The rest of this section provides detailed information about Klampt's support for various geometry operations. (Here, ๐Ÿ•‘ means support is on the TODO list for the near future.)

Loading / Saving

All types supported.

Triangle meshes can be saved/loaded from nearly all types (STL, OBJ, OFF, PLY, GLTF, etc), unless you are building from source and Assimp is unavailable at build time.

Point clouds can be saved/loaded from PCL format.

Primitives, convex hulls, and voxel grids use custom formats.

Heightmaps are stored in a custom JSON format. Heightmap images can be loaded from many image file formats on Windows or if ImageMagick was installed while KrisLibrary is built; otherwise, only BMP, TGA, and PPM are supported.

OpenGL drawing

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
โœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ

Type conversions

(Converting from the type listed in column to type listed in row.)

To โ†“ \ From โ†’Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโŒโŒโŒโŒโŒโŒ
CPโœ”๏ธโœ”๏ธยนโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
TMโœ”๏ธโœ”๏ธโŒโœ”๏ธโœ”๏ธโœ”๏ธ
PCโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
ISโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒโœ”๏ธ
OGโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
HMโœ”๏ธโŒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
  1. Convex decomposition of a non-convex watertight mesh can be performed with an appropriate parameter to the convert function.

These are shown in the following image:

Geometry conversion image

Note that a depth map is considered to be viewed from the "bottom up", so the occupied space is considered to be any space above the map. Here, the depth values outside of the sphere are assumed invalid.

Indirect conversions to a third type can be used to do some unsupported conversions. For example, convex polytope -> triangle mesh -> heightmap can replace the unsupported convex polytope -> heightmap conversion. Occupancy grid -> triangle mesh -> implicit surface can replace the unsupported occupancy grid -> implicit surface conversion.

Many conversions (mesh -> convex polytope, implicit surface, occupancy grid, heightmap) also depend on a resolution parameter. If the resolution is set too low, then the fidelity of the resulting geometry may suffer. As an example, the below image shows a CAD model of the Boston Dynamics Atlas torso converted to an implicit surface at two different resolutions:

Implicit surface conversion image

If in doubt, you should visualize the result (in Python, you can simply run from klampt import vis; vis.debug(geom)).

Conversion from a group to a target type is only available when:

  1. There is a single object that can be converted to the target type.
  2. The target is triangle mesh or point cloud, and all objects can be converted to the target type.

We perform computation speed tests to profile the performance of geometric operations. The test set contains both simple and complex geometries and is tested on a machine with a 5.4 Ghz Intel i9 processor. Simple test geometries are approximately spherical, have unit size, and have the following complexity:

  • GP: sphere
  • CP: 8 vertices
  • TM: 624 triangles
  • PC: 761 points
  • IS/OG: 64 x 64 x 64 grid
  • HM: 256 x 256 grid

While complex test geometries have the following complexity:

  • CP: 3,122 vertices
  • TM: 70,224 triangles
  • PC: 157,000 points
  • IS/OG: 256 x 256 x 256 grid
  • HM: 2,048 x 2,048 grid

Example conversion speeds are shown below (in ms). Algorithmic complexity is approximately linear in the number of elements for all representations except for Convex Polytope, which is superlinear. Conversions are listed from the type listed in column to type listed in row.

Simple geometries:

From โ†’ / To โ†“Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive
ConvexHull2.2896.2442.838495.6492.8271192.522
TriangleMesh0.0110.04438.9450.1737.988
PointCloud0.0560.0490.1027.2860.0433.521
ImplicitSurface0.49917.71222.407106.069
OccupancyGrid0.56917.7321.5080.0381.025106.331
Heightmap5.3964.4280.81212.1080.052

Complex geometries:

From โ†’ / To โ†“Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive0.000
ConvexHull0.0720.002765.82170.13912509.0971614.3233989.334
TriangleMesh0.00121.8020.707978.975766.626718.425
PointCloud0.00522.91310.8268.696631.070619.788424.437
ImplicitSurface0.351236.13514057.82533.7956995.770
OccupancyGrid0.387239.799165.434174.88883.79633.4897010.963
Heightmap10.66132.3638.649993.740992.1104.293

Proximity query acceleration data structures

To accelerate proximity queries (collision, ray casting, distances, etc.), most geometries create auxiliary data structures. These are initialized when a proximity query is first called. These structures are cached as long as the collision geometry undergoes rigid transforms via SetTransform (C++) / setCurrentTransform (Python).

However, the data structures must be refreshed if the geometry data is changed. The overhead of precomputation can be small for simple geometries. However, for complex geometries, the overhead can be substantial, so it is best to avoid interleaving changes to the geometry data with proximity queries.

Geometric primitiveNone
Convex polytopeSOLID3 data structure
Triangle meshPQP bounding volume hierarchy
Point cloudSparse voxel grid and octree
Implicit surfaceOctree
Occupancy gridList of occupied and surface cells
HeightmapNone

Example precomputation speeds are shown below (in ms):

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Simple0.0000.0001.2030.1420.9751.3950.128
Complex0.0000.000504.04413.737630.6961073.3317.041

Miscellaneous queries

Bounding box queries yield an axis-aligned (C++ and Python) or oriented bounding box (C++ only).

Bounding boxes

Ray casts find the first point of intersection between the geometry and a ray.

Ray cast

Support queries find the farthest point on the geometry in some direction.

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Bounding boxโœ”๏ธโœ”๏ธโœ”๏ธยนโœ”๏ธยนโœ”๏ธโœ”๏ธโœ”๏ธ
Ray castโœ”๏ธโŒยฒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
Supportโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒโŒ
  1. A fast approximate method is available.
  2. A limitation of SOLID3.

Point queries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Containmentโœ”๏ธโœ”๏ธโœ”๏ธยนโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
Distanceโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธโœ”๏ธยฒโœ”๏ธยฒ๐Ÿ•‘๐Ÿ•‘
  1. uses a heuristic to determine inside/outside.
  2. signed distance supported.

An example of point containment queries is shown below.

Point containment

An example of a point distace query is shown below with the query asking for the distance and closest point on the red geometry to the center of the green circle.

Point distance

Example computation speeds are shown below (in ms):

Simple geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Bounding box0.0000.0010.0000.0000.0010.0010.000
Ray cast0.0000.0000.0000.0000.0000.003
Support0.0000.0000.0010.003
Pt. Containment0.0000.0020.0050.0000.0000.0000.000
Pt. Distance0.0000.0030.0060.0030.000

Complex geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Bounding box0.0010.0030.0010.0000.0010.0010.001
Ray cast0.0000.0000.0000.0000.0000.020
Support0.0000.0000.0470.538
Pt. Containment0.0000.0030.0040.0000.0000.0000.000
Pt. Distance0.0000.0050.0100.0420.000

Collision detection

Collision detection detects whether two objects overlap. The extended version returns the element indices that overlap up to some number of max contacts, and if max contacts = 1 this costs no more time than the simple (boolean) version. Below, the orange triangles on the red object collide with the green triangles on the yellow object.

Collision detection example

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยนโœ”๏ธยฒโœ”๏ธยณ
CPโœ”๏ธยฒโœ”๏ธโœ”๏ธโœ”๏ธโŒโœ”๏ธยณโœ”๏ธยณ
TMโœ”๏ธยฒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณ
PCโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธยณโœ”๏ธ
ISโœ”๏ธยนโŒโœ”๏ธยณโœ”๏ธโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณ
OGโœ”๏ธยฒโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโœ”๏ธ
HMโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโœ”๏ธโœ”๏ธยณโœ”๏ธ๐Ÿ•‘
  1. for a couple geometric primitives (usually point and sphere).
  2. for common geometric primitives (usually point, sphere, box, and triangle)
  3. not accelerated, or scaling to large geometries is poor.

Within-distance detection is a boolearn query that detects whether two objects are within a given distance from one another. It is usually faster than distance calculation. The extended version returns the element indices that overlap up to some number of max contacts, and if the max contacts = 1 then this costs no more time than the simple (boolean) version. Below, the orange triangles on the red object are within 0.1 units from the green triangles on the yellow object.

Within distance example

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยนโœ”๏ธยฒโŒ
CPโœ”๏ธยฒโœ”๏ธโœ”๏ธโœ”๏ธโŒโœ”๏ธยณโŒ
TMโœ”๏ธยฒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธยณโœ”๏ธยณโŒ
PCโœ”๏ธยฒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธยณโŒ
ISโœ”๏ธยนโŒโœ”๏ธยณโœ”๏ธโœ”๏ธยณโœ”๏ธยณโŒ
OGโœ”๏ธยฒโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโœ”๏ธยณโŒโŒ
HMโŒโŒโŒโŒโŒโŒโŒ
  1. for a couple geometric primitives (usually point and sphere).
  2. for common geometric primitives (usually point, sphere, box, and triangle)
  3. not accelerated, or scaling to large geometries is poor.

Example computation speeds are shown below (in ms). Note that speeds vary significantly on the relative pose, size, and resolution of the objects, where performance worsens with close-but-not-colliding, highly overlapping, similar sized, and high-resolution objects.

Simple geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GP0.0000.0030.0010.0140.0010.0070.011
CP0.0030.0020.0110.0140.0040.072
TM0.0010.0110.0120.4370.1240.6170.029
PC0.0140.0140.4370.1700.0398.0420.016
IS0.0010.1240.0398.4391.3140.499
OG0.0070.0040.6178.0421.3141.3960.932
HM0.0110.0720.0290.0160.4990.932

Complex geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GP0.0010.0070.0020.3130.0050.001
CP0.0070.0068.82728.4040.08963.090
TM0.0028.8270.0112.2954.60831.0100.884
PC0.31328.4042.2954.5371.905560.1860.021
IS4.6081.9057.50487.1303.685
OG0.0050.08931.010560.18687.13027.40712.617
HM0.00163.0900.8840.0213.68512.617

Distance query

Distance queries determine the minimium distance between objects. Some geometry pairs also support signed distance queries, which return the negative penetration depth if the objects are overlapping.

Distance example

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธยฒโœ”๏ธโœ”๏ธยนโŒโŒ
CPโœ”๏ธยฒโœ”๏ธโŒโœ”๏ธโŒโŒโŒ
TMโœ”๏ธยฒโŒโœ”๏ธโœ”๏ธ๐Ÿ•‘โŒโŒ
PCโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒ
ISโœ”๏ธยนโŒ๐Ÿ•‘โœ”๏ธโŒโŒโŒ
OGโŒโŒโŒโŒโŒโŒโŒ
HMโŒโŒโŒโŒโŒโŒโŒ
  1. for a couple of primitives (usually point and sphere).
  2. for common geometric primitives (usually point, sphere, box, and triangle)

Example computation speeds are given below (in ms):

Simple geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive0.0010.0050.0030.0030.001
ConvexHull0.0050.0050.036
TriangleMesh0.0030.2080.699
PointCloud0.0030.0360.6990.1650.047
ImplicitSurface0.0010.047
OccupancyGrid
Heightmap

Complex geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive0.0250.0680.062
ConvexHull0.0250.0560.149
TriangleMesh0.0680.63513.961
PointCloud0.0620.14913.96134.0391.883
ImplicitSurface1.883
OccupancyGrid
Heightmap

Contact detection

Contact detection is used in physics simulation and stability prediction to produce accurate estimates of all the contact points that would be active between two objects that are touching. Below, the contact points are shown as orange points and normals are shown as red lines.

Contacts example

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโœ”๏ธยฒโœ”๏ธโœ”๏ธยนโœ”๏ธโœ”๏ธยฒโŒโŒ
CPโœ”๏ธโœ”๏ธโŒโœ”๏ธโŒโŒโŒ
TMโœ”๏ธยนโŒโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒ
PCโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒ
ISโœ”๏ธยฒโŒโœ”๏ธโœ”๏ธโŒโŒโŒ
OGโŒโŒโŒโŒโŒโŒโŒ
HMโŒโŒโŒโŒโŒโŒโŒ
  1. Only produces a single contact point, may lead to inaccurate simulations.
  2. For some primitives.

Example computation speeds are given below (in ms):

Simple geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive0.0000.0040.0010.0010.001
ConvexHull0.0040.0010.001
TriangleMesh0.0010.0220.6300.194
PointCloud0.0010.0010.6300.2440.002
ImplicitSurface0.0010.1940.002
OccupancyGrid
Heightmap

Complex geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive0.0160.0020.001
ConvexHull0.0160.003
TriangleMesh0.0020.00712.55523.283
PointCloud0.00112.55517.8520.022
ImplicitSurface23.2830.022
OccupancyGrid
Heightmap

Geometric operations

Transforms here refer to transforming the underlying geometry by translation, rotation, and/or scaling. (Recall that all collision objects have a current transform which can be set with nearly zero overhead.)

Remesh operations refine the representation to a specified coarser or finer resolution.

Union operations gather multiple objects of the same type into a single object. If a union cannot be performed, then a Group geometry is produced by the union operation.

Extract ROI operations extract a region (bounding box) from the object to produce an object of the same type. The below ROI of a mesh was computed and then the original mesh was moved to the left for visualization clarity.

Extract ROI example

Slice operations take a planar slice through the object.

Extract slice example

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Rigid transformโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒโœ”๏ธ
Nonuniform scaleโŒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
Scale + rigid transformโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒโŒ
RemeshโŒโŒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
UnionโŒโœ”๏ธโœ”๏ธโœ”๏ธโŒโŒโŒ
ROIโŒโŒโœ”๏ธโœ”๏ธโœ”๏ธยนโœ”๏ธยนโœ”๏ธยนยฒ
SliceโŒโŒโœ”๏ธโœ”๏ธโŒโŒโŒ
  1. Only axis-aligned.
  2. Depth maps not supported.

Merge operations union a geometry into an existing representation: (merging the type listed in row into target type listed in column)

Into โ†’ / From โ†“Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
GPโŒโŒโŒโŒโœ”๏ธโœ”๏ธโœ”๏ธ
CPโŒโœ”๏ธโŒโŒโœ”๏ธโœ”๏ธโŒ
TMโŒโŒโœ”๏ธโŒโœ”๏ธโœ”๏ธโœ”๏ธ
PCโŒโŒโŒโœ”๏ธโœ”๏ธโœ”๏ธโœ”๏ธ
ISโŒโŒโŒโŒโœ”๏ธโœ”๏ธโœ”๏ธ
OGโŒโŒโŒโŒโŒโœ”๏ธโœ”๏ธ
HMโŒโŒโŒโŒโŒโŒโœ”๏ธยน
  1. domains must be aligned. Support for unaligned domains is ๐Ÿ•‘.

For triangle mesh and point cloud targets, it is recommended that you first convert the merged geometry into the desired type before merging.

Below is an illustration of a geometric primitive (sphere) being merged into a heightmap of a lunar terrain. For visualization clarity, the primitive was moved to the right after merging.

Merge example

Computation speeds are shown below (in ms):

Simple geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Transform0.0000.0780.0030.0160.0030.0040.000
Remesh0.5020.2090.0426.9110.008
Union0.2540.0490.188
ROI0.0020.0150.0390.0270.114
Slice0.0010.004
Merge Into โ†’ / From โ†“Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive28.07118.0021.405
ConvexHull0.170785.52747.786
TriangleMesh4.195323.61217.8781.836
PointCloud0.83461.01514.1781.159
ImplicitSurface17.73823.70912.708
OccupancyGrid22.01412.785
Heightmap

Complex geometries

Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Transform0.00072.5830.3493.87814.3250.0002.626
Remesh24.16411.3090.048338.6940.008
Union133.6935.14642.201
ROI0.0022.4050.1770.1065.983
Slice0.0010.002
Merge Into โ†’ / From โ†“Geometric primitiveConvex polytopeTriangle meshPoint cloudImplicit surfaceOccupancy gridHeightmap
Primitive2725.7121095.119107.943
ConvexHull133.48083310.35265026.609
TriangleMesh529.4013051.742945.973123.200
PointCloud193.65915528.338953.14377.381
ImplicitSurface1095.7071526.8461129.939
OccupancyGrid1443.7281012.194
Heightmap

API summary

C++

Geometry data is stored in the AnyGeometry3D type and collision geometries are stored in the AnyCollisionGeometry3D type. These are essentially container types that abstract the underlying geometry and collision acceleration data structures. To operate on the data therein, users will need to inspect the geometry's type and cast to the appropriate type. The data contained within an AnyGeometry3D is an instance of a Geometry3D[X] object. The collision data contained within an AnyCollisionGeometry3D is stored in an instance of a Collider3D[X] object.

Detailed datatype documentation can be found in the following files:

  • KrisLibrary/math3d/geometry3d.h defines 3D geometric primitives, including Point3D, Segment3D, Triangle3D, AABB3D, Box3D, Sphere3D, and Ellipsoid3D. There is also a GeometricPrimitive3D class that abstracts common operations on any geometric primitive.
  • KrisLibrary/meshing/TriMesh.h defines 3D triangle meshes.
  • KrisLibrary/meshing/PointCloud.h defines a 3D point cloud. Each point may contain a variety of other named properties, including color, normal, id, etc.
  • KrisLibrary/meshing/Heightmap.h defines a height map or depth map (as a perspective projected height map). The map may be colored and can contain other property images.
  • KrisLibrary/meshing/VolumeGrid.h defines a volumetric grid, which may contain an implicit function or occupancy map.

Geometry caching

When multiple objects load the same geometry file, Klamp't uses a caching mechanism to avoid reloading the file from disk and re-creating collision acceleration structures. This is essential for loading very large scenes with many replicated objects.

In C++, if you change the underlying geometry data in a ManagedGeometry, it will affect all other shared geometries. To avoid this effect, call ManagedGeometry.SetUnique first.

Appearance

Klampt appearances are relatively simple materials that work with OpenGL and can specify:

  • Color
  • Transparency
  • Vertex / edge / face drawing with separate color/transparency
  • Vertex / edge size
  • 1D, 2D, or 3D textures
  • Texture projection mapping
  • Per-vertex / per-face colors
  • Mesh creasing
  • Silhouette drawing

Silhouette data and mesh creasing require some precomputation overhead, which can be substantial for complex geometries. To avoid incurring this overhead, turn them off.

Some geometry types (TriangleMesh, PointCloud, Heightmap) can also contain appearance data. An appearance created from these objects will load the associated apperance data upon initialization.

All geometry types except for point clouds are converted to a triangle mesh for rendering. This mesh is cached; if you change the geometry data, GeometryAppearance.Refresh() (C++) / Appearance.refresh() (Python) will need to be called. Note that this will read the geometry's appearance again. If you change the geometry data but want to keep your manually-specified changes to the appearance, you will need to call GeometryAppearance.RefreshGeometry() (C++). TODO: The Python API does not have a version of this yet.

Proper rendering of transparent objects requires some care to draw objects from back to front. The WorldModel.DrawGL() method (C++) and the Python vis module handle this automatically. Artifacts may still appear between elements within an object, which are not automatically ordered.

Known issues and plans

  • GeometricPrimitive support for segments, triangles, and polygons is sparse. Not sure how much demand there is for these primitives.
  • PointCloud per-point radius support is spotty and has not been tested thoroughly.
  • Want to include Gaussian Splatting representations in PointCloud at some point in the future.
  • TSDF proximity detection routines are largely incorrect.
  • Heightmap interpolation is still unimplemented.

Visualization

  • TSDFs aren't drawn correctly, showing back faces at -truncationDistance. TODO: throw out back faces.
  • Fractional occupancy grids are drawn as binary. TODO: draw fractional cells transparently? Or build a higher level function.

Conversions and merging

  • Heightmap -> TriangleMesh conversions does not throw out discontinuities. TODO: interpret parameter as depth threshold.
  • Heightmap merging could benefit from GPU acceleration. Need to devise a coherent strategy for caching OpenGL elements with geometries.

Collisions

Availability

  • ImplicitSurface - ConvexHull isn't implemented. Could iterate over cells that the ConvexHull's bounding box overlaps, or use hierarchy.
  • ImplicitSurface - box isn't implemented. Could iterate over cells that the box's bounding box overlaps, or use hierarchy.

Speed

  • ImplicitSurface - OccupancyGrid slow when close but not colliding
  • OccupancyGrid - OccupancyGrid slow when close but not colliding
  • Primitive - Heightmap is slow for perspective heightmaps when the primitive is near origin. Could benefit from GPU acceleration.
  • ConvexHull - Heightmap is slow for perspective heightmaps when the convex hull is near origin. Could benefit from GPU acceleration.
  • PointCloud - ImplicitSurface is slow when colliding. Can we use BVHs?
  • PointCloud - OccupancyGrid is slow when colliding

Correctness

  • TriangleMesh - perspective Heightmap can incorrectly return no collision for very large triangles that pass from behind the origin to collide with the heightmap.

Within distance

Availability (in addition to collision detection issues)

  • OccupancyGrid - OccupancyGrid isn't implemented -- need to walk around nearby cells
  • Heightmap - anything isn't implemented. Should at least be able to do this for points and spheres -- need to walk around nearby cells.

Correctness

  • Reported implicit surface elements can be outside of the actual geometry by tolerance

Speed (in addition to collision detection issues)

  • PointCloud - PointCloud is slow
  • OccupancyGrid - almost anything is slow

Distance

Availability

  • OccupancyGrid - anything isn't implemented. Could implement brute-force detection at least for primitives and convex hulls.
  • Heightmap - anything isn't implemented. Could implement iterative detection for primitives and convex hulls.

Speed

  • point cloud - point cloud is slow
  • point cloud - triangle mesh is slow

Contacts

All the weaknesses of WithinDistance are inherited.