Exemplo n.º 1
0
void MainWindow::_update_scene_matrix(const QMatrix4x4& mat)
{
    QMatrix4x4 moo;

    QVector3D eye(sqrt(2.0)*_axis_len/2.0,
                  0,
                  sqrt(2.0)*_axis_len/2.0);
    QVector3D center(0,0,0);
    QVector3D up(0,1,0);

    //moo.lookAt(eye,center,up);

    QVector4D xvec(_axis_len,0,0,1);
    QVector4D yvec(0,_axis_len,0,1);
    QVector4D zvec(0,0,_axis_len,1);

    xvec = moo*_mat*xvec;
    yvec = moo*_mat*yvec;
    zvec = moo*_mat*zvec;

    _xitem->setLine(0,0,xvec.x(),-xvec.y());
    _yitem->setLine(0,0,yvec.x(),-yvec.y());
    _zitem->setLine(0,0,zvec.x(),-zvec.y());
}
void MeshTopoData::ApplyMap(int mapType,  BOOL normalizeMap, Matrix3 gizmoTM, UnwrapMod *mod)
{
//this just catches some strane cases where the z axis is 0 which causes some bad numbers
/*
if (Length(gizmoTM.GetRow(2)) == 0.0f)
	{
		gizmoTM.SetRow(2,Point3(0.0f,0.0f,1.0f));
	}
*/

	float circ = 1.0f;
/*
 	if (!normalizeMap)
	{
		for (int i = 0; i < 3; i++)
		{
			Point3 vec = gizmoTM.GetRow(i);
			vec = Normalize(vec);
			gizmoTM.SetRow(i,vec);
		}
	}
*/
	Matrix3 toGizmoSpace = gizmoTM;

	BitArray tempVSel;
	DetachFromGeoFaces(mFSel, tempVSel, mod);
	TimeValue t = GetCOREInterface()->GetTime();

	//build available list

	if (mapType == SPHERICALMAP)
	{
		Tab<int> quads;
		quads.SetCount(TVMaps.v.Count());

		float longestR = 0.0f;
		for (int i = 0; i < TVMaps.v.Count(); i++)
		{
			BOOL found = FALSE;
			quads[i] = -1;
			if (tempVSel[i])
			{

				Point3 tp = TVMaps.v[i].GetP() * gizmoTM;//gverts.d[i].p * gtm;
					//z our y

				int quad = 0;
				if ((tp.x >= 0) && (tp.y >= 0))
					quad = 0;
				else if ((tp.x < 0) && (tp.y >= 0))
					quad = 1;
				else if ((tp.x < 0) && (tp.y < 0))
					quad = 2;
				else if ((tp.x >= 0) && (tp.y < 0))
					quad = 3;

				quads[i] = quad;

				//find the quad the point is in
			 	Point3 xvec(1.0f,0.0f,0.0f);
				Point3 zvec(0.0f,0.0f,-1.0f);

				float x= 0.0f;
				Point3 zp = tp;
				zp.z = 0.0f;
				
				float dot = DotProd(xvec,Normalize(zp));
				float angle = 0.0f;
				if (dot >= 1.0f)
					angle = 0.0f;
				else angle = acos(dot);

				x = angle/(PI*2.0f);
				if (quad > 1)
					x = (0.5f - x) + 0.5f;

				dot = DotProd(zvec,Normalize(tp));
				float yangle = 0.0f;
				if (dot >= 1.0f)
					yangle = 0.0f;
				else yangle = acos(dot);

				float y = yangle/(PI);
								
				tp.x = x;	
				tp.y = y;//tp.z;	
				float d = Length(tp);	
				tp.z = d;
				if (d > longestR)
					longestR = d;	

				TVMaps.v[i].SetFlag( 0 );
				TVMaps.v[i].SetInfluence( 0.0f );					
				TVMaps.v[i].SetP(tp);
				TVMaps.v[i].SetControlID(-1);
				mVSel.Set(i);
/*
				if (ct < alist.Count() )
				{
					int j = alist[ct];
					TVMaps.v[j].flags = 0;
					TVMaps.v[j].influence = 0.0f;					


					TVMaps.v[j].p = tp;
					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;

					tempv.p = tp;

					tempv.flags = 0;
					tempv.influence = 0.0f;
					gverts.d[i].newindex = TVMaps.v.Count();
					TVMaps.v.Append(1,&tempv,5000);

					int vct = TVMaps.v.Count()-1;
					extraSel.Append(1,&vct,5000);


					Control* c;
					c = NULL;
					TVMaps.cont.Append(1,&c,5000);
					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
		Tab<int> faceAcrossSeam;
		for (int i = 0; i < TVMaps.f.Count(); i++)
		{			
			if (mFSel[i])
			{
				//		ActiveAddFaces.Append(1,&i,1);
				int ct = i;//gfaces[i]->FaceIndex;
//				TVMaps.f[ct]->flags = gfaces[i]->flags;
//				TVMaps.f[ct]->flags |= FLAG_SELECTED;
				int pcount = 3;
				//		if (gfaces[i].flags & FLAG_QUAD) pcount = 4;
				pcount = TVMaps.f[i]->count;//gfaces[i]->count;
				int quad0 = 0;
				int quad3 = 0;
				for (int j = 0; j < pcount; j++)
				{
					int index = TVMaps.f[i]->t[j];
					if (quads[index] == 0) quad0++;
					if (quads[index] == 3) quad3++;
					//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 = TVMaps.f[i]->vecs->handles[j*2];

						if (quads[index] == 0) quad0++;
						if (quads[index] == 3) quad3++;
						//find spot in our list
//						TVMaps.f[ct]->vecs->handles[j*2] = gverts.d[index].newindex;

						index = TVMaps.f[i]->vecs->handles[j*2+1];
						if (quads[index] == 0) quad0++;
						if (quads[index] == 3) quad3++;
						//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 = TVMaps.f[i]->vecs->interiors[j];
							if (quads[index] == 0) quad0++;
							if (quads[index] == 3) quad3++;
							//find spot in our list
//							TVMaps.f[ct]->vecs->interiors[j] = gverts.d[index].newindex;
						}

					}
				}

				if ((quad3 > 0) && (quad0 > 0))
				{
 					for (int j = 0; j < pcount; j++)
					{
						//find spot in our list
						int index = TVMaps.f[ct]->t[j];
						if (TVMaps.v[index].GetP().x <= 0.25f)
						{
							UVW_TVVertClass tempv = TVMaps.v[index];
							Point3 fp = tempv.GetP();
							fp.x += 1.0f;
							tempv.SetP(fp);
							tempv.SetFlag(0);
							tempv.SetInfluence( 0.0f);
							TVMaps.v.Append(1,&tempv,5000);
							int vct = TVMaps.v.Count()-1;
							TVMaps.f[ct]->t[j] = vct;
						}

						if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs))
						{
							

							//find spot in our list
							int index = TVMaps.f[ct]->vecs->handles[j*2];

							if (TVMaps.v[index].GetP().x <= 0.25f)
							{
								UVW_TVVertClass tempv = TVMaps.v[index];
								Point3 fp = tempv.GetP();
								fp.x += 1.0f;
								tempv.SetP(fp);
								tempv.SetFlag(0);
								tempv.SetInfluence( 0.0f);
								TVMaps.v.Append(1,&tempv,5000);
								int vct = TVMaps.v.Count()-1;
								TVMaps.f[ct]->vecs->handles[j*2] = vct;
							}
							//find spot in our list
							index = TVMaps.f[ct]->vecs->handles[j*2+1];
							if (TVMaps.v[index].GetP().x <= 0.25f)
							{
								UVW_TVVertClass tempv = TVMaps.v[index];
								Point3 fp = tempv.GetP();
								fp.x += 1.0f;
								tempv.SetP(fp);
								tempv.SetFlag(0);
								tempv.SetInfluence( 0.0f);
								TVMaps.v.Append(1,&tempv,5000);
								int vct = TVMaps.v.Count()-1;
								TVMaps.f[ct]->vecs->handles[j*2+1] = vct;
							}
							if (TVMaps.f[ct]->flags & FLAG_INTERIOR)
							{
								index = TVMaps.f[ct]->vecs->interiors[j];
								if (TVMaps.v[index].GetP().x <= 0.25f)
								{
									UVW_TVVertClass tempv = TVMaps.v[index];
									Point3 fp = tempv.GetP();
									fp.x += 1.0f;
									tempv.SetP(fp);
									tempv.SetFlag(0);
									tempv.SetInfluence( 0.0f);
									TVMaps.v.Append(1,&tempv,5000);
									int vct = TVMaps.v.Count()-1;
									TVMaps.f[ct]->vecs->interiors[j] = vct;
								}
							}

						}
					}
				}

			}
		}

		if (!normalizeMap)
		{
			BitArray processedVerts;
			processedVerts.SetSize(TVMaps.v.Count());
			processedVerts.ClearAll();
			circ = circ * PI * longestR * 2.0f;
			for (int i = 0; i < TVMaps.f.Count(); i++)
			{	
				if (mFSel[i])
				{
					int pcount = 3;
					//		if (gfaces[i].flags & FLAG_QUAD) pcount = 4;
					pcount = TVMaps.f[i]->count;
 					int ct = i;
						
						for (int j = 0; j < pcount; j++)
						{
							//find spot in our list
							int index = TVMaps.f[ct]->t[j];
							if (!processedVerts[index])
							{
								Point3 p = TVMaps.v[index].GetP();
								p.x *= circ;
								p.y *= circ;
								TVMaps.v[index].SetP(p);
								processedVerts.Set(index,TRUE);
							}

							if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs))
							{
								

								//find spot in our list
								int index = TVMaps.f[ct]->vecs->handles[j*2];
								if (!processedVerts[index])
								{
									Point3 p = TVMaps.v[index].GetP();
									p.x *= circ;
									p.y *= circ;
									TVMaps.v[index].SetP(p);
									processedVerts.Set(index,TRUE);
								}
								//find spot in our list
								index = TVMaps.f[ct]->vecs->handles[j*2+1];
								if (!processedVerts[index])
								{
									Point3 p = TVMaps.v[index].GetP();
									p.x *= circ;
									p.y *= circ;
									TVMaps.v[index].SetP(p);
									processedVerts.Set(index,TRUE);
								}
								if (TVMaps.f[ct]->flags & FLAG_INTERIOR)
								{
									index = TVMaps.f[ct]->vecs->interiors[j];
									if (!processedVerts[index])
									{
										Point3 p = TVMaps.v[index].GetP();
										p.x *= circ;
										p.y *= circ;
										TVMaps.v[index].SetP(p);
										processedVerts.Set(index,TRUE);
									}
								}
							}
						}						
					}
			}
		}

		
		//now find the seam
		mVSel.SetSize(TVMaps.v.Count(), 1);
		mVSel.Set(TVMaps.v.Count()-1);
		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count(), 1);
/*		for (int i = 0; i < extraSel.Count(); i++)
			vsel.Set(extraSel[i],TRUE);
*/
	}
	else if (mapType == CYLINDRICALMAP)
	{
		Tab<int> quads;
		quads.SetCount(TVMaps.v.Count());

		float longestR = 0.0f;

		for (int i = 0; i < TVMaps.v.Count(); i++)
		{

			BOOL found = FALSE;
			quads[i] = -1;
			if (tempVSel[i])
//			if (gverts.sel[i])
			{

				Point3 gp = TVMaps.v[i].GetP();//gverts.d[i].p;
				Point3 tp = gp * toGizmoSpace;
					//z our y

				int quad = 0;
				if ((tp.x >= 0) && (tp.y >= 0))
					quad = 0;
				else if ((tp.x < 0) && (tp.y >= 0))
					quad = 1;
				else if ((tp.x < 0) && (tp.y < 0))
					quad = 2;
				else if ((tp.x >= 0) && (tp.y < 0))
					quad = 3;

				quads[i] = quad;

				//find the quad the point is in
			 	Point3 xvec(1.0f,0.0f,0.0f);
				
				float x= 0.0f;
				Point3 zp = tp;
				zp.z = 0.0f;
				
				float dot = DotProd(xvec,Normalize(zp));
				float angle = 0.0f;
				if (dot >= 1.0f)
					angle = 0.0f;
				else angle = acos(dot);

				x = angle/(PI*2.0f);
				if (quad > 1)
					x = (0.5f - x) + 0.5f;

				TVMaps.v[i].SetFlag(0);
				TVMaps.v[i].SetInfluence(0.0f);

				Point3 fp;
				fp.x = x;	
				fp.y = tp.z;	
				float d = Length(zp);	
				fp.z = d;

				SetTVVert(t,i,fp,mod);				


				if (d > longestR)
					longestR = d;
								
			}
		}


		//now copy our face data over
		Tab<int> faceAcrossSeam;
		for (int i = 0; i < TVMaps.f.Count(); i++)
		{			
			if (mFSel[i])
			{
				int ct = i;
				int pcount = 3;
				//		if (gfaces[i].flags & FLAG_QUAD) pcount = 4;
				pcount = TVMaps.f[i]->count;
				int quad0 = 0;
				int quad3 = 0;
				for (int j = 0; j < pcount; j++)
				{
					int index = TVMaps.f[i]->t[j];
					if (quads[index] == 0) quad0++;
					if (quads[index] == 3) quad3++;
					if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs))
					{
						index = TVMaps.f[i]->vecs->handles[j*2];

						if (quads[index] == 0) quad0++;
						if (quads[index] == 3) quad3++;

						index = TVMaps.f[i]->vecs->handles[j*2+1];
						if (quads[index] == 0) quad0++;
						if (quads[index] == 3) quad3++;
						//find spot in our list

						if (TVMaps.f[ct]->flags & FLAG_INTERIOR)
						{
							index = TVMaps.f[i]->vecs->interiors[j];
							if (quads[index] == 0) quad0++;
							if (quads[index] == 3) quad3++;
						}

					}
				}

				if ((quad3 > 0) && (quad0 > 0))
				{
 					for (int j = 0; j < pcount; j++)
					{
						//find spot in our list
						int index = TVMaps.f[ct]->t[j];
						if (TVMaps.v[index].GetP().x <= 0.25f)
						{
							UVW_TVVertClass tempv = TVMaps.v[index];
							Point3 tpv = tempv.GetP();
							tpv.x += 1.0f;
							tempv.SetP(tpv);							
							tempv.SetFlag(0);
							tempv.SetInfluence(0.0f);
							tempv.SetControlID(-1);
							TVMaps.v.Append(1,&tempv,5000);
							int vct = TVMaps.v.Count()-1;
							TVMaps.f[ct]->t[j] = vct;
						}

						if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs))
						{
							

							//find spot in our list
							int index = TVMaps.f[ct]->vecs->handles[j*2];

							if (TVMaps.v[index].GetP().x <= 0.25f)
							{
								UVW_TVVertClass tempv = TVMaps.v[index];
								Point3 tpv = tempv.GetP();
								tpv.x += 1.0f;
								tempv.SetP(tpv);							
								tempv.SetFlag(0);
								tempv.SetInfluence(0.0f);
								tempv.SetControlID(-1);
								TVMaps.v.Append(1,&tempv,5000);
								int vct = TVMaps.v.Count()-1;
								TVMaps.f[ct]->vecs->handles[j*2] = vct;
							}
							//find spot in our list
							index = TVMaps.f[ct]->vecs->handles[j*2+1];
							if (TVMaps.v[index].GetP().x <= 0.25f)
							{
								UVW_TVVertClass tempv = TVMaps.v[index];
								Point3 tpv = tempv.GetP();
								tpv.x += 1.0f;
								tempv.SetP(tpv);							
								tempv.SetFlag(0);
								tempv.SetInfluence(0.0f);
								tempv.SetControlID(-1);
								TVMaps.v.Append(1,&tempv,5000);
								int vct = TVMaps.v.Count()-1;
								TVMaps.f[ct]->vecs->handles[j*2+1] = vct;
								
							}
							if (TVMaps.f[ct]->flags & FLAG_INTERIOR)
							{
								index = TVMaps.f[ct]->vecs->interiors[j];
								if (TVMaps.v[index].GetP().x <= 0.25f)
								{
									UVW_TVVertClass tempv = TVMaps.v[index];
									Point3 tpv = tempv.GetP();
									tpv.x += 1.0f;
									tempv.SetP(tpv);							
									tempv.SetFlag(0);
									tempv.SetInfluence(0.0f);
									tempv.SetControlID(-1);
									TVMaps.v.Append(1,&tempv,5000);
									int vct = TVMaps.v.Count()-1;
									TVMaps.f[ct]->vecs->interiors[j] = vct;
								}
							}

						}
					}
				}

			}
		}

		if (!normalizeMap)
		{
			BitArray processedVerts;
			processedVerts.SetSize(GetNumberTVVerts());//TVMaps.v.Count());
			processedVerts.ClearAll();
			circ = circ * PI * longestR * 2.0f;
			for (int i = 0; i < GetNumberFaces(); i++)//gfaces.Count(); i++)
			{	
				if (mFSel[i])
				{
					int pcount = 3;
					//		if (gfaces[i].flags & FLAG_QUAD) pcount = 4;
					pcount = GetFaceDegree(i);//gfaces[i]->count;
 					int ct = i;//gfaces[i]->FaceIndex;
						
						for (int j = 0; j < pcount; j++)
						{
							//find spot in our list
							int index = TVMaps.f[ct]->t[j];
							if (!processedVerts[index])
							{
								Point3 p = TVMaps.v[index].GetP();
								p.x *= circ;
								TVMaps.v[index].SetP(p);
								processedVerts.Set(index,TRUE);
							}

							if ((TVMaps.f[ct]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[ct]->vecs))
							{
								

								//find spot in our list
								int index = TVMaps.f[ct]->vecs->handles[j*2];
								if (!processedVerts[index])
								{
									Point3 p = TVMaps.v[index].GetP();
									p.x *= circ;
									TVMaps.v[index].SetP(p);
									processedVerts.Set(index,TRUE);
								}
								//find spot in our list
								index = TVMaps.f[ct]->vecs->handles[j*2+1];
								if (!processedVerts[index])
								{
									Point3 p = TVMaps.v[index].GetP();
									p.x *= circ;
									TVMaps.v[index].SetP(p);
									processedVerts.Set(index,TRUE);
								}
								if (TVMaps.f[ct]->flags & FLAG_INTERIOR)
								{
									index = TVMaps.f[ct]->vecs->interiors[j];
									if (!processedVerts[index])
									{
										Point3 p = TVMaps.v[index].GetP();
										p.x *= circ;
										TVMaps.v[index].SetP(p);
										processedVerts.Set(index,TRUE);
									}
								}

							}
						
					}
				}
			}
		}

		
		//now find the seam
		mVSel.SetSize(TVMaps.v.Count(), 1);
		mVSel.Set(TVMaps.v.Count()-1);
		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count(), 1);
//		for (int i = 0; i < extraSel.Count(); i++)
//			vsel.Set(extraSel[i],TRUE);

	}
	else if ((mapType == PLANARMAP) || (mapType == PELTMAP)|| (mapType == BOXMAP))
	{
		for (int i = 0; i < TVMaps.v.Count(); i++)
		{
			if (tempVSel[i])
			{
				TVMaps.v[i].SetFlag(0);
				TVMaps.v[i].SetInfluence(0.0f);

				Point3 tp = TVMaps.v[i].GetP();
				tp = tp * toGizmoSpace;
				tp.x += 0.5f;
				tp.y += 0.5f;
				tp.z = 0.0f;
				SetTVVert(t,i,tp,mod);				
			}
		}
	}
	
	BuildTVEdges();	
	BuildVertexClusterList();
}