mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Almost done with color getters/setters
This commit is contained in:
@@ -1530,6 +1530,19 @@ public class PGL {
|
||||
}
|
||||
|
||||
|
||||
static public int nativeToJavaARGB(int color) {
|
||||
if (BIG_ENDIAN) {
|
||||
return (color & 0xff000000) |
|
||||
((color >> 8) & 0x00ffffff);
|
||||
} else {
|
||||
return (color & 0xff000000) |
|
||||
((color << 16) & 0xff0000) |
|
||||
(color & 0xff00) |
|
||||
((color >> 16) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert native OpenGL format into palatable ARGB format. This function
|
||||
* leaves alone (ignores) the alpha component. Also flips the image
|
||||
|
||||
@@ -6343,7 +6343,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
float y0 = in.vertices[3 * inIdx + 1];
|
||||
float z0 = in.vertices[3 * inIdx + 2];
|
||||
indices = fillIndices[inIdx];
|
||||
float[] weigths = fillWeights[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
// tessIdx is a linear combination of input vertices,
|
||||
// including inIdx:
|
||||
@@ -6356,7 +6356,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
// = xt + w2 * (x2' - x2)
|
||||
// This explains the calculations below:
|
||||
int tessIdx = indices[i];
|
||||
float weight = weigths[i];
|
||||
float weight = weights[i];
|
||||
float tx0 = vertices[3 * tessIdx + 0];
|
||||
float ty0 = vertices[3 * tessIdx + 1];
|
||||
float tz0 = vertices[3 * tessIdx + 2];
|
||||
@@ -6380,10 +6380,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
float ny0 = in.normals[3 * inIdx + 1];
|
||||
float nz0 = in.normals[3 * inIdx + 2];
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weigths = fillWeights[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
float weight = weigths[i];
|
||||
float weight = weights[i];
|
||||
float tnx0 = normals[3 * tessIdx + 0];
|
||||
float tny0 = normals[3 * tessIdx + 1];
|
||||
float tnz0 = normals[3 * tessIdx + 2];
|
||||
@@ -6417,10 +6417,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
float u0 = in.texcoords[2 * inIdx + 0];
|
||||
float v0 = in.texcoords[2 * inIdx + 1];
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weigths = fillWeights[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
float weight = weigths[i];
|
||||
float weight = weights[i];
|
||||
float tu0 = texcoords[2 * tessIdx + 0];
|
||||
float tv0 = texcoords[2 * tessIdx + 1];
|
||||
float tu = tu0 + weight * (u - u0);
|
||||
@@ -6430,6 +6430,143 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setFill(int inIdx, int fill) {
|
||||
int[] colors = tess.fillColors;
|
||||
|
||||
if (-1 < firstFillIndex) {
|
||||
int tessIdx = firstFillIndex + inIdx;
|
||||
colors[tessIdx] = fill;
|
||||
} else {
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
int fill0 = in.colors[inIdx];
|
||||
setColorARGB(colors, fill, fill0, indices, weights);
|
||||
}
|
||||
}
|
||||
|
||||
void setStroke(int inIdx, int stroke) {
|
||||
int[] indices;
|
||||
int[] colors;
|
||||
|
||||
indices = pointIndices[inIdx];
|
||||
colors = tess.pointColors;
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
colors[tessIdx] = stroke;
|
||||
}
|
||||
|
||||
indices = lineIndices[inIdx];
|
||||
colors = tess.lineColors;
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
colors[tessIdx] = stroke;
|
||||
}
|
||||
}
|
||||
|
||||
void setStrokeWeight(int inIdx, float weight) {
|
||||
|
||||
}
|
||||
|
||||
void setAmbient(int inIdx, int ambient) {
|
||||
int[] colors = tess.fillAmbient;
|
||||
|
||||
if (-1 < firstFillIndex) {
|
||||
int tessIdx = firstFillIndex + inIdx;
|
||||
colors[tessIdx] = ambient;
|
||||
} else {
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
int ambient0 = in.ambient[inIdx];
|
||||
setColorRGB(colors, ambient, ambient0, indices, weights);
|
||||
}
|
||||
}
|
||||
|
||||
void setSpecular(int inIdx, int specular) {
|
||||
int[] colors = tess.fillSpecular;
|
||||
|
||||
if (-1 < firstFillIndex) {
|
||||
int tessIdx = firstFillIndex + inIdx;
|
||||
colors[tessIdx] = specular;
|
||||
} else {
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
int specular0 = in.specular[inIdx];
|
||||
setColorRGB(colors, specular, specular0, indices, weights);
|
||||
}
|
||||
}
|
||||
|
||||
void setEmissive(int inIdx, int emissive) {
|
||||
int[] colors = tess.fillEmissive;
|
||||
|
||||
if (-1 < firstFillIndex) {
|
||||
int tessIdx = firstFillIndex + inIdx;
|
||||
colors[tessIdx] = emissive;
|
||||
} else {
|
||||
int[] indices = fillIndices[inIdx];
|
||||
float[] weights = fillWeights[inIdx];
|
||||
int emissive0 = in.emissive[inIdx];
|
||||
setColorRGB(colors, emissive, emissive0, indices, weights);
|
||||
}
|
||||
}
|
||||
|
||||
void setShininess(int inIdx, float weight) {
|
||||
|
||||
}
|
||||
|
||||
void setColorARGB(int[] colors, int fill, int fill0, int[] indices, float[] weights) {
|
||||
float a = (fill >> 24) & 0xFF;
|
||||
float r = (fill >> 16) & 0xFF;
|
||||
float g = (fill >> 8) & 0xFF;
|
||||
float b = (fill >> 0) & 0xFF;
|
||||
|
||||
float a0 = (fill0 >> 24) & 0xFF;
|
||||
float r0 = (fill0 >> 16) & 0xFF;
|
||||
float g0 = (fill0 >> 8) & 0xFF;
|
||||
float b0 = (fill0 >> 0) & 0xFF;
|
||||
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
float weight = weights[i];
|
||||
int tfill0 = colors[tessIdx];
|
||||
float ta0 = (tfill0 >> 24) & 0xFF;
|
||||
float tr0 = (tfill0 >> 16) & 0xFF;
|
||||
float tg0 = (tfill0 >> 8) & 0xFF;
|
||||
float tb0 = (tfill0 >> 0) & 0xFF;
|
||||
|
||||
int ta = (int) (ta0 + weight * (a - a0));
|
||||
int tr = (int) (tr0 + weight * (r - r0));
|
||||
int tg = (int) (tg0 + weight * (g - g0));
|
||||
int tb = (int) (tb0 + weight * (b - b0));
|
||||
|
||||
colors[tessIdx] = (ta << 24) | (tr << 16) | (tg << 8) | tb;
|
||||
}
|
||||
}
|
||||
|
||||
void setColorRGB(int[] colors, int fill, int fill0, int[] indices, float[] weights) {
|
||||
float r = (fill >> 16) & 0xFF;
|
||||
float g = (fill >> 8) & 0xFF;
|
||||
float b = (fill >> 0) & 0xFF;
|
||||
|
||||
float r0 = (fill0 >> 16) & 0xFF;
|
||||
float g0 = (fill0 >> 8) & 0xFF;
|
||||
float b0 = (fill0 >> 0) & 0xFF;
|
||||
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
int tessIdx = indices[i];
|
||||
float weight = weights[i];
|
||||
int tfill0 = colors[tessIdx];
|
||||
float tr0 = (tfill0 >> 16) & 0xFF;
|
||||
float tg0 = (tfill0 >> 8) & 0xFF;
|
||||
float tb0 = (tfill0 >> 0) & 0xFF;
|
||||
|
||||
int tr = (int) (tr0 + weight * (r - r0));
|
||||
int tg = (int) (tg0 + weight * (g - g0));
|
||||
int tb = (int) (tb0 + weight * (b - b0));
|
||||
|
||||
colors[tessIdx] = 0xff000000 | (tr << 16) | (tg << 8) | tb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Holds the input vertices: xyz coordinates, fill/tint color,
|
||||
|
||||
@@ -1824,20 +1824,11 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public int getVertexCount() {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return inGeo.vertexCount;
|
||||
}
|
||||
|
||||
|
||||
public PVector getVertex(int index, PVector vec) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return null;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
if (vec == null) {
|
||||
@@ -1851,10 +1842,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getVertexX(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.vertices[3 * index + 0];
|
||||
@@ -1862,10 +1849,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getVertexY(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.vertices[3 * index + 1];
|
||||
@@ -1873,10 +1856,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getVertexZ(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.vertices[3 * index + 2];
|
||||
@@ -1889,10 +1868,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public void setVertex(int index, float x, float y, float z) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
inGeo.tessMap.setVertex(index, x, y, z);
|
||||
@@ -1908,10 +1883,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public PVector getNormal(int index, PVector vec) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return null;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
if (vec == null) {
|
||||
@@ -1925,10 +1896,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getNormalX(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.normals[3 * index + 0];
|
||||
@@ -1936,10 +1903,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getNormalY(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.normals[3 * index + 1];
|
||||
@@ -1947,10 +1910,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getNormalZ(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.normals[3 * index + 2];
|
||||
@@ -1958,10 +1917,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public void setNormal(int index, float nx, float ny, float nz) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
inGeo.tessMap.setNormal(index, nx, ny, nz);
|
||||
@@ -1975,10 +1930,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getTextureU(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.texcoords[2 * index + 0];
|
||||
@@ -1986,10 +1937,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public float getTextureV(int index) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return 0;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.texcoords[2 * index + 1];
|
||||
@@ -1997,10 +1944,6 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
public void setTextureUV(int index, float u, float v) {
|
||||
if (family == GROUP) {
|
||||
PGraphics.showWarning("GROUP shapes don't have any vertices");
|
||||
return;
|
||||
}
|
||||
updateTessellation();
|
||||
|
||||
inGeo.tessMap.setTexcoords(index, u, v);
|
||||
@@ -2010,18 +1953,138 @@ public class PShape3D extends PShape {
|
||||
if (hasFill) modifiedFillTexCoords = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public int getFill(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return PGL.nativeToJavaARGB(inGeo.colors[index]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public float[] getVertex(int index) {
|
||||
public void setFill(int index, int fill) {
|
||||
updateTessellation();
|
||||
|
||||
int nfill = PGL.javaToNativeARGB(fill);
|
||||
inGeo.tessMap.setFill(index, nfill);
|
||||
inGeo.colors[index] = nfill;
|
||||
|
||||
if (hasFill) modifiedFillColors = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public int getStroke(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return PGL.nativeToJavaARGB(inGeo.scolors[index]);
|
||||
}
|
||||
|
||||
|
||||
public void setStroke(int index, int stroke) {
|
||||
updateTessellation();
|
||||
|
||||
int nstroke = PGL.javaToNativeARGB(stroke);
|
||||
inGeo.tessMap.setStroke(index, nstroke);
|
||||
inGeo.scolors[index] = nstroke;
|
||||
|
||||
if (hasPoints) modifiedPointColors = true;
|
||||
if (hasLines) modifiedLineColors = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public float getStrokeWeight(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.sweights[index];
|
||||
}
|
||||
|
||||
|
||||
public void setStrokeWeight(int index, float weight) {
|
||||
updateTessellation();
|
||||
|
||||
inGeo.tessMap.setStrokeWeight(index, weight);
|
||||
inGeo.sweights[index] = weight;
|
||||
|
||||
if (hasPoints) modifiedPointAttributes = true;
|
||||
if (hasLines) modifiedLineAttributes = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public int getAmbient(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return PGL.nativeToJavaARGB(inGeo.ambient[index]);
|
||||
}
|
||||
|
||||
|
||||
public void setAmbient(int index, int ambient) {
|
||||
updateTessellation();
|
||||
|
||||
int nambient = PGL.javaToNativeARGB(ambient);
|
||||
inGeo.tessMap.setAmbient(index, nambient);
|
||||
inGeo.ambient[index] = nambient;
|
||||
|
||||
if (hasFill) modifiedFillAmbient = true;
|
||||
modified();
|
||||
}
|
||||
public int[] getVertexCodes() {
|
||||
|
||||
public int getSpecular(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return PGL.nativeToJavaARGB(inGeo.specular[index]);
|
||||
}
|
||||
public int getVertexCodeCount() {
|
||||
|
||||
|
||||
public void setSpecular(int index, int specular) {
|
||||
updateTessellation();
|
||||
|
||||
int nspecular = PGL.javaToNativeARGB(specular);
|
||||
inGeo.tessMap.setSpecular(index, nspecular);
|
||||
inGeo.specular[index] = nspecular;
|
||||
|
||||
if (hasFill) modifiedFillSpecular = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public int getEmissive(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return PGL.nativeToJavaARGB(inGeo.emissive[index]);
|
||||
}
|
||||
public int getVertexCode(int index) {
|
||||
|
||||
|
||||
public void setEmissive(int index, int emissive) {
|
||||
updateTessellation();
|
||||
|
||||
int nemissive = PGL.javaToNativeARGB(emissive);
|
||||
inGeo.tessMap.setEmissive(index, nemissive);
|
||||
inGeo.emissive[index] = nemissive;
|
||||
|
||||
if (hasFill) modifiedFillEmissive = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
public float getShininess(int index) {
|
||||
updateTessellation();
|
||||
|
||||
return inGeo.shininess[index];
|
||||
}
|
||||
|
||||
|
||||
public void setShininess(int index, float shine) {
|
||||
updateTessellation();
|
||||
|
||||
inGeo.tessMap.setShininess(index, shine);
|
||||
inGeo.shininess[index] = shine;
|
||||
|
||||
if (hasFill) modifiedFillShininess = true;
|
||||
modified();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user