HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
euclid/SOP_Euclid.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.
*
*----------------------------------------------------------------------------
* Defines sops that attach euclidean expressions to gdps.
*/
#include "SOP_Euclid.h"
#include <GU/GU_Detail.h>
#include <OP/OP_Operator.h>
#include "EUC_Expression.C"
#include "EUC_Object.C"
using namespace HDK_Sample;
void
{
table->addOperator(new OP_Operator("euclidpoint",
"x Point",
0,
0,
0,
table->addOperator(new OP_Operator("euclidpointfromobject",
"x Point From Object",
1,
1,
0));
table->addOperator(new OP_Operator("euclidlinefrompoints",
"x Line From Points",
2,
2,
0));
table->addOperator(new OP_Operator("euclidcirclefrompoints",
"x Circle From Points",
2,
2,
0));
table->addOperator(new OP_Operator("euclidintersect",
"x Intersect",
2,
2,
0));
table->addOperator(new OP_Operator("euclidselect",
"x Select",
1,
1,
0));
}
static PRM_Name names[] =
{
PRM_Name("index", "Index"),
PRM_Name("hide", "Hide"),
PRM_Name("color", "Color"),
};
//
// SOP_Euclid
//
: SOP_Node(net, name, op)
, myExpression(NULL)
{
// This SOP always generates fresh geometry, so setting this flag
// is a bit redundant, but one could change it to check for the old
// attribute and only bump its data ID if the value changed.
mySopFlags.setManagesDataIDs(true);
}
SOP_EuclidBase::~SOP_EuclidBase()
{
}
{
const GU_Detail *igdp = inputGeo(idx);
GA_ROHandleI attrib(igdp->findIntTuple(GA_ATTRIB_GLOBAL, "euclid", 1));
if (attrib.isInvalid())
return 0;
// NOTE: The detail is *always* at GA_Offset(0)
int euc = attrib.get(GA_Offset(0));
return expr;
}
{
fpreal now = context.getTime();
// We must lock our inputs before we try to access their geometry.
// OP_AutoLockInputs will automatically unlock our inputs when we return.
// NOTE: Don't call unlockInputs yourself when using this!
OP_AutoLockInputs inputs(this);
if (inputs.lock(context) >= UT_ERROR_ABORT)
return error();
// Reset our old expression
// Get the new expression.
{
UT_Vector3 cd(CR(now), CG(now), CB(now));
myExpression->setLook(!HIDE(now), cd);
}
// Add to our gdp the signifier.
// NOTE: This will bump the data IDs for P and the topology attributes.
// NOTE: This attribute will have a new data ID, because there's no
// previous attribute that it might reuse in this case.
// NOTE: The detail is *always* at GA_Offset(0)
attrib.set(GA_Offset(0), myExpression->getUid());
else
attrib.set(GA_Offset(0), -1);
return error();
}
//
// SOP_EuclidPoint
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
};
SOP_EuclidPoint::SOP_EuclidPoint(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
{
}
SOP_EuclidPoint::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidPoint(net, name, op);
}
{
pt.x() = TX(context.getTime());
pt.y() = TY(context.getTime());
EUC_Expression *expr = new EUC_ExprPoint(pt);
return expr;
}
//
// SOP_EuclidPointFromObject
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
PRM_Template(PRM_INT_J, 1, &names[0]),
};
{
}
SOP_EuclidPointFromObject::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidPointFromObject(net, name, op);
}
{
int idx = IDX(context.getTime());
if (!expr)
return 0;
expr = new EUC_ExprPointFromObject(expr, idx);
return expr;
}
//
// SOP_EuclidLineFromPoints
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
};
{
}
SOP_EuclidLineFromPoints::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidLineFromPoints(net, name, op);
}
{
if (!expr1)
return 0;
if (!expr2)
return 0;
return new EUC_ExprLineFromPoints(expr1, expr2);
}
//
// SOP_EuclidCircleFromPoints
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
};
{
}
SOP_EuclidCircleFromPoints::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidCircleFromPoints(net, name, op);
}
{
if (!expr1)
return 0;
if (!expr2)
return 0;
return new EUC_ExprCircleFromPoints(expr1, expr2);
}
//
// SOP_EuclidIntersect
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
};
{
}
SOP_EuclidIntersect::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidIntersect(net, name, op);
}
{
if (!expr1)
return 0;
if (!expr2)
return 0;
return new EUC_ExprIntersect(expr1, expr2);
}
//
// SOP_EuclidSelect
//
PRM_Template(PRM_TOGGLE, 1, &names[1]),
PRM_Template(PRM_INT_J, 1, &names[0]),
};
SOP_EuclidSelect::SOP_EuclidSelect(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
{
}
SOP_EuclidSelect::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_EuclidSelect(net, name, op);
}
{
int idx = IDX(context.getTime());
if (!expr)
return 0;
expr = new EUC_ExprSelect(expr, idx);
return expr;
}