Categories
blog

Code + mesh generation

Although creating 3D models using Blender, Cinema4D, or (insert favourite 3D modeller here) is fun, programming 3D models is even .. funnerer. Here’s a few bits of info about this…

General Programming Languages

We can program 3D geometric meshes using just about any general programming language available. There are a number of libraries available for c++, for instance, that offer an API for creating, accessing, and modifying a mesh. Some examples are VCGLib (template joy!), OpenMesh (the simplest), and CGAL (heavy, has bindings for other languages.)

The generality of a programming language like C++ means that programming a mesh is more tedious than it should be. For example, it wouldn’t be out of the ordinary to see code like this:

Mesh m;
std::vector& verts = m.verts();
for(std::vector::iterator it = verts.begin();it!=verts.end();it++){
  Vertex& v = *it;
  std::vector neighbours = v.neighbours();
  float m = 0;
  for(std::vector::iterator nit = neighbours.begin();nit!=neighbours.end();nit++){
    m += nit->data();
  }
  v.setData(m/neighbours.size());
}

Erhk! A lot of power of programming comes from abstraction, so we can implement all the things we want and lock them away into a neat API, or scripting language. Fugu is an implementation of this idea and provides a user a few methods and functions for manipulating a mesh. On top of that, it uses the Lua scripting language, which has a friendlier syntax, and can be executed much quicker than compiled languages. The above program in Lua looks something like this:

m = Mesh()
foreach(vertices(m),
  function(v)
    v.data = 0
    local neighbours = nearby(v,1)
    foreach(neighbours,
      function(n)
        v.data = n.data
      end)
    v.data = v.data/#neighbours
  end)

Lua is popular in game development because it is small, fast and easy to embed. The most popular example World of Warcraft, where it is used customise the UI. Perhaps most relevant to this discussion, is that Lua has also been used in a real-time multimedia programming environment, LuaAV (link). From their github page

LuaAV is a real-time audiovisual scripting environment based around the Lua scripting language and a collection of libraries for sound, graphics, and media protocols. The goal of LuaAV is to serve as a computational platform for creative exploration that is both fluid and generative.

Here’s another similar Lua-based multimedia environment (I think, it’s in spanish so I have no idea what it is…!)

Another approach to mesh programming is to come up with a new language — specifically for the creation and manipulation of meshes. Vertex-vertex systems and GML are two such languages..

Vertex-Vertex Systems

In his dissertation, On Vertex-Vertex Systems and Their Use in Geometric and Biological Modelling (link), Colin Smith introduced a neat “programming language” for operating on meshes, called Vertex-Vertex Systems, or VV, for short. The primary data structure in  this language is the mesh, a collection of vertices and their local topology (a list of ordered neighbours). A key property of VV systems is that the elements of the mesh aren’t stored as an indexable list, but rather as a collection of vertices connected locally with a specific structure. Operations, such as insert and remove are available for modifying the mesh.

Smith’s dissertation is interesting to because he offers several examples of VV models, from different domains. For example, he implements a variety of smooth subdivision algorithms, demonstrating the terseness and readability of VV over conventional programming languages. He also demonstrates a number of biological models of growth. These are quite natural to model with VV.

Unfortunately, like most PhD projects, VV seems to be lost in the void (Smith is now working at a big animation studio). I have no doubt that a system like this would greatly improve the robustness and clarity of mesh-based programs, such as 3D modelling programs, generative software, and the like. (Factors like compactness of data structure and speed would have to be considered though.)

 

Generative Modelling Language

The generative modelling language, or GML (link), is a mesh-building language derived from Postscript. A GML program describes the construction of an object, through the concatenation of many operations. It is postfix (read: backwards), which gives it a unique charm (and makes the implementation of an interpreter trivial!).

In order to build/modify a mesh you need a way to access different parts of it. In GML you always have a handle on some part of the mesh. Each operation either transforms the mesh and gives you a new handle, or changes the position of the handle on the mesh. So for instance, if the handle was just a face of the mesh, and you executed the extrude operation, your new handle might be the face at the end of the extrusion. This assumption means that some things (like concatenating extrusions) are really easy … and other things are a little more tricky.

GML is a pretty nifty language and is targetted primarily towards “rigid” meshes, like buildings, hubcaps, and … chairs.

Generative Chairs! (from http://www.generative-modeling.org/x-coll7406)

The thing about GML is that, although it is a solid system with strictly specified semantics and a rich set of geometric operations, the tools for making GML models are … not good. It’s all ActiveX this, and ActiveX that. This seems like a mistake — the GML guys should instead have written a specific library, in c++, that could then be used in different applications, e.g., as a plugin for a Autocad or whatever. This kind of illustrates why any platform-specific technology should never be used — though as I write this I’m about to develop some Obj-C stuff (but what’s humanity without hypocrisy!)

I wouldn’t be so concerned about the tools if GML could be written by a human. Instead, it’s a human-readable but only-machine-understandable format (like XML). Want to add two numbers, here’s the program … “2 5 +”. Postfix is only awesome from a theoretical perspective, and a simplicity-of-implementation perspective. But as the interpreter will only be written a few times and GML programs many times, why should the simplicity be on the developer’s side? As an output format, GML seems is one of the more interesting ones, we just need some decent tools to work with it.

I should also give GSculpt a mention (link), it is a 3D modeller that stores the entire history of the modelling process. This history can then be re-executed to show how the model was built, or indeed modified to produce variants of the model. Gsculpt supports an equally huge number of operations as GML, but unfortunately has a dated and clumsy UI.

Categories
blog

What is procedural generation?

As the majority on content on my blog is related to procedural generation, I thought I’d give a short, non-technical, introduction on what procedural generation actually is. Enjoy!

If you’ve been following this blog for a while, you’ve probably noticed that I mention procedural generation a lot. In a nutshell, procedural generation is the act of generating things (3d structures, images, sounds) automatically with the computer. Procedural generation is used in architectural design, to create content for games and films (infinite dungeons, cities, worlds, …), and offers a new way to think about creativity.

The procedure in procedural generation ultimately refers to a computer procedure, however, it can be pretty much anything that a computer (or obedient person!) can understand — it doesn’t necessarily have to be low-level code. A simple example of a procedural system is:

Draw a square
Do this 10 times:
  Split a square into four smaller squares

Given this procedure, the computer might output something like this:

Categories
blog

The Fugues

Categories
blog

Fugu source opened!

Fugu, software for Lua-based form generation, is now open source! That means you can download the source, examine it, tweak it, and compile it for the arbitrary operating system of your choice! This is a huge and final step for me in the Fugu project.

Categories
blog

Moonman.io

Moonman now has a separate website at http://moonman.io. All future moonman posts will appear on the news feed there, although I’ll likely cross post the really interesting stuff. But anyway, you should head to the new site and check it out. Moonman also has a facebook page, if that’s your sort of thing. :)

Categories
blog

Another comparison of AO disabled and AO enabled

Categories
blog

SSAO in Fugu

I implemented a new visualisation into fugu today – Screen Space Ambient Occlusion. It is a shader effect (implemented from this discussion) that darkens creases and nooks of the model, as well as making individual parts stand out more. Below is a fugu model renderered as (top) flat-shaded, (middle) flat-shaded with SSAO, and (bottom) Phong shaded and subdivided with SSAO applied. I hope to get it stable and operational in the main fugu release soon. :)

Categories
blog

I don’t know where you pixies came from, but I sure like your pixie drink!

I don’t know where you pixies came from, but I sure like your pixie drink!

Categories
blog

Moonman Update

My progress on moonman has been speeding along quite quickly the last couple of weeks. This is because I’m on holidays from my other job, and so I can focus all my neuronal activity on this … and playing dark souls :S

Anyways, my devlog has the dets as usual, but here’s a screenshot that shows a bunch of the visual changes to moonman.

Categories
blog

The Exhibition

(This is the Day 9 and 10 entry for the 30 day world building challenge.)

‘Oh, I scrounge a meal, here and there’, remarked the old man with the one eye and the cleft jaw. I tried to give him some copper, but he refused, ‘Not the pieces with that ugly bird on, no way in hellsname!’ I assume he was referring to the The Crow, the portrait of whom adorned the back of every single piece of city treasure in The Fourth. I stepped over the vagrant and into the building he was slumped in front of, a scrawny dog by his side. Inside I spotted a swift grill, and from it ordered a hunk of charred impsnout — not the most appetising of meals — but very cheap, and also quite nourishing. A smallpint of honeymead washed it down and I disposed of the paper containers in the adjacent pile, closing the lid.

The show I was attending, an exhibition called ‘A Day of Kindness’, had been raved about by my closest friends, and I was curious to see it. Upon paying and entering the gallery I was confronted not with large and colourful tapestries, canvases, or boarskins, but with tiny square pictures drawn on common paper and placed on the wall at equal intervals. Examining the pictures more closely I was astonished to witness a degree of artistry, both illustration and composition, that I had never before seen. Each image, only a hands width wide, contained a complex illustrated scene with details tinier than I, of 20/20 vision, could discern. The scenes were both familiar, and yet odd, containing those denizens of The Fourth least understood. The stand out image for me was a scene on a balcony, standing on which was a gentleman, with a stately disposition, having a normal conversion with the A’leek! Really! The A’leek only sings AT you,  nobody has ever spoken WITH one. And so on it went, until I arrived at the last. This one stood apart from the others, it was not an illustration, but a mosaic, with uniform and square cells, eight across and eight down. As I squinted I could make out a strange smiling green face, and as I recognised it I got a vivid flash of a bloodcurdling scene in my mind — the world was scorched and everybody had turned to dust.