//
系统及版本声明
#define
VERSION 10.0.554
#define
I386
#define
WIN32
#define
SWAP_BITFIELDS
#define
DLLEXPORT __declspec(dllexport)
#define
SESI_LITTLE_ENDIAN
#define
MAKING_DSO
//
头文件声明
#include
<
UT
/
UT_DSOVersion.h
>
#include
<
UT
/
UT_Interrupt.h
>
#include
<
GU
/
GU_PrimPoly.h
>
#include
<
CH
/
CH_LocalVariable.h
>
#include
<
PRM
/
PRM_Include.h
>
#include
<
OP
/
OP_Operator.h
>
#include
<
OP
/
OP_OperatorTable.h
>
#include
<
SOP
/
SOP_Node.h
>
//
头文件定义
namespace
HDK_Sample{
class
SOP_Star:
public
SOP_Node
{
public
:
static
OP_Node
*
myConstructor(OP_Network
*
,
const
char
*
, OP_Operator
*
);
static
PRM_Template myTemplateList[];
static
CH_LocalVariable myVariables[];
protected
:
SOP_Star(OP_Network
*
net,
const
char
*
name,OP_Operator
*
op);
virtual
~
SOP_Star();
virtual
unsigned disableParms();
virtual
OP_ERROR cookMySop(OP_Context
&
context);
virtual
float
getVariableValue(
int
index,
int
thread);
private
:
int
DIVISIONS(
float
t) {
return
evalInt (
"
divs
"
,
0
,t);}
float
XRADIUS(
float
t) {
return
evalFloat (
"
rad
"
,
0
,t);}
float
YRADIUS(
float
t) {
return
evalFloat (
"
rad
"
,
1
,t);}
int
NEGRADIUS() {
return
evalInt (
"
nradius
"
,
0
,
0
);}
float
CENTERX(
float
t) {
return
evalFloat (
"
t
"
,
0
,t);}
float
CENTERY(
float
t) {
return
evalFloat (
"
t
"
,
1
,t);}
float
CENTERZ(
float
t) {
return
evalFloat (
"
t
"
,
2
,t);}
int
ORIENT() {
return
evalInt (
"
orient
"
,
0
,
0
);}
int
myCurrPoint;
int
myTotalPoints;
};
}
using
namespace
HDK_Sample;
//
消息钩子
void
newSopOperator(OP_OperatorTable
*
table)
{
table
->
addOperator(
new
OP_Operator(
"
hdk_star
"
,
"
Star
"
,
SOP_Star::myConstructor,
SOP_Star::myTemplateList,
0
,
0
,
SOP_Star::myVariables,
OP_FLAG_GENERATOR
)
);
}
//
参数定义
static
PRM_Name negativeName(
"
nradius
"
,
"
Negative Radius
"
);
static
PRM_Default fiveDefault(
5
);
static
PRM_Default radiDefaults[]
=
{
PRM_Default(
1
),
PRM_Default(
0.3
)
};
PRM_Template
SOP_Star::myTemplateList[]
=
{
PRM_Template(PRM_INT_J,
1
,
&
PRMdivName,
&
fiveDefault,
0
,
&
PRMdivision2Range),
PRM_Template(PRM_XYZ_J,
2
,
&
PRMradiusName,radiDefaults),
PRM_Template(PRM_TOGGLE,
1
,
&
negativeName),
PRM_Template(PRM_XYZ_J,
3
,
&
PRMcenterName),
PRM_Template(PRM_ORD,
1
,
&
PRMorientName,
0
,
&
PRMplaneMenu),
PRM_Template()
};
//
定义局部变量
enum
{ VAR_PT,VAR_NPT};
CH_LocalVariable
SOP_Star::myVariables[]
=
{
{
"
PT
"
, VAR_PT,
0
},
{
"
NPT
"
, VAR_NPT,
0
},
{
0
,
0
,
0
},
};
float
SOP_Star::getVariableValue(
int
index,
int
thread)
{
if
(myCurrPoint
<
0
)
return
0
;
switch
(index)
{
case
VAR_PT:
return
myCurrPoint;
case
VAR_NPT:
return
myTotalPoints;
}
return
SOP_Node::getVariableValue(index,thread);
}
//
节点构造
OP_Node
*
SOP_Star::myConstructor(OP_Network
*
net,
const
char
*
name, OP_Operator
*
op)
{
return
new
SOP_Star(net,name,op);
}
//
功能函数构造
SOP_Star::SOP_Star(OP_Network
*
net,
const
char
*
name,OP_Operator
*
op):SOP_Node(net,name,op)
{
myCurrPoint
=
-
1
;
}
//
功能函数析构
SOP_Star::
~
SOP_Star(){}
unsigned
SOP_Star::disableParms(){
return
0
;}
//
制作
OP_ERROR
SOP_Star::cookMySop(OP_Context
&
context)
{
float
now;
float
rad,tx,ty,tz;
int
divisions,plane,negradius;
int
xcoord,ycoord,zcoord;
float
tmp,tinc;
GEO_Point
*
ppt;
GU_PrimPoly
*
poly;
int
i;
UT_Interrupt
*
boss;
now
=
context.myTime;
divisions
=
DIVISIONS(now)
*
2
;
myTotalPoints
=
divisions;
myCurrPoint
=
0
;
plane
=
ORIENT();
negradius
=
NEGRADIUS();
tx
=
CENTERX(now);
ty
=
CENTERY(now);
tz
=
CENTERZ(now);
switch
(plane)
{
case
0
:
xcoord
=
0
;
ycoord
=
1
;
zcoord
=
2
;
break
;
case
1
:
xcoord
=
1
;
ycoord
=
2
;
zcoord
=
0
;
break
;
case
2
:
xcoord
=
0
;
ycoord
=
2
;
zcoord
=
1
;
break
;
}
if
(error()
<
UT_ERROR_ABORT)
{
boss
=
UTgetInterrupt();
if
(divisions
<
4
)
{
addWarning(SOP_MESSAGE,
"
Invalid divisions
"
);
divisions
=
4
;
}
gdp
->
clearAndDestroy();
boss
->
opStart(
"
Building Star
"
);
poly
=
GU_PrimPoly::build(gdp,divisions,GU_POLY_CLOSED);
tinc
=
M_PI
*
2
/
(
float
)divisions;
for
(i
=
0
;i
<
divisions;i
++
)
{
if
(boss
->
opInterrupt())
break
;
myCurrPoint
=
i;
tmp
=
(
float
)i
*
tinc;
rad
=
(i
&
1
)
?
XRADIUS(now) :YRADIUS(now);
if
(
!
negradius
&&
rad
<
0
)
rad
=
0
;
ppt
=
poly
->
getVertex(i).getPt();
ppt
->
getPos()(xcoord)
=
cos(tmp)
*
rad
+
tx;
ppt
->
getPos()(ycoord)
=
sin(tmp)
*
rad
+
ty;
ppt
->
getPos()(zcoord)
=
0
+
tz;
}
select(GU_SPrimitive);
boss
->
opEnd();
}
myCurrPoint
=
-
1
;
return
error();
}