Menu
Home
DS
PC
Tutorials
Links
Contact


Affiliates
MaxScript 2 - Exporting Multiple Meshes With Texture Coordinates

 

Bored of vertex colors and want to display the real textures?

Part A is for exporting multiple meshes that use the same texture map.
Part B will take you through how to export a function for each selected object.

Note: Debug Color was commented out because it's a diffuse, but you can always uncomment it if you'd like

Lesson 2 Part A:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- 3D MODEL EXPORTER - DS
-- select object in viewport and press ctrl+e

 
-- exports to $3dsmax_root/mesh/dsmodel.cpp
-- and every time, the file IS ERASED! 
 
out_name = ((GetDir #export)+"/dsmodel.cpp")
out_file = createfile out_name
 
format "\n#include <nds.h>\n\nvoid Draw_model( void ) {\nglBegin(GL_TRIANGLES);\n" to:out_file
 
TEX_WIDTH = 128-1
TEX_HEIGHT= 128-1

 
temp=0
 
divided = 1
fp = 4096
 
for m = 1 to selection.count do
(
 
	tmesh = snapshotAsMesh selection[m]
 
 
	-- divided is only if you're too lazy to scale it yourself
	-- remember: -8 to 7.998f axis limits
 
	numFaces = tMesh.numFaces
 

	for f = 1 to numFaces do
	(
		face = getFace tmesh f
 
		channel = 1
		theTFace = meshop.getMapFace tmesh channel f
 
		-- grab each ST vector (access as array)
		-- arrays in maxscript start at [1]
		tvx = meshop.getMapVert tmesh channel (theTFace.x as integer)
		tvy = meshop.getMapVert tmesh channel (theTFace.y as integer)
		tvz = meshop.getMapVert tmesh channel (theTFace.z as integer)
 
		-- debug coloring
/*		if temp == 0 then
		(
			format "glColor3f(1.0f,0,0);\n" to:out_file
			temp += 1
		)else if temp == 1 then(
			format "glColor3f(0,1.0f,0);\n" to:out_file
			temp += 1
		)else(
			format "glColor3f(0,0,1.0f);\n" to:out_file
			temp = 0
		)
*/
		--tris 
		vert = getVert tmesh face.x --vert 1 of 3
 
		format "\tglTexCoord2t16(%,%);\n" ((tvx[1]*TEX_WIDTH*16) as integer) \
											((tvx[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file
 
 
		vert = getVert tmesh face.y --vert 2 of 3 

 
		format "\tglTexCoord2t16(%,%);\n"  ((tvy[1]*TEX_WIDTH*16) as integer) \
											((tvy[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file		
 
		vert = getVert tmesh face.z --vert 3 of 3
 
		format "\tglTexCoord2t16(%,%);\n" ((tvz[1]*TEX_WIDTH*16) as integer) \
											((tvz[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file	
	) -- end f
 
)  --end m
 
-- finish the function 
format "glEnd();\n}\n" to:out_file
 
-- don't forget to close
close out_file

Analyze:

Be sure to change TEX_WIDTH and TEX_HEIGHT to that values of your texture's dimensions -1.

To convert from floating point textures to fixed point, you do (short int) (n * 127 * (1<<4))

The comments explain most of what's going on

Part B:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- 3D MODEL EXPORTER - DS
-- select object in viewport and press ctrl+e

 
-- exports to $3dsmax_root/mesh/dsmodel.cpp
-- and every time, the file IS ERASED! 
 
out_name = ((GetDir #export)+"/dsmodel.cpp")
out_file = createfile out_name
  
TEX_WIDTH = 128-1
TEX_HEIGHT= 128-1

 
temp=0
 
divided = 1
fp = 4096

format "\n#include <nds.h>" to:out_file
 
for m = 1 to selection.count do
(
 
	tmesh = snapshotAsMesh selection[m]
	format "\nvoid Draw_% void ) {\nglBegin(GL_TRIANGLES);\n" (selection[m].name) to:out_file
 
 
	-- divided is only if you're too lazy to scale it yourself
	-- remember: -8 to 7.998f axis limits
 
	numFaces = tMesh.numFaces
 

	for f = 1 to numFaces do
	(
		face = getFace tmesh f
 
		channel = 1
		theTFace = meshop.getMapFace tmesh channel f
 
		-- grab each ST vector (access as array)
		-- arrays in maxscript start at [1]
		tvx = meshop.getMapVert tmesh channel (theTFace.x as integer)
		tvy = meshop.getMapVert tmesh channel (theTFace.y as integer)
		tvz = meshop.getMapVert tmesh channel (theTFace.z as integer)
 
		-- debug coloring
/*		if temp == 0 then
		(
			format "glColor3f(1.0f,0,0);\n" to:out_file
			temp += 1
		)else if temp == 1 then(
			format "glColor3f(0,1.0f,0);\n" to:out_file
			temp += 1
		)else(
			format "glColor3f(0,0,1.0f);\n" to:out_file
			temp = 0
		)
*/
		--tris 
		vert = getVert tmesh face.x --vert 1 of 3
 
		format "\tglTexCoord2t16(%,%);\n" ((tvx[1]*TEX_WIDTH*16) as integer) \
											((tvx[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file
 
 
		vert = getVert tmesh face.y --vert 2 of 3 

 
		format "\tglTexCoord2t16(%,%);\n"  ((tvy[1]*TEX_WIDTH*16) as integer) \
											((tvy[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file		
 
		vert = getVert tmesh face.z --vert 3 of 3
 
		format "\tglTexCoord2t16(%,%);\n" ((tvz[1]*TEX_WIDTH*16) as integer) \
											((tvz[2]*TEX_HEIGHT*16) as integer) to:out_file
		format "\tglVertex3v16(%,%,%);\n" 	((vert.x/divided*fp) as integer) \
											((vert.z/divided*fp) as integer) \
											(-(vert.y/divided*fp) as integer) to:out_file	
	) -- end f

	-- finish the function 
	format "glEnd();\n}\n" to:out_file
 
)  --end m
  
-- don't forget to close
close out_file

Each function is exported as Draw_model_name().

Be sure to check out the other tutorials!