Class: EnfEditor::EEMaterialColor

Inherits:
Object
  • Object
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

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

#alphaArray<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_typeSymbol

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:

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:

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:

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_rgbaArray<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_strengthArray<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

#rgbArray<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

#rgbaArray<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_alphaFloat

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_rgbArray<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_rgbaArray<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