Class: Rgltf::Node
- Inherits:
-
Properties::Base
- Object
- Properties::Base
- Rgltf::Node
- Defined in:
- lib/rgltf/properties/node.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#camera ⇒ Object
readonly
Returns the value of attribute camera.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#mesh ⇒ Object
readonly
Returns the value of attribute mesh.
-
#rotation ⇒ Object
readonly
Returns the value of attribute rotation.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#skin ⇒ Object
readonly
Returns the value of attribute skin.
-
#translation ⇒ Object
readonly
Returns the value of attribute translation.
-
#weights ⇒ Object
readonly
Returns the value of attribute weights.
Attributes inherited from Properties::Base
#extensions, #extras, #index, #name, #owner_type, #source_json
Instance Method Summary collapse
-
#initialize(json, document:, index:) ⇒ Node
constructor
A new instance of Node.
- #matrix ⇒ Object
- #resolve_references! ⇒ Object
- #traverse(&block) ⇒ Object
- #trs? ⇒ Boolean
- #world_matrix(parent_matrix = IDENTITY) ⇒ Object
Methods inherited from Properties::Base
#extension, #nested_properties, #parse_extensions!
Constructor Details
#initialize(json, document:, index:) ⇒ Node
Returns a new instance of Node.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rgltf/properties/node.rb', line 49 def initialize(json, document:, index:) super(json, document:, index:, owner_type: :node) @child_indices = json.fetch('children', []) @mesh_index = json['mesh'] @skin_index = json['skin'] @camera_index = json['camera'] @translation = json.fetch('translation', [0.0, 0.0, 0.0]).freeze @rotation = json.fetch('rotation', [0.0, 0.0, 0.0, 1.0]).freeze @scale = json.fetch('scale', [1.0, 1.0, 1.0]).freeze @weights = json['weights']&.freeze @matrix = json['matrix']&.freeze return unless @matrix && (json.key?('translation') || json.key?('rotation') || json.key?('scale')) raise FormatError, "node #{index} cannot define both matrix and TRS" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
110 111 112 113 114 |
# File 'lib/rgltf/properties/node.rb', line 110 def method_missing(name, ...) return public_send(name, ...) if name == :to_larb && self.class.send(:install_larb_conversion!) super end |
Instance Attribute Details
#camera ⇒ Object (readonly)
Returns the value of attribute camera.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def camera @camera end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def children @children end |
#mesh ⇒ Object (readonly)
Returns the value of attribute mesh.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def mesh @mesh end |
#rotation ⇒ Object (readonly)
Returns the value of attribute rotation.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def rotation @rotation end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def scale @scale end |
#skin ⇒ Object (readonly)
Returns the value of attribute skin.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def skin @skin end |
#translation ⇒ Object (readonly)
Returns the value of attribute translation.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def translation @translation end |
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
46 47 48 |
# File 'lib/rgltf/properties/node.rb', line 46 def weights @weights end |
Instance Method Details
#matrix ⇒ Object
75 76 77 |
# File 'lib/rgltf/properties/node.rb', line 75 def matrix @matrix || (@computed_matrix ||= Matrix4.from_trs(translation, rotation, scale)) end |
#resolve_references! ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rgltf/properties/node.rb', line 65 def resolve_references! @children = @child_indices.each_with_index.map do |child_index, child_position| @document.fetch_reference(:nodes, child_index, "nodes/#{index}/children/#{child_position}") end.freeze @mesh = optional_reference(:meshes, @mesh_index, "nodes/#{index}/mesh") @skin = optional_reference(:skins, @skin_index, "nodes/#{index}/skin") @camera = optional_reference(:cameras, @camera_index, "nodes/#{index}/camera") self end |
#traverse(&block) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/rgltf/properties/node.rb', line 83 def traverse(&block) return enum_for(:traverse) unless block traverse_guarded({}, &block) self end |
#trs? ⇒ Boolean
79 80 81 |
# File 'lib/rgltf/properties/node.rb', line 79 def trs? @matrix.nil? end |