use of org.terasology.rendering.assets.mesh.Mesh in project Terasology by MovingBlocks.
the class Tessellator method generateMesh.
public Mesh generateMesh(ResourceUrn urn) {
Preconditions.checkNotNull(urn);
Mesh result = Assets.generateAsset(urn, meshData, Mesh.class);
meshData = new MeshData();
return result;
}
use of org.terasology.rendering.assets.mesh.Mesh in project Terasology by MovingBlocks.
the class Tessellator method generateMesh.
public Mesh generateMesh() {
Mesh result = Assets.generateAsset(meshData, Mesh.class);
meshData = new MeshData();
return result;
}
use of org.terasology.rendering.assets.mesh.Mesh in project Terasology by MovingBlocks.
the class FloatingTextRenderer method render.
private void render(Iterable<EntityRef> floatingTextEntities) {
Vector3f cameraPosition = camera.getPosition();
for (EntityRef entity : floatingTextEntities) {
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null) {
continue;
}
Vector3f worldPos = location.getWorldPosition();
if (!worldProvider.isBlockRelevant(worldPos)) {
continue;
}
FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
String[] linesOfText = floatingText.text.split("\n");
Color baseColor = floatingText.textColor;
Color shadowColor = floatingText.textShadowColor;
boolean underline = false;
int textWidth = 0;
for (String singleLine : linesOfText) {
if (font.getWidth(singleLine) > textWidth) {
textWidth = font.getWidth(singleLine);
}
}
FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
if (meshMap == null) {
meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
entityMeshCache.put(entity, meshMap);
}
if (floatingText.isOverlay) {
glDisable(GL_DEPTH_TEST);
}
glPushMatrix();
float scale = METER_PER_PIXEL * floatingText.scale;
glTranslated(worldPos.x - cameraPosition.x, worldPos.y - cameraPosition.y, worldPos.z - cameraPosition.z);
OpenGLUtils.applyBillboardOrientation();
glScaled(scale, -scale, scale);
glTranslated(-textWidth / 2.0, 0.0, 0.0);
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
Material material = meshMapEntry.getKey();
material.enable();
material.bindTextures();
material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
material.setFloat2("offset", 0.0f, 0.0f);
material.setFloat("alpha", 1.0f);
mesh.render();
}
glPopMatrix();
// Revert to default state
if (floatingText.isOverlay) {
glEnable(GL_DEPTH_TEST);
}
}
}
use of org.terasology.rendering.assets.mesh.Mesh in project Terasology by MovingBlocks.
the class FloatingTextRenderer method diposeMeshMap.
private void diposeMeshMap(Map<Material, Mesh> meshMap) {
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
mesh.dispose();
// Note: Material belongs to font and must not be disposed
}
}
use of org.terasology.rendering.assets.mesh.Mesh in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method drawTextureBordered.
@Override
public void drawTextureBordered(TextureRegion texture, Rect2i region, Border border, boolean tile, float ux, float uy, float uw, float uh, float alpha) {
if (!texture.getTexture().isLoaded()) {
return;
}
if (!currentTextureCropRegion.equals(requestedCropRegion) && !(currentTextureCropRegion.contains(region) && requestedCropRegion.contains(region))) {
textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY());
currentTextureCropRegion = requestedCropRegion;
}
Vector2i textureSize = new Vector2i(TeraMath.ceilToInt(texture.getWidth() * uw), TeraMath.ceilToInt(texture.getHeight() * uh));
TextureCacheKey key = new TextureCacheKey(textureSize, region.size(), border, tile);
usedTextures.add(key);
Mesh mesh = cachedTextures.get(key);
if (mesh == null || mesh.isDisposed()) {
MeshBuilder builder = new MeshBuilder();
float topTex = (float) border.getTop() / textureSize.y;
float leftTex = (float) border.getLeft() / textureSize.x;
float bottomTex = 1f - (float) border.getBottom() / textureSize.y;
float rightTex = 1f - (float) border.getRight() / textureSize.x;
int centerHoriz = region.width() - border.getTotalWidth();
int centerVert = region.height() - border.getTotalHeight();
float top = (float) border.getTop() / region.height();
float left = (float) border.getLeft() / region.width();
float bottom = 1f - (float) border.getBottom() / region.height();
float right = 1f - (float) border.getRight() / region.width();
if (border.getTop() != 0) {
if (border.getLeft() != 0) {
addRectPoly(builder, 0, 0, left, top, 0, 0, leftTex, topTex);
}
if (tile) {
addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), 0, centerHoriz, border.getTop()), Rect2f.createFromMinAndMax(left, 0, right, top), new Vector2i(textureSize.x - border.getTotalWidth(), border.getTop()), Rect2f.createFromMinAndMax(leftTex, 0, rightTex, topTex));
} else {
addRectPoly(builder, left, 0, right, top, leftTex, 0, rightTex, topTex);
}
if (border.getRight() != 0) {
addRectPoly(builder, right, 0, 1, top, rightTex, 0, 1, topTex);
}
}
if (border.getLeft() != 0) {
if (tile) {
addTiles(builder, Rect2i.createFromMinAndSize(0, border.getTop(), border.getLeft(), centerVert), Rect2f.createFromMinAndMax(0, top, left, bottom), new Vector2i(border.getLeft(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(0, topTex, leftTex, bottomTex));
} else {
addRectPoly(builder, 0, top, left, bottom, 0, topTex, leftTex, bottomTex);
}
}
if (tile) {
addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), border.getTop(), centerHoriz, centerVert), Rect2f.createFromMinAndMax(left, top, right, bottom), new Vector2i(textureSize.x - border.getTotalWidth(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(leftTex, topTex, rightTex, bottomTex));
} else {
addRectPoly(builder, left, top, right, bottom, leftTex, topTex, rightTex, bottomTex);
}
if (border.getRight() != 0) {
if (tile) {
addTiles(builder, Rect2i.createFromMinAndSize(region.width() - border.getRight(), border.getTop(), border.getRight(), centerVert), Rect2f.createFromMinAndMax(right, top, 1, bottom), new Vector2i(border.getRight(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(rightTex, topTex, 1, bottomTex));
} else {
addRectPoly(builder, right, top, 1, bottom, rightTex, topTex, 1, bottomTex);
}
}
if (border.getBottom() != 0) {
if (border.getLeft() != 0) {
addRectPoly(builder, 0, bottom, left, 1, 0, bottomTex, leftTex, 1);
}
if (tile) {
addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), region.height() - border.getBottom(), centerHoriz, border.getBottom()), Rect2f.createFromMinAndMax(left, bottom, right, 1), new Vector2i(textureSize.x - border.getTotalWidth(), border.getBottom()), Rect2f.createFromMinAndMax(leftTex, bottomTex, rightTex, 1));
} else {
addRectPoly(builder, left, bottom, right, 1, leftTex, bottomTex, rightTex, 1);
}
if (border.getRight() != 0) {
addRectPoly(builder, right, bottom, 1, 1, rightTex, bottomTex, 1, 1);
}
}
mesh = builder.build();
cachedTextures.put(key, mesh);
}
textureMat.setFloat2("scale", region.width(), region.height());
textureMat.setFloat2("offset", region.minX(), region.minY());
Rect2f textureArea = texture.getRegion();
textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height());
textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height());
textureMat.setTexture("texture", texture.getTexture());
textureMat.setFloat4("color", 1, 1, 1, alpha);
textureMat.bindTextures();
mesh.render();
}
Aggregations