Page 1 of 3 123 LastLast
Results 1 to 20 of 53
  1. #1
    Member
    Join Date
    Jul 2002
    Posts
    2,490

    Calculating the volume of a model

    Is there a python script to calculate the volume of a model?



  2. #2
    I really doubt it. It's not a trivial problem. If you really need it you'll probably have to code it yourself or convince someone else to. Here is a paper that explains one method of doing it: http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf

    If the reason you want it is for a game, you're probably better off just guessing at a number that works well with the physics.



  3. #3
    Member
    Join Date
    Jul 2002
    Posts
    2,490
    I have an idea.
    Now I work on a model that I want to print on a 3d wax printer. So this is why I need the volume.
    This printer works simple: it build the model from bottom to top by printing the section planes.

    So we need a script that slice the model to planes (virtually) and calculate the pixels on the plane that is in the body of the model.



  4. #4
    I am pretty sure that things like that can be done in Catia, at least I saw it done on my university. Is it necessary to do it in blender? I presume you don't have 3d printer at home, so is that a college assignment? Nice little thing, right?!



  5. #5
    Member
    Join Date
    Aug 2002
    Location
    Christchurch New Zealand (aka Aotearoa)
    Posts
    7,245
    just drop the model into a fluid sim bath, with an overflow into a known volume like a cube-jug thing with markings.

    might take a while but will be fairly accurate i would hope (how detailed is the model, it might be plus/minus a bit, probably will over-estimate the volume)

    yes its a huge workaround, but hey :P


    Alltaken
    Flippin Designer



  6. #6
    Member SamAdam's Avatar
    Join Date
    Mar 2004
    Location
    Columbus, Ohio, USA
    Posts
    2,581
    With a bit of calculus it is easily doable. Just slice the model into very thin planes, maybe about .01 apart. Then find vertices at the intersections of the original tris and that plane. Then do a triangle fill. Then find the area of the triangles. Then multiply the sum of all the areas by the thickness (.01) and then take the sum of all those.

    And that should do it.
    Go Bucks!



  7. #7
    Member slikdigit's Avatar
    Join Date
    Oct 2001
    Location
    Northampton, MA
    Posts
    1,804
    It should be doable with sum bounding box-tree method methinks- those functions might be already in blender to use for raytracing or so- won't be perfectly accurate but the more you subdivide the closer you get. It's doable, but I guess the functions will be slow if you do it all in python ?



  8. #8
    Member Fligh's Avatar
    Join Date
    Dec 2002
    Location
    Here
    Posts
    10,428
    Scorpius wrote a script for surface volume and (if I remember correctly) Bullx did the 'paper layers' thing but ended up using some other program (both in about 2003 though). I'll see what I can find in search.

    %<

    http://blenderartists.org/forum/showthread.php?t=49216

    It wasn't Bullx, it was MrMunkily:

    http://blenderartists.org/forum/showthread.php?t=17579

    %<
    Last edited by Fligh; 20-Dec-06 at 00:03.
    BLENDER - You'll get it when you get it.



  9. #9
    Member macouno's Avatar
    Join Date
    Jan 2002
    Location
    netherlands
    Posts
    2,729
    I've got a script online that does surface areas and such... volume is tricky though. There are a lot of standards for volume as well.
    Fligh: surface volume doesn't sound like volume at all... a surface is normally quite flat.
    Slicing a model shouldn't be too hard, tricky but not too hard. very codeable.



  10. #10
    Member PapaSmurf's Avatar
    Join Date
    Sep 2004
    Location
    Southeast USA
    Posts
    8,812
    Alltaken: I think that's how Socrates came to idea of mass; at least that's the urban legend he sat in a bathtub and it overflowed.



  11. #11
    Member
    Join Date
    Aug 2002
    Location
    Christchurch New Zealand (aka Aotearoa)
    Posts
    7,245
    eureka.....
    Flippin Designer



  12. #12
    Member
    Join Date
    Jun 2006
    Location
    Baja California Sul
    Posts
    7,836
    Originally Posted by RogerWickes View Post
    Alltaken: I think that's how Socrates came to idea of mass; at least that's the urban legend he sat in a bathtub and it overflowed.
    Umm, that was Archimedes in the bathtub. Socrates was the guy they poisoned for corrupting the youth. His main interest was politics and logic, not physics.
    Finished Projects: Absinthe on the Rocks
    Focused Critique: Anime Girl
    Animation: Cartoon Girl Shelly



  13. #13
    Member GreyBeard's Avatar
    Join Date
    May 2003
    Location
    Vancouver BC, Canada
    Posts
    1,742
    I can give you an algorithm but don't have time to code it. The mesh must be completely triangulated, manifold, with normals pointing outside. Imagine a plane (say zplane) that is parallel to the z axis located some distance underneath your model.

    pseudo code:

    area A = 0
    iterate through all faces (triangles)
    if the face normal vector's z component is positive
    --calculate the volume between the face and zplane and add to A
    if the face normal vector's z component is negative
    --calculate the volume between the face and zplane and subtract from A
    if the face normal vector's z component is zero
    --do nothing
    finished all faces
    print A

    Will work for all meshes including ones with holes -- even completely enclosed interior holes (carefull with the normals though)

    GreyBeard

    PS: its based on the way surveyors calculate areas and volumes from coordinates. I believe its the same method as discussed in RobCossens link but in terms a non-mathematician can understand.
    Last edited by GreyBeard; 28-Dec-06 at 13:00. Reason: change non-manifold to manifold



  14. #14
    Member GreyBeard's Avatar
    Join Date
    May 2003
    Location
    Vancouver BC, Canada
    Posts
    1,742
    I had some time this evening so I banged out the script (It just prints the volume to the console).

    http://members.shaw.ca/rjplus/volume.py

    Here was one of my test objects:



    The volume if it was a true sphere is calculated by hand to be 1.814 and the script gives a volume of 1.800 using the triangulated surface.

    GreyBeard

    P.S. be sure to heed the warnings or you will get incorrect results.
    Last edited by GreyBeard; 22-Dec-06 at 07:21.



  15. #15
    Member
    Join Date
    Jul 2002
    Posts
    2,490
    Thank you! I will try this script!



  16. #16
    Member macouno's Avatar
    Join Date
    Jan 2002
    Location
    netherlands
    Posts
    2,729
    GreyBeard, very cool... I know more people have been looking for this. I'll test it out later.
    Would you mind if I added a version that also works for quads to my odd measurements script (seems natural to have this function in there), and would you have a link I can use to give you credit?



  17. #17
    Member GreyBeard's Avatar
    Join Date
    May 2003
    Location
    Vancouver BC, Canada
    Posts
    1,742
    macouno,

    Help yourself to the code. I am unfamiliar with python and the differences between NMesh and Mesh so I don't know when I am creating a copy of the mesh data or referencing the original data --- line 24 can probably be changed

    from:
    mymesh = NMesh.GetRawFromObject(obname)
    to:
    mymesh = obj.getData()

    I am also not sure if "set smooth" changes the stored mesh data's face normals -- doing a "set solid" would probably be a good idea. Also apply any subsurfing before the triangulation of the mesh -- it appears that NMesh stores the subsurfed verts as well as the cage. The blender wiki python cookbook already has the code to convert the mesh to triangles.

    Attribution is not required (only a few lines of code). I just found the algorithm rather elegant.

    GreyBeard
    Last edited by GreyBeard; 28-Dec-06 at 13:03.



  18. #18
    Member Nyrath's Avatar
    Join Date
    May 2005
    Location
    the praeternatural tower
    Posts
    961
    GreyBeard, thank you so much! I had been looking for something like this for years.

    You see, there is a script like this for Lightwave:
    http://mywebpages.comcast.net/erniew...f/areavol.html

    There are science fiction fans in general, and Star Trek fans in particular, who obsess over such pointless issues as what is the internal volume of the starship Enterprise. Since the ships are seldom simple Euclidean shapes, this is not easy.

    A fan was using the Lightwave script to determine the volume of various trek ships.
    http://www.st-v-sw.net/STSWvolumetrics.html

    I had wanted something similar for Blender, and now I have it.
    Thanks again!



  19. #19
    Member
    Join Date
    Aug 2002
    Location
    Christchurch New Zealand (aka Aotearoa)
    Posts
    7,245
    Nyrath, cool now you can make awsome websites like that
    Flippin Designer



  20. #20
    Member yorik's Avatar
    Join Date
    Mar 2006
    Location
    São Paulo, Brazil
    Posts
    136
    This is very, very useful script!!! Thanks!



Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •