public void ExtractLightmaps()
{
chunk.Seek( header.lumps[ (int)Quake3LumpType.Lightmaps ].offset, SeekOrigin.Begin );
int numLightmaps = header.lumps[ (int)Quake3LumpType.Lightmaps ].size / BspLevel.LightmapSize;
// Lightmaps are always 128x128x24 (RGB).
for ( int i = 0; i < numLightmaps; i++ )
{
string name = String.Format( "@lightmap{0}", i );
byte[] buffer = new byte[ BspLevel.LightmapSize ];
chunk.Read( buffer, 0, BspLevel.LightmapSize );
// Load, no mipmaps, brighten by factor 4
// Set gamma explicitly, OpenGL doesn't apply it
// CHECK: Make OpenGL apply gamma at LoadImage
Image.ApplyGamma( buffer, 4, buffer.Length, 24 );
MemoryStream stream = new MemoryStream( buffer );
Image img = Image.FromRawStream( stream, 128, 128, PixelFormat.R8G8B8 );
TextureManager.Instance.LoadImage( name, ResourceGroupManager.Instance.WorldResourceGroupName, img, TextureType.TwoD );
}
}
/// <summary> /// /** Internal utility function for loading data from Quake3. /// </summary> protected void LoadQuake3Level(Quake3Level q3lvl) { SceneManager sm = SceneManagerEnumerator.Instance.GetSceneManager(SceneType.Interior); LoadEntities(q3lvl); Quake3ShaderManager.Instance.ParseAllSources(".shader"); q3lvl.ExtractLightmaps(); LoadLevelVertices(q3lvl); LoadLevelFaces(q3lvl); // now build patch information BuildQuake3Patches(q3lvl.NumVertices, q3lvl.NumElements); //----------------------------------------------------------------------- // Create materials for shaders //----------------------------------------------------------------------- CreateShaderMaterials(q3lvl, sm); //----------------------------------------------------------------------- // Nodes //----------------------------------------------------------------------- CreateNodes(q3lvl); //----------------------------------------------------------------------- // Brushes //----------------------------------------------------------------------- CreateBrushes(q3lvl); //----------------------------------------------------------------------- // Leaves //----------------------------------------------------------------------- CreateLeaves(q3lvl); // Vis - just copy visData.numClusters = q3lvl.VisData.clusterCount; visData.rowLength = q3lvl.VisData.rowSize; visData.tableData = new byte[q3lvl.VisData.rowSize * q3lvl.VisData.clusterCount]; Array.Copy(q3lvl.VisData.data, 0, visData.tableData, 0, visData.tableData.Length); }