00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <UT/UT_DSOVersion.h>
00030 #include <GEO/GEO_PointRef.h>
00031 #include <GU/GU_Detail.h>
00032 #include <PRM/PRM_Include.h>
00033 #include <OP/OP_Operator.h>
00034 #include <OP/OP_OperatorTable.h>
00035 #include "SOP_DetailAttrib.h"
00036
00037 using namespace HDK_Sample;
00038 void
00039 newSopOperator(OP_OperatorTable *table)
00040 {
00041 table->addOperator(new OP_Operator("hdk_detailattrib",
00042 "DetailAttrib",
00043 SOP_DetailAttrib::myConstructor,
00044 SOP_DetailAttrib::myTemplateList,
00045 1,
00046 1));
00047 }
00048
00049
00050 static PRM_Name sop_names[] = {
00051 PRM_Name("attribname", "Attribute"),
00052 PRM_Name("value", "Value"),
00053 };
00054
00055 static PRM_Default sop_valueDefault(0.1);
00056 static PRM_Range sop_valueRange(PRM_RANGE_RESTRICTED,0,PRM_RANGE_UI,1);
00057
00058 PRM_Template
00059 SOP_DetailAttrib::myTemplateList[]=
00060 {
00061 PRM_Template(PRM_STRING, 1, &sop_names[0], 0),
00062 PRM_Template(PRM_FLT_J, 1, &sop_names[1], &sop_valueDefault, 0,
00063 &sop_valueRange),
00064 PRM_Template()
00065 };
00066
00067
00068 OP_Node *
00069 SOP_DetailAttrib::myConstructor(OP_Network *net,const char *name,OP_Operator *entry)
00070 {
00071 return new SOP_DetailAttrib(net, name, entry);
00072 }
00073
00074
00075 SOP_DetailAttrib::SOP_DetailAttrib(OP_Network *net, const char *name, OP_Operator *entry)
00076 : SOP_Node(net, name, entry)
00077 {
00078 }
00079
00080 SOP_DetailAttrib::~SOP_DetailAttrib()
00081 {
00082 }
00083
00084
00085 unsigned
00086 SOP_DetailAttrib::disableParms()
00087 {
00088 int changed = 0;
00089
00090 return changed;
00091 }
00092
00093
00094 OP_ERROR
00095 SOP_DetailAttrib::cookMySop(OP_Context &context)
00096 {
00097 double t = context.getTime();
00098 UT_String aname;
00099 GB_AttributeRef aoff;
00100 int asize;
00101 GB_AttribType atype;
00102 GB_Attribute *attrib;
00103 static float zero = 0.0;
00104 float *detailattrib;
00105
00106 if (lockInputs(context) >= UT_ERROR_ABORT)
00107 return error();
00108
00109 duplicateSource(0, context);
00110
00111 ATTRIBNAME(aname, t);
00112
00113
00114 atype = GB_ATTRIB_FLOAT;
00115 attrib = gdp->attribs().find(aname, atype);
00116
00117 if (!attrib)
00118 {
00119
00120 gdp->addAttrib(aname, sizeof(float), GB_ATTRIB_FLOAT, &zero);
00121 attrib = gdp->attribs().find(aname, atype);
00122 }
00123
00124 asize = attrib->getSize();
00125 aoff = gdp->attribs().getOffset(aname, atype);
00126
00127
00128 gdp->attribs().getElement().setValue<float>(aoff, VALUE(t));
00129
00130 unlockInputs();
00131 return error();
00132 }
00133