Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Hybrid 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:


  3. #2
    -Ciclopy-
    -Ciclopy- is offline
    Guest
    Join Date
    2010 Sep
    Posts
    1
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0
    Estava procurando algo do tipo para poder mexer um pouco com o jogo ^^

  4. #3
    meat23
    meat23 is offline
    Guest
    Join Date
    2011 Mar
    Posts
    1
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0
    Hi Dwar, im trying to use this script in max 2010 but I am running into some errors.
    First off i'm great with max but not so good with max script so please excuse my noobness.
    When I try to run the script I get a dialogue saying:
    MAXScript FileIn Exception
    -- Syntax error: at \, expected string
    -- In line: group \g

    If I open the script in the max script window so I can look at the code and try to evaluate all the script stops on line 178 group ""(

    Any help would be appreciated. I would love to check out some of these models in max. I also ran your AikaJ2D tool to convert the textures and it worked perfectly. You rock!

    Thanks in advance!

  5. #4
    pkedpker
    pkedpker is offline
    Member-in-training
    Join Date
    2011 Mar
    Posts
    67
    Thanks Thanks Given 
    13
    Thanks Thanks Received 
    41
    Thanked in
    14 Posts
    Rep Power
    0
    replace all " with " thats html markup must of been a bad paste.

  6. #5
    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
    Quote Originally Posted by meat23 View Post
    If I open the script in the max script window so I can look at the code and try to evaluate all the script stops on line 178 group ""(
    Check this script again. " should be quote symbol "
    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

  7. #6
    CriticalError
    CriticalError is offline
    Senior Member CriticalError's Avatar
    Join Date
    2011 Jun
    Posts
    204
    Thanks Thanks Given 
    21
    Thanks Thanks Received 
    44
    Thanked in
    27 Posts
    Rep Power
    0
    hello how are you, well first of all I wanna say thanks for this great script, but the script not load in MAX :S don't know what happen I try run importer and nothing happened any know what happen? I try in 3D Studio Max 9 and 2009

  8. #7
    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
    Quote Originally Posted by CriticalError View Post
    but the script not load in MAX
    This script was tested long ago with old MAX and not by me. Probably it doesn't work with newest version. I can't correct and can't check it, 'coz it's not my field.
    But Aika's files and also jit textures can be opened in "3D Object Converter"

    P.S. I checked your 3d models, they are looks pretty good
    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

  9. #8
    Datatraveler
    Datatraveler is offline
    New member
    Join Date
    2011 Jul
    Location
    Malaysia
    Posts
    19
    Thanks Thanks Given 
    1
    Thanks Thanks Received 
    3
    Thanked in
    3 Posts
    Rep Power
    0
    I do have a question, what is this program for? is it to create/making own new design used by gaming artis?

  10. #9
    CriticalError
    CriticalError is offline
    Senior Member CriticalError's Avatar
    Join Date
    2011 Jun
    Posts
    204
    Thanks Thanks Given 
    21
    Thanks Thanks Received 
    44
    Thanked in
    27 Posts
    Rep Power
    0
    Quote Originally Posted by Datatraveler View Post
    I do have a question, what is this program for? is it to create/making own new design used by gaming artis?
    a .ms files are max scripts, this is for import files in this case .msh from Aika Online.

    .msh= 3D Model

  11. #10
    CriticalError
    CriticalError is offline
    Senior Member CriticalError's Avatar
    Join Date
    2011 Jun
    Posts
    204
    Thanks Thanks Given 
    21
    Thanks Thanks Received 
    44
    Thanked in
    27 Posts
    Rep Power
    0
    well guys trying get .mesh original with bones and fail today I get that thanks a lot chrox for this great script and Dwar too anyway good job, here a model load.

    Correct Script.

    PHP Code:
    if (heapSize 20000000then
       heapSize 
    200000000 -- allow 40 MB instead of just 7.5 MBPrevents "Runtime Error: Out of scripter memory"

    fname getOpenFileName \
    caption:"Open Aika Model File" \
    types:"Aika Model File(*.msh)|*.msh" \
    historyCategory:"AikaObjectPresets"
    fopen fname "rb"
    getFilenameFile fname
    gg 
    substring h 1 4 ".bon"
    g2 getFilenamePath fname gg
    fopen g2 "rb"
    print g
    total_size 
    getFileSize g2 8
    boneparentidarray 
    #()
    for 1 to total_size Do (
    boneparentid readlong g
    realboneid 
    readlong g
    printoffset boneparentid
    print realboneid
    append boneparentidarray boneparentid
    )
    fn PrintOffset Var =
    (
       
    local Var = Var
    print (
    "This is the offset 0x" + (bit.intAsHex Var) as string)
       Var
    )
    fn PrintCount Var =
    (
       
    local Var = Var
    print (
    "This is the Count 0x" + (bit.intAsHex Var) as string)
       Var
    )

    fn Readword fstream = (
    return 
    readshort fstream #unsigned
    )

    fn ReadFixedString bstream fixedLen =
    (
       
    local str ""
       
    for 1 to fixedLen do
       (
          
    str += bit.intAsChar (ReadByte bstream #unsigned)
       
    )
       
    str
    )

    struct Mesh_Info_Struct
    (
       
    Mesh_Name,vertstart,vertend,vertcount,facecount
    )
    struct Offset_Info_Struct
    (
       
    Section_Start,Vert_Start,Face_Start,vertsize
    )
    unk01 readlong f
    unk02 
    readlong f
    unk03 
    readlong f
    Count01 
    readlong f
    VertSize 
    readlong f
    unk06 
    readlong f
    BoneCount 
    readlong f
    VertCount
    readlong f
    FaceCount 
    readlong f

    struct Bone_Table_Data
    (
       
    BoneName,BoneParentID,BoneID
    )
    BoneStart = (ftell f)
    fseek f (0x40 BoneCount#seek_cur
    Bone_ID_Array #()
    for 1 to BoneCount Do (
    boneid readlong f
    append Bone_ID_Array boneid
    )
    fseek f BoneStart #seek_set
    BNArr #()
    for 1 to BoneCount Do (

    m11 readfloat fm12 readfloat fm13 readfloat fm14 readfloat f
    m21 
    readfloat fm22 readfloat fm23 readfloat fm24 readfloat f
    m31 
    readfloat fm32 readfloat fm33 readfloat fm34 readfloat f
    m41 
    readfloat fm42 readfloat fm43 readfloat fm44 readfloat f
    tfm2 
    matrix3 [m11,m12,m13] [m21,m22,m23] [m31,m32,m33] [m41,m42,m43]
    tfm inverse tfm2
    if isvalidnode (getnodebyname ("Bone_" Bone_ID_Array[i] as string)) == true then (
    append BNArr (getnodebyname ("Bone_" Bone_ID_Array[i] as string))
    )
    if 
    isvalidnode (getnodebyname ("Bone_" Bone_ID_Array[i] as string)) != true then (
       
    newBone bonesys.createbone   \
                  
    tfm.row4   \
                  (
    tfm.row4 0.01 * (normalize tfm.row1)) \
                  (
    normalize tfm.row3)
               
    newBone.name   = ("Bone_" Bone_ID_Array[i] as string)
             
    newBone.width  0.03
             newBone
    .height 0.03
             newBone
    .transform tfm
             newBone
    .wirecolor yellow
             newbone
    .showlinks true
             newBone
    .setBoneEnable false 0
             newBone
    .pos.controller      TCB_position ()
             
    newBone.rotation.controller TCB_rotation ()
    append BNArr newBone
                  
    )

    )
    for 
    1 to BoneCount Do (
    select (getnodebyname ("Bone_" + (Bone_ID_Array[i]) as string))
    if  
    boneparentidarray[Bone_ID_Array[(i)]] != 0 then
    $.parent = (getnodebyname ("Bone_" boneparentidarray[Bone_ID_Array[(i)] + 1] as string))
    boneid readlong f
       
    print boneid
    print (getnodebyname ("Bone_" boneparentidarray[Bone_ID_Array[(i)]] as string))
    )
    struct weight_data
    (
       
    boneids,weights
    )
    Vert_array #()
    Normal_array #()
    UV_array #()
    Face_array #()
    Weight_array #()
    for 1 to VertCount Do (
    vx readfloat f     --read xyz coordinates
    vy 
    readfloat f
    vz 
    readfloat f
       
    if VertSize == 0x24 do (
    bone1 readbyte f#unsigned
    bone2 readbyte f#unsigned
    bone3 readbyte f#unsigned
    bone4 readbyte f#unsigned
    weight1 readfloat f
    weight1 
    1.0
    weight2 
    0
    weight3 
    0
    weight4 
    0
    fseek f 0x8
    #seek_cur
       
    )
       if 
    VertSize == 0x28 do (
    weight1 readfloat f
    weight2 
    0
    bone1 
    readbyte f#unsigned
    bone2 readbyte f#unsigned
    bone3 readbyte f#unsigned
    bone4 readbyte f#unsigned
    weight3 0
    weight4 
    0
    fseek f 0xC
    #seek_cur
       
    )
          if 
    VertSize == 0x2C do (
    weight1 readfloat f
    weight2 
    readfloat f
    bone1 
    readbyte f#unsigned
    bone2 readbyte f#unsigned
    bone3 readbyte f#unsigned
    bone4 readbyte f#unsigned
    weight3 0
    weight4 
    0
    fseek f 0xC
    #seek_cur
       
    )
    tu readfloat f
    tv 
    readfloat f * -1
    = (weight_data boneids:#() weights:#())
    maxweight 0
       
    if(weight1 != 0then
       maxweight 
    maxweight weight1
    if(weight2 != 0then
       maxweight 
    maxweight weight2
    if(weight3 != 0then
       maxweight 
    maxweight weight3
    if(weight4 != 0then
       maxweight 
    maxweight weight4

    if(maxweight != 0) Do   
       (
          if(
    weight1 != 0) Do
       (
             
    w1 weight1 as float
             append w
    .boneids (bone1+1)
             
    append w.weights w1
          
    )
          if(
    weight2 != 0) Do
          (
             
    w2 weight2 as float
             append w
    .boneids (bone2+1)
             
    append w.weights w2
          
    )
          if(
    weight3 != 0) Do
          (
             
    w3 weight3 as float
             append w
    .boneids (bone3+1)
             
    append w.weights w3
          
    )
          if(
    weight4 != 0) Do
          (
             
    w4 weight4 as float
             append w
    .boneids (bone4+1)
             
    append w.weights w4
          
    )      
       )      
       

    append Vert_array [vx,vy,vz] --save verts to Vert_array
    append UV_array 
    [tu,tv,0]  --save UVs to UV_array
    append Weight_array w
    )
    for 
    1 to facecount 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
    )

    msh mesh vertices:Vert_array faces:Face_array
    msh
    .numTVerts UV_array.count
    buildTVFaces msh
    --msh.name Mesh_Name_array[a]
    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]

    max modify mode
    select msh
    skinMod 
    skin ()
    addModifier msh skinMod
    for 1 to BNArr.count do
    (
       
    maxbone getnodebyname BNArr[i].name
       
    if != BNArr.count then
          skinOps
    .addBone skinMod maxbone 0
       
    else
          
    skinOps.addBone skinMod maxbone 1
       
    )

    modPanel.setCurrentObject skinMod

    for 1 to Weight_array.count do
    (
       
    Weight_array[i]
       
    bi #() --bone index array
       
    wv #() --weight value array
       
       
    for 1 to w.boneids.count do
       (
          
    boneid w.boneids[j]
          
    weight w.weights[j]
          
    append bi boneid
          append wv weight
       
    )   
       
       
    skinOps.ReplaceVertexWeights skinMod i bi wv
       
    )
    max create mode

    printoffset 
    (ftell f)
    fclose f
    fclose g 

    Please register or login to download attachments.


  12. The Following 2 Users Say Thank You to CriticalError For This Useful Post:


Page 1 of 2 12 LastLast

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
  •