我是THREE.js的新手。 我正在尝试创建一个扩展THREE.Mesh的自定义类来添加到我的场景中。我的想法是自定义类必须通过json loader包含一个导入的网格,但是我所有尝试使它都失败了。
这是我的代码:
THREE.ImportedMesh = function(){
this.type = 'ImportedMesh';
this.load = function(url){
var loader = new THREE.JSONLoader();
loader.load(url, function(geometry,materials){
THREE.Mesh.call(self,geometry,new THREE.MeshFaceMaterial(materials));
});
};
};
THREE.ImportedMesh.prototype = Object.create( THREE.Mesh.prototype );
THREE.ImportedMesh.prototype.constructor = THREE.ImportedMesh;
此处错误打印在控制台
中未捕获的TypeError:无法读取属性'删除'未定义的
未捕获的TypeError:this.updateMorphTargets不是函数
谁能告诉我怎么做?
谢谢,
瑞克
答案 0 :(得分:0)
尝试这样的事情:
THREE.ImportedMesh = function(){
this.type = 'ImportedMesh';
THREE.Mesh.call(this);
var self = this
this.load = function(url){
var loader = new THREE.JSONLoader();
loader.load(url, function(geometry,materials){
self.material = new THREE.MeshFaceMaterial(materials)
self.geometry = geometry
});
};
};
THREE.ImportedMesh.prototype = Object.create( THREE.Mesh.prototype );
THREE.ImportedMesh.prototype.constructor = THREE.ImportedMesh;