Here's another version of my nif parsing code. It still fits in a single
file, so, code:
require 'xml/sax/x2j'
x2jclass 'nifxml'
extract=:4 :0
Name=: x
process fread y
)
NB. nif versioning:
vton=: 256 #. '.' 0&".;._1@, ]
Version=: vton '4.0.0.2' NB. Morrowind
'Items' x2jDefn NB. dispatch xml event handlers
/ := Result : Result=: ''
compound := defEnd y : x defStart y
basic := defEnd y : x defStart y
bitflags := defEnd y : x defStart y
enum := defEnd y : x defStart y
niobject := defEnd y : x defStart y
add := aEnd y : x aStart y
add := aChr y
option := aEnd y : x aStart y
option := aChr y
)
NB. --------- "low level" implementation --------
Interesting=: 0
ver1=: (>: vton)`1:@.(-:&_1@]) atr bind 'ver1'
ver2=: (<: vton)`1:@.(-:&_1@]) atr bind 'ver2'
NB. ------- "glue" ------------------------------
defStart=:4 :0 NB. event handlers for <compound>
if. Name -: atr 'name' do.
Interesting=: 1
end.
if. Interesting do.
Element=: y;<attributes x
Attributes=: i.0 1
end.
)
defEnd=:3 :0
if. Interesting do.
Result=: Result,Element,<Attributes
end.
Interesting=: 0
)
aStart=:4 :0 NB. event handlers for <add>
if. WasInteresting=: Interesting do.
if. Interesting=: (ver1 * ver2) Version do.
Attribute=: y;<attributes x
Comment=: ''
end.
end.
)
aEnd=:3 :0
if. Interesting do.
Attributes=: Attributes,<Attribute,<Comment
end.
Interesting=: WasInteresting
)
aChr=:3 :0
if. Interesting do.
Comment=: Comment,y
end.
)
This follows the basic pattern from before, but gives a boxed result. I
also recognize the full set of xml tags used in nif.xml so I should be able
to retrieve any definition using this code.
Here's a small sample result:
getdef'uint'
┌─────┬───────────────────────────┬─┐
│basic│┌────────────┬────────────┐│ │
│ ││name │uint ││ │
│ │├────────────┼────────────┤│ │
│ ││count │1 ││ │
│ │├────────────┼────────────┤│ │
│ ││niflibtype │unsigned int││ │
│ │├────────────┼────────────┤│ │
│ ││nifskopetype│uint ││ │
│ │└────────────┴────────────┘│ │
└─────┴───────────────────────────┴─┘
For 'uint', the definition has no internal structure, so the third box is
empty.
For larger definitions, the third box contains the internal structure. But
that gets too fat for an email message. So if you want to see it you will
have to try the code for yourself.
Also, I should mention why I picked Morrowind:
First, the game is an older game and many people should be able to pick it
up at low cost.
Second, Notch has said that this series of games was an inspiration for
Minecraft. The data structures are relatively orthogonal (though more
elaborate than those used in Minecraft).
Third, there's a good variety of freely available files designed to this
standard. And good examples are crucial to getting going with a new code
base. I'm planning on working with the set of furniture models at:
http://www.nexusmods.com/morrowind/mods/42513/
Note that you need a javascript enabled browser to download from that site.
Note that you might need to download 7-zip to unpack the files (from
http://www.7-zip.org).
To extract the files from a downloaded archive, use a command something
like:
7z x "Furniture - Orcish Lower Class-42513-1-0.rar"
To see the furniture models, you can download nifskope from
http://niftools.sourceforge.net/wiki/NifSkope
To see textures (colors) on the furniture models you will need to configure
nifskope so that it knows where to find the texture files. Use Render ->
Settings and then use Add Folder to add the folder named "Textures" which
was unpacked.
If all goes well (if I do not get sidetracked onto something else before I
run out of time), I will be approximating the functionality of nifskope in
J. If I do it right it will not be too painful to use, will not be an exact
match for the user interface (I am only supporting Morrowind, for example,
while nifskope supports many games) but will hopefully have some useful
features not found in NifSkope.
And, hopefully, you can pick up some useful coding techniques, if you are
interested in them.
And it would be kind of fun if I (or someone else - this is free work on my
part, and I might get side-tracked onto paying work before I finish) show
how to drive a 3d-printer more or less directly from the nif models.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm