Exporting Points Coordinate to Rhino for Grasshopper ( with DWG? )
in
Contributed Library Questions
•
8 months ago
Hello Processing Community
I am trying to export the Coordinate and their color code of a list of points ( 2000-5000 ) to Rhino for Grasshopper analyzing. I have tried the beginRAW(), but it said "only supports lines and triangles". But I do not want them to have any kind of form when they are exported to Rhino. Any work around?
Thank you for all contribution!
- //-----Importing Libraries-----Starts
- import processing.opengl.*;
- import peasy.*;
- import peasy.org.apache.commons.math.*;
- import peasy.org.apache.commons.math.geometry.*;
- import toxi.processing.*;
- import processing.dxf.*;
- //-----Importing Libraries-----Ends
- //-----Defining Vectors-----Starts
- Vec3D globalDrift, dir, focusPoint;
- Vector particles;
- //-----Defining Vectors-----Ends
- //-----Defining Planes-----Starts
- Plane focalPlane;
- //-----Defining Planes-----Ends
- public float neighbor, viscosity, speed, turbulence, strokefactor, cameraRate, rebirthRadius, spread, spread_, independence, dofRatio, backcolour;
- public int n;
- public boolean paused, label, stopR, dxfExport;
- PeasyCam cam;
- CameraState state;
- int focusX;
- float focusPointx=0;
- float focusPointy=0;
- float focusPointz=0;
- void setup() {
- size(2200, 1300, OPENGL);
- smooth();
- frameRate(30);
- cam = new PeasyCam(this, focusPointx, focusPointy, focusPointz, 1700);
- state = cam.getState();
- // {
- // println("COM Ports");
- // println(myPort.list());
- // println("=========");
- // myPort = new Serial(this, Serial.list()[5], 9600);
- // }
- setParameters();
- makeGUI();
- focusPoint = new Vec3D();
- dir = new Vec3D();
- globalDrift = new Vec3D(0, 1. / 3, 2. / 3);
- particles = new Vector();
- for (int i = 0; i < n; i++)
- particles.add(new Particle());
- }
- void draw() {
- Particle leader = (Particle) particles.get(0);
- focusPoint = leader.position;
- focusPointx = leader.position.x;
- focusPointy= leader.position.y;
- focusPointz= leader.position.z;
- println(focusPoint);
- translate(-focusPoint.x, -focusPoint.y, -focusPoint.z);
- float[] camPosition = cam.getPosition();
- focalPlane = new Plane(dir, new Vec3D(camPosition[0], camPosition[1], camPosition[2]));
- background(backcolour);
- noFill();
- hint(DISABLE_DEPTH_TEST);
- //--------------------- if export is TRUE
- if (dxfExport) {
- beginRaw(DXF, "output.dxf");
- }
- for (int i = 0; i < particles.size(); i++) {
- Particle cur = ((Particle) particles.get(i));
- if (!paused)
- cur.update();
- cur.draw();
- }
- if (particles.size() > n)
- particles.setSize(n);
- while (particles.size () < n)
- particles.add(new Particle());
- globalDrift.addSelf(
- turbulence / neighbor,
- turbulence / neighbor,
- turbulence / neighbor);
- // arduinoRead();
- // println(spread);
- // spread=spread_;
- //--------------------- finish export and set dxfExport to FALSE
- if (dxfExport) {
- endRaw();
- dxfExport = false;
- }
- //-----Camera Rotation-----Starts
- float[] look = cam.getLookAt();
- double disn = cam.getDistance();
- float[]rot = cam.getRotations();
- Rotation rotn = new Rotation(RotationOrder.XYZ,
- (double)rot[0], (double)rot[1], (double)rot[2]);
- if (!stopR) {
- Rotation rotd = new Rotation(RotationOrder.XYZ, -.002, -.002, -.002);
- Vector3D npos = new Vector3D(
- (double)look[0], (double)look[1], (double)look[2]);
- state = new CameraState(rotd.applyTo(rotn), npos, disn);
- }
- else {
- Rotation rotd = new Rotation(RotationOrder.XYZ, -.0, -.0, -.0);
- Vector3D npos = new Vector3D(
- (double)look[0], (double)look[1], (double)look[2]);
- state = new CameraState(rotd.applyTo(rotn), npos, disn);
- }
- cam.setState(state, 0);
- }
- //-----Camera Rotation-----Ends
- Particle randomParticle() {
- return ((Particle) particles.get((int) random(particles.size())));
- }
- void keyPressed() {
- if (key == 'p')
- paused = !paused;
- if (key == 'l')
- label = !label;
- if (key == 'r')
- stopR = !stopR;
- switch (key) {
- case 'x':
- dxfExport = true;
- println("DXF export complete!");
- break;
- }
- }
- //CLASS_PARTICLE---------------------------------------------------------
- Vec3D centerForce = new Vec3D();
- class Particle {
- Vec3D position, velocity, force;
- Vec3D localOffset;
- int red, green, blue;
- Particle() {
- initialisePosition();
- velocity = new Vec3D();
- force = new Vec3D();
- localOffset = Vec3D.randomVector();
- red = (int) random(0, 255);
- green = (int) random(0, 255);
- blue = (int) random(0, 255);
- }
- void initialisePosition() {
- position = Vec3D.randomVector();
- position.scaleSelf(random(rebirthRadius));
- if (particles.size() == 0)
- position.addSelf(dir);
- else
- position.addSelf(randomParticle().position);
- }
- void draw() {
- float distanceToFocalPlane = focalPlane.getDistanceToPoint(position);
- distanceToFocalPlane *= 1 / dofRatio;
- distanceToFocalPlane = constrain(distanceToFocalPlane, 1, 80);
- strokeWeight(distanceToFocalPlane*strokefactor);
- float r = red;
- float g = green;
- float b = blue;
- stroke(r, g, b, constrain(255 / (distanceToFocalPlane * distanceToFocalPlane), 1, 255));
- point(position.x, position.y, position.z);
- if (label) {
- textSize(8);
- fill(constrain(255 / (distanceToFocalPlane * distanceToFocalPlane), 1, 255));
- text(red, position.x, position.y, position.z);
- text(green, position.x, position.y-14, position.z);
- text(blue, position.x, position.y-28, position.z);
- }
- }
- void addFlock() {
- force.addSelf(
- noise(
- position.x / neighbor + globalDrift.x + localOffset.x * independence,
- position.y / neighbor,
- position.z / neighbor)
- - .5,
- noise(
- position.x / neighbor,
- position.y / neighbor + globalDrift.y + localOffset.y * independence,
- position.z / neighbor)
- - .5,
- noise(
- position.x / neighbor,
- position.y / neighbor,
- position.z / neighbor + globalDrift.z + localOffset.z * independence)
- - .5);
- }
- void addVisco() {
- force.addSelf(velocity.scale(-viscosity));
- }
- void addCen() {
- centerForce.set(position);
- centerForce.subSelf(dir);
- float distanceToCenter = centerForce.magnitude();
- centerForce.normalize();
- centerForce.scaleSelf(-distanceToCenter / (spread * spread));
- force.addSelf(centerForce);
- }
- void update() {
- force.clear();
- addFlock();
- addVisco();
- addCen();
- velocity.addSelf(force); // mass = 1
- position.addSelf(velocity.scale(speed));
- }
- }
- //CLASS_GUI-------------------------------------
- import controlP5.*;
- public ControlP5 control;
- public ControlWindow w;
- void setParameters() {
- n = 4000;
- dofRatio = 75;
- neighbor = 300;
- speed = 60;
- viscosity = .35;
- spread = 100;
- independence = .4;
- rebirthRadius = 350;
- turbulence =2.8;
- strokefactor = 8.5;
- cameraRate = 0;
- backcolour = 0;
- }
- void makeGUI() {
- control = new ControlP5(this);
- w = control.addControlWindow("controlWindow", 10, 10, 350, 700);
- w.hideCoordinates();
- w.setTitle("Particle Control");
- int y = 0;
- control.addSlider("n", 1, 30000, n, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("dofRatio", 1, 2000, dofRatio, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("neighbor", 1, width * 2, neighbor, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("speed", 0, 100, speed, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("viscosity", 0, 1, viscosity, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("spread", 40, 180, spread, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("independence", 0, 1, independence, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("turbulence", 0, 4, turbulence, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("strokefactor", 0.1, 20, strokefactor, 10, y += 16, 256, 14).setWindow(w);
- control.addSlider("backcolour", 0, 255, backcolour, 10, y += 16, 256, 14).setWindow(w);
- control.addToggle("paused", false, 10, y += 16, 14, 14).setWindow(w);
- control.addToggle("label", false, 10, y += 26, 14, 14).setWindow(w);
- control.addToggle("stopR", false, 10, y += 26, 14, 14).setWindow(w);
- control.setAutoInitialization(true);
- }
1