Search in sources :

Example 51 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class CurvesHelper method transformBevel.

/**
     * The method transforms the bevel along the curve.
     * 
     * @param bevel
     *            the bevel to be transformed
     * @param prevPos
     *            previous curve point
     * @param currPos
     *            current curve point (here the center of the new bevel will be
     *            set)
     * @param nextPos
     *            next curve point
     * @return points of transformed bevel
     */
protected Vector3f[] transformBevel(Vector3f[] bevel, Vector3f prevPos, Vector3f currPos, Vector3f nextPos) {
    bevel = bevel.clone();
    // currPos and directionVector define the line in 3D space
    Vector3f directionVector = prevPos != null ? currPos.subtract(prevPos) : nextPos.subtract(currPos);
    directionVector.normalizeLocal();
    // plane is described by equation: Ax + By + Cz + D = 0 where planeNormal = [A, B, C] and D = -(Ax + By + Cz)
    Vector3f planeNormal = null;
    if (prevPos != null) {
        planeNormal = currPos.subtract(prevPos).normalizeLocal();
        if (nextPos != null) {
            planeNormal.addLocal(nextPos.subtract(currPos).normalizeLocal()).normalizeLocal();
        }
    } else {
        planeNormal = nextPos.subtract(currPos).normalizeLocal();
    }
    // D = -(Ax + By + Cz)
    float D = -planeNormal.dot(currPos);
    // now we need to compute paralell cast of each bevel point on the plane, the leading line is already known
    // parametric equation of a line: x = px + vx * t; y = py + vy * t; z = pz + vz * t
    // where p = currPos and v = directionVector
    // using x, y and z in plane equation we get value of 't' that will allow us to compute the point where plane and line cross
    float temp = planeNormal.dot(directionVector);
    for (int i = 0; i < bevel.length; ++i) {
        float t = -(planeNormal.dot(bevel[i]) + D) / temp;
        if (fixUpAxis) {
            bevel[i] = new Vector3f(bevel[i].x + directionVector.x * t, bevel[i].y + directionVector.y * t, bevel[i].z + directionVector.z * t);
        } else {
            bevel[i] = new Vector3f(bevel[i].x + directionVector.x * t, -bevel[i].z + directionVector.z * t, bevel[i].y + directionVector.y * t);
        }
    }
    return bevel;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 52 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method computeFromTris.

/**
     * <code>computeFromTris</code> creates a new Bounding Box from a given
     * set of triangles. It is used in OBBTree calculations.
     * 
     * @param tris
     * @param start
     * @param end
     */
public void computeFromTris(Triangle[] tris, int start, int end) {
    if (end - start <= 0) {
        return;
    }
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
    Vector3f point;
    for (int i = start; i < end; i++) {
        point = tris[i].get(0);
        checkMinMax(min, max, point);
        point = tris[i].get(1);
        checkMinMax(min, max, point);
        point = tris[i].get(2);
        checkMinMax(min, max, point);
    }
    center.set(min.addLocal(max));
    center.multLocal(0.5f);
    xExtent = max.x - center.x;
    yExtent = max.y - center.y;
    zExtent = max.z - center.z;
    vars.release();
}
Also used : TempVars(com.jme3.util.TempVars)

Example 53 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class SinglePassAndImageBasedLightingLogic method updateLightListUniforms.

/**
     * Uploads the lights in the light list as two uniform arrays.<br/><br/> *
     * <p>
     * <code>uniform vec4 g_LightColor[numLights];</code><br/> //
     * g_LightColor.rgb is the diffuse/specular color of the light.<br/> //
     * g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/> //
     * 2 = Spot. <br/> <br/>
     * <code>uniform vec4 g_LightPosition[numLights];</code><br/> //
     * g_LightPosition.xyz is the position of the light (for point lights)<br/>
     * // or the direction of the light (for directional lights).<br/> //
     * g_LightPosition.w is the inverse radius (1/r) of the light (for
     * attenuation) <br/> </p>
     */
protected int updateLightListUniforms(Shader shader, Geometry g, LightList lightList, int numLights, RenderManager rm, int startIndex, int lastTexUnit) {
    if (numLights == 0) {
        // this shader does not do lighting, ignore.
        return 0;
    }
    Uniform lightData = shader.getUniform("g_LightData");
    //8 lights * max 3
    lightData.setVector4Length(numLights * 3);
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    Uniform lightProbeData = shader.getUniform("g_LightProbeData");
    lightProbeData.setVector4Length(1);
    Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
    Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
    lightProbe = null;
    if (startIndex != 0) {
        // apply additive blending for 2nd and future passes
        rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
        ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
    } else {
        lightProbe = extractIndirectLights(lightList, true);
        ambientColor.setValue(VarType.Vector4, ambientLightColor);
    }
    //If there is a lightProbe in the list we force it's render on the first pass
    if (lightProbe != null) {
        BoundingSphere s = (BoundingSphere) lightProbe.getBounds();
        lightProbeData.setVector4InArray(lightProbe.getPosition().x, lightProbe.getPosition().y, lightProbe.getPosition().z, 1f / s.getRadius(), 0);
        //assigning new texture indexes
        int irrUnit = lastTexUnit++;
        int pemUnit = lastTexUnit++;
        rm.getRenderer().setTexture(irrUnit, lightProbe.getIrradianceMap());
        lightProbeIrrMap.setValue(VarType.Int, irrUnit);
        rm.getRenderer().setTexture(pemUnit, lightProbe.getPrefilteredEnvMap());
        lightProbePemMap.setValue(VarType.Int, pemUnit);
    } else {
        //Disable IBL for this pass
        lightProbeData.setVector4InArray(0, 0, 0, -1, 0);
    }
    int lightDataIndex = 0;
    TempVars vars = TempVars.get();
    Vector4f tmpVec = vars.vect4f1;
    int curIndex;
    int endIndex = numLights + startIndex;
    for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
        Light l = lightList.get(curIndex);
        if (l.getType() == Light.Type.Ambient) {
            endIndex++;
            continue;
        }
        ColorRGBA color = l.getColor();
        if (l.getType() != Light.Type.Probe) {
            lightData.setVector4InArray(color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), lightDataIndex);
            lightDataIndex++;
        }
        switch(l.getType()) {
            case Directional:
                DirectionalLight dl = (DirectionalLight) l;
                Vector3f dir = dl.getDirection();
                //Data directly sent in view space to avoid a matrix mult for each pixel
                tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Point:
                PointLight pl = (PointLight) l;
                Vector3f pos = pl.getPosition();
                float invRadius = pl.getInvRadius();
                tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Spot:
                SpotLight sl = (SpotLight) l;
                Vector3f pos2 = sl.getPosition();
                Vector3f dir2 = sl.getDirection();
                float invRange = sl.getInvSpotRange();
                float spotAngleCos = sl.getPackedAngleCos();
                tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                lightDataIndex++;
                tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                lightDataIndex++;
                break;
            default:
                throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
    }
    vars.release();
    //Padding of unsued buffer space
    while (lightDataIndex < numLights * 3) {
        lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
        lightDataIndex++;
    }
    return curIndex;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) TempVars(com.jme3.util.TempVars)

Example 54 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class SinglePassLightingLogic method updateLightListUniforms.

/**
     * Uploads the lights in the light list as two uniform arrays.<br/><br/> *
     * <p>
     * <code>uniform vec4 g_LightColor[numLights];</code><br/> //
     * g_LightColor.rgb is the diffuse/specular color of the light.<br/> //
     * g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/> //
     * 2 = Spot. <br/> <br/>
     * <code>uniform vec4 g_LightPosition[numLights];</code><br/> //
     * g_LightPosition.xyz is the position of the light (for point lights)<br/>
     * // or the direction of the light (for directional lights).<br/> //
     * g_LightPosition.w is the inverse radius (1/r) of the light (for
     * attenuation) <br/> </p>
     */
protected int updateLightListUniforms(Shader shader, Geometry g, LightList lightList, int numLights, RenderManager rm, int startIndex) {
    if (numLights == 0) {
        // this shader does not do lighting, ignore.
        return 0;
    }
    Uniform lightData = shader.getUniform("g_LightData");
    //8 lights * max 3
    lightData.setVector4Length(numLights * 3);
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    if (startIndex != 0) {
        // apply additive blending for 2nd and future passes
        rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
        ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
    } else {
        ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList, true, ambientLightColor));
    }
    int lightDataIndex = 0;
    TempVars vars = TempVars.get();
    Vector4f tmpVec = vars.vect4f1;
    int curIndex;
    int endIndex = numLights + startIndex;
    for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
        Light l = lightList.get(curIndex);
        if (l.getType() == Light.Type.Ambient) {
            endIndex++;
            continue;
        }
        ColorRGBA color = l.getColor();
        //Color
        lightData.setVector4InArray(color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), lightDataIndex);
        lightDataIndex++;
        switch(l.getType()) {
            case Directional:
                DirectionalLight dl = (DirectionalLight) l;
                Vector3f dir = dl.getDirection();
                //Data directly sent in view space to avoid a matrix mult for each pixel
                tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
                rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
                //                        tmpVec.divideLocal(tmpVec.w);
                //                        tmpVec.normalizeLocal();
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Point:
                PointLight pl = (PointLight) l;
                Vector3f pos = pl.getPosition();
                float invRadius = pl.getInvRadius();
                tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
                rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
                //tmpVec.divideLocal(tmpVec.w);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Spot:
                SpotLight sl = (SpotLight) l;
                Vector3f pos2 = sl.getPosition();
                Vector3f dir2 = sl.getDirection();
                float invRange = sl.getInvSpotRange();
                float spotAngleCos = sl.getPackedAngleCos();
                tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
                rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
                // tmpVec.divideLocal(tmpVec.w);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                lightDataIndex++;
                //We transform the spot direction in view space here to save 5 varying later in the lighting shader
                //one vec4 less and a vec4 that becomes a vec3
                //the downside is that spotAngleCos decoding happens now in the frag shader.
                tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
                rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
                tmpVec.normalizeLocal();
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                lightDataIndex++;
                break;
            case Probe:
                break;
            default:
                throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
    }
    vars.release();
    //Padding of unsued buffer space
    while (lightDataIndex < numLights * 3) {
        lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
        lightDataIndex++;
    }
    return curIndex;
}
Also used : Vector4f(com.jme3.math.Vector4f) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) Light(com.jme3.light.Light) PointLight(com.jme3.light.PointLight) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Uniform(com.jme3.shader.Uniform) TempVars(com.jme3.util.TempVars) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Example 55 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class Line method distanceSquared.

public float distanceSquared(Vector3f point) {
    TempVars vars = TempVars.get();
    Vector3f compVec1 = vars.vect1;
    Vector3f compVec2 = vars.vect2;
    point.subtract(origin, compVec1);
    float lineParameter = direction.dot(compVec1);
    origin.add(direction.mult(lineParameter, compVec2), compVec2);
    compVec2.subtract(point, compVec1);
    float len = compVec1.lengthSquared();
    vars.release();
    return len;
}
Also used : TempVars(com.jme3.util.TempVars)

Aggregations

Vector3f (com.jme3.math.Vector3f)27 TempVars (com.jme3.util.TempVars)19 FloatBuffer (java.nio.FloatBuffer)6 ColorRGBA (com.jme3.math.ColorRGBA)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 SpotLight (com.jme3.light.SpotLight)4 Quaternion (com.jme3.math.Quaternion)4 Spatial (com.jme3.scene.Spatial)4 ArrayList (java.util.ArrayList)4 CollisionResult (com.jme3.collision.CollisionResult)3 Light (com.jme3.light.Light)3 Triangle (com.jme3.math.Triangle)3 Vector2f (com.jme3.math.Vector2f)3 Geometry (com.jme3.scene.Geometry)3 Mesh (com.jme3.scene.Mesh)3 BoundingSphere (com.jme3.bounding.BoundingSphere)2 MotionPath (com.jme3.cinematic.MotionPath)2 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)2