Scaling bug when Behavior.always_face_camera is on

Hi there,

I have an icon in my scene where I set icon_definition.behavior.always_face_camera = true. Currently it is translated and rotated in position but I would like to add scaling as well. BUT this seems to break in combination with the behavior.

Here’s roughly what I’m doing:

icon_definition = Sketchup.active_model.definitions.load(icon_path)
icon_definition.behavior.always_face_camera = true
rotation = ...
translation = ...
scale = Geom::Transformation.scaling(2)
entities.add_instance(icon_definition, rotation * translation * scale)

With any scale value other than 1 the icon will be rendered at the wrong position. It seems to me like the view is not updating as often as it should. When I disable and enable any layer it will be rendered at the right position again. But it will move wrongly when I rotate the scene.
When I set always_face_camera to false it works. My icon is at the right position at the right scale even when I move the camera.

Is this a bug in the implementation of Behavior.always_face_camera? If so can I work around that?

Why not add the definition WITH always_face_me behavior set to nil ?
THEN add the new instance, with the scaling transformation [only].
Then change the definition’s always_face_me behavior set to true ??

Hi TIG,

thanks for your suggestion. Is this the order you are suggesting?

icon_definition = Sketchup.active_model.definitions.load(icon_path)
scale = Geom::Transformation.scaling(2)
instance = entities.add_instance(icon_definition, scale)
instance.definition.behavior.always_face_camera = true

I tried this and it is still at that weird position. When I turn always_face_camera off it is located at 0,0,0 at the correct scale (as expected).

Still, scaling is unusable in combination with always_face_camera.

Any other thoughts?

Since we don’t have the component SKP or the model into which you are adding it then who can tell ?
So ideas…
If the component SKP geo-located ?
Is the component SKP’s geometry located at its model’s origin, it will rotate about that, which is also the insertion point of the instance.
Is the component SKP already set to have always_face_camera behavior true ?
If so switch it off immediately after loading the component-definition, then add the scaled instance, and then switch its behavior back on again…
Have you thought about alternatives… add the definition, make a scaling transformation and apply that to the icon_definition.entities(scale, icon_definition.entities.to_a)
Then place a instance with no scaling…
If you have various sizes using the same definition then use make_unique with each different scaling ??

Hey, thanks for your support.

The skp in question is only a single image, but I tried another simple model and it behaved just the same way.
Altering the insertion point did not make any difference.
The point in time when I set always_face_camera does not make a difference either.

Your last suggestion did the trick. I now create instances for all sizes as needed and cache the ComponentDefinitions. In each of those I alter the image entitie’s size so that I don’t need to scale it with a transformation.
This works beautifully. Thanks!