SketchUp is great. Not only is it free, but it supports Ruby as a scripting language, and provides plenty of interesting APIs and reasonable (though not very well inter-linked) documentation too. It’s long been discussed, in conjunction with Google Earth, as a potential virtual world, and rival to Second Life. While it will be fascinating to see how that develops, and whether they become more comparable over time, what interested me much more in the short term was some way of getting 3D data from SketchUp into Second Life. Dave did this recently with PowerPoint, which and it reminded me just how much I wanted to do the same thing in SketchUp.
What I really wanted was SketchUp -> Second Life exporter. I didn’t want to buy SketchUp pro (though I thought about it), because even that wouldn’t solve my problem. More recently, I saw that Blender 2.4.2 makes it possible to import SketchUp’s (proprietary, binary) .kmz file format. This is cool and potentially very useful, especially when you consider the Prim.Blender project allows you to draw SL prims and export them. Ideally, it would also do the hard work of creating simple SL style prims from the complex 3D data. This is not an easy project though, as discussed at 3pointD recently.
Eventually I gave up my search for a basic SketchUp -> Second Life exporter and realised I was going to have to write one. I’m really not a Ruby guru, but I surprised myself by knocking something up in 20 lines and no time flat. Ok, so it’s not very good, and it doesn’t bring us any closer to the nirvana of complex models being automagically generated using the minimum number of prims, but it was so easy that I’m very surprised not to be able to find anyone else taking this approach already. (Perhaps someone will fill me in it has already been done and I’ve simply missed it.)
So, what is it?
What I wrote was a short Ruby plugin for SketchUp. It writes out basic model information to a text file, allowing it to be imported again (as a notecard) into Second Life. From there, an object parses the notecard and re-generates the model in-world. It does not support the full power of SketchUp by any means, and takes some judicious short-cuts to avoid generating zillions of prims. In erring very heavily on the side of simplicity, I’ve made something that you’ll either find delightful or frustrating. Each face in your SketchUp model, you end up with a flat, rectangular prim which represents the bounds of that face. Imagine if every face of every shape in SketchUp was simplified down to a rectangle which marked it extents. That’s what my script does. It’s not perfect, but it’s a start. The interesting bit of the Ruby plugin looks something like this…
model = Sketchup.active_model file = File.new("/testfile", "w") model.active_entities.each do |entity| if entity.typename == "Face" #ignore everything but faces # (e.g. we won't pay any attention to edges, points, etc) face = entity.bounds # For now, make a rectangular prim ... ...
While it works very well for fairly basic models…
Something more complex ends up being made to look fairly ugly. Curves and non-regular faces are particularly badly hit…
Future developments will include colour/texture support, as well a bit more thought about the mapping between the SketchUp model and Second Life prims. I’m sure there are loads of things that can be done to improve it. I’m already enjoying it as a faster way to put simple things together though.