10 #include "Generator.h"
11 #include "BlockData.h"
14 #include "ExternalMutex.h"
15 #include "StampMesh.h"
16 #include "Clipboard.h"
17 #include "PhysicsData.h"
32 void ClearBoxArea(IBlockData* blockData,
const double kernel[8][3],
bool fullErase, TSet<CellId>* changedCells);
37 return (VOXEL_OCCUPANCY_BLOCK * VOXEL_OCCUPANCY_BLOCK * z) + (VOXEL_OCCUPANCY_BLOCK * x) + y;
105 bool cellIsEmpty(
CellId cell);
110 void recomputeScene();
133 void smoothBlock(
const int buildCursorSizes[3],
const CellId& hitId,
const int hitCell[3],
int iterations,
float blendWeight);
142 const double size[3],
146 const double position[3],
161 void raiseBlock(
const int buildCursorSizes[3],
const CellId& hitId,
const int hitCell[3],
int iterations,
float blendWeight);
163 void processModifiedCells(
const TSet<CellId>& modifiedCells,
bool deleting =
false);
169 CellId c1,
int x1,
int y1,
int z1,
171 CellId c2,
int x2,
int y2,
int z2
179 CellId c,
int x,
int y,
int z
211 int xsize,
int ysize,
int zsize,
221 int xsize,
int ysize,
int zsize,
229 const double kernel[8][3],
239 void setLineOfSight(
double x0,
double y0,
double z0,
double x1,
double y1,
double z1);
260 const int buildCursorSizes[3],
262 const double hitPos[3],
270 double getMeshHeight(
double x,
double y,
double z,
bool& approximated,
int& material,
int medium = 0);
292 static const int MAX_CELL_REQUEST = 30000;
293 CellId cellRequestArray[MAX_CELL_REQUEST];
315 virtual void cellProcessed(
CCellData* cellData) {};
316 virtual void cellEmpty(
CellId cell) {};
317 virtual void cellsMeshed() {};
318 virtual void cellsBaked() {};
319 virtual void cellDestroyed(
CellId cell) {};
324 void notifyCellQueued(
CellId cellId);
349 static const int VOXEL_OCCUPANCY_BLOCK =
BLOCK_SIZE/2;
351 static const int VOXEL_OCCUPANCY_BLOCK_DATASIZE = VOXEL_OCCUPANCY_BLOCK*VOXEL_OCCUPANCY_BLOCK*VOXEL_OCCUPANCY_BLOCK;
389 double sceneBounds[2][3];
390 double nextSceneBounds[2][3];
449 TSet<CCellData*> disposedCells;
451 TSet<CellId> seamCreateQueue;
452 TSet<CellId> seamInProgress;
453 TVector<CCellData*> seamBakeQueue;
454 TSet<CellId> seamPendingCells;
455 TSet<CellId> seamRequested;
459 TSet<CellId> editionInProgress;
460 TSet<CellId> pendingBakeEditionCells;
470 bool cellsPendingBaking;
509 void updateOffsets();
538 time_t lastSceneTime;
540 unsigned char* tmpRayTraceBuffer;
542 bool recomputeHitPos;
544 TList<std::pair<int, Scene*>> createdScenes;
547 static int planeBoxOverlap(
double normal[3],
double d,
double maxbox[3]);
548 void computeCellSeams(
CellId cell);
570 void pitch(
double ang)
573 if (cPitch > 90.f) cPitch = 90.f;
574 if (cPitch < -90.f) cPitch = -90.f;
584 if (cYaw > 360.f) cYaw -= 360.f;
585 if (cYaw < 0.f) cYaw += 360.f;
592 void roll(
double ang)
595 if (cRoll > 360.f) cRoll -= 360.f;
596 if (cRoll < 0.f) cRoll += 360.f;
600 extern const int VoxelCorners[8][3];
int buildCursorSize
Edition cursor size in voxels.
double fillWorldPos[3]
Position of the starting face in world units.
CellDataCache cellCache
A cache of recently built and used CCellData objects.
ExternalMutex::Mutex dataLock
Critical section to allow multiple threads to collaborate loading and disposing Scenes.
double ypos
Viewer coordinates along the Y axis.
int buildCursorSizeY
Edition cursor size Y in voxels.
void pasteFromClipboard(IClipboard *clipboard, CellId c, int x, int y, int z)
Paste voxels from clipboard into block layer.
TSet< CellId > downloadQueueSet
Set of Cells to be downloaded accordint to priority.
void addBlock(LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3], const int hitHint[3], TSet< CellId > &changedCells)
Adds a block at the given edition coordinates.
VoxelFarm::Algebra::Vector getViewDirection() const
Get the current view direction.
Scene * scene
Current Scene.
void notifyCellDestroyed(CCellData *cellData)
Notifies the host has destroyed the application data the cell.
bool cellsPendingUpdate
Signal there are cells pending an update. This often happens when the user builds or carves cells...
double lineOfSightZ0
Line of sight start Z coordinate.
TMap< CellId, unsigned char * > voxelCache
Voxel occupancy cache.
int fillStartDir[3]
Direction of the starting face in only one axis (x, y or z)
void sceneFade(bool &sceneChanged)
Morphs from the previous scene into the next.
double speed
Speed at which the view moves.
Combines several voxel layers into the final dataset sent to the contouring phase.
double getMeshHeight(double x, double y, double z, bool &approximated, int &material, int medium=0)
Computes the vertical position using meshes. This is used to implement walking.
bool approximatedPos
Signals whether the vertical position is accurate, based on the best octree level possible...
bool sceneLoop(LODStats &stats)
Performs a scene loop iteration, which discovers if a new scene is needed and proceeds to request it...
void leaveCriticalSection()
Releases the critical section for the data that is shared by all threads using the view...
bool moving
Signals whether the viewer is moving or not.
double oldSceneZpos
Z coordinates for previous Scene.
Contains all classes and functions for the VoxelFarm engine.
void stampVoxels(double worldPos[3], unsigned int *data, int xsize, int ysize, int zsize, IMeshStamMaterialSource *materials)
It stamps a block of voxels data into block layer.
Contains all materials available in the system.
const int BLOCK_SIZE
Actual number of voxels in one Cell Dim once the margin is considered.
void updateHitPos()
Computes the location of the next block addition or removal.
bool detectCollisionAABB(double boxcenter[3], double boxhalfsize[3])
Detects collision of axis aligned bounding box against the view's geometry.
double pitch()
Camera rotation over the X axis (-90 is UP)
CCellData * CreateCellData(CellId cell)
Prototype for event callback to create a celldata object. The client application must return a differ...
int totalDownload
Total downloaded size in sizes.
TSet< CellId > pendingEditionCells
List of Cells queued for edition purposes.
int buildCursorSizeZ
Edition cursor size Z in voxels.
int totalCells
Total processed cells.
double lineOfSightY0
Line of sight start Y coordinate.
void stampModel(const double size[3], Algebra::Quaternion rotations, const double position[3], Architecture::CArchitectureManager *architectureManager, int moduleId, Architecture::CPaletteDesc *palette, Architecture::PaletteType type, IMeshStamMaterialSource *materials)
Stamp a model from architecture.
An index of which Cells are empty and which ones contain information. For offline mode only...
double lineOfSightY1
Line of sight end Y coordinate.
double normal[3]
voxel normal at the hit position
unsigned int sceneCnt
Number of scences built.
bool valid
whether there is a valid hit position (the rest of the data is not useful if this is false) ...
const int VOXEL_OCCUPANCY_BLOCK_DATASIZE
Number of voxels to store voxel occupancy within a cell.
TDeque< CellId > downloadQueue
List of Cells to be downloaded accordint to priority.
A default implementation of IBlockData that also acts as a VoxelLayer.
virtual void requestCells(CellId *cells, int count, CClipmapView *view)=0
The view uses this method to tell the implementor of the interface a list of cells is needed...
double lastXpos
Previous position along the X axis.
UpdateViewerState * updateViewerState
Pointer to UpdateViewerState event callback.
void smoothBlock()
Smooth block at the current edition coordinates.
int buildMaterial
Material that will be added at the edition point.
VoxelHitInfo hitInfo
Voxel targeted for build/carve.
int voxel[3]
voxel coordinates within the cell
double zoffs
Additional offset for Viewer coordinates along the Z axis.
double lineOfSightX0
Line of sight start X coordinate.
Architecture system. It keeps a list of entities, their classes and the mesh instances they have prod...
int buildCursorSizeX
Edition cursor size X in voxels.
void enterCriticalSection()
Acquires the critical section for the data that is shared by all threads using the view...
It allows to access to the faces and materials of a list of solids.
void raiseBlock()
Raise block at the current edition coordinates.
void copyToClipboard(IClipboard *clipboard, CellId c1, int x1, int y1, int z1, CellId c2, int x2, int y2, int z2)
Copy voxels to the Clipboard.
double lastZpos
Previous position along the Z axis.
double sceneYpos
Y coordinates for the current scene.
double cShiftY
Camera Shift in Y.
double lastYpos
Previous position along the Y axis.
static const int GARBAGE_MAX_AGE
Number of generations before Cells go to garbage.
virtual CCellData * createCellData(CellId cell)=0
The client application must return a different types of celldata objects depending on the graphics AP...
double position[3]
position of the hit (in world space)
bool started
Flags where the view has begun to produce scenes.
void disposeScene(Scene *old, Scene *current)
Disposes a scene. Cells in the scene will be moved to the garbage list.
double cShiftZ
Camera Shift in Z.
TMap< CellId, CCellData * > CellDataCache
Type definition for a map that allows caching CCellData objects.
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
bool fillMode
It signals whether the fill tool is in use.
TSet< CCellData * > deadMeat
Set of Cells to be disposed.
Cells Scene
A Scene is a set of cells.
CreateCellData * createCellData
Create celldata object event callback.
void removeBlock(LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3])
Removes a block at the given edition coordinates.
void endFill(IMeshStamMaterialSource *material)
It ends the fill tool by stamping the designed box into a block layer.
Scene * newScene
A new Scene was just built.
int material
material of the hit voxel
bool computeLods
Set to true if LODs should be re-computed.
int lastCellGeneration
Generation of last batch of Cells.
bool firstLoad
Signals whether the view has just loaded.
Stores the information for a Cell that has already been converted to a polygonal mesh.
VoxelFarm::Algebra::Vector getViewPosition() const
Get the current camera position relative to the user's location.
int hitPosXi
Edition point X coordinate in voxels.
unsigned int renderTime
Time spent rendering.
CMaterialLibrary * materialLibrary
Points to the material library to be used by the view.
bool detectCollisionEllipsoid(double center[3], double radV, double radH, double pi[3], double push[3])
Detects collision of axis aligned ellipsoid against the view's geometry.
Generation of voxel data and then meshes out if it can be time consuming. The engine allows multiple ...
double xoffs
Additional offset for Viewer coordinates along the X axis.
TDeque< CellId > processQueue
List of Cells to be processed.
void beginFill()
It initializes the fill tool.
double zpos
Viewer coordinates along the Z axis.
VoxelFarm::Algebra::Vector getViewWorldPosition() const
Get the current view position in world.
unsigned int sceneTime
Stats about scene build time.
double cShiftX
Camera Shift in X.
int outsideDirection[3]
voxel direction to the open side of the voxel
double sceneFadeIn
Scene morph progress.
void UpdateViewerState()
Prototype for event callback to update viewer position. This is called right before the view is rende...
virtual void updateViewerState()=0
This is called right before the view is rendered. If desired this event can be used to query user inp...
A Matrix for 3D operations.
virtual void cellQueued(CellId cellId)=0
Called whenever a cell is queued for processing. Can be used to wake up processing threads...
double lineOfSightZ1
Line of sight end Z coordinate.
unsigned int renderCnt
Number of frames rendered.
const int VOXEL_OCCUPANCY_BLOCK
Dimensions for additional set to store voxel occupancy within a cell.
StatTracker LODStats[LEVELS][STAT_NULL]
Used to track stats across all LOD.
double oldSceneYpos
Y coordinates for previous Scene.
double yoffs
Additional offset for Viewer coordinates along the Y axis.
void setEvents(IEvents *events)
Set event interface.
void notifyCellBakedSeams(CCellData *cellData)
Notifies the host has processed seams for the cell.
void getBuildCursorSize(int sizes[3]) const
Get the current size of the build cursor.
CCellData * getNextCellToDestroy()
Returns the next cell which its information has to be destroyed by the host.
MapIndex * mapIndex
Current MapIndex object in use.
int totalDownloadCount
Total downloaded cells.
TSet< CCellData * > garbageCells
Set of Cells soon to be disposed unless they are recalled.
BuildCursorMode buildCursorMode
Defines cursor mode 0 - add, 1 - smooth.
int getVoxelOccupancyIndex(int x, int y, int z)
Return the index into the voxel occupancy data for a given x, y, z offset.
double yaw()
Camera rotation over the Y axis.
PaletteType
Type of palette of materials when collecting instances.
void endChanges()
Marks the end of an edition transaction.
CBillboardCache billboardCache
A cache storage for billboards and material instances.
CGenerator * generator
Points to the generator object to be used by the view. This object is able to generate voxel data fro...
CBlockData * blockData
Points to the an object that holds the user data. These are voxels that have been input by the user...
bool invalidateRenderCache
Signal any rendering caching should be invalidated.
void setRemoteView(IRemoteView *remoteView)
Assigns the remote view interface handler.
void updateFillScope()
It updates the fill scope based on the cursor position.
double fillScope[8][3]
It defines the scope for the fill tool. The first 4 points are the starting face for the box and the ...
void clearBoxArea(const double kernel[8][3], bool fullErase)
Clears a box of voxels in the block layer.
double heading
The direction on which the viewer is moving.
CellId cell
cell hit by a collision / ray
TSet< CellId > emptyCells
Set of Cells the engine knows they are empty.
Represents a moving view within a world. Computes new scenes as the view moves.
double slopeDamp
Dampenning to Viewer speed caused by high slope.
double oldSceneXpos
X coordinates for previous Scene.
BuildCursorMode
Build cursor mode.
unsigned char * createVoxelOccupancyData(ContourVoxelData *data)
Creates a leaner data structure to track voxel occupancy. Each voxel is stored in one bit...
The IRemoteView interface allows the clipmap view object to request data for cells. The clipmap view will determine which new cells are required for the next scene and will request them using this interface.
void notifyRemoteCellsChanged(CellId *cells, int count)
Notifies the view some cells have changed.
Scene * oldScene
Previous Scene that was just replaced.
bool resolutionSwitch
Flags a clipmap resolution switch is required.
void repairBlock(LODStats &stats, int buildCursorSize, const int buildCursorSizes[3], const CellId &hitId, const int hitCell[3])
Erases a block at the given edition coordinates.
void hitPosChanged()
Request the system to computes the location of the edition coordinates.
int hitPosYi
Edition point Y coordinate in voxels.
void stampMesh(double worldPos[3], IMeshStampSource *mesh, IMeshStamMaterialSource *materials, const Algebra::Matrix &transform)
It stamps a polygonal mesh into block layer.
void addSmoothBlock()
Adds a smooth block at the current edition coordinates.
int hitPosZi
Edition point Z coordinate in voxels.
void undo()
Reverts the last edition transaction.
Scene * nextScene
The next Scene down the pipeline.
int totalDownloadTime
Total download time.
double time
Time vector (used for animating grass)
bool contourLoop(CGenerator *threadGenerator, ContourThreadContext *tc, CCellData::ThreadContext *tcCellData, LODStats stats)
Performs a contour loop iteration. This will load the voxel data for pending Cells in the requested s...
CCellData * getNextCellToBakeSeams()
Returns the next cell to have its seams processed by the host.
double lineOfSightX1
Line of sight end X coordinate.
void notifyRemoteCellsReady(CellId *cells, int count)
Notifies the view data for some cells is ready.
void beginChanges()
Marks the start of an edition transaction. A call to undo() will restore to this state.
double sceneZpos
Z coordinates for the current scene.
int fillEndDir[3]
Direction of the ending face in only one axis (x, y or z)
int sceneResolution
The current clipmap resolution.
int maxSceneResolution
Desired clipmap resolution.
double sceneXpos
X coordinates for the current scene.
A palette of materials definition for the VoxelFarm.com engine.
void garbageCollect()
Performs garbage collection.
void setLineOfSight(double x0, double y0, double z0, double x1, double y1, double z1)
int scenePendingTotal
Amount of Cells pending processing.
double xpos
Viewer coordinates along the X axis.
Keeps an billboard cache entry for each cell that had its billboards and material instances generated...
CCellData * getNextCellToBake()
Returns the next cell to be processed by the host.
int lastSceneResolution
Previous clipmap resolution.
TVector< CCellData * > bakeQueue
List of Cells to be baked.
TSet< CellId > pendingCells
List of Cells int the downloading/generation and processing pipeline.
void notifyCellBaked(CCellData *cellData)
Notifies the host has processed the cell.
double roll()
Camera rotation over the Z axis.
It translates a given material depending of the position in the world.