fill and stroke methods in PShape3D

This commit is contained in:
codeanticode
2011-12-06 02:03:03 +00:00
parent afebba3bef
commit 341c74a9d6
3 changed files with 323 additions and 285 deletions
@@ -5819,7 +5819,7 @@ public class PGraphicsOpenGL extends PGraphics {
glParamsRead = true;
}
//////////////////////////////////////////////////////////////
@@ -6207,10 +6207,6 @@ public class PGraphicsOpenGL extends PGraphics {
mat.m30, mat.m31, mat.m32, mat.m33);
}
}
public InGeometry newInGeometry() {
return new InGeometry();
@@ -73,8 +73,6 @@ public class PShape3D extends PShape {
protected PImage texture;
protected boolean is3D;
// ........................................................
// OpenGL buffers
@@ -132,12 +130,23 @@ public class PShape3D extends PShape {
// Input data
protected float[] currentVertex = { 0, 0, 0 };
protected float[] currentColor = { 0, 0, 0, 0 };
protected float[] currentNormal = { 0, 0, 1 };
protected float[] currentTexcoord = { 0, 0 };
protected float[] currentStroke = { 0, 0, 0, 1, 1 };
protected float normalX, normalY, normalZ;
// ........................................................
// Fill, stroke and tint colors
protected boolean fill;
protected float fillR, fillG, fillB, fillA;
protected boolean stroke;
protected float strokeR, strokeG, strokeB, strokeA;
protected boolean tint;
protected float tintR, tintG, tintB, tintA;
protected int textureMode = IMAGE;
// ........................................................
// Bezier and Catmull-Rom curves
@@ -160,21 +169,7 @@ public class PShape3D extends PShape {
protected float curveVertices[][];
protected int curveVertexCount;
// ........................................................
// Fill color
/** true if fill() is enabled, (read-only) */
public boolean fill;
/** fill that was last set (read-only) */
public int fillColor = 0xffFFFFFF;
protected boolean fillAlpha;
protected float fillR, fillG, fillB, fillA;
protected int fillRi, fillGi, fillBi, fillAi;
public PShape3D(PApplet parent, int family) {
@@ -205,7 +200,8 @@ public class PShape3D extends PShape {
this.root = this;
this.parent = null;
this.modified = false;
this.is3D = true;
colorMode(RGB, 255);
tess = ogl.newTessGeometry(RETAINED);
if (family == GEOMETRY || family == PRIMITIVE || family == PATH) {
@@ -225,17 +221,11 @@ public class PShape3D extends PShape {
}
}
public void setKind(int kind) {
this.kind = kind;
}
public void set2D() {
is3D = false;
}
public void set3D() {
is3D = true;
}
public void setMode(int mode) {
if (mode == STATIC) {
@@ -247,6 +237,7 @@ public class PShape3D extends PShape {
}
}
protected void finalize() throws Throwable {
try {
release();
@@ -267,96 +258,146 @@ public class PShape3D extends PShape {
texture = tex;
}
public void noTexture() {
texture = null;
}
public void solid(boolean solid) {
isSolid = solid;
}
public void closed(boolean closed) {
isClosed = closed;
}
public void breakShape() {
breakShape = true;
}
public void vertex(float x, float y) {
vertex(x, y, 0, 0, 0);
}
public void vertex(float x, float y, float z) {
vertex(x, y, z, 0, 0);
}
public void vertex(float x, float y, float z, float u, float v) {
vertexImpl(x, y, z, u, v, VERTEX);
}
protected void vertexImpl(float x, float y, float z, float u, float v, int code) {
if (family != GEOMETRY && family != PATH) {
System.err.println("Cannot add vertices to GROUP of PRIMITIVE shape");
return;
}
currentVertex[0] = x;
currentVertex[1] = y;
currentVertex[2] = z;
if (texture != null) {
boolean textured = texture != null;
float fR, fG, fB, fA;
fR = fG = fB = fA = 0;
if (fill || textured) {
if (!textured) {
fR = fillR;
fG = fillG;
fB = fillB;
fA = fillA;
} else {
if (tint) {
fR = tintR;
fG = tintG;
fB = tintB;
fA = tintA;
} else {
fR = 1;
fG = 1;
fB = 1;
fA = 1;
}
}
}
if (texture != null && textureMode == IMAGE) {
u /= texture.width;
v /= texture.height;
PTexture tex = ogl.getTexture(texture);
if (tex.isFlippedY()) {
v = 1 - v;
}
}
currentTexcoord[0] = u;
currentTexcoord[1] = v;
}
float sR, sG, sB, sA, sW;
sR = sG = sB = sA = sW = 0;
if (stroke) {
sR = strokeR;
sG = strokeG;
sB = strokeB;
sA = strokeA;
sW = strokeWeight;
}
if (breakShape) {
code = BREAK;
breakShape = false;
}
in.addVertex(currentVertex, currentColor, currentNormal, currentTexcoord, currentStroke, code);
//in.addVertex(currentVertex, currentColor, currentNormal, currentTexcoord, currentStroke, code);
in.addVertex(x, y, z,
fR, fG, fB, fA,
normalX, normalY, normalZ,
u, v,
sR, sG, sB, sA, sW,
code);
root.modified = true;
modified = true;
}
public void normal(float nx, float ny, float nz) {
currentNormal[0] = nx;
currentNormal[1] = ny;
currentNormal[2] = nz;
normalX = nx;
normalY = ny;
normalZ = nz;
}
public void strokeWeight(float w) {
currentStroke[4] = w;
}
public void strokeJoin(int join) {
strokeJoin = join;
}
public void strokeCap(int cap) {
strokeCap = cap;
}
public void end() {
// ?
}
}
//////////////////////////////////////////////////////////////
// STROKE CAP/JOIN/WEIGHT
public void strokeWeight(float weight) {
strokeWeight = weight;
}
public void strokeJoin(int join) {
strokeJoin = join;
}
public void strokeCap(int cap) {
strokeCap = cap;
}
//////////////////////////////////////////////////////////////
// FILL COLOR
/*
public void noFill() {
fill = false;
}
@@ -397,269 +438,70 @@ public class PShape3D extends PShape {
fillG = calcG;
fillB = calcB;
fillA = calcA;
fillRi = calcRi;
fillGi = calcGi;
fillBi = calcBi;
fillAi = calcAi;
fillColor = calcColor;
fillAlpha = calcAlpha;
}
*/
public void noFill() {
fill(0, 0, 0, 0);
}
public void fill(float r, float g, float b, float a) {
currentColor[0] = r;
currentColor[1] = g;
currentColor[2] = b;
currentColor[3] = a;
public void textureMode(int mode) {
this.textureMode = mode;
}
//////////////////////////////////////////////////////////////
// STROKE CAP/JOIN/WEIGHT
/*
public void strokeWeight(float weight) {
strokeWeight = weight;
}
public void strokeJoin(int join) {
strokeJoin = join;
}
public void strokeCap(int cap) {
strokeCap = cap;
}
*/
//////////////////////////////////////////////////////////////
// STROKE COLOR
public void stroke(float r, float g, float b, float a) {
currentStroke[0] = r;
currentStroke[1] = g;
currentStroke[2] = b;
currentStroke[3] = a;
}
public void noStroke() {
stroke(0, 0, 0, 0);
}
/*
public void noStroke() {
stroke = false;
}
public void stroke(int rgb) {
colorCalc(rgb);
strokeFromCalc();
}
public void stroke(int rgb, float alpha) {
colorCalc(rgb, alpha);
strokeFromCalc();
}
public void stroke(float gray) {
colorCalc(gray);
strokeFromCalc();
}
public void stroke(float gray, float alpha) {
colorCalc(gray, alpha);
strokeFromCalc();
}
public void stroke(float x, float y, float z) {
colorCalc(x, y, z);
strokeFromCalc();
}
public void stroke(float x, float y, float z, float alpha) {
colorCalc(x, y, z, alpha);
strokeFromCalc();
}
protected void strokeFromCalc() {
stroke = true;
strokeR = calcR;
strokeG = calcG;
strokeB = calcB;
strokeA = calcA;
strokeRi = calcRi;
strokeGi = calcGi;
strokeBi = calcBi;
strokeAi = calcAi;
strokeColor = calcColor;
strokeAlpha = calcAlpha;
}
*/
/*
public void imageMode(int mode) {
if ((mode == CORNER) || (mode == CORNERS) || (mode == CENTER)) {
imageMode = mode;
} else {
String msg =
"imageMode() only works with CORNER, CORNERS, or CENTER";
throw new RuntimeException(msg);
}
}
*/
//////////////////////////////////////////////////////////////
// STYLE
/*
public void pushStyle() {
if (styleStackDepth == styleStack.length) {
styleStack = (PStyle[]) PApplet.expand(styleStack);
}
if (styleStack[styleStackDepth] == null) {
styleStack[styleStackDepth] = new PStyle();
}
PStyle s = styleStack[styleStackDepth++];
getStyle(s);
}
public void popStyle() {
if (styleStackDepth == 0) {
throw new RuntimeException("Too many popStyle() without enough pushStyle()");
}
styleStackDepth--;
style(styleStack[styleStackDepth]);
}
public void style(PStyle s) {
// if (s.smooth) {
// smooth();
// } else {
// noSmooth();
// }
imageMode(s.imageMode);
rectMode(s.rectMode);
ellipseMode(s.ellipseMode);
shapeMode(s.shapeMode);
if (s.tint) {
tint(s.tintColor);
} else {
noTint();
}
if (s.fill) {
fill(s.fillColor);
} else {
noFill();
}
if (s.stroke) {
stroke(s.strokeColor);
} else {
noStroke();
}
strokeWeight(s.strokeWeight);
strokeCap(s.strokeCap);
strokeJoin(s.strokeJoin);
// Set the colorMode() for the material properties.
// TODO this is really inefficient, need to just have a material() method,
// but this has the least impact to the API.
colorMode(RGB, 1);
ambient(s.ambientR, s.ambientG, s.ambientB);
emissive(s.emissiveR, s.emissiveG, s.emissiveB);
specular(s.specularR, s.specularG, s.specularB);
shininess(s.shininess);
// material(s.ambientR, s.ambientG, s.ambientB,
// s.emissiveR, s.emissiveG, s.emissiveB,
// s.specularR, s.specularG, s.specularB,
// s.shininess);
// Set this after the material properties.
colorMode(s.colorMode,
s.colorModeX, s.colorModeY, s.colorModeZ, s.colorModeA);
// This is a bit asymmetric, since there's no way to do "noFont()",
// and a null textFont will produce an error (since usually that means that
// the font couldn't load properly). So in some cases, the font won't be
// 'cleared' to null, even though that's technically correct.
if (s.textFont != null) {
textFont(s.textFont, s.textSize);
textLeading(s.textLeading);
}
// These don't require a font to be set.
textAlign(s.textAlign, s.textAlignY);
textMode(s.textMode);
}
public PStyle getStyle() { // ignore
return getStyle(null);
}
public PStyle getStyle(PStyle s) { // ignore
if (s == null) {
s = new PStyle();
}
s.imageMode = imageMode;
s.rectMode = rectMode;
s.ellipseMode = ellipseMode;
s.shapeMode = shapeMode;
s.colorMode = colorMode;
s.colorModeX = colorModeX;
s.colorModeY = colorModeY;
s.colorModeZ = colorModeZ;
s.colorModeA = colorModeA;
s.tint = tint;
s.tintColor = tintColor;
s.fill = fill;
s.fillColor = fillColor;
s.stroke = stroke;
s.strokeColor = strokeColor;
s.strokeWeight = strokeWeight;
s.strokeCap = strokeCap;
s.strokeJoin = strokeJoin;
s.ambientR = ambientR;
s.ambientG = ambientG;
s.ambientB = ambientB;
s.specularR = specularR;
s.specularG = specularG;
s.specularB = specularB;
s.emissiveR = emissiveR;
s.emissiveG = emissiveG;
s.emissiveB = emissiveB;
s.shininess = shininess;
s.textFont = textFont;
s.textAlign = textAlign;
s.textAlignY = textAlignY;
s.textMode = textMode;
s.textSize = textSize;
s.textLeading = textLeading;
return s;
}
*/
///////////////////////////////////////////////////////////
@@ -1006,8 +848,12 @@ public class PShape3D extends PShape {
if (modified) {
tessellator.setInGeometry(in);
tessellator.setTessGeometry(tess);
tessellator.setFill(fill || texture != null);
tessellator.setStroke(stroke);
tessellator.setStrokeWeight(strokeWeight);
tessellator.setStrokeCap(strokeCap);
tessellator.setStrokeJoin(strokeJoin);
tessellator.setStrokeColor(strokeR, strokeG, strokeB, strokeA);
if (family == GEOMETRY) {
if (kind == POINTS) {
@@ -1618,15 +1464,7 @@ public class PShape3D extends PShape {
}
} else {
if (!is3D) {
// if is stroked and textured:
// texSet.add(texture); for the textured fill
// texSet.add(null); for the stroke
// else
texSet.add(texture);
} else {
texSet.add(texture);
}
texSet.add(texture);
}
return texSet;