Search in sources :

Example 6 with TextureData

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

the class WorldPreGenerationScreen method updatePreview.

/**
 * Updates the preview according to any changes made to the configurator.
 * Also pops up a message and keeps track of percentage world preview prepared.
 */
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 = () -> {
        int zoom = TeraMath.floorToInt(zoomSlider.getValue());
        TextureData data = texture.getData();
        previewGen.render(data, zoom, progressListener);
        return data;
    };
    popup.onSuccess(texture::reload);
    popup.startOperation(operation, true);
}
Also used : MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UISlider(org.terasology.nui.widgets.UISlider) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Texture(org.terasology.engine.rendering.assets.texture.Texture) In(org.terasology.engine.registry.In) ModuleManager(org.terasology.engine.core.module.ModuleManager) LoggerFactory(org.slf4j.LoggerFactory) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) WidgetUtil(org.terasology.nui.WidgetUtil) ByteBuffer(java.nio.ByteBuffer) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) TeraMath(org.terasology.math.TeraMath) Binding(org.terasology.nui.databinding.Binding) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Logger(org.slf4j.Logger) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Assets(org.terasology.engine.utilities.Assets) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) NUIManager(org.terasology.engine.rendering.nui.NUIManager) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) UISliderOnChangeTriggeredListener(org.terasology.nui.widgets.UISliderOnChangeTriggeredListener) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) Name(org.terasology.gestalt.naming.Name) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) NUIManager(org.terasology.engine.rendering.nui.NUIManager)

Example 7 with TextureData

use of org.terasology.engine.rendering.assets.texture.TextureData 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 : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Component(org.terasology.gestalt.entitysystem.component.Component) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ByteBuffer(java.nio.ByteBuffer) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) Map(java.util.Map) TeraMath(org.terasology.math.TeraMath) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) Property(org.terasology.nui.properties.Property) Binding(org.terasology.nui.databinding.Binding) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) NUIManager(org.terasology.engine.rendering.nui.NUIManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) CoreRegistry(org.terasology.engine.registry.CoreRegistry) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UIDropdown(org.terasology.nui.widgets.UIDropdown) UISlider(org.terasology.nui.widgets.UISlider) ModuleManager(org.terasology.engine.core.module.ModuleManager) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) PropertyProvider(org.terasology.nui.properties.PropertyProvider) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) PropertyOrdering(org.terasology.nui.properties.PropertyOrdering) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) NUIManager(org.terasology.engine.rendering.nui.NUIManager)

Example 8 with TextureData

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

the class SelectionScreen method loadPreviewImages.

private void loadPreviewImages(final GameInfo gameInfo) {
    List<Texture> textures = new ArrayList<>();
    if (gameInfo != null && gameInfo.getSavePath() != null) {
        final List<BufferedImage> bufferedImages = GamePreviewImageProvider.getAllPreviewImages(gameInfo.getSavePath());
        textures = bufferedImages.stream().map(buffImage -> {
            TextureData textureData;
            try {
                textureData = AWTTextureFormat.convertToTextureData(buffImage, Texture.FilterMode.LINEAR);
            } catch (IOException e) {
                logger.error("Converting preview image to texture data {} failed", e);
                return null;
            }
            return Assets.generateAsset(new ResourceUrn(PREVIEW_IMAGE_URI_PATTERN + bufferedImages.indexOf(buffImage)), textureData, Texture.class);
        }).filter(Objects::nonNull).collect(Collectors.toList());
    }
    if (textures.isEmpty()) {
        textures.add(Assets.getTexture(DEFAULT_PREVIEW_IMAGE_URI).get());
    }
    previewSlideshow.clean();
    textures.forEach(tex -> {
        UIImage image = new UIImage(null, tex, true);
        previewSlideshow.addImage(image);
    });
}
Also used : TerasologyConstants(org.terasology.engine.core.TerasologyConstants) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) GamePreviewImageProvider(org.terasology.engine.persistence.internal.GamePreviewImageProvider) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) UIImageSlideshow(org.terasology.nui.widgets.UIImageSlideshow) Path(java.nio.file.Path) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) UILabel(org.terasology.nui.widgets.UILabel) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Objects(java.util.Objects) FilesUtil(org.terasology.engine.utilities.FilesUtil) List(java.util.List) Stream(java.util.stream.Stream) Config(org.terasology.engine.config.Config) NameVersion(org.terasology.gestalt.naming.NameVersion) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) UIList(org.terasology.nui.widgets.UIList) PlayerConfig(org.terasology.engine.config.PlayerConfig) AWTTextureFormat(org.terasology.engine.rendering.assets.texture.AWTTextureFormat) Name(org.terasology.gestalt.naming.Name) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) ArrayList(java.util.ArrayList) Objects(java.util.Objects) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) UIImage(org.terasology.nui.widgets.UIImage) Texture(org.terasology.engine.rendering.assets.texture.Texture) BufferedImage(java.awt.image.BufferedImage)

Example 9 with TextureData

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

the class LwjglFrameBufferObject method generateTexture.

private Texture generateTexture(ResourceUrn urn) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(size.x() * size.y() * Integer.BYTES);
    ByteBuffer[] mipmaps = new ByteBuffer[] { buffer };
    TextureData data = new TextureData(size.x(), size.y(), mipmaps, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    return Assets.generateAsset(urn, data, Texture.class);
}
Also used : TextureData(org.terasology.engine.rendering.assets.texture.TextureData) ByteBuffer(java.nio.ByteBuffer)

Example 10 with TextureData

use of org.terasology.engine.rendering.assets.texture.TextureData 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, MID_RED_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.LINEAR);
    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.engine.rendering.assets.texture.TextureData) MaterialData(org.terasology.engine.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Aggregations

TextureData (org.terasology.engine.rendering.assets.texture.TextureData)10 Texture (org.terasology.engine.rendering.assets.texture.Texture)9 ByteBuffer (java.nio.ByteBuffer)7 Context (org.terasology.engine.context.Context)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Config (org.terasology.engine.config.Config)4 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)4 UIImage (org.terasology.nui.widgets.UIImage)4 Lists (com.google.common.collect.Lists)3 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 In (org.terasology.engine.registry.In)3 CoreScreenLayer (org.terasology.engine.rendering.nui.CoreScreenLayer)3 Assets (org.terasology.engine.utilities.Assets)3 WorldGeneratorManager (org.terasology.engine.world.generator.internal.WorldGeneratorManager)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 Name (org.terasology.gestalt.naming.Name)3