Skip to content

Commit

Permalink
VOXELFORMAT: THING: parse scale value
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Jan 13, 2025
1 parent 879a160 commit 71402be
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/modules/voxelformat/private/rooms/ThingFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ bool ThingFormat::loadNodeSpec(io::SeekableReadStream &stream, NodeSpec &nodeSpe
}

static scenegraph::SceneGraphTransform toTransform(const voxel::Region &region, const glm::vec3 &localPos,
const glm::vec3 &localRot, const glm::vec3 &localSize) {
const glm::vec3 &localRot, const glm::vec3 &localSize, float scale) {
// TODO: VOXELFORMAT: positioning is wrong
scenegraph::SceneGraphTransform transform;
transform.setLocalOrientation(glm::quat(glm::radians(localRot)));
transform.setLocalTranslation(localPos);
if (localSize.x != 0.0f && localSize.y != 0.0f && localSize.z != 0.0f) {
if (!glm::epsilonEqual(scale, 1.0f, 0.00001f) ) {
transform.setLocalScale({scale, scale, scale});
} else if (localSize.x != 0.0f && localSize.y != 0.0f && localSize.z != 0.0f) {
const glm::vec3 fullSize(region.getDimensionsInVoxels());
transform.setLocalScale(localSize / fullSize);
}
Expand Down Expand Up @@ -82,7 +84,7 @@ void ThingFormat::addMediaImage(const io::ArchivePtr &archive, const NodeSpec &n
mediaNode.setName(nodeSpec.mediaName);
scenegraph::KeyFrameIndex keyFrameIdx = 0;
const scenegraph::SceneGraphTransform &transform =
toTransform(mediaNode.region(), mediaCanvas.localPos, mediaCanvas.localRot, mediaCanvas.localScale);
toTransform(mediaNode.region(), mediaCanvas.localPos, mediaCanvas.localRot, mediaCanvas.localScale, 1.0f);
mediaNode.setTransform(keyFrameIdx, transform);
voxSceneGraph.emplace(core::move(mediaNode));
} else {
Expand All @@ -109,7 +111,8 @@ bool ThingFormat::loadNode(const io::ArchivePtr &archive, const NodeSpec &nodeSp
}
scenegraph::SceneGraphNode &node = voxSceneGraph.node(e->first);
scenegraph::KeyFrameIndex keyFrameIdx = 0;
scenegraph::SceneGraphTransform transform = toTransform(node.region(), nodeSpec.localPos, nodeSpec.localRot, nodeSpec.localSize);
scenegraph::SceneGraphTransform transform =
toTransform(node.region(), nodeSpec.localPos, nodeSpec.localRot, nodeSpec.localSize, nodeSpec.scale);
node.setTransform(keyFrameIdx, transform);
node.setPivot(glm::vec3{0.5f});
node.setColor(nodeSpec.color);
Expand Down
10 changes: 10 additions & 0 deletions src/modules/voxelformat/private/rooms/ThingFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ namespace voxelformat {
*
* @todo some thing files contain a icon.png (128x128) thumbnail, which could be used for the thumbnailer
*
* https://medium.com/@btco_code/programming-in-rooms-xyz-part-1-cb498b2b4301
*
* +Z points to the left wall, +X points to the right wall.
* north is towards +Z
* east is towards +X
* south is towards -Z
* west is towards -X
* up is towards +Y
* down is towards -Y
*
* @ingroup Formats
*/
class ThingFormat : public Format {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/voxelformat/private/rooms/ThingNodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ bool ThingNodeParser::parseNode(core::Tokenizer &tok, NodeSpec &nodeSpec) const
core::string::parseVec3(tok.next(), glm::value_ptr(nodeSpec.localRot), " ,\t");
} else if (token == "localSize") {
core::string::parseVec3(tok.next(), glm::value_ptr(nodeSpec.localSize), " ,\t");
} else if (token == "scale") {
nodeSpec.scale = core::string::toFloat(tok.next());
} else {
Log::debug("ThingFormat: Ignoring token: '%s'", token.c_str());
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/voxelformat/private/rooms/ThingNodeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct NodeSpec {
glm::vec3 localPos{0.0f};
glm::vec3 localRot{0.0f};
glm::vec3 localSize{0.0f};
float scale = 1.0f;
core::RGBA color{0, 0, 0, 255};
core::DynamicArray<NodeSpec> children;
AnimSpec animSpec;
Expand Down

0 comments on commit 71402be

Please sign in to comment.