Example #1
0
    def CreateGeo(self):
        print(len(self.idxs))
        x = 0
        y = len(self.geos)  #8
        n = []  #[5,6,7]
        GEO_C = 0
        self.matList = []
        self.texList = []
        dirPath = rapi.getDirForFilePath(rapi.getInputName())
        for mat in self.mats:
            self.matList.append(mat.material)
            mat = mat.material
            diffuse = mat.texName
            normal = mat.nrmTexName
            specular = mat.specTexName
            for t in [diffuse, normal, specular]:
                try:
                    tex = open(dirPath + '/' + t, 'rb').read()
                    tex = rapi.loadTexByHandler(tex, '.dds')
                    tex.name = t
                    self.texList.append(tex)
                except:
                    raise

        for i in range(x, x + y):
            #for i in range(len(self.idxs)):
            idx = self.idxs[i]
            geo = self.geos[i]
            prop = geo.props
            print("%d: " % i, idx.name, " | ", geo.name)
            print(idx.numTri, idx.numIdx, geo.numVert)
            if not i in n:

                #material = self.matList[MaterialLink[idx.name]]
                rapi.rpgSetMaterial(MaterialLink[idx.name])
                rapi.rpgBindPositionBufferOfs(geo.vertBuffer,
                                              noesis.RPGEODATA_FLOAT,
                                              geo.vertLength, prop['position'])
                rapi.rpgBindUV1BufferOfs(geo.uvBuffer, noesis.RPGEODATA_FLOAT,
                                         geo.uvLength, prop['tex0'])
                rapi.rpgBindNormalBufferOfs(geo.vertBuffer,
                                            noesis.RPGEODATA_FLOAT,
                                            geo.vertLength, prop['normal'])
                rapi.rpgBindTangentBufferOfs(geo.vertBuffer,
                                             noesis.RPGEODATA_FLOAT,
                                             geo.vertLength, prop['tangent'])
                rapi.rpgCommitTriangles(idx.idxBuffer, noesis.RPGEODATA_USHORT,
                                        idx.numIdx, noesis.RPGEO_TRIANGLE, 1)
                #rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numTri,     noesis.RPGEO_TRIANGLE, 1)
            if GEO_C == 1:
                bs = NoeBitStream()
                fileG = open("geo-%d.p3ddump" % i, 'wb')
                bs.writeUInt(geo.numVert)
                bs.writeBytes(geo.vertBuffer)
                bs.writeUInt(idx.numTri)
                bs.writeBytes(idx.idxBuffer)
                fileG.write(bs.getBuffer())
                fileG.close()
    def CreateGeo(self):
        print(len(self.idxs))
        x=0
        y=len(self.geos)#8
        n = []#[5,6,7]
        GEO_C = 0
        self.matList    = []
        self.texList    = []
        dirPath         = rapi.getDirForFilePath(rapi.getInputName())
        for mat in self.mats:
            self.matList.append(mat.material)
            mat         = mat.material
            diffuse     = mat.texName
            normal      = mat.nrmTexName
            specular    = mat.specTexName
            for t in [diffuse,normal,specular]:
                try:
                    tex         = open(dirPath + '/' +t,'rb').read()
                    tex         = rapi.loadTexByHandler(tex,'.dds')
                    tex.name    = t
                    self.texList.append(tex)
                except:
                    raise
        
        for i in range(x,x+y):
        #for i in range(len(self.idxs)):
            idx  = self.idxs[i]
            geo  = self.geos[i]
            prop = geo.props
            print("%d: "%i,idx.name," | ",geo.name)
            print(idx.numTri,idx.numIdx,geo.numVert)
            if not i in n:

                #material = self.matList[MaterialLink[idx.name]]
                rapi.rpgSetMaterial(MaterialLink[idx.name])
                rapi.rpgBindPositionBufferOfs   (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['position'])
                rapi.rpgBindUV1BufferOfs        (geo.uvBuffer,     noesis.RPGEODATA_FLOAT,  geo.uvLength,   prop['tex0'])
                rapi.rpgBindNormalBufferOfs     (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['normal'])
                rapi.rpgBindTangentBufferOfs    (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['tangent'])
                rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numIdx,     noesis.RPGEO_TRIANGLE, 1)
                #rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numTri,     noesis.RPGEO_TRIANGLE, 1)
            if GEO_C == 1:
                bs = NoeBitStream()
                fileG = open("geo-%d.p3ddump"%i,'wb')
                bs.writeUInt(geo.numVert)
                bs.writeBytes(geo.vertBuffer)
                bs.writeUInt(idx.numTri)
                bs.writeBytes(idx.idxBuffer)
                fileG.write(bs.getBuffer())
                fileG.close()
    def __init__(self,data):
        fName=rapi.getInputName().split('\\')[-1][:-4]
        self.data       = NoeBitStream(data)
        self.magix      = noeStrFromBytes(self.data.readBytes(4))
        self.version    = self.data.readUShort()
        print("Version:",self.version)
        self.matList    = []
        if self.version != 120:
            self.padding    = self.data.readUShort()
            if self.padding >0: self.data.seek(self.padding,1)
        while  not self.data.checkEOF():
            current = self.data.tell()
            chunkID = self.data.readUShort()
            cSize   = self.data.readUInt()
            if chunkID   == 47066:
                self.skeleton = WZMSkeleton(self.data,self.version)
                if self.data.tell() != current + cSize:self.data.seek(current + cSize - self.data.tell(),1)
            elif chunkID == 47057:
                if self.version <=112:
                    print("Skeleton won't show up correctly")
                    mesh = WZMmesh112(self.data,self)
                elif self.version == 113 or self.version == 114:
                    mesh = WZMmesh112(self.data,self)
                elif self.version == 117:
                    mesh = WZMmesh117(self.data,self)
                elif self.version in [118,119]:
                    mesh = WZMmesh118(self.data,self)
                elif self.version == 120:
                    mesh = WZMmesh120(self.data,self)
                else:print("###\nUnknown mesh format\n###\nVersion: %d\n###"%self.version);self.data.seek(cSize - 6,1)
            elif chunkID == 47058:
                if cSize == 8:self.data.seek(2,1);maxWeight = 1
                else:
                    count = self.data.readUShort()
                    maxWeight = 0
                    extraWeight = []
                    for i in range(count):
                        extraWeight.append(WZMBoneWeight(self.data))
                        if extraWeight[-1].count > maxWeight:maxWeight = extraWeight[-1].count
            else:
                try:self.data.seek(cSize - 6,1)
                except:
                    print(self.data.tell(),cSize)
                    break
        for subMesh in mesh.subMesh:
            vertBuffer = b''
            for i in range(subMesh.numVert):
                vert = subMesh.vertBuff[i]
                vertBuffer += mesh.posBuffer[vert.vertID]
                vertBuffer += vert.normal
                vertBuffer += vert.tangent
                vertBuffer += vert.uv
            rapi.rpgBindPositionBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44, 0)
            if self.version == 112:
                rapi.rpgSetPosScaleBias((1,-1,1),(0,0,-5))
            rapi.rpgBindNormalBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44, 12)
            rapi.rpgBindTangentBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44, 24)
            rapi.rpgBindUV1BufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44, 36)

            wB = NoeBitStream()
            weightLength = maxWeight * 6
            for i in range(subMesh.numVert):
                vert = subMesh.vertBuff[i]
                if vert.boneID >= 0:
                    wB.writeUShort(vert.boneID)
                    for n in range(maxWeight - 1):
                        wB.writeUShort(0)
                    wB.writeFloat(1)
                    for n in range(maxWeight - 1):
                        wB.writeFloat(0)
                else:
                    ID  = abs(vert.boneID)-1
                    
                    weight = extraWeight[ID]
                    for bID in weight.boneID:
                        wB.writeUShort(bID)
                    for n in range(maxWeight - len(weight.boneID)):
                        wB.writeUShort(0)
                    for bW in weight.weight:
                        wB.writeFloat(bW)
                    for n in range(maxWeight - len(weight.weight)):
                        wB.writeFloat(0)
            weightBuffer = wB.getBuffer()
            rapi.rpgBindBoneIndexBufferOfs(weightBuffer, noesis.RPGEODATA_USHORT, weightLength, 0, maxWeight)
            rapi.rpgBindBoneWeightBufferOfs(weightBuffer, noesis.RPGEODATA_FLOAT, weightLength, maxWeight*2, maxWeight)
            material = NoeMaterial(subMesh.diffuse,subMesh.diffuse)
            material.setSpecularTexture(subMesh.specular)
            self.matList.append(material)
            rapi.rpgSetMaterial(subMesh.diffuse)
            rapi.rpgSetName(fName)
            rapi.rpgCommitTriangles(subMesh.idxBuffer,noesis.RPGEODATA_UINT, subMesh.numIdx*3, noesis.RPGEO_TRIANGLE, 1)
Example #4
0
    def __init__(self, data):
        fName = rapi.getInputName().split('\\')[-1][:-4]
        self.data = NoeBitStream(data)
        self.magix = noeStrFromBytes(self.data.readBytes(4))
        self.version = self.data.readUShort()
        print("Version:", self.version)
        self.matList = []
        if self.version != 120:
            self.padding = self.data.readUShort()
            if self.padding > 0: self.data.seek(self.padding, 1)
        while not self.data.checkEOF():
            current = self.data.tell()
            chunkID = self.data.readUShort()
            cSize = self.data.readUInt()
            if chunkID == 47066:
                self.skeleton = WZMSkeleton(self.data, self.version)
                if self.data.tell() != current + cSize:
                    self.data.seek(current + cSize - self.data.tell(), 1)
            elif chunkID == 47057:
                if self.version <= 112:
                    print("Skeleton won't show up correctly")
                    mesh = WZMmesh112(self.data, self)
                elif self.version == 113 or self.version == 114:
                    mesh = WZMmesh112(self.data, self)
                elif self.version == 117:
                    mesh = WZMmesh117(self.data, self)
                elif self.version in [118, 119]:
                    mesh = WZMmesh118(self.data, self)
                elif self.version == 120:
                    mesh = WZMmesh120(self.data, self)
                else:
                    print("###\nUnknown mesh format\n###\nVersion: %d\n###" %
                          self.version)
                    self.data.seek(cSize - 6, 1)
            elif chunkID == 47058:
                if cSize == 8:
                    self.data.seek(2, 1)
                    maxWeight = 1
                else:
                    count = self.data.readUShort()
                    maxWeight = 0
                    extraWeight = []
                    for i in range(count):
                        extraWeight.append(WZMBoneWeight(self.data))
                        if extraWeight[-1].count > maxWeight:
                            maxWeight = extraWeight[-1].count
            else:
                try:
                    self.data.seek(cSize - 6, 1)
                except:
                    print(self.data.tell(), cSize)
                    break
        for subMesh in mesh.subMesh:
            vertBuffer = b''
            for i in range(subMesh.numVert):
                vert = subMesh.vertBuff[i]
                vertBuffer += mesh.posBuffer[vert.vertID]
                vertBuffer += vert.normal
                vertBuffer += vert.tangent
                vertBuffer += vert.uv
            rapi.rpgBindPositionBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT,
                                          44, 0)
            if self.version == 112:
                rapi.rpgSetPosScaleBias((1, -1, 1), (0, 0, -5))
            rapi.rpgBindNormalBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44,
                                        12)
            rapi.rpgBindTangentBufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT,
                                         44, 24)
            rapi.rpgBindUV1BufferOfs(vertBuffer, noesis.RPGEODATA_FLOAT, 44,
                                     36)

            wB = NoeBitStream()
            weightLength = maxWeight * 6
            for i in range(subMesh.numVert):
                vert = subMesh.vertBuff[i]
                if vert.boneID >= 0:
                    wB.writeUShort(vert.boneID)
                    for n in range(maxWeight - 1):
                        wB.writeUShort(0)
                    wB.writeFloat(1)
                    for n in range(maxWeight - 1):
                        wB.writeFloat(0)
                else:
                    ID = abs(vert.boneID) - 1

                    weight = extraWeight[ID]
                    for bID in weight.boneID:
                        wB.writeUShort(bID)
                    for n in range(maxWeight - len(weight.boneID)):
                        wB.writeUShort(0)
                    for bW in weight.weight:
                        wB.writeFloat(bW)
                    for n in range(maxWeight - len(weight.weight)):
                        wB.writeFloat(0)
            weightBuffer = wB.getBuffer()
            rapi.rpgBindBoneIndexBufferOfs(weightBuffer,
                                           noesis.RPGEODATA_USHORT,
                                           weightLength, 0, maxWeight)
            rapi.rpgBindBoneWeightBufferOfs(weightBuffer,
                                            noesis.RPGEODATA_FLOAT,
                                            weightLength, maxWeight * 2,
                                            maxWeight)
            material = NoeMaterial(subMesh.diffuse, subMesh.diffuse)
            material.setSpecularTexture(subMesh.specular)
            self.matList.append(material)
            rapi.rpgSetMaterial(subMesh.diffuse)
            rapi.rpgSetName(fName)
            rapi.rpgCommitTriangles(subMesh.idxBuffer, noesis.RPGEODATA_UINT,
                                    subMesh.numIdx * 3, noesis.RPGEO_TRIANGLE,
                                    1)