Change back face color

Hi Guys,
I have created a viewer for sketchup model in virtual reality. That viewer doesn’t draw back face.
I want to alert Sketchup plugin users about back face in the model by changing the color of face to let say red. How can I change the color through ruby API not through Sketchup UI?

A face has a backface color if !face.back_material.nil? (when iterating over mixed entities take care that other entity types do not respond to the method back_material).

I’m not sure if users like their models to be altered, exporting is usually an action that produces a new file, but leaves the current data unchanged. Your extension should focus on doing one thing and doing it well.

You can show a report about backfaces if there are any found. It’s the users’ responsibility to find and fix them, and there exist other tools specialized in that. If you really want to do this (and don’t want to develop a more complicated tool that highlights faces with OpenGL without changing their material), you should at least make it an option. If backfaces are found, report it to the user and ask whether the user wishes them to be painted.

It’s a rendering option.

ro = Sketchup.active_model.rendering_options
ro.each{|o| puts"#{o} = \t#{ro[o]}" }

There are many things you can read and write…
In this case you want:
which will be something like
Color( 60, 130, 255, 255)
Remember it to a variable:
bfc = ro['FaceBackColor']
and then change it temporarily:
ro['FaceBackColor'] = 'red'
or whatever color you want.
Remember that as your tool exits to reset it with:
ro['FaceBackColor'] = bfc
Otherwise the user will be displeased that his model settings have been messed up by you!

1 Like

And be aware that changing rendering options (or even painting faces) changes the model and adds unnecessary operations to the undo stack. If it is not a natural goal of your tool to modify the model (like a drawing tool would do), there is a trick to keep the undo stack clean: Group temporary operations into a single operation (model.start_operation(…)) and abort the operation (model.abort_operation) when the temporary changes are not needed anymore.

1 Like

… and, when using rendering options “FaceBackColor”, the user needs to switch to monochrome render mode to see if any faces are reversed. (The user might have painted a material upon the back of faces unknowingly.)

To switch to monochrome mode …

def monochrome
  ro = Sketchup.active_model.rendering_options
  @render_mode = ro["RenderMode"]
  ro["RenderMode"]= 5

… and then to restore afterward …

def restore_render_mode
  Sketchup.active_model.rendering_options["RenderMode"]= @render_mode

Thank you all @DanRathbun @Aerilius @TIG

1 Like