Spotlight: Señor Casaroja's Noesis

General game file tools that are useful for more than one game
Privateer
veteran
Posts: 104
Joined: Fri Oct 21, 2011 1:33 pm
Location: On my Network, unless I'm somewhere else
Has thanked: 9 times
Been thanked: 30 times

Re: Señor Casaroja's Noesis

Post by Privateer »

My bad chrrox,
I stated that I need to change a signed int to a float 16
That is not the actual case.
I needed to change 4 bytes to a float 16 (Half Float)
Here's the Python code to do what I needed.

Code: Select all

import struct

def HalfToFloat(h):
    s = int((h >> 15) & 0x00000001)    # sign
    e = int((h >> 10) & 0x0000001f)    # exponent
    f = int(h & 0x000003ff)            # fraction

    if e == 0:
       if f == 0:
          return int(s << 31)
       else:
          while not (f & 0x00000400):
             f <<= 1
             e -= 1
          e += 1
          f &= ~0x00000400
          print s,e,f
    elif e == 31:
       if f == 0:
          return int((s << 31) | 0x7f800000)
       else:
          return int((s << 31) | 0x7f800000 | (f << 13))

    e = e + (127 -15)
    f = f << 13

    return int((s << 31) | (e << 23) | f)


if __name__ == "__main__":

    # sample (1.0) - see Wikipedia
    FP16='\x00\x3c'

    v = struct.unpack('H', FP16)
    x = HalfToFloat(v[0])

    # hack to coerce int to float
    str = struct.pack('I',x)
    f=struct.unpack('f', str)

    # print the floating point
    print f[0]
I also remembered that the texcoords are always inverted in GR2 files so adding the negate to the print f line will do that.
Note that We ONLY do that to the V not the U
So the code needs to account for that.
print - f[0]
This is done so We don't need to flip the texture upside down.
Last edited by Privateer on Sat Dec 24, 2011 8:03 pm, edited 1 time in total.
MrAdults
Moderator
Posts: 1007
Joined: Mon Mar 23, 2009 2:57 am
Has thanked: 44 times
Been thanked: 504 times

Re: Señor Casaroja's Noesis

Post by MrAdults »

Noesis has a function to encode a float in 2 bytes as a half-float, yeah. It's noesis.encodeFloat16. (or Math_EncodeFloat16 for native plugins) This encodes the float according to the IEEE 754 binary16 standard.

Noesis breaks everything down to raw triangle lists behind the scenes, regardless of how you feed the data in, or what type of index you feed into it. Satoh, in your case, you should use the immBegin/immEnd functions as mentioned previously. These allow you to loop through any kind of data feeding 1 triangle at a time (or more, if desired) to Noesis, where each triangle can have any given set of components. Noesis will then automatically batch the triangles into mesh buckets behind the scenes when the model is constructed, and you don't have to worry about breaking things up yourself at all.

Oh, and Noesis has support for 2 sets of UV's. The second set is typically used for lightmaps, but you can use it for whatever you want really.
Satoh
mega-veteran
mega-veteran
Posts: 195
Joined: Sat May 09, 2009 3:07 pm
Has thanked: 13 times
Been thanked: 37 times

Re: Señor Casaroja's Noesis

Post by Satoh »

I see, thank you, I'll try that.
Will that impact the performance of noesis at all though?
Privateer
veteran
Posts: 104
Joined: Fri Oct 21, 2011 1:33 pm
Location: On my Network, unless I'm somewhere else
Has thanked: 9 times
Been thanked: 30 times

Re: Señor Casaroja's Noesis

Post by Privateer »

MrAdults wrote:Noesis has a function to encode a float in 2 bytes as a half-float, yeah. It's noesis.encodeFloat16. (or Math_EncodeFloat16 for native plugins) This encodes the float according to the IEEE 754 binary16 standard.
So your saying I can decode the need info without the code I posted?
I can take x07 x7f and get the half-float?
I know you plan on better documentation ASAP and that's probably what I need.
In any case? Thanks for putting up with questions.
Give a man a fish and he'll eat for a day.
Try to teach a man to fish and he'll gripe at you for not just giving him the Damn Fish!
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 303 times

Re: Señor Casaroja's Noesis

Post by finale00 »

Ya, just pass the bytes to encodefloat16 and you should get the same output.
Maybe you can check that that is true.
Privateer
veteran
Posts: 104
Joined: Fri Oct 21, 2011 1:33 pm
Location: On my Network, unless I'm somewhere else
Has thanked: 9 times
Been thanked: 30 times

Re: Señor Casaroja's Noesis

Post by Privateer »

finale00 wrote:Ya, just pass the bytes to encodefloat16 and you should get the same output.
Maybe you can check that that is true.
Thanks for the responce.
I'll do that and respond.
Rolandonmilk
ultra-n00b
Posts: 6
Joined: Fri Jan 29, 2010 10:26 pm
Has thanked: 2 times

Re: Señor Casaroja's Noesis

Post by Rolandonmilk »

oh alright how do you get to view it in noesis or switch been finicing through data but nothing :(
MrAdults
Moderator
Posts: 1007
Joined: Mon Mar 23, 2009 2:57 am
Has thanked: 44 times
Been thanked: 504 times

Re: Señor Casaroja's Noesis

Post by MrAdults »

Satoh: No, performance shouldn't be impacted. The more logic you do in Python the longer your load times are going to be, naturally, but I wouldn't expect your load times should be getting upwards of 1 second unless you're looping through for hundreds of thousands of triangles.
Privateer wrote:So your saying I can decode the need info without the code I posted?
I can take x07 x7f and get the half-float?
I know you plan on better documentation ASAP and that's probably what I need.
In any case? Thanks for putting up with questions.
From what you said before, you wanted to encode a float into a half-float, but now it sounds like you want to decode a half-float from 2 bytes. You can do that as well, the function is noesis.getFloat16(yourint). (it expects an integer in the range of 0-65535)
Privateer
veteran
Posts: 104
Joined: Fri Oct 21, 2011 1:33 pm
Location: On my Network, unless I'm somewhere else
Has thanked: 9 times
Been thanked: 30 times

Re: Señor Casaroja's Noesis

Post by Privateer »

Thank You MrAdults,
That's what I was looking for and I admit I didn't understand the definition when I first looked at it.
I feel like an idiot but I learned a few things along the way.
:lol:
User avatar
UltimateSora
beginner
Posts: 25
Joined: Thu Jun 23, 2011 7:56 pm
Has thanked: 5 times

Re: Señor Casaroja's Noesis

Post by UltimateSora »

Hi, is there anyway to remove parts from a model before exporting it? When I use Data Viewer, I can highlight the individual sections. But there's no way to remove them, as far as I know. :(

Image

Thanks. :)
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 303 times

Re: Señor Casaroja's Noesis

Post by finale00 »

You can double-click on "skip render" and it should not be rendered.
I don't know whether exporting from preview will also skip those though (I would like to think it does, since there are two ways to export o.O)
chrrox
Moderator
Posts: 2602
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1397 times

Re: Señor Casaroja's Noesis

Post by chrrox »

why not just delete what you dont want in the program your loading it in?
User avatar
UltimateSora
beginner
Posts: 25
Joined: Thu Jun 23, 2011 7:56 pm
Has thanked: 5 times

Re: Señor Casaroja's Noesis

Post by UltimateSora »

finale00 wrote:You can double-click on "skip render" and it should not be rendered.
I don't know whether exporting from preview will also skip those though (I would like to think it does, since there are two ways to export o.O)
Sadly that method doesn't work. :(
chrrox wrote:why not just delete what you dont want in the program your loading it in?
Because it's time consuming and somewhat challenging. :(
chrrox
Moderator
Posts: 2602
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1397 times

Re: Señor Casaroja's Noesis

Post by chrrox »

what do you mean?
if they are separate mesh pieces in noesis they will be in your program also.
just click on the mesh and delete it done.
what program are you using?
Satoh
mega-veteran
mega-veteran
Posts: 195
Joined: Sat May 09, 2009 3:07 pm
Has thanked: 13 times
Been thanked: 37 times

Re: Señor Casaroja's Noesis

Post by Satoh »

chrrox wrote:what do you mean?
if they are separate mesh pieces in noesis they will be in your program also.
just click on the mesh and delete it done.
what program are you using?
I get the feeling, and I apologize if I'm wrong, that he doesn't know how to use a modeling program very well, or that the program he's using doesn't actually do modeling so much as pure animation or something similar.

In any case, @UltimateSora, you could try hiding the meshes you don't need, and exporting from preview. That may or may not export the hidden meshes. I've never tried it.
Post Reply