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);
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)
419 if (enable_blendshapes)
425 unique_name +=
"?default_layer";
428 if (!layer->construct(shape_names, transform_indices, deformers))
432 layer->setName(layer_name);
439 sopCreateCollisionLayer(
455 unique_name +=
"?collision_layer";
458 if (!layer->construct(shape_names, transform_indices, deforming))
462 layer->setName(layer_name);
478 bool enable_blendshapes)
489 for (
int i = 0; i < num_samples; ++i)
491 ty[i] = height * SYSsin(i *
M_PI / (num_samples-1));
493 sy[i] = 1.0 -
SYSabs(0.5 * SYSsin(i *
M_PI / (num_samples-1)));
500 for (
int i = 0; i < num_samples; ++i)
503 tz[i] = 1.5 * SYSsin(i *
M_PI / (num_samples-1));
507 if (enable_blendshapes)
512 for (
int i = 0; i < num_samples; ++i)
514 chan1[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples +
M_PI);
515 chan2[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples);
528 static constexpr
UT_StringLit theCustomDataItemType(
"bouncyagentdata");
551 return theCustomDataItemType.
asHolder();
556 int64 mem = inclusive ?
sizeof(*this) : 0;
557 mem += myName.getMemoryUsage(
false);
562 int value()
const {
return myValue; }
575 if (key == theValueToken.
asHolder())
580 else if (key == theNameToken.
asHolder())
626 #define SOP_SAVE_AGENT_DEFINITION 0
630 SOP_BouncyAgent::createDefinition(
fpreal t)
const
638 const bool enable_blendshapes = BLENDSHAPES(t);
645 sopCreateShapeLib(path, *rig, enable_blendshapes);
650 sopCreateDefaultLayer(path, rig, shapelib, enable_blendshapes);
656 if (!collision_layer)
662 sopCreateBounceClip(chans, rig, HEIGHT(t), enable_blendshapes);
666 #if SOP_SAVE_AGENT_DEFINITION
675 shapelib->save(writer);
679 default_layer->save(writer);
683 collision_layer->save(writer);
686 chans.
save(
"bouncy_bounce.bclip");
694 def->addLayer(default_layer);
695 def->addLayer(collision_layer);
706 SOP_BouncyAgent::onReload(
712 sop->myDefinition.reset();
746 agent_changed =
true;
747 input_changed =
true;
752 myDefinition = createDefinition(t);
779 if (agent_changed || input_changed)
793 AGENTNAME(agent_name, t);
805 clips.
append(myDefinition->clip(0).name());
811 name_attrib.set(pack->getMapOffset(), name.
buffer());
817 name_attrib.bumpDataId();
837 return "Points to attach agents";
CL_Track * addTrack(const UT_StringHolder &name)
bool jsonValue(bool value)
SYS_FORCE_INLINE void setPos3(GA_Offset ptoff, const UT_Vector3 &P)
Set P from a UT_Vector3.
PRM_API PRM_Default PRMzeroDefaults[]
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.
GLuint const GLchar * name
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
GLuint GLuint GLfloat weight
static GU_AgentCustomDataItemPtr construct(const GU_AgentDefinition &)
GLenum GLsizei GLenum GLenum const void * table
void setClipsByNames(GU_PrimPacked *prim, const UT_StringArray &clip_names)
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
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
PRM_API PRM_Default PRMoneDefaults[]
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)
void setDefinition(GU_PrimPacked *prim, const GU_AgentDefinitionPtr &definition)
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.
static GEO_Primitive * build(const GU_PrimSphereParms &parms, GA_PrimitiveTypeId type=GEO_PRIMSPHERE)
void allocateAndSet(GU_Detail *gdp, bool own=true)
void setCurrentLayer(GU_PrimPacked *prim, const GU_AgentLayerConstPtr &layer)
Sets the agent's display layer.
bool parseInt(int64 &v)
Alternate short-form.
const char * buffer() const
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.
GLint GLenum GLsizei GLint GLsizei const void * data
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.
GLubyte GLubyte GLubyte GLubyte w
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
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.
void setManagesDataIDs(bool onOff)
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.
GLsizei const GLchar *const * path
SYS_FORCE_INLINE const UT_StringRef & asRef() const
static GU_AgentClipPtr addClip(const UT_StringHolder &name, const GU_AgentRigConstPtr &rig)
Create an empty clip.
void setSampleRate(fpreal rate)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
SOP_BouncyAgent(OP_Network *net, const char *name, OP_Operator *op)
virtual bool setEntries(GA_Attribute *attrib, int n) const =0
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)
GLdouble GLdouble GLdouble r
SYS_FORCE_INLINE const UT_StringHolder & asHolder() const
GLint GLboolean GLint layer
PRM_API PRM_Range PRMrulerRange
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)
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.
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)
SYS_FORCE_INLINE GA_Offset pointOffset(GA_Index index) const
Given a point's index (in append order), return its data offset.
GLsizei const GLfloat * value
const UT_StringHolder & dataItemType() const override
void translate(T dx, T dy, T dz=0.0f)
void GU_API addInputsToBaseShape(GU_Detail &base_shape, const UT_StringArray &shape_names, const UT_StringArray &channel_names)
static const int tuple_size
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)
void setCollisionLayer(GU_PrimPacked *prim, const GU_AgentLayerConstPtr &layer)
Sets the agent's collision layer.
const char * getToken() const
GLenum const void * paths
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)