예제 #1
0
        public GOWrapperSO Create(GameObject gameObj)
        {
            fMaterial unityMaterial = gameObj.GetMaterial();

            if (unityMaterial == null)
            {
                AllowMaterialChanges = false;
            }
            else
            {
                SOMaterial setMaterial = new UnitySOMaterial(unityMaterial);
                AssignSOMaterial(setMaterial);
            }

            this.parentGO = gameObj;
            AppendExistingGO(gameObj);

            List <GameObject> children = new List <GameObject>();

            UnityUtil.CollectAllChildren(gameObj, children);
            for (int i = 0; i < children.Count; ++i)
            {
                AppendExistingGO(children[i]);
            }

            return(this);
        }
예제 #2
0
        public virtual void Create()
        {
            rootGO = new GameObject(UniqueNames.GetNext("HUDSlider"));

            fMaterial useMaterial = MaterialUtil.CreateFlatMaterialF(bgColor);

            backgroundGO = GameObjectFactory.CreateRectangleGO("background",
                                                               SliderWidth, SliderHeight, useMaterial, true, true);
            MaterialUtil.DisableShadows(backgroundGO);
            backgroundGO.RotateD(Vector3f.AxisX, -90.0f); // ??
            AppendNewGO(backgroundGO, rootGO, false);

            handleMaterial = MaterialUtil.CreateFlatMaterialF(handleColor);
            handleGO       = create_handle_go(handleMaterial);
            if (handleGO != null)
            {
                handleGO.Translate(0.001f * Vector3f.AxisY, true);
                AppendNewGO(handleGO, rootGO, false);
                handleStart = handleGO.GetLocalFrame();
            }

            create_visuals_geometry();

            TickMaterial = MaterialUtil.CreateFlatMaterialF(tickColor);

            update_geometry();
        }
예제 #3
0
 virtual public void PushOverrideMaterial(fMaterial m)
 {
     vMaterialStack.Add(displayMaterial);
     displayMaterial = m;
     set_material_internal(displayMaterial);
     increment_timestamp();
 }
예제 #4
0
        public virtual PolyCurveSO Create(SOMaterial defaultMaterial)
        {
            if (curve == null)
            {
                LineGenerator gen = new LineGenerator()
                {
                    Start = Vector3f.Zero, End = 10.0f * Vector3f.AxisY, StepSize = 0.1f
                };
                gen.Generate();
                curve = new DCurve3();
                gen.Make(curve);
            }

            // assumes type identifier is something like BlahBlahSO
            root = GameObjectFactory.CreateParentGO(UniqueNames.GetNext(Type.identifier.Remove(Type.identifier.Length - 2)));

            if (EnableLineRenderer)
            {
                LineRenderer ren = root.AddComponent <LineRenderer>();
                ren.startWidth    = ren.endWidth = 0.05f;
                ren.useWorldSpace = false;
            }

            AssignSOMaterial(defaultMaterial);       // need to do this to setup BaseSO material stack
            fMaterial useMaterial = CurrentMaterial;

            Create_internal(useMaterial);

            UpdateGeometry();

            increment_timestamp();

            return(this);
        }
예제 #5
0
 public BaseSO()
 {
     uuid            = System.Guid.NewGuid().ToString();
     displayMaterial = null;
     vMaterialStack  = new List <fMaterial>();
     inputBehaviours = new InputBehaviorSet();
 }
예제 #6
0
        /// <summary>
        /// This is very hacky.
        /// </summary>
        public static void AddDropShadow(HUDStandardItem item, Colorf color, float falloffWidth, Vector2f offset, float fZShift)
        {
            if (item is IBoxModelElement == false)
            {
                throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement");
            }

            // [TODO] need interface that provides a HUDShape?
            var   shape = item as IBoxModelElement;
            float w     = shape.Size2D.x + falloffWidth;
            float h     = shape.Size2D.y + falloffWidth;

            fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false);

            meshGO.RotateD(Vector3f.AxisX, -90.0f);
            fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth);

            meshGO.SetMaterial(dropMat);

            item.AppendNewGO(meshGO, item.RootGameObject, false);
            BoxModel.Translate(meshGO, offset, fZShift);

            Vector3 posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition());

            ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0));
        }
예제 #7
0
        /*
         *  internals
         */


        // selection material handling
        void push_selection_material(SceneObject so)
        {
            if (DisableSelectionMaterial)
            {
                throw new Exception("FScene.push_selection_material: disabled!");
            }

            fMaterial objectMat;

            if (PerObjectSelectionMaterial.TryGetValue(so, out objectMat))
            {
                so.PushOverrideMaterial(objectMat);
                return;
            }
            fMaterial typeMat;

            if (PerTypeSelectionMaterial.TryGetValue(so.Type, out typeMat))
            {
                so.PushOverrideMaterial(typeMat);
                return;
            }
            Func <SceneObject, fMaterial> matMap;

            if (PerTypeSelectionMaterialMap.TryGetValue(so.Type, out matMap))
            {
                fMaterial useMat = matMap(so);
                if (useMat != null)
                {
                    so.PushOverrideMaterial(useMat);
                    return;
                }
            }

            so.PushOverrideMaterial(SelectedMaterial);
        }
예제 #8
0
 override public void PushOverrideMaterial(fMaterial m)
 {
     if (AllowMaterialChanges)
     {
         base.PushOverrideMaterial(m);
     }
 }
예제 #9
0
        public static HUDToggleButton CreateToggleButton(HUDShape shape, float fHUDRadius,
                                                         float fAngleHorz, float fAngleVert,
                                                         string enabledIcon, string disabledIcon,
                                                         IGameObjectGenerator addGeometry = null)
        {
            fMaterial enabledMat  = MaterialUtil.CreateTransparentImageMaterialF(enabledIcon);
            fMaterial disabledMat = MaterialUtil.CreateTransparentImageMaterialF(disabledIcon);

            HUDToggleButton button = new HUDToggleButton()
            {
                Shape = shape
            };

            button.Create(enabledMat);
            if (addGeometry != null)
            {
                button.AddVisualElements(addGeometry.Generate(), true);
            }

            HUDUtil.PlaceInSphere(button, fHUDRadius, fAngleHorz, fAngleVert);
            button.OnToggled += (s, bEnabled) => {
                button.SetAllGOMaterials(bEnabled ? enabledMat : disabledMat);
            };
            return(button);
        }
예제 #10
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);
        }
예제 #11
0
 public override void Setup()
 {
     sphereGO       = GameObjectFactory.CreateMeshGO("sphere", UnityUtil.GetSphereMesh(), false);
     sphereMaterial = MaterialF();
     sphereGO.SetMaterial(sphereMaterial);
     sphereMaterial.color = ColorF();
     MaterialUtil.DisableShadows(sphereGO);
 }
예제 #12
0
 virtual public void PushOverrideMaterial(fMaterial m)
 {
     foreach (var so in vChildren)
     {
         so.PushOverrideMaterial(m);
     }
     increment_timestamp();
 }
예제 #13
0
        public virtual fMaterial MakeHoverMaterial(AxisGizmoFlags widget)
        {
            switch (widget)
            {
            case AxisGizmoFlags.AxisRotateX:
            case AxisGizmoFlags.AxisTranslateX:
            case AxisGizmoFlags.PlaneTranslateX:
                if (XHover == null)
                {
                    XHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoRed);
                    if (OverrideRenderQueue != -1)
                    {
                        XHover.renderQueue = OverrideRenderQueue;
                    }
                }
                return(XHover);

            case AxisGizmoFlags.AxisRotateY:
            case AxisGizmoFlags.AxisTranslateY:
            case AxisGizmoFlags.PlaneTranslateY:
                if (YHover == null)
                {
                    YHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoGreen);
                    if (OverrideRenderQueue != -1)
                    {
                        YHover.renderQueue = OverrideRenderQueue;
                    }
                }
                return(YHover);

            case AxisGizmoFlags.AxisRotateZ:
            case AxisGizmoFlags.AxisTranslateZ:
            case AxisGizmoFlags.PlaneTranslateZ:
                if (ZHover == null)
                {
                    ZHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoBlue);
                    if (OverrideRenderQueue != -1)
                    {
                        ZHover.renderQueue = OverrideRenderQueue;
                    }
                }
                return(ZHover);

            case AxisGizmoFlags.UniformScale:
                if (AllHover == null)
                {
                    AllHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoWhite);
                    if (OverrideRenderQueue != -1)
                    {
                        AllHover.renderQueue = OverrideRenderQueue;
                    }
                }
                return(AllHover);

            default:
                throw new Exception("DefaultAxisGizmoWidgetFactory.MakeHoverMaterial: invalid widget type " + widget.ToString());
            }
        }
예제 #14
0
        public static fDiscGameObject CreateDiscGO(string sName, float fRadius, fMaterial material, bool bShareMaterial, bool bCollider)
        {
            GameObject go       = new GameObject(sName);
            Mesh       discMesh = PrimitiveCache.GetPrimitiveMesh(fPrimitiveType.Disc);

            initialize_meshgo(go, new fMesh(discMesh), bCollider, true);
            go.SetMaterial(material, bShareMaterial);
            return(new fDiscGameObject(go, new fMesh(go.GetSharedMesh()), fRadius));
        }
예제 #15
0
 public override void Setup()
 {
     planeGO       = GameObjectFactory.CreateMeshGO("section_plane", UnityUtil.GetTwoSidedPlaneMesh(), false);
     planeMaterial = MaterialF();
     planeGO.SetMaterial(planeMaterial);
     planeMaterial.color = ColorF();
     MaterialUtil.DisableShadows(planeGO);
     //planeGO.SetLayer(FPlatform.WidgetOverlayLayer);
 }
예제 #16
0
        /// <summary>
        /// Create GO / geometry for a single tick, centered at origin
        /// </summary>
        protected virtual fGameObject create_tick_go(Vector2f tickSize, fMaterial baseMaterial)
        {
            fRectangleGameObject go = GameObjectFactory.CreateRectangleGO("tick", tickSize.x, tickSize.y,
                                                                          baseMaterial, true, false);

            MaterialUtil.DisableShadows(go);
            go.RotateD(Vector3f.AxisX, -90.0f);
            return(go);
        }
예제 #17
0
        /// <summary>
        /// Create the GO that acts as the "handle", ie identifies selected position on timelin
        /// Default is a kind of ugly large triangle underneath midline...
        /// Override to provide your own visuals. Return null for no handle.
        /// </summary>
        protected virtual fGameObject create_handle_go(fMaterial handleMaterial)
        {
            fTriangleGameObject handle = GameObjectFactory.CreateTriangleGO(
                "handle", Height, Height, handleMaterial.color, true);

            MaterialUtil.DisableShadows(handle);
            handle.RotateD(Vector3f.AxisX, -90.0f); // ??
            return(handle);
        }
예제 #18
0
        override protected void set_material_internal(fMaterial m)
        {
            base.set_material_internal(m);

            if (EnableLineRenderer)
            {
                LineRenderer ren = root.GetComponent <LineRenderer>();
                ren.material = m;
            }
        }
예제 #19
0
 public static void SetMaterial(this GameObject go, fMaterial mat, bool bShared = false)
 {
     if (bShared)
     {
         go.GetComponent <Renderer>().sharedMaterial = mat;
     }
     else
     {
         go.GetComponent <Renderer>().material = mat;
     }
 }
예제 #20
0
 virtual public void PopOverrideMaterial()
 {
     if (vMaterialStack.Count > 0)
     {
         fMaterial m = vMaterialStack.Last();
         vMaterialStack.RemoveAt(vMaterialStack.Count - 1);
         displayMaterial = m;
         set_material_internal(displayMaterial);
         increment_timestamp();
     }
 }
예제 #21
0
        // creates a button that is just the mesh
        public void Create(fMesh mesh, fMaterial meshMaterial, float fScale, Quaternionf transform)
        {
            button = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDButton"));

            iconMesh = AppendMeshGO("shape", mesh, meshMaterial, button);
            iconMesh.SetLocalScale(new Vector3f(fScale, fScale, fScale));
            iconMesh.SetLocalRotation(iconMesh.GetLocalRotation() * transform);
            MaterialUtil.DisableShadows(iconMesh);

            standard_mat = new fMaterial(meshMaterial);
        }
예제 #22
0
        /// <summary>
        /// Replace the material on the background GO of item.
        /// Assumes that the background GO has the name "background"...
        /// </summary>
        public static void SetBackgroundMaterial(HUDStandardItem item, fMaterial material, bool bShared = false)
        {
            var go = item.FindGOByName("background");

            if (go == null)
            {
                DebugUtil.Log(2, "HUDUtil.SetBackgroundImage: item {0} does not have go named 'background'", item.Name);
                return;
            }

            go.SetMaterial(material, bShared);
        }
예제 #23
0
 virtual public void Setup()
 {
     brushIndicator = new BrushCursorSphere()
     {
         PositionF = () => { return(lastBrushPosW.Origin); },
         Radius    = fDimension.World(() => { return(radius.WorldValue); })
     };
     primaryBrushMat   = MaterialUtil.CreateTransparentMaterialF(Colorf.CornflowerBlue, 0.2f);
     secondaryBrushMat = MaterialUtil.CreateTransparentMaterialF(Colorf.ForestGreen, 0.2f);
     Indicators.AddIndicator(brushIndicator);
     brushIndicator.material = primaryBrushMat;
 }
예제 #24
0
        // creates a button that is just the mesh
        public void Create(Mesh mesh, Material meshMaterial, float fScale, Quaternion transform)
        {
            button = new GameObject(UniqueNames.GetNext("HUDButton"));

            GameObject meshGO = AppendMeshGO("shape", mesh, meshMaterial, button);

            meshGO.transform.localScale     = new Vector3(fScale, fScale, fScale);
            meshGO.transform.localRotation *= transform;
            MaterialUtil.DisableShadows(meshGO);

            standard_mat = new fMaterial(meshMaterial);
        }
예제 #25
0
        public void Create(SOMaterial useMaterial, GameObject parent, float fMinDimension)
        {
            meshObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            fMaterial mat = MaterialUtil.ToMaterialf(useMaterial);

            meshObject.SetMaterial(mat, true);
            bUpdatePending = true;

            meshObject.transform.SetParent(parent.transform, false);

            Height = Width = Depth = fMinDimension;
        }
예제 #26
0
        public FScene(FContext context)
        {
            this.context = context;

            history       = new ChangeHistory();
            history_stack = new List <ChangeHistory>();
            TypeRegistry  = new SORegistry();

            initialize_scene_root();

            // initialize materials
            DefaultSOMaterial = new SOMaterial()
            {
                Name = "DefaultSO",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = ColorUtil.StandardBeige
            };
            DefaultCurveSOMaterial = new SOMaterial()
            {
                Name = "DefaultCurveSO",
                Type = SOMaterial.MaterialType.UnlitRGBColor, RGBColor = Colorf.DarkSlateGrey
            };
            DefaultMeshSOMaterial = new SOMaterial()
            {
                Name = "DefaultMeshSO",
                Type = SOMaterial.MaterialType.PerVertexColor, RGBColor = Colorf.White
            };
            NewSOMaterial = new SOMaterial()
            {
                Name = "NewSO",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = Colorf.CornflowerBlue
            };
            TransparentNewSOMaterial = new SOMaterial()
            {
                Name = "NewSO",
                Type = SOMaterial.MaterialType.TransparentRGBColor, RGBColor = new Colorf(Colorf.CornflowerBlue, 0.5f)
            };
            PivotSOMaterial = new SOMaterial()
            {
                Name = "PivotSO",
                Type = SOMaterial.MaterialType.TransparentRGBColor, RGBColor = ColorUtil.PivotYellow.SetAlpha(0.75f)
            };
            FrameSOMaterial = new SOMaterial()
            {
                Name = "PivotFrame",
                Type = SOMaterial.MaterialType.StandardRGBColor, RGBColor = ColorUtil.DarkGrey
            };

            SelectedMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold);
            FrameMaterial    = MaterialUtil.CreateStandardMaterial(ColorUtil.DarkGrey);
            PivotMaterial    = MaterialUtil.ToMaterialf(PivotSOMaterial);

            defaultPrimitiveType = SOTypes.Cylinder;
        }
예제 #27
0
        public void Create(fMaterial defaultMaterial)
        {
            button     = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDToggleButton"));
            buttonMesh = AppendMeshGO("disc", make_button_body_mesh(),
                                      defaultMaterial, button);

            buttonMesh.RotateD(Vector3f.AxisX, -90.0f); // ??

            if (text.Length > 0)
            {
                UpdateText();
            }
        }
예제 #28
0
        public void Create(fMaterial defaultMaterial)
        {
            button     = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDToggleButton"));
            buttonMesh = AppendMeshGO("shape", HUDUtil.MakeBackgroundMesh(this.Shape),
                                      defaultMaterial, button);

            buttonMesh.RotateD(Vector3f.AxisX, -90.0f); // ??

            if (text.Length > 0)
            {
                UpdateText();
            }
        }
예제 #29
0
 public virtual void initialize(fGameObject go, fMaterial material, bool bSharedMat)
 {
     r = ((GameObject)go).AddComponent <LineRenderer>();
     r.useWorldSpace = false;
     if (bSharedMat)
     {
         r.sharedMaterial = material;
     }
     else
     {
         r.material = material;
     }
 }
예제 #30
0
        // creates a button that is just the mesh, basically same as above but without the background disc
        public void Create(PrimitiveType eType, Material primMaterial, float fPrimScale = 1.0f)
        {
            button = new GameObject(UniqueNames.GetNext("HUDButton"));

            buttonMesh = AppendUnityPrimitiveGO(UniqueNames.GetNext("HUDButton"), eType, primMaterial, button);
            float primSize = Shape.EffectiveRadius() * fPrimScale;

            buttonMesh.transform.localScale = new Vector3(primSize, primSize, primSize);
            buttonMesh.transform.Translate(0.0f, 0.0f, -primSize);
            buttonMesh.transform.Rotate(-15.0f, 45.0f, 0.0f, Space.Self);
            MaterialUtil.DisableShadows(buttonMesh);

            standard_mat = new fMaterial(primMaterial);
        }