occ proto

This commit is contained in:
Val Erastov 2021-09-06 01:48:09 -07:00
parent f0e9543fdc
commit cb108cc2d4
6 changed files with 15731 additions and 248 deletions

View file

@ -0,0 +1 @@
console.log("Hello World")

15326
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,7 @@
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-react": "^7.19.0",
"file-loader": "^6.2.0",
"grunt": "^1.1.0",
"grunt-contrib-copy": "1.0.0",
"less-loader": "^5.0.0",
@ -72,6 +73,7 @@
"marked": "^1.0.0",
"mousetrap": "1.6.1",
"numeric": "1.2.6",
"opencascade.js": "^1.1.1",
"prop-types": "15.6.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",

View file

@ -4,7 +4,7 @@ import {CraftEngine} from "./craftEngine";
export function activate(ctx) {
loadWasm(ctx);
// loadWasm(ctx);
const wasmEngine = new GenericWASMEngine_V1();

View file

@ -0,0 +1,257 @@
import BrepBuilder from "brep/brep-builder";
import { normalizetessellationData } from "brep/io/brepIO";
import VertexFactory from "brep/vertexFactory";
import { BrepSurface } from "geom/surfaces/brepSurface";
import NullSurface from "geom/surfaces/nullSurface";
export function occ2brep(aShape: any, oc: any) {
let bb = new BrepBuilder();
let vf = new VertexFactory();
new oc.BRepMesh_IncrementalMesh_2(aShape, 3, false, 0.5, false);
console.log(oc.TopAbs_ShapeEnum.TopAbs_FACE)
const aExpFace = new oc.TopExp_Explorer_2(aShape, oc.TopAbs_ShapeEnum.TopAbs_FACE, oc.TopAbs_ShapeEnum.TopAbs_SHAPE);
const out = {};
const facesOut = [];
for (; aExpFace.More(); aExpFace.Next()) {
const aFace = oc.TopoDS.Face_1(aExpFace.Current());
bb.face();
// @ts-ignore
let nonDirect = false; // left handed coordinate system for planes
let inverted = aFace.Orientation_1() == oc.TopAbs_Orientation.TopAbs_REVERSED !== nonDirect;
const aSurface = oc.BRep_Tool.Surface_2(aFace).get();
aSurface.IsKind = () => false
// let surfaceOut = {};
if (aSurface.IsKind("Geom_BoundedSurface")) {
const bSpline = oc.GeomConvert.prototype.SurfaceToBSplineSurface(aSurface).get();
// surfaceOut = {"TYPE": "UNKNOWN"};//surfaceWriteBounded(bSpline);
//if BRepPrimAPI_MakePrism(,,,canonicalize = true ) then all swept surfaces(walls) are forced to planes if possible
} else if (aSurface.IsKind("Geom_ElementarySurface")) {
// printf("INTER TYPE: Geom_ElementarySurface \n");
if (aSurface.IsKind("Geom_Plane")) {
// surfaceOut = surfaceWritePlane(aSurface);
} else {
// surfaceOut = {"TYPE": "UNKNOWN"};
}
} else if (aSurface.IsKind("Geom_SweptSurface")) {
// printf("INTER TYPE: Geom_SweptSurface \n");
// surfaceOut = {"TYPE": "SWEPT"};
} else if (aSurface.IsKind("Geom_OffsetSurface")) {
// printf("INTER TYPE: Geom_OffsetSurface \n");
// surfaceOut = {"TYPE": "OFFSET"};
} else {
bb._face.surface = new BrepSurface(new NullSurface());
}
console.log("string tesselation");
let aLocation = new oc.TopLoc_Location_1();
let aTrHandler = oc.BRep_Tool.Triangulation(aFace, aLocation);
console.log("got triangles");
const tessOut = [];
if (!aTrHandler.IsNull()) {
const aTr = aTrHandler.get();
const aNodes = aTr.Nodes();
const points = [];
for (let i = 0; i < aNodes.Length(); i++) {
let p = aNodes.Value(i + 1).Transformed(aLocation.Transformation());
points.push([p.X(), p.Y(), p.Z()]);
}
const triangles = aTr.Triangles();
const nnn = aTr.NbTriangles();
const isPlane = aSurface.IsKind("Geom_Plane");
for (let nt = 1; nt < nnn + 1; nt++) {
// takes the node indices of each triangle in n1,n2,n3:
let t = triangles.Value(nt);
let n1 = t.Value(1);
let n2 = t.Value(2);
let n3 = t.Value(3);
const aPnt1 = points[n1 - 1];
const aPnt2 = points[n2 - 1];
const aPnt3 = points[n3 - 1];
const def = [];
const tr = [];
tr.push(aPnt1);
tr.push(aPnt2);
tr.push(aPnt3);
def.push(tr);
if (!isPlane) {
// const norms = [];
// norms.push(dirWrite(computeNormal(aTr->UVNode(n1), aSurface).Transformed(aLocation)));
// norms.push(dirWrite(computeNormal(aTr->UVNode(n2), aSurface).Transformed(aLocation)));
// norms.push(dirWrite(computeNormal(aTr->UVNode(n3), aSurface).Transformed(aLocation)));
// def.push(norms);
}
tessOut.push(def);
}
bb._face.data.tessellation = {
format: 'verbose',
data: normalizetessellationData(tessOut, inverted, null)
};
bb._face.data.externals = {
// ref: ((std::uintptr_t)aFace.TShape().get())
}
// bb._face.data.productionInfo = faceData.productionInfo;
}
//BRepTools::OuterWire(face) - return outer wire for classification if needed
const wires = new oc.TopExp_Explorer_2(aFace, oc.TopAbs_ShapeEnum.TopAbs_WIRE, oc.TopAbs_ShapeEnum.TopAbs_SHAPE);
while (wires.More()) {
bb.loop();
console.log("processing wires");
const wire = oc.TopoDS.Wire_1(wires.Current());
wires.Next();
const aExpEdge = new oc.BRepTools_WireExplorer_2(wire);
// const edgesOut = [];
while (aExpEdge.More()) {
const aEdge = oc.TopoDS.Edge_1(aExpEdge.Current());
aExpEdge.Next();
if(aEdge.IsNull()) {
console.log("edge is null, skipping");
continue;
}
// const edgeOut = {};//edgeWrite(aEdge);
// if (!edgeOut.hasKey("a") || !edgeOut.hasKey("b")) {
// std::cout << "can't write edge, skipping" << std::endl;
// continue;
// }
// const edgeTessOut = Array();
// let a = vf.getData(edgeData.inverted ? edgeData.b : edgeData.a);
// let b = vf.getData(edgeData.inverted ? edgeData.a : edgeData.b);
// bb.edge(a, b, () => undefined, edgeData.inverted, edgeData.edgeRef);
// bb.lastHalfEdge.edge.data.tessellation = edgeData.tess;
// //todo: data should provide full externals object
// bb.lastHalfEdge.edge.data.externals = {
// ptr: edgeData.ptr
// };
const edgePolHandler = oc.BRep_Tool.PolygonOnTriangulation_1(aEdge, aTrHandler, aLocation);
if(!edgePolHandler.IsNull()) {
const edgePol = edgePolHandler.get();
// const TColStd_Array1OfInteger& edgeIndices = edgePol->Nodes();
// for( Standard_Integer j = 1; j <= edgeIndices.Length(); j++ ) {
// gp_Pnt edgePoint = fPoints(edgeIndices(j));
// edgeTessOut.append(pntWrite(edgePoint));
// }
const eNodes = edgePol.Nodes();
const points = [];
for (let i = 0; i < eNodes.Length(); i++) {
let p = eNodes.Value(i + 1).Transformed(aLocation.Transformation());
points.push([p.X(), p.Y(), p.Z()]);
}
} else {
// Handle(Poly_PolygonOnTriangulation) pt;
// Handle(Poly_Triangulation) edgeTr;
// TopLoc_Location edgeLoc;
// BRep_Tool::PolygonOnTriangulation(aEdge, pt, edgeTr, edgeLoc);
// if(!pt.IsNull()) {
// const TColStd_Array1OfInteger& edgeIndices = pt->Nodes();
// const TColgp_Array1OfPnt& edgeNodes = edgeTr->Nodes();
// for( Standard_Integer j = 1; j <= edgeIndices.Length(); j++ ) {
// gp_Pnt edgePoint = edgeNodes(j).Transformed(edgeLoc);
// edgeTessOut.append(pntWrite(edgePoint));
// }
// }
// }
// if (!INTERROGATE_STRUCT_ONLY) {
// edgeOut["tess"] = edgeTessOut;
}
// TopoDS_Edge* persistEdge = new TopoDS_Edge(aEdge);
// edgeOut["ptr"] = ((std::uintptr_t)persistEdge);
// edgeOut["edgeRef"] = edgeFaceMap.FindIndex(aEdge);
// edgesOut.append(edgeOut);
}
// loopsOut.append(edgesOut);
}
// if (model != NULL) {
// if (model->hasData(aFace)) {
// faceOut["productionInfo"] = model->getData(aFace);
// }
// }
// faceOut["ref"] = ((std::uintptr_t)aFace.TShape().get());
}
return bb.build();;
}
// function readBrep(data: BrepOutputData) {
// let bb = new BrepBuilder();
// let vf = new VertexFactory();
// for (let faceData of data.faces) {
// bb.face();
// // @ts-ignore
// let nonDirect = faceData.surface.direct === false; // left handed coordinate system for planes
// let inverted = faceData.inverted !== nonDirect;
// bb._face.data.tessellation = {
// format: 'verbose',
// data: normalizetessellationData(faceData.tess, inverted, faceData.surface.TYPE === 'PLANE' ? faceData.surface.normal : undefined)
// };
// bb._face.data.productionInfo = faceData.productionInfo;
// if (faceData.ref !== undefined) {
// bb._face.data.externals = {
// ref: faceData.ref,
// ptr: faceData.ptr
// }
// }
// for (let loop of faceData.loops) {
// bb.loop();
// for (let edgeData of loop) {
// let a = vf.getData(edgeData.inverted ? edgeData.b : edgeData.a);
// let b = vf.getData(edgeData.inverted ? edgeData.a : edgeData.b);
// bb.edge(a, b, () => undefined, edgeData.inverted, edgeData.edgeRef);
// bb.lastHalfEdge.edge.data.tessellation = edgeData.tess;
// //todo: data should provide full externals object
// bb.lastHalfEdge.edge.data.externals = {
// ptr: edgeData.ptr
// };
// }
// }
// // try {
// // bb._face.surface = readSurface(faceData.surface, faceData.inverted, inverted, bb._face);
// // } catch (e) {
// // console.error(e);
// // bb._face.surface = new BrepSurface(new NullSurface());
// // }
// bb._face.surface = new BrepSurface(new NullSurface());
// }
// //todo: data should provide full externals object
// bb._shell.data.externals = {
// ptr: data.ptr
// };
// return bb.build();
// }

View file

@ -11,13 +11,20 @@ import {BrepInputData, CubeExample} from "engine/data/brepInputData";
import {ApplicationContext} from "context";
import {readShellEntityFromJson} from "./scene/wrappers/entityIO";
import {DEFLECTION, E0_TOLERANCE} from "./craft/e0/common";
import {readBrep, writeBrep} from "brep/io/brepIO";
import {normalizetessellationData, readBrep, writeBrep} from "brep/io/brepIO";
import {PRIMITIVE_TYPES} from "engine/data/primitiveData";
import {pullFace} from "brep/operations/directMod/pullFace";
import {DefeatureFaceWizard} from "./craft/defeature/DefeatureFaceWizard";
import {defeatureByVertex, defeatureByEdge} from "brep/operations/directMod/defeaturing";
import {BooleanType} from "engine/api";
import { testEdgeSplit } from 'brep/operations/directMod/edgeSplit';
import {initOpenCascade} from "opencascade.js";
import VertexFactory from 'brep/vertexFactory';
import { BrepSurface } from 'geom/surfaces/brepSurface';
import NullSurface from 'geom/surfaces/nullSurface';
import { BrepOutputData } from 'engine/data/brepOutputData';
import { MBrepShell } from './model/mshell';
import { occ2brep } from './occ/occ2models';
export function runSandbox(ctx: ApplicationContext) {
@ -601,19 +608,393 @@ export function runSandbox(ctx: ApplicationContext) {
// services.action.run('LOFT');
// window.voxelTest = voxelTest;
function testOJS() {
initOpenCascade().then(openCascade => {
let myWidth = 50, myHeight = 70, myThickness = 30;
const aPnt1 = new openCascade.gp_Pnt_3(-myWidth / 2., 0, 0);
const aPnt2 = new openCascade.gp_Pnt_3(-myWidth / 2., -myThickness / 4., 0);
const aPnt3 = new openCascade.gp_Pnt_3(0, -myThickness / 2., 0);
const aPnt4 = new openCascade.gp_Pnt_3(myWidth / 2., -myThickness / 4., 0);
const aPnt5 = new openCascade.gp_Pnt_3(myWidth / 2., 0, 0);
// Profile : Define the Geometry
const anArcOfCircle = new openCascade.GC_MakeArcOfCircle_4(aPnt2, aPnt3, aPnt4);
const aSegment1 = new openCascade.GC_MakeSegment_1(aPnt1, aPnt2);
const aSegment2 = new openCascade.GC_MakeSegment_1(aPnt4, aPnt5);
// Profile : Define the Topology
const anEdge1 = new openCascade.BRepBuilderAPI_MakeEdge_24(new openCascade.Handle_Geom_Curve_2(aSegment1.Value().get()));
const anEdge2 = new openCascade.BRepBuilderAPI_MakeEdge_24(new openCascade.Handle_Geom_Curve_2(anArcOfCircle.Value().get()));
const anEdge3 = new openCascade.BRepBuilderAPI_MakeEdge_24(new openCascade.Handle_Geom_Curve_2(aSegment2.Value().get()));
const aWire = new openCascade.BRepBuilderAPI_MakeWire_4(anEdge1.Edge(), anEdge2.Edge(), anEdge3.Edge());
// Complete Profile
const xAxis = openCascade.gp.OX();
const aTrsf = new openCascade.gp_Trsf_1();
aTrsf.SetMirror_2(xAxis);
const aBRepTrsf = new openCascade.BRepBuilderAPI_Transform_2(aWire.Wire(), aTrsf, false);
const aMirroredShape = aBRepTrsf.Shape();
const mkWire = new openCascade.BRepBuilderAPI_MakeWire_1();
mkWire.Add_2(aWire.Wire());
mkWire.Add_2(openCascade.TopoDS.Wire_1(aMirroredShape));
const myWireProfile = mkWire.Wire();
// Body : Prism the Profile
const myFaceProfile = new openCascade.BRepBuilderAPI_MakeFace_15(myWireProfile, false);
const aPrismVec = new openCascade.gp_Vec_4(0, 0, myHeight);
let myBody = new openCascade.BRepPrimAPI_MakePrism_1(myFaceProfile.Face(), aPrismVec, false, true);
// Body : Apply Fillets
const mkFillet = new openCascade.BRepFilletAPI_MakeFillet(myBody.Shape(), openCascade.ChFi3d_FilletShape.ChFi3d_Rational);
const anEdgeExplorer = new openCascade.TopExp_Explorer_2(myBody.Shape(), openCascade.TopAbs_ShapeEnum.TopAbs_EDGE, openCascade.TopAbs_ShapeEnum.TopAbs_SHAPE);
while(anEdgeExplorer.More()) {
const anEdge = openCascade.TopoDS.Edge_1(anEdgeExplorer.Current());
// Add edge to fillet algorithm
mkFillet.Add_2(myThickness / 12., anEdge);
anEdgeExplorer.Next();
}
myBody = mkFillet.Shape();
// Body : Add the Neck
const neckLocation = new openCascade.gp_Pnt_3(0, 0, myHeight);
const neckAxis = openCascade.gp.DZ();
const neckAx2 = new openCascade.gp_Ax2_3(neckLocation, neckAxis);
const myNeckRadius = myThickness / 4.;
const myNeckHeight = myHeight / 10.;
const MKCylinder = new openCascade.BRepPrimAPI_MakeCylinder_3(neckAx2, myNeckRadius, myNeckHeight);
const myNeck = MKCylinder.Shape();
myBody = new openCascade.BRepAlgoAPI_Fuse_3(myBody, myNeck);
// Body : Create a Hollowed Solid
let faceToRemove;
let zMax = -1;
const aFaceExplorer = new openCascade.TopExp_Explorer_2(myBody.Shape(), openCascade.TopAbs_ShapeEnum.TopAbs_FACE, openCascade.TopAbs_ShapeEnum.TopAbs_SHAPE);
for(; aFaceExplorer.More(); aFaceExplorer.Next()) {
const aFace = openCascade.TopoDS.Face_1(aFaceExplorer.Current());
// Check if <aFace> is the top face of the bottle's neck
const aSurface = openCascade.BRep_Tool.Surface_2(aFace);
if(aSurface.get().$$.ptrType.name === "Geom_Plane*") {
const aPlane = new openCascade.Handle_Geom_Plane_2(aSurface.get()).get();
const aPnt = aPlane.Location();
const aZ = aPnt.Z();
if(aZ > zMax) {
zMax = aZ;
faceToRemove = new openCascade.TopExp_Explorer_2(aFace, openCascade.TopAbs_ShapeEnum.TopAbs_FACE, openCascade.TopAbs_ShapeEnum.TopAbs_SHAPE).Current();
}
}
}
const facesToRemove = new openCascade.TopTools_ListOfShape_1();
facesToRemove.Append_1(faceToRemove);
const s = myBody.Shape();
myBody = new openCascade.BRepOffsetAPI_MakeThickSolid_1();
myBody.MakeThickSolidByJoin(s, facesToRemove, -myThickness / 50, 1.e-3, openCascade.BRepOffset_Mode.BRepOffset_Skin, false, false, openCascade.GeomAbs_JoinType.GeomAbs_Arc, false);
// Threading : Create Surfaces
const aCyl1 = new openCascade.Geom_CylindricalSurface_1(new openCascade.gp_Ax3_2(neckAx2), myNeckRadius * 0.99);
const aCyl2 = new openCascade.Geom_CylindricalSurface_1(new openCascade.gp_Ax3_2(neckAx2), myNeckRadius * 1.05);
// Threading : Define 2D Curves
const aPnt = new openCascade.gp_Pnt2d_3(2. * Math.PI, myNeckHeight / 2.);
const aDir = new openCascade.gp_Dir2d_4(2. * Math.PI, myNeckHeight / 4.);
const anAx2d = new openCascade.gp_Ax2d_2(aPnt, aDir);
const aMajor = 2. * Math.PI;
const aMinor = myNeckHeight / 10;
const anEllipse1 = new openCascade.Geom2d_Ellipse_2(anAx2d, aMajor, aMinor, true);
const anEllipse2 = new openCascade.Geom2d_Ellipse_2(anAx2d, aMajor, aMinor / 4, true);
const anArc1 = new openCascade.Geom2d_TrimmedCurve(new openCascade.Handle_Geom2d_Curve_2(anEllipse1), 0, Math.PI, true, true);
const anArc2 = new openCascade.Geom2d_TrimmedCurve(new openCascade.Handle_Geom2d_Curve_2(anEllipse2), 0, Math.PI, true, true);
const tmp1 = anEllipse1.Value(0);
const anEllipsePnt1 = new openCascade.gp_Pnt2d_3(tmp1.X(), tmp1.Y());
const tmp2 = anEllipse1.Value(Math.PI);
const anEllipsePnt2 = new openCascade.gp_Pnt2d_3(tmp2.X(), tmp2.Y());
const aSegment = new openCascade.GCE2d_MakeSegment_1(anEllipsePnt1, anEllipsePnt2);
// Threading : Build Edges and Wires
const anEdge1OnSurf1 = new openCascade.BRepBuilderAPI_MakeEdge_30(new openCascade.Handle_Geom2d_Curve_2(anArc1), new openCascade.Handle_Geom_Surface_2(aCyl1));
const anEdge2OnSurf1 = new openCascade.BRepBuilderAPI_MakeEdge_30(new openCascade.Handle_Geom2d_Curve_2(aSegment.Value().get()), new openCascade.Handle_Geom_Surface_2(aCyl1));
const anEdge1OnSurf2 = new openCascade.BRepBuilderAPI_MakeEdge_30(new openCascade.Handle_Geom2d_Curve_2(anArc2), new openCascade.Handle_Geom_Surface_2(aCyl2));
const anEdge2OnSurf2 = new openCascade.BRepBuilderAPI_MakeEdge_30(new openCascade.Handle_Geom2d_Curve_2(aSegment.Value().get()), new openCascade.Handle_Geom_Surface_2(aCyl2));
const threadingWire1 = new openCascade.BRepBuilderAPI_MakeWire_3(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge());
const threadingWire2 = new openCascade.BRepBuilderAPI_MakeWire_3(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge());
openCascade.BRepLib.BuildCurves3d_2(threadingWire1.Wire());
openCascade.BRepLib.BuildCurves3d_2(threadingWire2.Wire());
openCascade.BRepLib.BuildCurves3d_2(threadingWire1.Wire());
openCascade.BRepLib.BuildCurves3d_2(threadingWire2.Wire());
// Create Threading
const aTool = new openCascade.BRepOffsetAPI_ThruSections(true, false, 1.0e-06);
aTool.AddWire(threadingWire1.Wire());
aTool.AddWire(threadingWire2.Wire());
aTool.CheckCompatibility(false);
const myThreading = aTool.Shape();
// Building the Resulting Compound
const aRes = new openCascade.TopoDS_Compound();
const aBuilder = new openCascade.BRep_Builder();
aBuilder.MakeCompound(aRes);
aBuilder.Add(aRes, myBody.Shape());
aBuilder.Add(aRes, myThreading);
const brepdata = interogate(aRes, openCascade);
const mobject = new MBrepShell( occ2brep(aRes, openCascade) );
services.exposure.addOnScene(mobject);
});
function interogate(aShape: any, oc: any) {
new oc.BRepMesh_IncrementalMesh_2(aShape, 3, false, 0.5, false);
console.log(oc.TopAbs_ShapeEnum.TopAbs_FACE)
const aExpFace = new oc.TopExp_Explorer_2(aShape, oc.TopAbs_ShapeEnum.TopAbs_FACE, oc.TopAbs_ShapeEnum.TopAbs_SHAPE);
const out = {};
const facesOut = [];
for(;aExpFace.More();aExpFace.Next())
{
const faceOut = {};
const tessOut = [];
const aFace = oc.TopoDS.Face_1(aExpFace.Current());
const aSurface = oc.BRep_Tool.Surface_2(aFace).get();
aSurface.IsKind = () => false
let surfaceOut = {};
if (aSurface.IsKind("Geom_BoundedSurface")) {
const bSpline = oc.GeomConvert.prototype.SurfaceToBSplineSurface(aSurface).get();
surfaceOut = {"TYPE": "UNKNOWN"};//surfaceWriteBounded(bSpline);
//if BRepPrimAPI_MakePrism(,,,canonicalize = true ) then all swept surfaces(walls) are forced to planes if possible
} else if (aSurface.IsKind("Geom_ElementarySurface")) {
// printf("INTER TYPE: Geom_ElementarySurface \n");
if (aSurface.IsKind("Geom_Plane")) {
surfaceOut = surfaceWritePlane(aSurface);
} else {
surfaceOut = {"TYPE": "UNKNOWN"};
}
} else if ( aSurface.IsKind("Geom_SweptSurface")) {
// printf("INTER TYPE: Geom_SweptSurface \n");
surfaceOut = {"TYPE": "SWEPT"};
} else if ( aSurface.IsKind("Geom_OffsetSurface")) {
// printf("INTER TYPE: Geom_OffsetSurface \n");
surfaceOut = {"TYPE": "OFFSET"};
} else {
surfaceOut = {"TYPE": "UNKNOWN"};
}
faceOut["surface"] = surfaceOut;
console.log("string tesselation");
let aLocation = new oc.TopLoc_Location_1();
let aTrHandler = oc.BRep_Tool.Triangulation(aFace, aLocation);
console.log("got triangles");
if(!aTrHandler.IsNull()) {
const aTr = aTrHandler.get();
const aNodes = aTr.Nodes();
const points = [];
for(let i = 0; i < aNodes.Length(); i++) {
let p = aNodes.Value(i + 1).Transformed(aLocation.Transformation());
points.push([p.X(), p.Y(), p.Z()]);
}
const triangles = aTr.Triangles();
const nnn = aTr.NbTriangles();
const isPlane = aSurface.IsKind("Geom_Plane");
for( let nt = 1 ; nt < nnn+1 ; nt++) {
// takes the node indices of each triangle in n1,n2,n3:
let t = triangles.Value(nt);
let n1 = t.Value(1);
let n2 = t.Value(2);
let n3 = t.Value(3);
const aPnt1 = points[n1 - 1];
const aPnt2 = points[n2 - 1];
const aPnt3 = points[n3 - 1];
const def = [];
const tr = [];
tr.push(aPnt1);
tr.push(aPnt2);
tr.push(aPnt3);
def.push(tr);
if (!isPlane) {
// const norms = [];
// norms.push(dirWrite(computeNormal(aTr->UVNode(n1), aSurface).Transformed(aLocation)));
// norms.push(dirWrite(computeNormal(aTr->UVNode(n2), aSurface).Transformed(aLocation)));
// norms.push(dirWrite(computeNormal(aTr->UVNode(n3), aSurface).Transformed(aLocation)));
// def.push(norms);
}
tessOut.push(def);
}
}
//BRepTools::OuterWire(face) - return outer wire for classification if needed
const loopsOut = [];
// const wires = new oc.TopExp_Explorer_2(aFace, oc.TopAbs_WIRE, oc.TopAbs_ShapeEnum.TopAbs_SHAPE);
// while (wires.More()) {
// console.log("processing wires");
// const wire = oc.TopoDS.prototype.Wire(wires.Current());
// wires.Next();
// const aExpEdge = new oc.BRepTools_WireExplorer(wire);
// const edgesOut = [];
// while (aExpEdge.More()) {
// const aEdge = oc.TopoDS.prototype.Edge(aExpEdge.Current());
// aExpEdge.Next();
// if(aEdge.IsNull()) {
// console.log("edge is null, skipping");
// continue;
// }
// const edgeOut = {};//edgeWrite(aEdge);
// if (!edgeOut.hasKey("a") || !edgeOut.hasKey("b")) {
// std::cout << "can't write edge, skipping" << std::endl;
// continue;
// }
// const edgeTessOut = Array();
// Handle(Poly_PolygonOnTriangulation) edgePol = BRep_Tool::PolygonOnTriangulation(aEdge, aTr, aLocation);
// if(!edgePol.IsNull()) {
// const TColStd_Array1OfInteger& edgeIndices = edgePol->Nodes();
// for( Standard_Integer j = 1; j <= edgeIndices.Length(); j++ ) {
// gp_Pnt edgePoint = fPoints(edgeIndices(j));
// edgeTessOut.append(pntWrite(edgePoint));
// }
// } else {
// Handle(Poly_PolygonOnTriangulation) pt;
// Handle(Poly_Triangulation) edgeTr;
// TopLoc_Location edgeLoc;
// BRep_Tool::PolygonOnTriangulation(aEdge, pt, edgeTr, edgeLoc);
// if(!pt.IsNull()) {
// const TColStd_Array1OfInteger& edgeIndices = pt->Nodes();
// const TColgp_Array1OfPnt& edgeNodes = edgeTr->Nodes();
// for( Standard_Integer j = 1; j <= edgeIndices.Length(); j++ ) {
// gp_Pnt edgePoint = edgeNodes(j).Transformed(edgeLoc);
// edgeTessOut.append(pntWrite(edgePoint));
// }
// }
// }
// if (!INTERROGATE_STRUCT_ONLY) {
// edgeOut["tess"] = edgeTessOut;
// }
// TopoDS_Edge* persistEdge = new TopoDS_Edge(aEdge);
// edgeOut["ptr"] = ((std::uintptr_t)persistEdge);
// edgeOut["edgeRef"] = edgeFaceMap.FindIndex(aEdge);
// edgesOut.append(edgeOut);
// }
// loopsOut.append(edgesOut);
// }
faceOut["loops"] = loopsOut;
faceOut["inverted"] = aFace.Orientation_1() == oc.TopAbs_Orientation.TopAbs_REVERSED;
// if (!INTERROGATE_STRUCT_ONLY) {
faceOut["tess"] = tessOut;
// }
// if (model != NULL) {
// if (model->hasData(aFace)) {
// faceOut["productionInfo"] = model->getData(aFace);
// }
// }
// TopoDS_Face* persistFace = new TopoDS_Face(aFace);
// faceOut["ref"] = ((std::uintptr_t)aFace.TShape().get());
// faceOut["ptr"] = ((std::uintptr_t)persistFace);
facesOut.push(faceOut);
}
out["faces"] = facesOut;
return out;
}
function readBrep(data: BrepOutputData) {
let bb = new BrepBuilder();
let vf = new VertexFactory();
for (let faceData of data.faces) {
bb.face();
// @ts-ignore
let nonDirect = faceData.surface.direct === false; // left handed coordinate system for planes
let inverted = faceData.inverted !== nonDirect;
bb._face.data.tessellation = {
format: 'verbose',
data: normalizetessellationData(faceData.tess, inverted, faceData.surface.TYPE === 'PLANE' ? faceData.surface.normal : undefined)
};
bb._face.data.productionInfo = faceData.productionInfo;
if (faceData.ref !== undefined) {
bb._face.data.externals = {
ref: faceData.ref,
ptr: faceData.ptr
}
}
for (let loop of faceData.loops) {
bb.loop();
for (let edgeData of loop) {
let a = vf.getData(edgeData.inverted ? edgeData.b : edgeData.a);
let b = vf.getData(edgeData.inverted ? edgeData.a : edgeData.b);
bb.edge(a, b, () => undefined, edgeData.inverted, edgeData.edgeRef);
bb.lastHalfEdge.edge.data.tessellation = edgeData.tess;
//todo: data should provide full externals object
bb.lastHalfEdge.edge.data.externals = {
ptr: edgeData.ptr
};
}
}
// try {
// bb._face.surface = readSurface(faceData.surface, faceData.inverted, inverted, bb._face);
// } catch (e) {
// console.error(e);
// bb._face.surface = new BrepSurface(new NullSurface());
// }
bb._face.surface = new BrepSurface(new NullSurface());
}
//todo: data should provide full externals object
bb._shell.data.externals = {
ptr: data.ptr
};
return bb.build();
}
}
ctx.streams.lifecycle.projectLoaded.attach(ready => {
if (ready) {
// testEdgeSplit(ctx);
//testVertexMoving(ctx);
test4();
// test4();
//testSplitFace();
//testRemoveFaces();
//testRemoveVertex();
testRemoveEdge();
// testRemoveEdge();
testOJS()
}
});
}