ThreeJS - ColladaLoader回调的附加参数

时间:2018-02-09 17:03:17

标签: three.js

我使用ThreeJS中的ColladaLoader

var loader = new THREE.ColladaLoader();
loader.load(file, this.onModelLoadingCompleted);

private onModelLoadingCompleted(collada) {
    scene.add(collada.scene);
}

我现在想要向onModelLoadingCompleted函数添加自定义函数参数。这可能吗?如果是的话,该怎么做?

特别是我正在寻找类似的东西:

var loader = new THREE.ColladaLoader();
loader.load(file, this.onModelLoadingCompleted(collada, customProperty));

private onModelLoadingCompleted(collada, customProperty) {
    scene.add(collada.scene);
    //do something with customProperty
}

1 个答案:

答案 0 :(得分:1)

您可以使用匿名回调来访问额外变量。例如:

var loader = new THREE.ColladaLoader();
var customProperty = 3.14159;
loader.load( file, function (collada) {
  this.onModelLoadingCompleted(collada, customProperty);
}.bind(this) );


// elsewhere:
onModelLoadingCompleted(collada, customProperty) {
    scene.add(collada.scene);
    //do something with customProperty
}