BOOL PFOperatorInstanceShapeMXSValidator::Validate(PB2Value& v)
{
	INode* iNode = (INode*)v.r;
	if (iNode == NULL) return NULL;
	TimeValue t = GetCOREInterface()->GetTime();
	Tab<INode*> stack;

	stack.Append(1, &iNode, 10);
	while (stack.Count())
	{
		INode *node = stack[stack.Count()-1];
		stack.Delete(stack.Count()-1, 1);

		Object *obj = node->EvalWorldState(t).obj;
		if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0)))
			return TRUE;

		// add children to the stack
		for (int i = 0; i < node->NumberOfChildren(); i++) {
			INode *childNode = node->GetChildNode(i);
			if (childNode)	stack.Append(1, &childNode, 10);
		}
	}
	return FALSE;
}
void Unreal3DExport::RegisterMaterial( IGameNode* node, IGameMesh* mesh, FaceEx* f, FJSMeshTri* tri )
{
    tri->TextureNum = f->matID;

    int matid = f->matID;

    IGameMaterial* mat = mesh->GetMaterialFromFace(f);
    if( mat )
    {
        Tab<TSTR*> tokens = TokStr(mat->GetMaterialName(),_T(" \t,;"));
        for( int i=0; i!=tokens.Count(); ++i )
        {
            if( MatchPattern(*tokens[i],TSTR(_T("F=*")),TRUE) )
            {
                SplitStr(*tokens[i],_T('='));
                tri->Flags = static_cast<byte>(_ttoi(tokens[i]->data()));
            }
        }
        tokens.Delete(0,tokens.Count());

        if( Materials.Count() <= matid )
        {
            Materials.Append(matid-Materials.Count()+1,&sMaterial::DefaultMaterial);
        }
        
        if( Materials[matid].Mat != mat )
        {
            Materials[matid].Mat = mat;
        }

        /*for( int i=0; i!=mat->GetSubMaterialCount(); ++i )
        {
            IGameMaterial* sub = mat->GetSubMaterial(i);
            if( sub )
            {
                TSTR matname = sub->GetMaterialName();
                int subid = mat->GetMaterialID(i);
                int x = 0;
            }
        }*/
    }
}
Ejemplo n.º 3
0
void TVConnectionInfo::OrderLists()
{

	int hiddenVertID = -1;
	for (int i = 0; i < mVertex.Count(); i++)
	{




		if (mVertex[i]->mConnectedFaces.Count() > 0)
		{
		//	DumpVert(i);

			//order our faces
			Tab<int> faceStack;
			Tab<int> finalFaceStack;
			Tab<int> remainingFaces = mVertex[i]->mConnectedFaces;
			faceStack.Append(1,&remainingFaces[0]);
			remainingFaces.Delete(0,1);
			int vert = i;
			
			//gather all the faces that are together and ordered them
			while (remainingFaces.Count() > 0)
			{
				int currentFace = faceStack[0];
				int prevVert = -1;
				int nextVert = -1;
				int deg = mMd->GetFaceDegree(currentFace);
				for (int j = 0; j < deg; j++)
				{
					int a = mMd->GetFaceTVVert(currentFace,j);
					if (a == vert)
					{
						nextVert = mMd->GetFaceTVVert(currentFace,(j+1)%deg);
						prevVert = mMd->GetFaceTVVert(currentFace,(j+deg-1)%deg);
						j = deg;
					}
				}

				int  hit = FALSE;
				for (int j = 0; j < remainingFaces.Count(); j++)
				{
					int faceIndex = remainingFaces[j];
					//see if we have any matching faces
					int ithEdge = mMd->FindUVEdge(faceIndex,vert,nextVert);
					if (ithEdge != -1) //we have a match
					{
						faceStack.Append(1,&faceIndex,8);
						remainingFaces.Delete(j,1);					 
						j = -1;
						hit = TRUE;

						//find the new nextvert
						int deg = mMd->GetFaceDegree(faceIndex);						
						for (int k = 0; k < deg; k++)
						{
							int a = mMd->GetFaceTVVert(faceIndex,k);
							if (a == vert)
							{
								nextVert = mMd->GetFaceTVVert(faceIndex,(k+1)%deg);
								k = deg;
							}
						}
					}
					else
					{
						ithEdge = mMd->FindUVEdge(faceIndex,vert,prevVert);
						if (ithEdge != -1) //we have a match
						{
							faceStack.Insert(0,1,&faceIndex);
							remainingFaces.Delete(j,1);
							j = -1;
							hit = TRUE;

							//find the new prevvert
							int deg = mMd->GetFaceDegree(faceIndex);
							for (int k = 0; k < deg; k++)
							{
								int a = mMd->GetFaceTVVert(faceIndex,k);
								if (a == vert)
								{									
									prevVert = mMd->GetFaceTVVert(faceIndex,(k+deg-1)%deg);
									k = deg;
								}
							}
						}						
					}
				}

				//see if we hit an open edge if so add all the faces we have and add a -1 to mark the gap
				int remainingFacesCount = remainingFaces.Count();
				if (hit == FALSE || (remainingFacesCount == 0))
				{
					for (int j = 0; j < faceStack.Count(); j++)
						finalFaceStack.Append(1,&faceStack[j],8);
					int neg = -1;
					if (remainingFaces.Count() != 0)
						finalFaceStack.Append(1,&neg);

					if (remainingFaces.Count() > 0)
					{											
						faceStack.SetCount(0);
						faceStack.Append(1,&remainingFaces[0],8);
						remainingFaces.Delete(0,1);
					}
				}

			}


			//special condition with 1 face
			if (mVertex[i]->mConnectedFaces.Count() == 1)
			{
				int neg = -1;
				finalFaceStack = mVertex[i]->mConnectedFaces;
				finalFaceStack.Append(1,&neg);
			}		
			//else see if the last and end faces dont connect and if mark it with -1 
			else if (mVertex[i]->mConnectedFaces.Count() > 1)
			{

				int firstFace = finalFaceStack[0];
				int lastFace = finalFaceStack[finalFaceStack.Count()-1];
				int pVert = -1;
				int nVert = -1;
				if ((firstFace != -1) && (lastFace != -1))
				{
					int deg = mMd->GetFaceDegree(firstFace);
					for (int j = 0; j < deg; j++)
					{
						int a = mMd->GetFaceTVVert(firstFace,j);
						if (a == vert)
						{						
							pVert = mMd->GetFaceTVVert(firstFace,(j+deg-1)%deg);
							j = deg;
						}
					}
					deg = mMd->GetFaceDegree(lastFace);
					for (int j = 0; j < deg; j++)
					{
						int a = mMd->GetFaceTVVert(lastFace,j);
						if (a == vert)
						{
							nVert = mMd->GetFaceTVVert(lastFace,(j+1)%deg);
							j = deg;
						}
					}
				}

				//there is a gap add a neg -1 to signify this
				if (nVert != pVert)
				{
					int neg = -1;
					finalFaceStack.Append(1,&neg);
				}
			}



/*
			DebugPrint ("	unordered face list ");
			for (int j = 0; j < mVertex[i]->mConnectedFaces.Count(); j++)
			{
				DebugPrint(_T(" %d"),mVertex[i]->mConnectedFaces[j]);
			}
			DebugPrint (_T("\n"));

*/
			mVertex[i]->mConnectedFaces = finalFaceStack;
/*
			DebugPrint ("	ordered face list ");
			for (int j = 0; j < mVertex[i]->mConnectedFaces.Count(); j++)
			{
				DebugPrint(_T(" %d"),mVertex[i]->mConnectedFaces[j]);
			}
			DebugPrint (_T("\n"));
*/
			
			
			//now order the edges
			//just a temp list to store the verts as we sort them
			Tab<VertexConnectedTo> sortedtVerts;
			
			if (mVertex[i]->mConnectedFaces.Count() == 2)  //special case for corners since they have both the same face IDs
			{
				int faceIndex1 = mVertex[i]->mConnectedFaces[0];
				if (faceIndex1 == -1)
					faceIndex1 = mVertex[i]->mConnectedFaces[1];
								
				int prevVert = -1;
				int nextVert = -1;
				int deg = mMd->GetFaceDegree(faceIndex1);
				for (int j = 0; j < deg; j++)
				{
					int a = mMd->GetFaceTVVert(faceIndex1,j);
					if (a == vert)
					{
						nextVert = mMd->GetFaceTVVert(faceIndex1,(j+1)%deg);
						prevVert = mMd->GetFaceTVVert(faceIndex1,(j+deg-1)%deg);
						j = deg;
					}
				}

				//see if we need to swap edge order
				if (mVertex[i]->mConnectedTo[0].mVert == nextVert)
				{
					
					sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[1],8);
					sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[0],8);
				}
				else
				{
					sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[0],8);
					sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[1],8);
				}
				VertexConnectedTo data(hiddenVertID--,-1,0,-1,-1,FALSE);
				sortedtVerts.Append(1,&data,8);

			}
			else
			{
				int currentEdge = 0;
				//we can just walk around looking for matching faces at the edge
				for (int faceIndex = 0; faceIndex < mVertex[i]->mConnectedFaces.Count(); faceIndex++)
				{
					int fa = finalFaceStack[faceIndex];
					int fb = finalFaceStack[(faceIndex+1)%mVertex[i]->mConnectedFaces.Count()];
					//make sure to add the gap if there is no face 
					if (fa == -1)
					{
						VertexConnectedTo data(hiddenVertID--,-1,0,-1,-1,FALSE);
						sortedtVerts.Append(1,&data,8);  //open edges are not hidden since we want to count them for purpuses of rings and loops
						currentEdge++;
					}
					//find a matching edge
					for (int k = 0; k < mVertex[i]->mConnectedTo.Count(); k++)
					{
						int testa = mVertex[i]->mConnectedTo[k].mFace[0];
						int testb = mVertex[i]->mConnectedTo[k].mFace[1];
						if ( ((testa == fa)  && (testb == fb)) ||
							((testa == fb)  && (testb == fa)) )
						{
							sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[k],8);
	//						sortedtVerts[currentEdge] = mVertex[i]->mConnectedTo[k];
							currentEdge++;
							k =  mVertex[i]->mConnectedTo.Count();
						}
					}
				}
			}
/*
			DebugPrint ("	unordered edge list ");
			for (int j = 0; j < mVertex[i]->mConnectedTo.Count(); j++)
			{
				DebugPrint(_T(" %d"),mVertex[i]->mConnectedTo[j].mVert);
			}
			DebugPrint (_T("\n"));
*/

			mVertex[i]->mConnectedTo = sortedtVerts;

/*
			DebugPrint ("	ordered edge list ");
			for (int j = 0; j < mVertex[i]->mConnectedTo.Count(); j++)
			{
				DebugPrint(_T(" %d"),mVertex[i]->mConnectedTo[j].mVert);
			}
			DebugPrint (_T("\n"));
*/

			int ct = mVertex[i]->mConnectedTo.Count();
			for (int j = 0; j < ct; j++)
			{
				if (mVertex[i]->mConnectedTo[j].mHiddenEdge)
					mVertex[i]->mHiddenEdgeCount++;
				else 
					mVertex[i]->mVisibleEdgeCount++;
			}
		}
	}

//build our opposing edges now
	for (int i = 0; i < mVertex.Count(); i++)
	{
		
		Vertex *v = mVertex[i];
		v->mNumRealEdges = 0;
		int deg = v->mConnectedTo.Count();
		for (int j = 0; j < deg; j++)
		{
			if ( (v->mConnectedTo[j].mVert >= 0) && (v->mConnectedTo[j].mHiddenEdge == FALSE) )
				v->mNumRealEdges++;
		}


		if (v->mNumRealEdges == 3)
		{
			int center = -1;
			for (int j = 0; j < deg; j++)
			{
				if (v->mConnectedTo[j].mVert < 0) 
					center = j;
					
			}

			bool done = false;
			int prevIth = center;
			int nextIth = center;
			int nIndex = -1;
			int pIndex = -1;
			while (!done)
			{
				nextIth++;
				prevIth--;
				nextIth = (nextIth+deg)%deg;
				prevIth = (prevIth+deg)%deg;
				if ((v->mConnectedTo[nextIth].mVert >= 0) && (v->mConnectedTo[nextIth].mHiddenEdge == FALSE) )
				{
					if (nIndex == -1)
						nIndex = nextIth;
				}
				if ((v->mConnectedTo[prevIth].mVert >= 0) && (v->mConnectedTo[prevIth].mHiddenEdge == FALSE) )
				{
					if (pIndex == -1)
						pIndex = prevIth;
				}
				if ((pIndex != -1) && (nIndex != -1))
					done = true;
			}
			//find our -1 edge go left and right of it til hit a real edge
			v->mConnectedTo[pIndex].mIthOpposingEdge = nIndex;
			v->mConnectedTo[nIndex].mIthOpposingEdge = pIndex;

		}
		else if (v->mNumRealEdges > 3)
		{
			BOOL valid = FALSE;
			if ((v->mNumRealEdges%2) == 0)
				valid = TRUE;
			if (valid)
			{
				int halfIth = v->mNumRealEdges/2;
				for (int j = 0; j < deg; j++)
				{
					int startIndex = j;
					BOOL isEdgeHidden = v->mConnectedTo[startIndex].mHiddenEdge;
					
					if ( (v->mConnectedTo[startIndex].mVert < 0) || isEdgeHidden )
						v->mConnectedTo[j].mIthOpposingEdge = -1;
					else
					{
						int ct = 0;
						while (ct != halfIth)
						{
							startIndex++;
							if (startIndex >= deg)
								startIndex = 0;
							if ( (v->mConnectedTo[startIndex].mVert >= 0) && (v->mConnectedTo[startIndex].mHiddenEdge == FALSE) )
								ct++;
						}
						v->mConnectedTo[j].mIthOpposingEdge = startIndex;
					}
				}

			}
			else
				for (int j = 0; j < deg; j++)
					v->mConnectedTo[j].mIthOpposingEdge = -1;
		}
//		DumpVert(i);
	}

}
Ejemplo n.º 4
0
//pelt
void UVW_ChannelClass::EdgeListFromPoints(Tab<int> &selEdges, int source, int target, Point3 vec)
{
	//make sure point a and b are on the same element if not bail
	Tab<VConnections*> ourConnects;
	BOOL del = FALSE;

	BitArray selVerts;
	selVerts.SetSize(geomPoints.Count());
	selVerts.ClearAll();

//	if (TRUE)
	
		//loop through the edges
		Tab<int> numberOfConnections;
		numberOfConnections.SetCount(geomPoints.Count());
		for (int i = 0; i < geomPoints.Count(); i++)
		{
			numberOfConnections[i] = 0;
		}
		//count the number of vertxs connected
		for (int i = 0; i < gePtrList.Count(); i++)
		{
			if (!(gePtrList[i]->flags & FLAG_HIDDENEDGEA))
			{
				int a = gePtrList[i]->a;
				numberOfConnections[a] +=1;
				int b = gePtrList[i]->b;
				numberOfConnections[b] +=1;
			}
		}
		//allocate our connections now

		ourConnects.SetCount(geomPoints.Count());
		for (int i = 0; i < geomPoints.Count(); i++)
		{
			ourConnects[i] = new VConnections();
			ourConnects[i]->closestNode = NULL;
			ourConnects[i]->linkedListChild = NULL;
			ourConnects[i]->linkedListParent = NULL;
			ourConnects[i]->accumDist = 1.0e+9f;
			ourConnects[i]->solved = FALSE;
			ourConnects[i]->vid = i;

			ourConnects[i]->connectingVerts.SetCount(numberOfConnections[i]);
		}

		for (int i = 0; i < geomPoints.Count(); i++)
		{
			numberOfConnections[i] = 0;
		}

		//build our vconnection data
		for (int i = 0; i < gePtrList.Count(); i++)
		{
			if (!(gePtrList[i]->flags & FLAG_HIDDENEDGEA))
			{
				int a = gePtrList[i]->a;
				int b = gePtrList[i]->b;

				int index = numberOfConnections[a];
				ourConnects[a]->connectingVerts[index].vertexIndex = b;
				ourConnects[a]->connectingVerts[index].edgeIndex = i;
				numberOfConnections[a] +=1;

				index = numberOfConnections[b];
				ourConnects[b]->connectingVerts[index].vertexIndex = a;
				ourConnects[b]->connectingVerts[index].edgeIndex = i;
				numberOfConnections[b] +=1;
			}
		}


		del = TRUE;
	
	//	else ourConnects = vConnects;

	//spider out till hit our target or no more left
	BOOL done = FALSE;
	BOOL hit = FALSE;
	Tab<int> vertsToDo;
	BitArray processedVerts;
	processedVerts.SetSize(ourConnects.Count());
	processedVerts.ClearAll();

	//if no more left bail
	int currentVert = source;
	while (!done)
	{
		//	int startingNumberProcessed = processedVerts.NumberSet();

		int ct = ourConnects[currentVert]->connectingVerts.Count();
		processedVerts.Set(currentVert, TRUE);
		for (int j = 0; j < ct; j++)
		{
			int index = ourConnects[currentVert]->connectingVerts[j].vertexIndex;
			if (index == target) 
			{
				done = TRUE;
				hit = TRUE;
			}
			if (!processedVerts[index])
				vertsToDo.Append(1,&index, 10000);
		}

		if (vertsToDo.Count())
		{
			currentVert = vertsToDo[vertsToDo.Count()-1];
			vertsToDo.Delete(vertsToDo.Count()-1,1);
		}

		if (vertsToDo.Count() == 0) done = TRUE;
		//		int endingNumberProcessed = processedVerts.NumberSet();

		if (currentVert == target) 
		{
			done = TRUE;
			hit = TRUE;
		}
		//		if (startingNumberProcessed == endingNumberProcessed)
		//			done = TRUE;
	}
	vertsToDo.ZeroCount();

 	if (hit)
	{
		Tab<VConnections*> solvedNodes;

		ourConnects[source]->accumDist = 0;

		VConnections* unsolvedNodeHead = ourConnects[source];
		VConnections* unsolvedNodeCurrent = unsolvedNodeHead;
		
		//put all our vertices in the unsolved list
		
		for (int i = 0; i < ourConnects.Count(); i++)
		{			
			if (ourConnects[i] != unsolvedNodeHead)
			{
				unsolvedNodeCurrent->linkedListChild = ourConnects[i];
				VConnections *parent = unsolvedNodeCurrent;
				unsolvedNodeCurrent = ourConnects[i];
				unsolvedNodeCurrent->linkedListParent = parent;
			}
		}

		//build our edge distances
		Tab<float> edgeDistances;
		edgeDistances.SetCount(gePtrList.Count());
		for (int i = 0 ; i < gePtrList.Count(); i++)
		{
			int a = gePtrList[i]->a;
			int b = gePtrList[i]->b;
			float d = Length(geomPoints[a] - geomPoints[b]);
			edgeDistances[i] = d;

		}


		BOOL done = FALSE;
		while (!done)
		{
			//pop the top unsolved
			VConnections *top = unsolvedNodeHead;


			unsolvedNodeHead = unsolvedNodeHead->linkedListChild;
			top->linkedListChild = NULL;
			top->linkedListParent = NULL;
			if (unsolvedNodeHead != NULL)
			{
				unsolvedNodeHead->linkedListParent = NULL;
				//mark it as processed
				top->solved = TRUE;
				
				//put it in our solved list
				solvedNodes.Append(1,&top,5000);

				int neighborCount = top->connectingVerts.Count();
				//loop through the neighbors
				for (int i = 0; i < neighborCount; i++)
				{
					int index  = top->connectingVerts[i].vertexIndex;
					int eindex  = top->connectingVerts[i].edgeIndex;
					VConnections *neighbor = ourConnects[index];
					//make sure it is not procssedd
					if (!neighbor->solved)
					{
						//find the distance from the top to this neighbor
						float d = neighbor->accumDist;
						float testAccumDistance = top->accumDist + edgeDistances[eindex];
						//see if it accum dist needs to be relaxed
						if (testAccumDistance<d)
						{
							float originalDist = neighbor->accumDist;
							neighbor->accumDist = testAccumDistance;
							neighbor->closestNode = top;
							//sort this node
							float dist = neighbor->accumDist;


							if (originalDist == 1.0e+9f)
							{
								//start at the top and look down
								VConnections *currentNode = unsolvedNodeHead;
								if (neighbor == currentNode)
								{
									currentNode = currentNode->linkedListChild;
									unsolvedNodeHead = currentNode;
								}
								VConnections *prevNode = NULL;
								//unhook node
								VConnections *parent = neighbor->linkedListParent;
								VConnections *child = neighbor->linkedListChild;
								if (parent)
									parent->linkedListChild = child;
								if (child)
									child->linkedListParent = parent;
									

								while ((currentNode!= NULL) && (currentNode->accumDist < dist))
								{
								
									prevNode = currentNode;
									currentNode = currentNode->linkedListChild;
									SHORT iret = GetAsyncKeyState (VK_ESCAPE);
									if (iret==-32767)
									{
										done = TRUE;
										currentNode= NULL;
									}
								}
								//empty list
								if ((prevNode==NULL) && (currentNode== NULL))
								{
									neighbor->linkedListChild = NULL;
									neighbor->linkedListParent = NULL;
									unsolvedNodeHead = neighbor;
								}
								//at top
								else if (currentNode && (prevNode == NULL))
								{
									unsolvedNodeHead->linkedListParent = neighbor;
									neighbor->linkedListParent = NULL;
									neighbor->linkedListChild =unsolvedNodeHead;
									unsolvedNodeHead = neighbor;

								}
								//at bottom
								else if (currentNode == NULL)
								{
									prevNode->linkedListChild = neighbor;
									neighbor->linkedListParent = currentNode;
									neighbor->linkedListChild = NULL;
								}

								else if (currentNode)
								{
									//insert
									VConnections *parent = currentNode->linkedListParent;
									VConnections *child = currentNode;
		
									parent->linkedListChild = neighbor;
									child->linkedListParent = neighbor;

									neighbor->linkedListParent = parent;
									neighbor->linkedListChild = child;

								}



							}
							else
							{
								//sort smallest to largest
								BOOL moveUp = FALSE;

								if (neighbor->linkedListParent && neighbor->linkedListChild)
								{
									float parentDist = neighbor->linkedListParent->accumDist;
									float childDist = neighbor->linkedListChild->accumDist;
									//walkup up or down the list till find a spot an unlink and relink
									
									if ((dist >= parentDist) && (dist <= childDist))
									{
										//done dont need to move
									}
									else if (dist < parentDist)
										moveUp = FALSE;
								}
								else if (neighbor->linkedListParent && (neighbor->linkedListChild==NULL))
								{
									moveUp = TRUE;
								}
								else if ((neighbor->linkedListParent==NULL) && (neighbor->linkedListChild))
								{
									moveUp = FALSE;
								}

								//unlink the node
								//unhook node
								VConnections *parent = neighbor->linkedListParent;
								VConnections *child = neighbor->linkedListChild;
								if (parent)
									parent->linkedListChild = child;
								else unsolvedNodeHead = child;
								if (child)
									child->linkedListParent = parent;

								VConnections *currentNode = NULL;
								if (moveUp)
									currentNode = neighbor->linkedListParent;
								else currentNode = neighbor->linkedListChild;
								VConnections *prevNode = NULL;

								while ((currentNode!= NULL) && (currentNode->accumDist < dist))
								{							
									prevNode = currentNode;
									if (moveUp)
										currentNode = currentNode->linkedListParent;
									else currentNode = currentNode->linkedListChild;

									SHORT iret = GetAsyncKeyState (VK_ESCAPE);
									if (iret==-32767)
									{
										done = TRUE;
										currentNode= NULL;
									}

								}

								//empty list
								if ((prevNode==NULL) && (currentNode== NULL))
								{
									neighbor->linkedListChild = NULL;
									neighbor->linkedListParent = NULL;
									unsolvedNodeHead = neighbor;
								}
								//at top
								else if (currentNode && (prevNode == NULL))
								{
									unsolvedNodeHead->linkedListParent = neighbor;
									neighbor->linkedListParent = NULL;
									neighbor->linkedListChild =unsolvedNodeHead;
									unsolvedNodeHead = neighbor;

								}
								//at bottom
								else if (currentNode == NULL)
								{
									prevNode->linkedListChild = neighbor;
									neighbor->linkedListParent = currentNode;
									neighbor->linkedListChild = NULL;
								}
								else if (currentNode)
								{
									//insert
									VConnections *parent = currentNode->linkedListParent;
									VConnections *child = currentNode;
		
									parent->linkedListChild = neighbor;
									child->linkedListParent = neighbor;

									neighbor->linkedListParent = parent;
									neighbor->linkedListChild = child;

								}


							}

						}					
					}
				}
			}
			

			if (unsolvedNodeHead == NULL)
				done = TRUE;
			if ((solvedNodes[solvedNodes.Count()-1]) == ourConnects[target])
				done = TRUE;
		}
		//now get our edge list
		selEdges.ZeroCount();
		VConnections *cNode = ourConnects[target];
		while ((cNode->closestNode != NULL) && (cNode != ourConnects[source]))
		{
			VConnections *pNode = cNode->closestNode;
			int ct = cNode->connectingVerts.Count();
			int edgeIndex = -1;
			for (int i = 0; i < ct; i++)
			{
				int vindex = cNode->connectingVerts[i].vertexIndex;
				int eindex = cNode->connectingVerts[i].edgeIndex;
				if (ourConnects[vindex] == pNode)
				{
					edgeIndex = eindex;
					i = ct;
				}
			}
			if (edgeIndex != -1)
				selEdges.Append(1,&edgeIndex,500);

			cNode = pNode;
		}

	}

	if (del)
	{
		for (int i = 0; i < geomPoints.Count(); i++)
		{
			delete ourConnects[i];
		}
	}
}
Ejemplo n.º 5
0
void UnwrapMod::GetOpenEdges(MeshTopoData *ld, Tab<int> &openEdges, Tab<int> &results)
{
	if (openEdges.Count() == 0) return;


	int seedEdgeA = openEdges[0];

	if (openEdges.Count() > 0)
	{
		int initialEdge = seedEdgeA;
		results.Append(1,&seedEdgeA,5000);
		openEdges.Delete(0,1);

		int seedVert = ld->GetGeomEdgeVert(seedEdgeA,0);//TVMaps.gePtrList[seedEdgeA]->a;
		BOOL done = FALSE;
		int ct = openEdges.Count();
		while (!done)
		{
			for (int i = 0; i < openEdges.Count(); i++)
			{
				int edgeIndex = openEdges[i];

				if (edgeIndex != seedEdgeA)
				{
					int a = ld->GetGeomEdgeVert(edgeIndex,0);//TVMaps.gePtrList[edgeIndex]->a;
					int b = ld->GetGeomEdgeVert(edgeIndex,1);//TVMaps.gePtrList[edgeIndex]->b;
					if (a == seedVert)
					{
						seedVert = b;
						seedEdgeA = edgeIndex;
						results.Append(1,&seedEdgeA,5000);
						openEdges.Delete(i,1);
						
						i = openEdges.Count();
					}
					else if  (b == seedVert)
					{
						seedVert = a;
						seedEdgeA = edgeIndex;
						results.Append(1,&seedEdgeA,5000);
						openEdges.Delete(i,1);
						i = openEdges.Count();
					}
				}
			}					
			if (ct == openEdges.Count())
				done = TRUE;
			ct = openEdges.Count();
		}


		seedEdgeA = initialEdge;

		seedVert =  ld->GetGeomEdgeVert(seedEdgeA,1);//TVMaps.gePtrList[seedEdgeA]->b;
		done = FALSE;
		ct = openEdges.Count();
		while (!done)
		{
			for (int i = 0; i < openEdges.Count(); i++)
			{
				int edgeIndex = openEdges[i];

				if (edgeIndex != seedEdgeA)
				{
					int a = ld->GetGeomEdgeVert(edgeIndex,0);//TVMaps.gePtrList[edgeIndex]->a;
					int b = ld->GetGeomEdgeVert(edgeIndex,1);//TVMaps.gePtrList[edgeIndex]->b;
					if (a == seedVert)
					{
						seedVert = b;
						seedEdgeA = edgeIndex;
						results.Append(1,&seedEdgeA,5000);
						openEdges.Delete(seedEdgeA,1);
						i = openEdges.Count();
					}
					else if  (b == seedVert)
					{
						seedVert = a;
						seedEdgeA = edgeIndex;
						results.Append(1,&seedEdgeA,5000);
						openEdges.Delete(seedEdgeA,1);
						i = openEdges.Count();
					}
				}
			}					
			if (ct == openEdges.Count())
				done = TRUE;
			ct = openEdges.Count();
		}
	}

}
void Unreal3DExport::GetTris()
{
    
    // Export triangle data
    FJSMeshTri nulltri = FJSMeshTri();
    for( int n=0; n<Nodes.Count(); ++n )
    {
        CheckCancel();
        
        IGameNode* node = Nodes[n];
        IGameMesh* mesh = static_cast<IGameMesh*>(node->GetIGameObject());
        if( mesh->InitializeData() )
        {
            int vertcount = mesh->GetNumberOfVerts();
            int tricount = mesh->GetNumberOfFaces();
            if( vertcount > 0 && tricount > 0 )
            {
                // Progress
                ProgressMsg.printf(GetString(IDS_INFO_MESH),n+1,Nodes.Count(),TSTR(node->GetName()));
                pInt->ProgressUpdate(Progress+(static_cast<float>(n)/Nodes.Count()*U3D_PROGRESS_MESH), FALSE, ProgressMsg.data());

                // Alloc triangles space
                Tris.Resize(Tris.Count()+tricount);

                // Append triangles
                for( int i=0; i!=tricount; ++i )
                {
                    FaceEx* f = mesh->GetFace(i);
                    if( f )
                    {
                        FJSMeshTri tri(nulltri);

                        // TODO: add material id listing
                        RegisterMaterial( node, mesh, f, &tri );

                        tri.iVertex[0] = VertsPerFrame + f->vert[0];
                        tri.iVertex[1] = VertsPerFrame + f->vert[1];
                        tri.iVertex[2] = VertsPerFrame + f->vert[2];

                        Point2 p;
                        if( mesh->GetTexVertex(f->texCoord[0],p) ){
                            tri.Tex[0] = FMeshUV(p);
                        }
                        if( mesh->GetTexVertex(f->texCoord[1],p) ){
                            tri.Tex[1] = FMeshUV(p);
                        }
                        if( mesh->GetTexVertex(f->texCoord[2],p) ){
                            tri.Tex[2] = FMeshUV(p);
                        }
                        
                        Tris.Append(1,&tri);                       
                    }
                }

                VertsPerFrame += vertcount;
            }
            else
            {
                // remove invalid node
                Nodes.Delete(n--,1);
            }
        }
        node->ReleaseIGameObject();
    }
    Progress += U3D_PROGRESS_MESH;
}
BOOL MeshTopoData::NormalMap(Tab<Point3*> *normalList, Tab<ClusterClass*> &clusterList, UnwrapMod *mod )
{

	if (TVMaps.f.Count() == 0) return FALSE;


	BitArray polySel = mFSel;



	BitArray holdPolySel = mFSel;



	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];
		ClusterClass *cluster = new ClusterClass();
		cluster->normal = mapNormal[i];
		cluster->ld = this;
		clusterList.Append(1,&cluster);
	}


	//check for type

	BOOL bContinue = TRUE;
	TSTR statusMessage;


	Tab<Point3> objNormList;         
	mod->BuildNormals(this,objNormList);

	if (objNormList.Count() == 0)
	{
		return FALSE;
	}

	BitArray skipFace;
	skipFace.SetSize(mFSel.GetSize());
	skipFace.ClearAll();
	int numberSet = mFSel.NumberSet();
	for (int i = 0; i < mFSel.GetSize(); i++)
	{
		if (!mFSel[i])
			skipFace.Set(i);
	}





	for (int i =0; i < objNormList.Count(); i++)
	{
		int index = -1;
		float angle = 0.0f;
		if (skipFace[i] == FALSE)
		{
			for (int j =0; j < clusterList.Count(); j++)
			{
				if (clusterList[j]->ld == this)
				{
					Point3 debugNorm = objNormList[i];
					float dot = DotProd(debugNorm,clusterList[j]->normal);//mapNormal[j]);
					float newAngle = (acos(dot));

					if ((dot >= 1.0f) || (newAngle <= angle) || (index == -1))
					{
						index = j;
						angle = newAngle;
					}
				}
			}
			if (index != -1)
			{
				clusterList[index]->faces.Append(1,&i);
			}
		}
	}


	

	BitArray sel;
	sel.SetSize(TVMaps.f.Count());
	
	for (int i =0; i < clusterList.Count(); i++)
	{
		if (clusterList[i]->ld == this)
		{
			sel.ClearAll();
			for (int j = 0; j < clusterList[i]->faces.Count();j++)
				sel.Set(clusterList[i]->faces[j]);
			if (sel.NumberSet() > 0)
			{
	//			fnSelectPolygonsUpdate(&sel, FALSE);
				mFSel = sel;
				PlanarMapNoScale(clusterList[i]->normal,mod);

			}

			int per = (i * 100)/clusterList.Count();
			statusMessage.printf(_T("%s %d%%."),GetString(IDS_PW_STATUS_MAPPING),per);
			if (mod->Bail(GetCOREInterface(),statusMessage))
			{
				i = clusterList.Count();
				bContinue =  FALSE;
			}
		}
	}

	


	for (int i =0; i < clusterList.Count(); i++)
	{
		if (clusterList[i]->faces.Count() == 0)
		{
			delete clusterList[i];
			clusterList.Delete(i,1);
			i--;
		}

	}

	BitArray clusterVerts;
	clusterVerts.SetSize(TVMaps.v.Count());
	
	for (int i =0; i < clusterList.Count(); i++)
	{
		
		if (clusterList[i]->ld == this)
		{
			clusterVerts.ClearAll();
			for (int j = 0; j < clusterList[i]->faces.Count(); j++)
			{
				int findex = clusterList[i]->faces[j];
				AddVertsToCluster(findex,clusterVerts, clusterList[i]);
			}
		}
	}
	mFSel = holdPolySel ;

	return bContinue;
}