CreateManualObject() public method

Create a ManualObject, an object which you populate with geometry manually through a GL immediate-mode style interface.
public CreateManualObject ( string name ) : ManualObject
name string /// The name to be given to the object (must be unique). ///
return ManualObject
Esempio n. 1
0
		public ManualObject createRoom( SceneManager scene,
												   string name,
												   short doorFlags,
												   bool isEnclosure,
												   Vector3 dimensions,
												   Vector3 doorDimensions )
		{
			addMaterial( name, new ColorEx( .75f, 1f, 1f, 1f ), SceneBlendType.TransparentAlpha );

			ManualObject room = scene.CreateManualObject( name );

			room.Begin( name, OperationType.TriangleList );

			// create points
			createPoints( dimensions, doorDimensions );

			float fade = .5f;
			float solid = .8f;
			ColorEx color = new ColorEx( solid, 0, solid, 0 );

			// copy to room
			for ( int i = 0; i < 32; i++ )
			{
				room.Position( points[ i ] );
				room.Color( color );
			}

			createWalls( room, doorFlags, isEnclosure );

			room.End();

			return room;
		}
        /// <summary>
        /// Helper method to render a composite map.
        /// </summary>
        /// <param name="size"> The requested composite map size</param>
        /// <param name="rect"> The region of the composite map to update, in image space</param>
        /// <param name="mat">The material to use to render the map</param>
        /// <param name="destCompositeMap"></param>
        public virtual void RenderCompositeMap(int size, Rectangle rect,
            Material mat, Texture destCompositeMap)
        {
            //return;
            if (mCompositeMapSM == null)
            {
                //dedicated SceneManager

                mCompositeMapSM = Root.Instance.CreateSceneManager(SceneType.ExteriorClose, "TerrainMaterialGenerator_SceneManager");
                float camDist = 100;
                float halfCamDist = camDist * 0.5f;
                mCompositeMapCam = mCompositeMapSM.CreateCamera("TerrainMaterialGenerator_Camera");
                mCompositeMapCam.Position = new Vector3(0, 0, camDist);
                //mCompositeMapCam.LookAt(Vector3.Zero);
                mCompositeMapCam.ProjectionType = Projection.Orthographic;
                mCompositeMapCam.Near = 10;
                mCompositeMapCam.Far = 999999* 3;
                //mCompositeMapCam.AspectRatio = camDist / camDist;
                mCompositeMapCam.SetOrthoWindow(camDist, camDist);
                // Just in case material relies on light auto params
                mCompositeMapLight = mCompositeMapSM.CreateLight("TerrainMaterialGenerator_Light");
                mCompositeMapLight.Type = LightType.Directional;

                RenderSystem rSys = Root.Instance.RenderSystem;
                float hOffset = rSys.HorizontalTexelOffset / (float)size;
                float vOffset = rSys.VerticalTexelOffset / (float)size;

                //setup scene
                mCompositeMapPlane = mCompositeMapSM.CreateManualObject("TerrainMaterialGenerator_ManualObject");
                mCompositeMapPlane.Begin(mat.Name, OperationType.TriangleList);
                mCompositeMapPlane.Position(-halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Position(-halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Quad(0, 1, 2, 3);
                mCompositeMapPlane.End();
                mCompositeMapSM.RootSceneNode.AttachObject(mCompositeMapPlane);
            }//end if

            // update
            mCompositeMapPlane.SetMaterialName(0, mat.Name);
            mCompositeMapLight.Direction = TerrainGlobalOptions.LightMapDirection;
            mCompositeMapLight.Diffuse = TerrainGlobalOptions.CompositeMapDiffuse;
            mCompositeMapSM.AmbientLight =TerrainGlobalOptions.CompositeMapAmbient;
            

            //check for size change (allow smaller to be reused)
            if (mCompositeMapRTT != null && size != mCompositeMapRTT.Width)
            {
                TextureManager.Instance.Remove(mCompositeMapRTT);
                mCompositeMapRTT = null;
            }
            if (mCompositeMapRTT == null)
            {
                mCompositeMapRTT = TextureManager.Instance.CreateManual(
                    mCompositeMapSM.Name + "/compRTT",
                    ResourceGroupManager.DefaultResourceGroupName,
                    TextureType.TwoD,
                    size,
                    size,
                    0,
                    PixelFormat.BYTE_RGBA,
                    TextureUsage.RenderTarget);

                RenderTarget rtt = mCompositeMapRTT.GetBuffer().GetRenderTarget();
                // don't render all the time, only on demand
                rtt.IsAutoUpdated = false;
                Viewport vp = rtt.AddViewport(mCompositeMapCam);
                // don't render overlays
                vp.ShowOverlays = false;
            }

            // calculate the area we need to update
            float vpleft = (float)rect.Left / (float)size;
            float vptop = (float)rect.Top / (float)size;
            float vpright = (float)rect.Right / (float)size;
            float vpbottom = (float)rect.Bottom / (float)size;
            float vpwidth = (float)rect.Width / (float)size;
            float vpheight = (float)rect.Height / (float)size;

            RenderTarget rtt2 = mCompositeMapRTT.GetBuffer().GetRenderTarget();
            Viewport vp2 = rtt2.GetViewport(0);
            mCompositeMapCam.SetWindow(vpleft, vptop, vpright, vpbottom);
            rtt2.Update();
            vp2.Update();
            // We have an RTT, we want to copy the results into a regular texture
            // That's because in non-update scenarios we don't want to keep an RTT
            // around. We use a single RTT to serve all terrain pages which is more
            // efficient.
            BasicBox box = new BasicBox((int)rect.Left, (int)rect.Top, (int)rect.Right, (int)rect.Bottom);
            destCompositeMap.GetBuffer().Blit(mCompositeMapRTT.GetBuffer(), box, box);
        }