コード例 #1
0
        public void Build(int maxAxisSubdivs = 64)
        {
            AxisAlignedBox3d bounds   = BoundsUtil.Bounds(Points);
            double           cellsize = bounds.MaxDim / (double)maxAxisSubdivs;

            Build(cellsize, bounds.Min);
        }
コード例 #2
0
        public static void Center(FScene scene, IEnumerable <DMeshSO> objects, bool bInteractive)
        {
            AxisAlignedBox3d all_bounds = AxisAlignedBox3d.Empty;

            foreach (var so in objects)
            {
                TransformSequence seq    = SceneTransforms.ObjectToSceneXForm(so);
                AxisAlignedBox3d  bounds = BoundsUtil.Bounds(so.Mesh.Vertices(), seq);
                all_bounds.Contain(bounds);
            }
            Vector3f c = (Vector3f)all_bounds.Center;

            c.y = 0;

            foreach (var so in objects)
            {
                Frame3f curFrameS = so.GetLocalFrame(CoordSpace.SceneCoords);
                Frame3f newFrameS = curFrameS;
                newFrameS.Origin = curFrameS.Origin - c;
                TransformSOChange change = new TransformSOChange(so, curFrameS, newFrameS, CoordSpace.SceneCoords);
                scene.History.PushChange(change, false);
            }
            if (bInteractive)
            {
                scene.History.PushInteractionCheckpoint();
            }
        }
コード例 #3
0
 public override void update_curve(Vector3f[] Vertices)
 {
     base.update_curve(Vertices);
     if (Vertices == null)
     {
         center = Vector3f.Zero;
     }
     else
     {
         center = BoundsUtil.Bounds(Vertices, (x) => { return(x); }).Center;
     }
 }
コード例 #4
0
        public static void MoveToPrintBed(FScene scene, DMeshSO so, bool bInteractive)
        {
            TransformSequence seq    = SceneTransforms.ObjectToSceneXForm(so);
            AxisAlignedBox3d  bounds = BoundsUtil.Bounds(so.Mesh.Vertices(), seq);

            Frame3f curFrameS = so.GetLocalFrame(CoordSpace.SceneCoords);
            float   dy        = (float)(bounds.Center.y - bounds.Extents.y);

            if (Math.Abs(dy) > MathUtil.ZeroTolerancef)
            {
                Frame3f newFrameS = curFrameS;
                newFrameS.Origin = curFrameS.Origin - dy * Vector3f.AxisY;
                TransformSOChange change = new TransformSOChange(so, curFrameS, newFrameS, CoordSpace.SceneCoords);
                change.Tags.Add("MoveToPrintBed");
                scene.History.PushChange(change, false);
                if (bInteractive)
                {
                    scene.History.PushInteractionCheckpoint();
                }
            }
        }
コード例 #5
0
        public static void WriteDebugMeshAndMarkers(IMesh mesh, List <Vector3D> Markers, string sPath)
        {
            WriteOptions options = WriteOptions.Defaults;

            options.bWriteGroups = true;
            List <WriteMesh> meshes = new List <WriteMesh>()
            {
                new WriteMesh(mesh)
            };
            double size = BoundsUtil.Bounds(mesh).Diagonal.Length * 0.01f;

            foreach (Vector3D v in Markers)
            {
                TrivialBox3Generator boxgen = new TrivialBox3Generator();
                boxgen.Box = new Box3d(v, size * Vector3D.One);
                boxgen.Generate();
                DMesh3 m = new DMesh3();
                boxgen.MakeMesh(m);
                meshes.Add(new WriteMesh(m));
            }

            StandardMeshWriter.WriteFile(sPath, meshes, options);
        }
コード例 #6
0
        // appends connector to mesh. This one is messy
        bool compute_connector(DMesh3 mesh)
        {
            if (DebugStep <= 2)
            {
                return(true);
            }

            AxisAlignedBox3d socketBounds = mesh.CachedBounds;
            Vector3d         c            = socketBounds.Center;

            c.y = socketBounds.Min.y + ConnectorCutHeight;

            /*
             * first we select the outer shell triangles, and plane-cut them some ways up from the bottom.
             * This creates an open loop that we hang onto
             */

            MeshPlaneCut outer_cut = new MeshPlaneCut(mesh, c, CutPlaneNormal);

            outer_cut.CutFaceSet = new MeshFaceSelection(mesh, LastExtrudeOuterGroupID);
            outer_cut.Cut();

            MeshPlaneCut inner_cut = null;

            if (Connector.HasInner)
            {
                inner_cut            = new MeshPlaneCut(mesh, c, CutPlaneNormal);
                inner_cut.CutFaceSet = new MeshFaceSelection(mesh, LastInnerGroupID);
                inner_cut.Cut();
            }

            if (DebugStep <= 3)
            {
                return(true);
            }

            // save the loops we created
            EdgeLoop         outerCutLoop  = outer_cut.CutLoops[0];
            EdgeLoop         innerCutLoop  = (inner_cut != null) ? inner_cut.CutLoops[0] : null;
            AxisAlignedBox3d cutLoopBounds =
                BoundsUtil.Bounds(outerCutLoop.Vertices, (vid) => { return(mesh.GetVertex(vid)); });

            /*
             * Now we append the connector mesh and find its open loop
             */

            // figure out where we want to position connector (which will be centered below origin)
            double dy = 0; // socketBounds.Min.y;

            if (socketBounds.Min.y < 0)
            {
                dy = socketBounds.Min.y + 5.0;
            }
            Vector3d shiftxz  = Vector3d.Zero;// new Vector3d(cutLoopBounds.Center.x, 0, cutLoopBounds.Center.z);
            Vector3d shiftxyz = shiftxz + dy * Vector3d.AxisY;

            // append the connector
            // [TODO] do we need to hold the lock this entire time? I guess so since it would
            //   be a disaster if connector changes...
            bool bConnectorOK = true;

            lock (connector_lock) {
                SocketConnector.AppendInfo append_info =
                    Connector.AppendConnectorTo(mesh, shiftxyz);

                if (DebugStep <= 4)
                {
                    return(true);
                }

                // [TODO] push out of inner offset here...
                if (Connector.HasInner)
                {
                    merge_loops(mesh, innerCutLoop, append_info.InnerLoop, false);
                }
                // [TODO] in addition to pushing out of outer offset, we should also make sure
                //   we are far enough away from inner merge surface...
                merge_loops(mesh, outerCutLoop, append_info.OuterLoop, true);

                bConnectorOK = Connector.CutHoles(mesh, shiftxyz);
                if (bConnectorOK == false)
                {
                    f3.DebugUtil.Log("Connector.CutHoles failed!");
                }
            }

            return(bConnectorOK);
        }