ShockShapes/Scene.cpp
int Scene::save(const char *filename)
{
	char buf[128];
	time_t now;

	//Initialize the document root
	pugi::xml_document doc;
	pugi::xml_node collada_node = doc.append_child("COLLADA");
	collada_node.append_attribute("xmlns") = "http://www.collada.org/2008/03/COLLADASchema";
	collada_node.append_attribute("version") = "1.5.0";

	//Add an asset node
	pugi::xml_node asset_node = collada_node.append_child("asset");

	pugi::xml_node cont_node = asset_node.append_child("contributor");
	pugi::xml_node tool_node = cont_node.append_child("authoring_tool");
	tool_node.text() = VERSION_STRING;

	pugi::xml_node created_node = asset_node.append_child("created");
	pugi::xml_node modified_node = asset_node.append_child("modified");
	time(&now);
	strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));
	created_node.text() = buf;
	modified_node.text() = buf;

	pugi::xml_node unit_node = asset_node.append_child("unit");
	unit_node.append_attribute("meter") = 1.0f / units_per_meter;

	pugi::xml_node up_node = asset_node.append_child("up_axis");
	up_node.text() = "Y_UP";

	//Add the library of geometric objects and scenes
	pugi::xml_node lib_geometry = collada_node.append_child("library_geometries");
	pugi::xml_node lib_scenes = collada_node.append_child("library_visual_scenes");
	pugi::xml_node vscene_node = lib_scenes.append_child("visual_scene");
	vscene_node.append_attribute("id") = "DefaultScene";

	//Add the scene node
	pugi::xml_node scene_node = collada_node.append_child("scene");
	pugi::xml_node scene_inst_node = scene_node.append_child("instance_visual_scene");
	scene_inst_node.append_attribute("url") = "#DefaultScene";

	//Add each geometric object to the library and the scene
	int num_objects = objects.size();
	int id = 0;
	for(int i = 0; i < num_objects; i++) {
		if(objects[i]->saveGeometry(lib_geometry))
			return 1;

		if(objects[i]->isVisible() && objects[i]->saveInstance(vscene_node, &id, NULL))
			return 1;
	}

	//Write to the file
	if(!doc.save_file(filename))
		return 1;

	return 0;
}
//Save the scene to a COLLADA file
Save the scene to a COLLADA file
Save the scene to a COLLADA file
int Scene::save(const char *filename)
{
	char buf[128];
	time_t now;
	pugi::xml_document doc;
	pugi::xml_node collada_node = doc.append_child("COLLADA");
	collada_node.append_attribute("xmlns") = "http://www.collada.org/2008/03/COLLADASchema";
	collada_node.append_attribute("version") = "1.5.0";
	pugi::xml_node asset_node = collada_node.append_child("asset");
	pugi::xml_node cont_node = asset_node.append_child("contributor");
	pugi::xml_node tool_node = cont_node.append_child("authoring_tool");
	tool_node.text() = VERSION_STRING;
	pugi::xml_node created_node = asset_node.append_child("created");
	pugi::xml_node modified_node = asset_node.append_child("modified");
	time(&now);
	strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));
	created_node.text() = buf;
	modified_node.text() = buf;
	pugi::xml_node unit_node = asset_node.append_child("unit");
	unit_node.append_attribute("meter") = 1.0f / units_per_meter;
	pugi::xml_node up_node = asset_node.append_child("up_axis");
	up_node.text() = "Y_UP";
	pugi::xml_node lib_geometry = collada_node.append_child("library_geometries");
	pugi::xml_node lib_scenes = collada_node.append_child("library_visual_scenes");
	pugi::xml_node vscene_node = lib_scenes.append_child("visual_scene");
	vscene_node.append_attribute("id") = "DefaultScene";
	pugi::xml_node scene_node = collada_node.append_child("scene");
	pugi::xml_node scene_inst_node = scene_node.append_child("instance_visual_scene");
	scene_inst_node.append_attribute("url") = "#DefaultScene";
	int num_objects = objects.size();
	int id = 0;
	for(int i = 0; i < num_objects; i++) {
		if(objects[i]->saveGeometry(lib_geometry))
			return 1;
		if(objects[i]->isVisible() && objects[i]->saveInstance(vscene_node, &id, NULL))
			return 1;
	}
	if(!doc.save_file(filename))
		return 1;
	return 0;
}
int Scene :: save ( const char * filename ) { char buf [ 128 ] ; time_t now ; pugi :: xml_document doc ; pugi :: xml_node collada_node = doc . append_child ( " " ) ; collada_node . append_attribute ( " " ) = " " ; collada_node . append_attribute ( " " ) = " " ; pugi :: xml_node asset_node = collada_node . append_child ( " " ) ; pugi :: xml_node cont_node = asset_node . append_child ( " " ) ; pugi :: xml_node tool_node = cont_node . append_child ( " " ) ; tool_node . text ( ) = VERSION_STRING ; pugi :: xml_node created_node = asset_node . append_child ( " " ) ; pugi :: xml_node modified_node = asset_node . append_child ( " " ) ; time ( & now ) ; strftime ( buf , sizeof ( buf ) , " " , gmtime ( & now ) ) ; created_node . text ( ) = buf ; modified_node . text ( ) = buf ; pugi :: xml_node unit_node = asset_node . append_child ( " " ) ; unit_node . append_attribute ( " " ) = 1.0f / units_per_meter ; pugi :: xml_node up_node = asset_node . append_child ( " " ) ; up_node . text ( ) = " " ; pugi :: xml_node lib_geometry = collada_node . append_child ( " " ) ; pugi :: xml_node lib_scenes = collada_node . append_child ( " " ) ; pugi :: xml_node vscene_node = lib_scenes . append_child ( " " ) ; vscene_node . append_attribute ( " " ) = " " ; pugi :: xml_node scene_node = collada_node . append_child ( " " ) ; pugi :: xml_node scene_inst_node = scene_node . append_child ( " " ) ; scene_inst_node . append_attribute ( " " ) = " " ; int num_objects = objects . size ( ) ; int id = 0 ; for ( int i = 0 ; i < num_objects ; i ++ ) { if ( objects [ i ] -> saveGeometry ( lib_geometry ) ) return 1 ; if ( objects [ i ] -> isVisible ( ) && objects [ i ] -> saveInstance ( vscene_node , & id , NULL ) ) return 1 ; } if ( ! doc . save_file ( filename ) ) return 1 ; return 0 ; }
Save the scene to a COLLADA file
Save the scene to a COLLADA file
//Initialize the document root //Add an asset node //Add the library of geometric objects and scenes //Add the scene node //Add each geometric object to the library and the scene //Write to the file