void MaxAWDExporter::CreateDarkLights(){
    if((!opts->IncludeLights())||(!opts->ApplyDarkLight()))
        return;
    AWDMaterial *block;
    AWDBlockIterator *it;
    AWDBlockList * matBlockList = (AWDBlockList *)awd->get_material_blocks();
    if (matBlockList!=NULL){
        if (matBlockList->get_num_blocks()>0){
            it = new AWDBlockIterator(matBlockList);
            while ((block = (AWDMaterial * ) it->next()) != NULL) {
                if(block->get_lightPicker()==NULL){
                    AWDLightPicker * darkLightPicker = awd->CreateDarkLightPicker();
                    if (darkLightPicker!=NULL)
                        block->set_lightPicker(darkLightPicker);
                }
                AWDBlockIterator *itClones;
                AWDMaterial *cloneBlock;
                AWDBlockList * thisBlockList = (AWDBlockList *)block->get_materialClones();
                if((thisBlockList!=NULL)&&(thisBlockList->get_num_blocks()>0)){
                    itClones = new AWDBlockIterator(thisBlockList);
                    while ((cloneBlock = (AWDMaterial * ) it->next()) != NULL) {
                        if(cloneBlock->get_lightPicker()==NULL){
                            AWDLightPicker * darkLightPickerClone = awd->CreateDarkLightPicker();
                            if (darkLightPickerClone!=NULL)
                                cloneBlock->set_lightPicker(darkLightPickerClone);
                        }
                    }
                    delete itClones;
                }
            }
            delete it;
        }
    }
}
void MaxAWDExporter::ProcessGeoBlocks()
{
    AWDTriGeom *geoBlock;
    AWDBlockIterator *it;
    int proccessed=0;
    it = new AWDBlockIterator(awd->get_mesh_data_blocks());
    UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks());
    INodeTab lNodes;
    while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){
        INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock);
        if (node==NULL){
            AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry.");
            awd->get_message_blocks()->append(newWarning);
            return;
        }
        lNodes.AppendNode( node );
    }

    IGameScene* _pIgame = NULL;
    _pIgame = GetIGameInterface();
    _pIgame->InitialiseIGame( lNodes );
    it->reset();
    while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){
        INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock);
        if (node==NULL){
            AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry.");
            awd->get_message_blocks()->append(newWarning);
        }
        else{
            int exportThis=false;
            IGameObject * gobj = NULL;
            IGameMesh * igame_mesh = NULL;
            gobj = GetIGameInterface()->GetIGameNode(node)->GetIGameObject();
            if(gobj->GetIGameType()==IGameObject::IGAME_MESH){
                igame_mesh = (IGameMesh*)gobj;
                if (igame_mesh!=NULL){
                    igame_mesh->InitializeData();
                    if(igame_mesh->GetNumberOfFaces()>0){
                        exportThis=true;
                    }
                }
            }
            if (exportThis){
                Object *obj;
                obj = node->GetObjectRef();
                int skinIdx;
                ObjectState os;
                IDerivedObject *derivedObject = NULL;
                skinIdx = IndexOfSkinMod(node->GetObjectRef(), &derivedObject);
                if (skinIdx >= 0) {
                    // Flatten all modifiers up to but not including
                    // the skin modifier.
                    // to do: get the correct time for the neutral-pose
                    os = derivedObject->Eval(0, skinIdx + 1);
                }
                else {
                    // Flatten entire modifier stack
                    // to do: get the correct time for the neutral-pose
                    os = node->EvalWorldState(maxInterface->GetTime());
                }
                obj = os.obj;
                ISkin *skin = NULL;
                if (derivedObject != NULL && skinIdx >= 0) {
                    Modifier *mod = derivedObject->GetModifier(skinIdx);
                    skin = (ISkin *)mod->GetInterface(I_SKIN);
                }
                ExportTriGeom(geoBlock,obj,node,skin, igame_mesh);
                RETURN_IF_ERROR;
            }
        }
        proccessed++;
        UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks());
    }
    delete it;
    _pIgame->ReleaseIGame();
}