Ejemplo n.º 1
0
        public MeshGeometry3D GenerateMold(double resolution, List <MeshGeometry3D> airholes)
        {
            //generates the outer mold and interior cavity for the bolus
            var    mold = new BolusMold(_displayMesh, resolution, true);
            DMesh3 mesh = MeshGeometryToDMesh(mold.Mesh);

            //generate the airholes for boolean subtraction

            if (airholes.Count > 0)
            {
                DMesh3     booleanMesh = new DMesh3();
                var        holes       = new DMesh3();
                MeshEditor editor      = new MeshEditor(holes);
                foreach (MeshGeometry3D m in airholes)
                {
                    editor.AppendMesh(MeshGeometryToDMesh(m));
                }

                booleanMesh = holes;

                //boolean subtract the airholes from the mold
                _moldMesh = new List <DMesh3>()
                {
                    BooleanSubtraction(mesh, holes)
                };
            }

            return(DMeshToMeshGeometry(_moldMesh[0]));
        }
Ejemplo n.º 2
0
        public bool Compute()
        {
            PlanarMesh   = BuildPlanarMesh(false);
            InflatedMesh = ComputeInflation(PlanarMesh);

            DMesh3 remeshed = GenerateRemesh(InflatedMesh);

            Flatten(remeshed);

            ResultMesh = ComputeInflation(remeshed);

            MeshBoundaryLoops loops = new MeshBoundaryLoops(ResultMesh);

            DMesh3 otherSide = new DMesh3(ResultMesh);

            foreach (int vid in otherSide.VertexIndices())
            {
                Vector3d v = otherSide.GetVertex(vid);
                v.z = -v.z;
                otherSide.SetVertex(vid, v);
            }
            otherSide.ReverseOrientation();

            MeshEditor editor = new MeshEditor(ResultMesh);

            int[] mapVArray;
            editor.AppendMesh(otherSide, out mapVArray);
            IndexMap mapV = new IndexMap(mapVArray);

            foreach (EdgeLoop loop in loops)
            {
                int[] otherLoop = (int[])loop.Vertices.Clone();
                IndexUtil.Apply(otherLoop, mapV);
                editor.StitchLoop(loop.Vertices, otherLoop);
            }


            Remesher remesh = new Remesher(ResultMesh);

            remesh.SetTargetEdgeLength(TargetEdgeLength);
            remesh.SmoothSpeedT = 0.25f;
            for (int k = 0; k < 10; ++k)
            {
                remesh.BasicRemeshPass();
            }
            ResultMesh = new DMesh3(ResultMesh, true);


            LaplacianMeshSmoother smoother = new LaplacianMeshSmoother(ResultMesh);

            foreach (int vid in ResultMesh.VertexIndices())
            {
                smoother.SetConstraint(vid, ResultMesh.GetVertex(vid), 0.5f, false);
            }
            smoother.SolveAndUpdateMesh();


            return(true);
        }
Ejemplo n.º 3
0
        public static void AppendMeshSO(DMeshSO appendTo, DMeshSO append)
        {
            FScene scene = appendTo.GetScene();

            if (scene.IsSelected(appendTo))
            {
                scene.Deselect(appendTo);
            }
            if (scene.IsSelected(append))
            {
                scene.Deselect(append);
            }

            Frame3f  f1     = appendTo.GetLocalFrame(CoordSpace.ObjectCoords);
            Vector3f scale1 = appendTo.GetLocalScale();
            Frame3f  f2     = append.GetLocalFrame(CoordSpace.ObjectCoords);
            Vector3f scale2 = append.GetLocalScale();

            DMesh3 mesh1 = appendTo.Mesh;

            DMesh3 mesh2 = append.Mesh;

            foreach (int vid in mesh2.VertexIndices())
            {
                // convert point in mesh2 to scene coords
                Vector3f v2 = (Vector3f)mesh2.GetVertex(vid);
                v2 *= scale2;
                Vector3f v2s = f2.FromFrameP(v2);

                // transfer that scene coord into local coords of mesh1
                Vector3f v2in1 = f1.ToFrameP(v2s);
                v2in1 /= scale1;
                mesh2.SetVertex(vid, v2in1);

                if (mesh1.HasVertexNormals && mesh2.HasVertexNormals)
                {
                    Vector3f n   = mesh2.GetVertexNormal(vid);
                    Vector3f ns  = f2.FromFrameV(n);
                    Vector3f ns2 = f1.ToFrameV(ns);
                    mesh2.SetVertexNormal(vid, ns2);
                }
            }

            MeshEditor editor = new MeshEditor(mesh1);

            editor.AppendMesh(mesh2);

            appendTo.NotifyMeshEdited();

            // [TODO] change record!

            scene.RemoveSceneObject(append, false);
        }
Ejemplo n.º 4
0
        public static void WriteDebugMesh(IEnumerable <DMesh3> meshes, string sPath)
        {
            DMesh3     combined = new DMesh3(MeshComponents.FaceGroups);
            MeshEditor editor   = new MeshEditor(combined);
            int        gid      = 1;

            foreach (DMesh3 m in meshes)
            {
                editor.AppendMesh(m, gid++);
            }
            WriteDebugMesh(combined, sPath);
        }
Ejemplo n.º 5
0
		List<DMesh3> process_solids(List<DMesh3> solid_components)
		{
			// [TODO] maybe we can have special tags that extract out certain meshes?

			var combinedSolid = new DMesh3(SourceMesh.Components | MeshComponents.FaceGroups);
			var editor = new MeshEditor(combinedSolid);
			foreach (DMesh3 solid in solid_components)
			{
				editor.AppendMesh(solid, combinedSolid.AllocateTriangleGroup());
			}

			return new List<DMesh3>() { combinedSolid };
		}
Ejemplo n.º 6
0
        public List <MeshGeometry3D> GenerateMold(double resolution, List <MeshGeometry3D> airholes, List <double> z_slices)
        {
            //merges airholes and bolus mesh for subtraction later
            var bolus = new DMesh3();

            if (airholes.Count > 0)
            {
                //airholes
                var        holes  = new DMesh3();
                MeshEditor editor = new MeshEditor(holes);
                foreach (MeshGeometry3D m in airholes)
                {
                    editor.AppendMesh(MeshGeometryToDMesh(m));
                }


                //boolean union the airholes and the bolus
                if (_smoothMesh != null)
                {
                    bolus = BooleanUnion(_smoothMesh, holes);
                }
                else
                {
                    bolus = BooleanUnion(_mesh, holes);
                }
            }
            else
            if (_smoothMesh != null)
            {
                bolus = _smoothMesh;
            }
            else
            {
                bolus = _mesh;
            }

            //generates the outer mold and interior cavity for the bolus
            var _molds = new List <MeshGeometry3D>();

            _moldMesh = new List <DMesh3>();
            var molds = new BolusMold(_displayMesh, resolution, z_slices).Meshes;

            //subtract the bolus from the mold
            for (int i = 0; i <= z_slices.Count; i++)
            {
                _moldMesh.Add(BooleanSubtraction(MeshGeometryToDMesh(molds[i]), bolus));
                _molds.Add(DMeshToMeshGeometry(_moldMesh[i]));
            }

            return(_molds);
        }
Ejemplo n.º 7
0
        public AppendInfo AppendConnectorTo(DMesh3 mesh, Vector3d translate)
        {
            validate_geometry();

            AppendInfo info = new AppendInfo();

            MeshEditor editor = new MeshEditor(mesh);

            int[] mapV;

            if (HasInner)
            {
                info.InnerGID = mesh.AllocateTriangleGroup();
                editor.AppendMesh(InnerMesh, out mapV, info.InnerGID);
                info.InnerLoop = EdgeLoop.FromVertices(mesh, new MappedList(InnerLoop.Vertices, mapV));

                MeshTransforms.PerVertexTransform(mesh, InnerMesh.VertexIndices(),
                                                  (vid) => { return(mapV[vid]); },
                                                  (v, old_vid, new_vid) => { return(v + translate); });
            }
            else
            {
                info.InnerGID  = -1;
                info.InnerLoop = null;
            }

            info.OuterGID = mesh.AllocateTriangleGroup();
            editor.AppendMesh(OuterMesh, out mapV, info.OuterGID);
            info.OuterLoop = EdgeLoop.FromVertices(mesh, new MappedList(OuterLoop.Vertices, mapV));

            MeshTransforms.PerVertexTransform(mesh, OuterMesh.VertexIndices(),
                                              (vid) => { return(mapV[vid]); },
                                              (v, old_vid, new_vid) => { return(v + translate); });

            return(info);
        }
Ejemplo n.º 8
0
        public virtual void Setup()
        {
            // push history stream, so that we can do undo/redo internal to tool,
            // that will not end up in external history
            push_history_stream();

            if (OnApplyF == null)
            {
                OnApplyF = this.add_to_scene;
            }

            combineMesh = new DMesh3();
            MeshEditor editor = new MeshEditor(combineMesh);

            foreach (var so in InputSOs)
            {
                DMesh3 inputMesh = so.Mesh;
                int[]  mapV;
                if (editor.AppendMesh(so.Mesh, out mapV))
                {
                    MeshTransforms.PerVertexTransform(combineMesh, inputMesh, mapV, (v, old_id, new_id) => {
                        return(SceneTransforms.ObjectToSceneP(so, v));
                    });
                }
            }
            ;

            MeshSourceOp = new ConstantMeshSourceOp(combineMesh, true, true);
            SeparateOp   = new SeparateSolidsOp()
            {
                MeshSource = MeshSourceOp
            };

            ComputeOp = new ThreadedResultComputeOp <List <DMesh3> >()
            {
                ResultSource = SeparateOp
            };

            if (HiddenPreviewMaterial == null)
            {
                HiddenPreviewMaterial = SOMaterial.CreateTransparent("remove_hidden_generated", new Colorf(Colorf.DimGrey, 0.5f));
            }
            if (KeepPreviewMaterial == null)
            {
                KeepPreviewMaterial = SOMaterial.CreateFlatShaded("remove_keep_generated", Colorf.DimGrey);
            }
        }
Ejemplo n.º 9
0
        public virtual void Setup()
        {
            // push history stream, so that we can do undo/redo internal to tool,
            // that will not end up in external history
            push_history_stream();

            if (OnApplyF == null)
            {
                OnApplyF = this.add_so_to_scene;
            }

            if (PreviewMaterial == null)
            {
                PreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey);
            }
            if (ErrorMaterial == null)
            {
                ErrorMaterial = SOMaterial.CreateMesh("tool_generated_error", Colorf.VideoRed);
            }

            // clear selection here so that multi-select GroupSO goes away, otherwise
            // when we copy frmaes below, they are relative to that GroupSO, and things move
            inputSelection = new List <SceneObject>(Scene.Selected);
            set_allow_selection_changes(true);
            Scene.ClearSelection();
            set_allow_selection_changes(false);

            if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false)
            {
                combineMesh         = new DMesh3(InputSOs[0].Mesh);
                sceneToObjUnitScale = SceneTransforms.SceneToObject(InputSOs[0], 1.0f);
            }
            else
            {
                combineMesh = new DMesh3();
                MeshEditor editor = new MeshEditor(combineMesh);
                foreach (var so in InputSOs)
                {
                    TransformSequence xform     = SceneTransforms.ObjectToSceneXForm(so);
                    DMesh3            inputMesh = so.Mesh;
                    int[]             mapV;
                    if (editor.AppendMesh(so.Mesh, out mapV))
                    {
                        MeshTransforms.PerVertexTransform(combineMesh, inputMesh, mapV, (v, old_id, new_id) => {
                            return(xform.TransformP(v));
                        });
                    }
                }
                ;
                sceneToObjUnitScale = 1.0;
            }


            MeshSourceOp = new ConstantMeshSourceOp(combineMesh, true, true);
            EditOp       = edit_op_factory(MeshSourceOp);
            ComputeOp    = new ThreadedMeshComputeOp()
            {
                MeshSource = EditOp
            };

            PreviewSO = new DMeshSO()
            {
                EnableSpatial = EnablePreviewSpatial
            };
            PreviewSO.Create(new DMesh3(), PreviewMaterial);
            if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false)
            {
                PreviewSO.SetLocalFrame(InputSOs[0].GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords);
                PreviewSO.SetLocalScale(InputSOs[0].GetLocalScale());
            }
            Scene.AddSceneObject(PreviewSO);

            postprocess_target_objects();
            base_initialize_parameters();
        }
Ejemplo n.º 10
0
  public void takePointsinandAddtoMesh(List <Vector3d> pointers)
  {
      List <int>      tris    = new List <int>();
      List <Vector3d> normals = new List <Vector3d>();
      float           normal  = .01f;



      if (currentMesh == null)
      {
//ok so first mesh is not been created yet so create it from the first frame
          int counter = 0;
          foreach (Vector3d line in pointers)
          {
              counter++;
//Debug.Log(line);
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }

          DMesh3         pointSet = DMesh3Builder.Build(pointers, tris, normals);
          PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);
          bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
          double[] areas = new double[pointSet.MaxVertexID];
          foreach (int vid in pointSet.VertexIndices())
          {
              bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
              int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
              double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
              areas[vid] = Circle2d.RadiusArea(dist);
          }
          bvtree.FWNAreaEstimateF = (vid) => {
              return(areas[vid]);
          };
          MarchingCubes mc = new MarchingCubes();
          mc.Implicit = new PWNImplicit()
          {
              Spatial = bvtree
          };
          mc.IsoValue = 0.0;
          mc.CubeSize = bvtree.Bounds.MaxDim / 10;
          mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
          mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
          mc.Generate();
          DMesh3 resultMesh = mc.Mesh;
          //  g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
          currentMesh = resultMesh;
      }
      else
      {
//ok so this is where we are proscessing second mesh
          int counter = 0;
          foreach (Vector3d line in pointers)
          {
              counter++;
//Debug.Log(line);
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }

          DMesh3         pointSet = DMesh3Builder.Build(pointers, tris, normals);
          PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);
          bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
          double[] areas = new double[pointSet.MaxVertexID];
          foreach (int vid in pointSet.VertexIndices())
          {
              bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
              int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
              double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
              areas[vid] = Circle2d.RadiusArea(dist);
          }
          bvtree.FWNAreaEstimateF = (vid) => {
              return(areas[vid]);
          };
          MarchingCubes mc = new MarchingCubes();
          mc.Implicit = new PWNImplicit()
          {
              Spatial = bvtree
          };
          mc.IsoValue = 0.0;
          mc.CubeSize = bvtree.Bounds.MaxDim / 10;
          mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
          mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
          mc.Generate();
          DMesh3     resultMesh = mc.Mesh;
          MeshEditor editor     = new MeshEditor(currentMesh);

          editor.AppendMesh(resultMesh, currentMesh.AllocateTriangleGroup());
//suspected its crashing after mesh is over 64000 faces,
          faceLog.text = "Vertex Count =  " + transform.gameObject.GetComponent <MeshFilter>().mesh.triangles.Length;

          g3UnityUtils.SetGOMesh(transform.gameObject, currentMesh);
      }
  }
Ejemplo n.º 11
0
  public void fpMeshPointsfromTextFileWithaSecondPoints()
  {
//this is used in the fast points winding scene to optimize algorithm and make sure its working well
//it reads points via text files and then meshes them
      List <Vector3d> points  = new List <Vector3d>();
      List <int>      tris    = new List <int>();
      List <Vector3d> normals = new List <Vector3d>();
      float           normal  = .01f;

      string toPull = ReadString();

      string[] linesInFile = toPull.Split('\n');

      int counter = 0;

      foreach (string line in linesInFile)
      {
          counter++;
//Debug.Log(line);

          if (!string.IsNullOrEmpty(line))
          {
              points.Add(StringToVector3(line));
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }
      }

      DMesh3         pointSet = DMesh3Builder.Build(points, tris, normals);
      PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);

      bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
      double[] areas = new double[pointSet.MaxVertexID];
      foreach (int vid in pointSet.VertexIndices())
      {
          bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
          int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
          double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
          areas[vid] = Circle2d.RadiusArea(dist);
      }
      bvtree.FWNAreaEstimateF = (vid) => {
          return(areas[vid]);
      };
      MarchingCubes mc = new MarchingCubes();

      mc.Implicit = new PWNImplicit()
      {
          Spatial = bvtree
      };
      mc.IsoValue = 0.0;
      mc.CubeSize = bvtree.Bounds.MaxDim / 50;
      mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
      mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
      mc.Generate();
      DMesh3 resultMesh = mc.Mesh;

      g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);

      /*  MarchingCubes mc = new MarchingCubes();
       *   mc.Implicit = new PWNImplicit() { Spatial =  bvtree };
       *   mc.IsoValue = 0.0;
       *   mc.CubeSize = bvtree.Bounds.MaxDim / 10;
       *   mc.Bounds =  bvtree.Bounds.Expanded(mc.CubeSize * 3);
       *   mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
       *   mc.Generate();
       *   DMesh3 resultMesh = mc.Mesh;
       *   g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
       */
//ok now that we meshed the first point set, lets try to take in a second frame of points and then add to orginal dmesh
      points  = new List <Vector3d>();
      tris    = new List <int>();
      normals = new List <Vector3d>();


      toPull      = ReadString1();
      linesInFile = toPull.Split('\n');

      counter = 0;
      foreach (string line in linesInFile)
      {
          counter++;
          Debug.Log(line);

          if (!string.IsNullOrEmpty(line))
          {
              points.Add(StringToVector3(line));
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }
      }
      pointSet = DMesh3Builder.Build(points, tris, normals);
      bvtree   = new PointAABBTree3(pointSet, true);
      bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
      areas = new double[pointSet.MaxVertexID];
      foreach (int vid in pointSet.VertexIndices())
      {
          bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
          int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
          double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
          areas[vid] = Circle2d.RadiusArea(dist);
      }
      bvtree.FWNAreaEstimateF = (vid) => {
          return(areas[vid]);
      };
      mc          = new MarchingCubes();
      mc.Implicit = new PWNImplicit()
      {
          Spatial = bvtree
      };
      mc.IsoValue = 0.0;
      mc.CubeSize = bvtree.Bounds.MaxDim / 50;
      mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
      mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
      mc.Generate();
      DMesh3     resultMesh1 = mc.Mesh;
      MeshEditor editor      = new MeshEditor(resultMesh);

      editor.AppendMesh(resultMesh1, resultMesh.AllocateTriangleGroup());

      g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh1);

      //  g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
  }
Ejemplo n.º 12
0
        // extracts all MeshFilter objects from input GameObject and appends them, then passes to
        // function MakeSOFunc (if null, creates basic MeshSO). Then optionally adds to Scene,
        // preserving existing 3D position if desired (default true)
        public static SceneObject ImportExistingUnityGO(GameObject go, FScene scene,
                                                        bool bAddToScene = true, bool bKeepWorldPosition = true, bool bRecenterFrame = true,
                                                        Func <DMesh3, SOMaterial, SceneObject> MakeSOFunc = null)
        {
            List <MeshFilter> filters  = new List <MeshFilter>();
            List <GameObject> children = new List <GameObject>()
            {
                go
            };

            UnityUtil.CollectAllChildren(go, children);
            foreach (var cgo in children)
            {
                if (cgo.GetComponent <MeshFilter>() != null)
                {
                    filters.Add(cgo.GetComponent <MeshFilter>());
                }
            }
            if (filters.Count == 0)
            {
                throw new Exception("SceneUtil.ImportExistingUnityGO: no meshes!!");
            }

            DMesh3     CombineMesh = new DMesh3(MeshComponents.VertexNormals | MeshComponents.VertexColors);
            MeshEditor editor      = new MeshEditor(CombineMesh);
            int        gid         = 0;

            foreach (MeshFilter mesh in filters)
            {
                fMesh uMesh = new fMesh(mesh.sharedMesh);
                using (var imesh = uMesh.CreateCachedIMesh()) {
                    editor.AppendMesh(imesh, ++gid);
                }
            }

            Vector3f scale = go.GetLocalScale();

            AxisAlignedBox3d bounds = CombineMesh.CachedBounds;  // bounds.Center is wrt local frame of input go

            // ie offset from origin in local coordinates

            // if we want to move frame to center of mesh, we have to re-center it at origin
            // in local coordinates
            if (bRecenterFrame)
            {
                MeshTransforms.Translate(CombineMesh, -bounds.Center.x, -bounds.Center.y, -bounds.Center.z);
            }

            SceneObject newSO = (MakeSOFunc != null) ?
                                MakeSOFunc(CombineMesh, scene.DefaultMeshSOMaterial)
                : new DMeshSO().Create(CombineMesh, scene.DefaultMeshSOMaterial);

            newSO.Name = go.name;

            if (bAddToScene)
            {
                scene.AddSceneObject(newSO, false);
            }

            if (bKeepWorldPosition)
            {
                // compute world rotation/location. If we re-centered the mesh, we need
                // to offset by the transform we applied above in local coordinates
                // (hence we have to rotate & scale)
                if (go.transform.parent != null)
                {
                    throw new Exception("UnitySceneUtil.ImportExistingUnityGO: Not handling case where GO has a parent transform");
                }
                Frame3f  goFrameW = UnityUtil.GetGameObjectFrame(go, CoordSpace.WorldCoords);
                Vector3f originW  = goFrameW.Origin;
                if (bRecenterFrame)
                {
                    originW += goFrameW.Rotation * (scale * (Vector3f)bounds.Center);   // offset initial frame to be at center of mesh
                }
                // convert world frame and offset to scene coordinates
                Frame3f  goFrameS      = scene.ToSceneFrame(goFrameW);
                Vector3f boundsCenterS = scene.ToSceneP(originW);

                // translate new object to position in scene
                Frame3f curF = newSO.GetLocalFrame(CoordSpace.SceneCoords);
                curF.Origin += boundsCenterS;
                newSO.SetLocalFrame(curF, CoordSpace.SceneCoords);

                // apply rotation (around current origin)
                curF = newSO.GetLocalFrame(CoordSpace.SceneCoords);
                curF.RotateAround(curF.Origin, goFrameS.Rotation);
                newSO.SetLocalFrame(curF, CoordSpace.SceneCoords);

                // apply local scale
                newSO.SetLocalScale(scale);
            }

            return(newSO);
        }
Ejemplo n.º 13
0
        virtual public void PreRender()
        {
            if (in_shutdown())
            {
                return;
            }

            if (parameters_dirty)
            {
                // offset
                List <GeneralPolygon2d> offset = ClipperUtil.RoundOffset(combined_all, offset_distance);
                // aggressively simplify after round offset...
                foreach (var poly in offset)
                {
                    poly.Simplify(path_width);
                }

                // subtract initial and add tiny gap so these don't get merged by slicer
                if (SubtractSolids)
                {
                    offset = ClipperUtil.Difference(offset, combined_solid);
                    offset = ClipperUtil.MiterOffset(offset, -path_width * 0.1);
                }

                offset = CurveUtils2.FilterDegenerate(offset, 0.001);
                foreach (var poly in offset)
                {
                    poly.Simplify(path_width * 0.02);
                }

                DMesh3     mesh   = new DMesh3();
                MeshEditor editor = new MeshEditor(mesh);
                foreach (var poly in offset)
                {
                    TriangulatedPolygonGenerator polygen = new TriangulatedPolygonGenerator()
                    {
                        Polygon = poly
                    };
                    editor.AppendMesh(polygen.Generate().MakeDMesh());
                }
                MeshTransforms.ConvertZUpToYUp(mesh);

                if (mesh.TriangleCount > 0)
                {
                    MeshExtrudeMesh extrude = new MeshExtrudeMesh(mesh);
                    extrude.ExtrudedPositionF = (v, n, vid) => {
                        return(v + Layers * layer_height * Vector3d.AxisY);
                    };
                    extrude.Extrude();
                    MeshTransforms.Translate(mesh, -mesh.CachedBounds.Min.y * Vector3d.AxisY);
                }

                PreviewSO.ReplaceMesh(mesh, true);

                //Vector3d translate = scene_bounds.Point(1, -1, 1);
                //translate.x += spiral.Bounds.Width + PathWidth;
                //Frame3f sceneF = Frame3f.Identity.Translated((Vector3f)translate);
                //PreviewSO.SetLocalFrame(sceneF, CoordSpace.SceneCoords);

                parameters_dirty = false;
            }
        }
Ejemplo n.º 14
0
        public virtual void Update()
        {
            base.begin_update();
            int start_timestamp = this.CurrentInputTimestamp;

            if (MeshSource == null)
            {
                throw new Exception("CombineMeshesOp: must set valid MeshSource to compute!");
            }

            ResultMesh = null;

            try {
                DMesh3 meshIn = new DMesh3(MeshSource.GetDMeshUnsafe());

                if (orient_nested_shells)
                {
                    MeshConnectedComponents comp = new MeshConnectedComponents(meshIn);
                    comp.FindConnectedT();
                    DSubmesh3Set subMeshes = new DSubmesh3Set(meshIn, comp);

                    List <DMesh3> curMeshes = new List <DMesh3>();
                    foreach (var submesh in subMeshes)
                    {
                        curMeshes.Add(submesh.SubMesh);
                    }

                    MeshSpatialSort sort = new MeshSpatialSort();
                    foreach (var mesh in curMeshes)
                    {
                        sort.AddMesh(mesh, mesh);
                    }
                    sort.Sort();

                    ResultMesh = new DMesh3();
                    MeshEditor editor = new MeshEditor(ResultMesh);
                    foreach (var solid in sort.Solids)
                    {
                        DMesh3 outer = solid.Outer.Mesh;
                        if (!is_outward_oriented(outer))
                        {
                            outer.ReverseOrientation();
                        }
                        editor.AppendMesh(outer, ResultMesh.AllocateTriangleGroup());

                        foreach (var hole in solid.Cavities)
                        {
                            if (hole.Mesh.CachedIsClosed && is_outward_oriented(hole.Mesh) == true)
                            {
                                hole.Mesh.ReverseOrientation();
                            }
                            editor.AppendMesh(hole.Mesh, ResultMesh.AllocateTriangleGroup());
                        }
                    }
                }
                else
                {
                    ResultMesh = meshIn;
                }

                base.complete_update();
            } catch (Exception e) {
                PostOnOperatorException(e);
                ResultMesh = base.make_failure_output(MeshSource.GetDMeshUnsafe());
                base.complete_update();
            }
        }