MaxScript Error here:
-***************************************************************************
--* JMS Exporter by TheGhost *
--* for 3ds Max v5+ and gmax v1.2 *
--***************************************************************************
--* Features: *
--* - Exports all types of model geometry *
--* - Exports perfect texture coordinates *
--* - Exports proper, well-calculated vertex normals *
--* - Exports all nodes and markers (for weapons, vehicles, etc.) *
--* - Exports biped systems or bones for character models *
--* - Exports vertex weights for fully rigged model! *
--* - Exports from gmax / 3ds max version independent *
--*-------------------------------------------------------------------------*
--* Instructions: Check the checkbox captioned "Export vertex weights" if *
--* you are exporting a rigged model. Select the method to export the JMS *
--* data, either writing to a JMS file or streaming through the listener *
--* (for gmax). Click the "Export JMS Data" button to begin. *
--*-------------------------------------------------------------------------*
--* Submit bugs to TheGhost on the Gearbox Software forums. Visit the *
--* forums for additional help at
http://gbxforums.gearboxsoftware.com. *
--* Visit the project site (
http://ghost.halomaps.org/BlueStreak/) for more *
--* details on this and other projects. *
--*-------------------------------------------------------------------------*
--* Copyright (C) 2006 Adam Papamarcos (mailto:papamarcos@gmail.com) *
--* This program is free software; you can redistribute it and/or modify it *
--* under the terms of the GNU General Public License as published by the *
--* Free Software Foundation; either version 2 of the License, or (at your *
--* option) any later version. This program is distributed in the hope that *
--* it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
--* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See *
--* the GNU General Public License for more details. A full copy of this *
--* license is available at
http://www.gnu.org/licenses/gpl.txt. *
--*-------------------------------------------------------------------------*
all_objects_array = #()
all_object_names = #()
node_objects = #()
node_array = #()
node_translation = #()
node_rotation = #()
node_child_indices = #()
node_first_child_index = #()
node_next_sibling_index = #()
marker_array = #()
marker_parent_index = #()
marker_translation = #()
marker_rotation = #()
geometry_objects = #()
geom_parent_index = #()
geom_materials = #()
geom_bone_array = #()
geom_object_has_skin = #()
geom_object_has_tverts = #()
geom_mesh_faces = #()
face_verts = #()
face_matID = #()
face_SG = #()
face_tverts = #()
face_shader_index = #()
vert_pos = #()
vert_node0index = #()
vert_node1index = #()
vert_node1weight = #()
vert_normal = #()
tvert_pos = #()
exportFailed = false
sceneParent = undefined
nodeParent = undefined
numFaces = 0
boneAffectWarning = false
validJMS = false
maxver = maxVersion()
fn getFaceSmoothGroupB obj face =
(
local sgroup_val = getFaceSmoothGroup obj face
local sg_bitarray = #{}
if sgroup_val .5)
sgroup_val /= 2
)
sg_bitarray as array
)
rollout roll "JMS Model Exporter" width:209 height:254
(
GroupBox grp1 "" pos:[7,0] width:194 height:32
label lbl_title "BlueStreak: Halo Model Exporter" pos:[26,12] width:159 height:13
GroupBox grp2 "User Information" pos:[8,37] width:193 height:40
edittext edt_info "" pos:[13,53] width:176 height:18 enabled:false
GroupBox grp3 "Export options" pos:[7,82] width:194 height:40
checkbox chk_weight "Export vertex weights (rigged)" pos:[17,100] width:173 height:16 checked:true
GroupBox grp4 "Export Method" pos:[7,127] width:194 height:103
checkbox chk_jms "Save to JMS File (3ds max only)" pos:[17,146] width:174 height:16 checked:true
checkbox chk_stream "Stream with MAXScript Listener" pos:[17,165] width:174 height:16
button go_button "Export JMS Data" pos:[38,188] width:128 height:31
label lbl7 "Script by TheGhost" pos:[8,235] width:101 height:14 enabled:false
label lbl8 "v1.0.1" pos:[167,236] width:36 height:14 enabled:false
on roll open do
(
ClearListener()
if maxver[1] 0 do geom_object_has_tverts[g] = true
if chk_weight.checked == true then
(
if classOf geometry_objects[g].modifiers[1] == Skin then
(
theSkin = geometry_objects[g].modifiers[1]
numBones = skinOps.getNumberBones theSkin
if numBones > 1 then
(
geom_object_has_skin[g] = true
temp_bone_array = #()
for b = 1 to numBones do
(
select geometry_objects[g]
max modify mode
subobjectLevel = 1
boneName = skinOps.getBoneName theSkin b 0
theNode = getNodeByName boneName exact:true ignoreCase:false
nodeNum = findItem node_array theNode
if nodeNum == 0 then
(
messageBox ("Warning: bone " + boneName + " in skin modifier is not a node.") title:"BlueStreak Error"
append temp_bone_array 1
)
else
(
append temp_bone_array nodeNum
)
)
geom_bone_array[g] = temp_bone_array
)
)
)
default_node0index = (geom_parent_index[g] - 1)
face_verts = #()
face_matID = #()
face_SG = #()
face_tverts = #()
for f = 1 to geom_mesh_faces[g] do
(
face_verts[f] = getFace tmesh f
face_matID[f] = getFaceMatID tmesh f
face_SG[f] = getFaceSmoothGroupB tmesh f
if geom_object_has_tverts[g] == true do face_tverts[f] = getTVFace tmesh f
for vertices = 1 to 3 do
(
v += 1
vert_pos = getVert tmesh face_verts[f][vertices]
if geom_object_has_skin[g] == true then
(
skinNode0 = skinOps.getVertexWeightBoneID theSkin face_verts[f][vertices] 1
weightedNode0Index = geom_bone_array[g][skinNode0] - 1
vert_node0index = weightedNode0Index
boneAffectNum = skinOps.getVertexWeightCount theSkin face_verts[f][vertices]
if boneAffectNum > 2 do boneAffectWarning = true
if boneAffectNum == 1 then
(
if boneAffectNum > 2 do boneAffectWarning = true
vert_node1index = -1
vert_node1weight = 0
)
else
(
skinNode1 = skinOps.GetVertexWeightBoneID theSkin face_verts[f][vertices] 2
weightedNode1Index = geom_bone_array[g][skinNode1] - 1
weightedNode1Weight = skinOps.GetVertexWeight theSkin face_verts[f][vertices] 2
if weightedNode1Weight > 0.5 then
(
vert_node0index = weightedNode1Index
vert_node1index = weightedNode0Index
vert_node1weight = (1.0 - weightedNode1Weight)
)
else
(
vert_node0index = weightedNode0Index
vert_node1index = weightedNode1Index
vert_node1weight = weightedNode1Weight
)
)
)
else
(
vert_node0index = default_node0index
vert_node1index = -1
vert_node1weight = 0
)
vNormal = [0,0,0]
vNormal += getFaceNormal tmesh f
simFaces = meshop.getFacesUsingVert tmesh face_verts[f][vertices] as array
del_index = findItem simFaces f
deleteItem simFaces del_index
for s = 1 to simFaces.count do
(
affectNormal = false
neiSG = getFaceSmoothGroupB tmesh simFaces[s]
for aN = 1 to face_SG[f].count do
(
if affectNormal == false then
(
if findItem neiSG face_SG[f][aN] != 0 then
(
affectNormal = true
)
)
)
if affectNormal == true then
(
vNormal += getFaceNormal tmesh simFaces[s]
)
)
vert_normal = normalize(vNormal)
if geom_object_has_tverts[g] == true then
(
tvert_pos = getTVert tmesh face_tverts[f][vertices]
)
else
(
tvert_pos = [0,0,0]
)
)
append face_shader_index ((findItem geom_materials geometry_objects[g].material[face_matID[f]]) - 1)
)
max create mode
clearSelection()
)
if boneAffectWarning == true then
(
messageBox "Warning: some vertices are weighted by more than two bones." title:"BlueStreak Error"
)
)
else
(
messageBox "Warning: there was no geometry to export." title:"BlueStreak Error"
)
)
if exportFailed != true then
(
-- Print the JMS file to JMS or the MAXScript Listener --
if chk_jms.checked == true then
(
output_name = getSaveFileName caption:"Select File to Export" \
filename: "C:\\Program Files\\Microsoft Games\\Halo Custom Edition\\data\\" \
types:"BlueStreak Model Exporter (*.jms)|*.jms|All Files (*.*)|*.*|"
if output_name != undefined then
(
jms = createfile output_name
validJMS = true
)
else
(
validJMS = false
messageBox "You did not create or select a JMS file to save to. Export failed." \
title: "JMS export terminated"
)
)
else
(
ClearListener()
jms = listener
validJMS = true
)
if validJMS == true then
(
ProgressStart "Exporting JMS Data"
start1 = timeStamp()
node_count = node_array.count
format "%\n%\n%\n" 8200 3251 node_count to:jms
for n = 1 to node_count do
(
format "%\n" node_array[n].name to:jms
format "%\n" (node_first_child_index[n] - 1) to:jms
format "%\n" (node_next_sibling_index[n] - 1) to:jms
format "%\t%\t%\t%\n" node_rotation[n].x node_rotation[n].y node_rotation[n].z node_rotation[n].w to:jms
format "%\t%\t%\n" node_translation[n].x node_translation[n].y node_translation[n].z to:jms
)
mat_count = geom_materials.count
format "%\n" mat_count to:jms
for m = 1 to mat_count do
(
format "%\n%\n" geom_materials[m].name "" to:jms
)
marker_count = marker_array.count
format "%\n" marker_count to:jms
for m = 1 to marker_count do
(
format "%\n-1\n" (substring marker_array[m].name 2 -1) to:jms
format "%\n" (marker_parent_index[m] - 1) to:jms
format "%\t%\t%\t%\n" marker_rotation[m].x marker_rotation[m].y marker_rotation[m].z marker_rotation[m].w to:jms
format "%\t%\t%\n2.0\n" marker_translation[m].x marker_translation[m].y marker_translation[m].z to:jms
)
numVerts = vert_pos.count
format "%\n%\n%\n" 1 "unnamed" numVerts to:jms
totalCount = numVerts + numFaces
for v = 1 to numVerts do
(
format "%\n" vert_node0index to:jms
format "%\t%\t%\n" vert_pos.x vert_pos.y vert_pos.z to:jms
format "%\t%\t%\n" vert_normal.x vert_normal.y vert_normal.z to:jms
format "%\n" vert_node1index to:jms
format "%\n" vert_node1weight to:jms
format "%\n" tvert_pos.x to:jms
format "%\n0\n" tvert_pos.y to:jms
ProgressUpdate ((v as float / totalCount) * 100.0)
)
format "%\n" numFaces to:jms
c = 0
for n = 1 to numFaces do
(
format "0\n%\n" face_shader_index[n] to:jms
format "%\t%\t%\n" c (c+1) (c+2) to:jms
c += 3
ProgressUpdate (((numVerts + n as float) / totalCount) * 100.0)
)
end1 = timeStamp()
if chk_jms.checked == true then
(
format ("JMS took % seconds to write.") ((end1 - start1) / 1000.0) to:listener
close jms
)
ProgressEnd()
)
)
if exportFailed == true then
(
messageBox "Export module failure" title:"Export"
for a = 1 to all_objects_array.count do
(
all_objects_array[a].name = all_object_names[a]
)
)
)
)
CreateDialog roll
-- End of Script --