Example #1
0
        private static bool CheckPosition(int meshGroupToMoveIndex, List <MeshGroup> allMeshGroups, List <ScaleRotateTranslate> meshTransforms, MeshGroup meshGroupToMove, AxisAlignedBoundingBox meshToMoveBounds, int yStep, int xStep, ref Matrix4X4 transform)
        {
            double xStepAmount = 5;
            double yStepAmount = 5;

            Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0);
            Vector3   newPosition       = Vector3.Transform(Vector3.Zero, positionTransform);

            transform = Matrix4X4.CreateTranslation(newPosition);
            AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform);
            bool foundHit = false;

            for (int i = 0; i < meshGroupToMoveIndex; i++)
            {
                MeshGroup meshToTest = allMeshGroups[i];
                if (meshToTest != meshGroupToMove)
                {
                    AxisAlignedBoundingBox existingMeshBounds = GetAxisAlignedBoundingBox(meshToTest, meshTransforms[i].TotalTransform);
                    AxisAlignedBoundingBox intersection       = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds);
                    if (intersection.XSize > 0 && intersection.YSize > 0)
                    {
                        foundHit = true;
                        break;
                    }
                }
            }

            if (!foundHit)
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        private static bool CheckPosition(IEnumerable <IObject3D> itemsToAvoid, IObject3D itemToMove, AxisAlignedBoundingBox meshToMoveBounds, int yStep, int xStep, ref Matrix4X4 transform)
        {
            double xStepAmount = 5;
            double yStepAmount = 5;

            Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0);
            Vector3   newPosition       = Vector3Ex.Transform(Vector3.Zero, positionTransform);

            transform = Matrix4X4.CreateTranslation(newPosition);

            AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform);

            foreach (IObject3D meshToTest in itemsToAvoid)
            {
                if (meshToTest != itemToMove)
                {
                    AxisAlignedBoundingBox existingMeshBounds = meshToTest.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
                    AxisAlignedBoundingBox intersection       = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds);
                    if (intersection.XSize > 0 && intersection.YSize > 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public AxisAlignedBoundingBox GetAxisAlignedBoundingBox()
        {
            Vector3 localOrigin = Origin;
            AxisAlignedBoundingBox localBounds = Child.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox bounds      = localBounds.NewTransformed(AxisToWorld);

            return(bounds);
        }
Example #4
0
        public static void MoveMeshGroupToOpenPosition(int meshGroupToMoveIndex, List <PlatingMeshGroupData> perMeshInfo, List <MeshGroup> allMeshGroups, List <ScaleRotateTranslate> meshTransforms)
        {
            MeshGroup meshGroupToMove = allMeshGroups[meshGroupToMoveIndex];
            // find a place to put it that doesn't hit anything
            AxisAlignedBoundingBox meshToMoveBounds = meshGroupToMove.GetAxisAlignedBoundingBox(meshTransforms[meshGroupToMoveIndex].TotalTransform);

            // add in a few mm so that it will not be touching
            meshToMoveBounds.minXYZ -= new Vector3(2, 2, 0);
            meshToMoveBounds.maxXYZ += new Vector3(2, 2, 0);
            double    ringDist       = Math.Min(meshToMoveBounds.XSize, meshToMoveBounds.YSize);
            double    currentDist    = 0;
            double    angle          = 0;
            double    angleIncrement = MathHelper.Tau / 64;
            Matrix4X4 transform;

            while (true)
            {
                Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(currentDist, 0, 0);
                positionTransform *= Matrix4X4.CreateRotationZ(angle);
                Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform);
                transform = Matrix4X4.CreateTranslation(newPosition);
                AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform);
                bool foundHit = false;
                for (int i = 0; i < allMeshGroups.Count; i++)
                {
                    MeshGroup meshToTest = allMeshGroups[i];
                    if (meshToTest != meshGroupToMove)
                    {
                        AxisAlignedBoundingBox existingMeshBounds = meshToTest.GetAxisAlignedBoundingBox(meshTransforms[i].TotalTransform);
                        AxisAlignedBoundingBox intersection       = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds);
                        if (intersection.XSize > 0 && intersection.YSize > 0)
                        {
                            foundHit = true;
                            break;
                        }
                    }
                }

                if (!foundHit)
                {
                    break;
                }

                angle += angleIncrement;
                if (angle >= MathHelper.Tau)
                {
                    angle        = 0;
                    currentDist += ringDist;
                }
            }

            ScaleRotateTranslate moved = meshTransforms[meshGroupToMoveIndex];

            moved.translation *= transform;
            meshTransforms[meshGroupToMoveIndex] = moved;
        }
Example #5
0
        public AxisAlignedBoundingBox GetAxisAlignedBoundingBox()
        {
            if (Child == null)
            {
                return(new AxisAlignedBoundingBox(Vector3.Zero, Vector3.Zero));
            }
            Vector3 localOrigin = Origin;
            AxisAlignedBoundingBox localBounds = Child.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox bounds      = localBounds.NewTransformed(AxisToWorld);

            return(bounds);
        }
Example #6
0
        public override List <WidgetAndPosition> FindDescendants(IEnumerable <string> namesToSearchFor, List <WidgetAndPosition> foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true)
        {
            foreach (InteractionVolume child in this.InteractionVolumes)
            {
                string object3DName = child.Name;

                bool nameFound = false;

                foreach (var nameToSearchFor in namesToSearchFor)
                {
                    if (seachType == SearchType.Exact)
                    {
                        if (object3DName == nameToSearchFor)
                        {
                            nameFound = true;
                            break;
                        }
                    }
                    else
                    {
                        if (nameToSearchFor == "" ||
                            object3DName.Contains(nameToSearchFor))
                        {
                            nameFound = true;
                            break;
                        }
                    }
                }

                if (nameFound &&
                    child.CollisionVolume != null)
                {
                    AxisAlignedBoundingBox bounds = child.CollisionVolume.GetAxisAlignedBoundingBox();
                    bounds = bounds.NewTransformed(child.TotalTransform);

                    RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;
                    for (int i = 0; i < 4; i++)
                    {
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i)));
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i)));
                    }

                    if (touchingBounds.IsTouching(screenBoundsOfObject3D))
                    {
                        Vector3 renderPosition           = bounds.Center;
                        Vector2 objectCenterScreenSpace  = this.World.GetScreenPosition(renderPosition);
                        var     screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

                        foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child));
                    }
                }
            }

            foreach (var child in scene.Children)
            {
                string object3DName = child.Name;
                if (object3DName == null && child.MeshPath != null)
                {
                    object3DName = Path.GetFileName(child.MeshPath);
                }

                bool nameFound = false;

                foreach (var nameToSearchFor in namesToSearchFor)
                {
                    if (seachType == SearchType.Exact)
                    {
                        if (object3DName == nameToSearchFor)
                        {
                            nameFound = true;
                            break;
                        }
                    }
                    else
                    {
                        if (nameToSearchFor == "" ||
                            object3DName.Contains(nameToSearchFor))
                        {
                            nameFound = true;
                            break;
                        }
                    }
                }

                if (nameFound)
                {
                    AxisAlignedBoundingBox bounds = child.GetBVHData().GetAxisAlignedBoundingBox();

                    RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;
                    for (int i = 0; i < 4; i++)
                    {
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i)));
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i)));
                    }

                    if (touchingBounds.IsTouching(screenBoundsOfObject3D))
                    {
                        Vector3 renderPosition           = bounds.Center;
                        Vector2 objectCenterScreenSpace  = this.World.GetScreenPosition(renderPosition);
                        var     screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

                        foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child));
                    }
                }
            }

            return(base.FindDescendants(namesToSearchFor, foundChildren, touchingBounds, seachType, allowInvalidItems));
        }
 public static AxisAlignedBoundingBox GetWorldspaceAabbOfRenderAabb(AxisAlignedBoundingBox bounds, Matrix4X4 matrix, double lineWidth = 1, double extendLineLength = 0)
 {
     bounds = bounds.NewTransformed(matrix);
     bounds.Expand(extendLineLength);
     return(bounds);
 }
Example #8
0
        public override AxisAlignedBoundingBox GetAxisAlignedBoundingBox()
        {
            AxisAlignedBoundingBox childBounds = objectToTransform.GetAxisAlignedBoundingBox();

            return(childBounds.NewTransformed(transform));
        }