[Closed] detect shape
Hiya! I am trying to detect if an imported object is a cube or cylinder. Normally I would try some ideas first and post them here but I honestly don’t have any “simple” ideas on how to do it. It could be said I don’t have any “difficult” ideas either. Is there an existing script somewhere I can use as reference to get started?
Thanks!
You mean, check the mesh itself to see if its a box? As in, the overall shape?
I wouldn’t use the bounds box, since that won’t help really. The first thought to mind is to select a Vertex, and get the faces connected to that Vertex. Then from there, compare angles between faces or something.
So if you have a simple box, if u grabbed any vert, u should get 3 faces/sides, and the angles should be 90 degrees or around there from each other. If it was a Cylinder, you’d get very minimal changes if it was on the rounded side.
#1.
to find a sphere is simple. every vertex has to be at about the same distance from the center.
#2.
a cube is a bit complicated.
if cube is a 3d solid object bounded by six square faces then:
- find a pair of vertices with biggest distance. it’s a long diagonal of the cube.
- after that we know the dimension of the cube and its area
- check the summary face area of the object, if it equals the cube area the object is a cube.
Seems to me that volume test is a good comparison for cube.
(for ex. the cube with dimension 1 (1x1x1) has volume 1)
As for the cylinder, volumeselect modifier come to my mind.
another idea for cubes:
summing the angles around a vertex
corner=270
the rest = 360
total corners==8