Search in sources :

Example 1 with SkeletalMeshData

use of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData in project Terasology by MovingBlocks.

the class ColladaLoader method parseSkeletalMeshData.

protected void parseSkeletalMeshData(Element rootElement) throws ColladaParseException {
    List<MD5Joint> md5JointList = new ArrayList<>();
    List<MD5Mesh> md5MeshList = new ArrayList<>();
    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?
    Map<String, MD5Joint> md5JointBySidMap = new HashMap<>();
    MD5Joint parentMD5Joint = null;
    ElementSet nodeParentSet = rootElement.find("library_visual_scenes", "visual_scene", "node");
    for (Element element : nodeParentSet) {
        createMd5JointForElementAndParent(md5JointBySidMap, element, parentMD5Joint);
    }
    ElementSet controllerSet = rootElement.find("library_controllers", "controller");
    for (Element controller : controllerSet) {
        ElementSet skinSet = controller.find("skin");
        if (1 != skinSet.size()) {
            throw new ColladaParseException("Found " + skinSet.size() + " skin sets for controller id=" + controller.id() + " name=" + controller.name());
        }
        Element skin = skinSet.first();
        ElementSet jointsSet = skin.find("joints");
        if (1 != jointsSet.size()) {
            throw new ColladaParseException("Found " + jointsSet.size() + " joints sets for controller id=" + controller.id() + " name=" + controller.name());
        }
        Element joints = jointsSet.first();
        ElementSet vertexWeightsSet = skin.find("vertex_weights");
        if (1 != vertexWeightsSet.size()) {
            throw new ColladaParseException("Found " + vertexWeightsSet.size() + " vertex weights sets for controller id=" + controller.id() + " name=" + controller.name());
        }
        Element vertexWeights = vertexWeightsSet.first();
        String vertexWeightsCountString = vertexWeights.attr("count");
        int vertexWeightsCount = Integer.parseInt(vertexWeightsCountString);
        String[] jointNameArray = null;
        float[] inverseBindMatrixArray;
        Quat4f[] rotationArray;
        ElementSet jointsInputSet = joints.find("input");
        List<Input> inputList = parseInputs(jointsInputSet);
        for (Input jointsInput : inputList) {
            if ("JOINT".equals(jointsInput.semantic)) {
                Element jointNameSourceElement = skin.select(jointsInput.sourceName);
                Source jointNameSource = parseSource(jointNameSourceElement);
                jointNameArray = jointNameSource.nameValues;
            }
            if ("INV_BIND_MATRIX".equals(jointsInput.semantic)) {
                Element jointMatrixSourceElement = skin.select(jointsInput.sourceName);
                Source jointMatrixSource = parseSource(jointMatrixSourceElement);
                inverseBindMatrixArray = jointMatrixSource.floatValues;
                rotationArray = quad4fArrayFromFloat16ArrayData(inverseBindMatrixArray);
            }
        }
        List<MD5Weight> md5WeightList = Lists.newArrayList();
        float[] weightsArray = null;
        ElementSet vertexWeightsInputSet = vertexWeights.find("input");
        List<Input> vertexWeightsInputList = parseInputs(vertexWeightsInputSet);
        // TODO: for now, assume the offsets will always perfectly match the sorted-by-offset list indexes
        Collections.sort(vertexWeightsInputList, (i1, i2) -> i1.offset - i2.offset);
        for (int i = 0; i < vertexWeightsInputList.size(); i++) {
            Input input = vertexWeightsInputList.get(i);
            if (input.offset != i) {
                throw new ColladaParseException("vertex weights input list offset does not match list index for vertex weights input " + input + " for controller id=" + controller.id() + " name=" + controller.name());
            }
        }
        for (Input vertexWeightsInput : vertexWeightsInputList) {
            // }
            if ("WEIGHT".equals(vertexWeightsInput.semantic)) {
                Element jointMatrixSourceElement = skin.select(vertexWeightsInput.sourceName);
                Source weightsArraySource = parseSource(jointMatrixSourceElement);
                weightsArray = weightsArraySource.floatValues;
            }
        }
        ElementSet vertexWeightsVCountDataSet = vertexWeights.find("vcount");
        if (1 != vertexWeightsVCountDataSet.size()) {
            throw new ColladaParseException("Found " + vertexWeightsVCountDataSet.size() + " vertex weights vcount sets for controller id=" + controller.id() + " name=" + controller.name());
        }
        Element vertexWeightsVCountData = vertexWeightsVCountDataSet.first();
        String vertexWeightsVCountString = vertexWeightsVCountData.text();
        String[] vertexWeightsVCountStrings = getItemsInString(vertexWeightsVCountString);
        if (vertexWeightsVCountStrings.length != vertexWeightsCount) {
            throw new ColladaParseException("Expected " + vertexWeightsCount + " but was " + vertexWeightsVCountStrings.length + " for controller id=" + controller.id() + " name=" + controller.name());
        }
        ElementSet vertexWeightsVDataSet = vertexWeights.find("v");
        if (1 != vertexWeightsVDataSet.size()) {
            throw new ColladaParseException("Found " + vertexWeightsVDataSet.size() + " vertex weights v sets for controller id=" + controller.id() + " name=" + controller.name());
        }
        Element vertexWeightsVData = vertexWeightsVDataSet.first();
        String vertexWeightsVDataString = vertexWeightsVData.text();
        String[] vertexWeightsVStrings = getItemsInString(vertexWeightsVDataString);
        // if (vertexWeightsVStrings.length != (vertexWeightsCount * vertexWeightsInputList.size())) {
        // throw new ColladaParseException("Expected " + vertexWeightsCount + " * input count of "
        // + vertexWeightsInputList.size() + " but was "
        // + vertexWeightsVStrings.length + " for controller id=" + controller.id() + " name=" + controller.name());
        // }
        // TODO: these aren't actually needed once we are populating MD5Weight records
        String[] vertexWeightsJointNameArray = new String[vertexWeightsCount];
        float[] vertexWeightsArray = new float[vertexWeightsCount];
        int vertexWeightsVDataIndex = -1;
        for (int vertexWeightsIndex = 0; vertexWeightsIndex < vertexWeightsCount; vertexWeightsIndex++) {
            MD5Weight md5Weight = new MD5Weight();
            Vector3f vertexPosition = new Vector3f();
            vertexPosition.x = vertices.get(3 * vertexWeightsIndex + 0);
            vertexPosition.y = vertices.get(3 * vertexWeightsIndex + 1);
            vertexPosition.z = vertices.get(3 * vertexWeightsIndex + 2);
            md5Weight.position = vertexPosition;
            md5WeightList.add(md5Weight);
            String vCountString = vertexWeightsVCountStrings[vertexWeightsIndex];
            int vCount = Integer.parseInt(vCountString);
            for (int vCountIndex = 0; vCountIndex < vCount; vCountIndex++) {
                for (Input vertexWeightsInput : vertexWeightsInputList) {
                    // vCount varies each time
                    ++vertexWeightsVDataIndex;
                    String indexString = vertexWeightsVStrings[vertexWeightsVDataIndex];
                    int index = Integer.parseInt(indexString);
                    if (-1 == index) {
                        throw new ColladaParseException("We do not support indexing into the bind shape yet");
                    }
                    if ("JOINT".equals(vertexWeightsInput.semantic)) {
                        md5Weight.jointIndex = index;
                        vertexWeightsJointNameArray[vertexWeightsIndex] = jointNameArray[index];
                    // logger.debug(String.valueOf(vertexWeightsVDataIndex) + ": " + "jointName=" + vertexWeightsJointNameArray[vertexWeightsIndex]);
                    } else if ("WEIGHT".equals(vertexWeightsInput.semantic)) {
                        md5Weight.bias = weightsArray[index];
                        vertexWeightsArray[vertexWeightsIndex] = weightsArray[index];
                    // logger.debug(String.valueOf(vertexWeightsVDataIndex) + ": " + "weight=" + vertexWeightsArray[vertexWeightsIndex]);
                    } else {
                        throw new ColladaParseException("Found unexpected vertex weights Input semantic " + vertexWeightsInput.semantic + " for controller id=" + controller.id() + " name=" + controller.name());
                    }
                }
            }
        }
        MD5Mesh md5Mesh = new MD5Mesh();
        md5Mesh.weightList = md5WeightList;
        // Find a node with sid="joint-name"
        for (String jointName : jointNameArray) {
            MD5Joint md5Joint = md5JointBySidMap.get(jointName);
            if (null == md5Joint) {
                throw new ColladaParseException("Cannot find joint node for node sid value for joint " + jointName + " in nodes for library_visual_scenes");
            }
            md5JointList.add(md5Joint);
        }
    }
    Deque<MD5Joint> jointsToProcess = new LinkedList<>(md5JointList);
    while (!jointsToProcess.isEmpty()) {
        MD5Joint joint = jointsToProcess.pop();
        MD5Joint parentJoint = joint.parent;
        if (null != parentJoint) {
            if (!md5JointList.contains(parentJoint)) {
                md5JointList.add(parentJoint);
                jointsToProcess.push(parentJoint);
            }
        }
    }
    for (MD5Joint joint : md5JointList) {
        if (null == joint.position) {
            throw new ColladaParseException("no joint position for joint with element id " + joint.element.id());
        }
        if (null == joint.orientation) {
            throw new ColladaParseException("no joint orientation for joint with element id " + joint.element.id());
        }
        // index argument is not used for anything currently, so we'll just set it to -1
        joint.bone = new Bone(-1, joint.name, joint.position, joint.orientation);
    }
    for (MD5Joint joint : md5JointList) {
        // We can probably skip unused end nodes
        joint.childList.stream().filter(childJoint -> childJoint.bone != null).forEach(childJoint -> joint.bone.addChild(childJoint.bone));
    }
    for (MD5Joint joint : md5JointList) {
        skeletonBuilder.addBone(joint.bone);
    }
    if (md5MeshList.size() > 0) {
        // TODO: Support multiple mesh somehow?
        MD5Mesh mesh = md5MeshList.get(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(vertices.size() / 3);
        TIntList vertexWeightCount = new TIntArrayList(vertices.size() / 3);
        for (int i = 0; i < vertices.size() / 3; i++) {
            vertexStartWeight.add(i);
            vertexWeightCount.add(1);
        }
        skeletonBuilder.setVertexWeights(vertexStartWeight, vertexWeightCount);
        for (int i = 0; i < normals.size() / 2; i++) {
            uvs.add(new Vector2f(normals.get(i * 2 + 0), normals.get(i * 2 + 1)));
        }
        skeletonBuilder.setUvs(uvs);
        skeletonBuilder.setIndices(indices);
    }
// Now if you have come this far, you should be able to read the geometry data,
// as well as the skeleton and skinning data from COLLADA documents. And you should be able to draw
// the model in raw triangles, as well as draw the skeleton. Although I haven't discussed how you
// can accumulate the world matrices for each joint and then draw in world coordinates for debugging
// purposes but I think I gave a hint that we have to multiply parent joint's world matrix with current
// joint's Joint matrix and save the result in current joint's world matrix. We have to start this
// process from the root bone. So that we don't have dirty world matrices from parents, and the root
// Joint's world matrix becomes the Joint matrix, since root don't have any parent. If you are also
// reading the COLLADA specification version 1.5 you can find the skinning equation so you should also
// be able to put the model in bind shape. How can we animate this model is still not covered and will
// be covered in the following sections.
// THIS IS THE TARGET GOAL:
/*
        Bones
        - String name
        - int index
        - V3 object position
        - Quat4f obj rotation
        - parent / children bones

        SkeletalMesh


        // This part may not be required if we can implement SkeletalMeshData methods without it

        //////////////

        public SkeletalMeshData(List<Bone> bones, List<BoneWeight> weights,
           List<Vector2f> uvs,
           TIntList vertexStartWeights, TIntList vertexWeightCounts,
           TIntList indices) {

        BoneWeight
        Vector3f position = new Vector3f();
        float bias;
        int boneIndex;
        Vector3f normal = new Vector3f();

        //////////////


           public Collection<Bone> getBones();
           public Bone getRootBone();
           public Bone getBone(String name);

           public int getVertexCount();

           public List<Vector3f> getBindPoseVertexPositions();
           public List<Vector3f> getVertexPositions(List<Vector3f> bonePositions, List<Quat4f> boneRotations);

           public List<Vector3f> getBindPoseVertexNormals();
           public List<Vector3f> getVertexNormals(List<Vector3f> bonePositions, List<Quat4f> boneRotations);

           public TIntList getIndices();
           public List<Vector2f> getUVs();
         */
}
Also used : Bone(org.terasology.rendering.assets.skeletalmesh.Bone) Arrays(java.util.Arrays) BoneWeight(org.terasology.rendering.assets.skeletalmesh.BoneWeight) TIntArrayList(gnu.trove.list.array.TIntArrayList) Element(org.eaxy.Element) LoggerFactory(org.slf4j.LoggerFactory) Vector3f(org.terasology.math.geom.Vector3f) SkeletalMeshDataBuilder(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder) HashMap(java.util.HashMap) Deque(java.util.Deque) Document(org.eaxy.Document) Matrix4f(org.terasology.math.geom.Matrix4f) ArrayList(java.util.ArrayList) ElementSet(org.eaxy.ElementSet) Lists(com.google.common.collect.Lists) Map(java.util.Map) TFloatList(gnu.trove.list.TFloatList) LinkedList(java.util.LinkedList) TIntList(gnu.trove.list.TIntList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) Logger(org.slf4j.Logger) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) NonMatchingPathException(org.eaxy.NonMatchingPathException) Vector2f(org.terasology.math.geom.Vector2f) IOException(java.io.IOException) List(java.util.List) Quat4f(org.terasology.math.geom.Quat4f) Collections(java.util.Collections) Xml(org.eaxy.Xml) InputStream(java.io.InputStream) ElementSet(org.eaxy.ElementSet) HashMap(java.util.HashMap) Element(org.eaxy.Element) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) BoneWeight(org.terasology.rendering.assets.skeletalmesh.BoneWeight) SkeletalMeshDataBuilder(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder) Vector2f(org.terasology.math.geom.Vector2f) LinkedList(java.util.LinkedList) TIntArrayList(gnu.trove.list.array.TIntArrayList) Vector3f(org.terasology.math.geom.Vector3f) Bone(org.terasology.rendering.assets.skeletalmesh.Bone) TIntList(gnu.trove.list.TIntList) Quat4f(org.terasology.math.geom.Quat4f)

Example 2 with SkeletalMeshData

use of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData in project Terasology by MovingBlocks.

the class HeadlessGraphics method registerCoreAssetTypes.

@Override
public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
    assetTypeManager.registerCoreAssetType(Font.class, (AssetFactory<Font, FontData>) FontImpl::new, "fonts");
    assetTypeManager.registerCoreAssetType(Texture.class, (AssetFactory<Texture, TextureData>) HeadlessTexture::new, "textures", "fonts");
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getName(2).toString().equals("textures")));
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getName(2).toString().equals("fonts")));
    assetTypeManager.registerCoreAssetType(Shader.class, (AssetFactory<Shader, ShaderData>) HeadlessShader::new, "shaders");
    assetTypeManager.registerCoreAssetType(Material.class, (AssetFactory<Material, MaterialData>) HeadlessMaterial::new, "materials");
    assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>) HeadlessMesh::new, "mesh");
    assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>) HeadlessSkeletalMesh::new, "skeletalMesh");
    assetTypeManager.registerCoreAssetType(MeshAnimation.class, (AssetFactory<MeshAnimation, MeshAnimationData>) MeshAnimationImpl::new, "animations");
    assetTypeManager.registerCoreAssetType(Atlas.class, (AssetFactory<Atlas, AtlasData>) Atlas::new, "atlas");
    assetTypeManager.registerCoreAssetType(Subtexture.class, (AssetFactory<Subtexture, SubtextureData>) Subtexture::new);
}
Also used : PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) RenderingSubsystemFactory(org.terasology.engine.subsystem.RenderingSubsystemFactory) Texture(org.terasology.rendering.assets.texture.Texture) MeshData(org.terasology.rendering.assets.mesh.MeshData) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) HeadlessDisplayDevice(org.terasology.engine.subsystem.headless.device.HeadlessDisplayDevice) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) FontData(org.terasology.rendering.assets.font.FontData) Material(org.terasology.rendering.assets.material.Material) MaterialData(org.terasology.rendering.assets.material.MaterialData) Mesh(org.terasology.rendering.assets.mesh.Mesh) Shader(org.terasology.rendering.assets.shader.Shader) PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) Atlas(org.terasology.rendering.assets.atlas.Atlas) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) MeshAnimationImpl(org.terasology.rendering.assets.animation.MeshAnimationImpl) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) ShaderManager(org.terasology.rendering.ShaderManager) AssetFactory(org.terasology.assets.AssetFactory) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) FontImpl(org.terasology.rendering.assets.font.FontImpl) ShaderData(org.terasology.rendering.assets.shader.ShaderData) HeadlessCanvasRenderer(org.terasology.engine.subsystem.headless.renderer.HeadlessCanvasRenderer) HeadlessRenderingSubsystemFactory(org.terasology.engine.subsystem.headless.renderer.HeadlessRenderingSubsystemFactory) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) ShaderManagerHeadless(org.terasology.engine.subsystem.headless.renderer.ShaderManagerHeadless) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) Font(org.terasology.rendering.assets.font.Font) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture) TextureData(org.terasology.rendering.assets.texture.TextureData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) Atlas(org.terasology.rendering.assets.atlas.Atlas) FontData(org.terasology.rendering.assets.font.FontData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) Mesh(org.terasology.rendering.assets.mesh.Mesh) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) Material(org.terasology.rendering.assets.material.Material) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Shader(org.terasology.rendering.assets.shader.Shader) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) Texture(org.terasology.rendering.assets.texture.Texture) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) Font(org.terasology.rendering.assets.font.Font) MeshData(org.terasology.rendering.assets.mesh.MeshData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) ShaderData(org.terasology.rendering.assets.shader.ShaderData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) TextureData(org.terasology.rendering.assets.texture.TextureData) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) MaterialData(org.terasology.rendering.assets.material.MaterialData) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture)

Example 3 with SkeletalMeshData

use of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData in project Terasology by MovingBlocks.

the class LwjglGraphics method registerCoreAssetTypes.

@Override
public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.registerCoreAssetType(Font.class, (AssetFactory<Font, FontData>) FontImpl::new, "fonts");
    assetTypeManager.registerCoreAssetType(Texture.class, (AssetFactory<Texture, TextureData>) (urn, assetType, data) -> (new OpenGLTexture(urn, assetType, data, this)), "textures", "fonts");
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> {
        if (path.getName(1).toString().equals(ModuleAssetDataProducer.OVERRIDE_FOLDER)) {
            return path.getName(3).toString().equals("textures");
        } else {
            return path.getName(2).toString().equals("textures");
        }
    }));
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> {
        if (path.getName(1).toString().equals(ModuleAssetDataProducer.OVERRIDE_FOLDER)) {
            return path.getName(3).toString().equals("fonts");
        } else {
            return path.getName(2).toString().equals("fonts");
        }
    }));
    assetTypeManager.registerCoreAssetType(Shader.class, (AssetFactory<Shader, ShaderData>) GLSLShader::new, "shaders");
    assetTypeManager.registerCoreAssetType(Material.class, (AssetFactory<Material, MaterialData>) GLSLMaterial::new, "materials");
    assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>) (urn, assetType, data) -> new OpenGLMesh(urn, assetType, bufferPool, data), "mesh");
    assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>) (urn, assetType, data) -> new OpenGLSkeletalMesh(urn, assetType, data, bufferPool), "skeletalMesh");
    assetTypeManager.registerCoreAssetType(MeshAnimation.class, (AssetFactory<MeshAnimation, MeshAnimationData>) MeshAnimationImpl::new, "animations");
    assetTypeManager.registerCoreAssetType(Atlas.class, (AssetFactory<Atlas, AtlasData>) Atlas::new, "atlas");
    assetTypeManager.registerCoreAssetType(Subtexture.class, (AssetFactory<Subtexture, SubtextureData>) Subtexture::new);
}
Also used : RenderingSubsystemFactory(org.terasology.engine.subsystem.RenderingSubsystemFactory) MeshData(org.terasology.rendering.assets.mesh.MeshData) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) LWJGLException(org.lwjgl.LWJGLException) ByteBuffer(java.nio.ByteBuffer) FontData(org.terasology.rendering.assets.font.FontData) Material(org.terasology.rendering.assets.material.Material) PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) ImageIO(javax.imageio.ImageIO) Atlas(org.terasology.rendering.assets.atlas.Atlas) GL11(org.lwjgl.opengl.GL11) TextureUtil(org.terasology.rendering.assets.texture.TextureUtil) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) BufferedImage(java.awt.image.BufferedImage) ShaderManager(org.terasology.rendering.ShaderManager) RenderingConfig(org.terasology.config.RenderingConfig) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) GameState(org.terasology.engine.modes.GameState) ShaderData(org.terasology.rendering.assets.shader.ShaderData) Queues(com.google.common.collect.Queues) List(java.util.List) LwjglCanvasRenderer(org.terasology.rendering.nui.internal.LwjglCanvasRenderer) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) Font(org.terasology.rendering.assets.font.Font) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture) TextureData(org.terasology.rendering.assets.texture.TextureData) GameEngine(org.terasology.engine.GameEngine) ModuleAssetDataProducer(org.terasology.assets.module.ModuleAssetDataProducer) ShaderManagerLwjgl(org.terasology.rendering.ShaderManagerLwjgl) Texture(org.terasology.rendering.assets.texture.Texture) GameThread(org.terasology.engine.GameThread) org.lwjgl.opengl(org.lwjgl.opengl) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) Lists(com.google.common.collect.Lists) MaterialData(org.terasology.rendering.assets.material.MaterialData) Mesh(org.terasology.rendering.assets.mesh.Mesh) Shader(org.terasology.rendering.assets.shader.Shader) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) Logger(org.slf4j.Logger) MeshAnimationImpl(org.terasology.rendering.assets.animation.MeshAnimationImpl) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) BlockingDeque(java.util.concurrent.BlockingDeque) AssetFactory(org.terasology.assets.AssetFactory) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) IOException(java.io.IOException) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) FontImpl(org.terasology.rendering.assets.font.FontImpl) org.terasology.rendering.opengl(org.terasology.rendering.opengl) Consumer(java.util.function.Consumer) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) Atlas(org.terasology.rendering.assets.atlas.Atlas) FontData(org.terasology.rendering.assets.font.FontData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) Mesh(org.terasology.rendering.assets.mesh.Mesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Material(org.terasology.rendering.assets.material.Material) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Shader(org.terasology.rendering.assets.shader.Shader) Texture(org.terasology.rendering.assets.texture.Texture) Font(org.terasology.rendering.assets.font.Font) MeshData(org.terasology.rendering.assets.mesh.MeshData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) ShaderData(org.terasology.rendering.assets.shader.ShaderData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) TextureData(org.terasology.rendering.assets.texture.TextureData) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) MaterialData(org.terasology.rendering.assets.material.MaterialData) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture)

Example 4 with SkeletalMeshData

use of org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupAssetManager.

@Override
protected AssetManager setupAssetManager() {
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, false, "prefabs");
    assetTypeManager.registerCoreAssetType(BlockShape.class, (AssetFactory<BlockShape, BlockShapeData>) BlockShapeImpl::new, "shapes");
    assetTypeManager.registerCoreAssetType(BlockSounds.class, (AssetFactory<BlockSounds, BlockSoundsData>) BlockSounds::new, "blockSounds");
    assetTypeManager.registerCoreAssetType(BlockTile.class, (AssetFactory<BlockTile, TileData>) BlockTile::new, "blockTiles");
    assetTypeManager.registerCoreAssetType(BlockFamilyDefinition.class, (AssetFactory<BlockFamilyDefinition, BlockFamilyDefinitionData>) BlockFamilyDefinition::new, "blocks");
    assetTypeManager.registerCoreAssetType(StaticSound.class, NullSound::new, "sounds");
    assetTypeManager.registerCoreAssetType(StreamingSound.class, NullStreamingSound::new, "music");
    DefaultBlockFamilyFactoryRegistry blockFamilyFactoryRegistry = new DefaultBlockFamilyFactoryRegistry();
    blockFamilyFactoryRegistry.setBlockFamilyFactory("horizontal", new HorizontalBlockFamilyFactory());
    blockFamilyFactoryRegistry.setBlockFamilyFactory("alignToSurface", new AttachedToSurfaceFamilyFactory());
    assetTypeManager.registerCoreFormat(BlockFamilyDefinition.class, new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager(), blockFamilyFactoryRegistry));
    assetTypeManager.registerCoreAssetType(UISkin.class, (AssetFactory<UISkin, UISkinData>) UISkin::new, "skins");
    assetTypeManager.registerCoreAssetType(BehaviorTree.class, (AssetFactory<BehaviorTree, BehaviorTreeData>) BehaviorTree::new, false, "behaviors");
    assetTypeManager.registerCoreAssetType(UIElement.class, (AssetFactory<UIElement, UIData>) UIElement::new, "ui");
    assetTypeManager.registerCoreAssetType(Font.class, (AssetFactory<Font, FontData>) FontImpl::new, "fonts");
    assetTypeManager.registerCoreAssetType(Texture.class, (AssetFactory<Texture, TextureData>) HeadlessTexture::new, "textures", "fonts");
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getName(2).toString().equals("textures")));
    assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getName(2).toString().equals("fonts")));
    assetTypeManager.registerCoreAssetType(Shader.class, (AssetFactory<Shader, ShaderData>) HeadlessShader::new, "shaders");
    assetTypeManager.registerCoreAssetType(Material.class, (AssetFactory<Material, MaterialData>) HeadlessMaterial::new, "materials");
    assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>) HeadlessMesh::new, "mesh");
    assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>) HeadlessSkeletalMesh::new, "skeletalMesh");
    assetTypeManager.registerCoreAssetType(MeshAnimation.class, (AssetFactory<MeshAnimation, MeshAnimationData>) MeshAnimationImpl::new, "animations");
    assetTypeManager.registerCoreAssetType(Atlas.class, (AssetFactory<Atlas, AtlasData>) Atlas::new, "atlas");
    assetTypeManager.registerCoreAssetType(Subtexture.class, (AssetFactory<Subtexture, SubtextureData>) Subtexture::new);
    assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
    context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    return assetTypeManager.getAssetManager();
}
Also used : PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) MeshData(org.terasology.rendering.assets.mesh.MeshData) UIElement(org.terasology.rendering.nui.asset.UIElement) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) CelestialSystem(org.terasology.world.sun.CelestialSystem) AssetManager(org.terasology.assets.management.AssetManager) Time(org.terasology.engine.Time) Config(org.terasology.config.Config) BehaviorTreeData(org.terasology.logic.behavior.asset.BehaviorTreeData) BlockTile(org.terasology.world.block.tiles.BlockTile) FontData(org.terasology.rendering.assets.font.FontData) Material(org.terasology.rendering.assets.material.Material) PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) NullStreamingSound(org.terasology.audio.nullAudio.NullStreamingSound) PrefabData(org.terasology.entitySystem.prefab.PrefabData) EngineTime(org.terasology.engine.EngineTime) WorldAtlas(org.terasology.world.block.tiles.WorldAtlas) Path(java.nio.file.Path) TileData(org.terasology.world.block.tiles.TileData) AudioManager(org.terasology.audio.AudioManager) Set(java.util.Set) ReadWriteStorageManager(org.terasology.persistence.internal.ReadWriteStorageManager) BlockShapeImpl(org.terasology.world.block.shapes.BlockShapeImpl) UISkinData(org.terasology.rendering.nui.skin.UISkinData) NullAudioManager(org.terasology.audio.nullAudio.NullAudioManager) EntitySystemSetupUtil(org.terasology.engine.bootstrap.EntitySystemSetupUtil) AttachedToSurfaceFamilyFactory(org.terasology.world.block.family.AttachedToSurfaceFamilyFactory) CollisionGroupTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.CollisionGroupTypeHandler) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) BlockFamilyDefinitionFormat(org.terasology.world.block.loader.BlockFamilyDefinitionFormat) ModuleManagerFactory(org.terasology.testUtil.ModuleManagerFactory) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture) Mockito.mock(org.mockito.Mockito.mock) BlockManager(org.terasology.world.block.BlockManager) Prefab(org.terasology.entitySystem.prefab.Prefab) UISkin(org.terasology.rendering.nui.skin.UISkin) Mesh(org.terasology.rendering.assets.mesh.Mesh) Shader(org.terasology.rendering.assets.shader.Shader) NetworkSystemImpl(org.terasology.network.internal.NetworkSystemImpl) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) BlockTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockTypeHandler) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) Name(org.terasology.naming.Name) ModuleManager(org.terasology.engine.module.ModuleManager) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) StaticSound(org.terasology.audio.StaticSound) MeshAnimationImpl(org.terasology.rendering.assets.animation.MeshAnimationImpl) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) DefaultCelestialSystem(org.terasology.world.sun.DefaultCelestialSystem) StreamingSound(org.terasology.audio.StreamingSound) IOException(java.io.IOException) FontImpl(org.terasology.rendering.assets.font.FontImpl) EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) BasicCelestialModel(org.terasology.world.sun.BasicCelestialModel) NetworkSystem(org.terasology.network.NetworkSystem) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) DependencyResolver(org.terasology.module.DependencyResolver) LoggerFactory(org.slf4j.LoggerFactory) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) WorldTime(org.terasology.world.time.WorldTime) Block(org.terasology.world.block.Block) Atlas(org.terasology.rendering.assets.atlas.Atlas) BlockShape(org.terasology.world.block.shapes.BlockShape) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) DefaultBlockFamilyFactoryRegistry(org.terasology.world.block.family.DefaultBlockFamilyFactoryRegistry) UIData(org.terasology.rendering.nui.asset.UIData) BlockFamilyTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.BlockFamilyTypeHandler) BlockShapeData(org.terasology.world.block.shapes.BlockShapeData) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) BiomeManager(org.terasology.world.biomes.BiomeManager) WorldProvider(org.terasology.world.WorldProvider) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BehaviorTree(org.terasology.logic.behavior.asset.BehaviorTree) FileSystem(java.nio.file.FileSystem) ShaderData(org.terasology.rendering.assets.shader.ShaderData) LoadPrefabs(org.terasology.engine.modes.loadProcesses.LoadPrefabs) CollisionGroup(org.terasology.physics.CollisionGroup) Font(org.terasology.rendering.assets.font.Font) TextureData(org.terasology.rendering.assets.texture.TextureData) BlockFamily(org.terasology.world.block.family.BlockFamily) ShrinkWrapFileSystems(org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems) HorizontalBlockFamilyFactory(org.terasology.world.block.family.HorizontalBlockFamilyFactory) Texture(org.terasology.rendering.assets.texture.Texture) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) ModuleRegistry(org.terasology.module.ModuleRegistry) CollisionGroupManager(org.terasology.physics.CollisionGroupManager) MaterialData(org.terasology.rendering.assets.material.MaterialData) PathManager(org.terasology.engine.paths.PathManager) ResolutionResult(org.terasology.module.ResolutionResult) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) WorldTimeImpl(org.terasology.world.time.WorldTimeImpl) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) Logger(org.slf4j.Logger) AssetFactory(org.terasology.assets.AssetFactory) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) NullSound(org.terasology.audio.nullAudio.NullSound) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Mockito.when(org.mockito.Mockito.when) StorageManager(org.terasology.persistence.StorageManager) WorldInfo(org.terasology.world.internal.WorldInfo) BlockSounds(org.terasology.world.block.sounds.BlockSounds) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) BlockSoundsData(org.terasology.world.block.sounds.BlockSoundsData) NullStreamingSound(org.terasology.audio.nullAudio.NullStreamingSound) UIElement(org.terasology.rendering.nui.asset.UIElement) BlockFamilyDefinitionFormat(org.terasology.world.block.loader.BlockFamilyDefinitionFormat) UISkin(org.terasology.rendering.nui.skin.UISkin) UISkinData(org.terasology.rendering.nui.skin.UISkinData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) BlockTile(org.terasology.world.block.tiles.BlockTile) DefaultBlockFamilyFactoryRegistry(org.terasology.world.block.family.DefaultBlockFamilyFactoryRegistry) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Shader(org.terasology.rendering.assets.shader.Shader) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) Texture(org.terasology.rendering.assets.texture.Texture) Font(org.terasology.rendering.assets.font.Font) ShaderData(org.terasology.rendering.assets.shader.ShaderData) TileData(org.terasology.world.block.tiles.TileData) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) TextureData(org.terasology.rendering.assets.texture.TextureData) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) AttachedToSurfaceFamilyFactory(org.terasology.world.block.family.AttachedToSurfaceFamilyFactory) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) NullSound(org.terasology.audio.nullAudio.NullSound) WorldAtlas(org.terasology.world.block.tiles.WorldAtlas) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) Atlas(org.terasology.rendering.assets.atlas.Atlas) PrefabData(org.terasology.entitySystem.prefab.PrefabData) BehaviorTreeData(org.terasology.logic.behavior.asset.BehaviorTreeData) BlockShape(org.terasology.world.block.shapes.BlockShape) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) FontData(org.terasology.rendering.assets.font.FontData) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) Mesh(org.terasology.rendering.assets.mesh.Mesh) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) Material(org.terasology.rendering.assets.material.Material) BehaviorTree(org.terasology.logic.behavior.asset.BehaviorTree) BlockShapeData(org.terasology.world.block.shapes.BlockShapeData) UIData(org.terasology.rendering.nui.asset.UIData) MeshData(org.terasology.rendering.assets.mesh.MeshData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) BlockSounds(org.terasology.world.block.sounds.BlockSounds) BlockSoundsData(org.terasology.world.block.sounds.BlockSoundsData) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) HorizontalBlockFamilyFactory(org.terasology.world.block.family.HorizontalBlockFamilyFactory) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) MaterialData(org.terasology.rendering.assets.material.MaterialData) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture)

Aggregations

SkeletalMeshData (org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData)4 IOException (java.io.IOException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AssetFactory (org.terasology.assets.AssetFactory)3 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Config (org.terasology.config.Config)2 MeshAnimation (org.terasology.rendering.assets.animation.MeshAnimation)2 MeshAnimationData (org.terasology.rendering.assets.animation.MeshAnimationData)2 MeshAnimationImpl (org.terasology.rendering.assets.animation.MeshAnimationImpl)2 Atlas (org.terasology.rendering.assets.atlas.Atlas)2 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)2 Font (org.terasology.rendering.assets.font.Font)2 FontData (org.terasology.rendering.assets.font.FontData)2 FontImpl (org.terasology.rendering.assets.font.FontImpl)2 Material (org.terasology.rendering.assets.material.Material)2 MaterialData (org.terasology.rendering.assets.material.MaterialData)2 Mesh (org.terasology.rendering.assets.mesh.Mesh)2