VOXELFORMAT: removed Format::load
parent
7beda6d3fc
commit
8806f7bae4
|
@ -113,15 +113,6 @@ void Format::calcMinsMaxs(const voxel::Region& region, const glm::ivec3 &maxSize
|
||||||
Log::debug("maxs(%i:%i:%i)", maxs.x, maxs.y, maxs.z);
|
Log::debug("maxs(%i:%i:%i)", maxs.x, maxs.y, maxs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
voxel::RawVolume* Format::load(const core::String &filename, io::SeekableReadStream& stream) {
|
|
||||||
SceneGraph sceneGraph;
|
|
||||||
if (!loadGroups(filename, stream, sceneGraph)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
const SceneGraph::MergedVolumePalette &merged = sceneGraph.merge();
|
|
||||||
return merged.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Format::loadPalette(const core::String &filename, io::SeekableReadStream& stream, voxel::Palette &palette) {
|
size_t Format::loadPalette(const core::String &filename, io::SeekableReadStream& stream, voxel::Palette &palette) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,6 @@ public:
|
||||||
* @brief If the format supports multiple layers or groups, this method will give them to you as single volumes
|
* @brief If the format supports multiple layers or groups, this method will give them to you as single volumes
|
||||||
*/
|
*/
|
||||||
virtual bool loadGroups(const core::String &filename, io::SeekableReadStream& stream, SceneGraph& sceneGraph) = 0;
|
virtual bool loadGroups(const core::String &filename, io::SeekableReadStream& stream, SceneGraph& sceneGraph) = 0;
|
||||||
/**
|
|
||||||
* @brief Merge the loaded volumes into one. The returned memory is yours.
|
|
||||||
*/
|
|
||||||
virtual voxel::RawVolume* load(const core::String &filename, io::SeekableReadStream& stream);
|
|
||||||
virtual bool saveGroups(const SceneGraph& sceneGraph, const core::String &filename, io::SeekableWriteStream& stream) = 0;
|
virtual bool saveGroups(const SceneGraph& sceneGraph, const core::String &filename, io::SeekableWriteStream& stream) = 0;
|
||||||
virtual bool save(const voxel::RawVolume* volume, const core::String &filename, io::SeekableWriteStream& stream);
|
virtual bool save(const voxel::RawVolume* volume, const core::String &filename, io::SeekableWriteStream& stream);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,7 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndex(const core::String &fil
|
||||||
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
||||||
ASSERT_TRUE(format->save(&volume, filename, stream));
|
ASSERT_TRUE(format->save(&volume, filename, stream));
|
||||||
stream.seek(0);
|
stream.seek(0);
|
||||||
std::unique_ptr<voxel::RawVolume> loaded(format->load(filename, stream));
|
std::unique_ptr<voxel::RawVolume> loaded(load(filename, stream, *format));
|
||||||
ASSERT_NE(nullptr, loaded);
|
ASSERT_NE(nullptr, loaded);
|
||||||
EXPECT_TRUE(volumeComparator(volume, *loaded, false, includingRegion)) << "Volumes differ: " << volume << *loaded;
|
EXPECT_TRUE(volumeComparator(volume, *loaded, false, includingRegion)) << "Volumes differ: " << volume << *loaded;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndexConversion(Format &srcFo
|
||||||
io::BufferedReadWriteStream srcFormatStream(10 * 1024 * 1024);
|
io::BufferedReadWriteStream srcFormatStream(10 * 1024 * 1024);
|
||||||
EXPECT_TRUE(srcFormat.save(&original, destFilename, srcFormatStream)) << "Could not save " << destFilename;
|
EXPECT_TRUE(srcFormat.save(&original, destFilename, srcFormatStream)) << "Could not save " << destFilename;
|
||||||
srcFormatStream.seek(0);
|
srcFormatStream.seek(0);
|
||||||
std::unique_ptr<voxel::RawVolume> origReloaded(srcFormat.load(destFilename, srcFormatStream));
|
std::unique_ptr<voxel::RawVolume> origReloaded(load(destFilename, srcFormatStream, srcFormat));
|
||||||
if (includingRegion) {
|
if (includingRegion) {
|
||||||
ASSERT_EQ(original.region(), origReloaded->region());
|
ASSERT_EQ(original.region(), origReloaded->region());
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ void AbstractVoxFormatTest::testFirstAndLastPaletteIndexConversion(Format &srcFo
|
||||||
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
||||||
EXPECT_TRUE(destFormat.save(origReloaded.get(), destFilename, stream)) << "Could not save " << destFilename;
|
EXPECT_TRUE(destFormat.save(origReloaded.get(), destFilename, stream)) << "Could not save " << destFilename;
|
||||||
stream.seek(0);
|
stream.seek(0);
|
||||||
std::unique_ptr<voxel::RawVolume> loaded(destFormat.load(destFilename, stream));
|
std::unique_ptr<voxel::RawVolume> loaded(load(destFilename, stream, destFormat));
|
||||||
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
|
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
|
||||||
if (includingRegion) {
|
if (includingRegion) {
|
||||||
ASSERT_EQ(original.region(), loaded->region());
|
ASSERT_EQ(original.region(), loaded->region());
|
||||||
|
@ -96,10 +96,10 @@ void AbstractVoxFormatTest::testRGB(voxel::RawVolume* volume) {
|
||||||
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 12).getMaterial());
|
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 12).getMaterial());
|
||||||
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 19).getMaterial());
|
EXPECT_EQ(voxel::VoxelType::Generic, volume->voxel( 9, 0, 19).getMaterial());
|
||||||
|
|
||||||
EXPECT_EQ(245, volume->voxel( 0, 0, 0).getColor()) << "Expected to get the palette index 0";
|
EXPECT_EQ(245, volume->voxel( 0, 0, 0).getColor()) << "Expected to get the palette index 245";
|
||||||
EXPECT_EQ(245, volume->voxel(31, 0, 0).getColor()) << "Expected to get the palette index 0";
|
EXPECT_EQ(245, volume->voxel(31, 0, 0).getColor()) << "Expected to get the palette index 245";
|
||||||
EXPECT_EQ(245, volume->voxel(31, 0, 31).getColor()) << "Expected to get the palette index 0";
|
EXPECT_EQ(245, volume->voxel(31, 0, 31).getColor()) << "Expected to get the palette index 245";
|
||||||
EXPECT_EQ(245, volume->voxel( 0, 0, 31).getColor()) << "Expected to get the palette index 0";
|
EXPECT_EQ(245, volume->voxel( 0, 0, 31).getColor()) << "Expected to get the palette index 245";
|
||||||
|
|
||||||
EXPECT_EQ( 1, volume->voxel( 0, 31, 0).getColor()) << "Expected to get the palette index 1";
|
EXPECT_EQ( 1, volume->voxel( 0, 31, 0).getColor()) << "Expected to get the palette index 1";
|
||||||
EXPECT_EQ( 1, volume->voxel(31, 31, 0).getColor()) << "Expected to get the palette index 1";
|
EXPECT_EQ( 1, volume->voxel(31, 31, 0).getColor()) << "Expected to get the palette index 1";
|
||||||
|
@ -112,17 +112,19 @@ void AbstractVoxFormatTest::testRGB(voxel::RawVolume* volume) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename, Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion) {
|
void AbstractVoxFormatTest::testLoadSaveAndLoad(const core::String& srcFilename, Format &srcFormat, const core::String& destFilename, Format &destFormat, bool includingColor, bool includingRegion) {
|
||||||
std::unique_ptr<voxel::RawVolume> src(load(srcFilename, srcFormat));
|
voxelformat::SceneGraph sceneGraph;
|
||||||
ASSERT_TRUE(src.get() != nullptr);
|
EXPECT_TRUE(loadGroups(srcFilename, srcFormat, sceneGraph));
|
||||||
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
io::BufferedReadWriteStream stream(10 * 1024 * 1024);
|
||||||
EXPECT_TRUE(destFormat.save(src.get(), destFilename, stream)) << "Could not save " << destFilename;
|
EXPECT_TRUE(destFormat.saveGroups(sceneGraph, destFilename, stream)) << "Could not save " << destFilename;
|
||||||
stream.seek(0);
|
stream.seek(0);
|
||||||
std::unique_ptr<voxel::RawVolume> loaded(destFormat.load(destFilename, stream));
|
std::unique_ptr<voxel::RawVolume> loaded(load(destFilename, stream, destFormat));
|
||||||
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
|
ASSERT_NE(nullptr, loaded) << "Could not load " << destFilename;
|
||||||
|
SceneGraph::MergedVolumePalette merged = sceneGraph.merge();
|
||||||
|
std::unique_ptr<voxel::RawVolume> src(merged.first);
|
||||||
if (includingRegion) {
|
if (includingRegion) {
|
||||||
ASSERT_EQ(src->region(), loaded->region());
|
ASSERT_EQ(src->region(), loaded->region());
|
||||||
}
|
}
|
||||||
EXPECT_TRUE(volumeComparator(*src.get(), *loaded, includingColor, includingRegion)) << "Volumes differ: " << *src.get() << *loaded;
|
EXPECT_TRUE(volumeComparator(*src, *loaded, includingColor, includingRegion)) << "Volumes differ: " << *src << *loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractVoxFormatTest::testSaveMultipleLayers(const core::String &filename, Format *format) {
|
void AbstractVoxFormatTest::testSaveMultipleLayers(const core::String &filename, Format *format) {
|
||||||
|
@ -235,7 +237,7 @@ void AbstractVoxFormatTest::testSaveLoadVoxel(const core::String &filename, Form
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
readStream->seek(0);
|
readStream->seek(0);
|
||||||
std::unique_ptr<voxel::RawVolume> loaded(format->load(filename, *readStream));
|
std::unique_ptr<voxel::RawVolume> loaded(load(filename, *readStream, *format));
|
||||||
ASSERT_NE(nullptr, loaded);
|
ASSERT_NE(nullptr, loaded);
|
||||||
EXPECT_EQ(original, *loaded);
|
EXPECT_EQ(original, *loaded);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "io/Filesystem.h"
|
#include "io/Filesystem.h"
|
||||||
#include "core/Var.h"
|
#include "core/Var.h"
|
||||||
#include "core/GameConfig.h"
|
#include "core/GameConfig.h"
|
||||||
|
#include "voxelformat/SceneGraph.h"
|
||||||
|
|
||||||
namespace voxelformat {
|
namespace voxelformat {
|
||||||
|
|
||||||
|
@ -44,14 +45,31 @@ protected:
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
voxel::RawVolume* load(const core::String& filename, Format& format) {
|
voxel::RawVolume* load(const core::String& filename, io::SeekableReadStream& stream, Format& format) {
|
||||||
const io::FilePtr& file = open(filename);
|
SceneGraph sceneGraph;
|
||||||
if (!file->validHandle()) {
|
if (!format.loadGroups(filename, stream, sceneGraph)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const SceneGraph::MergedVolumePalette &merged = sceneGraph.merge();
|
||||||
|
return merged.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
voxel::RawVolume* load(const core::String& filename, Format& format) {
|
||||||
|
SceneGraph sceneGraph;
|
||||||
|
if (!loadGroups(filename, format, sceneGraph)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
const SceneGraph::MergedVolumePalette &merged = sceneGraph.merge();
|
||||||
|
return merged.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loadGroups(const core::String& filename, Format& format, voxelformat::SceneGraph &sceneGraph) {
|
||||||
|
const io::FilePtr& file = open(filename);
|
||||||
|
if (!file->validHandle()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
io::FileStream stream(file);
|
io::FileStream stream(file);
|
||||||
voxel::RawVolume* v = format.load(filename, stream);
|
return format.loadGroups(filename, stream, sceneGraph);
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadPalette(const core::String& filename, Format& format, voxel::Palette &palette) {
|
int loadPalette(const core::String& filename, Format& format, voxel::Palette &palette) {
|
||||||
|
|
|
@ -154,7 +154,7 @@ TEST_F(VoxFormatTest, testSave) {
|
||||||
EXPECT_TRUE(f.save(loadedVolume, fileSave->name(), sstream));
|
EXPECT_TRUE(f.save(loadedVolume, fileSave->name(), sstream));
|
||||||
const io::FilePtr &fileLoadAfterSave = open("magicavoxel-save.vox");
|
const io::FilePtr &fileLoadAfterSave = open("magicavoxel-save.vox");
|
||||||
io::FileStream stream2(fileLoadAfterSave);
|
io::FileStream stream2(fileLoadAfterSave);
|
||||||
voxel::RawVolume *savedVolume = f.load(fileLoadAfterSave->name(), stream2);
|
voxel::RawVolume *savedVolume = load(fileLoadAfterSave->name(), stream2, f);
|
||||||
EXPECT_NE(nullptr, savedVolume) << "Could not load saved vox file";
|
EXPECT_NE(nullptr, savedVolume) << "Could not load saved vox file";
|
||||||
if (savedVolume) {
|
if (savedVolume) {
|
||||||
EXPECT_EQ(*savedVolume, *loadedVolume);
|
EXPECT_EQ(*savedVolume, *loadedVolume);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "voxel/Voxel.h"
|
#include "voxel/Voxel.h"
|
||||||
#include "voxel/tests/TestHelper.h"
|
#include "voxel/tests/TestHelper.h"
|
||||||
#include "voxelformat/QBFormat.h"
|
#include "voxelformat/QBFormat.h"
|
||||||
|
#include "voxelformat/SceneGraph.h"
|
||||||
#include "voxelgenerator/ShapeGenerator.h"
|
#include "voxelgenerator/ShapeGenerator.h"
|
||||||
#include "voxelutil/VolumeVisitor.h"
|
#include "voxelutil/VolumeVisitor.h"
|
||||||
|
|
||||||
|
@ -34,7 +35,10 @@ protected:
|
||||||
const io::FilePtr& file = io::filesystem()->open(filename);
|
const io::FilePtr& file = io::filesystem()->open(filename);
|
||||||
ASSERT_TRUE(file) << "Can't open " << filename;
|
ASSERT_TRUE(file) << "Can't open " << filename;
|
||||||
io::FileStream stream(file);
|
io::FileStream stream(file);
|
||||||
voxel::RawVolume* v = format.load(file->fileName(), stream);
|
voxelformat::SceneGraph sceneGraph;
|
||||||
|
ASSERT_TRUE(format.loadGroups(file->fileName(), stream, sceneGraph));
|
||||||
|
voxelformat::SceneGraph::MergedVolumePalette merged = sceneGraph.merge();
|
||||||
|
voxel::RawVolume* v = merged.first;
|
||||||
ASSERT_NE(nullptr, v) << "Can't load " << filename;
|
ASSERT_NE(nullptr, v) << "Can't load " << filename;
|
||||||
EXPECT_EQ(*v, *_volume);
|
EXPECT_EQ(*v, *_volume);
|
||||||
delete v;
|
delete v;
|
||||||
|
|
Loading…
Reference in New Issue