webglwebgl-extensions

load / remove multiple models in PhiloGL - WebGL


I am trying to load & remove models from the main webgl view with philoGL. In the original script I found the place where one model is loaded. However, I want to remove the first model and replace it with a second.

This is how a model is loaded at start:

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);

I was thinking about running the following code:

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

Ideas anyone? Thanks, EL


Solution

  • The best way to replace a model in philoGL is

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

    This is because you cannot track the position of the model that you want to replace with the methods that PhiloGL have. To perform operations in model you have to access the models property of the Scene object directly.