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.
For this example, I was defining my scene nodes in the COLLADA file like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<library_visual_scenes> <visual_scene id="VisualSceneNode"> <node name="surfaces"> <instance_geometry url="#surfaces-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-fx-surfaces" target="#mat-fx-surfaces"/> </technique_common> </bind_material> </instance_geometry> </node> <node name="pattern-0_Pattern-1"> <instance_geometry url="#pattern-0_Pattern-1-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-pattern-0_Pattern-1" target="#mat-pattern-0_Pattern-1"/> </technique_common> </bind_material> </instance_geometry> </node> <node name="origin-pattern-0_Pattern-1"> <instance_geometry url="#origin-pattern-0_Pattern-1-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-origin-pattern-0_Pattern-1" target="#mat-origin-pattern-0_Pattern-1"/> </technique_common> </bind_material> </instance_geometry> </node> </visual_scene> </library_visual_scenes> <scene> <instance_visual_scene url="#VisualSceneNode"/> </scene> |
When imported into SketchUp, this COLLADA file results in one big component which look like this:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<library_nodes> <node id="surfaces"> <instance_geometry url="#surfaces-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-fx-surfaces" target="#mat-fx-surfaces"/> </technique_common> </bind_material> </instance_geometry> </node> <node id="pattern-0_Pattern-1"> <instance_geometry url="#pattern-0_Pattern-1-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-pattern-0_Pattern-1" target="#mat-pattern-0_Pattern-1"/> </technique_common> </bind_material> </instance_geometry> </node> <node id="origin-pattern-0_Pattern-1"> <instance_geometry url="#origin-pattern-0_Pattern-1-lib"> <bind_material> <technique_common> <instance_material symbol="mat-sym-origin-pattern-0_Pattern-1" target="#mat-origin-pattern-0_Pattern-1"/> </technique_common> </bind_material> </instance_geometry> </node> </library_nodes> <library_visual_scenes> <visual_scene id="VisualSceneNode"> <node id="surfaces"> <instance_node url="#surfaces"/> </node> <node name="pattern-0_Pattern-1"> <instance_node url="#pattern-0_Pattern-1"/> </node> <node name="origin-pattern-0_Pattern-1"> <instance_node url="#origin-pattern-0_Pattern-1"/> </node> </visual_scene> </library_visual_scenes> <scene> <instance_visual_scene url="#VisualSceneNode"/> </scene> |
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:
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!
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
Each thing you want to be its own component needs to have an <instance_node> and then they need to be added to the <library_nodes> section. That’s what this post is about. Am I misunderstanding your question?
I’ll email you an example of an export from my software.
Thanks Andy, appreciate the reply and email. In case anyone doesn’t get it first time like me, I have put a visual guide of the required structure in this post.
https://forums.sketchup.com/t/importing-collada-dae-with-multiple-geometries-objects/129675
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.
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.
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?