void CMeshSmoothGroups::GenerateSmoothingFromNames(CMeshEditor* pcMeshEditor)
{
	int				i;
	int				iNumPolygons;
	CMeshPolygon*	pcPolygon;
	int				iNumFaces;
	int				j;
	int				iFace;
	CArrayInt		aiUniqueNames;
	unsigned int	uiFaceName;
	unsigned int	uiSmoothingGroup;

	iNumPolygons = pcMeshEditor->mcPolygons.mcPolygons.NumElements();

	aiUniqueNames.Init();
	pcMeshEditor->mcPolygons.GetUniqueNames(&aiUniqueNames);

	if (aiUniqueNames.NumElements() >= 32)
	{
		//Too many face names to deal with.
		mcSmoothingGroups.SetArrayValues(1);
	}
	else
	{
		for (i = 0; i < iNumPolygons; i++)
		{
			pcPolygon = pcMeshEditor->mcPolygons.Get(i);
			iNumFaces = pcPolygon->maiFaces.NumElements();
			uiFaceName = pcPolygon->miName;
			if (uiFaceName != 0)
			{
				uiSmoothingGroup = 1 << (uiFaceName-1);
			}
			else
			{
				uiSmoothingGroup = 0;
			}

			for (j = 0; j < iNumFaces; j++)
			{
				iFace = pcPolygon->maiFaces.GetValue(j);
				mcSmoothingGroups.SetValue(iFace, uiSmoothingGroup);
			}
		}
	}

	aiUniqueNames.Kill();
}
예제 #2
0
void TestArrayIntRemoveDuplicates(void)
{
	CArrayInt	cArray;

	cArray.Init(1);
	cArray.AddList(-1, 1, 1, 2, 3, 3, 3, 4, 5, 5, -1);
	cArray.RemoveDuplicatesFromSorted();
	AssertInt(5, cArray.NumElements());
	AssertInt(1, cArray[0]);
	AssertInt(2, cArray[1]);
	AssertInt(3, cArray[2]);
	AssertInt(4, cArray[3]);
	AssertInt(5, cArray[4]);

	cArray.Kill();
}
void CMeshSmoothGroups::GenerateSmoothingFromAngles(CMeshEditor* pcMeshEditor)
{
	int				i;
	int				iNumPolygons;
	CMeshPolygon*	pcPolygon;
	CArrayFloat3	asNormals;
	CArrayInt		aiAdjPolys;
	SFloat3*		psThisNormal;
	SFloat3*		psOtherNormal;
	int				j;
	int				iOtherGon;
	float			fDot;
	float			fResult;

	fDot = Deg2Dot(mfSharpAngle);

	asNormals.Init();
	pcMeshEditor->mcPolygons.GetNormals(&asNormals, &pcMeshEditor->mpcMesh->mcNormals);

	mcSmoothingGroups.SetArrayValues(0);

	iNumPolygons = pcMeshEditor->mcPolygons.mcPolygons.NumElements();
	for (i = 0; i < iNumPolygons; i++)
	{
		psThisNormal = asNormals.Get(i);
		pcPolygon = pcMeshEditor->mcPolygons.Get(i);
		aiAdjPolys.Init();
		pcMeshEditor->mcPolygons.GetAdjacentPolygons(pcMeshEditor->mpcMesh->GetConnectivity(), i, &aiAdjPolys);

		for (j = 0; j < aiAdjPolys.NumElements(); j++)
		{
			iOtherGon = aiAdjPolys.GetValue(j);
			psOtherNormal = asNormals.Get(iOtherGon);

			fResult = Float3Dot(psThisNormal, psOtherNormal);
			if (fResult >= fDot)
			{
				//Smooth!
			}
		}

		aiAdjPolys.Kill();
	}

	asNormals.Kill();
}
예제 #4
0
void CConvexHull::GetVertices(CArrayBlock* pasPositions, SFloat3* psPoints, int iStride)
{
	CArrayInt	aiIndices;
	int			i;
	int			iIndex;
	SFloat3*	psPosition;

	aiIndices.Init(mcPolygons.NumElements()+1);
	GetIndices(&aiIndices, psPoints, iStride);

	for (i = 0; i < aiIndices.NumElements(); i++)
	{
		iIndex = aiIndices.GetValue(i);
		psPosition = GetPosition(psPoints, iStride, iIndex);
		pasPositions->Add(psPosition);
	}

	aiIndices.Kill();
}
예제 #5
0
void TestArrayIntRemoveAt(void)
{
	CArrayInt	cArray;
	CArrayInt	cKiller;

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 8, 5, 0, 5, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(7, cArray.NumElements());

	AssertInt(3, cArray[0]);
	AssertInt(7, cArray[1]);
	AssertInt(8, cArray[2]);
	AssertInt(1, cArray[3]);
	AssertInt(0, cArray[4]);
	AssertInt(2, cArray[5]);
	AssertInt(2, cArray[6]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 8, 5, 2, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(7, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(8, cArray[2]);
	AssertInt(1, cArray[3]);
	AssertInt(0, cArray[4]);
	AssertInt(2, cArray[5]);
	AssertInt(2, cArray[6]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 1, 2, 7, 8, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(4, cArray.NumElements());

	AssertInt(8, cArray[0]);
	AssertInt(1, cArray[1]);
	AssertInt(9, cArray[2]);
	AssertInt(0, cArray[3]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	AssertInt(10, cArray.NumElements());

	cKiller.Init(1);
	cKiller.AddList(-1, 3, 4, 5, 6, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(6, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(7, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(4, cArray[4]);
	AssertInt(2, cArray[5]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(0, cArray.NumElements());

	cKiller.Kill();
	cArray.Kill();


	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(10, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(3, cArray[1]);
	AssertInt(7, cArray[2]);
	AssertInt(8, cArray[3]);
	AssertInt(1, cArray[4]);
	AssertInt(9, cArray[5]);
	AssertInt(0, cArray[6]);
	AssertInt(2, cArray[7]);
	AssertInt(4, cArray[8]);
	AssertInt(2, cArray[9]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 0, 2, 4, 6, 8, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(5, cArray.NumElements());

	AssertInt(3, cArray[0]);
	AssertInt(8, cArray[1]);
	AssertInt(9, cArray[2]);
	AssertInt(2, cArray[3]);
	AssertInt(2, cArray[4]);

	cKiller.Kill();
	cArray.Kill();

	////////////////////////////////////////////////
	cArray.Init(1);

	//                 0  1  2  3  4  5  6  7  8  9  Stop
	cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1);

	cKiller.Init(1);
	cKiller.AddList(-1, 1, 3, 5, 7, 9, -1);
	cKiller.MakeUnique();

	cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements());

	AssertInt(5, cArray.NumElements());

	AssertInt(4, cArray[0]);
	AssertInt(7, cArray[1]);
	AssertInt(1, cArray[2]);
	AssertInt(0, cArray[3]);
	AssertInt(4, cArray[4]);

	cKiller.Kill();
	cArray.Kill();
}