Class: Stagecraft::Materials::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/stagecraft/materials/material.rb

Direct Known Subclasses

PBR, Shader, Unlit

Constant Summary collapse

SIDES =
%i[front back double].freeze
BLENDS =
%i[normal additive multiply].freeze
ALPHA_MODES =
%i[opaque mask blend].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transparent: false, opacity: 1.0, side: :front, depth_write: true, depth_test: true, blend: :normal, alpha_mode: :opaque, alpha_cutoff: 0.5) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/stagecraft/materials/material.rb', line 12

def initialize(transparent: false, opacity: 1.0, side: :front, depth_write: true,
               depth_test: true, blend: :normal, alpha_mode: :opaque, alpha_cutoff: 0.5)
  @version = 0
  self.transparent = transparent
  self.opacity = opacity
  self.side = side
  self.depth_write = depth_write
  self.depth_test = depth_test
  self.blend = blend
  self.alpha_mode = alpha_mode
  self.alpha_cutoff = alpha_cutoff
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/stagecraft/materials/material.rb', line 10

def version
  @version
end

Class Method Details

.versioned_attribute(name, coerce: nil, validate: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stagecraft/materials/material.rb', line 25

def self.versioned_attribute(name, coerce: nil, validate: nil)
  attr_reader name
  define_method(:"#{name}=") do |value|
    next_value = coerce ? coerce.call(value) : value
    if validate && !validate.call(next_value)
      raise ArgumentError, "invalid #{name}: #{value.inspect}"
    end
    return next_value if instance_variable_defined?(:"@#{name}") &&
                         instance_variable_get(:"@#{name}") == next_value

    instance_variable_set(:"@#{name}", next_value)
    @version += 1
    next_value
  end
end

Instance Method Details

#transparent?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/stagecraft/materials/material.rb', line 53

def transparent?
  transparent || opacity < 1.0 || alpha_mode == :blend
end