Class: Collada::Parser::VisualScene::Node
- Inherits:
-
Object
- Object
- Collada::Parser::VisualScene::Node
- Defined in:
- lib/collada/parser/scene.rb,
lib/collada/parser/visual_scene.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#instances ⇒ Object
readonly
Returns the value of attribute instances.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
-
#transforms ⇒ Object
readonly
Returns the value of attribute transforms.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .parse(doc, element) ⇒ Object
- .parse_children(doc, element) ⇒ Object
- .parse_instances(doc, element) ⇒ Object
- .parse_transforms(doc, element) ⇒ Object
Instance Method Summary collapse
- #attach!(parent) ⇒ Object
-
#initialize(id, name, type, transforms, instances, children, attributes = {}) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #local_transform_matrix ⇒ Object
- #parents(type = nil) ⇒ Object
- #transform_matrix ⇒ Object
Constructor Details
#initialize(id, name, type, transforms, instances, children, attributes = {}) ⇒ Node
Returns a new instance of Node.
210 211 212 |
# File 'lib/collada/parser/scene.rb', line 210 def initialize(structure = {}) @structure = structure end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
100 101 102 |
# File 'lib/collada/parser/visual_scene.rb', line 100 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
98 99 100 |
# File 'lib/collada/parser/visual_scene.rb', line 98 def children @children end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
91 92 93 |
# File 'lib/collada/parser/visual_scene.rb', line 91 def id @id end |
#instances ⇒ Object (readonly)
Returns the value of attribute instances.
97 98 99 |
# File 'lib/collada/parser/visual_scene.rb', line 97 def instances @instances end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
92 93 94 |
# File 'lib/collada/parser/visual_scene.rb', line 92 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
89 90 91 |
# File 'lib/collada/parser/visual_scene.rb', line 89 def parent @parent end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
214 215 216 |
# File 'lib/collada/parser/scene.rb', line 214 def structure @structure end |
#transforms ⇒ Object (readonly)
Returns the value of attribute transforms.
95 96 97 |
# File 'lib/collada/parser/visual_scene.rb', line 95 def transforms @transforms end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
93 94 95 |
# File 'lib/collada/parser/visual_scene.rb', line 93 def type @type end |
Class Method Details
.parse(doc, element) ⇒ Object
216 217 218 |
# File 'lib/collada/parser/scene.rb', line 216 def self.parse(doc, element) self.new(element) end |
.parse_children(doc, element) ⇒ Object
155 156 157 158 159 |
# File 'lib/collada/parser/visual_scene.rb', line 155 def self.parse_children(doc, element) OrderedMap.parse(element, 'node') do |node_element| Node.parse(doc, node_element) end end |
.parse_instances(doc, element) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/collada/parser/visual_scene.rb', line 143 def self.parse_instances(doc, element) instances = [] INSTANCE_ELEMENTS.each do |(element_name, klass)| element.elements.each(element_name) do |instance_element| instances << klass.parse(doc, instance_element) end end return instances end |
.parse_transforms(doc, element) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/collada/parser/visual_scene.rb', line 132 def self.parse_transforms(doc, element) transforms = [] element.elements.each('translate | rotate | scale | matrix') do |transform_element| values = transform_element.text.strip.split(/\s+/).collect &:to_f transforms << [transform_element.name.to_sym, values] end return transforms end |
Instance Method Details
#attach!(parent) ⇒ Object
85 86 87 |
# File 'lib/collada/parser/visual_scene.rb', line 85 def attach!(parent) @parent = parent end |
#inspect ⇒ Object
102 103 104 |
# File 'lib/collada/parser/visual_scene.rb', line 102 def inspect "\#<#{self.class} #{id} -> [#{children.keys.join(', ')}]>" end |
#local_transform_matrix ⇒ Object
106 107 108 |
# File 'lib/collada/parser/visual_scene.rb', line 106 def local_transform_matrix Transforms.for(@transforms) end |
#parents(type = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/collada/parser/visual_scene.rb', line 118 def parents(type = nil) result = [] parent = @parent while parent result << parent if !type || parent.type == type parent = parent.parent end return result end |
#transform_matrix ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/collada/parser/visual_scene.rb', line 110 def transform_matrix if parent parent.transform_matrix * local_transform_matrix else local_transform_matrix end end |