6 #include <unordered_map>
43 using std::make_unique;
46 using std::unique_ptr;
47 using std::unordered_map;
84 void TMWriter::write(
Model* model,
const string& pathName,
const string& fileName,
bool useBC7TextureCompression)
87 write(model, data, useBC7TextureCompression);
88 FileSystem::getInstance()->setContent(pathName, fileName, data);
109 for (
const auto& [materialId, material]: model->
getMaterials()) {
117 if (Application::hasApplication() ==
true && os.
getData()->size() < 10 * 1024 * 1024)
writeThumbnail(&os, model);
121 unordered_map<string, Texture*> embeddedTextures;
122 for (
const auto& [materialId, material]: m->
getMaterials()) {
123 auto smp = material->getSpecularMaterialProperties();
125 if (smp->getDiffuseTexture() !=
nullptr) embeddedTextures[smp->getDiffuseTexture()->getId()] = smp->getDiffuseTexture();
126 if (smp->getSpecularTexture() !=
nullptr) embeddedTextures[smp->getSpecularTexture()->getId()] = smp->getSpecularTexture();
127 if (smp->getNormalTexture() !=
nullptr) embeddedTextures[smp->getNormalTexture()->getId()] = smp->getNormalTexture();
129 auto pmp = material->getPBRMaterialProperties();
131 if (pmp->getBaseColorTexture() !=
nullptr) embeddedTextures[pmp->getBaseColorTexture()->getId()] = pmp->getBaseColorTexture();
132 if (pmp->getMetallicRoughnessTexture() !=
nullptr) embeddedTextures[pmp->getMetallicRoughnessTexture()->getId()] = pmp->getMetallicRoughnessTexture();
133 if (pmp->getNormalTexture() !=
nullptr) embeddedTextures[pmp->getNormalTexture()->getId()] = pmp->getNormalTexture();
134 if (pmp->getEmissiveTexture() !=
nullptr) embeddedTextures[pmp->getEmissiveTexture()->getId()] = pmp->getEmissiveTexture();
137 os->
writeInt(embeddedTextures.size());
138 for (
const auto& [embeddedTextureId, embeddedTexture]: embeddedTextures) {
141 if (useBC7TextureCompression ==
true) {
143 vector<uint8_t> bc7Data;
144 os->
writeInt(embeddedTexture->getWidth());
145 os->
writeInt(embeddedTexture->getHeight());
146 os->
writeInt(embeddedTexture->getTextureWidth());
147 os->
writeInt(embeddedTexture->getTextureHeight());
148 os->
writeByte(embeddedTexture->getRGBDepthBitsPerPixel());
149 os->
writeByte(embeddedTexture->getMinFilter());
150 os->
writeByte(embeddedTexture->getMagFilter());
151 BC7TextureWriter::write(embeddedTexture->getTextureWidth(), embeddedTexture->getTextureHeight(), embeddedTexture->getRGBDepthBitsPerPixel() / 8, embeddedTexture->getRGBTextureData(), bc7Data);
154 if (embeddedTexture->isUseMipMap() ==
false) {
157 auto mipMapTextures = embeddedTexture->getMipMapTextures(
true);
159 for (
const auto& mipMapTexture: mipMapTextures) {
163 os->
writeInt(mipMapTexture.textureData.getBufferVector()->size());
168 vector<uint8_t> pngData;
169 PNGTextureWriter::write(embeddedTexture, pngData,
false,
false);
171 os->
writeByte(embeddedTexture->getMinFilter());
172 os->
writeByte(embeddedTexture->getMagFilter());
190 os->
writeInt(smp->getTextureAtlasSize());
193 os->
writeString(smp->getDiffuseTransparencyTexturePathName());
194 os->
writeString(smp->getDiffuseTransparencyTextureFileName());
195 os->
writeString(smp->getSpecularTexturePathName());
196 os->
writeString(smp->getSpecularTextureFileName());
200 os->
writeBoolean(smp->hasDiffuseTextureMaskedTransparency());
201 os->
writeFloat(smp->getDiffuseTextureMaskedTransparencyThreshold());
204 if (pmp ==
nullptr) {
209 os->
writeString(pmp->getBaseColorTexturePathName());
210 os->
writeString(pmp->getBaseColorTextureFileName());
211 os->
writeBoolean(pmp->hasBaseColorTextureMaskedTransparency());
212 os->
writeFloat(pmp->getBaseColorTextureMaskedTransparencyThreshold());
215 os->
writeString(pmp->getMetallicRoughnessTexturePathName());
216 os->
writeString(pmp->getMetallicRoughnessTextureFileName());
221 os->
writeString(pmp->getEmissiveTexturePathName());
222 os->
writeString(pmp->getEmissiveTextureFileName());
243 for (
auto i = 0; i < v.size(); i++) {
251 if (tc.size() == 0) {
256 for (
auto i = 0; i < tc.size(); i++) {
266 for (
auto i = 0; i < indices.size(); i++) {
287 for (
auto i = 0; i < facesEntities.size(); i++) {
288 const auto& fe = facesEntities[i];
290 if (fe.getMaterial() ==
nullptr) {
297 for (
auto j = 0; j < fe.getFaces().size(); j++) {
298 const auto& f = fe.getFaces()[j];
322 if (skinning ==
nullptr) {
328 for (
auto i = 0; i < skinning->
getJoints().size(); i++) {
344 for (
const auto& [subNodeId, subNode]: subNodes) {
368 auto prototype = make_unique<Prototype>(
370 Prototype_Type::MODEL,
378 vector<uint8_t> pngData;
379 string base64PNGData;
380 Tools::oseThumbnail(prototype.get(), pngData);
381 prototype->unsetModel();
Application base class, please make sure to allocate application on heap to have correct application ...
Color 4 definition class.
vector< uint8_t > * getData()
Get data.
void writeString(const string &s)
Writes a string to output stream.
void writeUInt8tArray(const vector< uint8_t > &d)
Writes a uint8_t array to output stream, note that no size information is given in this case.
void writeByte(uint8_t b)
Writes a byte to output stream.
void writeInt(int32_t i)
Writes a integer to output stream.
void writeFloat(float f)
Writes a float to output stream.
void writeFloatArray(const array< float, 2 > &f)
Writes a float array to output stream.
void writeBoolean(bool b)
Writes a boolean to output stream.
static void writeAnimationSetup(TMWriterOutputStream *os, AnimationSetup *animationSetup)
Write animation setup.
static void writeAnimation(TMWriterOutputStream *os, Animation *a)
Write animation to output stream.
static void writeTextureCoordinates(TMWriterOutputStream *os, const vector< Vector2 > &tc)
Write texture coordinates to output stream.
static void write(Model *model, const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
TDME model format writer.
static void writeFacesEntities(TMWriterOutputStream *os, const vector< FacesEntity > &facesEntities)
Write faces entities to output stream.
static void writeSkinning(TMWriterOutputStream *os, Skinning *skinning)
Write skinning to output stream.
static void writeThumbnail(TMWriterOutputStream *os, Model *model)
Write thumbnail to output stream.
static void writeVertices(TMWriterOutputStream *os, const vector< Vector3 > &v)
Write vertices to output stream.
static void writeMaterial(TMWriterOutputStream *os, Material *m)
Write material.
static void writeEmbeddedTextures(TMWriterOutputStream *os, Model *m, bool useBC7TextureCompression)
Write embedded textures.
static void writeSkinningJoint(TMWriterOutputStream *os, const Joint &joint)
Write skinning joint.
static void writeNode(TMWriterOutputStream *os, Node *g)
Write node to output stream.
static void writeSubNodes(TMWriterOutputStream *os, const unordered_map< string, Node * > &subNodes)
Write sub nodes.
static void writeIndices(TMWriterOutputStream *os, const array< int32_t, 3 > &indices)
Write indices to output stream.
static void writeSkinningJointWeight(TMWriterOutputStream *os, const JointWeight &jointWeight)
Write skinning joint weight.
BC7 texture writer class.
PNG texture writer class.
const string & getOverlayFromNodeId()
If this is a overlay animation this returns a node id from which node the animation will start in the...
const vector< Matrix4x4 > & getTransformMatrices() const
Returns transform matrices.
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Node faces entity A node can have multiple entities containing faces and a applied material.
int32_t getWeightIndex() const
int32_t getJointIndex() const
const Matrix4x4 & getBindMatrix() const
Bind matrix.
const string & getNodeId() const
Associated node or bone id.
const PBRMaterialProperties * getPBRMaterialProperties() const
const SpecularMaterialProperties * getSpecularMaterialProperties() const
const string & getId() const
bool isDoubleSided() const
const Matrix3x3 & getTextureMatrix() const
Representation of a 3D model.
unordered_map< string, Node * > & getSubNodes()
Returns object's sub nodes.
unordered_map< string, Material * > & getMaterials()
Returns all object materials.
RotationOrder * getRotationOrder()
bool hasEmbeddedPBRTextures() const
const Matrix4x4 & getImportTransformMatrix()
ShaderModel * getShaderModel()
bool hasEmbeddedSpecularTextures() const
const unordered_map< string, AnimationSetup * > & getAnimationSetups()
BoundingBox * getBoundingBox()
const vector< Vector3 > & getBitangents() const
unordered_map< string, Node * > & getSubNodes()
const vector< Vector3 > & getTangents() const
Animation * getAnimation()
const vector< Vector3 > & getVertices() const
const vector< Vector3 > & getNormals() const
const vector< Vector2 > & getTextureCoordinates() const
const string & getId()
Returns id.
const vector< FacesEntity > & getFacesEntities() const
const Matrix4x4 & getTransformMatrix() const
Represents specular material properties.
Represents rotation orders of a model.
Skinning definition for nodes.
const vector< float > & getWeights()
const vector< vector< JointWeight > > & getVerticesJointsWeights()
const vector< Joint > & getJoints()
Represents specular material properties.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
const array< float, 9 > & getArray() const
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
const array< float, 16 > & getArray() const
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
const array< float, 3 > & getArray() const
File system singleton class.
const string & getName() const
std::exception Exception
Exception base class.