#include <stdlib.h>
using namespace HDK_Sample;
void
{
"hdk_bouncyagent",
"BouncyAgent",
1,
1
);
}
{
}
static PRM_Name sopAgentName(
"agentname",
"Agent Name");
static PRM_Name sopHeight(
"height",
"Height");
static PRM_Name sopClipLength(
"cliplength",
"Clip Length");
static PRM_Name sopClipOffset(
"clipoffset",
"Clip Offset");
static PRM_Name sopEnableBlendshapes(
"enableblendshapes",
"Enable Blendshapes");
static PRM_Name sopReload(
"reload",
"Reload");
{
0, &sopClipOffsetRange),
&SOP_BouncyAgent::onReload),
};
{
mySopFlags.setManagesDataIDs(true);
}
SOP_BouncyAgent::~SOP_BouncyAgent()
{
}
enum
{
};
sopCreateRig(
const char *
path,
bool enable_blendshapes)
{
rig_name += "?rig";
if (!rig->construct(transforms, child_counts, children))
return nullptr;
if (enable_blendshapes)
{
channels.
append(theChannel1Name.asHolder());
channels.
append(theChannel2Name.asHolder());
if (!rig->addChannels(channels, default_values, transforms, errors))
return nullptr;
}
return rig;
}
sopCreateSphere(bool for_default)
{
if (for_default)
{
sphere.freq = 2;
}
else
{
sphere.xform.scale(1.5, 1, 1.5);
sphere.xform.translate(0, 1, 0.5);
}
return shape;
}
static void
{
channel_name);
xform.scale(1.5);
{
id_attrib.
set(ptoff, src_idx);
}
}
static void
{
sopAddBlendshapeInput(*base_shape_gdp, 3, theChannel1Name.asRef(), shape1,
shape1_name);
sopAddBlendshapeInput(*base_shape_gdp, 4, theChannel2Name.asRef(), shape2,
shape2_name);
shape_names.
append(shape1_name);
shape_names.
append(shape2_name);
channel_names.
append(theChannel1Name.asHolder());
channel_names.
append(theChannel2Name.asHolder());
channel_names);
}
static void
{
int regions_i = -1;
capt, regions_i);
for (int i = 0; i < num_regions; ++i)
for (int i = 0; i < num_regions; ++i)
{
if (i == 0)
else
}
{
for (int i = 0; i < num_regions; ++i)
{
fpreal weight = 1.0/num_regions;
weights->
setData(capt, ptoff, i, weight);
}
}
}
#define SOP_DEFAULT_SKIN_NAME GU_AGENT_LAYER_DEFAULT".skin"
#define SOP_COLLISION_SKIN_NAME GU_AGENT_LAYER_COLLISION".skin"
sopCreateShapeLib(
const char *path,
const GU_AgentRig &rig,
bool enable_blendshapes)
{
shapelib_name += "?shapelib";
sopAddSkinWeights(rig, skin_geo);
if (enable_blendshapes)
sopAddBlendshapes(rig, *shapelib, skin_geo);
return shapelib;
}
sopCreateDefaultLayer(
const char *path,
bool enable_blendshapes)
{
if (enable_blendshapes)
else
unique_name += "?default_layer";
if (!layer->construct(
shape_names, transform_indices, deformers, bounds_scales))
{
return nullptr;
}
layer->setName(layer_name);
}
sopCreateCollisionLayer(
const char *path,
{
unique_name += "?collision_layer";
if (!layer->construct(
shape_names, transform_indices, deformers, bounds_scales))
{
return nullptr;
}
layer->setName(layer_name);
}
{
}
bool enable_blendshapes)
{
for (int i = 0; i < num_samples; ++i)
{
ty[i] = height * SYSsin(i *
M_PI / (num_samples-1));
sy[i] = 1.0 -
SYSabs(0.5 * SYSsin(i *
M_PI / (num_samples-1)));
}
for (int i = 0; i < num_samples; ++i)
{
ty[i] = 2.0;
tz[i] = 1.5 * SYSsin(i *
M_PI / (num_samples-1));
}
if (enable_blendshapes)
{
fpreal *chan1 = chans.
addTrack(theChannel1Name.asHolder())->getData();
fpreal *chan2 = chans.
addTrack(theChannel2Name.asHolder())->getData();
for (int i = 0; i < num_samples; ++i)
{
chan1[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples +
M_PI);
chan2[i] = 0.5 + 0.5 * SYScos(i * 2 *
M_PI / num_samples);
}
}
if (!clip)
return nullptr;
clip->load(chans);
}
static constexpr
UT_StringLit theCustomDataItemType(
"bouncyagentdata");
{
public:
{
}
{
return UTmakeIntrusive<GU_BouncyAgentCustomData>();
}
{
return theCustomDataItemType.asHolder();
}
int64 getMemoryUsage(
bool inclusive)
const override
{
int64 mem = inclusive ?
sizeof(*this) : 0;
return mem;
}
int value()
const {
return myValue; }
{
{
return false;
if (key == theValueToken.asHolder())
{
return false;
}
else if (key == theNameToken.asHolder())
{
return false;
}
else
{
return false;
}
}
return true;
}
{
bool ok = true;
ok = ok && w.
jsonKey(theNameToken.asHolder());
ok = ok && w.
jsonKey(theValueToken.asHolder());
return ok;
}
private:
};
void
{
}
#define SOP_SAVE_AGENT_DEFINITION 0
SOP_BouncyAgent::createDefinition(
fpreal t)
const
{
const bool enable_blendshapes = BLENDSHAPES(t);
if (!rig)
return nullptr;
sopCreateShapeLib(path, *rig, enable_blendshapes);
if (!shapelib)
return nullptr;
sopCreateDefaultLayer(path, rig, shapelib, enable_blendshapes);
if (!default_layer)
return nullptr;
rig, shapelib);
if (!collision_layer)
return nullptr;
sopCreateBounceClip(chans, rig, HEIGHT(t), enable_blendshapes);
if (!clip)
return nullptr;
#if SOP_SAVE_AGENT_DEFINITION
{
rig->save(writer);
}
{
shapelib->save(writer);
}
{
default_layer->save(writer);
}
{
collision_layer->save(writer);
}
{
chans.
save(
"bouncy_bounce.bclip");
}
#endif
auto def = UTmakeIntrusive<GU_AgentDefinition>(rig, shapelib);
def->addLayer(default_layer);
def->addLayer(collision_layer);
def->addClip(clip);
def->addCustomDataItem(
UTmakeIntrusive<GU_BouncyAgentCustomData>("mycustomdata", 42));
def->sortItemsIfNeeded();
return def;
}
int
SOP_BouncyAgent::onReload(
{
{
sop->
myDefinition.reset();
}
return 1;
}
{
int input_changed;
bool agent_changed =
isParmDirty(sopAgentName.getToken(),
t);
agent_changed |=
isParmDirty(sopEnableBlendshapes.getToken(),
t);
if (!myDefinition)
{
agent_changed = true;
input_changed = true;
}
if (agent_changed)
{
myDefinition = createDefinition(t);
if (!myDefinition)
{
}
}
if (input_changed)
{
{
}
}
if (agent_changed || input_changed)
{
"name", 1));
AGENTNAME(agent_name, t);
int name_i = 0;
{
clips.
append(myDefinition->clip(0).name());
name_attrib.set(pack->getMapOffset(), name.
buffer());
++name_i;
}
name_attrib.bumpDataId();
}
{
}
}
const char *
{
return "Points to attach agents";
}