Wavefront model parser in Python

Need some nice Mods? Here, you are right!
Post Reply
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Wavefront model parser in Python

Post by Gustavo6046 »

This is a Wavefront model parser in Python I'm still working on; the .obj parser is almost finished, all that remains is UV coordinates.
ObjModelParser.zip
The file with the source code in Python and the console app's binary file included.
(4.72 MiB) Downloaded 106 times
The animation will be done with only a folder "commandLineOption1" and the files "commandLineOption2_FrameNumber" (e.g. "Lorrobasanti_00001", "Lorrobasanti_00002" files inside "LorrobasantiAnim" folder, etc.), since the animations in a Unreal model are simply ranges that determine the frames that will be the animation. Yes, animations doesn't contain frames -- a model does. It contains these frames and THEN assign them to animations.

This way, we won't need to autogenerate a .uc file. This program is not to be used by noobs that want to create annoying crap, for example some guys that made a Monster Hunt level and put a lot of BlockAll's, dickies, BSP errors and such. (Monster Hunt is the gametype where the most mappers are actually crappers!) Without a template we discourage people that don't make something decent or even understandable. We avoid crap. We assure quality of output. (I'm sure sektor will agree, he is "at war with noobs" :P )

The parser I made outputs one AnimationFrame object per file, which itself contains a list of Polygons, which are a list of Vertice objects (just X, Y and Z coordinates plus a bunch of functions) and in the future a list of texture vertexes/coordinates as well).

However, I have one little question, are normal vertexes used in Unreal models? By "normal" I don't mean the standard (geometry) vertex, but THE normal or something like that... Understand me?

Oh... last note: this was built with Blender-exported Wavefront models in mind. If you use some other modeller, then don't ask for support "my obj model is not working in your parser and it not being parsed coz i didn't use blender"!
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Wavefront model parser in Python

Post by sektor2111 »

Gustavo6046 wrote: (I'm sure sektor will agree, he is "at war with noobs" :P )
I'm not in war with anybody, admins are getting mad even if they don't speak. No one is agree to ruin a server which cost money after all for player deception. So... drew your conclusions.
Else, Python is not in my Inventory this time, perhaps another guy might be interested. But thanks for clarification toward MH, yes even if you might be considered too young by them, at least you could figure what dumb stuff they do - wasting time in Editor.
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Wavefront model parser in Python

Post by Higor »

Wonder if it's possible to hack in a .OBJ mesh importer into Unreal Editor.
Sure, using a derivate of UFactory is doable but i'd love to have a button...

Let's say... create a vertex buffer, scale up/down and round to fit into the 2048x2048x1024 size defined by the UMesh format (32 bit packed vector [11b,11b,10b]), set an appropiate transformation vector so that despite scaling the model looks the same.
Since .OBJ aren't animated we wouldn't be needing a more complex ULodMesh class, only UMesh I guess.
Maybe VTable hooking the UEditorEngine class to implement EditObject command so it's possible to edit a mesh's default textures as well.
Also... what about triangle splitting? UMesh doesn't support outside-of-boundary UV coordinates so they won't wrap around, maybe adding an option to split faces to keep textures properly aligned could be of use?

So many things that could be done.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

Higor wrote:Since .OBJ aren't animated we wouldn't be needing a more complex ULodMesh class, only UMesh I guess.
Or the parser could read each frame (.OBJ file) in the folder and output a file with all the vertexes and animations; one binary or ASCII file readable to Unreal Editor with a hacked-in button. Simple :)

I'd rather do it in ASCII due to the simplicity (just open, write and close the file in Python), though binary is more compact. (how do you write hex/binary files with Python?)
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Wavefront model parser in Python

Post by Higor »

Never tried Python lol, are you using Blender? AFAIK Blender uses lots of Python based extensions and plugins, and given those scripts already parse models and stuff, they'd be the ideal guides.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

Higor wrote:Never tried Python lol, are you using Blender? AFAIK Blender uses lots of Python based extensions and plugins, and given those scripts already parse models and stuff, they'd be the ideal guides.
Try it, it's a slow, but compact AND simple language! You can do lots of cool stuff in it. Now try packaging it into a single .exe.

Also I added conversion to .amf (Animated Mesh File) file format to my converter -- and you can do your own exporter! :D

Will upload as soon as the assembling (PyInstaller) is done.

EDIT: NooooOOOO! PyInstaller does not support importing Python files in the same folder via importlib.import_module!

EDIT2: You will, from now on, require (unfortunately) a Python interpreter! :( But at least it works :)
ObjModelParser.zip
The source code (use interpreter), without binary files :(
(5.51 MiB) Downloaded 98 times
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

Bump, since a day has passed.

I'm planning to collaborate with a certain person in doing a .3d exporter for this! :D Isn't it awesome? This means anyone will be able to do animated .3d files in Unreal! From anything that exports Wavefront models! :D :D :D
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

'nother day, 'nother bump. (wow, people isn't interested in modelling as much as me :( )

Aniv file exporter is almost ready, but it fails to export in binary format (and I'm not sure it would work even then; I didn't use C types).

Quote from UnrealSP:
That's why I did a exporter decorator.

All you have to do is the following for a example exporter:

Code: Select all

from exportercommons import model_output


def export(frames):
    # function that returns the string that should be written to the file.

def register_exporter():
    return model_output(export, True) # or False in case of non-binary
Where "frames" is a list of frames (duh) and the classes for it are:

Code: Select all

AnimFrame -> contains variables "polygons" (list of Polygon's) and "frame_index" (thanks Captain Obvious! :D).

Polygon    -> contains variables "texture_coordinates" (a size-two list of texture coordinates, first part is U and second part is V; floats that are NOT converted from the numbers stored in the "vt" part of the .obj file) and "vertices" (tuple of Vertex'es of any size) and the int "index" (normally the index of the polygon in the frame).

Vertex      -> contains variables "x", "y" and "z", along with many vectorial functions.
It doesn't support multiple files, but there must be a workaround!

EDIT: I found a workaround:

Two exporters instead of one! One for anivfile and other for data file. :)

EDIT 2: I finished the aniv-file exporter:

Code: Select all

from exportercommons import model_output
from sys import getsizeof


def export(frames):
    number_of_vertices = 0

    measureframe = frames[0]

    for polygon in measureframe.polygons:
        for vertex in polygon.vertices:
            number_of_vertices += 1

    export_string = "{}{}".format(len(frames), number_of_vertices * getsizeof(number_of_vertices))
    frame_number = 0

    for frame in frames:
        for poly in frame.polygons:
            for vertex in poly.vertices:
                export_string += str(
                    (vertex.x * 8.0) & 0x7ff | ((vertex.y * 8.0) & 0x7ff) << 11 | ((vertex.z * 4.0) & 0x3ff) << 22)

        frame_number += 1

    return export_string


def register_exporter():
    return model_output(export, True)

I am not sure as for the datafile one :/
EDIT 3: Noooo! I'm not writing the aniv file correctly!
EDIT: I modified the source code of the own exporter for the case of binary files..
bigbird_a.zip
An aniv file.
(143.28 KiB) Downloaded 92 times
Is this a correct aniv file?
Last edited by Gustavo6046 on Thu Apr 21, 2016 3:33 pm, edited 1 time in total.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Wavefront model parser in Python

Post by sektor2111 »

Wanna real home-work toward modelling ?
All right - export out all craps from UT and/or "custom" lousy things and add animation "Fighter" where it's missing + the rest of 0 animations called in classes. Then post mesh and code for importing into U packages.
I'm interested to solve more animations missing... I'm waiting.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

sektor2111 wrote:Wanna real home-work toward modelling ?
All right - export out all craps from UT and/or "custom" lousy things and add animation "Fighter" where it's missing + the rest of 0 animations called in classes. Then post mesh and code for importing into U packages.
I'm interested to solve more animations missing... I'm waiting.
Doing the exporter is already enough home-work, plus school's real homework and the school time (except the late two days I were sick and today... today and tomorrow are holidays)... I'm not interested in "Missing animations" if they DO work in UT. I just want to do my own models.

And to anyone else -- is the aniv file I posted earlier with the edit a correct one?
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Wavefront model parser in Python

Post by sektor2111 »

Gustavo6046 wrote:I'm not interested in "Missing animations" if they DO work in UT
They doesn't work because ARE MISSING - So nobody figured them EVER. I'm sorry if I have been disturbing your coding spree.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

sektor2111 wrote:They doesn't work because ARE MISSING - So nobody figured them EVER. I'm sorry if I have been disturbing your coding spree.
What I mean is that I don't bother with them since UT works WITHOUT them.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Wavefront model parser in Python

Post by sektor2111 »

Fighter was crashing randomly for your personal knowledge - and NO, they doesn't work causing even troubles, getting over excuses based on your 0 (ZERO) Experience with servers. Of course, I don't see that guy - because I'm not looking in that direction :loool: .
Cya ! I'm not the guy accepting SHIT messages in console while my games are running. If you speak about modelling I was hoping that you might help. The rest looks as a myth since I don't see anything valid yet. I apology for disturbance.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Wavefront model parser in Python

Post by Gustavo6046 »

sektor2111 wrote:Cya ! I'm not the guy accepting SHIT messages in console while my games are running. If you speak about modelling I was hoping that you might help. The rest looks as a myth since I don't see anything valid yet. I apology for disturbance.
Goodbye :noidea

I think this project is being too hard to write data files. It'd be better to port it to a Blender plugin before continue work in it as a separate converter.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Post Reply