Dice3DS is a set of Python modules for dealing with 3D Studio format files. I have released it under the terms of a BSD-style license.
3D Studio is a 3D graphics modeling and rendering program that saved it images in a rather simple binary file format known as 3DS format. Although 3D Studio has not released the details of the 3DS format, it has been reverse engineered by some ambitious people, and I used the information to write Dice3DS, a Python package that slices and dices 3DS files.
Dice3DS requires Python 2.6, and numpy 1.1.0. (Earlier versions of Python, going back to 2.2, might still work but are no longer officially supported.) The view3ds script additionally requires any or all of PIL, PyOpenGL 3, PyGame, and Pyglet. PIL and PyOpenGL is enough for most cases.
Examples
Here is an example of creating a 3DS file from scratch, and writing it to output. In the snippet, pointarray is a n-by-3 numpy array listing vertex coordinates, and facearray is an m-by-3 listing of point indices making up a face.
from Dice3DS import dom3ds
import numpy
def output_model(facearray,pointarray,filename):
n = len(pointarray)
m = len(facearray)
# First, add a fourth column to facearray for the face flags.
# Dice3DS pretty much ignores these flags, but they're required by
# the 3DS format.
padfacearray = numpy.zeros((n,4),numpy.uint32)
padfacearray[:,:3] = facearray
padfacearray[:,3] = 7
# Create a smoothing group array. When the whole model is to be
# smooth, it is appropriate to set the array to all ones.
smoothing = numpy.ones(m,numpy.uint32)
# Create an N_TRI_OBJECT, which is basically a big list of
# triangles. This object lists the vertices, faces, smoothing
# groups, and the transformation matrix, which is set to identity.
#
# Note that you can initialize a 3DS chunk in one of two ways: by
# passing keyword arguments to its constructor, or assigning
# attributes.
obj = dom3ds.N_TRI_OBJECT()
obj.points = dom3ds.POINT_ARRAY(npoints=n,array=pointarray)
obj.faces = dom3ds.FACE_ARRAY(nfaces=m,array=padfacearray)
obj.faces.smoothing = dom3ds.SMOOTH_GROUP(array=smoothing)
obj.matrix = dom3ds.MESH_MATRIX(array=numpy.identity(4,numpy.float32))
# Create a named object. Give it the name OBJECT, and set its
# object to the N_TRI_OBJECT created above.
nobj = dom3ds.NAMED_OBJECT(name="OBJECT",obj=obj)
# Now, create the stuff that appears in every (or almost every)
# 3DS file.
dom = dom3ds.M3DMAGIC()
dom.version = dom3ds.M3D_VERSION(number=3)
dom.mdata = dom3ds.MDATA()
dom.mdata.scale = dom3ds.MASTER_SCALE(value=1.0)
dom.mdata.objects = [ nobj ]
# Output the 3DS file
dom3ds.write_3ds_file(filename,dom)
Scripts
Dice3DS provides is two scripts, dump3ds and view3ds:
dump3ds dumps the a 3DS file to output in human-readable form.
view3ds is a simple 3DS model viewer.
Downloads
Dice3DS is licensed under a BSD-style license.
Version 0.13 is the most recent version, released 5 October 2010.
I originally was going to call it Utility3DS or Util3DS. (Lib3DS was taken, and Py3DS is just lame, as all Py* names are). However, Utility is a boring and aesthetically unpleasing name, and didn’t sound right. (I couldn’t call it 3DSUtil because it needed to be a legal Python symbol.
So, I decided to name it Dice3DS in honor the famous cliche “It slices, it dices!” Definitely cooler and more euphonic than Util3DS.
The IOCCC Flight Simulator was the winning entry in the 1998 International Obfuscated C Code Contest. It is a flight simulator in under 2 kilobytes of code, complete with relatively accurate 6-degree-of-freedom dynamics, loadable wireframe scenery, and a small instrument panel.
IOCCC Flight Simulator runs on Unix-like systems with X Windows. As per contest rules, it is in the public domain.
Documentation
Introduction
You have just stepped out of the real world and into the virtual. You are now sitting in the cockpit of a Piper Cherokee airplane, heading north, flying 1000 feet above ground level.
Use the keyboard to fly the airplane. The arrow keys represent the control stick. Press the Up Arrow key to push the stick forward. Press the left arrow key to move the stick left, and so on. Press Enter to re-center the stick. Use Page Up and Page Down increase and decrease the throttle, respectively. (The rudder is automatically coordinated with the turn rate, so rudder pedals are not represented.)
On your display, you will see on the bottom left corner three instruments. The first is the airspeed indicator; it tells you how fast you’re going in knots. The second is the heading indicator, or compass. 0 is north, 90 is east, 180 is south, 270 is west. The third instrument is the altimeter, which measures your height above ground level in feet.
Usage
To use, type:
cat horizon.sc pittsburgh.sc | ./banks
banks is the name of the program (a quirk of IOCCC rules, and no pun intended). horizon.sc and pittsburgh.sc are scenery files.
Features
Simulator models a Piper Cherokee, which is a light, single-engine, propeller-driven airplane.
The airplane is modeled as a six degree-of-freedom rigid body, accurately reflecting its dynamics (for normal flight conditions, at least).
Fly through a virtual 3-D world, while sitting at your X console.
Loadable scenery files.
Head-up display contains three instruments: a true airspeed indicator, a heading indicator (compass), and an altimeter.
Flight controls may be mapped to any keys at compile time by redefining the macros in the build file. Nice if your keyboard doesn’t have arrow keys.
Time step size can be set at compile time. This is useful to reduce flicker on network X connections. (But be careful: step sizes longer than about 0.03 seconds tend to have numerical stability problems.)
Airplane never stalls!
Airplane never runs out of fuel!
Scenery
Each of the *.sc files is a scenery file. The simulator program reads in the scenery from standard input on startup. You may input more than one scenery file, as long as there are less than 1000 total lines of input.
Here is a brief description of the scenery files:
horizon.sc – A horizon, nothing more. You will probably always want to input this piece of scenery.
mountains.sc – An alternate horizon; a little more mountainous.
pittsburgh.sc – Scenery of downtown Pittsburgh. The downtown area is initially located to your right.
bb.sc – Simple obstacle course. Try to fly over the buildings and under the bridges.
pyramids.sc – Fly over the tombs of the ancient Pharaohs in this (fictitious) Egyptian landscape.
You can simulate flying through a cloud bank as well:
./banks < /dev/null
You will usually want at least a horizon, though.
The format of scenery files is simple, by the way. They’re just a list of 3-D coordinates, and the simulator simply draws line segments from point to point as listed in the scenery file. 0 0 0 is used to end a series of consecutive line segments. Note that in the coordinate system used, the third coordinate represents altitude in a negative sense: negative numbers are positive altitudes.
I’m sure you’ll be making your own scenery files very soon!!!
Alternate Build Instructions
Several options must be passed to the compiler to make the build work. The provided build file has the appropriate options set to default values. Use this section if you want to compile with different options.
To map a key to a control, you must pass an option to the compiler in the format “-Dcontrol=key”. The possible controls you can map are described in the table below:
Control Description Default Key
------- --------------------- -----------
IT Open throttle XK_Page_Up
DT Close throttle XK_Page_Down
FD Move stick forward XK_Up
BK Move stick back XK_Down
LT Move stick left XK_Left
RT Move stick right XK_Right
CS Center stick XK_Enter
Values for the possible keys can be found in the X Windows header file <X11/keysym.h>. This file is most likely a cross-reference to another header, <X11/keysymdef.h>.
You must map all seven controls to keys at compile time, or the compilation will fail.
For example, to map Center Stick to the space-bar, the compile option would be “-DCS=XK_space”.
To set the time step size, you must pass the following option to the compiler: “-Ddt=duration”, where dt is literal, and where duration is the time in seconds you want the time step to be.
Two things to keep in mind when selecting a time step. Time steps that are too large (more than about 0.03) will cause numerical stability problems and should be avoided. Setting the time step to be smaller than your clock resolution will slow down the simulator, because the system pauses for more time than the simulator expects.
The best advice is to set time step size to your system timer resolution. Try a
longer period if you’re getting too much flicker.
Screen Shots
Here we are flying towards Downtown Pittsburgh. We can see the Point, several buildings including the USX tower, and several bridges including the Smithfield Street bridge. We see three instruments near the bottom.
About the IOCCC Entry
IOCCC stands for “International Obfuscated C Code Contest.” It is an quasi-annual contest to see who can write the most unreadable, unintelligible, unmanagable, but legal C program.
In the 1998 IOCCC, My flight simulator won the “Best of Show” prize. Here is the source code to the program:
One of the rules of the contest was that the program could not be longer than 1536 bytes (excluding spaces, tabs, newlines, semicolons, and braces). Needless to say, cramming a flight simulator into such a small file was fairly difficult. I will say that if it weren’t for the wonderful property of orthogonal matrices, this flight simulator would not have been possible.
Sightings
The IOCCC Simulator appeared in a book, Calculated Bets by Steve Skiena.
Wikipedia has a listing of IOCCC Simluator in its IOCCC Entry.
IOCCC Flight Simulator’s Facebook page. (I made this page because random people around the world would send me friend requests and it was creeping me out.)
Downloads
I do not distribute this program myself. If you want it, you can download the 1998 IOCCC Winners Distribution. The distribution comes with a dozen or so other winning entries, all quite interesting programs.
Note that this is a source distribution, and you will have compile it to run it. I’ve tested it on some versions of Linux, AIX, Irix, and Sun.
IOCCC Flight Simulator source code is in the public domain; there are no copyright restrictions on it whatsoever. However, the winners distribution has been copyrighted by the IOCCC judges. See the hint files in the distribution for details.
In those 15 years, many things about the World Wide Web have changed tremendously, but one thing has remained the same: my web pages have been almost entirely static. Except for a few minor cgi-bin applications (including the Oracle of Notre Dame in a previous form), all my web content was edited on my desktop, uploaded, and served as-is.
Well, I’ve finally jumped on the dynamic content bandwagon. Welcome to my new blog. Like any respectable web app, it stores content in a database and retrieves it upon request.
So what pushed me over? Well, it’s mostly a matter of the right technologies coming together and getting support from inexpensive web hosts. Until recently (last few years), most inexpensive web hosts only supported dynamic content with PHP (which I will never touch) and cgi-bin scripts. CGI is terrible for anything more than trivial apps. But lately web hosts are supporting a wider variety of web frameworks (largely due to the success of Ruby on Rails, I think).
With that development I began considering to implement my own dynamic content in Python. There are now tons of libraries one can leverage to take care of the gory details (and that’s all I wanted—which is why I didn’t go with a framework like Django). I found CherryPy to be especially helpful to take care of all the HTTP aspects, while not being overly formulaic to use. The major libraries that came together for my blog are:
CherryPy manages the HTTP aspects
Mako manages the HTML templating
Docutils converts user input to HTML
SQLAlchemy manages the database
Elixir set up the SQLAlchemy’s ORM classes
I threw together a couple small apps with CherryPy and SQLAlchemy, and then decided I was ready to try for a blog, and here it is.
Facebook added an application kill switch, which I invoked, so now all applications are blocked. Yay.
Here is a list of Facebook apps I’ve blocked. With one minor
exception, my policy is not to allow any third-party Facebook apps.
Even though I use Facebook sparingly (it’s mostly there just in case
people want to find me), I find Facebook apps irritating enough to
stomp out and brag about it. Besides being annoying information vomit,
they are often also security risks (they can phish information from
your Facebook profile if you allow them).
The first 20 or so apps on this list I blocked before even having used
them; when I first signed up I browsed through the most popular apps
and blocked them all. I take great pride in having blocked SuperPoke
without ever having been SuperPoked.
Dear the five or so job recruiters per day who try to contact me:
First of all, I would like to thank you for your interest. It is
comforting to know that I always have options. However, several
aspects of you methodology have been a source of irritation to me, so
I thought I’d write this letter to make you aware of this.
1. Please do not cold call me. I realize that calling the victim,
er, prospective employee is the modus operandi of some of you, and
that’s perfectly fine. But, there a little problem here. You see,
the resume I have up on Monster.com has a contact preference set to
“Email.” And when that didn’t work, I decided to put a line at the
very top, right in the objective, that says “ATTN Recruiters:
please contact me by email only, not telephone.” But that didn’t
work either. I may have to remove my phone number altogether (which
I don’t want to do, because I would like someone I’ve communicated
with to be able to refer to it to get my number).
You see, it’s really annoying to get 2 or 3 calls a day while at
work, oftentimes when I’m at a meeting. Which brings me to my next
annoyance….
2. Ok, you’ve decided to cold call me. Why in God’s Holy Name would
you call me during work hours? Isn’t that the worst time
imaginable? “Hell-lo, Meester Bonks, my nay-yam is Hajib, er,
Michael, I-ee om calleeng you on behoff of a large
tech-no-loj-ee-cal firm. Do you have twoo meenutes to speek with
me?” Um, yeah, sure Hajib, I’m sure my coworkers won’t suspect
anything if I shout my preferred job locations into a phone for the
benefit of a guy in India with a bad connection. Which brings me to
my third annoyance….
3. Don’t use non-native English speakers to recruit. You’ve
outsourced your call center, your software division, your
manufacturing, your accounting department, and so on. Fine, you
gotta roll with the times. But if there’s one thing you don’t want
to outsource to non-native speakers, under any circumstances, it’s
recruiting. Let’s take a look at my thought process to figure out
why. “Hell-lo, Meester Bonks, my ney-yam is Okmed, er, Matt….”
Hmm, some Indian guy is calling me about a job. I’m not too
familiar with the firm he’s mentioning. I wonder if I should
consider working for it? Well, let’s see, what do I know about this
company so far? Number one: They outsource jobs to Asia. Yeah,
great first impression there, what American wouldn’t want to work
for a company that has a history of shipping jobs overseas?
To be honest, I don’t personally care about this so much; from a
purely economic perspective it makes sense to outsource. And I am
the sort that wouldn’t exactly be crushed by unemployment. In fact,
I’d probably volunteer if there were upcoming layoffs. But, a
recruiter does have to talk about more varied things than a
customer service rep. I don’t mind talking to Hajib over a billing
issue, but over a potential job is a little much.
4. If you’re not going to read my resume, please don’t act like you
did. All too often I get emails like this: “Greetings Carl, I
have personally reviewed your resume and I believe you would be an
excellent fit for this job opportunity. If you have an MSEE and 7+
years experience working with PLC, please respond with an updated
resume in Word format.” Um, dude? You just claimed in the very
previous sentence that you reviewed my resume. I shouldn’t have to
tell you that I don’t have an MSEE nor 7 years experience in
anything.
If you’re going to send out mass emails based on keywords, fine,
but don’t be a pretentious fool by claiming you read my resume.
5. Give me details about the job. My rule of thumb is that I don’t
respond to any recruiter who’s failed to supply at least three
things: a brief job description, a job location, and a description
of the firm. This should be a common sense thing for a recruiter to
provide. I get emails like this all the time: “We are looking for
an experienced Python developer. Please call me if you are
interested.” Um, how the hell would I know if I’m interested or
not? All I have to go on is Python developer. That’s not a brief
job decription. What kind of Python developer? What software
domain? There’s nothing about a job location or firm.
Even a bit of information might pique my interest; for instance,
I’d probably respond to this solicitation: “A medium-size
aeronautical firm in Northern California that is looking for an
experienced Python developer to write user-friendly interfaces for
numerical simulations.” Conversely, the tiny bit of information
might be enough to rule out the offer, saving everyone’s time. When
recruiters don’t volunteer this information, I assume they have
something to hide and ignore it.
6. Emailing me a tenth time isn’t going to get me to alter my
decision to have ignored you the previous nine times. If I don’t
respond, it’s because I wasn’t interested. Sometimes if a person is
polite and emails me back for an answer, yes or no, I’ll write them
back to say no. But mostly these repeated messages are just spam.
7. There’s a reason that, although I live in Cincinnati, Cincinnati
isn’t listed among my preferred locations on my Monster resume.
Hint: It’s because I don’t want to work in Cincinnati.
I think you for reading this, and I would encourage you to pass this
on to any of your friends to that all may be enlightened.
The Apostrophe Rule is a rule I made up while advising someone on an
Internet forum what to do about his wife who would always talk his ear
off. I’ve been told many times how clever the rule is, so I thought
I’d share it with the whole world.
The husband in question here didn’t want to shut his wife down
completely, I guess because he thought gossiping was the highlight of
her day, or something. Anyway I gave him this rule which is designed
merely to set boundaries about who she can talk about, and it’s pretty
clever. Here is the rule as the husband would dictate it to his wife:
You may not gossip about anyone you need an apostrophe to name.
If you think about it for a moment, it’s clear how and why it works,
but I’ll give some examples anyway. First of all, people who are on
first name basis with both spouses are acceptable, since they can be
named with their actual name, no apostrophe needed. Any relative or
friend of the wife would be acceptable; she could name them as “my
sister”, “my mom”, “my best friend”, “my coworker”, “my dentist”,
etc. However, the rule kicks in once she starts getting to “my
sister’s friend”, “my coworker’s niece”, “my mom’s psychiatrist”,
“Dawn’s hairdresser”, etc. Those people need apostrophes to be named,
so she is not allowed to talk about them.
This rule has two benefits. It limits the number of people available
for the wife to gossip about, ostensibly reducing the overall time
she’ll be able to spend gossiping. Also it helps limit the gossip to
be about people that the husband is less uninterested in.
As far as I know, I am the first person to come up with this
rule. I’ve had a lot of people follow-up with praise for this rule
whenever I post it. They will write, “Wow, that’s a really good rule.”
I’ve even had women say they would respect men who instituted it. It
seems that a lot of people like rule.
The Apostrophe Rule is slightly related to an observation I made about
urban legends, which I’ll call the Apostrophe Theorem even though it
isn’t a theorem and isn’t even always true, for that matter. It’s just
cool to call things theorems. It goes like this:
Whenever someone claims a dubious, urban-legend type story really
happened to someone they need an apostrophe to name, it isn’t
true.
Point is, stuff you hear from the grapevine, even short grapevines,
isn’t trustworthy, which is why gossip about your father’s brother’s
nephew’s cousin’s former roommate is so inane. What’s the point of
listening to all that when it’s probably not even true? Some people
have an instinctual filter to that causes untrustworthy information to
bore us; others don’t. That’s why we need the Apostrophe Rule.
I just got done watching a very good, highly entertaining movie, V
for Vendetta, on FX. It was created by the Wachowski brothers, who
made another movie I thought was excellent, Bound, but are most
well-known for the Matrix Trilogy.
V for Vendetta and Bound were such good movies, it makes me
wonder, why did The Matrix suck so bad?
I know exactly why I didn’t like The Matrix; I just wonder why the
Wachowski brothers did it. In V for Vendetta they took existing
idea—totalitarianism, vigilanteism, revolution, and vengeance—and made
a movie about them, but without the pretension of being the first ones
to ever present those ideas. It’s not as if no one has ever sat down
and thought about whether vigilanteism is ever justified, and the
movie didn’t make itself out to be the first to ever ponder these
ideas.
The Matrix, however, did. The Wachowski brothers presented this idea
that the world we live in is just an illusion, as if they were the
first people to ever ponder that idea. Well, no they weren’t: the
Greek philosopher Plato wrote about this idea only around 2500 years
ago in his Allegory of the Cave. And, to make matters worse, the
movie fails miserably to convince me that the world could be an
illusion. I’m apparently expected to believe that if you get shot in
the Matrix, your body will be riddled with bullet wounds in the real
world, and nonsense like that. The movie tries to be like, “This could
really happen,” but the silly inconsistencies, stupid plot devices,
and bad thermodynamics destroy that. It tries to be plausible, but it
just isn’t.
Cinematographically it’s not even close to being as well done as V
for Vendetta or Bound. All it really has going for it is special
effects (which are not as technologically advanced as they appear) and
little in-jokes (oooh Neo is an anagram of One, that is so cool).
In short, it sucked.
I just wonder how the Wachowski brothers did so poorly with it, when
they did so well on other movies.
Yes, this image is really an MRI scan of my brain.
The story behind this image begins in 2005, when I began to experience
minor but irritating dizzy spells. After some otolaryngologists were
unable to diagnose the problem (I had no hearing loss so it didn’t
appear to be Ménière’s Disease), I was recommended to a neural
specialist who ran an MRI on me as a precautionary measure. They were
looking for multiple sclerosis. Fortunately my brain scan was normal,
and as a side effect I got this cool image that shows my brain in all
its glory.
By the way, I still don’t know what caused my dizzy spells, but after
I went through some physical therapy the spells became much less
severe and frequent but I still get them once in awhile. I think it’s
safest for me to assume I have a minor case of Ménière’s Disease so I
try to avoid getting water in my ears.
There is a lot of controversy over whether the money we spend on
manned space flight is worth it, with many opponents of it claiming
that that money would be better spent on social programs or other
things.
Those in favor of funding space flight most often tout the scientific
benefits of the space program as its justification. Problem is, it’s a
weak argument. From a short-sighted economic standpoint, the science
potential doesn’t justify the cost of human space flight, by any
reasonable definition (especially since a very big chunk of that
science can be accomplished remotely via robots). Some would even say
unmanned space flight doesn’t justify the cost.
Of course, one can always argue that this is more than an economic
issue (which is valid but lost on a lot of people), or that the
science will ultimately pay dividends long term, even if we don’t live
to see it. But it would be missing out on a much better argument:
The most immediate and tangible benefit of the space program is
not science, but engineering.
There’s an old riddle that goes something like this: What’s the
difference between science and engineering? Science costs money,
engineering makes money.
Well, in the space program that isn’t true.
Unlike science, engineering is very much goal oriented. Generally,
that goal is to make money. And, in the process of engineering so that
we can make money, we learn a lot about how to make things better
(i.e., safer, more efficient, more reliable, etc.).
But the thing is, when you’re trying to make money, there’s only so
much risk you’re willing to take, and therefore, there are only so
many goals you’re willing to aim for. But, when you decide to put
humans into space at a cost, you create engineering goals that never
could have been created simply from people seeking to make a
profit. And, in striving to meet those goals, we learn things we
wouldn’t learn otherwise.
To me, the engineering benefits justify the money we spend on space
flight. I think we should spend more.
I’m not just talking about the Tempurpedic mattress, either. Thanks to
the space program, airplane and cars are safer and more fuel
efficient. Computers are faster. Many products are cheaper.
And what about all those homeless people we should be feeding instead?
The engineering advances we make to achieve space flight could make it
more feasible to feed those homeless people. (Not saying it has or
will, but could.)