1-4期
195人加入学习
(33人评价)
Houdini 影视特效实验班

6个月零基础到入职

价格 ¥ 6198.00
教学计划
承诺服务


for(int i = 0; i < npoints(0); i++){
    
    vector current_P = point(0, "P", i);
    int current_id = point(0, "id", i);
    int branch_count_temp = point(0, "branch_count", i);
    int branch_time_temp = point(0, "branch_time", i);
    
    float seach_radius = chf("seach_radius");
    int max_points = chi("max_points");
    
    int found_ptnum;
    
    int handle = pcopen(1, "P", current_P, seach_radius, max_points);
    while(pciterate(handle)){
        pcimport(handle, "point.number", found_ptnum);
        
        int bool_A = branch_count_temp == -1 ? 1 : 0;
        int array_check = find(temp_array, found_ptnum);
        int bool_B = array_check < 0 ? 1 : 0;
        
        if(bool_A && bool_B){
            setpointattrib(0, "branch_point", i, found_ptnum, "set");
            
            append(temp_array, found_ptnum);
            temp_array = sort(temp_array);
            
            setpointattrib(0, "Cd", i, {1,0,0}, "set");
        }
    }
    pcclose(handle);
}
setpointattrib(0, "already_taken", 0, temp_array, "set");

 

这整段代码是用来确定被找到的分支闪电的目标点的唯一性,其原理是来自于SOPsolve这个节点在DOP网络里粒子系统中的循环,我不知道该怎么来形容,不过就是这么个意思,关于这种分支闪电是非常高级的应用技巧了,在实际镜头运用中我想不到除了这个效果,其他有什么作用,关于这种效果可以直接拿过来使用,唯一要改的地方只有bool_C和bool_D两个条件设置的参数,用来确定闪电分支的多少

[展开全文]

最后already_taken并没有被写上数字,失败了,还要回去多检查几遍代码。

[展开全文]

布尔标准写法:

int bool_A = xxx ==-1 ? 1 : 0;

条件A,xxx是否等于-1? 是的话返回1,不是的话返回0

 

find函数:

find(操作于哪个数组,哪个点是否在数组中);

 

append函数:

append(对哪个数组进行操作,附加到数组上的数据);

 

本节完整VEX代码:(仅供阅读,以后我可以翻着看。。)

int temp_array[] = point(0, "already_taken", 0); 


for(int idx=0; idx<npoints(0); idx++){
    //grab particle attribute
    vector cur_P = point(0, "P", idx);
    int cur_id = point(0, "id", idx);
    int found_pt = -1;
    int branch_count_tmp = point(0, "branch_count", idx);
    int branch_time_tmp = point(0, "branch_time", idx);    
    
    //get point cloud handle
    int handle = pcopen(1, "P", cur_P, chf("rad"), chi("max_pts"));
    
    //if branch count has been initiated and brance count is smaller than branch time
    if(branch_count_tmp>-1 && branch_count_tmp <= branch_time_tmp){
        branch_count_tmp++;
        setpointattrib(0, "branch_count", idx, branch_count_tmp, "set");
    }else if(branch_count_tmp>-1 && branch_count_tmp > branch_time_tmp){
        branch_count_tmp = -1;
        setpointattrib(0, "branch_count", idx, branch_count_tmp, "set");
        
     //set Cd for debugging
        setpointattrib(0, "Cd", idx, {0, 0, 0}, "set");
    }    
    
       
    //open point cloud
    while(pciterate(handle)){
        pcimport(handle, "point.number", found_pt);
        int bool_A = branch_count_tmp == -1 ? 1 : 0;
        //check if found point is already in array
        int array_check = find(temp_array, found_pt);
        int bool_B = array_check < 0 ? 1 : 0;
        
        //if all conditions are true,then assign branch_point attribute to particle
        if(bool_A && bool_B){
            setpointattrib(0, "branch_point", idx, found_pt, "set");
            
            //append found point number to temp array and store only on point 0
            append(temp_array,found_pt);
            temp_array = sort(temp_array);
            //update Cd for debugging
            setpointattrib(0, "Cd", idx, {1, 0, 0}, "set");
        //end of if statement
        }
    //end of while loop over point cloud handle  
    }
//end of for loop over each particle
}
setpointattrib(0, "already_taken", 0, temp_array, "set");

 

 

 

!!看完04-06节后再回来!!

while循环中,做完布尔判定后,缺少了语句:

setpointattrib(0, "branch_count", idx, branch_count_tmp +1, "set");

使得上面的branch_count并未成功计数,解除了两天来的疑惑,添加此语句后,branch_count开始逐帧增加1

 

[展开全文]