Module: SkippyLib::Image

Defined in:
modules/image.rb

Overview

Since:

  • 3.0.0

Class Method Summary collapse

Class Method Details

.clone_material(image, name: nil, force: false) ⇒ Sketchup::Material

Parameters:

  • image (Sketchup::Image)

Returns:

  • (Sketchup::Material)

Since:

  • 3.0.0

SketchUp:

  • 2018



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'modules/image.rb', line 13

def self.clone_material(image, name: nil, force: false)
  definition = self.definition(image)
  material_name = name || "Copy of #{definition.name}"
  model = image.model
  # Reuse existing materials if it exists. Only checking for existing names.
  if force
    material = model.materials[material_name]
    return material if material
  end
  # Note that materials.add create unique names on demand.
  material = model.materials.add(material_name)
  # rubocop:disable SketchupSuggestions/Compatibility
  material.texture = image.image_rep
  # rubocop:enable SketchupSuggestions/Compatibility
  material
end

.definition(image) ⇒ Sketchup::ComponentDefinition

Parameters:

  • image (Sketchup::Image)

Returns:

  • (Sketchup::ComponentDefinition)

Since:

  • 3.0.0



33
34
35
36
37
# File 'modules/image.rb', line 33

def self.definition(image)
  image.model.definitions.find { |definition|
    definition.image? && definition.instances.include?(image)
  }
end