Page 38 of 123

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 2:36 am
by MrAdults
I was just relating how games get model data into rendered triangles to how triangles are meant to be fed into the rpg interface in Noesis. The purpose of that interface is to provide a graphics API-like interface for feeding data, mainly because that's usually (but not always) the way data is already set up to be dealt with in game model formats. You don't have to actually worry about what Noesis does internally for previewing/converting data. But you can relate rpgCommitTriangles to a graphics API's draw call(s), and rpgSetMaterial is like binding the texture(s) before you "draw" the triangles.
finale00 wrote:Also, null-terminated strings.
I used to just read one char at a time, check if it's null, and then just add them to a string, but maybe there's a better way?

And is there a function that I can call that will parse a standard DDS file? Like maybe just take the one that's already used to load a DDS, but give me a texture object instead. Whatever I write to get a dds texture object probably isn't going to be as great lol
bs.readString will do that automatically for you in a non-unicode stream. Otherwise, if you don't have the string length or an offset table, checking for null characters 1 at a time is the right thing to do.

When you're creating NoeTexture objects, Noesis accepts DXT1/3/5 and some other image formats natively. So you can feed DXT-compressed data directly to it. As for loading DDS files entirely without even having to parse their headers, the best way to do that is through a function that won't be coming til the next version. (as chrrox has also requested it) It'll be called loadTexByHandler, and will allow you to load any image type that Noesis supports directly into a NoeTexture object. Hopefully I'll get around to working on the next release this week sometime, the todo list for it is getting pretty massive.

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 2:55 am
by finale00
Hmm can you see what's wrong with my string-making function. I get this exception

"TypeError: sequence item 1: expected str instance, bytes found"

Code: Select all

string = ""
char = self.inFile.read_char() #self.inFile = StructReader
while char != "\x00":
	string = ''.join([string, char])
	char = self.inFile.read_char()
return string
Where read_char is defined (in StructReader)

Code: Select all

def read_char(self, n=1):
        
	data = self.parser.read('c'*n) #self.parser = NoeBitStream(data)
	if n == 1:
		return data[0]
	return data
read_char returns a bytes type value, although I assumed it should be a string type since I'm using 'c'?

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 3:40 am
by MrAdults
read is always going to return a bytearray, as is the standard behavior for all such reads in Python. And you can't treat bytearrays as strings directly. readString will give you back an actual string, though.

It should also be noted that you're probably going to see significantly decreased performance here over using the NoeBitStream's readString, because the NoeBitStream is implemented in native binary, where things like loops are much faster.

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 4:16 am
by finale00
Hmm I'll have to re-think how I write the interface cause your methods would definitely be more efficient than whatever I write. Of course there is the possibility of just scrapping the interface entirely and just learn your API (lol), but I don't know I think writing "read('i')" everywhere seems kind of odd.

Anyways I'm turning another plugin I wrote before into noesis plugin and ran into an issue with assigning face material.
Here, the model defines one mesh with all the verts and indices, but the material is defined for each face.

So like

face 1 uses mat 0
face 2 uses mat 0
face 3 uses mat 1
face 4 uses mat 0
etc

I previous used metasequoia for all of my viewing needs, and it defines which face uses what material so there is no problem there, but how would I deal with this kind of format in noesis?

I thought maybe I'll split the mesh into smaller pieces cause another format did this, but then that would most likely be duplicating vertices and would be quite troublesome to make sure all the faces refer to the right ones...

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 4:45 am
by chrrox
you could jsut make a list equal to the face count of materials then as you loop through the faces have it assign the id.

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 5:09 am
by finale00
Oh, we can assign material to faces also. I thought it was just the whole mesh.
How do I assign to faces?

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 8:07 pm
by MrAdults
rpgSetMaterial before each CommitTriangles and/or immBegin/immEnd. Typically when something has per-triangle materials I'll draw 1 triangle at a time with immBegin/immEnd while making a rpgSetMaterial call for each triangle.

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 9:23 pm
by finale00
I'll try writing a plugin using the RPG interface. It actually looks easier than just creating meshes on my own since it seems more flexible.

Btw can you add support for the "xrange" function in a later release? I heard it was more efficient than the regular "range".

EDIT: Hmm something seems off again. I started making rapi function calls but whenever I try to iterate over an integer, it says

"RuntimeError: Type is not a list"

This occurs when I try to print a number (eg: numVerts) or when I try to do a loop (eg: range(numVerts))

Re: Señor Casaroja's Noesis

Posted: Tue Dec 13, 2011 11:14 pm
by MrAdults
xrange was deprecated in Python 3. Of course you can't iterate over an int, haha. If you want to loop n times, use range(0, n). Also, printing numbers (e.g. print(numVerts)) works just fine, as does printing lists, so something else is wrong with your syntax and/or logic. Noesis doesn't add or remove anything to/from the standard Python 3 implementation, all it does is provide extra libraries and interfaces.

Re: Señor Casaroja's Noesis

Posted: Wed Dec 14, 2011 12:55 am
by finale00
Actually, range(5) is the same as range(0, 5). And yes I just remembered that in 3.x range is now the 2.x version of xrange.

This plugin already worked before and I am just modifying one or two functions to use the RPG interface.
It doesn't work when I switch to rapi calls though.

Then again maybe I'm just calling the functions wrong.
Here are two methods that are causing the problems:

Code: Select all

def parse_vertices(self, meshName, numVerts):
      
      self.vertList = self.inFile.inFile.readBytes(numVerts * 48)
      rapi.rpgBindPositionBufferOfs(self.vertList, noesis.RPGEODATA_FLOAT, 48, 0)
      rapi.rpgBindNormalBuffer(self.vertList, noesis.RPGEODATA_FLOAT, 48, 28)
      rapi.rpgBindUV1Buffer(self.vertList, noesis.RPGEODATA_FLOAT, 48, 40)

def parse_faces(self, meshName, numFaces):
      
      self.faceList = self.inFile.inFile.readBytes(numFaces*2)
      rapi.rpgCommitTriangles(self.faceList, noesis.RPGEODATA_USHORT, numFaces, noesis.RPGEO_TRIANGLE, 1)
EDIT: oh, and I just noticed that I am still directly creating a mesh object. After commenting out the line I don't get the odd type issue anymore.

Re: Señor Casaroja's Noesis

Posted: Wed Dec 14, 2011 1:05 am
by MrAdults
Yes, I was trying to demonstrate to you that an int is not itself an iterable. You need to use range.

Presumably numFaces in your code is inappropriately named and actually reflects the number of indices, since otherwise numFaces*2 is wrong. Other than that, you are not using "Ofs" versions of the functions to bind your normal and UV buffers, which is going to give you the wrong buffer offsets for those components.

Re: Señor Casaroja's Noesis

Posted: Wed Dec 14, 2011 1:12 am
by finale00
Yes, numFaces is indeed the number of indices (poorly updated code copied from existing plugins)

I took out one of the methods that was explicitly creating a Mesh object and the problem disappeared.
The model also loaded correctly as a result.

It seems like I can't mix up using rapi with directly creating stuff.

Anyways with directly creating a mesh I could specify the position vectors as (vx, vy, vz) or (vx, vz, vy), or maybe (vx*-1, vy, vz) when I'm creating the lists.

How would I go about specifying the order that the xyz coords are given when using the RPGBindPositionBuffer?

Re: Señor Casaroja's Noesis

Posted: Wed Dec 14, 2011 1:19 am
by MrAdults
Sure you can. You just have to keep in mind that rpgConstructModel gives you an actual model object so you'd need to append your meshes to that same model if you want to combine methods. But combining methods would be rather silly and needlessly sloppy.

You need to use immediate mode drawing if you want to procedurally generate a model using Python native types. That mode is catered to formats where it's necessary to fuck about with the data and perform operations/conversions before giving it to Noesis. The buffered mode is meant to take raw byte arrays, usually directly read from the file. (which is why you can also set the endian mode for the RPG interface) You could also repack your data to flat bytes/bytearrays to bind it, but again that would be silly.

I would venture a guess that you don't need to be reading your data into float lists at all, and you can just use readBytes over your vertex buffers and bind the byte arrays directly. This is far more efficient in terms of both CPU usage and memory usage.

Edit: Oh, and in most cases where you'd want to screw around with your position order, it's appropriate to just apply a transform matrix instead. (rpgSetTransform)

Re: Señor Casaroja's Noesis

Posted: Wed Dec 14, 2011 7:49 pm
by pixellegolas
How hard is it to translate this information about dragon nest into noesis?

http://www.gpbeta.com/post/develop/drag ... converter/

I have promised chrrox to try to learn soon but I am struggling...alot :) What do you say about this source?

Re: Señor Casaroja's Noesis

Posted: Thu Dec 15, 2011 3:50 am
by MrAdults
pixellegolas wrote:How hard is it to translate this information about dragon nest into noesis?

http://www.gpbeta.com/post/develop/drag ... converter/

I have promised chrrox to try to learn soon but I am struggling...alot :) What do you say about this source?
Looks like a simple format, good for your first Noesis scripting experience!