We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello forumers,
I am looking for tips and hints on "the best way" to approach something. I want to either import, or create, geometry (initially a cylinder), isolate half of it, and move the vertices around, then export it again as an .obj or .stl. I realise there are libraries that will do this but I need this to work on Android and the libraries (as far as I know) don't. I made these images in 3DMax to explain what I mean.
I have adapted this method for creating a cylinder from an example in the book: Processing 2: Creative Coding Hotshot...
float[][] vertx;
float[][] verty;
void setup() {
size(800, 600, P3D);
vertx = new float[36][36];//36 triangle strips, 36 vertices
verty = new float[36][36];
}
void draw() {
hint( ENABLE_DEPTH_TEST );
pushMatrix();
background(125);
fill(255);
strokeWeight(0.5);
translate( width/2, height/2, 200);
rotateX(radians(-45));
scale( 1 );
translate(0, -50, 0);
initPoints();
beginShape(TRIANGLE_STRIP );
for ( int h = 1; h < 36; h++) {
for ( int a = 0; a<37; a++ ) {
int aa = a % 36;
// normal( vertx[h][aa], 0, verty[h][aa]);
vertex( vertx[h][aa], h*5.0, verty[h][aa] );
//normal( vertx[h-1][aa], 0, verty[h-1][aa]);
vertex( vertx[h-1][aa], (h-1)*5.0, verty[h-1][aa] );
}
}
endShape();
beginShape(TRIANGLE_FAN); //bottom
int h = 35;
vertex( 0, h*5, 0 );
for ( int a = 0; a<37; a++ ) {
int aa = a % 36;
vertex( vertx[h][aa], h*5, verty[h][aa] );
}
endShape();
popMatrix();
hint(DISABLE_DEPTH_TEST);
}
float getR( float a, float h ) {
float r = 50;
return r;
}
void initPoints() {
for ( int h = 0; h < 36; h++) {
for ( int a = 0; a<36; a++) {
float r = getR( a*10.0, h*5.0 ); //a = 10 (360/36)
vertx[h][a] = cos( radians( a*10.0 )) * r;
verty[h][a] = sin( radians( a*10.0 )) * r;
}
}
}
...and I am assuming it is possible to isolate/grab certain vertices from the array?
Any other approaches, or any advice on how to develop this? Is the import > transform method even possible?
Answers
In you method initPoints() you create the cylinder, where
a
defines the angle.So if you modify the vertices where i.e.
a
is lower than 18, this should be one half of the cylinder. Here is an example that increaes the radius of the vertices using noise():see
https://forum.processing.org/two/discussion/12089/small-3d-editor#latest
@benja - That is a good approach as I wish to do this dynamically, though oddly, when I run the new code (below) I get three Errors:
This is strange because the indicated values must be used somewhere to create the cylinder. I assume offset is never called because float a is never used. Either float a or int a, are superfluous here?
@Chrisir - that is very impressive, and something I will have a look at in more depth. PeasyCam does not work on Android, but there will be ways around this I am sure. Thank you.
I trimmed some of the superfluous code, and this does create noise, but across the entire cylinder. I guess the following is in the wrong place:
But thanks to @benja, this is progress...
yes, swap the 2 lines...
do it like this please
by the way:
if(a < 17);
would fail since the sign;
ends the line and the commandif....
Processing would read this as "if true do all between ) and ; " which is... nothing. Oups. Thus no
;
in this place!remark
maybe in this line
you want to say
+ offset
- I am not sure:then this
would be
(not tested....)
Best, Chrisir
This just about works...
that's the key
or
or
^:)^
;-)