public csgjs_csgnode() { front = null; back = null; plane = new csgjs_plane(); polygons = new List <csgjs_polygon>(); }
// Convert solid space to empty space and empty space to solid space. void invert() { for (int i = 0; i < polygons.Count; i++) { polygons[i].flip(); } plane.flip(); if (front != null) { front.invert(); } if (back != null) { back.invert(); } //std::swap(front, back); //hmm - need to swap front and back... csgjs_csgnode f = null; csgjs_csgnode b = null; if (front != null) { f = front.clone(); } if (back != null) { b = back.clone(); } back = f; front = b; }
public csgjs_csgnode() { front = null; back = null; plane = new csgjs_plane(); polygons = new List<csgjs_polygon>(); }
private void RunThread() { RaiseEvent(eCSGEvent.eStarted, "", null); try { List <csgjs_polygon> a = ConvertTo(m_obj1); List <csgjs_polygon> b = ConvertTo(m_obj2); csgjs_csgnode A = new csgjs_csgnode(a); csgjs_csgnode B = new csgjs_csgnode(b); csgjs_csgnode AB = null; switch (m_op) { case eCSGOp.eIntersection: AB = csgjs_csgnode.csg_intersect(A, B); break; case eCSGOp.eSubtraction: AB = csgjs_csgnode.csg_subtract(A, B); break; case eCSGOp.eUnion: AB = csgjs_csgnode.csg_union(A, B); break; } //raise an event Object3d res = ConvertFrom(AB.allPolygons()); RaiseEvent(eCSGEvent.eCompleted, "", res); } catch (Exception ex) { DebugLogger.Instance().LogError(ex); RaiseEvent(eCSGEvent.eError, "", null); } m_running = false; }
private Object3d Intersect(Object3d obj1, Object3d obj2) { List <csgjs_polygon> a = ConvertTo(obj1); List <csgjs_polygon> b = ConvertTo(obj2); csgjs_csgnode A = new csgjs_csgnode(a); csgjs_csgnode B = new csgjs_csgnode(b); csgjs_csgnode AB = csgjs_csgnode.csg_intersect(A, B); return(ConvertFrom(AB.allPolygons())); }
// Remove all polygons in this BSP tree that are inside the other BSP tree // `bsp`. void clipTo(csgjs_csgnode other) { polygons = other.clipPolygons(polygons); if (front != null) { front.clipTo(other); } if (back != null) { back.clipTo(other); } }
// Return a new CSG solid representing space in either this solid or in the // solid `csg`. Neither this solid nor the solid `csg` are modified. public static csgjs_csgnode csg_union(csgjs_csgnode a1, csgjs_csgnode b1) { csgjs_csgnode a = a1.clone(); csgjs_csgnode b = b1.clone(); a.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); a.build(b.allPolygons()); csgjs_csgnode ret = new csgjs_csgnode(a.allPolygons()); a = null; b = null; return(ret); }
public csgjs_csgnode clone() { csgjs_csgnode ret = new csgjs_csgnode(); foreach (csgjs_polygon p in polygons) { ret.polygons.Add(p.clone()); } ret.plane = plane.clone(); if (front != null) ret.front = front.clone(); if (back!= null) ret.back = back.clone(); return ret; }
public csgjs_csgnode clone() { csgjs_csgnode ret = new csgjs_csgnode(); foreach (csgjs_polygon p in polygons) { ret.polygons.Add(p.clone()); } ret.plane = plane.clone(); if (front != null) { ret.front = front.clone(); } if (back != null) { ret.back = back.clone(); } return(ret); }
// Build a BSP tree out of `polygons`. When called on an existing tree, the // new polygons are filtered down to the bottom of the tree and become new // nodes there. Each set of polygons is partitioned using the first polygon // (no heuristic is used to pick a good split). void build(List <csgjs_polygon> list) { if (list.Count == 0) { return; } if (!plane.ok()) { plane = list[0].plane; } List <csgjs_polygon> list_front = new List <csgjs_polygon>(); List <csgjs_polygon> list_back = new List <csgjs_polygon>(); for (int i = 0; i < list.Count; i++) { plane.splitPolygon(list[i], polygons, polygons, ref list_front, ref list_back); } if (list_front.Count > 0) { if (front == null) { front = new csgjs_csgnode(); } front.build(list_front); } if (list_back.Count > 0) { if (back == null) { back = new csgjs_csgnode(); } back.build(list_back); } }
// Build a BSP tree out of `polygons`. When called on an existing tree, the // new polygons are filtered down to the bottom of the tree and become new // nodes there. Each set of polygons is partitioned using the first polygon // (no heuristic is used to pick a good split). void build( List<csgjs_polygon> list) { if (list.Count == 0) return; if (!plane.ok()) plane = list[0].plane; List<csgjs_polygon> list_front = new List<csgjs_polygon>(); List<csgjs_polygon> list_back = new List<csgjs_polygon>(); for (int i = 0; i < list.Count; i++) { plane.splitPolygon(list[i], polygons, polygons,ref list_front,ref list_back); } if (list_front.Count > 0) { if (front == null) front = new csgjs_csgnode(); front.build(list_front); } if (list_back.Count > 0) { if (back == null) back = new csgjs_csgnode(); back.build(list_back); } }
// Convert solid space to empty space and empty space to solid space. void invert() { for (int i = 0; i < polygons.Count; i++) { polygons[i].flip(); } plane.flip(); if (front !=null) { front.invert(); } if (back != null) { back.invert(); } //std::swap(front, back); //hmm - need to swap front and back... csgjs_csgnode f = null; csgjs_csgnode b = null; if(front != null) { f = front.clone(); } if(back !=null) { b = back.clone(); } back = f; front = b; }
// Return a new CSG solid representing space both this solid and in the // solid `csg`. Neither this solid nor the solid `csg` are modified. public static csgjs_csgnode csg_intersect( csgjs_csgnode a1, csgjs_csgnode b1) { csgjs_csgnode a = a1.clone(); csgjs_csgnode b = b1.clone(); a.invert(); b.clipTo(a); b.invert(); a.clipTo(b); b.clipTo(a); a.build(b.allPolygons()); a.invert(); csgjs_csgnode ret = new csgjs_csgnode(a.allPolygons()); a = null; b = null; return ret; }
private Object3d Intersect(Object3d obj1, Object3d obj2) { List<csgjs_polygon> a = ConvertTo(obj1); List<csgjs_polygon> b = ConvertTo(obj2); csgjs_csgnode A = new csgjs_csgnode(a); csgjs_csgnode B = new csgjs_csgnode(b); csgjs_csgnode AB = csgjs_csgnode.csg_intersect(A, B); return ConvertFrom(AB.allPolygons()); }
private void RunThread() { RaiseEvent(eCSGEvent.eStarted, "", null); try { List<csgjs_polygon> a = ConvertTo(m_obj1); List<csgjs_polygon> b = ConvertTo(m_obj2); csgjs_csgnode A = new csgjs_csgnode(a); csgjs_csgnode B = new csgjs_csgnode(b); csgjs_csgnode AB = null; switch (m_op) { case eCSGOp.eIntersection: AB = csgjs_csgnode.csg_intersect(A, B); break; case eCSGOp.eSubtraction: AB = csgjs_csgnode.csg_subtract(A, B); break; case eCSGOp.eUnion: AB = csgjs_csgnode.csg_union(A, B); break; } //raise an event Object3d res = ConvertFrom(AB.allPolygons()); RaiseEvent(eCSGEvent.eCompleted, "", res); } catch (Exception ex) { DebugLogger.Instance().LogError(ex); RaiseEvent(eCSGEvent.eError, "", null); } m_running = false; }
public static Object3d Union(Object3d obj1, Object3d obj2) { List<csgjs_polygon> a = ConvertTo(obj1); List<csgjs_polygon> b = ConvertTo(obj2); csgjs_csgnode A = new csgjs_csgnode(a); csgjs_csgnode B = new csgjs_csgnode(b); csgjs_csgnode AB = csgjs_csgnode.csg_union(A,B); return ConvertFrom(AB.allPolygons()); }