Search in sources :

Example 1 with SubtextureData

use of org.terasology.rendering.assets.texture.subtexture.SubtextureData in project Terasology by MovingBlocks.

the class AtlasFormat method load.

@Override
public AtlasData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (Reader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
        AtlasDefinition def = gson.fromJson(reader, AtlasDefinition.class);
        Optional<? extends Texture> texture = assetManager.getAsset(def.getTexture(), Texture.class);
        if (texture.isPresent()) {
            Vector2i size = def.getTextureSize();
            if (size == null) {
                size = new Vector2i(texture.get().getWidth(), texture.get().getHeight());
            }
            Map<Name, SubtextureData> result = Maps.newHashMap();
            if (def.getGrid() != null) {
                process(def.getGrid(), texture.get(), size, result);
            }
            if (def.getGrids() != null) {
                for (GridDefinition grid : def.getGrids()) {
                    process(grid, texture.get(), size, result);
                }
            }
            if (def.getSubimage() != null) {
                process(def.getSubimage(), texture.get(), size, result);
            }
            if (def.getSubimages() != null) {
                for (FreeformDefinition freeform : def.getSubimages()) {
                    process(freeform, texture.get(), size, result);
                }
            }
            return new AtlasData(result);
        }
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Vector2i(org.terasology.math.geom.Vector2i) Name(org.terasology.naming.Name)

Example 2 with SubtextureData

use of org.terasology.rendering.assets.texture.subtexture.SubtextureData 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 SubtextureData

use of org.terasology.rendering.assets.texture.subtexture.SubtextureData in project Terasology by MovingBlocks.

the class Atlas method doReload.

@Override
protected void doReload(AtlasData data) {
    subtextures.clear();
    for (Map.Entry<Name, SubtextureData> entry : data.getSubtextures().entrySet()) {
        ResourceUrn subtextureUrn = new ResourceUrn(getUrn().getModuleName(), getUrn().getResourceName(), entry.getKey());
        subtextures.put(subtextureUrn, entry.getValue());
    }
}
Also used : SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) ResourceUrn(org.terasology.assets.ResourceUrn) Map(java.util.Map) Name(org.terasology.naming.Name)

Example 4 with SubtextureData

use of org.terasology.rendering.assets.texture.subtexture.SubtextureData in project Terasology by MovingBlocks.

the class AtlasFormat method process.

private void process(GridDefinition grid, Texture texture, Vector2i size, Map<Name, SubtextureData> out) {
    if (grid.getTileSize() == null) {
        logger.error("Bad grid definition - missing mandatory property tileSize");
        return;
    }
    if (grid.getGridDimensions() == null) {
        logger.error("Bad grid definition - missing mandatory property gridDimensions");
        return;
    }
    Vector2f offset = new Vector2f(0, 0);
    if (grid.getGridOffset() != null) {
        offset.set((float) grid.getGridOffset().x / size.x, (float) grid.getGridOffset().y / size.y);
    }
    Vector2f tileSize = new Vector2f((float) grid.getTileSize().x / size.x, (float) grid.getTileSize().y / size.y);
    int tileX = 0;
    int tileY = 0;
    for (String name : grid.getTileNames()) {
        if (!name.isEmpty()) {
            Vector2f pos = new Vector2f(offset);
            pos.x += tileX * tileSize.x;
            pos.y += tileY * tileSize.y;
            Rect2f tileLocation = Rect2f.createFromMinAndSize(offset.x + tileX * tileSize.x, offset.y + tileY * tileSize.y, tileSize.x, tileSize.y);
            out.put(new Name(name), new SubtextureData(texture, tileLocation));
        }
        tileX++;
        if (tileX == grid.getGridDimensions().x) {
            tileX = 0;
            tileY++;
        }
    }
}
Also used : Rect2f(org.terasology.math.geom.Rect2f) Vector2f(org.terasology.math.geom.Vector2f) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) Name(org.terasology.naming.Name)

Example 5 with SubtextureData

use of org.terasology.rendering.assets.texture.subtexture.SubtextureData in project Terasology by MovingBlocks.

the class AtlasFormat method process.

private void process(FreeformDefinition freeform, Texture texture, Vector2i size, Map<Name, SubtextureData> out) {
    if (freeform.getName() == null || freeform.getName().isEmpty()) {
        logger.error("Bad subimage definition - missing mandatory property name");
        return;
    }
    if (freeform.getMin() == null) {
        logger.error("Bad subimage definition '{}' - missing mandatory property min", freeform.getName());
        return;
    }
    if (freeform.getSize() == null && freeform.getMax() == null) {
        logger.error("Bad subimage definition '{}' - requires one of max or size", freeform.getName());
        return;
    }
    Vector2f min = new Vector2f((float) freeform.getMin().x / size.x, (float) freeform.getMin().y / size.y);
    if (freeform.getSize() != null) {
        Vector2f itemSize = new Vector2f((float) freeform.getSize().x / size.x, (float) freeform.getSize().y / size.y);
        out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndSize(min, itemSize)));
    } else if (freeform.getMax() != null) {
        Vector2f max = new Vector2f((float) freeform.getMax().x / size.x, (float) freeform.getMax().y / size.y);
        out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndMax(min, max)));
    }
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) Name(org.terasology.naming.Name)

Aggregations

SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)8 Name (org.terasology.naming.Name)6 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)4 AssetFactory (org.terasology.assets.AssetFactory)3 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)3 Vector2f (org.terasology.math.geom.Vector2f)3 MeshAnimation (org.terasology.rendering.assets.animation.MeshAnimation)3 MeshAnimationData (org.terasology.rendering.assets.animation.MeshAnimationData)3 MeshAnimationImpl (org.terasology.rendering.assets.animation.MeshAnimationImpl)3 Atlas (org.terasology.rendering.assets.atlas.Atlas)3 Font (org.terasology.rendering.assets.font.Font)3 FontData (org.terasology.rendering.assets.font.FontData)3 FontImpl (org.terasology.rendering.assets.font.FontImpl)3 Material (org.terasology.rendering.assets.material.Material)3 MaterialData (org.terasology.rendering.assets.material.MaterialData)3 Mesh (org.terasology.rendering.assets.mesh.Mesh)3 MeshData (org.terasology.rendering.assets.mesh.MeshData)3 Shader (org.terasology.rendering.assets.shader.Shader)3 ShaderData (org.terasology.rendering.assets.shader.ShaderData)3 SkeletalMesh (org.terasology.rendering.assets.skeletalmesh.SkeletalMesh)3