Game Development Reference
In-Depth Information
Open the
03-Loading-Scene.html
file in your favorite editor. If you observe the
scene, you will see that there are four buildings, six street lamps, and two railings.
Hence, we added the
cloneObjects
function that clones the objects and adds
them to the scene. The
cloneObjects
function invokes the function
clone
of the
SceneObject's class, which invokes the
clone
function of the
Geometry
class. The
following is the code snippet from the
03-Loading-Scene.html
file:
function start() {
........................................
addStageObject("model/obj/terrain.json",
[0.0,0.0,0.0],0.00,0.0,0.0);
addStageObject("model/obj/building.json",
[55.0,0.0,170],0.0,0.0,0.0);
addStageObject("model/obj/giantPillar.json",
[-60.0,0.0,-200],0.0,0.0,0.0);
addStageObject("model/obj/pillarBroken.json",
[10.0,0.0,-200.00],0.0,0.0,0.0);
addStageObject("model/obj/streetlamp.json",
[20.0,0.0,200.00],0.0,0.0,0.0);
addStageObject("model/obj/cityLine.json",
[12.0,0.0,-335.0],0,3.14,0.0);
addStageObject("model/obj/railing.json",
[0.0,5.0,200.0],0.0,0.0,0.0);
addStageObject("model/obj/dump.json",
[-40.0,0.0,-30.0],0.0,0.0,0.0);
initScene();
}
function addStageObject(url,location,rotationX,
rotationY,rotationZ){
$.getJSON(url,function(data){
.........................................
cloneObjects(stageObject)
...........................
});
}
function cloneObjects(stageObject){){
if(stageObject.name=="building"){
var building1=stageObject.clone();
..................
building1.location=[-85.0,0.0,170.0];
..........
stage.addModel(building1);
.....
}