Handling instanced objects
-
Hi.
I have been using Sketchup for 3d development quite nicely but have hit a wall I am hoping you can help me overcome. In the worlds I am designing, I have the main terrain and level geometry. Then I have hundreds of objects which add variation. My problem is that for a lot of these objects, the models are the same. I would rather not create 100 instances of a trees with world coordinate vertices when I can just say there is a tree at 100.0f, 100.0f, 100.0f.
I am wondering if Sketchup supports this. Furthermore, I am wondering if it's possible to export the information about the objects.
Just to clarify, imagine I have a desert with trees. The desert terrain should be in the export but the trees should be instances, that is, there is a model references an, x, y, and z translation, scale and rotation, rather than the vertices in world coordinates.
Is this possible?
-
Just draw a vertical line "component" instancied is not sufficient ?
You can replace them at any moment by another component more complex! -
Hi,
I think chanz is asking essentially an internal question to sketchup. And the answer is yes. In sketchup component instances store a reference to the contents of the component (rather than the contents themselves) along with a transformation ( translation, rotation, scaling (+ shearing )) that is specific to the instance. chanz is also asking about exporting instance info. Instance info can be exported depending on where you are exporting your model to and how. For example kerkythe can optionally export Sk model instance based (therefore potentially much more efficiently).
-
oganocali, this is exactly what I mean. Where the transform is stored with a reference rather than the vertices in world position. What is the term for this? Component? Group? How do I add additional model instances?
Furthermore, I will be exporting them as .obj so I think the main world geometry will be in one export and then I'll have to find a way to export the instances. Does sketchup support any way of exporting a list with the model name and its translation, rotation and scaling? I'm a programmer so if I have to dig into the ruby stuff I can.
The game engine I'm loading these into was written by me so as long as I can export an instance list even in plaintext, I can utilize it.
Thanks a bunch!
-
Yes, the SketchUp entities you want are either Groups or Components. These are very similar, the main difference being whether each instance is intended to be independent (Group) or whether all instances share a common template so that editing any one of them causes the same change to propagate immediately to all the other instances (Component). From what you describe, I suspect you want Components. However, Groups are actually implemented as a special case of Components so the differences for your purpose are in details not fundamentals.
There is likely no exporter that does exactly what you want, particularly as your target is a game engine you wrote yourself. So you are indeed going to have to dig into the Ruby API and write your own. However, this should not be too difficult, as Components are implemented very much the way you want. The actual geometry (Edges and Faces) defining a Component are owned by a ComponentDefinition. Each ComponentInstance of that ComponentDefinition contains the Transformation that scales, places, and orients the instance in the model (detail: if the instance is nested inside another Component, the Transformation relates it to the enclosing Component, not to the model. In this case you have to build up the full Transformation stage by stage through the nesting).
So, give it a shot and see whether you grasp the workings of the Ruby API. If you run into trouble you should post over in the Developers' area, where you will find people with years of experience.
-
If you want a 'crib', then why not look at my [somewhat old but still working]:
http://sketchucation.com/pluginstore?pln=OBJexporter
It exports the SKP's geometry, and deals with 'containers', transformations etc...There are several 'exporters' in the PluginStore which may have additional/better clues...
Advertisement