mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
PShapeSVG to GLModel tesselation is working
This commit is contained in:
@@ -64,6 +64,9 @@ public interface GLConstants {
|
||||
public static final int DYNAMIC = 1;
|
||||
|
||||
|
||||
/**
|
||||
* Used in GLModels..
|
||||
*/
|
||||
public static final int VERTICES = 0;
|
||||
public static final int NORMALS = 1;
|
||||
public static final int COLORS = 2;
|
||||
|
||||
@@ -76,7 +76,10 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
protected int recreateResourceIdx;
|
||||
|
||||
public float depth;
|
||||
|
||||
protected float xmin, xmax;
|
||||
protected float ymin, ymax;
|
||||
protected float zmin, zmax;
|
||||
|
||||
protected static final int SIZEOF_FLOAT = Float.SIZE / 8;
|
||||
|
||||
|
||||
@@ -126,6 +129,10 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
createModel(numVert);
|
||||
initGroups();
|
||||
updateElement = -1;
|
||||
|
||||
width = height = depth = 0;
|
||||
xmin = ymin = zmin = 10000;
|
||||
xmax = ymax = zmax = -10000;
|
||||
|
||||
try {
|
||||
Method meth = this.getClass().getMethod("recreateResource", new Class[] { PGraphicsAndroid3D.class });
|
||||
@@ -362,9 +369,10 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
grIdx1 = idx;
|
||||
}
|
||||
|
||||
updateBounds(x, y, z);
|
||||
vertexArray[3 * idx + 0] = x;
|
||||
vertexArray[3 * idx + 1] = y;
|
||||
vertexArray[3 * idx + 2] = z;
|
||||
vertexArray[3 * idx + 2] = z;
|
||||
}
|
||||
|
||||
|
||||
@@ -381,6 +389,10 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
grIdx1 = numVertices - 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numVertices; i++) {
|
||||
updateBounds(data[3 * i + 0], data[3 * i + 1], data[3 * i + 2]);
|
||||
}
|
||||
|
||||
PApplet.arrayCopy(data, vertexArray);
|
||||
}
|
||||
|
||||
@@ -404,9 +416,25 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
vertexArray[3 * i + 0] = vec.x;
|
||||
vertexArray[3 * i + 1] = vec.y;
|
||||
vertexArray[3 * i + 2] = vec.z;
|
||||
updateBounds(vec.x, vec.y, vec.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void updateBounds(float x, float y, float z) {
|
||||
xmin = PApplet.min(xmin, x);
|
||||
xmax = PApplet.max(xmax, x);
|
||||
|
||||
ymin = PApplet.min(ymin, y);
|
||||
ymax = PApplet.max(ymax, y);
|
||||
|
||||
zmin = PApplet.min(zmin, z);
|
||||
zmax = PApplet.max(zmax, z);
|
||||
|
||||
width = xmax - xmin;
|
||||
height = ymax - ymin;
|
||||
depth = zmax - zmin;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1296,42 +1324,31 @@ public class GLModel extends PShape implements GLConstants, PConstants {
|
||||
|
||||
// Methods inherited from PShape.
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public float getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void draw(PGraphics g) {
|
||||
render();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// Rendering methods
|
||||
// Drawing methods
|
||||
|
||||
public void render() {
|
||||
render(0, groups.size() - 1);
|
||||
public void draw(PGraphics g) {
|
||||
draw(g, 0, groups.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
public void render(int gr) {
|
||||
render(gr, gr);
|
||||
public void draw(PGraphics g, int gr) {
|
||||
draw(g, gr, gr);
|
||||
}
|
||||
|
||||
|
||||
public void render(int gr0, int gr1) {
|
||||
public void draw(PGraphics g, int gr0, int gr1) {
|
||||
int texTarget = GL11.GL_TEXTURE_2D;
|
||||
GLTexture tex;
|
||||
float pointSize;
|
||||
|
||||
@@ -3012,7 +3012,6 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
return new PShapeSVG(this, filename);
|
||||
} else if (filename.toLowerCase().endsWith(".obj")) {
|
||||
if (g instanceof PGraphicsAndroid3D) {
|
||||
// TODO: implement obj loading for GLModels
|
||||
return new GLModel(this, filename);
|
||||
} else {
|
||||
throw new RuntimeException("OBJ files can be loaded only when using the A3D renderer.");
|
||||
@@ -3022,10 +3021,14 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
}
|
||||
|
||||
|
||||
public PShape createShape(int nvert) {
|
||||
public PShape createShape(int nvert, int kind) {
|
||||
return this.createShape(nvert, kind, GLConstants.STATIC);
|
||||
}
|
||||
|
||||
|
||||
public PShape createShape(int nvert, int kind, int mode) {
|
||||
if (g instanceof PGraphicsAndroid3D) {
|
||||
// TODO: how to handle custom parameters?
|
||||
GLModel.Parameters params = GLModel.newParameters(TRIANGLES, GLConstants.STATIC);
|
||||
GLModel.Parameters params = GLModel.newParameters(kind, GLConstants.STATIC);
|
||||
GLModel model = new GLModel(this, nvert, params);
|
||||
return model;
|
||||
} else {
|
||||
@@ -3033,6 +3036,19 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PShape createShape(PShape shape) {
|
||||
if (g instanceof PGraphicsAndroid3D) {
|
||||
PGraphicsAndroid3D a3d = (PGraphicsAndroid3D)g;
|
||||
a3d.beginShapeRecorderImpl();
|
||||
shape(shape, 0, 0, 1, 1);
|
||||
GLModel model = a3d.endShapeRecorderImpl();
|
||||
return model;
|
||||
} else {
|
||||
throw new RuntimeException("3D PShapes can only be created when using the A3D renderer.");
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// FONT I/O
|
||||
|
||||
@@ -290,9 +290,9 @@ public interface PConstants {
|
||||
static final int SPHERE = 40;
|
||||
static final int BOX = 41;
|
||||
|
||||
static public final int LINE_STRIP = 50;
|
||||
static public final int LINE_LOOP = 51;
|
||||
static public final int POINT_SPRITES = 52;
|
||||
static public final int LINE_STRIP = 50;
|
||||
static public final int LINE_LOOP = 51;
|
||||
static public final int POINT_SPRITES = 52;
|
||||
|
||||
|
||||
// shape closing modes
|
||||
|
||||
@@ -630,21 +630,26 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
|
||||
|
||||
//public void beginShape()
|
||||
|
||||
|
||||
|
||||
public void beginShapeRecorder() {
|
||||
beginShapeRecorder(POLYGON);
|
||||
}
|
||||
|
||||
|
||||
public void beginShapeRecorder(int kind) {
|
||||
beginShapeRecorderImpl();
|
||||
beginShape(kind);
|
||||
}
|
||||
|
||||
|
||||
protected void beginShapeRecorderImpl() {
|
||||
recordingModel = true;
|
||||
recordedVertices = new ArrayList<PVector>(vertexBuffer.capacity() / 3);
|
||||
recordedColors = new ArrayList<float[]>(colorBuffer.capacity() / 4);
|
||||
recordedNormals = new ArrayList<PVector>(normalBuffer.capacity() / 4);
|
||||
recordedTexCoords = new ArrayList<PVector>(texCoordBuffer.capacity() / 2);
|
||||
recordedGroups = new ArrayList<VertexGroup>();
|
||||
beginShape(kind);
|
||||
recordedGroups = new ArrayList<VertexGroup>();
|
||||
}
|
||||
|
||||
|
||||
@@ -959,31 +964,38 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
|
||||
public GLModel endShapeRecorder(int mode) {
|
||||
endShape(mode);
|
||||
|
||||
recordingModel = false;
|
||||
GLModel model = new GLModel(parent, recordedVertices.size());
|
||||
|
||||
model.beginUpdate(GLConstants.VERTICES);
|
||||
model.setVertex(recordedVertices);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.COLORS);
|
||||
model.setColor(recordedColors);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.NORMALS);
|
||||
model.setNormal(recordedNormals);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.TEXTURES);
|
||||
model.setTexCoord(recordedTexCoords);
|
||||
model.endUpdate();
|
||||
|
||||
model.setGroups(recordedGroups);
|
||||
return model;
|
||||
return endShapeRecorderImpl();
|
||||
}
|
||||
|
||||
|
||||
protected GLModel endShapeRecorderImpl() {
|
||||
recordingModel = false;
|
||||
if (0 < recordedVertices.size()) {
|
||||
GLModel model = new GLModel(parent, recordedVertices.size());
|
||||
|
||||
model.beginUpdate(GLConstants.VERTICES);
|
||||
model.setVertex(recordedVertices);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.COLORS);
|
||||
model.setColor(recordedColors);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.NORMALS);
|
||||
model.setNormal(recordedNormals);
|
||||
model.endUpdate();
|
||||
|
||||
model.beginUpdate(GLConstants.TEXTURES);
|
||||
model.setTexCoord(recordedTexCoords);
|
||||
model.endUpdate();
|
||||
|
||||
model.setGroups(recordedGroups);
|
||||
return model;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// BEZIER CURVE VERTICES
|
||||
@@ -1704,19 +1716,6 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
|
||||
|
||||
//protected void sort()
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// MODEL, SHAPE
|
||||
|
||||
|
||||
public void model(GLModel model, float x, float y, float z) {
|
||||
gl.glPushMatrix();
|
||||
gl.glTranslatef(x, y, z);
|
||||
model.render();
|
||||
gl.glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user