Exemplo n.º 1
0
def noePadByteString(str, padLen):
	bstr = bytearray(str, "ASCII")
	if len(bstr) >= padLen: #check is >= under the expectation that the string should be 0-terminated
		noesis.doException("Provided string exceeds max length")
	exLen = padLen-len(bstr)
	bstr.extend(0 for i in range(0, exLen)) #pad out
	return bstr
Exemplo n.º 2
0
	def read(self, fmtStr):
		readBytes = struct.calcsize(fmtStr)
		if (self.byteOfs+readBytes) > self.dataSize:
			noesis.doException("Tried to read off end of data array.")
		readData = noeUnpackFrom(fmtStr, self.data, self.byteOfs)
		self.byteOfs += readBytes
		return readData
Exemplo n.º 3
0
	def read(self, fmtStr):
		readBytes = struct.calcsize(fmtStr)
		if (self.byteOfs+readBytes) > self.dataSize:
			noesis.doException("Tried to read off end of data array.")
		readData = noeUnpackFrom(fmtStr, self.data, self.byteOfs)
		self.byteOfs += readBytes
		return readData
Exemplo n.º 4
0
def noePadByteString(str, padLen):
	bstr = bytearray(str, "ASCII")
	if len(bstr) >= padLen: #check is >= under the expectation that the string should be 0-terminated
		noesis.doException("Provided string exceeds max length")
	exLen = padLen-len(bstr)
	bstr.extend(0 for i in range(0, exLen)) #pad out
	return bstr
Exemplo n.º 5
0
	def setTangents(self, tanList, slot = 0):
		noesis.validateListType(tanList, NoeMat43)
		if slot == 0:
			self.tangents = tanList
		elif slot == 1:
			self.lmTangents = tanList
		else:
			noesis.doException("Unsupported tangent slot")
Exemplo n.º 6
0
	def setUVs(self, uvList, slot = 0):
		noesis.validateListType(uvList, NoeVec3)
		if slot == 0:
			self.uvs = uvList
		elif slot == 1:
			self.lmUVs = uvList
		else:
			noesis.doException("Unsupported uv slot")
Exemplo n.º 7
0
	def setTangents(self, tanList, slot = 0):
		noesis.validateListType(tanList, NoeMat43)
		if slot == 0:
			self.tangents = tanList
		elif slot == 1:
			self.lmTangents = tanList
		else:
			noesis.doException("Unsupported tangent slot")
Exemplo n.º 8
0
	def setUVs(self, uvList, slot = 0):
		noesis.validateListType(uvList, NoeVec3)
		if slot == 0:
			self.uvs = uvList
		elif slot == 1:
			self.lmUVs = uvList
		else:
			noesis.doException("Unsupported uv slot")
Exemplo n.º 9
0
    def read_header(self):
        self.color_format = self.bs.readUByte()
        self.data_format = self.bs.readUByte()
        self.bs.seek(2, NOESEEK_REL)
        self.width = self.bs.readUShort()
        self.height = self.bs.readUShort()
        data = self.bs.getBuffer(self.bs.tell(), self.bs.getSize())
        self.bs = NoeBitStream(data)

        if (self.data_format == PvrTexture.TWIDDLED
                or self.data_format == PvrTexture.TWIDDLED_MM
                or self.data_format == PvrTexture.TWIDDLED_RECTANGLE
                or self.data_format == PvrTexture.TWIDDLED_MM_ALIAS):
            self.isTwiddled = True

        if (self.data_format == PvrTexture.TWIDDLED_MM
                or self.data_format == PvrTexture.PALETTIZE4_MM
                or self.data_format == PvrTexture.PALETTIZE8_MM
                or self.data_format == PvrTexture.ABGR_MM
                or self.data_format == PvrTexture.VQ_MM
                or self.data_format == PvrTexture.SMALLVQ_MM):
            self.isMipmap = True

        if (self.data_format == PvrTexture.SMALLVQ
                or self.data_format == PvrTexture.SMALLVQ_MM):
            self.codebook_size = self.get_codebook_size()
            self.isCompressed = True

        if (self.data_format == PvrTexture.VQ
                or self.data_format == PvrTexture.VQ_MM):
            self.isCompressed = True

        if (self.data_format == PvrTexture.PALETTIZE4
                or self.data_format == PvrTexture.PALETTIZE4_MM
                or self.data_format == PvrTexture.PALETTIZE8
                or self.data_format == PvrTexture.PALETTIZE8_MM
                or self.data_format == PvrTexture.STRIDE
                or self.data_format == PvrTexture.ABGR
                or self.data_format == PvrTexture.ABGR_MM):
            noesis.doException("Non supported pvr data format")

        self.mipWidth = self.width
        self.mipHeight = self.height
        if self.isCompressed:
            self.mipWidth = int(self.mipWidth / 2)
            self.mipHeight = int(self.mipHeight / 2)
        self.dst_array = [None] * (self.mipWidth * self.mipHeight)
        return 1
Exemplo n.º 10
0
	def setMatrix(self, matrix):
		if not isinstance(matrix, NoeMat43):
			noesis.doException("Invalid type provided for bone matrix")
		self._matrix = matrix
Exemplo n.º 11
0
	def setModelMaterials(self, modelMats):
		if modelMats is not None and not isinstance(modelMats, NoeModelMaterials):
			noesis.doException("Invalid type provided for model materials")
		self.modelMats = modelMats
Exemplo n.º 12
0
	def numWeights(self):
		n = len(self.indices)
		if n != len(self.weights):
			noesis.doException("Weight without matching index/value length")
		return n
Exemplo n.º 13
0
    def create_bitmap(self):
        tmp_bitmap = []
        if self.isCompressed:
            cb_len = PvrTexture.WORD_SIZE
            cb_len = cb_len * PvrTexture.CODE_COMPONENTS
            cb_len = cb_len * self.codebook_size
            data = self.bs.readBytes(cb_len)
            self.codebook = NoeBitStream(data)
            data = self.bs.getBuffer(self.bs.tell(), self.bs.getSize())
            self.bs = NoeBitStream(data)

        if self.isMipmap:
            seek_ofs = self.get_mipmap_size()
            self.bs.seek(seek_ofs, NOESEEK_REL)
            data = self.bs.getBuffer(self.bs.tell(), self.bs.getSize())
            self.bs = NoeBitStream(data)

        if self.isTwiddled and self.mipWidth == self.mipHeight:
            self.dst_array = self.detwiddle(self.mipWidth, self.mipHeight)

        elif self.isTwiddled and self.mipWidth > self.mipHeight:
            width = int(self.mipWidth / 2)
            height = self.mipHeight

            one = self.detwiddle(width, height)
            self.bs.seek(int(self.bs.getSize() / 2), NOESEEK_ABS)
            data = self.bs.getBuffer(self.bs.tell(), self.bs.getSize())
            self.bs = NoeBitStream(data)
            two = self.detwiddle(width, height)

            idx1 = 0
            idx2 = 0
            for i in range(len(self.dst_array)):
                x = i % self.mipWidth
                if x < width:
                    self.dst_array[i] = one[idx1]
                    idx1 = idx1 + 1
                else:
                    self.dst_array[i] = two[idx2]
                    idx2 = idx2 + 1

        elif self.isTwiddled and self.mipWidth < self.mipHeight:
            width = self.mipWidth
            height = int(self.mipHeight / 2)

            one = self.detwiddle(width, height)
            self.bs.seek(int(self.bs.getSize() / 2), NOESEEK_ABS)
            data = self.bs.getBuffer(self.bs.tell(), self.bs.getSize())
            self.bs = NoeBitStream(data)
            two = self.detwiddle(width, height)

            idx1 = 0
            idx2 = 0
            for i in range(len(self.dst_array)):
                if i < width * height:
                    self.dst_array[i] = one[idx1]
                    idx1 = idx1 + 1
                else:
                    self.dst_array[i] = two[idx2]
                    idx2 = idx2 + 1

        else:
            for i in range(self.mipWidth * self.mipHeight):
                if self.isCompressed:
                    self.dst_array[i] = self.bs.readUByte()
                else:
                    self.dst_array[i] = self.bs.readUShort()

        if self.isCompressed:
            x = 0
            y = 0
            tmp = [None] * (self.width * self.height)

            for i in range(len(self.dst_array)):
                idx = self.untwiddle(x, y)
                srcPos = self.dst_array[idx]
                srcPos = srcPos * PvrTexture.WORD_SIZE
                srcPos = srcPos * PvrTexture.CODE_COMPONENTS
                self.codebook.seek(srcPos, NOESEEK_ABS)

                for xOfs in range(2):
                    for yOfs in range(2):
                        idx = (y * 2 + yOfs) * self.width + (x * 2 + xOfs)
                        tmp[idx] = self.codebook.readUShort()

                x = x + 1
                if x >= self.mipWidth:
                    x = 0
                    y = y + 1
            self.dst_array = tmp

        for i in range(len(self.dst_array)):
            if self.color_format == 0:
                color = self.dst_array[i]
                bitmap = self.ARGB_1555(color)
                tmp_bitmap.extend(bitmap)
            elif self.color_format == 1:
                color = self.dst_array[i]
                bitmap = self.ARGB_565(color)
                tmp_bitmap.extend(bitmap)
            elif self.color_format == 2:
                color = self.dst_array[i]
                bitmap = self.ARGB_4444(color)
                tmp_bitmap.extend(bitmap)
            else:
                print("Color format: ", self.color_format)
                noesis.doException("Non supported pvr color format")
        return struct.pack('B' * len(tmp_bitmap), *tmp_bitmap)
Exemplo n.º 14
0
	def setMatrix(self, matrix):
		if not isinstance(matrix, NoeMat43):
			noesis.doException("Invalid type provided for bone matrix")
		self._matrix = matrix
Exemplo n.º 15
0
	def setModelMaterials(self, modelMats):
		if modelMats is not None and not isinstance(modelMats, NoeModelMaterials):
			noesis.doException("Invalid type provided for model materials")
		self.modelMats = modelMats
Exemplo n.º 16
0
	def numWeights(self):
		n = len(self.indices)
		if n != len(self.weights):
			noesis.doException("Weight without matching index/value length")
		return n