88 struct VSGXCHANGE_DECLSPEC
ExtensionsExtras :
public vsg::Inherit<vsg::JSONParser::Schema, ExtensionsExtras>
90 vsg::ref_ptr<Extensions> extensions;
91 vsg::ref_ptr<Extras> extras;
93 virtual bool requireMetaData()
const {
return extras.valid(); }
95 void report(vsg::LogOutput& output);
97 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
100 vsg::ref_ptr<T> extension(
const char* name)
const
102 if (!extensions)
return {};
104 auto itr = extensions->values.find(name);
105 if (itr != extensions->values.end())
106 return itr->second.cast<T>();
142 struct VSGXCHANGE_DECLSPEC
Sparse :
public vsg::Inherit<NameExtensionsExtras, Sparse>
145 vsg::ref_ptr<SparseIndices> indices;
146 vsg::ref_ptr<SparseValues> values;
148 void report(vsg::LogOutput& output);
149 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
150 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
173 struct VSGXCHANGE_DECLSPEC
Accessor :
public vsg::Inherit<NameExtensionsExtras, Accessor>
176 uint32_t byteOffset = 0;
177 uint32_t componentType = 0;
178 bool normalized =
false;
181 vsg::ValuesSchema<double> max;
182 vsg::ValuesSchema<double> min;
183 vsg::ref_ptr<Sparse> sparse;
187 void report(vsg::LogOutput& output);
188 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
189 void read_string(vsg::JSONParser& parser,
const std::string_view& property)
override;
190 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
191 void read_bool(vsg::JSONParser& parser,
const std::string_view& property,
bool value)
override;
192 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
254 struct VSGXCHANGE_DECLSPEC
KHR_texture_transform :
public vsg::Inherit<vsg::JSONParser::Schema, KHR_texture_transform>
256 vsg::ValuesSchema<float> offset;
257 float rotation = 0.0f;
258 vsg::ValuesSchema<float> scale;
259 uint32_t texCoord = 0;
262 vsg::ref_ptr<vsg::Object> clone(
const vsg::CopyOp&)
const override {
return KHR_texture_transform::create(*
this); }
264 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
265 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
270 vsg::ValuesSchema<float> baseColorFactor;
272 float metallicFactor = 1.0f;
273 float roughnessFactor = 1.0f;
276 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
277 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
278 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
298 float specularFactor = 1.0f;
300 vsg::ValuesSchema<float> specularColorFactor;
304 vsg::ref_ptr<vsg::Object> clone(
const vsg::CopyOp&)
const override {
return KHR_materials_specular::create(*
this); }
306 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
307 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
308 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
314 vsg::ValuesSchema<float> diffuseFactor;
316 vsg::ValuesSchema<float> specularFactor;
317 float glossinessFactor = 1.0f;
321 vsg::ref_ptr<vsg::Object> clone(
const vsg::CopyOp&)
const override {
return KHR_materials_pbrSpecularGlossiness::create(*
this); }
323 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
324 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
325 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
391 struct VSGXCHANGE_DECLSPEC
Material :
public vsg::Inherit<NameExtensionsExtras, Material>
397 vsg::ValuesSchema<float> emissiveFactor;
398 std::string alphaMode =
"OPAQUE";
399 float alphaCutoff = 0.5f;
400 bool doubleSided =
false;
402 void report(vsg::LogOutput& output);
403 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
404 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
405 void read_string(vsg::JSONParser& parser,
const std::string_view& property)
override;
406 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
407 void read_bool(vsg::JSONParser& parser,
const std::string_view& property,
bool value)
override;
417 struct VSGXCHANGE_DECLSPEC
Primitive :
public vsg::Inherit<ExtensionsExtras, Primitive>
423 vsg::ObjectsSchema<Attributes> targets;
425 void report(vsg::LogOutput& output);
426 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
427 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
428 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
466 struct VSGXCHANGE_DECLSPEC
Node :
public vsg::Inherit<NameExtensionsExtras, Node>
471 vsg::ValuesSchema<glTFid> children;
472 vsg::ValuesSchema<double> matrix;
473 vsg::ValuesSchema<double> rotation;
474 vsg::ValuesSchema<double> scale;
475 vsg::ValuesSchema<double> translation;
476 vsg::ValuesSchema<double> weights;
478 void report(vsg::LogOutput& output);
479 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
480 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
564 struct VSGXCHANGE_DECLSPEC
Camera :
public vsg::Inherit<NameExtensionsExtras, Camera>
566 vsg::ref_ptr<Orthographic> orthographic;
567 vsg::ref_ptr<Perspective> perspective;
570 void report(vsg::LogOutput& output);
571 void read_string(vsg::JSONParser& parser,
const std::string_view& property)
override;
572 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
583 struct VSGXCHANGE_DECLSPEC
Light :
public vsg::Inherit<NameExtensionsExtras, Light>
585 vsg::ValuesSchema<float> color;
586 float intensity = 1.0f;
587 vsg::ref_ptr<Spot> spot;
589 float range = std::numeric_limits<float>::max();
591 void read_string(vsg::JSONParser& parser,
const std::string_view& property)
override;
592 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
593 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
594 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
599 vsg::ObjectsSchema<Light> lights;
603 vsg::ref_ptr<vsg::Object> clone(
const vsg::CopyOp&)
const override {
return KHR_lights_punctual::create(*
this); }
605 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
606 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
609 struct VSGXCHANGE_DECLSPEC
glTF :
public vsg::Inherit<ExtensionsExtras, glTF>
615 vsg::StringsSchema extensionsUsed;
616 vsg::StringsSchema extensionsRequired;
617 vsg::ref_ptr<Asset> asset;
618 vsg::ObjectsSchema<Accessor> accessors;
619 vsg::ObjectsSchema<BufferView> bufferViews;
620 vsg::ObjectsSchema<Buffer> buffers;
621 vsg::ObjectsSchema<Image> images;
622 vsg::ObjectsSchema<Material> materials;
623 vsg::ObjectsSchema<Mesh> meshes;
624 vsg::ObjectsSchema<Node> nodes;
625 vsg::ObjectsSchema<Sampler> samplers;
627 vsg::ObjectsSchema<Scene> scenes;
628 vsg::ObjectsSchema<Texture> textures;
629 vsg::ObjectsSchema<Animation> animations;
630 vsg::ObjectsSchema<Camera> cameras;
631 vsg::ObjectsSchema<Skins> skins;
633 void read_array(vsg::JSONParser& parser,
const std::string_view& property)
override;
634 void read_object(vsg::JSONParser& parser,
const std::string_view& property)
override;
635 void read_number(vsg::JSONParser& parser,
const std::string_view& property, std::istream& input)
override;
637 void report(vsg::LogOutput& output);
639 virtual void resolveURIs(vsg::ref_ptr<const vsg::Options> options);
642 class VSGXCHANGE_DECLSPEC SceneGraphBuilder :
public vsg::Inherit<vsg::Object, SceneGraphBuilder>
649 vsg::ref_ptr<vsg::Sampler> sampler;
650 vsg::ref_ptr<vsg::Data> image;
653 vsg::ref_ptr<const vsg::Options> options;
654 vsg::ref_ptr<vsg::ShaderSet> flatShaderSet;
655 vsg::ref_ptr<vsg::ShaderSet> pbrShaderSet;
656 vsg::ref_ptr<vsg::SharedObjects> sharedObjects;
658 vsg::CoordinateConvention source_coordinateConvention = vsg::CoordinateConvention::Y_UP;
659 int instanceNodeHint = vsg::Options::INSTANCE_NONE;
660 bool cloneAccessors =
false;
661 float maxAnisotropy = 16.0f;
663 vsg::ref_ptr<glTF> model;
665 std::vector<vsg::ref_ptr<vsg::Data>> vsg_buffers;
666 std::vector<vsg::ref_ptr<vsg::Data>> vsg_bufferViews;
667 std::vector<vsg::ref_ptr<vsg::Data>> vsg_accessors;
668 std::vector<vsg::ref_ptr<vsg::Camera>> vsg_cameras;
669 std::vector<vsg::ref_ptr<vsg::JointSampler>> vsg_skins;
670 std::vector<vsg::ref_ptr<vsg::Sampler>> vsg_samplers;
671 std::vector<vsg::ref_ptr<vsg::Data>> vsg_images;
672 std::vector<SamplerImage> vsg_textures;
673 std::vector<vsg::ref_ptr<vsg::DescriptorConfigurator>> vsg_materials;
674 std::vector<vsg::ref_ptr<vsg::Node>> vsg_meshes;
675 std::vector<vsg::ref_ptr<vsg::Light>> vsg_lights;
676 std::vector<vsg::ref_ptr<vsg::Node>> vsg_nodes;
677 std::vector<vsg::ref_ptr<vsg::Node>> vsg_scenes;
678 std::vector<bool> vsg_joints;
679 vsg::Animations vsg_animations;
683 vsg::ref_ptr<gltf::Attributes> instancedAttributes;
684 vsg::ref_ptr<vsg::JointSampler> jointSampler;
687 vsg::ref_ptr<vsg::DescriptorConfigurator> default_material;
690 std::map<std::string, std::string> attributeLookup;
695 bool decodePrimitiveIfRequired(vsg::ref_ptr<gltf::Primitive> gltf_primitive);
697 void flattenTransforms(
gltf::Node& node,
const vsg::dmat4& transform);
699 bool getTransform(
gltf::Node& node, vsg::dmat4& transform);
701 vsg::ref_ptr<vsg::Data> createBuffer(vsg::ref_ptr<gltf::Buffer> gltf_buffer);
702 vsg::ref_ptr<vsg::Data> createBufferView(vsg::ref_ptr<gltf::BufferView> gltf_bufferView);
703 vsg::ref_ptr<vsg::Data> createArray(
const std::string& type, uint32_t componentType,
glTFid bufferView, uint32_t offset, uint32_t count);
704 vsg::ref_ptr<vsg::Data> createAccessor(vsg::ref_ptr<gltf::Accessor> gltf_accessor);
705 vsg::ref_ptr<vsg::Camera> createCamera(vsg::ref_ptr<gltf::Camera> gltf_camera);
706 vsg::ref_ptr<vsg::Sampler> createSampler(vsg::ref_ptr<gltf::Sampler> gltf_sampler);
707 vsg::ref_ptr<vsg::Data> createImage(vsg::ref_ptr<gltf::Image> gltf_image);
708 SamplerImage createTexture(vsg::ref_ptr<gltf::Texture> gltf_texture);
709 vsg::ref_ptr<vsg::DescriptorConfigurator> createPbrMaterial(vsg::ref_ptr<gltf::Material> gltf_material);
710 vsg::ref_ptr<vsg::DescriptorConfigurator> createUnlitMaterial(vsg::ref_ptr<gltf::Material> gltf_material);
711 vsg::ref_ptr<vsg::DescriptorConfigurator> createMaterial(vsg::ref_ptr<gltf::Material> gltf_material);
712 vsg::ref_ptr<vsg::Node> createMesh(vsg::ref_ptr<gltf::Mesh> gltf_mesh,
const MeshExtras& extras = {});
713 vsg::ref_ptr<vsg::Light> createLight(vsg::ref_ptr<gltf::Light> gltf_light);
714 vsg::ref_ptr<vsg::Node> createNode(vsg::ref_ptr<gltf::Node> gltf_node,
bool jointNode);
715 vsg::ref_ptr<vsg::Animation> createAnimation(vsg::ref_ptr<gltf::Animation> gltf_animation);
716 vsg::ref_ptr<vsg::Node> createScene(vsg::ref_ptr<gltf::Scene> gltf_scene,
bool requiresRootTransformNode,
const vsg::dmat4& matrix);
718 vsg::ref_ptr<vsg::ShaderSet> getOrCreatePbrShaderSet();
719 vsg::ref_ptr<vsg::ShaderSet> getOrCreateFlatShaderSet();
721 vsg::ref_ptr<vsg::Object> createSceneGraph(vsg::ref_ptr<gltf::glTF> in_model, vsg::ref_ptr<const vsg::Options> in_options);