Class: Stagecraft::Loaders::GLTF
- Inherits:
-
Object
- Object
- Stagecraft::Loaders::GLTF
- Defined in:
- lib/stagecraft/loaders/gltf_loader.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ATTRIBUTE_NAMES =
{ POSITION: :position, NORMAL: :normal, TEXCOORD_0: :uv, TEXCOORD_1: :uv1, TANGENT: :tangent, COLOR_0: :color, JOINTS_0: :joints, WEIGHTS_0: :weights }.freeze
- TOPOLOGIES =
{ points: :point_list, lines: :line_list, line_strip: :line_strip, triangles: :triangle_list, triangle_strip: :triangle_strip }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(document) ⇒ GLTF
constructor
A new instance of GLTF.
Constructor Details
#initialize(document) ⇒ GLTF
Returns a new instance of GLTF.
34 35 36 37 38 |
# File 'lib/stagecraft/loaders/gltf_loader.rb', line 34 def initialize(document) @document = document @textures = {} @materials = {} end |
Class Method Details
.load(source) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/stagecraft/loaders/gltf_loader.rb', line 26 def self.load(source) require "rgltf" require "texel" document = source.is_a?(Rgltf::Document) ? source : Rgltf.load(source) new(document).convert end |
Instance Method Details
#convert ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/stagecraft/loaders/gltf_loader.rb', line 40 def convert source_scenes = @document.scenes converted = source_scenes.map { |scene| convert_scene(scene) } default_index = @document.default_scene && source_scenes.index(@document.default_scene) default_index ||= 0 default_scene = converted[default_index] || convert_scene(nil) mapping = @scene_mappings.fetch(default_scene.object_id) Result.new( scene: default_scene, scenes: converted.empty? ? [default_scene] : converted, animations: convert_animations(mapping), cameras: converted_cameras(mapping) ) end |