home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 10914 / fmt_p4d_gmd.7z / fmt_p4d_gmd.py
Encoding:
Python Source  |  2016-05-08  |  22.3 KB  |  615 lines

  1. #Noesis Python model import+export test module, imports/exports some data from/to a made-up format
  2.  
  3. from inc_noesis import *
  4.  
  5. import noesis
  6. import struct
  7.  
  8. #rapi methods should only be used during handler callbacks
  9. import rapi
  10.  
  11. #registerNoesisTypes is called by Noesis to allow the script to register formats.
  12. #Do not implement this function in script files unless you want them to be dedicated format modules!
  13. def registerNoesisTypes():
  14.    handle = noesis.register("Persona 4: Dancing All Night", ".gmd")
  15.    noesis.setHandlerTypeCheck(handle, noepyCheckType)
  16.    noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
  17.    handle = noesis.register("Persona 4: Dancing All Night", ".GFS")
  18.    noesis.setHandlerTypeCheck(handle, noepyCheckType)
  19.    noesis.setHandlerLoadModel(handle, noepyLoadModel)
  20.        #noesis.setHandlerWriteModel(handle, noepyWriteModel)
  21.        #noesis.setHandlerWriteAnim(handle, noepyWriteAnim)
  22. ##   noesis.logPopup()
  23.        #print("The log can be useful for catching debug prints from preview loads.\nBut don't leave it on when you release your script, or it will probably annoy people.")
  24.    return 1
  25.  
  26. NOEPY_HEADER = "GFS0"
  27.  
  28. #check if it's this type based on the data
  29. def noepyCheckType(data):
  30.    bs = NoeBitStream(data)
  31.    if len(data) < 16:
  32.       return 0
  33.    if bs.readBytes(4).decode("ASCII").rstrip("\0") != NOEPY_HEADER:
  34.       return 0
  35.    return 1       
  36.  
  37. #load the model
  38. def noepyLoadModel(data, mdlList):
  39.    ctx = rapi.rpgCreateContext()
  40.    bs = NoeBitStream(data, 1)
  41.    sb = NoeBitStream(data)
  42. ##   bs.setByteEndianForBits(NOE_BIGENDIAN)
  43.    bs.setEndian(NOE_BIGENDIAN)
  44.    rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
  45.  
  46.    DDSSpitOut = 0
  47.    SkipMaterials = 0
  48.    Skin = 1
  49.    Optimize = 0
  50.    EXPMorph = 1
  51.    MATDEBUG = 0
  52.    MESHDEBUG = 0
  53.    EmergencyNameDump = 0
  54.    BoneOverride = 0
  55.    if BoneOverride:
  56.       Skin = 0
  57.       SkipNodes = 1
  58.    else:
  59.       SkipNodes = 0
  60.    BL = None
  61.    
  62.    MAGIC = bs.readBytes(4)
  63.    TOPID = bs.readUInt()
  64.    TOPTYPE = bs.readUInt()
  65.    BLANK = bs.readUInt()
  66.    CHUNKID = bs.readUInt()
  67.    CHUNKTYPE = bs.readUInt()
  68.    CHUNKSIZE = ((bs.readUInt()) - 8)
  69.    BLANK = bs.readUInt()
  70.    ContentCOUNT = bs.readUInt()
  71.  
  72.    DDSNames = []
  73.    DDSContent = []
  74.    print(bs.tell())
  75.    texList = []
  76.    texIndex = []
  77.    for D in range(0, ContentCOUNT):
  78.       NameCharCount = bs.readUShort()
  79.       if MATDEBUG:
  80.          print("NameCharCount", NameCharCount, bs.tell())
  81.       DDSName = bs.readBytes(NameCharCount).decode("ASCII").rstrip("\0")
  82.       texIndex.append(DDSName)
  83.       TextureFormat = bs.readUShort()
  84.       TextureSize = bs.readUInt()
  85.       if MATDEBUG:
  86.          print("TextureSize", TextureSize)
  87.       Return = bs.tell()
  88.       bs.seek(12, NOESEEK_REL)
  89.       z = bs.tell()
  90.       sb.seek(z, NOESEEK_ABS)
  91.       DDSHeight = sb.readUInt()
  92.       DDSWidth = sb.readUInt()
  93.       bs.seek(72, NOESEEK_REL)
  94.       DDSFormat = bs.readBytes(4).decode("ASCII").rstrip("\0")
  95.       print(DDSFormat, bs.tell())
  96.       bs.seek(Return, NOESEEK_ABS)
  97.       bs.seek(128, NOESEEK_REL)
  98.       Content = (TextureSize - 128)
  99.       DDSContent2 = bs.readBytes(Content)
  100.       bs.seek(Return, NOESEEK_ABS)
  101.       DDSContent = bs.readBytes(TextureSize)
  102.       DDSFooter = bs.readUInt()
  103.       if DDSFormat == ("DXT5"):
  104.          DDSFormat2 = noesis.NOESISTEX_DXT5
  105.       if DDSFormat == ("DXT1"):
  106.          DDSFormat2 = noesis.NOESISTEX_DXT1
  107.       if DDSFormat == ("DXT3"):
  108.          DDSFormat2 = noesis.NOESISTEX_DXT3
  109.       texList.append(NoeTexture(DDSName, DDSWidth, DDSHeight, DDSContent2, DDSFormat2))
  110.       if DDSSpitOut == 1:
  111.          dds = NoeBitStream()
  112.          dds.writeBytes(DDSContent)
  113.          ExportDDSName = (noesis.getSelectedDirectory() + DDSName)
  114.          if MATDEBUG:
  115.             print("Writing", ExportDDSName)
  116.          o = open(ExportDDSName, 'wb')
  117.          o.write(dds.getBuffer())
  118.          o.close()
  119.       if MATDEBUG:
  120.          print("DDSEND", bs.tell())
  121.    print(DDSName)
  122.  
  123.    MaterialStart = (bs.tell())
  124.    print(MaterialStart)
  125.    ChunkID = bs.readUInt()
  126.    ChunkType = bs.readUInt()
  127.    ChunkSize = (bs.readUInt())
  128.    Blank = bs.readUInt()
  129.    ContentCount = bs.readUInt()
  130.    if SkipMaterials == 1:
  131.       bs.seek(ChunkSize - 20, NOESEEK_REL)
  132.    else:
  133.       matList = []
  134.       matNames = []
  135.       for M in range(0, ContentCount):
  136.          if MATDEBUG:
  137.             print("Reading MATS", bs.tell())
  138.          MaterialNameChar = bs.readUShort()
  139.          MaterialName = bs.readBytes(MaterialNameChar).decode("ASCII").rstrip("\0")
  140.          shit = bs.readUInt()
  141.          MaterialName = MaterialName.replace(':', '_')
  142.          Material = NoeMaterial(MaterialName, "")
  143.          MatType = bs.readUShort()
  144.          MatBS = bs.readUShort()
  145.          if MATDEBUG:
  146.             print("MATTYPE", MatType)
  147.          if MatType == int(0):
  148.             Diffuse = NoeVec4([0.0, 0.0, 0.0, 0.0])
  149.             Material.setDiffuseColor(Diffuse)
  150.             bs.seek(102, NOESEEK_REL)
  151.          if MatType == int(17):
  152.             AmbX = bs.readFloat()
  153.             AmbY = bs.readFloat()
  154.             AmbZ = bs.readFloat()
  155.             Amb = NoeVec4([AmbX, AmbY, AmbZ, 1.0])
  156.             blank = bs.readUInt()
  157.             RimC = NoeVec3.fromBytes(bs.readBytes(12))
  158.             Material.setRimLighting(RimC)
  159.             Spec = NoeVec4([0.0, 0.0, 0.0, 0.0,])
  160.             Material.setSpecularColor(Spec)
  161.             bs.seek(74, NOESEEK_REL)
  162.             CurrentCount = bs.readUShort()
  163.             CurrentTex = bs.readBytes(CurrentCount).decode("ASCII").rstrip("\0")
  164.             Material.setTexture(CurrentTex)
  165.             Material.setAmbientColor(Amb)
  166.             bs.seek(124, NOESEEK_REL)
  167.          if MatType == int(16):
  168.             bs.seek(102, NOESEEK_REL)
  169.             CurrentCount = bs.readUShort()
  170.             CurrentTex = bs.readBytes(CurrentCount).decode("ASCII").rstrip("\0")
  171.             Material.setTexture(CurrentTex)
  172.             bs.seek(76, NOESEEK_REL)
  173.          if MatType == int(145):
  174.             AmbX = bs.readFloat()
  175.             AmbY = bs.readFloat()
  176.             AmbZ = bs.readFloat()
  177.             Amb = NoeVec4([AmbX, AmbY, AmbZ, 1.0])
  178.             blank = bs.readUInt()
  179.             RimC = NoeVec3.fromBytes(bs.readBytes(12))
  180.             Material.setRimLighting(RimC)
  181.             Spec = NoeVec4([0.0, 0.0, 0.0, 0.0,])
  182.             Material.setSpecularColor(Spec)
  183.             bs.seek(50, NOESEEK_REL)
  184.             Four = bs.readUInt()
  185.             Byte = bs.readUByte()
  186.             print(Byte)
  187.             Count = bs.readUByte()
  188.             Two = bs.readUInt()
  189.             bs.seek(14, NOESEEK_REL)
  190.             for TC in range(0, 2):
  191.                CurrentCount = bs.readUShort()
  192.                CurrentTex = bs.readBytes(CurrentCount).decode("ASCII").rstrip("\0")
  193.                if TC == 0:
  194.                   Material.setTexture(CurrentTex)
  195.                if TC == 1:
  196.                   Material.setSpecularTexture(CurrentTex)
  197.                bs.seek(76, NOESEEK_REL)
  198.                if MATDEBUG:
  199.                   print("Tex ", TC, " Done", bs.tell())
  200.             bs.seek(48, NOESEEK_REL)
  201.             if MATDEBUG:
  202.                print("LoopDone", bs.tell())
  203.             Material.setAmbientColor(Amb)
  204.          matList.append(Material)
  205.          matNames.append(MaterialName)
  206.          Material = None
  207.  
  208. ##   MESHES
  209.    ChunkID = bs.readUInt()
  210.    ChunkType = bs.readUInt()
  211.    ChunkSize = bs.readUInt()
  212.    Blank = bs.readUInt()
  213.    MeshType = bs.readUInt()
  214. ##MeshTypes: 7 = Skinned Mesh; 3 = Static Mesh; 11 = Morphed Mesh; 30 = World Mesh
  215.    B = None
  216.    NameList = []
  217.    BoneMats = []
  218.    BoneName = []
  219.    if MeshType == 7:
  220.       BoneCount = bs.readUInt()
  221.       BoneList = []
  222.       BoneParents = []
  223.       for B in range(0, BoneCount):
  224.          boneMat44 = NoeMat44.fromBytes(bs.readBytes(64), NOE_BIGENDIAN)
  225.          boneMat43 = boneMat44.toMat43()
  226.          BoneMats.append(boneMat43.inverse())
  227. ##         BoneList.append(NoeBone(B, "bone_"+str(B), boneMat43, None, 0))
  228.       for BP in range(0, BoneCount):
  229.          BoneParents.append(bs.readUShort())
  230.       BBOXSHIT = bs.readBytes(40)
  231.    if MeshType == 11:
  232.       BBOXSHIT = bs.readBytes(40)
  233.       BoneList = []
  234.       BoneParents = []
  235.    if MeshType == 3:
  236.       Shit = bs.readBytes(40)
  237.    Other = []
  238.    Extra = []
  239.    BS2 = []
  240.    BSC = 0
  241.    BSP = []
  242.    NM = 0
  243.    BPP = [-1]
  244.    BB = -1
  245.    BSBoneList = []
  246.    RigMatrix = []
  247.    Mesh = 0
  248.    Bone = 0
  249.    MeshCount = 0
  250.    RootNodeChar = bs.readUShort()
  251.    RootNodeName = bs.readBytes(RootNodeChar).decode("ASCII").rstrip("\0")
  252.    RootHash = bs.readUInt()
  253.    POSX = bs.readFloat()
  254.    POSY = bs.readFloat()
  255.    POSZ = bs.readFloat()
  256.    ROTX = bs.readFloat()
  257.    ROTY = bs.readFloat()
  258.    ROTZ = bs.readFloat()
  259.    SCAX = bs.readFloat()
  260.    SCAY = bs.readFloat()
  261.    SCAZ = bs.readFloat()
  262.    Scale = bs.readFloat()
  263.    Matrix0 = NoeVec3((ROTX, ROTY, ROTZ))
  264.    Matrix1 = Matrix0.toAnglesDirect()
  265.    Matrix = Matrix1.toMat43()
  266.    Matrix.__setitem__(3,(POSX,POSY,POSZ))
  267.    BS2.append(NoeBone(BSC, RootNodeName, Matrix, None, -1))
  268.    Blank = bs.readUInt()
  269.    Byte = bs.readUByte()
  270.    Scale = bs.readFloat()
  271.    Test2 = bs.readUInt()
  272.    if Test2 > 0:
  273.       for T in range(0, (Test2)):
  274.          BSP.append(BSC)
  275.    SuperTest = int(0)
  276.    while (SuperTest != int(272)):
  277.       NM = (NM + 1)
  278.       NodeChar = bs.readUShort()
  279.       NodeName = bs.readBytes(NodeChar).decode("ASCII").rstrip("\0")
  280.       if MESHDEBUG:
  281.          print(NodeName)
  282.       NodeHash = bs.readUInt()
  283.       POSX = bs.readFloat()
  284.       POSY = bs.readFloat()
  285.       POSZ = bs.readFloat()
  286.       ROTX = bs.readFloat()
  287.       ROTY = bs.readFloat()
  288.       ROTZ = bs.readFloat()
  289.       SCAX = bs.readFloat()
  290.       SCAY = bs.readFloat()
  291.       SCAZ = bs.readFloat()
  292.       Scale = bs.readFloat()
  293.       Matrix0 = NoeVec3((ROTX,ROTY,-ROTZ))
  294.       Matrix1 = Matrix0.toAnglesDirect()
  295.       Matrix = Matrix1.toMat43()
  296.       Matrix.__setitem__(3,(POSX,POSY,POSZ))
  297.       if MeshType == 11 or BoneOverride:
  298.          if BoneOverride:
  299.             print("BONEOVERRIDE", NodeName)
  300.          Remember = BSP[-1]
  301.          BSP.pop(-1)
  302.          if NodeName == "root":
  303.             Remember = -1
  304.          BS2.append(NoeBone(NM, NodeName, Matrix, None, Remember))
  305.       
  306.       Test = bs.readUInt()
  307.       ModelType = 0
  308.       if MESHDEBUG:
  309.          print("Set Bone", BB, bs.tell())
  310.       if Test != int(0):
  311.          if MESHDEBUG:
  312.             print("A Mesh", NM)
  313.          Mesh = 1
  314.          Bone = 0
  315.          SubMeshCount = Test
  316.          if MeshType == 11:
  317.             if SubMeshCount > 1:
  318.                SubMeshCount = (SubMeshCount - 1)
  319.          MeshName = NodeName
  320. ##         print("SubMesh", SubMeshCount, bs.tell())
  321.          for SC in range(0, SubMeshCount):
  322.             print(bs.tell(), SC, SubMeshCount)
  323.             Four = bs.readUInt()
  324.  
  325.             if Four == 9:
  326.                if MESHDEBUG:
  327.                   print("Mesh ", BB, " Has Morphs")
  328.                MorphThing1 = bs.readUInt()
  329.                if MorphThing1 == 15:
  330.                   if MESHDEBUG:
  331.                      print("Morph Thing is 15")
  332.                   shit = bs.readBytes(60)
  333.                elif MorphThing1 == 6:
  334.                   shit = bs.readBytes(24)
  335.                MorphSetNameChar = bs.readUShort()
  336.                MorphSetName = bs.readBytes(MorphSetNameChar).decode("ASCII").rstrip("\0")
  337.                MorphSetID = bs.readUInt()
  338.                FourAgain = bs.readUInt()
  339.  
  340.             Thing = bs.readUShort()
  341.             ModelType = bs.readUShort()
  342.             if ModelType == 94:
  343.                if MESHDEBUG:
  344.                   print("Morph Enabled", SC)
  345.                Morph = 1
  346.             else:
  347.                Morph = 0
  348.             Stride = bs.readUInt()
  349.             if MESHDEBUG:
  350.                print("Stride", SC, Stride, bs.tell())
  351.             if Stride == int(18):
  352.                VertStride = 44
  353.                UVStride = None
  354.                NormOff = 12
  355.                IAmStatic = 0
  356.             if Stride == int(82):
  357.                if Morph == 1:
  358.                   VertStride = 28
  359.                   UVStride = None
  360.                   IAmStatic = 1
  361.                elif ModelType == 30:
  362.                   VertStride = 28
  363.                   UVStride = None
  364.                   IAmStatic = 1
  365.                else:
  366.                   VertStride = 48
  367.                   UVStride = None
  368.                   IAmStatic = 0
  369.             elif Stride == int(274):
  370.                if ModelType == 30:
  371.                   VertStride = 32
  372.                   UVStride = 24
  373.                   NormOff = 12
  374.                   IAmStatic = 1
  375.                else:
  376.                   VertStride = 52
  377.                   UVStride = 24
  378.                   NormOff = 12
  379.                   IAmStatic = 0
  380.             elif Stride == int(338):
  381.                if Morph == 1:
  382.                   VertStride = 36
  383.                   UVStride = 28
  384.                   IAmStatic = 1
  385.                else:
  386.                   VertStride = 56
  387.                   UVStride = 28
  388.                   IAmStatic = 0
  389.                UVType = noesis.RPGEODATA_FLOAT
  390.                NormOff = 12
  391.                if ModelType == 30 or ModelType == 1310:
  392.                   VertStride = 36
  393.                   UVStride = 28
  394.                   IAmStatic = 1
  395.             FaceBuffSize = (bs.readUInt() * 6)
  396.             FaceCount = (FaceBuffSize / 2)
  397.             FaceCount = int(FaceCount)
  398.             One = bs.readUShort()
  399.             if MESHDEBUG:
  400.                print("VertAT", bs.tell())
  401.             VertCount = bs.readUInt()
  402.             Blank = bs.readUInt()
  403.  
  404.             VPOS = []
  405.             VPOS2 = []
  406.             NORM = []
  407.             UV = []
  408.             Weights = []
  409.             Indexs = []
  410.             print(Stride, VertStride, VertCount)
  411.             for VS in range(0, VertCount):
  412.                VPOSX = bs.readFloat()
  413.                VPOSY = bs.readFloat()
  414.                VPOSZ = bs.readFloat()
  415.                VPOS.append(VPOSX)
  416.                VPOS.append(VPOSY)
  417.                VPOS.append(VPOSZ)
  418.                VPOS2.append((VPOSX, VPOSY, VPOSZ))
  419.                NormX = bs.readFloat()
  420.                NormY = bs.readFloat()
  421.                NormZ = bs.readFloat()
  422.                NORM.append(NormX)
  423.                NORM.append(NormY)
  424.                NORM.append(NormZ)
  425.                if (Stride == int(338)) or (Stride == int(82)):
  426.                   Negative1 = bs.readUInt()
  427.                if UVStride != None:
  428.                   U = bs.readFloat()
  429.                   V = bs.readFloat()
  430.                   UV.append(U)
  431.                   UV.append(V)
  432.                if UVStride == None:
  433.                   U = float(0.0)
  434.                   V = float(0.0)
  435.                   UV.append(U)
  436.                   UV.append(V)
  437.                if MeshType == 7:
  438.                   if IAmStatic == 0:
  439.                      Weight4 = bs.readFloat()
  440.                      Weight3 = bs.readFloat()
  441.                      Weight2 = bs.readFloat()
  442.                      Weight1 = bs.readFloat()
  443.                      Index1 = bs.readByte()
  444.                      Index2 = bs.readByte()
  445.                      Index3 = bs.readByte()
  446.                      Index4 = bs.readByte()
  447.                      Weights.append(Weight4)
  448.                      Weights.append(Weight3)
  449.                      Weights.append(Weight2)
  450.                      Weights.append(Weight1)
  451.                      Indexs.append(Index4)
  452.                      Indexs.append(Index3)
  453.                      Indexs.append(Index2)
  454.                      Indexs.append(Index1)
  455.             POSBUFF = struct.pack('>' + 'f'*len(VPOS), *VPOS)
  456.             UVBUFF = struct.pack('>' + 'f'*len(UV), *UV)
  457.             NORMBUFF = struct.pack('>' + 'f'*len(NORM), *NORM)
  458.             if MeshType == 7:
  459.                if ModelType != 30:
  460.                   WeightBuff = struct.pack('>' + 'f'*len(Weights), *Weights)
  461.                   IndexBuff = struct.pack('>' + 'b'*len(Indexs), *Indexs)
  462.             if Morph == 1:
  463.                if MESHDEBUG:
  464.                   print("Doing Morph Things", SC)
  465.                MorphThing1 = bs.readUInt()
  466.                MorphCount = bs.readUInt()
  467.                MPOS = []
  468.                MPOS2 = []
  469.                MFrame = []
  470.                for MBS in range(0, MorphCount):
  471.                   MorphThing2 = bs.readUInt()
  472.                   MorphVertCount = bs.readUInt()
  473.    ##               print(bs.tell())
  474.                   if MorphVertCount != VertCount:
  475.                      print("PANIC", MorphVertCount, VertCount, MBS)
  476.                   for MVS in range(0, MorphVertCount):
  477.                      X = VPOS2[MVS]
  478.                      XX = X[0]
  479.                      XXX = X[1]
  480.                      XXXX = X[2]
  481.                      MPOSX = (bs.readFloat() + XX)
  482.                      MPOSY = (bs.readFloat() + XXX)
  483.                      MPOSZ = (bs.readFloat() + XXXX)
  484.                      MPOS.append(MPOSX)
  485.                      MPOS.append(MPOSY)
  486.                      MPOS.append(MPOSZ)
  487.                   MORPHBUFF = struct.pack('>' + 'f'*len(MPOS), *MPOS)
  488.                   MFrame.append(MORPHBUFF)
  489.                   MPOS = []
  490.                   MBS = 0
  491.                   MVS = 0
  492.                   MVVS = 0
  493.             if MESHDEBUG:
  494.                print("VertDone", bs.tell())
  495.             FaceBuff = bs.readBytes(FaceBuffSize)
  496.             if MESHDEBUG:
  497.                print("FaceBuff Done", bs.tell())
  498.             MaterialChar = bs.readUShort()
  499.             CurrentMaterial = bs.readBytes(MaterialChar).decode("ASCII").rstrip("\0")
  500.             CurrentMaterial = CurrentMaterial.replace(':', '_')
  501.             if SubMeshCount > 1:
  502.                MeshName = (MeshName + "_sub_" + str(SC))
  503.             if EXPMorph == 1:
  504.                if Morph == 1:
  505.                   rapi.rpgBindPositionBuffer(POSBUFF, noesis.RPGEODATA_FLOAT, 12)
  506.                   rapi.rpgSetName(MeshName)
  507.                   rapi.rpgBindNormalBuffer(NORMBUFF, noesis.RPGEODATA_FLOAT, 12)
  508.                   rapi.rpgBindUV1Buffer(UVBUFF, noesis.RPGEODATA_FLOAT, 8)
  509.                   rapi.rpgSetMaterial(CurrentMaterial)
  510.                   rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount, noesis.RPGEO_TRIANGLE, 1)
  511.                   rapi.rpgClearBufferBinds()
  512.                   for Frame1 in range(0, MorphCount):
  513.                      rapi.rpgBindPositionBuffer(MFrame[Frame1], noesis.RPGEODATA_FLOAT, 12)
  514.                      rapi.rpgSetName(MeshName + "_Morph" + str(Frame1))
  515.                      rapi.rpgBindNormalBuffer(NORMBUFF, noesis.RPGEODATA_FLOAT, 12)
  516.                      rapi.rpgBindUV1Buffer(UVBUFF, noesis.RPGEODATA_FLOAT, 8)
  517.                      rapi.rpgSetMaterial(CurrentMaterial)
  518.                      rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount, noesis.RPGEO_TRIANGLE, 1)
  519.                      rapi.rpgClearBufferBinds()
  520.                else:
  521.                   rapi.rpgBindPositionBuffer(POSBUFF, noesis.RPGEODATA_FLOAT, 12)
  522.                   rapi.rpgBindNormalBuffer(NORMBUFF, noesis.RPGEODATA_FLOAT, 12)
  523.                   rapi.rpgBindUV1Buffer(UVBUFF, noesis.RPGEODATA_FLOAT, 8)
  524.                   rapi.rpgSetName(MeshName)
  525.                   rapi.rpgSetMaterial(CurrentMaterial)
  526.                   if MeshType == 7:
  527.                         if ModelType == 31:
  528.                            if Skin == 1:
  529.                               rapi.rpgBindBoneWeightBuffer(WeightBuff, noesis.RPGEODATA_FLOAT, 16, 4)
  530.                               rapi.rpgBindBoneIndexBuffer(IndexBuff, noesis.RPGEODATA_BYTE, 4, 4)
  531.                   rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, FaceCount, noesis.RPGEO_TRIANGLE, 1)
  532.                   if Optimize:
  533.                      rapi.rpgOptimize()
  534.                   rapi.rpgClearBufferBinds()
  535.                   MFrame = []
  536.                   MeshCount = (MeshCount + 1)
  537.             MaterialID = bs.readUInt()
  538.             BBOXSHIT = bs.readBytes(40)
  539.             MeshName = NodeName
  540.             NameList.append(MeshName)
  541.             print(SC, " Done ", bs.tell())
  542.       Byte = bs.readUByte()
  543.       if Byte == int(1):
  544.          if Mesh != 1:
  545.             Bone = 1
  546.             Mesh = 0
  547.             BB = (BB + 1)
  548.          Prop2 = bs.readUInt()
  549.          if MESHDEBUG:
  550.             print("Extra Params Start", bs.tell(), "0", "Count", Prop2)
  551.          for BSProp in range(0, Prop2):
  552.             Thing = bs.readUInt()
  553.             propchar = bs.readUShort()
  554.             propname = bs.readBytes(propchar).decode("ASCII").rstrip("\0")
  555.             prophash = bs.readUInt()
  556.             Type2 = bs.readUInt()
  557. ##            if prophash == int(1882726475) or int(1253562415):
  558. ##               Type2 = (Type2 - 1)
  559.             if Thing == int(4):
  560.                Type2 = (Type2 - 1)
  561.             PropData = bs.seek(Type2, NOESEEK_REL)
  562.             if MESHDEBUG:
  563.                print(BSProp, bs.tell())
  564.       if MESHDEBUG:
  565.          print("Extra Params End", bs.tell(), "1")
  566.       Float = bs.readFloat()
  567.       Test2 = bs.readUInt()
  568.       if Test2 != 0:
  569.          for T2 in range(0, Test2):
  570.             if ModelType == 30:
  571.                BSP.append(NM)
  572.             else:
  573.                BSP.append(NM)
  574.                if Bone:
  575.                   BPP.append(BB)
  576.       if Bone:
  577.          BoneName.append(NodeName)
  578.          RigMatrix.append(Matrix)
  579.       SuperTest = bs.readUShort()
  580.       if SuperTest != int(272):
  581.          bs.seek(-2, NOESEEK_REL)
  582.       if MESHDEBUG:
  583.          print("Complete", bs.tell())
  584.       Mesh = 0
  585.    mdl = rapi.rpgConstructModel()
  586.          
  587.    if MeshType == 7:
  588.       if not BoneOverride:
  589.          if MESHDEBUG:
  590.             print("Setting Bones")
  591.          MaxBoneList = max(BoneParents)
  592.          print("BoneParentListMax ", MaxBoneList)
  593.          print(len(BPP), BPP)
  594.          print(len(BoneName), BoneName)
  595.          print(BoneCount)
  596.          Diff = (MaxBoneList - BoneCount)
  597.          for BD in range(0, BoneCount):
  598.             CBP = BoneParents[BD]
  599.             print(BD, CBP)
  600.             CBP = (CBP - 1)
  601.             BoneList.append(NoeBone(BD, "bone_"+str(BD), BoneMats[BD], None, 0))
  602.          mdl.setBones(BoneList)
  603.    if MeshType == 11 or MeshType == 3 or BoneOverride:
  604.       if MESHDEBUG:
  605.          print("Setting Bones")
  606.       BS2 = rapi.multiplyBones(BS2)
  607.       mdl.setBones(BS2)
  608.    mdl.setModelMaterials(NoeModelMaterials(texList, matList))
  609.    if EmergencyNameDump:
  610.       print(NameList)
  611.    mdlList.append(mdl)         
  612.       
  613.    rapi.rpgClearBufferBinds()   
  614.    return 1
  615.