Quantcast
Channel: directxtk Wiki Rss Feed
Viewing all articles
Browse latest Browse all 874

Updated Wiki: ModelMesh

$
0
0
This class is part of the Model hierarchy. The primary purpose of this class is to be a shared container for a list of ModelMeshPart instances which are referenced by one or more instances of the Model class.

Initialization

ModelMesh instances are typically created by a Model loader along with the ModelMeshPart instances that make up the mesh.

Simple drawing

Use the Model::Draw function which will call ModelMesh::Draw on all the meshes it contains.

Advanced drawing

The ModelMesh::Draw method draws the mesh in two passes. In the first pass, all 'opaque' ModelMeshPart instances are drawn (i.e. ModelMeshPart::isAlpha is false), and in the second pass all 'alpha' instances are drawn (i.e. ModelMeshPart::isAlpha is true).

The Draw method assumes that the proper blend state, depth/stencil state, rasterizer state, and sampler state have been set up before being called. The ModelMesh::PrepareForRendering method can be used to set up standard defaults via CommonStates or it can be skipped in favor of custom state setting.
  • The opaque pass is drawn using Opaque() blending, DepthDefault() sorting, an optional wireframe mode or a winding mode based on ModelMesh::ccw.
  • The alpha pass is drawn using alpha blending, DepthRead() sorting, an optional wireframe mode or a winding mode based on ModelMesh::ccw. The choice of alpha blending is based on ModelMesh::pmalpha to select between AlphaBlend() and NonPremultiplied().
ModelMesh::Draw can be used to implement alternate 'scene graph' policies.

// Rather than draw each model's opaque and then alpha parts in turn, this version// draws all the models' opaque parts first then all the alpha parts second which// can be important for some complex scenes.

std::list<std::unique_ptr<Model>> models;

...

// Draw opaque partsfor( auto mit = models.cbegin(); mit != models.cend(); ++mit )
{
    auto model = mit->get();
    assert( model != 0 );

    for( auto it = model->meshes.cbegin(); it != model->meshes.cend(); ++it )
    {
        auto mesh = it->get();
        assert( mesh != 0 );

        mesh->PrepareForRendering( deviceContext, states, false );

        mesh->Draw( deviceContext, world, view, projection, false );
    }
}

// Draw alpha partsfor( auto mit = models.cbegin(); mit != models.cend(); ++mit )
{
    auto model = mit->get();
    assert( model != 0 );

    for( auto it = model->meshes.cbegin(); it != model->meshes.cend(); ++it )
    {
        auto mesh = it->get();
        assert( mesh != 0 );

        mesh->PrepareForRendering( deviceContext, states, true );

        mesh->Draw( deviceContext, world, view, projection, true );
    }
}

!Metadata
In addition to the list of ModelMeshPart instances that make up the mesh, a ModelMesh also includes a name (a wide-character string) for tracking and application logic.

It includes a bool to indicate if the mesh should be rendered using counter-clockwise winding or clockwise winding (ccw), as well as a bool to indicate if the mesh should be rendered with premultiplied alpha blending or 'straight' alpha blending (pmalpha).

A ModelMesh also includes bounding information for culling & collision detection in the form of a BoundingSphere and a BoundingBox.

http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.directxcollision.boundingsphere.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.directxcollision.boundingbox.aspx

Viewing all articles
Browse latest Browse all 874

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>