Package de.venjinx.jme3

Examples of de.venjinx.jme3.VoxelState


        Geometry zAxis;
        Geometry xzGrid;
        Geometry xyGrid;
        Geometry yzGrid;

        ScenegraphNode coordNode = new ScenegraphNode("Coodination Grid");
        ScenegraphNode labelNode = new ScenegraphNode("Grid labels");
        coordNode.attachChild(labelNode);

        // create x-axis
        Arrow arrowX = new Arrow(new Vector3f(size, 0.0f, 0.0f));
        xAxis = new Geometry("X-Axis", arrowX);
        mat = new Material(am, Materials.UNSHADED);
        mat.setColor("Color", ColorRGBA.Red);
        xAxis.setMaterial(mat);

        // create xy-grid
        Grid xyPlane = new Grid(size, size, segSize);
        xyGrid = new Geometry("XY-Plane", xyPlane);
        xyGrid.setMaterial(mat);
        xyGrid.rotateUpTo(new Vector3f(0.0f, 0.0f, 1.0f));
        xyGrid.setLocalTranslation(new Vector3f(-offset, offset, 0.0f));

        // create y-axis
        Arrow arrowY = new Arrow(new Vector3f(0.0f, size, 0.0f));
        yAxis = new Geometry("Y-Axis", arrowY);
        mat = new Material(am, Materials.UNSHADED);
        mat.setColor("Color", ColorRGBA.Green);
        yAxis.setMaterial(mat);

        // create yz-grid
        Grid yzPlane = new Grid(size, size, segSize);
        yzGrid = new Geometry("YZ-Plane", yzPlane);
        yzGrid.setMaterial(mat);
        yzGrid.rotateUpTo(new Vector3f(1.0f, 0.0f, 0.0f));
        yzGrid.setLocalTranslation(new Vector3f(0.0f, offset, -offset));

        // create z-axis
        Arrow arrowZ = new Arrow(new Vector3f(0.0f, 0.0f, size));
        zAxis = new Geometry("Z-Axis", arrowZ);
        mat = new Material(am, Materials.UNSHADED);
        mat.setColor("Color", ColorRGBA.Blue);
        zAxis.setMaterial(mat);

        // create xz-grid
        Grid xzPlane = new Grid(size, size, segSize);
        xzGrid = new Geometry("XZ-Plane", xzPlane);
        xzGrid.setMaterial(mat);
        xzGrid.rotateUpTo(new Vector3f(0.0f, 1.0f, 0.0f));
        xzGrid.setLocalTranslation(new Vector3f(-offset, 0.0f, -offset));

        // attach arrows to coordination node
        coordNode.attachChild(xAxis);
        coordNode.attachChild(yAxis);
        coordNode.attachChild(zAxis);

        // attach grids to coordination node
        coordNode.attachChild(xyGrid);
        coordNode.attachChild(xzGrid);
        coordNode.attachChild(yzGrid);

        Vector3f pos = new Vector3f(0, 0, 0);

        BitmapText vertId = new BitmapText(guiFont);
        vertId.setSize(.1f);
        vertId.setText("x0, y0, z0");
        vertId.setName("Gridlabel - x0, y0, z0");
        vertId.setLocalTranslation(pos);
        vertId.addControl(bc.cloneForSpatial(vertId));
        labelNode.attachChild(vertId);

        for (int x = 1; x < offset; x++) {
            pos.set(x, 0, 0);
            vertId = new BitmapText(guiFont);
            vertId.setSize(.2f);
            vertId.setText("x" + x);
            vertId.setName("Gridlabel - x" + x);
            vertId.setLocalTranslation(pos);
            vertId.addControl(bc.cloneForSpatial(vertId));
            labelNode.attachChild(vertId);
        }
        for (int y = 1; y < offset; y++) {
            pos.set(0, y, 0);
            vertId = new BitmapText(guiFont);
            vertId.setSize(.2f);
            vertId.setText("y" + y);
            vertId.setName("Gridlabel - y" + y);
            vertId.setLocalTranslation(pos);
            vertId.addControl(bc.cloneForSpatial(vertId));
            labelNode.attachChild(vertId);
        }
        for (int z = 1; z < offset; z++) {
            pos.set(0, 0, z);
            vertId = new BitmapText(guiFont);
            vertId.setSize(.2f);
            vertId.setText("z" + z);
            vertId.setName("Gridlabel - z" + z);
            vertId.setLocalTranslation(pos);
            vertId.addControl(bc.cloneForSpatial(vertId));
            labelNode.attachChild(vertId);
        }
        return coordNode;
    }
View Full Code Here


    private BoundingSphere worldBound;
    private ScenegraphNode voxelWorldNode;
    private HashSet<VoxelObjectNode> worldObjects = new HashSet<>();

    public VoxelState() {
        voxelWorldNode = new ScenegraphNode("VoxelWorld");
        world = new VoxelWorld();
    }
View Full Code Here

            } else detachChild(voxelGrid);
        }
    }

    public static ScenegraphNode buildDebugObjects(Geometry refGeom) {
        ScenegraphNode node = new ScenegraphNode("Debug '" + refGeom.getName() + "'");
        ScenegraphNode normals;
        ScenegraphNode tangents;
        ScenegraphNode binormals;
        ScenegraphNode wire;
        ScenegraphNode voxelGrid;

        if ((refGeom != null) && (refGeom.getMesh() != null)) {
            node.attachChild(buildBound(refGeom));

            if (refGeom.getMesh().getBuffer(Type.Position) != null) {
                normals = buildNormals(refGeom);
                normals.setLocalTranslation(refGeom.getLocalTranslation());
                node.attachChild(normals);
            }

            if (refGeom.getMesh().getBuffer(Type.Tangent) != null) {
                tangents = buildTangents(refGeom);
                tangents.setLocalTranslation(refGeom.getLocalTranslation());
                node.attachChild(tangents);
            }

            if (refGeom.getMesh().getBuffer(Type.Binormal) != null) {
                binormals = buildBinormals(refGeom);
                binormals.setLocalTranslation(refGeom.getLocalTranslation());
                node.attachChild(binormals);
            }

            if (refGeom.getMesh().getMode() == Mode.Triangles) {
                wire = buildWireframe(refGeom);
                wire.setLocalTranslation(refGeom.getLocalTranslation());
                node.attachChild(wire);
            }

            if (refGeom.getName().contains("Voxel")) {
                VoxelObjectNode vo;
                Node parent = refGeom.getParent();
                while (!(parent instanceof VoxelObjectNode))
                    parent = parent.getParent();
                vo = (VoxelObjectNode) parent;
                voxelGrid = buildVoxelGrid(vo);
                voxelGrid.setLocalTranslation(vo.getLocalTranslation());
                node.attachChild(voxelGrid);

                vo.showChunkLODs();
                vo.showChunkBounds();
            }
View Full Code Here

    }

    public static ScenegraphNode buildNormals(Geometry refGeom) {
        Geometry g;
        Arrow a;
        ScenegraphNode normals = new ScenegraphNode("Normals");
        Vector3f dir = new Vector3f();

        FloatBuffer nB = refGeom.getMesh().getFloatBuffer(Type.Normal);
        FloatBuffer vB = refGeom.getMesh().getFloatBuffer(Type.Position);

        for (int i = 0; i < nB.limit(); i += 3) {
            dir.set(nB.get(i), nB.get(i + 1), nB.get(i + 2));
            a = new Arrow(dir);
            a.setLineWidth(3f);
            g = new Geometry("Normal" + dir, a);
            g.scale(.1f);
            g.setLocalTranslation(vB.get(i), vB.get(i + 1), vB.get(i + 2));
            g.setMaterial(DebugMaterials.normalMat);
            normals.attachChild(g);
        }

        // GeometryBatchFactory.optimize(normals);
        return normals;
    }
View Full Code Here

    }

    public static ScenegraphNode buildTangents(Geometry refGeom) {
        Geometry g;
        Arrow a;
        ScenegraphNode tangents = new ScenegraphNode("Tangents");
        Vector3f dir = new Vector3f();

        FloatBuffer tB = refGeom.getMesh().getFloatBuffer(Type.Tangent);
        FloatBuffer vB = refGeom.getMesh().getFloatBuffer(Type.Position);

        int posFix = 0;
        for (int i = 0; i < tB.limit(); i += 4) {
            dir.set(tB.get(i), tB.get(i + 1), tB.get(i + 2)).normalizeLocal();
            a = new Arrow(dir);
            a.setLineWidth(2f);
            g = new Geometry("Tangent" + dir, a);
            g.scale(.1f);
            g.setLocalTranslation(vB.get(i - posFix), vB.get((i - posFix) + 1),
                                  vB.get((i - posFix) + 2));
            g.setMaterial(DebugMaterials.tangentMat);
            tangents.attachChild(g);
            posFix++;
        }

        // GeometryBatchFactory.optimize(tangents);
        return tangents;
View Full Code Here

    }

    public static ScenegraphNode buildBinormals(Geometry refGeom) {
        Geometry g;
        Arrow a;
        ScenegraphNode binormals = new ScenegraphNode("Binormals");
        Vector3f dir = new Vector3f();

        FloatBuffer bnB = refGeom.getMesh().getFloatBuffer(Type.Binormal);
        FloatBuffer vB = refGeom.getMesh().getFloatBuffer(Type.Position);

        for (int i = 0; i < bnB.limit(); i += 3) {
            dir.set(bnB.get(i), bnB.get(i + 1), bnB.get(i + 2));
            a = new Arrow(dir);
            g = new Geometry("Binormal" + dir, a);
            g.scale(.1f);
            g.setLocalTranslation(vB.get(i), vB.get(i + 1), vB.get(i + 2));
            g.setMaterial(DebugMaterials.binormalMat);
            binormals.attachChild(g);
        }

        // GeometryBatchFactory.optimize(binormals);
        return binormals;
    }
View Full Code Here

    public static ScenegraphNode buildWireframe(Geometry refGeom) {
        Line line;
        Triangle tri;
        Geometry g;
        ScenegraphNode tris = new ScenegraphNode("Wireframe");
        for (int i = 0; i < refGeom.getMesh().getTriangleCount(); i++) {
            tri = new Triangle();
            refGeom.getMesh().getTriangle(i, tri);

            // bc = new BillboardControl();
            // helloText = new BitmapText(guiFont, false);
            // helloText.setSize(.05f);
            // helloText.setText("tri" + i);
            // helloText.setLocalTranslation(tri.getCenter());
            // helloText.addControl(bc);
            // myApp.getRootNode().attachChild(helloText);

            line = new Line(tri.get1(), tri.get2());
            g = new Geometry("Line" + tri.get1() + "->" + tri.get2(), line);
            g.setMaterial(DebugMaterials.wireMat);
            tris.attachChild(g);

            line = new Line(tri.get2(), tri.get3());
            g = new Geometry("Line" + tri.get2() + "->" + tri.get3(), line);
            g.setMaterial(DebugMaterials.wireMat);
            tris.attachChild(g);

            line = new Line(tri.get3(), tri.get1());
            g = new Geometry("Line" + tri.get3() + "->" + tri.get1(), line);
            g.setMaterial(DebugMaterials.wireMat);
            tris.attachChild(g);
        }
        GeometryBatchFactory.optimize(tris);
        return tris;
    }
View Full Code Here

        }
        return node;
    }

    public static ScenegraphNode buildVoxelGrid(VoxelObjectNode voxelObjectNode) {
        ScenegraphNode voxelGrid =
                new ScenegraphNode("Voxel grid " + voxelObjectNode.getName());
        ScenegraphNode voxelNode = new ScenegraphNode("Voxels");
        ScenegraphNode labelNode = new ScenegraphNode("Voxel labels");
        float[][][] data = voxelObjectNode.getData();

        HashSet<Voxel> voxels = new HashSet<>();

        // for (long quad : geometry.getFaceIDs()) {
        // // tree = new VoxelQuadTree(quad, geometry.getLOD(),
        // // geometry.getZipKey(), geometry.getVoxelData());
        // tree = new VoxelQuadTree(quad, geometry, data);
        // if ((tree.quadCase > 0) && (tree.quadCase < (QuadCases.caseCount() -
        // 1)))
        // buildTreeVoxels(tree, voxels);
        // }

        for (Voxel v : voxels) {
            voxelNode.attachChild(v);
            labelNode.attachChild(v.valueText);
        }
        GeometryBatchFactory.optimize(voxelNode);

        voxelGrid.attachChild(voxelNode);
        voxelGrid.attachChild(labelNode);
View Full Code Here

TOP

Related Classes of de.venjinx.jme3.VoxelState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.