Three.js/3D models - calculating few volumes of ob

2019-03-05 01:28发布

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).

0条回答
登录 后发表回答