this.meshMap = new Object();
this.addMesh = function(key,url)
{
var map = this.meshMap; // redefinition
var loader = new THREE.JSONLoader();
loader.load( url, function(geometry)
{
map[key] = new THREE.Mesh(geometry, material); // object to store
scene.add(map[key]); // Works
});
map[key].position = new THREE.Vector3(0, -10, 0); // ERROR: Null
}
如何正确地将网格存储到地图中?
答案 0 :(得分:0)
确保调用addMesh时map [key](你的this.meshMap)是一个对象。请注意,这与说地图本身是一个对象不同。如果map [key]不是对象,则它不能具有属性(例如位置)。
您可以尝试以下操作:
this.meshMap = new Object();
this.addMesh = function(key,url)
{
var map = this.meshMap; // redefinition
var loader = new THREE.JSONLoader();
loader.load( url, function(geometry)
{
map[key] = new THREE.Mesh(geometry, material); // object to store
map[key].position = new THREE.Vector3(0, -10, 0); // ERROR: Null
scene.add(map[key]); // Works
});
}