taking sections of 3d shapes

Hi All, i'm working on project were we have kind of a water nozzle system, a bidimensional array. Nothing new, the idea is to make water shapes fall from those nozzles.

So what i need is a way to import a solid into processing, section it, and for each sections see what points (each one corresponding to a nozzle) is inside or outside.

I have two ways in my mind: taking actual sections as image (i would prefer) and then having a filled shape, to do a bidimensional boolean operation (i saw something in toxic lib) or having actual 3d boolean, to see if a point is or is not inside a shape).

I had a look to toxic lib but i was unable to really find a way to di this slicing of a 3d object.

I guess is a common problem, for example, for preparing 3d print file starting from a stl.

Any suggestion?

Tagged:

Answers

  • edited June 2017

    So like one of these falling water nozzle systems, only a grid rather than a strip?

    What is your input data format -- or what are the formats you are considering?

    You could render the shape, set the perspective to underneath the shape, and set a narrow clipping slice area which is a thin plane perpendicular to the camera perspective. Now advance the object toward the camera each frame, and different cross sections will be rendered according to how they intersect with the clipping area. Check the image values to activate your nozzles. (untested)

  • edited June 2017

    Hi jeremy, actually our goal is more like this: The point is that is tridimentional. The clipping function act in a bidimentional way from the point of view. So basically what i think i need to do is more something like this: Any idea about some library, even a java library, i could potentially use for doing this in processing?

  • edited June 2017

    Yes, I understood -- sorry if that wasn't clear from my response.

    That is why I recommended using perspective() -- you can set a clipping plane (the line passing through your dragon) using only the perspective() command zNear and zFar arguments. As long as you load your 3D object in "overhead" position, then calling perspective will give you the cross sections you need in (a) and (b) -- and these can be used to drive nozzle activation.

    Here is a simple example sketch. For demo objects it shows a simple rotated cube and a simple sphere. Moving the clipping plane over the volumes generates nozzle activation data as a cross sectional image that changes over time.

    // falling water sculptures with clipping cross-sections
    // Jeremy Douglass 2017-06-29 Processing 3.3.5
    // forum.processing.org/two/discussion/23210/taking-sections-of-3d-shapes
    
    float fovy;
    float aspect;
    float cameraZ;
    float zNear;
    float zFar;
    
    boolean clipMode;
    int clipStep;
    int CLIPDEPTH = 5;
    int shape;
    
    void setup() {
      size(200, 200, P3D);
    
      // default perspective values
      fovy = PI/3.0; 
      aspect = width/height;
      cameraZ = (height/2.0) / tan(PI*60.0/360.0);
      zNear = cameraZ/10.0; // 17.32
      zFar = cameraZ*10.0;  // 1732
      stroke(200);
    }
    
    void draw() {
      background(0);
      perspective(fovy, aspect, zNear, zFar);
      text("Space to switch and advance", 5, 15);
      if (clipMode) {
        clipStep = frameCount%200 + 50;
        perspective(fovy, aspect, clipStep, clipStep + CLIPDEPTH);
      }
      drawShape(shape);
      callNozzles();
    }
    
    void drawShape(int shape) {
      switch(shape) {
      case 0: 
        pushMatrix();
        translate(100, 100);
        rotateX(PI/3);
        rotateY(PI/3);
        box(100);
        popMatrix();
        break;
      case 1: 
        pushMatrix();
        translate(100, 100);
        rotateX(PI/3);
        rotateY(PI/3);
        sphere(75);
        popMatrix();
        break;
      }
    }
    
    void callNozzles() {
      // use pixels[] or get()
      // to check values
      // and turn nozzles on or off.
    }
    
    void keyPressed() {
      clipMode = !clipMode;
      if (!clipMode) {
        shape = (shape+1)%2;
      }
    }
    

    In the case of your dragon object, you need to load the dragon shape into the space and orient it so that the default camera appears to be "overhead." Then manipulating zNear / zFar as in this example sketch will give you the expected clipping results as in (a) and (b).

    These cross sectional shapes could be hollow or filled, and they could be played in real-time or they could be written to an array of nozzle data so that the graphic scan only needs to be performed once per object.

  • Hi Jeremy, just tried this importing an external obj, it works as well, looks like a very creative solution :-) I could try to render this in a pgraphic to reimport it. Do you think there is any way to have an inner fill in the shapes? Thank you btw

  • edited July 2017

    I'm actually not sure if there is a built-in way to render clipped object faces as solid -- I don't believe so.

    One simple approach is to implement flood fill of the background -- then invert to find the foreground. This won't work if there are captured background shapes, however.

    There is a scanline flood fill example in this thread:

Sign In or Register to comment.