createMesh method

dynamic createMesh(
  1. dynamic relationships,
  2. Map geometryMap,
  3. dynamic materialMap
)

Implementation

createMesh( relationships, Map geometryMap, materialMap ) {

	var model;
	var geometry = null;
	var material = null;
	var materials = [];

	// get geometry and materials(s) from connections
	relationships["children"].forEach( ( child ) {

		if ( geometryMap.containsKey( child["ID"] ) ) {

			geometry = geometryMap[ child["ID"] ];

		}

		if ( materialMap.containsKey( child["ID"] ) ) {

			materials.add( materialMap[child["ID"]] );

		}

	} );

	if ( materials.length > 1 ) {

		material = materials;

	} else if ( materials.length > 0 ) {

		material = materials[ 0 ];

	} else {

		material = new MeshPhongMaterial( { "color": 0xcccccc } );
		materials.add( material );

	}

	if ( geometry.attributes["color"] != null ) {

		materials.forEach( ( material ) {

			material.vertexColors = true;

		} );

	}

	if ( geometry.userData["FBX_Deformer"] != null ) {

		model = new SkinnedMesh( geometry, material );
		model.normalizeSkinWeights();

	} else {

		model = new Mesh( geometry, material );

	}

	return model;

}