学习A——一个简单的小球。

代码
#include <GU/GU_Detail.h>
static float
densityFunction(
const UT_Vector3 &P)
{
    
return 1 - P.length(); // Return signed distance to unit sphere
}
int
main(
int argc, char *argv[])
{
     GU_Detail            gdp;
     UT_BoundingBox       bounds;
     bounds.setBounds(
-1-1-1111);
     gdp.polyIsoSurface(HDK_Sample::densityFunction, bounds, 
202020);
     gdp.save(
"sphere.bgeo"true, NULL);
     
return 0;
}

上面是个非常简单的独立程序,目的是生成一个小的、ISO球体。

如果改成SOP的节点,需要以下的步骤:

  1. 系统及版本等申明
  2. 头文件声明
  3. 头文件定义(可以分开)
  4. 消息钩子,链接到houdini中
  5. 参数定义
  6. 节点构造
  7. 功能函数构造
  8. 功能函数析构
  9. 制作过程,cooking
代码
//版本,系统声明
#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 <GU/GU_Detail.h>            //构建geometry
#include <SOP/SOP_Node.h>            //
#include <PRM/PRM_Include.h>
#include 
<OP/OP_OperatorTable.h>

//头文件定义

class SOP_Sphere:public SOP_Node
{
public:
    SOP_Sphere(OP_Network 
*net, const char *name, OP_Operator *entry);
    
virtual ~SOP_Sphere();

    
static OP_Node *myConstructor(OP_Network *const char *, OP_Operator *);
    
static PRM_Template myTemplateList[];
protected:
    
virtual OP_ERROR cookMySop(OP_Context &context);
};
///////////////////////////////////////////////////////////////

//消息钩子,与houdini联系

void newSopOperator(OP_OperatorTable *table)
{
    table
->addOperator(new OP_Operator(
        
"hdk_sphere",                        //内部名称
        "mySphere",                            //界面名称
        SOP_Sphere::myConstructor,            //构造
        SOP_Sphere::myTemplateList,            //参数
        0,                                    //最小输入
        0                                    //最大输入
        ));
}

//参数
PRM_Template
SOP_Sphere::myTemplateList[]
=
{
    PRM_Template()
};

//节点构造
OP_Node *
SOP_Sphere::myConstructor(OP_Network 
*net, const char *name, OP_Operator *entry)
{
    
return new SOP_Sphere(net,name,entry);
}
//构造SOP_Sphere函数
SOP_Sphere::SOP_Sphere(OP_Network *net, const char *name, OP_Operator *entry):SOP_Node(net,name,entry)
{}
//析构SOP_Sphere函数
SOP_Sphere::~SOP_Sphere(){}

//cooking部分,构建功能
static float densityFunction(const UT_Vector3 &P)
{
    
return 1-P.length();
}
OP_ERROR SOP_Sphere::cookMySop(OP_Context 
&context)
{
    
//GU_Detail        *gdp;
    UT_BoundingBox    bounds;
    gdp
->clearAndDestroy();
    bounds.setBounds(
-1,-1,-1,1,1,1);
    gdp
->polyIsoSurface(densityFunction,bounds,20,20,20);
    
return error();
}

添加上一个简单的参数,结果如下:

代码
//版本,系统声明
#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 <GU/GU_Detail.h>            //构建geometry
#include <SOP/SOP_Node.h>            //
#include <PRM/PRM_Include.h>
#include 
<OP/OP_OperatorTable.h>

//头文件定义

class SOP_Sphere:public SOP_Node
{
public:
    SOP_Sphere(OP_Network 
*net, const char *name, OP_Operator *entry):SOP_Node(net,name,entry){};
    
virtual ~SOP_Sphere(){};

    
static OP_Node *myConstructor(OP_Network *const char *, OP_Operator *);
    
static PRM_Template myTemplateList[];
protected:
    
virtual OP_ERROR cookMySop(OP_Context &context);
    
int    DIVX()        {return evalInt(0,0,0);}
    
int    DIVY()        {return evalInt(0,1,0);}
    
int    DIVZ()        {return evalInt(0,2,0);}
};
///////////////////////////////////////////////////////////////

//消息钩子,与houdini联系

void newSopOperator(OP_OperatorTable *table)
{
    table
->addOperator(new OP_Operator(
        
"hdk_sphere",                        //内部名称
        "mySphere",                            //界面名称
        SOP_Sphere::myConstructor,            //构造
        SOP_Sphere::myTemplateList,            //参数
        0,                                    //最小输入
        0                                    //最大输入
        ));
}

//参数
//参数名
static PRM_Name        names[]=
{
    PRM_Name(
"division",                //内部名称
            "Division X/Y/Z"            //界面名称
            ),
    PRM_Name(
0)
};
//参数初始值
static PRM_Default    divDefaults[]=
{
    PRM_Default(
20),
    PRM_Default(
40),
    PRM_Default(
20)
};
//参数范围
PRM_Range divRange(PRM_RANGE_RESTRICTED,0,PRM_RANGE_RESTRICTED,50);

//参数构造
PRM_Template
SOP_Sphere::myTemplateList[]
=
{
    PRM_Template(PRM_XYZ,
3,&names[0],divDefaults,0,&divRange),
    PRM_Template()
};

//节点构造
OP_Node *
SOP_Sphere::myConstructor(OP_Network 
*net, const char *name, OP_Operator *entry)
{
    
return new SOP_Sphere(net,name,entry);
}

//cooking部分,构建功能
static float densityFunction(const UT_Vector3 &P)
{
    
return 1-P.length();
}
OP_ERROR SOP_Sphere::cookMySop(OP_Context 
&context)
{
    
//GU_Detail        *gdp;
    int        divx,divy,divz;
    divx
=DIVX();
    divy
=DIVY();
    divz
=DIVZ();
    UT_BoundingBox    bounds;
    gdp
->clearAndDestroy();
    bounds.setBounds(
-1,-1,-1,1,1,1);
    gdp
->polyIsoSurface(densityFunction,bounds,divx,divy,divz);
    
return error();
}


 

  • int pi
    Parameter index
  • const char *pn
    Parameter name token
  • int *pi
    Parameter index passed by reference, looked up using 'pn'
  • PRM_Parm *parm
    Parameter by reference
  • int vi
    Component index of a parameter
  • float t
    Evaluation time
  • int thread
    Thread id (ie. return value from UTgetSTID())
  • int  evalInt (int pi, int vi, float t) const

    evalInt(0,      //参数索引(第几个参数)

        0,     //参数分量索引(参数中的第几个分量)

        0      //时间值(可否动画)

         )

    原文地址:https://www.cnblogs.com/houdinime/p/1705866.html