/// <summary> /// Draws the component. /// </summary> /// <param name="caller">Entity calling the draw operation.</param> public override void Draw(BaseEntity caller) { // Do nothing if no static geometry if (staticGeometry == null) { return; } // Do nothing if no batches or component is disabled if (staticGeometry.StaticBatches == null || !enabled) { return; } // Calculate world matrix Matrix worldMatrix = matrix * caller.Matrix; // Set transforms core.ModelManager.ModelEffect_World = worldMatrix; core.ModelManager.ModelEffect_View = core.ActiveScene.Camera.ViewMatrix; core.ModelManager.ModelEffect_Projection = core.ActiveScene.Camera.ProjectionMatrix; // Set buffers core.GraphicsDevice.SetVertexBuffer(staticGeometry.VertexBuffer); core.GraphicsDevice.Indices = staticGeometry.IndexBuffer; // Draw batches foreach (var item in staticGeometry.StaticBatches) { // Apply material BaseMaterialEffect materialEffect = core.MaterialManager.GetMaterialEffect(item.Key); materialEffect.Apply(); // Render geometry foreach (EffectPass pass in materialEffect.Effect.CurrentTechnique.Passes) { // Apply effect pass pass.Apply(); // Draw primitives core.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, staticGeometry.VertexBuffer.VertexCount, item.Value.StartIndex, item.Value.PrimitiveCount); } } }
/// <summary> /// Draws component. /// </summary> /// <param name="caller">Entity calling the draw operation.</param> public override void Draw(BaseEntity caller) { // Do nothing if disabled or no model data if (!enabled || modelData == null) { return; } // Exit if model data is empty if (modelData.SubMeshes == null) { return; } // Calculate world matrix Matrix worldMatrix = matrix * caller.Matrix; // Set transforms core.ModelManager.ModelEffect_World = worldMatrix; core.ModelManager.ModelEffect_View = core.ActiveScene.Camera.ViewMatrix; core.ModelManager.ModelEffect_Projection = core.ActiveScene.Camera.ProjectionMatrix; // Set buffers core.GraphicsDevice.SetVertexBuffer(modelData.VertexBuffer); core.GraphicsDevice.Indices = modelData.IndexBuffer; // Draw batches foreach (var sm in modelData.SubMeshes) { // Apply material BaseMaterialEffect materialEffect = core.MaterialManager.GetMaterialEffect(sm.MaterialKey); materialEffect.Apply(); // Render geometry foreach (EffectPass pass in materialEffect.Effect.CurrentTechnique.Passes) { // Apply effect pass pass.Apply(); // Draw indexed primitives core.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, modelData.VertexBuffer.VertexCount, sm.StartIndex, sm.PrimitiveCount); } } }