Package org.lwjgl.util.par
Class ParShapes
- java.lang.Object
-
- org.lwjgl.util.par.ParShapes
-
public class ParShapes extends java.lang.ObjectBindings to par_shapes.h, a single-file, zero-dependency, C99 library that can generate simple shapes and perform basic operations on them. These operations include:- Applying affine transformations
- Computing surface normals
- Welding colocated vertices
The library provides a set of functions that populate fields of the
ParShapesMeshstructure.The
normalsandtcoordsfields might be null, but every other field is guaranteed to have valid values. This mesh representation is very limited: indices must be unsigned 16-bit integers, points must be three-tuples, and there is no support for face-varying data.When you’re done extracting the data you need from the mesh, be sure to free it:
par_shapes_mesh* m = par_shapes_create_subdivided_sphere(1); // ... par_shapes_free_mesh(m);
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static ParShapesMeshpar_shapes_clone(ParShapesMesh mesh, ParShapesMesh target)Makes a deep copy of a mesh.static voidpar_shapes_compute_aabb(ParShapesMesh mesh, float[] aabb)Array version of:compute_aabbstatic voidpar_shapes_compute_aabb(ParShapesMesh mesh, java.nio.FloatBuffer aabb)Takes a pointer to 6 floats and sets them to min xyz, max xyz.static voidpar_shapes_compute_normals(ParShapesMesh mesh)Computes smooth normals by averaging adjacent facet normals.static ParShapesMeshpar_shapes_create_cube()Generates points for a cube that fits in the unit sphere.static ParShapesMeshpar_shapes_create_cylinder(int slices, int stacks)Creates a cylinder that sits on the Z=0 plane using the given tessellation levels across the UV domain.static ParShapesMeshpar_shapes_create_disk(float radius, int slices, float[] center, float[] normal)Array version of:create_diskstatic ParShapesMeshpar_shapes_create_disk(float radius, int slices, java.nio.FloatBuffer center, java.nio.FloatBuffer normal)Generates an orientable disk shape in 3-space.static ParShapesMeshpar_shapes_create_dodecahedron()Generates points for a 12-sided polyhedron that fits in the unit sphere.static ParShapesMeshpar_shapes_create_empty()Creates an empty shape.static ParShapesMeshpar_shapes_create_hemisphere(int slices, int stacks)Creates a hemisphere mesh.static ParShapesMeshpar_shapes_create_icosahedron()Generates points for a 20-sided polyhedron that fits in the unit sphere.static ParShapesMeshpar_shapes_create_klein_bottle(int slices, int stacks)Creates a klein bottle mesh.static ParShapesMeshpar_shapes_create_lsystem(java.nio.ByteBuffer program, int slices, int maxdepth)Creates trees or vegetation by executing a recursive turtle graphics program.static ParShapesMeshpar_shapes_create_lsystem(java.lang.CharSequence program, int slices, int maxdepth)Creates trees or vegetation by executing a recursive turtle graphics program.static ParShapesMeshpar_shapes_create_octohedron()Generates points for an 8-sided polyhedron that fits in the unit sphere.static ParShapesMeshpar_shapes_create_parametric_sphere(int slices, int stacks)Creates a sphere with texture coordinates and small triangles near the poles.static ParShapesMeshpar_shapes_create_plane(int slices, int stacks)Creates a plane mesh.static ParShapesMeshpar_shapes_create_rock(int seed, int nsubdivisions)Generates a rock shape that sits on the Y=0 plane, and sinks into it a bit.static ParShapesMeshpar_shapes_create_subdivided_sphere(int nsubdivisions)Approximates a sphere with a subdivided icosahedron, which produces a nice distribution of triangles, but no texture coordinates.static ParShapesMeshpar_shapes_create_tetrahedron()Generates points for a 4-sided polyhedron that fits in the unit sphere.static ParShapesMeshpar_shapes_create_torus(int slices, int stacks, float radius)Creates a donut that sits on the Z=0 plane with the specified inner radius.static ParShapesMeshpar_shapes_create_trefoil_knot(int slices, int stacks, float radius)Creates a trefoil knot mesh.static voidpar_shapes_export(ParShapesMesh mesh, java.nio.ByteBuffer objfile)Dumps out a text file conforming to the venerable OBJ format.static voidpar_shapes_export(ParShapesMesh mesh, java.lang.CharSequence objfile)Dumps out a text file conforming to the venerable OBJ format.static voidpar_shapes_free_mesh(ParShapesMesh mesh)Frees the specifiedParShapesMeshstructure.static voidpar_shapes_invert(ParShapesMesh mesh, int startface, int nfaces)Reverses the winding of a run of faces.static voidpar_shapes_merge_and_free(ParShapesMesh dst, ParShapesMesh src)Merges two shapes and frees the source shape.static voidpar_shapes_merge(ParShapesMesh dst, ParShapesMesh src)Merges two shapes.static voidpar_shapes_remove_degenerate(ParShapesMesh mesh, float minarea)Removes all triangles whose area is less thanminarea.static voidpar_shapes_rotate(ParShapesMesh mesh, float radians, float[] axis)Array version of:rotatestatic voidpar_shapes_rotate(ParShapesMesh mesh, float radians, java.nio.FloatBuffer axis)Rotates the specified mesh.static voidpar_shapes_scale(ParShapesMesh mesh, float x, float y, float z)Scales the specified mesh.static voidpar_shapes_translate(ParShapesMesh mesh, float x, float y, float z)Translates the specified mesh.static voidpar_shapes_unweld(ParShapesMesh mesh, boolean create_indices)Dereferences the entire index buffer and replaces the point list.static ParShapesMeshpar_shapes_weld(ParShapesMesh mesh, float epsilon, short[] mapping)Array version of:weldstatic ParShapesMeshpar_shapes_weld(ParShapesMesh mesh, float epsilon, java.nio.ShortBuffer mapping)Merges colocated verts, builds a new index buffer, and returns the optimized mesh.
-
-
-
Method Detail
-
par_shapes_free_mesh
public static void par_shapes_free_mesh(ParShapesMesh mesh)
Frees the specifiedParShapesMeshstructure.- Parameters:
mesh- the mesh to free
-
par_shapes_create_cylinder
public static ParShapesMesh par_shapes_create_cylinder(int slices, int stacks)
Creates a cylinder that sits on the Z=0 plane using the given tessellation levels across the UV domain. Think of "slices" like a number of pizza slices, and "stacks" like a number of stacked rings. Height and radius are both 1.0, but they can easily be changed withscale.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
par_shapes_create_torus
public static ParShapesMesh par_shapes_create_torus(int slices, int stacks, float radius)
Creates a donut that sits on the Z=0 plane with the specified inner radius. The outer radius can be controlled withscale.- Parameters:
slices- the number of slicesstacks- the number of stacksradius- the torus radius
-
par_shapes_create_parametric_sphere
public static ParShapesMesh par_shapes_create_parametric_sphere(int slices, int stacks)
Creates a sphere with texture coordinates and small triangles near the poles.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
par_shapes_create_subdivided_sphere
public static ParShapesMesh par_shapes_create_subdivided_sphere(int nsubdivisions)
Approximates a sphere with a subdivided icosahedron, which produces a nice distribution of triangles, but no texture coordinates. Each subdivision level scales the number of triangles by four, so use a very low number.- Parameters:
nsubdivisions- the number of subdivisions
-
par_shapes_create_klein_bottle
public static ParShapesMesh par_shapes_create_klein_bottle(int slices, int stacks)
Creates a klein bottle mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
par_shapes_create_trefoil_knot
public static ParShapesMesh par_shapes_create_trefoil_knot(int slices, int stacks, float radius)
Creates a trefoil knot mesh.- Parameters:
slices- the number of slicesstacks- the number of stacksradius-
-
par_shapes_create_hemisphere
public static ParShapesMesh par_shapes_create_hemisphere(int slices, int stacks)
Creates a hemisphere mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
par_shapes_create_plane
public static ParShapesMesh par_shapes_create_plane(int slices, int stacks)
Creates a plane mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
par_shapes_create_icosahedron
public static ParShapesMesh par_shapes_create_icosahedron()
Generates points for a 20-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated.
-
par_shapes_create_dodecahedron
public static ParShapesMesh par_shapes_create_dodecahedron()
Generates points for a 12-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated.
-
par_shapes_create_octohedron
public static ParShapesMesh par_shapes_create_octohedron()
Generates points for an 8-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated.
-
par_shapes_create_tetrahedron
public static ParShapesMesh par_shapes_create_tetrahedron()
Generates points for a 4-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated.
-
par_shapes_create_cube
public static ParShapesMesh par_shapes_create_cube()
Generates points for a cube that fits in the unit sphere. Texture coordinates and normals are not generated.
-
par_shapes_create_disk
public static ParShapesMesh par_shapes_create_disk(float radius, int slices, java.nio.FloatBuffer center, java.nio.FloatBuffer normal)
Generates an orientable disk shape in 3-space. Does not include normals or texture coordinates.- Parameters:
radius- the disk radiusslices- the number of slicescenter- the disk centernormal- the disk normal
-
par_shapes_create_empty
public static ParShapesMesh par_shapes_create_empty()
Creates an empty shape. Useful for building scenes withmerge_and_free.
-
par_shapes_create_rock
public static ParShapesMesh par_shapes_create_rock(int seed, int nsubdivisions)
Generates a rock shape that sits on the Y=0 plane, and sinks into it a bit. This includes smooth normals but no texture coordinates. Each subdivision level scales the number of triangles by four, so use a very low number.- Parameters:
seed- a seed valuensubdivisions- the number of subdivisions
-
par_shapes_create_lsystem
public static ParShapesMesh par_shapes_create_lsystem(java.nio.ByteBuffer program, int slices, int maxdepth)
Creates trees or vegetation by executing a recursive turtle graphics program. The program is a list of command-argument pairs. See the unit test for an example. Texture coordinates and normals are not generated.- Parameters:
program- the list of command-argument pairsslices- the number of slicesmaxdepth- the maximum depth
-
par_shapes_create_lsystem
public static ParShapesMesh par_shapes_create_lsystem(java.lang.CharSequence program, int slices, int maxdepth)
Creates trees or vegetation by executing a recursive turtle graphics program. The program is a list of command-argument pairs. See the unit test for an example. Texture coordinates and normals are not generated.- Parameters:
program- the list of command-argument pairsslices- the number of slicesmaxdepth- the maximum depth
-
par_shapes_export
public static void par_shapes_export(ParShapesMesh mesh, java.nio.ByteBuffer objfile)
Dumps out a text file conforming to the venerable OBJ format.- Parameters:
mesh- the mesh to exportobjfile- the OBJ file path
-
par_shapes_export
public static void par_shapes_export(ParShapesMesh mesh, java.lang.CharSequence objfile)
Dumps out a text file conforming to the venerable OBJ format.- Parameters:
mesh- the mesh to exportobjfile- the OBJ file path
-
par_shapes_compute_aabb
public static void par_shapes_compute_aabb(ParShapesMesh mesh, java.nio.FloatBuffer aabb)
Takes a pointer to 6 floats and sets them to min xyz, max xyz.- Parameters:
mesh- the mesh to queryaabb- a pointer to an array of 6 floats in which the AABB will be written
-
par_shapes_clone
public static ParShapesMesh par_shapes_clone(ParShapesMesh mesh, ParShapesMesh target)
Makes a deep copy of a mesh. To make a brand new copy, passNULLtotarget. To avoid memory churn, pass an existing mesh totarget.- Parameters:
mesh- the mesh to copytarget- the target mesh
-
par_shapes_merge
public static void par_shapes_merge(ParShapesMesh dst, ParShapesMesh src)
Merges two shapes.- Parameters:
dst- the destination meshsrc- the source mesh
-
par_shapes_translate
public static void par_shapes_translate(ParShapesMesh mesh, float x, float y, float z)
Translates the specified mesh.- Parameters:
mesh- the mesh to translatex- the X axis translation amounty- the Y axis translation amountz- the Z axis translation amount
-
par_shapes_rotate
public static void par_shapes_rotate(ParShapesMesh mesh, float radians, java.nio.FloatBuffer axis)
Rotates the specified mesh.- Parameters:
mesh- the mesh to rotateradians- the rotation angle, in radiansaxis- the rotation axis
-
par_shapes_scale
public static void par_shapes_scale(ParShapesMesh mesh, float x, float y, float z)
Scales the specified mesh.- Parameters:
mesh- the mesh to scalex- the X axis scale factory- the Y axis scale factorz- the Z axis scale factor
-
par_shapes_merge_and_free
public static void par_shapes_merge_and_free(ParShapesMesh dst, ParShapesMesh src)
Merges two shapes and frees the source shape.- Parameters:
dst- the destination meshsrc- the source mesh
-
par_shapes_invert
public static void par_shapes_invert(ParShapesMesh mesh, int startface, int nfaces)
Reverses the winding of a run of faces. Useful when drawing the inside of a Cornell Box. Pass 0 fornfacesto reverse every face in the mesh.- Parameters:
mesh- the mesh to reversestartface- the index of the first face to reversenfaces- the number of faces to reverse
-
par_shapes_remove_degenerate
public static void par_shapes_remove_degenerate(ParShapesMesh mesh, float minarea)
Removes all triangles whose area is less thanminarea.- Parameters:
mesh- the mesh to cleanupminarea- triangles with an area below this value will be removed
-
par_shapes_unweld
public static void par_shapes_unweld(ParShapesMesh mesh, boolean create_indices)
Dereferences the entire index buffer and replaces the point list.This creates an inefficient structure, but is useful for drawing facets. If
create_indicesis true, a trivial "0 1 2 3..." index buffer is generated.- Parameters:
mesh- the mesh to unweldcreate_indices- if an index buffer should be generated
-
par_shapes_weld
public static ParShapesMesh par_shapes_weld(ParShapesMesh mesh, float epsilon, java.nio.ShortBuffer mapping)
Merges colocated verts, builds a new index buffer, and returns the optimized mesh. is the maximum distance to consider when welding vertices. The mapping argument can be- Parameters:
mesh- the mesh to weldepsilon- the maximum distance to consider when welding verticesmapping- null, or a pointer tonpoints16-bit integers, which gets filled with the mapping from old vertex indices to new indices
-
par_shapes_compute_normals
public static void par_shapes_compute_normals(ParShapesMesh mesh)
Computes smooth normals by averaging adjacent facet normals.- Parameters:
mesh- the mesh
-
par_shapes_create_disk
public static ParShapesMesh par_shapes_create_disk(float radius, int slices, float[] center, float[] normal)
Array version of:create_disk
-
par_shapes_compute_aabb
public static void par_shapes_compute_aabb(ParShapesMesh mesh, float[] aabb)
Array version of:compute_aabb
-
par_shapes_rotate
public static void par_shapes_rotate(ParShapesMesh mesh, float radians, float[] axis)
Array version of:rotate
-
par_shapes_weld
public static ParShapesMesh par_shapes_weld(ParShapesMesh mesh, float epsilon, short[] mapping)
Array version of:weld
-
-