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