Class: Collada::Parser::VisualScene::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/collada/parser/scene.rb,
lib/collada/parser/visual_scene.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, sid, 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

#attributesObject (readonly)

Returns the value of attribute attributes.



103
104
105
# File 'lib/collada/parser/visual_scene.rb', line 103

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



101
102
103
# File 'lib/collada/parser/visual_scene.rb', line 101

def children
  @children
end

#idObject (readonly)

Returns the value of attribute id.



92
93
94
# File 'lib/collada/parser/visual_scene.rb', line 92

def id
  @id
end

#instancesObject (readonly)

Returns the value of attribute instances.



100
101
102
# File 'lib/collada/parser/visual_scene.rb', line 100

def instances
  @instances
end

#nameObject (readonly)

Returns the value of attribute name.



95
96
97
# File 'lib/collada/parser/visual_scene.rb', line 95

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



90
91
92
# File 'lib/collada/parser/visual_scene.rb', line 90

def parent
  @parent
end

#sidObject (readonly)

Returns the value of attribute sid.



93
94
95
# File 'lib/collada/parser/visual_scene.rb', line 93

def sid
  @sid
end

#structureObject (readonly)

Returns the value of attribute structure.



214
215
216
# File 'lib/collada/parser/scene.rb', line 214

def structure
  @structure
end

#transformsObject (readonly)

Returns the value of attribute transforms.



98
99
100
# File 'lib/collada/parser/visual_scene.rb', line 98

def transforms
  @transforms
end

#typeObject (readonly)

Returns the value of attribute type.



96
97
98
# File 'lib/collada/parser/visual_scene.rb', line 96

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



158
159
160
161
162
# File 'lib/collada/parser/visual_scene.rb', line 158

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



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/collada/parser/visual_scene.rb', line 146

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



135
136
137
138
139
140
141
142
143
144
# File 'lib/collada/parser/visual_scene.rb', line 135

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



86
87
88
# File 'lib/collada/parser/visual_scene.rb', line 86

def attach!(parent)
	@parent = parent
end

#inspectObject



105
106
107
# File 'lib/collada/parser/visual_scene.rb', line 105

def inspect
	"\#<#{self.class} #{id} -> [#{children.keys.join(', ')}]>"
end

#local_transform_matrixObject



109
110
111
# File 'lib/collada/parser/visual_scene.rb', line 109

def local_transform_matrix
	Transforms.for(@transforms)
end

#parents(type = nil) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/collada/parser/visual_scene.rb', line 121

def parents(type = nil)
	result = []
	
	parent = @parent
	
	while parent
		result << parent if !type || parent.type == type
		
		parent = parent.parent
	end
	
	return result
end

#transform_matrixObject



113
114
115
116
117
118
119
# File 'lib/collada/parser/visual_scene.rb', line 113

def transform_matrix
	if parent
		parent.transform_matrix * local_transform_matrix
	else
		local_transform_matrix
	end
end