Beispiel #1
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);
        }
Beispiel #2
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();
        }
Beispiel #3
0
 virtual public AxisAlignedBox3f GetLocalBoundingBox()
 {
     // [RMS] is this correct?
     DebugUtil.Log("BaseSO.GetLocalBoundingBox: this bounding box may be incorrect...check this usage");
     return(UnityUtil.GetGeometryBoundingBox(RootGameObject, true));
 }
        public void Create(FScene parentScene, List <TransformableSO> targets)
        {
            this.parentScene = parentScene;
            this.targets     = targets;

            gizmo = new GameObject("TransformGizmo");

            float fAlpha = 0.5f;

            xMaterial        = MaterialUtil.CreateTransparentMaterial(Color.red, fAlpha);
            yMaterial        = MaterialUtil.CreateTransparentMaterial(Color.green, fAlpha);
            zMaterial        = MaterialUtil.CreateTransparentMaterial(Color.blue, fAlpha);
            xHoverMaterial   = MaterialUtil.CreateStandardMaterial(Color.red);
            yHoverMaterial   = MaterialUtil.CreateStandardMaterial(Color.green);
            zHoverMaterial   = MaterialUtil.CreateStandardMaterial(Color.blue);
            allMaterial      = MaterialUtil.CreateTransparentMaterial(Color.white, fAlpha);
            allHoverMaterial = MaterialUtil.CreateStandardMaterial(Color.white);

            x = AppendMeshGO("x_translate",
                             (Mesh)Resources.Load("transform_gizmo/axis_translate_x", typeof(Mesh)),
                             xMaterial, gizmo);
            Widgets[x] = new AxisTranslationWidget(0)
            {
                RootGameObject    = x, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };
            y = AppendMeshGO("y_translate",
                             (Mesh)Resources.Load("transform_gizmo/axis_translate_y", typeof(Mesh)),
                             yMaterial, gizmo);
            Widgets [y] = new AxisTranslationWidget(1)
            {
                RootGameObject    = y, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };
            z = AppendMeshGO("z_translate",
                             (Mesh)Resources.Load("transform_gizmo/axis_translate_z", typeof(Mesh)),
                             zMaterial, gizmo);
            Widgets [z] = new AxisTranslationWidget(2)
            {
                RootGameObject    = z, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };


            rotate_x = AppendMeshGO("x_rotate",
                                    (Mesh)Resources.Load("transform_gizmo/axisrotate_x", typeof(Mesh)),
                                    xMaterial, gizmo);
            Widgets [rotate_x] = new AxisRotationWidget(0)
            {
                RootGameObject = rotate_x, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial
            };
            rotate_y = AppendMeshGO("y_rotate",
                                    (Mesh)Resources.Load("transform_gizmo/axisrotate_y", typeof(Mesh)),
                                    yMaterial, gizmo);
            Widgets [rotate_y] = new AxisRotationWidget(1)
            {
                RootGameObject = rotate_y, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial
            };
            rotate_z = AppendMeshGO("z_rotate",
                                    (Mesh)Resources.Load("transform_gizmo/axisrotate_z", typeof(Mesh)),
                                    zMaterial, gizmo);
            Widgets [rotate_z] = new AxisRotationWidget(2)
            {
                RootGameObject = rotate_z, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial
            };


            // plane translation widgets
            translate_xy = AppendMeshGO("xy_translate",
                                        (Mesh)Resources.Load("transform_gizmo/plane_translate_xy", typeof(Mesh)),
                                        zMaterial, gizmo);
            Widgets [translate_xy] = new PlaneTranslationWidget(2)
            {
                RootGameObject    = translate_xy, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };
            translate_xz = AppendMeshGO("xz_translate",
                                        (Mesh)Resources.Load("transform_gizmo/plane_translate_xz", typeof(Mesh)),
                                        yMaterial, gizmo);
            Widgets [translate_xz] = new PlaneTranslationWidget(1)
            {
                RootGameObject    = translate_xz, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };
            translate_yz = AppendMeshGO("yz_translate",
                                        (Mesh)Resources.Load("transform_gizmo/plane_translate_yz", typeof(Mesh)),
                                        xMaterial, gizmo);
            Widgets [translate_yz] = new PlaneTranslationWidget(0)
            {
                RootGameObject    = translate_yz, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial,
                TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };


            uniform_scale = AppendMeshGO("uniform_scale",
                                         Resources.Load <Mesh>("transform_gizmo/uniform_scale"), allMaterial, gizmo);
            Widgets[uniform_scale] = new UniformScaleWidget(parentScene.ActiveCamera)
            {
                RootGameObject   = uniform_scale, StandardMaterial = allMaterial, HoverMaterial = allHoverMaterial,
                ScaleMultiplierF = () => { return(1.0f / parentScene.GetSceneScale()); }
            };

            gizmoGeomBounds = UnityUtil.GetGeometryBoundingBox(new List <GameObject>()
            {
                x, y, z, rotate_x, rotate_y, rotate_z, translate_xy, translate_xz, translate_yz, uniform_scale
            });

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

            eCurrentFrameMode = FrameType.LocalFrame;
            SetActiveFrame(eCurrentFrameMode);

            SetLayer(FPlatform.WidgetOverlayLayer);

            // 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
            gizmo.Hide();
        }