0
$\begingroup$

I'm sorry the title is vague, but I couldn't come up with a summary of my problem.

I am trying to convert a script made for a model viewing tool called Noesis to Blender. I'm stuck on some Noesis specific functions and need guidance.

Now this is the specific line that I am stuck on:

boneMat = NoeMat44.fromBytes(bs.readBytes(0x40)).toMat43()

I have already made a function for bs.readBytes(). I have printed out various values. From what I know, this function is making a vector 44 and converting it to a vector 43, I'll show some values that I have printed out from the original script.

These are the bytes that are from bs.readBytes(0x40):

b'\x00\x00\x80?
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?'

Somehow, they get converted to this vector:

((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0), (0.0, 0.0, 0.0))

I imagine this would be linked to bone matrices in Blender as that is what they are called in Noesis.

$\endgroup$
1
  • $\begingroup$ It is still vague after you finish the question description. How could we help you with any specified question? A guide to convert 4×3 to bledner 4×4 matrices? In general, you said you're converting Noesis to Blender to what?? Examining it or extract function or mock the process? $\endgroup$ – HikariTW Sep 28 '20 at 4:53
1
$\begingroup$

I'm not sure why your bytes code became split into lines. I think this is stackexchange, but if this is done by bs.readBytes(0x40) you need to concatenate all lines before you will be able to decode them into floats. Decoding can be done with built-in memoryview() method or with built-in struct module, like struct.unpack('f', bs.readBytes(0x40)). After that you can arrange floats into tuples. For example like this (consider bs.readBytes(0x40) doesn't split result into lines):

# readBytes_result = bs.readBytes(0x40)
def readBytes_to_vector(readBytes_result):
    bytes_to_floats = memoryview(readBytes_result).cast('f')
    counter = 0
    axis = []
    my_floats = []
    for fl in bytes_to_floats:
        axis.append(fl)
        counter+=1
        if counter == 4:
            counter=0
            my_floats.append(tuple(axis))
            axis = []
    return tuple(my_floats)

I prefer to use memoryview instead of struct because though it returns its own "memoryview object" instead of sequence of values (which is not always very handy) it is faster, especially when you need to handle large bytes arrays, like pixel data for example.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.