use of com.ardor3d.image.Texture in project energy3d by concord-consortium.
the class TriangleMeshLib method createMeshes.
private static List<Mesh> createMeshes(final ArrayList<GroupData> groups) {
final List<Mesh> results = new ArrayList<Mesh>();
for (final GroupData group : groups) {
final Mesh mesh = new Mesh();
mesh.setUserData(group.key);
mesh.setModelBound(new BoundingBox());
results.add(mesh);
final FloatBuffer vertexBuffer = BufferUtils.createVector3Buffer(group.vertices.size());
mesh.getMeshData().setVertexBuffer(vertexBuffer);
for (final ReadOnlyVector3 v : group.vertices) {
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
}
final FloatBuffer normalBuffer = BufferUtils.createFloatBuffer(vertexBuffer.limit());
mesh.getMeshData().setNormalBuffer(normalBuffer);
for (final ReadOnlyVector3 v : group.normals) {
normalBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
}
if (!group.textures.isEmpty()) {
final FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(group.textures.size());
mesh.getMeshData().setTextureBuffer(textureBuffer, 0);
for (final ReadOnlyVector2 v : group.textures) {
textureBuffer.put(v.getXf()).put(v.getYf());
}
if (group.textureImage != null) {
final Texture texture = TextureManager.loadFromImage(group.textureImage, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat);
final TextureState ts = new TextureState();
ts.setTexture(texture);
mesh.setRenderState(ts);
}
}
mesh.updateModelBound();
}
return results;
}
use of com.ardor3d.image.Texture in project energy3d by concord-consortium.
the class HousePart method updateTextureAndColor.
protected void updateTextureAndColor(final Mesh mesh, final ReadOnlyColorRGBA defaultColor, final TextureMode textureMode) {
if (this instanceof Tree) {
// special treatment because the same mesh of a tree has two textures (shed or not)
final TextureState ts = new TextureState();
final Texture texture = getTexture(getTextureFileName(), textureMode == TextureMode.Simple, defaultColor, lockEdit);
ts.setTexture(texture);
mesh.setRenderState(ts);
} else {
if (SceneManager.getInstance().getSolarHeatMap()) {
if (isDrawable()) {
if (this instanceof Foundation || this instanceof Wall || this instanceof Roof || this instanceof Floor) {
SolarRadiation.getInstance().initMeshTextureData(mesh, mesh, this instanceof Roof ? (ReadOnlyVector3) mesh.getParent().getUserData() : getNormal());
}
}
} else if (textureMode == TextureMode.None || getTextureFileName() == null) {
mesh.clearRenderState(StateType.Texture);
mesh.setDefaultColor(defaultColor);
} else {
final TextureState ts = new TextureState();
final Texture texture = getTexture(getTextureFileName(), textureMode == TextureMode.Simple, defaultColor, false);
ts.setTexture(texture);
mesh.setRenderState(ts);
mesh.setDefaultColor(ColorRGBA.WHITE);
}
}
}
use of com.ardor3d.image.Texture in project energy3d by concord-consortium.
the class HousePart method getTexture.
private Texture getTexture(final String filename, final boolean isTransparent, final ReadOnlyColorRGBA defaultColor, final boolean grayout) {
Texture texture = TextureManager.load(filename, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat, true);
if (isTransparent) {
final Color color = new Color(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue());
final Image image = texture.getImage();
final ByteBuffer data = image.getData(0);
byte alpha;
int i;
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
i = (y * image.getWidth() + x) * 4;
alpha = data.get(i + 3);
if (alpha == 0) {
// when it is transparent, put the default color of the part
data.put(i, (byte) color.getRed());
data.put(i + 1, (byte) color.getGreen());
data.put(i + 2, (byte) color.getBlue());
}
}
}
texture.setImage(image);
}
if (grayout) {
final Texture grayoutTexture = cachedGrayTextures.get(filename + ":grayout");
if (grayoutTexture != null) {
return grayoutTexture;
}
final Image image = texture.getImage();
// make a copy
final Image grayImage = new Image();
grayImage.setDataFormat(image.getDataFormat());
grayImage.setDataType(image.getDataType());
grayImage.setWidth(image.getWidth());
grayImage.setHeight(image.getHeight());
grayImage.setMipMapByteSizes(image.getMipMapByteSizes());
final ByteBuffer data = image.getData(0);
final ByteBuffer grayData = ByteBuffer.allocate(data.capacity());
byte alpha, red, green, blue, gray;
int i;
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
i = (y * image.getWidth() + x) * 4;
red = data.get(i);
green = data.get(i + 1);
blue = data.get(i + 2);
alpha = data.get(i + 3);
gray = (byte) Math.min(red, green);
gray = (byte) Math.min(blue, gray);
grayData.put(i, gray);
grayData.put(i + 1, gray);
grayData.put(i + 2, gray);
grayData.put(i + 3, alpha);
}
}
grayImage.addData(grayData);
texture = TextureManager.loadFromImage(grayImage, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat);
cachedGrayTextures.put(filename + ":grayout", texture);
}
return texture;
}
Aggregations