Exemple #1
0
void LodManager::loadLod(Ogre::MeshPtr mesh, const LodDefinition& def)
{
    if (def.getUseAutomaticLod()) {
        loadAutomaticLod(mesh);
    } else if (def.getLodDistanceCount() == 0) {
        mesh->removeLodLevels();
        return;
    } else {
        Ogre::LodStrategy* strategy;
        if (def.getStrategy() == LodDefinition::LS_DISTANCE) {
            strategy = &Ogre::DistanceLodStrategy::getSingleton();
        } else {
            strategy = &Ogre::PixelCountLodStrategy::getSingleton();
        }
        mesh->setLodStrategy(strategy);

        if (def.getType() == LodDefinition::LT_AUTOMATIC_VERTEX_REDUCTION) {
            // Automatic vertex reduction
            LodConfig lodConfig;
            lodConfig.mesh = mesh;
            const LodDefinition::LodDistanceMap& data = def.getManualLodData();
            if (def.getStrategy() == LodDefinition::LS_DISTANCE) {
                // TODO: Use C++11 lambda, instead of template.
                loadAutomaticLodImpl(data.begin(), data.end(), lodConfig);
            } else {
                loadAutomaticLodImpl(data.rbegin(), data.rend(), lodConfig);
            }
            // Uncomment the ProgressiveMesh of your choice.
            // NOTE: OgreProgressiveMeshExt doesn't support collapse cost based reduction.
            // OgreProgressiveMeshExt pm;
            // ProgressiveMeshGenerator pm;
            QueuedProgressiveMeshGenerator pm;
            pm.build(lodConfig);
        } else {
            // User created Lod

            mesh->removeLodLevels();

            const LodDefinition::LodDistanceMap& data = def.getManualLodData();
            if (def.getStrategy() == LodDefinition::LS_DISTANCE) {
                // TODO: Use C++11 lambda, instead of template.
                loadUserLodImpl(data.begin(), data.end(), mesh.get());
            } else {
                loadUserLodImpl(data.rbegin(), data.rend(), mesh.get());
            }
        }
    }
}