示例#1
0
/*---------------------------------------------------------------------------*/
NiTriShapeRef NifConvertUtility::convertNiTriStrips(NiTriStripsRef pSrcNode, NiTriShapeRef pTmplNode, NiAlphaPropertyRef pTmplAlphaProp)
{
	NiTriShapeRef			pDstNode   (new NiTriShape());
	NiTriShapeDataRef		pDstGeo    (new NiTriShapeData());
	NiTriStripsDataRef		pSrcGeo    (DynamicCast<NiTriStripsData>(pSrcNode->GetData()));
	vector<NiPropertyRef>	srcPropList(pSrcNode->GetProperties());

	//  copy NiTriStrips to NiTriShape
	pDstNode->SetCollisionObject(NULL);  //  no collision object here
	pDstNode->SetFlags          (14);    //  ???
	pDstNode->SetName           (pSrcNode->GetName());
	pDstNode->SetLocalTransform (pSrcNode->GetLocalTransform());
	pDstNode->SetData           (pDstGeo);

	//  move properties
	for (auto pIter=srcPropList.begin(), pEnd=srcPropList.end(); pIter != pEnd; ++pIter)
	{
		if (DynamicCast<NiVertexColorProperty>(*pIter) != NULL)
		{
			int	iii=0;
		}
		pDstNode->AddProperty(*pIter);
	}
	pSrcNode->ClearProperties();

	//  data node
	if (pSrcGeo != NULL)
	{
		pDstGeo->SetVertices    (pSrcGeo->GetVertices());
		pDstGeo->SetNormals     (pSrcGeo->GetNormals());
		pDstGeo->SetTriangles   (pSrcGeo->GetTriangles());
		pDstGeo->SetVertexColors(pSrcGeo->GetColors());
		pDstGeo->SetUVSetCount  (pSrcGeo->GetUVSetCount());
		for (short idx(0), max(pSrcGeo->GetUVSetCount()); idx < max; ++idx)
		{
			pDstGeo->SetUVSet(idx, pSrcGeo->GetUVSet(idx));
		}
	}  //  if (pSrcGeo != NULL)

	//  return converted NiTriShape
	return convertNiTri(pDstNode, pTmplNode, pTmplAlphaProp);
}
示例#2
0
文件: main.cpp 项目: Yacoby/CellToNif
void addToNif(Land l, long offx, long offy, CellMeshList& cml){
	using namespace Niflib;

	std::vector<Vector3> verts;
	std::vector<Vector3> normals;
	std::vector<TexCoord> txCoords;
	std::vector<Triangle> tris;


	for ( int x = 0; x < 65; x++){
		for ( int y = 0; y < 65; y++){
			verts.push_back(
				Vector3(x*128,y*128,l.land[x][y]*8)
			);

			//vector needs to be normalized
			float nx = l.normals[x][y].x;
			float ny = l.normals[x][y].y;
			float nz = l.normals[x][y].z;
			float mag = sqrt(nx*nx+ny*ny+nz*nz);
			nx/=mag;
			ny/=mag;
			nz/=mag;

			normals.push_back(
				Vector3(nx,ny,nz)
			);

			txCoords.push_back(
				TexCoord(x/(float)65, y/(float)65)
			);
		}
	}

	//ak. Hacky
	const unsigned vertNum = 65 * 65;
	const unsigned meshLength = sqrt((float) vertNum);

	const unsigned loopSize = (vertNum) - (meshLength * 2) + 65;
	for( unsigned i = 0; i < loopSize; i++){
		unsigned iTmp = i;
		while ( iTmp > (meshLength - 1) )
			iTmp -= meshLength;

		if ( iTmp == (meshLength - 1) )
			continue;

		Triangle tri;

		tri.v1 = i;
		tri.v2 = i + meshLength;
		tri.v3 = i + 1;
		tris.push_back(tri);


		tri.v1 = i + meshLength;
		tri.v2 = i + meshLength + 1;
		tri.v3 = i + 1;
		tris.push_back(tri);
	}

	NiTriShapeRef shape = new NiTriShape;
	shape->SetName("TxtMesh");
	shape->AddProperty(getMatProp());
	shape->AddProperty(getTexture());


	NiTriShapeDataRef triData = new NiTriShapeData;
	triData->SetVertices(verts);
	triData->SetNormals(normals);
	triData->SetTriangles(tris);

	//uv
	triData->SetUVSetCount(1);
	triData->SetUVSet(0, txCoords);

	//ad it to the TriShape
	NiGeometryDataRef gRef = DynamicCast<NiGeometryData>( triData );
	shape->SetData(gRef);


	NiAVObjectRef avObj = DynamicCast<NiAVObject>(  shape );

	//make it so the center of the cell is on 0, 0
	Vector3 vec3;
	vec3.x = offx;
	vec3.y = offy;
	avObj->SetLocalTranslation(vec3);

	cml.push_back(avObj);
}