布/网眼相交,光线投射

时间:2018-07-01 18:00:46

标签: javascript three.js

在此处使用布料模拟演示:

https://threejs.org/examples/webgl_animation_cloth.html

我正试图阻止布料与电线杆和电线本身交叉(电线也似乎会折叠起来)。不确定两者的解决方案是否相同(或者对于相交的标志,我只需要设置一些内容),但是我尝试了以下方法。

设置冲突列表:

var collidableMeshList = [];

在其中添加旗杆:

collidableMeshList.push(flagpole);

然后在我的动画循环中检查标志是否与列表中的任何内容相交:

var originPoint = flag.position.clone();

for (var vertexIndex = 0; vertexIndex < flag.geometry.vertices.length; vertexIndex++)
{       
    var localVertex = flag.geometry.vertices[vertexIndex].clone();
    var globalVertex = localVertex.applyMatrix4( flag.matrix );
    var directionVector = globalVertex.sub( flag.position );

    var ray = new THREE.Raycaster( originPoint, directionVector.clone().normalize() );
    var collisionResults = ray.intersectObjects( collidableMeshList );
    if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() ) 
        console.log(" Hit ");
}

它似乎什么也没做。

0 个答案:

没有答案
相关问题