# Class: EnfEditor::EEMaterialColor

Inherits:
  Object
  - Object
  - EnfEditor::EEMaterialColor
  show all

Defined in:
  lib/enfeditor/core_ext/color_utils.rb,
  ext/enfhandler/EnfHandler_wrap2.cxx

## Overview

Proxy of C++ EnfEditor::EEMaterialColor class

## Instance Method Summary collapse

- #alpha ⇒ Array<Float>
  alpha

    Float array.

- #color_type ⇒ Symbol

  Color_type.

- #equal_material_color?(other) ⇒ Boolean

  Returns true if #color_type is same and difference of each Float values are less than zero tolerance (1.0e-12).

- #equal_material_color_alpha?(other) ⇒ Boolean

  Returns true if #color_type is :alpha or :rgba and difference of alpha values are less than zero tolerance (1.0e-12).

- #equal_rgb_color?(other) ⇒ Boolean

  Returns true if #color_type is :rgb or :rgba and difference of r,g,b values are less than zero tolerance (1.0e-12).

- #initialize(color_type, value_array) ⇒ EEMaterialColor constructor

  Create material color.

- #material_rgba ⇒ Array<Float>
  ambient-r, ambient-g, ambient-b, ambient-a, diffuse-r, diffuse-g, diffuse-b, diffuse-a, specular-r, specular-g, specular-b, specular-a, emission-r, emission-g, emission-b, emission-a, shininess

    Float array.

- #material_strength ⇒ Array<Float>
  r, g, b, a, ambient, diffuse, specular, emission, shininess

    Float array.

- #rgb ⇒ Array<Float>
  r,g,b

    Float array.

- #rgba ⇒ Array<Float>
  r,g,b,a

    Float array.

- #to_alpha ⇒ Float

  Returns color value as alpha.

- #to_rgb ⇒ Array<Float>

  Returns color value array as rgb.

- #to_rgba ⇒ Array<Float>

  Returns color value array as rgba.

## Constructor Details

### #initialize(color_type, value_array) ⇒ `EEMaterialColor`

Note:

See also #alpha, #rgb, #rgba, #material_strength and #material_rgba methods for value_array contents.

Create material color

Examples:

    # Assign color red (r=1.0, g=0.0, b=0.0) to element
    element.color = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.0])

Parameters:

- color_type (`Symbol`) —

  Valid types are :unknown, :alpha, :rgb, :rgba, :material_strength and :material_rgba.

- value_array (`Array<Float>`) —

  Color values in float array.

Since:

- 0.1.0.0

    91
    # File 'lib/enfeditor/core_ext/color_utils.rb', line 91

    'c_defined'.to_s

## Instance Method Details

### #alpha ⇒ `Array<Float>`

Note:

This API raises error if #color_type is not :alpha. 0.0 is transparent, while 1.0 is opaque.

Returns [alpha] Float array. Array size is 1. Each Float value range is from 0.0 to 1.0.

Examples:

    # Get alpha value
    color_type = element.color.color_type
    if color_type == :alpha
      p element.alpha  # => [0.5]
    else
      p element.alpha  # => raise EEError
    end

Returns:

- (`Array<Float>`) —
  alpha

    Float array. Array size is 1. Each Float value range is from 0.0 to 1.0.

Since:

- 0.1.0.0

### #color_type ⇒ `Symbol`

Returns color_type. Valid types are :alpha, :rgb, :rgba, :material_strength and :material_rgba.

Examples:

    # Get color type
    color_type = element.color.color_type
    if color_type == :rgba
      p element.rgba  # => [1.0, 0.0, 0.0, 1.0]
    elsif color_type == :alpha
      p element.alpha # => [1.0]
      p element.rgb   # => raise error because type is different
    end

Returns:

- (`Symbol`) —

  color_type. Valid types are :alpha, :rgb, :rgba, :material_strength and :material_rgba.

Since:

- 0.1.0.0

### #equal_material_color?(other) ⇒ `Boolean`

Note:

This API can be called for all #color_type.

Returns true if #color_type is same and difference of each Float values are less than zero tolerance (1.0e-12).

Examples:

    # Compare material color
    color1 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    color2 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    color3 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.4])
    color4 = EEMaterialColor.new(:rgba, [1.0, 0.0, 0.5, 1.0])
    p color1.equal_material_color? (color2) # => true
    p color1.equal_material_color? (color3) # => false
    p color1.equal_material_color? (color4) # => false

Parameters:

- other (`EEMaterialColor`) —

  Color to compare

Returns:

- (`Boolean`) —

  Returns true if #color_type is same and difference of each Float values are less than zero tolerance (1.0e-12).

Since:

- 0.1.0.0

### #equal_material_color_alpha?(other) ⇒ `Boolean`

Returns true if #color_type is :alpha or :rgba and difference of alpha values are less than zero tolerance (1.0e-12).

Examples:

    # Compare alpha value of material color
    color1 = EEMaterialColor.new(:alpha, [0.7])
    color2 = EEMaterialColor.new(:rgba, [1.0, 0.0, 0.5, 0.7])
    color3 = EEMaterialColor.new(:rgba, [0.4, 0.8, 0.4, 0.7])
    color4 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.4])
    p color1.equal_material_color_alpha? (color2) # => true
    p color2.equal_material_color_alpha? (color3) # => true
    p color4.equal_material_color_alpha? (color4) # => false

Parameters:

- other (`EEMaterialColor`) —

  Color to compare

Returns:

- (`Boolean`) —

  Returns true if #color_type is :alpha or :rgba and difference of alpha values are less than zero tolerance (1.0e-12).

Since:

- 0.1.0.0

### #equal_rgb_color?(other) ⇒ `Boolean`

Returns true if #color_type is :rgb or :rgba and difference of r,g,b values are less than zero tolerance (1.0e-12).

Examples:

    # Compare rgb value of material color
    color1 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    color2 = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    color3 = EEMaterialColor.new(:rgba, [1.0, 0.0, 0.5, 0.5])
    color4 = EEMaterialColor.new(:alpha, [1.0])
    p color1.equal_rgb_color? (color2) # => true
    p color1.equal_rgb_color? (color3) # => true
    p color4.equal_rgb_color? (color4) # => false

Parameters:

- other (`EEMaterialColor`) —

  Color to compare

Returns:

- (`Boolean`) —

  Returns true if #color_type is :rgb or :rgba and difference of r,g,b values are less than zero tolerance (1.0e-12).

Since:

- 0.1.0.0

### #material_rgba ⇒ `Array<Float>`

Note:

This API raises error if #color_type is not :material_rgba.

Returns [ambient-r, ambient-g, ambient-b, ambient-a, diffuse-r, diffuse-g, diffuse-b, diffuse-a, specular-r, specular-g, specular-b, specular-a, emission-r, emission-g, emission-b, emission-a, shininess] Float array. Array size is 17. Each Float value range is from 0.0 to 128.0 for shininess and from 0.0 to 1.0 for the others.

Examples:

    # Get color value for material_rgba type
    color_type = element.color.color_type
    if color_type == :material_rgba
      p element.material_rgba  # => [1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 128.0]
    else
      p element.material_rgba  # => raise EEError
    end

Returns:

- (`Array<Float>`) —
  ambient-r, ambient-g, ambient-b, ambient-a, diffuse-r, diffuse-g, diffuse-b, diffuse-a, specular-r, specular-g, specular-b, specular-a, emission-r, emission-g, emission-b, emission-a, shininess

    Float array.

  Array size is 17. Each Float value range is from 0.0 to 128.0 for shininess and from 0.0 to 1.0 for the others.

Since:

- 0.1.0.0

### #material_strength ⇒ `Array<Float>`

Note:

This API raises error if #color_type is not :material_strength.

Returns [r, g, b, a, ambient, diffuse, specular, emission, shininess] Float array. Array size is 9. Each Float value range is from 0.0 to 128.0 for shininess and from 0.0 to 1.0 for the others.

Examples:

    # Get color value for material_strength type
    color_type = element.color.color_type
    if color_type == :material_strength
      p element.material_strength  # => [1.0, 0.0, 0.0, 1.0, 0.5, 0.5, 0.5, 0.5, 128.0]
    else
      p element.material_strength  # => raise EEError
    end

Returns:

- (`Array<Float>`) —
  r, g, b, a, ambient, diffuse, specular, emission, shininess

    Float array.

  Array size is 9. Each Float value range is from 0.0 to 128.0 for shininess and from 0.0 to 1.0 for the others.

Since:

- 0.1.0.0

### #rgb ⇒ `Array<Float>`

Note:

This API raises error if #color_type is not :rgb.

Returns [r,g,b] Float array. Array size is 3. Each Float value range is from 0.0 to 1.0.

Examples:

    # Get color value for rgb type
    color_type = element.color.color_type
    if color_type == :rgb
      p element.rgb  # => [1.0, 0.0, 0.0]
    else
      p element.rgb  # => raise EEError
    end

Returns:

- (`Array<Float>`) —
  r,g,b

    Float array. Array size is 3. Each Float value range is from 0.0 to 1.0.

Since:

- 0.1.0.0

### #rgba ⇒ `Array<Float>`

Note:

This API raises error if #color_type is not :rgba.

Returns [r,g,b,a] Float array. Array size is 4. Each Float value range is from 0.0 to 1.0.

Examples:

    # Get color value for rgba type
    color_type = element.color.color_type
    if color_type == :rgba
      p element.rgba  # => [1.0, 0.0, 0.0, 1.0]
    else
      p element.rgba  # => raise EEError
    end

Returns:

- (`Array<Float>`) —
  r,g,b,a

    Float array. Array size is 4. Each Float value range is from 0.0 to 1.0.

Since:

- 0.1.0.0

### #to_alpha ⇒ `Float`

Note:

This API can be called for all #color_type.

Returns color value as alpha.

Examples:

    # Get alpha value for all color types.
    color = EEMaterialColor.new(:rgba, [1.0, 0.0, 0.5, 0.7])
    p color.to_alpha # => 0.7   # return alpha value
    color = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    p color.to_alpha # => 1.0   # return 1.0 for :rgb type

Returns:

- (`Float`) —

  Returns color value as alpha.

Since:

- 0.1.0.0

### #to_rgb ⇒ `Array<Float>`

Note:

This API can be called for all #color_type except :alpha.

Returns color value array as rgb.

Examples:

    # Get rgb value from color type rgba
    color = EEMaterialColor.new(:rgba, [1.0, 0.0, 0.5, 0.7])
    p color.to_rgb #=> [1.0, 0.0, 0.5]  # return rgb value
    color = EEMaterialColor.new(:alpha, [0.5])
    p color.to_rgb                      # raise EEError

Returns:

- (`Array<Float>`) —

  Returns color value array as rgb.

Since:

- 0.1.0.0

### #to_rgba ⇒ `Array<Float>`

Note:

This API can be called for all #color_type except :alpha.

Returns color value array as rgba.

Examples:

    # Get rgba value from color type rgb
    color = EEMaterialColor.new(:rgb, [1.0, 0.0, 0.5])
    p color.to_rgba #=> [1.0, 0.0, 0.5, 1.0]  # return rgba value. alpha will be 1.0
    color = EEMaterialColor.new(:alpha, [0.5])
    p color.to_rgba                      # raise EEError

Returns:

- (`Array<Float>`) —

  Returns color value array as rgba.

Since:

- 0.1.0.0