Skip to content

Commit

Permalink
* enable loading of nested scene graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Zerbst committed Aug 2, 2012
1 parent 1d590a4 commit 4513a83
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/loaders/SceneLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,37 @@ THREE.SceneLoader.prototype.createScene = function ( json, callbackFinished, url
}

};

function handle_objects() {

var object;

for( dd in data.objects ) {

// the toplevel loader function, delegates to handle_children
function handle_objects() {

console.log("handle_objects");

var parentNode=result.scene;
var children = data.objects;

handle_children( parentNode, children);
}

// the loading function to load all children of one node
// parentNode: the node to attach the children to, either the scene itself or Object3D
// children: the list of children to handle
function handle_children( parentNode, childrenVar) {

console.log("handle_children", parentNode, childrenVar);

var object;

for( dd in childrenVar ) {
console.log("dd : ", dd);
console.log("children ", childrenVar[dd].children);
console.log("check", !result.objects[ dd ] , " ", result.objects[ dd ] );

// check by id if child has already been handled,
// if not, create new objec
if ( !result.objects[ dd ] ) {

o = data.objects[ dd ];
o = childrenVar[ dd ];
console.log("o : ", o);

if ( o.geometry !== undefined ) {

Expand Down Expand Up @@ -215,7 +236,7 @@ THREE.SceneLoader.prototype.createScene = function ( json, callbackFinished, url
object.castShadow = o.castShadow;
object.receiveShadow = o.receiveShadow;

result.scene.add( object );
parentNode.add( object );

result.objects[ dd ] = object;

Expand Down Expand Up @@ -252,12 +273,20 @@ THREE.SceneLoader.prototype.createScene = function ( json, callbackFinished, url
object.scale.set( s[0], s[1], s[2] );
object.visible = ( o.visible !== undefined ) ? o.visible : false;

result.scene.add( object );
parentNode.add( object );

result.objects[ dd ] = object;
result.empties[ dd ] = object;

}

// recursive descend if necessary
if ( o.children !== undefined ) {
console.log("add children of ", dd);
handle_children( object, o.children);
} else {
console.log("no children of ", dd);
}

}

Expand Down

0 comments on commit 4513a83

Please sign in to comment.