Examples of SkinnedMesh


Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            public void actionPerformed(final ActionEvent event) {
                _root.acceptVisitor(new Visitor() {
                    @Override
                    public void visit(final Spatial spatial) {
                        if (spatial instanceof SkinnedMesh) {
                            final SkinnedMesh skinnedSpatial = (SkinnedMesh) spatial;
                            if (gpuSkinningCheck.isSelected()) {
                                skinnedSpatial.setGPUShader(gpuShader);
                                skinnedSpatial.setUseGPU(true);
                            } else {
                                skinnedSpatial.setGPUShader(null);
                                skinnedSpatial.clearRenderState(StateType.GLSLShader);
                                skinnedSpatial.setUseGPU(false);
                            }
                        }
                    }
                }, true);
            }
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            // OPTIMIZATION: turn on the buffers in our skeleton so they can be shared. (reuse ids)
            primeModel.acceptVisitor(new Visitor() {
                @Override
                public void visit(final Spatial spatial) {
                    if (spatial instanceof SkinnedMesh) {
                        final SkinnedMesh skinnedSpatial = (SkinnedMesh) spatial;
                        skinnedSpatial.recreateWeightAttributeBuffer();
                        skinnedSpatial.recreateJointAttributeBuffer();
                    }
                }
            }, true);

            // OPTIMIZATION: run nv strippifyier on model...
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            public void actionPerformed(final ActionEvent event) {
                _root.acceptVisitor(new Visitor() {
                    @Override
                    public void visit(final Spatial spatial) {
                        if (spatial instanceof SkinnedMesh) {
                            final SkinnedMesh skinnedSpatial = (SkinnedMesh) spatial;
                            if (gpuSkinningCheck.isSelected()) {
                                skinnedSpatial.setGPUShader(gpuShader);
                                skinnedSpatial.setUseGPU(true);
                            } else {
                                skinnedSpatial.setGPUShader(null);
                                skinnedSpatial.clearRenderState(StateType.GLSLShader);
                                skinnedSpatial.setUseGPU(false);
                            }
                        }
                    }
                }, true);
            }
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            // OPTIMIZATION: turn on the buffers in our skeleton so they can be shared. (reuse ids)
            primeModel.acceptVisitor(new Visitor() {
                @Override
                public void visit(final Spatial spatial) {
                    if (spatial instanceof SkinnedMesh) {
                        final SkinnedMesh skinnedSpatial = (SkinnedMesh) spatial;
                        skinnedSpatial.recreateWeightAttributeBuffer();
                        skinnedSpatial.recreateJointAttributeBuffer();
                    }
                }
            }, true);

            // OPTIMIZATION: run nv strippifyier on model...
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            gpuShader.setUniform("specularMap", 2);

            colladaNode.acceptVisitor(new Visitor() {
                public void visit(final Spatial spatial) {
                    if (spatial instanceof SkinnedMesh) {
                        final SkinnedMesh skinnedMesh = (SkinnedMesh) spatial;
                        skinnedMesh.setGPUShader(gpuShader);

                        final TextureState ts = (TextureState) skinnedMesh
                                .getLocalRenderState(RenderState.StateType.Texture);
                        if (ts != null) {
                            ts.setTexture(t, 1);
                            ts.setTexture(specular, 2);
                            skinnedMesh.setRenderState(ts);
                        }

                        final MaterialState ms = new MaterialState();
                        ms.setAmbient(MaterialState.MaterialFace.FrontAndBack, ColorRGBA.WHITE);
                        ms.setDiffuse(MaterialState.MaterialFace.FrontAndBack, ColorRGBA.WHITE);
                        ms.setSpecular(MaterialState.MaterialFace.FrontAndBack, ColorRGBA.WHITE);
                        ms.setShininess(32);
                        skinnedMesh.setRenderState(ms);

                        skinnedMesh.setGpuAttributeSize(3);
                        skinnedMesh.setGpuUseMatrixAttribute(true);
                        skinnedMesh.setUseGPU(true);
                    }
                }
            }, false);
        } catch (final IOException ioe) {
            ioe.printStackTrace();
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

        pose1 = new SkeletonPose(sk);
        pose1.updateTransforms();
        pose2 = new SkeletonPose(sk);
        pose2.updateTransforms();

        arm = new SkinnedMesh("arm");
        final Cylinder cy = new Cylinder("cylinder", 3, 8, 1, 10);
        arm.setBindPoseData(cy.getMeshData());
        arm.getMeshData().setVertexBuffer(BufferUtils.createFloatBuffer(cy.getMeshData().getVertexBuffer().capacity()));
        arm.getMeshData().setNormalBuffer(BufferUtils.createFloatBuffer(cy.getMeshData().getNormalBuffer().capacity()));
        arm.getMeshData().setIndices(BufferUtils.clone(cy.getMeshData().getIndices()));
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

        light.setAmbient(new ColorRGBA(0.25f, 0.25f, 0.25f, 1.0f));
        light.setDirection(new Vector3(-1, -1, -1).normalizeLocal());
        light.setEnabled(true);
        _lightState.attach(light);

        final SkinnedMesh skeleton = loadMainSkeleton();

        // Load collada model
        for (int i = 0; i < 10; i++) {
            final SkinnedMesh copy = skeleton.makeCopy(true);
            copy.setCurrentPose(skeleton.getCurrentPose().makeCopy());
            copy.setTranslation(((i % 5) - 2) * 60, 0, ((i / 5) * 40) - 320);
            _root.attachChild(copy);
            final AnimationManager manager = createAnimationManager(copy.getCurrentPose());
            managers.add(manager);
            animInfo.add(new AnimationInfo());
            poseToMesh.put(copy.getCurrentPose(), copy);
        }
    }
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            poseToMesh.put(copy.getCurrentPose(), copy);
        }
    }

    private SkinnedMesh loadMainSkeleton() {
        SkinnedMesh skeleton = null;
        try {
            final long time = System.currentTimeMillis();
            final ColladaImporter colladaImporter = new ColladaImporter();

            // OPTIMIZATION: run GeometryTool on collada meshes to reduce redundant vertices...
            colladaImporter.setOptimizeMeshes(true);

            // Load the collada scene
            final String mainFile = "collada/skeleton/skeleton.walk.dae";
            final ColladaStorage storage = colladaImporter.load(mainFile);
            final Node colladaNode = storage.getScene();

            System.out.println("Importing: " + mainFile);
            System.out.println("Took " + (System.currentTimeMillis() - time) + " ms");

            final GLSLShaderObjectsState gpuShader = new GLSLShaderObjectsState();
            gpuShader.setEnabled(true);
            try {
                gpuShader.setVertexShader(ResourceLocatorTool.getClassPathResourceAsStream(AnimationDemoExample.class,
                        "com/ardor3d/extension/animation/skeletal/skinning_gpu_texture.vert"));
                gpuShader.setFragmentShader(ResourceLocatorTool.getClassPathResourceAsStream(
                        AnimationDemoExample.class,
                        "com/ardor3d/extension/animation/skeletal/skinning_gpu_texture.frag"));

                gpuShader.setUniform("texture", 0);
                gpuShader.setUniform("lightDirection", new Vector3(1, 1, 1).normalizeLocal());
            } catch (final IOException ioe) {
                ioe.printStackTrace();
            }

            // OPTIMIZATION: SkinnedMesh combining... Useful in our case because the skeleton model is composed of 2
            // separate meshes.
            skeleton = (SkinnedMesh) MeshCombiner.combine(colladaNode, new SkinnedMeshCombineLogic());
            // Non-combined:
            // primeModel = colladaNode;

            // OPTIMIZATION: turn on the buffers in our skeleton so they can be shared. (reuse ids)
            skeleton.acceptVisitor(new Visitor() {
                @Override
                public void visit(final Spatial spatial) {
                    if (spatial instanceof SkinnedMesh) {
                        final SkinnedMesh skinnedSpatial = (SkinnedMesh) spatial;
                        skinnedSpatial.recreateWeightAttributeBuffer();
                        skinnedSpatial.recreateJointAttributeBuffer();
                    }
                }
            }, true);

            // OPTIMIZATION: run nv strippifyier on model...
View Full Code Here

Examples of com.ardor3d.extension.animation.skeletal.SkinnedMesh

            // 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);
                            if (bindPose.getNormalBuffer() != null) {
                                bindPose.transformNormals(bindShapeMatrix, true);
                            }
                        }

                        // TODO: This is only needed for CPU skinning... consider a way of making it optional.
                        // Copy bind pose to mesh data to setup for CPU skinning
                        final MeshData meshData = copyMeshData(skMesh.getBindPoseData());
                        meshData.getVertexCoords().setVboAccessMode(VBOAccessMode.StreamDraw);
                        if (meshData.getNormalCoords() != null) {
                            meshData.getNormalCoords().setVboAccessMode(VBOAccessMode.StreamDraw);
                        }
                        skMesh.setMeshData(meshData);
                    } catch (final IOException e) {
                        e.printStackTrace();
                        throw new ColladaException("Unable to copy skeleton bind pose data.", geometry);
                    }

                    // Grab the MeshVertPairs from Global for this mesh.
                    final Collection<MeshVertPairs> vertPairsList = _dataCache.getVertMappings().get(geometry);
                    MeshVertPairs pairsMap = null;
                    if (vertPairsList != null) {
                        for (final MeshVertPairs pairs : vertPairsList) {
                            if (pairs.getMesh() == sourceMesh) {
                                pairsMap = pairs;
                                break;
                            }
                        }
                    }

                    if (pairsMap == null) {
                        throw new ColladaException("Unable to locate pair map for geometry.", geometry);
                    }

                    // Check for a remapping, if we optimized geometry
                    final VertMap vertMap = _dataCache.getMeshVertMap().get(sourceMesh);

                    // Use pairs map and vertWeightMap to build our weights and joint indices.
                    {
                        // count number of weights used
                        int maxWeightsPerVert = 0;
                        int weightCount;
                        for (final int originalIndex : pairsMap.getIndices()) {
                            weightCount = 0;

                            // get weights and joints at original index and add weights up to get divisor sum
                            // we'll assume 0's for vertices with no matching weight.
                            if (vertWeightMap.length > originalIndex) {
                                final int[] data = vertWeightMap[originalIndex];
                                for (int i = 0; i < data.length; i += maxOffset + 1) {
                                    final float weight = jointWeights.get(data[i + weightOff]);
                                    if (weight != 0) {
                                        weightCount++;
                                    }
                                }
                                if (weightCount > maxWeightsPerVert) {
                                    maxWeightsPerVert = weightCount;
                                }
                            }
                        }

                        final int verts = skMesh.getMeshData().getVertexCount();
                        final FloatBuffer weightBuffer = BufferUtils.createFloatBuffer(verts * maxWeightsPerVert);
                        final ShortBuffer jointIndexBuffer = BufferUtils.createShortBuffer(verts * maxWeightsPerVert);
                        int j;
                        float sum = 0;
                        final float[] weights = new float[maxWeightsPerVert];
                        final short[] indices = new short[maxWeightsPerVert];
                        int originalIndex;
                        for (int x = 0; x < verts; x++) {
                            if (vertMap != null) {
                                originalIndex = pairsMap.getIndices()[vertMap.getFirstOldIndex(x)];
                            } else {
                                originalIndex = pairsMap.getIndices()[x];
                            }

                            j = 0;
                            sum = 0;

                            // get weights and joints at original index and add weights up to get divisor sum
                            // we'll assume 0's for vertices with no matching weight.
                            if (vertWeightMap.length > originalIndex) {
                                final int[] data = vertWeightMap[originalIndex];
                                for (int i = 0; i < data.length; i += maxOffset + 1) {
                                    final float weight = jointWeights.get(data[i + weightOff]);
                                    if (weight != 0) {
                                        weights[j] = jointWeights.get(data[i + weightOff]);
                                        indices[j] = (short) order[jointIndices.get(data[i + indOff])];
                                        sum += weights[j++];
                                    }
                                }
                            }
                            // add extra padding as needed
                            while (j < maxWeightsPerVert) {
                                weights[j] = 0;
                                indices[j++] = 0;
                            }
                            // add weights to weightBuffer / sum
                            for (final float w : weights) {
                                weightBuffer.put(sum != 0 ? w / sum : 0);
                            }
                            // add joint indices to jointIndexBuffer
                            jointIndexBuffer.put(indices);
                        }

                        final float[] totalWeights = new float[weightBuffer.capacity()];
                        weightBuffer.flip();
                        weightBuffer.get(totalWeights);
                        skMesh.setWeights(totalWeights);

                        final short[] totalIndices = new short[jointIndexBuffer.capacity()];
                        jointIndexBuffer.flip();
                        jointIndexBuffer.get(totalIndices);
                        skMesh.setJointIndices(totalIndices);

                        skMesh.setWeightsPerVert(maxWeightsPerVert);
                    }

                    // add to the skinNode.
                    skinNode.attachChild(skMesh);

                    // Manually apply our bind pose to the skin mesh.
                    skMesh.applyPose();

                    // Update the model bounding.
                    skMesh.updateModelBound();

                    // add mesh to store
                    skinDataStore.getSkins().add(skMesh);
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.