HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LOP/LOP_Sphere.C
/*
* Copyright (c) 2024
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*----------------------------------------------------------------------------
* The Surface SOP. This SOP Surfaces the volume into polygons.
*/
// Disable TBB warnings about atomics
#define __TBB_show_deprecation_message_atomic_H
#define __TBB_show_deprecation_message_task_H
#include "LOP_Sphere.h"
#include <LOP/LOP_Error.h>
#include <HUSD/XUSD_Data.h>
#include <OP/OP_Operator.h>
using namespace HDK_Sample;
void
{
"hdk_sphere",
"Sphere",
LOP_Sphere::myConstructor,
LOP_Sphere::myTemplateList,
(unsigned)0,
(unsigned)1));
}
static PRM_Name theRadiusName("radius", "Radius");
LOP_Sphere::myTemplateList[] = {
PRM_Template(PRM_FLT, 1, &theRadiusName, PRMoneDefaults),
};
LOP_Sphere::myConstructor(OP_Network *net, const char *name,
{
return new LOP_Sphere(net, name, op);
}
LOP_Sphere::LOP_Sphere(OP_Network *net, const char *name, OP_Operator *op)
: LOP_Node(net, name, op)
{
}
LOP_Sphere::~LOP_Sphere()
{
}
void
LOP_Sphere::PRIMPATH(UT_String &str, fpreal t)
{
evalString(str, lopPrimPathName, 0, t);
}
LOP_Sphere::RADIUS(fpreal t)
{
return evalFloat(theRadiusName, 0, t);
}
LOP_Sphere::cookMyLop(OP_Context &context)
{
// Cook the node connected to our input, and make a "soft copy" of the
// result into our own HUSD_DataHandle.
if (cookModifyInput(context) >= UT_ERROR_FATAL)
return error();
UT_String primpath;
fpreal radius;
PRIMPATH(primpath, context.getTime());
radius = RADIUS(context.getTime());
// Use editableDataHandle to get non-const access to our data handle, and
// the lock it for writing. This makes sure that the USD stage is set up
// to match the configuration defined in our data handle. Any edits made
// to the stage at this point will be preserved in our data handle when
// we unlock it.
HUSD_AutoWriteLock writelock(editableDataHandle());
HUSD_AutoLayerLock layerlock(writelock);
// Create a helper class for creating USD primitives on the stage.
HUSD_CreatePrims creator(layerlock);
// Use the helper class to create a new "Sphere" primitive, with a
// specifier type of "def" to define this primitive even if it doesn't
// exist on the stage yet.
//
// The "empty string" parameter to createPrim tells it to not author a
// "kind" setting for this primiitve.
if (!creator.createPrim(primpath, "UsdGeomSphere",
{
addError(LOP_PRIM_NOT_CREATED, primpath);
return error();
}
// Use direct editing of the USD stage to modify the radius attribute
// of the new sphere primitive. We could use the HUSD_SetAttributes
// helper class here, but this demonstrates that we are allowed to
// access the stage directly. The edit target will already be set to
// the "active layer", and as long as we leave it there, any changes
// we make will be preserved by our data handle.
UsdStageRefPtr stage = writelock.data()->stage();
SdfPath sdfpath(HUSDgetSdfPath(primpath));
UsdPrim prim = stage->GetPrimAtPath(sdfpath);
if (prim)
prim.GetAttribute(UsdGeomTokens->radius).Set(radius);
setLastModifiedPrims(primpath);
return error();
}