Manages the organization and rendering of a 'scene' i.e. a collection of objects and potentially world geometry.
This class defines the interface and the basic behaviour of a 'Scene Manager'. A SceneManager organizes the culling and rendering of the scene, in conjunction with the RenderQueue. This class is designed to be extended through subclassing in order to provide more specialized scene organization structures for particular needs. The default SceneManager culls based on a hierarchy of node bounding boxes, other implementations can use an octree (), a BSP tree (), and many other options. New SceneManager implementations can be added at runtime by plugins, see SceneManagerEnumerator for the interfaces for adding new SceneManager types.

There is a distinction between 'objects' (which subclass MovableObject, and are movable, discrete objects in the world), and 'world geometry', which is large, generally static geometry. World geometry tends to influence the SceneManager organizational structure (e.g. lots of indoor static geometry might result in a spatial tree structure) and as such world geometry is generally tied to a given SceneManager implementation, whilst MovableObject instances can be used with any SceneManager. Subclasses are free to define world geometry however they please.

Multiple SceneManager instances can exist at one time, each one with a distinct scene. Which SceneManager is used to render a scene is dependent on the Camera, which will always call back the SceneManager which created it to render the scene.

Наследование: DisposableObject
Пример #1
0
 public World(SceneManager pSceneManager)
 {
     SceneManager = pSceneManager;
     Ships = new List<Ship>(48);
     Bullets = new List<Bullet>(256);
     Trails = new List<Trail>(256);
 }
Пример #2
0
        public void OnLoad()
        {
            var dir = Directory.GetCurrentDirectory();
            ResourceGroupManager.Instance.AddResourceLocation(dir, "Folder");
            //MaterialManager.Instance.Initialize();

            _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance");
            _scene.ClearScene();

            Bindings.Axiom.SLSharp.Init();
            Shader.DebugMode = true;

            //Shader.DebugMode = true;

            _clipmap = new Clipmap(_scene);
            RecalcHeight();

            _camera = _scene.CreateCamera("MainCamera");
            _camera.Position = new Vector3(0, 0, 5);
            _camera.LookAt(Vector3.Zero);
            _camera.Near = 0.001f;
            _camera.Far = 20.0f;
            _camera.AutoAspectRatio = true;

            var vp = _window.AddViewport(_camera);
            vp.BackgroundColor = ColorEx.CornflowerBlue;
        }
 public GlobalAmbientLight(IWorldContainer parentContainer, WorldEditor worldEditor)
 {
     this.app = worldEditor;
     this.parent = parentContainer;
     this.scene = app.Scene;
     this.color = app.Config.DefaultAmbientLightColor;
 }
Пример #4
0
		public PCZCamera( string name, SceneManager sceneManager )
			: base( name, sceneManager )
		{
			this.box = new AxisAlignedBox( new Vector3( -0.1f, -0.1f, -0.1f ), new Vector3( 0.1f, 0.1f, 0.1f ) );
			this.extraCullingFrustum = new PCZFrustum();
			this.extraCullingFrustum.SetUseOriginPlane( true );
		}
Пример #5
0
        public SmoothCamera(String pName, SceneManager pSceneManager, MovingObject pTarget, Int32 pFramesBehind)
            : base(pName, pSceneManager)
        {
            Node = pSceneManager.RootSceneNode.CreateChildSceneNode();
            Node.Position = cameraOffset;
            Node.AttachObject(this);

            x = new List<double>(pFramesBehind);
            y = new List<double>(pFramesBehind);
            dx = new List<double>(pFramesBehind);
            dy = new List<double>(pFramesBehind);
            framesBehind = Math.Max(1, pFramesBehind);
            target = pTarget;

            for (var i = 0; i < pFramesBehind; i++)
            {
                x.Add(pTarget.Position.x);
                y.Add(pTarget.Position.y);
                dx.Add(0);
                dy.Add(0);
            }

            x.Insert(0, pTarget.Position.x);
            y.Insert(0, pTarget.Position.y);
            dx.Insert(0, pTarget.Velocity.x);
            dy.Insert(0, pTarget.Velocity.y);

            isYawFixed = true;
            FixedYawAxis = Vector3.UnitZ;
            Near = 5;
            AutoAspectRatio = true;
        }
 public GlobalAmbientLight(IWorldContainer parentContainer,WorldEditor worldEditor, SceneManager sceneManager, ColorEx lightColor)
 {
     this.parent = parentContainer;
     this.app = worldEditor;
     this.scene = sceneManager;
     this.color = lightColor;
 }
        public GlobalAmbientLight(IWorldContainer parentContainer, WorldEditor worldEditor, SceneManager sceneManager,  XmlReader r)
        {
            this.app = worldEditor;
            this.parent = parentContainer;
            this.scene = sceneManager;

            fromXml(r);
        }
Пример #8
0
 public GlobalFog(IWorldContainer parentContainer, WorldEditor worldEditor)
 {
     this.parent = parentContainer;
     this.app = worldEditor;
     this.scene = app.Scene;
     this.color = app.Config.FogColorDefault;
     this.far = app.Config.FogFarDefault;
     this.near = app.Config.FogNearDefault;
 }
Пример #9
0
        public MultiLights(SceneManager pSceneManager, SceneNode pCamNode, MovingObject pPlayerShip, Int32 pNumberOfLights)
        {
            oldCamLightColor = CamLightColor = new ColorEx(0.13f, 0.1f, 0.05f);
            PlayerLightColor = ColorEx.White;
            camLights = new List<Light>(pNumberOfLights);

            innerLights = (Int32)Math.Round(pNumberOfLights / 3.0f, MidpointRounding.AwayFromZero);
            outerLights = pNumberOfLights - innerLights;

            // create the playership's light.
            playerLight = pSceneManager.CreateLight("playerSpotLight");
            playerLight.Type = LightType.Spotlight;
            playerLight.Diffuse = PlayerLightColor;
            playerLight.Specular = ColorEx.White;
            playerLight.SetSpotlightRange(0.0f, 120.0f);
            playerLight.Direction = Vector3.NegativeUnitZ;

            playerLightNode = pPlayerShip.Node.CreateChildSceneNode();
            playerLightNode.AttachObject(playerLight);
            playerLightNode.Position = new Vector3(0, 0, 0);
            playerLightNode.SetDirection(new Vector3(1, 0, 0), TransformSpace.Local);

            // create the camera spotlights around the camera's direction.
            camInnerLightNode = pCamNode.CreateChildSceneNode();
            camInnerLightNode.Position = new Vector3(0, 0, 0);
            camOuterLightNode = pCamNode.CreateChildSceneNode();
            camOuterLightNode.Position = new Vector3(0, 0, 0);

            for (var i = 0; i < innerLights; i++)
            {
                var light = pSceneManager.CreateLight("camInnerLight " + (i + 1));
                light.Type = LightType.Spotlight;
                light.Diffuse = CamLightColor;
                light.Specular = ColorEx.White;
                light.SetSpotlightRange(0.0f, 25.0f);
                light.Direction = Quaternion.FromAngleAxis(360.0 * i / innerLights * Constants.DegreesToRadians, Vector3.UnitZ) *
                    Quaternion.FromAngleAxis(10.0 * Constants.DegreesToRadians, Vector3.UnitX) *
                    Vector3.NegativeUnitZ;

                camLights.Add(light);
                camInnerLightNode.AttachObject(light);
            }
            for (var i = 0; i < outerLights; i++)
            {
                var light = pSceneManager.CreateLight("camOuterLight " + (i + 1));
                light.Type = LightType.Spotlight;
                light.Diffuse = CamLightColor;
                light.Specular = ColorEx.White;
                light.SetSpotlightRange(0.0f, 25.0f);
                light.Direction = Quaternion.FromAngleAxis(360.0 * i / outerLights * Constants.DegreesToRadians, Vector3.UnitZ) *
                    Quaternion.FromAngleAxis(20.0 * Constants.DegreesToRadians, Vector3.UnitX) *
                    Vector3.NegativeUnitZ;

                camLights.Add(light);
                camOuterLightNode.AttachObject(light);
            }
        }
Пример #10
0
        public Clipmap(SceneManager scene)
        {
            _scene = scene;
            _scene.QueueStarted += (sender, args) =>
            {
                if (args.RenderQueueId == _scene.GetRenderQueue().DefaultRenderGroup)
                    QueuePatches(_scene.GetRenderQueue());
                args.SkipInvocation = false;
            };

            using (var testMap = (Bitmap)Image.FromFile(@"height.jpg"))
            {
                _testMapWidth = testMap.Width;
                _testMapHeight = testMap.Height;
                _testMap = new float[_testMapWidth * _testMapHeight];
                var i = 0;
                for (var y = 0; y < testMap.Height; y++)
                    for (var x = 0; x < testMap.Width; x++)
                        _testMap[i++] = testMap.GetPixel(x, y).R / 255.0f;
            }

            var tu = _shader.Sampler(() => _shader.Heightmap);
            tu.DesiredFormat = PixelFormat.FLOAT32_RGB;
            tu.SetTextureFiltering(FilterOptions.Point, FilterOptions.Point, FilterOptions.None);
            tu.SetTextureAddressingMode(TextureAddressing.Wrap);
            tu.BindingType = TextureBindingType.Vertex;

            _shader.SetAuto(() => _shader.ModelViewProjectionMatrix, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix);
            //_shader.SetAuto(() => _shader.NormalMatrix, GpuProgramParameters.AutoConstantType.ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX);
            _shader.SetAuto(() => _shader.ScaleFactor, GpuProgramParameters.AutoConstantType.Custom, 0);
            _shader.SetAuto(() => _shader.FineBlockOrigin, GpuProgramParameters.AutoConstantType.Custom, 1);

            Position = new IntFloatVector2(new IntFloat(-_testMapWidth / 4), new IntFloat(-_testMapHeight / 4));

            Locations = new PatchLocations(H, M);

            var scale = Scale;
            var scaleInt = 1;

            for (var i = 0; i < Levels; i++)
            {
                _levels[i] = new ClipmapLevel(scale, scaleInt, this);
                var level = _levels[i];
                tu.SetTextureName(level.Heightmap.Name);
                var m = _shader.CloneMaterial("ClipmapLevel" + i);
                _levels[i].Material = m;

                scale *= 2.0f;
                scaleInt *= 2;
            }

            UpdatePosition();
            Reset();

            _initialized = true;
        }
 public AddDirectionalLightCommand(WorldEditor worldEditor, IWorldContainer parentObject, String objectName, string meshName, ColorEx specular, ColorEx diffuse)
 {
     this.app = worldEditor;
     this.parent =  (Boundary) parentObject;
     this.name = objectName;
     this.meshName = meshName;
     this.specular = specular;
     this.diffuse = diffuse;
     this.scene = app.Scene;
 }
Пример #12
0
		public PCZSceneNode( SceneManager creator, string name )
			: base( creator, name )
		{
			this.homeZone = null;
			this.anchored = false;
			AllowToVisit = true;
			LastVisibleFrame = 0;
			LastVisibleFromCamera = null;
			Enabled = true;
		}
Пример #13
0
		public PCZSceneNode( SceneManager creator, string name )
			: base( creator, name )
		{
			homeZone = null;
			anchored = false;
			allowedToVisit = true;
			lastVisibleFrame = 0;
			lastVisibleFromCamera = null;
			enabled = true;
		}
Пример #14
0
 public PointLight(WorldEditor worldEditor, IWorldContainer parent, SceneManager scene, string name, ColorEx specular, ColorEx diffuse, Vector3 position)
 {
     this.app = worldEditor;
     this.parent = parent;
     this.scene = scene;
     this.name = name;
     this.position = position;
     this.specular = specular;
     this.diffuse = diffuse;
     this.terrainOffset = app.Config.DefaultPointLightHeight;
 }
 public AddPointLightCommand(WorldEditor worldEditor, IWorldContainer parentObject, String objectName, string meshName, ColorEx specular, ColorEx diffuse)
 {
     this.app = worldEditor;
     this.parent = parentObject;
     this.name = objectName;
     this.meshName = meshName;
     this.specular = specular;
     this.diffuse = diffuse;
     this.scene = app.Scene;
     placing = true;
 }
        private static bool ManagerContainsNode( SceneManager sceneManager, SceneNode childNode )
        {
            bool managerContainsChild = false;

            foreach ( SceneNode sceneNode in sceneManager.SceneNodes )
            {
                if ( sceneNode.Equals( childNode ) )
                {
                    managerContainsChild = true;
                }
            }
            return managerContainsChild;
        }
 public DisplayParticleSystem(String name, SceneManager scene, string particleSystemName, Vector3 position, Vector3 scale, Vector3 rotation, float velocityScale, float particleScale)
 {
     this.name = name;
     this.scene = scene;
     this.particleSystemName = particleSystemName;
     this.position = position;
     this.scale = scale;
     this.rotation = rotation;
     this.particleScale = particleScale;
     this.velocityScale = velocityScale;
     attached = false;
     AddToScene();
 }
Пример #18
0
 public Region(StaticGeometry parent, string name, SceneManager mgr, UInt32 regionID, Vector3 center)
 {
     this.parent = parent;
     this.name = name;
     this.sceneMgr = mgr;
     this.regionID = regionID;
     this.center = center;
     queuedSubMeshes = new List<QueuedSubMesh>();
     lodSquaredDistances = new List<float>();
     aabb = new AxisAlignedBox();
     lodBucketList = new List<LODBucket>();
     shadowRenderables = new ShadowRenderableList();
 }
        /// <summary>
        ///     Internal constructor.  This class cannot be instantiated externally.
        /// </summary>
        internal SceneManagerEnumerator()
        {
            if (instance == null) {
                instance = this;

                // by default, use the standard scene manager.
                defaultSceneManager = new SceneManager("Default Scene Manager");

                // by default, all scenetypes use the default Scene Manager.  Note: These can be overridden by plugins.
                SetSceneManager(SceneType.Generic, defaultSceneManager);
                SetSceneManager(SceneType.ExteriorClose, defaultSceneManager);
                SetSceneManager(SceneType.ExteriorFar, defaultSceneManager);
                SetSceneManager(SceneType.Interior, defaultSceneManager);
                SetSceneManager(SceneType.Overhead, defaultSceneManager);
            }
        }
Пример #20
0
		public void OnLoad()
		{
			//ResourceGroupManager.Instance.AddResourceLocation("media", "Folder", true);

			_root.SceneManager = _sceneManager = _root.CreateSceneManager(SceneType.ExteriorClose);
			_sceneManager.ClearScene();

			_camera = _sceneManager.CreateCamera("MainCamera");

			_camera.Position = new Vector3(0, 0, 500);
			_camera.LookAt(new Vector3(0, 0, -300));
			_camera.Near = 5;
			_camera.AutoAspectRatio = true;
			_camera.FieldOfView = 0.70f;
			_viewport = _renderWindow.AddViewport(_camera, 0, 0, 1.0f, 1.0f, 100);
			_viewport.BackgroundColor = ColorEx.Black; ;

			_light = _sceneManager.CreateLight("light1");
			_light.Type = LightType.Directional;
			_light.Position = new Vector3(0, 150, 300);
			_light.Diffuse = ColorEx.Blue;
			_light.Specular = ColorEx.Blue;
			//_light.Direction = new Vector3(0, 0, -300);
			_sceneManager.AmbientLight = ColorEx.White;// new ColorEx(0.2f, 0.2f, 0.2f);

			ResourceGroupManager.Instance.InitializeAllResourceGroups();


			_inputReader = PlatformManager.Instance.CreateInputReader();
			_inputReader.Initialize(_renderWindow, true, true, false, false);

			_inputReader.UseKeyboardEvents = true;
			_inputReader.UseMouseEvents = false;

			//_renderItems.Add(new BasicCube());
			_renderItems.Add(new CubeBrowser());
			foreach (var i in _renderItems)
			{
				i.Initialise(_root);
			}
		}
Пример #21
0
        public Ship(SceneManager pSceneManager, Controller pController)
            : base(pController)
        {
            var name = Methods.GenerateUniqueID.ToString();

            Node = pSceneManager.RootSceneNode.CreateChildSceneNode(name);
            MeshNode = Node.CreateChildSceneNode();
            MeshNode.Orientation = new Quaternion(0.5, 0.5, -0.5, -0.5);
            MeshNode.AttachObject(pSceneManager.CreateEntity(name, "ship_assault_1.mesh"));

            UpgradeGroup = new UpgradeGroup
            {
                CannonAutoFire = { Level = 10 },
                CannonMultiFire = { Level = 10 },
                CannonSpeed = { Level = 7 },
                CannonPower = { Level = 5 }
            };

            cannon = new Cannon(this);
            UpgradeGroup.UpgradeCannon(ref cannon, UpgradeGroup);
        }
Пример #22
0
        public Arena(SceneManager pSceneManager, Int32 pScale, Int32 pNumAdditionalGrids)
        {
            var random = new Random();
            var topgrid = pSceneManager.CreateEntity("grid top", "grid.mesh");
            var topgridnode = pSceneManager.RootSceneNode.CreateChildSceneNode("grid top");

            topgridnode.Position = new Vector3(0, 0, -10);
            topgridnode.Orientation = Quaternion.FromAxes(Vector3.UnitX, Vector3.UnitZ, Vector3.NegativeUnitY);
            topgridnode.Scale = new Vector3(pScale, 1, pScale);
            topgridnode.AttachObject(topgrid);

            Width = (Int32)(topgrid.BoundingBox.Size.x * pScale);
            Height = (Int32)(topgrid.BoundingBox.Size.z * pScale);

            Right = Width / 2;
            Bottom = Height / 2;
            Left = -Right;
            Top = -Bottom;

            for (var i = 1; i <= pNumAdditionalGrids; i++)
            {
                var grid = pSceneManager.CreateEntity("grid" + i, "grid.mesh");
                var gridnode = pSceneManager.RootSceneNode.CreateChildSceneNode("grid" + i);

                gridnode.Position = new Vector3(
                    random.Next(-pScale / 5, pScale / 5),
                    random.Next(-pScale / 5, pScale / 5),
                    -10 - pScale * i / 10);
                gridnode.Orientation = Quaternion.FromAxes(
                    Vector3.UnitX,
                    Vector3.UnitZ,
                    Vector3.NegativeUnitY);
                gridnode.Scale = new Vector3(
                    pScale + i * random.Next(pScale / 8, pScale / 4),
                    1,
                    pScale + i * random.Next(pScale / 8, pScale / 4));
                gridnode.AttachObject(grid);
            }
        }
        public DisplayObject(IWorldObject parent, WorldEditor app, string name, string type, SceneManager scene, string meshName, Vector3 position, Vector3 scale, Vector3 rotation, SubMeshCollection subMeshCollection)
        {
            this.name = name;
            this.scene = scene;
            this.meshName = meshName;
            this.type = type;
            this.parent = parent;
            oidCounter++;
            this.oid = oidCounter;
            this.app = app;

            // if we were passed a subMeshCollection, then use it, otherwise make one.
            if (subMeshCollection == null)
            {
                this.subMeshCollection = new SubMeshCollection(meshName);
            }
            else
            {
                this.subMeshCollection = subMeshCollection;
            }

            AddToScene(position, scale, rotation);
        }
 protected void ChooseSceneManager()
 {
     scene = Root.Instance.SceneManagers.GetSceneManager(SceneType.ExteriorClose);
 }
Пример #25
0
		/// <summary>
		///		Destroys an instance of a SceneManager.
		/// </summary>
		/// <param name="instance"></param>
		public abstract void DestroyInstance( SceneManager instance );
Пример #26
0
		protected internal DefaultIntersectionSceneQuery( SceneManager creator )
			: base( creator )
		{
			// No world geometry results supported
			this.AddWorldFragmentType( WorldFragmentType.None );
		}
Пример #27
0
		protected internal DefaultPlaneBoundedVolumeListSceneQuery( SceneManager creator )
			: base( creator )
		{
			// No world geometry results supported
			this.AddWorldFragmentType( WorldFragmentType.None );
		}
Пример #28
0
			public ShadowCasterSceneQueryListener( SceneManager sceneManager )
			{
				this.sceneManager = sceneManager;
			}
Пример #29
0
		public override void DestroyInstance( SceneManager instance )
		{
			instance.ClearScene();
		}
Пример #30
0
		public BspSphereRegionSceneQuery( SceneManager creator )
			: base( creator )
		{
			AddWorldFragmentType( WorldFragmentType.PlaneBoundedRegion );
		}
Пример #31
0
 /* Standard Constructor */
 public Camera(string name, Axiom.Core.SceneManager creator) : base(name, creator)
 {
 }
Пример #32
0
 protected void ChooseSceneManager()
 {
     scene          = Root.Instance.SceneManagers.GetSceneManager(SceneType.ExteriorClose);
     DisplayTerrain = false;
 }