Houdini Volume Deform 奇 思

时间:2020-03-15 09:40:56   收藏:0   阅读:147

最近在做Houdini Volume的一些结算,工作的过程中突然闪现一个想法,可不可以把Houdini 中 Point Deform 节点的原理和算法运用到Volume上 ? 经过测试, 发现是可以的。

Point Deform 是根据 模型的变形(Geometry Deform) 来改变点的位置。利用模型的变形的好处是:模型本身的点相对少,内存占用少些,效率更高。Volume Deform 运用Point Deform相同的原理,利用模型变形的信息的话,会继承它的这些优点。

在这之前想说的是,还有很多Volume Deform的方法,这里只是提供另一个思路~

测试的Demo如下:

 

这题的框架如下图:

技术分享图片

 

其中compute_xforms_sequential是Point Deform节点中对应的相应节点,注意的是我测试用的Houdini版本是16。目前houdini 18的话,Point Deform会:如果模型中(第二个端口)存在id属性,会优先使用id,而不是ptnum(点号)。

上图中VolumeDeform的参数和代码整合如下:

技术分享图片

 // vex

 

技术分享图片
// ************************************************
// Capture and CaptWeights
// ************************************************
float radius = ch("radius");
int maxpt = chi("maxpt");
int minpt = chi("minpt");

int pCaptPts[];
float pCaptWeights[];

pCaptPts = pcfind(1, P, @P, radius, maxpt);
if (len(pCaptPts) < minpt)
{
    pCaptPts = pcfind(1, P, @P, 1e15, minpt);
    radius = 1.1 * distance(@P, point(1, P, pCaptPts[-1]));
}

foreach (int pt; pCaptPts)
{
    float r2 = distance2( vector(point(1, P, pt)), @P );
    r2 /= radius*radius;
    float weight = 1-r2;
    weight *= weight;
    //weight = 1-weight;
    
    push(pCaptWeights, weight);
}

// ************************************************
// Compute Offset
//*************************************************
float totalweight = 0;
vector delta = 0;
matrix3 totalxform = 0;
vector offset;
foreach (int idx; int pt; pCaptPts)
{
    vector oldcenter = point(1, P, pt);
    vector diff = point(2, P, pt) - oldcenter;
    matrix3 xform = point(1, xform, pt);
    float weight = pCaptWeights[idx]; 
    
    // Compute our new location according this xform.
    vector newp = @P;
    newp -= oldcenter;
    newp *= xform;
    newp += oldcenter;
    newp += diff;
    diff = newp - @P;
    delta += diff * weight;
    totalweight += weight;
    totalxform += xform * weight;
}

delta /= totalweight;
//@P += delta;
offset = delta;

if (totalweight > 0)
{
    totalxform /= totalweight;
    if (chi("rigidprojection"))
        totalxform = polardecomp(totalxform);
   
}

// ************************************************
//Deform
// ************************************************
 f@density = volumesample(3,0,@P + offset);
View Code

 

 

 

 

 

 

  

 

原文:https://www.cnblogs.com/peng-vfx/p/12495492.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!