VOXELFORMAT: vxm can have multiple volumes as layers
which we transform into scene graph nodesmaster
parent
4796cd25f4
commit
311b3b3a73
|
@ -152,7 +152,7 @@ bool VXRFormat::saveGroups(const SceneGraph& sceneGraph, const core::String &fil
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VXRFormat::loadChildVXM(const core::String& vxmPath, SceneGraphNode &node, int version) {
|
bool VXRFormat::loadChildVXM(const core::String& vxmPath, SceneGraph &sceneGraph, SceneGraphNode &node, int version) {
|
||||||
const io::FilePtr& file = io::filesystem()->open(vxmPath);
|
const io::FilePtr& file = io::filesystem()->open(vxmPath);
|
||||||
if (!file->validHandle()) {
|
if (!file->validHandle()) {
|
||||||
Log::error("Could not open file '%s'", vxmPath.c_str());
|
Log::error("Could not open file '%s'", vxmPath.c_str());
|
||||||
|
@ -166,12 +166,11 @@ bool VXRFormat::loadChildVXM(const core::String& vxmPath, SceneGraphNode &node,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int modelCount = (int)childSceneGraph.size(SceneGraphNodeType::Model);
|
const int modelCount = (int)childSceneGraph.size(SceneGraphNodeType::Model);
|
||||||
if (modelCount > 1) {
|
if (modelCount < 1) {
|
||||||
Log::warn("Unexpected scene graph found in vxm file - only use the first one");
|
|
||||||
} else if (modelCount != 1) {
|
|
||||||
Log::error("No models found in vxm file: %i", modelCount);
|
Log::error("No models found in vxm file: %i", modelCount);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Log::debug("Found %i layers in vxm", modelCount);
|
||||||
SceneGraphNode* childModelNode = childSceneGraph[0];
|
SceneGraphNode* childModelNode = childSceneGraph[0];
|
||||||
core_assert_always(childModelNode != nullptr);
|
core_assert_always(childModelNode != nullptr);
|
||||||
childModelNode->releaseOwnership();
|
childModelNode->releaseOwnership();
|
||||||
|
@ -184,6 +183,20 @@ bool VXRFormat::loadChildVXM(const core::String& vxmPath, SceneGraphNode &node,
|
||||||
const voxelformat::SceneGraphTransform &childTransform = childModelNode->transform(0);
|
const voxelformat::SceneGraphTransform &childTransform = childModelNode->transform(0);
|
||||||
voxelformat::SceneGraphTransform &transform = node.transform(0);
|
voxelformat::SceneGraphTransform &transform = node.transform(0);
|
||||||
transform.setPivot(childTransform.pivot());
|
transform.setPivot(childTransform.pivot());
|
||||||
|
|
||||||
|
// TODO: support loading all layers
|
||||||
|
#if 0
|
||||||
|
for (int i = 1; i < modelCount; ++i) {
|
||||||
|
SceneGraphNode child;
|
||||||
|
SceneGraphNode &src = *childSceneGraph[i];
|
||||||
|
copyNode(src, child, false);
|
||||||
|
src.releaseOwnership();
|
||||||
|
child.setVolume(src.volume(), true);
|
||||||
|
// TODO: the node instance is not yet added to the scene graph - and thus doesn't have a parent yet
|
||||||
|
sceneGraph.emplace(core::move(child), node.parent());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +299,7 @@ bool VXRFormat::importChild(const core::String& vxmPath, io::SeekableReadStream&
|
||||||
wrapBool(stream.readString(sizeof(filename), filename, true))
|
wrapBool(stream.readString(sizeof(filename), filename, true))
|
||||||
if (filename[0] != '\0') {
|
if (filename[0] != '\0') {
|
||||||
const core::String modelPath = core::string::path(core::string::extractPath(vxmPath), filename);
|
const core::String modelPath = core::string::path(core::string::extractPath(vxmPath), filename);
|
||||||
if (!loadChildVXM(modelPath, node, version)) {
|
if (!loadChildVXM(modelPath, sceneGraph, node, version)) {
|
||||||
Log::warn("Failed to attach model for id '%s' with filename %s (%s)", id, filename, modelPath.c_str());
|
Log::warn("Failed to attach model for id '%s' with filename %s (%s)", id, filename, modelPath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,7 +401,7 @@ bool VXRFormat::loadGroupsVersion3AndEarlier(const core::String &filename, io::S
|
||||||
wrapBool(stream.readString(sizeof(vxmFilename), vxmFilename, true))
|
wrapBool(stream.readString(sizeof(vxmFilename), vxmFilename, true))
|
||||||
if (vxmFilename[0] != '\0') {
|
if (vxmFilename[0] != '\0') {
|
||||||
const core::String modelPath = core::string::path(core::string::extractPath(filename), vxmFilename);
|
const core::String modelPath = core::string::path(core::string::extractPath(filename), vxmFilename);
|
||||||
if (!loadChildVXM(modelPath, *node, version)) {
|
if (!loadChildVXM(modelPath, sceneGraph, *node, version)) {
|
||||||
Log::warn("Failed to attach model for %s with filename %s", nodeId, modelPath.c_str());
|
Log::warn("Failed to attach model for %s with filename %s", nodeId, modelPath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace voxelformat {
|
||||||
*/
|
*/
|
||||||
class VXRFormat : public PaletteFormat {
|
class VXRFormat : public PaletteFormat {
|
||||||
private:
|
private:
|
||||||
bool loadChildVXM(const core::String& vxmPath, SceneGraphNode &node, int version);
|
bool loadChildVXM(const core::String& vxmPath, SceneGraph &sceneGraph, SceneGraphNode &node, int version);
|
||||||
|
|
||||||
bool handleVersion8AndLater(io::SeekableReadStream& stream, SceneGraphNode &node);
|
bool handleVersion8AndLater(io::SeekableReadStream& stream, SceneGraphNode &node);
|
||||||
bool importChild(const core::String& vxmPath, io::SeekableReadStream& stream, SceneGraph& sceneGraph, int version, int parent);
|
bool importChild(const core::String& vxmPath, io::SeekableReadStream& stream, SceneGraph& sceneGraph, int version, int parent);
|
||||||
|
|
Loading…
Reference in New Issue