VOXELFORMAT: Revert "save the palette image data as base64" for now

This reverts commit e7856fd1463#196878f802a4d5887a9c899a7d4f0.
master
Martin Gerhardy 2022-05-23 13:34:57 +02:00
parent 6531158648
commit de861f670b
1 changed files with 10 additions and 10 deletions

View File

@ -103,40 +103,41 @@ bool GLTFFormat::saveMeshes(const core::Map<int, int> &meshIdxNodeMap, const Sce
const voxel::Palette &palette = graphNode.palette(); const voxel::Palette &palette = graphNode.palette();
int materialId = -1; int materialId = -1;
int texcoordIndex = 0;
if (graphNode.type() == SceneGraphNodeType::Model) { if (graphNode.type() == SceneGraphNodeType::Model) {
const auto palTexIter = paletteMaterialIndices.find(palette.hash()); const auto palTexIter = paletteMaterialIndices.find(palette.hash());
if (palTexIter != paletteMaterialIndices.end()) { if (palTexIter != paletteMaterialIndices.end()) {
materialId = palTexIter->second; materialId = palTexIter->second;
Log::debug("Re-use material id %i for hash %" PRIu64, materialId, palette.hash()); Log::debug("Re-use material id %i for hash %" PRIu64, materialId, palette.hash());
} else { } else {
const int textureIndex = (int)m.textures.size();
const int imageIndex = (int)m.images.size();
const core::String hashId = core::String::format("%" PRIu64, palette.hash()); const core::String hashId = core::String::format("%" PRIu64, palette.hash());
core::String palettename = core::string::stripExtension(filename); core::String palettename = core::string::stripExtension(filename);
palettename.append(hashId); palettename.append(hashId);
palettename.append(".png"); palettename.append(".png");
const int imageIndex = (int)m.images.size();
{ {
tinygltf::Image colorPaletteImg; tinygltf::Image colorPaletteImg;
const std::string pal64 = colorPaletteImg.uri = core::string::extractFilenameWithExtension(palettename).c_str();
tinygltf::base64_encode((const unsigned char *)palette.colors, sizeof(palette.colors));
colorPaletteImg.uri = "data:image/png;base64," + pal64;
m.images.emplace_back(core::move(colorPaletteImg)); m.images.emplace_back(core::move(colorPaletteImg));
} }
const int textureIndex = (int)m.textures.size(); if (!palette.save(palettename.c_str())) {
Log::error("Failed to save palette data");
}
// TODO: save emissiveTexture
{ {
tinygltf::Texture paletteTexture; tinygltf::Texture paletteTexture;
paletteTexture.source = imageIndex; paletteTexture.source = imageIndex;
m.textures.emplace_back(core::move(paletteTexture)); m.textures.emplace_back(core::move(paletteTexture));
} }
// TODO: save emissiveTexture
{ {
tinygltf::Material mat; tinygltf::Material mat;
if (withTexCoords) { if (withTexCoords) {
mat.pbrMetallicRoughness.baseColorTexture.index = textureIndex; mat.pbrMetallicRoughness.baseColorTexture.index = textureIndex;
mat.pbrMetallicRoughness.baseColorTexture.texCoord = texcoordIndex;
} else if (withColor) { } else if (withColor) {
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f}; mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f};
} }
@ -362,8 +363,7 @@ bool GLTFFormat::saveMeshes(const core::Map<int, int> &meshIdxNodeMap, const Sce
meshPrimitive.attributes["POSITION"] = meshPrimitive.attributes["POSITION"] =
primIdxFactor * nthNodeIdx + 1; // The index of the accessor for positions primIdxFactor * nthNodeIdx + 1; // The index of the accessor for positions
if (withTexCoords) { if (withTexCoords) {
const core::String &texcoordsKey = core::String::format("TEXCOORD_%i", texcoordIndex); meshPrimitive.attributes["TEXCOORD_0"] = primIdxFactor * nthNodeIdx + 2;
meshPrimitive.attributes[texcoordsKey.c_str()] = primIdxFactor * nthNodeIdx + 2;
} else if (withColor) { } else if (withColor) {
meshPrimitive.attributes["COLOR_0"] = primIdxFactor * nthNodeIdx + 2; meshPrimitive.attributes["COLOR_0"] = primIdxFactor * nthNodeIdx + 2;
} }