Class OctreeVolume
java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume
Sparse voxel octree for 3D volume storage and ray tracing.
The octree represents a 3D volume with three cell types:
- UNUSED - Empty cell, not yet allocated
- SOLID - Contains color and illumination data
- CLUSTER - Contains pointers to 8 child cells (for subdivision)
Cell data is stored in parallel arrays (cell1 through cell8)
for memory efficiency. Each array stores different aspects of cell data.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionint[]Cell data array 1: stores cell state and first child pointer.int[]Cell data array 2: stores color values.int[]Cell data array 3: stores illumination values.int[]Cell data array 4: stores child pointer 4.int[]Cell data array 5: stores child pointer 5.int[]Cell data array 6: stores child pointer 6.int[]Cell data array 7: stores child pointer 7.int[]Cell data array 8: stores child pointer 8.intPointer to the next unused cell in the allocation buffer.intSize of the root (master) cell in world units.static final intReturn value indicating no intersection during ray tracing.intNumber of currently allocated cells. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new octree volume with default buffer size (1.5M cells) and master cell size of 256*64 units. -
Method Summary
Modifier and TypeMethodDescriptionvoidbreakSolidCell(int pointer) Subdivides a solid cell into 8 child cells, each with the same color and illumination.voidclearCell(int pointer) Clears the cell.voiddeleteCell(int cellPointer) Marks a cell as deleted and returns it to the unused pool.intdoesIntersect(int cubeX, int cubeY, int cubeZ, int cubeSize, Ray r) Tests whether a ray intersects with a cubic region.voidfillRectangle(IntegerPoint p1, IntegerPoint p2, Color color) Fills a 3D rectangular region with solid cells of the given color.intgetCellColor(int pointer) Returns the color value stored in a solid cell.intgetCellIllumination(int pointer) Returns the illumination value stored in a solid cell.intScans cells arrays and returns pointer to found unused cell.voidinitWorld(int bufferLength, int masterCellSize) Initializes the octree storage arrays with the specified buffer size and root cell size.booleanisCellSolid(int pointer) Checks if the cell at the given pointer is a solid (leaf) cell.intmakeNewCell(int color, int illumination) Allocates a new solid cell with the given color and illumination.voidmarkCellAsSolid(int pointer) Mark cell as solid.voidStores a voxel at the given world coordinates with the specified color.voidsetCellColor(int pointer, int color) Sets the color value for the cell at the given pointer.voidsetCellIllumination(int pointer, int illumination) Sets the illumination value for the cell at the given pointer.intTraces a ray through the octree to find an intersecting solid cell.
-
Field Details
-
TRACE_NO_HIT
public static final int TRACE_NO_HITReturn value indicating no intersection during ray tracing.- See Also:
-
cell1
public int[] cell1Cell data array 1: stores cell state and first child pointer. -
cell2
public int[] cell2Cell data array 2: stores color values. -
cell3
public int[] cell3Cell data array 3: stores illumination values. -
cell4
public int[] cell4Cell data array 4: stores child pointer 4. -
cell5
public int[] cell5Cell data array 5: stores child pointer 5. -
cell6
public int[] cell6Cell data array 6: stores child pointer 6. -
cell7
public int[] cell7Cell data array 7: stores child pointer 7. -
cell8
public int[] cell8Cell data array 8: stores child pointer 8. -
cellAllocationPointer
public int cellAllocationPointerPointer to the next unused cell in the allocation buffer. -
usedCellsCount
public int usedCellsCountNumber of currently allocated cells. -
masterCellSize
public int masterCellSizeSize of the root (master) cell in world units.
-
-
Constructor Details
-
OctreeVolume
public OctreeVolume()Creates a new octree volume with default buffer size (1.5M cells) and master cell size of 256*64 units.
-
-
Method Details
-
breakSolidCell
public void breakSolidCell(int pointer) Subdivides a solid cell into 8 child cells, each with the same color and illumination.- Parameters:
pointer- the cell to break up
-
clearCell
public void clearCell(int pointer) Clears the cell.- Parameters:
pointer- Pointer to the cell.
-
deleteCell
public void deleteCell(int cellPointer) Marks a cell as deleted and returns it to the unused pool.- Parameters:
cellPointer- the cell to delete
-
doesIntersect
Tests whether a ray intersects with a cubic region.- Parameters:
cubeX- the X center of the cubecubeY- the Y center of the cubecubeZ- the Z center of the cubecubeSize- the half-size of the cuber- the ray to test- Returns:
- intersection type code, or 0 if no intersection
-
fillRectangle
Fills a 3D rectangular region with solid cells of the given color.- Parameters:
p1- one corner of the rectanglep2- the opposite corner of the rectanglecolor- the color to fill with
-
getCellColor
public int getCellColor(int pointer) Returns the color value stored in a solid cell.- Parameters:
pointer- the cell pointer- Returns:
- the packed RGB color value
-
getCellIllumination
public int getCellIllumination(int pointer) Returns the illumination value stored in a solid cell.- Parameters:
pointer- the cell pointer- Returns:
- the packed RGB illumination value
-
initWorld
public void initWorld(int bufferLength, int masterCellSize) Initializes the octree storage arrays with the specified buffer size and root cell size.- Parameters:
bufferLength- the number of cells to allocate space formasterCellSize- the size of the root cell in world units
-
isCellSolid
public boolean isCellSolid(int pointer) Checks if the cell at the given pointer is a solid (leaf) cell.- Parameters:
pointer- the cell pointer to check- Returns:
trueif the cell is solid
-
getNewCellPointer
public int getNewCellPointer()Scans cells arrays and returns pointer to found unused cell.- Returns:
- pointer to found unused cell
-
makeNewCell
public int makeNewCell(int color, int illumination) Allocates a new solid cell with the given color and illumination.- Parameters:
color- the color value for the new cellillumination- the illumination value for the new cell- Returns:
- the pointer to the newly allocated cell
-
markCellAsSolid
public void markCellAsSolid(int pointer) Mark cell as solid.- Parameters:
pointer- pointer to cell
-
putCell
Stores a voxel at the given world coordinates with the specified color.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinatecolor- the color of the voxel
-
setCellColor
public void setCellColor(int pointer, int color) Sets the color value for the cell at the given pointer.- Parameters:
pointer- the cell pointercolor- the color value to set
-
setCellIllumination
public void setCellIllumination(int pointer, int illumination) Sets the illumination value for the cell at the given pointer.- Parameters:
pointer- the cell pointerillumination- the illumination value to set
-
traceCell
Traces a ray through the octree to find an intersecting solid cell.- Parameters:
cellX- the X coordinate of the current cell centercellY- the Y coordinate of the current cell centercellZ- the Z coordinate of the current cell centercellSize- the size of the current cellpointer- the pointer to the current cellray- the ray to trace- Returns:
- pointer to intersecting cell or TRACE_NO_HIT if no intersection
-