S3DBLayer: use transparency of extrusion style (#556)
This commit is contained in:
parent
c0efc78d37
commit
981af11011
@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* Copyright 2018 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
@ -115,6 +116,22 @@ public final class Color {
|
||||
return ((color) & 0xff);
|
||||
}
|
||||
|
||||
public static int setA(int color, int a) {
|
||||
return ((a << 24) | (color & 0xffffff));
|
||||
}
|
||||
|
||||
public static int setR(int color, int r) {
|
||||
return ((r << 16) | (color & 0xff00ffff));
|
||||
}
|
||||
|
||||
public static int setG(int color, int g) {
|
||||
return ((g << 8) | (color & 0xffff00ff));
|
||||
}
|
||||
|
||||
public static int setB(int color, int b) {
|
||||
return (b | (color & 0xffffff00));
|
||||
}
|
||||
|
||||
public static int parseColorComponents(String str) {
|
||||
int numComponents = 4;
|
||||
int cur = 5;
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.oscim.layers.tile.buildings;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.Box;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapElement;
|
||||
@ -45,6 +46,7 @@ public class S3DBLayer extends BuildingLayer {
|
||||
private final float TILE_SCALE = (ExtrusionUtils.REF_TILE_SIZE / (Tile.SIZE * COORD_SCALE));
|
||||
|
||||
private boolean mColored = true;
|
||||
private boolean mTransparent = true;
|
||||
|
||||
public S3DBLayer(Map map, VectorTileLayer tileLayer) {
|
||||
this(map, tileLayer, MIN_ZOOM, map.viewport().getMaxZoomLevel());
|
||||
@ -62,6 +64,17 @@ public class S3DBLayer extends BuildingLayer {
|
||||
mColored = colored;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return mTransparent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transparent if true it adopts transparency of extrusion styles
|
||||
*/
|
||||
public void setTransparent(boolean transparent) {
|
||||
mTransparent = transparent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(MapTile tile, boolean success) {
|
||||
super.complete(tile, success);
|
||||
@ -137,6 +150,9 @@ public class S3DBLayer extends BuildingLayer {
|
||||
|
||||
if (bColor == null) {
|
||||
bColor = extrusion.colorTop;
|
||||
} else if (mTransparent) {
|
||||
// Multiply alpha channel of extrusion style
|
||||
bColor = ExtrusionStyle.blendAlpha(bColor, Color.aToFloat(extrusion.colorTop));
|
||||
}
|
||||
|
||||
// Scale x, y and z axis
|
||||
@ -238,9 +254,14 @@ public class S3DBLayer extends BuildingLayer {
|
||||
|
||||
GeometryBuffer gElement = new GeometryBuffer(element);
|
||||
GeometryBuffer specialParts = null;
|
||||
if (roofColor == null) roofColor = buildingColor;
|
||||
boolean success = false;
|
||||
if (roofColor == null)
|
||||
roofColor = buildingColor;
|
||||
else if (mTransparent) {
|
||||
// For simplicity use transparency of building, which is identical in nearly all cases
|
||||
roofColor = ExtrusionStyle.blendAlpha(roofColor, Color.aToFloat(buildingColor));
|
||||
}
|
||||
|
||||
boolean success;
|
||||
switch (v) {
|
||||
case Tag.VALUE_DOME:
|
||||
case Tag.VALUE_ONION:
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2017 devemux86
|
||||
* Copyright 2018 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -56,6 +57,20 @@ public class ExtrusionStyle extends RenderStyle<ExtrusionStyle> {
|
||||
this.defaultHeight = b.defaultHeight;
|
||||
}
|
||||
|
||||
public static int blendAlpha(int color, float alpha) {
|
||||
if (alpha == 1.0f)
|
||||
return color;
|
||||
return Color.setA(color, (int) (Color.a(color) * alpha));
|
||||
}
|
||||
|
||||
public static void blendAlpha(float colors[], float alpha) {
|
||||
if (alpha == 1.0f)
|
||||
return;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = alpha * colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static void fillColors(int side, int top, int line, float[] colors) {
|
||||
float a = Color.aToFloat(top);
|
||||
colors[0] = a * Color.rToFloat(top);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user