public abstract class MeshBase extends java.lang.Object implements Renderable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
RigidTransform3d |
XMeshToWorld |
TRANSPARENT, TWO_DIMENSIONAL
Constructor and Description |
---|
MeshBase()
Creates an empty polyline mesh.
|
Modifier and Type | Method and Description |
---|---|
Vertex3d |
addVertex(double x,
double y,
double z)
Adds a point to the set of vertices associated with this mesh.
|
Vertex3d |
addVertex(Point3d pnt)
Adds a point to the set of vertices associated with this mesh.
|
Vertex3d |
addVertex(Point3d pnt,
boolean byReference)
Adds a point to the set of vertices associated with this mesh.
|
void |
addVertex(Vertex3d vtx)
Adds a vertex to the set of vertices associated with this mesh.
|
long |
checksum() |
void |
clear()
Clears this mesh (makes it empty).
|
void |
clearColors()
Clears the color information for this mesh.
|
void |
clearNormals()
Clears any normals that have been explicitly set for the mesh using
setNormals(java.util.List<maspack.matrix.Vector3d>, int[]) . |
void |
clearRenderProps() |
void |
clearTextureCoords()
Clears the texture information for this mesh.
|
MeshBase |
clone()
Creates a clone of this mesh.
|
double |
computeAverageRadius() |
void |
computeCentroid(Vector3d centroid) |
void |
computeLocalBounds(Vector3d pmin,
Vector3d pmax,
RigidTransform3d TFM)
Compute the bounds of the vertices of this mesh with respect to a frame F
that is described with respect to local mesh coordinates.
|
OBB |
computeOBB()
Computes the oriented bounding box (OBB) that most tightly contains
this mesh, using the
OBB.Method.ConvexHull method. |
OBB |
computeOBB(OBB.Method method)
Computes the oriented bounding box (OBB) that most tightly contains
this mesh, using the specified method.
|
double |
computeRadius()
Returns the radius of this mesh.
|
void |
computeWorldBounds(Vector3d pmin,
Vector3d pmax,
RigidTransform3d TFW)
Compute the bounds of the vertices of this mesh with respect to a frame F
that is described with respect to world coordinates.
|
boolean |
containsVertex(Vertex3d vtx) |
MeshBase |
copy()
Creates a copy of this mesh.
|
int[] |
createFeatureIndices()
Creates and returns a set of feature indices for this mesh.
|
SpatialInertia |
createInertia(double mass,
MassDistribution dist)
Computes a spatial inertia for this mesh, given a mass and a mass
distribution.
|
RenderProps |
createRenderProps()
Factory method to create render properties appropriate to this object.
|
abstract RenderProps |
createRenderProps(HasProperties host)
Creates an appropriate RenderProps for this Mesh.
|
abstract int[] |
createVertexIndices()
Creates and returns the vertex indices associated with each geometric
feature in this mesh.
|
boolean |
epsilonEquals(MeshBase base,
double eps)
Base method for testing if two meshes are equal.
|
abstract BVTree |
getBVTree()
Returns a bounding volume tree to be used for proximity queries
involving this mesh.
|
float[] |
getColor(int idx)
Returns the color corresponding to index
idx . |
int[] |
getColorIndices()
Returns the color indices associated with this mesh, or
null
if this mesh does not have colors. |
Renderer.ColorInterpolation |
getColorInterpolation()
Returns the interpolation method to be used for vertex-based coloring.
|
java.util.ArrayList<float[]> |
getColors()
Returns the colors associated with this mesh, or
null if
this mesh does not have colors. |
float[] |
getFeatureColor(int fidx,
int k)
Returns the color associated with the k-th vertex of the feature indexed
by
fidx , or null if there is no such color. |
boolean |
getFeatureColoringEnabled()
Returns
true if feature coloring is enabled for this
mesh, as described for setFeatureColoringEnabled() . |
int[] |
getFeatureIndexOffsets()
Returns the index offsets for each geometric feature (face, line segment,
etc.) associated with this mesh.
|
Vector3d |
getFeatureNormal(int fidx,
int k)
Returns the normal associated with the k-th vertex of the feature indexed
by
fidx , or null if there is no such normal. |
Vector3d |
getFeatureTextureCoords(int fidx,
int k)
Returns the texture coordinate associated with the k-th vertex of the
feature indexed by
fidx , or null if there is no
such coordinate. |
void |
getLocalBounds(Vector3d pmin,
Vector3d pmax)
Returns the minimum and maximum coordinates for this mesh, in mesh local
coordinates.
|
RigidTransform3d |
getMeshToWorld()
Returns a pointer to the current mesh to world transform.
|
void |
getMeshToWorld(RigidTransform3d X)
Returns the spatial transform this mesh.
|
java.lang.String |
getName() |
Vector3d |
getNormal(int idx)
Returns the normal corresponding to index
idx . |
int[] |
getNormalIndices()
Returns the normal indices associated with this mesh, or
null if this mesh does not have normals. |
java.util.ArrayList<Vector3d> |
getNormals()
Returns the vertex normals associated with this mesh, or
null if this mesh does not have normals. |
double |
getRadius()
Computes an approximate radius for this mesh, determined as
half the diagonal of the corners of its bounding box.
|
int |
getRenderHints()
Returns a bit code giving rendering hints about this renderable.
|
float[] |
getRenderNormal(int idx) |
RenderProps |
getRenderProps()
Returns the render properities for this object.
|
void |
getSelection(java.util.LinkedList<java.lang.Object> list,
int qid)
Append to
list the component (or components) associated with
the qid -th selection query issued by this component's render
method. |
java.util.ArrayList<Vector3d> |
getTextureCoords()
Returns all the texture coordinates associated with this mesh, or
null if this mesh does not have texture coordinates. |
Vector3d |
getTextureCoords(int idx)
Returns the texture coordinate corresponding to index
idx . |
int[] |
getTextureIndices()
Returns the texture indices associated with this mesh, or
null if this mesh does not have texture coordinates. |
int |
getVersion()
A version number that changes for ANY modifications,
including vertex position changes
|
Vertex3d |
getVertex(int idx)
Returns the idx-th vertex in this mesh.
|
boolean |
getVertexColoringEnabled()
Returns
true if vertex coloring is enabled for this
mesh, as described for setVertexColoringEnabled() . |
Renderer.ColorMixing |
getVertexColorMixing()
Returns the color mixing method to be used for vertex-based coloring.
|
java.util.ArrayList<Vertex3d> |
getVertices()
Returns this mesh's vertices.
|
void |
getWorldBounds(Vector3d pmin,
Vector3d pmax)
Returns the minimum and maximum coordinates for this mesh, in world
coordinates.
|
abstract boolean |
getWriteNormals()
Returns
true if this mesh's normals should be written
to a file. |
RigidTransform3d |
getXMeshToWorldRender() |
abstract boolean |
hasAutoNormalCreation()
Returns
true if this mesh automatically creates a default
set of normals if getNormals() is called and no normals have been
explicitly set using setNormals(java.util.List<maspack.matrix.Vector3d>, int[]) . |
boolean |
hasColors()
Returns
true if there are colors associated
with this mesh. |
boolean |
hasExplicitColors() |
boolean |
hasExplicitNormals()
Returns
true if vertex normal information has been
explicitly specified using setNormals(java.util.List<maspack.matrix.Vector3d>, int[]) . |
boolean |
hasNormals()
Returns
true if there are normals associated with
this mesh (or if they will be generated automatically). |
boolean |
hasTextureCoords()
Returns
true if there are texture coordinates associated
with this mesh. |
void |
inverseTransform(AffineTransform3dBase X)
Applies an inverse affine transformation to the vertices of this mesh, in
local mesh coordinates.
|
void |
inverseTransform(VectorTransformer3d trans)
Applies an inverse transform to the vertices and normals of this mesh, in
local mesh coordinates.
|
boolean |
isColorsFixed()
|
boolean |
isEmpty()
Returns true if this mesh is empty.
|
boolean |
isFeatureColored()
Returns
true if the colors for this mesh are assigned on a
per-feature basis. |
boolean |
isFixed()
Returns whether or not this mesh is considered ``fixed'', as described in
setFixed . |
boolean |
isRenderBuffered() |
boolean |
isSelectable()
Returns true if this object is in fact selectable.
|
boolean |
isTextureCoordsFixed()
|
boolean |
isVertexColored()
Returns
true if the colors for this mesh are assigned on a
per-vertex basis. |
boolean |
meshToWorldIsIdentity()
Returns true if the mesh to world transform is the identity.
|
void |
notifyVertexPositionsModified()
Notifies this mesh that vertex positions have been modified, and cached
data dependent on these positions should be invalidated.
|
int |
numColors()
Returns the number of colors associated with this mesh, or 0 if
no colors are defined.
|
abstract int |
numFeatures()
Returns the number of features in this mesh.
|
int |
numNormals()
Returns the number of normals associated with this mesh, or 0 if
no normals are defined.
|
int |
numSelectionQueriesNeeded()
If this selectable manages its own selection (by issuing selection
queries within its
render method), then this method should
return the maximum number of selection queries that will be
required. |
int |
numTextureCoords()
Returns the number of texture coordinates associated with this mesh, or 0 if
no texture coordinates are defined.
|
int |
numVertices()
Returns the number of vertices in this mesh.
|
void |
perturb(double tol)
Applies a random perturbation to the vertex positions of this mesh.
|
void |
prerender(RenderList list)
Called prior to rendering to allow this object to update the internal
state required for rendering (such as by caching rendering coordinates).
|
void |
prerender(RenderProps props) |
void |
read(java.io.File file)
Reads this mesh from a file, with the file format being inferred from the
file name suffix.
|
void |
read(java.io.File file,
boolean zeroIndexed)
Reads this mesh from a file, with the file format being inferred from the
file name suffix.
|
void |
read(java.io.Reader reader)
Reads the contents of this mesh from a Reader.
|
void |
read(java.io.Reader reader,
boolean zeroIndexed)
Reads the contents of this mesh from a Reader.
|
abstract void |
read(ReaderTokenizer rtok,
boolean zeroIndexed)
Reads the contents of this mesh from a ReaderTokenizer.
|
boolean |
removeVertex(Vertex3d vtx)
Removes a vertex from this mesh.
|
boolean |
removeVertexFast(Vertex3d vtx)
Removes a vertex from this mesh.
|
java.util.ArrayList<java.lang.Integer> |
removeVertices(java.util.Collection<Vertex3d> vertices)
Removes a set of vertices from this mesh, as indicated by a collection.
|
void |
render(Renderer renderer,
int flags)
Render this object using the functionality of the supplied
Renderer . |
abstract void |
render(Renderer renderer,
RenderProps props,
int flags) |
void |
replaceVertices(java.util.List<? extends Vertex3d> vtxs) |
void |
saveRenderInfo(RenderProps props) |
void |
scale(double s)
Scales the vertices of this mesh.
|
void |
scale(double sx,
double sy,
double sz)
Scales the vertices of this mesh in the given directions.
|
void |
setColor(int idx,
java.awt.Color color)
Sets the color corresponding to index
idx . |
void |
setColor(int idx,
double r,
double g,
double b,
double a)
Sets the color corresponding to index
idx . |
void |
setColor(int idx,
float[] color)
Sets the color corresponding to index
idx . |
void |
setColor(int idx,
float r,
float g,
float b,
float a)
Sets the color corresponding to index
idx . |
Renderer.ColorInterpolation |
setColorInterpolation(Renderer.ColorInterpolation interp)
Sets the interpolation method to be used for vertex-based coloring.
|
void |
setColors(java.util.List<float[]> colors,
int[] indices)
Explicitly sets the colors and associated indices for this mesh.
|
void |
setColorsFixed(boolean set)
Sets whether or not colors should be considered ``fixed''.
|
void |
setFeatureColoringEnabled()
Enables feature coloring for this mesh.
|
void |
setFixed(boolean fixed)
Sets whether or not this mesh to is to be considered ``fixed''.
|
void |
setMeshToWorld(RigidTransform3d X)
Sets the spatial transform this mesh.
|
void |
setName(java.lang.String name) |
void |
setNormal(int idx,
Vector3d nrml)
Sets the normal corresponding to index
idx . |
void |
setNormals(java.util.List<Vector3d> normals,
int[] indices)
Explicitly sets the normals and associated indices for this mesh.
|
void |
setRenderBuffered(boolean enable) |
void |
setRenderProps(RenderProps props)
Assigns a new set of render properties to this object.
|
void |
setTextureCoords(int idx,
Vector3d coords)
Sets the texture coordinate corresponding to index
idx . |
void |
setTextureCoords(java.util.List<Vector3d> coords,
int[] indices)
Explicitly sets the texture coordinates and associated indices for this
mesh.
|
void |
setTextureCoordsFixed(boolean set)
Sets whether or not texture coordinates should be considered ``fixed''.
|
void |
setVertexColoringEnabled()
Enables vertex coloring for this mesh.
|
Renderer.ColorMixing |
setVertexColorMixing(Renderer.ColorMixing cmix)
Sets the color mixing method to be used for vertex-based coloring.
|
Point3d |
size() |
boolean |
supportsMassDistribution(MassDistribution dist)
Queries whether or not a given mass distrubution is supported for this
mesh type.
|
void |
transform(AffineTransform3dBase X)
Applies an affine transformation to the vertices of this mesh.
|
void |
transform(VectorTransformer3d trans)
Applies a transform to the vertices and normals of this mesh, in
local mesh coordinates.
|
void |
transformToLocal(Point3d pnt) |
void |
transformToLocal(Vector3d pnt) |
RigidTransform3d |
transformToOBB()
Transforms this mesh so that its center and orientation are aligned
with its oriented bounding box (OBB) as computed by
computeOBB() . |
RigidTransform3d |
transformToOBB(OBB.Method method)
Transforms this mesh so that its center and orientation are aligned
with its oriented bounding box (OBB) as computed by
computeOBB(OBB.Method) . |
void |
transformToWorld(Point3d pnt) |
void |
transformToWorld(Vector3d pnt) |
void |
translate(Vector3d off)
Translates the vertices of this mesh.
|
RigidTransform3d |
translateToCentroid()
Translates the vertices of this mesh so that its origin coincides
with the centroid.
|
void |
updateBounds(Vector3d pmin,
Vector3d pmax)
Update the minimum and maximum points for this object.
|
void |
write(java.io.File file)
Writes this mesh to a File, with the file format being inferred from the
file name suffix.
|
void |
write(java.io.File file,
java.lang.String fmtStr,
boolean zeroIndexed)
Writes this mesh to a File, with the file format being inferred from the
file name suffix.
|
abstract void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
boolean zeroIndexed)
Writes this mesh to a PrintWriter.
|
void |
write(java.io.PrintWriter pw,
java.lang.String fmtStr)
Writes this mesh to a PrintWriter.
|
void |
write(java.lang.String filePath)
Writes this mesh to a file, with the file format being inferred from the
file name suffix.
|
public RigidTransform3d XMeshToWorld
public void setName(java.lang.String name)
public java.lang.String getName()
public Renderer.ColorInterpolation getColorInterpolation()
public Renderer.ColorInterpolation setColorInterpolation(Renderer.ColorInterpolation interp)
interp
- new color interpolation methodpublic Renderer.ColorMixing getVertexColorMixing()
public Renderer.ColorMixing setVertexColorMixing(Renderer.ColorMixing cmix)
cmix
- new color mixing methodpublic int getVersion()
public void notifyVertexPositionsModified()
public void setFixed(boolean fixed)
By default, a mesh is set to be fixed unless the vertices are created
using referenced points (see addVertex
).
fixed
- if true, sets this mesh to be considered fixed.isFixed
public boolean isFixed()
setFixed
.public void setVertexColoringEnabled()
createVertexIndices()
. The application can
subsequently set the colors for each vertex using the various
setColor()
methods, or by accessing and modifying the
colors directly from getColors()
. When vertex coloring is enabled,
the color and index sets are automatically adjusted whenever vertices or
features are added or removed.
Vertex coloring is disabled by clearColors()
, setFeatureColoringEnabled()
, or any call to setColors(java.util.List<float[]>, int[])
.
public boolean getVertexColoringEnabled()
true
if vertex coloring is enabled for this
mesh, as described for setVertexColoringEnabled()
.true
if vertex coloring is enabled.public boolean isVertexColored()
true
if the colors for this mesh are assigned on a
per-vertex basis. This will be true if vertex coloring is explicitly
enabled, or if the number of colors equals the number of vertices
and the vertex and color indexing is the same.public void setFeatureColoringEnabled()
createFeatureIndices()
. The application can
subsequently set the colors for each feature using the various
setColor()
methods, or by accessing and modifying the
colors directly from getColors()
. When feature coloring is
enabled, the color and index sets are automatically adjusted whenever
features are added or removed.
Feature coloring is disabled by clearColors()
, setVertexColoringEnabled()
, or any call to setColors(java.util.List<float[]>, int[])
.
public boolean getFeatureColoringEnabled()
true
if feature coloring is enabled for this
mesh, as described for setFeatureColoringEnabled()
.true
if feature coloring is enabled.public boolean isFeatureColored()
true
if the colors for this mesh are assigned on a
per-feature basis. This will be true if feature coloring is explicitly
enabled, or if the number of colors equals the number of vertices
and the feature and color indexing is the same.public RenderProps getRenderProps()
getRenderProps
in interface HasRenderProps
public abstract RenderProps createRenderProps(HasProperties host)
host
- if non-null, is used to initialize inherited valuespublic RenderProps createRenderProps()
createRenderProps
in interface HasRenderProps
public void setRenderProps(RenderProps props)
null
will remove render properties from this object.setRenderProps
in interface HasRenderProps
props
- new render properties for this objectpublic void clearRenderProps()
public void getMeshToWorld(RigidTransform3d X)
X
- returns the transform from mesh to world coordinatespublic RigidTransform3d getXMeshToWorldRender()
public float[] getRenderNormal(int idx)
public boolean meshToWorldIsIdentity()
public RigidTransform3d getMeshToWorld()
public void setMeshToWorld(RigidTransform3d X)
meshToWorldIsIdentity
will subsequently
return true.X
- transform from mesh to world coordinatespublic void transformToWorld(Point3d pnt)
public void transformToLocal(Point3d pnt)
public void transformToWorld(Vector3d pnt)
public void transformToLocal(Vector3d pnt)
public java.util.ArrayList<Vertex3d> getVertices()
Vertex3d
. Modifying these elements will
modify the mesh.public int numVertices()
public Vertex3d getVertex(int idx)
idx
- index of the desired vertexpublic abstract int numFeatures()
public void getLocalBounds(Vector3d pmin, Vector3d pmax)
pmin
- (optional) minimum point of the bounding boxpmax
- (optional) maximum point of the bounding boxpublic void getWorldBounds(Vector3d pmin, Vector3d pmax)
pmin
- (optional) minimum point of the bounding boxpmax
- (optional) maximum point of the bounding boxpublic void read(java.io.Reader reader) throws java.io.IOException
reader
- supplies the input description of the meshjava.io.IOException
public void read(java.io.Reader reader, boolean zeroIndexed) throws java.io.IOException
reader
- supplies the input description of the meshzeroIndexed
- if true, the index numbering for mesh vertices starts at 0. Otherwise,
numbering starts at 1.java.io.IOException
public abstract void read(ReaderTokenizer rtok, boolean zeroIndexed) throws java.io.IOException
rtok
- tokenizer providing the inputzeroIndexed
- if true, the index numbering for mesh vertices starts at 0. Otherwise,
numbering starts at 1.java.io.IOException
public void computeWorldBounds(Vector3d pmin, Vector3d pmax, RigidTransform3d TFW)
TFW
that maps from F to world coordinates. Specifying
TFW
as null
is equivalent to specifying it as the
identity, in which case F will be the same as the world frame.pmin
- returns the minimum corner of the bounding box (in F)pmax
- returns the maximum corner of the bounding box (in F)TFW
- pose of F with respect to world. If null
, F
is taken to be the world frame.public void computeLocalBounds(Vector3d pmin, Vector3d pmax, RigidTransform3d TFM)
TFM
that maps from F to mesh coordinates.
Specifying TFM
as null
is equivalent to specifying it as
the identity, in which case F will be the same as mesh frame.pmin
- returns the minimum corner of the bounding box (in F)pmax
- returns the maximum corner of the bounding box (in F)TFM
- pose of F with respect to mesh coordinates. If null
, F
is taken to be the mesh frame.public void addVertex(Vertex3d vtx)
pnt
field of the vertex should be
non-null. The index of the vertex will be set to reflect it's position in
the list of vertices.vtx
- vertex to addaddVertex(Point3d,boolean)
,
addVertex(Point3d)
public boolean removeVertexFast(Vertex3d vtx)
vtx
- vertex to removepublic boolean removeVertex(Vertex3d vtx)
vtx
- vertex to removepublic java.util.ArrayList<java.lang.Integer> removeVertices(java.util.Collection<Vertex3d> vertices)
vertices
- Collection of vertices to removepublic boolean containsVertex(Vertex3d vtx)
public Vertex3d addVertex(Point3d pnt)
addVertex(pnt,false)
.pnt
- vertex point to addaddVertex(Point3d,boolean)
public Vertex3d addVertex(double x, double y, double z)
x
- vertex x coordinatey
- vertex y coordinatez
- vertex z coordinatepublic Vertex3d addVertex(Point3d pnt, boolean byReference)
pnt
- vertex point to addbyReference
- if true, then the supplied Point3d argument is not copied but is referred
to directly by the vertex structure. The mesh will track any changes to
this point and isFixed
will return false.addVertex(Point3d)
public void read(java.io.File file) throws java.io.IOException
file
- file containing the mesh descriptionjava.io.IOException
- if an I/O error occurred or if the file
type is not compatible with polygonal meshespublic void read(java.io.File file, boolean zeroIndexed) throws java.io.IOException
For Alias Wavefront obj files (with extension .obj
), zeroIndexed
can be used to indicate that the numbering of vertex indices
starts at 0. Otherwise, numbering starts at 1.
file
- file containing the mesh descriptionzeroIndexed
- if true, index numbering for mesh vertices starts at 0. Otherwise,
numbering starts at 1.java.io.IOException
- if an I/O error occurred or if the file
type is not compatible with polygonal meshespublic void write(java.io.File file) throws java.io.IOException
file
- File to write this mesh tojava.io.IOException
- if an I/O error occurred or if the file format is not
compatible with the mesh typepublic void write(java.lang.String filePath) throws java.io.IOException
filePath
- Path name of the file to write this mesh tojava.io.IOException
- if an I/O error occurred or if the file format is not
compatible with the mesh typepublic void write(java.io.File file, java.lang.String fmtStr, boolean zeroIndexed) throws java.io.IOException
For text file formats, the optional argument fmtStr
supplies a C printf
style format string used for
printing the vertex coordinates. For a description of the format string
syntax, see NumberFormat
. Good default
choices for fmtStr
are either "%g"
(full
precision), or "%.Ng"
, where N is the number of
desired significant figures. If fmtStr
is null
, full
precision is assumed.
For Alias Wavefront obj files (with extension .obj
), zeroIndexed
can be used to request that the numbering of vertex indices
starts at 0. Otherwise, numbering starts at 1.
file
- File to write this mesh tofmtStr
- optional format string for mesh verticeszeroIndexed
- if true, index numbering for mesh vertices starts at 0. Otherwise,
numbering starts at 1.java.io.IOException
- if an I/O error occurred or if the file format is not
compatible with the mesh typepublic void write(java.io.PrintWriter pw, java.lang.String fmtStr) throws java.io.IOException
printf
style format string contained in the parameter fmtStr
. For a
description of the format string syntax, see NumberFormat
. Good default choices for
fmtStr
are either "%g"
(full precision), or
"%.Ng"
, where N is the number of desired significant
figures.pw
- PrintWriter to write this mesh tofmtStr
- string specifying the format for writing the vertex coordinatesjava.io.IOException
public abstract void write(java.io.PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws java.io.IOException
pw
- PrintWriter to write this mesh tofmt
- format for writing the vertex coordinateszeroIndexed
- if true, index numbering for mesh vertices starts at 0. Otherwise,
numbering starts at 1.java.io.IOException
public void scale(double s)
s
- scale factorpublic void scale(double sx, double sy, double sz)
sx
- scaling factor in the x directionsy
- scaling factor in the y directionsz
- scaling factor in the z directionpublic Point3d size()
public double getRadius()
public void updateBounds(Vector3d pmin, Vector3d pmax)
updateBounds
in interface IsRenderable
pmin
- minimum pointpmax
- maximum pointpublic void translate(Vector3d off)
off
- offset to add to the mesh verticespublic RigidTransform3d translateToCentroid()
public RigidTransform3d transformToOBB()
computeOBB()
.public RigidTransform3d transformToOBB(OBB.Method method)
computeOBB(OBB.Method)
.method
- method used to compute the OBB.public void transform(AffineTransform3dBase X)
X
- affine transformationpublic void inverseTransform(AffineTransform3dBase X)
X
- affine transformationpublic void transform(VectorTransformer3d trans)
trans
- transformation to applypublic void inverseTransform(VectorTransformer3d trans)
trans
- transformation to applypublic int getRenderHints()
TRANSPARENT
and
TWO_DIMENSIONAL
.getRenderHints
in interface IsRenderable
public void clear()
public boolean isEmpty()
public void getSelection(java.util.LinkedList<java.lang.Object> list, int qid)
IsSelectable
list
the component (or components) associated with
the qid
-th selection query issued by this component's render
method. This will only be called if this component manages its own
selection (i.e., the number nums
returned by IsSelectable.numSelectionQueriesNeeded()
is positive), and qid
will in
turn be a number between 0 and nums
-1.getSelection
in interface IsSelectable
list
- selected objects are appended to the end of this listqid
- index of the selection querypublic boolean isSelectable()
IsSelectable
isSelectable
in interface IsSelectable
public int numSelectionQueriesNeeded()
IsSelectable
render
method), then this method should
return the maximum number of selection queries that will be
required. Otherwise, this method should return -1.numSelectionQueriesNeeded
in interface IsSelectable
public void prerender(RenderList list)
IsRenderable
list.addIfVisible (obj);
for each of the objects in question.prerender
in interface IsRenderable
list
- list of objects to be renderedpublic void prerender(RenderProps props)
public void setRenderBuffered(boolean enable)
public boolean isRenderBuffered()
public void saveRenderInfo(RenderProps props)
public MeshBase copy()
public MeshBase clone()
clone
in class java.lang.Object
public void replaceVertices(java.util.List<? extends Vertex3d> vtxs)
public void computeCentroid(Vector3d centroid)
public OBB computeOBB(OBB.Method method)
method
- method used to compute the OBBpublic OBB computeOBB()
OBB.Method.ConvexHull
method.public double computeRadius()
public double computeAverageRadius()
public void render(Renderer renderer, int flags)
Renderer
.render
in interface IsRenderable
renderer
- provides the functionality used to perform the rendering.flags
- flags that may be used to control different
aspects of the rendering. Flags are defined in Renderer
and currently include
Renderer.HIGHLIGHT
and
Renderer.SORT_FACES
.public abstract void render(Renderer renderer, RenderProps props, int flags)
public boolean epsilonEquals(MeshBase base, double eps)
eps
. This method, and its overrides, is used
in mesh unit tests.public int[] getFeatureIndexOffsets()
getNormalIndices()
,
getColorIndices()
, and getTextureIndices()
, which can be
used to find the normal, color, or texture indices that correspond to the
vertices of the feature. So for example, if we have a
PolygonalMesh
and we want to find the normals associated
with each of the three vertices of the (triangular) face at index
fidx
, we could use the following code fragment:
ArrayList<Vector3d> normals = mesh.getNormals();
int[] indices = mesh.getNormalIndices();
int[] indexOffs = mesh.getFeatureIndexOffsets();
int offset = indexOffs[fidx];
Vector3d nrm0 = normals.get(indices[offset]);
Vector3d nrm1 = normals.get(indices[offset+1]);
Vector3d nrm2 = normals.get(indices[offset+2]);
The array returned by this method has a length of n+1,
where n is the number of mesh features. The last entry contains
the total number of feature vertices. This is the length
of the index array that is returned by
getNormalIndices()
, getColorIndices()
, etc.,
as well as the length that must be used for the indices
argument (if specified) in
setNormals(java.util.List<maspack.matrix.Vector3d>, int[])
, setColors(java.util.List<float[]>, int[])
, etc.
public abstract int[] createVertexIndices()
The indices are zero-based and specify the vertex indices for
each mesh feature. The number of indices and their structure hence
depends on the mesh subclass: for PolygonalMesh
meshes,
this gives the vertices for each face; for PolylineMesh
, the
vertices for each polyline, and for PointMesh
, the vertices
for each point. For example, assume that we have a
PolygonalMesh
with four vertices and
four triangles arranged to form a tetrahedron, so that the vertex
indices for each triangular face are given by (0, 2, 1)
,
(0, 3, 2)
, (0, 1, 3)
,
and (1, 2, 3)
. Then the returned vertex
indices will be
0 2 1 0 3 2 0 1 3 1 2 3
public int[] createFeatureIndices()
The indices are zero-based and specify, for each feature
vertex, the index of the feature. What the features are
depends on the mesh subclass: faces for PolygonalMesh
,
polyline for PolylineMesh
, vertices themselves
for PointMesh
. For example, assume that we have a
PolygonalMesh
with four vertices and
four triangles arranged to form a tetrahedron. Then the returned feature
indices will be
0 0 0 1 1 1 2 2 2 3 3 3
public abstract boolean hasAutoNormalCreation()
true
if this mesh automatically creates a default
set of normals if getNormals()
is called and no normals have been
explicitly set using setNormals(java.util.List<maspack.matrix.Vector3d>, int[])
.true
if this mesh automatically creates normals.public abstract boolean getWriteNormals()
true
if this mesh's normals should be written
to a file. This will be the case if the normals were explicitly
set, or if they were automatically created using information
(such as hard edges) that cannot be easily reconstructed from the
information written to standard file formats.true
if the normals should be written to a filepublic java.util.ArrayList<Vector3d> getNormals()
null
if this mesh does not have normals. If no normal
information is currently defined and hasAutoNormalCreation()
returns true
, then a set of vertex normals and indices will
be generated automatically.
The set of normals is indexed by the indices returned by getNormalIndices()
to specify a single normal per feature vertex.
Vertex normals are used for shading computations during smooth mesh rendering. If smooth mesh rendering is selected and there are no normals, then shading will be disabled.
null
if there are
none.public int numNormals()
public boolean hasNormals()
true
if there are normals associated with
this mesh (or if they will be generated automatically).true
if this mesh has normalspublic Vector3d getNormal(int idx)
idx
. The returned
value is a reference that can be modified by the application. If normals
are automatically generated, then modifying the value may lead to
unexpected results.idx
- normal indexjava.lang.IndexOutOfBoundsException
- if normals are not defined or
if the index is out of range.public void setNormal(int idx, Vector3d nrml)
idx
. If normals are
automatically generated, then this may lead to unexpected results.idx
- normal indexnrml
- new normal value (should be normalized)java.lang.IndexOutOfBoundsException
- if normals are not defined or
if the index is out of range.public Vector3d getFeatureNormal(int fidx, int k)
fidx
, or null
if there is no such normal.fidx
- feature indexk
- vertex index relative to the featurenull
public int[] getNormalIndices()
null
if this mesh does not have normals. If no normal
information is currently defined and hasAutoNormalCreation()
returns true
, then a set of vertex normals and indices will
be generated automatically.
The indices are zero-based and index into the list returned by getNormals()
to specific a normal per feature vertex. The number of
indices and their structure hences depends on the mesh subclass:
polygonal meshes have one index per vertex per face, polyline meshes will
have two indices per line segment, and point meshes will have one index
per vertex. For polygonal meshes, if there is one normal per vertex, then
the indexing structure will be the same as that for face vertices. For
example, assume that we have a mesh with four vertices and four triangles
arranged to form a tetrahedron, so that the vertex indices for each
triangular face are given by (0, 2, 1)
, (0, 3,
2)
, (0, 1, 3)
, and (1, 2, 3)
. Then if
there is one normal per vertex, there should be 12 normal indices with
the values`
0 2 1 0 3 2 0 1 3 1 2 3
In some cases, there may be no normal information for the vertices of
specific features. In such cases, the cooresponding index values will be
-1
.
null
. Must
not be modified.public void setNormals(java.util.List<Vector3d> normals, int[] indices)
nrmls
and indices
is
copied to internal structures that are subsequently returned by getNormals()
and getNormalIndices()
, respectively.
The argument indices
specifies an index values into
nrmls
for each vertex of each feature, as described for
getNormalIndices()
. If a feature vertex has no normal value, the
index should be specified as -1
.
indices
is null
, then nrmls
should
contain one normal per vertex and a default index set will be created,
appropriate to the mesh subclass.
If normals
is null
, then
normals are explicitly removed and subsequent calls to getNormals()
will return null
.
After this call, hasExplicitNormals()
will return
true
.
normals
- vertex normals to be set for this meshindices
- normal indices, or null
if the indices are to be
automatically generated.public boolean hasExplicitNormals()
true
if vertex normal information has been
explicitly specified using setNormals(java.util.List<maspack.matrix.Vector3d>, int[])
. If normals have been
explicitly set, then it is up to the application to update the normals
whenever the vertex positions are modified. Note that even if this
method returns true
, it is still possible for the
mesh to not have any normals (i.e.,
hasNormals()
and numNormals()
may return
false
and 0
). That's because
setNormals(null,null)
will explicitly
set the mesh to not have any normals.public void clearNormals()
setNormals(java.util.List<maspack.matrix.Vector3d>, int[])
. After this call, hasExplicitNormals()
will
return false
and getNormals()
and getNormalIndices()
will either return null
or automatically
create new normals and indices, depending on whether
hasAutoNormalCreation()
returns true
.public java.util.ArrayList<float[]> getColors()
null
if
this mesh does not have colors. This set of colors is indexed by the
indices returned by getColorIndices()
to specify a single color
per feature vertex.
Each color in the returned list is described by a float[]
of length four giving the RGBA values in the range 0 to 1. The structure
of the list should not be modified, but individual float[]
objects can be changed to modify the corresponding color.
null
if there
are none.public int numColors()
public boolean hasColors()
true
if there are colors associated
with this mesh.true
if this mesh has colorspublic float[] getColor(int idx)
idx
. The returned
value is a reference that can be modified by the application.idx
- color indexjava.lang.IndexOutOfBoundsException
- if colors are not defined or
if the index is out of range.public void setColor(int idx, float[] color)
idx
.idx
- color indexcolor
- new color value. Array must have a length >=
3 and
give the RGB (or RGBA values for length >=
4) in the range [0,
1].java.lang.IndexOutOfBoundsException
- if colors are not defined or
if the index is out of range.public void setColor(int idx, java.awt.Color color)
idx
.idx
- color indexcolor
- new color valuejava.lang.IndexOutOfBoundsException
- if colors are not defined or
if the index is out of range.public void setColor(int idx, float r, float g, float b, float a)
idx
.idx
- color indexr
- red (range [0,1])g
- green (range [0,1])b
- blue (range [0,1])a
- alpha (range [0,1])java.lang.IndexOutOfBoundsException
- if colors are not defined or
if the index is out of range.public void setColor(int idx, double r, double g, double b, double a)
idx
.idx
- color indexr
- red (range [0,1])g
- green (range [0,1])b
- blue (range [0,1])a
- alpha (range [0,1])java.lang.IndexOutOfBoundsException
- if colors are not defined or
if the index is out of range.public float[] getFeatureColor(int fidx, int k)
fidx
, or null
if there is no such color.fidx
- feature indexk
- vertex index relative to the featurenull
public int[] getColorIndices()
null
if this mesh does not have colors. These index into the list returned by
getColors()
to specify a color per feature vertex, using the same
indexing structure as that described for getNormalIndices()
.null
. Must not be
modified.public boolean hasExplicitColors()
public void setColors(java.util.List<float[]> colors, int[] indices)
colors
and indices
is
copied to internal structures that are subsequently returned by getColors()
and getColorIndices()
, respectively.
Colors should be specified as float[]
objects with a
length >=
3, indicating RGG values (or RGBA values for length
>=
4) in the range [0,1].
The argument indices
specifies an index values into
colors
for each vertex of each feature, as described for
getNormalIndices()
. If a feature vertex has no color value, the
index should be specified as -1
. If indices
is
null
, then colors
should contain one color per
vertex and a default index set will be created, appropriate to the mesh
subclass.
If colors
is null
, then
colors are explicitly removed and subsequent calls to getColors()
will return null
.
Each entry in colors
should be a float[]
of
length three (or four) giving the RGB (or RGBA) values for the color in
the range 0 to 1.
Calling this method clears vertex or feature coloring, if either of
those had been set. However, isVertexColored()
or isFeatureColored()
may still return true if colors and their indexing
match either.
colors
- colors to be set for this meshindices
- color indices, or null
if the indices are to
be automatically generated.public void clearColors()
getColors()
and getColorIndices()
will both return
null
.public void setColorsFixed(boolean set)
public boolean isColorsFixed()
public void setTextureCoordsFixed(boolean set)
public boolean isTextureCoordsFixed()
public java.util.ArrayList<Vector3d> getTextureCoords()
null
if this mesh does not have texture coordinates. These
coordinates are indexed by the indices returned by getTextureIndices()
to specify a single coordinate per feature vertex.
The structure of this list should not be modified, but individual entries can be changed to modify the corresponding coordinates.
null
if there are none.public int numTextureCoords()
public boolean hasTextureCoords()
true
if there are texture coordinates associated
with this mesh.true
if this mesh has texture coordiatespublic Vector3d getTextureCoords(int idx)
idx
. The returned value is a reference that can be modified
by the application.idx
- coordinate indexidx
java.lang.IndexOutOfBoundsException
- if texture coordinates are not defined
or if the index is out of range.public void setTextureCoords(int idx, Vector3d coords)
idx
.idx
- coordinate indexcoords
- new texture coordinatesjava.lang.IndexOutOfBoundsException
- if texture coordinates are not defined
or if the index is out of range.public Vector3d getFeatureTextureCoords(int fidx, int k)
fidx
, or null
if there is no
such coordinate.fidx
- feature indexk
- vertex index relative to the featurenull
public int[] getTextureIndices()
null
if this mesh does not have texture coordinates. These
index into the list returned by getTextureCoords()
to specify a
coordinates per feature vertex, using the same indexing structure as that
described for getNormalIndices()
.null
. Must not be
modified.public void setTextureCoords(java.util.List<Vector3d> coords, int[] indices)
coords
and
indices
is copied to internal structures that are
subsequently returned by getTextureCoords()
and getTextureIndices()
, respectively.
The argument indices
specifies an index values into
coords
for each vertex of each feature, as described for
getNormalIndices()
. If a feature vertex has no texture coordinate
value, the index should be specified as -1
.
If indices
is
null
, then coords
should contain one coordinate
per vertex and a default index set will be created, appropriate to the
mesh subclass.
If coords
is null
, then
texture coordinates are explicitly removed and subsequent calls to getTextureCoords()
will return null
.
coords
- texture coordinates to be set for this meshindices
- texture indices, or null
if the indices are to
be automatically generated.public void clearTextureCoords()
getColors()
and getColorIndices()
will both return
null
.public void perturb(double tol)
rad
* tol
, where
rad
is an estimate of the mesh's ``radius'', as computed by
getRadius()
, and tol
is a supplied tolerance argument.
This method calls notifyVertexPositionsModified()
after
applying the perturbation.
tol
- controls the size of the perturbationpublic long checksum()
public SpatialInertia createInertia(double mass, MassDistribution dist)
MassDistribution.POINT
distribution (since all
meshes contain vertices), but only meshes with area features (such as
faces) support an MassDistribution.AREA
distribution.mass
- overall massdist
- how the mass is distributed across the featuresjava.lang.IllegalArgumentException
- if the distribution is not compatible
with the available mesh features.public boolean supportsMassDistribution(MassDistribution dist)
true
if the indicated mass distrubution is supportedpublic abstract BVTree getBVTree()