Package com.ardor3d.scenegraph

Examples of com.ardor3d.scenegraph.Mesh


        box.setRandomColors();

        final Random rand = new Random(1337);
        for (int x = 0; x < 8; x++) {
            for (int y = 0; y < 8; y++) {
                final Mesh sm = box.makeCopy(true);

                sm.setTranslation(500 + rand.nextDouble() * 300 - 150, 20 + rand.nextDouble() * 5.0,
                        500 + rand.nextDouble() * 300 - 150);
                occluders.attachChild(sm);
            }
        }

View Full Code Here


        _camera.setEyeSeparation(_camera.getFocalDistance() / 30.0);
        _camera.setAperture(45.0 * MathUtils.DEG_TO_RAD);
        _camera.setSideBySideMode(_sideBySide);
        _camera.setupLeftRightCameras();

        final Mesh tp = new Teapot("Teapot");
        tp.setModelBound(new BoundingBox());
        tp.setTranslation(new Vector3(0, 0, -50));
        tp.setScale(2);
        _root.attachChild(tp);

        final Mesh torus = new Torus("Torus", 16, 16, 1, 4);
        torus.setModelBound(new BoundingBox());
        torus.setTranslation(new Vector3(4, 0, -10));
        _root.attachChild(torus);

        final Mesh sphere = new Sphere("Sphere", 16, 16, 5);
        sphere.setModelBound(new BoundingBox());
        sphere.setTranslation(new Vector3(-8, 0, -30));
        _root.attachChild(sphere);

        final Box box = new Box("Box", new Vector3(), 50, 1, 50);
        box.setModelBound(new BoundingBox());
        box.setTranslation(new Vector3(0, -1, -25));
View Full Code Here

        }));

        // Combine into one mesh
        _logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.G), new TriggerAction() {
            public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
                final Mesh merged = MeshCombiner.combine(boxNode);
                boxNode.detachAllChildren();
                boxNode.attachChild(merged);
            }
        }));
View Full Code Here

            str.append(spatial.getName());
            str.append(" - ");
            str.append(spatial.getClass().getName()).append('\n');

            if (spatial instanceof Mesh) {
                final Mesh mesh = (Mesh) spatial;
                str.append("Primitives: ");
                str.append(mesh.getMeshData().getTotalPrimitiveCount()).append('\n');
                str.append("Index mode: ");
                str.append(mesh.getMeshData().getIndexMode(0)).append('\n');
            }

            str.append(spatial.getTransform()).append('\n');
            if (spatial.getWorldBound() != null) {
                str.append(spatial.getWorldBound()).append('\n');
View Full Code Here

        final Teapot teapot = new Teapot();
        teapot.setScale(20);
        teapot.updateModelBound();
        teapot.setRandomColors();

        final Mesh multiStrip = createMultiStrip();
        multiStrip.updateModelBound();
        multiStrip.setTranslation(0, 0, -30);

        originalNode = new Node("originalNode");
        originalNode.attachChild(torus);
        originalNode.attachChild(quad);
        originalNode.attachChild(multiStrip);
View Full Code Here

            logger.log(Level.SEVERE, "XMLImporter failed to load file", e);
        }
    }

    private Mesh createMultiStrip() {
        final Mesh mesh = new Mesh();
        final MeshData meshData = mesh.getMeshData();

        final FloatBuffer vertexBuffer = BufferUtils.createVector3Buffer(16);

        vertexBuffer.put(-30).put(0).put(0);
        vertexBuffer.put(-40).put(0).put(0);
        vertexBuffer.put(-40).put(10).put(0);
        vertexBuffer.put(-30).put(10).put(0);

        vertexBuffer.put(-10).put(0).put(0);
        vertexBuffer.put(-20).put(0).put(0);
        vertexBuffer.put(-20).put(10).put(0);
        vertexBuffer.put(-10).put(10).put(0);

        vertexBuffer.put(10).put(0).put(0);
        vertexBuffer.put(20).put(0).put(0);
        vertexBuffer.put(20).put(10).put(0);
        vertexBuffer.put(10).put(10).put(0);

        vertexBuffer.put(30).put(0).put(0);
        vertexBuffer.put(40).put(0).put(0);
        vertexBuffer.put(40).put(10).put(0);
        vertexBuffer.put(30).put(10).put(0);

        meshData.setVertexBuffer(vertexBuffer);

        final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(18, vertexBuffer.capacity() - 1);

        // Strips
        indices.put(0).put(3).put(1).put(2);
        indices.put(4).put(7).put(5).put(6);

        // Quad
        indices.put(8).put(9).put(10).put(11);

        // Triangles
        indices.put(12).put(13).put(15);
        indices.put(13).put(15).put(14);

        meshData.setIndices(indices);

        // Setting sub primitive data
        final int[] indexLengths = new int[] { 4, 4, 4, 6 };
        meshData.setIndexLengths(indexLengths);

        final IndexMode[] indexModes = new IndexMode[] { IndexMode.TriangleStrip, IndexMode.TriangleStrip,
                IndexMode.Quads, IndexMode.Triangles };
        meshData.setIndexModes(indexModes);

        final WireframeState ws = new WireframeState();
        mesh.setRenderState(ws);
        mesh.updateModelBound();

        return mesh;
    }
View Full Code Here

            }

            // Visit our Node and pull out any Mesh children. Turn them into SkinnedMeshes
            for (final Spatial spat : meshNode.getChildren()) {
                if (spat instanceof Mesh && ((Mesh) spat).getMeshData().getVertexCount() > 0) {
                    final Mesh sourceMesh = (Mesh) spat;
                    final SkinnedMesh skMesh = new SkinnedMesh(sourceMesh.getName());
                    skMesh.setCurrentPose(skPose);

                    // copy material info mapping for later use
                    final String material = _dataCache.getMeshMaterialMap().get(sourceMesh);
                    _dataCache.getMeshMaterialMap().put(skMesh, material);

                    // copy mesh render states across.
                    copyRenderStates(sourceMesh, skMesh);

                    // copy hints across
                    skMesh.getSceneHints().set(sourceMesh.getSceneHints());

                    try {
                        // Use source mesh as bind pose data in the new SkinnedMesh
                        final MeshData bindPose = copyMeshData(sourceMesh.getMeshData());
                        skMesh.setBindPoseData(bindPose);

                        // Apply our BSM
                        if (!bindShapeMatrix.isIdentity()) {
                            bindPose.transformVertices(bindShapeMatrix);
View Full Code Here

            // Grab all mesh types (polygons, triangles, etc.)
            // Create each as an Ardor3D Mesh, and attach to node
            boolean hasChild = false;
            if (cMesh.getChild("polygons") != null) {
                for (final Element p : cMesh.getChildren("polygons")) {
                    final Mesh child = buildMeshPolygons(colladaGeometry, p);
                    if (child != null) {
                        if (child.getName() == null) {
                            child.setName(meshNode.getName() + "_polygons");
                        }
                        meshNode.attachChild(child);
                        hasChild = true;
                    }
                }
            }
            if (cMesh.getChild("polylist") != null) {
                for (final Element p : cMesh.getChildren("polylist")) {
                    final Mesh child = buildMeshPolylist(colladaGeometry, p);
                    if (child != null) {
                        if (child.getName() == null) {
                            child.setName(meshNode.getName() + "_polylist");
                        }
                        meshNode.attachChild(child);
                        hasChild = true;
                    }
                }
            }
            if (cMesh.getChild("triangles") != null) {
                for (final Element t : cMesh.getChildren("triangles")) {
                    final Mesh child = buildMeshTriangles(colladaGeometry, t);
                    if (child != null) {
                        if (child.getName() == null) {
                            child.setName(meshNode.getName() + "_triangles");
                        }
                        meshNode.attachChild(child);
                        hasChild = true;
                    }
                }
            }
            if (cMesh.getChild("lines") != null) {
                for (final Element l : cMesh.getChildren("lines")) {
                    final Line child = buildMeshLines(colladaGeometry, l);
                    if (child != null) {
                        if (child.getName() == null) {
                            child.setName(meshNode.getName() + "_lines");
                        }
                        meshNode.attachChild(child);
                        hasChild = true;
                    }
                }
View Full Code Here

    @SuppressWarnings("unchecked")
    public Mesh buildMeshPolygons(final Element colladaGeometry, final Element polys) {
        if (polys == null || polys.getChild("input") == null) {
            return null;
        }
        final Mesh polyMesh = new Mesh(extractName(colladaGeometry, polys));
        polyMesh.getMeshData().setIndexMode(IndexMode.Triangles);

        // Build and set RenderStates for our material
        _colladaMaterialUtils.applyMaterial(polys.getAttributeValue("material"), polyMesh);

        final LinkedList<ColladaInputPipe> pipes = new LinkedList<ColladaInputPipe>();
        final int maxOffset = extractPipes(polys, pipes);
        final int interval = maxOffset + 1;

        // use interval & sum of sizes of p entries to determine buffer sizes.
        int numEntries = 0;
        int numIndices = 0;
        for (final Element vals : polys.getChildren("p")) {
            final int length = _colladaDOMUtil.parseIntArray(vals).length;
            numEntries += length;
            numIndices += (length / interval - 2) * 3;
        }
        numEntries /= interval;

        // Construct nio buffers for specified inputs.
        for (final ColladaInputPipe pipe : pipes) {
            pipe.setupBuffer(numEntries, polyMesh.getMeshData(), _dataCache);
        }

        // Add to vert mapping
        final int[] indices = new int[numEntries];
        final MeshVertPairs mvp = new MeshVertPairs(polyMesh, indices);
        _dataCache.getVertMappings().put(colladaGeometry, mvp);

        // Prepare indices buffer
        final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, polyMesh.getMeshData()
                .getVertexCount() - 1);
        polyMesh.getMeshData().setIndices(meshIndices);

        // go through the polygon entries
        int firstIndex = 0, vecIndex;
        final int[] currentVal = new int[interval];
        for (final Element dia : polys.getChildren("p")) {
            // for each p, iterate using max offset
            final int[] vals = _colladaDOMUtil.parseIntArray(dia);

            final int first = firstIndex + 0;
            System.arraycopy(vals, 0, currentVal, 0, interval);
            vecIndex = processPipes(pipes, currentVal);
            if (vecIndex != Integer.MIN_VALUE) {
                indices[firstIndex + 0] = vecIndex;
            }

            int prev = firstIndex + 1;
            System.arraycopy(vals, interval, currentVal, 0, interval);
            vecIndex = processPipes(pipes, currentVal);
            if (vecIndex != Integer.MIN_VALUE) {
                indices[firstIndex + 1] = vecIndex;
            }

            // first add the first two entries to the buffers.

            // Now go through remaining entries and create a polygon as a triangle fan.
            for (int j = 2, max = vals.length / interval; j < max; j++) {
                // add first as index
                meshIndices.put(first);
                // add prev as index
                meshIndices.put(prev);

                // set prev to current
                prev = firstIndex + j;
                // add current to buffers
                System.arraycopy(vals, j * interval, currentVal, 0, interval);
                vecIndex = processPipes(pipes, currentVal);
                if (vecIndex != Integer.MIN_VALUE) {
                    indices[firstIndex + j] = vecIndex;
                }
                // add current as index
                meshIndices.put(prev);
            }
            firstIndex += vals.length / interval;
        }

        if (_optimizeMeshes) {
            final VertMap map = GeometryTool.minimizeVerts(polyMesh, _optimizeSettings);
            _dataCache.setMeshVertMap(polyMesh, map);
        }

        // update bounds
        polyMesh.updateModelBound();

        // return
        return polyMesh;
    }
View Full Code Here

    public Mesh buildMeshPolylist(final Element colladaGeometry, final Element polys) {
        if (polys == null || polys.getChild("input") == null) {
            return null;
        }
        final Mesh polyMesh = new Mesh(extractName(colladaGeometry, polys));
        polyMesh.getMeshData().setIndexMode(IndexMode.Triangles);

        // Build and set RenderStates for our material
        _colladaMaterialUtils.applyMaterial(polys.getAttributeValue("material"), polyMesh);

        final LinkedList<ColladaInputPipe> pipes = new LinkedList<ColladaInputPipe>();
        final int maxOffset = extractPipes(polys, pipes);
        final int interval = maxOffset + 1;

        // use interval & sum of sizes of vcount to determine buffer sizes.
        int numEntries = 0;
        int numIndices = 0;
        for (final int length : _colladaDOMUtil.parseIntArray(polys.getChild("vcount"))) {
            numEntries += length;
            numIndices += (length - 2) * 3;
        }

        // Construct nio buffers for specified inputs.
        for (final ColladaInputPipe pipe : pipes) {
            pipe.setupBuffer(numEntries, polyMesh.getMeshData(), _dataCache);
        }

        // Add to vert mapping
        final int[] indices = new int[numEntries];
        final MeshVertPairs mvp = new MeshVertPairs(polyMesh, indices);
        _dataCache.getVertMappings().put(colladaGeometry, mvp);

        // Prepare indices buffer
        final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, polyMesh.getMeshData()
                .getVertexCount() - 1);
        polyMesh.getMeshData().setIndices(meshIndices);

        // go through the polygon entries
        int firstIndex = 0;
        int vecIndex;
        final int[] vals = _colladaDOMUtil.parseIntArray(polys.getChild("p"));
        for (final int length : _colladaDOMUtil.parseIntArray(polys.getChild("vcount"))) {
            final int[] currentVal = new int[interval];

            // first add the first two entries to the buffers.
            final int first = firstIndex + 0;
            System.arraycopy(vals, (first * interval), currentVal, 0, interval);
            vecIndex = processPipes(pipes, currentVal);
            if (vecIndex != Integer.MIN_VALUE) {
                indices[firstIndex + 0] = vecIndex;
            }

            int prev = firstIndex + 1;
            System.arraycopy(vals, (prev * interval), currentVal, 0, interval);
            vecIndex = processPipes(pipes, currentVal);
            if (vecIndex != Integer.MIN_VALUE) {
                indices[firstIndex + 1] = vecIndex;
            }

            // Now go through remaining entries and create a polygon as a triangle fan.
            for (int j = 2, max = length; j < max; j++) {
                // add first as index
                meshIndices.put(first);
                // add prev as index
                meshIndices.put(prev);

                // set prev to current
                prev = firstIndex + j;
                // add current to buffers
                System.arraycopy(vals, (prev * interval), currentVal, 0, interval);
                vecIndex = processPipes(pipes, currentVal);
                if (vecIndex != Integer.MIN_VALUE) {
                    indices[firstIndex + j] = vecIndex;
                }
                // add current as index
                meshIndices.put(prev);
            }
            firstIndex += length;
        }

        if (_optimizeMeshes) {
            final VertMap map = GeometryTool.minimizeVerts(polyMesh, _optimizeSettings);
            _dataCache.setMeshVertMap(polyMesh, map);
        }

        // update bounds
        polyMesh.updateModelBound();

        // return
        return polyMesh;
    }
View Full Code Here

TOP

Related Classes of com.ardor3d.scenegraph.Mesh

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.