Class: PBRT::Texture

Inherits:
Object
  • Object
show all
Defined in:
lib/pbrt/texture.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, *args) ⇒ Texture

Returns a new instance of Texture.



9
10
11
12
# File 'lib/pbrt/texture.rb', line 9

def initialize(builder, *args)
  @builder = builder
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'lib/pbrt/texture.rb', line 7

def args
  @args
end

Class Method Details

.raise_ambiguous_error(value) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/pbrt/texture.rb', line 47

def self.raise_ambiguous_error(value)
  message = "Please specify whether #{value.inspect} is a spectrum or texture.\n"
  message += "If it's a texture, wrap it with: texture(#{value.inspect})\n"
  message += "If it's a spectrum, wrap it with its representation: sampled(#{value.inspect})\n"
  message += "Valid representations are: rgb, xyz, sampled and blackbody"

  raise AmbiguousArgumentError, message
end

.string?(*value) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/pbrt/texture.rb', line 56

def self.string?(*value)
  value.flatten.first.is_a?(String)
end

.unpack(type, value) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pbrt/texture.rb', line 28

def self.unpack(type, value)
  return [type, value] unless type.to_s.include?("texture")
  return [:texture, value.args] if value.is_a?(self)

  if type == :float_texture
    return string?(value) ? [:texture, value] : [:float, value]
  end

  if type == :spectrum_texture && !string?(value)
    return [:spectrum, value]
  end

  if type == :texture && !string?(value)
    return [:float, value]
  end

  raise_ambiguous_error(value)
end

Instance Method Details

#colorObject



20
21
22
# File 'lib/pbrt/texture.rb', line 20

def color
  PBRT::Builder::Texture.new(@builder, args.first, "color")
end

#floatObject



24
25
26
# File 'lib/pbrt/texture.rb', line 24

def float
  PBRT::Builder::Texture.new(@builder, args.first, "float")
end

#spectrumObject

If these three methods are called, it means the user is trying to write a Texture directive, so delegate to that builder.



16
17
18
# File 'lib/pbrt/texture.rb', line 16

def spectrum
  PBRT::Builder::Texture.new(@builder, args.first, "spectrum")
end