示例#1
0
void ModelDesc::save(const std::string &filename)
{
	JsonValue json_animations = JsonValue::array();
	for (const auto &animation : animations)
	{
		JsonValue json_animation = JsonValue::object();
		json_animation["name"].set_string(animation.name);
		json_animation["start_frame"].set_number(animation.start_frame);
		json_animation["end_frame"].set_number(animation.end_frame);
		json_animation["play_speed"].set_number(animation.play_speed);
		json_animation["move_speed"].set_number(animation.move_speed);
		json_animation["loop"].set_boolean(animation.loop);
		json_animation["rarity"].set_number(animation.rarity);
		json_animations.items().push_back(json_animation);
	}

	JsonValue json_attachment_points = JsonValue::array();
	for (const auto &attachment : attachment_points)
	{
		JsonValue json_attachment = JsonValue::object();
		json_attachment["bone_name"].set_string(attachment.bone_name);
		json_attachment["name"].set_string(attachment.name);
		json_attachment["orientation"] = JsonValue::object();
		json_attachment["orientation"]["x"].set_number(attachment.orientation.x);
		json_attachment["orientation"]["y"].set_number(attachment.orientation.y);
		json_attachment["orientation"]["z"].set_number(attachment.orientation.z);
		json_attachment["orientation"]["w"].set_number(attachment.orientation.w);
		json_attachment["position"] = JsonValue::object();
		json_attachment["position"]["x"].set_number(attachment.position.x);
		json_attachment["position"]["y"].set_number(attachment.position.y);
		json_attachment["position"]["z"].set_number(attachment.position.z);
		json_attachment["test_model"].set_string(PathHelp::make_relative(PathHelp::get_fullpath(filename), attachment.test_model));
		json_attachment["test_scale"].set_number(attachment.test_scale);
		json_attachment_points.items().push_back(json_attachment);
	}

	JsonValue json_materials = JsonValue::array();
	for (const auto &material : materials)
	{
		JsonValue json_material = JsonValue::object();
		json_material["mesh_material"].set_string(material.mesh_material);
		json_material["transparent"].set_boolean(material.transparent);
		json_material["two_sided"].set_boolean(material.two_sided);
		json_material["alpha_test"].set_boolean(material.alpha_test);
		json_materials.items().push_back(json_material);
	}

	JsonValue json_emitters = JsonValue::array();

	JsonValue json = JsonValue::object();
	json["type"].set_string("fbx-model");
	json["version"].set_number(1);
	json["animations"] = json_animations;
	json["attachment_points"] = json_attachment_points;
	json["materials"] = json_materials;
	json["emitters"] = json_emitters;
	json["fbx_filename"].set_string(PathHelp::make_relative(PathHelp::get_fullpath(filename), fbx_filename));

	File::write_all_text(filename, json.to_json());
}