Exemplo n.º 1
0
	 void CLocalSplitMapSaver::SaveAsAudio()
	 {
		 string strSaveAudioFile = m_strMapPathName + ".audio";

		 //save .audio file 
		 COperator *pOperator = CMapEditApp::GetInst()->GetOperator();

		 locale loc = locale::global(locale(""));
		 FILE * fp = NULL;
		 fp = fopen(strSaveAudioFile.c_str(),"wb");

		 if (!fp)
		 {
			 string log = strSaveAudioFile + "无法保存";
			 MessageBox(NULL,log.c_str(),"提示",MB_OK);
			 return;
		 }
		 else
		 {
			 DWORD version = AUDIO_PLAYTIME_INTERVAL;
			 fwrite(&version, sizeof(version), 1, fp);

			 //////////////////////////////////////////////////////////////////////////
			 ///save cue name
			 int nNameLen = 0;
			 int nGridCnt   = terrain->GetGridCount(), nSaveGridIndex = 0;
			 string strCueName = "";
			 size_t dwLen = 0;
			 set<int> nGrindIndexs;
			 map<int, int>::iterator splitRevertGriditer, splitGriditer;

			 for( int i = 0; i < nGridCnt; ++i )
			 {
				 SGrid * pGrid = &terrain->GetGrid(i);
				 if ( !pGrid->vecCenterObjects.empty() )
				 {
					 for ( vector< CTObjectPtr >::iterator iter = pGrid->vecCenterObjects.begin(); iter != pGrid->vecCenterObjects.end(); ++iter)
					 {
						 CTObjectPtr p = (*iter);

						 CEditModelGroup *pModelGroup = p->GetModelGroup();

						 if( pModelGroup->m_pSceneAudio )
						 {
							 splitRevertGriditer = this->mapRevertSplitMapGridIndex.find(i);
							 if( splitRevertGriditer != this->mapRevertSplitMapGridIndex.end() )
							 {
								 nSaveGridIndex = splitRevertGriditer->second;
								 nGrindIndexs.insert(i);
							 }
						 }
					 }
				 }
			 }

			 size_t size = nGrindIndexs.size();
			 fwrite(&size,sizeof(size),1,fp);

			 set<int>::iterator end = nGrindIndexs.end();
			 map<int, int>::iterator begsplit, endsplit = this->mapRevertSplitMapGridIndex.end();

			 for( set<int>::iterator beg = nGrindIndexs.begin(); beg != end; ++beg )
			 {
				 int nGridIndex = *beg;
				 int nSaveGridIndex = 0;

				 begsplit = this->mapRevertSplitMapGridIndex.find(nGridIndex);
				 if( begsplit != endsplit )
					 nSaveGridIndex = begsplit->second;
				 else
					 nSaveGridIndex = nGridIndex;

				 fwrite(&nSaveGridIndex,sizeof(nSaveGridIndex),1,fp);	

				 SGrid * pGrid = &terrain->GetGrid(nGridIndex);
				 if ( !pGrid->vecCenterObjects.empty() )
				 {
					 int8 nAudioObjectIndex = 0; 
					 DWORD dw = 0;
					 long lCntOffset = ftell(fp);
					 fwrite(&dw,sizeof(DWORD),1,fp);

					 for ( vector< CTObjectPtr >::iterator iter = pGrid->vecCenterObjects.begin(); iter != pGrid->vecCenterObjects.end(); ++iter)
					 {
						 CTObjectPtr p = (*iter);

						 CEditModelGroup *pModelGroup = p->GetModelGroup();

						 strCueName = pModelGroup->GetSceneCueName();
						 if( pModelGroup->m_pSceneAudio && !strCueName.empty() )
						 {
							 //////////////////////////////////////////////////////////////////////////
							 ///play time mechanism

							 ///一段时间的播放长度最小最大值
							 DWORD time = pModelGroup->GetPlayTimeLenMin();
							 fwrite(&time,sizeof(time),1,fp);

							 time = pModelGroup->GetPlayTimeLenMax();
							 fwrite(&time,sizeof(time),1,fp);

							 ///二段播放间隔长度最小最大值
							 time = pModelGroup->GetPlayIntervalMin();
							 fwrite(&time,sizeof(time),1,fp);

							 time = pModelGroup->GetPlayIntervalMax();
							 fwrite(&time,sizeof(time),1,fp);

							 //////////////////////////////////////////////////////////////////////////

							 ///cue name
							 dwLen = strCueName.size();
							 fwrite(&dwLen,sizeof(int),1,fp);
							 fwrite(strCueName.c_str(),dwLen,1,fp);

							 dw++;

							 string strItemName = pModelGroup->GetItemName();

							 dwLen = strItemName.size();
							 fwrite(&dwLen,sizeof(int),1,fp);
							 fwrite(strItemName.c_str(),dwLen,1,fp);

							 //////////////////////////////////////////////////////////////////////////
							 ///offset
							 CVector3f vUserOffsetEx = pModelGroup->GetUserOffset();
							 fwrite(&vUserOffsetEx,sizeof(CVector3f),1,fp);
							 //////////////////////////////////////////////////////////////////////////

							 int n = p->GetCenterGridIndex();
							 int nSaveModelIndex = 0;

							 begsplit = this->mapRevertSplitMapGridIndex.find(nGridIndex);
							 if( begsplit != endsplit )
								 nSaveModelIndex = begsplit->second;
							 else
								 nSaveModelIndex = n;

							 fwrite(&nSaveModelIndex,sizeof(nSaveModelIndex),1,fp);

							 //y 轴
							 float fRotation = pModelGroup->GetRotation();
							 fwrite(&fRotation,sizeof(float),1,fp);

							 int nRotationCnt = pModelGroup->GetRotationCount();
							 fwrite(&nRotationCnt,sizeof(int),1,fp);

							 //////////////////////////////////////////////////////////////////////////
							 //新版本新增的绕x,z轴渲染,物体缩放信息
							 //z 轴
							 float fPitch = pModelGroup->GetPitch();
							 fwrite(&fPitch,sizeof(float),1,fp);

							 int nPitchCnt = pModelGroup->GetPitchCount();
							 fwrite(&nPitchCnt,sizeof(int),1,fp);

							 //x 轴
							 float fYaw = pModelGroup->GetYaw();
							 fwrite(&fYaw,sizeof(float),1,fp);

							 int nYawCnt = pModelGroup->GetYawCount();
							 fwrite(&nYawCnt,sizeof(int),1,fp);

							 //缩放
							 float xScale = pModelGroup->GetScaleX();
							 fwrite(&xScale,sizeof(float),1,fp);
							 float yScale = pModelGroup->GetScaleY();
							 fwrite(&yScale,sizeof(float),1,fp);
							 float zScale = pModelGroup->GetScaleZ();
							 fwrite(&zScale,sizeof(float),1,fp);
							 //////////////////////////////////////////////////////////////////////////

							 BYTE byRenderStyle = pModelGroup->GetRenderStyle();
							 fwrite(&byRenderStyle,sizeof(BYTE),1,fp);

							 int nAtten = pModelGroup->GetAtten();
							 fwrite(&nAtten,sizeof(int),1,fp);

							 bool bShadow = p->IsCastShadow();
							 fwrite(&bShadow,sizeof(bool),1,fp);

							 ///写是否接收阴影信息
							 bool bReceiveShadow = pModelGroup->IsReceiveShadow();
							 fwrite(&bReceiveShadow,sizeof(bool),1,fp);

							 ///是否消隐,登录模型应该不需要消隐的吧
							 bool bTrans = false;
							 fwrite(&bTrans,sizeof(bTrans),1,fp);

							 ///mirror type
							 int nMirrorType = pModelGroup->GetMirrorType();
							 fwrite(&nMirrorType, sizeof(nMirrorType), 1, fp);

							 ///nAffectRadio
							 int nRatio = pModelGroup->GetAffectRatio();
							 fwrite( &nRatio, sizeof(int), 1, fp);
						 }

					 }

					 long lNow = ftell(fp);
					 fseek(fp,lCntOffset,SEEK_SET);
					 fwrite(&dw,sizeof(dw),1,fp);
					 fseek(fp,lNow,SEEK_SET);
				 }
				 else
				 {
					 int16 dw = 0;
					 fwrite(&dw,sizeof(dw),1,fp);
				 }
			 }

			 fclose(fp);
			 locale::global(loc);//恢复全局locale	

			 MessageBox(NULL,"场景音源保存完毕","提示",MB_OK);
		}
	 }
Exemplo n.º 2
0
void sqr::CMapCommonDataSaver::SaveEachGridInfo(FILE * fp, SGrid* pGrid, int& SceneLightCount, int& nSpotLightCount, bool bResize, bool bSplit)
{
    bool   bEffectBased = false, bEffecIsExit = false;
    string strName = "", strEffectName = "", strCueName = "";
    map<int, int>::iterator iiter;

    /////////////////////////////////////////////////////////////////
    fwrite(&pGrid->bCliffLayerOne, sizeof(bool), 1, fp);

    fwrite(&pGrid->bMatNotEffectByTileSets, sizeof(bool), 1, fp);

    fwrite(&pGrid->bCliffLayerOne, sizeof(bool), 1, fp);

    //纹理坐标信息,第1层纹理坐标的信息
    for (int i = 0; i < 4; ++i)
    {
        fwrite(&pGrid->uv[0][i].x, sizeof(float), 1, fp);
        fwrite(&pGrid->uv[0][i].y, sizeof(float), 1, fp);
    }

    fwrite(&pGrid->vCenter.y,sizeof(float),1,fp);

    ///物体是否受顶点色影响
    //bool bEffectByVertexColor = true;
    fwrite(&pGrid->bEffectByVertexColor,sizeof(bool),1,fp);

    ///保存顶点色是否影响场景物体标志
    fwrite(&pGrid->bCliffLayerOne, sizeof(bool), 1, fp);

    //格子上的模型信息
    // central  object
    if ( !pGrid->vecCenterObjects.empty() )
    {
        DWORD dw = 0;
        long lCntOffset = ftell(fp);
        fwrite(&dw,sizeof(DWORD),1,fp);

        for ( vector< CTObjectPtr >::iterator iter = pGrid->vecCenterObjects.begin(); iter != pGrid->vecCenterObjects.end(); ++iter)
        {
            CTObjectPtr p = (*iter);

            CEditModelGroup *pModelGroup = p->GetModelGroup();

            ///login model 跳过
            if( pModelGroup->m_bLoginModel )
            {
                nLoginGridIndexs.insert(pGrid->dwGridIndex);
                continue;
            }

            if( pModelGroup->m_bReginEffect )
            {
                continue;
            }

            if( pModelGroup->m_pSceneAudio )
                continue;

            // effect bound?
            bEffectBased = pModelGroup->GetIsEffectBased();
            bEffecIsExit = pModelGroup->GetEffectName(strEffectName);
            if ( bEffectBased && bEffecIsExit )
            {
                //记录场景点光源个数---
                if (pModelGroup->m_SL.m_bIAmbScenePointLight)
                    ++SceneLightCount;

                //记录场景聚光灯个数---
                if (pModelGroup->m_SpotLight.m_bIAmbSceneSpotLight)
                    ++nSpotLightCount;

                //---
                bool b = true;
                fwrite(&b,sizeof(bool),1,fp);
                DWORD dwLen = strEffectName.size();
                fwrite(&dwLen,sizeof(int),1,fp);
                fwrite(strEffectName.c_str(),dwLen,1,fp);
            }
            else
            {
                bool b = false;

                fwrite(&b,sizeof(bool),1,fp);
            }

            dw++;

            string strItemName = pModelGroup->GetItemName();

            DWORD dwLen = strItemName.size();
            fwrite(&dwLen,sizeof(int),1,fp);
            fwrite(strItemName.c_str(),dwLen,1,fp);

            //////////////////////////////////////////////////////////////////////////
            ///save as modelgroup
            int nAtten = pModelGroup->GetAtten();
            fwrite(&nAtten,sizeof(int),1,fp);

            ///nAffectRadio
            int nRatio = pModelGroup->GetAffectRatio();
            fwrite( &nRatio, sizeof(int), 1, fp);

            ///save model property
            CMapEditObject *pMapEditObject = NULL;
            pMapEditObject = pModelGroup->GetSelfPresentation(0);
            if( pModelGroup == NULL )
            {
                MessageBox(NULL,"没有模型,不保存","",MB_OK);
                return;
            }

            CVector3f offset;
            pMapEditObject->GetImageOffsetToAdjustedCenterGrid(offset);
            MoldeSaveProperty sModelSavePro = pMapEditObject->sModelSavePro;
            sModelSavePro.vPosition = offset;

            if( bResize && !bSplit )
            {
                int nOldGridIndex = pMapEditObject->sModelSavePro.nCenterGridIndex;
                iiter = pOperator->m_OldMapGridIndexMap.find(nOldGridIndex);
                if( iiter != pOperator->m_OldMapGridIndexMap.end() )
                {
                    int nNewGridIndex = iiter->second;
                    sModelSavePro.nCenterGridIndex = nNewGridIndex;

                    int nOldX = 0, nOldZ = 0, nNewX = 0, nNewZ = 0;
                    nOldX = nOldGridIndex % terrain->GetWidth(); // 列
                    nOldZ = nOldGridIndex / terrain->GetWidth(); // 行
                    nNewX = nNewGridIndex % dwNewMapWidth; // 列
                    nNewZ = nNewGridIndex / dwNewMapWidth; // 行

                    CVector3f oldpos = sModelSavePro.vPosition;
                    CVector3f offset(oldpos.x - nOldX * GRID_SPACE, oldpos.y, oldpos.z - nOldZ * GRID_SPACE);
                    CVector3f newpos = CVector3f(offset.x + nNewX * GRID_SPACE, offset.y, offset.z + nNewZ * GRID_SPACE);
                    sModelSavePro.vPosition = newpos;
                    //sModelSavePro.vUserOffsetEx = offset - CVector3f(32.0f,0.0f,32.0f);
                }
            }
            else
            {
                if( !bResize && bSplit )
                {
                    int nOldGridIndex = pMapEditObject->sModelSavePro.nCenterGridIndex;
                    iiter = pOperator->m_SplitOldMapGridIndexMap.find(nOldGridIndex);
                    if( iiter != pOperator->m_SplitOldMapGridIndexMap.end() )
                    {
                        int nNewGridIndex = iiter->second;
                        sModelSavePro.nCenterGridIndex = nNewGridIndex;

                        int nOldX = 0, nOldZ = 0, nNewX = 0, nNewZ = 0;
                        nOldX = nOldGridIndex % dwNewMapWidth; // 列
                        nOldZ = nOldGridIndex / dwNewMapWidth; // 行
                        nNewX = nNewGridIndex % dwNewMapWidth; // 列
                        nNewZ = nNewGridIndex / dwNewMapWidth; // 行

                        CVector3f oldpos = pMapEditObject->sModelSavePro.vPosition;
                        CVector3f offset(oldpos.x - nOldX * GRID_SPACE, oldpos.y, oldpos.z - nOldZ * GRID_SPACE);
                        CVector3f newpos = CVector3f(offset.x + nNewX * GRID_SPACE, offset.y, offset.z + nNewZ * GRID_SPACE);
                        sModelSavePro.vPosition = newpos;
                    }
                }
            }

            fwrite( &sModelSavePro, sizeof(sModelSavePro),  1, fp);
        }

        long lNow = ftell(fp);
        fseek(fp,lCntOffset,SEEK_SET);
        fwrite(&dw,sizeof(DWORD),1,fp);
        fseek(fp,lNow,SEEK_SET);
    }
    else
    {
        DWORD dw = 0;
        fwrite(&dw,sizeof(int),1,fp);
    }
}
Exemplo n.º 3
0
	void CChangeMoveMapData::MoveAsMap( const int nStartReginX, const int nStartReginZ, const int nOffsetReginWidth, const int nOffsetReginDepth )
	{
		this->ClearInfo();

		COperator *pOperator = CMapEditApp::GetInst()->GetOperator();

		int nGridCount = terrain->GetGridCount();
		int nVertexCount = terrain->GetVertexCount();
		int nMapWidth  = terrain->GetWidth();
		int nNewGridIndex = 0, nOldGridIndex = 0;//nOldGridIndex为原始地表格子索引,nNewGridIndex为偏移后地表格子索引
		int nOldVertexIndex = 0, nNewVertexIndex = 0;
		int nXOffsetGridCount = nOffsetReginWidth * REGION_SPACE;
		int nZOffsetGridCount = nOffsetReginDepth * REGION_SPACE;
		int nStartRegionGridStartX   = nStartReginX * REGION_SPACE;
		int nStartRegionGridStartZ   = nStartReginZ * REGION_SPACE;
		map<int, SGrid> mapTempTerrainGridInfo;///将所有老格子上的信息传先暂时保存下来
		map<int, SVertex> mapTempTerrainVertexInfo;///将所有老顶点上的信息传先暂时保存下来
		map<int, SGrid> mapTempWaterGridInfo;///将所有老格子上的信息传先暂时保存下来
		map<int, SVertex> mapTempWaterVertexInfo;///将所有老顶点上的信息传先暂时保存下来

		CTerrainMesh *pWater = terrain->GetWater();

		for( int m = 0; m < nZOffsetGridCount; ++m )
		{
			int nOldDepth = nStartRegionGridStartZ + m;
			int nNewDepth = nStartRegionGridStartZ + m + m_nMapZMoveOffset;
			for ( int n = 0; n < nXOffsetGridCount; ++n )
			{
				int nOldGridIndex = n + nStartRegionGridStartX + nOldDepth * nMapWidth;
				int nNewGridIndex = n + nStartRegionGridStartX + m_nMapXMoveOffset + nNewDepth * nMapWidth;

				//DebugOut("old %d, new %d\n", nOldGridIndex, nNewGridIndex);
				mapOldMapGridIndex[nOldGridIndex] = nNewGridIndex;
				
				if( terrain->IsValid(nOldGridIndex) && terrain->IsValid(nNewGridIndex) )
				{
					SGrid OldTerrainGrid = terrain->GetGrid(nOldGridIndex);
					SGrid OldWaterGrid   = pWater->GetGrid(nOldGridIndex);
					SGrid *pNewGrid      = &terrain->GetGrid(nNewGridIndex);

					mapTempTerrainGridInfo[nOldGridIndex] = OldTerrainGrid;
					mapTempWaterGridInfo[nOldGridIndex]   = OldWaterGrid;
					
					for( int i = 0; i < 4; ++i )
					{
						nOldVertexIndex = OldTerrainGrid.dwVertexIndex[i];
						nNewVertexIndex = pNewGrid->dwVertexIndex[i];
						mapOldMapVertexIndex[nOldVertexIndex] = nNewVertexIndex;

						SVertex TerrainVertex = terrain->GetVertex(nOldVertexIndex);
						mapTempTerrainVertexInfo[nOldVertexIndex] = TerrainVertex;
						SVertex WaterVertex = pWater->GetVertex(nOldVertexIndex);
						mapTempWaterVertexInfo[nOldVertexIndex] = WaterVertex;
					}
				}
			}
		}

		map<int, SVertex>::iterator vertexiter;
		map<int, int>::iterator vertexbeg = mapOldMapVertexIndex.begin();
		map<int, int>::iterator vertexend = mapOldMapVertexIndex.end();
		set<int> newHasMoveVertexIndexs;//记录哪些顶点移动了,移动后新顶点的索引
		for ( vertexbeg; vertexbeg != vertexend; ++vertexbeg )
		{
			nOldVertexIndex = vertexbeg->first;
			nNewVertexIndex = vertexbeg->second;
			newHasMoveVertexIndexs.insert(nNewVertexIndex);

			vertexiter = mapTempTerrainVertexInfo.find(nOldVertexIndex);
			if( vertexiter != mapTempTerrainVertexInfo.end() )
			{
				if (terrain->IsValidVertexIndex(nNewVertexIndex))
				{
					SVertex Vertex = vertexiter->second;
					SVertex &newvertex = terrain->GetVertex(nNewVertexIndex);

					newvertex.vPosition.y	 = Vertex.vPosition.y;
					newvertex.oColor	     = Vertex.oColor;
					newvertex.sColor		 = Vertex.sColor;
					newvertex.vNormal		 = Vertex.vNormal;
					newvertex.fLogicHeight   = Vertex.fLogicHeight;

					pWater->GetVertex(nNewVertexIndex).vPosition.y = newvertex.vPosition.y + WATER_LAYER_BASE;

					if( newHasMoveVertexIndexs.find(nOldVertexIndex) == newHasMoveVertexIndexs.end() )
					{
						SVertex &oldvertex = terrain->GetVertex(nOldVertexIndex);
						oldvertex.vPosition.y	 = 0.0f;
						oldvertex.oColor		 = VERTEX_COLOR;
						oldvertex.sColor		 = 0;
						oldvertex.vNormal		 = CVector3f(0.0f,1.0f,0.0f);
						oldvertex.fLogicHeight	 = 0.0f;
						pWater->GetVertex(nOldVertexIndex).vPosition.y = WATER_LAYER_BASE;
					}
				}
			}
		}

		string strDefaultTerrainTexName = terrain->GetTerrainDefaultTextureName();

		map<int, int>::iterator beg = mapOldMapGridIndex.begin();
		map<int, int>::iterator end = mapOldMapGridIndex.end();
		map<int, SGrid>::iterator iter;
		set<int> newHasMoveGridIndexs;//记录哪些格子移动了,移动后新格子的索引
		set<int>::iterator iiter;
		for ( beg; beg != end; ++beg )
		{
			nOldGridIndex = beg->first;
			nNewGridIndex = beg->second;
			newHasMoveGridIndexs.insert(nNewGridIndex);

			iter = mapTempTerrainGridInfo.find(nOldGridIndex);
			if( iter != mapTempTerrainGridInfo.end() )
			{
				if( terrain->IsValid(nNewGridIndex) )
				{
					SGrid oldGrid = iter->second;
					SGrid &grid = terrain->GetGrid(nNewGridIndex);
					grid.ClearGridInfo();
					{
						grid.pRiver				  = oldGrid.pRiver;
						grid.pWave				  = oldGrid.pWave;
						grid.vecCenterObjects	  = oldGrid.vecCenterObjects;
	
						grid.bReverse			  = oldGrid.bReverse;
						grid.bEffectByVertexColor = oldGrid.bEffectByVertexColor;
						grid.bCliffLayerOne		  = oldGrid.bCliffLayerOne;
						grid.bGridHide			  = oldGrid.bGridHide;
						grid.nGridSeekRoadWeight  = oldGrid.nGridSeekRoadWeight;
						grid.m_bSetExactBlock	  = oldGrid.m_bSetExactBlock;
						grid.nMaterialIndex		  = oldGrid.nMaterialIndex;
						grid.nBlockType			  = oldGrid.nBlockType;

						grid.bMatNotEffectByTileSets = oldGrid.bMatNotEffectByTileSets;///强行设置该格子不受图素包设置影响,默认为受影响

						grid.nMaterialIndex			 = oldGrid.nMaterialIndex;
						grid.bSide					 = oldGrid.bSide;

						for ( int i = 0; i < 4; ++i )
						{
							grid.subGridTypes[i] = oldGrid.subGridTypes[i];
							grid.nodeInfo.strTextureNames[i] = oldGrid.nodeInfo.strTextureNames[i];
						}

						grid.vCenter.y = oldGrid.vCenter.y;
						grid.pRiver = oldGrid.pRiver;

						for ( vector< CTObjectPtr >::iterator iter = oldGrid.vecCenterObjects.begin(); iter != oldGrid.vecCenterObjects.end(); ++iter )
						{
							CEditModelGroup *pModelGroup = NULL;
							pModelGroup = (*iter)->GetModelGroup();

							string strEffectName = "";
							string strCueName = pModelGroup->GetSceneCueName();
							string strItemName = pModelGroup->GetItemName();
							bool bEffectBased = pModelGroup->GetIsEffectBased();
							bool bEffecIsExit = pModelGroup->GetEffectName(strEffectName);
							int nAtten = pModelGroup->GetAtten();
							int nRatio = pModelGroup->GetAffectRatio();
							bool bPointLight = false, bSpotLight = false;

							if (pModelGroup->m_SL.m_bIAmbScenePointLight)
								bPointLight = true;

							if (pModelGroup->m_SpotLight.m_bIAmbSceneSpotLight)
								bSpotLight = true;

							///一段时间的播放长度最小最大值
							DWORD dwPlayLenMin = pModelGroup->GetPlayTimeLenMin();
							DWORD dwPlayLenMax = pModelGroup->GetPlayTimeLenMax();

							///二段播放间隔长度最小最大值
							DWORD dwPlayIntervalMin = pModelGroup->GetPlayIntervalMin();
							DWORD dwPlayIntervalMax = pModelGroup->GetPlayIntervalMax();

							CMapEditObject *pMapEditObject = NULL;
							pMapEditObject = pModelGroup->GetSelfPresentation(0);
							if( pModelGroup == NULL )
							{
								MessageBox(NULL,"没有模型,不保存","",MB_OK);
								return;
							}

							MoldeSaveProperty sModelSavePro = pMapEditObject->sModelSavePro;
							sModelSavePro.nCenterGridIndex = nNewGridIndex;

							if ( bEffectBased && bEffecIsExit )
							{
								pOperator->RebirthIndividualEffect(strEffectName, sModelSavePro.nCenterGridIndex, sModelSavePro.vRotate.y, sModelSavePro.nRotationCnt,
									sModelSavePro.vRotate.z, sModelSavePro.nPitchCnt, sModelSavePro.vRotate.x, sModelSavePro.nYawCnt, sModelSavePro.vScale.x, sModelSavePro.vScale.y, sModelSavePro.vScale.z, &sModelSavePro.vUserOffsetEx, sModelSavePro.vPosition, 0, NULL, 0);
				
							}
							else // effect
							{
								if( strCueName != "" )
								{
									EAUTO_GENERATION_TYPE eAutoGenerationType = EAGT_NONE;
									BYTE byRenderStyle = 0;
									bool bShadow = true;
									bool bReceiveShadow = false;
									BYTE bTransState = 0;
									int nMirrorType = 0, nRatio = 0;
									bool bTrans = true;
									CVector3f vUserOffsetEx2 = CVector3f(sModelSavePro.vUserOffsetEx.y,sModelSavePro.vUserOffsetEx.x,sModelSavePro.vUserOffsetEx.z);

									pOperator->Rebirth(strItemName, sModelSavePro.nCenterGridIndex, sModelSavePro.vRotate.y, sModelSavePro.nRotationCnt,
										sModelSavePro.vRotate.z, sModelSavePro.nPitchCnt, sModelSavePro.vRotate.x, sModelSavePro.nYawCnt, sModelSavePro.vScale.x, sModelSavePro.vScale.y, sModelSavePro.vScale.z, &vUserOffsetEx2, 0, NULL, 0,0,1.0f,
										eAutoGenerationType,byRenderStyle,nAtten,false,bShadow,bTrans,bTransState,nMirrorType,nRatio, "", strItemName, strCueName);
								}
								else
									pOperator->Rebirth(&sModelSavePro, strItemName, "", nRatio, strItemName, strCueName);
							}

							size_t size = grid.vecCenterObjects.size();
							CEditModelGroup *pNewModelGroup = NULL;
							CTObjectPtr p = grid.vecCenterObjects[size-1];
							pNewModelGroup = p->GetModelGroup();
							if( pNewModelGroup )
							{
								if( bPointLight )
								{
									pNewModelGroup->m_SL = pModelGroup->m_SL;
									pNewModelGroup->SetIsLightEffect(true);

									iiter = terrain->m_DynamicLightGrids.find(nOldGridIndex);
									if ( iiter != terrain->m_DynamicLightGrids.end() )
										terrain->m_DynamicLightGrids.erase(iiter);
									terrain->m_DynamicLightGrids.insert(nNewGridIndex);
								}
								else
								{
									if( bSpotLight )
									{
										pNewModelGroup->m_SpotLight = pModelGroup->m_SpotLight;
										pNewModelGroup->SetIsLightEffect(true);
									}
									else
									{
										if( strCueName != "" )
										{
											if( pModelGroup->m_pSceneAudio )
											{
												if( pNewModelGroup->m_pSceneAudio == NULL )
													pNewModelGroup->m_pSceneAudio = new SceneAudio;

												pNewModelGroup->SetSceneCueName(strCueName);

												DWORD time = pModelGroup->GetPlayTimeLenMin();
												pNewModelGroup->SetPlayTimeLenMin(time);

												time = pModelGroup->GetPlayTimeLenMax();
												pNewModelGroup->SetPlayTimeLenMax(time);

												time = pModelGroup->GetPlayIntervalMin();
												pNewModelGroup->SetPlayIntervalMin(time);

												time = pModelGroup->GetPlayIntervalMax();
												pNewModelGroup->SetPlayIntervalMax(time);

											}
										}
									}
								}
							}
						}
					}

					if( newHasMoveGridIndexs.find(nOldGridIndex) == newHasMoveGridIndexs.end() )
					{
						SGrid &oldgrid = terrain->GetGrid(nOldGridIndex);
						oldgrid.pWave = NULL;
						oldgrid.ClearGridInfo();
						oldgrid.nodeInfo.strTextureNames[0] = strDefaultTerrainTexName;
					}
				}
			}
		}

		//////////////////////////////////////////////////////////////////////////
		///water
		set<int> setGridIndicesVisibleWater = pWater->GetGridIndicesVisibleWater();
		map< CRiver*, vector<int> > mapRivers;
		for ( set<int>::iterator iter = setGridIndicesVisibleWater.begin(); iter != setGridIndicesVisibleWater.end();)
		{
			int nGridIndex = *iter;
			++iter;

			SGrid & gridW = pWater->GetGrid(nGridIndex);
			Ast(gridW.bVisible);
			if ( gridW.pRiver )
			{
				mapRivers[gridW.pRiver].push_back(nGridIndex);
			}
		}

		CWaterOperator* pWaterOperator = CMapEditApp::GetInst()->GetWaterOperator();

		vector<int> vecGridIndicesRiver;
		for ( map< CRiver*, vector<int> >::iterator iterMapRivers = mapRivers.begin(); iterMapRivers != mapRivers.end(); ++iterMapRivers )
		{
			CRiver * pRiver = iterMapRivers->first;
			string strItemName = pRiver->GetItemName();
			pWaterOperator->RebirthRiver(strItemName);

			for (size_t i = 0; i < iterMapRivers->second.size(); ++i  )
			{
				int nOldGridIndex = iterMapRivers->second[i];///移动前的格子索引
				int nNewGridIndex = mapOldMapGridIndex[nOldGridIndex];///移动后的格子索引

				iter = mapTempTerrainGridInfo.find(nOldGridIndex);
				if( iter != mapTempTerrainGridInfo.end() )
				{
					if( terrain->IsValid(nNewGridIndex) )
					{
						SGrid &gridOldW = mapTempWaterGridInfo[nOldGridIndex];
						SGrid &gridNewW = pWater->GetGrid(nNewGridIndex);

						gridOldW.pRiver = NULL;
						vecGridIndicesRiver.push_back(nNewGridIndex);

						pWater->EraseGridIndexVisibleWater(nOldGridIndex);
						//pWater->InsertGridIndexVisibleWater(nNewGridIndex);

						for ( int j = 0; j < 4; ++j )
						{
							int nOldVertexIndex = gridOldW.dwVertexIndex[j];
							SVertex &OldVertex  = mapTempWaterVertexInfo[nOldVertexIndex];

							int nNewVertexIndex = gridNewW.dwVertexIndex[j];
							SVertex &NewVertex  = pWater->GetVertex(nNewVertexIndex);

							NewVertex.vPosition.y = OldVertex.vPosition.y;
							NewVertex.oColor	  = OldVertex.oColor;

							//OldVertex.vPosition.y = WATER_LAYER_BASE;
							//OldVertex.oColor	  = WATER_COLOR;
							//OldVertex.vNormal	  = CVector3f(0.0, 1.0f, 0.0f);
						}
					}
				}
			}
		}
		size_t size = vecGridIndicesRiver.size();
		for (size_t i = 0; i < size; ++i )
		{
			pWater->AdjustWaterMeshVisibility(vecGridIndicesRiver[i],true);
		}

		this->ChangeRegionLightInfo();
		//////////////////////////////////////////////////////////////////////////

		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 0);
		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 1);
		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 2);
		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 3);
		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 4);
		terrain->ReWriteTerrainBuffer(terrain->m_TerrainBufferIndexs, 5);
	}