52 lines
1.9 KiB
C++
52 lines
1.9 KiB
C++
/**
|
|
* \file model_contouring.cpp
|
|
* \brief Generate entities vertices
|
|
* \author Maelys Bois
|
|
* \version 0.0.1
|
|
*
|
|
* Generate ShortIndexed::Data for manually defined chunks.
|
|
*/
|
|
|
|
#include <fstream>
|
|
#include "world/generator.hpp"
|
|
#include "world/Chunk.hpp"
|
|
#include "contouring/FlatDualMC.hpp"
|
|
|
|
class Contouring: public contouring::FlatDualMC {
|
|
public:
|
|
Contouring() : FlatDualMC("iso = 0.1\nkeep_distance = 2\nload_distance = 1\nlod_levels = [ false, false, false, false, true ]\nlod_quality = 0.0\nlod_strength = 0.15\nmanifold = true\nreordering = true\ntransparency = true") { }
|
|
void render(const std::shared_ptr<world::Chunk>& chunk, buffer::LodShortIndexed::LodData& out) const {
|
|
contouring::surrounding::corners surround = {
|
|
chunk, world::EMPTY_CHUNK, world::EMPTY_CHUNK, world::EMPTY_CHUNK,
|
|
world::EMPTY_CHUNK, world::EMPTY_CHUNK, world::EMPTY_CHUNK, world::EMPTY_CHUNK
|
|
};
|
|
std::vector<buffer::VertexData> tmp;
|
|
FlatDualMC::render(surround, out, tmp);
|
|
}
|
|
};
|
|
|
|
/// Entry point
|
|
int main(int /*unused*/, char * /*unused*/[])
|
|
{
|
|
const auto generator = world::generator::load(world::generator::Void::Params());
|
|
const auto chunk = std::make_shared<world::Chunk>(chunk_pos(0), generator);
|
|
|
|
//TODO: load from file
|
|
for (auto x = 1; x <= 6; x++) {
|
|
for (auto y = 1; y <= 6; y++) {
|
|
for (auto z = 1; z <= 6; z++) {
|
|
chunk->setAt(chunk_voxel_pos(x, y, z), world::Voxel(z >= 4 ? world::materials::ROCK : world::materials::GRASS, world::Voxel::DENSITY_MAX));
|
|
}}}
|
|
|
|
buffer::LodShortIndexed::LodData data;
|
|
Contouring ct = Contouring();
|
|
ct.render(chunk, data);
|
|
assert(data.second.size() == 1 && "Must contain a single lod");
|
|
data.first.indices.resize(data.second.front()); //Discard full res
|
|
|
|
std::ofstream out("content/model.ivb");
|
|
data.first.serialize(out);
|
|
out.close();
|
|
|
|
return 0;
|
|
} |