Important information: this site is currently scheduled to go offline indefinitely by end of the year.

Noesis tutorial Basic Model

Read or post any tutorial related to file format analysis for modding purposes.
User avatar
Seyren
advanced
Posts: 63
Joined: Sat Oct 30, 2010 1:39 pm
Has thanked: 18 times
Been thanked: 9 times

Re: Noesis tutorial Basic Model

Post by Seyren »

I know this may sound dumb but i got lost in the very first steps.

I just did this:

Code: Select all

#Noesis Python model import+export test module, imports/exports some data from/to a made-up format

from inc_noesis import *

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("S4 League", ".scn")
	noesis.setHandlerTypeCheck(handle, noepyCheckType)
	noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
	#noesis.setHandlerWriteModel(handle, noepyWriteModel)
	#noesis.setHandlerWriteAnim(handle, noepyWriteAnim)

	noesis.logPopup()
	print("The log can be useful for catching debug prints from preview loads.\nBut don't leave it on when you release your script, or it will probably annoy people.")
	return 1


#check if it's this type based on the data
def noepyCheckType(data):
	bs = NoeBitStream(data)
	if bs.readInt() != 0x01000000 :
		return 0
	return 1

#load the model
def noepyLoadModel(data, mdlList):
	ctx = rapi.rpgCreateContext()
	bs = NoeBitStream(data)
	rapi.rpgClearBufferBinds()
	hdrInfo = bs.read("i")
	print(hdrInfo)	
	return 1
Not a big deal, just trying to read an int and in the guide it said it was going to be written in the output log, but only this shows up:

Image

I think it has something to do with the header reading, but i don't know what to do.

I'm not sure if this is supposed to happen, since the images from the tutorial are missing and i'm not sure if i should continue or not.

I know this is one of those mistakes that will make you be ashamed for life, but i don't know what is wrong, i'm sorry :(

File i'm trying to read is attached in the post
You do not have the required permissions to view the files attached to this post.
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4284
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1146 times
Been thanked: 2242 times

Re: Noesis tutorial Basic Model

Post by shakotay2 »

use this line:
if bs.readInt() != 0x00000001 :

because the signature 01 00 00 00 in the header is little endian.
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
User avatar
Seyren
advanced
Posts: 63
Joined: Sat Oct 30, 2010 1:39 pm
Has thanked: 18 times
Been thanked: 9 times

Re: Noesis tutorial Basic Model

Post by Seyren »

Thank you for your help shakotay2, once again you got me out of this nooby issues :erm:

I got another question, how does the Vertex Buff actually works? Since in the guide they use the following:

Code: Select all

VertBuff = bs.readBytes(VCount[0] * 0x58)
   rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, 88, 0)
   rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, VCount[0], noesis.RPGEO_POINTS, 1)
   mdl = rapi.rpgConstructModel()
   mdlList.append(mdl)         #important, don't forget to put your loaded model in the mdlList
I don't really know what a vertex with a size of 88 bytes meant, so i started trying random numbers until one worked, which was 24.

Image
Using sword.scn
(Vertex count: 0x0986, after that there are 345 floats and the int that tells you the faces, which is positioned at 0x19B6, in this case are 282 faces)


the bad thing for this is that the number of the vertices, faces, uvs, etc are between the buffers, so the only way to be able to continue to get the number of faces is by using 0x04 instead of 0x18

So my question is, since the coordinates are made by floats,and since floats are 4 bytes, should i use 4 or should i use 24 and go back to the position of the faces count?, because if i do the last thing i said using FaceBuff = bs.readBytes(FCount[0] * 2) the following result appears:

Image

Thanks in advance again ^^
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4284
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1146 times
Been thanked: 2242 times

Re: Noesis tutorial Basic Model

Post by shakotay2 »

didn't get exactly what you mean.
use this for sword.scn (and only sword.scn):

Code: Select all

#Noesis Python model import+export test module, imports/exports some data from/to a made-up format

from inc_noesis import *

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("S4 League", ".scn")
   noesis.setHandlerTypeCheck(handle, noepyCheckType)
   noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
   #noesis.setHandlerWriteModel(handle, noepyWriteModel)
   #noesis.setHandlerWriteAnim(handle, noepyWriteAnim)

   noesis.logPopup()
   print("The log can be useful for catching debug prints from preview loads.\nBut don't leave it on when you release your script, or it will probably annoy people.")
   return 1


#check if it's this type based on the data
def noepyCheckType(data):
   bs = NoeBitStream(data)
   if bs.readInt() != 0x00000001 :
      return 0
   return 1


#load the model
def noepyLoadModel(data, mdlList):
   ctx = rapi.rpgCreateContext()
   bs = NoeBitStream(data)
   rapi.rpgClearBufferBinds()
   hdrInfo = bs.read("i")
   print(hdrInfo)   
   # works for sword.scn only!
   bs.seek(0x982, NOESEEK_ABS)  #Seek to counts
   facesCount = bs.read("i")	# faces count
   vertsCount = bs.read("i")
   VertBuff = bs.readBytes(vertsCount[0] * 12)
   facesCount2 = bs.read("i")	# faces count again
   print(facesCount2)
   if facesCount2!=facesCount:
      print("error: 2nd facesCount doesn't match!")
      return 1
   idxBuff = bs.readBytes(facesCount[0] *2 *3)
   rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, 12, 0)
   #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, facesCount[0], noesis.RPGEO_POINTS, 1)
   rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, facesCount[0]*3, noesis.RPGEO_TRIANGLE, 1)
   mdl = rapi.rpgConstructModel()
   mdlList.append(mdl)          #important, don't forget to put your loaded model in the mdlList

   return 1
it's just a quick hack - I'm not familiar with Noesis.

(Maybe it's a good idea to edit further questions into your previous post?
So not to spam chrrox' tutorial.)
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
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: 307 times

Re: Noesis tutorial Basic Model

Post by finale00 »

You should bump chrrox's tutorial as much as you can.
clang7775
ultra-n00b
Posts: 9
Joined: Sun Sep 28, 2014 7:31 pm

Re: Noesis tutorial Basic Model

Post by clang7775 »

Thanks for the tutorial! Time to dust off my python skills (and indenting!)
deltaone
beginner
Posts: 37
Joined: Sat Feb 19, 2011 1:18 am
Has thanked: 4 times
Been thanked: 13 times

Re: Noesis tutorial Basic Model

Post by deltaone »

anyone have images for this this tutorial ?

thx ...
MarieRose1301
veteran
Posts: 97
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 17 times
Been thanked: 7 times

Re: Noesis tutorial Basic Model

Post by MarieRose1301 »

Hello. i just began writing a script for a game and i think i got the wrong header because i get this error:
Image

http://sta.sh/21xrx3h6mxxn?edit=1 - these are the model and the script,anyone able to tell me what's wrong and how to fix it?
chrrox
Moderator
Posts: 2602
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1422 times

Re: Noesis tutorial Basic Model

Post by chrrox »

the string you are showing is not ascii and its not 16 bytes long.
try something like

NOEPY_HEADER = 0x334D430A

#check if it's this type based on the data
def noepyCheckType(data):
bs = NoeBitStream(data)
if len(data) < 4:
return 0
if bs.readUInt() != NOEPY_HEADER:
return 0
MarieRose1301
veteran
Posts: 97
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 17 times
Been thanked: 7 times

Re: Noesis tutorial Basic Model

Post by MarieRose1301 »

It gives me an other error this time Image
It's my first time writing a noesis plugin, so I'm a little bit lost here, sorry
chrrox
Moderator
Posts: 2602
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1422 times

Re: Noesis tutorial Basic Model

Post by chrrox »

Here is a start for you.
You do not have the required permissions to view the files attached to this post.
MarieRose1301
veteran
Posts: 97
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 17 times
Been thanked: 7 times

Re: Noesis tutorial Basic Model

Post by MarieRose1301 »

Thank you so much, i hope there won't be any more problems ^^'
Acewell
VIP member
VIP member
Posts: 1330
Joined: Wed Nov 05, 2008 12:16 pm
Has thanked: 2710 times
Been thanked: 884 times

Re: Noesis tutorial Basic Model

Post by Acewell »

finale00 wrote:There are several ways to go to different positions of a file (eg: seeking)

They are typically seeking from
-beginning of the file (absolute offset) eg: seek_abs
-current position (relative offset) eg: seek_curr
-end of file (seeking backwards)
So what is the correct syntax in Noesis for seeking to an offset from the end of a file?
i have been trying something like bs.seek(-44, 2) without success. :(
User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 4284
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 1146 times
Been thanked: 2242 times

Re: Noesis tutorial Basic Model

Post by shakotay2 »

"2" is ony valid when using import os, I guess - since there's
NOESEEK_ABS = 0 and NOESEEK_REL = 1 only.

I tried such (import os required)

Code: Select all

   fileName= 'G:\test.txt'

   statinfo = os.stat(fileName)
   print("statinfo, file size: ", statinfo.st_size)
   fsize= statinfo.st_size
   with open(fileName, "rb") as f:
       #f.seek(fsize-11, os.SEEK_SET)
       f.seek(-11, 2)
       a= f.read()
       print("a: ", a)
where test.txt is an ASCII file, opened in binary mode (to avoid weird outputs from print())
Both f.seek lines worked - if you use f.seek(-11, 2) you don't need to get the file size!

But I dunno how to get the filename via rapi, when the file is opened in the Noesis file explorer -

bs = NoeBitStream(data)
bs.seek(-11, 2) didn't work.
Tuts: a) Bigchillghost, viewtopic.php?f=29&t=17889
b) Extracting simple models: http://forum.xentax.com/viewtopic.php?f=29&t=10894
"Quoting the whole thing. Would u ever stop this nonsense?"
Acewell
VIP member
VIP member
Posts: 1330
Joined: Wed Nov 05, 2008 12:16 pm
Has thanked: 2710 times
Been thanked: 884 times

Re: Noesis tutorial Basic Model

Post by Acewell »

Okay thanks, i hoped there was something simple i was overlooking like NOESEEK_END i could use. i don't know enough about programming to make work what you have there. i will have to find another way :(

editx2
okay this works :D

Code: Select all

    bs.seek(len(data) - 0x2C, NOESEEK_ABS) #goto 44 bytes from end of file
Post Reply