2017-12-08 14:05:47 +00:00
|
|
|
// This code is in the public domain -- castano@gmail.com
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef NV_MESH_ATLASPACKER_H
|
|
|
|
#define NV_MESH_ATLASPACKER_H
|
|
|
|
|
|
|
|
#include "nvcore/RadixSort.h"
|
|
|
|
#include "nvimage/BitMap.h"
|
|
|
|
#include "nvimage/Image.h"
|
2017-12-19 15:16:55 +00:00
|
|
|
#include "nvmath/Random.h"
|
|
|
|
#include "nvmath/Vector.h"
|
2017-12-08 14:05:47 +00:00
|
|
|
|
|
|
|
#include "nvmesh/nvmesh.h"
|
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
namespace nv {
|
|
|
|
class Atlas;
|
|
|
|
class Chart;
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
struct AtlasPacker {
|
|
|
|
AtlasPacker(Atlas *atlas);
|
|
|
|
~AtlasPacker();
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
void packCharts(int quality, float texelArea, bool blockAligned, bool conservative);
|
|
|
|
float computeAtlasUtilization() const;
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
private:
|
|
|
|
void findChartLocation(int quality, const BitMap *bitmap, Vector2::Arg extents, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r);
|
|
|
|
void findChartLocation_bruteForce(const BitMap *bitmap, Vector2::Arg extents, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r);
|
|
|
|
void findChartLocation_random(const BitMap *bitmap, Vector2::Arg extents, int w, int h, int *best_x, int *best_y, int *best_w, int *best_h, int *best_r, int minTrialCount);
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
void drawChartBitmapDilate(const Chart *chart, BitMap *bitmap, int padding);
|
|
|
|
void drawChartBitmap(const Chart *chart, BitMap *bitmap, const Vector2 &scale, const Vector2 &offset);
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
bool canAddChart(const BitMap *bitmap, int w, int h, int x, int y, int r);
|
|
|
|
void addChart(const BitMap *bitmap, int w, int h, int x, int y, int r, Image *debugOutput);
|
|
|
|
//void checkCanAddChart(const Chart * chart, int w, int h, int x, int y, int r);
|
|
|
|
void addChart(const Chart *chart, int w, int h, int x, int y, int r, Image *debugOutput);
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
static bool checkBitsCallback(void *param, int x, int y, Vector3::Arg bar, Vector3::Arg dx, Vector3::Arg dy, float coverage);
|
|
|
|
static bool setBitsCallback(void *param, int x, int y, Vector3::Arg bar, Vector3::Arg dx, Vector3::Arg dy, float coverage);
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
private:
|
|
|
|
Atlas *m_atlas;
|
|
|
|
BitMap m_bitmap;
|
|
|
|
//Image m_debug_bitmap;
|
|
|
|
RadixSort m_radix;
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
uint m_width;
|
|
|
|
uint m_height;
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
MTRand m_rand;
|
|
|
|
};
|
2017-12-08 14:05:47 +00:00
|
|
|
|
2017-12-19 15:16:55 +00:00
|
|
|
} // namespace nv
|
2017-12-08 14:05:47 +00:00
|
|
|
|
|
|
|
#endif // NV_MESH_ATLASPACKER_H
|