Results 11 to 20 of 20

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10

    Aika .msh to Max Importer

    This is complete script for loading .msh into Max.


    PHP Code:
    Utility Aika_tool "Aika .msh Importer" (
    fn importmsh f = (
    Vert_array #()         --define arrays for verts, normals, UV and Faces
    Normal_array #()
    UV_array #()
    Face_array #()
    Magic1 readlong f
    Null1 
    readlong f
    Ckey 
    readlong f
    Unk2 
    readlong f
    Csize 
    readlong f
    UNK3 
    readlong f
    Bsize 
    readlong f
    Vsize 
    readlong f
    Fsize 
    = (readlong f) / 3
     
    for 1 to Bsize do (
        
    w1 readfloat f
        w2 
    readfloat f
        w3 
    readfloat f
        w4 
    readfloat f
        x1 
    readfloat f
        x2 
    readfloat f
        x3 
    readfloat f
        x4 
    readfloat f
        y1 
    readfloat f
        y2 
    readfloat f
        y3 
    readfloat f
        y4 
    readfloat f
        z1 
    readfloat f
        z2 
    readfloat f
        z3 
    readfloat f
        z4 
    readfloat f
    )
     
    for 
    1 to Bsize do (
        
    Bid readlong f
    )
     
    if 
    Csize == 36 do (
     
    for 
    1 to Vsize do (     --* number of verts count
    vx 
    readfloat f                --read xyz coordinates
    vy 
    readfloat f
    vz 
    readfloat f
     
    append Vert_array 
    [vx,vy,vz] --save verts to Vert_array
     
    w1 
    readbyte f      --bone weight
    w2 
    readbyte f
    w3 
    readbyte f
    w4 
    readbyte f
     
    nx 
    readlong f      --read Normal ??
    ny readlong f
    nz 
    readlong f
    append Normal_array 
    [nx,ny,nz] --save normals to Normal_array
     
    tu 
    readfloat f                --read UV float value
    tv 
    = (readfloat f) * -
    append UV_array 
    [tu,tv,0]       --save UVs to UV_array
     
    --since UV in Max are in point3 formatso we add 0 for z value
    )
    )
     
    if 
    Csize == 40 do (
    for 
    1 to Vsize do (     --* number of verts count
    vx 
    readfloat f                --read xyz coordinates
    vy 
    readfloat f
     
    vz 
    readfloat f
    append Vert_array 
    [vx,vy,vz] --save verts to Vert_array
     
    b1 
    readbyte f      
    b2 
    readbyte f      
    b3 
    readbyte f      
    b4 
    readbyte f
    w1 
    readbyte f      --bone weight
     
    w2 
    readbyte f
    w3 
    readbyte f
    w4 
    readbyte f
     
    nx 
    readlong f      --read Normal ??
    ny readlong f
    nz 
    readlong f
     
    append Normal_array 
    [nx,ny,nz] --save normals to Normal_array
    tu 
    readfloat f                --read UV float value
    tv 
    = (readfloat f) * -
    append UV_array 
    [tu,tv,0]       --save UVs to UV_array
    --since UV in Max are in point3 formatso we add 0 for z value
    )
    )
     
    if 
    Csize == 44 do (
    for 
    1 to Vsize do (     --* number of verts count
    vx 
    readfloat f                --read xyz coordinates
    vy 
    readfloat f
    vz 
    readfloat f
     
    append Vert_array 
    [vx,vy,vz] --save verts to Vert_array
     
    b1 
    readbyte f      
    b2 
    readbyte f      
    b3 
    readbyte f      
    b4 
    readbyte f
    w1 
    readbyte f      --bone weight
    w2 
    readbyte f
    w3 
    readbyte f
    w4 
    readbyte f
    bw1 
    readfloat f
     
    nx 
    readlong f      --read Normal ??
    ny readlong f
    nz 
    readlong f
    append Normal_array 
    [nx,ny,nz] --save normals to Normal_array
    tu 
    readfloat f                --read UV float value
    tv 
    = (readfloat f) * -
    append UV_array 
    [tu,tv,0]       --save UVs to UV_array
    --since UV in Max are in point3 formatso we add 0 for z value
     
    )
    )
     
    if 
    Csize == 48 do (
    for 
    1 to Vsize do (     --* number of verts count
    vx 
    readfloat f                --read xyz coordinates
    vy 
    readfloat f
    vz 
    readfloat f
    append Vert_array 
    [vx,vy,vz] --save verts to Vert_array
     
    b1 
    readbyte f      
    b2 
    readbyte f      
    b3 
    readbyte f      
    b4 
    readbyte f
     
    w1 
    readbyte f      --bone weight
    w2 
    readbyte f
    w3 
    readbyte f
    w4 
    readbyte f
    bw2 
    readfloat f
     
    bw1 
    readfloat f
     
    nx 
    readlong f      --read Normal ??
    ny readlong f
    nz 
    readlong f
    append Normal_array 
    [nx,ny,nz] --save normals to Normal_array
     
    tu 
    readfloat f                --read UV float value
     
    tv 
    = (readfloat f) * -
    append UV_array 
    [tu,tv,0]       --save UVs to UV_array
    --since UV in Max are in point3 formatso we add 0 for z value
    )
    )
     
    for 
    1 to Fsize do (
    f1 = (readshort f) + 1      --read face indicesgames are start form 0but Max start from 1
    f2 
    = (readshort f) + 1      --so we add 1 to each index
    f3 
    = (readshort f) + 1
     
    append Face_array 
    [f1,f2,f3] --save faces to Face_array
    )
    fclose f                --close file
    msh 
    mesh vertices:Vert_array faces:Face_array     --build mesh
    msh
    .numTVerts UV_array.count
    buildTVFaces msh
    for 1 to UV_array.count             do setTVert     msh j UV_array[j]
    for 
    1 to Face_array.count       do setTVFace msh j Face_array[j]
    for 
    1 to Normal_array.count do setNormal msh j Normal_array[j]
     
    )--
    end fn
     
    --GUI--
    group ""(
            
    button impmsh "" images:#("Aika.bmp",undefined,1,1,1,1,1) width:160 height:128 align:#center tooltip:"Aika msh Importer" offset:[0,-5]
            
    label lbl1 "By chrrox" align:#right --offset:[0,-40]
            
    label lbl2 "9/29/2009" align:#right
            
    label lbl3 "Gui By fatduck" align:#right
            
    button btn_fix "Fix all meshes..." offset:[0,8]
            
    label lbl4 "Use when done importing" align:#right
    )
    --
    button expDDS "Convert Textures" width:150
     
     
    on impmsh pressed 
    do (
        
    fname GetOpenFileName caption:"Open Aika Model File" types:"Aika Model File(*.msh)|*.msh"
        
    if fname != undefined then (
        
    fopen fname "rb"
        
    try (
            
    importmsh f                             
            
    ) catch (
             
    messagebox "msh FN error" 
            
    )
            
    fclose f
            

    )
     
    on btn_fix pressed do (
        try(
            
    actionMan.executeAction 0 "40021"     -- SelectionSelect All
             rotate 
    $ (angleaxis 180 [0,1,0])
             
    rotate $ (angleaxis 90 [1,0,0])
             
    scale $ [50,50,50]
     
             
    clearSelection()
             
    actionMan.executeAction 0 "311"      -- ToolsZoom Extents All Selected
            
    )
            catch (
             
    messagebox "MESH FIX error" 
            
    )
        )
    )--
    end Utility 
    by chrrox
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  2. The Following User Says Thank You to Dwar For This Useful Post:


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •