Tag Archives: erlang

Letterhead: a 3D printed sculpture for word gamers

Yesterday, I was very excitedly waiting for the UPS truck to bring me my first 3D printed model. When it arrived, the box was surprisingly light. I opened it with a fair degree of trepidation, half expected a formless piece of plastic in place of the model I thought I had designed and printed. But no, it worked!

A photograph of the Letterhead model.
Letterhead, a 3D printed sculpture for the avid word gamer

As you can see, the figure has a letter tile for a head while their brain is held in their hand.

I have made a few small changes to the model since printing it, making the neck area less bulky and beefing up the upper arm a little. If you would like to print a copy, you can do that from the model’s page at Shapeways, Letterhead (Revision 1.0).

The model was designed mostly using Wings3D and touched up using Meshlab (Visual Computing Lab – ISTI – CNR), both excellent open source packages. Wings3D is written in Erlang, which is quite exciting.

I made this model in honour of my brother, Adam Lamprell, my arch-adversary at Lexulous. Adam, you are awesome.

Building Wings3d on Snow Leopard

Wings3d is a surprisingly excellent 3d modeling package, written in Erlang. I have been playing with it for a few weeks, using a prebuilt .dmg. I now need to be able to build from source so I can tinker.

I hit some rocks following the build instructions on the wings3d site.

First problem: the build of ESDL which the ESDL website claims is the latest is esdl-0.94.0615. This is outdated and not compatible with current Wings3d source code – there seem to be big differences in the OpenGL libraries. Get the actual latest version instead from ESDL [sourceforge]. I got 1.0.1 and that seems to work.

After building ESDL, ESDL_PATH needs to be set correctly to compile Wings3d. I achieved that with:

export ESDL_PATH=/usr/local/lib/erlang/lib/esdl-1.0.1

Another problem with ESDL – somehow, the library files had been installed with the wrong permissions: they were owned by root and had permissions -rwx——– and so could not be read by erlang. I fixed the permissions.

Final ESDL problem – when I had built Wings3d and started it from the command line, I got an error:

Driver failed: dlopen(/usr/local/lib/erlang/lib/esdl-1.0.1/priv/sdl_driver.so, 2): no suitable image found. Did find:
/usr/local/lib/erlang/lib/esdl-1.0.1/priv/sdl_driver.so: mach-o, but wrong architecture

After some digging, I found that:

% file /usr/local/lib/erlang/lib/esdl-1.0.1/priv/sdl_driver.so
/usr/local/lib/erlang/lib/esdl-1.0.1/priv/sdl_driver.so: Mach-O 64-bit bundle x86_64

but

% file `which erlc`
/usr/local/bin/erlc: Mach-O executable i386

I added ‘-arch i386’ to the LDFLAGS and CFLAGS in the Makefile in the c_src directory of the ESDL sources and got an i386 .so library out as needed.

Another problem is that the Mac specific Makefiles and the XCode project needed to build a .dmg specify MacOS 10.4. I am running 10.6.6 and do not have the 10.4 frameworks installed on this machine, so to build I needed to specify 10.6 or latest versions of the frameworks. This was achieved by deleting -isysroot /Developer/SDKs/MacOSX10.4u.sdk where it appears in various Makefiles, and editing the XCode project in macosx/Wings3d.xcodeproj/ to change the target to 10.6 or latest from 10.4.

That was enough to get the build to work, and to yield a .dmg containing an application bundle to install.

My first piece of fiddling has been to allow a mousepress while holding down the CMD modifier to fake a right button click if a single button mouse is being used. I changed the first clause of handle_event_0 in wings.erl to this:

handle_event_0(#mousebutton{button=But,mod=Mod}=Ev, St)
   when But == 1, Mod band ?META_BITS =/= 0 ->
   %% Define CMD-mouse as right mouse button if only 1 mouse button
   case wings_pref:get_value(num_buttons) of
      1 -> ModNoMeta = Mod bxor ?META_BITS,
         handle_event_1(Ev#mousebutton{button=3,mod=ModNoMeta}, St) ;
      Otherwise -> handle_event_1(Ev, St)
end ;