We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In the code below, I am having two issues:
1) The line tempcell.setSize(cellsize,cellsize,cellsize); gives me the error:
The function setSize(float,float,float) does not exist.
Yet I can use getChild() right above it?
I must not understand this library stuff.
Any help or suggestions?
2) The line brain.tint(0,trans); returns an error of tint() can only be called between beginShape() and endShape() Can anyone recommend the syntec to use in place of that command that is callable on a Box from Shapes3D
Any other suggestions or recommendations on optimization are accepted. Thanks for everybody's help.
//----------------------------------------------------------
// Custom Cube Celled Brain Class
class CubeCelledBrain {
float cellwidth, cellheight, celldepth, cellsize, gridsize; // width, height, depth, size of cell
int cells_per_side, half_cells_per_side,total_cells;
// Position & location vectors
PVector position; // Initial Positioning in row, column, file
PVector location; // cell location in x,y,z
PShape cell, brain, tempcell;
//*****************************************************************************************************
CubeCelledBrain(PApplet _myPApplet, int tempN, float tempS, float tempG, int tempTrans) { // CONSTRUCTOR
cells_per_side = tempN;
half_cells_per_side = int(cells_per_side/2);
total_cells = cells_per_side*cells_per_side*cells_per_side;
cellsize = tempS;
gridsize = tempG;
trans = tempTrans;
// myPApplet = _myPApplet;
// Create the shape group
brain = createShape(GROUP);
for (int i = -half_cells_per_side; i < half_cells_per_side; i++) {
for (int j = -half_cells_per_side; j < half_cells_per_side; j++) {
for (int k = -half_cells_per_side; k < half_cells_per_side; k++) {
cell = createShape(BOX, cellSize);
lights();
cell.setFill(color(255-128*i/cells_per_side,255-128*j/cells_per_side,255-128*k/cells_per_side,trans+128));
cell.translate(i*gridsize, j*gridsize, k*gridsize);
location = new PVector(i*gridsize, j*gridsize, k*gridsize);
position = new PVector(i, j, k);
brain.addChild(cell);
}}}}
void resize(float cellsize) {
// for (every child cell in brain) { cell.size = cellsize }
for (int i = 0; i<total_cells; i++) {
tempcell= brain.getChild(i);
print(i+" Resizing cell "+tempcell+" from "+tempcell.getWidth());
//tempcell.setSize(cellsize,cellsize,cellsize);
println("to "+cellsize);}
shape(brain); // Draw the brain
} // end resize
void settrans(int trans) {
println("Setting TINT*************************************************");
brain.tint(0,trans);
shape(brain); } // Draw the brain
void draw() { lights(); shape(brain); } // Draw the brain
}
Answers
You are confusing PShape with the Shapes3D library. PShape is a part of Processing and Shapes3D is a contributed library so they must be treated differently.
Methods that apply to PShape e.g. tint() do not apply to Box and methods that apply to Box e.g. setSize(...) do not apply to PShape.
I am not familiar with PShape so someone else might help you there but using tint with Box shapes might, I stress might be possible using something like
replacing .... with something suitable for the tint command and
replacing box with the name of a shape created from the Shapes3D library.
Thank you very much quark. You are correct that I am mixing the two.
Now that I know that, I will not use the Box in Shapes3D, and will have to do some of the coding myself. The other reason that I was using Shapes3D for was the PICKING capability.
With the Shapes3D picking, am I able to pick the child from within a PShape, or only the entire PShape? In my instance, My PShape is 3 layers deep: Brain Cells CellFaces
Would I be able to pick out a Cell or Face, or only the entire Brain? Thank you for your assistance, education and clarification.
Shapes3D picking only is for shapes created with Shapes3D - it will not work with PShape shapes.
Thank you very much for all of your help and guidance.