Tutorials | (back to the list of tutorials) |
Panelization Example10The input file used in the example is this.
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double gap = 0.25;
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1-gap)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1-gap)*uinc, (j+1-gap)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1-gap)*vinc );
new ISurface(pt1,pt2,pt3,pt4);
}
}
surf.del();
}
In the following code, divided rectangular cell is randomly triangulated. The surface is created by offset of the triangular or rectangular cell and extrusion.
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double offsetDist = -0.04;
int degree = 1; // 1 or 2
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
if(IRandom.percent(30)){ // rectangle
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -4).clr(0.2);
}
else if(IRandom.percent(30)){ // triangles
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -2).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt1, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -2).clr(0.2);
}
else{ // triangles in other direction
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -1).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt2, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -1).clr(0.2);
}
}
}
surf.del();
}
If you change the variable degree from 1 to 2, it change the profile from polyline to curve and the extruded surface also get curved.
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double offsetDist = -0.04;
int degree = 2; // 1 or 2
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
if(IRandom.percent(30)){ // rectangle
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -4).clr(0.2);
}
else if(IRandom.percent(30)){ // triangles
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -2).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt1, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -2).clr(0.2);
}
else{ // triangles in other direction
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -1).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt2, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -1).clr(0.2);
}
}
}
surf.del();
}
The following code takes 1 bitmap input.
The bitmap defines void area.
When the value of bitmap is less than 0.5 (dark),
the geometry is created and otherwise not.
The below is "voidmap.jpg"
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
IImageMap map1 = new IImageMap("voidmap.jpg");
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double offsetDist = -0.04;
int degree = 1; // 1 or 2
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
if(map1.get( (i+0.5)*uinc, (j+0.5)*vinc ) < 0.5 ){
if(IRandom.percent(30)){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -3).clr(0.2);
}
else if(IRandom.percent(30)){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -2).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt1, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -2).clr(0.2);
}
else{
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -1).clr(0.2);
ICurve crv2 = new ICurve(new IVec[]{ pt2, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -1).clr(0.2);
}
}
}
}
surf.del();
}
The following code takes 5 image maps. Each of them defines, void, height, randomization of height, condition to be triangulated or not, and color.
Here are "voidmap.jpg", "heightmap.jpg",
"heightRandomizeMap.jpg", "divisionmap.jpg" and
"colormap.jpg".
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
IImageMap map1 = new IImageMap("voidmap.jpg");
IImageMap map2 = new IImageMap("heightmap.jpg");
IImageMap map3 = new IImageMap("heightRandomizeMap.jpg");
IImageMap map4 = new IImageMap("divisionmap.jpg");
IImageMap map5 = new IImageMap("colormap.jpg");
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double offsetDist = -0.04;
int degree = 1; // 1 or 2
double maxHeight = 2;
double heightRandomizeRange = 2.5;
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
double division =
map4.get((i+0.5)*uinc,(j+0.5)*vinc)*maxHeight;
double height =
map2.get((i+0.5)*uinc,(j+0.5)*vinc)*maxHeight;
height += map3.get((i+0.5)*uinc,(j+0.5)*vinc) *
IRandom.get(0,heightRandomizeRange);
if(map1.get( (i+0.5)*uinc, (j+0.5)*vinc ) < 0.5 ){
if(division < 0.5){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
else if(IRandom.percent(50)){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
ICurve crv2 = new ICurve(new IVec[]{ pt1, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
else{
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
ICurve crv2 = new ICurve(new IVec[]{ pt2, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
}
}
}
surf.del();
}
The following is in case the variable degree is changed to 2.
![]()
![]()
![]()
![]()
import processing.opengl.*;
import igeo.*;
size(480, 360, IG.GL);
IG.open("surface11.3dm");
ISurface[] surfaces = IG.surfaces();
IImageMap map1 = new IImageMap("voidmap.jpg");
IImageMap map2 = new IImageMap("heightmap.jpg");
IImageMap map3 = new IImageMap("heightRandomizeMap.jpg");
IImageMap map4 = new IImageMap("divisionmap.jpg");
IImageMap map5 = new IImageMap("colormap.jpg");
for (ISurface surf : surfaces) {
int unum = 30, vnum = 30;
double uinc = 1.0/unum, vinc = 1.0/vnum;
double offsetDist = -0.04;
int degree = 2; // 1 or 2
double maxHeight = 2;
double heightRandomizeRange = 2.5;
for(int i=0; i < unum; i++){
for(int j=0; j < vnum; j++){
IVec pt1 = surf.pt( i*uinc, j*vinc );
IVec pt2 = surf.pt( (i+1)*uinc, j*vinc );
IVec pt3 = surf.pt( (i+1)*uinc, (j+1)*vinc );
IVec pt4 = surf.pt( i*uinc, (j+1)*vinc );
double division = map4.get((i+0.5)*uinc,(j+0.5)*vinc)*maxHeight;
double height = map2.get((i+0.5)*uinc,(j+0.5)*vinc)*maxHeight;
height += map3.get((i+0.5)*uinc,(j+0.5)*vinc) * IRandom.get(0,heightRandomizeRange);
if(map1.get( (i+0.5)*uinc, (j+0.5)*vinc ) < 0.5 ){
if(division < 0.5){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
else if(IRandom.percent(50)){
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt3 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
ICurve crv2 = new ICurve(new IVec[]{ pt1, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
else{
ICurve crv = new ICurve(new IVec[]{ pt1, pt2, pt4 }, degree, true);
ICurve offCrv = IG.offset(crv, offsetDist);
IG.extrude(offCrv, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
ICurve crv2 = new ICurve(new IVec[]{ pt2, pt3, pt4 }, degree, true);
ICurve offCrv2 = IG.offset(crv2, offsetDist);
IG.extrude(offCrv2, -height).clr(map5.clr((i+0.5)*uinc, (j+0.5)*vinc));
}
}
}
}
surf.del();
}
HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java /
Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT