示例#1
0
        /// <summary>
        /// Updates the contents of the prefab with the contents of the provided prefab instance. If the provided object
        /// is not a prefab instance nothing happens.
        /// </summary>
        /// <param name="obj">Prefab instance whose prefab to update.</param>
        /// <param name="refreshScene">If true, all prefab instances in the current scene will be updated so they consistent
        ///                            with the newly saved data.</param>
        public static void ApplyPrefab(SceneObject obj, bool refreshScene = true)
        {
            if (obj == null)
                return;

            SceneObject prefabInstanceRoot = GetPrefabParent(obj);
            if (prefabInstanceRoot == null)
                return;

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                    Internal_RecordPrefabDiff(root.GetCachedPtr());
            }

            string prefabUUID = GetPrefabUUID(prefabInstanceRoot);
            string prefabPath = ProjectLibrary.GetPath(prefabUUID);
            Prefab prefab = ProjectLibrary.Load<Prefab>(prefabPath);
            if (prefab != null)
            {
                IntPtr soPtr = prefabInstanceRoot.GetCachedPtr();
                IntPtr prefabPtr = prefab.GetCachedPtr();

                Internal_ApplyPrefab(soPtr, prefabPtr);
                ProjectLibrary.Save(prefab);
            }

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                    Internal_UpdateFromPrefab(root.GetCachedPtr());
            }
        }
        public Objekte(SceneObject Objekt, int Lebenspunkte, String Material)
        {
            objekt = Objekt;
            lebenspunkte = Lebenspunkte;

            setMaterial(Material);
        }
示例#3
0
        /// <summary>
        /// Creates new a scene object by cloning an existing object.
        /// </summary>
        /// <param name="so">Scene object to clone.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        /// <returns>Cloned scene object.</returns>
        public static SceneObject CloneSO(SceneObject so, string description = "")
        {
            if (so != null)
                return Internal_CloneSO(so.GetCachedPtr(), description);

            return null;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="WhatPumpkin.SceneInfo"/> class.
		/// I'm using this constructor primarily for receiving save/load data.
		/// </summary>
		/// <param name="key">Key.</param>
		/// <param name="sceneObjects">Scene objects.</param>
		/*
		public SceneInfo(string key, IEnumerable sceneObjects) {
				
			_key = key;

		}*/

		/// <summary>
		/// Initializes a new instance of the <see cref="WhatPumpkin.SceneInfo"/> class.
		/// </summary>
		/// <param name="key">Key.</param>

		public SceneInfo(string key) {
		
			_key = key;

			// TODO: Abstract this data

			foreach (Entity entity in  GameObject.FindObjectsOfType<Entity>()) {
				
				
							ISceneObject<string> item = (ISceneObject<string>)entity;
				
							if (item != null) {
									try {
						
											SceneObject sceneObject = new SceneObject ();

											_sceneObjects.Add (sceneObject);

											sceneObject.ReceiveData(item);
									} catch (System.Exception e) {
											Debug.LogException(e);
									}
							}

			}
		}
示例#5
0
 /// <summary>
 ///   Creates a new instance of the InstanceEntity
 /// </summary>
 /// <param name = "name">The name of the instance</param>
 /// <param name = "index">The index used in the SceneObject.SkinBones array</param>
 /// <param name = "sceneObject">The SceneObject this instance pertains to</param>
 /// <param name = "transform">The matrix used to place the instance in the world</param>
 protected internal InstanceEntity(string name, int index, SceneObject sceneObject, Matrix transform)
     : base(name, false)
 {
     Index = index;
     Parent = sceneObject;
     World = transform;
 }
        /// <summary>
        /// Records the current state of the provided scene object.
        /// </summary>
        /// <param name="so">Scene object to record the state for.</param>
        /// <param name="hierarchy">If true, state will be recorded for the scene object and all of its children. Otherwise
        ///                         the state will only be recorded for the provided scene object.</param>
        public SerializedSceneObject(SceneObject so, bool hierarchy)
        {
            IntPtr soPtr = IntPtr.Zero;
            if (so != null)
                soPtr = so.GetCachedPtr();

            Internal_CreateInstance(this, soPtr, hierarchy);
        }
示例#7
0
        /// <summary>
        /// Breaks the link between a prefab instance and its prefab. Object will retain all current values but will
        /// no longer be influenced by modifications to its parent prefab.
        /// </summary>
        /// <param name="obj">Prefab instance whose link to break.</param>
        public static void BreakPrefab(SceneObject obj)
        {
            if (obj == null)
                return;

            IntPtr objPtr = obj.GetCachedPtr();
            Internal_BreakPrefab(objPtr);
        }
示例#8
0
        /// <summary>
        /// Returns the root object of the prefab instance that this object belongs to, if any. 
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab parent for.</param>
        /// <returns>Prefab parent of the provided object, or null if the object is not part of a prefab instance.</returns>
        public static SceneObject GetPrefabParent(SceneObject obj)
        {
            if (obj == null)
                return null;

            IntPtr objPtr = obj.GetCachedPtr();
            return Internal_GetPrefabParent(objPtr);
        }
示例#9
0
        /// <summary>
        /// Checks if a scene object has a prefab link. Scene objects with a prefab link will be automatically updated
        /// when their prefab changes in order to reflect its changes.
        /// </summary>
        /// <param name="obj">Scene object to check if it has a prefab link.</param>
        /// <returns>True if the object is a prefab instance (has a prefab link), false otherwise.</returns>
        public static bool IsPrefabInstance(SceneObject obj)
        {
            if (obj == null)
                return false;

            IntPtr objPtr = obj.GetCachedPtr();
            return Internal_HasPrefabLink(objPtr);
        }
示例#10
0
        public NativeRenderable(SceneObject sceneObject)
        {
            IntPtr sceneObjPtr = IntPtr.Zero;
            if (sceneObject != null)
                sceneObjPtr = sceneObject.GetCachedPtr();

            Internal_Create(this, sceneObjPtr);
        }
示例#11
0
        public NativeRigidbody(SceneObject linkedSO)
        {
            IntPtr linkedSOPtr = IntPtr.Zero;
            if (linkedSO != null)
                linkedSOPtr = linkedSO.GetCachedPtr();

            Internal_CreateInstance(this, linkedSOPtr);
        }
示例#12
0
 private void Form_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(
             new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
             CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         var rotator = new SatelliteManipulater();
         rotator.Bind(camera, this.glCanvas1);
         this.scene = new Scene(camera, this.glCanvas1);
         this.scene.RootViewPort.ClearColor = Color.SkyBlue;
         this.glCanvas1.Resize += this.scene.Resize;
     }
     {
         const int gridsPer2Unit = 20;
         const int scale = 2;
         var ground = GroundRenderer.Create(new GroundModel(gridsPer2Unit * scale));
         ground.Scale = new vec3(scale, scale, scale);
         var obj = new SceneObject();
         obj.Renderer = ground;
         this.scene.RootObject.Children.Add(obj);
     }
     {
         SimpleRenderer movableRenderer = SimpleRenderer.Create(new Teapot());
         movableRenderer.RotationAxis = new vec3(0, 1, 0);
         movableRenderer.Scale = new vec3(0.1f, 0.1f, 0.1f);
         this.movableRenderer = movableRenderer;
         SceneObject obj = movableRenderer.WrapToSceneObject();
         this.scene.RootObject.Children.Add(obj);
     }
     {
         BillboardRenderer billboardRenderer = BillboardRenderer.Create(new BillboardModel());
         SceneObject obj = billboardRenderer.WrapToSceneObject(new UpdateBillboardPosition(movableRenderer));
         this.scene.RootObject.Children.Add(obj);
     }
     {
         LabelRenderer labelRenderer = LabelRenderer.Create();
         labelRenderer.Text = "Teapot - CSharpGL";
         SceneObject obj = labelRenderer.WrapToSceneObject(new UpdateLabelPosition(movableRenderer));
         this.scene.RootObject.Children.Add(obj);
     }
     {
         var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
             new Padding(3, 3, 3, 3), new Size(128, 128));
         this.scene.RootUI.Children.Add(uiAxis);
     }
     {
         var frmPropertyGrid = new FormProperyGrid(this.scene);
         frmPropertyGrid.Show();
     }
     {
         var frmPropertyGrid = new FormProperyGrid(this.glCanvas1);
         frmPropertyGrid.Show();
     }
     {
         this.scene.Start();
     }
 }
 public override void Initialize()
 {
     base.Initialize();
     this.SO = new SceneObject(((ReadOnlyCollection<ModelMesh>)ResourceManager.GetModel("Model/SpaceObjects/planet_" + (object)this.moonType).Meshes)[0]);
     this.SO.ObjectType = ObjectType.Static;
     this.SO.Visibility = ObjectVisibility.Rendered;
     this.WorldMatrix = ((Matrix.Identity * Matrix.CreateScale(this.scale)) * Matrix.CreateTranslation(new Vector3(this.Position, 2500f)));
     this.SO.World = this.WorldMatrix;
     base.Radius = this.SO.ObjectBoundingSphere.Radius * this.scale * 0.65f;
 }
	public void delWatcher(SceneObject obj)
	{
		for(int i=0; i<watcherobjs.Count; i++)
		{
			if(watcherobjs[i] == obj){
				watcherobjs.RemoveAt(i);
				return;
			}
		}
	}
示例#15
0
		public Scene(Window window)
		{
			this.window = window;

			eventManager = new EventManager(this);

			SetupEventSystems();

			rootSceneObject = new SceneObject("Root", this);
		}
示例#16
0
 public static void ProjectCylindric(SceneObject obj)
 {
     obj.rebuild();
     Vector min = obj.Min();
     Vector max = obj.Max();
     float dz = 1 / (max.Z - min.Z);
     for (int i = 0; i < obj.vertices; i++)
     {
         obj.vertex[i].pos.BuildCylindric();
         obj.vertex[i].Tu = obj.vertex[i].pos.Theta / (2 * 3.14159265f);
         obj.vertex[i].Tv = (obj.vertex[i].pos.Z - min.Z) * dz;
     }
 }
示例#17
0
 public static void ProjectTop(SceneObject obj)
 {
     obj.rebuild();
     Vector min = obj.Min();
     Vector max = obj.Max();
     float du = 1 / (max.X - min.X);
     float dv = 1 / (max.Z - min.Z);
     for (int i = 0; i < obj.vertices; i++)
     {
         obj.vertex[i].Tu = (obj.vertex[i].pos.X - min.X) * du;
         obj.vertex[i].Tv = (obj.vertex[i].pos.Z - min.Z) * dv;
     }
 }
示例#18
0
        /// <summary>
        /// Creates new scene object(s) by cloning existing objects.
        /// </summary>
        /// <param name="so">Scene object(s) to clone.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        /// <returns>Cloned scene objects.</returns>
        public static SceneObject[] CloneSO(SceneObject[] so, string description = "")
        {
            if (so != null)
            {
                List<IntPtr> soPtrs = new List<IntPtr>();
                for (int i = 0; i < so.Length; i++)
                {
                    if(so[i] != null)
                        soPtrs.Add(so[i].GetCachedPtr());
                }

                return Internal_CloneSOMulti(soPtrs.ToArray(), description);
            }

            return new SceneObject[0];
        }
        /// <summary>
        /// Creates a new GUIFieldSelector and registers its GUI elements in the provided layout.
        /// </summary>
        /// <param name="layout">Layout into which to add the selector GUI hierarchy.</param>
        /// <param name="so">Scene object to inspect the fields for.</param>
        /// <param name="width">Width of the selector area, in pixels.</param>
        /// <param name="height">Height of the selector area, in pixels.</param>
        public GUIFieldSelector(GUILayout layout, SceneObject so, int width, int height)
        {
            rootSO = so;

            scrollArea = new GUIScrollArea();
            scrollArea.SetWidth(width);
            scrollArea.SetHeight(height);

            layout.AddElement(scrollArea);

            GUISkin skin = EditorBuiltin.GUISkin;
            GUIElementStyle style = skin.GetStyle(EditorStyles.Expand);
            foldoutWidth = style.Width;

            Rebuild();
        }
 public override void Initialize()
 {
     base.Initialize();
     this.AsteroidSO = new SceneObject(Ship_Game.ResourceManager.GetModel(string.Concat("Model/Asteroids/asteroid", this.whichRoid)).Meshes[0])
     {
         ObjectType = ObjectType.Static,
         Visibility = ObjectVisibility.Rendered
     };
     this.WorldMatrix = ((((Matrix.Identity * Matrix.CreateScale(this.scale)) * Matrix.CreateRotationX(this.Xrotate)) * Matrix.CreateRotationY(this.Yrotate)) * Matrix.CreateRotationZ(this.Zrotate)) * Matrix.CreateTranslation(this.Position3D);
     this.AsteroidSO.World = this.WorldMatrix;
     base.Radius = this.AsteroidSO.ObjectBoundingSphere.Radius * this.scale * 0.65f;
     int radius = (int)base.Radius / 5;
     base.Position = new Vector2(this.Position3D.X, this.Position3D.Y);
     this.Position3D.X = base.Position.X;
     this.Position3D.Y = base.Position.Y;
     this.Center = base.Position;
 }
示例#21
0
        /// <summary>
        /// Converts a hierarchy of scene objects and their children into a flat array. Doesn't modify the scene object's
        /// themselves. 
        /// </summary>
        /// <param name="so">Scene object whose hierarchy to flatten.</param>
        /// <returns>Array of flattened hierarchy in a depth-first manner.</returns>
        public static SceneObject[] FlattenHierarchy(SceneObject so)
        {
            Stack<SceneObject> todo = new Stack<SceneObject>();
            todo.Push(so);

            List<SceneObject> flattenedHierarchy = new List<SceneObject>();
            while (todo.Count > 0)
            {
                SceneObject cur = todo.Pop();
                flattenedHierarchy.Add(cur);

                int numChildren = cur.GetNumChildren();
                for (int i = 0; i < numChildren; i++)
                    todo.Push(cur.GetChild(i));
            }

            return flattenedHierarchy.ToArray();
        }
示例#22
0
        public UpdateImageScript(Control canvas, SceneObject obj = null)
            : base(obj)
        {
            this.canvas = canvas;

            if (this.openTextureDlg == null)
            {
                {
                    var openTextureDlg = new OpenFileDialog();
                    openTextureDlg.Filter = "Image File(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG";
                    this.openTextureDlg = openTextureDlg;
                }
                {
                    this.keyPress = this.glCanvas1_KeyPress;
                    this.canvas.KeyPress += this.keyPress;
                }
            }
        }
        public void TestSceneGraph( )
        {
            Scene scene = new Scene( );

            SceneObject subTree = new SceneObject( new SceneObject( ), new SceneObject( ) );

            SceneObject root =
                new SceneObject
                (
                    new SceneObject( ),
                    subTree,
                    new SceneObject( )
                );

            scene.Objects.Add( root );
            root.CheckAddCount( 1 );

            root.RemoveChild( subTree );
            subTree.CheckAddCount( 0 );
        }
示例#24
0
        /// <summary>
        /// Creates a new scene axes GUI.
        /// </summary>
        /// <param name="window">Window in which the GUI is located in.</param>
        /// <param name="panel">Panel onto which to place the GUI element.</param>
        /// <param name="width">Width of the GUI element.</param>
        /// <param name="height">Height of the GUI element.</param>
        /// <param name="projType">Projection type to display on the GUI.</param>
        public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType)
        {
            renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height);
            renderTexture.Priority = 1;

            SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);
            camera = cameraSO.AddComponent<Camera>();
            camera.Target = renderTexture;
            camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

            cameraSO.Position = new Vector3(0, 0, 5);
            cameraSO.LookAt(new Vector3(0, 0, 0));

            camera.Priority = 2;
            camera.NearClipPlane = 0.05f;
            camera.FarClipPlane = 1000.0f;
            camera.ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
            camera.ProjectionType = ProjectionType.Orthographic;
            camera.Layers = SceneAxesHandle.LAYER;
            camera.AspectRatio = 1.0f;
            camera.OrthoHeight = 2.0f;
            camera.HDR = false;

            renderTextureGUI = new GUIRenderTexture(renderTexture, true);

            GUILayoutY layout = panel.AddLayoutY();
            GUILayoutX textureLayout = layout.AddLayoutX();
            textureLayout.AddElement(renderTextureGUI);
            textureLayout.AddFlexibleSpace();

            Rect2I bounds = new Rect2I(0, 0, width, height);
            sceneHandles = new SceneHandles(window, camera);
            renderTextureGUI.Bounds = bounds;

            labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered);
            layout.AddElement(labelGUI);
            layout.AddFlexibleSpace();

            this.panel = panel;
            this.bounds = bounds;
        }
示例#25
0
        /// <summary>
        /// Gets a <see cref="SceneObject"/> that contains this renderer.
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="name"></param>
        /// <param name="generateBoundingBox"></param>
        /// <param name="scripts"></param>
        /// <returns></returns>
        public static SceneObject WrapToSceneObject(
            this RendererBase renderer,
            string name,
            bool generateBoundingBox,
            params Script[] scripts)
        {
            var obj = new SceneObject();
            obj.Renderer = renderer;
            obj.Name = name;
            obj.Scripts.AddRange(scripts);
            if (generateBoundingBox)
            {
                BoundingBoxRenderer box = renderer.GetBoundingBoxRenderer();
                var boxObj = new SceneObject();
                boxObj.Renderer = box;
                boxObj.Name = string.Format("Box of [{0}]", name);
                obj.Children.Add(boxObj);
            }

            return obj;
        }
示例#26
0
		private void OnWindowLoad()
		{
			mainScene = new Scene(window);
			uiScene = new Scene(window);

			SceneObject cameraObject = new SceneObject("CameraObject", mainScene);
			cameraObject.AddModule<Camera>();
			cameraObject.AddModule<OrbitCamera>();

			PolyMesh polyMesh = new PolyMesh();
			polyMesh.geometry.Vertices.Add(-1, 0, 0);
			polyMesh.geometry.Vertices.Add(-1, 0, 2);
			polyMesh.geometry.Vertices.Add(1, 0, 2);
			polyMesh.geometry.Vertices.Add(1, 0, 0);

			polyMesh.geometry.Faces.AddFace(0, 1, 2, 3);

			PolyObject polyObject = new SceneObject("PolyObject", mainScene).AddModule<PolyObject>();
			polyObject.polyMesh = polyMesh;
			polyObject.UpdateMesh();
			polyObject.transform.localScale = Vector3.One*3;
		}
        public void LoadContent(Ship_Game.ScreenManager ScreenManager)
        {
            Model InnerModel = ScreenManager.Content.Load<Model>("Model/Stations/spacestation01_inner");
            Model OuterModel = ScreenManager.Content.Load<Model>("Model/Stations/spacestation01_outer");

            ModelMesh mesh = InnerModel.Meshes[0];
            this.InnerSO = new SceneObject(mesh)
            {
                ObjectType = ObjectType.Dynamic,
                World = Matrix.Identity
            };

            ModelMesh mesh1 = OuterModel.Meshes[0];
            this.OuterSO = new SceneObject(mesh1)
            {
                ObjectType = ObjectType.Dynamic,
                World = Matrix.Identity
            };

            this.Position = this.planet.Position;

            //The Doctor: Mod definable spaceport 'station' art scaling
            float scale = 0.8f;
            if (GlobalStats.ActiveMod != null)
            {
                scale = GlobalStats.ActiveModInfo.Spaceportscale;
            }

            if (this.InnerSO != null && this.OuterSO != null)
            {
                this.InnerSO.World = (((((Matrix.Identity * Matrix.CreateScale(scale)) * Matrix.CreateRotationZ(1.57079637f)) * Matrix.CreateRotationX(MathHelper.ToRadians(20f))) * Matrix.CreateRotationY(MathHelper.ToRadians(65f))) * Matrix.CreateRotationZ(1.57079637f)) * Matrix.CreateTranslation(this.Position.X, this.Position.Y, 600f);
                this.OuterSO.World = (((((Matrix.Identity * Matrix.CreateScale(scale)) * Matrix.CreateRotationZ(1.57079637f)) * Matrix.CreateRotationX(MathHelper.ToRadians(20f))) * Matrix.CreateRotationY(MathHelper.ToRadians(65f))) * Matrix.CreateRotationZ(1.57079637f)) * Matrix.CreateTranslation(this.Position.X, this.Position.Y, 600f);
            }
            lock (GlobalStats.ObjectManagerLocker)
            {
                ScreenManager.inter.ObjectManager.Submit(this.InnerSO);
                ScreenManager.inter.ObjectManager.Submit(this.OuterSO);
            }
        }
 public override void LoadContent()
 {
     base.ScreenManager.inter.ObjectManager.Clear();
     base.ScreenManager.inter.LightManager.Clear();
     this.model = base.ScreenManager.Content.Load<Model>("Model/SpaceObjects/planet_22");
     LightRig rig = base.ScreenManager.Content.Load<LightRig>("example/light_rig");
     base.ScreenManager.inter.LightManager.Submit(rig);
     base.ScreenManager.environment = base.ScreenManager.Content.Load<SceneEnvironment>("example/scene_environment");
     ModelMesh mesh = this.model.Meshes[0];
     this.shipSO = new SceneObject(mesh)
     {
         ObjectType = ObjectType.Dynamic,
         World = this.worldMatrix
     };
     base.ScreenManager.inter.ObjectManager.Submit(this.shipSO);
     float width = (float)base.ScreenManager.GraphicsDevice.Viewport.Width;
     Viewport viewport = base.ScreenManager.GraphicsDevice.Viewport;
     float aspectRatio = width / (float)viewport.Height;
     Vector3 camPos = new Vector3(0f, 0f, 1500f) * new Vector3(-1f, 1f, 1f);
     this.view = ((Matrix.CreateTranslation(0f, 0f, 0f) * Matrix.CreateRotationY(MathHelper.ToRadians(180f))) * Matrix.CreateRotationX(MathHelper.ToRadians(0f))) * Matrix.CreateLookAt(camPos, new Vector3(camPos.X, camPos.Y, 0f), new Vector3(0f, -1f, 0f));
     this.projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f, aspectRatio, 1f, 6000000f);
     base.LoadContent();
 }
示例#29
0
 public static Vector3d SceneToObjectP(SceneObject so, Vector3d scenePt)
 {
     return((Vector3d)SceneToObjectP(so, (Vector3f)scenePt));
 }
 public SceneObjectListEventArgs(SceneObject sceneObject)
 {
     Item        = 0;
     SceneObject = sceneObject;
 }
示例#31
0
        public override void onMount(GameBase obj, SceneObject mountObj, int node)
        {
            WheeledVehicle vehicle = obj._ID;

            vehicle.setImageAmmo(node, true);
        }
示例#32
0
        private void mniLoadECLGrid_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //ModelContainer modelContainer = this.ModelContainer;

            string fileName = openFileDialog1.FileName;
            SimulationInputData inputData;

            try
            {
                inputData = this.LoadEclInputData(fileName);
            }
            catch (Exception err)
            {
                MessageBox.Show(String.Format("Load Error,{0}", err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                List <GridBlockProperty> gridProperties = inputData.RootDataFile.GetGridProperties();
                GridBlockProperty        firstProperty = gridProperties[0];
                double axisMin, axisMax, step;
                ColorIndicatorAxisAutomator.Automate(firstProperty.MinValue, firstProperty.MaxValue, out axisMin, out axisMax, out step);
                CatesianGrid grid = inputData.DumpCatesianGrid((float)axisMin, (float)axisMax);

                SceneObject   gridObj = GetCatesianGridObj(grid, gridProperties, fileName);
                SceneObject[] wellObjects = GetWellObjects(inputData, grid, fileName);
                var           list = new List <IModelSpace>();
                list.Add(gridObj.Renderer);
                list.AddRange(from item in wellObjects select item.Renderer);
                BoundingBoxRenderer boxRenderer = list.GetBoundingBoxRenderer();
                SceneObject         mainObj     = boxRenderer.WrapToSceneObject(
                    string.Format("CatesianGrid: {0}", fileName),
                    new ModelScaleScript());
                mainObj.Children.Add(gridObj);
                mainObj.Children.AddRange(wellObjects);

                this.scientificCanvas.Scene.RootObject.Children.Add(mainObj);
                this.scientificCanvas.Scene.FirstCamera.ZoomCamera(boxRenderer.GetBoundingBox());

                vec3 back = this.scientificCanvas.Scene.FirstCamera.GetBack();
                this.scientificCanvas.Scene.FirstCamera.Target   = -grid.DataSource.Position;
                this.scientificCanvas.Scene.FirstCamera.Position = this.scientificCanvas.Scene.FirstCamera.Target + back;
                this.scientificCanvas.ColorPalette.SetCodedColor(axisMin, axisMax, step);

                // update tree node.
                TreeNode rootNode = DumpTreeNode(this.scientificCanvas.Scene.RootObject);
                this.objectsTreeView.Nodes.Clear();
                this.objectsTreeView.Nodes.Add(rootNode);
                this.objectsTreeView.ExpandAll();

                // refresh objects state in scene.
                this.scientificCanvas.Scene.UpdateOnce();

                // render scene to this canvas.
                this.scientificCanvas.Invalidate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#33
0
 public bool HasDeletedSceneObject(SceneObject so)
 {
     return(vDeleted.Find((x) => x == so) != null);
 }
示例#34
0
        public bool IsSelected(SceneObject s)
        {
            var found = vSelected.Find(x => x == s);

            return(found != null);
        }
示例#35
0
        /// <summary>
        /// transform frame from Object coords of fromSO into Object coords of toSO
        /// </summary>
        public static Frame3f TransformTo(Frame3f frameIn, SceneObject fromSO, SceneObject toSO)
        {
            Frame3f frameS = TransformTo(frameIn, fromSO, CoordSpace.ObjectCoords, CoordSpace.SceneCoords);

            return(TransformTo(frameS, toSO, CoordSpace.SceneCoords, CoordSpace.ObjectCoords));
        }
示例#36
0
        void LoadEGMs()
        {
            try
            {
                List <SceneObject> tmp_objects = new List <SceneObject>();

                e.StartData();
                tmp_objects.Clear();

                DbProviderFactory f = DbProviderFactories.GetFactory("System.Data.SqlClient");

                DbConnection c = f.CreateConnection();
                c.ConnectionString = ConfigurationSettings.AppSettings["db.connectionString"];
                c.Open();

                DbCommand cmd = f.CreateCommand();
                cmd.Connection  = c;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = e.GetQuery();
                cmd.CommandText = cmd.CommandText.Replace("<%=db%>", ConfigurationSettings.AppSettings["db.name"]);
                cmd.CommandText = cmd.CommandText.Replace("<%=olddb%>", ConfigurationSettings.AppSettings["db.oldname"]);
                cmd.CommandText = cmd.CommandText.Replace("<%=padron%>", ConfigurationSettings.AppSettings["db.padron"]);
                Debug.WriteLine(cmd.CommandText);

                int mid_x = 0, mid_y = 0, count = 0, max = 0;

                DataSet       ds = new DataSet();
                DbDataAdapter da = f.CreateDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);

                DbDataReader dr = ds.CreateDataReader();

                //DbDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                //foreach ( DataRow dr in ds.Tables[0].Rows )
                {
                    e.PrepareData(dr);
                    int x = (int)dr[1];
                    int y = (int)dr[2];

                    mid_x += x;
                    mid_y += y;
                    count++;

                    if (x > max)
                    {
                        max = x;
                    }
                    if (y > max)
                    {
                        max = y;
                    }
                }

                if (count != 0)
                {
                    mid_x /= count;
                    mid_y /= count;
                }

                mid_x = int.Parse(ConfigurationSettings.AppSettings["g.midx"]);
                mid_y = int.Parse(ConfigurationSettings.AppSettings["g.midy"]);

                dr.Close();

                if (count != 0)
                {
                    //dr = cmd.ExecuteReader();
                    dr = ds.CreateDataReader();

                    while (dr.Read())
                    {
                        int x = (int)dr[1] - mid_x;
                        int y = (int)dr[2] - mid_y;

                        if ((string)dr[0] == "0010394")
                        {
                            int k = 9;
                        }

                        SceneObject o = new SceneObject
                        {
                            Name            = (string)dr[0],
                            Location        = new Vector3(SCALE * x, 0, SCALE * y),
                            Angle           = new Vector3(0.0f, (float)(int)dr[3], 0.0f),
                            RotationalSpeed = new Vector3(0, 0, 0),
                            Light           = e.GetLight(dr),
                            BlinkingLight   = e.BlinkingLight(dr),
                            Alpha           = e.GetAlpha(dr),
                            Model           = Content.Load <Model>("MV_Converted")
                        };

                        o.BoundingBox = CreateBoundingBox(o.Model, o.Location);
                        tmp_objects.Add(o);

                        if (selected == null)
                        {
                            selected = o;
                        }
                    }

                    c.Close();
                    online = true;
                    lock (lock_scene_objects)
                        scene_objects = tmp_objects;

                    e.EndData();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                Logs.LogError("UNHANDLED EXCEPTION: " + ex.Message + ex.StackTrace);
                online = false;
            }
        }
示例#37
0
 int CompareSceneObjects(SceneObject a, SceneObject b)
 {
     return(DistanceToCamera(camera, b.Location).CompareTo(DistanceToCamera(camera, a.Location)));
 }
示例#38
0
        // a platform has been spawned, now spawn the scene objects and setup for a turn if needed
        private void PlatformSpawned(PlatformObject platform, ObjectLocation location, Vector3 direction, bool activateImmediately)
        {
            bool isTurn = platform.leftTurn || platform.rightTurn;

            if (isTurn || spawnFullLength)
            {
                // set largestScene to 0 to prevent the scene spawner from waiting for space for the largest scene object
                spawnData.largestScene   = 0;
                spawnData.useWidthBuffer = false;
            }

            // spawn all of the scene objects until we have spawned enough scene objects
            SetupSection(location, true);
            int         localIndex;
            SceneObject scene = null;

            while ((localIndex = infiniteObjectManager.GetNextObjectIndex(ObjectType.Scene, spawnData)) != -1)
            {
                Vector3     position  = Vector3.zero;
                SceneObject prevScene = infiniteObjectHistory.GetTopInfiniteObject(location, true) as SceneObject;
                bool        useZSize  = true;
                int         prevSceneIndex;
                // may be null if coming from a turn
                if (prevScene == null)
                {
                    if (location != ObjectLocation.Center)
                    {
                        prevSceneIndex = sceneTurnIndex[(int)ObjectLocation.Center];
                        prevScene      = turnScene[(int)ObjectLocation.Center];
                    }
                    else
                    {
                        prevScene      = infiniteObjectHistory.GetTopInfiniteObject(location, true) as SceneObject;
                        prevSceneIndex = infiniteObjectHistory.GetLastLocalIndex(location, ObjectType.Scene);
                    }
                    useZSize = false;
                }
                else
                {
                    prevSceneIndex = infiniteObjectHistory.GetLastLocalIndex(location, ObjectType.Scene);
                }
                if (prevScene)
                {
                    position = prevScene.GetTransform().position - sceneStartPosition[prevSceneIndex] + (useZSize ? sceneSizes[prevSceneIndex].z : sceneSizes[prevSceneIndex].x) / 2 * direction + sceneSizes[prevSceneIndex].y * Vector3.up;
                }
                scene = SpawnSceneObject(localIndex, location, position, direction, activateImmediately);
                // the section may change because of the newly spawned scene object
                SetupSection(location, true);
            }

            if (isTurn)
            {
                spawnData.largestScene   = largestSceneLength;
                spawnData.useWidthBuffer = true;

                turnPlatform[(int)location] = platform;
                turnIndex[(int)location]    = infiniteObjectHistory.GetLastLocalIndex(location, ObjectType.Platform);

                turnScene[(int)location]      = scene;
                sceneTurnIndex[(int)location] = infiniteObjectHistory.GetLastLocalIndex(location, ObjectType.Scene);

                if (location == ObjectLocation.Center)
                {
                    infiniteObjectHistory.ResetTurnCount();
                }
            }
            else if (platform.sectionTransition)
            {
                infiniteObjectHistory.DidSpawnSectionTranition(location, false);
            }
        }
示例#39
0
        /// <summary>
        /// Activates or deactivates the profiler overlay according to current editor settings.
        /// </summary>
        private void UpdateProfilerOverlay()
        {
            if (EditorSettings.GetBool(ProfilerOverlayActiveKey))
            {
                if (activeProfilerOverlay == null)
                {
                    SceneObject profilerSO = new SceneObject("EditorProfilerOverlay");
                    profilerCamera = profilerSO.AddComponent<Camera>();
                    profilerCamera.Target = renderTexture;
                    profilerCamera.ClearFlags = ClearFlags.None;
                    profilerCamera.Priority = 1;
                    profilerCamera.Layers = 0;
                    profilerCamera.HDR = false;

                    activeProfilerOverlay = profilerSO.AddComponent<ProfilerOverlay>();
                }
            }
            else
            {
                if (activeProfilerOverlay != null)
                {
                    activeProfilerOverlay.SceneObject.Destroy();
                    activeProfilerOverlay = null;
                    profilerCamera = null;
                }
            }
        }
        public Scene MakeScene(ILoader loader = null)
        {
            //TextureState.ResetCache();

            Scene scene = new Scene();

            Dictionary <ulong, Renderable> models = new Dictionary <ulong, Renderable>();

            int i     = 0;
            int index = 1;

            foreach (ModelInstance instance in Instances)
            {
                int progress = (index - 1) * 100 / Instances.Count;
                loader?.SetProgress(progress);

                loader?.SetStatus("Loading(" + progress.ToString("D2") + "%): ModelInstance: " + index + "/" + Instances.Count);
                //DebugTimer t = DebugTimer.Start("ModelInstance[" + index + "/" + Instances.Count + "]");
                index++;

                if (!InRange(instance))
                {
                    continue;
                }

                if (models.ContainsKey(instance.ModelEntryID))
                {
                    Renderable  renderable  = models[instance.ModelEntryID];
                    SceneObject sceneObject = new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                    sceneObject.ID        = i.ToString();
                    sceneObject.Transform = instance.Transform;

                    scene.AddObject(sceneObject);
                }
                else
                {
                    BundleEntry modelEntry = Entry.Archive.GetEntryByID(instance.ModelEntryID);
                    if (modelEntry == null)
                    {
                        string file = BundleCache.GetFileByEntryID(instance.ModelEntryID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            modelEntry = archive.GetEntryByID(instance.ModelEntryID);
                        }
                    }

                    if (modelEntry != null)
                    {
                        BundleEntry renderableEntry = modelEntry.GetDependencies()[0].Entry;
                        Renderable  renderable      = new Renderable();
                        renderable.Read(renderableEntry, null);                         // TODO: Null Loader
                        models.Add(instance.ModelEntryID, renderable);
                        SceneObject sceneObject =
                            new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                        sceneObject.ID        = i.ToString();
                        sceneObject.Transform = instance.Transform;

                        scene.AddObject(sceneObject);
                    }
                }
                i++;
                //t.StopLog();
            }
            loader?.SetProgress(100);

            //TextureState.ResetCache();

            return(scene);
        }
示例#41
0
 /// <summary>
 /// Cache the transform sequence from scene coordinates down to SO-local coordinates
 /// </summary>
 public static TransformSequence SceneToObjectXForm(SceneObject so)
 {
     // [TODO] could be more efficient?
     return(ObjectToSceneXForm(so).MakeInverse());
 }
 public HouseRouteBehaviour(SceneObject sceneObject) : base(sceneObject)
 {
 }
示例#43
0
        /// <summary>
        /// transform point from Object coords of fromSO into Object coords of toSO
        /// </summary>
        public static Vector3d TransformTo(Vector3d ptIn, SceneObject fromSO, SceneObject toSO)
        {
            Frame3f frameS = TransformTo(new Frame3f((Vector3f)ptIn), fromSO, CoordSpace.ObjectCoords, CoordSpace.SceneCoords);

            return(TransformTo(frameS, toSO, CoordSpace.SceneCoords, CoordSpace.ObjectCoords).Origin);
        }
示例#44
0
 protected virtual void OnSceneChanged(SceneObject so, SceneChangeType type)
 {
     FUtil.SafeSendAnyEvent(ChangedEvent, this, so, type);
 }
示例#45
0
    // Adds a SceneObject to the story scene.
    private void loadSceneObject(SceneObject sceneObject)
    {
        // Allow multiple scene objects per label as long as we believe that they are referring to
        // different objects.
        if (this.sceneObjectsLabelToId.ContainsKey(sceneObject.label))
        {
            // Check for overlap.
            foreach (int existingObject in this.sceneObjectsLabelToId[sceneObject.label])
            {
                if (Util.RefersToSameObject(
                        sceneObject.position,
                        this.sceneObjects[existingObject].GetComponent <SceneObjectManipulator>().position))
                {
                    // Logger.Log("Detected overlap for object " + sceneObject.label);
                    return;
                }
            }
        }
        // Save this id under its label.
        if (!this.sceneObjectsLabelToId.ContainsKey(sceneObject.label))
        {
            this.sceneObjectsLabelToId[sceneObject.label] = new List <int>();
        }
        this.sceneObjectsLabelToId[sceneObject.label].Add(sceneObject.id);

        GameObject newObj =
            Instantiate((GameObject)Resources.Load("Prefabs/SceneObject"));

        newObj.transform.SetParent(this.graphicsPanel.transform, false);
        newObj.GetComponent <RectTransform>().SetAsLastSibling();
        // Set the position.
        SceneObjectManipulator manip =
            newObj.GetComponent <SceneObjectManipulator>();
        Position pos = sceneObject.position;

        manip.id       = sceneObject.id;
        manip.label    = sceneObject.label;
        manip.position = pos;
        manip.MoveToPosition(
            new Vector3(this.storyImageX + pos.left * this.imageScaleFactor,
                        this.storyImageY - pos.top * this.imageScaleFactor)
            )();
        manip.ChangeSize(
            new Vector2(pos.width * this.imageScaleFactor,
                        pos.height * this.imageScaleFactor)
            )();

        // TODO: find the appropriate sprite and assign it here.
        // Sprite toadSprite = Resources.Load<Sprite>("toad_sprite");
        //manip.SetSprite(toadSprite);

        // Set the pivot.
        manip.SetPivotToCenter();
        manip.Scale(new Vector3(1.1f, 1.1f));


        // Add a dummy handler to check things.
        manip.AddClickHandler(() =>
        {
            Logger.Log("SceneObject clicked " +
                       manip.label);
        });
        // Add a click handler to send a ROS message.
        if (Constants.USE_ROS)
        {
            manip.AddClickHandler(
                this.rosManager.SendSceneObjectTappedAction(sceneObject.id, sceneObject.label));
        }
        // Add additional click handlers if the scene object's label is not in the story text.
        if (!sceneObject.inText)
        {
            manip.AddClickHandler(() =>
            {
                Logger.Log("Not in text! " + manip.label);
                this.showPopupText(manip.label, manip.position);
            });
        }
        // Name the GameObject so we can inspect in the editor.
        newObj.name = sceneObject.label;
        this.sceneObjects[sceneObject.id] = newObj;
    }
示例#46
0
        private void OnEditorUpdate()
        {
            if (currentType == InspectorType.SceneObject)
            {
                Component[] allComponents   = activeSO.GetComponents();
                bool        requiresRebuild = allComponents.Length != inspectorComponents.Count;

                if (!requiresRebuild)
                {
                    for (int i = 0; i < inspectorComponents.Count; i++)
                    {
                        if (inspectorComponents[i].instanceId != allComponents[i].InstanceId)
                        {
                            requiresRebuild = true;
                            break;
                        }
                    }
                }

                if (requiresRebuild)
                {
                    SceneObject so = activeSO;
                    Clear();
                    SetObjectToInspect(so);
                }
                else
                {
                    RefreshSceneObjectFields(false);

                    InspectableState componentModifyState = InspectableState.NotModified;
                    for (int i = 0; i < inspectorComponents.Count; i++)
                    {
                        componentModifyState |= inspectorComponents[i].inspector.Refresh();
                    }

                    if (componentModifyState.HasFlag(InspectableState.ModifyInProgress))
                    {
                        EditorApplication.SetSceneDirty();
                    }

                    modifyState |= componentModifyState;
                }
            }
            else if (currentType == InspectorType.Resource)
            {
                inspectorResource.inspector.Refresh();
            }

            // Detect drag and drop
            bool isValidDrag = false;

            if (activeSO != null)
            {
                if ((DragDrop.DragInProgress || DragDrop.DropInProgress) && DragDrop.Type == DragDropType.Resource)
                {
                    Vector2I windowPos     = ScreenToWindowPos(Input.PointerPosition);
                    Vector2I scrollPos     = windowPos;
                    Rect2I   contentBounds = inspectorLayout.Bounds;
                    scrollPos.x -= contentBounds.x;
                    scrollPos.y -= contentBounds.y;

                    bool   isInBounds = false;
                    Rect2I dropArea   = new Rect2I();
                    foreach (var bounds in dropAreas)
                    {
                        if (bounds.Contains(scrollPos))
                        {
                            isInBounds = true;
                            dropArea   = bounds;
                            break;
                        }
                    }

                    Type draggedComponentType = null;
                    if (isInBounds)
                    {
                        ResourceDragDropData dragData = DragDrop.Data as ResourceDragDropData;
                        if (dragData != null)
                        {
                            foreach (var resPath in dragData.Paths)
                            {
                                ResourceMeta meta = ProjectLibrary.GetMeta(resPath);
                                if (meta != null)
                                {
                                    if (meta.ResType == ResourceType.ScriptCode)
                                    {
                                        ScriptCode scriptFile = ProjectLibrary.Load <ScriptCode>(resPath);

                                        if (scriptFile != null)
                                        {
                                            Type[] scriptTypes = scriptFile.Types;
                                            foreach (var type in scriptTypes)
                                            {
                                                if (type.IsSubclassOf(typeof(Component)))
                                                {
                                                    draggedComponentType = type;
                                                    isValidDrag          = true;
                                                    break;
                                                }
                                            }

                                            if (draggedComponentType != null)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (isValidDrag)
                    {
                        scrollAreaHighlight.Bounds = dropArea;

                        if (DragDrop.DropInProgress)
                        {
                            activeSO.AddComponent(draggedComponentType);

                            modifyState = InspectableState.Modified;
                            EditorApplication.SetSceneDirty();
                        }
                    }
                }
            }

            if (scrollAreaHighlight != null)
            {
                scrollAreaHighlight.Active = isValidDrag;
            }
        }
 /// <summary>Serializes the current state of the provided scene object.</summary>
 /// <param name="sceneObject">Object whose state to serialize.</param>
 /// <param name="hierarchy">
 /// If true all children of the provided scene object will be serialized as well, otherwise just the provided object will.
 /// </param>
 public SerializedSceneObject(SceneObject sceneObject, bool hierarchy = false)
 {
     Internal_SerializedSceneObject(this, sceneObject, hierarchy);
 }
示例#48
0
        /// <summary>
        /// Updates contents of the scene object specific fields (name, position, rotation, etc.)
        /// </summary>
        /// <param name="forceUpdate">If true, the GUI elements will be updated regardless of whether a change was
        ///                           detected or not.</param>
        private void RefreshSceneObjectFields(bool forceUpdate)
        {
            if (activeSO == null)
            {
                return;
            }

            soNameInput.Text     = activeSO.Name;
            soActiveToggle.Value = activeSO.Active;
            soMobility.Value     = (ulong)activeSO.Mobility;

            SceneObject prefabParent = PrefabUtility.GetPrefabParent(activeSO);

            // Ignore prefab parent if scene root, we only care for non-root prefab instances
            bool hasPrefab = prefabParent != null && prefabParent.Parent != null;

            if (soHasPrefab != hasPrefab || forceUpdate)
            {
                int numChildren = soPrefabLayout.ChildCount;
                for (int i = 0; i < numChildren; i++)
                {
                    soPrefabLayout.GetChild(0).Destroy();
                }

                GUILabel prefabLabel = new GUILabel(new LocEdString("Prefab"), GUIOption.FixedWidth(50));
                soPrefabLayout.AddElement(prefabLabel);

                if (hasPrefab)
                {
                    GUIButton btnApplyPrefab  = new GUIButton(new LocEdString("Apply"), GUIOption.FixedWidth(60));
                    GUIButton btnRevertPrefab = new GUIButton(new LocEdString("Revert"), GUIOption.FixedWidth(60));
                    GUIButton btnBreakPrefab  = new GUIButton(new LocEdString("Break"), GUIOption.FixedWidth(60));

                    btnApplyPrefab.OnClick += () =>
                    {
                        PrefabUtility.ApplyPrefab(activeSO);
                    };
                    btnRevertPrefab.OnClick += () =>
                    {
                        UndoRedo.RecordSO(activeSO, true, "Reverting \"" + activeSO.Name + "\" to prefab.");

                        PrefabUtility.RevertPrefab(activeSO);
                        EditorApplication.SetSceneDirty();
                    };
                    btnBreakPrefab.OnClick += () =>
                    {
                        UndoRedo.BreakPrefab(activeSO, "Breaking prefab link for " + activeSO.Name);

                        EditorApplication.SetSceneDirty();
                    };

                    soPrefabLayout.AddElement(btnApplyPrefab);
                    soPrefabLayout.AddElement(btnRevertPrefab);
                    soPrefabLayout.AddElement(btnBreakPrefab);
                }
                else
                {
                    GUILabel noPrefabLabel = new GUILabel("None");
                    soPrefabLayout.AddElement(noPrefabLabel);
                }

                soHasPrefab = hasPrefab;
            }

            Vector3    position;
            Quaternion rotation;

            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
            {
                position = activeSO.Position;
                rotation = activeSO.Rotation;
            }
            else
            {
                position = activeSO.LocalPosition;
                rotation = activeSO.LocalRotation;
            }

            Vector3 scale = activeSO.LocalScale;

            if (!soPos.HasInputFocus)
            {
                soPos.Value = position;
            }

            // Avoid updating the rotation unless actually changed externally, since switching back and forth between
            // quaternion and euler angles can cause weird behavior
            if (!soRot.HasInputFocus && rotation != lastRotation)
            {
                soRot.Value  = rotation.ToEuler();
                lastRotation = rotation;
            }

            if (!soScale.HasInputFocus)
            {
                soScale.Value = scale;
            }
        }
示例#49
0
 // this removes so from a SO/parent hierarchy and parents to Scene instead
 public void ReparentSceneObject(SceneObject so, bool bKeepPosition = true)
 {
     so.RootGameObject.transform.SetParent(null);
     so.RootGameObject.transform.SetParent(scene_objects.transform, bKeepPosition);
     so.Parent = this;
 }
 private static extern void Internal_SerializedSceneObject(SerializedSceneObject managedInstance, SceneObject sceneObject, bool hierarchy);
示例#51
0
 public SceneObjectSelectedMessage(SceneObject sceneObject)
 {
     SceneObject = sceneObject;
 }
示例#52
0
 public static Vector3d ObjectToScene(SceneObject so, Vector3d objectPt)
 {
     return(ObjectToSceneP(so, objectPt));
 }
示例#53
0
 public static Vector3d ObjectToSceneP(SceneObject so, Vector3d scenePt)
 {
     return((Vector3d)ObjectToSceneP(so, (Vector3f)scenePt));
 }
示例#54
0
 public static Vector3d SceneToObject(SceneObject so, Vector3d scenePt)
 {
     return(SceneToObjectP(so, scenePt));
 }
示例#55
0
        /// <summary>
        /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="so">Scene object to inspect.</param>
        private void SetObjectToInspect(SceneObject so)
        {
            if (so == null)
            {
                return;
            }

            currentType = InspectorType.SceneObject;
            activeSO    = so;

            inspectorScrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);
            scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture);
            scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR);
            scrollAreaHighlight.Active = false;

            GUI.AddElement(inspectorScrollArea);
            GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel();

            inspectorLayout = inspectorPanel.AddLayoutY();
            highlightPanel  = inspectorPanel.AddPanel(-1);
            highlightPanel.AddElement(scrollAreaHighlight);

            // SceneObject fields
            CreateSceneObjectFields();
            RefreshSceneObjectFields(true);

            // Components
            Component[] allComponents = so.GetComponents();
            for (int i = 0; i < allComponents.Length; i++)
            {
                inspectorLayout.AddSpace(COMPONENT_SPACING);

                InspectorComponent data = new InspectorComponent();
                data.instanceId = allComponents[i].InstanceId;
                data.folded     = false;

                data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout);
                data.foldout.AcceptsKeyFocus = false;

                SpriteTexture xBtnIcon = EditorBuiltin.GetEditorIcon(EditorIcon.X);
                data.removeBtn = new GUIButton(new GUIContent(xBtnIcon), GUIOption.FixedWidth(30));

                data.title = inspectorLayout.AddLayoutX();
                data.title.AddElement(data.foldout);
                data.title.AddElement(data.removeBtn);
                data.panel = inspectorLayout.AddPanel();

                var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId);

                data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType());
                data.inspector.Initialize(data.panel, allComponents[i], persistentProperties);

                bool isExpanded = data.inspector.Persistent.GetBool(data.instanceId + "_Expanded", true);
                data.foldout.Value = isExpanded;

                if (!isExpanded)
                {
                    data.inspector.SetVisible(false);
                }

                Type curComponentType = allComponents[i].GetType();
                data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded);
                data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType);

                inspectorComponents.Add(data);
            }

            inspectorLayout.AddFlexibleSpace();

            UpdateDropAreas();
        }
示例#56
0
 /// <summary>
 /// input dimension is in scene coords, (recursively) apply all
 /// intermediate inverse-scales to get it into local coords of SO.
 /// </summary>
 public static float SceneToObject(SceneObject so, float sceneDim)
 {
     return(inverse_scale_recursive(so, sceneDim));
 }
示例#57
0
 public override bool CanGenerate(SceneObject so)
 {
     return(so is PolyCurveSO);
 }
 public SceneObjectListEventArgs(int itemIndex)
 {
     Item        = itemIndex;
     SceneObject = new SceneObject();
 }
示例#59
0
        /// <summary>
        /// Creates the scene camera and updates the render texture. Should be called at least once before using the
        /// scene view. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            width = MathEx.Max(20, width);
            height = MathEx.Max(20, height);

            // Note: Depth buffer and readable flags are required because ScenePicking uses it
            Texture2D colorTex = new Texture2D(width, height, PixelFormat.R8G8B8A8, TextureUsage.Render | TextureUsage.CPUReadable);
            Texture2D depthTex = new Texture2D(width, height, PixelFormat.D32_S8X24, TextureUsage.DepthStencil | TextureUsage.CPUReadable);

            renderTexture = new RenderTexture2D(colorTex, depthTex);
            renderTexture.Priority = 1;

            if (camera == null)
            {
                SceneObject sceneCameraSO = new SceneObject("SceneCamera", true);
                camera = sceneCameraSO.AddComponent<Camera>();
                camera.Target = renderTexture;
                camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

                sceneCameraSO.Position = new Vector3(0, 0.5f, 1);
                sceneCameraSO.LookAt(new Vector3(0, 0.5f, 0));

                camera.Priority = 2;
                camera.NearClipPlane = 0.05f;
                camera.FarClipPlane = 2500.0f;
                camera.ClearColor = ClearColor;
                camera.Layers = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera

                cameraController = sceneCameraSO.AddComponent<SceneCamera>();

                renderTextureGUI = new GUIRenderTexture(renderTexture);
                rtPanel.AddElement(renderTextureGUI);

                sceneGrid = new SceneGrid(camera);
                sceneSelection = new SceneSelection(camera);
                sceneGizmos = new SceneGizmos(camera);
                sceneHandles = new SceneHandles(this, camera);
            }
            else
            {
                camera.Target = renderTexture;
                renderTextureGUI.RenderTexture = renderTexture;
            }

            Rect2I rtBounds = new Rect2I(0, 0, width, height);
            renderTextureGUI.Bounds = rtBounds;
            focusCatcher.Bounds = GUIUtility.CalculateBounds(rtPanel, GUI);

            sceneAxesGUI.SetPosition(width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY);

            // TODO - Consider only doing the resize once user stops resizing the widget in order to reduce constant
            // render target destroy/create cycle for every single pixel.

            camera.AspectRatio = width / (float)height;

            if (profilerCamera != null)
                profilerCamera.Target = renderTexture;
        }
示例#60
0
 public override List <ISnapSegment> GenerateSegments(SceneObject so)
 {
     return(null);
 }