Operation on 3D model using Python in Processing

Hello everyone.

I need to do operation on every pixel of 3d model. How to go through every pixel of 3d model? Usually, in python we read image as array and using row & column we get particular pixel. But for 3d model how to do this.
Operation like any pixel of 3d model is in particular plane or not.

1 Like

It depends on what you mean by “3D model”.

If your “3D model” is a 3 dimensional array of colors (ie, voxels), then you can go through it the same way as you would with a 2D images, but with three loops instead of two.

Or you could draw 2D cross sections of it with relative ease…

If, however, your “3D model” is made up of lots of vertexes that draw many 2D triangles in a 3D space, you have a different sort of problem entirely.

3 Likes

I have OBJ file of 3d model.
Using loadShape() function i load 3D model in PShape type variable. PShape isn’t array so we can not perform like 2D image in python.

  1. can we convert PShape to array? and how?
  2. Any other way to load 3D model in array or any other thing?

This is that case where your 3D model is made up of lots of vertexes that draw 2D triangles in a 3D space.

The problem is that it’s not easy to even know if a point is inside your object or not - let alone determine what color that point should be! Essentially, your object is not solid - it is a paper-thin outer shell that only looks like a solid thing.

Imagine a stack of cardboard boxes all jumbled in a pile. You can look at them, and they look solid, but really they’re hollow. If you consider all the points in and around the pile, it is difficult to know if a point is inside any box.

If they were stacked neatly, you might be able to work out what a cross section looks like. (This is the Voxels case).

But your PShape is even more complicated than a jumbled pile of boxes. It’s not even cardboard boxes. It’s triangles of cardboard that are glued edge-to-edge to make a model. Working out if a point is inside the model or not is not only hard, it might not even be meaningful!


You could always just draw the model, then use the 2D image of it. That’d give you an array to work with. But what the colors are in that array would depend a lot on which way you drew looking at the 3D model.

2 Likes

How to get cross section area of plane and 3D model? Any particular way or function for it in processing or python.

Does anyone else ever get the feeling that no one is listening to you?

This is a very hard problem. There is no simple function to do it.

You might have some luck writing one yourself, but only if you pre-process your model to create a 3D (Voxel) dataset. Essentially you would be “filling in” your hollow outer shell with many well-stacked cardboard boxes. But even that is hard to do.

It depends on how complicated your object is, really. If your 3D object is a sphere, say, then cross sections are easy. Cubes less easy, but still possible. Anything more complex, and you’re going to have a hard time of it. So what’s the object anyway?

2 Likes