Search in sources :

Example 41 with Point

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

the class TemporalMesh method clone.

@Override
public TemporalMesh clone() {
    try {
        TemporalMesh result = new TemporalMesh(meshStructure, blenderContext, false);
        result.name = name;
        for (Vector3f v : vertices) {
            result.vertices.add(v.clone());
        }
        for (Vector3f n : normals) {
            result.normals.add(n.clone());
        }
        for (Map<String, Float> group : vertexGroups) {
            result.vertexGroups.add(new HashMap<String, Float>(group));
        }
        for (byte[] vertColor : verticesColors) {
            result.verticesColors.add(vertColor.clone());
        }
        result.materials = materials;
        result.properties = properties;
        result.boneIndexes.putAll(boneIndexes);
        result.postMeshCreationModifiers.addAll(postMeshCreationModifiers);
        for (Face face : faces) {
            result.faces.add(face.clone());
        }
        for (Edge edge : edges) {
            result.edges.add(edge.clone());
        }
        for (Point point : points) {
            result.points.add(point.clone());
        }
        result.rebuildIndexesMappings();
        return result;
    } catch (BlenderFileException e) {
        LOGGER.log(Level.SEVERE, "Error while cloning the temporal mesh: {0}. Returning null.", e.getLocalizedMessage());
    }
    return null;
}
Also used : Vector3f(com.jme3.math.Vector3f) BlenderFileException(com.jme3.scene.plugins.blender.file.BlenderFileException)

Example 42 with Point

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

the class MaskModifier method removeVertexAt.

/**
     * Every face, edge and point that contains
     * the vertex will be removed.
     * @param index
     *            the index of a vertex to be removed
     * @throws IndexOutOfBoundsException
     *             thrown when given index is negative or beyond the count of vertices
     */
private void removeVertexAt(final int index, TemporalMesh temporalMesh) {
    if (index < 0 || index >= temporalMesh.getVertexCount()) {
        throw new IndexOutOfBoundsException("The given index is out of bounds: " + index);
    }
    temporalMesh.getVertices().remove(index);
    temporalMesh.getNormals().remove(index);
    if (temporalMesh.getVertexGroups().size() > 0) {
        temporalMesh.getVertexGroups().remove(index);
    }
    if (temporalMesh.getVerticesColors().size() > 0) {
        temporalMesh.getVerticesColors().remove(index);
    }
    IndexPredicate shiftPredicate = new IndexPredicate() {

        @Override
        public boolean execute(Integer i) {
            return i > index;
        }
    };
    for (int i = temporalMesh.getFaces().size() - 1; i >= 0; --i) {
        Face face = temporalMesh.getFaces().get(i);
        if (face.getIndexes().indexOf(index) >= 0) {
            temporalMesh.getFaces().remove(i);
        } else {
            face.getIndexes().shiftIndexes(-1, shiftPredicate);
        }
    }
    for (int i = temporalMesh.getEdges().size() - 1; i >= 0; --i) {
        Edge edge = temporalMesh.getEdges().get(i);
        if (edge.getFirstIndex() == index || edge.getSecondIndex() == index) {
            temporalMesh.getEdges().remove(i);
        } else {
            edge.shiftIndexes(-1, shiftPredicate);
        }
    }
    for (int i = temporalMesh.getPoints().size() - 1; i >= 0; --i) {
        Point point = temporalMesh.getPoints().get(i);
        if (point.getIndex() == index) {
            temporalMesh.getPoints().remove(i);
        } else {
            point.shiftIndexes(-1, shiftPredicate);
        }
    }
}
Also used : IndexPredicate(com.jme3.scene.plugins.blender.meshes.IndexesLoop.IndexPredicate) Point(com.jme3.scene.plugins.blender.meshes.Point) Face(com.jme3.scene.plugins.blender.meshes.Face) Edge(com.jme3.scene.plugins.blender.meshes.Edge) Point(com.jme3.scene.plugins.blender.meshes.Point)

Example 43 with Point

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

the class Face method contains.

/**
     * The method verifies if the edge is contained within the face.
     * It means it cannot cross any other edge and it must be inside the face and not outside of it.
     * @param edge
     *            the edge to be checked
     * @return <b>true</b> if the given edge is contained within the face and <b>false</b> otherwise
     */
private boolean contains(Edge edge) {
    int index1 = edge.getFirstIndex();
    int index2 = edge.getSecondIndex();
    // check if the line between the vertices is not a border edge of the face
    if (!indexes.areNeighbours(index1, index2)) {
        for (int i = 0; i < indexes.size(); ++i) {
            int i1 = this.getIndex(i - 1);
            int i2 = this.getIndex(i);
            // check if the edges have no common verts (because if they do, they cannot cross)
            if (i1 != index1 && i1 != index2 && i2 != index1 && i2 != index2) {
                if (edge.cross(new Edge(i1, i2, 0, false, temporalMesh))) {
                    return false;
                }
            }
        }
        // computing the edge's middle point
        Vector3f edgeMiddlePoint = edge.computeCentroid();
        // computing the edge that is perpendicular to the given edge and has a length of 1 (length actually does not matter)
        Vector3f edgeVector = edge.getSecondVertex().subtract(edge.getFirstVertex());
        Vector3f edgeNormal = temporalMesh.getNormals().get(index1).cross(edgeVector).normalizeLocal();
        Edge e = new Edge(edgeMiddlePoint, edgeNormal.add(edgeMiddlePoint));
        // compute the vectors from the middle point to the crossing between the extended edge 'e' and other edges of the face
        List<Vector3f> crossingVectors = new ArrayList<Vector3f>();
        for (int i = 0; i < indexes.size(); ++i) {
            int i1 = this.getIndex(i);
            int i2 = this.getIndex(i + 1);
            Vector3f crossPoint = e.getCrossPoint(new Edge(i1, i2, 0, false, temporalMesh), true, false);
            if (crossPoint != null) {
                crossingVectors.add(crossPoint.subtractLocal(edgeMiddlePoint));
            }
        }
        if (crossingVectors.size() == 0) {
            // edges do not cross
            return false;
        }
        // use only distinct vertices (doubles may appear if the crossing point is a vertex)
        List<Vector3f> distinctCrossingVectors = new ArrayList<Vector3f>();
        for (Vector3f cv : crossingVectors) {
            double minDistance = Double.MAX_VALUE;
            for (Vector3f dcv : distinctCrossingVectors) {
                minDistance = Math.min(minDistance, dcv.distance(cv));
            }
            if (minDistance > FastMath.FLT_EPSILON) {
                distinctCrossingVectors.add(cv);
            }
        }
        if (distinctCrossingVectors.size() == 0) {
            throw new IllegalStateException("There MUST be at least 2 crossing vertices!");
        }
        // checking if all crossing vectors point to the same direction (if yes then the edge is outside the face)
        // if at least one vector has different direction that this - it means that the edge is inside the face
        float direction = Math.signum(distinctCrossingVectors.get(0).dot(edgeNormal));
        for (int i = 1; i < distinctCrossingVectors.size(); ++i) {
            if (direction != Math.signum(distinctCrossingVectors.get(i).dot(edgeNormal))) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList)

Example 44 with Point

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

the class SubdivisionSurfaceModifier method computeFaceUVs.

/**
     * The method computes the UV coordinates of the face middle point.
     * @param face
     *            the face of the mesh
     * @return a map whose key is the name of the UV set and value is the UV coordinate of the face's middle point
     */
private Map<String, Vector2f> computeFaceUVs(Face face) {
    Map<String, Vector2f> result = null;
    Map<String, List<Vector2f>> uvSets = face.getUvSets();
    if (uvSets != null && uvSets.size() > 0) {
        result = new HashMap<String, Vector2f>(uvSets.size());
        for (Entry<String, List<Vector2f>> entry : uvSets.entrySet()) {
            Vector2f faceUV = new Vector2f();
            for (Vector2f uv : entry.getValue()) {
                faceUV.addLocal(uv);
            }
            faceUV.divideLocal(entry.getValue().size());
            result.put(entry.getKey(), faceUV);
        }
    }
    return result;
}
Also used : Vector2f(com.jme3.math.Vector2f) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with Point

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

the class BasicShadowRenderer method postQueue.

public void postQueue(RenderQueue rq) {
    for (Spatial scene : viewPort.getScenes()) {
        ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
    }
    // update frustum points based on current camera
    Camera viewCam = viewPort.getCamera();
    ShadowUtil.updateFrustumPoints(viewCam, viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points);
    Vector3f frustaCenter = new Vector3f();
    for (Vector3f point : points) {
        frustaCenter.addLocal(point);
    }
    frustaCenter.multLocal(1f / 8f);
    // update light direction
    shadowCam.setProjectionMatrix(null);
    shadowCam.setParallelProjection(true);
    //        shadowCam.setFrustumPerspective(45, 1, 1, 20);
    shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
    shadowCam.update();
    shadowCam.setLocation(frustaCenter);
    shadowCam.update();
    shadowCam.updateViewProjection();
    // render shadow casters to shadow map
    ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
    if (shadowOccluders.size() == 0) {
        noOccluders = true;
        return;
    } else {
        noOccluders = false;
    }
    Renderer r = renderManager.getRenderer();
    renderManager.setCamera(shadowCam, false);
    renderManager.setForcedMaterial(preshadowMat);
    r.setFrameBuffer(shadowFB);
    r.clearBuffers(true, true, true);
    viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
    r.setFrameBuffer(viewPort.getOutputFrameBuffer());
    renderManager.setForcedMaterial(null);
    renderManager.setCamera(viewCam, false);
}
Also used : Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) Renderer(com.jme3.renderer.Renderer) Camera(com.jme3.renderer.Camera)

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