private void CreateInstanceGeom()
{
if ( Root.Instance.RenderSystem.HardwareCapabilities.HasCapability( Capabilities.VertexPrograms ) == false )
{
throw new AxiomException( "Your video card doesn't support batching" );
}
Entity ent = SceneManager.CreateEntity( meshes[ this.mSelectedMesh ], meshes[ this.mSelectedMesh ] + ".mesh" );
this.renderInstance = new List<InstancedGeometry>( this.mNumRendered );
//Load a mesh to read data from.
var batch = new InstancedGeometry( SceneManager, meshes[ this.mSelectedMesh ] + "s" );
batch.CastShadows = true;
batch.BatchInstanceDimensions = new Vector3( 1000000f, 1000000f, 1000000f );
int batchSize = ( this.mNumMeshes > maxObjectsPerBatch ) ? maxObjectsPerBatch : this.mNumMeshes;
SetupInstancedMaterialToEntity( ent );
for ( int i = 0; i < batchSize; i++ )
{
batch.AddEntity( ent, Vector3.Zero );
}
batch.Origin = Vector3.Zero;
batch.Build();
for ( int k = 0; k < this.mNumRendered - 1; k++ )
{
batch.AddBatchInstance();
}
k = 0;
foreach ( var batchInstance in batch.BatchInstances )
{
int j = 0;
foreach ( var instancedObject in batchInstance.Objects )
{
instancedObject.Position = this.posMatrices[ k ][ j ];
++j;
}
k++;
}
batch.IsVisible = true;
this.renderInstance[ 0 ] = batch;
SceneManager.RemoveEntity( ent );
}