Module: Rgltf
- Defined in:
- lib/rgltf.rb,
lib/rgltf/glb.rb,
lib/rgltf/errors.rb,
lib/rgltf/writer.rb,
lib/rgltf/builder.rb,
lib/rgltf/version.rb,
lib/rgltf/document.rb,
lib/rgltf/extension.rb,
lib/rgltf/validator.rb,
lib/rgltf/accessor_reader.rb,
lib/rgltf/buffer_resolver.rb,
lib/rgltf/properties/base.rb,
lib/rgltf/properties/mesh.rb,
lib/rgltf/properties/node.rb,
lib/rgltf/properties/skin.rb,
lib/rgltf/properties/asset.rb,
lib/rgltf/properties/image.rb,
lib/rgltf/properties/scene.rb,
lib/rgltf/validation/skins.rb,
lib/rgltf/builder/accessors.rb,
lib/rgltf/builder/materials.rb,
lib/rgltf/properties/buffer.rb,
lib/rgltf/properties/camera.rb,
lib/rgltf/validation/meshes.rb,
lib/rgltf/properties/sampler.rb,
lib/rgltf/properties/texture.rb,
lib/rgltf/validation/buffers.rb,
lib/rgltf/validation/cameras.rb,
lib/rgltf/validation/context.rb,
lib/rgltf/properties/accessor.rb,
lib/rgltf/properties/material.rb,
lib/rgltf/properties/animation.rb,
lib/rgltf/validation/accessors.rb,
lib/rgltf/writer/buffer_merger.rb,
lib/rgltf/builder/accessor_data.rb,
lib/rgltf/validation/animations.rb,
lib/rgltf/properties/buffer_view.rb,
lib/rgltf/writer/default_omitter.rb,
lib/rgltf/validation/scenes_nodes.rb,
lib/rgltf/builder/component_builders.rb,
lib/rgltf/builder/document_properties.rb,
lib/rgltf/validation/images_materials.rb,
lib/rgltf/writer/extension_serializer.rb,
lib/rgltf/extensions/khr_lights_punctual.rb,
lib/rgltf/extensions/khr_materials_unlit.rb,
lib/rgltf/extensions/khr_texture_transform.rb,
lib/rgltf/validation/root_asset_extensions.rb,
lib/rgltf/extensions/khr_materials_emissive_strength.rb
Defined Under Namespace
Modules: AccessorReader, Extensions, GLB, Matrix4, Properties, Validation
Classes: Accessor, Animation, Asset, Buffer, BufferResolver, BufferView, Builder, Camera, Document, Error, Extension, ExtensionRegistry, FormatError, Image, Material, Mesh, MissingResourceError, Node, NormalTextureInfo, OcclusionTextureInfo, PbrMetallicRoughness, Primitive, Sampler, Scene, Skin, Texture, TextureInfo, UnsupportedError, UnsupportedExtensionError, ValidationError, Validator, Writer
Constant Summary
collapse
- VERSION =
'1.0.0'
Class Method Summary
collapse
-
.default_extensions ⇒ Object
-
.load(source, base_dir: nil, **options) ⇒ Object
-
.load_glb(data, base_dir: nil, **options) ⇒ Object
-
.load_json(json, base_dir: nil, buffers: nil, glb_bin: nil, lazy: true, extensions: default_extensions, validate: false, strict_extensions: true) ⇒ Object
Class Method Details
.default_extensions ⇒ Object
75
76
77
|
# File 'lib/rgltf/extension.rb', line 75
def default_extensions
@default_extensions ||= ExtensionRegistry.new
end
|
.load(source, base_dir: nil, **options) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rgltf.rb', line 26
def load(source, base_dir: nil, **options)
data, inferred_base_dir, inferred_format = read_source(source)
base_dir ||= inferred_base_dir
if inferred_format == :glb
raise FormatError, 'not a GLB (bad magic)' unless glb?(data)
load_glb(data, base_dir:, **options)
elsif glb?(data)
load_glb(data, base_dir:, **options)
else
load_json(data, base_dir:, **options)
end
rescue Errno::ENOENT, Errno::EACCES => e
raise MissingResourceError, e.message
rescue Error
raise
rescue StandardError => e
raise FormatError, "could not load glTF: #{e.message}"
end
|
.load_glb(data, base_dir: nil, **options) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/rgltf.rb', line 47
def load_glb(data, base_dir: nil, **options)
json, bin = GLB.read(binary_string(data))
load_json(json, base_dir:, glb_bin: bin, **options)
rescue Error
raise
rescue StandardError => e
raise FormatError, "could not load GLB: #{e.message}"
end
|
.load_json(json, base_dir: nil, buffers: nil, glb_bin: nil, lazy: true, extensions: default_extensions, validate: false, strict_extensions: true) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rgltf.rb', line 56
def load_json(json, base_dir: nil, buffers: nil, glb_bin: nil, lazy: true,
extensions: default_extensions, validate: false,
strict_extensions: true)
parsed = json.is_a?(Hash) ? deep_copy(json) : JSON.parse(string_data(json))
validate_before_build!(parsed, supplied_buffers: buffers) if validate
Document.new(
parsed,
base_dir:,
supplied_buffers: buffers,
glb_bin:,
lazy:,
extension_registry: extensions,
validate:,
strict_extensions:
)
rescue JSON::ParserError => e
raise FormatError, "invalid glTF JSON: #{e.message}"
rescue FormatError => e
raise ValidationError, e.message if validate
raise
rescue Error
raise
rescue StandardError => e
raise FormatError, "could not load glTF JSON: #{e.message}"
end
|