Rapid Content Production with Google SketchUp by nwr27961


									Rapid Content Production
with Google SketchUp

                                       Chris Roby
             Lead Technical Designer, Destineer Studios
                                     Scott Jacobs
                   Lead Programmer, Destineer Studios
•   What is SketchUp?
•   Advantages
•   Traditional Content Pipeline
•   Leveraging Existing Pipelines
•   Ruby-based API Overview
•   Extending with C++
•   Weaknesses
•   3rd Party Plugins / Exporters
•   Who Else is Using SketchUp
         What is SketchUp?
• 3d modeling software for both the PC and Mac
            Why SketchUp
• Cost – Free / Pro $500
• Obviously not a replacement for traditional
  3d modeling software, however cost is
  significantly less
• 3ds Max – ~3-4k
• Easy to learn / Low barrier to entry
• Great online video tutorials and step-by-
  step in-application tutorials
  – sketchup.google.com/training
• Intuitive tool concepts
  – Inference system allows people to model in
  – Intuitive tools such as push/pull
     Reusability and Sharing
• Components system (instance objects)
  – Component cutters
     Stock Art for Prototyping
• Google Warehouse
               Model Export
•   3D Studio - .3ds
•   Autodesk FBX - .fbx
•   Softimage XSI - .xsi
•   Alias Wavefront - .obj
•   Collada - .dae
•   Google Earth - .kmz (collada zip)
•   Autocad - .dwg & .dxf
•   VRML- .wml
             Model Import
• 3D Studio - .3ds
• Autocad - .dwg & .dxf
• Digital Elevation Model - .dem

• Not a lot of choices!
• Note: Google Earth will export to
   Traditional Content Pipeline
• Photoshop or
  Illustrator 2d maps
  handed off to the art
   Traditional Content Pipeline
• Brush / BSP in-game design tools
• Advantage to being all in-game
       Issues with Traditional
• Required full-featured engine in ordered to
  get started on the concept and prototype
• Designing own tools is a long process and
  often suffer from usability issues
• No mesh creation
   Leverage Existing Pipelines
• Use existing export formats to get content into
  game engines
   Leverage Existing Pipelines
• SketchUp video puzzle walkthrough
• Crysis game video of same space
  Issues with Existing Pipelines
• Managing multiple software packages
• Reduced iteration time
• Potential quirks:
   – material problems
     (1 material per face)
   – Smoothing groups
     not being saved
   – Geometry color and
     name not being
• 1 model at a time
• Aligning the scene back
  up in the game engine
      SketchUp Extendibility
• SketchUp can be extended to produce
  custom content pipelines
  – Ruby API
  – HTML interface
  – C++ SDK
       SketchUp Extendibility
• Video illustrating rapid content prototyping
   Ruby-based API Overview
• Ruby benefits
  – Easy to pick up
  – Good online documentation and community
    • http://code.google.com/apis/sketchup/
    • http://www.sketchucation.com/forums/scf/viewforu
  – Easy to extend with C++
    • Obtain headers from Ruby 1.8
  – Extremely expressive
    (less lines of code = less code to debug)
       Ruby-based API Overview
• A simple class hierarchy describes the
  geometric primitives.


Edge    Face   ComponentInstance    ComponentDefinition   Group
               Ruby-based API Overview
    • Geometry and materials can be created
      queried and modified
# extract geometry from the selected component
selectedComponent = Sketchup.active_model.selection[0]
# Collect all the faces in the component since they are the visible geometry
faces = selectedComponent.definition.entities.find_all { |entity| Sketchup::Face == entity.class }
# Each face can be turned into a polygonal mesh consisting of at least one triangle.
faces.each do |face|
   material = face.material
   faceMesh = face.mesh(5) # Arg passes flags to control additional vertex attributes. 5 == normals + front facing Uvs
   faceMesh.polygons.each do |polygon|
      (1..faceMesh.count_points).each do |index|
         point = faceMesh.point_at(index)
         uv = faceMesh.uv_at(index,true) #true means get the front-face uvs
         normal = faceMesh.normal_at(index)

#extract details from a Sketchup material
if (material && material.texture)
            textureFilename = material.texture.filename
            textureWidth = material.texture.image_width
            textureHeight = material.texture.image_height
color = material.color # A Color object from which rgb is available
alpha = material.alpha
   Ruby-based API Overview
• Observers provide the mechanism for
  reacting to events within SketchUp
  – SelectionObserver
    • Adding, removing, clearing selections
  – AppObserver
    • New files, opening files, quitting
  – EntitiesObserver
    • Geometry is added or removed
   Ruby-based API Overview
• Implement methods from the Tool
  interface to create a new tool
  – Custom tools can:
    • respond to mouse clicks, movement, keyboard
      input, and modifier keys
    • draw simple elements
    • create and destroy geometry
    • retrieve, store, and modify elements of attribute
                  HTML UI
• SketchUp provides
  Ruby to Javascript
• UIs can be built with
  HTML & Javascript
  to modify SketchUp
  content through the
  Ruby API
                     HTML UI
• Most of the capabilities
  from a modern AJAX
  web site can be
• Take advantage of
  existing Javascript
  libraries to produce UI
• Don’t need to be a
  professional web
                                      HTML UI
• Ruby
dialog = UI::WebDialog.new("title", true)
dialog.set_file(Sketchup.find_support_file("dialog.html", "UI/html"))
dialog.add_action_callback(“myCallback") { |dialog, parameters|
   #Do something with the parameters, passed as a string.

• HTML / Javascript
<script type=“text/javascript”>
<function someFunc() {
     window.location = 'skp:myCallback@' + parameter
// -->
<input type="text" name=“name1" id=“id1" onChange=“someFunc('mod_path')"></input>
         Extending with C++
• Allows for direct interface with game
• Expose game engine classes to Ruby and
  they become available in SketchUp
  – Build DLLs with the Ruby 1.8 distribution
                    Extending with C++
class MyClass
   void Method(const char *str);

//typedef and subsequent reinterpret_casts were inspired by
//I suspect that VC 8.0 must be more picky about the automatic conversion from ... to VALUE (or whatever)
//Perhaps this is fixed in rubys > 1.8.0, but I need 1.8.0 for Sketchup 6
typedef VALUE (*RUBY_METHOD_CALL)(...);

static VALUE rubyclass_MyClass;

static VALUE myclass_new(VALUE Class)
   MyClass* myInstance = new MyClass();
   VALUE rubyInstance = Data_Wrap_Struct(Class, 0, myclass_delete, myInstance);
   rb_obj_call_init(rubyInstance, 0, NULL);
   return rubyInstance;
                    Extending with C++
static VALUE myclass_delete(VALUE self, VALUE parameter)
   MyClass *myInstance = NULL;
   Data_Get_Struct(self, MyClass, myInstance);
   delete myInstance;

static VALUE myclass_method(VALUE self, VALUE parameter)
   MyClass *myInstance = NULL;
   Data_Get_Struct(self, MyClass, myInstance);
   const char *str = StringValuePtr(parameter);
   return self;

__declspec(dllexport) void Init_MyEngine()
   rubyclass_MyClass = rb_define_class("MyClass", rb_cObject);
   rb_define_singleton_method(rubyclass_MyClass, "new", reinterpret_cast<RUBY_METHOD_CALL>(myclass_new),
   rb_define_method(rubyclass_MyClass, "method", reinterpret_cast<RUBY_METHOD_CALL>(myclass_method), 1);
        SketchUp C++ SDK
• Alternate route for producing exporters
• Allows for direct import of SketchUp data
  into game engines
                                       Unit Testing
• Unit Testing
        – Ruby-1.8’s test framework can be used
          directly in SketchUp
require 'test/unit'
require 'MyClass'

class MyClassTest < Test::Unit::TestCase

      def test_creation
          myInstance = MyClass.new()

require 'test/unit/ui/console/testrunner'
runner = Test::Unit::UI::Console::TestRunner.new(DESketchupTest, Test::Unit::UI::Console::TestRunner::NORMAL,
                                   Unit Testing
• Unit Testing
        – Ruby-1.8’s test framework can be used
          directly in SketchUp
# Passed to the unit test runner so results are written to SketchUp’s console.
class SketchupConsoleOutput
    def puts s
        print s.to_s + "\n"

      def write s
          print s

      def flush
          # The testrunner expects to be able to call this method on the supplied io object.
• No native support for batch processing,
  however SketchUp can load and run ruby
  files in the plugins directory
  – Files which perform specific operations can
    be copied into place and removed when done
• SketchUp as
  game editor
• SketchUp as
  a game
• Poor content management tools
  – All models and textures are stored in the skp
    file (No way to do true xref)
  – No large scale content management system,
    each component must be refreshed one at a
  – This leads to a huge problem with #’s
  – Highly recommend coding a solution for this if
    using SketchUp in a team environment
• No “material system” and/or shader
  support (Only 1 material per object)
• Outliner – refreshes on each component
• Layer system – confusing and just barely
  gets the job done
           Production Tips
• Unify naming of layers as soon as possible
• Use 3d text and the notation system where
  ever possible
• Try to be consistent on thumbnails
 3rd Party Plug-ins & Exporters
• Sketchy Physics –
• LightUp – www.light-up.co.uk
• PlayUp – www.playuptools.com
• UT Exporter
• .X Exporter
   Who Else is Using SketchUp
• Architects &
• Movie Industry – 3D
  mock-ups of some of
  the Serenity interiors
• Game Industry
   – Destineer Studios
   – Lionhead Studios
   – Massive Black

To top