Search in sources :

Example 1 with TextureRegionAsset

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

the class IconMeshDataProducer method getAssetData.

@Override
public Optional<MeshData> getAssetData(ResourceUrn urn) throws IOException {
    if (ICON_DISCRIMINATOR.equals(urn.getResourceName())) {
        ResourceUrn textureUrn = new ResourceUrn(urn.getModuleName().toString() + ResourceUrn.RESOURCE_SEPARATOR + urn.getFragmentName().toString());
        Optional<TextureRegionAsset> textureRegionAsset = assetManager.getAsset(textureUrn, TextureRegionAsset.class);
        if (textureRegionAsset.isPresent() && !textureRegionAsset.get().getTexture().isDisposed()) {
            return Optional.of(IconMeshFactory.generateIconMeshData(textureRegionAsset.get()));
        }
    }
    return Optional.empty();
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) TextureRegionAsset(org.terasology.rendering.assets.texture.TextureRegionAsset)

Example 2 with TextureRegionAsset

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

the class BlockDamageRenderer method renderOverlay.

@Override
public void renderOverlay() {
    if (blockSelectionRenderer == null) {
        Texture texture = Assets.getTextureRegion("core:blockdamageeffects#1").get().getTexture();
        blockSelectionRenderer = new BlockSelectionRenderer(texture);
    }
    // group the entities into what texture they will use so that there is less recreating meshes (changing a texture region on the BlockSelectionRenderer
    // will recreate the mesh to use the different UV coordinates).  Also this allows
    Multimap<Integer, Vector3i> groupedEntitiesByEffect = ArrayListMultimap.create();
    for (EntityRef entity : entityManager.getEntitiesWith(HealthComponent.class, BlockComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
        groupedEntitiesByEffect.put(getEffectsNumber(health), blockComponent.getPosition());
    }
    for (EntityRef entity : entityManager.getEntitiesWith(BlockRegionComponent.class, HealthComponent.class)) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health.currentHealth == health.maxHealth) {
            continue;
        }
        BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
        for (Vector3i blockPos : blockRegion.region) {
            groupedEntitiesByEffect.put(getEffectsNumber(health), blockPos);
        }
    }
    // we know that the texture will be the same for each block effect,  just differnt UV coordinates.  Bind the texture already
    blockSelectionRenderer.beginRenderOverlay();
    for (Integer effectsNumber : groupedEntitiesByEffect.keySet()) {
        Optional<TextureRegionAsset> texture = Assets.getTextureRegion("core:blockdamageeffects#" + effectsNumber);
        if (texture.isPresent()) {
            blockSelectionRenderer.setEffectsTexture(texture.get());
            for (Vector3i position : groupedEntitiesByEffect.get(effectsNumber)) {
                blockSelectionRenderer.renderMark(position);
            }
        }
    }
    blockSelectionRenderer.endRenderOverlay();
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) Vector3i(org.terasology.math.geom.Vector3i) BlockSelectionRenderer(org.terasology.rendering.world.selection.BlockSelectionRenderer) Texture(org.terasology.rendering.assets.texture.Texture) EntityRef(org.terasology.entitySystem.entity.EntityRef) TextureRegionAsset(org.terasology.rendering.assets.texture.TextureRegionAsset)

Aggregations

TextureRegionAsset (org.terasology.rendering.assets.texture.TextureRegionAsset)2 ResourceUrn (org.terasology.assets.ResourceUrn)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 Vector3i (org.terasology.math.geom.Vector3i)1 Texture (org.terasology.rendering.assets.texture.Texture)1 BlockSelectionRenderer (org.terasology.rendering.world.selection.BlockSelectionRenderer)1 BlockComponent (org.terasology.world.block.BlockComponent)1 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)1