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::DrawGizmo(TimeValue t, INode* inode,/*w4 ModContext *mc, */GraphicsWindow *gw) { ComputeSelectedFaceData(); Matrix3 vtm(1); Interval iv; if (inode) vtm = inode->GetObjectTM(t,&iv); Point3 a(-0.5f,-0.5f,0.0f),b(0.5f,-0.5f,0.0f),c(0.5f,0.5f,0.0f),d(-0.5f,0.5f,0.0f); Matrix3 modmat, ntm = inode->GetObjectTM(t); modmat = GetMapGizmoMatrix(t); gw->setTransform(modmat); if ( (fnGetMapMode() == PLANARMAP) || (fnGetMapMode() == PELTMAP) ) { Point3 line[5]; line[0] = a; line[1] = b; line[2] = c; line[3] = d; line[4] = line[0]; gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); gw->polyline(5, line, NULL, NULL, 0); } else if (fnGetMapMode() == CYLINDRICALMAP) { //draw the bottom circle int segs = 32; float angle = 0.0f; float inc = 1.0f/(float)segs * 2 * PI; Point3 prevVec; gw->startSegments(); Point3 pl[3]; gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); for (int i = 0; i < (segs+1); i++) { Matrix3 tm(1); tm.RotateZ(angle); Point3 vec (0.50f,0.0f,0.0f); vec = vec * tm; if ( i >= 1) { pl[0] = vec; pl[1] = prevVec; gw->segment(pl,1); pl[0].z = 1.0f; pl[1].z = 1.0f; gw->segment(pl,1); if (((i%4) == 0) && (i != segs)) { pl[0] = vec; pl[1] = vec; pl[1].z = 1.0f; gw->segment(pl,1); } } prevVec = vec; angle += inc; } Color c(openEdgeColor); gw->setColor(LINE_COLOR,c); pl[0] = Point3(0.50f,0.0f,0.0f); pl[1] = Point3(0.50f,0.0f,0.0f); pl[1].z = 1.0f; gw->segment(pl,1); gw->endSegments(); } else if (fnGetMapMode() == SPHERICALMAP) { //draw the bottom circle int segs = 32; float inc = 1.0f/(float)segs * 2 * PI; gw->startSegments(); Point3 pl[3]; Color c(openEdgeColor); gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); pl[0] = Point3(0.0f,0.0f,.6f); pl[1] = Point3(0.0f,0.0f,-.5f); gw->segment(pl,1); for (int j = 0; j < 3; j++) { float angle = 0.0f; Point3 prevVec; gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); for (int i = 0; i < (segs+1); i++) { Matrix3 tm(1); Point3 vec (0.50f,0.0f,0.0f); if (j == 0) tm.RotateZ(angle); if (j == 1) { vec = Point3(0.0f,0.5f,0.0f); tm.RotateX(angle); } if (j == 2) { vec = Point3(0.0f,0.0f,-0.5f); if (i < ((segs+2)/2)) gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); else gw->setColor(LINE_COLOR,c); tm.RotateY(angle); } vec = vec * tm; if ( i >= 1) { pl[0] = vec; pl[1] = prevVec; gw->segment(pl,1); } prevVec = vec; angle += inc; } } gw->endSegments(); } else if (fnGetMapMode() == BOXMAP) { Point3 line[3]; gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS)); gw->startSegments(); line[0] = Point3(-0.5f,-0.5f,-0.5f); line[1] = Point3(0.5f,-0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,0.5f,-0.5f); line[1] = Point3(0.5f,0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(0.5f,0.5f,-0.5f); line[1] = Point3(0.5f,-0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,0.5f,-0.5f); line[1] = Point3(-0.5f,-0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,-0.5f,0.5f); line[1] = Point3(0.5f,-0.5f,0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,0.5f,0.5f); line[1] = Point3(0.5f,0.5f,0.5f); gw->segment(line,1); line[0] = Point3(0.5f,0.5f,0.5f); line[1] = Point3(0.5f,-0.5f,0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,0.5f,0.5f); line[1] = Point3(-0.5f,-0.5f,0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,-0.5f,0.5f); line[1] = Point3(-0.5f,-0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(0.5f,-0.5f,0.5f); line[1] = Point3(0.5f,-0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(-0.5f,0.5f,0.5f); line[1] = Point3(-0.5f,0.5f,-0.5f); gw->segment(line,1); line[0] = Point3(0.5f,0.5f,0.5f); line[1] = Point3(0.5f,0.5f,-0.5f); gw->segment(line,1); gw->endSegments(); } }