void ClearConversionArrays( void) { acmMaterials.Clear(); actTriangles.Clear(); avVertices.Clear(); avTextureVertices.Clear(); aiRemap.Clear(); }
/* Copy container of entities from another world to this one and select them. */ void CWorld::CopyEntities(CWorld &woOther, CDynamicContainer<CEntity> &cenToCopy, CEntitySelection &senCopied, const CPlacement3D &plOtherSystem) { INDEX ctEntities = cenToCopy.Count(); if (ctEntities<=0) { return; } ULONG ulCopyFlags = COPY_REMAP; if(_bReinitEntitiesWhileCopying) { ulCopyFlags|=COPY_REINIT; }; // create array of pointer remaps _aprRemaps.Clear(); _aprRemaps.New(ctEntities); // PASS 1: create entities // for each entity to copy INDEX iRemap = 0; {FOREACHINDYNAMICCONTAINER(cenToCopy, CEntity, itenToCopy) { CEntity &enToCopy = *itenToCopy; CEntity *penNew; CPlacement3D plEntity; // thansform the entity placement from the system of other world plEntity = enToCopy.en_plPlacement; plEntity.RelativeToAbsolute(plOtherSystem); // mirror and stretch placement if needed if (_bMirrorAndStretch) { MirrorAndStretchPlacement(plEntity); } /* * NOTE: We must use CreateEntity_t() overload with class name instead with class pointer * because the entity class must be obtained by the target world too! */ // try to try { // create an entity of same class as the one to copy penNew = CreateEntity_t(plEntity, enToCopy.en_pecClass->GetName()); // if not successfull } catch (char *strError) { (void)strError; ASSERT(FALSE); // this should not happen FatalError(TRANS("Cannot CopyEntity():\n%s"), strError); } // remember its remap pointer _aprRemaps[iRemap].pr_penOriginal = &enToCopy; _aprRemaps[iRemap].pr_penCopy = penNew; iRemap++; }}
void CDlgFilterVertexSelection::DoDataExchange(CDataExchange* pDX) { CWorldEditorDoc* pDoc = theApp.GetActiveDocument(); // if dialog is recieving data if( pDX->m_bSaveAndValidate == FALSE) { } CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgFilterVertexSelection) DDX_Text(pDX, IDC_MAX_Y, m_fMaxY); DDX_Text(pDX, IDC_MAX_X, m_fMaxX); DDX_Text(pDX, IDC_MAX_Z, m_fMaxZ); DDX_Text(pDX, IDC_MIN_X, m_fMinX); DDX_Text(pDX, IDC_MIN_Y, m_fMinY); DDX_Text(pDX, IDC_MIN_Z, m_fMinZ); //}}AFX_DATA_MAP // if dialog is giving data if( pDX->m_bSaveAndValidate != FALSE) { CDynamicContainer<CBrushVertex> dcVertices; {FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx) { dcVertices.Add( itvtx); }} // for each of the dynamic container {FOREACHINDYNAMICCONTAINER( dcVertices, CBrushVertex, itvtx) { BOOL bDeselect=FALSE; FLOAT3D vVtx=itvtx->bvx_vAbsolute; if(vVtx(1)<m_fMinX || vVtx(1)>m_fMaxX) bDeselect=TRUE; if(vVtx(2)<m_fMinY || vVtx(2)>m_fMaxY) bDeselect=TRUE; if(vVtx(3)<m_fMinZ || vVtx(3)>m_fMaxZ) bDeselect=TRUE; if( bDeselect) { pDoc->m_selVertexSelection.Deselect( *itvtx); } }}
void CStock_TYPE::FreeUnused(void) { BOOL bAnyRemoved; // repeat do { // create container of objects that should be freed CDynamicContainer<TYPE> ctToFree; {FOREACHINDYNAMICCONTAINER(st_ctObjects, TYPE, itt) { if (!itt->IsUsed()) { ctToFree.Add(itt); } }} bAnyRemoved = ctToFree.Count()>0; // for each object that should be freed {FOREACHINDYNAMICCONTAINER(ctToFree, TYPE, itt) { st_ctObjects.Remove(itt); st_ntObjects.Remove(itt); delete (&*itt); }} // as long as there is something to remove } while (bAnyRemoved); }
CDlgBrowseByClass::~CDlgBrowseByClass() { dcEntities.Clear(); }
/* * Converts data from Exploration3D format into arrays used for conversion to O3D */ void FillConversionArrays_t(const FLOATmatrix3D &mTransform) { #if USE_E3D // all polygons must be triangles if(_pe3Object->_facecount != 0) { throw("Error: Not all polygons are triangles!"); } // check if we need flipping (if matrix is flipping, polygons need to be flipped) const FLOATmatrix3D &m = mTransform; FLOAT fDet = m(1,1)*(m(2,2)*m(3,3)-m(2,3)*m(3,2))+ m(1,2)*(m(2,3)*m(3,1)-m(2,1)*m(3,3))+ m(1,3)*(m(2,1)*m(3,2)-m(2,2)*m(3,1)); FLOAT bFlipped = fDet<0; // ------------ Convert object vertices (coordinates) INDEX ctVertices = _pe3Object->pointcount; avVertices.New(ctVertices); // copy vertices for( INDEX iVtx=0; iVtx<ctVertices; iVtx++) { avVertices[iVtx] = ((FLOAT3D &)_pe3Object->points[iVtx])*mTransform; avVertices[iVtx](1) = -avVertices[iVtx](1); avVertices[iVtx](3) = -avVertices[iVtx](3); } // ------------ Convert object's mapping vertices (texture vertices) INDEX ctTextureVertices = _pe3Object->txtcount; avTextureVertices.New(ctTextureVertices); // copy texture vertices for( INDEX iTVtx=0; iTVtx<ctTextureVertices; iTVtx++) { avTextureVertices[iTVtx] = (FLOAT2D &)_pe3Object->txtpoints[iTVtx]; } // ------------ Organize triangles as list of surfaces // allocate triangles INDEX ctTriangles = _pe3Object->facecount; actTriangles.New(ctTriangles); acmMaterials.Lock(); // sort triangles per surfaces for( INDEX iTriangle=0; iTriangle<ctTriangles; iTriangle++) { ConversionTriangle &ctTriangle = actTriangles[iTriangle]; e3_TFACE *pe3Triangle = _pe3Object->GetFace( iTriangle); // copy vertex indices if (bFlipped) { ctTriangle.ct_iVtx[0] = pe3Triangle->v[2]; ctTriangle.ct_iVtx[1] = pe3Triangle->v[1]; ctTriangle.ct_iVtx[2] = pe3Triangle->v[0]; } else { ctTriangle.ct_iVtx[0] = pe3Triangle->v[0]; ctTriangle.ct_iVtx[1] = pe3Triangle->v[1]; ctTriangle.ct_iVtx[2] = pe3Triangle->v[2]; } // copy texture vertex indices if (bFlipped) { ctTriangle.ct_iTVtx[0] = pe3Triangle->t[2]; ctTriangle.ct_iTVtx[1] = pe3Triangle->t[1]; ctTriangle.ct_iTVtx[2] = pe3Triangle->t[0]; } else { ctTriangle.ct_iTVtx[0] = pe3Triangle->t[0]; ctTriangle.ct_iTVtx[1] = pe3Triangle->t[1]; ctTriangle.ct_iTVtx[2] = pe3Triangle->t[2]; } // obtain material e3_MATERIAL *pe3Mat = pe3Triangle->material; BOOL bNewMaterial = TRUE; // attach triangle into one material for( INDEX iMat=0; iMat<acmMaterials.Count(); iMat++) { // if this material already exist in array of materu if( acmMaterials[ iMat].cm_ulTag == (ULONG) pe3Mat) { // set index of surface ctTriangle.ct_iMaterial = iMat; // add triangle into surface list of triangles INDEX *piNewTriangle = new INDEX(1); *piNewTriangle = iTriangle; acmMaterials[ iMat].ms_Polygons.Add( piNewTriangle); bNewMaterial = FALSE; continue; } } // if material hasn't been added yet if( bNewMaterial) { // add new material ConversionMaterial *pcmNew = new ConversionMaterial; acmMaterials.Unlock(); acmMaterials.Add( pcmNew); acmMaterials.Lock(); // set polygon's material index INDEX iNewMaterial = acmMaterials.Count()-1; ctTriangle.ct_iMaterial = iNewMaterial; // add triangle into new surface's list of triangles INDEX *piNewTriangle = new INDEX(1); *piNewTriangle = iTriangle; acmMaterials[ iNewMaterial].ms_Polygons.Add( piNewTriangle); // remember recognition tag (ptr) pcmNew->cm_ulTag = (ULONG) pe3Mat; // ---------- Set material's name // if not default material if( pe3Mat != NULL && pe3Mat->name != NULL) { acmMaterials[iNewMaterial].cm_strName = CTString(pe3Mat->name); // get color COLOR colColor = CLR_CLRF( pe3Mat->GetDiffuse().rgb()); acmMaterials[iNewMaterial].cm_colColor = colColor; } else { acmMaterials[iNewMaterial].cm_strName = "Default"; acmMaterials[iNewMaterial].cm_colColor = C_GRAY; } } } acmMaterials.Unlock(); #endif }
CTString GetItemValue(CEntity *pen, INDEX iColumn, INDEX &iFormat) { ASSERT(pen!=NULL); if(pen==NULL) return CTString(""); CEntityClass *pecEntityClass = pen->GetClass(); CDLLEntityClass *pdllecDllEntityClass = pecEntityClass->ec_pdecDLLClass; FLOAT3D vOrigin = pen->GetPlacement().pl_PositionVector; ANGLE3D vAngles = pen->GetPlacement().pl_OrientationAngle; CTString strResult=""; iFormat=PDF_STRING; switch( iColumn) { case COLUMN_INDEX: { INDEX iIndex=dcEntities.GetIndex(pen); strResult.PrintF("%d", FLOAT(iIndex)); iFormat=PDF_INDEX; break; } case COLUMN_CLASS: { strResult=pdllecDllEntityClass->dec_strName; break; } case COLUMN_NAME: { strResult=pen->GetName(); break; } case COLUMN_DESCRIPTION: { strResult=pen->GetDescription(); break; } case COLUMN_SECTOR_NAME: { CBrushSector *pbsc = pen->GetFirstSectorWithName(); if( pbsc!=NULL) { strResult=pbsc->bsc_strName; } break; } case COLUMN_X: { strResult.PrintF("%g", vOrigin(1)); iFormat=PDF_FLOAT; break; } case COLUMN_Y: { strResult.PrintF("%g", vOrigin(2)); iFormat=PDF_FLOAT; break; } case COLUMN_Z: { strResult.PrintF("%g", vOrigin(3)); iFormat=PDF_FLOAT; break; } case COLUMN_H: { strResult.PrintF("%g", vAngles(1)); iFormat=PDF_FLOAT; break; } case COLUMN_P: { strResult.PrintF("%g", vAngles(2)); iFormat=PDF_FLOAT; break; } case COLUMN_B: { strResult.PrintF("%g", vAngles(3)); iFormat=PDF_FLOAT; break; } case COLUMN_DISTANCE: { if( _penForDistanceSort != NULL) { FLOAT3D vSelectedOrigin = _penForDistanceSort->GetPlacement().pl_PositionVector; FLOAT3D fDistance = vOrigin-vSelectedOrigin; strResult.PrintF("%g", fDistance.Length()); iFormat=PDF_FLOAT; } break; } case COLUMN_SPAWN_FLAGS: { strResult.PrintF("0x%08X", pen->GetSpawnFlags()); break; } // entity properties default: { CDLLEntityClass *pdecDLLClass = pen->GetClass()->ec_pdecDLLClass; // for all classes in hierarchy of this entity INDEX iPropertyOrder=0; for(;pdecDLLClass!=NULL; pdecDLLClass = pdecDLLClass->dec_pdecBase) { // for all properties for(INDEX iProperty=0; iProperty<pdecDLLClass->dec_ctProperties; iProperty++) { CEntityProperty *pepProperty = &pdecDLLClass->dec_aepProperties[iProperty]; if( pepProperty->ep_strName!=CTString("")) { if( iPropertyOrder==iColumn-COLUMN_PROPERTY_START) { strResult=GetPropertyValue(pen, pepProperty, iFormat); return strResult; } iPropertyOrder++; } } } } } return strResult; }