@@ -244,11 +244,26 @@ public int getData() {
244
244
}
245
245
}
246
246
247
+ /** The type of Octree, used to adjust intersection code based on contents*/
248
+ public enum OctreeType {
249
+ /**
250
+ * Contains all world geometry excluding water, water is removed from water logged blocks
251
+ * and full water blocks are replaced with air
252
+ */
253
+ WORLD ,
254
+ /**
255
+ * Contains all the water geometry only, other blocks are air
256
+ */
257
+ WATER
258
+ }
259
+
247
260
/**
248
261
* Timestamp of last serialization.
249
262
*/
250
263
private long timestamp = 0 ;
251
264
265
+ public OctreeType type ;
266
+
252
267
private OctreeImplementation implementation ;
253
268
254
269
/**
@@ -257,9 +272,10 @@ public int getData() {
257
272
*
258
273
* @param octreeDepth The number of levels in the Octree.
259
274
*/
260
- public Octree (String impl , int octreeDepth ) {
275
+ public Octree (String impl , int octreeDepth , OctreeType type ) {
261
276
Log .infof ("Building new octree (%s)" , impl );
262
277
implementation = getImplementationFactory (impl ).create (octreeDepth );
278
+ this .type = type ;
263
279
}
264
280
265
281
protected Octree (OctreeImplementation impl ) {
@@ -484,6 +500,8 @@ public boolean enterBlock(Scene scene, Ray ray, BlockPalette palette) {
484
500
int depth = implementation .getDepth ();
485
501
486
502
double distance = 0 ;
503
+ //tread air as a null block depending on octreetype and were we are in the trace
504
+ boolean includeAir = this .type == OctreeType .WORLD && !ray .getPrevMaterial ().isWater ();
487
505
488
506
// floating point division are slower than multiplication so we cache them
489
507
// We also try to limit the number of time the ray origin is updated
@@ -539,9 +557,14 @@ public boolean enterBlock(Scene scene, Ray ray, BlockPalette palette) {
539
557
ray .distance += distance ;
540
558
distance = 0 ;
541
559
if (currentBlock .intersect (ray , scene )) {
542
- if (prevBlock != currentBlock )
560
+ if (prevBlock != currentBlock ) { //|| (currentBlock.refractive)) {
561
+ //for things like glass panes coerce the current mat to be air or water
562
+ // TODO testing
563
+ if (currentBlock .refractive ) {
564
+ //ray.setCurrentMaterial(currentBlock.waterlogged ? Water.INSTANCE : Air.INSTANCE);
565
+ }
543
566
return true ;
544
-
567
+ }
545
568
ray .o .scaleAdd (Ray .OFFSET , ray .d );
546
569
offsetX = -ray .o .x * invDx ;
547
570
offsetY = -ray .o .y * invDy ;
@@ -556,7 +579,7 @@ public boolean enterBlock(Scene scene, Ray ray, BlockPalette palette) {
556
579
offsetZ = -ray .o .z * invDz ;
557
580
continue ;
558
581
}
559
- } else if (!currentBlock .isSameMaterial (prevBlock ) && currentBlock != Air .INSTANCE ) {
582
+ } else if (!currentBlock .isSameMaterial (prevBlock ) && ( currentBlock != Air .INSTANCE || includeAir ) ) {
560
583
// Origin and distance of ray need to be updated
561
584
ray .o .scaleAdd (distance , ray .d );
562
585
ray .distance += distance ;
0 commit comments