Class: Ogre::RMaterial
Overview
result = rmaterial.load!
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.load(file) {|rmaterial| ... } ⇒ Object
Used to create an rmaterial with a block.
Instance Method Summary collapse
-
#create_ogre_material! ⇒ Object
Loads the rmaterial from Ogre.
- #evaluate!(template) ⇒ Object
-
#initialize(rmaterial) ⇒ RMaterial
constructor
A new instance of RMaterial.
- #method_missing(name, *args) ⇒ Object
-
#parse! ⇒ Object
Parses through ERB to create a ogre-compatible material.
- #tangent_space ⇒ Object
Constructor Details
#initialize(rmaterial) ⇒ RMaterial
Returns a new instance of RMaterial.
42 43 44 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 42 def initialize(rmaterial) @rmaterial = rmaterial end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 63 def method_missing(name, *args) # Check if the method is a setter if name.to_s[-1].chr == "=" name = name.to_s[0...-1].to_sym # Set the instance variable to the sent variable ivar = "@#{ name }".to_sym instance_variable_set(ivar, args[0]) else begin return eval("@#{name}") rescue StandardError => bang raise NoMethodError, "Rmaterial could not find the #{name} attribute: #{bang.}" end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 31 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
31 32 33 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 31 def result @result end |
Class Method Details
.load(file) {|rmaterial| ... } ⇒ Object
Used to create an rmaterial with a block. Returns an Ogre material
35 36 37 38 39 40 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 35 def self.load(file) rmaterial = self.new(file) yield rmaterial rmaterial.parse! return rmaterial.create_ogre_material! end |
Instance Method Details
#create_ogre_material! ⇒ Object
Loads the rmaterial from Ogre. Must call parse! first.
56 57 58 59 60 61 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 56 def create_ogre_material! unless(MaterialManager.instance.resource_exists(name.to_s)) MaterialManager.instance.parse_script(result, "General") end return MaterialManager.instance.get_by_name(name.to_s) end |
#evaluate!(template) ⇒ Object
78 79 80 81 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 78 def evaluate!(template) evaluator = ERB.new(template) return @result ||= evaluator.result(binding) end |
#parse! ⇒ Object
Parses through ERB to create a ogre-compatible material
47 48 49 50 51 52 53 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 47 def parse! begin evaluate!(File.open(@rmaterial).readlines.join('')) rescue Errno::ENOENT => bang raise Errno::ENOENT, "RMaterial for '#{name}' not found: #{bang.}" end end |
#tangent_space ⇒ Object
82 83 84 |
# File 'lib/shattered_ogrerb/rmaterial.rb', line 82 def tangent_space false end |