ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Texture

Inherits:
ModraUp::Entity show all

Overview

Texture mapping. Obtain from ModraUp::Material#texture. Parent class is ModraUp::Entity, not ModraUp::Drawingelement.

#width / #height are tile inches; #image_width / #image_height are pixels. #image_rep / #write(colorize) uses host PNG/JPEG decoding.

Examples:

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

Instance Method Summary # collapse

Inherited from ModraUp::Entity

Instance Method Details

texture.filename ⇒ String

Texture path. This retains the string passed to ModraUp::Material#texture=.

Returns:

  • (String)

Examples:

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

texture.width ⇒ Float

Tile width, inches.

Returns:

  • (Float)

Examples:

mat = ModraUp.active_model.materials.add("Joe")
# mat.texture = "wood.png" after assigning the texture
# mat.texture.width == 10.0

texture.height ⇒ Float

Tile height, inches.

Returns:

  • (Float)

Examples:

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

texture.image_width ⇒ Integer

Image pixel width. Read from the PNG/JPEG header; defaults to 0 if not readable.

Returns:

  • (Integer)

Examples:

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

texture.image_height ⇒ Integer

Image pixel height. Read from the PNG/JPEG header; returns 0 if not readable.

Returns:

  • (Integer)

Examples:

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

texture.average_color ⇒ ModraUp::Color, nil

The average RGB values of the decoded pixels. Returns nil if decoding fails.

Returns:

  • (ModraUp::Color, nil)

Examples:

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

texture.image_rep ⇒ ModraUp::ImageReptexture.image_rep(colorized) ⇒ ModraUp::ImageRep

Decodes to a ModraUp::ImageRep. If colorized is true and the material is colored, it applies HLS colorization (SHIFT/TINT) as defined by ModraUp::Material#colorize_type.

Parameters:

  • colorized (Boolean) Default false

Returns:

  • (ModraUp::ImageRep)

Raises:

  • [RuntimeError] The texture has been deleted or cannot be decoded

Examples:

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

texture.size = inches ⇒ inchestexture.size = [width, height] ⇒ [width, height]

Set the tile inch size. Use a single value to scale by the width while maintaining the aspect ratio; use an array to set the width and height separately.

Parameters:

  • value (Numeric, Array<Numeric>)

Returns:

  • (Numeric, Array<Numeric>)

Examples:

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

texture.write(path) ⇒ Booleantexture.write(path, colorize) ⇒ Boolean

Write the texture file. If colorize is false or the material is not colored, write the bytes as is; if the material is colored and colorize is true, decode the bytes, then apply HLS colorization as specified by ModraUp::Material#colorize_type and re-encode.

Parameters:

  • path (String)
  • colorize (Boolean) Default false

Returns:

  • (Boolean)

Examples:

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

texture.valid? ⇒ Boolean

Returns true if the material still has a texture.

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.materials.add("Joe").texture.nil?