void UnwrapMod::fnPasteInstance() { //make sure mods are the same theHold.Begin(); HoldPointsAndFaces(); for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) { MeshTopoData *ld = mMeshTopoData[ldID]; if ((this == copyPasteBuffer.mod) && (ld == copyPasteBuffer.lmd)) { BitArray faceSel = ld->GetFaceSelection(); //loop through selected faces int copyIndex = 0; for (int i =0; i < faceSel.GetSize(); i++) { if (faceSel[i]) { //make sure selected faces count = buffer face if (( i < ld->GetNumberFaces()/*TVMaps.f.Count()*/) && (copyIndex < copyPasteBuffer.faceData.Count())) { int degree = ld->GetFaceDegree(i); if (degree == copyPasteBuffer.faceData[copyIndex]->count) { //if so set the face data indices as the same for (int j = 0; j < degree; j++) { //index into the texture vertlist ld->SetFaceTVVert(i,j,copyPasteBuffer.faceData[copyIndex]->t[j]);//TVMaps.f[i]->t[j] = copyPasteBuffer.faceData[copyIndex]->t[j]; //index into the geometric vertlist if ((ld->GetFaceHasVectors(i)/*TVMaps.f[i]->vecs*/) && (j < 4)) { ld->SetFaceTVInterior(i,j,copyPasteBuffer.faceData[copyIndex]->vecs->interiors[j]);//TVMaps.f[i]->vecs->interiors[j] = copyPasteBuffer.faceData[copyIndex]->vecs->interiors[j]; ld->SetFaceTVHandle(i,j*2,copyPasteBuffer.faceData[copyIndex]->vecs->handles[j*2]);//TVMaps.f[i]->vecs->handles[j*2] = copyPasteBuffer.faceData[copyIndex]->vecs->handles[j*2]; ld->SetFaceTVHandle(i,j*2+1,copyPasteBuffer.faceData[copyIndex]->vecs->handles[j*2+1]);//TVMaps.f[i]->vecs->handles[j*2+1] = copyPasteBuffer.faceData[copyIndex]->vecs->handles[j*2+1]; } } copyIndex++; } } } } ld->SetTVEdgeInvalid(); } } CleanUpDeadVertices(); theHold.Accept(GetString(IDS_PW_PASTE)); NotifyDependents(FOREVER,PART_ALL,REFMSG_CHANGE); InvalidateView(); GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime()); }
void UnwrapMod::PlanarMapNoScale(Point3 gNormal) { AlignMap(); //add vertices to our internal vertex list filling in dead spots where appropriate int ct = 0; //get align normal //get fit data PlanarTM.IdentityMatrix(); Interval v; Point3 identScale(1.0f,1.0f,1.0f); if (scaleControl) scaleControl->GetValue(0,&gScale,v); PlanarTM.SetScale(identScale); if (rotateControl) rotateControl->GetValue(0,&gRotate,v); PlanarTM.RotateZ(gRotate); if (offsetControl) offsetControl->GetValue(0,&gOffset,v); PlanarTM.SetTrans(gOffset); ComputeSelectedFaceData(); Matrix3 gtm; UnwrapMatrixFromNormal(gNormal,gtm); gtm = Inverse(gtm); DeleteVertsFromFace(gfaces); //unselect all verts for (int j=0;j<TVMaps.v.Count();j++) { if (vsel[j]) { vsel.Clear(j); } } //build available list Tab<int> alist; alist.ZeroCount(); for (j=0;j<TVMaps.v.Count();j++) { if (TVMaps.v[j].flags & FLAG_DEAD) //dead veretx found copy new vert in and note the place { alist.Append(1,&j,1); } } for (int i = 0; i < gverts.d.Count(); i++) { BOOL found = FALSE; if (gverts.sel[i]) { if (ct < alist.Count() ) { j = alist[ct]; TVMaps.v[j].flags = 0; TVMaps.v[j].influence = 0.0f; Point3 tp = gverts.d[i].p - gCenter; tp = tp * gtm; tp.z = 0.0f; TVMaps.v[j].p = tp; int vcount = vsel.GetSize(); vsel.Set(j); if (TVMaps.cont[j]) TVMaps.cont[j]->SetValue(0,&tp,CTRL_ABSOLUTE); gverts.d[i].newindex = j; ct++; } else { UVW_TVVertClass tempv; Point3 tp = gverts.d[i].p - gCenter; tp = tp * gtm; tp.z = 0.0f; tempv.p = tp; tempv.flags = 0; tempv.influence = 0.0f; gverts.d[i].newindex = TVMaps.v.Count(); TVMaps.v.Append(1,&tempv,1); vsel.SetSize(TVMaps.v.Count(), 1); vsel.Set(TVMaps.v.Count()-1); Control* c; c = NULL; TVMaps.cont.Append(1,&c,1); if (TVMaps.cont[TVMaps.v.Count()-1]) TVMaps.cont[TVMaps.v.Count()-1]->SetValue(0,&TVMaps.v[TVMaps.v.Count()-1].p,CTRL_ABSOLUTE); } } } //now copy our face data over for (i = 0; i < gfaces.Count(); i++) { int ct = gfaces[i]->FaceIndex; TVMaps.f[ct]->flags = gfaces[i]->flags; TVMaps.f[ct]->flags |= FLAG_SELECTED; int pcount = 3; pcount = gfaces[i]->count; for (int j = 0; j < pcount; j++) { int index = gfaces[i]->t[j]; //find spot in our list TVMaps.f[ct]->t[j] = gverts.d[index].newindex; if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs)) { index = gfaces[i]->vecs->handles[j*2]; //find spot in our list TVMaps.f[ct]->vecs->handles[j*2] = gverts.d[index].newindex; index = gfaces[i]->vecs->handles[j*2+1]; //find spot in our list TVMaps.f[ct]->vecs->handles[j*2+1] = gverts.d[index].newindex; if (TVMaps.f[ct]->flags & FLAG_INTERIOR) { index = gfaces[i]->vecs->interiors[j]; //find spot in our list TVMaps.f[ct]->vecs->interiors[j] = gverts.d[index].newindex; } } } } CleanUpDeadVertices(); TVMaps.edgesValid= FALSE; }
void UnwrapMod::fnPaste(BOOL rotate) { //check for type TimeValue t = GetCOREInterface()->GetTime(); theHold.Begin(); HoldPointsAndFaces(); for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) { MeshTopoData *ld = mMeshTopoData[ldID]; //check faces if just one selected normal paste with rotates //or if all faces where selected //or if first paste //hold the points and faces BitArray holdFaceSel(ld->GetFaceSelection()); BitArray subFaceSel; if ( ip && (ip->GetSubObjectLevel() == 0) ) { //convert our current selection into faces if (fnGetTVSubMode() == TVVERTMODE) ld->GetFaceSelFromVert(subFaceSel,FALSE); else if (fnGetTVSubMode() == TVEDGEMODE) { BitArray tempVSel; ld->GetVertSelFromEdge(tempVSel); BitArray vsel = ld->GetTVVertSelection(); BitArray holdVSel(vsel); ld->SetTVVertSelection(tempVSel);//vsel = tempVSel; ld->GetFaceSelFromVert(subFaceSel,FALSE); ld->SetTVVertSelection(holdVSel);//vsel = holdVSel; } else if (fnGetTVSubMode() == TVFACEMODE) { subFaceSel = ld->GetFaceSelection();//.SetSize(fsel.GetSize()); //subFaceSel = fsel; } } else { if (fnGetTVSubMode() == TVFACEMODE) { subFaceSel = ld->GetFaceSelection();//.SetSize(fsel.GetSize()); //subFaceSel = fsel; } } if ( (copyPasteBuffer.copyType == 0) || (copyPasteBuffer.copyType == 1) || (copyPasteBuffer.iRotate==0)) { int copyIndex = 0; Tab<int> vertexLookUpList; vertexLookUpList.SetCount(copyPasteBuffer.tVertData.Count()); BitArray faceSel = ld->GetFaceSelection(); for (int i =0; i < vertexLookUpList.Count(); i++) vertexLookUpList[i] = -1; if (copyPasteBuffer.copyType == 1) copyPasteBuffer.iRotate = 0; else { if (copyPasteBuffer.lastSel.GetSize() == faceSel.GetSize()) { if (copyPasteBuffer.lastSel == faceSel) { if (rotate) { copyPasteBuffer.iRotate++; } else copyPasteBuffer.iRotate = 0; } } } if (copyPasteBuffer.copyType == 2) copyPasteBuffer.iRotate = 0; copyPasteBuffer.lastSel = faceSel; //loop through selected faces for (int i =0; i < faceSel.GetSize(); i++) { if (faceSel[i]) { //make sure selected faces count = buffer face if (( i < ld->GetNumberFaces()/*TVMaps.f.Count()*/) && (copyIndex < copyPasteBuffer.faceData.Count())) { int degree = ld->GetFaceDegree(i); if (/*TVMaps.f[i]->count*/ degree == copyPasteBuffer.faceData[copyIndex]->count) { //if so set the face data indices as the same for (int j = 0; j < degree/*TVMaps.f[i]->count*/; j++) { //index into the texture vertlist int vid = (j + copyPasteBuffer.iRotate)%degree;//TVMaps.f[i]->count; int vertexIndex = copyPasteBuffer.faceData[copyIndex]->t[vid]; if (vertexLookUpList[vertexIndex] == -1) { Point3 p = copyPasteBuffer.tVertData[vertexIndex]; ld->AddTVVert(t, p, i, j, this,FALSE);//ld->AddPoint(p, i, j,FALSE); vertexLookUpList[vertexIndex] = ld->GetFaceTVVert(i,j);//TVMaps.f[i]->t[j]; } else ld->SetFaceTVVert(i,j,vertexLookUpList[vertexIndex]);//TVMaps.f[i]->t[j] = vertexLookUpList[vertexIndex]; if ((ld->GetFaceHasVectors(i)/*TVMaps.f[i]->vecs*/) && (copyPasteBuffer.faceData[copyIndex]->vecs) && (j < 4)) { int hid = (j*2 + (copyPasteBuffer.iRotate*2))%(/*TVMaps.f[i]->count*/degree*2); int handleIndex = copyPasteBuffer.faceData[copyIndex]->vecs->handles[hid]; if ((handleIndex >= 0) && (vertexLookUpList[handleIndex] == -1)) { Point3 p = copyPasteBuffer.tVertData[handleIndex]; ld->AddTVHandle(t,p, i, j*2,this,FALSE); vertexLookUpList[handleIndex] = ld->GetFaceTVHandle(i,j*2);// TVMaps.f[i]->vecs->handles[j*2]; } else ld->SetFaceTVHandle(i,j*2,vertexLookUpList[handleIndex]);//TVMaps.f[i]->vecs->handles[j*2] = vertexLookUpList[handleIndex]; hid = (j*2 + (copyPasteBuffer.iRotate*2))%(degree/*TVMaps.f[i]->count*/*2)+1; handleIndex = copyPasteBuffer.faceData[copyIndex]->vecs->handles[hid]; if ((handleIndex >= 0) && (vertexLookUpList[handleIndex] == -1)) { Point3 p = copyPasteBuffer.tVertData[handleIndex]; ld->AddTVHandle(t,p, i, j*2+1,this,FALSE); vertexLookUpList[handleIndex] = ld->GetFaceTVHandle(i,j*2+1);//TVMaps.f[i]->vecs->handles[j*2+1]; } else ld->SetFaceTVHandle(i,j*2+1,vertexLookUpList[handleIndex]);//TVMaps.f[i]->vecs->handles[j*2+1] = vertexLookUpList[handleIndex]; int iid = (j + (copyPasteBuffer.iRotate))%degree;//(TVMaps.f[i]->count); int interiorIndex = copyPasteBuffer.faceData[copyIndex]->vecs->interiors[iid]; if ((interiorIndex >= 0) && (vertexLookUpList[interiorIndex] == -1)) { Point3 p = copyPasteBuffer.tVertData[interiorIndex]; ld->AddTVInterior(t,p, i, j,this,FALSE); vertexLookUpList[interiorIndex] = ld->GetFaceTVInterior(i,j);//TVMaps.f[i]->vecs->handles[j]; } else ld->SetFaceTVInterior(i,j,vertexLookUpList[interiorIndex]);//TVMaps.f[i]->vecs->interiors[j] = vertexLookUpList[interiorIndex]; } } copyIndex++; if (copyIndex >= copyPasteBuffer.faceData.Count()) copyIndex = 0; } } } } } ld->SetTVEdgeInvalid();//RebuildEdges(); if ( ip && (ip->GetSubObjectLevel() == 0) ) { if (fnGetTVSubMode() == TVVERTMODE) { BitArray fsel = ld->GetFaceSelection(); BitArray vsel = ld->GetTVVertSelection(); BitArray holdFSel(fsel); fsel = subFaceSel; ld->GetVertSelFromFace(vsel); ld->SetTVVertSelection(vsel); ld->SetFaceSelection(holdFSel);//fsel = holdFSel; } else if (fnGetTVSubMode() == TVEDGEMODE) { BitArray fsel = ld->GetFaceSelection(); BitArray esel = ld->GetTVEdgeSelection(); BitArray holdFSel(fsel); fsel = subFaceSel; ld->GetVertSelFromFace(fsel); ld->SetFaceSelection(fsel);// ld->GetEdgeSelFromVert(esel,FALSE); ld->SetTVEdgeSelection(esel); ld->SetFaceSelection(holdFSel);//fsel = holdFSel; } else if (fnGetTVSubMode() == TVFACEMODE) { ld->SetFaceSelection(subFaceSel);//fsel = subFaceSel; } } else { // md->faceSel = holdFaceSel; ld->SetFaceSelection(subFaceSel); /* if (fnGetTVSubMode() == TVFACEMODE) { ld->SetFaceSelection(subFaceSel);//fsel = subFaceSel; } */ } } CleanUpDeadVertices(); theHold.Accept(GetString(IDS_PW_PASTE)); NotifyDependents(FOREVER,PART_ALL,REFMSG_CHANGE); InvalidateView(); GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime()); }
void UnwrapMod::fnFlattenMap(float angleThreshold, Tab<Point3*> *normalList, float spacing, BOOL normalize, int layoutType, BOOL rotateClusters, BOOL fillHoles) { for (int i = 0; i < mMeshTopoData.Count(); i++) { mMeshTopoData[i]->HoldSelection(); } BailStart(); if (preventFlattening) return; /* if (TVMaps.f.Count() == 0) return; BitArray *polySel = fnGetSelectedPolygons(); if (polySel == NULL) return; */ theHold.Begin(); HoldPointsAndFaces(); /* BitArray holdPolySel; holdPolySel.SetSize(polySel->GetSize()); holdPolySel = *polySel; */ Point3 normal(0.0f,0.0f,1.0f); Tab<Point3> mapNormal; mapNormal.SetCount(normalList->Count()); for (int i =0; i < mapNormal.Count(); i++) { mapNormal[i] = *(*normalList)[i]; } BOOL noSelection = TRUE; for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) { if (mMeshTopoData[ldID]->GetFaceSelection().NumberSet()) noSelection = FALSE; } if (noSelection) { for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) { BitArray fsel = mMeshTopoData[ldID]->GetFaceSelection(); fsel.SetAll(); mMeshTopoData[ldID]->SetFaceSelection(fsel); } } TSTR statusMessage; MeshTopoData::GroupBy groupBy = MeshTopoData::kFaceAngle; int v = 0; pblock->GetValue(unwrap_flattenby,0,v,FOREVER); if (v == 0) groupBy = MeshTopoData::kFaceAngle; else if (v == 2) groupBy = MeshTopoData::kMaterialID; else if (v == 1) groupBy = MeshTopoData::kSmoothingGroup; BOOL bContinue = BuildCluster( mapNormal, angleThreshold, TRUE,TRUE,groupBy); /* BitArray sel; sel.SetSize(TVMaps.f.Count()); */ gBArea = 0.0f; int initialCluster = clusterList.Count(); if (bContinue) { for (int i =0; i < clusterList.Count(); i++) { MeshTopoData *ld = clusterList[i]->ld; ld->ClearSelection(TVFACEMODE);// sel.ClearAll(); for (int j = 0; j < clusterList[i]->faces.Count();j++) ld->SetFaceSelected(clusterList[i]->faces[j],TRUE);//sel.Set(clusterList[i]->faces[j]); ld->PlanarMapNoScale(clusterList[i]->normal,this); int per = (i * 100)/clusterList.Count(); statusMessage.printf(_T("%s %d%%."),GetString(IDS_PW_STATUS_MAPPING),per); if (Bail(ip,statusMessage)) { i = clusterList.Count(); bContinue = FALSE; } } // if (0) if (bContinue) { for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) mMeshTopoData[ldID]->UpdateClusterVertices(clusterList); if (layoutType == 1) bContinue = LayoutClusters( spacing, rotateClusters, TRUE, fillHoles); else { if (flattenMax5) bContinue = LayoutClusters3( spacing, rotateClusters, fillHoles); else bContinue = LayoutClusters2( spacing, rotateClusters, fillHoles); } //normalize map to 0,0 to 1,1 if ((bContinue) && (normalize)) { NormalizeCluster(spacing); } } } CleanUpDeadVertices(); if (bContinue) { theHold.Accept(GetString(IDS_PW_FLATTEN)); theHold.Suspend(); fnSyncTVSelection(); theHold.Resume(); } else { theHold.Cancel(); // theHold.SuperCancel(); } for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++) { mMeshTopoData[ldID]->SetTVEdgeInvalid(); mMeshTopoData[ldID]->BuildTVEdges(); mMeshTopoData[ldID]->BuildVertexClusterList(); } theHold.Suspend(); fnSyncTVSelection(); fnSyncGeomSelection(); theHold.Resume(); for (int i = 0; i < mMeshTopoData.Count(); i++) { mMeshTopoData[i]->RestoreSelection(); } NotifyDependents(FOREVER,PART_SELECT,REFMSG_CHANGE); InvalidateView(); #ifdef DEBUGMODE if (gDebugLevel >= 1) { int finalCluster = clusterList.Count(); gEdgeHeight = 0.0f; gEdgeWidth = 0.0f; for (int i =0; i < clusterList.Count(); i++) { gEdgeHeight += clusterList[i]->h; gEdgeWidth += clusterList[i]->w; } ScriptPrint(_T("Surface Area %f bounds area %f per used %f\n"),gSArea,gBArea,gSArea/gBArea); ScriptPrint(_T("Edge Height %f Edge Width %f\n"),gEdgeHeight,gEdgeWidth); ScriptPrint(_T("Initial Clusters %d finalClusters %d\n"),initialCluster,finalCluster); } #endif FreeClusterList(); statusMessage.printf(_T("Done, area coverage %3.2f"),(gSArea/gBArea)*100.f); Bail(ip,statusMessage,0); }