async function createModel(data)
    {
        let model  = new THREE.Group(),
            frames = data.frames,
            step   = data.step,
            start  = data.start,
            stop   = data.stop;

            for (let group of data.groups) {
                let comp = new THREE.Group(), // composite group to which we add objects
                    geometry,
                    material;

                comp.name = group.name;

                for (let obj of group.objs) {
                    if (obj.type === "box") {
                        geometry = new THREE.BoxBufferGeometry(obj.scale[0], obj.scale[1], obj.scale[2]);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5 } );
                    }
                    else if (obj.type === "cylinder") {
                        geometry = new THREE.CylinderBufferGeometry(obj.scale[0], obj.scale[1], obj.scale[2], 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5 } );
                    }
                    else if (obj.type === "ellipsoid") {
                        geometry = new THREE.SphereBufferGeometry(obj.scale[0] * 0.5, 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5, transparent: true } );
                        let matrix = new THREE.Matrix4();
                        matrix.makeScale(1.0, obj.scale[1] / obj.scale[0], obj.scale[2] / obj.scale[0]);
                        geometry.applyMatrix(matrix);
                    }
                    else if (obj.type === "sphere") {
                        geometry = new THREE.SphereBufferGeometry(obj.diameter, 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color),  overdraw: 0.5 } );
                    }
                    else if (obj.type === "mesh") {
                        geometry = await loadData(obj.url);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color),  overdraw: 0.5 } );
                    }

                    material.transparent = true;
                    let mesh = new THREE.Mesh(geometry, material);

                    if (obj.type === "mesh" && obj.scale !== undefined) {
                        mesh.scale.set(obj.scale[0], obj.scale[1], obj.scale[2]);
                    }

                    comp.add(mesh);
                }

                model.add(comp);
            }

        scene.add(model);
        animation = {model, step, start, stop, frames};
    }
/* ------------------------------------------------------------------------
     * createModel:
     * ------------------------------------------------------------------------
     * param data - JSON data for model parsed from file.
     *
     * Extract model information from JSON data.
     */


param data - JSON data for model parsed from file.

Extract model information from JSON data.
param data - JSON data for model parsed from file . Extract model information from JSON data .
async function createModel(data)
    {
        let model  = new THREE.Group(),
            frames = data.frames,
            step   = data.step,
            start  = data.start,
            stop   = data.stop;
            for (let group of data.groups) {
                let comp = new THREE.Group(), 
                    geometry,
                    material;
                comp.name = group.name;
                for (let obj of group.objs) {
                    if (obj.type === "box") {
                        geometry = new THREE.BoxBufferGeometry(obj.scale[0], obj.scale[1], obj.scale[2]);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5 } );
                    }
                    else if (obj.type === "cylinder") {
                        geometry = new THREE.CylinderBufferGeometry(obj.scale[0], obj.scale[1], obj.scale[2], 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5 } );
                    }
                    else if (obj.type === "ellipsoid") {
                        geometry = new THREE.SphereBufferGeometry(obj.scale[0] * 0.5, 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color), overdraw: 0.5, transparent: true } );
                        let matrix = new THREE.Matrix4();
                        matrix.makeScale(1.0, obj.scale[1] / obj.scale[0], obj.scale[2] / obj.scale[0]);
                        geometry.applyMatrix(matrix);
                    }
                    else if (obj.type === "sphere") {
                        geometry = new THREE.SphereBufferGeometry(obj.diameter, 32, 32);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color),  overdraw: 0.5 } );
                    }
                    else if (obj.type === "mesh") {
                        geometry = await loadData(obj.url);
                        material = new THREE.MeshLambertMaterial( { color: parseInt(obj.color),  overdraw: 0.5 } );
                    }
                    material.transparent = true;
                    let mesh = new THREE.Mesh(geometry, material);
                    if (obj.type === "mesh" && obj.scale !== undefined) {
                        mesh.scale.set(obj.scale[0], obj.scale[1], obj.scale[2]);
                    }
                    comp.add(mesh);
                }
                model.add(comp);
            }
        scene.add(model);
        animation = {model, step, start, stop, frames};
    }
async function createModel ( data ) { let model = new THREE . Group ( ) , frames = data . frames , step = data . step , start = data . start , stop = data . stop ; for ( let group of data . groups ) { let comp = new THREE . Group ( ) , geometry , material ; comp . name = group . name ; for ( let obj of group . objs ) { if ( obj . type === "box" ) { geometry = new THREE . BoxBufferGeometry ( obj . scale [ 0 ] , obj . scale [ 1 ] , obj . scale [ 2 ] ) ; material = new THREE . MeshLambertMaterial ( { color : parseInt ( obj . color ) , overdraw : 0.5 } ) ; } else if ( obj . type === "cylinder" ) { geometry = new THREE . CylinderBufferGeometry ( obj . scale [ 0 ] , obj . scale [ 1 ] , obj . scale [ 2 ] , 32 , 32 ) ; material = new THREE . MeshLambertMaterial ( { color : parseInt ( obj . color ) , overdraw : 0.5 } ) ; } else if ( obj . type === "ellipsoid" ) { geometry = new THREE . SphereBufferGeometry ( obj . scale [ 0 ] * 0.5 , 32 , 32 ) ; material = new THREE . MeshLambertMaterial ( { color : parseInt ( obj . color ) , overdraw : 0.5 , transparent : true } ) ; let matrix = new THREE . Matrix4 ( ) ; matrix . makeScale ( 1.0 , obj . scale [ 1 ] / obj . scale [ 0 ] , obj . scale [ 2 ] / obj . scale [ 0 ] ) ; geometry . applyMatrix ( matrix ) ; } else if ( obj . type === "sphere" ) { geometry = new THREE . SphereBufferGeometry ( obj . diameter , 32 , 32 ) ; material = new THREE . MeshLambertMaterial ( { color : parseInt ( obj . color ) , overdraw : 0.5 } ) ; } else if ( obj . type === "mesh" ) { geometry = await loadData ( obj . url ) ; material = new THREE . MeshLambertMaterial ( { color : parseInt ( obj . color ) , overdraw : 0.5 } ) ; } material . transparent = true ; let mesh = new THREE . Mesh ( geometry , material ) ; if ( obj . type === "mesh" && obj . scale !== undefined ) { mesh . scale . set ( obj . scale [ 0 ] , obj . scale [ 1 ] , obj . scale [ 2 ] ) ; } comp . add ( mesh ) ; } model . add ( comp ) ; } scene . add ( model ) ; animation = { model , step , start , stop , frames } ; }
createModel:
createModel :
// composite group to which we add objects