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 <UT/UT_Math.h>
00031 #include <UT/UT_Matrix3.h>
00032 #include <UT/UT_Matrix4.h>
00033 #include <GU/GU_Detail.h>
00034 #include <GU/GU_PrimPoly.h>
00035 #include <PRM/PRM_Include.h>
00036 #include <OP/OP_Operator.h>
00037 #include <OP/OP_OperatorTable.h>
00038 #include <SOP/SOP_Guide.h>
00039 #include "SOP_PointWave.h"
00040
00041 using namespace HDK_Sample;
00042
00043 void
00044 newSopOperator(OP_OperatorTable *table)
00045 {
00046 table->addOperator(new OP_Operator("hdk_pointwave",
00047 "Point Wave",
00048 SOP_PointWave::myConstructor,
00049 SOP_PointWave::myTemplateList,
00050 1,
00051 1,
00052 0));
00053 }
00054
00055 static PRM_Name names[] = {
00056 PRM_Name("amp", "Amplitude"),
00057 PRM_Name("phase", "Phase"),
00058 PRM_Name("period", "Period"),
00059 };
00060
00061 PRM_Template
00062 SOP_PointWave::myTemplateList[] = {
00063 PRM_Template(PRM_STRING, 1, &PRMgroupName, 0, &SOP_Node::pointGroupMenu),
00064 PRM_Template(PRM_FLT_J, 1, &names[0], PRMoneDefaults, 0,
00065 &PRMscaleRange),
00066 PRM_Template(PRM_FLT_J, 1, &names[1], PRMzeroDefaults),
00067 PRM_Template(PRM_FLT_J, 1, &names[2], PRMoneDefaults),
00068 PRM_Template(),
00069 };
00070
00071
00072 OP_Node *
00073 SOP_PointWave::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00074 {
00075 return new SOP_PointWave(net, name, op);
00076 }
00077
00078 SOP_PointWave::SOP_PointWave(OP_Network *net, const char *name, OP_Operator *op)
00079 : SOP_Node(net, name, op), myGroup(0)
00080 {
00081 }
00082
00083 SOP_PointWave::~SOP_PointWave() {}
00084
00085 OP_ERROR
00086 SOP_PointWave::cookInputGroups(OP_Context &context, int alone)
00087 {
00088
00089
00090 return cookInputPointGroups(context, myGroup, myDetailGroupPair, alone);
00091 }
00092
00093 OP_ERROR
00094 SOP_PointWave::cookMySop(OP_Context &context)
00095 {
00096 GEO_Point *ppt;
00097 float t;
00098 float amp, period, phase;
00099
00100
00101
00102 if (lockInputs(context) >= UT_ERROR_ABORT)
00103 return error();
00104
00105 t = context.myTime;
00106
00107
00108
00109
00110 duplicatePointSource(0, context);
00111
00112
00113
00114
00115 phase = PHASE(t);
00116 amp = AMP(t);
00117 period = PERIOD(t);
00118
00119
00120
00121 if (error() < UT_ERROR_ABORT && cookInputGroups(context) < UT_ERROR_ABORT)
00122 {
00123 FOR_ALL_OPT_GROUP_POINTS(gdp, myGroup, ppt)
00124 {
00125 UT_Vector4 p;
00126
00127 p = ppt->getPos();
00128
00129 p.y() += SYSsin( (p.x() / period + phase) * M_PI * 2 ) * amp;
00130
00131 ppt->getPos() = p;
00132 }
00133 }
00134 unlockInputs();
00135
00136 return error();
00137 }