@@ -244,11 +244,26 @@ public int getData() {
244244 }
245245 }
246246
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+
247260 /**
248261 * Timestamp of last serialization.
249262 */
250263 private long timestamp = 0 ;
251264
265+ public OctreeType type ;
266+
252267 private OctreeImplementation implementation ;
253268
254269 /**
@@ -257,9 +272,10 @@ public int getData() {
257272 *
258273 * @param octreeDepth The number of levels in the Octree.
259274 */
260- public Octree (String impl , int octreeDepth ) {
275+ public Octree (String impl , int octreeDepth , OctreeType type ) {
261276 Log .infof ("Building new octree (%s)" , impl );
262277 implementation = getImplementationFactory (impl ).create (octreeDepth );
278+ this .type = type ;
263279 }
264280
265281 protected Octree (OctreeImplementation impl ) {
@@ -484,6 +500,8 @@ public boolean enterBlock(Scene scene, Ray ray, BlockPalette palette) {
484500 int depth = implementation .getDepth ();
485501
486502 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 ();
487505
488506 // floating point division are slower than multiplication so we cache them
489507 // 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) {
539557 ray .distance += distance ;
540558 distance = 0 ;
541559 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+ }
543566 return true ;
544-
567+ }
545568 ray .o .scaleAdd (Ray .OFFSET , ray .d );
546569 offsetX = -ray .o .x * invDx ;
547570 offsetY = -ray .o .y * invDy ;
@@ -556,7 +579,7 @@ public boolean enterBlock(Scene scene, Ray ray, BlockPalette palette) {
556579 offsetZ = -ray .o .z * invDz ;
557580 continue ;
558581 }
559- } else if (!currentBlock .isSameMaterial (prevBlock ) && currentBlock != Air .INSTANCE ) {
582+ } else if (!currentBlock .isSameMaterial (prevBlock ) && ( currentBlock != Air .INSTANCE || includeAir ) ) {
560583 // Origin and distance of ray need to be updated
561584 ray .o .scaleAdd (distance , ray .d );
562585 ray .distance += distance ;
0 commit comments