rapidjson::Document SceneConvertor::Convert( const Scene* scene )
{
	Document json;
	json.SetObject();
	Document::AllocatorType& al = json.GetAllocator();

	
	json.AddMember( "FILE_TYPE",		"SCENE",							al );

	Value stringNode;
	Value nullNode;
	nullNode.SetNull();

	Material* skyboxMat = scene->GetSkyboxMaterial();
	if (skyboxMat != NULL)
	{
		stringNode.SetString( skyboxMat->GetName().ToChar(),				al );
		json.AddMember( "skyboxMaterial",	stringNode,						al );
	}
	else
	{
		json.AddMember( "skyboxMaterial",	nullNode,						al );
	}

	json.AddMember( "skyboxSize",	scene->GetSkyboxSize(),					al );

	Value vec3Node = _Vec3_to_JSON( scene->GetAmbientLight(), al );
	json.AddMember( "ambientLight",	vec3Node,								al );

		
	if ( scene->GetMainCamera() != NULL )
	{
		stringNode.SetString( scene->GetMainCamera()->GetName().ToChar(),	al );
		json.AddMember( "mainCamera",	stringNode,							al );
	}
	else
	{
		json.AddMember( "mainCamera",	nullNode,							al );
	}

	Value arrayNode;
	arrayNode.SetArray();
	for (uint i = 0; i < scene->GetGameObjectCount(); ++i)
	{
		GameObject* gameObject = scene->GetGameObjectAt(i);
		if ( gameObject->GetParentNode() == NULL && (_useAll || gameObject->IsSavable()) )
		{
			arrayNode.PushBack( _GameObject_to_JSON(gameObject, al),		al );
		}
	}

	json.AddMember( "gameObjects",		arrayNode,							al );


	return json;
}
void HierarchyWindow::Initialize()
{
	// delete all items
	while ( _qtTree->topLevelItemCount() > 0 )
	{
		_qtTree->takeTopLevelItem(0);
	}


	Scene* scene = Systems::Scene()->GetCurrentScene();
	QTreeWidgetItem* rootItem = _qtTree->invisibleRootItem();

	for (uint i = 0; i < scene->GetGameObjectCount(); ++i)
	{
		GameObject* gameObject = scene->GetGameObjectAt(i);

		if ( gameObject->GetParentNode() == NULL )
		{
			_DisplayHierarchy( gameObject, rootItem );
		}
	}
}