0
点赞
收藏
分享

微信扫一扫

#yyds干货盘点#three.js源码解读-Object3D构造函数的结构

在three.js中有很多构造函数都是继承自Object3D,现对Object3D构造函数梳理一下,如下:

结构代码

function Object3D() {

}

// recursive: 递归的意思
Object3D.prototype = Object.assign({}, {
constructor: Object3D,
isObject3D: true,
add: function() {},
clone: function (recursive) {
return new this.constructor().copy(this, recursive);
},
copy: function (source, recursive) {
if (recursive === undefined) {
recursive = true;
}
this.name = source.name
this.userData = JSON.parse(JSON.stringify(source.userData))
if (recursive === true) {
for (var i = 0; i < source.children.length; i++) {
var child = source.children[i];
this.add(child.clone()); // 此处有递归调用
}
}
// ... 其他代码
}
})
举报

相关推荐

0 条评论