ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Material

Inherits:
ModraUp::Entity show all

Overview

A material: name, color, transparency, and an optional texture. The parent class is ModraUp::Entity, not a Drawingelement. Textured shading is done using #colorize_type (COLORIZE_SHIFT / COLORIZE_TINT).

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.color = [255, 0, 0]
mat.is_a?(ModraUp::Entity)  #=> true

Constants # collapse

ModraUp::Material::MATERIAL_SOLID

MATERIAL_SOLID = 0

ModraUp::Material#materialType: Solid color.

Returns:

  • (Integer)

Examples:

ModraUp::Material::MATERIAL_SOLID  #=> 0
ModraUp::Material::MATERIAL_TEXTURED

MATERIAL_TEXTURED = 1

ModraUp::Material#materialType: Textured.

Returns:

  • (Integer)

Examples:

ModraUp::Material::MATERIAL_TEXTURED  #=> 1
ModraUp::Material::MATERIAL_COLORIZED_TEXTURED

MATERIAL_COLORIZED_TEXTURED = 2

ModraUp::Material#materialType: colored textured material.

Returns:

  • (Integer)

Examples:

ModraUp::Material::MATERIAL_COLORIZED_TEXTURED  #=> 2
ModraUp::Material::COLORIZE_SHIFT

COLORIZE_SHIFT = 0

ModraUp::Material#colorize_type: Colorize by hue shift (official default).

Returns:

  • (Integer)

Examples:

ModraUp::Material::COLORIZE_SHIFT  #=> 0
ModraUp::Material::COLORIZE_TINT

COLORIZE_TINT = 1

ModraUp::Material#colorize_type:Colorize by target hue. When setting #color= for a material with a texture, the hue will be adjusted accordingly.

Returns:

  • (Integer)

Examples:

ModraUp::Material::COLORIZE_TINT  #=> 1

Instance Method Summary # collapse

Inherited from ModraUp::Entity

Instance Method Details

#hatch_pattern ⇒ ModraUp::HatchPattern, nil

Read the hatch pattern of the material: returns the section fill pattern used for sections of groups and components (including nested content that inherits this material).

Returns:

  • (ModraUp::HatchPattern, nil)

Examples:

material = ModraUp.active_model.materials.first
material.hatch_pattern if material

#hatch_pattern=(hatch_pattern) ⇒ ModraUp::HatchPattern, nil

Sets the material's hatch pattern; nil removes the pattern.

Parameters:

  • hatch_pattern (ModraUp::HatchPattern, nil) The hatch pattern of this model.

Returns:

  • (ModraUp::HatchPattern, nil)

Raises:

  • [ArgumentError] The hatch pattern belongs to another model.

Examples:

model = ModraUp.active_model
material = model.materials.first
material.hatch_pattern = model.hatch_patterns.first if material

material.name ⇒ String

Internal unique name. Interface display uses #display_name.

Returns:

  • (String)

Examples:

ModraUp.active_model.materials.add("[Joe]").name  #=> "[Joe]"

material.name=(name) ⇒ name

Rename. Throws an error if the name already exists for another material.

Parameters:

  • name (String)

Returns:

  • (String)

Raises:

  • [ArgumentError] Name is empty or already in use

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.name = "Crimson"

material.display_name ⇒ String

Display name. Remove square brackets when the name is in the format [Joe].

Returns:

  • (String)

Examples:

ModraUp.active_model.materials.add("[Joe]").display_name  #=> "Joe"

material.write_thumbnail(path, max_size) ⇒ Boolean, nil

Write the material's color or texture thumbnail to an image file while maintaining the aspect ratio.

Parameters:

  • path (String) Output file path
  • max_size (Integer) Maximum edge length (pixels)

Returns:

  • (Boolean, nil) Returns true if writing is successful, false if it fails, and nil if the parameter is invalid.

Examples:

mat = ModraUp.active_model.materials.add("Oak")
mat.write_thumbnail(File.join(ModraUp.temp_dir, "oak.png"), 128)

material.color ⇒ ModraUp::Color

Material color.

Returns:

  • (ModraUp::Color)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.color = [255, 0, 0]
mat.color.red  #=> 255

material.color=(color) ⇒ color

Set the color. Accepts ModraUp::Color or [r, g, b] (0–255).

Parameters:

  • color (ModraUp::Color, Array<Numeric>)

Returns:

  • (ModraUp::Color, Array<Numeric>)
Note: ModraUp extension. ModraUp::Color#alpha does not write to the material; use transparency with #alpha=.

Examples:

ModraUp.active_model.materials.add("Joe").color = ModraUp::Color.new(0, 128, 0)

material.alpha ⇒ Float

Opacity, 0.0–1.0.

Returns:

  • (Float)

Examples:

ModraUp.active_model.materials.add("Joe").alpha  #=> 1.0

material.alpha=(value) ⇒ value

Set opacity, values outside the 0–1 range will be clamped.

Parameters:

  • value (Numeric)

Returns:

  • (Numeric)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.alpha = 0.5

material.use_alpha? ⇒ Boolean

Returns true if the material's opacity is less than 1.

Returns:

  • (Boolean)
Note: ModraUp extension. Does not decode patch image pixel alpha.

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.alpha = 0.5
mat.use_alpha?

material.texture ⇒ ModraUp::Texture, nil

Texture. Returns nil if no texture is set.

Returns:

  • (ModraUp::Texture, nil)

Examples:

ModraUp.active_model.materials.add("Joe").texture  #=> nil

material.texture=(filename) ⇒ filenamematerial.texture=(properties) ⇒ propertiesmaterial.texture=(texture) ⇒ texturematerial.texture=(nil) ⇒ nil

Set the texture. nil clears it. The path reads in raw bytes; the default tile size is 10x10 inches. The array format is [filename, width, height].

Untextured materials use the average texture color for image decoding success, displaying as a solid color; existing textures retain their color.

Parameters:

  • arg (String, Array, ModraUp::Texture, nil)

Returns:

  • (Object)

Raises:

  • [ArgumentError] Failed to read file
Note: ModraUp extension. Does not accept ImageRep; retains the original material color when no image decoding host is available.

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.texture = nil

material.materialType ⇒ Integer

MATERIAL_SOLID / MATERIAL_TEXTURED / MATERIAL_COLORIZED_TEXTURED。

Returns:

  • (Integer)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.materialType == ModraUp::Material::MATERIAL_SOLID

material.colorize_type ⇒ Integer

COLORIZE_SHIFT or COLORIZE_TINT. Readable even without a texture; defaults to SHIFT.

Returns:

  • (Integer)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.colorize_type == ModraUp::Material::COLORIZE_SHIFT

material.colorize_type=(type) ⇒ type

Sets the coloring method. Only accepts COLORIZE_SHIFT / COLORIZE_TINT.

Parameters:

  • type (Integer)

Returns:

  • (Integer)

Raises:

  • [ArgumentError] must be 0 or 1

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.colorize_type = ModraUp::Material::COLORIZE_TINT

material.colorize_deltas ⇒ Array(Float, Float, Float)

HLS delta from texture average color to material color: hue (degrees), saturation, lightness. Returns [0, 0, 0] when there is no texture or the pixels cannot be solved.

Returns:

  • (Array<Float>)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat.colorize_deltas.length  #=> 3

material == other ⇒ Boolean

Returns true if the same model and slot are identical.

Parameters:

  • other (Object)

Returns:

  • (Boolean)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
mat == ModraUp.active_model.materials["Joe"]