VOXCONVERT: add --crop parameter to resize volumes to its voxels #108

master
Martin Gerhardy 2022-01-04 15:04:58 +01:00
parent 272f54b959
commit 75045dc193
3 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,7 @@
`./vengi-voxconvert --merge --scale --input infile --output outfile`
* `--crop`: reduces the volume sizes to their voxel boundaries.
* `--export-palette`: will save the included palette as png next to the source file. Use in combination with `--src-palette`.
* `--filter <filter>`: will filter out layers not mentioned in the expression. E.g. `1-2,4` will handle layer 1, 2 and 4. It is the same as `1,2,4`. The first layer is `0`. See the layers note below.
* `--force`: overwrite existing files
@ -38,6 +39,7 @@ color from the source file palette to the specified palette.
* translate
* script
* pivot
* crop
## Layers

View File

@ -24,6 +24,7 @@
#include "voxelformat/VoxelVolumes.h"
#include "voxelgenerator/LUAGenerator.h"
#include "voxelutil/ImageUtils.h"
#include "voxelutil/VolumeCropper.h"
#include "voxelutil/VolumeRescaler.h"
#include "voxelutil/VolumeRotator.h"
@ -133,6 +134,7 @@ app::AppState VoxConvert::onInit() {
const bool srcPalette = hasArg("--src-palette");
const bool exportPalette = hasArg("--export-palette");
const bool changePivot = hasArg("--pivot");
const bool cropVolumes = hasArg("--crop");
Log::info("Options");
if (voxelformat::isMeshFormat(outfile)) {
@ -156,6 +158,7 @@ app::AppState VoxConvert::onInit() {
}
Log::info("* merge volumes: - %s", (mergeVolumes ? "true" : "false"));
Log::info("* scale volumes: - %s", (scaleVolumes ? "true" : "false"));
Log::info("* crop volumes: - %s", (cropVolumes ? "true" : "false"));
Log::info("* change pivot: - %s", (changePivot ? "true" : "false"));
Log::info("* mirror volumes: - %s", (mirrorVolumes ? "true" : "false"));
Log::info("* translate volumes: - %s", (translateVolumes ? "true" : "false"));
@ -296,6 +299,10 @@ app::AppState VoxConvert::onInit() {
}
}
if (cropVolumes) {
crop(volumes);
}
Log::debug("Save %i volumes", (int)volumes.size());
if (!voxelformat::saveFormat(outputFile, volumes)) {
voxel::clearVolumes(volumes);
@ -309,6 +316,18 @@ app::AppState VoxConvert::onInit() {
return state;
}
void VoxConvert::crop(voxel::VoxelVolumes& volumes) {
Log::info("Crop volumes");
for (voxel::VoxelVolume& v : volumes) {
if (v.volume == nullptr) {
continue;
}
voxel::RawVolume *cropped = voxel::cropVolume(v.volume);
delete v.volume;
v.volume = cropped;
}
}
void VoxConvert::pivot(const glm::ivec3& pivot, voxel::VoxelVolumes& volumes) {
Log::info("Set pivot to %i:%i:%i", pivot.x, pivot.y, pivot.z);
for (voxel::VoxelVolume& v : volumes) {

View File

@ -31,6 +31,7 @@ protected:
void script(const core::String &scriptParameters, voxel::VoxelVolumes& volumes);
void translate(const glm::ivec3& pos, voxel::VoxelVolumes& volumes);
void pivot(const glm::ivec3& pivot, voxel::VoxelVolumes& volumes);
void crop(voxel::VoxelVolumes& volumes);
void filterVolumes(voxel::VoxelVolumes& volumes);
public:
VoxConvert(const metric::MetricPtr& metric, const io::FilesystemPtr& filesystem, const core::EventBusPtr& eventBus, const core::TimeProviderPtr& timeProvider);