VOXELFORMAT: save and load layer color
parent
b572508981
commit
21cb77f4ee
|
@ -23,6 +23,7 @@ namespace voxelformat {
|
|||
|
||||
// the max amount of voxels - [0-255]
|
||||
static constexpr int MaxRegionSize = 256;
|
||||
#define VOXELFORMAT_PROPERTY_COLOR "color"
|
||||
|
||||
/**
|
||||
* @brief Base class for all voxel formats.
|
||||
|
|
|
@ -288,10 +288,12 @@ bool GoxFormat::loadChunk_LAYR(State& state, const GoxChunk &c, io::SeekableRead
|
|||
// "base_id" int
|
||||
// "material" int (index)
|
||||
node.setProperty(dictKey, core::string::toString(*(const int32_t*)dictValue));
|
||||
} else if (!strcmp(dictKey, "box") || !strcmp(dictKey, "shape") || !strcmp(dictKey, "color")) {
|
||||
} else if (!strcmp(dictKey, "color")) {
|
||||
const core::RGBA color = *(const uint32_t*)dictValue;
|
||||
node.setProperty(VOXELFORMAT_PROPERTY_COLOR, core::Color::toHex(color));
|
||||
} else if (!strcmp(dictKey, "box") || !strcmp(dictKey, "shape")) {
|
||||
// "box" 4x4 bounding box float
|
||||
// "shape" layer layer - currently unsupported TODO
|
||||
// "color" 4xbyte
|
||||
}
|
||||
}
|
||||
// TODO: fix this properly - without mirroring
|
||||
|
@ -533,6 +535,12 @@ bool GoxFormat::saveChunk_LAYR(io::SeekableWriteStream& stream, const SceneGraph
|
|||
glm::mat4 mat(1.0f);
|
||||
wrapBool(saveChunk_DictEntry(stream, "mat", (const uint8_t*)glm::value_ptr(mat), sizeof(mat)))
|
||||
wrapBool(saveChunk_DictEntry(stream, "id", layerId))
|
||||
const core::String &layerColorStr = node.property(VOXELFORMAT_PROPERTY_COLOR);
|
||||
if (!layerColorStr.empty()) {
|
||||
const glm::vec4 &layerColor = core::Color::fromHex(layerColorStr.c_str());
|
||||
const core::RGBA &layerRGBA = core::Color::getRGBA(layerColor);
|
||||
wrapBool(saveChunk_DictEntry(stream, "color", layerRGBA.rgba))
|
||||
}
|
||||
#if 0
|
||||
wrapBool(saveChunk_DictEntry(stream, "base_id", &layer->base_id))
|
||||
wrapBool(saveChunk_DictEntry(stream, "material", &material_idx))
|
||||
|
|
|
@ -168,14 +168,20 @@ bool VoxFormat::addGroup(const ogt_vox_scene *scene, uint32_t ogt_parentGroupIdx
|
|||
bool hidden = ogt_group.hidden;
|
||||
const char *name = "Group";
|
||||
const uint32_t layerIdx = ogt_group.layer_index;
|
||||
SceneGraphNode node(SceneGraphNodeType::Group);
|
||||
if (layerIdx < scene->num_layers) {
|
||||
const ogt_vox_layer &layer = scene->layers[layerIdx];
|
||||
hidden |= layer.hidden;
|
||||
if (layer.name != nullptr) {
|
||||
name = layer.name;
|
||||
}
|
||||
core::RGBA color;
|
||||
color.r = layer.color.r;
|
||||
color.g = layer.color.g;
|
||||
color.b = layer.color.b;
|
||||
color.a = layer.color.a;
|
||||
node.setProperty(VOXELFORMAT_PROPERTY_COLOR, core::Color::toHex(color));
|
||||
}
|
||||
SceneGraphNode node(SceneGraphNodeType::Group);
|
||||
loadKeyFrames(node, ogt_group.transform_anim.keyframes, ogt_group.transform_anim.num_keyframes);
|
||||
node.setName(name);
|
||||
node.setVisible(!hidden);
|
||||
|
@ -344,6 +350,15 @@ bool VoxFormat::saveGroups(const SceneGraph &sceneGraph, const core::String &fil
|
|||
ogt_vox_layer &layer = layers[mdlIdx];
|
||||
layer.name = node.name().c_str();
|
||||
layer.hidden = !node.visible();
|
||||
const core::String& colorString = node.property(VOXELFORMAT_PROPERTY_COLOR);
|
||||
if (!colorString.empty()) {
|
||||
const glm::vec4 &layerColor = core::Color::fromHex(colorString.c_str());
|
||||
const core::RGBA layerRGBA = core::Color::getRGBA(layerColor);
|
||||
layer.color.r = layerRGBA.r;
|
||||
layer.color.g = layerRGBA.g;
|
||||
layer.color.b = layerRGBA.b;
|
||||
layer.color.a = layerRGBA.a;
|
||||
}
|
||||
|
||||
ogt_vox_instance &instance = instances[mdlIdx];
|
||||
instance.group_index = 0;
|
||||
|
|
Loading…
Reference in New Issue