Sign in to follow this  
b3rs3rk

MaxScript Exporter and Unwrap UVW

Recommended Posts

i'm trying to write an exporter for my engine and spent last two days learning MaxScript. Finally I managed to make it work... this is the model in Max: and this is a result in my engine: As you can se, it works good and i'm very satisfied, so i tryied to step up. Within Max (i'm using Max 8) i did a render to texture step and created an ambient occlusion map. Then applyed the Unwrap UVW modifier on the mesh (uv channel 1) and tryed to export. This is a screenshot of the model as it should be: and this is in my engine: It's totally messed up! These are the relevant parts of the script:

struct tVertex
(
	pos,
	uv1,
	uv2
)

struct tFace
(
	v1,
	v2,
	v3,	
	matId
)

struct tMesh
(
	Verts = #(),
	Faces = #(),

fn AddTriangle obj triindx self =(
   vertindices = getFace obj triindx
   UV1_indices = meshop.getmapface obj 1 triindx
   vertindices = #(vertindices.x as integer, vertindices.y as integer, vertindices.z as integer)
   UV1_indices = #(UV1_indices.x as integer, UV1_indices.y as integer, UV1_indices.z as integer)	

   matId = getfacematid obj triindx
		
   VList = #()
		
   for i=1 to 3 do
   (
	pos = obj.verts[vertindices[i]].pos
        uv1 = meshop.getmapvert obj 1 UV1_indices[i]
	newVert = tVertex pos #(uv1.x, uv1.y) 
        append self.Verts newVert
	VList[i] = self.Verts.count
   )
   append self.Faces (tFace VList[1] VList[2] VList[3] matId )	
),

fn WriteToFile self oFile = 	(
   format "Faces: % - Vertices: %\n" self.Faces.count self.Verts.count to:oFile
   for v = 1 to self.Verts.count do
   (
      format "[%, %, %] - " self.Verts[v].pos.x self.Verts[v].pos.y self.Verts[v].pos.z to:oFile
     format "[%, %]\n" self.Verts[v].uv1[1] self.Verts[v].uv1[2] to:oFile
   )
		
  for f = 1 to self.Faces.count do
  (
      self.Faces[f].v1 = self.Faces[f].v1 - 1
      self.Faces[f].v2 = self.Faces[f].v2 - 1
      self.Faces[f].v3 = self.Faces[f].v3 - 1
      self.Faces[f].matId = self.Faces[f].matId - 1
      format "[%, %, %] - [%]\n" self.Faces[f].v1 self.Faces[f].v2 self.Faces[f].v3 self.Faces[f].matId to:oFile
   )
)

) -- end of tMesh struct



MeshList = #()

for o=0 to --every object in the scene
   obj = -- i-th object
   MeshList[o] = tMesh()

   for f = 1 to obj.numfaces do 
   (
	MeshList[o].AddTriangle obj f MeshList[o]
   )
   MeshList[o].WriteToFile MeshList[o] out_file

Any clues?

Share this post


Link to post
Share on other sites
It looks like the ambient occlusion map uses other UV coordinates than the one used for standard textures (which you exported). I guess you can either tell max to use standard UVs or export 2 UV sets.

[Edited by - therealremi on March 11, 2007 8:06:36 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this