70 using namespace HDK_Sample;
95 static PRM_Name sopAgentName(
"agentname",
"Agent Name");
97 static PRM_Name sopHeight(
"height",
"Height");
99 static PRM_Name sopClipLength(
"cliplength",
"Clip Length");
100 static PRM_Name sopClipOffset(
"clipoffset",
"Clip Offset");
103 static PRM_Name sopEnableBlendshapes(
"enableblendshapes",
104 "Enable Blendshapes");
105 static PRM_Name sopReload(
"reload",
"Reload");
115 0, &sopClipOffsetRange),
118 &SOP_BouncyAgent::onReload),
155 static constexpr
UT_StringLit theChannel1Name(
"channel1");
156 static constexpr
UT_StringLit theChannel2Name(
"channel2");
161 sopCreateRig(
const char *
path,
bool enable_blendshapes)
168 transforms.
append(
"skin");
169 transforms.
append(
"parent");
170 transforms.
append(
"child");
183 if (!rig->construct(transforms, child_counts, children))
187 if (enable_blendshapes)
201 if (!rig->addChannels(channels, default_values, transforms, errors))
209 sopCreateSphere(
bool for_default)
223 sphere.xform.scale(1.5, 1, 1.5);
224 sphere.xform.translate(0, 1, 0.5);
232 sopAddBlendshapeInput(
const GU_Detail &
src,
int increment,
251 for (
GA_Index i = 0; i <
n; ++i, ++ptoff)
253 const GA_Index src_idx = i * increment;
257 id_attrib.
set(ptoff, src_idx);
270 sopAddBlendshapeInput(*base_shape_gdp, 3, theChannel1Name.
asRef(), shape1,
274 sopAddBlendshapeInput(*base_shape_gdp, 4, theChannel2Name.
asRef(), shape2,
277 shapelib.
addShape(shape1_name, shape1);
278 shapelib.
addShape(shape2_name, shape2);
283 shape_names.
append(shape1_name);
284 shape_names.
append(shape2_name);
316 for (
int i = 0; i < num_regions; ++i)
322 for (
int i = 0; i < num_regions; ++i)
342 for (
int i = 0; i < num_regions; ++i)
346 weights->
setIndex(capt, ptoff, i, i);
349 fpreal weight = 1.0/num_regions;
350 weights->
setData(capt, ptoff, i, weight);
356 #define SOP_DEFAULT_SKIN_NAME GU_AGENT_LAYER_DEFAULT".skin"
357 #define SOP_COLLISION_SKIN_NAME GU_AGENT_LAYER_COLLISION".skin"
362 sopCreateShapeLib(
const char *path,
const GU_AgentRig &rig,
363 bool enable_blendshapes)
366 shapelib_name +=
"?shapelib";
371 sopAddSkinWeights(rig, skin_geo);
373 if (enable_blendshapes)
374 sopAddBlendshapes(rig, *shapelib, skin_geo);
401 sopCreateDefaultLayer(
405 bool enable_blendshapes)
420 if (enable_blendshapes)
428 unique_name +=
"?default_layer";
431 if (!layer->construct(
432 shape_names, transform_indices, deformers, bounds_scales))
438 layer->setName(layer_name);
445 sopCreateCollisionLayer(
459 deformers.
append(
nullptr);
463 unique_name +=
"?collision_layer";
466 if (!layer->construct(
467 shape_names, transform_indices, deformers, bounds_scales))
473 layer->setName(layer_name);
489 bool enable_blendshapes)
500 for (
int i = 0; i < num_samples; ++i)
502 ty[i] = height * SYSsin(i *
M_PI / (num_samples-1));
504 sy[i] = 1.0 -
SYSabs(0.5 * SYSsin(i *
M_PI / (num_samples-1)));
511 for (
int i = 0; i < num_samples; ++i)
514 tz[i] = 1.5 * SYSsin(i *
M_PI / (num_samples-1));
518 if (enable_blendshapes)
523 for (
int i = 0; i < num_samples; ++i)
525 chan1[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples +
M_PI);
526 chan2[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples);
539 static constexpr
UT_StringLit theCustomDataItemType(
"bouncyagentdata");
557 return UTmakeIntrusive<GU_BouncyAgentCustomData>();
562 return theCustomDataItemType.
asHolder();
567 int64 mem = inclusive ?
sizeof(*this) : 0;
568 mem += myName.getMemoryUsage(
false);
573 int value()
const {
return myValue; }
586 if (key == theValueToken.
asHolder())
591 else if (key == theNameToken.
asHolder())
637 #define SOP_SAVE_AGENT_DEFINITION 0
641 SOP_BouncyAgent::createDefinition(
fpreal t)
const
649 const bool enable_blendshapes = BLENDSHAPES(t);
656 sopCreateShapeLib(path, *rig, enable_blendshapes);
661 sopCreateDefaultLayer(path, rig, shapelib, enable_blendshapes);
667 if (!collision_layer)
673 sopCreateBounceClip(chans, rig, HEIGHT(t), enable_blendshapes);
677 #if SOP_SAVE_AGENT_DEFINITION
686 shapelib->save(writer);
690 default_layer->save(writer);
694 collision_layer->save(writer);
697 chans.
save(
"bouncy_bounce.bclip");
703 auto def = UTmakeIntrusive<GU_AgentDefinition>(rig, shapelib);
705 def->addLayer(default_layer);
706 def->addLayer(collision_layer);
711 def->addCustomDataItem(
712 UTmakeIntrusive<GU_BouncyAgentCustomData>(
"mycustomdata", 42));
715 def->sortItemsIfNeeded();
721 SOP_BouncyAgent::onReload(
727 sop->myDefinition.reset();
761 agent_changed =
true;
762 input_changed =
true;
767 myDefinition = createDefinition(t);
794 if (agent_changed || input_changed)
810 AGENTNAME(agent_name, t);
822 clips.
append(myDefinition->clip(0).name());
828 name_attrib.set(pack->getMapOffset(), name.
buffer());
834 name_attrib.bumpDataId();
854 return "Points to attach agents";
CL_Track * addTrack(const UT_StringHolder &name)
bool jsonValue(bool value)
const GA_AIFIndexPair * getAIFIndexPair() const
bool parseString(UT_WorkBuffer &v)
PRM_API const PRM_Type PRM_CALLBACK
Generic Attribute Interface class to get/set data as index pairs.
static GU_PrimPacked * agent(GU_Detail &dest, GA_Offset ptoff=GA_INVALID_OFFSET)
Convenience method to create a packed agent primitive.
virtual bool setIndex(GA_Attribute *attrib, GA_Offset ai, int entry, int32 index) const =0
Class which stores the default values for a GA_Attribute.
bool jsonBeginMap()
Begin a map/object dictionary.
#define SOP_COLLISION_SKIN_NAME
SIM_API const UT_StringHolder agent
static GU_AgentCustomDataItemPtr construct(const GU_AgentDefinition &)
GLsizei const GLchar *const * path
void setClipsByNames(GU_PrimPacked *prim, const UT_StringArray &clip_names)
void setCollisionLayers(GU_PrimPacked *prim, const UT_Array< GU_AgentLayerConstPtr > &layers)
Sets the agent's collision layers.
const UT_StringHolder & transformName(exint i) const
Return the name of the given transform.
virtual void forceRecook(bool evensmartcache=true)
SYS_FORCE_INLINE const char * buffer() const
const UT_StringHolder & name() const override
JSON reader class which handles parsing of JSON or bJSON files.
#define SOP_DEFAULT_SKIN_NAME
bool save(UT_JSONWriter &w) const override
Class which writes ASCII or binary JSON streams.
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
Convenience class to store a bone capture region.
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
void GUregisterAgentCustomDataItemType()
Entry point for registering GU_BouncyAgentCustomData.
void addError(int code, const char *msg=0)
GU_BouncyAgentCustomData()
exint GA_Size
Defines the bit width for index and offset types in GA.
GU_BouncyAgentCustomData(const UT_StringHolder &name, int value)
GA_Size destroyPrimitives(const GA_Range &it, bool and_points=false)
OP_ERROR cookMySop(OP_Context &context) override
Method to cook geometry for the SOP.
GLenum GLuint GLint GLint layer
static GEO_Primitive * build(const GU_PrimSphereParms &parms, GA_PrimitiveTypeId type=GEO_PRIMSPHERE)
void allocateAndSet(GU_Detail *gdp, bool own=true)
bool parseInt(int64 &v)
Alternate short-form.
const char * buffer() const
GLint GLsizei GLsizei height
This class provides a way to manage a reference to an attribute permitting Read-Write access...
A rig for the agent primitive.
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
GA_Range getPointRange(const GA_PointGroup *group=0) const
Get a range of all points in the detail.
CH_Manager * CHgetManager()
OP_ERROR duplicateChangedSource(unsigned idx, OP_Context &ctx, int *changed=0, bool force=false)
Only duplicates the source if the source has changed since the last call to this method.
SYS_FORCE_INLINE const char * buffer() const
SYS_FORCE_INLINE GA_Offset appendPointBlock(GA_Size npoints)
Append new points, returning the first offset of the contiguous block.
void bumpDataId()
Use this to mark primitives or their intrinsic data as dirty.
static GU_AgentLayerPtr addLayer(const UT_StringHolder &unique_name, const GU_AgentRigConstPtr &rig, const GU_AgentShapeLibConstPtr &shapelib)
PRM_API const PRM_Type PRM_TOGGLE_J
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
void newSopOperator(OP_OperatorTable *table)
bool skipNextObject()
Simple convenience method to skip the next object in the stream.
GA_AttributeSet & getAttributes()
int save(UT_OStream &os, const CL_ClipPrivateIO *priv=0, bool use_blosc_compresssion=false) const
void appendMultiple(const T &t, exint count)
Wrapper around hboost::intrusive_ptr.
virtual void setObjectValues(int objid, int propid, const fpreal32 *v, int tuple_size)=0
virtual bool setData(GA_Attribute *attrib, GA_Offset ai, int entry, fpreal32 data, int data_component=0) const =0
static GA_AIFIndexPairObjects * getBoneCaptureRegionObjects(const GA_RWAttributeRef &h, int &property_i)
void void addWarning(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
bool jsonKey(const char *value, int64 length=0)
UT_StringHolder getFullPath() const
bool load(UT_JSONParser &p) override
#define GU_AGENT_LAYER_COLLISION
GLuint const GLchar * name
size_t format(const char *fmt, const Args &...args)
Format a string using the same formatting codes as UTformat.
GA_API const UT_StringHolder id
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
PRM_API const PRM_Type PRM_FLT_J
bool parseKey(UT_WorkBuffer &v)
bool addShape(const UT_StringHolder &key, const GU_ConstDetailHandle &gdp, bool replace_existing=true)
Add entire geometry as a shape in the library.
GLenum GLenum GLsizei void * table
void setManagesDataIDs(bool onOff)
PRM_API PRM_Range PRMrulerRange
PRM_API const PRM_Type PRM_ALPHASTRING
static GU_AgentShapeLibPtr addLibrary(const UT_StringHolder &name)
Create a new library using the given name.
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
int64 getMemoryUsage(bool inclusive) const override
The amount of memory used by this item.
UT_Vector3T< fpreal32 > UT_Vector3F
SYS_FORCE_INLINE const UT_StringRef & asRef() const
PRM_API PRM_Default PRMoneDefaults[]
static GU_AgentClipPtr addClip(const UT_StringHolder &name, const GU_AgentRigConstPtr &rig)
Create an empty clip.
void setSampleRate(fpreal rate)
SOP_BouncyAgent(OP_Network *net, const char *name, OP_Operator *op)
SYS_FORCE_INLINE void setPos3(GA_Offset ptoff, const UT_Vector3 &pos)
Set P from a UT_Vector3.
virtual bool setEntries(GA_Attribute *attrib, int n) const =0
void translate(T dx, T dy, T dz=0)
void setDefinition(GU_PrimPacked *prim, const GU_AgentDefinitionConstPtr &definition)
SYS_FORCE_INLINE void set(GA_Offset off, const T &val) const
const char * inputLabel(unsigned input_index) const override
Method to provide input labels.
#define GU_AGENT_LAYER_DEFAULT
void setClipTime(GU_PrimPacked *prim, exint i, fpreal seconds)
SYS_FORCE_INLINE const UT_StringHolder & asHolder() const
static PRM_Template myTemplateList[]
int getTrackLength() const
bool jsonEndMap()
End the object.
const GA_PrimitiveList & getPrimitiveList() const
static GU_AgentRigPtr addRig(const UT_StringHolder &name)
GLubyte GLubyte GLubyte GLubyte w
virtual void setObjectCount(int nobj)=0
void bumpAllDataIds(GA_AttributeOwner owner)
Bumps all data IDs of attributes of the specified owner.
void clear()
Resets list to an empty list.
GA_Range getPrimitiveRange(const GA_PrimitiveGroup *group=0) const
Get a range of all primitives in the detail.
static void registerCustomDataItemType(const UT_StringHolder &dataitemtype, CustomDataItemConstructor constructor)
Register a new custom data item type.
PRM_API PRM_Default PRMzeroDefaults[]
GA_Attribute * addIntTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringHolder &name, int tuple_size, const GA_Defaults &defaults=GA_Defaults(0), const UT_Options *creation_args=0, const GA_AttributeOptions *attribute_options=0, GA_Storage storage=GA_STORE_INT32, const GA_ReuseStrategy &reuse=GA_ReuseStrategy())
GA_Attribute * addPointCaptureAttribute(geo_NPairs n_pairs, CaptureType t=CAPTURE_BONE, GA_Storage s=GA_STORE_INVALID)
Add the (index, weight) point attribute for capture type t.
~SOP_BouncyAgent() override
static GU_AgentShapeDeformerConstPtr getBlendShapeAndSkinDeformer(GU_AgentLinearSkinDeformer::Method skinning_method=GU_AgentLinearSkinDeformer::Method::Linear)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
SYS_FORCE_INLINE GA_Offset pointOffset(GA_Index index) const
Given a point's index (in append order), return its data offset.
const UT_StringHolder & dataItemType() const override
void GU_API addInputsToBaseShape(GU_Detail &base_shape, const UT_StringArray &shape_names, const UT_StringArray &channel_names)
static const int tuple_size
void setCurrentLayers(GU_PrimPacked *prim, const UT_Array< GU_AgentLayerConstPtr > &layers)
Sets the agent's display layers.
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
const char * getToken() const
SYS_FORCE_INLINE GA_Size getNumPoints() const
Return the number of points.
bool isParmDirty(int idx, fpreal t)
GA_Attribute * addStringTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringHolder &name, int tuple_size, const UT_Options *creation_args=0, const GA_AttributeOptions *attribute_options=0, const GA_ReuseStrategy &reuse=GA_ReuseStrategy())
static GU_AgentShapeDeformerConstPtr getLinearSkinDeformer(GU_AgentLinearSkinDeformer::Method method=GU_AgentLinearSkinDeformer::Method::Linear)