Fix closed model detection when meshes are connected in an edge.
This commit is contained in:
parent
67a4754ec9
commit
265464fb60
@ -236,16 +236,24 @@ OV.IsSolid = function (element)
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: two cubes connecting in one edge is solid, but it detects it as not solid
|
||||
const topology = OV.GetTopology (element);
|
||||
for (let edgeIndex = 0; edgeIndex < topology.edges.length; edgeIndex++) {
|
||||
const edge = topology.edges[edgeIndex];
|
||||
if (edge.triangles.length !== 2) {
|
||||
let triCount = edge.triangles.length;
|
||||
if (triCount === 0 || triCount % 2 !== 0) {
|
||||
return false;
|
||||
}
|
||||
const edgeOrientation1 = GetEdgeOrientationInTriangle (topology, edge.triangles[0], edgeIndex);
|
||||
const edgeOrientation2 = GetEdgeOrientationInTriangle (topology, edge.triangles[1], edgeIndex);
|
||||
if (edgeOrientation1 === edgeOrientation2) {
|
||||
let edgesDirection = 0;
|
||||
for (let triIndex = 0; triIndex < edge.triangles.length; triIndex++) {
|
||||
const triangleIndex = edge.triangles[triIndex];
|
||||
const edgeOrientation = GetEdgeOrientationInTriangle (topology, triangleIndex, edgeIndex);
|
||||
if (edgeOrientation) {
|
||||
edgesDirection += 1;
|
||||
} else {
|
||||
edgesDirection -= 1;
|
||||
}
|
||||
}
|
||||
if (edgesDirection !== 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,6 +178,13 @@ describe ('Model Utils', function () {
|
||||
const model = testUtils.GetTwoCubesConnectingInOneEdgeModel ();
|
||||
let topology = OV.GetTopology (model);
|
||||
assert.strictEqual (topology.vertices.length, 14);
|
||||
assert (!OV.IsSolid (model)); // TODO: should be identified as solid
|
||||
});
|
||||
assert (OV.IsSolid (model));
|
||||
});
|
||||
|
||||
it ('Two Cubes Connecting in One Face Topology Calculation', function () {
|
||||
const model = testUtils.GetTwoCubesConnectingInOneFaceModel ();
|
||||
let topology = OV.GetTopology (model);
|
||||
assert.strictEqual (topology.vertices.length, 12);
|
||||
assert (OV.IsSolid (model));
|
||||
});
|
||||
});
|
||||
|
||||
@ -15,6 +15,21 @@ describe ('Quantities', function () {
|
||||
assert.strictEqual (OV.CalculateVolume (model), null);
|
||||
});
|
||||
|
||||
it ('Two Cubes Connecting in One Vertex Volume Calculation', function () {
|
||||
const model = testUtils.GetTwoCubesConnectingInOneVertexModel ();
|
||||
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
|
||||
});
|
||||
|
||||
it ('Two Cubes Connecting in One Edge Volume Calculation', function () {
|
||||
const model = testUtils.GetTwoCubesConnectingInOneEdgeModel ();
|
||||
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
|
||||
});
|
||||
|
||||
it ('Two Cubes Connecting in One Face Volume Calculation', function () {
|
||||
const model = testUtils.GetTwoCubesConnectingInOneFaceModel ();
|
||||
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
|
||||
});
|
||||
|
||||
it ('Cube with Wrongly Oriented Triangle Volume Calculation', function () {
|
||||
var mesh = new OV.Mesh ();
|
||||
mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
|
||||
@ -197,6 +197,24 @@ module.exports =
|
||||
return model;
|
||||
},
|
||||
|
||||
|
||||
GetTwoCubesConnectingInOneFaceModel ()
|
||||
{
|
||||
let model = new OV.Model ();
|
||||
|
||||
let cube1 = this.GetCubeMesh ();
|
||||
model.AddMesh (cube1);
|
||||
|
||||
let cube2 = this.GetCubeMesh ();
|
||||
let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 0.0);
|
||||
let transformation = new OV.Transformation (matrix);
|
||||
OV.TransformMesh (cube2, transformation);
|
||||
model.AddMesh (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { new OV.Material () });
|
||||
return model;
|
||||
},
|
||||
|
||||
GetCubeWithOneMissingFaceMesh ()
|
||||
{
|
||||
var cube = new OV.Mesh ();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user