博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Interpolation particles In Katana
阅读量:6428 次
发布时间:2019-06-23

本文共 15210 字,大约阅读时间需要 50 分钟。

I write the sphere radius interpolation for katana plugin that can transfer attributes,render attributes ,render velocity motion blur directly.

 

 

 

--GLY_MATH header source:

//// Created by gearslogy on 4/13/16.//#ifndef GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H#define GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H#include 
#include
#include
#include
#define gly_rand_01 double(rand()) / double(RAND_MAX)namespace GLY_MATH{ template
T min(T a,T b) { if(a>b) { return b; } else { return a; } } template
T max(T a,T b) { if(a>b) { return a; } else { return b; } } template
int zero_compare(T a, double tol=0.00001) { return a >= -tol && a <= tol; } // DO NOT USE THIS FIT TO FIT VECTOR VALUE template
T fit(T var, T omin, T omax,T nmin, T nmax) { T d = omax-omin; if(zero_compare(d)) { return (nmin+nmax)*0.5; } if(omin
omax) return nmax; } else { if (var < omax) return nmax; if (var > omin) return nmin; } return nmin + (nmax-nmin)*(var-omin)/d; } //return -1 to 1 template
T fit_negate(T var,T omin,T omax) { return fit(var,omin,omax,-1.0,1.0); } // fast random 01 var double random_01_value(int seed) { srand(seed); return gly_rand_01; } //string split std::vector
split_string(std::string &inputString, char &split_char) { std::stringstream ss(inputString); std::string sub_str; std::vector
sp_strPath; sp_strPath.clear(); while(getline(ss,sub_str,split_char)) { sp_strPath.push_back(sub_str); } return sp_strPath; } //value to string template
// T must be a value int/float/double std::string value_to_str(T &value) { std::ostringstream os; os<< value; return os.str(); }}#endif //GLY_POINTSINTERPOLATION_GLY_COMMON_MATH_H
View Code

 

--Arnold Source Code:

#include 
#include
#include
#include "GLY_common_math.h"#include
#include
#include
#include
using namespace std;#define RAND_NORMALIZE float(rand()) / float(RAND_MAX)// global variables for read data//@pt_radius = point radiusfloat pt_radius;//@pt_list_num = point interpolation numAtUInt32 pt_list_num;//float replicate_radius;AtArray *offset_vec;AtArray *frequency_vec;//motion blur param//@pt_use_vel_mb choose should use motion blurint pt_use_vel_mb;float shuffer_open_val;float shuffer_close_val;//exist attributeAtArray *id_array_list; //Katana particles id ->define named "ins_id" from houdini abcAtArray *pos_array_list; // Katana particles P ->define named "P" from houdini abcAtArray *vel_array_list;// other attributestring attribute_list;struct katana_attribute_map{ string name; AtArray *map_array; //@map_array type = AI_TYPE_BYTE ->0 //@map_array type = AI_TYPE_INT ->1 //@map_array type = AI_TYPE_FLOAT ->4 //@map_array type = AI_TYPE_POINT ->8};vector
att_maps;//get shuffer open posAtVector get_shuffer_open_pos(AtVector &curl_v,AtVector &curl_p, float shuffer_open_val){ return curl_p+curl_v*shuffer_open_val;}// get shuffer close posAtVector get_shuffer_close_pos(AtVector &curl_v,AtVector &curl_p, float shuffer_close_val){ return curl_p+curl_v*shuffer_close_val;}// this is set the constant radiusstatic void setConstantRadius(AtArray *radius_array , float &rad){ #pragma omp parallel for for(int i=0;i
nelements;i++) { AiArraySetFlt(radius_array,i,rad); }}//@shuffer_value may be open or close value//@cur_pos_array is the new pos from the interpolation array//@orig_velocity_array is from katanastatic AtArray* createMotionBlurOpenPoints(AtArray *orig_velocity_array, AtArray *cur_pos_array,float shuffer_value,AtUInt32 &iter_num){ AtInt32 num_pt = orig_velocity_array->nelements/3; printf("motion open ->get the num_pt is %d \n",num_pt); AtArray *_motion_points = AiArrayAllocate(cur_pos_array->nelements,1,AI_TYPE_POINT); vector
large_vel_list; // THIS IS NOT SIMD PROGRAM /* for(AtUInt32 i=0;i
get the large vel array size is %d\n",large_vel_list.size()); printf("motion open ->get the pos array size is %d\n",cur_pos_array->nelements); */ large_vel_list.resize(iter_num * num_pt); // TELL THE GCC SIZE ,INDEX THE THREAD #pragma omp parallel for for(AtUInt32 i=0;i
end\n ");}static AtArray* createMotionBlurClosePoints(AtArray *orig_velocity_array, AtArray *cur_pos_array,float shuffer_value,AtUInt32 &iter_num){ AtInt32 num_pt = orig_velocity_array->nelements/3; printf("motion open ->get the num_pt is %d \n",num_pt); AtArray *_motion_points = AiArrayAllocate(cur_pos_array->nelements,1,AI_TYPE_POINT); vector
large_vel_list; /* for(AtUInt32 i=0;i
end\n ");}//transfer the vector attribute to the replicate pointsstatic void fork_vector_attribute(AtArray *src_vector_array,AtArray *des_vector_array,AtUInt32 &iter_num){ float *src_vec_data = static_cast
(src_vector_array->data); AtUInt32 src_num_pt = src_vector_array->nelements/3;// divide 3 because from Katana is a float array.. vector
src_vec_list; src_vec_list.resize(src_num_pt * iter_num); #pragma omp parallel for for(AtUInt32 i=0; i
nelements); #pragma omp parallel for for(AtUInt32 i=0;i
(src_float_array->data); AtUInt32 src_num_pt = src_float_array->nelements; vector
src_vec_list; src_vec_list.resize(src_num_pt * iter_num); #pragma omp parallel for for(AtUInt32 i=0;i
nelements); #pragma omp parallel for for(int j=0;j
type==4); // 4 is the AI_TYPE_FLOAT,because from katana P data is Array Float.... assert(orig_id_array->type==1); // 1 is the AI_TYPE_INT vector
child_pt_pos_list; for(AtUInt32 i=0;i
nelements;i++) { int _id = AiArrayGetInt(orig_id_array,i); AtVector orig_pos; orig_pos.x = AiArrayGetFlt(orig_pos_array,i*3 + 0); orig_pos.y = AiArrayGetFlt(orig_pos_array,i*3 + 1); orig_pos.z = AiArrayGetFlt(orig_pos_array,i*3 + 2); //printf("orig_pos_x -> : %f \n",orig_pos.x); //printf("orig_pos_y -> : %f \n",orig_pos.y); //printf("orig_pos_z -> : %f \n",orig_pos.z); for(int k=0;k
: %f \n",i,k,pt.x); //printf("the father %d,the child %d,noise_pos_y -> : %f \n",i,k,pt.y); //printf("the father %d,the child %d,noise_pos_z -> : %f \n",i,k,pt.z); child_pt_pos_list.push_back(new_pt + orig_pos); } } assert(child_pt_pos_list.size()==num_pt); #pragma omp parallel for for(AtUInt32 child=0;child
nelements;i++) { printf("get the offset val %f \n",AiArrayGetFlt(offset_vec,i)); } */ //printf("pt_init get the attribtue list is %s \n",attribute_list.c_str()); /* printf("get the type is %d \n",vel_array_list->type); for(int i=0;i
nelements;i++) { printf("get the array is %f\n", AiArrayGetFlt(vel_array_list, i)); }*/ char split_char = ','; vector
_attrib_list = GLY_MATH::split_string(attribute_list,split_char); att_maps.resize( _attrib_list.size() ); // SIMD SET ARRAY... #pragma omp parallel for for(int i=0; i<_attrib_list.size();i++) { string _curl_attrib_name = _attrib_list[i]; katana_attribute_map _map; _map.name = _curl_attrib_name; _map.map_array = AiNodeGetArray(node,_curl_attrib_name.c_str()); att_maps[i] = _map; } printf("pt_init get iter num particles is %d \n",pt_list_num); printf("pt_init get particles radius is %f \n",pt_radius); printf("pt_init get shuffer_open is %f \n", shuffer_open_val); printf("pt_init get shuffer close is %f \n", shuffer_close_val); printf("pt_init get the use_motion_blur is %d \n",pt_use_vel_mb); return true;}static int pt_cleanup(void *user_ptr){ return true;}static int pt_numnodes(void *user_ptr){ return 1;}static AtNode *MyGetNode(void *user_ptr,int i){ printf("create node\n"); AtNode *node = AiNode("points"); AtInt32 orig_num_pt = id_array_list->nelements; // from Houdini have num_pt AtInt32 iter_num_pt = orig_num_pt * pt_list_num; // every point have-> orig num pt * iterNum AtArray *pointArray = AiArrayAllocate(iter_num_pt,1,AI_TYPE_POINT); if(pt_use_vel_mb) { pointArray = AiArrayAllocate(iter_num_pt,2,AI_TYPE_POINT); } else { pointArray = AiArrayAllocate(iter_num_pt,1,AI_TYPE_POINT); } printf("start create pt\n"); AtArray *curl_pos_array = AiArrayAllocate(iter_num_pt,1,AI_TYPE_POINT); curl_pos_array=makeSpherePoints(pt_list_num,orig_num_pt,pos_array_list,id_array_list); if(pt_use_vel_mb) { printf("start create motion blur points\n"); AtArray *__open_pos_array = createMotionBlurOpenPoints(vel_array_list,curl_pos_array,shuffer_open_val,pt_list_num); AtArray *__close_pos_array = createMotionBlurClosePoints(vel_array_list,curl_pos_array,shuffer_close_val,pt_list_num); float *__open_pos_array_data = static_cast
(__open_pos_array->data); float *__close_pos_array_data = static_cast
(__close_pos_array->data); printf("setting motion blur points\n"); AiArraySetKey(pointArray,0,__open_pos_array_data); AiArraySetKey(pointArray,1,__close_pos_array_data); printf("setting motion blur points compelte\n"); } else { pointArray = curl_pos_array; } //Radius setttings //printf("starting create radius array\n"); AtArray *radiusArray = AiArrayAllocate(iter_num_pt,1,AI_TYPE_FLOAT); setConstantRadius(radiusArray,pt_radius); // transfer v attribute that can use "use_data_rgb/use_data_rgba" to render channel. AtArray *channel_v = AiArrayAllocate(iter_num_pt,1,AI_TYPE_RGBA); fork_vector_attribute(vel_array_list,channel_v,pt_list_num); AiNodeDeclare(node, "v", "uniform RGBA"); AiNodeSetArray(node,"v",channel_v); // transfer other transfer attribute for(int i=0; i
nelements == orig_num_pt) // not vector attrib { printf("fork other float/int attribute name is %s \n",att_name.c_str()); fork_float_attribute(array,_channel,pt_list_num); AiNodeSetArray(node,att_name.c_str(),_channel); } if(array->nelements == orig_num_pt *3 ) // vector attrib { printf("fork other vector attribute name is %s \n",att_name.c_str()); fork_vector_attribute(array,_channel,pt_list_num); AiNodeSetArray(node,att_name.c_str(),_channel); } } AiNodeSetArray(node,"points",pointArray); AiNodeSetArray(node,"radius",radiusArray); AiNodeSetStr(node, "mode", "sphere"); printf("complete the procedural points\n"); return node;}proc_loader{ vtable->Init = pt_init; vtable->Cleanup = pt_cleanup; vtable->NumNodes = pt_numnodes; vtable->GetNode = MyGetNode; strcpy(vtable->version,AI_VERSION); return true;}
View Code

--KATANA Source code:

---header

//// Created by GearsLogy on 4/11/16.// this file connect the procedural points create ...//#ifndef GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H#define GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H#include 
#include
#include
#include
#include
#include
#include
class GLY_InterpolationOP : public Foundry::Katana::GeolibOp{public: static void setup(Foundry::Katana::GeolibSetupInterface &interface) { interface.setThreading(Foundry::Katana::GeolibSetupInterface::ThreadModeConcurrent); } static void cook(Foundry::Katana::GeolibCookInterface &interface);};#endif //GLY_INTERPOLATIONPARTICLES_GLY_INTERPOLATIONOP_H
View Code

---source

/// Created by gearslogy on 4/11/16.//#include "GLY_InterpolationOP.h"#include 
#include
#include
#include
using namespace std;void GLY_InterpolationOP::cook(Foundry::Katana::GeolibCookInterface &interface){ FnAttribute::StringAttribute get_par_loc = interface.getOpArg("particle_path"); FnAttribute::StringAttribute get_procedural_loc = interface.getOpArg("procedural_path"); if(!get_procedural_loc.isValid() || get_procedural_loc.getValue("",false).empty()) return; // next create a location just for the rendering... string procedural_loc_str = get_procedural_loc.getValue("",false); Foundry::Katana::CreateLocationInfo createLocationInfo; Foundry::Katana::CreateLocation(createLocationInfo,interface,procedural_loc_str); if(!get_par_loc.isValid()) { printf("%s not found the attribute",get_par_loc.getValue("", false)); return; } /* int ex = interface.doesLocationExist(get_par_loc.getValue("",false)); if(!ex) { printf("%s do not exist in the location\n",get_par_loc.getValue("", false)); return; }*/ string par_loc_str = get_par_loc.getValue("",false); FnAttribute::FloatAttribute get_par_radius_att = interface.getOpArg("pointRadius"); FnAttribute::IntAttribute get_par_num_att = interface.getOpArg("interpolationNum"); FnAttribute::IntAttribute get_use_motion_blur = interface.getOpArg("use_vel_motion_blur"); FnAttribute::FloatAttribute get_shuffer_open = interface.getOpArg("shuffer_open"); FnAttribute::FloatAttribute get_shuffer_close = interface.getOpArg("shuffer_close"); FnAttribute::FloatAttribute get_replicate_radius = interface.getOpArg("replicate_radius"); FnAttribute::FloatAttribute get_noise_fre = interface.getOpArg("frequency"); FnAttribute::FloatAttribute get_noise_offset = interface.getOpArg("offset"); FnAttribute::StringAttribute get_attribute_list = interface.getOpArg("attributeTransferList"); //printf("oparg check\n"); if(!get_par_radius_att.isValid()) return; if(!get_par_num_att.isValid()) return; if(!get_shuffer_open.isValid()) return; if(!get_use_motion_blur.isValid()) return; if(!get_shuffer_close.isValid()) return; if(!get_replicate_radius.isValid()) return; if(!get_attribute_list.isValid()) return; if(!get_noise_fre.isValid()) {printf("not found frequency arg\n");return;} if(!get_noise_offset.isValid()) {printf("not found offset arg\n");return;} //float pt_radius = get_par_radius_att.getValue(0.0f,false); //int pt_num = get_par_num_att.getValue(0,false); //printf("transfer data\n"); //get id and p attribute FnAttribute::IntAttribute id_attribute = interface.getAttr("geometry.arbitrary.ins_id.value",par_loc_str); FnAttribute::FloatAttribute pos_attribute = interface.getAttr("geometry.point.P",par_loc_str); FnAttribute::FloatAttribute vel_attribute = interface.getAttr("geometry.point.v",par_loc_str); if(!id_attribute.isValid()){ Foundry::Katana::ReportError(interface,"No ins_id attribute in particles location\n"); return; } if(!pos_attribute.isValid()){ Foundry::Katana::ReportError(interface,"No P attribute in particles"); return; } if(!vel_attribute.isValid()){ Foundry::Katana::ReportError(interface,"No v attribute in particles"); return; } string fullName = interface.getOutputLocationPath(); FnGeolibUtil::Path::FnMatchInfo fnMatchInfo; FnGeolibUtil::Path::FnMatch(fnMatchInfo, fullName,procedural_loc_str); if (!fnMatchInfo.match) return; //attribute transfer list checking string attr_list = get_attribute_list.getValue("", false); //printf("current attribute list is %s \n",attr_list.c_str()); stringstream ss(attr_list); string sub_str; vector
sp_strPath; sp_strPath.clear(); while(getline(ss,sub_str,',')) { sp_strPath.push_back(sub_str); } if(sp_strPath.size()!=0 && attr_list!="") { interface.setAttr("rendererProcedural.args.attributeTransferList",get_attribute_list); for(int i=0;i
setting complete\n");}
View Code

 

转载于:https://www.cnblogs.com/gearslogy/p/5421039.html

你可能感兴趣的文章
TRUNCATE,DORP,DELETE
查看>>
Chrome的开发必备小技巧
查看>>
can-i-win(好)
查看>>
Centos6.5下安装protobuf及简单使用
查看>>
[SharePoint] SharePoint 错误集 3
查看>>
高压光耦
查看>>
[转]DPM2012系列之六:在Win7上安装DPM远程管理控制台
查看>>
postgres函数
查看>>
Microsoft AJAX Library Cheat Sheet(5): Number和Error类型的扩展
查看>>
POJ 3580 SuperMemo(splay)
查看>>
AfxGetMainWnd函数
查看>>
WebView增加一个水平Progress,位置、长相随意
查看>>
easyui messager alert 三秒后自动关闭提示
查看>>
带你Python入门,踏进人工智能领域
查看>>
core data 基础操作
查看>>
手机共享电脑网络
查看>>
ORM框架Hibernate (四) 一对一单向、双向关联映射
查看>>
20140616 科技脉搏 -最大颠覆来自创业公司与边缘产业
查看>>
offsetLeft, offsetTop以及postion().left , postion().top有神马区别
查看>>
visual studio 中GIT的用法
查看>>