Programming 3D Tools

• Kinect Point-Cloud Data to Blender Smoke Generation

Screen Shot 2014-01-07 at 1.35.30 PM
Blender Python Script
see : smoke generator script

 

 

• 3D Lamp post generator

Another idea I’m highly interested in is generative modeling tools for use in 3D design and animation. One of these such tools i have wanted to make is a Lamp-post generator. Providing the user with a set of inputs which affect a 3D model and set different aspects of it. ie: the height, widths, tapers, number of lamps, lamp-style, etc…

Once developed for processing as an “.obj” exporting tool, i hope to implement the work into blender, an open-source 3D production suite.

for example:xxxxxxxxxxxxxxx

FINAL PROTOTYPE

Libraries.tar
LampostGenerator.tar

show the code »


/*
 to do
 camera up slider
 reordering of menu items
 fix hole
 add bell shape ending w options
 deal with memory problem
 add radial mirror

*/

//////////////////////////////////////////////////////
 //                                                  //
 //   3D Lamp-Post Generator  | By Jason Hendrik     //
 //                                                  //
 //////////////////////////////////////////////////////

////////////////////////////////////////////////   LIBRARIES /////////////////////////////////////

import guicomponents.*;
 import shapes3d.utils.*;
 //import shapes3d.animation.*;
 import shapes3d.*;
 import processing.opengl.*;

//for exports
 import toxi.geom.*;
 import toxi.geom.mesh.*;

////////////////////////////////////////////// LIBRARY VARIABLES /////////////////////////////////

GWSlider
 elbowCircumferenceSlider,
 postHeightSlider,
 baseCircumferenceSlider,
 armDistanceSlider,
 radialMirrorSlider,
 resolutionSlider,
 curveFactorSlider,
 bulbSlider,
 armHeightSlider,
 postRotationSlider;

private BezTube btube;

//////////////////////////////////////////////// MY VARIABLES ////////////////////////////////////

int baseCircumference = 8;
 int elbowCircumference = 4;

int armDistance = 32;
 int armHeight = 50;
 int curveFactor = 8;

int postHeight = 76;
 int postRotation = 200;

int radialMirror = 00;
 int bulbSize = 10;

int inverter = 1;

// set variable for lamp type buttons
 int lampType = 1;
 boolean lampType1_over = false;
 boolean lampType2_over = false;
 boolean lampType3_over = false;
 boolean lampType4_over = false;
 boolean lampType5_over = false;

boolean inverterButton = true;

// array selector for resolution of mesh.
 int[] resolution = {
 8, 12, 16, 24, 32, 48
 };

//init res
 int res = 0;

// slider delay reaction
 int sticky = 10;

/// Colors Setup

color BGcolor = color(32);
 color postColor = color(100);
 color floorPlaneColor = color(24);

int sliderWidth = 128;
 int menuLeftRule =45;
 /////////////////////////////////////////////////////// SETUP /////////////////////////////////////

void setup() {
 size(1024, 768, OPENGL);
 hint(ENABLE_OPENGL_4X_SMOOTH);
 smooth();
 stroke(2);

// =Slider 1
 elbowCircumferenceSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+10, sliderWidth);
 elbowCircumferenceSlider.setInertia(sticky);
 elbowCircumferenceSlider.setValue(elbowCircumference);
 elbowCircumferenceSlider.setRenderMaxMinLabel(false); //hides labels
 elbowCircumferenceSlider.setRenderValueLabel(false);  //hides value label
 //  elbowCircumferenceSlider.setLimits(1, 1, 60);  //hides value label
 // =Slider 2
 postHeightSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+40+10, sliderWidth);
 postHeightSlider.setInertia(sticky);
 postHeightSlider.setValue(postHeight);
 postHeightSlider.setRenderMaxMinLabel(false); //hides labels
 postHeightSlider.setRenderValueLabel(false);  //hides value label
 // postHeightSlider.setLimits(1, 0, 100);  //hides value label
 // =Slider 3
 baseCircumferenceSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+80+10, sliderWidth);
 baseCircumferenceSlider.setInertia(sticky);
 baseCircumferenceSlider.setValue(baseCircumference);
 baseCircumferenceSlider.setRenderMaxMinLabel(false); //hides labels
 baseCircumferenceSlider.setRenderValueLabel(false);  //hides value label
 // baseCircumferenceSlider.setLimits(1, 1, 100);
 // =Slider 4
 armDistanceSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+120+10, sliderWidth);
 armDistanceSlider.setInertia(sticky);
 armDistanceSlider.setValue(armDistance);
 armDistanceSlider.setRenderMaxMinLabel(false); //hides labels
 armDistanceSlider.setRenderValueLabel(false);  //hides value label
 //  // =Slider 5
 //  radialMirrorSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+160+10, sliderWidth);
 //  radialMirrorSlider.setInertia(sticky);
 //  radialMirrorSlider.setValue(radialMirror);
 //  radialMirrorSlider.setRenderMaxMinLabel(false); //hides labels
 //  radialMirrorSlider.setRenderValueLabel(false);  //hides value label
 //  radialMirrorSlider.setStickToTicks(true);
 // =Slider 6
 resolutionSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+200+10, sliderWidth);
 resolutionSlider.setInertia(sticky);
 resolutionSlider.setTickCount(5);
 resolutionSlider.setRenderMaxMinLabel(false); //hides labels
 resolutionSlider.setRenderValueLabel(false);  //hides value label
 resolutionSlider.setStickToTicks(true);
 resolutionSlider.setLimits(1, 0, 5);
 resolutionSlider.setValue(res);
 // =Slider 7 aka Arc Resolution
 curveFactorSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+240+10, sliderWidth);
 curveFactorSlider.setInertia(sticky);
 curveFactorSlider.setTickCount(13);
 curveFactorSlider.setRenderMaxMinLabel(false); //hides labels
 curveFactorSlider.setRenderValueLabel(false);  //hides value label
 curveFactorSlider.setStickToTicks(true);
 curveFactorSlider.setLimits(1, 2, 16);
 curveFactorSlider.setValue(curveFactor);

// =Slider 8
 postRotationSlider = new GWSlider(this, "purple18px", 186, 124, 340);
 postRotationSlider.setInertia(10);
 postRotationSlider.setTickCount(16);
 postRotationSlider.setRenderMaxMinLabel(false); //hides labels
 postRotationSlider.setRenderValueLabel(false);  //hides value label
 postRotationSlider.setStickToTicks(false);
 postRotationSlider.setLimits(1, 1, 360);
 postRotationSlider.setValue(postRotation);

// Slider 8 -> arm height
 // =Slider 8
 armHeightSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+320+10, sliderWidth);
 armHeightSlider.setInertia(10);
 armHeightSlider.setTickCount(4);
 armHeightSlider.setRenderMaxMinLabel(false); //hides labels
 armHeightSlider.setRenderValueLabel(false);  //hides value label
 armHeightSlider.setStickToTicks(false);
 armHeightSlider.setLimits(1, 5, 110);
 armHeightSlider.setValue(armHeight);

// Slider 9 -> Bulb Size
 bulbSlider = new GWSlider(this, "purple18px", menuLeftRule, 55+280+10, sliderWidth);
 bulbSlider.setInertia(20);
 bulbSlider.setTickCount(16);
 bulbSlider.setRenderMaxMinLabel(false); //hides labels
 bulbSlider.setRenderValueLabel(false);  //hides value label
 bulbSlider.setStickToTicks(true);
 bulbSlider.setLimits(1, 2, 50);
 bulbSlider.setValue(bulbSize);
 }

////////////////////////////////////// DRAW ////////////////////////// DRAW ////////////////////////// DRAW //////////////////////////////////////////// DRAW //////////////////////////////////

void draw() {
 update(mouseX, mouseY);

// strap sliders to mesh
 elbowCircumference =  elbowCircumferenceSlider.getValue();
 baseCircumference =  baseCircumferenceSlider.getValue();
 armDistance =  armDistanceSlider.getValue()*5;
 postHeight =  postHeightSlider.getValue()*8;
 res = resolutionSlider.getValue();
 curveFactor = curveFactorSlider.getValue();
 postRotation = postRotationSlider.getValue()*2;
 bulbSize = bulbSlider.getValue();
 armHeight = armHeightSlider.getValue();

background(BGcolor);

lights();

pushMatrix();
 translate(512, 512);
 rotateZ(radians(0));
 rotateX(radians(90));
 rotateZ(radians(90));

// draw floor plane
 fill(floorPlaneColor);
 rectMode(CENTER);
 rect(0, 0, height*1.5, width);
 rectMode(CORNER);

popMatrix();

pushMatrix();
 translate(512, 512);
 // rotateZ(radians(mouseX));
 rotateX(radians(90));
 rotateZ(radians(postRotation));

/////////////////////////////////////////////////////// DRAW POST /////////////////////////////////////////

//draw main post
 fill(postColor);
 drawMainPost(resolution[res], baseCircumference, elbowCircumference, postHeight);
 popMatrix();
 // draw arm
 btube = makeBezTube(elbowCircumference, curveFactor, 7+(res+1), armDistance, lampType);
 pushMatrix();
 translate(512, 512-(postHeight/2) );
 rotateX(radians(90));
 rotateZ(radians(postRotation-90));
 btube.draw();
 popMatrix();

//////////////////////////////////////////////////  UI Design elements ////////////////////////////////////

// semi opaque squares for sliders menu bg and lamptype bg
 rectMode(CORNER);
 strokeWeight(1);
 stroke(0);
 fill(127, 127);

// menu background
 rect(40, 40, 140, 370);

//  // -1  button
 //  rect(536, 56, 32, 32);
 //  pushMatrix();
 //  translate(524, 40);
 //  strokeWeight(4);
 //  line(20, 32, 26, 32);
 //  line(30, 24, 30, 40);
 //  strokeWeight(1);
 //  fill(127, 127);
 //  popMatrix();

// N post button
 rect(466, 40, 64, 64);
 pushMatrix();
 translate(458, 40);
 strokeWeight(4);
 line(32, 16, 32, 48);
 line(30, 16, 40, 20);
 line(40, 20, 48, 15);
 line(48, 15, 53, 19);
 strokeWeight(1);
 fill(255, 210, 30, 180);
 ellipseMode(CENTER);
 ellipse(55, 22, 10, 10);
 fill(127, 127);
 popMatrix();

// L post button
 rect(396, 40, 64, 64);
 pushMatrix();
 translate(400, 40);
 strokeWeight(4);
 line(18, 18, 18, 48);
 line(16, 18, 40, 18);
 strokeWeight(1);
 fill(255, 210, 30, 255);
 ellipseMode(CENTER);
 ellipse(40, 20, 10, 10);
 fill(127, 127);
 popMatrix();

// basic curve post button
 rect(326, 40, 64, 64);
 pushMatrix();
 translate(320, 44);
 strokeWeight(4);
 noFill();
 arc(42, 16, 20, -20, 0, PI);
 line(32, 16, 32, 48);
 strokeWeight(1);
 fill(255, 210, 30, 180);
 ellipseMode(CENTER);
 ellipse(50, 16, 10, 10);
 fill(127, 127);
 popMatrix();

//  quarter curve
 rect(256, 40, 64, 64);
 pushMatrix();
 translate(250, 44);
 strokeWeight(4);
 noFill();
 arc(32, 24, 34, -34, 0, PI/2);
 line(32, 6, 32, 48);
 strokeWeight(1);
 fill(255, 210, 30, 180);
 ellipseMode(CENTER);
 ellipse(50, 24, 10, 10);
 fill(127, 127);
 popMatrix();

// point light
 rect(186, 40, 64, 64);
 pushMatrix();
 translate(186, 40);
 strokeWeight(4);
 line(32, 16, 32, 48);
 strokeWeight(1);
 fill(255, 210, 30, 180);
 ellipseMode(CENTER);
 ellipse(32, 16, 10, 10);
 fill(127, 127);
 popMatrix();

noStroke();
 //text color
 fill(200);
 //title
 text("LAMP-POST GENERATOR V1.1", width - 256, 40);

//menu
 text("Elbow Circumference", menuLeftRule, 55);
 text("Post Height", menuLeftRule, 55+40);
 text("Base Circumference", menuLeftRule, 55+80);
 text("Arm Distance", menuLeftRule, 55+120);
 //  text ("Radial Mirror", menuLeftRule, 55+160);
 text("Mesh Resolution", menuLeftRule, 55+200);
 text("Arm Resolution", menuLeftRule, 55+240);
 text("Bulb Size", menuLeftRule, 55+280);
 text("Arm Height", menuLeftRule, 55+320);
 text("Post Rotation", 186, 120);
 //lamptype Selectors

println(inverter);
 }

////////////////////////   end  draw /////////////////////   end  draw /////////   end  draw /////////   end  draw //////

//PRINTOUT sliders

void handleSliderEvents(GSlider slider) {
 println("integer value:" + slider.getValue() + " float value:" + slider.getValuef());
 }

///////////////////////////// begin draw for posts

//BASE CLASS
 void drawMainPost( int sides, float r1, float r2, float h)
 {
 float angle = 360 / sides;
 float halfHeight = h / 2;

// top
 beginShape();
 stroke(255);
 for (int i = 0; i < sides; i++) {
 float x = cos( radians( i * angle ) ) * r1;
 float y = sin( radians( i * angle ) ) * r1;
 vertex( x, y, -halfHeight);
 }
 noStroke();
 endShape(CLOSE);

// bottom
 beginShape();
 stroke(255);
 for (int i = 0; i < sides; i++) {
 float x = cos( radians( i * angle ) ) * r2;
 float y = sin( radians( i * angle ) ) * r2;
 vertex( x, y, halfHeight);
 }
 noStroke();
 endShape(CLOSE);

// draw body
 beginShape(QUAD_STRIP);
 for (int i = 0; i < sides + 1; i++) {  float x1 = cos( radians( i * angle ) ) * r1;  float y1 = sin( radians( i * angle ) ) * r1;  float x2 = cos( radians( i * angle ) ) * r2;  float y2 = sin( radians( i * angle ) ) * r2;  vertex( x1, y1, -halfHeight);  vertex( x2, y2, halfHeight);  }  endShape(CLOSE);  } // ARM CLASS  public BezTube makeBezTube(int thickness, int curveFactor, int numbSlices, int armLength, int lampType) { if (lampType == 2) { //lampType selection  PVector[] p = new PVector[] {  new PVector(0f, 0f, 0f-armHeight),  new PVector(0f, 1f*(armLength), 0f-armHeight)  };  BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);  bt.fill(color(postColor));  bt.stroke(color(postColor));  bt.fill(color(postColor), BezTube.BOTH_CAP);  // attach a bulb @ arms length  pushMatrix();  translate(512, 512-postHeight/2+armHeight);  pushMatrix();  rotateY(radians(-postRotation));  translate(armDistance, 0);  fill(255, 210, 30, 70);  sphere(bulbSize);  popMatrix();  popMatrix();  return bt;  } if (lampType == 3) { //lampType selection //-> DONE
 PVector[] p = new PVector[] {
 new PVector(0f, 0f, 0f-armHeight),
 new PVector(0f, 0f, 100f-armHeight),
 new PVector(0f, 1f*(armLength), 100f-armHeight),
 new PVector(0f, 1f*(armLength), 0f-armHeight)
 };
 BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);
 bt.fill(color(postColor));
 bt.stroke(color(postColor));
 bt.fill(color(postColor), BezTube.BOTH_CAP);
 // attach a bulb @ arms length
 pushMatrix();
 translate(512, 512-postHeight/2+armHeight);
 pushMatrix();
 rotateY(radians(-postRotation));
 translate(armDistance, 0);
 fill(255, 210, 30, 70);
 sphere(bulbSize);
 popMatrix();
 popMatrix();
 return bt;
 }

if (lampType == 4) { //lampType selection
 PVector[] p = new PVector[] {
 new PVector(0f, 0f, -(armHeight)*1f),
 new PVector(0f, 1f*(armLength), 0f-armHeight),
 new PVector(0f, 1f*(armLength), -armLength-armHeight)
 };
 BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);
 bt.fill(color(postColor));
 bt.stroke(color(postColor));
 bt.fill(color(postColor), BezTube.BOTH_CAP);
 // attach a bulb @ arms length
 pushMatrix();
 // rotateY(radians(90));
 translate(512, (512-postHeight/2)+armLength+armHeight);
 pushMatrix();
 rotateY(radians(-postRotation));
 translate(armDistance, 0);
 fill(255, 210, 30, 70);
 sphere(bulbSize);
 popMatrix();
 popMatrix();
 return bt;
 }

if (lampType == 5) { //lampType selection
 PVector[] p = new PVector[] {
 new PVector(0f, 0f, 0f),
 new PVector(0f, 0f, 0f)
 };
 BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);
 bt.fill(color(postColor));
 bt.stroke(color(postColor));
 bt.fill(color(postColor), BezTube.BOTH_CAP);
 // attach a bulb
 pushMatrix();
 // rotateY(radians(90));
 translate(512, 512-postHeight/2+armHeight);
 fill(255, 210, 30, 70);
 sphere(bulbSize);
 popMatrix();
 return bt;
 }

if (lampType== 1) {
 PVector[] p = new PVector[] {
 new PVector(0f, 0f, -armHeight),
 new PVector(0f, 0f, -100f-armHeight),
 new PVector(0f, 1f*(armLength), 100f-armHeight),
 new PVector(0f, 1f*(armLength), 0f-armHeight)
 };
 BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);
 bt.fill(color(postColor));
 bt.stroke(color(postColor));
 bt.fill(color(postColor), BezTube.BOTH_CAP);
 // attach a bulb @ arms length
 pushMatrix();
 // rotateY(radians(90));
 translate(512, 512-postHeight/2+armHeight);
 pushMatrix();
 rotateY(radians(-postRotation));
 translate(armDistance, 0);
 fill(255, 210, 30, 70);
 sphere(bulbSize);
 popMatrix();
 popMatrix();
 return bt;
 }

else {
 /// draw first style
 PVector[] p = new PVector[] {
 new PVector(0f, 0f, -armHeight),
 new PVector(0f, 0f, -100f-armHeight),
 new PVector(0f, 1f*(armLength), 100f-armHeight),
 new PVector(0f, 1f*(armLength), 0f-armHeight)
 };
 BezTube bt = new BezTube(this, new Bezier3D(p, p.length), thickness, curveFactor, numbSlices);
 bt.fill(color(postColor));
 bt.stroke(color(postColor));
 bt.fill(color(postColor), BezTube.BOTH_CAP);
 // attach a bulb @ arms length
 pushMatrix();
 // rotateY(radians(90));
 translate(512, 512-postHeight/2+armHeight);
 pushMatrix();
 rotateY(radians(-postRotation));
 translate(armDistance, 0);
 fill(255, 210, 30, 70);
 sphere(bulbSize);
 popMatrix();
 popMatrix();
 return bt;
 }
 }

void update(int x, int y)
 {
 if ( lampType1(466, 40, 64, 64) ) {
 lampType1_over = true;
 lampType2_over = false;
 lampType3_over = false;
 lampType4_over = false;
 lampType5_over = false;
 }
 if ( lampType2(396, 40, 64, 64) ) {
 lampType1_over = false;
 lampType2_over = true;
 lampType3_over = false;
 lampType4_over = false;
 lampType5_over = false;
 }
 if ( lampType2(326, 40, 64, 64) ) {
 lampType1_over = false;
 lampType2_over = false;
 lampType3_over = true;
 lampType4_over = false;
 lampType5_over = false;
 }
 if ( lampType2(256, 40, 64, 64) ) {
 lampType1_over = false;
 lampType2_over = false;
 lampType3_over = false;
 lampType4_over = true;
 lampType5_over = false;
 }
 if ( lampType2(186, 40, 64, 64) ) {
 lampType1_over = false;
 lampType2_over = false;
 lampType3_over = false;
 lampType4_over = false;
 lampType5_over = true;
 }

//  if ( inverterButton(536, 56, 32, 32) ) {
 //    inverterButton = true;
 //  }
 }

////////////////// mouse pressed to counter

void mouseClicked()
 {
 //  if (inverterButton) {
 //    inverter = inverter * -1;
 //  }

if (lampType1_over) {
 lampType = 1;
 }

if (lampType2_over) {
 lampType = 2;
 }

if (lampType3_over) {
 lampType = 3;
 }

if (lampType4_over) {
 lampType = 4;
 }

if (lampType5_over) {
 lampType = 5;
 }
 }

///////////////// button checks

//boolean inverterButton(int x, int y, int width, int height) {
 //  if (mouseX >= x && mouseX <= x+width &&  //    mouseY >= y && mouseY <= y+height) {  //    return true;  //  }  //  else {  //    return false;  //  }  //}  boolean lampType1(int x, int y, int width, int height)  {  if (mouseX >= x && mouseX <= x+width &&  mouseY >= y && mouseY <= y+height) {  return true;  }  else {  return false;  }  } boolean lampType2(int x, int y, int width, int height)  {  if (mouseX >= x && mouseX <= x+width &&  mouseY >= y && mouseY <= y+height) {  return true;  }  else {  return false;  }  }  boolean lampType3(int x, int y, int width, int height)  {  if (mouseX >= x && mouseX <= x+width &&  mouseY >= y && mouseY <= y+height) {  return true;  }  else {  return false;  }  }  boolean lampType4(int x, int y, int width, int height)  {  if (mouseX >= x && mouseX <= x+width &&  mouseY >= y && mouseY <= y+height) {  return true;  }  else {  return false;  }  }  boolean lampType5(int x, int y, int width, int height)  {  if (mouseX >= x && mouseX <= x+width &&  mouseY >= y && mouseY <= y+height) {
 return true;
 }
 else {
 return false;
 }
 }

}

Copyright © All right reserved. | Theme: Full Click by eVisionThemes