From 6857d776ee3d1a3e113e33aa535d1ca7cc3d89ed Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 26 Oct 2011 05:41:47 +0000 Subject: [PATCH] copy geometry to root shape --- .../src/processing/opengl/PShape3D.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/java/libraries/opengl/src/processing/opengl/PShape3D.java b/java/libraries/opengl/src/processing/opengl/PShape3D.java index bf3c988c0..7bae24166 100644 --- a/java/libraries/opengl/src/processing/opengl/PShape3D.java +++ b/java/libraries/opengl/src/processing/opengl/PShape3D.java @@ -615,14 +615,8 @@ public class PShape3D extends PShape { } if (parent == null) { - initBuffers(vertexCount, indexCount); - + initBuffers(vertexCount, indexCount); copyGeometry(0, vertexCount, vertices, texcoords, colors, normals, indices); - - //int offset = 0; - //int size = vertexCount; - - } } @@ -643,6 +637,7 @@ public class PShape3D extends PShape { } } + protected int copyOffset; public void aggregate() { if (family == GROUP && parent == null) { // We recursively calculate the total number of vertices and indices. @@ -652,6 +647,9 @@ public class PShape3D extends PShape { // Now that we know, we can initialize the buffers with the correct size. initBuffers(vertexCount, indexCount); + + copyOffset = 0; + copyGeometryToRoot(); } } @@ -683,6 +681,8 @@ public class PShape3D extends PShape { indices[i] = root.indexCount + i; } root.indexCount += indexCount; + // parent.indexCount += indexCount; ? + // parent.vertexCount += vertexCount; ? return indexCount; } @@ -724,6 +724,18 @@ public class PShape3D extends PShape { getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } + protected void copyGeometryToRoot() { + if (family == GROUP) { + for (int i = 0; i < childCount; i++) { + PShape3D child = (PShape3D)children[i]; + child.copyGeometryToRoot(); + } + } else { + root.copyGeometry(root.copyOffset, vertexCount, vertices, texcoords, colors, normals, indices); + root.copyOffset += vertexCount; + } + } + protected void copyGeometry(int offset, int size, float[] vertices, float[] texcoords, float[] colors, float[] normals, int[] indices) { getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glVertexBufferID);