Comments (1)
#define MAX_LOD 4
/**
* @brief computes the level of detail for a quad.
* @return the coarsest level of detail where a quad is non-degenerate.
*
* @note If each quad is an integer unit square (i.e.
* not the output from a greedy mesh), then we can take the smallest corner and compute the quad LOD in constant time
* using a call to count-trailing zeroes. For general quads, the situation is a bit more involved. For a general
* axis-aligned quad, we can compute the level of detail by taking the minimum level of detail along each axis. So it
* then suffices to consider the case of one interval, where the level of detail can be computed by brute force using
* the following algorithm
*/
static int quadLOD(const Mesh* mesh, const Quad& quad) {
const int lo = 0; // TODO
const int hi = 0;
return SDL_MostSignificantBitIndex32(lo ^ hi);
}
/**
* @brief To construct the POP buffer, we need to sort the quads and count how many quads are in each LOD. This is an
* ideal place to use counting sort, which we can do in-place in O(n) time
*
* @link https://0fps.net/2018/03/03/a-level-of-detail-method-for-blocky-voxels/
*/
static core::Array<int, MAX_LOD> buildPopBuffers(const Mesh* mesh, QuadListVector& vecListQuads) {
core::Array<int, MAX_LOD> buckets {};
buckets.fill(0);
// count number of quads in each LOD
for (const QuadList &list : vecListQuads) {
for (const Quad& quad : list) {
buckets[quadLOD(mesh, quad)] += 1;
}
}
// compute prefix sum
int t = 0;
for (int i = 0; i < MAX_LOD; ++i) {
const int b = buckets[i];
buckets[i] = t;
t += b;
}
// partition quads across each LOD
for (int n = (int)vecListQuads.size() - 1; n >= 0; --n) {
for (auto outerIter = vecListQuads[n].rbegin(); outerIter != vecListQuads[n].rend(); ++outerIter) {
QuadList::reverse_iterator innerIter = outerIter;
++innerIter;
while (innerIter != vecListQuads[n].rend()) {
const Quad& q = *quaditer;
const int lod = quadLOD(mesh, q);
const int ptr = buckets[lod];
if (i < ptr) {
break;
}
quads[i] = quads[ptr];
quads[ptr] = q;
buckets[lod] += 1;
}
}
}
// buckets now contains the prefixes for each LOD
return buckets;
}
void meshify(Mesh* result, bool mergeQuads, QuadListVector& vecListQuads) {
core_trace_scoped(GenerateMeshify);
if (mergeQuads) {
core_trace_scoped(MergeQuads);
for (QuadList& listQuads : vecListQuads) {
// Repeatedly call this function until it returns
// false to indicate nothing more can be done.
while (performQuadMerging(listQuads, result)) {
}
}
}
buildPopBuffers(result, vecListQuads);
for (QuadList& listQuads : vecListQuads) {
for (const Quad& quad : listQuads) {
const IndexType i0 = quad.vertices[0];
const IndexType i1 = quad.vertices[1];
const IndexType i2 = quad.vertices[2];
const IndexType i3 = quad.vertices[3];
const VoxelVertex& v00 = result->getVertex(i3);
const VoxelVertex& v01 = result->getVertex(i0);
const VoxelVertex& v10 = result->getVertex(i2);
const VoxelVertex& v11 = result->getVertex(i1);
if (isQuadFlipped(v00, v01, v10, v11)) {
result->addTriangle(i1, i2, i3);
result->addTriangle(i1, i3, i0);
} else {
result->addTriangle(i0, i1, i2);
result->addTriangle(i0, i2, i3);
}
}
}
}
from vengi.
Related Issues (20)
- VOXELGENERATOR: add material bindings to the palette lua bindings
- VOXBROWSER: handle http status code 429
- VOXBROWSER: keep filters visible on scrolling the asset list
- VOXBROWSER: allow to refresh a particular voxel source
- VOXFORMAT: Colors of a red/green Qubicle model become darker as the voxel resolution increases HOT 2
- VOXEDIT: implement repeat command
- VOXELFORMAT: STARMADE: improve sment support
- VOXEDIT: segfault in simplified mode HOT 1
- APP: the application should create a pid file and check for a stale pid to detect a previous crash HOT 1
- VOXEDIT: spanning an aabb doesn't work anymore into the second dimension after fixing the first dimension
- VOXEDIT: don't show referenced models in edit mode - switch to the referenced model node
- EMSCRIPTEN: osx keys don't map properly HOT 2
- EMSCRIPTEN: autosave leads to a lot of downloads
- VOXEDIT: duplicate a node with reference children and delete the children afterwards triggers assert HOT 1
- VOXEDIT: plane modifier / extrude doesn't work on the region outer boundaries HOT 1
- VOXEDIT: transform matrix flipped for frames > 0 on reference model nodes. HOT 2
- VOXEDIT: reference nodes are visible in edit mode while having "Only active" enabled
- VOXEDIT: transform child if parent has rotation doesnโt work well
- VOXEDIT: new scene dialog - fetch more models from github HOT 1
- VOXEDIT: convert reference to model changes transforms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vengi.