|
You've got your modeller and it's time to put the mesh in your game, but how do you get the information? This breif tutorial will walk you through some basics in MaxScript and will allow you to export one selected mesh to a function in a .cpp file.
Lesson 1 Code:
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 |
out_name = ((GetDir #export)+"/dsmodel.cpp")
out_file = createfile out_name
temp=0
tmesh = snapshotAsMesh selection[1]
format "\n#include <nds.h>\n\nvoid Draw_model( void ) {\nglBegin(GL_TRIANGLES);\n" to:out_file
divided = 1
fp = 4096
numFaces = tMesh.numFaces
for f = 1 to numFaces do
(
face = getFace tmesh f
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
)
vert = getVert tmesh face.x 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 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 format "\tglVertex3v16(%,%,%);\n" ((vert.x/divided*fp) as integer) \
((vert.z/divided*fp) as integer) \
(-(vert.y/divided*fp) as integer) to:out_file
)
format "glEnd();\n}\n" to:out_file
close out_file |
Notes:
-- are comments
/* */ are also acceptable
variables don't require declaration (like visual basic)
\ will extend for the next line, just as C compilers allow
Analyze:
Line 8: out_name = ((GetDir #export)+"/dsmodel.cpp")
Creates the string for $3dsmax_root/meshes/dsmodel.cpp
Line 14: tmesh = snapshotAsMesh selection[1]
tmesh becomes a node with the information for the currently selected model
Line 16: format "\n#include <nds.h>\n\nvoid Draw_model( void ) {\nglBegin(GL_TRIANGLES);\n" to:out_file
Formats the string to out_file. This is the start of the file, beginning with a global nds.h include and declaring the function Draw_model().
Lines 31-41: debug color exporting
this is used to you can distinguish your model. Without this, you would have a one colored filled model rendering, and you most likely wouldn't be able to see parts you would like. This is easily able to be taken out with the /* */ comment block.
Line 46: format "\tglVertex3v16(%,%,%);\n" ....
This particluar format includes the tab \t and variable output %. after the string, you should always keep the variables in parenthesis, especially if you're doing math operations.
The operation on this line converts from Max's coordinate system to OpenGL (X,Y,Z -> X,Z,-Y) and converts the coordinates to DS' 3D fixed point format. (int)(float * (1<<12))
After gazing at your model on the ds, move on to the next lesson to find out how to export the texture coordinates (ST-coords) |