Package org.terasology.rendering.assets.skeletalmesh

Examples of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder


    protected void parseSkeletalMeshData(Element rootElement) throws ColladaParseException {

        List<MD5Joint> md5JointList = new ArrayList<MD5Joint>();
        List<MD5Mesh> md5MeshList = new ArrayList<MD5Mesh>();

        skeletonBuilder = new SkeletalMeshDataBuilder();

        // TODO: we need a better way to construct the parent/child nodes, especially for the non-joint nodes
        // MAYBE we can construct all of the nodes up-front, and then fill in the missing data for the ones of type JOINT later
        // And only keep the MD5 nodes in the final list if they are used?
View Full Code Here


    @Override
    public SkeletalMeshData load(Module module, InputStream stream, List<URL> urls, List<URL> deltas) throws IOException {
        try {
            MD5 md5 = parse(stream);
            SkeletalMeshDataBuilder skeletonBuilder = new SkeletalMeshDataBuilder();
            List<Bone> bones = Lists.newArrayListWithCapacity(md5.numJoints);
            for (int i = 0; i < md5.numJoints; ++i) {
                MD5Joint joint = md5.joints[i];
                Bone bone = new Bone(i, joint.name, joint.position, joint.orientation);
                bones.add(bone);
                if (joint.parent != -1) {
                    bones.get(joint.parent).addChild(bone);
                }
                skeletonBuilder.addBone(bone);
            }
            if (md5.meshes.length > 0) {
                // TODO: Support multiple mesh somehow?
                MD5Mesh mesh = md5.meshes[0];
                for (MD5Weight weight : mesh.weightList) {
                    skeletonBuilder.addWeight(new BoneWeight(weight.position, weight.bias, weight.jointIndex));
                }

                List<Vector2f> uvs = Lists.newArrayList();
                TIntList vertexStartWeight = new TIntArrayList(mesh.numVertices);
                TIntList vertexWeightCount = new TIntArrayList(mesh.numVertices);
                for (MD5Vertex vert : mesh.vertexList) {
                    uvs.add(vert.uv);
                    vertexStartWeight.add(vert.startWeight);
                    vertexWeightCount.add(vert.countWeight);
                }
                skeletonBuilder.setVertexWeights(vertexStartWeight, vertexWeightCount);
                skeletonBuilder.setUvs(uvs);
                TIntList indices = new TIntArrayList(mesh.indexList.length);
                for (int i = 0; i < mesh.numTriangles; ++i) {
                    indices.add(mesh.indexList[i * 3]);
                    indices.add(mesh.indexList[i * 3 + 2]);
                    indices.add(mesh.indexList[i * 3 + 1]);
                }
                skeletonBuilder.setIndices(indices);
            }

            return skeletonBuilder.build();
        } catch (NumberFormatException e) {
            throw new IOException("Error parsing " + module.toString(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder

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.