Esempio n. 1
0
        virtual protected fGameObject append_widget(AxisGizmoFlags widgetType, int nAxis, string name,
                                                    fMaterial material, fMaterial hoverMaterial)
        {
            var useMaterial = (Factory.UniqueColorPerWidget || material == null)
                ? Factory.MakeMaterial(widgetType) : material;
            var useHoverMaterial = (Factory.UniqueColorPerWidget || hoverMaterial == null)
                ? Factory.MakeHoverMaterial(widgetType) : hoverMaterial;
            var go = AppendMeshGO(name, Factory.MakeGeometry(widgetType), useMaterial, RootGameObject, true);

            Standard3DTransformWidget widget = null;

            switch (widgetType)
            {
            case AxisGizmoFlags.AxisTranslateX:
            case AxisGizmoFlags.AxisTranslateY:
            case AxisGizmoFlags.AxisTranslateZ:
                widget = new AxisTranslationWidget(nAxis)
                {
                    RootGameObject    = go, StandardMaterial = useMaterial, HoverMaterial = useHoverMaterial,
                    TranslationScaleF = () => { return(TranslateSpeed / parentScene.GetSceneScale()); }
                };
                break;

            case AxisGizmoFlags.AxisRotateX:
            case AxisGizmoFlags.AxisRotateY:
            case AxisGizmoFlags.AxisRotateZ:
                widget = new AxisRotationWidget(nAxis)
                {
                    RootGameObject   = go, StandardMaterial = useMaterial, HoverMaterial = useHoverMaterial,
                    EnableSnapping   = EnableRotationSnapping,
                    SnapIncrementDeg = RotationSnapStepSizeDeg
                };
                break;

            case AxisGizmoFlags.PlaneTranslateX:
            case AxisGizmoFlags.PlaneTranslateY:
            case AxisGizmoFlags.PlaneTranslateZ:
                widget = new PlaneTranslationWidget(nAxis)
                {
                    RootGameObject    = go, StandardMaterial = useMaterial, HoverMaterial = useHoverMaterial,
                    TranslationScaleF = () => { return(TranslateSpeed / parentScene.GetSceneScale()); }
                };
                break;

            case AxisGizmoFlags.UniformScale:
                widget = new UniformScaleWidget(parentScene.ActiveCamera)
                {
                    RootGameObject   = go, StandardMaterial = useMaterial, HoverMaterial = useHoverMaterial,
                    ScaleMultiplierF = () => { return(ScaleSpeed / parentScene.GetSceneScale()); }
                };
                break;

            default:
                throw new Exception("DefaultAxisGizmoWidgetFactory.MakeHoverMaterial: invalid widget type " + widget.ToString());
            }

            Widgets[go] = widget;
            return(go);
        }
Esempio n. 2
0
        public void Create(Scene parentScene, TransformableSceneObject target)
        {
            this.parentScene = parentScene;
            this.target      = target;

            this.parentScene.SelectionChangedEvent += OnSceneSelectionChanged;

            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);

            x = AppendMeshGO("x_translate",
                             (Mesh)Resources.Load("meshes/transform_gizmo_x", typeof(Mesh)),
                             xMaterial, gizmo);
            Widgets [x] = new AxisTranslationWidget(0, parentScene);
            y           = AppendMeshGO("y_translate",
                                       (Mesh)Resources.Load("meshes/transform_gizmo_y", typeof(Mesh)),
                                       yMaterial, gizmo);
            Widgets [y] = new AxisTranslationWidget(1, parentScene);
            z           = AppendMeshGO("z_translate",
                                       (Mesh)Resources.Load("meshes/transform_gizmo_z", typeof(Mesh)),
                                       zMaterial, gizmo);
            Widgets [z] = new AxisTranslationWidget(2, parentScene);

            rotate_x = AppendMeshGO("x_rotate",
                                    (Mesh)Resources.Load("meshes/axisrotate_x", typeof(Mesh)),
                                    xMaterial, gizmo);
            Widgets [rotate_x] = new AxisRotationWidget(0, parentScene);
            rotate_y           = AppendMeshGO("y_rotate",
                                              (Mesh)Resources.Load("meshes/axisrotate_y", typeof(Mesh)),
                                              yMaterial, gizmo);
            Widgets [rotate_y] = new AxisRotationWidget(1, parentScene);
            rotate_z           = AppendMeshGO("z_rotate",
                                              (Mesh)Resources.Load("meshes/axisrotate_z", typeof(Mesh)),
                                              zMaterial, gizmo);
            Widgets [rotate_z] = new AxisRotationWidget(2, parentScene);


            // plane translation widgets
            translate_xy = AppendMeshGO("xy_translate",
                                        (Mesh)Resources.Load("meshes/plane_translate_xy", typeof(Mesh)),
                                        zMaterial, gizmo);
            Widgets [translate_xy] = new PlaneTranslationWidget(2, parentScene);
            translate_xz           = AppendMeshGO("xz_translate",
                                                  (Mesh)Resources.Load("meshes/plane_translate_xz", typeof(Mesh)),
                                                  yMaterial, gizmo);
            Widgets [translate_xz] = new PlaneTranslationWidget(1, parentScene);
            translate_yz           = AppendMeshGO("yz_translate",
                                                  (Mesh)Resources.Load("meshes/plane_translate_yz", typeof(Mesh)),
                                                  xMaterial, gizmo);
            Widgets [translate_yz] = new PlaneTranslationWidget(0, parentScene);


            // disable shadows on widget components
            foreach (var go in GameObjects)
            {
                go.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            }

            eCurrentFrameMode = FrameType.LocalFrame;
            SetActiveFrame(eCurrentFrameMode);

            int nWidgetLayer = LayerMask.NameToLayer(SceneGraphConfig.WidgetOverlayLayerName);

            foreach (var go in GameObjects)
            {
                go.layer = nWidgetLayer;
            }
        }
        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();
        }