Class ParShapes
The par_shapes API is divided into three sections:
- Generators - Create parametric surfaces, platonic solids, etc.
- Queries - Ask a mesh for its axis-aligned bounding box, etc.
- Transforms - Rotate a mesh, merge it with another, add normals, etc.
For our purposes, a "mesh" is a list of points and a list of triangles; the former is a flattened list of three-tuples (32-bit floats) and the latter
is also a flattened list of three-tuples (16-bit uints). Triangles are always oriented such that their front face winds counter-clockwise.
Depending on which generator function is used, meshes may or may not contain normals and texture coordinates (one per vertex).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidnpar_shapes__connect(long scene, long cylinder, int slices) static longnpar_shapes_clone(long mesh, long target) Unsafe version of:clonestatic voidnpar_shapes_compute_aabb(long mesh, float[] aabb) Array version of:npar_shapes_compute_aabb(long, long)static voidnpar_shapes_compute_aabb(long mesh, long aabb) Unsafe version of:compute_aabbstatic voidnpar_shapes_compute_normals(long mesh) Unsafe version of:compute_normalsstatic longnpar_shapes_create_cone(int slices, int stacks) Unsafe version of:create_conestatic longUnsafe version of:create_cubestatic longnpar_shapes_create_cylinder(int slices, int stacks) Unsafe version of:create_cylinderstatic longnpar_shapes_create_disk(float radius, int slices, float[] center, float[] normal) Array version of:npar_shapes_create_disk(float, int, long, long)static longnpar_shapes_create_disk(float radius, int slices, long center, long normal) Unsafe version of:create_diskstatic longUnsafe version of:create_dodecahedronstatic longUnsafe version of:create_emptystatic longnpar_shapes_create_hemisphere(int slices, int stacks) Unsafe version of:create_hemispherestatic longUnsafe version of:create_icosahedronstatic longnpar_shapes_create_klein_bottle(int slices, int stacks) Unsafe version of:create_klein_bottlestatic longnpar_shapes_create_lsystem(long program, int slices, int maxdepth, long rand_fn, long context) Unsafe version of:create_lsystemstatic longUnsafe version of:create_octahedronstatic longnpar_shapes_create_parametric_disk(int slices, int stacks) Unsafe version of:create_parametric_diskstatic longnpar_shapes_create_parametric_sphere(int slices, int stacks) Unsafe version of:create_parametric_spherestatic longnpar_shapes_create_plane(int slices, int stacks) Unsafe version of:create_planestatic longnpar_shapes_create_rock(int seed, int nsubdivisions) Unsafe version of:create_rockstatic longnpar_shapes_create_subdivided_sphere(int nsubdivisions) Unsafe version of:create_subdivided_spherestatic longUnsafe version of:create_tetrahedronstatic longnpar_shapes_create_torus(int slices, int stacks, float radius) Unsafe version of:create_torusstatic longnpar_shapes_create_trefoil_knot(int slices, int stacks, float radius) Unsafe version of:create_trefoil_knotstatic voidnpar_shapes_export(long mesh, long objfile) Unsafe version of:exportstatic voidnpar_shapes_free_mesh(long mesh) Unsafe version of:free_meshstatic voidnpar_shapes_invert(long mesh, int startface, int nfaces) Unsafe version of:invertstatic voidnpar_shapes_merge(long dst, long src) Unsafe version of:mergestatic voidnpar_shapes_merge_and_free(long dst, long src) Unsafe version of:merge_and_freestatic voidnpar_shapes_remove_degenerate(long mesh, float minarea) Unsafe version of:remove_degeneratestatic voidnpar_shapes_rotate(long mesh, float radians, float[] axis) Array version of:npar_shapes_rotate(long, float, long)static voidnpar_shapes_rotate(long mesh, float radians, long axis) Unsafe version of:rotatestatic voidnpar_shapes_scale(long mesh, float x, float y, float z) Unsafe version of:scalestatic voidnpar_shapes_translate(long mesh, float x, float y, float z) Unsafe version of:translatestatic voidnpar_shapes_unweld(long mesh, boolean create_indices) Unsafe version of:unweldstatic longnpar_shapes_weld(long mesh, float epsilon, int[] mapping) Array version of:npar_shapes_weld(long, float, long)static longnpar_shapes_weld(long mesh, float epsilon, long mapping) Unsafe version of:weldstatic voidstatic voidpar_shapes__connect(ParShapesMesh scene, ParShapesMesh cylinder, int slices) static @Nullable ParShapesMeshpar_shapes_clone(ParShapesMesh mesh, @Nullable 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, FloatBuffer aabb) Takes a pointer to 6 floats and sets them to min xyz, max xyz.static voidComputes smooth normals by averaging adjacent facet normals.static @Nullable ParShapesMeshpar_shapes_create_cone(int slices, int stacks) Creates a cone similar tocreate_cylinderbut the radius diminishes to zero as Z increases.static @Nullable ParShapesMeshGenerates points for a cube that fits in the unit sphere.static @Nullable 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 @Nullable ParShapesMeshpar_shapes_create_disk(float radius, int slices, float[] center, float[] normal) Array version of:create_diskstatic @Nullable ParShapesMeshpar_shapes_create_disk(float radius, int slices, FloatBuffer center, FloatBuffer normal) Generates an orientable disk shape in 3-space.static @Nullable ParShapesMeshGenerates points for a 12-sided polyhedron that fits in the unit sphere.static @Nullable ParShapesMeshCreates an empty shape.static @Nullable ParShapesMeshpar_shapes_create_hemisphere(int slices, int stacks) Creates a hemisphere mesh.static @Nullable ParShapesMeshGenerates points for a 20-sided polyhedron that fits in the unit sphere.static @Nullable ParShapesMeshpar_shapes_create_klein_bottle(int slices, int stacks) Creates a klein bottle mesh.static @Nullable ParShapesMeshpar_shapes_create_lsystem(CharSequence program, int slices, int maxdepth, @Nullable ParShapesRandFnI rand_fn, long context) Creates trees or vegetation by executing a recursive turtle graphics program.static @Nullable ParShapesMeshpar_shapes_create_lsystem(ByteBuffer program, int slices, int maxdepth, @Nullable ParShapesRandFnI rand_fn, long context) Creates trees or vegetation by executing a recursive turtle graphics program.static @Nullable ParShapesMeshGenerates points for an 8-sided polyhedron that fits in the unit sphere.static @Nullable ParShapesMeshpar_shapes_create_parametric_disk(int slices, int stacks) Creates a disk of radius1.0with texture coordinates and normals by squashing a cone flat on theZ=0plane.static @Nullable ParShapesMeshpar_shapes_create_parametric_sphere(int slices, int stacks) Creates a sphere with texture coordinates and small triangles near the poles.static @Nullable ParShapesMeshpar_shapes_create_plane(int slices, int stacks) Creates a plane mesh.static @Nullable 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 @Nullable 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 @Nullable ParShapesMeshGenerates points for a 4-sided polyhedron that fits in the unit sphere.static @Nullable 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 @Nullable ParShapesMeshpar_shapes_create_trefoil_knot(int slices, int stacks, float radius) Creates a trefoil knot mesh.static voidpar_shapes_export(ParShapesMesh mesh, CharSequence objfile) Dumps out a text file conforming to the venerable OBJ format.static voidpar_shapes_export(ParShapesMesh mesh, ByteBuffer objfile) Dumps out a text file conforming to the venerable OBJ format.static voidFrees the specifiedParShapesMeshstructure.static voidpar_shapes_invert(ParShapesMesh mesh, int startface, int nfaces) Reverses the winding of a run of faces.static voidpar_shapes_merge(ParShapesMesh dst, ParShapesMesh src) Merges two shapes.static voidMerges two shapes and frees the source shape.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, 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_set_epsilon_degenerate_sphere(float epsilon) static voidpar_shapes_set_epsilon_welded_normals(float epsilon) 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 @Nullable ParShapesMeshpar_shapes_weld(ParShapesMesh mesh, float epsilon, int @Nullable [] mapping) Array version of:weldstatic @Nullable ParShapesMeshpar_shapes_weld(ParShapesMesh mesh, float epsilon, @Nullable IntBuffer mapping) Merges colocated verts, builds a new index buffer, and returns the optimized mesh.
-
Method Details
-
npar_shapes_free_mesh
public static void npar_shapes_free_mesh(long mesh) Unsafe version of:free_mesh -
par_shapes_free_mesh
Frees the specifiedParShapesMeshstructure.- Parameters:
mesh- the mesh to free
-
npar_shapes_create_cylinder
public static long npar_shapes_create_cylinder(int slices, int stacks) Unsafe version of:create_cylinder -
par_shapes_create_cylinder
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
-
npar_shapes_create_cone
public static long npar_shapes_create_cone(int slices, int stacks) Unsafe version of:create_cone -
par_shapes_create_cone
Creates a cone similar tocreate_cylinderbut the radius diminishes to zero as Z increases. Again, height and radius are 1.0, but can be changed withscale.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_parametric_disk
public static long npar_shapes_create_parametric_disk(int slices, int stacks) Unsafe version of:create_parametric_disk -
par_shapes_create_parametric_disk
Creates a disk of radius1.0with texture coordinates and normals by squashing a cone flat on theZ=0plane.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_torus
public static long npar_shapes_create_torus(int slices, int stacks, float radius) Unsafe version of:create_torus -
par_shapes_create_torus
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
-
npar_shapes_create_parametric_sphere
public static long npar_shapes_create_parametric_sphere(int slices, int stacks) Unsafe version of:create_parametric_sphere -
par_shapes_create_parametric_sphere
Creates a sphere with texture coordinates and small triangles near the poles.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_subdivided_sphere
public static long npar_shapes_create_subdivided_sphere(int nsubdivisions) Unsafe version of:create_subdivided_sphere -
par_shapes_create_subdivided_sphere
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
-
npar_shapes_create_klein_bottle
public static long npar_shapes_create_klein_bottle(int slices, int stacks) Unsafe version of:create_klein_bottle -
par_shapes_create_klein_bottle
Creates a klein bottle mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_trefoil_knot
public static long npar_shapes_create_trefoil_knot(int slices, int stacks, float radius) Unsafe version of:create_trefoil_knot -
par_shapes_create_trefoil_knot
public static @Nullable 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 stacks
-
npar_shapes_create_hemisphere
public static long npar_shapes_create_hemisphere(int slices, int stacks) Unsafe version of:create_hemisphere -
par_shapes_create_hemisphere
Creates a hemisphere mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_plane
public static long npar_shapes_create_plane(int slices, int stacks) Unsafe version of:create_plane -
par_shapes_create_plane
Creates a plane mesh.- Parameters:
slices- the number of slicesstacks- the number of stacks
-
npar_shapes_create_icosahedron
public static long npar_shapes_create_icosahedron()Unsafe version of:create_icosahedron -
par_shapes_create_icosahedron
Generates points for a 20-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated. -
npar_shapes_create_dodecahedron
public static long npar_shapes_create_dodecahedron()Unsafe version of:create_dodecahedron -
par_shapes_create_dodecahedron
Generates points for a 12-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated. -
npar_shapes_create_octahedron
public static long npar_shapes_create_octahedron()Unsafe version of:create_octahedron -
par_shapes_create_octahedron
Generates points for an 8-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated. -
npar_shapes_create_tetrahedron
public static long npar_shapes_create_tetrahedron()Unsafe version of:create_tetrahedron -
par_shapes_create_tetrahedron
Generates points for a 4-sided polyhedron that fits in the unit sphere. Texture coordinates and normals are not generated. -
npar_shapes_create_cube
public static long npar_shapes_create_cube()Unsafe version of:create_cube -
par_shapes_create_cube
Generates points for a cube that fits in the unit sphere. Texture coordinates and normals are not generated. -
npar_shapes_create_disk
public static long npar_shapes_create_disk(float radius, int slices, long center, long normal) Unsafe version of:create_disk -
par_shapes_create_disk
public static @Nullable ParShapesMesh par_shapes_create_disk(float radius, int slices, FloatBuffer center, 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
-
npar_shapes_create_empty
public static long npar_shapes_create_empty()Unsafe version of:create_empty -
par_shapes_create_empty
Creates an empty shape. Useful for building scenes withmerge_and_free. -
npar_shapes_create_rock
public static long npar_shapes_create_rock(int seed, int nsubdivisions) Unsafe version of:create_rock -
par_shapes_create_rock
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
-
npar_shapes_create_lsystem
public static long npar_shapes_create_lsystem(long program, int slices, int maxdepth, long rand_fn, long context) Unsafe version of:create_lsystem -
par_shapes_create_lsystem
public static @Nullable ParShapesMesh par_shapes_create_lsystem(ByteBuffer program, int slices, int maxdepth, @Nullable ParShapesRandFnI rand_fn, long context) 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 depthrand_fn- is expected to return a value between 0 and 1, or can beNULL(in which case(float) rand() / RAND_MAXwill be used)context- passed unmodified torand_fn
-
par_shapes_create_lsystem
public static @Nullable ParShapesMesh par_shapes_create_lsystem(CharSequence program, int slices, int maxdepth, @Nullable ParShapesRandFnI rand_fn, long context) 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 depthrand_fn- is expected to return a value between 0 and 1, or can beNULL(in which case(float) rand() / RAND_MAXwill be used)context- passed unmodified torand_fn
-
npar_shapes_export
public static void npar_shapes_export(long mesh, long objfile) Unsafe version of:export -
par_shapes_export
Dumps out a text file conforming to the venerable OBJ format.- Parameters:
mesh- the mesh to exportobjfile- the OBJ file path
-
par_shapes_export
Dumps out a text file conforming to the venerable OBJ format.- Parameters:
mesh- the mesh to exportobjfile- the OBJ file path
-
npar_shapes_compute_aabb
public static void npar_shapes_compute_aabb(long mesh, long aabb) Unsafe version of:compute_aabb -
par_shapes_compute_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
-
npar_shapes_clone
public static long npar_shapes_clone(long mesh, long target) Unsafe version of:clone -
par_shapes_clone
public static @Nullable ParShapesMesh par_shapes_clone(ParShapesMesh mesh, @Nullable 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
-
npar_shapes_merge
public static void npar_shapes_merge(long dst, long src) Unsafe version of:merge -
par_shapes_merge
Merges two shapes.- Parameters:
dst- the destination meshsrc- the source mesh
-
npar_shapes_translate
public static void npar_shapes_translate(long mesh, float x, float y, float z) Unsafe version of:translate -
par_shapes_translate
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
-
npar_shapes_rotate
public static void npar_shapes_rotate(long mesh, float radians, long axis) Unsafe version of:rotate -
par_shapes_rotate
Rotates the specified mesh.- Parameters:
mesh- the mesh to rotateradians- the rotation angle, in radiansaxis- the rotation axis
-
npar_shapes_scale
public static void npar_shapes_scale(long mesh, float x, float y, float z) Unsafe version of:scale -
par_shapes_scale
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
-
npar_shapes_merge_and_free
public static void npar_shapes_merge_and_free(long dst, long src) Unsafe version of:merge_and_free -
par_shapes_merge_and_free
Merges two shapes and frees the source shape.- Parameters:
dst- the destination meshsrc- the source mesh
-
npar_shapes_invert
public static void npar_shapes_invert(long mesh, int startface, int nfaces) Unsafe version of:invert -
par_shapes_invert
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
-
npar_shapes_remove_degenerate
public static void npar_shapes_remove_degenerate(long mesh, float minarea) Unsafe version of:remove_degenerate -
par_shapes_remove_degenerate
Removes all triangles whose area is less thanminarea.- Parameters:
mesh- the mesh to cleanupminarea- triangles with an area below this value will be removed
-
npar_shapes_unweld
public static void npar_shapes_unweld(long mesh, boolean create_indices) Unsafe version of:unweld -
par_shapes_unweld
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
-
npar_shapes_weld
public static long npar_shapes_weld(long mesh, float epsilon, long mapping) Unsafe version of:weld -
par_shapes_weld
public static @Nullable ParShapesMesh par_shapes_weld(ParShapesMesh mesh, float epsilon, @Nullable IntBuffer mapping) Merges colocated verts, builds a new index buffer, and returns the optimized mesh.- Parameters:
mesh- the mesh to weldepsilon- the maximum distance to consider when welding verticesmapping- null, or a pointer tonpoints32-bit integers, which gets filled with the mapping from old vertex indices to new indices
-
npar_shapes_compute_normals
public static void npar_shapes_compute_normals(long mesh) Unsafe version of:compute_normals -
par_shapes_compute_normals
Computes smooth normals by averaging adjacent facet normals.- Parameters:
mesh- the mesh
-
par_shapes_set_epsilon_welded_normals
public static void par_shapes_set_epsilon_welded_normals(float epsilon) -
par_shapes_set_epsilon_degenerate_sphere
public static void par_shapes_set_epsilon_degenerate_sphere(float epsilon) -
npar_shapes__compute_welded_normals
public static void npar_shapes__compute_welded_normals(long m) -
par_shapes__compute_welded_normals
-
npar_shapes__connect
public static void npar_shapes__connect(long scene, long cylinder, int slices) -
par_shapes__connect
-
npar_shapes_create_disk
public static long npar_shapes_create_disk(float radius, int slices, float[] center, float[] normal) Array version of:npar_shapes_create_disk(float, int, long, long) -
par_shapes_create_disk
public static @Nullable ParShapesMesh par_shapes_create_disk(float radius, int slices, float[] center, float[] normal) Array version of:create_disk -
npar_shapes_compute_aabb
public static void npar_shapes_compute_aabb(long mesh, float[] aabb) Array version of:npar_shapes_compute_aabb(long, long) -
par_shapes_compute_aabb
Array version of:compute_aabb -
npar_shapes_rotate
public static void npar_shapes_rotate(long mesh, float radians, float[] axis) Array version of:npar_shapes_rotate(long, float, long) -
par_shapes_rotate
Array version of:rotate -
npar_shapes_weld
public static long npar_shapes_weld(long mesh, float epsilon, int[] mapping) Array version of:npar_shapes_weld(long, float, long) -
par_shapes_weld
public static @Nullable ParShapesMesh par_shapes_weld(ParShapesMesh mesh, float epsilon, int @Nullable [] mapping) Array version of:weld
-