|
@@ -28,7 +28,7 @@ a 256x256x256 cube of voxels.</p>
|
|
|
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">const cellSize = 256;
|
|
|
const cell = new Uint8Array(cellSize * cellSize * cellSize);
|
|
|
</pre>
|
|
|
-<p>I then made a single layer with a kind of hills of
|
|
|
+<p>I then made a single layer with a kind of hills of
|
|
|
sine waves like this</p>
|
|
|
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">for (let y = 0; y < cellSize; ++y) {
|
|
|
for (let z = 0; z < cellSize; ++z) {
|
|
@@ -77,7 +77,7 @@ the problem is there are just way too many objects. 256x256
|
|
|
is 65536 boxes!</p>
|
|
|
<p>Using <a href="rendering-on-demand.html">the technique of merging the geometry</a>
|
|
|
will fix the issue for this example but what if instead of just making
|
|
|
-a single layer we filled in everything below the ground with voxel.
|
|
|
+a single layer we filled in everything below the ground with voxel.
|
|
|
In other words change the loop filling in the voxels to this</p>
|
|
|
<pre class="prettyprint showlinemods notranslate lang-js" translate="no">for (let y = 0; y < cellSize; ++y) {
|
|
|
for (let z = 0; z < cellSize; ++z) {
|
|
@@ -124,7 +124,7 @@ if nothing else in much of the space nothing is there so that's a lot of wasted
|
|
|
memory. It's also a huge number of voxels, 16 million! That's too much to
|
|
|
consider at once.</p>
|
|
|
<p>A solution is to divide the area into smaller areas.
|
|
|
-Any area that has nothing in it needs no storage. Let's use
|
|
|
+Any area that has nothing in it needs no storage. Let's use
|
|
|
32x32x32 areas (that's 32k) and only create an area if something is in it.
|
|
|
We'll call one of these larger 32x32x32 areas a "cell".</p>
|
|
|
<p>Let's break this into pieces. First let's make a class to manage the voxel data.</p>
|
|
@@ -134,7 +134,7 @@ We'll call one of these larger 32x32x32 areas a "cell".</p>
|
|
|
}
|
|
|
}
|
|
|
</pre>
|
|
|
-<p>Let's make the function that makes geometry for a cell.
|
|
|
+<p>Let's make the function that makes geometry for a cell.
|
|
|
Let's assume you pass in a cell position.
|
|
|
In other words if you want the geometry for the cell that covers voxels (0-31x, 0-31y, 0-31z)
|
|
|
then you'd pass in 0,0,0. For the cell that covers voxels (32-63x, 0-31y, 0-31z) you'd
|
|
@@ -1072,13 +1072,13 @@ At the end we update the attributes and indices with the new data.</p>
|
|
|
<p></p>
|
|
|
<p>Some notes:</p>
|
|
|
<p><code class="notranslate" translate="no">RayCaster</code> might have worked just fine. I didn't try it.
|
|
|
-Instead I found <a href="http://www.cse.chalmers.se/edu/year/2010/course/TDA361/grid.pdf">a voxel specific raycaster</a>.
|
|
|
+Instead I found <a href="https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.42.3443&rep=rep1&type=pdf">a voxel specific raycaster</a>.
|
|
|
that is optimized for voxels.</p>
|
|
|
<p>I made <code class="notranslate" translate="no">intersectRay</code> part of VoxelWorld because it seemed
|
|
|
like if it gets too slow we could raycast against cells
|
|
|
before raycasting on voxels as a simple speed up if it becomes
|
|
|
too slow.</p>
|
|
|
-<p>You might want to change the length of the raycast
|
|
|
+<p>You might want to change the length of the raycast
|
|
|
as currently it's all the way to Z-far. I expect if the
|
|
|
user clicks something too far way they don't really want
|
|
|
to be placing blocks on the other side of the world that
|
|
@@ -1086,7 +1086,7 @@ are 1 or 2 pixel large.</p>
|
|
|
<p>Calling <code class="notranslate" translate="no">geometry.computeBoundingSphere</code> might be slow.
|
|
|
We could just manually set the bounding sphere to the fit
|
|
|
the entire cell.</p>
|
|
|
-<p>Do we want remove cells if all voxels in that cell are 0?
|
|
|
+<p>Do we want remove cells if all voxels in that cell are 0?
|
|
|
That would probably be reasonable change if we wanted to ship this.</p>
|
|
|
<p>Thinking about how this works it's clear the absolute
|
|
|
worst case is a checkerboard of on and off voxels. I don't
|
|
@@ -1115,11 +1115,11 @@ to generate some what efficient geometry.</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<script src="/manual/resources/prettify.js"></script>
|
|
|
<script src="/manual/resources/lesson.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-</body></html>
|
|
|
+</body></html>
|