Javascript方法无法在BabylonJS中使用自定义网格

时间:2016-06-12 18:13:11

标签: javascript babylonjs

我对BabylonJS很新,我创建了一个这样的自定义网格(我不知道它是否正确):

function DragSphere() {
    this.sphere = BABYLON.Mesh.CreateSphere("sphere", 15, 2, scene);
    this.sphere.material = new BABYLON.StandardMaterial("sphereMat", scene);
    ...
    return (this.sphere);
}

DragSphere.prototype.setRGBColor = function(r, g, b) {
    this.sphere.material.diffuseColor = new BABYLON.Color3(r/255, g/255, b/255);
}

所以我想使用SetRGBColor的{​​{1}}方法更新其颜色,但浏览器似乎不同意我的说法:

DragSphere

1 个答案:

答案 0 :(得分:1)

从构造函数中删除return (this.sphere);语句。

如果您只使用TypeScript,则可以使用new运算符调用void函数。如上所述,在签名中调用返回类型的函数将导致在转换的JavaScript中未定义setRGBColor函数。

您可以在Babylon JS playground中尝试这一点。