Search in sources :

Example 11 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class ShaderManagerLwjgl method addShaderProgram.

// TODO: discuss having a `public removeShaderProgram`, to dispose shader programs no longer in use by any node
public GLSLMaterial addShaderProgram(String title) {
    String uri = "engine:" + title;
    Optional<? extends Shader> shader = Assets.getShader(uri);
    checkState(shader.isPresent(), "Failed to resolve %s", uri);
    shader.get().recompile();
    GLSLMaterial material = (GLSLMaterial) Assets.generateAsset(new ResourceUrn("engine:prog." + title), new MaterialData(shader.get()), Material.class);
    progamaticShaders.add(material);
    return material;
}
Also used : Material(org.terasology.rendering.assets.material.Material) GLSLMaterial(org.terasology.rendering.opengl.GLSLMaterial) MaterialData(org.terasology.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.assets.ResourceUrn) GLSLMaterial(org.terasology.rendering.opengl.GLSLMaterial)

Example 12 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class AmbientOcclusionNode method generateNoiseTexture.

private Texture generateNoiseTexture() {
    Optional<Texture> texture = Assets.getTexture("engine:ssaoNoise");
    if (!texture.isPresent()) {
        ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4);
        for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) {
            Vector3f noiseVector = new Vector3f(randomGenerator.nextFloat(-1.0f, 1.0f), randomGenerator.nextFloat(-1.0f, 1.0f), 0.0f);
            noiseVector.normalize();
            noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) 0x0);
        }
        noiseValues.flip();
        return Assets.generateAsset(new ResourceUrn("engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE, new ByteBuffer[] { noiseValues }, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class);
    }
    return texture.get();
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) Vector3f(org.terasology.math.geom.Vector3f) ResourceUrn(org.terasology.assets.ResourceUrn) Texture(org.terasology.rendering.assets.texture.Texture) DepthStencilTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.DepthStencilTexture) NormalsTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.NormalsTexture) ByteBuffer(java.nio.ByteBuffer)

Example 13 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class InteractionSystem method onScreenLayerClosed.

/**
 * The method listens for the event that the user closes the screen of the current interaction target.
 * <p>
 * When it happens then it cancels the interaction.
 */
@ReceiveEvent(components = { ClientComponent.class })
public void onScreenLayerClosed(ScreenLayerClosedEvent event, EntityRef container, ClientComponent clientComponent) {
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if ((activeInteractionScreenUri != null) && (activeInteractionScreenUri.equals(event.getClosedScreenUri()))) {
        InteractionUtil.cancelInteractionAsClient(clientComponent.character);
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 14 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class InteractionUtil method getActiveInteractionScreenUri.

/**
 * @return the active interaction screen uri of the specified character.
 * The method returns null if the player has no interaction screen open.
 * The method is only intended to be called for the own character.
 */
public static ResourceUrn getActiveInteractionScreenUri(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        return null;
    }
    EntityRef interactionTarget = characterComponent.predictedInteractionTarget;
    if (!interactionTarget.exists()) {
        return null;
    }
    InteractionScreenComponent screenComponent = interactionTarget.getComponent(InteractionScreenComponent.class);
    if (screenComponent == null) {
        return null;
    }
    return new ResourceUrn(screenComponent.screen);
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 15 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class AssetSuggester method suggest.

@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
    Map<String, Set<ResourceUrn>> resourceMap = Maps.newHashMap();
    Set<String> suggestions = Sets.newHashSet();
    for (ResourceUrn resolvedParameter : assetManager.getAvailableAssets(assetType)) {
        String resourceName = resolvedParameter.getResourceName().toString();
        if (!resourceMap.containsKey(resourceName)) {
            resourceMap.put(resourceName, Sets.newHashSet());
        }
        resourceMap.get(resourceName).add(resolvedParameter);
    }
    for (String key : resourceMap.keySet()) {
        Set<ResourceUrn> set = resourceMap.get(key);
        if (set.size() == 1) {
            suggestions.add(set.iterator().next().getResourceName().toString());
        } else {
            for (ResourceUrn resourceUrn : set) {
                suggestions.add(resourceUrn.toString());
            }
        }
    }
    return suggestions;
}
Also used : Set(java.util.Set) ResourceUrn(org.terasology.assets.ResourceUrn)

Aggregations

ResourceUrn (org.terasology.assets.ResourceUrn)65 Before (org.junit.Before)10 BlockFamilyDefinitionData (org.terasology.world.block.loader.BlockFamilyDefinitionData)10 AssetManager (org.terasology.assets.management.AssetManager)9 Prefab (org.terasology.entitySystem.prefab.Prefab)9 SymmetricBlockFamilyFactory (org.terasology.world.block.family.SymmetricBlockFamilyFactory)9 Command (org.terasology.logic.console.commandSystem.annotations.Command)8 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 PrefabData (org.terasology.entitySystem.prefab.PrefabData)7 BlockUri (org.terasology.world.block.BlockUri)7 Name (org.terasology.naming.Name)6 Texture (org.terasology.rendering.assets.texture.Texture)6 BlockManagerImpl (org.terasology.world.block.internal.BlockManagerImpl)6 NullWorldAtlas (org.terasology.world.block.tiles.NullWorldAtlas)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)5 SimpleUri (org.terasology.engine.SimpleUri)5 IOException (java.io.IOException)4 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)4 BiomeManager (org.terasology.world.biomes.BiomeManager)4