2#include "Engine/Animation/AnimationAsset.h"
3#include "Engine/Animation/SkinAsset.h"
4#include "Engine/Ecs/EcsData.h"
5#include "Engine/Material/MaterialData.h"
6#include "Engine/World/Transform.h"
8#include <Engine/Mesh/Vertex.h>
10#include <glm/gtc/quaternion.hpp>
67 const std::vector<tinygltf::Buffer> & buffers,
68 const std::vector<tinygltf::BufferView> & bufferViews,
106 const std::vector<tinygltf::Buffer> & buffers,
107 const std::vector<tinygltf::BufferView> & bufferViews,
108 const std::vector<tinygltf::Accessor> & accessors,
109 const tinygltf::Primitive & primitive
126 std::optional<GltfBufferDataView>
202 tinygltf::Image
image = tinygltf::Image();
266 const tinygltf::Value & vs_extension,
267 const tinygltf::Model * model =
nullptr
419 const tinygltf::Value & extension,
420 const tinygltf::Model * model =
nullptr
846 const tinygltf::Model & model,
847 const tinygltf::Material & material,
1037 void parsePbrData(
const tinygltf::Model & model,
const tinygltf::Material & material );
1084 tinygltf::Model model,
1165 const tinygltf::Model & model,
1166 const tinygltf::Mesh &
mesh,
1167 const tinygltf::Node & node,
1259 void load(
const std::filesystem::path & path, std::vector<GltfMeshData> & meshes )
const;
1271 std::optional<tinygltf::Model>
loadModel(
const std::filesystem::path & path )
const;
1282 tinygltf::Model
loadAsync(
const std::filesystem::path & path )
const;
Animation clip loaded from glTF animation data.
std::vector< Vertex > getPrimitiveVertices(const tinygltf::Primitive &primitive)
Legacy primitive vertex extraction entry point.
NamedThreadPool * threadPool
std::optional< tinygltf::Model > loadModel(const std::filesystem::path &path) const
Loads a full ASCII glTF model through tinygltf.
static Assets::Skin loadSkinData(const tinygltf::Model &model, int skinIndex)
Loads skin data from a glTF model.
GltfLoader(NamedThreadPool *threadPool=nullptr)
Creates a loader that can use an optional thread pool for deferred work.
tinygltf::Model loadMetadataOnly(const std::filesystem::path &path) const
Loads only glTF metadata without loading buffer data.
void load(const std::filesystem::path &path, std::vector< GltfMeshData > &meshes) const
Loads mesh nodes from a glTF file.
Ecs::PrimitiveData loadPrimitiveData(GltfVertexData vertexData)
Converts resolved glTF vertex and index views into engine primitive data.
static Animation loadAnimationData(const tinygltf::Model &model, int animIndex, const Assets::Skin &skin)
Loads animation data from a glTF model.
tinygltf::Model loadAsync(const std::filesystem::path &path) const
Loads a glTF model while skipping image payload loading.
~GltfLoader()
Waits for queued work on the supplied thread pool before destruction.
Runtime-owned Vulkan texture resource.
Skeleton definition loaded from glTF skin data.
Wrapper for texture data.
Coordinates engine asset loading pipelines and runtime texture descriptor ownership.
Engine::Core::MaterialData MaterialData
Alias for the unified material data type.
PipelineNames
Named graphics pipelines used by material selection and shader lookup.
const tinygltf::Buffer & buffer
Buffer referenced by bufferView.buffer.
GltfBufferDataView(const std::vector< tinygltf::Buffer > &buffers, const std::vector< tinygltf::BufferView > &bufferViews, const tinygltf::Accessor &accessor)
Resolves an accessor to its buffer view, buffer, and raw data pointer.
const tinygltf::Accessor & accessor
Accessor that describes the element count, type, and component type.
const tinygltf::BufferView & bufferView
Buffer view referenced by accessor.bufferView.
const float * data
Raw pointer to the first accessor byte, interpreted as float data by callers.
Material data extracted from a glTF material and engine extensions.
float getMetallicFactor() const
Gets the glTF metallic factor.
glm::vec3 getEmissiveFactor() const
Gets the emissive factor.
bool hasVulkanSchneeExtension() const
Checks whether the material has a Vulkan Schnee material extension.
void parsePbrData(const tinygltf::Model &model, const tinygltf::Material &material)
const Materials::MaterialData & getMaterialData() const
Gets immutable engine material data generated from glTF and extension data.
GltfMaterialData()=default
Creates default material data with no parsed source material.
uint32_t getNormalTextureIndex() const
Gets the engine normal texture index.
bool hasTexture() const
Checks whether the material references a base color texture.
GltfMaterialData(const tinygltf::Model &model, const tinygltf::Material &material, const StaticMeshExtensions &meshSettings)
Parses material data from glTF and engine extension metadata.
int32_t getGltfMetallicRoughnessTextureIndex() const
Gets the original glTF metallic-roughness texture index.
bool hasEmissiveTexture() const
Checks whether the glTF material references an emissive texture.
bool hasNormalTexture() const
Checks whether the glTF material references a normal texture.
int32_t gltfNormalTextureIndex
uint32_t roughnessMetallicTextureIndex
uint32_t getTextureIndex() const
Gets the engine texture index for the base color texture.
const VulkanSchneeMaterialExtension & getVulkanSchneeExtension() const
Gets the parsed Vulkan Schnee material extension.
const std::filesystem::path & getLightmapPath() const
Gets the lightmap texture path from the engine extension.
int32_t getGltfNormalTextureIndex() const
Gets the original glTF normal texture index.
int32_t getGltfEmissiveTextureIndex() const
Gets the original glTF emissive texture index.
float getRoughnessFactor() const
Gets the glTF roughness factor.
int32_t gltfMetallicRoughnessTextureIndex
uint32_t getEmissiveTextureIndex() const
Gets the engine emissive texture index.
Materials::MaterialData materialData
std::optional< MaterialExtensions > materialExtensions
float getNormalScale() const
Gets the normal map scale.
uint32_t getRoughnessMetallicTextureIndex() const
Gets the engine metallic-roughness texture index.
bool hasMetallicRoughnessTexture() const
Checks whether the glTF material references a metallic-roughness texture.
Materials::MaterialData & getMaterialDataRef()
Gets mutable engine material data generated from glTF and extension data.
std::filesystem::path lightmapPath
uint32_t normalTextureIndex
int32_t gltfEmissiveTextureIndex
glm::vec4 baseColorFactor
uint32_t emissiveTextureIndex
bool hasLightmapTexture() const
Checks whether this material uses a lightmap texture path.
std::string getShaderName() const
Gets the shader name selected for this material.
std::vector< GltfMeshPrimitiveData > getPrimitives() const
Gets a copy of parsed primitives.
std::string getName() const
Gets the mesh node name.
int skinIndex
glTF skin index (-1 = no skin)
GltfMeshData(const tinygltf::Model &model, const tinygltf::Mesh &mesh, const tinygltf::Node &node, const glm::mat4 &transform)
Parses one mesh node into engine primitive data.
std::vector< GltfMeshPrimitiveData > & getPrimitivesRef()
Gets mutable parsed primitives.
std::vector< GltfMeshPrimitiveData > primitives
glm::mat4 getTransform() const
Gets the imported model transform for the mesh node.
int getSkinIndex() const
Gets the glTF skin index referenced by the mesh node.
GltfMaterialData getMaterialData() const
Gets material data parsed for this primitive.
const std::vector< BoneVertexData > & getBoneVertexData() const
Gets per-vertex bone weights and joint indices.
GltfMeshPrimitiveData()=default
Creates empty primitive data.
RuntimeTexture * colorTexturePtr
bool hasSkinData() const
Checks whether this primitive has skinning data.
uint32_t getColorTextureIndex() const
Gets the glTF color texture index referenced by this primitive.
std::vector< Vertex > vertices
std::vector< Vertex > getVertices() const
Gets the vertices parsed for this primitive.
RuntimeTexture * getColorTexturePtr() const
Gets the pointer to the primitive of the color texture.
GltfMeshPrimitiveData(tinygltf::Model model, tinygltf::Primitive primitive, StaticMeshExtensions meshSettings)
Extracts primitive geometry and material data from tinygltf objects.
std::vector< uint32_t > indices
tinygltf::Primitive primitive
std::vector< BoneVertexData > boneVertexData
Empty for static meshes.
std::vector< uint32_t > getIndices() const
Gets local primitive indices.
GltfMaterialData materialData
GltfTextureData()=default
Creates an empty texture payload.
bool hasTextureData() const
Checks whether an image payload is stored.
GltfTextureData(const tinygltf::Image &image)
Stores an image payload from tinygltf.
tinygltf::Image getImage() const
Gets the stored tinygltf image.
Resolved vertex attribute and index views for a glTF primitive.
std::optional< GltfBufferDataView > uvDataView
TEXCOORD_0 attribute view when present.
std::optional< GltfBufferDataView > positionDataView
POSITION attribute view when present.
std::optional< GltfBufferDataView > normalDataView
NORMAL attribute view when present.
std::optional< GltfBufferDataView > indexDataView
Primitive index accessor view.
GltfVertexData(const std::vector< tinygltf::Buffer > &buffers, const std::vector< tinygltf::BufferView > &bufferViews, const std::vector< tinygltf::Accessor > &accessors, const tinygltf::Primitive &primitive)
Extracts known attribute views from a primitive.
std::optional< GltfBufferDataView > jointsDataView
JOINTS_0 attribute view when present.
std::optional< GltfBufferDataView > tangentDataView
TANGENT attribute view when present. The xyz values store tangent direction and w stores handedness.
std::optional< GltfBufferDataView > lightmapDataView
TEXCOORD_1 attribute view when present.
std::optional< GltfBufferDataView > weightsDataView
WEIGHTS_0 attribute view when present.
MaterialExtensions()=default
Creates an empty material extension bundle.
std::optional< VulkanSchneeMaterialExtension > vulkanSchneeMaterialExtension
Parsed Vulkan Schnee material extension when present.
MaterialExtensions(const tinygltf::ExtensionMap &material)
Parses material-level glTF extensions recognized by the engine.
Parsed extension bundle for one mesh or node.
StaticMeshExtensions(const tinygltf::Model &model, const tinygltf::ExtensionMap &extensions)
Parses mesh or node extensions with access to model-dependent data.
StaticMeshExtensions(const tinygltf::ExtensionMap &extensions)
Parses mesh or node extensions without model-dependent data.
StaticMeshExtensions()=default
Creates an empty static mesh extension bundle.
std::optional< VulkanSchneeExtension > vulkanSchneeExtension
Parsed Vulkan Schnee engine extension when present.
StaticMeshSettings(const tinygltf::Value &extras)
Parses lightmap settings from a tinygltf extras object.
StaticMeshSettings()=default
Creates settings with lightmaps disabled.
std::filesystem::path lightMapPath
Path to the baked lightmap texture.
bool bUsesLightMaps
True when the mesh uses baked lightmaps.
int lightMapUvIndex
UV channel index used for lightmap sampling.
Syntax-level reference from an owning mesh node to an AnchorPoint node.
uint32_t nodeIndex
Referenced entry in the source glTF node array.
std::string name
Authored empty-node name used for runtime lookup.
Child shape data for compound collision.
std::vector< uint32_t > edgeIndices
Child edge indices used by collision visualization and hull tooling.
glm::vec3 offset
Child local offset relative to the parent collision shape.
std::string name
Authored child mesh name.
std::vector< glm::vec3 > vertices
Child collision vertices in child-local space after imported transforms are applied.
std::vector< uint32_t > indices
Child triangle indices.
glm::quat rotation
Child local rotation relative to the parent collision shape.
std::string collisionProfile
Named collision response profile imported from the authoring tool.
ShapeType
Collision shape type imported from the engine glTF extension.
@ CAPSULE
Capsule shape using capsuleRadius and capsuleHeight.
@ SPHERE
Sphere shape using sphereRadius.
@ COMPOUND
Compound shape assembled from child collision meshes.
@ NONE
No collision shape was authored.
@ BOX
Axis-aligned box shape using boxHalfExtents.
@ TRIANGLE_MESH
Triangle mesh built from imported vertices and indices.
@ CONVEX_HULL
Convex hull built from imported vertices.
CollisionProperties()=default
Creates collision settings with collision disabled.
std::vector< uint32_t > indices
Triangle indices for triangle mesh collision.
float capsuleHeight
Height for capsule collision.
bool hasCollision() const
Checks whether this record describes a collision shape.
bool generateConvexHull
True when runtime collision generation should build a convex hull.
float capsuleRadius
Radius for capsule collision.
glm::vec3 offset
Local collision shape offset in node space.
static ShapeType parseShapeType(const std::string &typeStr)
CollisionProperties(const tinygltf::Value &extension, const tinygltf::Model *model=nullptr)
Parses collisionProperties from the engine extension.
std::vector< CompoundChild > compoundChildren
Compound collision children.
std::vector< glm::vec3 > vertices
Collision vertices for convex hull and triangle mesh shapes.
glm::vec3 boxHalfExtents
Half extents for box collision.
float sphereRadius
Radius for sphere collision.
ShapeType shapeType
Shape type selected by collisionType.
glm::vec3 direction
Direction vector in glTF node space or exported world space, depending on authoring data.
glm::vec3 color
RGB light color.
bool castsShadows
True when the directional light casts shadows.
bool enabled
True when the imported light should spawn enabled.
float angularDiameterDegrees
Angular diameter used for sun disk and soft shadow calculations.
float intensity
Light intensity in engine lighting units.
DirectionalLightProperties(const tinygltf::Value &extension)
Parses directional light settings from directionalLightProperties.
bool hasDirection
True when the extension supplied a non-zero direction vector.
bool isLightmapPathValid() const
Checks whether either lightmap path is present.
uint32_t lightmapUvIndex
UV set index used for lightmap sampling.
std::filesystem::path lightmapPath
Authored lightmap image path, usually relative to the glTF file.
LightmapProperties(const tinygltf::Value &extension)
Parses a lightmapProperties object.
std::filesystem::path lightmapKtxPath
Runtime KTX lightmap path when the export converted the source image.
const std::filesystem::path & getRuntimeLightmapPath() const
Gets the texture path used at runtime.
std::optional< LightmapProperties > lightmapProperties
bool getReceiveShadows() const
Checks whether the object receives shadows.
bool getCastShadows() const
Checks whether the object casts shadows.
bool getHasLightmaps() const
Checks whether the object uses baked lightmaps.
LightProperties(const tinygltf::Value &extension)
Parses lightingProperties from the parent engine extension object.
bool collisionEnabled
True when authored collision should be enabled on the spawned mesh actor.
bool isStatic
True when the object is authored as static.
MeshProperties(const tinygltf::Value &extension)
Parses meshProperties from the parent engine extension object.
float cullDistance
Distance at which the light can be culled.
float intensity
Light intensity in engine lighting units.
glm::vec3 color
RGB light color.
float radius
Point light influence radius.
PointLightProperties(const tinygltf::Value &extension)
Parses point light settings from pointLightProperties.
VulkanSchneeExtension(const tinygltf::Value &vs_extension, const tinygltf::Model *model=nullptr)
Parses the engine extension object.
VulkanSchneeExtension()=default
Creates an empty extension record.
std::optional< LightProperties > lightProperties
Parsed object lighting flags when lightingProperties is present.
bool hasPointLightProperties() const
Checks whether point light settings were parsed.
std::optional< DirectionalLightProperties > directionalLightProperties
Parsed directional light settings when directionalLightProperties is present.
bool hasCollisionProperties() const
Checks whether collision settings were parsed.
static std::string extractVersion(const tinygltf::Value &vs_extension)
Extracts the version from the material extension.
bool hasAnchorPoints() const
Checks whether valid AnchorPoint references were parsed.
std::vector< AnchorPointReference > anchorPoints
Valid AnchorPoint references parsed from the extension.
std::optional< PointLightProperties > pointLightProperties
Parsed point light settings when pointLightProperties is present.
bool hasLightProperties() const
Checks whether object lighting flags were parsed.
bool hasMeshProperties() const
Checks whether mesh behavior flags were parsed.
bool hasLightmapProperties() const
Checks whether lightmap settings were parsed.
std::optional< MeshProperties > meshProperties
Parsed mesh behavior flags when meshProperties is present.
std::optional< LightProperties::LightmapProperties > lightmapProperties
Parsed lightmap settings when lightmapProperties is present.
std::optional< CollisionProperties > collisionProperties
Parsed collision settings when collisionProperties is present.
bool hasDirectionalLightProperties() const
Checks whether directional light settings were parsed.
std::string type
Parameter source type, usually connected or value.
ShaderParameter(const tinygltf::Value ¶m)
Parses one shader parameter object.
std::string socketType
Blender socket type string for the parameter.
tinygltf::Value value
Direct parameter value when type is value.
Parsed VULKAN_SCHNEE_materials material extension data.
std::map< std::string, tinygltf::Value > customProperties
Custom material properties preserved as tinygltf values.
VulkanSchneeMaterialExtension()=default
Creates an empty material extension record.
VulkanSchneeMaterialExtension(const tinygltf::Value &vs_extension)
Parses a VULKAN_SCHNEE_materials extension object.
std::string shaderType
Shader type string exported by the Blender material node.
bool normalMapBC5
True when the normal map texture uses BC5 two-channel encoding.
std::map< std::string, ShaderParameter > shaderParameters
Shader socket parameters keyed by exported socket name.
Rendering::PipelineNames materialName
Renderer pipeline name resolved from shaderType.
std::map< std::string, double > nodeProperties
Numeric node properties keyed by exported property name.
CPU geometry for one mesh primitive before renderer upload.