MAXScript Compatibility (3Ds Max 2013 - 2014)

Hi i'm having a problem using a script i used on 3Ds max 2013 on 2014 its a model exporter for a game when i export it using 2014 it ends up being broken in game any ideas on how i can fix this would be great thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Luke's picture

Sorry

Sorry the file i export it is a SCM and the script uses multiply script files i would say it would be the exporter one.

 

/*
========================================

========================================
*/
fileIn "structs.ms"                -- supremecommander structs
filein "supcom2write.ms"    -- write to file functions

fn SetDebugHeader h=
(
    h.boneoffset = 0
    h.wbonecount = 0
    h.vertoffset = 0
    h.evertoffset = 0
    h.vertcount = 0
    h.indexoffset = 0
    h.indexcount = 0
    h.infooffset = 0
    h.infocount = 0
    h.totalbones = 0
    h.xtraoffset = 0
    --xtravalue,
    h.materialoffset = 0
    h.materialnum = 0
)

fn CalculatePadding offset=
(
    padding = 16 - (mod offset 16)
    if padding < 4 do padding += 16
    newoffset = offset+padding
   
    padding -=4
    return #(padding, newoffset)
)

fn ExportSupCom2Format G path=
(
    format "\t*************\nexporting supcom2 model\n\t*************\n"
    --- check if gamemesh is multi surface.
    format "numsurfaces: %\n" G.numSurfaces
    if G.isAnimated == false do
    (
        messagebox "GMError: not animated"
        return false
    )
    --- COLLECT DATA
    Header = SC2_Header()
    SetDebugHeader Header
    Header.infocount = 43    --- fixed string "Exported with scmtool www.janvanderweg.com"
   
    Bonelist = SC2_Bonelist()
    gm_numbones = G.Hierarchy.bones.count
   
    SKELOFFSET = undefined
    VTXLOFFSET = undefined
    TRISOFFSET = undefined
    XTRAOFFSET = undefined
    INFOOFFSET = undefined
    MNAMOFFSET = undefined
    MATSOFFSET = undefined
   
    boneoffset = 64 -- bonelist offset is 64 bytes, the size of the header.
    for i = 1 to gm_numbones do
    (
        name = G.Hierarchy.bones[i].name
        append Bonelist.bones name
        append Bonelist.offset boneoffset
        boneoffset+= (name.count +1)
    )
    SKELOFFSET = CalculatePadding boneoffset
    Bonelist.padding = SKELOFFSET[1]
    Header.boneoffset = SKELOFFSET[2] --boneoffset
    Header.wbonecount = G.Hierarchy.bones.count
    Header.totalbones = G.Hierarchy.bones.count
   
    -- Collect Bone Data
    sc2bones=#()
    for i = 1 to gm_numbones do
    (
        sc2bone = SC2_Bone()
        format "bone: % parent: %\n" g.Hierarchy.bonename[i] g.hierarchy.parentindex[i]
       
        sc2bone.name = g.Hierarchy.bonename[i]
        sc2bone.nameoffset = Bonelist.offset[i]
       
        node = g.hierarchy.bones[i]
        parent = undefined
        parentindex = g.hierarchy.parentindex[i] + 1
        if parentindex != 0 do parent = g.hierarchy.bones[parentindex] \
       
        transform = node.transform
        parent = node.parent
        if parent == undefined then
        (
            --local parentindex = -1
            sc2bone.parentboneindex = -1
            sc2bone.position = transform.row4
            sc2bone.rotation = quat 0 0 0 1
        )
        else
        (
            sc2bone.parentboneindex = g.hierarchy.parentindex[i]
            --relative position and rotation
            sc2bone.position = ( in coordsys parent node.pos )
            sc2bone.rotation = ( in coordsys parent node.rotation )
        )
        Transform.row1 = normalize Transform.row1
        Transform.row2 = normalize Transform.row2
        Transform.row3 = normalize Transform.row3
        iTransform = inverse transform
        sc2bone.RestPoseInverse1 = ( normalize [ iTransform.row1[1], iTransform.row2[1], iTransform.row3[1]] )
        sc2bone.RestPoseInverse2 = ( normalize [ iTransform.row1[2], iTransform.row2[2], iTransform.row3[2]] )
        sc2bone.RestPoseInverse3 = ( normalize [ iTransform.row1[3], iTransform.row2[3], iTransform.row3[3]] )
        sc2bone.RestPoseInverse4 = iTransform.row4
       
        append sc2bones sc2bone
    )
    --- Bonedata size = (108 * totalbones) bytes large
    VTXLOFFSET = CalculatePadding (SKELOFFSET[2] + 108 * gm_numbones)
    Header.vertoffset = VTXLOFFSET[2]
   
    sc2Verts=#()
    for s = 1 to G.numSurfaces do
    (
        SF = G.Surfaces[s]
        for v = 1 to SF.numverts do
        (
            sc2vert = SC2_Vertex()
            gmvert = SF.Vertex[v]
           
            sc2vert.position = gmvert.position
            sc2vert.normal = gmvert.normal
            sc2vert.tangent = gmvert.tangent
            sc2vert.bitangent = gmvert.bitangent
            sc2vert.uv1 = gmvert.uvw
            sc2vert.uv2 = gmvert.uvw
           
            bl=#()
            wl=#()
            tw = 0
            for j = 1 to 4 do
            (
                b = gmvert.boneindex[j]
                w = gmvert.boneweight[j]
                b = finditem G.Hierarchy.bonename b
                b -= 1
                if gmvert.boneindex[j] == undefined do b = 0
                w = (w *255) as integer
                tw += w
                append bl b
                append wl w
            )
            if tw < 255 do    --ensure that all weights total 255
            (
                toadd = 255 - tw
                wl[1] += toadd
            )
            sc2vert.boneindex = bl
            sc2vert.boneweights = wl
            append sc2verts sc2vert
        )
    )
   
    Header.vertcount = sc2Verts.count
    TRISOFFSET = CalculatePadding (VTXLOFFSET[2] + 68 * sc2Verts.count)
    Header.indexoffset = TRISOFFSET[2]
   
    MaterialData=#()
   
    ioffset = 0
    for s = 1 to G.numSurfaces do
    (
        SF = G.Surfaces[s]
        indexref = (SF.tris[1][1] + ioffset - 2) as integer
        --format "%\n" indexref
        --indexref -= 1
        append MaterialData #(SF.tris.count, ioffset, (SF.material.name.count + 1), indexref, SF.NumVerts)
        Header.indexcount += SF.tris.count
        ioffset += (SF.tris.count * 3)
    )
    MaterialData[1][4]=0
    MaterialData[1][5]=sc2Verts.count
   
    Header.indexcount *= 3
    --format "ioffset: %\n" ioffset
    XTRAOFFSET = CalculatePadding(TRISOFFSET[2] + ( ioffset *2))
    Header.xtraoffset = XTRAOFFSET[2]
   
    --format "xo: %\n" XTRAOFFSET[2]
    INFOOFFSET = CalculatePadding(XTRAOFFSET[2] + 4 * sc2Verts.count)
    Header.infooffset = INFOOFFSET[2]
   
    MaterialStringSize = 0
   
    for s = 1 to G.numSurfaces do
    (
        SF = G.Surfaces[s]
        MaterialStringSize += SF.material.name.count + 1
    )
    --format "MaterialStringSize: %\n" MaterialStringSize
   
    MATSOFFSET = CalculatePadding(INFOOFFSET[2] + 80 + MaterialStringSize)
    --format "io: %\n" INFOOFFSET[2]
    --format "mo: %\n" MATSOFFSET[2]
    Header.materialoffset = MATSOFFSET[2]
    Header.materialnum = G.numSurfaces
   
    --- WRITE FILE
    bstream = fopen path "wb"

    SC2_WriteHeader bstream Header
    SC2_WriteBonelist bstream Bonelist
    SC2_WriteBones bstream sc2bones VTXLOFFSET[1]
    SC2_WriteVerts bstream sc2Verts TRISOFFSET[1]
   
    for s = 1 to G.numSurfaces do
    (
        SF = G.Surfaces[s]
        SC2_WriteSurfaceTris bstream SF.tris MaterialData[s][2]
    )
    SC2_WriteTrisPadding bstream XTRAOFFSET[1]
    SC2_WriteXtra bstream sc2verts INFOOFFSET[1]
   
    WriteString bstream "Exported with scmtool www.janvanderweg.com"
    for i = 1 to 33 do WriteByte bstream 187
    WriteByte bstream 77 -- MNAM
    WriteByte bstream 78
    WriteByte bstream 65
    WriteByte bstream 77
   
    MaterialStringSize = 0
   
    for s = 1 to G.numSurfaces do
    (
        SF = G.Surfaces[s]
        WriteString bstream SF.material.name
    )
    for i = 1 to MATSOFFSET[1] do WriteByte bstream 187
    WriteByte bstream 77 -- MATS
    WriteByte bstream 65
    WriteByte bstream 84
    WriteByte bstream 83
   
   
    SC2_WriteMATS bstream MaterialData (INFOOFFSET[2] +80) sc2Verts.count
   
    fclose bstream
)
/*
    --- Vertex Data
    s = G.Surfaces[1] -- assume only one surface
    sc2verts=#()
   
    H.indexcount = s.numtris * 3
    H.vertcount = s.numverts
   
    for i = 1 to s.numverts do
    (
        sc2vert = SC2_Vertex()
        gmvert = s.Vertex[i]
       
        sc2vert.position = gmvert.position
        sc2vert.normal = gmvert.normal
        sc2vert.tangent = gmvert.tangent
        sc2vert.bitangent = gmvert.bitangent
        sc2vert.uv1 = gmvert.uvw
        sc2vert.uv2 = gmvert.uvw
       
        bl=#()
        wl=#()
        tw = 0
        for j = 1 to 4 do
        (
            b = gmvert.boneindex[j]
            w = gmvert.boneweight[j]
            b = finditem G.Hierarchy.bonename b
            b -= 1
            if gmvert.boneindex[j] == undefined do b = 0
            w = (w *255) as integer
            tw += w
            append bl b
            append wl w
        )
        if tw < 255 do    --ensure that all weights total 255
        (
            toadd = 255 - tw
            wl[1] += toadd
        )
        sc2vert.boneindex = bl
        sc2vert.boneweights = wl
        append sc2verts sc2vert
    )
   
    --calculate vertexdata padding
    --a single vertex entry is 68 bytes. 17*4
    indexoffset = H.vertoffset + ( sc2verts.count * 68 )
    vertdatapadding = 16 - ( mod indexoffset 16 )
    if vertdatapadding < 4 then
    (
        vertdatapadding += 16
    )
    indexoffset = ( indexoffset + vertdatapadding )
    vertdatapadding -= 4
    H.indexoffset = indexoffset
    VertexDataPadding = vertdatapadding
   
    --calculate trisdata padding
    --a single index entry is 6 bytes. 3*2
    xtraoffset = H.indexoffset + ( s.numtris * 6 )
    trispadding = 16 - ( mod xtraoffset 16 )
    if trispadding < 4 then
    (
        trispadding += 16
    )
    xtraoffset += trispadding
    trispadding -= 4
    H.xtraoffset = xtraoffset
    TrisDataPadding = trispadding
   
    -- calculate xtra data padding
    -- a single xtra data entry is 4 bytes
    infooffset = H.xtraoffset + (sc2verts.count * 4)
    xtrapadding = 16 - ( mod infooffset 16)
    if xtrapadding < 4 then
    (
        xtrapadding += 16
    )
    infooffset += xtrapadding
    xtrapadding -= 4
    H.infooffset = infooffset
    XtraDataPadding = xtrapadding
   
    H.materialoffset = H.infooffset + 96
    H.materialnum = 1
   
    -- Write File
    bstream = fopen path "wb"

    SC2_WriteHeader bstream H
    SC2_WriteBonelist bstream Bonelist
    SC2_WriteBones bstream sc2bones BoneDataPadding
    SC2_WriteVerts bstream sc2verts VertexDataPadding
    SC2_WriteTris bstream s.tris TrisDataPadding
    SC2_WriteXtra bstream sc2verts XtraDataPadding
   
    WriteString bstream "Exported with scmtool www.janvanderweg.com"
    for i = 1 to 33 do WriteByte bstream 187
    WriteByte bstream 77 -- MNAM
    WriteByte bstream 78
    WriteByte bstream 65
    WriteByte bstream 77
    WriteString bstream "Diffuse"
    for i = 1 to 4 do WriteByte bstream 187
    WriteByte bstream 77 -- MATS
    WriteByte bstream 65
    WriteByte bstream 84
    WriteByte bstream 83
   
    WriteLong bstream (H.materialoffset - 16)
    WriteLong bstream s.numtris
    WriteLong bstream 0
    WriteLong bstream 0
   
    WriteLong bstream s.numverts
   
    fclose bstream
)
*/

br0t's picture

provide more information and

provide more information and maybe people can help you. post the script if you can, tell us about the format you export to.

Never get low & slow & out of ideas

tassel's picture

I guess this is part of some

I guess this is part of some Supreme Commander 2.
The rest of the files can be found here:

http://www.janvanderweg.com/supcom2/

Raymond H.Ingebretsen - http://www.homme3d.com

Luke's picture

That doesnt help

That doesn't help it not supporting max 2014 or having any problem using version later than 2010.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.