GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Model.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_RESOURCE_MODEL_HPP
5#define GREM_RESOURCE_MODEL_HPP
6
8
31#include <GREM/core/math.hpp>
34
35#include <stdexcept> // std::out_of_range
36
37namespace grem {
38class Filesystem; // Forward declaration, to avoid including Filesystem.hpp.
39} // namespace grem
40
41namespace grem::gltf {
42struct Asset; // Forward declaration, to avoid including gltf.hpp.
43} // namespace grem::gltf
44
45namespace grem::obj {
46struct Asset; // Forward declaration, to avoid including obj.hpp.
47namespace mtl {
48struct Library; // Forward declaration, to avoid including obj.hpp.
49} // namespace mtl
50} // namespace grem::obj
51
52namespace grem::resource {
53
57enum class ModelFileType : uint8_t {
62};
63
71 vec3 rootTranslation{0.0f, 0.0f, 0.0f};
72
76 quat rootRotation{0.0f, 0.0f, 0.0f, 1.0f};
77
81 vec3 rootScale{1.0f, 1.0f, 1.0f};
82
89 bool excludeAnimations = false;
90
97 bool excludeLights = false;
98
108 bool excludeColliders = false;
109
116 bool excludePhysics = false;
117
125 [[nodiscard]] constexpr bool operator==(const ModelOptions& other) const = default;
126};
127
132struct Model {
133 static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ >= 4); // Make sure the 4-byte values stored in the data arrays will be properly aligned.
134
135 using ValueOffset = uint32_t;
136 using IndexCount = uint32_t;
137 using VertexCount = uint32_t;
138 using MorphTargetCount = uint32_t;
139 using KeyframeCount = uint32_t;
140 using MorphTargetWeightIndex = uint32_t;
142 using TextureIndex = uint32_t;
144 using MaterialIndex = uint32_t;
146 using MeshIndex = uint32_t;
148 using JointIndex = uint32_t;
150 using AnimationChannelIndex = uint32_t;
152 using AnimationIndex = uint32_t;
154 using InstanceIndex = uint32_t;
156 using LightIndex = uint32_t;
158 using PhysicsObjectIndex = uint32_t;
160 using PhysicsJointIndex = uint32_t;
162
163 static constexpr size_t MAX_COLLISION_LAYER_COUNT = 32;
165 using CollisionLayerIndex = uint8_t;
166
168 using VertexFlags = uint16_t;
169
183
185 using FragmentFlags = uint16_t;
186
203
205 using InstanceFlags = uint8_t;
206
208 enum InstanceFlag : InstanceFlags { // NOLINT(cppcoreguidelines-use-enum-class)
210 };
211
213 enum class PrimitiveType : uint8_t {
214 POINTS = 0,
215 LINES = 1,
216 // Note: LINE_LOOP is intentionally omitted since Vulkan does not support it.
220 };
221
282
285
287 enum class MinificationFilter : uint32_t { // NOLINT(performance-enum-size)
289 NEAREST = 9728,
290 LINEAR = 9729,
295 };
296
298 enum class MagnificationFilter : uint32_t { // NOLINT(performance-enum-size)
300 NEAREST = 9728,
301 LINEAR = 9729,
302 };
303
305 enum class WrappingMode : uint32_t { // NOLINT(performance-enum-size)
306 REPEAT = 10497,
309 };
310
319
324 enum class MaterialType : uint8_t {
326 UNLIT = 1,
327 };
328
353
382
388
390 struct PointLight {
392 float intensity;
393 float range;
394 };
395
404
406 struct Light : Variant<DirectionalLight, PointLight, SpotLight> {
408 };
409
411 struct PlaneShape {
412 float sizeX;
413 float sizeZ;
415 };
416
418 struct SphereShape {
419 float radius;
420 };
421
423 struct BoxShape {
425 };
426
431 float topRadius;
432 };
433
438 float topRadius;
439 };
440
443
446
449
459
466 enum class FrictionCombine : uint8_t {
471 };
472
479 enum class RestitutionCombine : uint8_t {
484 };
485
503
532
540
548
550 enum class InterpolationMode : uint8_t {
554 };
555
568
585
588
591
594
597
600
603
630
678
682 struct PoseView {
687
693 };
694
703
709
715 constexpr operator PoseView() const noexcept {
716 return PoseView{.localJoints = localJoints, .localMorphTargetWeights = localMorphTargetWeights};
717 }
718
727 GREM_API(resource) PoseReference applyAnimation(const AnimationState& animationState) const; // NOLINT(modernize-use-nodiscard)
728 };
729
733 struct Pose {
736
742 constexpr operator PoseReference() noexcept {
743 return PoseReference{.localJoints = localJoints.data(), .localMorphTargetWeights = localMorphTargetWeights.data()};
744 }
745
751 constexpr operator PoseView() const noexcept {
752 return PoseView{.localJoints = localJoints.data(), .localMorphTargetWeights = localMorphTargetWeights.data()};
753 }
754
763 Pose& applyAnimation(const AnimationState& animationState) {
764 static_cast<PoseReference>(*this).applyAnimation(animationState);
765 return *this;
766 }
767 };
768
774 const bool* jointsVisible;
775 const float* morphTargetWeights;
776 };
777
785
791 constexpr operator TransformationView() const noexcept {
792 return TransformationView{.jointMatrices = jointMatrices, .jointsVisible = jointsVisible, .morphTargetWeights = morphTargetWeights};
793 }
794
812 GREM_API(resource) void pose(Span<const Joint> localJoints, Span<const float> localMorphTargetWeights, Span<const JointIndex> modelJointParentIndices) const;
813 };
814
822
828 constexpr operator TransformationReference() noexcept {
829 return TransformationReference{.jointMatrices = jointMatrices.data(), .jointsVisible = jointsVisible.data(), .morphTargetWeights = morphTargetWeights.data()};
830 }
831
837 constexpr operator TransformationView() const noexcept {
838 return TransformationView{.jointMatrices = jointMatrices.data(), .jointsVisible = jointsVisible.data(), .morphTargetWeights = morphTargetWeights.data()};
839 }
840
858 void assign(const mat4& rootTransformation, Span<const Joint> localJoints, Span<const float> localMorphTargetWeights, Span<const JointIndex> modelJointParentIndices) {
859 const size_t jointCount = localJoints.size();
860 GREM_ASSERT(modelJointParentIndices.size() == jointCount);
861 // Make sure resize() doesn't over-allocate, since jointMatrices and jointsVisible are unlikely to grow.
862 // Without this, we'd just be wasting memory (and cache) in the typical case.
863 if (jointCount > jointMatrices.capacity()) {
864 [[unlikely]];
865 jointMatrices.reserve(jointCount);
866 jointsVisible.reserve(jointCount);
867 }
868 jointMatrices.resize(jointCount);
869 jointMatrices.front() = rootTransformation;
870 jointsVisible.resize(jointCount);
871 jointsVisible.front() = true;
872 morphTargetWeights.assign(localMorphTargetWeights.size(), 0.0f);
873 pose(localJoints, localMorphTargetWeights, modelJointParentIndices);
874 }
875
893 void pose(Span<const Joint> localJoints, Span<const float> localMorphTargetWeights, Span<const JointIndex> modelJointParentIndices) {
894 GREM_ASSERT(localJoints.size() == jointMatrices.size());
895 GREM_ASSERT(localMorphTargetWeights.size() == morphTargetWeights.size());
896 GREM_ASSERT(modelJointParentIndices.size() == localJoints.size());
897 static_cast<TransformationReference>(*this).pose(localJoints, localMorphTargetWeights, modelJointParentIndices);
898 }
899 };
900
927
953 GREM_ASSERT(normalData.size_bytes() % sizeof(iA2B10G10R10vec4norm) == 0);
954 generateTriangleNormals(StridedSpan{normalData.data(), normalData.size_bytes() / sizeof(iA2B10G10R10vec4norm), sizeof(iA2B10G10R10vec4norm)}, positions, indices);
955 }
956
983
1015 GREM_API(resource)
1016 static void generateTriangleTangents(StridedSpan<byte> tangentData, StridedSpan<const vec3> positions, StridedSpan<const iA2B10G10R10vec4norm> normals,
1017 StridedSpan<const vec2> textureCoordinates, StridedSpan<const uint32_t> indices);
1018
1049 static void generateTriangleTangents(Span<byte> tangentData, StridedSpan<const vec3> positions, StridedSpan<const iA2B10G10R10vec4norm> normals,
1050 StridedSpan<const vec2> textureCoordinates, StridedSpan<const uint32_t> indices) {
1051 GREM_ASSERT(tangentData.size_bytes() % sizeof(iA2B10G10R10vec4norm) == 0);
1052 generateTriangleTangents(StridedSpan{tangentData.data(), tangentData.size_bytes() / sizeof(iA2B10G10R10vec4norm), sizeof(iA2B10G10R10vec4norm)}, positions, normals,
1053 textureCoordinates, indices);
1054 }
1055
1086 StridedSpan<const vec2> textureCoordinates, Span<const uint32_t> indices) {
1087 generateTriangleTangents(as_strided_writable_bytes(tangents), positions, normals, textureCoordinates, indices);
1088 }
1089
1099 [[nodiscard]] GREM_API(resource) static ModelFileType determineFileType(Span<const byte> fileContents) noexcept;
1100
1129
1138 Model() noexcept = default;
1139
1169 GREM_API(resource)
1170 Model(StridedSpan<const vec3> positions, StridedSpan<const uint32_t> indices, StridedSpan<const iA2B10G10R10vec4norm> normals = {},
1171 StridedSpan<const iA2B10G10R10vec4norm> tangents = {}, StridedSpan<const vec2> textureCoordinatesChannel0 = {}, StridedSpan<const vec2> textureCoordinatesChannel1 = {},
1172 StridedSpan<const u8vec4norm> colors = {}, const Optional<Material>& material = {});
1173
1185 Model(const ConvexPolytope<3, float>& polytope, const mat4& transformation = mat4{1.0f});
1186
1217 GREM_API(resource) Model(const Filesystem& filesystem, CStringView filepath, const ModelOptions& options = {});
1218
1236 GREM_API(resource)
1237 Model(const gltf::Asset& asset, FunctionView<Image(CStringView relativeFilepath, const ImageOptions& options)> loadImage,
1238 FunctionView<Variant<Allocation<byte>, Span<const byte>>(CStringView relativeFilepath)> loadBufferData, const ModelOptions& options = {});
1239
1258 GREM_API(resource)
1259 Model(const obj::Asset& asset, const obj::mtl::Library& materialLibrary, FunctionView<Image(CStringView relativeFilepath, const ImageOptions& options)> loadImage,
1260 const ModelOptions& options = {});
1261
1270 void reset() noexcept {
1271 meshData.clear();
1272 morphTargetData.clear();
1273 skinData.clear();
1274 meshes.clear();
1275 bindPose.localJoints.clear();
1276 bindPose.localMorphTargetWeights.clear();
1277 jointParentIndices.clear();
1278 jointColliders.clear();
1280 staticJointCount = 0;
1281 animations.clear();
1282 animationChannels.clear();
1285 textures.clear();
1286 materials.clear();
1287 instances.clear();
1288 lights.clear();
1289 physicsObjects.clear();
1290 physicsJoints.clear();
1293 jointMap.clear();
1294 skinMap.clear();
1295 animationMap.clear();
1296 textureMap.clear();
1297 materialMap.clear();
1298 lightMap.clear();
1299 collisionLayerMap.clear();
1300 }
1301
1331 GREM_API(resource)
1332 void assign(StridedSpan<const vec3> positions, StridedSpan<const uint32_t> indices, StridedSpan<const iA2B10G10R10vec4norm> normals = {},
1333 StridedSpan<const iA2B10G10R10vec4norm> tangents = {}, StridedSpan<const vec2> textureCoordinatesChannel0 = {}, StridedSpan<const vec2> textureCoordinatesChannel1 = {},
1334 StridedSpan<const u8vec4norm> colors = {}, const Optional<Material>& material = {});
1335
1347 void assign(const ConvexPolytope<3, float>& polytope, const mat4& transformation = mat4{1.0f});
1348
1379 GREM_API(resource) void load(const Filesystem& filesystem, CStringView filepath, const ModelOptions& options = {});
1380
1398 GREM_API(resource)
1399 void load(const gltf::Asset& asset, FunctionView<Image(CStringView relativeFilepath, const ImageOptions& options)> loadImage,
1400 FunctionView<Variant<Allocation<byte>, Span<const byte>>(CStringView relativeFilepath)> loadBufferData, const ModelOptions& options = {});
1401
1420 GREM_API(resource)
1421 void load(const obj::Asset& asset, const obj::mtl::Library& materialLibrary, FunctionView<Image(CStringView relativeFilepath, const ImageOptions& options)> loadImage,
1422 const ModelOptions& options = {});
1423
1432 [[nodiscard]] Optional<AnimationIndex> findAnimationIndex(StringView name) const noexcept {
1433 if (const auto it = animationMap.find(name); it != animationMap.end()) {
1434 return it->second;
1435 }
1436 return {};
1437 }
1438
1448 [[nodiscard]] AnimationIndex getAnimationIndex(StringView name) const {
1449 if (const Optional<AnimationIndex> animationIndex = findAnimationIndex(name)) {
1450 return *animationIndex;
1451 }
1452 throw std::out_of_range{"Animation \"" + String{name} + "\" not found."};
1453 }
1454
1465 if (static_cast<size_t>(index) >= animations.size()) {
1466 throw std::out_of_range{"Invalid animation index."};
1467 }
1468 const Animation& animation = animations[index];
1469 const AnimationChannelIndex animationChannelsBegin = animation.animationChannelOffset;
1470 const AnimationChannelIndex animationChannelsEnd =
1471 (index + 1 < animations.size()) ? animations[index + 1].animationChannelOffset : static_cast<AnimationChannelIndex>(animationChannels.size());
1472 return AnimationView{
1473 .minTimePoint = animation.minTimePoint,
1474 .maxTimePoint = animation.maxTimePoint,
1475 .channels = Span{animationChannels}.subspan(animationChannelsBegin, animationChannelsEnd - animationChannelsBegin),
1476 .keyframeInputTimePoints = keyframeInputTimePoints,
1477 .keyframeOutputValueData = keyframeOutputValueData,
1478 };
1479 }
1480
1490 [[nodiscard]] AnimationView getAnimation(StringView name) const {
1492 }
1493
1502 [[nodiscard]] Optional<AnimationView> findAnimation(StringView name) const noexcept {
1503 if (const Optional<AnimationIndex> animationIndex = findAnimationIndex(name)) {
1504 return getAnimationAtIndex(*animationIndex);
1505 }
1506 return {};
1507 }
1508
1517 [[nodiscard]] Optional<JointIndex> findJointIndex(StringView name) const noexcept {
1518 if (const auto it = jointMap.find(name); it != jointMap.end()) {
1519 return it->second;
1520 }
1521 return {};
1522 }
1523
1533 [[nodiscard]] JointIndex getJointIndex(StringView name) const {
1534 if (const Optional<JointIndex> jointIndex = findJointIndex(name)) {
1535 return *jointIndex;
1536 }
1537 throw std::out_of_range{"Joint \"" + String{name} + "\" not found."};
1538 }
1539
1548 [[nodiscard]] Optional<JointIndex> findSkinRootJointIndex(StringView name) const noexcept {
1549 if (const auto it = skinMap.find(name); it != skinMap.end()) {
1550 return it->second;
1551 }
1552 return {};
1553 }
1554
1565 [[nodiscard]] JointIndex getSkinRootJointIndex(StringView name) const {
1566 if (const Optional<JointIndex> rootJointIndex = findSkinRootJointIndex(name)) {
1567 return *rootJointIndex;
1568 }
1569 throw std::out_of_range{"Skin \"" + String{name} + "\" not found."};
1570 }
1571
1580 [[nodiscard]] Optional<TextureIndex> findTextureIndex(StringView name) const noexcept {
1581 if (const auto it = textureMap.find(name); it != textureMap.end()) {
1582 return it->second;
1583 }
1584 return {};
1585 }
1586
1596 [[nodiscard]] TextureIndex getTextureIndex(StringView name) const {
1597 if (const Optional<TextureIndex> textureIndex = findTextureIndex(name)) {
1598 return *textureIndex;
1599 }
1600 throw std::out_of_range{"Texture \"" + String{name} + "\" not found."};
1601 }
1602
1611 [[nodiscard]] Optional<MaterialIndex> findMaterialIndex(StringView name) const noexcept {
1612 if (const auto it = materialMap.find(name); it != materialMap.end()) {
1613 return it->second;
1614 }
1615 return {};
1616 }
1617
1627 [[nodiscard]] MaterialIndex getMaterialIndex(StringView name) const {
1628 if (const Optional<MaterialIndex> materialIndex = findMaterialIndex(name)) {
1629 return *materialIndex;
1630 }
1631 throw std::out_of_range{"Material \"" + String{name} + "\" not found."};
1632 }
1633
1642 [[nodiscard]] Optional<LightIndex> findLightIndex(StringView name) const noexcept {
1643 if (const auto it = lightMap.find(name); it != lightMap.end()) {
1644 return it->second;
1645 }
1646 return {};
1647 }
1648
1658 [[nodiscard]] LightIndex getLightIndex(StringView name) const {
1659 if (const Optional<LightIndex> lightIndex = findLightIndex(name)) {
1660 return *lightIndex;
1661 }
1662 throw std::out_of_range{"Light \"" + String{name} + "\" not found."};
1663 }
1664
1674 if (const auto it = collisionLayerMap.find(name); it != collisionLayerMap.end()) {
1675 return it->second;
1676 }
1677 return {};
1678 }
1679
1691 if (const Optional<CollisionLayerIndex> collisionLayerIndex = findCollisionLayerIndex(name)) {
1692 return *collisionLayerIndex;
1693 }
1694 throw std::out_of_range{"Collision layer \"" + String{name} + "\" not found."};
1695 }
1696};
1697
1698} // namespace grem::resource
1699
1700#endif
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Definition Allocation.hpp:25
Definition ArrayList.hpp:27
Definition BitArray.hpp:23
Definition Buffer.hpp:28
Convex polytope.
Definition ConvexPolytope.hpp:171
Base interface for a filesystem.
Definition Filesystem.hpp:25
Definition FunctionView.hpp:29
Definition HashMap.hpp:30
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition SharedPointer.hpp:65
Definition Span.hpp:146
constexpr detail::subspan_type_t< T, EXTENT, Offset, N > subspan() const
Definition Span.hpp:284
constexpr size_type size_bytes() const noexcept
Definition Span.hpp:253
constexpr size_type size() const noexcept
Definition Span.hpp:207
constexpr pointer data() const noexcept
Definition Span.hpp:203
Definition StridedSpan.hpp:427
Definition algorithms.hpp:132
Tagged union value type that holds a value of one of the given types.
Definition Variant.hpp:293
friend class Variant
Definition Variant.hpp:1402
Definition concepts.hpp:243
Definition gltf.hpp:22
Definition obj.hpp:105
Definition aliases.hpp:18
Definition Window.hpp:15
ModelFileType
File type of a Model.
Definition Model.hpp:57
@ GLTF_BINARY
Binary glTF (.glb).
Definition Model.hpp:61
@ GLTF
glTF (.gltf).
Definition Model.hpp:60
@ OBJ
Wavefront OBJ (.obj).
Definition Model.hpp:59
@ UNKNOWN
Unknown file type.
Definition Image.hpp:31
Definition aliases.hpp:9
qua< float > quat
Definition math.hpp:892
Clock::duration Duration
Definition Clock.hpp:25
StridedSpan(R &&range) -> StridedSpan< std::remove_reference_t< decltype(*std::data(range))>, DYNAMIC_EXTENT, sizeof(std::remove_reference_t< decltype(*std::data(range))>)>
vec< 4, float > vec4
Definition math.hpp:440
vec< 2, float > vec2
Definition math.hpp:438
vec< 3, float > vec3
Definition math.hpp:439
mat< 2, 2, float > mat2
Definition math.hpp:804
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
auto as_strided_writable_bytes(StridedSpan< T, N, S > s) noexcept
Definition StridedSpan.hpp:734
mat< 4, 4, float > mat4
Definition math.hpp:806
constexpr Multiply MULTIPLY
Definition algorithms.hpp:92
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
Definition Pair.hpp:53
The root object for a glTF asset.
Definition gltf.hpp:769
Definition math.hpp:474
Collection of Node elements defined by an OBJ file.
Definition obj.hpp:83
Material library that stores the material properties for objects defined in an Asset.
Definition obj.hpp:153
Options for loading an image.
Definition Image.hpp:911
Configuration options for a Model.
Definition Model.hpp:67
vec3 rootScale
Scale to apply to the root joint of the model.
Definition Model.hpp:81
constexpr bool operator==(const ModelOptions &other) const =default
Compare these options to another set of options for equality.
bool excludePhysics
Exclude any physics information from the loaded model.
Definition Model.hpp:116
quat rootRotation
Rotation to apply to the root joint of the model.
Definition Model.hpp:76
bool excludeAnimations
Exclude any animations from the loaded model.
Definition Model.hpp:89
vec3 rootTranslation
Translation to apply to the root joint of the model.
Definition Model.hpp:71
bool excludeColliders
Exclude any colliders from the loaded model.
Definition Model.hpp:108
bool excludeLights
Exclude any lights from the loaded model.
Definition Model.hpp:97
Channel of a model animation.
Definition Model.hpp:557
AnimationPath targetPath
Target type.
Definition Model.hpp:565
MorphTargetWeightCount targetMorphTargetWeightCount
Number of affected morph target weights.
Definition Model.hpp:564
uint32_t targetOffset
Index into the joint array or morph target weight array.
Definition Model.hpp:563
KeyframeCount keyframeCount
Number of keyframes.
Definition Model.hpp:560
InterpolationMode interpolationMode
Interpolation type.
Definition Model.hpp:566
ValueOffset keyframeOutputValueOffset
Offset of the keyframe output values.
Definition Model.hpp:562
float maxTimePoint
End time of keyframes.
Definition Model.hpp:559
ValueOffset keyframeInputTimePointOffset
Offset of the keyframe input time points.
Definition Model.hpp:561
float minTimePoint
Start time of keyframes.
Definition Model.hpp:558
State of an animation affecting a pose.
Definition Model.hpp:634
Span< const float > jointBlendWeights
Normalized blend weights of each joint's influence on the pose.
Definition Model.hpp:661
bool looping
Whether the animation time should be wrapped or clamped when out of range of the animation.
Definition Model.hpp:676
Duration time
Current animation time from the start of the animation.
Definition Model.hpp:647
AnimationView animation
Animation to apply.
Definition Model.hpp:642
float blendWeight
Normalized overall blend weight of this animation's influence on the pose.
Definition Model.hpp:653
Span< const float > morphTargetWeightBlendWeights
Normalized blend weights of each morph target weight's influence on the pose.
Definition Model.hpp:670
Non-owning read-only view over a set of animation channels and their associated data.
Definition Model.hpp:608
float maxTimePoint
End time of all animation channels.
Definition Model.hpp:613
Span< const float > keyframeInputTimePoints
Non-owning read-only view over the keyframe input time points indexed by the animation channels.
Definition Model.hpp:622
Span< const AnimationChannel > channels
Non-owning read-only view over the animation channels.
Definition Model.hpp:616
float minTimePoint
Start time of all animation channels.
Definition Model.hpp:610
Span< const byte > keyframeOutputValueData
Non-owning read-only view over the keyframe output value data indexed by the animation channels.
Definition Model.hpp:628
Animation of a model.
Definition Model.hpp:570
float minTimePoint
Start time of all animation channels.
Definition Model.hpp:572
AnimationChannelIndex animationChannelOffset
Index of the first animation channel.
Definition Model.hpp:583
float maxTimePoint
End time of all animation channels.
Definition Model.hpp:575
Parameters describing a box shape.
Definition Model.hpp:423
vec3 size
Extents of the box in each axis in local space.
Definition Model.hpp:424
Parameters describing a capsule shape.
Definition Model.hpp:435
float halfLength
Half of the distance between the centers of the two capping spheres of capsule.
Definition Model.hpp:436
float bottomRadius
Radius of the sphere located at the bottom of the capsule (i.e. the sphere at the half-height along -...
Definition Model.hpp:437
float topRadius
Radius of the sphere located at the top of the capsule (i.e. the sphere at the half-height along +Y).
Definition Model.hpp:438
Collider in a model.
Definition Model.hpp:451
CollisionLayers responseLayers
Collision layers that the collider responds to collisions with.
Definition Model.hpp:456
CollisionLayers layers
Collision layers that the collider belongs to.
Definition Model.hpp:453
Shape shape
Shape of the collider.
Definition Model.hpp:452
CollisionLayers noDetectionLayers
Collision layers that the collider skips collision detection with.
Definition Model.hpp:455
CollisionLayers detectionLayers
Collision layers that the collider detects collisions with.
Definition Model.hpp:454
CollisionLayers noResponseLayers
Collision layers that the collider skips collision response with.
Definition Model.hpp:457
Parameters describing a cylinder shape.
Definition Model.hpp:428
float halfLength
Half of the height of the cylinder, centered along the Y axis.
Definition Model.hpp:429
float bottomRadius
Radius of the bottom of the cylinder (the disk located along -Y.).
Definition Model.hpp:430
float topRadius
Radius of the top of the cylinder (the disk located along +Y.).
Definition Model.hpp:431
Parameters describing a directional light.
Definition Model.hpp:384
float intensity
Illuminance of the light, in lux, if it were colored pure white.
Definition Model.hpp:386
vec3 color
Color of the light in linear RGB space.
Definition Model.hpp:385
Mesh instance in a model.
Definition Model.hpp:355
MeshIndex meshIndex
Index of the instance's mesh.
Definition Model.hpp:360
ValueOffset skinDataOffset
Index of the first 4-byte value in the skin data in the model.
Definition Model.hpp:371
MorphTargetWeightIndex morphTargetWeightOffset
Offset of the initial morph target weights of the instance, or 0 if not morphed.
Definition Model.hpp:374
InstanceFlags instanceFlags
Instance flags of the instance.
Definition Model.hpp:380
MaterialIndex materialIndex
Index of the instance's material, or an out-of-range index if the instance uses the default material.
Definition Model.hpp:357
JointIndex jointIndex
Index of the joint that the instance is attached to.
Definition Model.hpp:377
State of a local joint in a pose of a model.
Definition Model.hpp:534
vec3 translation
Local position of the joint.
Definition Model.hpp:535
bool visible
Whether the joint and its children are currently visible or not.
Definition Model.hpp:538
vec3 scale
Local scale of the joint.
Definition Model.hpp:537
quat rotation
Local orientation of the joint.
Definition Model.hpp:536
Light source in a model.
Definition Model.hpp:406
JointIndex jointIndex
Index of the model joint that controls the position and direction of the light.
Definition Model.hpp:407
Information about how a material uses a texture.
Definition Model.hpp:332
vec2 textureOffset
Texture coordinate offset to apply when sampling the texture.
Definition Model.hpp:334
mat2 textureBasis
Texture coordinate basis to apply when sampling the texture.
Definition Model.hpp:335
TextureIndex textureIndex
Index of the texture in the model's texture array, or an out-of-range index for the default texture.
Definition Model.hpp:333
Material of a mesh instance in a model.
Definition Model.hpp:330
MaterialType materialType
How to interpret the material parameters when shading.
Definition Model.hpp:338
TextureInfo occlusionRoughnessMetallicMap
Occlusion-roughness-metallic map of the material (linearly encoded), or an out-of-range index for a f...
Definition Model.hpp:348
float roughnessFactor
Roughness factor of the material.
Definition Model.hpp:341
float metallicFactor
Metallic factor of the material.
Definition Model.hpp:342
float indexOfRefraction
Index of refraction of the material.
Definition Model.hpp:346
float occlusionStrength
Occlusion strength of the material.
Definition Model.hpp:340
TextureInfo baseColorMap
Base color map of the material (sRGB-encoded), or an out-of-range index for a fully white texture.
Definition Model.hpp:347
vec3 emissiveFactor
Emissive factor of the material.
Definition Model.hpp:344
TextureInfo emissiveMap
Emissive map of the material (sRGB-encoded), or an out-of-range index for a fully white texture.
Definition Model.hpp:350
float normalScale
Normal scale of the material.
Definition Model.hpp:343
float alphaCutoff
Alpha cutoff value of the material.
Definition Model.hpp:345
vec4 baseColorFactor
Base color factor of the material.
Definition Model.hpp:339
FragmentFlags fragmentFlags
Fragment flags of the material.
Definition Model.hpp:351
TextureInfo normalMap
Normal map of the material (linearly encoded), or an out-of-range index for a flat normal texture.
Definition Model.hpp:349
Range of indexed vertices in a model.
Definition Model.hpp:223
IndexCount indexCount
Number of indices of the mesh, or 0 if not indexed.
Definition Model.hpp:228
Box< 3, float > boundingBox
Local axis-aligned bounding box of the mesh's vertex positions.
Definition Model.hpp:274
ValueOffset morphedVertexStride
Stride, in 4-byte values, of the vertices in the morph targets in this mesh, or 0 if not morphed.
Definition Model.hpp:237
VertexCount vertexCount
Number of vertices in the mesh.
Definition Model.hpp:231
MorphTargetCount morphTargetCount
Number of morph targets/weights, or 0 if not morphed.
Definition Model.hpp:234
ValueOffset morphTargetDataOffset
Index of the first 4-byte value in the morph target data in the model.
Definition Model.hpp:271
ValueOffset meshDataOffset
Index of the first 4-byte value in the mesh data in the model.
Definition Model.hpp:253
float boundingRadius
Maximum distance from the origin of the mesh's vertex positions.
Definition Model.hpp:277
PrimitiveType primitiveType
Type of primitives formed by the vertices of the mesh.
Definition Model.hpp:225
VertexFlags vertexFlags
Vertex flags of the mesh.
Definition Model.hpp:280
Physics joint between two physics objects in a model.
Definition Model.hpp:505
vec3 minDistances
The minimum of the allowed range of relative distance along each axis.
Definition Model.hpp:515
vec3 angularDriveDamping
The damping of the angular drive, scaling the torque based on the target angular velocity.
Definition Model.hpp:530
vec3 maxDistances
The maximum of the allowed range of relative distance along each axis.
Definition Model.hpp:516
bool driveIgnoresMassZ
Whether the value computed from the spring equation is the linear acceleration or the force to apply ...
Definition Model.hpp:510
vec3 targetAngularVelocity
Target angular velocity about each axis that this drive attempts to achieve.
Definition Model.hpp:528
vec3 minAngles
The minimum of the allowed range of relative angle about each axis.
Definition Model.hpp:517
vec3 linearStiffnesses
The spring constants used to calculate a restorative force along each axis when the joint is extended...
Definition Model.hpp:519
bool driveIgnoresMomentOfInertiaX
Whether the value computed from the spring equation is the angular acceleration or the torque to appl...
Definition Model.hpp:511
vec3 targetPosition
Target translation along each axis that the drive attempts to achieve.
Definition Model.hpp:525
vec3 linearDamping
Damping applied to the linear velocity along each axis when the joint is extended beyond the limit.
Definition Model.hpp:521
bool enableCollision
Allow the connected objects to collide.
Definition Model.hpp:514
vec3 linearDriveDamping
The damping of the linear drive, scaling the force based on the target linear velocity.
Definition Model.hpp:529
vec3 targetAngles
Target angle about each axis that the drive attempts to achieve.
Definition Model.hpp:526
Pair< PhysicsObjectIndex > objectIndices
Ordered pair of indices of the connected physics objects, or the maximum value if there is no object.
Definition Model.hpp:506
vec3 maxForce
Maximum force applied along each driven linear axis.
Definition Model.hpp:523
vec3 targetLinearVelocity
Target linear velocity along each axis that this drive attempts to achieve.
Definition Model.hpp:527
bool driveIgnoresMassY
Whether the value computed from the spring equation is the linear acceleration or the force to apply ...
Definition Model.hpp:509
vec3 angularDamping
Damping applied to the angular velocity about each axis when the joint is extended beyond the limit.
Definition Model.hpp:522
bool driveIgnoresMomentOfInertiaZ
Whether the value computed from the spring equation is the angular acceleration or the torque to appl...
Definition Model.hpp:513
vec3 maxAngles
The maximum of the allowed range of relative angle about each axis.
Definition Model.hpp:518
bool driveIgnoresMomentOfInertiaY
Whether the value computed from the spring equation is the angular acceleration or the torque to appl...
Definition Model.hpp:512
bool driveIgnoresMassX
Whether the value computed from the spring equation is the linear acceleration or the force to apply ...
Definition Model.hpp:508
Pair< JointIndex > jointIndices
Ordered pair of indices of the joints serving as the attachment frames.
Definition Model.hpp:507
vec3 maxTorque
Maximum torque applied along each driven angular axis.
Definition Model.hpp:524
vec3 angularStiffnesses
The spring constants used to calculate a restorative torque about each axis when the joint is extende...
Definition Model.hpp:520
Physics object contained in a model.
Definition Model.hpp:487
RestitutionCombine restitutionCombine
How to combine the restitution when this object collides with another.
Definition Model.hpp:501
float gravityFactor
Gravity factor of the object.
Definition Model.hpp:495
float restitution
Coefficient of restitution of the object.
Definition Model.hpp:499
float dynamicFriction
Dynamic friction of the object.
Definition Model.hpp:497
vec3 initialLinearVelocity
Initial linear velocity of the object in local space.
Definition Model.hpp:493
float staticFriction
Static friction of the object.
Definition Model.hpp:496
vec3 centerOfMass
Local center of mass of the object.
Definition Model.hpp:490
vec3 initialAngularVelocity
Initial angular velocity of the object in local space.
Definition Model.hpp:494
quat inertiaOrientation
Orientation of the local moment of inertia tensor of the object.
Definition Model.hpp:492
float mass
Mass of the object, or 0 to calculate.
Definition Model.hpp:489
JointIndex jointIndex
Index of the model joint that is affected by the object.
Definition Model.hpp:488
FrictionCombine frictionCombine
How to combine the friction when this object collides with another.
Definition Model.hpp:500
float rollingResistance
Rolling resistance of the object.
Definition Model.hpp:498
vec3 principalMomentsOfInertia
Diagonal of the local moment of inertia tensor of the object, or 0 to calculate.
Definition Model.hpp:491
Parameters describing a plane shape.
Definition Model.hpp:411
bool doubleSided
Whether the plane is double-sided or not.
Definition Model.hpp:414
float sizeZ
Size of the plane in the local Z axis.
Definition Model.hpp:413
float sizeX
Size of the plane in the local X axis.
Definition Model.hpp:412
Parameters describing a point light.
Definition Model.hpp:390
vec3 color
Color of the light in linear RGB space.
Definition Model.hpp:391
float intensity
Luminous intensity of the light, in candela, if it were colored pure white.
Definition Model.hpp:392
Reference to a local pose of a model.
Definition Model.hpp:698
PoseReference applyAnimation(const AnimationState &animationState) const
Add the influence of an animation state to the current pose.
Joint * localJoints
Non-owning pointer to the current local joints of the pose.
Definition Model.hpp:702
float * localMorphTargetWeights
Non-owning pointer to the current local morph target weights of the pose.
Definition Model.hpp:708
Read-only view over a local pose of a model.
Definition Model.hpp:682
const Joint * localJoints
Non-owning read-only pointer to the current local joints of the pose.
Definition Model.hpp:686
const float * localMorphTargetWeights
Non-owning read-only pointer to the current local morph target weights of the pose.
Definition Model.hpp:692
Local pose of a model.
Definition Model.hpp:733
ArrayList< Joint > localJoints
Current local joints of the pose.
Definition Model.hpp:734
ArrayList< float > localMorphTargetWeights
Current local morph target weights of the pose.
Definition Model.hpp:735
Pose & applyAnimation(const AnimationState &animationState)
Add the influence of an animation state to the current pose.
Definition Model.hpp:763
Parameters describing a sphere shape.
Definition Model.hpp:418
float radius
Radius of the sphere.
Definition Model.hpp:419
Parameters describing a spot light.
Definition Model.hpp:397
vec3 color
Color of the light in linear RGB space.
Definition Model.hpp:398
float outerConeAngle
Angle, in radians, where the light cone fades to zero.
Definition Model.hpp:402
float innerConeAngle
Angle, in radians, where the light cone reaches maximum brightness.
Definition Model.hpp:401
float intensity
Luminous intensity of the light, in candela, if it were colored pure white.
Definition Model.hpp:399
Texture of a material in a model.
Definition Model.hpp:312
WrappingMode horizontalWrappingMode
Horizontal wrapping mode of the texture sampler.
Definition Model.hpp:316
MinificationFilter minificationFilter
Minification filter of the texture sampler.
Definition Model.hpp:314
MagnificationFilter magnificationFilter
Magnification filter of the texture sampler.
Definition Model.hpp:315
Image image
Texture image data.
Definition Model.hpp:313
WrappingMode verticalWrappingMode
Vertical wrapping mode of the texture sampler.
Definition Model.hpp:317
Reference to a world-space transformation of a model.
Definition Model.hpp:781
float * morphTargetWeights
Non-owning pointer to the morph target weights of the model.
Definition Model.hpp:784
mat4 * jointMatrices
Non-owning pointer to the world-space transformations of the joints in the model.
Definition Model.hpp:782
bool * jointsVisible
Non-owning pointer to the visibility flags of the joints in the model.
Definition Model.hpp:783
void pose(Span< const Joint > localJoints, Span< const float > localMorphTargetWeights, Span< const JointIndex > modelJointParentIndices) const
Skin the non-root joints of the transformation according to a local pose, relative to the current roo...
Read-only view over a world-space transformation of a model.
Definition Model.hpp:772
const mat4 * jointMatrices
Non-owning read-only pointer to the world-space transformations of the joints in the model.
Definition Model.hpp:773
const float * morphTargetWeights
Non-owning read-only pointer to the morph target weights of the model.
Definition Model.hpp:775
const bool * jointsVisible
Non-owning read-only pointer to the visibility flags of the joints in the model.
Definition Model.hpp:774
World-space transformation of a model.
Definition Model.hpp:818
ArrayList< float > morphTargetWeights
Morph target weights of the model.
Definition Model.hpp:821
ArrayList< bool > jointsVisible
Whether each joint in the model is currently visible.
Definition Model.hpp:820
void assign(const mat4 &rootTransformation, Span< const Joint > localJoints, Span< const float > localMorphTargetWeights, Span< const JointIndex > modelJointParentIndices)
Assign new joints and morph target weights to the transformation according to a local pose,...
Definition Model.hpp:858
void pose(Span< const Joint > localJoints, Span< const float > localMorphTargetWeights, Span< const JointIndex > modelJointParentIndices)
Skin the non-root joints of the transformation according to a local pose, relative to the current roo...
Definition Model.hpp:893
ArrayList< mat4 > jointMatrices
World-space transformations of the joints in the model.
Definition Model.hpp:819
AnimationIndex getAnimationIndex(StringView name) const
Get the index of an animation with a specific name.
Definition Model.hpp:1448
ArrayList< AnimationChannel > animationChannels
Animation channels of the model. Indexed by animations.
Definition Model.hpp:1111
HashMap< String, JointIndex, TransparentHash< StringView >, TransparentEqual< StringView > > JointMap
Map from name strings to joint indices.
Definition Model.hpp:587
MaterialType
Material type that specifies how the material parameters should be interpreted when shading a mesh in...
Definition Model.hpp:324
@ UNLIT
The shader should use only the base color at full brightness.
Definition Model.hpp:326
@ METALLIC_ROUGHNESS
The shader should interpret the material according to the standard metallic-roughness model.
Definition Model.hpp:325
LightMap lightMap
Map from light names to their index in the light array.
Definition Model.hpp:1127
PrimitiveType
Graphical primitive type formed by vertices in a model mesh.
Definition Model.hpp:213
@ TRIANGLE_STRIP
Each point, except the first two, forms a filled triangle with the previous two points.
Definition Model.hpp:219
@ POINTS
Individual points.
Definition Model.hpp:214
@ TRIANGLES
Each consecutive triple of points forms an individual filled triangle.
Definition Model.hpp:218
@ LINES
Each consecutive pair of points forms an individual line segment.
Definition Model.hpp:215
@ LINE_STRIP
Each point, except the first, forms a line segment to the previous point.
Definition Model.hpp:217
BitArray< MAX_COLLISION_LAYER_COUNT > CollisionLayers
Set of collision layers.
Definition Model.hpp:164
ArrayList< Material > materials
Materials of the model. Indexed by instances and materialMap.
Definition Model.hpp:1115
uint32_t PhysicsObjectIndex
Offset of a physics object in the model's physics object array.
Definition Model.hpp:158
Variant< resource::Image, resource::ImageView > Image
Image of a texture in a model.
Definition Model.hpp:284
uint16_t FragmentFlags
Set of FragmentFlag bits.
Definition Model.hpp:185
Model(const ConvexPolytope< 3, float > &polytope, const mat4 &transformation=mat4{1.0f})
Construct an untextured single-mesh model from a convex polytope.
AnimationView getAnimation(StringView name) const
Get the animation with a specific name.
Definition Model.hpp:1490
uint32_t MorphTargetWeightIndex
Offset of a morph target weight in the model's morph target weight array.
Definition Model.hpp:140
static ModelFileType determineFileType(Span< const byte > fileContents) noexcept
Determine which model file type a file should be parsed as based on the contents at the beginning of ...
uint32_t KeyframeCount
Number of keyframes in an animation channel of the model.
Definition Model.hpp:139
Buffer< byte > skinData
Skin data of the model. Indexed by instances.
Definition Model.hpp:1103
Buffer< byte > morphTargetData
Morph target data of the model. Indexed by meshes.
Definition Model.hpp:1102
AnimationMap animationMap
Map from animation names to their index in the animation array.
Definition Model.hpp:1124
CollisionLayerIndex getCollisionLayerIndex(StringView name) const
Get the index of a collision layer with a specific name.
Definition Model.hpp:1690
uint16_t VertexFlags
Set of VertexFlag bits.
Definition Model.hpp:168
uint32_t AnimationIndex
Offset of an animation in the model's animation array.
Definition Model.hpp:152
AnimationChannelIndex AnimationChannelCount
Number of animation channels in a range within the model's animation channel array.
Definition Model.hpp:151
ArrayList< float > keyframeInputTimePoints
Keyframe input time points of animation channels. Indexed by animationChannels.
Definition Model.hpp:1112
void reset() noexcept
Reset the model to an empty, invalid state that must not be rendered until the model is manually made...
Definition Model.hpp:1270
InstanceFlag
Single flag in a set of InstanceFlags, specifying information about a model mesh instance.
Definition Model.hpp:208
@ INSTANCE_REVERSE_WINDING_ORDER
Consider mesh faces with clockwise winding order as front-facing for this instance.
Definition Model.hpp:209
uint8_t InstanceFlags
Set of InstanceFlag bits.
Definition Model.hpp:205
uint32_t JointIndex
Offset of a joint in the model's joint array.
Definition Model.hpp:148
static void generateTriangleNormals(StridedSpan< iA2B10G10R10vec4norm > normals, StridedSpan< const vec3 > positions, StridedSpan< const uint32_t > indices)
Generate normal vectors for each vertex in a set of triangles.
Definition Model.hpp:980
Optional< LightIndex > findLightIndex(StringView name) const noexcept
Find the index of a light with a specific name.
Definition Model.hpp:1642
Buffer< byte > meshData
Mesh data of the model. Indexed by meshes.
Definition Model.hpp:1101
TextureMap textureMap
Map from texture names to their index in the texture array.
Definition Model.hpp:1125
MaterialIndex MaterialCount
Number of materials in a range within the model's material array.
Definition Model.hpp:145
uint32_t MaterialIndex
Offset of a material in the model's material array.
Definition Model.hpp:144
uint32_t InstanceIndex
Offset of an instance in the model's instance array.
Definition Model.hpp:154
HashMap< String, CollisionLayerIndex, TransparentHash< StringView >, TransparentEqual< StringView > > CollisionLayerMap
Map from name strings to collision layer indices.
Definition Model.hpp:602
Optional< MaterialIndex > findMaterialIndex(StringView name) const noexcept
Find the index of a material with a specific name.
Definition Model.hpp:1611
HashMap< String, MaterialIndex, TransparentHash< StringView >, TransparentEqual< StringView > > MaterialMap
Map from name strings to material indices.
Definition Model.hpp:596
JointIndex getSkinRootJointIndex(StringView name) const
Get the index of the root joint of a skin with a specific name.
Definition Model.hpp:1565
Model() noexcept=default
Construct an empty, invalid model that must not be rendered until manually made valid.
uint32_t MorphTargetCount
Number of morph targets in a mesh of the model.
Definition Model.hpp:138
JointMap skinMap
Map from skin names to the index of their root joint in the joint array.
Definition Model.hpp:1123
Variant< PlaneShape, SphereShape, BoxShape, CylinderShape, CapsuleShape, ConvexPolytopeShape, TriangleMeshShape > Shape
Collision shape in a model.
Definition Model.hpp:448
HashMap< String, LightIndex, TransparentHash< StringView >, TransparentEqual< StringView > > LightMap
Map from name strings to light indices.
Definition Model.hpp:599
PhysicsJointIndex PhysicsJointCount
Number of physics joints in a range within the model's physics joint array.
Definition Model.hpp:161
void assign(StridedSpan< const vec3 > positions, StridedSpan< const uint32_t > indices, StridedSpan< const iA2B10G10R10vec4norm > normals={}, StridedSpan< const iA2B10G10R10vec4norm > tangents={}, StridedSpan< const vec2 > textureCoordinatesChannel0={}, StridedSpan< const vec2 > textureCoordinatesChannel1={}, StridedSpan< const u8vec4norm > colors={}, const Optional< Material > &material={})
Assign a basic single-mesh model from raw mesh data.
AnimationIndex AnimationCount
Number of animations in a range within the model's animation array.
Definition Model.hpp:153
AnimationPath
Target type of a model animation channel.
Definition Model.hpp:542
@ JOINT_SCALE
The animation targets the scale of a local joint.
Definition Model.hpp:544
@ JOINT_ROTATION
The animation targets the rotation of a local joint.
Definition Model.hpp:543
@ JOINT_TRANSLATION
The animation targets the translation of a local joint.
Definition Model.hpp:545
@ MORPH_TARGET_WEIGHTS
The animation targets the morph target weights of the model.
Definition Model.hpp:546
uint32_t IndexCount
Number of indices in a mesh of the model.
Definition Model.hpp:136
uint32_t LightIndex
Offset of a light in the model's light array.
Definition Model.hpp:156
MeshIndex MeshCount
Number of meshes in a range within the model's mesh array.
Definition Model.hpp:147
SharedPointer< ConvexPolytope< 3, float > > ConvexPolytopeShape
Parameters describing a convex polytope shape.
Definition Model.hpp:442
ArrayList< PhysicsJoint > physicsJoints
Physics joints in the model.
Definition Model.hpp:1119
FragmentFlag
Single flag in a set of FragmentFlags, specifying fragment shader usage.
Definition Model.hpp:188
@ FRAGMENT_BASE_COLOR_MAPPED_ON_CHANNEL_0
The base color map is sampled using texture coordinate channel 0.
Definition Model.hpp:192
@ FRAGMENT_ALPHA_MASKED
Fragments with alpha less than the alpha cutoff are discarded.
Definition Model.hpp:189
@ FRAGMENT_METALLIC_ROUGHNESS_MAPPED_ON_CHANNEL_0
The metallic/roughness map is sampled using texture coordinate channel 0.
Definition Model.hpp:194
@ FRAGMENT_EMISSIVE_MAPPED_ON_CHANNEL_0
The emissive map is sampled using texture coordinate channel 0.
Definition Model.hpp:200
@ FRAGMENT_EMISSIVE_MAPPED_ON_CHANNEL_1
The emissive map is sampled using texture coordinate channel 1.
Definition Model.hpp:201
@ FRAGMENT_ALPHA_BLENDED
Fragments are alpha blended.
Definition Model.hpp:190
@ FRAGMENT_NORMAL_MAPPED_ON_CHANNEL_0
The normal map is sampled using texture coordinate channel 0.
Definition Model.hpp:198
@ FRAGMENT_METALLIC_ROUGHNESS_MAPPED_ON_CHANNEL_1
The metallic/roughness map is sampled using texture coordinate channel 1.
Definition Model.hpp:195
@ FRAGMENT_OCCLUSION_MAPPED_ON_CHANNEL_1
The occlusion map is sampled using texture coordinate channel 1.
Definition Model.hpp:197
@ FRAGMENT_NORMAL_MAPPED_ON_CHANNEL_1
The normal map is sampled using texture coordinate channel 1.
Definition Model.hpp:199
@ FRAGMENT_DOUBLE_SIDED
Fragments are double-sided.
Definition Model.hpp:191
@ FRAGMENT_OCCLUSION_MAPPED_ON_CHANNEL_0
The occlusion map is sampled using texture coordinate channel 0.
Definition Model.hpp:196
@ FRAGMENT_BASE_COLOR_MAPPED_ON_CHANNEL_1
The base color map is sampled using texture coordinate channel 1.
Definition Model.hpp:193
Optional< JointIndex > findSkinRootJointIndex(StringView name) const noexcept
Find the index of the root joint of a skin with a specific name.
Definition Model.hpp:1548
Optional< AnimationView > findAnimation(StringView name) const noexcept
Try to get the animation with a specific name.
Definition Model.hpp:1502
VertexFlag
Single flag in a set of VertexFlags, specifying vertex attribute usage.
Definition Model.hpp:171
@ VERTEX_COLORED
The vertex color component is used to tint the fragment color.
Definition Model.hpp:174
@ VERTEX_MORPHED_NORMAL
The vertex normal is morphed against the morph targets of the model using provided weights.
Definition Model.hpp:177
@ VERTEX_MORPHED_COLOR
The vertex color is morphed against the morph targets of the model using provided weights.
Definition Model.hpp:181
@ VERTEX_TEXTURED_ON_CHANNEL_1
Texture coordinate channel 1 is used to sample materials.
Definition Model.hpp:173
@ VERTEX_TEXTURED_ON_CHANNEL_0
Texture coordinate channel 0 is used to sample materials.
Definition Model.hpp:172
@ VERTEX_MORPHED_TEXTURE_COORDINATES_CHANNEL_1
Texture coordinate channel 1 is morphed against the morph targets of the model using provided weights...
Definition Model.hpp:180
@ VERTEX_MORPHED_TANGENT
The vertex tangent is morphed against the morph targets of the model using provided weights.
Definition Model.hpp:178
@ VERTEX_MORPHED_TEXTURE_COORDINATES_CHANNEL_0
Texture coordinate channel 0 is morphed against the morph targets of the model using provided weights...
Definition Model.hpp:179
@ VERTEX_MORPHED_POSITION
The vertex position is morphed against the morph targets of the model using provided weights.
Definition Model.hpp:176
@ VERTEX_SKINNED
The vertex joint components are used to skin the vertex over the model joints.
Definition Model.hpp:175
uint8_t CollisionLayerIndex
Index of a collision layer in a set of collision layers.
Definition Model.hpp:165
FrictionCombine
Friction combination algorithm.
Definition Model.hpp:466
@ MAXIMUM
The largest of the two values should be used.
Definition Model.hpp:469
@ AVERAGE
The two values should be averaged.
Definition Model.hpp:467
@ MINIMUM
The smallest of the two values should be used.
Definition Model.hpp:468
JointIndex getJointIndex(StringView name) const
Get the index of a joint with a specific name.
Definition Model.hpp:1533
Optional< TextureIndex > findTextureIndex(StringView name) const noexcept
Find the index of a texture with a specific name.
Definition Model.hpp:1580
InstanceIndex InstanceCount
Number of instances in a range within the model's instance array.
Definition Model.hpp:155
JointCount staticJointCount
Number of unskinned joints at the beginning of the joint array.
Definition Model.hpp:1109
uint32_t TextureIndex
Offset of a texture in the model's texture array.
Definition Model.hpp:142
ArrayList< Mesh > meshes
Layout of mesh data in the model. Indexed by instances.
Definition Model.hpp:1104
static void generateTriangleTangents(StridedSpan< byte > tangentData, StridedSpan< const vec3 > positions, StridedSpan< const iA2B10G10R10vec4norm > normals, StridedSpan< const vec2 > textureCoordinates, StridedSpan< const uint32_t > indices)
Generate tangent vectors for each vertex in a set of triangles.
MinificationFilter
Minification filter of a texture in a model.
Definition Model.hpp:287
@ UNSPECIFIED
Unspecified filter.
Definition Model.hpp:288
@ NEAREST_MIPMAP_NEAREST
Nearest-neighbor filtering from the nearest mip level.
Definition Model.hpp:291
@ LINEAR_MIPMAP_NEAREST
Linear filtering from the nearest mip level.
Definition Model.hpp:292
@ NEAREST_MIPMAP_LINEAR
Nearest-neighbor filtering linearly interpolated between mip levels.
Definition Model.hpp:293
@ LINEAR
Linear filtering without mipmapping.
Definition Model.hpp:290
@ NEAREST
Nearest-neighbor filtering without mipmapping.
Definition Model.hpp:289
@ LINEAR_MIPMAP_LINEAR
Linear filtering linearly interpoated between mip levels.
Definition Model.hpp:294
Optional< CollisionLayerIndex > findCollisionLayerIndex(StringView name) const noexcept
Find the index of a collision layer with a specific name.
Definition Model.hpp:1673
MorphTargetWeightIndex MorphTargetWeightCount
Number of morph target weights in a range within the model's morph target weight array.
Definition Model.hpp:141
JointMap jointMap
Map from joint names to their index in the joint array.
Definition Model.hpp:1122
Optional< JointIndex > findJointIndex(StringView name) const noexcept
Find the index of a joint with a specific name.
Definition Model.hpp:1517
WrappingMode
Wrapping mode of a texture in a model.
Definition Model.hpp:305
@ REPEAT
Wrap the texture coordinates.
Definition Model.hpp:306
@ CLAMP_TO_EDGE
Clamp the texture coordinates.
Definition Model.hpp:308
@ MIRRORED_REPEAT
Mirror the texture coordinates.
Definition Model.hpp:307
LightIndex getLightIndex(StringView name) const
Get the index of a light with a specific name.
Definition Model.hpp:1658
SharedPointer< TriangleMesh< 3, float > > TriangleMeshShape
Parameters describing a triangle mesh shape.
Definition Model.hpp:445
JointIndex JointCount
Number of joints in a range within the model's joint array.
Definition Model.hpp:149
uint32_t MeshIndex
Offset of a mesh in the model's mesh array.
Definition Model.hpp:146
TextureIndex getTextureIndex(StringView name) const
Get the index of a texture with a specific name.
Definition Model.hpp:1596
ArrayList< PhysicsObject > physicsObjects
Physics objects in the model. Indexed by physicsJoints and jointPhysicsObjectIndices.
Definition Model.hpp:1118
uint32_t AnimationChannelIndex
Offset of an animation channel in the model's animation channel array.
Definition Model.hpp:150
RestitutionCombine
Restitution combination algorithm.
Definition Model.hpp:479
Box< 3, float > bindPoseBoundingBox
Local axis-aligned bounding box of all meshes' vertex positions in the initial bind pose.
Definition Model.hpp:1120
ArrayList< PhysicsObjectIndex > jointPhysicsObjectIndices
Indices of the physics object that each joint in the model belongs to, or the maximum value if none.
Definition Model.hpp:1108
MaterialIndex getMaterialIndex(StringView name) const
Get the index of a material with a specific name.
Definition Model.hpp:1627
ArrayList< Optional< Collider > > jointColliders
Colliders of each joint in the model.
Definition Model.hpp:1107
PhysicsObjectIndex PhysicsObjectCount
Number of physics objects in a range within the model's physics object array.
Definition Model.hpp:159
static void generateTriangleNormals(Span< byte > normalData, StridedSpan< const vec3 > positions, StridedSpan< const uint32_t > indices)
Generate normal vectors for each vertex in a set of triangles.
Definition Model.hpp:952
HashMap< String, TextureIndex, TransparentHash< StringView >, TransparentEqual< StringView > > TextureMap
Map from name strings to texture indices.
Definition Model.hpp:593
Optional< AnimationIndex > findAnimationIndex(StringView name) const noexcept
Find the index of an animation with a specific name.
Definition Model.hpp:1432
MagnificationFilter
Magnification filter of a texture in a model.
Definition Model.hpp:298
MaterialMap materialMap
Map from material names to their index in the material array.
Definition Model.hpp:1126
uint32_t VertexCount
Number of vertices in a mesh of the model.
Definition Model.hpp:137
InterpolationMode
Interpolation type of a model animation channel.
Definition Model.hpp:550
@ STEP
Discrete steps without interpolation.
Definition Model.hpp:552
@ CUBIC_SPLINE
Cubic spline interpolation.
Definition Model.hpp:553
Buffer< byte > keyframeOutputValueData
Keyframe output value data of animation channels. Indexed by animationChannels.
Definition Model.hpp:1113
Model(const Filesystem &filesystem, CStringView filepath, const ModelOptions &options={})
Load a model from a file.
float bindPoseBoundingRadius
Maximum distance from the origin of all meshes' vertex positions in the initial bind pose.
Definition Model.hpp:1121
ArrayList< Instance > instances
Mesh instances of the model.
Definition Model.hpp:1116
void assign(const ConvexPolytope< 3, float > &polytope, const mat4 &transformation=mat4{1.0f})
Assign an untextured single-mesh model from a convex polytope.
uint32_t ValueOffset
Index of a 4-byte value in a data array of the model.
Definition Model.hpp:135
static constexpr size_t MAX_COLLISION_LAYER_COUNT
Maximum number of collision layers in a model.
Definition Model.hpp:163
uint32_t PhysicsJointIndex
Offset of a physics joint in the model's physics joint array.
Definition Model.hpp:160
ArrayList< JointIndex > jointParentIndices
Indices of the parent joint of each joint of the model.
Definition Model.hpp:1106
AnimationView getAnimationAtIndex(AnimationIndex index) const
Get the animation at a specific index.
Definition Model.hpp:1464
ArrayList< Light > lights
Lights in the model. Indexed by lightMap.
Definition Model.hpp:1117
HashMap< String, AnimationIndex, TransparentHash< StringView >, TransparentEqual< StringView > > AnimationMap
Map from name strings to animation indices.
Definition Model.hpp:590
static void generateTriangleNormals(StridedSpan< byte > normalData, StridedSpan< const vec3 > positions, StridedSpan< const uint32_t > indices)
Generate normal vectors for each vertex in a set of triangles.
Pose bindPose
Initial bind pose of the model. Indexed by instances, lights, physicsObjects, jointMap and skinMap.
Definition Model.hpp:1105
TextureIndex TextureCount
Number of textures in a range within the model's texture array.
Definition Model.hpp:143
static void generateTriangleTangents(StridedSpan< iA2B10G10R10vec4norm > tangents, StridedSpan< const vec3 > positions, StridedSpan< const iA2B10G10R10vec4norm > normals, StridedSpan< const vec2 > textureCoordinates, Span< const uint32_t > indices)
Generate tangent vectors for each vertex in a set of triangles.
Definition Model.hpp:1085
ArrayList< Animation > animations
Animations of the model. Indexed by animationMap.
Definition Model.hpp:1110
ArrayList< Texture > textures
Textures of the model. Indexed by materials and textureMap.
Definition Model.hpp:1114
LightIndex LightCount
Number of lights in a range within the model's light array.
Definition Model.hpp:157
void load(const Filesystem &filesystem, CStringView filepath, const ModelOptions &options={})
Load and assign a model from a file.
CollisionLayerMap collisionLayerMap
Map from collision layer names to their index in a collision layer set.
Definition Model.hpp:1128