在PhiloGL中加载/删除多个模型 - WebGL

时间:2014-02-19 21:40:37

标签: webgl webgl-extensions

我正在尝试加载&使用philoGL从主webgl视图中删除模型。 在原始脚本中,我找到了加载一个模型的位置。 但是,我想删除第一个模型并将其替换为第二个模型。

这是在开始时加载模型的方式:

model = new O3D.Model({
    program: 'default',
    drawType: (item[0] == 't') ? "TRIANGLES" : "TRIANGLE_STRIP",
    vertices: item[1],
    normals: item[2],
    colors: item[3],
    indices: item[4]
});
scene.add(model);

我在考虑运行以下代码:

scene.remove(model);
scene.add(otherModel);

任何人的想法? 谢谢, EL

1 个答案:

答案 0 :(得分:2)

替换philoGL中的model的最佳方法是

var indexModel = scene.models.indexOf(model);

if (indexModel > -1) {
   models.splice(indexModel, 1, otherModel);
   scene.defineBuffers(otherModel);
}

这是因为您无法使用PhiloGL所具有的方法跟踪要替换的model的位置。要在model中执行操作,您必须直接访问models对象的Scene属性。