1 #ifndef BLUB_PROCEDURAL_VOXEL_EDIT_BASE_HPP
2 #define BLUB_PROCEDURAL_VOXEL_EDIT_BASE_HPP
5 #include "blub/core/enableSharedFromThis.hpp"
6 #include "blub/core/globals.hpp"
7 #include "blub/core/noncopyable.hpp"
8 #include "blub/math/axisAlignedBox.hpp"
9 #include "blub/math/plane.hpp"
10 #include "blub/math/transform.hpp"
11 #include "blub/math/vector3int.hpp"
12 #include "blub/procedural/predecl.hpp"
13 #include "blub/procedural/voxel/simple/container/base.hpp"
14 #include "blub/procedural/voxel/tile/container.hpp"
32 template <
class configType>
33 class base :
public enableSharedFromThis<base<configType> >,
public blub::noncopyable
37 typedef enableSharedFromThis<base<t_config> > t_base;
38 typedef sharedPointer<base<t_config> > pointer;
39 typedef typename t_config::t_container::t_simple t_voxelContainerSimple;
40 typedef typename t_config::t_container::t_tile t_voxelContainerTile;
57 BASSERT(m_voxelContainer !=
nullptr);
59 m_voxelContainer->editVoxel(t_base::getSharedThisPtr(), trans);
75 BLUB_PROCEDURAL_LOG_OUT() <<
"calculateVoxel trans:" << trans;
80 const int32 voxelsPerTile(t_config::voxelsPerTile);
81 const vector3int32 posContainerAbsolut(voxelContainerOffset*voxelsPerTile);
82 for (int32 indX = 0; indX < t_config::voxelsPerTile; ++indX)
84 for (int32 indY = 0; indY < t_config::voxelsPerTile; ++indY)
86 for (int32 indZ = 0; indZ < t_config::voxelsPerTile; ++indZ)
89 vector3 posAbsolut(posContainerAbsolut + posVoxel);
96 posAbsolut -= trans.position;
97 posAbsolut /= trans.scale;
108 voxelContainer->setVoxelIfInterpolationHigher(posVoxel, voxelResult);
113 voxelContainer->setVoxelIfInterpolationLower(posVoxel, voxelResult);
143 m_voxelContainer = toSet;
150 return m_voxelContainer;
162 : m_voxelContainer(nullptr)
198 virtual void createLine(t_voxelContainerTile *voxelContainer,
206 const real &pointA(from);
229 int32 voxelStartRel(0);
230 int32 voxelEndRel(0);
231 const real level(0.5);
234 real roundedDown(blub::math::floor(pointA));
235 if (roundedDown >= 0 && roundedDown < t_config::voxelsPerTile)
237 if (
vector3(lineAxis).dotProduct(planeA.normal) <= -level)
239 real valueDown(roundedDown-pointA);
240 real zResultDown(127.*valueDown);
241 BASSERT(zResultDown <= 0.);
242 BASSERT(zResultDown >= -127.);
244 setVoxel(voxelContainer, posVoxel +
vector3int32(roundedDown)*lineAxis, bufferVoxel);
250 real roundedUp(blub::math::ceil(pointA));
251 if (roundedUp >= 0. && roundedUp < t_config::voxelsPerTile)
253 if (
vector3(lineAxis).dotProduct(planeA.normal) <= -level)
255 real valueUp(roundedUp-pointA);
256 real zResultUp(127.*valueUp);
257 BASSERT(zResultUp >= 0.);
258 BASSERT(zResultUp <= 127.);
260 setVoxel(voxelContainer, posVoxel +
vector3int32(roundedUp)*lineAxis, bufferVoxel);
268 real roundedDown(blub::math::floor(pointB));
269 if (roundedDown >= 0 && roundedDown < t_config::voxelsPerTile)
271 if (
vector3(lineAxis).dotProduct(planeB.normal) >= level)
273 real valueDown(roundedDown-pointB);
274 real zResultDown(127.*valueDown);
275 BASSERT(zResultDown <= 0.);
276 BASSERT(zResultDown >= -127.);
278 setVoxel(voxelContainer, posVoxel +
vector3int32(roundedDown)*lineAxis, bufferVoxel);
284 real roundedUp(blub::math::ceil(pointB));
285 if (roundedUp >= 0. && roundedUp < t_config::voxelsPerTile)
287 if (
vector3(lineAxis).dotProduct(planeB.normal) >= level)
289 real valueUp(roundedUp-pointB);
290 real zResultUp(127.*valueUp);
291 BASSERT(zResultUp >= 0.);
292 BASSERT(zResultUp <= 127.);
294 setVoxel(voxelContainer, posVoxel +
vector3int32(roundedUp)*lineAxis, bufferVoxel);
301 real cutPointVoxelDown = blub::math::floor(pointA);
302 real cutPointVoxelUp = blub::math::ceil(pointB+1);
304 int32 voxelClampedStart = math::clamp<real>(cutPointVoxelDown, 0., t_config::voxelsPerTile);
305 int32 voxelClampedEnd = math::clamp<real>(cutPointVoxelUp, 0., t_config::voxelsPerTile);
307 for (int32 ind = voxelClampedStart + voxelStartRel; ind < voxelClampedEnd - voxelEndRel; ++ind)
310 setVoxel(voxelContainer, posVoxel +
vector3int32(ind)*lineAxis, bufferVoxel);
317 virtual void setVoxel(t_voxelContainerTile *voxelContainer,
const vector3int32 &posVoxel, t_voxel &toSet)
const
319 voxelContainer->setVoxelIfInterpolationHigher(posVoxel, toSet);
323 t_voxelContainerSimple* m_voxelContainer;
336 #endif // BLUB_PROCEDURAL_VOXEL_EDIT_BASE_HPP
virtual void createLine(t_voxelContainerTile *voxelContainer, const vector3int32 &posVoxel, const real &from, const real &len, const axis &ax, const blub::plane &planeA, const blub::plane &planeB) const
createLine creates a voxel-line on one axis with a specific length
Definition: base.hpp:198
Definition: customVertexInformation.cpp:193
base class of all edits. Has various features you may wanna overwrite. If you want to write your own ...
Definition: predecl.hpp:71
virtual ~base()
destructor
Definition: base.hpp:46
void setCut(const bool &cut)
Enable or disable cut. Don't change the value while active calculation.
Definition: base.hpp:124
virtual blub::axisAlignedBox getAxisAlignedBoundingBox(const transform &trans) const =0
getAxisAlignedBoundingBox returns the transformed blub::axisAlignedBox in which the voxel have to get...
virtual void calculateVoxel(t_voxelContainerTile *voxelContainer, const vector3int32 &voxelContainerOffset, const transform &trans) const
calculates all voxel in getAxisAlignedBoundingBox() and inserts them into voxelContainer. Method gets called once per tile from various threads. Voxel only will get set if the interpolation is higher than the inerpoaltion before calculation.
Definition: base.hpp:70
axis
The axis enum is used by createLine() for describing the direction.
Definition: base.hpp:181
bool contains(const vector3 &v) const
Definition: axisAlignedBox.hpp:496
void setInterpolation(const int8 &toSet)
setInterpolation sets interpolation
Definition: data.hpp:61
Definition: noncopyable.hpp:10
Definition: vector3.hpp:26
const bool & getCut() const
Returns if cutting is enabled.
Definition: base.hpp:132
Definition: axisAlignedBox.hpp:20
The data class is the default voxel. Contains an 8-bit interpolation value. Replace/derive it and set...
Definition: data.hpp:27
t_voxelContainerSimple * getVoxelContainer() const
Definition: base.hpp:148
int8 & getInterpolation()
getInterpolation returns reference to interpolation.
Definition: data.hpp:70
Definition: deadlineTimer.hpp:10
virtual bool calculateOneVoxel(const vector3 &pos, t_voxel *resultVoxel) const
Implement this method for your own edit.
Definition: base.hpp:173
void calculateVoxel(const transform &trans) const
calculates voxel in the container u have to set by setVoxelContainer() before. If setVoxelContainer()...
Definition: base.hpp:55
void setVoxelContainer(t_voxelContainerSimple *toSet)
Sets the voxelcontainer used by calculateVoxel().
Definition: base.hpp:141
Definition: customVertexInformation.cpp:177