1717#include < openvdb/tools/Morphology.h> // for tools::dilateActiveValues(), tools::erodeActiveValues()
1818#include < openvdb/points/PointDataGrid.h>
1919#include < OBJ/OBJ_Camera.h>
20+ #include < UT/UT_Version.h>
2021#include < cmath> // for std::abs(), std::round()
2122#include < exception>
2223#include < string>
@@ -35,7 +36,11 @@ class SOP_OpenVDB_Clip: public hvdb::SOP_NodeVDB
3536
3637 static OP_Node* factory (OP_Network*, const char * name, OP_Operator*);
3738
38- int isRefInput (unsigned input) const override { return (input == 1 ); }
39+ int isRefInput (OP_InputIdx input) const override
40+ {
41+ UT_ASSERT (input >= 0 );
42+ return (input == 1 );
43+ }
3944
4045 class Cache : public SOP_VDBCacheOptions
4146 {
@@ -109,7 +114,11 @@ Mask VDB:\n\
109114
110115 parms.add (hutil::ParmFactory (PRM_STRING, " camera" , " Camera" )
111116 .setTypeExtended (PRM_TYPE_DYNAMIC_PATH)
117+ #if SYS_VERSION_MAJOR_INT >= 21
118+ .setSpareData (&PRM_SpareData::anyCameraPath)
119+ #else
112120 .setSpareData (&PRM_SpareData::objCameraPath)
121+ #endif
113122 .setTooltip (" Specify the path to a reference camera" )
114123 .setDocumentation (
115124 " The path to the camera whose frustum is to be used as a clipping region"
@@ -430,11 +439,32 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
430439 const auto time = context.getTime ();
431440
432441 UT_String cameraPath;
442+ OBJ_CameraParms cameraParms;
433443 evalString (cameraPath, " camera" , 0 , time);
434444 if (!cameraPath.isstring ()) {
435445 throw std::runtime_error{" no camera path was specified" };
436446 }
437447
448+ #if SYS_VERSION_MAJOR_INT >= 21
449+ UT_Matrix4D cameratosop;
450+ OBJ_Node *meobj = cookparms ()->getNode ()
451+ ? cookparms ()->getNode ()->getCreator ()->castToOBJNode ()
452+ : nullptr ;
453+ UT_StringHolder errstr;
454+
455+ OP_Node::getCameraInfoAndRelativeTransform (
456+ cameraPath,
457+ meobj ? meobj->getFullPath () : UT_StringHolder::theEmptyString,
458+ cookparms ()->getCwd (),
459+ false , // get_inverse_xform
460+ context,
461+ cookparms ()->depnode (),
462+ cameraParms,
463+ cameratosop,
464+ errstr);
465+ if (errstr.isstring ())
466+ throw std::runtime_error{" camera \" " + cameraPath.toStdString () + " \" was not found" };
467+ #else
438468 OBJ_Camera* camera = nullptr ;
439469 if (auto * obj = cookparms ()->getCwd ()->findOBJNode (cameraPath)) {
440470 camera = obj->castToOBJCamera ();
@@ -446,8 +476,9 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
446476 }
447477 self->addExtraInput (camera, OP_INTEREST_DATA);
448478
449- OBJ_CameraParms cameraParms;
450479 camera->getCameraParms (cameraParms, time);
480+ #endif
481+
451482 if (cameraParms.projection != OBJ_PROJ_PERSPECTIVE) {
452483 throw std::runtime_error{cameraPath.toStdString () + " is not a perspective camera" };
453484 // / @todo support ortho and other cameras?
@@ -458,13 +489,18 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
458489
459490 const float nearPlane = (evalInt (" setnear" , 0 , time)
460491 ? static_cast <float >(evalFloat (" near" , 0 , time))
461- : static_cast <float >(camera-> getNEAR (time) )) - padding[2 ];
492+ : static_cast <float >(cameraParms. mynear )) - padding[2 ];
462493 const float farPlane = (evalInt (" setfar" , 0 , time)
463494 ? static_cast <float >(evalFloat (" far" , 0 , time))
464- : static_cast <float >(camera-> getFAR (time) )) + padding[2 ];
495+ : static_cast <float >(cameraParms. myfar )) + padding[2 ];
465496
497+ #if SYS_VERSION_MAJOR_INT >= 21
498+ mFrustum = hvdb::frustumTransformFromCamera (cameraParms, cameratosop,
499+ /* offset=*/ 0 .f , nearPlane, farPlane, /* voxelDepth=*/ 1 .f , /* voxelCountX=*/ 100 );
500+ #else
466501 mFrustum = hvdb::frustumTransformFromCamera (*self, context, *camera,
467502 /* offset=*/ 0 .f , nearPlane, farPlane, /* voxelDepth=*/ 1 .f , /* voxelCountX=*/ 100 );
503+ #endif
468504
469505 if (!mFrustum || !mFrustum ->constMap <openvdb::math::NonlinearFrustumMap>()) {
470506 throw std::runtime_error{
0 commit comments