in Code

COLLADA Files and SketchUp Component Hierarchies

One of the formats my bloodstain pattern analysis software will export data to is COLLADA. COLLADA is an open format used to exchange 3D scene data between software packages. It is an XML format, meaning it’s readable in a text editor, but it is extremely verbose and not a simple thing to understand unless you know what you’re looking at [and even then…]. Before using it for my current work, I’d used COLLADA with an internal version of the Torque game engine at GarageGames, so I had some familiarity with the format before using it this time.

SketchUp is a powerful free modelling tool from Google. As with any software importing COLLADA, some of the concepts in the format map to concepts within the software, while others do not. One of the things that was not obvious to me when I started exporting COLLADA files for use in Google SketchUp was how to set up my COLLADA so it had hierarchical components upon import. My scenes always showed up as one monolithic component which meant that modifying parts of it to add textures or colours was not easy.

For the bloodstain analysis work, I only have to deal with simple scenes consisting of planar surfaces and lines.

SketchUp COLLADA Import Example

SketchUp COLLADA Import Example

For this example, I was defining my scene nodes in the COLLADA file like this:

When imported into SketchUp, this COLLADA file results in one big component which look like this:

SketchUp Without Component Hierarchy

SketchUp Without Component Hierarchy

You’ll notice that the surfaces and lines are all one component called <skpi8o43Q>. This makes the scene a lot more difficult to work with in SketchUp since you can’t deal with the lines and surfaces separately.

I discovered that a small change in my COLLADA output would allow SketchUp to create multiple components when imported. Essentially SketchUp will create a component for each node that is instanced using <instance_node> and the <library_nodes> section [SketchUp component == instanced geometry]. In retrospect this makes a lot of sense, but it was not obvious when I wrote the first exporter which is why I am writing this up. I am sure someone else will face the same dilemma at some point.

So to fix this, I changed my COLLADA exporter to produce this:

All I have done is create a new <library_nodes> section and moved my nodes in there, then declared them as instances in the <visual_scene> using the <instance_node> element. Quite a simple fix.

Now when I import the COLLADA file into SketchUp, I get my scene with hierarchical components:

SketchUp With Component Hierarchy

SketchUp With Component Hierarchy

This allows me to modify the individual components of the scene – for example change colours or add textures. I haven’t been able to set up my COLLADA export to create multiple top-level components and I suspect this is a limitation of SketchUp. It is possible that in SketchUp’s view of the world, each COLLADA import is a single hierarchical component.

Another thing I have yet to figure out is if it is possible to modify the COLLADA so that SketchUp will use node names I assign. Component <skpGLOKN3> with <Component#1>, <Component#2>, and <Component> as its children is not exactly descriptive. I expected SketchUp to pull the name attribute from the instance node in the COLLADA file so the component names make more sense, but it does not. I suspect SketchUp simply doesn’t support this, but if anyone knows how to do it I’d appreciate it if you could let me know!

Leave a Reply for Al Schade Cancel Reply

Write a Comment

Comment

  1. Hi Andy, found this post after a ton of searching… did you determine how much of the xml is required to ensure the objects are split apart?

    Could you please post the full collada file somewhere? I am trying to replicate your success (ref: my github notes). Thanks

    e.g.

    <instance_material symbol

  2. When you have the model in Sketchup, if you keep double clicking the model, doesn’t it break down into the indivual geometry?

    Correct – you can select the lines you want then make a group or component out of them out of them by right-clicking and using the context menu. My goal is to make the exported COLLADA as useful as possible “as-is” so that those with limited experience can still take advantage of SketchUp or other modelling software.

    Could you do that with a ruby file in Sketchup?

    I suppose it might be possible, but it seems like a lot more trouble than it’s worth to get component names. SketchUp really should be respecting the names given in the file…

    There seems to be all sorts of things the SketchUp importer doesn’t handle, so for me it’s a matter of reverse engineering what they actually do and then to play to that while maintaining the compatibility of the .dae file with other tools that handle them better such as Apple Preview. COLLADA is a complex format, so I’m not surprised every tool seems to have problems with different aspects of it.

  3. Very Nice. I guess it depends on what you use the exported files for, if it even needs all of the naming conventions exported with it. I work with Robert Johnson and we are working on Importing your HemoSpat info into Sketchup and than export into Unity.
    In that instance, it is a demonstartive exibit used to show area of origin during real time walk throughs for trial purposes. Your HemoSpat software holds the background information necassary to prove the accurracy and intregrity of the information. So I’m not sure your exporter really needs to forward that information also.
    “This allows me to modify the individual components of the scene – for example change colours ”
    When you have the model in Sketchup, if you keep double clicking the model, doesn’t it break down into the indivual geometry? You can just regroup it in Sketchup as you see fit. Although I agree if it is already exported in groups/componants, it is a nice time saving feature.
    “I expected SketchUp to pull the name attribute from the instance node in the COLLADA file ”
    Could you do that with a ruby file in Sketchup?