从r68开始,在THREE.js上获取getDescendants()的正确方法

时间:2014-09-03 20:09:13

标签: javascript three.js

r68起,getDescendants()方法已从THREE.Object3D中移除。

现在推荐使用相同功能的方法是什么? (因为没有提供警告信息......)

1 个答案:

答案 0 :(得分:2)

以下是从r.68中删除的getDescendants()方法:

THREE.Object3D.prototype.getDescendants = function ( array ) {

    if ( array === undefined ) array = [];

    Array.prototype.push.apply( array, this.children );

    for ( var i = 0, l = this.children.length; i < l; i ++ ) {

        this.children[ i ].getDescendants( array );

    }

    return array;

};

如果您想编写自定义内容,可以使用Object3D.traverse()方法;

object.traverse( function( node ) {

    // your code here

} );

three.js r.68