Assign a texture to a face is displaying the average color


#1

Hello,

Sorry for my english

I have to create a material and add it a texture through Ruby API.

When i assign the material to a face, it displays the average color of the texture. At contrary, when i colorize a face through UI with the same material (from my code), it works fine.

Here is my code

    model = Sketchup.active_model
    materials = model.materials
    material = materials.add("test")
    material.texture = params.to_s #path to texture
    material.texture.size = 160.mm

    for parent_entity in model.entities
        if parent_entity.is_a? Sketchup::ComponentInstance
            definition = parent_entity.definition
            for entity in definition.entities
                if entity.is_a? Sketchup::Face
                    entity.material="test"
                    entity.back_material="test"
                end
            end
        end
    end

Any idea ?

Thank you for you help


#2

I just found a solution

Sketchup.send_action "renderTextures:"

++


#3

It is preferable to set the rendering options via:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/renderingoptions


Texture rendering is controlled via “Texture” attribute, which can be true|false

ropts = Sketchup.active_model.rendering_options
ropts["RenderMode"]=2
ropts["Texture"]=true

The “RenderMode” values are:

0 = Wireframe
1 = HiddenLine
2 = Shaded
5 = Monochrome

XRay mode is controlled via “ModelTransparency” which can be true|false


Show back dashed edges mode is controlled via “DrawBackEdges” which can be true|false (This only works for SketchUp v15+)


:bulb:


#4

Could this also be related to this method in the API?

Material.colorize_type=

Maybe if you try one of the two options it will work as well.