Class: Rgltf::Extensions::KHRTextureTransform
- Inherits:
-
Rgltf::Extension
- Object
- Rgltf::Extension
- Rgltf::Extensions::KHRTextureTransform
- Defined in:
- lib/rgltf/extensions/khr_texture_transform.rb
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#rotation ⇒ Object
readonly
Returns the value of attribute rotation.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#tex_coord ⇒ Object
readonly
Returns the value of attribute tex_coord.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json) ⇒ KHRTextureTransform
constructor
A new instance of KHRTextureTransform.
- #uv_matrix ⇒ Object
Methods inherited from Rgltf::Extension
decode_primitive, register, serialize_properties
Constructor Details
#initialize(json) ⇒ KHRTextureTransform
Returns a new instance of KHRTextureTransform.
8 9 10 11 12 13 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 8 def initialize(json) @offset = json.fetch('offset', [0.0, 0.0]).freeze @rotation = json.fetch('rotation', 0.0) @scale = json.fetch('scale', [1.0, 1.0]).freeze @tex_coord = json['texCoord'] end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
6 7 8 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 6 def offset @offset end |
#rotation ⇒ Object (readonly)
Returns the value of attribute rotation.
6 7 8 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 6 def rotation @rotation end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
6 7 8 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 6 def scale @scale end |
#tex_coord ⇒ Object (readonly)
Returns the value of attribute tex_coord.
6 7 8 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 6 def tex_coord @tex_coord end |
Class Method Details
.parse(json, owner:, doc:) ⇒ Object
25 26 27 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 25 def self.parse(json, owner:, doc:) new(json) end |
.serialize(object, doc:) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 29 def self.serialize(object, doc:) value = {}.tap do |json| json['offset'] = object.offset unless object.offset == [0.0, 0.0] json['rotation'] = object.rotation unless object.rotation == 0.0 json['scale'] = object.scale unless object.scale == [1.0, 1.0] json['texCoord'] = object.tex_coord unless object.tex_coord.nil? end serialize_properties(value, handled_keys: %w[offset rotation scale texCoord]) end |
Instance Method Details
#uv_matrix ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rgltf/extensions/khr_texture_transform.rb', line 15 def uv_matrix cosine = Math.cos(rotation) sine = Math.sin(rotation) [ cosine * scale[0], sine * scale[0], 0.0, -sine * scale[1], cosine * scale[1], 0.0, offset[0], offset[1], 1.0 ].freeze end |