• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
johnnyBravo

Is it possible to calculate the volume for a mesh?

16 posts in this topic

Hi, say I've got a mesh, which is my spaceship constructed out of a trianglelist of triangles. ie 3 vertices for each triangle. Is there someway I can calculate the volume inside my spaceship? I want to do this so I can use the volume as the mass of the ship. Thanks
0

Share this post


Link to post
Share on other sites
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?
0

Share this post


Link to post
Share on other sites
Maybe something you already have thought of.
But you can calculate the bounding box of your mesh and
use the volume of bouding box to set your mass.
This won't be as accurate but is a lot more easy to do.
0

Share this post


Link to post
Share on other sites
You can pick a plane (Most easily the XY Plane)
For each traingle you can project it onto that plane (easy)
This creates a prism-like solid. Add the volume of that solid to the total mesh volume.
For counter clock wise traingles the volume should be positive and for clockwise triangles it should be negative.

This method is credited to Dmytry and he can give more explanation on the subject.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by meo
Maybe something you already have thought of.
But you can calculate the bounding box of your mesh and
use the volume of bouding box to set your mass.
This won't be as accurate but is a lot more easy to do.


seconded.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
Quote:
Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.


i second the bounding box solution. especially because volume probably wouldn't be proportional to volume anyways. Using the surface size (which is a LOT easier to compute) as a guideline for weight would probably be more realistic anyways because it is very likely that the hull is the heaviest component.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
Quote:
Original post by Daerax
Yes, but it is not worthwhile to do so unless you really must. Also can you explain why you are using you ship's volume for its mass? That doesnt make much sense. Why not just give the ship a mass?


I thought it would be nice to give a ship a unique mass, depending on how big it is. I would just calculate the mass once for each ship type.


Oh! Then that is actually a good idea, I think I might use it myself [smile]. Im going to assume you are going to replace the triangles with an actual complex mesh otherwise you can simply assign a height and calculate the volume using the equation for the volume of a pyramaid. Otherwise...

I would also second the idea of computing a bounding volume for your needs, since accuracy is not really imperative here. I would go a step further however and suggest you include the concept of density into your calculations since a large volume does not necessarily imply a large mass. Look at a bowling bowl versus a balloon or something as an example, both can be of equal volume but definately not equal weight [mass *g].

Using DirectX you can compute the bounding box using the D3DXComputeBoundingBox() function. This function returns two vectors pMin and pMax. The product of the vector components of the vector that is the difference between these two vectors will be the volume you need e.g.

D3DXVECTOR3 dimension_vector, pMin, pMax;

D3DXComputeBoundingBox(.., &pMin, &pMax)
dimension_vector = pMax - pMin;
float volume = dimension_vector.x*dimension_vector.y*dimension_vector.z;

Here is where it gets tricky though, in order for the equation you will use to calculate the mass for volume, m = ρV, where ρ is density and V is volume, to make sense we are going to replace he ship with a box of uniform density and mass distribution which bounds the ship as an approximation of the ship's volume. I make the emphasis on replacing with a box as an approximation because there is no gurantee that the object [ship] will have a uniform mass distribution. Actually, chances are that it will not. The significance of this is that certain areas of the ship will be more dense than others and you would actually need to differntiate across the entire surface (hard) to get proper results. So we just approximate with a simple box [grin]. You can multiply by .05 to .1+ to make up for the empty space that will be around the spaceship depending on your needs.

So you can give each ship a default density in the constructor of the ship class or something and you dont really need to change it unless you have to, say upgrading to a ship with a lighter material or something. Otherwise the density part of the equation remains transparent and you more or less use the volume to calculate the mass.

Here is a list of the density of different materials.
0

Share this post


Link to post
Share on other sites
if it's for a game, you'd be better of to make it up. Then you can tweak the gameplay as you wish (add more mass since the ship is more powerful than expected, ect...).
0

Share this post


Link to post
Share on other sites
Quote:
if it's for a game, you'd be better of to make it up. Then you can tweak the gameplay as you wish (add more mass since the ship is more powerful than expected, ect...).

I second that.. and a ship's density isn't constant, you could have a very small ship that weights the same or more than a larger ship, how do you determine the average density?
the same for all ships? quite restrictive... :/
by hand? then you'd better just set their weight by hand in the first place, and then you won't need their density...
anyway.. that's just my opinion.. if you still want to compute their volume, you can use the method Dmytry described in the other thread. (link's somewhere up on this page)
I use that method too and it works fine.
just take the AABB height and lower Y bound, place the virtual projection plane at min.y - (height * 0.1) (the relative offset is here just to avoid some imprecisions if the meshes you want to measure vary widely in size, then just ignore the Y coordinate of the triangles, compute the 2D area (dot product), and do area * (v0->y + v1->y + v2->y) / 3.0f, and add these values for each triangle to an accumulator. in the end, you'll get the volume.
he gave some visual explanations in the other thread if I recall correctly... might be clearer :)

note that if your mesh isn't closed, you will have volume "leaking" in or out, depending if the "hole" is located on the top or bottom of the mesh... anyway, make sure the mesh is completely closed.
0

Share this post


Link to post
Share on other sites
Simple geometric solution:
http://amp.ece.cmu.edu/Publication/Cha/icip01_Cha.pdf
0

Share this post


Link to post
Share on other sites
I like the surface area approximation, after all the inside tends to be mostly air as far as science fiction spaceships go... Get the area and multiply with the thickness of your armor plating. Add some known/constant values for things like thrusters or nuclear reactors or cargo. That way you can display how many kilotons of neutronium you have onboard and have it actually mean something (Total mass = hull mass + systems + payload).

But then you'll need to know the volume anyway to tell how many standard crates you can fit in the hold :)
0

Share this post


Link to post
Share on other sites
yes I was thinking of just getting the area of a triangle and multiply that by the armour thickness.

But this isn't really a game that I'm making, its more of just a testing ground for ai ideas, eg flocking, fighting etc. So I don't really have imaginary cockpits etc. And I just want my world to have realistic physics, but simple representations of stuff, eg spaceships as a solid object.

Right now weapons and engines don't really add to the mass, as they are just represented as invisible objects placed on the spaceship, eg thrusters are placed around the ship so it can manuevour properly, and when a thruster fires, it just applies a force the ship. And weapons which are all projectiles, just create objects eg bullet or missile which apply that force to the ship when fired.

So what I'm trying to say is, every is to be simple, no cargo etc. Maybe the number of projectiles mass might be added to the ship's mass, and removed as they are shot. Hmmm now that also involves space within the spaceship.

And using Daerax's density link, I will just apply density to my ships from looking at the different metals I could use.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
Hi, say I've got a mesh, which is my spaceship constructed out of a trianglelist of triangles. ie 3 vertices for each triangle.

Is there someway I can calculate the volume inside my spaceship?

I want to do this so I can use the volume as the mass of the ship.
Thanks


Suppose you have a vertex array V[] of N vertices. The triangle list is an array I[] of 3*T indices into the vertex array and represents T triangles. Suppose the mesh is closed, each edge is shared by two triangles, and the mesh is not self-intersecting ("water tight" in the vernacular). Also assume that the triangles are counterclockwise oriented as viewed by an observer outside the mesh. Finally, assume that the mass density is constant (1). If nonconstant, the problem is much more difficult.


float volume = 0;
int* index = I;
for (i = 0; i < T; i++)
{
Vector3 v0 = V[*index++];
Vector3 v1 = V[*index++];
Vector3 v2 = V[*index++];
volume += Dot(v0,Cross(v1,v2));
}
volume /= 6;

0

Share this post


Link to post
Share on other sites
For example, with real planes, mass is not proportional to volume. (large plane have lower average density than small plane). Area * armor thickness seems as reasonable idea, except that inside ship you also must have structural elements for strength. As about using densities of metals, spacecrafts made out of solid metal is too cool, heck.

Quote:
Original post by Dave Eberly
Quote:
Original post by johnnyBravo
Hi, say I've got a mesh, which is my spaceship constructed out of a trianglelist of triangles. ie 3 vertices for each triangle.

Is there someway I can calculate the volume inside my spaceship?

I want to do this so I can use the volume as the mass of the ship.
Thanks


Suppose you have a vertex array V[] of N vertices. The triangle list is an array I[] of 3*T indices into the vertex array and represents T triangles. Suppose the mesh is closed, each edge is shared by two triangles, and the mesh is not self-intersecting ("water tight" in the vernacular). Also assume that the triangles are counterclockwise oriented as viewed by an observer outside the mesh. Finally, assume that the mass density is constant (1). If nonconstant, the problem is much more difficult.


float volume = 0;
int* index = I;
for (i = 0; i < T; i++)
{
Vector3 v0 = V[*index++];
Vector3 v1 = V[*index++];
Vector3 v2 = V[*index++];
volume += Dot(v0,Cross(v1,v2));
}
volume /= 6;


Quote:

Have you considered using Gauss' Theorem?

Let we have field F(P)=P . It have constant divergence Ñ·F = 3 . Flow of F(P) through triangle ABC is 1/2 * A.BXC . Method above uses exactly that. (it indeed could be said that it just adds volume of pyramids. [grin] but you can derive it from divergence theorem (aka Gauss's Theorem) , and will not have problems proving that negative volume trick will work)

(2everyone who suggested my method explained in other tread, that only differs in "volume+=(v0.x+v1.x+v2.x)*Cross(v1-v0,v2-v0).x" (uses field F(P)=[P.x,0,0] with divergence 1) : it was made to simplify computation of volume of submerged object. In other cases, "pyramids method" is nicer)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0