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(); } }
public void Build(int maxAxisSubdivs = 64) { AxisAlignedBox3d bounds = BoundsUtil.Bounds(Points); double cellsize = bounds.MaxDim / (double)maxAxisSubdivs; Build(cellsize, bounds.Min); }
private bool IsGroupValid(List <GameObject> group, List <Vector2> blockBounds) { //check if existing group bool isAlreadyGroup = this.IsGroupAlreadyExist(group); //check if the geometry is correct List <Vector2> boundsFromGeometry = BoundsUtil.GetBoundsFromGeometry(group); bool areBoundsEqual = BoundsUtil.AreBoundsSizeEqual(boundsFromGeometry, blockBounds, Block.BlockSize / 4f); return(isAlreadyGroup == false && areBoundsEqual); }
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; } }
public DMeshSO BuildSO(FScene scene, SOMaterial material) { DMesh3 revolveMesh = UnityUtil.UnityMeshToDMesh(meshObject.GetSharedMesh(), false); // move axis frame to center of bbox of mesh, measured in axis frame Frame3f useF = OutputFrame; AxisAlignedBox3f boundsInFrame = (AxisAlignedBox3f)BoundsUtil.BoundsInFrame(revolveMesh.Vertices(), useF); useF.Origin = useF.FromFrameP(boundsInFrame.Center); // transform mesh into this frame MeshTransforms.ToFrame(revolveMesh, useF); // create new so DMeshSO meshSO = new DMeshSO(); meshSO.Create(revolveMesh, material); meshSO.SetLocalFrame(useF, CoordSpace.ObjectCoords); return(meshSO); }
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(); } } }
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); }
/// <summary> /// Unions blocks from the block list representing blocks whoich can be united. /// </summary> /// <param name="blocks"></param> public void UnionBlocks(List <GameObject> blocks) { print("UnionBlocks"); BlockColor color = blocks[0].GetComponent <Block>().color; //get Bounds List <Vector2> bounds = BoundsUtil.GetBoundsFromGeometry(blocks); //Destroy blocks for (var iB = 0; iB < blocks.Count; iB++) { this.blocks.Remove(blocks[iB]); Destroy(blocks[iB]); } //Create unioned Block int widthUnits = Mathf.RoundToInt((bounds[1].x - bounds[0].x) / this.blockSize); int heightUnits = Mathf.RoundToInt((bounds[1].y - bounds[0].y) / this.blockSize); GameObject block = this.CreateBlock(bounds[1].x, bounds[0].y, widthUnits, heightUnits, false, color); //Invalidate this.InvalidateRows(); }
// 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); }
/// <summary> /// Sets the movement target and the target location. Note that the two may not be the same. /// The visual target can be out of bounds but the target location cannot. /// </summary> public void SetMoveTarget(Vector2 target) { moving = true; targetRenderer.transform.position = target; this.target = BoundsUtil.VerifyBounds(target, new Bounds2D(collider2d.bounds), field.MovementBounds); }