use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.
the class FontMaterialProducer method getAssetData.
@Override
public Optional<MaterialData> getAssetData(ResourceUrn urn) throws IOException {
if (RESOURCE_NAME.equals(urn.getResourceName()) && !urn.getFragmentName().isEmpty()) {
Optional<? extends Shader> fontShader = assetManager.getAsset(FONT_SHADER_URN, Shader.class);
if (!fontShader.isPresent()) {
logger.error("Unable to resolve font shader");
return Optional.empty();
}
Optional<Texture> texture = assetManager.getAsset(new ResourceUrn(urn.getModuleName(), urn.getFragmentName()), Texture.class);
if (texture.isPresent()) {
MaterialData materialData = new MaterialData(fontShader.get());
materialData.setParam("texture", texture.get());
return Optional.of(materialData);
}
}
return Optional.empty();
}
use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.
the class LwjglGraphics method registerCoreAssetTypes.
@Override
public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.registerCoreAssetType(Font.class, (AssetFactory<Font, FontData>) FontImpl::new, "fonts");
assetTypeManager.registerCoreAssetType(Texture.class, (AssetFactory<Texture, TextureData>) (urn, assetType, data) -> (new OpenGLTexture(urn, assetType, data, this)), "textures", "fonts");
assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> {
if (path.getName(1).toString().equals(ModuleAssetDataProducer.OVERRIDE_FOLDER)) {
return path.getName(3).toString().equals("textures");
} else {
return path.getName(2).toString().equals("textures");
}
}));
assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> {
if (path.getName(1).toString().equals(ModuleAssetDataProducer.OVERRIDE_FOLDER)) {
return path.getName(3).toString().equals("fonts");
} else {
return path.getName(2).toString().equals("fonts");
}
}));
assetTypeManager.registerCoreAssetType(Shader.class, (AssetFactory<Shader, ShaderData>) GLSLShader::new, "shaders");
assetTypeManager.registerCoreAssetType(Material.class, (AssetFactory<Material, MaterialData>) GLSLMaterial::new, "materials");
assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>) (urn, assetType, data) -> new OpenGLMesh(urn, assetType, bufferPool, data), "mesh");
assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>) (urn, assetType, data) -> new OpenGLSkeletalMesh(urn, assetType, data, bufferPool), "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 HeadlessEnvironment method setupAssetManager.
@Override
protected AssetManager setupAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, false, "prefabs");
assetTypeManager.registerCoreAssetType(BlockShape.class, (AssetFactory<BlockShape, BlockShapeData>) BlockShapeImpl::new, "shapes");
assetTypeManager.registerCoreAssetType(BlockSounds.class, (AssetFactory<BlockSounds, BlockSoundsData>) BlockSounds::new, "blockSounds");
assetTypeManager.registerCoreAssetType(BlockTile.class, (AssetFactory<BlockTile, TileData>) BlockTile::new, "blockTiles");
assetTypeManager.registerCoreAssetType(BlockFamilyDefinition.class, (AssetFactory<BlockFamilyDefinition, BlockFamilyDefinitionData>) BlockFamilyDefinition::new, "blocks");
assetTypeManager.registerCoreAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.registerCoreAssetType(StreamingSound.class, NullStreamingSound::new, "music");
DefaultBlockFamilyFactoryRegistry blockFamilyFactoryRegistry = new DefaultBlockFamilyFactoryRegistry();
blockFamilyFactoryRegistry.setBlockFamilyFactory("horizontal", new HorizontalBlockFamilyFactory());
blockFamilyFactoryRegistry.setBlockFamilyFactory("alignToSurface", new AttachedToSurfaceFamilyFactory());
assetTypeManager.registerCoreFormat(BlockFamilyDefinition.class, new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager(), blockFamilyFactoryRegistry));
assetTypeManager.registerCoreAssetType(UISkin.class, (AssetFactory<UISkin, UISkinData>) UISkin::new, "skins");
assetTypeManager.registerCoreAssetType(BehaviorTree.class, (AssetFactory<BehaviorTree, BehaviorTreeData>) BehaviorTree::new, false, "behaviors");
assetTypeManager.registerCoreAssetType(UIElement.class, (AssetFactory<UIElement, UIData>) UIElement::new, "ui");
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);
assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
context.put(AssetManager.class, assetTypeManager.getAssetManager());
return assetTypeManager.getAssetManager();
}
use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.
the class HeightMapSurfaceHeightProvider method reloadHeightmap.
private void reloadHeightmap() {
logger.info("Reading height map '{}'", configuration.heightMap);
ResourceUrn urn = new ResourceUrn("core", configuration.heightMap);
Texture texture = Assets.getTexture(urn).get();
ByteBuffer[] bb = texture.getData().getBuffers();
IntBuffer intBuf = bb[0].asIntBuffer();
mapWidth = texture.getWidth();
mapHeight = texture.getHeight();
heightmap = new float[mapWidth][mapHeight];
while (intBuf.position() < intBuf.limit()) {
int pos = intBuf.position();
long val = intBuf.get() & 0xFFFFFFFFL;
heightmap[pos % mapWidth][pos / mapWidth] = val / (256 * 256 * 256 * 256f);
}
}
use of org.terasology.rendering.assets.texture.Texture 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();
}
Aggregations