parseGeoNode method

dynamic parseGeoNode(
  1. Map geoNode,
  2. dynamic skeleton
)

Implementation

parseGeoNode( Map geoNode, skeleton ) {

	var geoInfo = {};

	geoInfo["vertexPositions"] = ( geoNode["Vertices"] != null ) ? geoNode["Vertices"]["a"] : [];
	geoInfo["vertexIndices"] = ( geoNode["PolygonVertexIndex"] != null ) ? geoNode["PolygonVertexIndex"]["a"] : [];

	if ( geoNode["LayerElementColor"] != null ) {

		geoInfo["color"] = this.parseVertexColors( geoNode["LayerElementColor"][ 0 ] );

	}

	if ( geoNode["LayerElementMaterial"] != null ) {

		geoInfo["material"] = this.parseMaterialIndices( geoNode["LayerElementMaterial"][ 0 ] );

	}

	if ( geoNode["LayerElementNormal"] != null ) {

		geoInfo["normal"] = this.parseNormals( geoNode["LayerElementNormal"][ 0 ] );

	}

	if ( geoNode["LayerElementUV"] != null ) {

		geoInfo["uv"] = [];

		var i = 0;
		while ( geoNode["LayerElementUV"][ i ] != null ) {

			if ( geoNode["LayerElementUV"][ i ]["UV"] != null ) {

				geoInfo["uv"].add( this.parseUVs( geoNode["LayerElementUV"][ i ] ) );

			}

			i ++;

		}

	}

	geoInfo["weightTable"] = {};

	if ( skeleton != null ) {

		geoInfo["skeleton"] = skeleton;


		if( skeleton["rawBones"] != null ) skeleton["rawBones"].asMap().forEach( ( i, rawBone ) {

			// loop over the bone's vertex indices and weights
			rawBone["indices"].asMap().forEach(  ( j, index ) {

				if ( geoInfo["weightTable"][ index ] == null ) geoInfo["weightTable"][ index ] = [];

				geoInfo["weightTable"][ index ].add( {

					"id": i,
					"weight": rawBone["weights"][ j ],

				} );

			} );

		} );

	}

	return geoInfo;

}