I create a piston-like object with the ruby API (i.e. two cylinders that slide inside of each other).
I do this by first creating a Circle (circle = Entities::add_circle), then adding a face to it the resulting edges (face = Entities::add_face(circle)) and the pushpulling it (face.pushpull(length)).
This will create a simple cylinder, which I want to color in dynamically (i.e. around once per frame).
Unfortunately, this slows the simulation, I have running, down a lot (about 10 fps drop per cylinder). Inside the simulation there are a few much more complex bottle structures, which work much quicker.
Investigating the problem, I found out, that the bottle structures are loaded via an .skp file and calling entity.definition.entities reveals, that the only have two entities that are being colored in. On the other hand, the cylinders I create with the Ruby API have almost 100 entities, which all have to be colored. I assume that this is where the performance is going away.
Is there a way to “squash” all the entities of my object into one contiguous face that can be colored? Might it bring performance improvements, if I would create an .skp file for the cylinders?
This is how I create the cylinders
def create_cylinder(name, diameter)
definition = Sketchup.active_model.definitions.add(name)
circle_edgearray = definition.entities.add_circle(@center,
face = definition.entities.add_face(circle_edgearray)
face.pushpull(-2 * @length / 3, false)
and then, in order to render it correctly, I create a component instance
return @entity if @entity
translation = Geom::Transformation.translation(@center)
rotation_angle = Geometry.rotation_angle_between(Geometry::Z_AXIS,
rotation_axis = Geometry.perpendicular_rotation_axis(Geometry::Z_AXIS,
rotation = Geom::Transformation.rotation(@center,
transformation = rotation * translation
entity = Sketchup.active_model.active_entities.add_instance(@definition,
changing the color is done like this:
@entity.definition.entities.each do |ent|
if ent.material != color
ent.material = color
ent.material.alpha = 1.0
A skp file of the bottle model is attached.
5-small-single-bottle(23cm).skp (26.7 KB)