From 50c188f6bbecadff7ddd6276b3c32826d3d09e3e Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 9 May 2010 03:41:03 +0000 Subject: [PATCH] Fixed texturing and coloring in OBJ loading (PShape3D) --- .../processing/core/PGraphicsAndroid3D.java | 7 +++---- .../core/src/processing/core/PShape3D.java | 20 +++++++++++++++++-- .../core/src/processing/core/PTexture.java | 3 +-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index d719dd077..86bd9566f 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -56,9 +56,8 @@ import processing.core.PShape3D.VertexGroup; * By Andres Colubri * * TODO: Comment A3D, PShape3D and PTexture, - * TODO: Check lighting and materials, specially in PShape3D.. + * TODO: Check lighting and materials. * TODO: Revise triangulator (issues are particularly apparent when tesselating SVG shapes). - * TODO: Optimize Vertex Array rendering on real N1 hardware. */ public class PGraphicsAndroid3D extends PGraphics { public SurfaceHolder holder; @@ -456,7 +455,7 @@ public class PGraphicsAndroid3D extends PGraphics { protected void drawScreenTexture() { - // TODO: try using glDrawTexiOES + // TODO: try using glDrawTexiOES maybe? tint(255); fill(255); int w = 256; @@ -3652,7 +3651,7 @@ public class PGraphicsAndroid3D extends PGraphics { /** - * Switches off all lights, but keeps lighting enabled.. + * Switches off all lights, but keeps lighting enabled. * TODO: discuss if this method is needed. */ public void resetLights() { diff --git a/android/core/src/processing/core/PShape3D.java b/android/core/src/processing/core/PShape3D.java index 0542fb08e..2700bf04e 100644 --- a/android/core/src/processing/core/PShape3D.java +++ b/android/core/src/processing/core/PShape3D.java @@ -100,7 +100,6 @@ public class PShape3D extends PShape implements PConstants { } - // TODO: Properly debug OBJ loading. Particuarly when loading textured materials. public PShape3D(PApplet parent, String filename, int mode) { this.parent = parent; a3d = (PGraphicsAndroid3D)parent.g; @@ -1313,7 +1312,7 @@ public class PShape3D extends PShape implements PConstants { * the data already stored in it by copying to the beginning of the * new buffers. * - * TODO: Test!. + * TODO: Test! * */ public void resize(int numVert) { @@ -2187,6 +2186,15 @@ public class PShape3D extends PShape implements PConstants { protected void recordOBJ(ArrayList vertices, ArrayList normals, ArrayList textures, ArrayList faces, ArrayList materials) { int mtlIdxCur = -1; OBJMaterial mtl = null; + + // Using normal mode for texture coordinates (i.e.: normalized between 0 and 1). + int tMode0 = a3d.textureMode; + a3d.textureMode = NORMAL; + + // Using RGB mode for coloring. + int cMode0 = a3d.colorMode; + a3d.colorMode = RGB; + a3d.beginShapeRecorderImpl(); for (int i = 0; i < faces.size(); i++) { OBJFace face = (OBJFace) faces.get(i); @@ -2202,6 +2210,11 @@ public class PShape3D extends PShape implements PConstants { a3d.ambient(mtl.ka.x * 255.0f, mtl.ka.y * 255.0f, mtl.ka.z * 255.0f); a3d.fill(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); a3d.shininess(mtl.ns); + + if (mtl.kdMap != null) { + // If current material is textured, then tinting the texture using the diffuse color. + a3d.tint(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); + } } // Recording current face. @@ -2272,6 +2285,9 @@ public class PShape3D extends PShape implements PConstants { xmax = ymax = zmax = -10000; a3d.endShapeRecorderImpl(this); + + a3d.textureMode = tMode0; + a3d.colorMode = cMode0; } diff --git a/android/core/src/processing/core/PTexture.java b/android/core/src/processing/core/PTexture.java index 05c7d54a2..956aea55d 100644 --- a/android/core/src/processing/core/PTexture.java +++ b/android/core/src/processing/core/PTexture.java @@ -37,8 +37,7 @@ import java.nio.*; * By Andres Colubri * TODO: Finish integration with PImage * TODO: Revise updating mechanism (what happens when the pixels change in the PImage, etc). - * TODO: Find alternative for FOBs or how to expose FBO functionality in N1 and other EGL2 phones. - * TODO: + * TODO: Find alternative for FOBs or how to expose FBO functionality in N1 and other EGL2 phones. */ @SuppressWarnings("unused") public class PTexture implements PConstants {