Search in sources :

Example 6 with Texture

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

the class BlockDamageAuthoritySystem method createBlockParticleEffect.

/**
 * Creates a new entity for the block damage particle effect.
 *
 * If the terrain texture of the damaged block is available, the particles will have the block texture. Otherwise,
 * the default sprite (smoke) is used.
 *
 * @param family the {@link BlockFamily} of the damaged block
 * @param location the location of the damaged block
 */
private void createBlockParticleEffect(BlockFamily family, Vector3f location) {
    EntityBuilder builder = entityManager.newBuilder("core:defaultBlockParticles");
    builder.getComponent(LocationComponent.class).setWorldPosition(location);
    Optional<Texture> terrainTexture = Assets.getTexture("engine:terrain");
    if (terrainTexture.isPresent() && terrainTexture.get().isLoaded()) {
        final BlockAppearance blockAppearance = family.getArchetypeBlock().getPrimaryAppearance();
        final float relativeTileSize = worldAtlas.getRelativeTileSize();
        final float particleScale = 0.25f;
        final float spriteSize = relativeTileSize * particleScale;
        ParticleDataSpriteComponent spriteComponent = builder.getComponent(ParticleDataSpriteComponent.class);
        spriteComponent.texture = terrainTexture.get();
        spriteComponent.textureSize.set(spriteSize, spriteSize);
        final List<Vector2f> offsets = computeOffsets(blockAppearance, particleScale);
        TextureOffsetGeneratorComponent textureOffsetGeneratorComponent = builder.getComponent(TextureOffsetGeneratorComponent.class);
        textureOffsetGeneratorComponent.validOffsets.addAll(offsets);
    }
    builder.build();
}
Also used : ParticleDataSpriteComponent(org.terasology.particles.components.ParticleDataSpriteComponent) TextureOffsetGeneratorComponent(org.terasology.particles.components.generators.TextureOffsetGeneratorComponent) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector2f(org.terasology.math.geom.Vector2f) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.logic.location.LocationComponent) Texture(org.terasology.rendering.assets.texture.Texture)

Example 7 with Texture

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

the class WorldAtlasImpl method buildAtlas.

private void buildAtlas() {
    calculateAtlasSizes();
    int numMipMaps = getNumMipmaps();
    ByteBuffer[] data = createAtlasMipmaps(numMipMaps, TRANSPARENT_COLOR, tiles, "tiles.png");
    ByteBuffer[] dataNormal = createAtlasMipmaps(numMipMaps, UNIT_Z_COLOR, tilesNormal, "tilesNormal.png", tilesGloss);
    ByteBuffer[] dataHeight = createAtlasMipmaps(numMipMaps, BLACK_COLOR, tilesHeight, "tilesHeight.png");
    TextureData terrainTexData = new TextureData(atlasSize, atlasSize, data, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    Texture terrainTex = Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainTexData, Texture.class);
    TextureData terrainNormalData = new TextureData(atlasSize, atlasSize, dataNormal, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    Assets.generateAsset(new ResourceUrn("engine:terrainNormal"), terrainNormalData, Texture.class);
    TextureData terrainHeightData = new TextureData(atlasSize, atlasSize, dataHeight, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    Assets.generateAsset(new ResourceUrn("engine:terrainHeight"), terrainHeightData, Texture.class);
    MaterialData terrainMatData = new MaterialData(Assets.getShader("engine:block").get());
    terrainMatData.setParam("textureAtlas", terrainTex);
    terrainMatData.setParam("colorOffset", new float[] { 1, 1, 1 });
    terrainMatData.setParam("textured", true);
    Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainMatData, Material.class);
    createTextureAtlas(terrainTex);
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) MaterialData(org.terasology.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.rendering.assets.texture.Texture)

Example 8 with Texture

use of org.terasology.rendering.assets.texture.Texture 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 9 with Texture

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

the class NUIEditorItemRenderer method getTexture.

@Override
public Texture getTexture(JsonTreeValue value) {
    String textureName = null;
    if (value.getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
        textureName = ATTRIBUTE_TEXTURE_NAME;
    } else if (value.getType() == JsonTreeValue.Type.OBJECT) {
        JsonTree node = (JsonTree) editorTreeViewModel.getNodeByValue(value);
        // If the node has a "type": "..." child, retrieve the texture by the type name.
        if (node != null) {
            // If the node has no type and is a root node, do not draw an icon.
            if (node.isRoot()) {
                return null;
            } else if (!node.isRoot() && "elements".equals(node.getParent().getValue().getKey())) {
                textureName = node.getValue().getKey();
            } else {
                for (Tree<JsonTreeValue> child : node.getChildren()) {
                    JsonTreeValue childValue = child.getValue();
                    if (childValue.getType() == JsonTreeValue.Type.KEY_VALUE_PAIR && "type".equals(childValue.getKey())) {
                        textureName = (String) childValue.getValue();
                    }
                }
            }
        }
        // Otherwise use the default texture.
        if (textureName == null) {
            textureName = OBJECT_TEXTURE_NAME;
        }
    } else if (value.getType() == JsonTreeValue.Type.ARRAY) {
        textureName = ARRAY_TEXTURE_NAME;
    } else if (value.getKey() != null) {
        textureName = value.getKey();
    } else {
        return null;
    }
    Optional<Texture> texture = Assets.getTexture(textureName != null ? String.format("engine:editor_%s", textureName) : ICON_BLANK);
    return texture.isPresent() ? texture.get() : null;
}
Also used : JsonTreeValue(org.terasology.rendering.nui.widgets.treeView.JsonTreeValue) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) Texture(org.terasology.rendering.assets.texture.Texture)

Example 10 with Texture

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

the class PreviewWorldScreen method updatePreview.

private void updatePreview() {
    final NUIManager manager = context.get(NUIManager.class);
    final WaitPopup<TextureData> popup = manager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage("Updating Preview", "Please wait ...");
    ProgressListener progressListener = progress -> popup.setMessage("Updating Preview", String.format("Please wait ... %d%%", (int) (progress * 100f)));
    Callable<TextureData> operation = () -> {
        if (seed != null) {
            worldGenerator.setWorldSeed(seed.getText());
        }
        int zoom = TeraMath.floorToInt(zoomSlider.getValue());
        TextureData data = texture.getData();
        if (zoneSelector.isVisible()) {
            previewGen = zoneSelector.getSelection().preview(worldGenerator);
        }
        previewGen.render(data, zoom, progressListener);
        return data;
    };
    popup.onSuccess(texture::reload);
    popup.startOperation(operation, true);
}
Also used : CoreScreenLayer(org.terasology.rendering.nui.CoreScreenLayer) Zone(org.terasology.world.zones.Zone) ContextImpl(org.terasology.context.internal.ContextImpl) DependencyResolver(org.terasology.module.DependencyResolver) UISlider(org.terasology.rendering.nui.widgets.UISlider) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) Property(org.terasology.rendering.nui.properties.Property) ByteBuffer(java.nio.ByteBuffer) WorldConfigurator(org.terasology.world.generator.WorldConfigurator) Map(java.util.Map) PropertyLayout(org.terasology.rendering.nui.layouts.PropertyLayout) SimpleUri(org.terasology.engine.SimpleUri) TeraMath(org.terasology.math.TeraMath) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) WidgetUtil(org.terasology.rendering.nui.WidgetUtil) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) Collectors(java.util.stream.Collectors) PropertyProvider(org.terasology.rendering.nui.properties.PropertyProvider) UIImage(org.terasology.rendering.nui.widgets.UIImage) Objects(java.util.Objects) List(java.util.List) UnresolvedDependencyException(org.terasology.module.exceptions.UnresolvedDependencyException) CoreRegistry(org.terasology.registry.CoreRegistry) TextureData(org.terasology.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.assets.ResourceUrn) In(org.terasology.registry.In) MenuAnimationSystems(org.terasology.rendering.nui.animation.MenuAnimationSystems) Texture(org.terasology.rendering.assets.texture.Texture) Callable(java.util.concurrent.Callable) FacetLayerPreview(org.terasology.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) Lists(com.google.common.collect.Lists) WorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary) ResolutionResult(org.terasology.module.ResolutionResult) NUIManager(org.terasology.rendering.nui.NUIManager) ModuleManager(org.terasology.engine.module.ModuleManager) Assets(org.terasology.utilities.Assets) Logger(org.slf4j.Logger) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) TempWorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.TempWorldGeneratorPluginLibrary) UIText(org.terasology.rendering.nui.widgets.UIText) WorldGeneratorManager(org.terasology.world.generator.internal.WorldGeneratorManager) UIDropdown(org.terasology.rendering.nui.widgets.UIDropdown) WorldGenerator(org.terasology.world.generator.WorldGenerator) Binding(org.terasology.rendering.nui.databinding.Binding) PreviewGenerator(org.terasology.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Component(org.terasology.entitySystem.Component) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler) UIButton(org.terasology.rendering.nui.widgets.UIButton) PropertyOrdering(org.terasology.rendering.nui.properties.PropertyOrdering) TextureData(org.terasology.rendering.assets.texture.TextureData) NUIManager(org.terasology.rendering.nui.NUIManager)

Aggregations

Texture (org.terasology.rendering.assets.texture.Texture)15 ResourceUrn (org.terasology.assets.ResourceUrn)7 TextureData (org.terasology.rendering.assets.texture.TextureData)7 ByteBuffer (java.nio.ByteBuffer)6 MaterialData (org.terasology.rendering.assets.material.MaterialData)5 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)4 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AssetFactory (org.terasology.assets.AssetFactory)3 Config (org.terasology.config.Config)3 Context (org.terasology.context.Context)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 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)3 Font (org.terasology.rendering.assets.font.Font)3 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 List (java.util.List)2