Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Noesis Python model import+export test module, imports/exports some data from/to a made-up format
- from inc_noesis import *
- from array import array
- import noesis
- #rapi methods should only be used during handler callbacks
- import rapi
- #registerNoesisTypes is called by Noesis to allow the script to register formats.
- #Do not implement this function in script files unless you want them to be dedicated format modules!
- def registerNoesisTypes():
- handle = noesis.register("RAGE PS3 Cell drawable", ".cdr")
- noesis.setHandlerTypeCheck(handle, psaCheckType)
- noesis.setHandlerLoadModel(handle, psaLoadModel) #see also noepyLoadModelRPG
- #noesis.setHandlerWriteModel(handle, noepyWriteModel)
- #noesis.setHandlerWriteAnim(handle, noepyWriteAnim)
- noesis.logPopup()
- return 1
- #check if it's this type based on the data
- def psaCheckType(data):
- bs = NoeBitStream(data)
- bs.setEndian(NOE_BIGENDIAN)
- IdMagic = bs.readInt()
- print("UdMagic: " + hex(IdMagic))
- if IdMagic != 0x4C5B8100:
- return 0
- return 1
- def removeCPUAddress(data):
- address = data-0x50000000
- return address
- def removeGPUAddress(data):
- address = (data-0x60000000)+0x3000
- return address
- #load the model
- def psaLoadModel(data, mdlList):
- f = open('index-data-decompressed.block', 'wb+')
- ctx = rapi.rpgCreateContext()
- bs = NoeBitStream(data)
- bs.setEndian(NOE_BIGENDIAN)
- rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
- rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
- fvfTableOffset = 0x1D10
- bs.seek(fvfTableOffset, NOESEEK_ABS)
- bs.seek(0x08, NOESEEK_REL)
- vertexCount = bs.readUShort()
- indexCount = bs.readUShort()
- print('Vertex Count: ' + str(vertexCount))
- print('Index Count: ' + str(indexCount))
- bs.seek(0x04, NOESEEK_REL)
- indexOffset = bs.readUInt()
- indexOffset = removeCPUAddress(indexOffset)
- print('Index Offset: ' + hex(indexOffset))
- indexSize = bs.readUShort()
- print('index Size: ' + hex(indexSize))
- unk01 = bs.readUShort()
- unkOffset = bs.readUInt()
- unkOffset = removeCPUAddress(unkOffset)
- print('Unknown Offset: ' + hex(unkOffset))
- unkown01Offset = bs.readUInt()
- unkSize = bs.readUShort()
- print('Unknown Size: ' + hex(unkSize))
- bs.seek(0xA, NOESEEK_REL)
- vertexDataOffset = bs.readUInt()
- vertexDataOffset = removeGPUAddress(vertexDataOffset)
- print('Vertex Offset: ' + hex(vertexDataOffset))
- vertexDataSize = bs.readUInt()
- print('Vertex Data Size: ' + hex(vertexDataSize))
- bs.seek(indexOffset, NOESEEK_ABS)
- edgeData = bs.readBytes(indexSize)
- edgeDecomp = rapi.decompressEdgeIndices(edgeData, indexCount)
- for i in range(0, indexCount): #decompressEdgeIndices returns indices in little-endian, so swap back to big because rpg is in bigendian mode
- t = edgeDecomp[i*2]
- edgeDecomp[i*2] = edgeDecomp[i*2 + 1]
- edgeDecomp[i*2 + 1] = t
- # Need to know where are vertex really located we have two options: VertexDataOffset and
- # VertexOffset according to the decompressed index there are 72x verts so vert count is 2D6=726 and
- # with (vert count * 16) in asteroid.cdr size should 0x2D60 that even corresponds to the length of
- # the vertexData block that we are getting on vertexDataOffset starting.
- f.write(edgeDecomp)
- bs.seek(vertexDataOffset, NOESEEK_ABS)
- #vertexSize = 0x10 * vertexCount
- print('Vertex Size: ' + hex(vertexDataSize))
- vertbuff = bs.readBytes(vertexDataSize)
- print('vertbuff Size: ' + hex(len(vertbuff)))
- rapi.rpgBindPositionBufferOfs(vertbuff, noesis.RPGEODATA_FLOAT, 0x10, 0)
- rapi.rpgSetName(str(i))
- #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, (vertexSize // 16), noesis.RPGEO_POINTS, 1)
- rapi.rpgCommitTriangles(edgeDecomp, noesis.RPGEODATA_USHORT,vertexCount, noesis.RPGEO_TRIANGLE, 1)
- mdl = rapi.rpgConstructModel()
- mdlList.append(mdl)
- f.close()
- rapi.rpgClearBufferBinds()
- return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement