use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MeshBase method setTextureCoords.
/**
* Explicitly sets the texture coordinates and associated indices for this
* mesh. The information supplied by <code>coords</code> and
* <code>indices</code> is copied to internal structures that are
* subsequently returned by {@link #getTextureCoords} and {@link
* #getTextureIndices}, respectively.
* The argument <code>indices</code> specifies an index values into
* <code>coords</code> for each vertex of each feature, as described for
* {@link #getNormalIndices()}. If a feature vertex has no texture coordinate
* value, the index should be specified as <code>-1</code>.
* If <code>indices</code> is
* <code>null</code>, then <code>coords</code> should contain one coordinate
* per vertex and a default index set will be created, appropriate to the
* mesh subclass.
*
* <p>If <code>coords</code> is <code>null</code>, then
* texture coordinates are explicitly removed and subsequent calls to {@link
* #getTextureCoords} will return <code>null</code>.
*
* @param coords texture coordinates to be set for this mesh
* @param indices texture indices, or <code>null</code> if the indices are to
* be automatically generated.
*/
public void setTextureCoords(List<Vector3d> coords, int[] indices) {
if (coords == null) {
myTextureCoords = null;
myTextureIndices = null;
} else {
ArrayList<Vector3d> newCoords = new ArrayList<Vector3d>(coords.size());
for (int i = 0; i < coords.size(); i++) {
newCoords.add(new Vector3d(coords.get(i)));
}
if (indices == null && coords.size() != numVertices()) {
throw new IllegalArgumentException("Number of coords must equal number of vertices when " + "indices argument is null");
}
int[] newIndices = createIndices(indices, coords.size());
myTextureCoords = newCoords;
myTextureIndices = newIndices;
}
notifyModified();
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MeshBase method transform.
/**
* Applies a transform to the vertices and normals of this mesh, in
* local mesh coordinates. The topology of the mesh remains unchanged.
*
* @param trans transformation to apply
*/
public void transform(VectorTransformer3d trans) {
for (Vertex3d vertex : myVertices) {
trans.transformPnt(vertex.pnt, vertex.pnt);
}
if (myNormalsExplicitP) {
for (int i = 0; i < myNormals.size(); i++) {
Vector3d nrm = myNormals.get(i);
trans.transformCovec(nrm, nrm);
nrm.normalize();
}
} else {
// auto normals will be regenerated
clearNormals();
}
invalidateBoundingInfo();
notifyModified();
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MeshBase method inverseTransform.
/**
* Applies an inverse affine transformation to the vertices of this mesh, in
* local mesh coordinates. The topology of the mesh remains unchanged.
*
* @param X
* affine transformation
*/
public void inverseTransform(AffineTransform3dBase X) {
for (Vertex3d vertex : myVertices) {
vertex.pnt.inverseTransform(X);
}
if (myNormalsExplicitP) {
Matrix3d A = new Matrix3d(X.getMatrix());
A.transpose();
for (int i = 0; i < myNormals.size(); i++) {
Vector3d nrm = myNormals.get(i);
A.mul(nrm, nrm);
nrm.normalize();
}
} else {
// auto normals will be regenerated
clearNormals();
}
invalidateBoundingInfo();
notifyModified();
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MeshBase method translateToCentroid.
/**
* Translates the vertices of this mesh so that its origin coincides
* with the centroid. The topology of the mesh remains unchanged.
*/
public void translateToCentroid() {
Vector3d off = new Vector3d();
computeCentroid(off);
off.negate();
translate(off);
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MeshBase method updateVertexRenderNormals.
protected void updateVertexRenderNormals() {
ArrayList<Vector3d> normals = getNormals();
if (normals != null) {
for (int i = 0; i < normals.size(); i++) {
Vector3d nrm = normals.get(i);
float[] vec = myRenderNormals[i];
vec[0] = (float) nrm.x;
vec[1] = (float) nrm.y;
vec[2] = (float) nrm.z;
}
}
}
Aggregations