From d32f24f147068e6cbecb31c7f98047f68bc8b58a Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 21 Jul 2019 19:03:28 -0400
Subject: [PATCH] Embed texture.
---
CameraPane.java | 100 +++++++++++++++++++--------------
GroupEditor.java | 2
Object3D.java | 21 +++++++
3 files changed, 80 insertions(+), 43 deletions(-)
diff --git a/CameraPane.java b/CameraPane.java
index 1364b89..acc49b8 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -2405,6 +2405,45 @@
return currentGL;
}
+ private BufferedImage CreateBim(TextureData texturedata)
+ {
+ // cache to disk
+ Buffer buffer = texturedata.getBuffer(); // getMipmapData();
+ //buffers[0].
+ ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
+ int[] pixels = new int[bytebuf.capacity()/3];
+ int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
+ int height = width;
+ for (int i=pixels.length; --i>=0;)
+ {
+ int i3 = i*3;
+ pixels[i] = 0xFF;
+ pixels[i] <<= 8;
+ pixels[i] |= bytebuf.get(i3+2) & 0xFF;
+ pixels[i] <<= 8;
+ pixels[i] |= bytebuf.get(i3+1) & 0xFF;
+ pixels[i] <<= 8;
+ pixels[i] |= bytebuf.get(i3) & 0xFF;
+ }
+ /*
+ int r=0,g=0,b=0,a=0;
+ for (int i=0; i<width; i++)
+ for (int j=0; j<height; j++)
+ {
+ int index = j*width+i;
+ int p = pixels[index];
+ a = ((p>>24) & 0xFF);
+ r = ((p>>16) & 0xFF);
+ g = ((p>>8) & 0xFF);
+ b = (p & 0xFF);
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
+ }
+ /**/
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
+ return rendImage;
+ }
+
/**/
class CacheTexture
{
@@ -8308,9 +8347,9 @@
{
TextureData texturedata = null;
- if (bim == null)
+ if (bim != null)
{
-
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
}
else
if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
@@ -8329,6 +8368,8 @@
{
texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
}
+ else
+ new Exception().printStackTrace();
// }
} else
if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
@@ -8337,6 +8378,8 @@
texturecache = textures.get(tex);
if (texturecache == null)
texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
+ else
+ new Exception().printStackTrace();
} else
{
//if (tex.equals("IMMORTAL"))
@@ -8349,6 +8392,8 @@
texturecache = textures.get(tex);
if (texturecache == null)
texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
+ else
+ new Exception().printStackTrace();
} else
{
if (textureon)
@@ -8417,6 +8462,7 @@
if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
{
//return false;
+ assert(bim == null);
// System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
@@ -8436,52 +8482,17 @@
File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
if (!cachefile.exists())
{
- // cache to disk
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
- //buffers[0].
-
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
- int[] pixels = new int[bytebuf.capacity()/3];
-
- // squared size heuristic...
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
+ //if (texturedata.getWidth() == texturedata.getHeight())
{
- for (int i=pixels.length; --i>=0;)
- {
- int i3 = i*3;
- pixels[i] = 0xFF;
- pixels[i] <<= 8;
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
- pixels[i] <<= 8;
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
- pixels[i] <<= 8;
- pixels[i] |= bytebuf.get(i3) & 0xFF;
- }
-
- /*
- int r=0,g=0,b=0,a=0;
- for (int i=0; i<width; i++)
- for (int j=0; j<height; j++)
- {
- int index = j*width+i;
- int p = pixels[index];
- a = ((p>>24) & 0xFF);
- r = ((p>>16) & 0xFF);
- g = ((p>>8) & 0xFF);
- b = (p & 0xFF);
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
- }
- /**/
- int width = (int)Math.sqrt(pixels.length); // squared
- int height = width;
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
+ BufferedImage rendImage = CreateBim(texturedata);
+
ImageWriter writer = null;
Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
if (iter.hasNext()) {
writer = (ImageWriter)iter.next();
}
- float compressionQuality = 0.9f;
+
+ float compressionQuality = 0.85f;
try
{
ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
@@ -8528,6 +8539,11 @@
return texturecache;
}
+ static void EmbedTextures(cTexture tex)
+ {
+
+ }
+
com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
{
CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
diff --git a/GroupEditor.java b/GroupEditor.java
index ff6c98d..0372f78 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -3153,7 +3153,7 @@
for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
{
obj = (Object3D)e.nextElement();
- obj.SetBumpTexture(null);
+ obj.ResetBumpTexture();
}
refreshContents();
diff --git a/Object3D.java b/Object3D.java
index 0fe5ff5..2ccc4c6 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -5775,6 +5775,27 @@
}
}
+ void EmbedTextures()
+ {
+ if (blockloop)
+ return;
+
+ CameraPane.EmbedTextures(texture);
+
+ int nb = Size();
+ for (int i = 0; i < nb; i++)
+ {
+ Object3D child = (Object3D) get(i);
+
+ if (child == null)
+ continue;
+
+ blockloop = true;
+ child.EmbedTextures();
+ blockloop = false;
+ }
+ }
+
void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
{
Draw(display, root, selected, blocked);
--
Gitblit v1.6.2