hemesh-controlp5 question
in
Contributed Library Questions
•
2 years ago
how do I link the hemesh box chamfer to the control p5 slider. It doesn't update with the rest of the script.
- import controlP5.*;
- import wblut.hemesh.modifiers.*;
- import wblut.hemesh.tools.*;
- import wblut.hemesh.wip.*;
- import wblut.hemesh.subdividors.*;
- import wblut.hemesh.*;
- import wblut.hemesh.creators.*;
- import wblut.geom.*;
- import wblut.math.*;
- import wblut.hemesh.kdtree.*;
- import guicomponents.*;
- import processing.opengl.*;
- //declare
- GVertSlider sdrScale;
- float zoom;
- float zoomfactor;
- Particle p[];
- int num;
- HE_Mesh mesh;
- //slider declare
- ControlP5 controlP5;
- int Chamfer = 100;
- void setup(){
- size(500, 500, OPENGL);
- hint(DISABLE_OPENGL_2X_SMOOTH);
- hint(ENABLE_OPENGL_4X_SMOOTH);
- noSmooth();
- //slider setup
- controlP5 = new ControlP5(this);
- controlP5.addSlider("Chamfer",0,255,128,200,0,100,10);
- HEC_Cube cube = new HEC_Cube(this).setEdge(100);
- mesh = new HE_Mesh(cube);
- HEM_ChamferCorners cc = new HEM_ChamferCorners().setDistance(10);
- mesh.modify(cc);
- fill(000);
- //slider setup
- GComponent.globalColor = GCScheme.getColor(this, GCScheme.GREEN_SCHEME);
- GComponent.globalFont = GFont.getFont(this, "Serif", 11);
- sdrScale = new GVertSlider(this, 0, 0, 10, height);
- sdrScale.setLimits(200, 0, height);
- sdrScale.setInertia(1);
- zoomfactor = 45.0f / height;
- zoom = 0.1 * zoomfactor * sdrScale.getValue();
- initialize();
- }
- void draw(){
- pushMatrix();
- translate(width/2, height/2, -200);
- noStroke();
- background(000);
- lights();
- scale(zoom);
- fill(255);
- stroke(255);
- for(int i=0;i<p.length;i++){
- p[i].update();
- translate(width/2, height/2, -200);
- p[i].draw();
- }
- popMatrix();
- }
- void initialize() {
- num=int(random(1,5));
- p=new Particle[num];
- for(int i=0; i<num; i++) {
- p[i]=new Particle();
- }
- }
- void handleSliderEvents(GSlider slider){
- zoom = zoomfactor * slider.getValue() * 0.1f;
- }
- //Particle class
- class Particle{
- Particle(){
- }
- void update(){
- rotateX(frameCount*PI/150);
- rotateY(frameCount*PI/170);
- rotateZ(frameCount*PI/90);
- }
- void draw(){
- fill(#79d11a);
- noStroke();
- mesh.drawFaces();
- noFill();
- stroke(0);
- mesh.drawEdges();
- saveFrame("hemesh-chamfercorners.png");
- }
- }
1