6 min read

Creating and loading models using SketchUp

SketchUp is a free 3D modeling program, which was acquired by Google in 2006. It has been designed as a 3D modeling program that’s easier to use than other 3D modeling programs. A key to its success is its easy learning curve compared to other 3D tools.

Mac OS X, Windows XP, and Windows Vista operating systems are supported by this program that can be downloaded from http://sketchup.google.com/. Although there is a commercial SketchUp Pro version available, the free version works fine in conjunction with Papervision3D.

An interesting feature for non-3D modelers is the integration with Google’s 3D Warehouse. This makes it possible to search for models that have been contributed by other SketchUp users. These models are free of any rights and can be used in commercial (Papervision3D) projects.

Exporting a model from Google’s 3D Warehouse for Papervision3D

There are several ways to load a model, coming from Google 3D Warehouse, into Papervision3D. One of them is by downloading a SketchUp file and exporting it to a format Papervision3D works with. This approach will be explained.

The strength of Google 3D Warehouse is also its weakness. Anybody with a Google account can add models to the warehouse. This results in a variety of quality of the models. Some are very optimized and work fluently, whereas others reveal problems when you try to make them work in Papervision3D. Or they may not work at all, as they’re made of too many polygons to run in Papervision3D. Take this into account while searching for a model in the 3D warehouse.

For our example we’re going to export a picnic table that was found on Google 3D Warehouse.

  1. Start Sketch Up.
  2. Choose a template when prompted. This example uses Simple Template – Meters, although there shouldn’t be a problem with using one of the other templates.
  3. Go to File | 3D Warehouse | Get models to open 3D Warehouse inside SketchUp.
  4. Papervision3D External Models: Part 2

  5. Enter a keyword to search for. In this example that will be picnic table.
  6. Select a model of your choice. Keep in mind that it has to be low poly, which is something you usually find out by trial and error.
  7. Click on Download Model, to import the model into SketchUp and click OK when asked if you want to load the model directly into your Google SketchUp model.
  8. Place the model at the origin of the scene. To follow these steps, it doesn’t have to be the exact origin, approximately is good enough.
  9. By default, a 2D character called Sang appears in the scene, which you do not necessarily have to remove; it will be ignored during export.
  10. Because the search returned a lot of picnic tables varying in quality, there is a SketchUp file (can be downloaded from http://www.packtpub.com/files/code/5722_Code.zip). This file has a picnic table already placed on the origin. Of course, you could also choose another picnic table, or any other object of your choice.
  11. Papervision3D External Models: Part 2

  12. Leave the model as it is and export it. Go to File | Export | 3D Model. Export it using the Google Earth (*.kmz) format and save it in your assets folder.

T he file format we’re exporting to originally was meant to display 3D objects in Google Earth. The file ends with .kmz as its extension, and is actually a ZIP archive that contains a COLLADA file and the textures. In the early days of Papervision3D, it was a common trick to create a model using SketchUp and then get the COLLADA file out of the exported Google Earth file, as the Google Earth KMZ file format wasn’t still supported then.

Importing a Google Earth model into Papervision3D

Now that we have successfully exported a model from SketchUp, we will import it into Papervision3D. This doesn’t really differ from loading a COLLADA or 3D Studio file.

The class we use for parsing the created PicnicTable.kmz file is called KMZ and can be found in the parsers package. Add the following line to the import section of your document class:

import org.papervision3d.objects.parsers.KMZ;

Replace or comment the code that loads the animated COLLADA model and defines the animations from the previous example. In the init() method we can then instantiate the KMZ class, assign it to the model class property, and load the KMZ file. Make sure you have saved PicnicTable.kmz file into the assets folder of your project.

model = new KMZ();
model.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);
KMZ(model).load("assets/PicnicTable.kmz");

ExternalModelsExample

That looks familiar, right? Now let’s publish the project and your model should appear on the screen.

Papervision3D External Models: Part 2

Notice that in many cases, the downloaded and exported model from Google 3D Warehouse might appear very small on your screen in Papervision3D. This is because they are modeled with other metric units than we use in Papervision3D. Our example application places the camera at a 1000 units away from the origin of the scene. Many 3D Warehouse models are made using units that define meters or feet, which makes sense if you were to translate them to real-world units. When a model is, for example, 1 meter wide in SketchUp, this equals to 1 unit in Papervision3D. As you can imagine, a 1 unit wide object in Papervision3D will barely be visible when placing the camera at a distance of 1000. To solve this you could use one of the following options:

  • Use other units in Papervision3D and place your camera at a distance of 5 instead of 1000. Usually you can do this at the beginning of your project, but not while the project is already in progress, as this might involve a lot of changes in your code due to other objects, animations, and calculations that are made with a different scale.
  • Scale your model inside SketchUp to a value that matches the units as you use them in Papervision3D. When the first option can’t be realized, this option is recommended.
  • Scale the loaded model in Papervision3D by changing the scale property of your model.
      model.scale = 20;
  • Although this is an option that works, it’s not recommended. Papervision3D has some issues with scaled 3D objects at the time of writing. It is a good convention to use the same units in Papervision3D and your 3D modeling tool.

If you want to learn more about modeling with SketchUp, visit the support page on the SketchUp web site http://sketchup.google.com/support. You’ll find help resources such as video tutorials and a help forum.

Creating and loading models using Blender

Blender is an open source, platform-independent 3D modeling tool, which was first released in 1998 as a shareware program. It went open source in 2002. Its features are similar to those in commercial tools such as 3ds Max, Maya, and Cinema4D. However, it has a reputation of having a difficult learning curve compared to other 3D modeling programs. Blender is strongly based on usage of keyboard shortcuts and not menus, which makes it hard for new users to find the options they’re looking for. In the last few years, more menu-driven interfaces have been added.

It’s not in the scope of this article to teach you everything about the modeling tools that can be used with Papervision3D. This also counts for Blender. There are many resources such as online tutorials and books that cover how to work with Blender.

A link to the Blender installer download can be found on its web site: www.blender.org.

LEAVE A REPLY

Please enter your comment!
Please enter your name here