All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.stephengold.joltjni.Face Maven / Gradle / Ivy

The newest version!
/*
Copyright (c) 2024 Stephen Gold

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 */
package com.github.stephengold.joltjni;

/**
 * A triangular element on the surface of a soft body. (native type:
 * {@code SoftBodySharedSettings::Face})
 *
 * @author Stephen Gold [email protected]
 */
public class Face extends JoltPhysicsObject {
    // *************************************************************************
    // constructors

    /**
     * Instantiate a default face.
     */
    public Face() {
        long faceVa = createDefault();
        setVirtualAddress(faceVa, () -> free(faceVa));
    }
    // *************************************************************************
    // new methods exposed

    /**
     * Return the material index. The face is unaffected. (native attribute:
     * mMaterialIndex)
     *
     * @return the index of the material in the body's shared settings (≥0)
     */
    public int getMaterialIndex() {
        long faceVa = va();
        int result = getMaterialIndex(faceVa);

        return result;
    }

    /**
     * Return the mesh vertex at the specified corner. The face is unaffected.
     * (native attribute: mVertex)
     *
     * @param indexInFace which corner of the face (0 or 1 or 2)
     * @return the mesh index of the vertex (≥0)
     */
    public int getVertex(int indexInFace) {
        long faceVa = va();
        int result = getVertex(faceVa, indexInFace);

        return result;
    }

    /**
     * Test whether the face is degenerate. The face is unaffected.
     *
     * @return {@code true} if degenerate, otherwise {@code false}
     */
    public boolean isDegenerate() {
        long faceVa = va();
        boolean result = isDegenerate(faceVa);

        return result;
    }

    /**
     * Assign the specified material to the face. (native attribute:
     * mMaterialIndex)
     *
     * @param material the index of the desired material (≥0, default=0)
     */
    public void setMaterialIndex(int material) {
        long faceVa = va();
        setMaterialIndex(faceVa, material);
    }

    /**
     * Assign the specified mesh vertex to the face. (native attribute: mVertex)
     *
     * @param indexInFace which corner of the triangle (0 or 1 or 2)
     * @param indexInMesh the index of the vertex to assign (≥0)
     */
    public void setVertex(int indexInFace, int indexInMesh) {
        long faceVa = va();
        setVertex(faceVa, indexInFace, indexInMesh);
    }
    // *************************************************************************
    // native private methods

    native private static long createDefault();

    native private static void free(long faceVa);

    native private static int getMaterialIndex(long faceVa);

    native private static int getVertex(long faceVa, int indexInFace);

    native private static boolean isDegenerate(long faceVa);

    native private static void setMaterialIndex(long faceVa, int material);

    native private static void setVertex(
            long faceVa, int indexInFace, int indexInMesh);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy