Esempio n. 1
0
        public AxisAlignedBox3f GetPrintMeshesBounds(bool bPrecise)
        {
            AxisAlignedBox3f b = AxisAlignedBox3f.Empty;

            foreach (PrintMeshSO so in PrintMeshes)
            {
                if (SceneUtil.IsVisible(so) == false)
                {
                    continue;
                }

                if (bPrecise)
                {
                    var xform = SceneTransforms.ObjectToSceneXForm(so);
                    foreach (Vector3d v in so.Mesh.Vertices())
                    {
                        b.Contain((Vector3f)xform.TransformP(v));
                    }
                }
                else
                {
                    Box3f sobox = so.GetBoundingBox(CoordSpace.SceneCoords);
                    if (sobox.Volume > 0)
                    {
                        foreach (Vector3d v in sobox.VerticesItr())
                        {
                            b.Contain(v);
                        }
                    }
                }
            }
            return(b);
        }
Esempio n. 2
0
        //new Bounds(Vector3.zero, new Vector3(-1.31337f, -1.31337f, -1.31337f));

        public static AxisAlignedBox3f GetBoundingBox(GameObject go)
        {
            Renderer r = go.GetComponent <Renderer>();

            if (r != null)
            {
                return(r.bounds);
            }
            else if (go.HasChildren())
            {
                AxisAlignedBox3f b = InvalidBounds; int i = 0;
                foreach (GameObject child_go in go.Children())
                {
                    if (i++ == 0)
                    {
                        b = GetBoundingBox(child_go);
                    }
                    else
                    {
                        b.Contain(GetBoundingBox(child_go));
                    }
                }
                return(b);
            }
            else
            {
                return(new AxisAlignedBox3f(go.transform.position, new Vector3(0.001f, 0.001f, 0.001f)));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Compute AABB of scene in given space. Note that this will *not* be the same box
        /// in world space as in scene space.
        /// This computation ignores SOs with zero volume.
        /// </summary>
        public AxisAlignedBox3f GetBoundingBox(CoordSpace eSpace, bool bIncludeBoundsObjects)
        {
            if (eSpace == CoordSpace.ObjectCoords)
            {
                eSpace = CoordSpace.SceneCoords;
            }

            AxisAlignedBox3f b = AxisAlignedBox3f.Empty;

            foreach (SceneObject so in SceneObjects)
            {
                Box3f sobox = so.GetBoundingBox(eSpace);
                if (sobox.Volume > 0)
                {
                    foreach (Vector3d v in sobox.VerticesItr())
                    {
                        b.Contain(v);
                    }
                }
            }
            if (bIncludeBoundsObjects)
            {
                AxisAlignedBox3f sceneBounds =
                    UnityUtil.GetGeometryBoundingBox(BoundsObjects, true);
                if (sceneBounds.Volume > 0)
                {
                    if (eSpace == CoordSpace.WorldCoords)
                    {
                        for (int k = 0; k < 8; ++k)
                        {
                            b.Contain(ToWorldP(sceneBounds.Corner(k)));
                        }
                    }
                    else
                    {
                        b.Contain(sceneBounds);
                    }
                }
            }
            if (b.Volume == 0)
            {
                b = new AxisAlignedBox3f(1.0f);
            }
            return(b);
        }
Esempio n. 4
0
        public AxisAlignedBox3f GetBoundingBox(bool bIncludeBoundsObjects)
        {
            AxisAlignedBox3f b = UnityUtil.InvalidBounds;

            foreach (SceneObject so in SceneObjects)
            {
                b.Contain(so.GetTransformedBoundingBox());
            }
            if (b == UnityUtil.InvalidBounds || bIncludeBoundsObjects)
            {
                UnityUtil.Combine(b, UnityUtil.GetBoundingBox(BoundsObjects));
            }
            if (b == UnityUtil.InvalidBounds)
            {
                b.Contain(Vector3f.Zero);
                b.Expand(1.0f);
            }
            return(b);
        }
Esempio n. 5
0
        /// <summary>
        /// get combined MeshFilter bounding box of objects
        /// </summary>
        public static AxisAlignedBox3f GetGeometryBoundingBox(List <fGameObject> objects, bool bIncludeChildren = false)
        {
            AxisAlignedBox3f b = AxisAlignedBox3f.Empty;

            foreach (fGameObject go in objects)
            {
                b.Contain(GetGeometryBoundingBox(go, bIncludeChildren));
            }
            return(b);
        }
Esempio n. 6
0
        public static AxisAlignedBox3f BoundsInFrame(Mesh m, Frame3f f)
        {
            AxisAlignedBox3f box = AxisAlignedBox3f.Empty;
            int N = m.vertexCount;

            for (int k = 0; k < N; ++k)
            {
                box.Contain(f.ToFrameP(m.vertices[k]));
            }
            return(box);
        }
Esempio n. 7
0
        // will return InvalidBounds if any element in list doesn't have a mesh
        public static AxisAlignedBox3f GetGeometryBoundingBox(List <GameObject> objects)
        {
            if (objects.Count == 0)
            {
                return(InvalidBounds);
            }
            AxisAlignedBox3f b = GetGeometryBoundingBox(objects[0]);

            foreach (GameObject go in objects)
            {
                b.Contain(GetGeometryBoundingBox(go));
            }
            return(b);
        }
Esempio n. 8
0
        public static AxisAlignedBox3f GetBoundingBox(List <GameObject> objects)
        {
            if (objects.Count == 0)
            {
                return(InvalidBounds);
            }
            AxisAlignedBox3f b = GetBoundingBox(objects[0]);

            for (int i = 1; i < objects.Count; ++i)
            {
                b.Contain(GetBoundingBox(objects[i]));
            }
            return(b);
        }
Esempio n. 9
0
        // knows about our magic invalid value
        public static AxisAlignedBox3f Combine(AxisAlignedBox3f b1, AxisAlignedBox3f b2)
        {
            if (b1 == InvalidBounds)
            {
                return(b2);
            }
            else if (b2 == InvalidBounds)
            {
                return(b1);
            }
            AxisAlignedBox3f r = b1;

            r.Contain(b2);
            return(r);
        }
Esempio n. 10
0
        /// <summary>
        /// Get MeshFilter bounding box of GO. If bIncludeChildren = true, descend
        /// into children and return union of boxes
        /// </summary>
        public static AxisAlignedBox3f GetGeometryBoundingBox(GameObject go, bool bIncludeChildren = false)
        {
            MeshFilter       f = go.GetComponent <MeshFilter>();
            AxisAlignedBox3f b = (f != null) ? (AxisAlignedBox3f)f.mesh.bounds : AxisAlignedBox3f.Empty;

            if (bIncludeChildren && go.HasChildren())
            {
                foreach (GameObject child_go in go.Children())
                {
                    AxisAlignedBox3f child_b = GetGeometryBoundingBox(child_go, true);
                    b.Contain(child_b);
                }
            }

            return(b);
        }
Esempio n. 11
0
        public static Bounds GetLocalBoundingBox(IEnumerable <SceneObject> vObjects)
        {
            int i = 0;
            AxisAlignedBox3f b = AxisAlignedBox3f.Infinite;

            foreach (SceneObject so in vObjects)
            {
                if (i == 0)
                {
                    b = so.GetLocalBoundingBox();
                }
                else
                {
                    b.Contain(so.GetLocalBoundingBox());
                }
            }
            return(b);
        }
Esempio n. 12
0
        public virtual void Create(FScene parentScene, List <SceneObject> targets)
        {
            this.parentScene = parentScene;
            this.targets     = targets;

            root = GameObjectFactory.CreateParentGO("TransformGizmo");

            var xMaterial      = Factory.MakeMaterial(AxisGizmoFlags.AxisTranslateX);
            var xHoverMaterial = Factory.MakeHoverMaterial(AxisGizmoFlags.AxisTranslateX);
            var yMaterial      = Factory.MakeMaterial(AxisGizmoFlags.AxisTranslateY);
            var yHoverMaterial = Factory.MakeHoverMaterial(AxisGizmoFlags.AxisTranslateY);
            var zMaterial      = Factory.MakeMaterial(AxisGizmoFlags.AxisTranslateZ);
            var zHoverMaterial = Factory.MakeHoverMaterial(AxisGizmoFlags.AxisTranslateZ);

            if (Factory.Supports(AxisGizmoFlags.AxisTranslateX))
            {
                translate_x = append_widget(AxisGizmoFlags.AxisTranslateX, 0, "x_translate", xMaterial, xHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.AxisTranslateY))
            {
                translate_y = append_widget(AxisGizmoFlags.AxisTranslateY, 1, "y_translate", yMaterial, yHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.AxisTranslateZ))
            {
                translate_z = append_widget(AxisGizmoFlags.AxisTranslateZ, 2, "z_translate", zMaterial, zHoverMaterial);
            }

            if (Factory.Supports(AxisGizmoFlags.AxisRotateX))
            {
                rotate_x = append_widget(AxisGizmoFlags.AxisRotateX, 0, "x_rotate", xMaterial, xHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.AxisRotateY))
            {
                rotate_y = append_widget(AxisGizmoFlags.AxisRotateY, 1, "y_rotate", yMaterial, yHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.AxisRotateZ))
            {
                rotate_z = append_widget(AxisGizmoFlags.AxisRotateZ, 2, "z_rotate", zMaterial, zHoverMaterial);
            }

            if (Factory.Supports(AxisGizmoFlags.PlaneTranslateX))
            {
                translate_yz = append_widget(AxisGizmoFlags.PlaneTranslateX, 0, "yz_translate", xMaterial, xHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.PlaneTranslateY))
            {
                translate_xz = append_widget(AxisGizmoFlags.PlaneTranslateY, 1, "xz_translate", yMaterial, yHoverMaterial);
            }
            if (Factory.Supports(AxisGizmoFlags.PlaneTranslateZ))
            {
                translate_xy = append_widget(AxisGizmoFlags.PlaneTranslateZ, 2, "xy_translate", zMaterial, zHoverMaterial);
            }

            if (Factory.Supports(AxisGizmoFlags.UniformScale))
            {
                uniform_scale = append_widget(AxisGizmoFlags.UniformScale, 0, "uniform_scale", null, null);
            }

            gizmoGeomBounds = UnityUtil.GetGeometryBoundingBox(root, true);
            gizmoGeomBounds.Contain(Vector3d.Zero);
            initialGizmoRadius = gizmoGeomBounds.MaxDim;
            foreach (var widget in Widgets)
            {
                widget.Value.SetGizmoInitialRadius(initialGizmoRadius);
            }

            // disable shadows on widget components
            foreach (var go in GameObjects)
            {
                MaterialUtil.DisableShadows(go);
            }

            update_active();

            eCurrentFrameMode = FrameType.LocalFrame;
            SetActiveFrame(eCurrentFrameMode);

            SetLayer((GizmoLayer == -1) ? FPlatform.WidgetOverlayLayer : GizmoLayer);

            // seems like possibly this geometry will be shown this frame, before PreRender()
            // is called, which means that on next frame the geometry will pop.
            // So we hide here and show in PreRender
            root.Hide();
        }
Esempio n. 13
0
        public static void SwapUpDirection(FScene scene, List <PrintMeshSO> objects)
        {
            AxisAlignedBox3f sceneBounds  = AxisAlignedBox3f.Empty;
            Vector3f         sharedOrigin = Vector3f.Zero;

            foreach (var meshSO in objects)
            {
                sharedOrigin += meshSO.GetLocalFrame(CoordSpace.SceneCoords).Origin;
                sceneBounds.Contain(meshSO.GetBoundingBox(CoordSpace.SceneCoords).ToAABB());
            }
            sharedOrigin /= objects.Count;

            foreach (var so in objects)
            {
                Frame3f     curF = so.GetLocalFrame(CoordSpace.SceneCoords);
                UpDirection from = so.UpDirection;
                UpDirection to   = (from == UpDirection.YUp) ? UpDirection.ZUp : UpDirection.YUp;

                Quaternionf rotate = Quaternionf.AxisAngleD(Vector3f.AxisX, (to == UpDirection.YUp) ? -90 : 90);
                Frame3f     newF   = curF;
                newF.RotateAround(sharedOrigin, rotate);
                TransformSOChange upChange = new TransformSOChange(so, newF, CoordSpace.SceneCoords)
                {
                    OnApplyF  = (x) => { so.UpDirection = to; },
                    OnRevertF = (x) => { so.UpDirection = from; }
                };
                scene.History.PushChange(upChange, false);
            }

            AxisAlignedBox3f newSceneBounds = AxisAlignedBox3f.Empty;

            foreach (var meshSO in objects)
            {
                newSceneBounds.Contain(meshSO.GetBoundingBox(CoordSpace.SceneCoords).ToAABB());
            }

            Vector3f startBase = sceneBounds.Center; startBase.y = 0;
            Vector3f newBase   = newSceneBounds.Center; newBase.y = newSceneBounds.Min.y;

            Vector3f df = startBase - newBase;

            foreach (var so in objects)
            {
                Frame3f           curF         = so.GetLocalFrame(CoordSpace.SceneCoords);
                Frame3f           newF         = curF.Translated(df);
                TransformSOChange centerChange = new TransformSOChange(so, newF, CoordSpace.SceneCoords);
                scene.History.PushChange(centerChange, false);
            }


            // reposition pivots at base of
            List <Frame3f> setF = new List <Frame3f>();

            foreach (var so in objects)
            {
                Frame3f  objF   = so.GetLocalFrame(CoordSpace.ObjectCoords);
                Vector3f center = so.GetBoundingBox(CoordSpace.SceneCoords).Center;
                center.y = 0;
                Frame3f sceneF = new Frame3f(center);
                setF.Add(sceneF);
            }
            for (int k = 0; k < objects.Count; ++k)
            {
                RepositionPivotChangeOp change = new RepositionPivotChangeOp(setF[k], objects[k], CoordSpace.SceneCoords);
                scene.History.PushChange(change, false);
            }
        }