I'm a Render Engine developer, how can I support Skatter?

Scattered instances are stored in an hash/array structure which can be read by render engines (or anyone for that matter). This is very similar to parsing the model and reading the transformation of regular Component Instances. This allows users to render hundreds of thousands of instances without overloading Sketchup.

The hash is in a shared namespace called Common, and its name is render_instances.

It is structured like so:

	Sketchup.active_model.definitions.entityID => { 
		plugin_name => {
			comp_def => [
				{:transformation => trans1, :material => mat1},
				{:transformation => trans2, :material => mat2},
  • Sketchup.active_model.definitions.entityID is used to differentiate models on OSX, as we can have multiple models opened in one Sketchup instance

    • plugin_name is the plugin's name, in this case "skatter". This level is necessary so we don't overwrite each other's data

    • comp_def is the Sketchup::ComponentDefinition of the scattered object. Each item of this array is an individual instance generated by Skatter.

      • :transformation is a Geom::Transformation that represents the instance's transform

      • :material is a Sketchup::Material assigned to the instance. If this is not defined or nil, simply consider this instance as having the default material applied to it, just like a regular Component Instance.

Reading this in Ruby is pretty simple:

modelID = Sketchup.active_model.definitions.entityID

if defined?(Common.render_instances) && Common.render_instances[modelID]
	for plugin_name, definitions in Common.render_instances[modelID]
		for definition, instances in definitions 
			for instance in instances
				transform = instance [:transformation]
				material = instance [:material]
				# Then do your stuff using definition, transform and material...

Additionally, you can add an observer to the Common module, and Skatter will call it every time it updates. It is useful if you are doing Real Time rendering.

class MyObserver
	def on_render_instances_updated(model_id, plugin_name, definition)
		puts model_id.to_s + " -> " + plugin_name + " -> " + definition.name
		data = Common.render_instances[model_id][plugin_name][definition]
	  # Then do your stuff...


If you have any question or need a NFR license to test your implementation with Skatter, contact us at skatter@lindale.io.

This is an open protocol, so if other plugins use it, you will automatically support them as well.

Last updated