57 using namespace HDK_Sample;
71 SNOW_Solver::getSolverSNOWDopDescription()
89 return &theDopDescription;
130 int sx,
int sy,
int sz,
131 int dx,
int dy,
int dz,
132 int &rx,
int &ry,
int &rz,
137 int xdiv = (
int)div.
x();
138 int ydiv = (
int)div.
y();
139 int zdiv = (
int)div.
z();
177 int end_x[6], end_y[6], end_z[6],
dist[6];
179 int dxvals[6] = { -1, 0, 0, 1, 0, 0 };
180 int dyvals[6] = { 0, -1, 1, 0, 0, 0 };
181 int dzvals[6] = { 0, 0, 0, 0, 1, -1 };
184 for (direction = 0; direction < 6; direction++)
189 dxvals[direction], dyvals[direction], dzvals[direction],
190 end_x[direction], end_y[direction], end_z[direction],
194 if (dist[direction] < mindist)
201 if (mindist == 320000)
216 int choice = rand->
choice(numchoice);
228 int xdiv = (
int)div.
x();
230 int sx = (
int)(startx * xdiv);
231 int ex = (
int)(endx * xdiv);
233 if (sx >= xdiv)
return;
235 if (ex >= xdiv) ex = xdiv - 1;
239 for (
int x = sx;
x < ex;
x++)
249 for (
int x = sx;
x < ex;
x++)
269 int xdiv = (
int)div.
x();
270 int ydiv = (
int)div.
y();
271 int zdiv = (
int)div.
z();
284 int bminx = (
int)
SYSfloor(bbox(0, 0) * (xdiv + 1));
285 if (bminx < 0) bminx = 0;
286 int bmaxx = (
int)
SYSceil(bbox(0, 1) * (xdiv + 1));
287 if (bmaxx >= xdiv) bmaxx = xdiv-1;
288 int bminy = (
int)
SYSfloor(bbox(1, 0) * (ydiv + 1));
289 if (bminy < 0) bminy = 0;
290 int bmaxy = (
int)
SYSceil(bbox(1, 1) * (ydiv + 1));
291 if (bmaxy >= ydiv) bmaxy = ydiv-1;
292 int bminz = (
int)
SYSfloor(bbox(2, 0) * (zdiv + 1));
293 if (bminz < 0) bminz = 0;
294 int bmaxz = (
int)
SYSceil(bbox(2, 1) * (zdiv + 1));
295 if (bmaxz >= zdiv) bmaxz = zdiv-1;
309 for (
int z = bmaxz;
z >= bminz;
z--)
311 orig.
z() = (
z + 0.5) / (zdiv + 1);
312 for (
int y = bminy;
y <= bmaxy;
y++)
314 orig.
y() = (
y + 0.5) / (ydiv + 1);
322 int numhit = isect->
sendRay(xorig, xdir, hitinfo);
337 for (
int hitnum = 0; hitnum <= numhit; hitnum++)
347 pos.
x() = (t + lt) / 2.0;
352 fillRow(snow, lt, t,
y,
z, voxeltype, rand);
365 SNOW_Solver::solveForObject(
SIM_Object &
object,
373 int xdiv = (
int)div.
x();
374 int ydiv = (
int)div.
y();
375 int zdiv = (
int)div.
z();
382 tosnow.
scale(size.
x(), size.
y(), size.
z());
386 fpreal birthrate = getBirthRate();
392 for (
int z = 0;
z < zdiv;
z++)
394 for (
int y = 0;
y <= ydiv;
y++)
396 for (
int x = 0;
x <= xdiv;
x++)
409 object.getAffectors(sourceaffectors,
"SIM_RelationshipSource");
411 for (
int i = 0; i <
n; i++)
413 const SIM_Object *affector = sourceaffectors(i);
427 xform = worldtogeo * xform;
430 xform = tosnow * xform;
436 object.getColliderInfo(colliderinfo);
438 for (
int i = 0; i <
n; i++)
440 const SIM_Object *affector = colliderinfo(i).getAffector();
454 xform = worldtogeo * xform;
456 xform = tosnow * xform;
463 for (
int y = 0;
y < ydiv;
y++)
465 for (
int x = 0;
x < xdiv;
x++)
467 if (rand->
frandom() < birthrate)
474 int dxvals[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
475 int dyvals[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
481 for (
int z = 1;
z < zdiv;
z++)
488 int yend, ystart, yinc;
489 int xend, xstart, xinc;
510 for (
int y = ystart;
y != yend;
y += yinc)
512 for (
int x = xstart;
x != xend;
x += xinc)
518 for (dxidx = 0; dxidx < 9; dxidx++)
524 validdxidx[numdxidx++] = dxidx;
532 dxidx = validdxidx[dxidx];
555 SNOW_Solver::setVoxelArrayAttributes(
SNOW_VoxelArray *voxelarray)
const
560 int xdiv = (
int)div.
x();
561 int ydiv = (
int)div.
y();
562 int zdiv = (
int)div.
z();
564 int depth = getOriginalDepth();
566 for (
int z = 0;
z <
SYSmin(depth, zdiv);
z++)
568 for (
int y = 0;
y < ydiv;
y++)
570 for (
int x = 0;
x < xdiv;
x++)
601 setVoxelArrayAttributes(snow);
606 solveForObject(
object, *snow, timestep);
616 : BaseClass(factory),
627 SNOW_VoxelArray::getVoxelArrayDopDescription()
641 "hdk_snowvoxelarray",
647 return &theDopDescription;
669 return myVoxelArray->
getValue(x, y, z);
679 myVoxelArray->
setValue(x, y, z, voxel);
686 return myDetailHandle;
690 SNOW_VoxelArray::freeArray()
const
697 SNOW_VoxelArray::allocateArray()
const
704 int divx =
SYSmax((
int)div.
x(), 1);
705 int divy =
SYSmax((
int)div.
y(), 1);
706 int divz =
SYSmax((
int)div.
z(), 1);
708 myVoxelArray->
size(divx, divy, divz);
715 SNOW_VoxelArray::createOrFindPoint(
GU_Detail *gdp,
int x,
int y,
int z)
718 int xdiv = (
int)div.
x();
719 int ydiv = (
int)div.
y();
720 int zdiv = (
int)div.
z();
722 exint idx = (
exint(z) * (ydiv + 1) + y)*(xdiv + 1) + x;
725 if (it != myPointHash.end())
732 #if defined(HOUDINI_11)
749 myPointHash[idx] = ptoff;
755 SNOW_VoxelArray::buildFace(
GU_Detail *gdp,
756 int x0,
int y0,
int z0,
757 int x1,
int y1,
int z1,
758 int x2,
int y2,
int z2,
759 int x3,
int y3,
int z3)
765 ptoff = createOrFindPoint(gdp, x0, y0, z0);
767 ptoff = createOrFindPoint(gdp, x1, y1, z1);
769 ptoff = createOrFindPoint(gdp, x2, y2, z2);
771 ptoff = createOrFindPoint(gdp, x3, y3, z3);
776 SNOW_VoxelArray::buildGeometryFromArray()
778 if (myDetailHandle.
isNull())
783 int xdiv = (
int)div.
x();
784 int ydiv = (
int)div.
y();
785 int zdiv = (
int)div.
z();
800 for (
int z = 0; z < zdiv; z+=zstep)
802 for (
int y = 0; y < ydiv; y+=ystep)
804 for (
int x = 0; x < xdiv; x+=xstep)
817 buildFace( gdp, x, y, z,
824 buildFace( gdp, x+xstep, y, z,
826 x+xstep, y+ystep, z+zstep,
827 x+xstep, y+ystep, z );
831 buildFace( gdp, x, y, z,
838 buildFace( gdp, x, y+ystep, z,
840 x+xstep, y+ystep, z+zstep,
841 x, y+ystep, z+zstep );
845 buildFace( gdp, x, y, z,
852 buildFace( gdp, x, y, z+zstep,
854 x+xstep, y+ystep, z+zstep,
855 x+xstep, y, z+zstep );
870 BaseClass::initializeSubclass();
872 myDetailHandle.
clear();
880 BaseClass::makeEqualSubclass(source);
884 setDivisions(srcvox->getDivisions());
886 if (srcvox->myVoxelArray)
891 *myVoxelArray = *srcvox->myVoxelArray;
905 int xdiv = (
int)div.
x();
906 int ydiv = (
int)div.
y();
907 int zdiv = (
int)div.
z();
909 BaseClass::saveIOSubclass(os, io);
912 for (
int z = 0; z < zdiv; z++)
914 for (
int y = 0; y < ydiv; y++)
917 for (
int x = 0; x < xdiv; x++)
931 if (!BaseClass::loadIOSubclass(is, io))
935 int xdiv = (
int)div.
x();
936 int ydiv = (
int)div.
y();
937 int zdiv = (
int)div.
z();
953 while (idx < arraysize && bufis)
983 int64 mem =
sizeof(*this);
986 if (!myDetailHandle.
isNull())
1000 BaseClass::handleModificationSubclass(code);
1003 myDetailHandle.
clear();
1012 myVoxelArray->collapseAllTiles();
1016 : BaseClass(factory),
1027 SNOW_Visualize::getVisualizeDopDescription()
1029 static PRM_Name theGuideBox(
"usebox",
"Bounding Box");
1046 "hdk_snowvisualize",
1051 theDopDescription.setGuideTemplates(theGuideTemplates);
1053 return &theDopDescription;
1073 #if defined(HOUDINI_11)
1074 static float one[3] = { 1, 1, 1 };
1075 gdp->
addPointAttrib(
"Cd", 3 *
sizeof(
float), GB_ATTRIB_FLOAT, one);
1089 for (
int idx1 = 0; idx1 < 8; idx1++)
1094 pos.
x() = (idx1 & 1) ? bbox.
xmax() : bbox.
xmin();
1095 pos.
y() = (idx1 & 2) ? bbox.
ymax() : bbox.
ymin();
1096 pos.
z() = (idx1 & 4) ? bbox.
zmax() : bbox.
zmin();
1097 gdp->
setPos3(corners[idx1], pos);
1099 cdh.set(corners[idx1], color);
1107 for (
int idx1 = 0; idx1 < 8; idx1++)
1109 for (
int idx2 = idx1+1; idx2 < 8; idx2++)
1111 switch (idx1 ^ idx2)
1153 bbmin = myArray->getCenter();
1155 bbmin -= myArray->getSize()*0.5;
1156 bbmax += myArray->getSize()*0.5;
1169 int divx = (
int)div.
x();
1170 int divy = (
int)div.
y();
1171 int divz = (
int)div.
z();
1176 for (
int z = 0; z < divz; z++)
1177 for (
int y = 0; y < divy; y++)
1178 for (
int x = 0; x < divx; x++)
1183 cdh.set(ptoff, color);
1190 v *= myArray->getSize();
1191 v += myArray->getCenter();
1201 if (getUseBox(options))
1208 BaseClass::initializeSubclass();
GU_Detail * getGdp() const
int sendRay(const UT_Vector3 &org, const UT_Vector3 &dir, GU_RayInfo &hitinfo) const
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GA_API const UT_StringHolder dist
GA_API const UT_StringHolder div
GLenum GLuint GLenum GLsizei const GLchar * buf
SYS_FORCE_INLINE GA_Attribute * addPointAttrib(const GA_Attribute *src)
#define SIM_DATA_CASTCONST(Data, DataClass)
void initAlternateRepresentationSubclass(const SIM_Data &) override
PRM_API PRM_Range PRMunitRange
virtual void optionChangedSubclass(const char *name)
void getTransform(UT_DMatrix4 &xform) const
void setValue(UT_Vector3I index, T value)
#define IMPLEMENT_DATAFACTORY(DataClass)
void transform(const MATRIX &mat)
Class which stores the default values for a GA_Attribute.
bool getBBox(UT_BoundingBox *bbox, const GA_PrimitiveGroup *g=nullptr) const
PRM_API const PRM_Type PRM_RGB
int64 getMemoryUsage(bool inclusive) const
Return the amount of memory used by this array.
void initializeSubclass() override
GA_Attribute * addFloatTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringHolder &name, int tuple_size, const GA_Defaults &defaults=GA_Defaults(0.0), const UT_Options *creation_args=0, const GA_AttributeOptions *attribute_options=0, GA_Storage storage=GA_STORE_REAL32, const GA_ReuseStrategy &reuse=GA_ReuseStrategy())
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
void pubHandleModification()
GLsizei const GLfloat * value
Data represents a color. Token "color".
GLdouble GLdouble GLdouble z
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
constexpr SYS_FORCE_INLINE T & z() noexcept
fpreal frandom()
Returns a random float from [0..1)
const GA_Attribute * findDiffuseAttribute(GA_AttributeOwner who) const
void makeEqualSubclass(const SIM_Data *source) override
Makes this geometry equal to some other SIM_Geometry.
SYS_FORCE_INLINE const char * buffer() const
void initializeSubclass() override
Set initial values on all the geometry attributes.
SIM_API PRM_Name SIMshowguideName
int64 getMemorySizeSubclass() const override
GA_Offset appendParticle(GA_Offset pt)
Append a new particle.
An input stream object that owns its own string buffer storage.
**But if you need a or simply need to know when the task has note that the like this
PRM_API PRM_Default PRMpointOneDefaults[]
void fillRow(SNOW_VoxelArray &snow, fpreal startx, fpreal endx, int y, int z, u8 voxeltype, SIM_Random *rand) const
**But if you need a result
GU_ConstDetailHandle getGeometrySubclass() const override
PRM_API const PRM_Type PRM_INT_J
void size(int xres, int yres, int zres, bool reset=true)
bool getIsAlternateRepresentationSubclass() const override
u8 getVoxel(int x, int y, int z) const
GA_PrimitiveGroup * newPrimitiveGroup(const UT_StringHolder &name)
int64 getMemoryUsage(bool inclusive) const override
Compute memory usage (includes all shared memory)
GA_RWHandleT< UT_Vector3F > GA_RWHandleV3
PRM_API const PRM_Type PRM_INT
void allocateAndSet(GU_Detail *gdp, bool own=true)
void initAlternateRepresentation() const
PRM_API PRM_Default PRMtenDefaults[]
void initializeSIM(void *)
int rand_choice(int numchoice, SIM_Random *rand) const
bool getLine(UT_WorkBuffer &buffer, int end='\n')
Holds pointers to a number of SIM_Object objects.
void saveIOSubclass(std::ostream &os, SIM_DataThreadedIO *io) const override
#define SIM_DATA_GET(Parent, DataName, DataClass)
PRM_API const PRM_Type PRM_XYZ
GLsizei GLsizei GLchar * source
SYS_FORCE_INLINE GA_Offset appendPoint()
Append a new point, returning its new data offset.
const SIM_Geometry * getGeometry() const
#define SIM_SOLVER_DATANAME
void identity()
Set the matrix to identity.
SNOW_Visualize(const SIM_DataFactory *factory)
SYS_API fpreal32 SYSfloor(fpreal32 val)
GLuint const GLchar * name
int clearInDirection(const SNOW_VoxelArray &snow, int sx, int sy, int sz, int dx, int dy, int dz, int &rx, int &ry, int &rz, int maxdist, SIM_Random *rand) const
static void createBoundingBoxGuide(GU_Detail *gdp, const UT_BoundingBox &bbox, const UT_Vector3 &color)
void swap(UT_WorkBuffer &buf)
PRM_API const PRM_Type PRM_FLT_J
void setVoxel(u8 voxel, int x, int y, int z)
void add(const GA_Primitive *prim)
void applyGeometry(SNOW_VoxelArray &snow, const GU_ConstDetailHandle &gdh, const UT_DMatrix4 &xform, u8 voxletype, SIM_Random *rand) const
#define SIM_NAME_BIRTHRATE
void getInverseTransform(UT_DMatrix4 &xform) const
SIM_Guide * createGuideObjectSubclass() const override
GLint GLint GLsizei GLsizei GLsizei depth
void optionChangedSubclass(const char *name) override
exint entries() const
Alias of size(). size() is preferred.
bool SYSequalZero(const UT_Vector3T< T > &v)
void scale(T sx, T sy, T sz, T sw=1)
PRM_API PRM_Default PRMoneDefaults[]
SNOW_Solver(const SIM_DataFactory *factory)
SYS_FORCE_INLINE GA_Offset appendPointOffset()
bool brownianize(int &v, int dv, int max, SIM_Random *rand) const
GEO_AttributeHandle getPointAttribute(const char *attrib_name) const
SYS_FORCE_INLINE void setPos3(GA_Offset ptoff, const UT_Vector3 &pos)
Set P from a UT_Vector3.
const SIM_Position * getPosition() const
T getValue(int x, int y, int z) const
void clearSnow(SNOW_VoxelArray &snow, int x, int y, int z, SIM_Random *rand) const
void translate(T dx, T dy, T dz=0)
SNOW_VoxelArray(const SIM_DataFactory *factory)
GU_ConstDetailHandle getGeometry() const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
SYS_FORCE_INLINE void initBounds()
PRM_API const PRM_Type PRM_TOGGLE
void handleModificationSubclass(int code) override
static GU_PrimParticle * build(GU_Detail *gdp, GA_Size numparts, bool appendPts=true)
UT_StringStreamBuffer * rdbuf() const
Returns the underlying stream buffer object.
int isInsideWinding(const UT_Vector3 &pt, bool ignoretrim=true, float tol=0.1) const
bool loadIOSubclass(UT_IStream &is, SIM_DataThreadedIO *io) override
SIM_Result solveSingleObjectSubclass(SIM_Engine &engine, SIM_Object &object, SIM_ObjectArray &feedbacktoobjects, const SIM_Time ×tep, bool newobject) override
~SNOW_VoxelArray() override
void setBorder(UT_VoxelBorderType type, T t)
SIM_API PRM_Name SIMcolorName
~SNOW_Visualize() override
void buildGuideGeometrySubclass(const SIM_RootData &root, const SIM_Options &options, const GU_DetailHandle &gdh, UT_DMatrix4 *xform, const SIM_Time &t) const override
GLdouble GLdouble GLdouble y2
void init(float max=1E18f, float min=0.0f, GU_RayFindType type=GU_FIND_CLOSEST, float tolerance=1e-1F, int ignoretrims=1, int usealgebraic=0)
SYS_FORCE_INLINE void setTypeInfo(GA_TypeInfo type)
#define SNOW_NAME_DIVISIONS
SYS_FORCE_INLINE const GA_Attribute * findPointAttribute(GA_AttributeScope s, const UT_StringRef &name) const
constexpr SYS_FORCE_INLINE T & y() noexcept
#define SIM_NAME_ORIGINALDEPTH
PRM_API PRM_Default PRMzeroDefaults[]
bool isValidIndex(int x, int y, int z) const
Returns true if the given x, y, z values lie inside the valid index.
SIM_Random * createRandomData(SIM_Object *obj) const
#define SIM_DATA_CREATE(Parent, DataName, DataClass, Flags)
const GU_Detail * getGdp() const
UT_Array< GU_RayInfoHit > * myHitList
SYS_FORCE_INLINE void multiply3(const UT_Matrix4T< S > &mat)
void pretranslate(T dx, T dy, T dz=0)
SYS_API fpreal32 SYSceil(fpreal32 val)
static GEO_PrimPoly * build(GA_Detail *gdp, GA_Size nvertices, bool open=false, bool appendpts=true)
constexpr SYS_FORCE_INLINE T & x() noexcept