public override void CreateScene() { viewport.BackgroundColor = ColorEx.Black; scene.AmbientLight = ColorEx.Gray; Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 20, 80, 50 ); light.Diffuse = ColorEx.Blue; scene.LoadWorldGeometry( "JigLibX_Terrain.xml" ); scene.SetFog( FogMode.Exp2, ColorEx.White, .008f, 0, 250 ); // water plane setup Plane waterPlane = new Plane( Vector3.UnitY, 1.5f ); MeshManager.Instance.CreatePlane( "WaterPlane", ResourceGroupManager.DefaultResourceGroupName, waterPlane, 2800, 2800, 20, 20, true, 1, 10, 10, Vector3.UnitZ ); Entity waterEntity = scene.CreateEntity( "Water", "WaterPlane" ); waterEntity.MaterialName = "Terrain/WaterPlane"; waterNode = scene.RootSceneNode.CreateChildSceneNode( "WaterNode" ); //waterNode.AttachObject( waterEntity ); waterNode.Translate( new Vector3( 1000, 0, 1000 ) ); }
/// <summary> /// /// </summary> protected override void SetupContent() { SceneManager.SetSkyBox( true, "Examples/EveningSkyBox", 5000 ); // dim orange ambient and two bright orange lights to match the skybox SceneManager.AmbientLight = new ColorEx( 0.3f, 0.2f, 0.0f ); Light light = SceneManager.CreateLight( "Light1" ); light.Position = new Vector3( 2000, 1000, -1000 ); light.Diffuse = new ColorEx( 1.0f, 0.5f, 0.0f ); light = SceneManager.CreateLight( "Light2" ); light.Position = new Vector3( 2000, 1000, 1000 ); light.Diffuse = new ColorEx( 1.0f, 0.5f, 0.0f ); _pivot = SceneManager.RootSceneNode.CreateChildSceneNode(); // create a pivot node // create a child node and attach ogre head and some smoke to it SceneNode headNode = _pivot.CreateChildSceneNode( new Vector3( 100, 0, 0 ) ); headNode.AttachObject( SceneManager.CreateEntity( "Head", "ogrehead.mesh" ) ); headNode.AttachObject( ParticleSystemManager.Instance.CreateSystem( "Smoke", "Examples/Smoke" ) ); Camera.Position = new Vector3( 0.0f, 30.0f, 350.0f ); base.SetupContent(); }
public void TestRecreationOfChildNodeAfterRemovalByReference() { Node node = new SceneNode( this.fakeSceneManager ); Node childNode = node.CreateChild( Name ); node.RemoveChild( childNode ); node.CreateChild( Name ); }
public override void ClearScene() { base.ClearScene(); tiles = null; terrainMaterial = null; terrainRoot = null; }
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); } }
public void CreateScene() { _entity = _root.SceneManager.CreateEntity("BasicCube", PrefabEntity.Cube); _entity.MaterialName = "Examples/TestImage"; _sceneNode = Root.Instance.SceneManager.RootSceneNode.CreateChildSceneNode(); _sceneNode.Position = new Vector3(150, 0, -300); _sceneNode.AttachObject(_entity); _sceneNode.Yaw(45); }
public override void CreateScene() { if ( !Root.Instance.RenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) || !Root.Instance.RenderSystem.Capabilities.HasCapability( Capabilities.FragmentPrograms ) ) { throw new Exception( "Your hardware does not support vertex and fragment programs, so you cannot run this demo." ); } // create a simple default point light Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 20, 80, 50 ); rotNode = scene.RootSceneNode.CreateChildSceneNode(); rotNode.CreateChildSceneNode( new Vector3( 20, 40, 50 ), Quaternion.Identity ).AttachObject( light ); Entity entity = scene.CreateEntity( "Head", "ogrehead.mesh" ); camera.Position = new Vector3( 20, 0, 100 ); camera.LookAt( Vector3.Zero ); // eyes SubEntity subEnt = entity.GetSubEntity( 0 ); subEnt.MaterialName = "Examples/CelShading"; subEnt.SetCustomParameter( CustomShininess, new Vector4( 35.0f, 0.0f, 0.0f, 0.0f ) ); subEnt.SetCustomParameter( CustomDiffuse, new Vector4( 1.0f, 0.3f, 0.3f, 1.0f ) ); subEnt.SetCustomParameter( CustomSpecular, new Vector4( 1.0f, 0.6f, 0.6f, 1.0f ) ); // skin subEnt = entity.GetSubEntity( 1 ); subEnt.MaterialName = "Examples/CelShading"; subEnt.SetCustomParameter( CustomShininess, new Vector4( 10.0f, 0.0f, 0.0f, 0.0f ) ); subEnt.SetCustomParameter( CustomDiffuse, new Vector4( 0.0f, 0.5f, 0.0f, 1.0f ) ); subEnt.SetCustomParameter( CustomSpecular, new Vector4( 0.3f, 0.5f, 0.3f, 1.0f ) ); // earring subEnt = entity.GetSubEntity( 2 ); subEnt.MaterialName = "Examples/CelShading"; subEnt.SetCustomParameter( CustomShininess, new Vector4( 25.0f, 0.0f, 0.0f, 0.0f ) ); subEnt.SetCustomParameter( CustomDiffuse, new Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); subEnt.SetCustomParameter( CustomSpecular, new Vector4( 1.0f, 1.0f, 0.7f, 1.0f ) ); // teeth subEnt = entity.GetSubEntity( 3 ); subEnt.MaterialName = "Examples/CelShading"; subEnt.SetCustomParameter( CustomShininess, new Vector4( 20.0f, 0.0f, 0.0f, 0.0f ) ); subEnt.SetCustomParameter( CustomDiffuse, new Vector4( 1.0f, 1.0f, 0.7f, 1.0f ) ); subEnt.SetCustomParameter( CustomSpecular, new Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // add entity to the root scene node scene.RootSceneNode.CreateChildSceneNode().AttachObject( entity ); window.GetViewport( 0 ).BackgroundColor = ColorEx.White; }
/// <summary> /// /// </summary> protected override void SetupContent() { this.ptex = TextureManager.Instance.CreateManual( "DynaTex", ResourceGroupManager.DefaultResourceGroupName, TextureType.ThreeD, 64, 64, 64, 0, Media.PixelFormat.A8R8G8B8, TextureUsage.Default, null ); SceneManager.AmbientLight = new ColorEx( 0.6f, 0.6f, 0.6f ); SceneManager.SetSkyBox( true, "Examples/MorningSkyBox", 50 ); Light light = SceneManager.CreateLight( "VolumeTextureSampleLight" ); light.Diffuse = new ColorEx( 0.75f, 0.75f, 0.80f ); light.Specular = new ColorEx( 0.9f, 0.9f, 1 ); light.Position = new Vector3( -100, 80, 50 ); SceneManager.RootSceneNode.AttachObject( light ); // Create volume renderable this.snode = SceneManager.RootSceneNode.CreateChildSceneNode( Vector3.Zero ); this.vrend = new VolumeRendable( 32, 750, "DynaTex" ); this.snode.AttachObject( this.vrend ); this.trend = new ThingRendable( 90, 32, 7.5f ); this.trend.Material = (Material)MaterialManager.Instance.GetByName( "Examples/VTDarkStuff" ); this.trend.Material.Load(); this.snode.AttachObject( this.trend ); this.fnode = SceneManager.RootSceneNode.CreateChildSceneNode(); Entity head = SceneManager.CreateEntity( "head", "ogrehead.mesh" ); this.fnode.AttachObject( head ); Animation anim = SceneManager.CreateAnimation( "OgreTrack", 10 ); anim.InterpolationMode = InterpolationMode.Spline; NodeAnimationTrack track = anim.CreateNodeTrack( 0, this.fnode ); TransformKeyFrame key = track.CreateNodeKeyFrame( 0 ); key.Translate = new Vector3( 0, -15, 0 ); key = track.CreateNodeKeyFrame( 5 ); key.Translate = new Vector3( 0, 15, 0 ); key = track.CreateNodeKeyFrame( 10 ); key.Translate = new Vector3( 0, -15, 0 ); this.animState = SceneManager.CreateAnimationState( "OgreTrack" ); this.animState.IsEnabled = true; this.globalReal = 0.4f; this.globalImag = 0.6f; this.globalTheta = 0.0f; CreateControls(); DragLook = true; Generate(); }
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 Boundary(String name) { points = new List<Vector2>(); semantics = new List<IBoundarySemantic>(); touchedPages = new List<PageCoord>(); this.name = name; sceneNode = parentSceneNode.CreateChildSceneNode(name); pageSize = TerrainManager.Instance.PageSize; }
public WaterPlane(SceneNode parentSceneNode, XmlTextReader r) { FromXML(r); // create a scene node if (parentSceneNode == null) { parentSceneNode = TerrainManager.Instance.RootSceneNode; } waterSceneNode = parentSceneNode.CreateChildSceneNode(name); // set up material material = TerrainManager.Instance.WaterMaterial; }
protected override void CreateScene() { // set some ambient light scene.AmbientLight = ColorEx.Gray; // create an entity to have follow the path Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh"); // create a scene node for the entity and attach the entity SceneNode headNode = scene.RootSceneNode.CreateChildSceneNode(); headNode.AttachObject(ogreHead); // // create a cool glowing green particle system // ParticleSystem greenyNimbus = ParticleSystemManager.Instance.CreateSystem("GreenyNimbus", "ParticleSystems/GreenyNimbus"); // scene.RootSceneNode.CreateChildSceneNode().AttachObject(greenyNimbus); ParticleSystem fireworks = ParticleSystemManager.Instance.CreateSystem("Fireworks", "Examples/Fireworks"); scene.RootSceneNode.CreateChildSceneNode().AttachObject(fireworks); // shared node for the 2 fountains fountainNode = scene.RootSceneNode.CreateChildSceneNode(); // create the first fountain ParticleSystem fountain1 = ParticleSystemManager.Instance.CreateSystem("Fountain1", "Examples/PurpleFountain"); SceneNode node = fountainNode.CreateChildSceneNode(); node.Translate(new Vector3(200, -100, 0)); node.Rotate(Vector3.UnitZ, 20); node.AttachObject(fountain1); // create the second fountain ParticleSystem fountain2 = ParticleSystemManager.Instance.CreateSystem("Fountain2", "Examples/PurpleFountain"); node = fountainNode.CreateChildSceneNode(); node.Translate(new Vector3(-200, -100, 0)); node.Rotate(Vector3.UnitZ, -20); node.AttachObject(fountain2); // create a rainstorm ParticleSystem rain = ParticleSystemManager.Instance.CreateSystem("Rain", "Examples/Rain"); scene.RootSceneNode.CreateChildSceneNode(new Vector3(0, 1000, 0), Quaternion.Identity).AttachObject(rain); rain.FastForward(5.0f); // Aureola around Ogre perpendicular to the ground ParticleSystem pSys5 = ParticleSystemManager.Instance.CreateSystem("Aureola", "Examples/Aureola"); scene.RootSceneNode.CreateChildSceneNode().AttachObject(pSys5); // Set nonvisible timeout ParticleSystem.DefaultNonVisibleUpdateTimeout = 5; }
public WaterPlane(float height, String name, SceneNode parentSceneNode) { this.height = height; this.name = name; // create a scene node if (parentSceneNode == null) { parentSceneNode = TerrainManager.Instance.RootSceneNode; } waterSceneNode = parentSceneNode.CreateChildSceneNode(name); // set up material material = TerrainManager.Instance.WaterMaterial; CastShadows = false; }
public override void CreateScene() { // set some ambient light scene.AmbientLight = new ColorEx( 1.0f, 0.2f, 0.2f, 0.2f ); // create a skydome scene.SetSkyDome( true, "Examples/CloudySky", 5, 8 ); // create a simple default point light Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 20, 80, 50 ); // create a plane for the plane mesh Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 200; // create a plane mesh MeshManager.Instance.CreatePlane( "FloorPlane", ResourceGroupManager.DefaultResourceGroupName, plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ ); // create an entity to reference this mesh Entity planeEntity = scene.CreateEntity( "Floor", "FloorPlane" ); planeEntity.MaterialName = "Examples/RustySteel"; scene.RootSceneNode.CreateChildSceneNode().AttachObject( planeEntity ); // create an entity to have follow the path Entity ogreHead = scene.CreateEntity( "OgreHead", "ogrehead.mesh" ); // create a scene node for the entity and attach the entity headNode = scene.RootSceneNode.CreateChildSceneNode( "OgreHeadNode", Vector3.Zero, Quaternion.Identity ); headNode.AttachObject( ogreHead ); // make sure the camera tracks this node camera.SetAutoTracking( true, headNode, Vector3.Zero ); // create a scene node to attach the camera to SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode( "CameraNode" ); cameraNode.AttachObject( camera ); // turn on some fog scene.SetFog( FogMode.Exp, ColorEx.White, 0.0002f ); }
public override void CreateScene() { scene.AmbientLight = new ColorEx( .4f, .4f, .4f ); Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 50, 80, 0 ); Entity head = scene.CreateEntity( "OgreHead", "ogrehead.mesh" ); entityList.Add( head ); scene.RootSceneNode.CreateChildSceneNode().AttachObject( head ); Entity box = scene.CreateEntity( "Box1", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( -100, 0, 0 ), Quaternion.Identity ).AttachObject( box ); box = scene.CreateEntity( "Box2", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( 100, 0, -300 ), Quaternion.Identity ).AttachObject( box ); box = scene.CreateEntity( "Box3", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( -200, 100, -200 ), Quaternion.Identity ).AttachObject( box ); frustum = new Frustum( "PlayFrustum" ); frustum.Near = 10; frustum.Far = 300; // create a node for the frustum and attach it frustumNode = scene.RootSceneNode.CreateChildSceneNode( new Vector3( 0, 0, 200 ), Quaternion.Identity ); // set the camera in a convenient position camera.Position = new Vector3( 0, 759, 680 ); camera.LookAt( Vector3.Zero ); frustumNode.AttachObject( frustum ); frustumNode.AttachObject( camera2 ); }
/// <summary> /// Internal method for notifying the manager that a SceneNode is autotracking. /// </summary> /// <param name="node">Scene node that is auto tracking another scene node.</param> /// <param name="autoTrack">True if tracking, false if it is stopping tracking.</param> internal void NotifyAutoTrackingSceneNode( SceneNode node, bool autoTrack ) { if ( autoTrack ) { this.autoTrackingSceneNodes.Add( node ); } else { autoTrackingSceneNodes.Remove( node.Name ); } }
/// <summary> /// Enables / disables a 'sky plane' i.e. a plane at constant /// distance from the camera representing the sky. /// </summary> /// <param name="enable">True to enable the plane, false to disable it.</param> /// <param name="plane">Details of the plane, i.e. it's normal and it's distance from the camera.</param> /// <param name="materialName">The name of the material the plane will use.</param> /// <param name="scale">The scaling applied to the sky plane - higher values mean a bigger sky plane.</param> /// <param name="tiling">How many times to tile the texture across the sky.</param> /// <param name="drawFirst"> /// If true, the plane is drawn before all other geometry in the scene, without updating the depth buffer. /// This is the safest rendering method since all other objects /// will always appear in front of the sky. However this is not /// the most efficient way if most of the sky is often occluded /// by other objects. If this is the case, you can set this /// parameter to false meaning it draws <em>after</em> all other /// geometry which can be an optimisation - however you must /// ensure that the plane.d value is large enough that no objects /// will 'poke through' the sky plane when it is rendered. /// </param> /// <param name="bow"> /// If above zero, the plane will be curved, allowing /// the sky to appear below camera level. Curved sky planes are /// simular to skydomes, but are more compatable with fog. /// </param> /// <param name="groupName"></param> public virtual void SetSkyPlane( bool enable, Plane plane, string materialName, float scale, float tiling, bool drawFirst, float bow, string groupName ) { this.isSkyPlaneEnabled = enable; if ( enable ) { string meshName = "SkyPlane"; this.skyPlane = plane; Material m = (Material)MaterialManager.Instance[ materialName ]; if ( m == null ) { throw new AxiomException( string.Format( "Skyplane material '{0}' not found.", materialName ) ); } // make sure the material doesn't update the depth buffer m.DepthWrite = false; m.Load(); this.isSkyPlaneDrawnFirst = drawFirst; // set up the place Mesh planeMesh = (Mesh)MeshManager.Instance[ meshName ]; // unload the old one if it exists if ( planeMesh != null ) { MeshManager.Instance.Unload( planeMesh ); } // create up vector Vector3 up = plane.Normal.Cross( Vector3.UnitX ); if ( up == Vector3.Zero ) { up = plane.Normal.Cross( -Vector3.UnitZ ); } if ( bow > 0 ) { planeMesh = MeshManager.Instance.CreateCurvedIllusionPlane( meshName, groupName, plane, scale * 100, scale * 100, scale * bow * 100, 6, 6, false, 1, tiling, tiling, up ); } else { planeMesh = MeshManager.Instance.CreatePlane( meshName, groupName, plane, scale * 100, scale * 100, 1, 1, false, 1, tiling, tiling, up ); } if ( this.skyPlaneEntity != null ) { this.RemoveEntity( this.skyPlaneEntity ); } // create entity for the plane, using the mesh name this.skyPlaneEntity = CreateEntity( meshName, meshName ); this.skyPlaneEntity.MaterialName = materialName; // sky entities need not cast shadows this.skyPlaneEntity.CastShadows = false; if ( this.skyPlaneNode == null ) { this.skyPlaneNode = this.CreateSceneNode( meshName + "Node" ); } else { this.skyPlaneNode.DetachAllObjects(); } // attach the skyplane to the new node this.skyPlaneNode.AttachObject( this.skyPlaneEntity ); } }
/// <summary> /// </summary> public void SetSkyDome( bool isEnabled, string materialName, float curvature, float tiling, float distance, bool drawFirst, Quaternion orientation, string groupName ) { this.isSkyDomeEnabled = isEnabled; if ( isEnabled ) { Material material = (Material)MaterialManager.Instance[ materialName ]; if ( material == null ) { throw new AxiomException( string.Format( "Could not find skydome material '{0}'", materialName ) ); } // make sure the material doesn't update the depth buffer material.DepthWrite = false; // ensure loading material.Load(); this.isSkyDomeDrawnFirst = drawFirst; // create node if ( this.skyDomeNode == null ) { this.skyDomeNode = this.CreateSceneNode( "SkyDomeNode" ); } else { this.skyDomeNode.DetachAllObjects(); } // set up the dome (5 planes) for ( int i = 0; i < 5; ++i ) { Mesh planeMesh = this.CreateSkyDomePlane( (BoxPlane)i, curvature, tiling, distance, orientation, groupName ); string entityName = String.Format( "SkyDomePlane{0}", i ); // create entity if ( this.skyDomeEntities[ i ] != null ) { this.RemoveEntity( this.skyDomeEntities[ i ] ); } this.skyDomeEntities[ i ] = CreateEntity( entityName, planeMesh.Name ); this.skyDomeEntities[ i ].MaterialName = material.Name; // Sky entities need not cast shadows this.skyDomeEntities[ i ].CastShadows = false; // attach to node this.skyDomeNode.AttachObject( this.skyDomeEntities[ i ] ); } // for each plane } }
/// <summary> /// Enables / disables a 'sky box' i.e. a 6-sided box at constant /// distance from the camera representing the sky. /// </summary> /// <remarks> /// You could create a sky box yourself using the standard mesh and /// entity methods, but this creates a plane which the camera can /// never get closer or further away from - it moves with the camera. /// (you could create this effect by creating a world box which /// was attached to the same SceneNode as the Camera too, but this /// would only apply to a single camera whereas this skybox applies /// to any camera using this scene manager). /// <p/> /// The material you use for the skybox can either contain layers /// which are single textures, or they can be cubic textures, i.e. /// made up of 6 images, one for each plane of the cube. See the /// TextureLayer class for more information. /// </remarks> /// <param name="enable">True to enable the skybox, false to disable it</param> /// <param name="materialName">The name of the material the box will use.</param> /// <param name="distance">Distance in world coordinates from the camera to each plane of the box. </param> /// <param name="drawFirst"> /// If true, the box is drawn before all other /// geometry in the scene, without updating the depth buffer. /// This is the safest rendering method since all other objects /// will always appear in front of the sky. However this is not /// the most efficient way if most of the sky is often occluded /// by other objects. If this is the case, you can set this /// parameter to false meaning it draws <em>after</em> all other /// geometry which can be an optimisation - however you must /// ensure that the distance value is large enough that no /// objects will 'poke through' the sky box when it is rendered. /// </param> /// <param name="orientation"> /// Specifies the orientation of the box. By default the 'top' of the box is deemed to be /// in the +y direction, and the 'front' at the -z direction. /// You can use this parameter to rotate the sky if you want. /// </param> ///<param name="groupName"></param> public void SetSkyBox( bool enable, string materialName, float distance, bool drawFirst, Quaternion orientation, string groupName ) { // enable the skybox? this.isSkyBoxEnabled = enable; if ( enable ) { Material m = (Material)MaterialManager.Instance[ materialName ]; if ( m == null ) { this.isSkyBoxEnabled = false; throw new AxiomException( string.Format( "Could not find skybox material '{0}'", materialName ) ); } // Make sure the material doesn't update the depth buffer m.DepthWrite = false; // Ensure loaded m.Load(); // ensure texture clamping to reduce fuzzy edges when using filtering m.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ).SetTextureAddressingMode( TextureAddressing.Clamp ); this.isSkyBoxDrawnFirst = drawFirst; if ( this.skyBoxNode == null ) { this.skyBoxNode = this.CreateSceneNode( "SkyBoxNode" ); } else { this.skyBoxNode.DetachAllObjects(); } // need to create 6 plane entities for each side of the skybox for ( int i = 0; i < 6; i++ ) { Mesh planeModel = this.CreateSkyboxPlane( (BoxPlane)i, distance, orientation, groupName ); string entityName = "SkyBoxPlane" + i; if ( this.skyBoxEntities[ i ] != null ) { this.RemoveEntity( this.skyBoxEntities[ i ] ); } // create an entity for this plane this.skyBoxEntities[ i ] = CreateEntity( entityName, planeModel.Name ); // skyboxes need not cast shadows this.skyBoxEntities[ i ].CastShadows = false; // Have to create 6 materials, one for each frame // Used to use combined material but now we're using queue we can't split to change frame // This doesn't use much memory because textures aren't duplicated Material boxMaterial = (Material)MaterialManager.Instance[ entityName ]; if ( boxMaterial == null ) { // Create new by clone boxMaterial = m.Clone( entityName ); boxMaterial.Load(); } else { // Copy over existing //must not copy over the name, otherwise the sky box entity will be set to use the origional m material instead of the copy for each entity which each uses a different frame m.CopyTo( boxMaterial, false ); boxMaterial.Load(); } // set the current frame boxMaterial.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ).CurrentFrame = i; this.skyBoxEntities[ i ].MaterialName = boxMaterial.Name; // Attach to node this.skyBoxNode.AttachObject( this.skyBoxEntities[ i ] ); } // for each plane } }
/// <summary> /// Creates an instance of a SceneNode. /// </summary> /// <remarks> /// Note that this does not add the SceneNode to the scene hierarchy. /// This method is for convenience, since it allows an instance to /// be created for which the SceneManager is responsible for /// allocating and releasing memory, which is convenient in complex /// scenes. /// <p/> /// To include the returned SceneNode in the scene, use the AddChild /// method of the SceneNode which is to be it's parent. /// <p/> /// Note that this method takes no parameters, and the node created is unnamed (it is /// actually given a generated name, which you can retrieve if you want). /// If you wish to create a node with a specific name, call the alternative method /// which takes a name parameter. /// </remarks> /// <returns></returns> public virtual SceneNode CreateSceneNode() { SceneNode node = new SceneNode( this ); this.sceneNodeList.Add( node ); return node; }
public SceneManager( string name ) : base() { this.cameraList = new CameraCollection(); this.sceneNodeList = new SceneNodeCollection(); this.animationList = new AnimationCollection(); this.animationStateList = new AnimationStateSet(); this.regionList = new List<StaticGeometry.Region>(); this.shadowCasterQueryListener = new ShadowCasterSceneQueryListener( this ); // create the root scene node this.rootSceneNode = new SceneNode( this, "Root" ); this.rootSceneNode.SetAsRootNode(); this.defaultRootNode = this.rootSceneNode; this.name = name; // default to no fog this.fogMode = FogMode.None; // no shadows by default this.shadowTechnique = ShadowTechnique.None; // setup default shadow camera setup this._defaultShadowCameraSetup = new DefaultShadowCameraSetup(); this.illuminationStage = IlluminationRenderStage.None; this.renderingNoShadowQueue = false; this.renderingMainGroup = false; this.shadowColor.a = this.shadowColor.r = this.shadowColor.g = this.shadowColor.b = 0.25f; this.shadowDirLightExtrudeDist = 10000; this.shadowIndexBufferSize = 51200; this.shadowTextureOffset = 0.6f; this.shadowTextureFadeStart = 0.7f; this.shadowTextureFadeEnd = 0.9f; this.shadowTextureSize = 512; this.shadowTextureCount = 1; this.findVisibleObjects = true; this.suppressRenderStateChanges = false; this.suppressShadows = false; this.shadowUseInfiniteFarPlane = true; }
/// <summary> /// Empties the entire scene, inluding all SceneNodes, Entities, Lights, /// BillboardSets etc. Cameras are not deleted at this stage since /// they are still referenced by viewports, which are not destroyed during /// this process. /// </summary> public virtual void ClearScene() { DestroyAllStaticGeometry(); this.DestroyAllMovableObjects(); if ( this.rootSceneNode != null ) { this.rootSceneNode.RemoveAllChildren(); this.rootSceneNode.DetachAllObjects(); } // Delete all SceneNodes, except root that is foreach ( Node node in sceneNodeList ) { foreach ( SceneNode currentNode in this.sceneNodeList.Values ) { if ( !currentNode.IsDisposed ) currentNode.Dispose(); } } this.sceneNodeList.Clear(); if ( this.autoTrackingSceneNodes != null ) { this.autoTrackingSceneNodes.Clear(); } // Clear animations this.DestroyAllAnimations(); // Remove sky nodes since they've been deleted this.skyBoxNode = this.skyPlaneNode = this.skyDomeNode = null; this.isSkyBoxEnabled = this.isSkyPlaneEnabled = this.isSkyDomeEnabled = false; if ( renderQueue != null ) renderQueue.Clear(); }
public PCZone( PCZSceneManager creator, string name ) { this.mLastVisibleFrame = 0; LastVisibleFromCamera = null; this.mName = name; this.mZoneTypeName = "ZoneType_Undefined"; this.mEnclosureNode = null; this.mPCZSM = creator; HasSky = false; }
public void Build(bool stencilShadows, int logLevel) { // Create a node this.node = this.sceneMgr.RootSceneNode.CreateChildSceneNode(name, this.center); this.node.AttachObject(this); // We need to create enough LOD buckets to deal with the highest LOD // we encountered in all the meshes queued for (ushort lod = 0; lod < this.lodValues.Count; ++lod) { var lodBucket = new LODBucket(this, lod, (float)this.lodValues[lod]); this.lodBucketList.Add(lodBucket); // Now iterate over the meshes and assign to LODs // LOD bucket will pick the right LOD to use IEnumerator iter = this.queuedSubMeshes.GetEnumerator(); while (iter.MoveNext()) { var qsm = (QueuedSubMesh)iter.Current; lodBucket.Assign(qsm, lod); } // now build lodBucket.Build(stencilShadows, logLevel); } // Do we need to build an edge list? if (stencilShadows) { var eb = new EdgeListBuilder(); //int vertexSet = 0; foreach (var lod in this.lodBucketList) { foreach (var mat in lod.MaterialBucketMap.Values) { // Check if we have vertex programs here var t = mat.Material.GetBestTechnique(); if (null != t) { var p = t.GetPass(0); if (null != p) { if (p.HasVertexProgram) { this.vertexProgramInUse = true; } } } foreach (var geom in mat.GeometryBucketList) { // Check we're dealing with 16-bit indexes here // Since stencil shadows can only deal with 16-bit // More than that and stencil is probably too CPU-heavy // in any case if (geom.IndexData.indexBuffer.Type != IndexType.Size16) { throw new AxiomException("Only 16-bit indexes allowed when using stencil shadows"); } eb.AddVertexData(geom.VertexData); eb.AddIndexData(geom.IndexData); } } } this.edgeList = eb.Build(); } }
/// <summary> /// If set, only the selected node is rendered. /// To render all nodes, set to null. /// </summary> /// public void OverrideRootSceneNode( SceneNode node ) { this.rootSceneNode = node; }
public void RestoreRootSceneNode() { this.rootSceneNode = this.defaultRootNode; }
/// <summary> /// Destroys and removes a node from the scene. /// </summary> /// <param name="node">A SceneNode</param> public virtual void DestroySceneNode( SceneNode node ) { DestroySceneNode( node, true ); }
/// <summary> /// /// </summary> /// <param name="disposeManagedResources"></param> protected override void dispose( bool disposeManagedResources ) { if ( !this.IsDisposed ) { if ( disposeManagedResources ) { this.ClearScene(); this.RemoveAllCameras(); if ( op != null ) { if ( !op.IsDisposed ) op.Dispose(); op = null; } if ( this.autoParamDataSource != null ) { if ( !this.autoParamDataSource.IsDisposed ) this.autoParamDataSource.Dispose(); this.autoParamDataSource = null; } if ( this.rootSceneNode != null ) { if ( !this.rootSceneNode.IsDisposed ) this.rootSceneNode.Dispose(); this.rootSceneNode = null; } } } base.dispose( disposeManagedResources ); }
/// <summary> /// Internal method to destroy and remove a node from the scene. /// Do not remove from parent by option. /// </summary> /// <param name="node"></param> /// <param name="removeFromParent"></param> internal void DestroySceneNode( SceneNode node, bool removeFromParent ) { // Find any scene nodes which are tracking this node, and turn them off. foreach ( SceneNode autoNode in this.autoTrackingSceneNodes.Values ) { // Tracking this node if ( autoNode.AutoTrackTarget == node ) { // turn off, this will notify SceneManager to remove autoNode.SetAutoTracking( false ); } else if ( autoNode == node ) { // node being removed is a tracker autoTrackingSceneNodes.Remove( name ); } } if ( removeFromParent && node.Parent != null ) { node.Parent.RemoveChild( node ); } // removes the node from the list sceneNodeList.Remove( node.Name ); }
/// <summary> /// Creates an instance of a SceneNode with a given name. /// </summary> /// <remarks> /// Note that this does not add the SceneNode to the scene hierarchy. /// This method is for convenience, since it allows an instance to /// be created for which the SceneManager is responsible for /// allocating and releasing memory, which is convenient in complex /// scenes. /// <p/> /// To include the returned SceneNode in the scene, use the AddChild /// method of the SceneNode which is to be it's parent. /// <p/> /// Note that this method takes a name parameter, which makes the node easier to /// retrieve directly again later. /// </remarks> /// <returns></returns> public virtual SceneNode CreateSceneNode( string name ) { SceneNode node = new SceneNode( this, name ); this.sceneNodeList.Add( node ); return node; }
public void RekeySceneNode( string oldName, SceneNode node ) { if ( this.sceneNodeList[ oldName ] == node ) { this.sceneNodeList.Remove( oldName ); this.sceneNodeList.Add( node ); } }