loadScene_new method

Future loadScene_new(
  1. int sceneIndex
)

Implementation

Future loadScene_new(int sceneIndex ) async{
	final extensions = this.extensions;
	final sceneDef = this.json['scenes'][ sceneIndex ] as Map;

	// Loader returns Group, not Scene.
	// See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
	final scene = new Group();

	if ( sceneDef['name'] != null) scene.name = createUniqueName( sceneDef['name'] );
	assignExtrasToUserData( scene, sceneDef );

	if ( sceneDef['extensions'] != null) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
	final nodeIds = sceneDef['nodes'] ?? [];
	final pending = [];

	for (int i = 0, il = nodeIds.length; i < il; i ++ ) {
		pending.add( await getDependency( 'node', nodeIds[ i ] ) );
	}

    for ( int i = 0, il = pending.length; i < il; i ++ ) {
      scene.add( pending[ i ] );
    }

    // Removes dangling associations, associations that reference a node that
    // didn't make it into the scene.
    final reduceAssociations = ( node ){
      final reducedAssociations = new Map();
      for ( final key in associations.keys) {
        if ( key is Material || key is Texture ) {
          reducedAssociations[key] =  associations[key];
        }
      }

      node.traverse(( node ){
        final mappings = parser.associations[node];
        if ( mappings != null ) {
          reducedAssociations[node] =  mappings;
        }
      } );

      return reducedAssociations;
    };

    parser.associations = reduceAssociations( scene );

    return scene;
}