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;
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations