23 using std::make_unique;
27 using std::unique_ptr;
44 string Model::ANIMATIONSETUP_DEFAULT =
"tdme.default";
45 uint32_t Model::uidCounter = 0;
47 constexpr
float Model::FPS_DEFAULT;
52 this->
id =
id +
":uid=" + to_string(this->
uniqueId);
60 this->boundingBox = unique_ptr<BoundingBox>(
boundingBox);
69 for (
const auto& [materialId, material]:
materials)
delete material;
70 for (
const auto& [animationSetupId, animationSetup]:
animationSetups)
delete animationSetup;
74 for (
const auto& [subNodeId, subNode]:
subNodes) {
81 vector<string> result;
82 for (
const auto& [materialId, material]:
materials) result.push_back(material->getId());
83 sort(result.begin(), result.end());
88 vector<string> result;
89 for (
const auto& [nodeId, node]:
nodes) result.push_back(node->getId());
90 sort(result.begin(), result.end());
95 vector<string> result;
96 for (
const auto& [animationSetupId, animationSetup]:
animationSetups) result.push_back(animationSetup->getId());
97 sort(result.begin(), result.end());
105 delete animationSetupIt->second;
108 auto animationSetup = make_unique<AnimationSetup>(
this,
id, startFrame, endFrame, loop,
string(), speed);
110 return animationSetup.release();
117 delete animationSetupIt->second;
120 auto animationSetup = make_unique<AnimationSetup>(
this,
id, startFrame, endFrame, loop, overlayFromNodeId, speed);
122 return animationSetup.release();
128 auto animationSetup = animationSetupIt->second;
130 animationSetup->setId(newId);
138 delete animationSetupIt->second;
144 for (
const auto& [animationSetupId, animationSetup]:
animationSetups) {
145 delete animationSetup;
163 for (
const auto& [subNodeId, subNode]:
nodes) {
165 auto animation = subNode->getAnimation();
166 if (animation !=
nullptr && frame != -1) {
167 const auto& animationMatrices = animation->getTransformMatrices();
168 transformMatrix.
set(animationMatrices[frame % animationMatrices.size()]);
171 transformMatrix.
set(subNode->getTransformMatrix());
175 transformMatrix.
multiply(parentTransformMatrix);
178 if (subNode->getId() == nodeId)
return true;
181 const auto&
subNodes = subNode->getSubNodes();
184 if (haveTransformMatrix ==
true)
return true;
Representation of a 3D model.
const vector< string > getMaterialIds()
void clearAnimationSetups()
Clear animation setups.
AuthoringTool authoringTool
unordered_map< string, Node * > nodes
void invalidateBoundingBox()
Invalidates bounding box.
bool removeAnimationSetup(const string &id)
Remove animation setup.
unordered_map< string, Node * > subNodes
RotationOrder * rotationOrder
static constexpr STATIC_DLL_IMPEXT float FPS_DEFAULT
static STATIC_DLL_IMPEXT uint32_t uidCounter
const vector< string > getNodeIds()
Returns all object's node ids.
AnimationSetup * addAnimationSetup(const string &id, int32_t startFrame, int32_t endFrame, bool loop, float speed=1.0f)
Adds an base animation setup.
AnimationSetup * addOverlayAnimationSetup(const string &id, const string &overlayFromNodeId, int32_t startFrame, int32_t endFrame, bool loop, float speed=1.0f)
Adds an overlay animation setup.
ShaderModel * shaderModel
unordered_map< string, Material * > materials
unique_ptr< BoundingBox > boundingBox
void deleteSubNodes(const unordered_map< string, Node * > &subNodes)
Delete sub nodes.
bool computeTransformMatrix(const unordered_map< string, Node * > &nodes, const Matrix4x4 &parentTransformMatrix, int32_t frame, const string &nodeId, Matrix4x4 &transformMatrix)
Computes a transform matrix at a given frame for a given node id recursivly.
const vector< string > getAnimationSetupIds()
bool renameAnimationSetup(const string &id, const string &newId)
Rename animation set up.
bool embedSpecularTextures
BoundingBox * getBoundingBox()
Matrix4x4 importTransformMatrix
unordered_map< string, AnimationSetup * > animationSetups
Represents rotation orders of a model.
static STATIC_DLL_IMPEXT ShaderModel * SPECULAR
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
static BoundingBox * createBoundingBox(Model *model, const unordered_map< string, Matrix4x4 * > overriddenNodeTransformMatrices=unordered_map< string, Matrix4x4 * >())
Creates a bounding box from given model.
Object model To be used in non engine context.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Matrix4x4 clone() const
Clones this matrix.
Matrix4x4 & identity()
Creates identity matrix.
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Matrix4x4 & set(float r0c0, float r0c1, float r0c2, float r0c3, float r1c0, float r1c1, float r1c2, float r1c3, float r2c0, float r2c1, float r2c2, float r2c3, float r3c0, float r3c1, float r3c2, float r3c3)
Sets this matrix by its components.