Search in sources :

Example 31 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method processTriangle.

public static TriangleData processTriangle(int[] index, Vector3f[] v, Vector2f[] t) {
    TempVars tmp = TempVars.get();
    try {
        Vector3f edge1 = tmp.vect1;
        Vector3f edge2 = tmp.vect2;
        Vector2f edge1uv = tmp.vect2d;
        Vector2f edge2uv = tmp.vect2d2;
        Vector3f tangent = tmp.vect3;
        Vector3f binormal = tmp.vect4;
        Vector3f normal = tmp.vect5;
        t[1].subtract(t[0], edge1uv);
        t[2].subtract(t[0], edge2uv);
        float det = edge1uv.x * edge2uv.y - edge1uv.y * edge2uv.x;
        boolean normalize = false;
        if (Math.abs(det) < ZERO_TOLERANCE) {
            log.log(Level.WARNING, "Colinear uv coordinates for triangle " + "[{0}, {1}, {2}]; tex0 = [{3}, {4}], " + "tex1 = [{5}, {6}], tex2 = [{7}, {8}]", new Object[] { index[0], index[1], index[2], t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y });
            det = 1;
            normalize = true;
        }
        v[1].subtract(v[0], edge1);
        v[2].subtract(v[0], edge2);
        tangent.set(edge1);
        tangent.normalizeLocal();
        binormal.set(edge2);
        binormal.normalizeLocal();
        if (Math.abs(Math.abs(tangent.dot(binormal)) - 1) < ZERO_TOLERANCE) {
            log.log(Level.WARNING, "Vertices are on the same line " + "for triangle [{0}, {1}, {2}].", new Object[] { index[0], index[1], index[2] });
        }
        float factor = 1 / det;
        tangent.x = (edge2uv.y * edge1.x - edge1uv.y * edge2.x) * factor;
        tangent.y = (edge2uv.y * edge1.y - edge1uv.y * edge2.y) * factor;
        tangent.z = (edge2uv.y * edge1.z - edge1uv.y * edge2.z) * factor;
        if (normalize) {
            tangent.normalizeLocal();
        }
        binormal.x = (edge1uv.x * edge2.x - edge2uv.x * edge1.x) * factor;
        binormal.y = (edge1uv.x * edge2.y - edge2uv.x * edge1.y) * factor;
        binormal.z = (edge1uv.x * edge2.z - edge2uv.x * edge1.z) * factor;
        if (normalize) {
            binormal.normalizeLocal();
        }
        tangent.cross(binormal, normal);
        normal.normalizeLocal();
        return new TriangleData(tangent.clone(), binormal.clone(), normal.clone());
    } finally {
        tmp.release();
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f)

Example 32 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class BufferUtils method getVector3Array.

/**
     * Generates a Vector3f array from the given FloatBuffer.
     * 
     * @param buff
     *            the FloatBuffer to read from
     * @return a newly generated array of Vector3f objects
     */
public static Vector3f[] getVector3Array(FloatBuffer buff) {
    buff.clear();
    Vector3f[] verts = new Vector3f[buff.limit() / 3];
    for (int x = 0; x < verts.length; x++) {
        Vector3f v = new Vector3f(buff.get(), buff.get(), buff.get());
        verts[x] = v;
    }
    return verts;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 33 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class BufferUtils method addInBuffer.

/**
     * Add to a Vector3f in-buffer.
     * 
     * @param toAdd
     *            the vector to add from
     * @param buf
     *            the buffer to find the Vector3f within
     * @param index
     *            the position (in terms of vectors, not floats) of the vector
     *            to add to
     */
public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) {
    TempVars vars = TempVars.get();
    Vector3f tempVec3 = vars.vect1;
    populateFromBuffer(tempVec3, buf, index);
    tempVec3.addLocal(toAdd);
    setInBuffer(tempVec3, buf, index);
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 34 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class BufferUtils method normalizeVector3.

/**
     * Normalize a Vector3f in-buffer.
     * 
     * @param buf
     *            the buffer to find the Vector3f within
     * @param index
     *            the position (in terms of vectors, not floats) of the vector
     *            to normalize
     */
public static void normalizeVector3(FloatBuffer buf, int index) {
    TempVars vars = TempVars.get();
    Vector3f tempVec3 = vars.vect1;
    populateFromBuffer(tempVec3, buf, index);
    tempVec3.normalizeLocal();
    setInBuffer(tempVec3, buf, index);
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 35 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class Picture method setWidth.

/**
     * Set the width in pixels of the picture, if the width
     * does not match the texture's width, then the texture will
     * be scaled to fit the picture.
     * 
     * @param width the width to set.
     */
public void setWidth(float width) {
    this.width = width;
    setLocalScale(new Vector3f(width, height, 1f));
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)536 Material (com.jme3.material.Material)126 Geometry (com.jme3.scene.Geometry)118 DirectionalLight (com.jme3.light.DirectionalLight)95 Quaternion (com.jme3.math.Quaternion)94 TempVars (com.jme3.util.TempVars)67 ColorRGBA (com.jme3.math.ColorRGBA)64 Node (com.jme3.scene.Node)63 Spatial (com.jme3.scene.Spatial)57 Box (com.jme3.scene.shape.Box)57 Sphere (com.jme3.scene.shape.Sphere)51 Texture (com.jme3.texture.Texture)41 KeyTrigger (com.jme3.input.controls.KeyTrigger)36 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)35 Vector2f (com.jme3.math.Vector2f)35 FilterPostProcessor (com.jme3.post.FilterPostProcessor)34 FloatBuffer (java.nio.FloatBuffer)34 InputCapsule (com.jme3.export.InputCapsule)33 BoundingBox (com.jme3.bounding.BoundingBox)30 AmbientLight (com.jme3.light.AmbientLight)30