Project Frontier #13: An Animated Topic

By Shamus Posted Monday Jul 4, 2011

Filed under: Programming 86 comments

Heads up, I did a weekend post on project frontier, so if you’re one of the many Monday-Friday readers (aren’t you supposed to be working?) then you might have missed it. In that post, Reader Jordi asks:

Hi Shamus, why don't you make your own file formats that are maximally efficient for your situation? Although writing a compiler/converter from a third party file format to your own takes some extra effort (although I imagine this would be fairly easy), I think it has 2 major advantages:
1) You get to select the third party format purely based on what modeling/animation tools you want to use, or how easy the format is to parse without having to worry about efficiency (both in terms of extra data/memory and parsing speed).
2) In your game you get to use maximally efficient and flexible file formats because you can custom tailor them to your own unique situation.

Ah. I really wanted to take this route. But my art path begins with Blender. (I’ll get into why later. I’m not planning on using it myself, I’ll tell you that.) If I knew Python and knew how to make Python talk to Blender, then I’d do this in a heartbeat. But I don’t and “learn a new language so you can avoid learning a new file format” isn’t really the most efficient way of doing things. Particularly since I’d still have to write the Python scripts, and then write C++ code to read the resulting files.

frontier12_3.jpg

So we’re stuck with whatever goofball lame-brain files we can wring out of Blender. Now, my first instinct is to write a model importer and replace Sticky the Stickman with proper geometry. But, I remind myself, we’re working backwards this time. So instead of bringing in a model, we’re going to bring in an animation and have Sticky perform it.

I search around and find this Creative Commons character: http://opengameart.org/content/very-low-poly-human

frontier13_1.jpg

He’s perfect for my tests:

  1. He’s low poly. Later, when I’m working on a model importer, it will be a lot easier to test on this 400 polygon guy than on some 10,000 polygon beast. When points go out of place, I’ll have a sporting chance at being able to spot the problem, instead of finding myself looking at a dense tangle of visually indecipherable geometry.
  2. He comes with several animations. In Blender, he can run, punch, and stand. This gives me a variety of animations for testing.
  3. He’s a minimalist humanoid. No guns, armor, furry sidekicks, fancy clothing, or wild anime hair. It’s just a guy, and nothing else. Again, simplicity is clarity.

Note that this is NOT something to be used in the game. This is only for research. My research begins with the following highly rigorous scientific approach:

I open the guy up in Blender. After just ten minutes I figure out how to select his animations, and then I go to File » Export and save the animation in every format available. COLLADA, Stanford .ply, Motion Capture .bvh, Stl, 3ds, obj, fbx, and x3d. Once I have a nice, even coating of random files spewed all over my desktop, I start opening up the files in a text editor. Most files are binary. (And thus gibberish in a text editor.) I set those aside. Text files are far easier to work with than binary files. You can read a text file yourself, which lets you know what the file “really” says. This makes it fairly easy to spot the difference between a design problem (I’m misunderstanding the format) and an implementation problem. (A regular old software bug.)

I inspect the files, and find that .bvh files look very, very straightforward. It’s a description of a skeleton (which I don’t need, because I already have one) followed by a pure list of rotations. “Turn the shoulder 30 degrees. Twist the spine -15 degrees. Rotate the knee 20 degrees.” Smashing. This is exactly what I want. Some animations files (perhaps most animation files) are inextricably linked to a particular skeleton. So every skeleton in the game (say, men and women) needs to have its own animations. That’s fine if you’re a big studio and you can solve problems with money, but indies can’t go around doubling their workload on a whim.

The downside to using interchangeable animations is that different skeletons will end up with different results. If your artist designs an animation for a full-grown man to put his hands on his knees, and then you apply that animation to a sixteen year old girl, the different proportions of their bodies may lead to undesired results. Her hands might end up clipping though her knees slightly, or floating a bit above them. In a cartoon-y world these aberrations would go completely unnoticed, but in a photo-realistic world you end up chucking your characters into the Uncanny Valley. Just one of thousands of ways photo-realism ends up costing so damn much.

There’s a bit of ambiguity that confuses me for a while. The designer of this model has joints for both “shoulders” and “upper arms”, and my model has a single joint for the shoulders. This leads to some puzzling movement until I discover the problem. The coordinate systems don’t agree, either. My world is set up so that positive X is east, positive Y is south, and positive Z is up. Better than half of the graphics engines out there use use Y for vertical and Z for north / south. (Notch is a loose cannon. He uses Z for east / west. I’ve NEVER seen that before.) My coordinate system was chosen carefully. 1 unit = 1 meter = 1 square of terrain detail. I can covert between “map coords” and “world coords” by just throwing away the Z value. (In my previous job where Y was “up”, this was done by throwing away Y, then making Z the new Y, then dividing the new X, Y values by 10. I’m sure you can see how this could lead to occasional confusion.)

But the person who made this animation has another system in mind, and so I have to sort that out. The shoulders rotate on the wrong axis for me. Instead of swinging forward, they rotate in place. (Imagine your arms at your sides. Now turn your arm so that the palm of your hand faces forward, then behind you, etc.) The knees move backwards for a while and things are generally creepy and strange until I get it all sorted. I really wish I’d taken a screenshot of the process.

In any event, I manage to figure it out. I have an animation system, and Sticky the Stickman can now run in place. I forgot to take screenshots, but he’re’s a shot of Sticky doing the sine-wave animations from earlier, which we can pretend is a victory dance.

frontier13_2.jpg

Just one step left. I have to read in a skeleton, vertex points, and polygons. It’s the hardest step, but at least i know everything underneath it works properly.

 


From The Archives:
 

86 thoughts on “Project Frontier #13: An Animated Topic

  1. benjamin says:

    amazing! your fast pace is simply breast taking, making a game seem really easy (when YOU do it).

    it’s a pity you don’t know python. it’s a beautiful and elegant language that you can, really, learn in one day.

    1. Bubble181 says:

      Let’s hope his wife doesn’t find out about his new pace, than. :-P

      1. Alexander The 1st says:

        Just a heads up, Shamus, if you’re using that comic to start learning: That was Python 2.x .

        The “Hello World Program” in Python 3.x is:

        print("Hello World")

        [/pedantic]

        import antigravity still works the same though.

    2. (LK) says:

      Breast taking, that’s a new one

      1. benjamin says:

        damm!

        well, talk about lapsus :-T

  2. MrGamer says:

    Very nice animation work there.

  3. Jordi says:

    Thank you very much for answering my question, Shamus! I hope you don’t mind me hammering on about it a bit. You say you would want to use Python to talk to Blender directly. While I agree that would be awesome, it wasn’t really what I had in mind. What I was thinking, is that you could just take any easy to parse file format (e.g. the bvh one) that isn’t necessarily very efficient for you, parse it (which you have to do either way) and then instead of immediately using it in your game, you save it to a format that you made up and that is exactly what you want it to be. I can see why Python or another scripting language would be suited for that, but you can also do it with C++.

    In fact, you should probably be able to find a generic object serialization library for C++ (although writing your own binary serialization for the object should not be a problem for you either). That way, when you parse the bvh file into your Animation class (I assume you have, or could easily make, something like this), do all kinds of preprocessing that you might want, and serialize the object to disk. Then, in the game, where performance really matters, you deserialize it and instantly have your Animation object ready to go.

    Okay, I’m done now. :)

    I’d just like to add that I agree with benjamin and am in awe of how fast you are accomplishing all these cool things. And happy Independence Day!

    1. Jamie says:

      Actually, technically python is INSIDE of blender.. you just have to open the script window.

      The route I took was to take a well defined format (.obj) and tweak the export script to include extra data that I want in the file..

      http://wiki.blender.org/index.php/Doc:2.5/Manual/Extensions/Python/Intro_to_Python

  4. Eärlindor says:

    I would like to say I have something intelligent and funny to say about Sticky the Stickman.

    But I don’t.

    Uh… “Victory Dance emote for Sticky?” :D Nah… :/

    Keep up the good work, and Happy Fourth! :)

  5. Doctor Satan says:

    nice animations. OT: how is the book coming along?

    1. BenD says:

      Spoilsport.

  6. Piflik says:

    I thought you hate Blender

    And I wholeheartedly agree with that assessment…Blender is pure evil…the UI pre-2.5 was abysmal…I’m constantly told it is better now, but whenever I try finding my way into that program, I fail at hurdles so basic that I don’t want to try going further in…I guess I’ll stay with 3ds Max for the rest of my life…

    One thing confuses me…you wrote that the Blender character had joints for shoulders and upper arms whereas yours only had shoulders…I have to admit I can’t follow you here…on your screenshots your character does have both shoulders and upper arms and the Rig in the Blender screen doesn’t look so different…

    1. psivamp says:

      Two joints one separate axis? The shoulder’s a socket joint or some such (I haven’t taken anatomy in forever) so you can’t model it using a single planar joint which I’m assuming is how these joints work.

      1. Piflik says:

        Joints typically have three degrees of freedom (rotations) unless you tell them not to be.

        A basic character arm rig you have a clavicle bone, an upper arm bone and a lower arm bone…and as far as I can see both Shamus’ Stickman and the Blender Character have exactly these…advanced rigs have additional bones in the upper and lower arm to blend rotations, but none of these have anything to do with the shoulder itself…

        Though I have to admit I still have much to learn considering rigging, especially at the shoulder…I have yet to find a simple solution to prevent the shoulder from collapsing in itself when the arm ie raised…

    2. Deadfast says:

      Unfortunately I don’t think Shamus has the luxury of choice. No matter how many negatives Blender has, there is one masive advantage it has over the competition – it’s 100% free.

      1. Felblood says:

        I suspect that the explanation we’ve been promised will be that someone else is delivering the models for him, and they actually like the program.

    3. Wtrmute says:

      It’s funny how people have this massive UI lockin on arts programs. All the graphics designers I’ve ever met work with only with Photoshop and God help you if you ever suggest using the GIMP, even though they have the same tools. For 3d modelling, I know a few editors which lack some operators and have others, but it’s probably the same issue with investing too much into the specific UI.

      1. Piflik says:

        Don’t get me started on GIMP…it might have more or less the same tools as PS, but I really hate that three-windows-design that can all separately lose focus and disappear behind other windows…also it tends to have problems with my Wacom…

        Blender is really a beast in terms of UI…it is not only cluttered with features noone ever uses, but also completely counterintuitive…I don’t know why, but they chose to do it completely different to everybody else…Max, Maya, C4D, XSI, etc all share some similarities in UI and basic functionalities…if you know one of these you can open each of them and know your way around them in a couple of minutes (at least or the basics), but not Blender…the only other app I know, that os similarly different, is zBrush, and even that is by far easier to learn than Blender…

        I think Blender might be acceptable to use as a first 3D program, but when you used a different one before, it is just frustrating to sit in font of the screen trying for hours to create stuff you can do in the other tool in minutes…

        1. HeroOfHyla says:

          “I really hate that three-windows-design that can all separately lose focus and disappear behind other windows”
          If that happens, it’s a glitch. The tool and layer windows have been special “always on top” windows for the last couple of years at least. I know it doesn’t work right on KDE (at least when I tried it on Ubuntu), but it works properly for me in Windows and Gnome.

          1. Piflik says:

            Don’t know which version it was, but the last time I tried it, I full-screen-ed the image and my tools and layers where hidden behind it…completely stupid…haven’t tried it since…

            1. Mephane says:

              Heh yeah, and I remember when running it normally, i.e. free floating windows, one mis-click and you bring something else in front of the whole thing, and have to bring each window separately back to front. At least that’s how I remember it, was some couple of years ago and it took me 5 minutes to say “screw this crap”.

              I’ve got the feeling GIMP was made by/for people who never have more than one program open, and a completely empty desktop…

              1. Piflik says:

                Well…with a multi-monitor setup, it might be worth a try…having the canvas on the primary fullscreen and the tools and other stuff on the secondary…but I still prefer Photoshop…

              2. karln says:

                Maybe they come from Linuxland and are used to giving big multi-window apps like the GIMP their own workspaces. Or, yeah, multiple monitors.

              3. Kelhim says:

                It’s definitely nice on a dual-monitor setup, and for many window managers you can define window rules to make the program behave the way you want. The next version of GIMP will, however, offer a single-window-mode.

      2. J Greely says:

        Has GIMP caught up to the functionality of Photoshop 4 yet? Setting aside the terrible UI, someone who spends their days working with Photoshop probably doesn’t want to go hunting for plugins that sort-of implement features they’ve been using for over a decade.

        -j

        1. BenD says:

          Pretty much this. I suspect some game designers do so much of their work in 3D modeling programs and the like that their Photoshop work is agonizingly simple, however, so why not use GIMP? If you’re a photographer or a print designer, the two programs stop looking identical.

    4. Zak McKracken says:

      I think the thing about Blender is just that it requires you to think about using it differently, but then you become super efficient.
      It’s a but like Python in that respect, if you’ve only ever done Fortran before … (so maybe that’s not a represantative example?). It was pretty painful doing the simplest things, but after I had rewired my brain, it was pure joy and Fortran looks soo clunky now!

      One of these days I’ll have to learn Blender properly. Let’s see how that’ll be going. At least it will be a good exercise in not stopping to learn new stuff.

      1. Piflik says:

        One of these days I'll have to learn Blender properly.

        Tell me how that’s going…I didn’t have much luck the last 15 times I tried :D

        1. Christopher M says:

          I’ve learned to use it (albeit without prior knowledge of a different system). I can whip out game-quality (EG not-CG) models/UV maps in no time flat. So, it works, if you know it. Hard if you don’t, though.

  7. scowdich says:

    You’re a loose cannon, Notch…but you’re a damn good cop!

  8. anaphysik says:

    My world is set up so that positive X is east, positive Y is south, and positive Z is up.

    What? A left-handed system?

    1. Shamus says:

      I guess so. I like this because when I look down from above (as with the map) the origin is in the upper-left.

      1. HeroOfHyla says:

        I’ve always wondered why graphing for math and such has the origin in the lower left, but it’s in the upper left for computer graphics.

        1. Random says:

          I would guess that:
          For Math, x is left to right because it’s the way we read, and y is pointing up because, well, it seems logical to display something that increase as going up.

          For computer graphics, it originate from the CRTs of olde, where the beam started hitting the screen at the upper left corner.

          Of course I might be totally wrong on both accounts.

          1. Deadfast says:

            Actually, a more likely explanation for having the origin in the upper left seems to be an extension to your reading theory – the page starts in the upper left.

            1. decius says:

              In math, the origin is at the center. In computer science, the origin is at the beginning. I don’t understand why character models would care which way was east, though. Do they only have one axis of rotation? Is it less trivial to roll or pitch a character than it is to yaw them?

          2. Zak McKracken says:

            In Maths (and in Physics as well) any coordinate can point anywhere it likes, only usually you have x going left to right, because that’s how people read. Where I work, we’re sometimes juggling with lots and lots of different coordinate systems. If I was to code something like hierarchical motion, every body part would have its own local coordinate system.
            One thing they’d all have in common though: They’re right-handed. If you have left-handed coordinate systems, all of vector mathematics falls apart (or at least you need to rethink everything you do, because all operations and laws are established for right-handed systems). I heartily recommend always using right-handed systems (says the left-hander) if you plan on doing anything requiring coordinate transformations (like, rotating stuff in 3D or such…)

            For non-technical/mathematical people out there: A right-handed system is one you can construct by pointing the thumb of your right hand in positive x direction, the index finger in positive y direction and then pointing the middle finger at a right angle to both. You can turn that thing any way you want (actually, a good see how far you can twist your arm is to try and visualise some weird coordinate system), it will always be right-handed. And you’ll never manage to form the same system with your left hand except if you’re able to bend your middle finger 90° backwards.

            For computer screens, I think coordinates just follow the raster beam of CRT tubes. Starting top left, going down linewise. Still no problem to construct a right-handed system there, just put your right hand on the screen, thumb right, index finger down … I’m not responsible for injuries :)

            1. Zukhramm says:

              Actually I can quite easily form the exact same system with both my hands. Sure, the axes will be named differently, but that’s just arbitrary labels. I do not understand how the names of the coordinates would change how the mathematics works.

              1. Tobias says:

                The ordering of the coordinates matters, not the naming. If you change from right handed to left handed some vector operations switch signs.

                You say x1 cross x2 equals x3, for your definition. If you switch x1 and x2 suddenly your x3 points in the other direction.

                Imagine turning a screw from x1 to x2, than the screw travels in x3 direction.

                You could theoretically build up a left handed mathematic, but then you will have lots of trouble adding some kinds of physics.
                When x1 is left to right and x2 is up to down x3 is into the monitor.
                If x1 is east x2 is south then x3 goes down.
                In my work x1: left x2:up x3:back is very popular.

                1. Zukhramm says:

                  If x1 cross x2 equals x3, and then we switch the x1 and x2 axes of the system. x2 cross x1 still equals x3, right?

                  1. William Newman says:

                    You wrote “x2 cross x1 still equals x3, right?”

                    It ends up being an arbitrary sign convention. Underlying it is a sort of pun: cross products and vectors have the same number of components, and transform similarly in some ways (e.g., you can add them: adding angular momentum works the same way as adding momentum), so it’s a useful pun. But they aren’t quite the same thing.

                    Chasing the links early in http://en.wikipedia.org/wiki/Cross_product (to things like pseudovector, bivector, and exterior product) will tell you more about this issue in a general abstract way. Or if you can be satisfied with a single concrete point to back up my claim that there’s an arbitrary pun going on, note that if you transform your coordinate system as if by reflection through a mirror, then true vectors which were parallel remain parallel, but a true vector which was parallel to a cross product (e.g., a momentum which was parallel to an angular momentum) will now be antiparallel, running in the opposite direction.

              2. Zak McKracken says:

                Nope, you cannot. Remember:
                Thumb: positive x
                Index: positive y
                middle: positive z

                Ah … just look it up:
                http://en.wikipedia.org/wiki/Right-hand_rule
                it’s impossible to make the same coordinate system with both hands, one axis will always be reversed, or two have to switch places (which is the same as inverting one and then rotating 90°)

                1. Zukhramm says:

                  Oh, I’ve looked it up. Trust me. I just could find no place that actually explains it.

                  Just turning my left hand 90 degrees to the left I get the same system, the one from my right hand will have to coordinates x, y, z, and the one from my left will instead call them z, y, x, but I don’t see how they’re actually any different.

                  1. Zak McKracken says:

                    noooooo! The important part is that your thumb is always x, the index finger is always y and so on. You’re not allowed to rename them!
                    It’s impossible to turn a left-hand system into a right-hand system only by moving/rotating. As I said above, you can’t do it without swapping two axes or inverting one. Which is what you did => you cheated!

                    If you don’t cheat, it is possible to build every possible 3D cartesian coordinate system with exactly one of your hands, which means each of those is either left- or right-handed.

                    Actually, physicists have a hard time understanding why magnetic fields are right-handed. An electron moving along your right thumb through a magnetic field that goes in the direction of your right index finger experiences a force in the direction of your right middle finger. If you try it with your left hand, you get the direction of the force wrong.

                    1. Kian says:

                      The reason it’s not the same (and why you’re not allowed to switch the axis) is that the order of the values is an integral part of what defines the coordinates that the axis measure. That is to say, (2,1) is a different point to (1,2).

                      In the example where you ‘get the same coordinate axis, but with different names’, the reason they’re different is because (1,2,3) in one will not map to the same place as (1,2,3) in the other. If a given point is not the same in both coordinate systems, then the coordinate systems are not the same, even if you manage to have different axis line up.

                      As for the electron and right-handed systems, that is plain wrong. The equations work correctly in either case. If you try it with your left hand, you get the opposite direction, but you also have the axis reversed. Meaning the force is still pushing the electron in the right direction. You’ve just changed the arbitrary labels of the points in space.

                    2. Zukhramm says:

                      It’s not cheating. Who decided I can’t rename my own coordinate system?

                    3. Zak McKracken says:

                      @Zukhramm:
                      You wanted the right-hand rule explained. That is the right-hand rule.

                      In vector maths: a x b = -(b x a) (=> cross products are not communtative)

                      In words:
                      1. any two right-hand systems can be transformed into one another by means of rotation, translation and scaling (with non-negative factors!); the same goes for left-hand systems
                      2. You cannot transform a right-hand system into a left-hand system without inverting an axis or swapping two of them. Swapping axes or inverting them will change results of vector operations.

                    4. Shamus says:

                      My experience bore this out. Moving from right-hand to left-hand, I had to invert the X axis of incoming models.

                    5. Zak McKracken says:

                      @ Kian:
                      Yes, yes, you could also compute magnetic (not electric! electric fields are scalar potential fields, magnetic ones are vector fields) forces with left-handed vector maths, or you could just rearrange the vectors and call it left-handed, that’s just a matter of definition.

                      The thing is this: If field vector and movement vector are normal to each other, and the force is normal to both of them, then how does this force “pick” one of the two possible solutions (and always the same one)? This can be traced back to quantum mechanics and some other stuff I’m not familiar with, but the question remains: How have elementar forces and particles a sense of left or right? You could easily imagine a universe following the same laws as ours, only with one coordinate inverted. There’s no known reason it could not work. But it’s completely incompatible with ours.

                    6. Zukhramm says:

                      @Zak McKracken
                      I never asked for the right hand rule explained, I already knew it. 2. answers my question however, so thank you.

        2. Jarenth says:

          Amusingly, I was always taught in math class that two-dimensional systems start in the bottom left, but three-dimensional systems start in the top left. In fact, I read Shamus’ axis description and found it odd that that was supposed to be odd.

  9. Christopher M says:

    You’re taking a very similar approach to getting animation working to my own: A blocked-out reference figure rather than a straight-up high-detail mesh. It does make it easier to work with, and I must admit, I get rather attached to the little guy. But I hope you won’t end up leaving the project at that stage – I’m looking forward to seeing what artstyle-specific human figure you can come up with.

  10. Isy says:

    Still looks great. I could probably waste a month imply running an avatar around an infinite number of WoW-sized worlds.

  11. Lachlan Stuart says:

    But I don't and “learn a new language so you can avoid learning a new file format” isn't really the most efficient way of doing things.

    You’d think so, but in retrospect I spent more time poring over documents describing the Quake 3 model and map file formats (MD3 and BSP) before I was able to make an importer, than I did reading Python tutorials before I was able to use it to pass 2 rounds in Google Code Jam.

    That said, you could always just use AssImp to import from any common format. It’s not the fastest way to import, but the expectation is that when you want speed you can just load everything into custom data structures and dump it to disk with a little bit of pointer correction.

    On a lighter note, it makes a big difference seeing characters in your world. I really like how it’s shaping up. That first screenshot looks fantastic for a couple months of spare time work.

  12. JimminyJoJo says:

    “Notch is a loose cannon.” hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaahahahahahahahahahahahahaha

  13. Potado says:

    Great job! It’s nice that you’re using Blender – my specialty.

  14. Jamie says:

    i agree, big ++ for blender

  15. SoupSandwich says:

    “Low Poly Human? He’s just this guy, you know?”

  16. Nathanael says:

    The Wavatar PHP doesn't work!

    1. Shamus says:

      Hm?

      Wavatars were folded into the core of WordPress a couple of years ago. You no longer need the plugin. If you’ve got a version of WordPress made since 2008, you should have wavatars on your site.

      You’re using one right now. It’s right beside your comment.

      1. Nathanael says:

        I know, but I want to use Wavatars for my blogs.

        1. Nathanael says:

          Look here,
          http://smallysreviews.wordpress.com/2011/07/02/welcome-to-smallys-review-blog/
          when I tested one of my blogs and posted myself a comment as a logged off person, it is a different icon, so it’s not a Wavatar. So how to get Wavatars now? By the way, visit mrcontesty on YouTube for Shapeworld based on your Wavatar creations.

  17. Odoylerules360 says:

    You don’t know Python? What!? You should really halt the project and go rectify that. In my experience, coding anything in Python takes, at most, half as long as in any other language. And really, learning Python probably won’t even take a full day.

    1. Alex says:

      What would you recommend for a Python tutorial that’s the least infected with either self-indulgent wackiness (“think of programming as being like waxing your car with a unicorn!”) or open hostility toward people who don’t already know Python?

      Bonus points if it avoids the massive, unexplained jump in difficulty that seems to be de rigeur in programming texts – you know, the part that inevitably comes where in one exercise you’re, say, writing nested loops, and in the next you’re supposed to write a program to calculate compound interest under several different tax structures using mechanics that have, at best, been hinted at in the explanatory text. (That’s a real thing that happens in an online tutorial for either Python or Perl, I wish I could remember where I saw it.)

      1. Simon Buchan says:

        1: Get python. [1]
        2: Open IDLE. [2]
        3: > help()
        4: try something
        5: go to 3

        It’s how I did it, along with Google and reading existing code. The vast majority of modules that come with Python are in Python (and therefore come in source).

        Shamus here would care about open(path, “wb”) to open the file, and the ‘struct’ module to write packed data, eg:


        import struct
        def write_mesh(path, mesh):
            with open(path+'.vertex', 'wb') as file:
                for (x,y,z) in mesh.vertices:
                    file.write(struct.pack('<fff', x, y, z))
            with open(path+'.index', 'wb') as file:
                for (i0,i1,i2) in mesh.triangles:
                    file.write(struct.pack('<HHH', i0, i1, i2))

        The C++ code would just be opening the files and dumping the bytes into the GL mapped buffer. You could do it more complicated, but I dont really see the point.

        [1] I’d recommend python 3 if you don’t have a reason not to, but you probably won’t be able to tell the difference at first.
        [2] The editor/”IDE” (but not really) that comes with Python. It’s no Visual Studio, but it’s pretty good.

        1. Alex the Elder says:

          I envy people who can take this approach. Becoming a full-time code monkey has taught me that I am, to some small degree, a social creature after all, at least insofar as I need to talk things out with people from time to time. ^^; I think Zak’s link below might be a good place for me to start…

          1. Simon Buchan says:

            Well, it certainly helps if you can program already, the more languages you know, the easier it is to learn a new one. python.org itself has a pretty comprehensive tutorial, too, although it does take a while to get into actual python: http://docs.python.org/py3k/tutorial/index.html

            1. Alex the Elder says:

              I know snippets of many languages (going all the way back to BASIC and LOGO; my languages in college were C++ and VB); I’m realizing that what I’m weaker on is devising algorithms, which I don’t get to practice much at work, rather than learning syntax and whatnot. My day (and evening, and middle-of-the-night) job involves quickly generating SQL and PL/SQL (yes, yes, go ahead and hate :-P ) on short notice, so I do a large number of variations on a small number of things repeatedly, and one’s brain can get a bit calcified that way.

              That’s what I think needs more emphasis: logical and algorithmic thinking. Not even necessarily in a CS context – back in college I took a semester-long logic course in the philosophy department as a liberal-arts collective, and it’s stayed with me all these years, perhaps the best course I’ve ever taken.

      2. Zak McKracken says:

        This is what helped me a lot:
        http://diveintopython.org/
        It’s for people who can code already, know nothing about python and may or may not know about object oriented programming. Was exactly right for me, very comprehensive, very practical, very interstingly written.
        Whether this actually is right for you depends heavily on your background, though.
        If you’re a seasoned coder, you might not need such a long introduction (see Simons post). If you’ve never coded before, it might be a bit steep.

      3. coarse.sand says:

        Alex, sounds like you ran into trouble with why’s (poignant) guide to Ruby, or something similar. Nothing I’ve ever seen come out of the Python community was as… strange as that. Anyways, here are two suggestions from someone who’s now gainfully employed as a programmer largely because of Python.

        Learn Python the Hard Way. It sounds intimidating, but really isn’t. Basically it’s a series of exercises that lead you through learning Python, and I’ve heard many good things about it from people new to programming. Zed Shaw’s also a good guy, so throw him a buck for the PDF.

        The other option is a great book from O’Reilly, “Learning Python” by Mark Lutz. I learned from this myself since LPTHW wasn’t around at the time, and I can attest to its greatness personally.

        As for the nested loops deal moving right into calculating compound interest, I’ve never seen something so strange in starter material, but keep an open mind. The exercises these tutorials lead you through tend to be more about getting the concepts into your head than being really practical. If you’re already an experienced programmer, well, try writing some pseudocode, but surround your conditionals with parens (), and open your blocks with a colon. You’ll probably be within shooting distance of having a working Python program, just fix whatever errors you get.

        Also, I’ve personally never touched IDLE, but I was using Linux at the same time I picked up programming, so I had easy access to the command line. If you’re on Windows, use IDLE.

        1. Simon Buchan says:

          IDLE does give you some code hinting and multiple documents, so I’d probably still recommend it over “$ python” unless you have a strongly preferred editor.

          PS: you don’t need parens in conditionals: “if foo == 0:” works fine. A lot of the time, you don’t even need parens in tuples, “for key, value in mydict.items():” is the classic example, but also “a, b = b, a”.

  18. Blake says:

    I gotta jump in and say you should learn some python too.
    I only learnt it late last year when I was at work one day and had the need to parse a microsoft tool generated file (internally it was XML) and link parts of it together and such into lua tables.

    My lead at work told me to do it in python, I mentioned not knowing the language, he told me to learn it.

    Half a day later I had a fully functioning script that is still a part of our tool chain.

    It really bothers me the way whitespace matters in the language, but as long as you’re cognizant of the fact it really is easy to learn and fast to code in.

    Also I’m going to agree with what someone up that ^ way said, write a script to parse whichever format you export in into a binary blob your game can read. It’ll help with load times and keep your code base less cluttered.

    Also means you could ditch that format should you choose just by writing a different conversion script.

  19. Michael says:

    In response to the last picture:

    “Hey, Sticklyman, whaaaaat are you doing?”
    [pause while Sticklyman gestures]
    “Correct me if I’m wrong but are you asking for a challeeeeeeenge?!”

  20. The_Unforgiven says:

    /THANK YOU/. I hate people who use Y for up/down and Z for north/south. It doesn’t make sense, and it’s WRONG (according to me, about 3 of my teachers in college and my physics teacher in highschool). I don’t care if you want positive moment to make you go down, or something, but Z should always be up/down, Y north/south, and X east/west.

    1. Kian says:

      Everyone seems to have it backwards. The only relevant attribute for a reference system is whether it’s left-handed or right-handed.

      The rest is a matter of how you orient your models, whether you align the terrain with the X-Y plane or the X-Z plane. :D

  21. Jarenth says:

    Tell me Sticky the Stickman does not look like the Fonz in that last picture.

    I dare you.

    1. Sucal says:

      He does not look like the Foz in that last picture

    2. HeroOfHyla says:

      Reminds me more of a scout from TF2.

    3. krellen says:

      He’s missing the leather jacket. Add that, and you’ve got a sure-fire Fonz.

  22. TheBecker says:

    Hi Shamus

    I worked on modeling the human body as an engineer, and I may have a clue to your shoulder problem.

    Keep your arm still, in whatever position it is, and try moving your shoulder up and down. that is, move the shoulder blade, but do not rotate the shoulder joint.

    It moves right?

    The “shoulder joint” would be better described as the clavicle. It is placed where the horizontal piece of the shoulder connects to the spine. And its rotations allow the position of the shoulder itself to move without moving the arm, allowing you to shrug your shoulders and throw baseballs.

    The “upper arm joint” is the one we would normally call a shoulder joint, and is the ball and socket joint for the shoulder, allowing the arm to rotate any which way.

    The problem seems to be from a misuse of the naming system you mentioned. Here these two joints are referring to the bones they move (shoulder joint literally moves the shoulder, but isn’t at the shoulder, upper arm joint literally moves the arm, but isn’t part of the arm).

    maybe that will help.

    in other news, this is my first post here on this site, and I want to say I love to see what you’re doing here. Its inspiring me to start up my own project as well.

    Although one question (for anyone).
    I currently use a host file to block all ads everywhere, which I feel like I have to do for the usual reasons. But a handful of sites (like yours) both moderate their ads (so they are safe) and have earned my support. Anyone know a way to block ads just for everyone else’s site or support Twenty Sided in another way?

    1. Alex the Elder says:

      The AdBlock for Google Chrome allows you to turn off ad blocking for the site or domain you’re currently on, adding it to a whitelist. Not sure about the current state of things in other browsers.

      1. mike says:

        If you would like to support the site in some other way:
        The Money Goes in the Money-Place.
        Edit: I was actually intending to reply to “TheBecker”… sorry about that.

  23. Gantidae says:

    I am not a programmer. I took one BASIC class in high school then promptly forgot everything. Even so I find these programming discussions of yours fascinating, Shamus.

  24. Goatcathead says:

    when are you putting in the (insert some graphic thing that needs the newest video card)?

  25. thenoob says:

    Z is east/west? Maybe Notch is reminiscing to his school days where X points right, Y points up, Z points towards you? (If he’s looking from East-West)

    For mapping I much prefer bottom left as origin, it’s built into my brain :\.

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun. Your email address will not be published. Required fields are marked*

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>

Leave a Reply to BenD Cancel reply

Your email address will not be published.