Vai al contenuto
carmentano

Texture Coordinate In Maxsxript!

Recommended Posts

Non riesco a capire come esportare correttamente le Texture Coord da una mesh di 3d studio max in DirectX! Ho scritto il seguente codice:

uv_verts = tmesh.numverts

	format "%\n" ("MeshTextureCoords {") to:out_file

	format "%\n" (uv_verts as string + ";") to:out_file


	tt = #()


	for v3 = 1 to num_faces do

	(

		fv = getface tmesh v3

		ft = gettvface tmesh v3


		t_index1 = fv.x as integer

		t_index2 = fv.y as integer

		t_index3 = fv.z as integer


		tt[t_index1] = ft.x as integer

		tt[t_index2] = ft.y as integer

		tt[t_index3] = ft.z as integer

	)


	for v3 = 1 to tt.count do

	(

		vert = getTVert tmesh tt[v3]

		if v3 != tt.count then format "%\n" (vert.x as string +";"+ vert.y as string +";") to:out_file

		if v3 == tt.count then format "%\n" (vert.x as string +";"+ vert.y as string +";;") to:out_file

	)

	format "%\n" ("}") to:out_file

	format "%\n" ("}") to:out_file

	)

)


format "%\n" ("}") to:out_file
il problema è che in studio max una mesh può avere un numero diverso di "vertici texture" da quello dei "vertci 3d" mentre DirectX non accetta questa situazione di diversità. Come si può fare quindi? Bisognerebbe aumentare il numero dei vertici 3d della mesh?? Inoltre invio il codice dell'intero exporter, non si sa mai magari può sempre servire ;) ciao e grazie
out_name = ("c:/prova.x")

out_file = createfile out_name


format "%\n" "xof 0303txt 0032" to:out_file

format "%\n" "template XSkinMeshHeader {" to:out_file

format "%\n" "<3cf169ce-ff7c-44ab-93c0-f78f62d172e2>" to:out_file

format "%\n" "WORD nMaxSkinWeightsPerVertex;" to:out_file

format "%\n" "WORD nMaxSkinWeightsPerFace;" to:out_file

format "%\n" "WORD nBones;" to:out_file

format "%\n" "}" to:out_file

format "%\n" "template VertexDuplicationIndices {" to:out_file

format "%\n" "<b8d65549-d7c9-4995-89cf-53a9a8b031e3>" to:out_file

format "%\n" "DWORD nIndices;" to:out_file

format "%\n" "DWORD nOriginalVertices;" to:out_file

format "%\n" "array DWORD indices[nIndices];" to:out_file

format "%\n" "}" to:out_file

format "%\n" "template SkinWeights {" to:out_file

format "%\n" "<6f0d123b-bad2-4167-a0d0-80224f25fabb>" to:out_file

format "%\n" "STRING transformNodeName;" to:out_file

format "%\n" "DWORD nWeights;" to:out_file

format "%\n" "array DWORD vertexIndices[nWeights];" to:out_file

format "%\n" "array FLOAT weights[nWeights];" to:out_file

format "%\n" "Matrix4x4 matrixOffset;" to:out_file

format "%\n" "}" to:out_file

format "%\n" "Material DefaultMaterial {" to:out_file

format "%\n" "0.500000;0.500000;0.500000;1.000000;;	// R = 0.5, G = 0.5, B = 0.5" to:out_file

format "%\n" "0.500000;" to:out_file

format "%\n" "0.500000;0.500000;0.500000;;" to:out_file

format "%\n" "0.500000;0.500000;0.500000;;" to:out_file


format "%\n" "TextureFilename {" to:out_file

format "%\n" "\"mars.jpg\";" to:out_file

format "%\n" "}" to:out_file



format "%\n" "}" to:out_file

format "%\n" "Frame RootFrame {" to:out_file

format "%\n" "FrameTransformMatrix {" to:out_file

format "%\n" "1.000000, 0.000000, 0.000000, 0.000000," to:out_file

format "%\n" "0.000000, 1.000000, 0.000000, 0.000000," to:out_file

format "%\n" "0.000000, 0.000000, 1.000000, 0.000000," to:out_file

format "%\n" "0.000000, 0.000000, 0.000000, 1.000000;;" to:out_file

format "%\n" "}" to:out_file


coordsys world


for s = 1 to selection.count do

(

	tmesh = convertToMesh selection[s]


	if classOf tmesh == Editable_mesh then

	(

	num_verts = tmesh.numverts 

	num_faces = tmesh.numfaces

	tmatrix = tmesh.transform

	isRight = ((dot (cross tmatrix[1] tmatrix[2]) tmatrix[3]) > 0)


	t_string = "Mesh " + selection[s].name + " {"


	format "%\n" t_string to:out_file

	format "%\n" (num_verts as string + ";") to:out_file


	for v = 1 to num_verts do

	(

		vert = getVert tmesh v


		if v != num_verts then format "%\n" (((vert.x)) as string +";"+ vert.y as string +";"+ (-(vert.z)) as string + ";,") to:out_file

		if v == num_verts then format "%\n" (((vert.x)) as string +";"+ vert.y as string +";"+ (-(vert.z)) as string + ";;") to:out_file

	)


	format "%\n" (num_faces as string + ";") to:out_file


	for f = 1 to num_faces do

	(

		face = getFace tmesh f


		if isRight == true then

		(

		if f != num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.z as integer-1) as string +","+ (face.y as integer-1)as string + ";,") to:out_file

		if f == num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.z as integer-1) as string +","+ (face.y as integer-1)as string + ";;") to:out_file

		)


		if isRight == false then

		(

		if f != num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.y as integer-1) as string +","+ (face.z as integer-1)as string + ";,") to:out_file

		if f == num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.y as integer-1) as string +","+ (face.z as integer-1)as string + ";;") to:out_file

		)


	)


	format "%\n" ("MeshMaterialList {") to:out_file

	format "%\n" ("1;") to:out_file

	format "%\n" (num_faces as string + ";") to:out_file


	for f = 1 to num_faces do

	(

		face = getFace tmesh f

		if f != num_faces then format "%\n" ("0,") to:out_file

		if f == num_faces then format "%\n" ("0;;") to:out_file

	)

	format "%\n" ("{DefaultMaterial}") to:out_file

	format "%\n" ("}") to:out_file


	format "%\n" ("MeshNormals {") to:out_file

	format "%\n" (num_verts as string + ";") to:out_file


	for v2 = 1 to num_verts do

	(

		vert = getNormal tmesh v2


		if v2 != num_verts then format "%\n" (((vert.x)) as string +";"+ vert.y as string +";"+ (-(vert.z)) as string + ";,") to:out_file

		if v2 == num_verts then format "%\n" (((vert.x)) as string +";"+ vert.y as string +";"+ (-(vert.z)) as string + ";;") to:out_file

	)


	format "%\n" (num_faces as string + ";") to:out_file


	for f2 = 1 to num_faces do

	(

		face = getFace tmesh f2


		if isRight == true then

		(

		if f2 != num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.z as integer-1) as string +","+ (face.y as integer-1)as string + ";,") to:out_file

		if f2 == num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.z as integer-1) as string +","+ (face.y as integer-1)as string + ";;") to:out_file

		)


		if isRight == false then

		(

		if f2 != num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.y as integer-1) as string +","+ (face.z as integer-1)as string + ";,") to:out_file

		if f2 == num_faces then format "%\n" ("3;"+(face.x as integer-1) as string +","+ (face.y as integer-1) as string +","+ (face.z as integer-1)as string + ";;") to:out_file

		)


	)

	format "%\n" ("}") to:out_file


	uv_verts = tmesh.numverts

	format "%\n" ("MeshTextureCoords {") to:out_file

	format "%\n" (uv_verts as string + ";") to:out_file


	tt = #()


	for v3 = 1 to num_faces do

	(

		fv = getface tmesh v3

		ft = gettvface tmesh v3


		t_index1 = fv.x as integer

		t_index2 = fv.y as integer

		t_index3 = fv.z as integer


		tt[t_index1] = ft.x as integer

		tt[t_index2] = ft.y as integer

		tt[t_index3] = ft.z as integer

	)


	for v3 = 1 to tt.count do

	(

		vert = getTVert tmesh tt[v3]

		if v3 != tt.count then format "%\n" (vert.x as string +";"+ vert.y as string +";") to:out_file

		if v3 == tt.count then format "%\n" (vert.x as string +";"+ vert.y as string +";;") to:out_file

	)

	format "%\n" ("}") to:out_file

	format "%\n" ("}") to:out_file

	)

)


format "%\n" ("}") to:out_file


close out_file

Ciao confido in VOI!!

Condividi questo messaggio


Link al messaggio
Condividi su altri siti

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora

  • Navigazione recente   0 utenti

    Non ci sono utenti registrati da visualizzare in questa pagina.

×