Esempio n. 1
0
        void initialize_scene_root()
        {
            vObjects       = new List <SceneObject>();
            vSelected      = new List <SceneObject>();
            vUIElements    = new List <SceneUIElement>();
            vBoundsObjects = new List <fGameObject>();
            ObjectAnimator = new GenericAnimator();
            LinkManager    = new SOLinkManager(this);
            vDeleted       = new List <SceneObject>();

            sceneRoot = GameObjectFactory.CreateParentGO("Scene");
            // for animation playbacks
            sceneRoot.AddComponent <UnityPerFrameAnimationBehavior>().Animator = ObjectAnimator;

            transient_objects = GameObjectFactory.CreateParentGO("transient");
            sceneRoot.AddChild(transient_objects, false);

            lighting_objects = GameObjectFactory.CreateParentGO("lighting_objects");
            sceneRoot.AddChild(lighting_objects, false);

            bounds_objects = GameObjectFactory.CreateParentGO("bounds_objects");
            sceneRoot.AddChild(bounds_objects, false);

            scene_objects = GameObjectFactory.CreateParentGO("scene_objects");
            sceneRoot.AddChild(scene_objects, false);

            deleted_objects = GameObjectFactory.CreateParentGO("deleted_objects");
            sceneRoot.AddChild(deleted_objects, false);
        }
Esempio n. 2
0
        public virtual PivotSO Create(SOMaterial shapeMaterial, SOMaterial frameMaterial = null, int nShapeLayer = -1)
        {
            // [TODO] replace frame geometry with line renderer ?
            // [TODO] still cast shadows  (semitransparent objects don't cast shadows, apparently)
            // [TODO] maybe render solid when not obscured by objects? use raycast in PreRender?

            AssignSOMaterial(shapeMaterial);       // need to do this to setup BaseSO material stack

            pivotGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("Pivot"));

            shapeGO = create_pivot_shape();
            AppendNewGO(shapeGO, pivotGO, false);

            pivotGO.AddChild(shapeGO);

            if (frameMaterial != null)
            {
                this.frameMaterial = frameMaterial;

                frameGO = UnityUtil.CreateMeshGO("pivotFrame", "icon_meshes/axis_frame", 1.0f,
                                                 UnityUtil.MeshAlignOption.NoAlignment, MaterialUtil.ToUnityMaterial(frameMaterial), false);
                MaterialUtil.SetIgnoreMaterialChanges(frameGO);
                MaterialUtil.DisableShadows(frameGO);
                AppendNewGO(frameGO, pivotGO, false);
            }

            if (nShapeLayer >= 0)
            {
                shapeGO.SetLayer(nShapeLayer);
            }

            increment_timestamp();
            return(this);
        }
Esempio n. 3
0
        // remove SO from scene.
        // bDestroy means that SO is actually deleted, otherwise just added
        // to internal Deleted set, so it can be recovered by undo.
        public void RemoveSceneObject(SceneObject so, bool bDestroy)
        {
            DebugUtil.Log(1, "[Scene.AddSceneObject] removing {0} (destroy: {1})", so.Name, bDestroy);

            if (vSelected.Contains(so))
            {
                Deselect(so);
            }
            vObjects.Remove(so);
            OnSceneChanged(so, SceneChangeType.Removed);

            if (so.RootGameObject != null)
            {
                if (bDestroy)
                {
                    SceneUtil.DestroySO(so);
                }
                else
                {
                    // add to deleted set
                    vDeleted.Add(so);
                    deleted_objects.AddChild(so.RootGameObject, true);
                    so.RootGameObject.SetVisible(false);
                }
            }
        }
Esempio n. 4
0
        // called by FContext.PushCockpit()
        public void Start(ICockpitInitializer setup)
        {
            // create invisible plane for cockpit
            gameobject = GameObjectFactory.CreateParentGO("cockpit");

            onCameraGO = GameObjectFactory.CreateParentGO("cockpit_camera");
            gameobject.AddChild(onCameraGO, false);

            // add hud animation controller
            gameobject.AddComponent <UnityPerFrameAnimationBehavior>().Animator = HUDAnimator;

            // create HUD
            try {
                setup.Initialize(this);
            } catch (Exception e) {
                // if hud setup fails we still want to keep going
                DebugUtil.Log(2, "[Cockpit.Start] exception in initializer: {0}\nTrace:\n{1}", e.Message, e.StackTrace);
                if (FPlatform.InUnityEditor())
                {
                    throw;
                }
            }

            // position in front of camera
            UpdateTracking(true);
        }
Esempio n. 5
0
        // called by FContext.PushCockpit()
        public void Start(ICockpitInitializer setup)
        {
            // create invisible plane for cockpit
            gameobject = GameObjectFactory.CreateParentGO("cockpit");

            onCameraGO = GameObjectFactory.CreateParentGO("cockpit_camera");
            gameobject.AddChild(onCameraGO, false);

            // [RMS] probably can delete this code now?
            //gameobject = GameObject.CreatePrimitive (PrimitiveType.Plane);
            //gameobject.SetName("cockpit");
            //MeshRenderer ren = gameobject.GetComponent<MeshRenderer> ();
            //ren.enabled = false;
            //gameobject.GetComponent<MeshCollider> ().enabled = false;

            // add hud animation controller
            gameobject.AddComponent <UnityPerFrameAnimationBehavior>().Animator = HUDAnimator;

            // create HUD
            try {
                setup.Initialize(this);
            } catch (Exception e) {
                DebugUtil.Log(2, "[Cockpit.Start] exception in initializer: {0}\nTrace:\n{1}", e.Message,
                              e.StackTrace);
                // if hud setup fails we still want to keep going
            }

            // position in front of camera
            UpdateTracking(true);
        }
Esempio n. 6
0
        // [RMS] management of Panel children. Currently we do not use Panel
        //   directly, so these are not publicly accessible. I don't entirely like this.
        //   However, C# does not allow us to "hide" a public member in a subclass,
        //   which means that Panel implementations would directly expose these, when
        //   in most cases they should not be exposed...

        protected virtual void AddChild(SceneUIElement ui, bool bKeepWorldPosition = true)
        {
            if (!Children.Contains(ui))
            {
                Children.Add(ui);
                ui.Parent = this;
                ui.SetLayer(this.Layer);
                gameObject.AddChild(ui.RootGameObject, bKeepWorldPosition);
            }
        }
Esempio n. 7
0
 public void RestoreDeletedSceneObject(SceneObject so)
 {
     if (vDeleted.Find((x) => x == so) == null)
     {
         return;
     }
     vDeleted.Remove(so);
     vObjects.Add(so);
     so.RootGameObject.SetVisible(true);
     scene_objects.AddChild(so.RootGameObject, true);
     so.SetCurrentTime(currentTime);
 }
Esempio n. 8
0
        public void RemoveAllUIElements(bool bDiscardTransientObjects = true)
        {
            while (vUIElements.Count > 0)
            {
                RemoveUIElement(vUIElements[0], true);
            }

            // discard any transient objects we have floating around
            if (bDiscardTransientObjects)
            {
                transient_objects.Destroy();
                transient_objects = GameObjectFactory.CreateParentGO("transient");
                sceneRoot.AddChild(transient_objects, false);
            }
        }
Esempio n. 9
0
        public virtual fMeshGameObject AppendMeshGO(string name, fMesh mesh, fMaterial setMaterial, fGameObject parent, bool bCollider = true)
        {
            fMeshGameObject go = new fMeshGameObject(mesh, true, bCollider);

            go.EnableCollisions = false;
            go.SetMaterial(setMaterial);
            go.SetName(name);

            vObjects.Add(go);

            parent.AddChild(go);
            go.SetLayer(parent.GetLayer());

            return(go);
        }
Esempio n. 10
0
 public HUDPanel()
 {
     Children = new HUDChildren(this)
     {
         OnChildAdded = (elem, bKeepWorldPosition) => {
             elem.SetLayer(this.Layer);
             parent.AddChild(elem.RootGameObject, bKeepWorldPosition);
         },
         OnChildRemoved = (elem) => {
             ;
         }
     };
     width   = 1;
     height  = 1;
     padding = 0;
 }
Esempio n. 11
0
        void InitOnMainThread(fGameObject parentGO)
        {
            LineGO = GameObjectFactory.CreateLineGO(NameF(), ColorF(), LineWidthF(), LineWidthType.World);
            LineGO.SetStart(StartF());
            LineGO.SetEnd(EndF());
            if (parentGO != null)
            {
                parentGO.AddChild(LineGO, false);
            }

            LineGO.GetComponent <PreRenderBehavior>().AddAction(() => { Update(); });

            if (OnCreateF != null)
            {
                OnCreateF(LineGO);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Utility to add SO geometry to a parent GO, which would then be passed to Create()
        /// </summary>
        public static void AppendSOGeometry(fGameObject parentGO, SceneObject so, bool bAddMeshColliders)
        {
            fGameObject copy = GameObjectFactory.Duplicate(so.RootGameObject);

            // if so is a DMeshSO, and it doesn't have a collider, add it
            if (so is DMeshSO && bAddMeshColliders)
            {
                foreach (var go in copy.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }

            parentGO.AddChild(copy, true);
        }
Esempio n. 13
0
        public void Create(SOMaterial useMaterial, fGameObject parent, int nLayer = -1)
        {
            if (curve == null)
            {
                curve = new DCurve3()
                {
                    Closed = closed
                }
            }
            ;

            curveObject = GameObjectFactory.CreatePolylineGO("preview_curve", null, useMaterial.RGBColor, 0.05f, LineWidthType.World);
            if (nLayer >= 0)
            {
                curveObject.SetLayer(nLayer);
            }

            bUpdatePending = true;

            parent.AddChild(curveObject, false);
        }
Esempio n. 14
0
        public FScene(FContext context)
        {
            this.context = context;

            history      = new ChangeHistory();
            TypeRegistry = new SORegistry();

            vObjects       = new List <SceneObject>();
            vSelected      = new List <SceneObject>();
            vUIElements    = new List <SceneUIElement>();
            vBoundsObjects = new List <fGameObject>();
            ObjectAnimator = new GenericAnimator();
            LinkManager    = new SOLinkManager(this);

            sceneRoot = GameObjectFactory.CreateParentGO("Scene");
            // for animation playbacks
            sceneRoot.AddComponent <SceneAnimator>().Scene = this;
            sceneRoot.AddComponent <UnityPerFrameAnimationBehavior>().Animator = ObjectAnimator;

            scene_objects = GameObjectFactory.CreateParentGO("scene_objects");
            sceneRoot.AddChild(scene_objects, false);

            deleted_objects = GameObjectFactory.CreateParentGO("deleted_objects");
            sceneRoot.AddChild(deleted_objects, false);
            vDeleted = new List <SceneObject>();

            // 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.ToUnityMaterial(PivotSOMaterial);

            defaultPrimitiveType = SOTypes.Cylinder;
        }
Esempio n. 15
0
        public static GOWrapperSO CombineAnySOs(SceneObject s1, SceneObject s2, bool bDeleteExisting = true)
        {
            FScene scene = s1.GetScene();

            if (scene.IsSelected(s1))
            {
                scene.Deselect(s1);
            }
            if (scene.IsSelected(s2))
            {
                scene.Deselect(s2);
            }

            fGameObject parentGO = GameObjectFactory.CreateParentGO("combined");

            fGameObject copy1 = GameObjectFactory.Duplicate(s1.RootGameObject);
            fGameObject copy2 = GameObjectFactory.Duplicate(s2.RootGameObject);


            // if inputs are DMeshSOs, they do not have colliders, which we will need...
            if (s1 is DMeshSO)
            {
                foreach (var go in copy1.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }
            if (s2 is DMeshSO)
            {
                foreach (var go in copy2.Children())
                {
                    if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null)
                    {
                        go.AddComponent <MeshCollider>();
                    }
                }
            }

            parentGO.AddChild(copy1, true);
            parentGO.AddChild(copy2, true);

            GOWrapperSO wrapperSO = new GOWrapperSO()
            {
                AllowMaterialChanges = false
            };

            wrapperSO.Create(parentGO);

            if (bDeleteExisting)
            {
                scene.RemoveSceneObject(s1, false);
                scene.RemoveSceneObject(s2, false);
            }

            scene.AddSceneObject(wrapperSO, false);

            return(wrapperSO);
        }