Pixels export .mtl
in
Contributed Library Questions
•
8 months ago
Hey all,
Quick question, as I am not sure this is doable. I am new to processing as a sidenote..
I have taken an image into processing, and as all the examples on pixels show, exploded it based on the image pixels saturation or hue or brightness.
I can export those exploded mesh faces and get them into rhino no problem with a set color using muehlseife library which outputs a .mtl file and an obj. However, the whole object is one color, what I want is that each rectangle from the exploded image maintains its color.
I am using the geo.setMaterial ("string", int,int,int,int) so basically the material name and RGBA values. I thought I could use color c = img.pixels[loc] since later on in the code I fill(c) which is reading the color from the pixels. So I tried ("name", int(c), int(c), int(c), int(c)) But no luck. Anyone ever tried to export the pixel color data before? My code, which is probably sloppy is below...Any help would be great!
- import peasy.*;
- PeasyCam cam;
- import muehlseife.*;
- String outputFolder;
- PImage img; // The source image
- int cellsize = 6; // Dimensions of each cell in the grid
- int cols, rows; // Number of columns and rows in our system
- public void setup(){
- size(800,764,P3D);
- cam = new PeasyCam(this, width/2, height/2, 100, 100);
- img = loadImage("All Surface Invert full screen_small.jpg"); // Load the image
- cols = width/cellsize; // Calculate # of columns
- rows = height/cellsize; // Calculate # of rows
- smooth();
- background (0);
- }
- public void draw (){
- GeometryExporter geo = new GeometryExporter(this);
- //start the recording
- beginRaw(geo);
- loadPixels();
- // Begin loop for columns
- for ( int i = 0; i < cols;i++) {
- // Begin loop for rows
- for ( int j = 0; j < rows;j++) {
- int x = i*cellsize + cellsize/2; // x position
- int y = j*cellsize + cellsize/2; // y position
- int loc = x + y*width; // Pixel array location
- color c = img.pixels[loc]; // Grab the color
- // Calculate a z position as a function of mouseX and pixel brightness
- float z = (mouseY/(float)width) * brightness(img.pixels[loc]) - 500.0;
- // Translate to the location, set fill and stroke, and draw the rect
- pushMatrix();
- translate(x,y,z);
- fill(c);
- noStroke();
- rectMode(CENTER);
- rect(0,0,cellsize,cellsize);
- popMatrix();
- //make group
- geo.setObject("normal");
- //assign a material
- geo.setMaterial("imagecolor", int(mouseX),int(mouseY),int(mouseX),255);
- updatePixels();
- }
- }
- endRaw();
- }
1