Search in sources :

Example 31 with Vector3d

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();
}
Also used : Vector3d(maspack.matrix.Vector3d) ArrayList(java.util.ArrayList)

Example 32 with Vector3d

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();
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 33 with Vector3d

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();
}
Also used : Matrix3d(maspack.matrix.Matrix3d) Vector3d(maspack.matrix.Vector3d)

Example 34 with Vector3d

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);
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 35 with Vector3d

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;
        }
    }
}
Also used : Vector3d(maspack.matrix.Vector3d)

Aggregations

Vector3d (maspack.matrix.Vector3d)441 Point3d (maspack.matrix.Point3d)128 RigidTransform3d (maspack.matrix.RigidTransform3d)56 ArrayList (java.util.ArrayList)38 Matrix3d (maspack.matrix.Matrix3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)30 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)24 PolygonalMesh (maspack.geometry.PolygonalMesh)23 Vertex3d (maspack.geometry.Vertex3d)23 Face (maspack.geometry.Face)20 AxisAngle (maspack.matrix.AxisAngle)19 Vector3i (maspack.matrix.Vector3i)19 Point (artisynth.core.mechmodels.Point)18 RenderProps (maspack.render.RenderProps)17 VectorNd (maspack.matrix.VectorNd)15 AffineTransform3d (maspack.matrix.AffineTransform3d)14 IOException (java.io.IOException)13 Vector2d (maspack.matrix.Vector2d)11 Plane (maspack.matrix.Plane)10 GLViewer (maspack.render.GL.GLViewer)9