Class: Rgltf::Primitive

Inherits:
Rgltf::Properties::Base show all
Defined in:
lib/rgltf/properties/mesh.rb

Constant Summary collapse

MODES =
{
  0 => :points, 1 => :lines, 2 => :line_loop, 3 => :line_strip,
  4 => :triangles, 5 => :triangle_strip, 6 => :triangle_fan
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Rgltf::Properties::Base

#extensions, #extras, #index, #name, #owner_type, #source_json

Instance Method Summary collapse

Methods inherited from Rgltf::Properties::Base

#extension, #nested_properties, #parse_extensions!

Constructor Details

#initialize(json, document:, mesh_index:, index:) ⇒ Primitive

Returns a new instance of Primitive.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rgltf/properties/mesh.rb', line 12

def initialize(json, document:, mesh_index:, index:)
  super(json, document:, index:, owner_type: :primitive)
  @attributes = json.fetch('attributes').to_h do |semantic, accessor_index|
    [semantic.to_sym, document.fetch_reference(
      :accessors,
      accessor_index,
      "meshes/#{mesh_index}/primitives/#{index}/attributes/#{semantic}"
    )]
  end.freeze
  @indices = optional_reference(document, :accessors, json['indices'],
                                "meshes/#{mesh_index}/primitives/#{index}/indices")
  @material = optional_reference(document, :materials, json['material'],
                                 "meshes/#{mesh_index}/primitives/#{index}/material")
  @mode = MODES.fetch(json.fetch('mode', 4))
  @targets = json.fetch('targets', []).each_with_index.map do |target, target_index|
    target.to_h do |semantic, accessor_index|
      [semantic.to_sym, document.fetch_reference(
        :accessors,
        accessor_index,
        "meshes/#{mesh_index}/primitives/#{index}/targets/#{target_index}/#{semantic}"
      )]
    end.freeze
  end.freeze
rescue KeyError => e
  raise FormatError, "invalid mesh primitive: #{e.message}"
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'lib/rgltf/properties/mesh.rb', line 10

def attributes
  @attributes
end

#indicesObject (readonly)

Returns the value of attribute indices.



10
11
12
# File 'lib/rgltf/properties/mesh.rb', line 10

def indices
  @indices
end

#materialObject (readonly)

Returns the value of attribute material.



10
11
12
# File 'lib/rgltf/properties/mesh.rb', line 10

def material
  @material
end

#modeObject (readonly)

Returns the value of attribute mode.



10
11
12
# File 'lib/rgltf/properties/mesh.rb', line 10

def mode
  @mode
end

#targetsObject (readonly)

Returns the value of attribute targets.



10
11
12
# File 'lib/rgltf/properties/mesh.rb', line 10

def targets
  @targets
end