|
?槭颤N我必?以"Render all mesh parts"去取代mesh.Draw();才看得到3D model
如果我用mesh.Draw()去??3D model的?,??床灰?任何?|西
所以我想知道
mesh.Draw();
和
// Render all mesh parts
foreach (ModelMeshPart part in mesh.MeshParts)
{
// Render data our own way
my_device.Vertices[0].SetSource(
mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
my_device.Indices = mesh.IndexBuffer;
// And render
my_device.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
part.BaseVertex, 0, part.NumVertices,
part.StartIndex, part.PrimitiveCount);
} // foreach
?烧哂泻尾?e?
如果我要用effect file的?,一定要用"Render all mesh parts"的?去呈?3D model??不可以用mesh.Draw()??
private Effect mfx = null; // shader object
Model myModel;
protected override void Initialize()
{
mfx = content.Load<Effect>(@"Content\Ambient");
mfx.CurrentTechnique = mfx.Techniques["TShader"];
// set vertex format
mVertPosColor = new VertexDeclaration(graphics.GraphicsDevice,
VertexPositionColor.VertexElements);
graphics.GraphicsDevice.VertexDeclaration = mVertPosColor;
// Remember device
my_device = graphics.GraphicsDevice;
base.Initialize();
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
if (mfx == null)
return;
// Copy any parent transforms.
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
// Draw the model. A model can have multiple meshes, so loop.
Matrix MatWorld;
Matrix MatView;
Matrix MatProj;
mfx.Begin();
foreach (EffectPass pass in mfx.CurrentTechnique.Passes)
{
pass.Begin();
// Render all meshes
foreach (ModelMesh mesh in myModel.Meshes)
{
MatWorld = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)
* Matrix.CreateTranslation(modelPosition);
MatView = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
MatProj = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
mfx.Parameters["matWorldViewProj"].SetValue(MatWorld * MatView * MatProj);
//mesh.Draw();<=======================problem
// Render all mesh parts
foreach (ModelMeshPart part in mesh.MeshParts)
{
// Render data our own way
my_device.Vertices[0].SetSource(
mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
my_device.Indices = mesh.IndexBuffer;
// And render
my_device.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
part.BaseVertex, 0, part.NumVertices,
part.StartIndex, part.PrimitiveCount);
} // foreach
} // foreach
pass.End();
} // for
mfx.End();
base.Draw(gameTime);
}
|
|