1

I work about one project in Three.js and I must solve one problem as fast as possible. I need to calculate few volumes of an 3D object.

First what I need is exactly the same like here: How to calculate the volume of a 3D mesh object the surface of which is made up triangles

And I calculate it in the same way. This is an entire object volume.

That is enough if object doesn't need an additional material when he goes into 3D printing. For example if that will be a glass (an open cylinder) i need to calculate a volume of additional material, that will be used in printing of this model. That material will be "inside" the glass and will prevent a floor of the glass from falling inside the model.

I don't know how to calculate that, too less math knowledge I think. Is there a way to calulate this? Or maybe is there a way to calculate a "closed-mesh volume" even, when this is an open one (like glass)?

EDIT: I do not have a glass model, but I have a model of a box. The box will be printed with the open side on the bottom. I need to know the "inside" volume.

Sorry for my english, hope it's understandable.

enter image description here

Here is how I calculate volume of object (exactly like in link in 1st post):

function volumeOfT(p1, p2, p3){
    var v321 = p3.x*p2.y*p1.z;
    var v231 = p2.x*p3.y*p1.z;
    var v312 = p3.x*p1.y*p2.z;
    var v132 = p1.x*p3.y*p2.z;
    var v213 = p2.x*p1.y*p3.z;
    var v123 = p1.x*p2.y*p3.z;
    return (-v321 + v231 + v312 - v132 - v213 + v123)/6.0;
}

function calculateVolume(object){
    var volumes = 0.0;

    for(var i = 0; i < object.geometry.faces.length; i++){
        var Pi = object.geometry.faces[i].a;
        var Qi = object.geometry.faces[i].b;
        var Ri = object.geometry.faces[i].c;

        var P = new THREE.Vector3(object.geometry.vertices[Pi].x, object.geometry.vertices[Pi].y, object.geometry.vertices[Pi].z);
        var Q = new THREE.Vector3(object.geometry.vertices[Qi].x, object.geometry.vertices[Qi].y, object.geometry.vertices[Qi].z);
        var R = new THREE.Vector3(object.geometry.vertices[Ri].x, object.geometry.vertices[Ri].y, object.geometry.vertices[Ri].z);
        volumes += volumeOfT(P, Q, R);
    }

    loadedObjectVolume = Math.abs(volumes);
}

I checked in other software and Volume of object is correct.

Here is how I tried to create a ConvexGeometry:

var geometry = new THREE.STLLoader().parse( contents );
geometry.sourceType = "stl";
geometry.sourceFile = file.name;

geometry.computeFaceNormals();
geometry.computeVertexNormals();

var convexGeometry = THREE.ConvexGeometry(geometry.vertices);

var material = new THREE.MeshLambertMaterial({
    color: 0xff0000,
    emissive: 0x000000,
    shading: THREE.FlatShading
});

var mesh = new THREE.Mesh( geometry, material );

On line var convexGeometry = THREE.ConvexGeometry(geometry.vertices); browser hangs. Only models with low verticies can go through this (cube for example).

Community
  • 1
  • 1
rgwsk65
  • 199
  • 2
  • 16
  • Can you show a live example of the mesh you want to calculate the volume of? The shape should not matter, as long as it is not self-intersecting and closed. – WestLangley Apr 24 '14 at 22:25
  • I havent glass model, but i've got box one. Here is it: http://postimg.org/image/erw0dl4az/ If the box will be printed with open side on bottom - i need to know his "inside" volume. – rgwsk65 Apr 25 '14 at 07:03
  • Sorry, I do not understand the question. Maybe someone else can help. Perhaps you can show a live example of the calculations you have tried. – WestLangley Apr 25 '14 at 16:48
  • I have to count 3 volumes of that "example" object. It's an open object (skip that part on the right side, i talk about an box object without top wall). 1. Volume of material used to print that box in 3D (solid box walls), and that I have done like in lik at 1st post. 2. Volume inside the box - water, that he can contain (I can't calculate this from BoundingBoxVolume-BoxWallsVolume, because box have regular walls, but other models could not have, for example bottle) 3. Full box volume (for example Box Walls + water inside) To do this I need to have one more volume - 2nd or 3rd – rgwsk65 Apr 25 '14 at 21:38
  • 1
    If the box is printable, it must be a closed mesh, which I assume it is. Apply your formula to the closed mesh and you should get the volume of the material required to print it. To get the volume of the shell, consider, as an approximation, computing the volume of `THREE.ConvexGeometry( verities )`. That will be the volume of the box's convex hull. The volume of the water would be the shell volume minus the material volume. – WestLangley Apr 25 '14 at 22:07
  • Thank you very much for fast reply. I will try it soon and I will post my results here :). – rgwsk65 Apr 25 '14 at 22:27
  • I havent an ConvexGeometry method/constructor :/ – rgwsk65 Apr 26 '14 at 23:27
  • Ok I know what to do with that, sorry for spam. – rgwsk65 Apr 26 '14 at 23:36
  • Creating a ConvexGeometry from my models in the way `var convexGeometry = THREE.ConvexGeometry(loadedObject.geometry.vertices);` Hangs out my browser (takes too much long time). Only a simple Cube can be loaded - probably because vertices count is low. I don't know what to do now. – rgwsk65 Apr 26 '14 at 23:58
  • 1. Can you post a live example showing how you compute the volume of the material? Does it compute the correct value? 2. Can you post a live example of your attempt to create a `ConvexGeometry`? – WestLangley Apr 27 '14 at 00:46
  • Yes, I will do this tomorrow. – rgwsk65 Apr 27 '14 at 01:19
  • I edited main post - dunno how StackOverflow works (I mean notifications) – rgwsk65 Apr 29 '14 at 02:17
  • 1. Use @username to force a notification. 2. `ConvexGeometry` works for me with 100,000 vertices in a few seconds. 3. three.js is a rendering engine, not a modeling tool. You may have to find another approach. – WestLangley Apr 29 '14 at 03:14

0 Answers0