void Scene::initialize(Display::Draw* _draw,Input::Input* _input,Tim::ThreadPool *_thread_pool){ input=_input; thread_pool=_thread_pool; draw=_draw; receiver=new Input::Receiver(scene_name()); input->push_receiver(receiver); scene_initialize(); }
void DocumentExporter::exportCurrentScene(Scene *sce) { PointerRNA sceneptr, unit_settings; PropertyRNA *system; /* unused , *scale; */ clear_global_id_map(); COLLADABU::NativeString native_filename = COLLADABU::NativeString(std::string(this->export_settings->filepath), COLLADABU::NativeString::ENCODING_UTF8); COLLADASW::StreamWriter sw(native_filename); fprintf(stdout, "Collada export: %s\n", this->export_settings->filepath); // open <collada> sw.startDocument(); // <asset> COLLADASW::Asset asset(&sw); RNA_id_pointer_create(&(sce->id), &sceneptr); unit_settings = RNA_pointer_get(&sceneptr, "unit_settings"); system = RNA_struct_find_property(&unit_settings, "system"); //scale = RNA_struct_find_property(&unit_settings, "scale_length"); std::string unitname = "meter"; float linearmeasure = RNA_float_get(&unit_settings, "scale_length"); switch (RNA_property_enum_get(&unit_settings, system)) { case USER_UNIT_NONE: case USER_UNIT_METRIC: if (linearmeasure == 0.001f) { unitname = "millimeter"; } else if (linearmeasure == 0.01f) { unitname = "centimeter"; } else if (linearmeasure == 0.1f) { unitname = "decimeter"; } else if (linearmeasure == 1.0f) { unitname = "meter"; } else if (linearmeasure == 1000.0f) { unitname = "kilometer"; } break; case USER_UNIT_IMPERIAL: if (linearmeasure == 0.0254f) { unitname = "inch"; } else if (linearmeasure == 0.3048f) { unitname = "foot"; } else if (linearmeasure == 0.9144f) { unitname = "yard"; } break; default: break; } asset.setUnit(unitname, linearmeasure); asset.setUpAxisType(COLLADASW::Asset::Z_UP); if (U.author[0] != '\0') { asset.getContributor().mAuthor = U.author; } else { asset.getContributor().mAuthor = "Blender User"; } char version_buf[128]; #ifdef WITH_BUILDINFO sprintf(version_buf, "Blender %d.%02d.%d r%s", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION, build_rev); #else sprintf(version_buf, "Blender %d.%02d.%d", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION); #endif asset.getContributor().mAuthoringTool = version_buf; asset.add(); LinkNode *export_set = this->export_settings->export_set; // <library_cameras> if (bc_has_object_type(export_set, OB_CAMERA)) { CamerasExporter ce(&sw, this->export_settings); ce.exportCameras(sce); } // <library_lights> if (bc_has_object_type(export_set, OB_LAMP)) { LightsExporter le(&sw, this->export_settings); le.exportLights(sce); } // <library_images> ImagesExporter ie(&sw, this->export_settings); ie.exportImages(sce); // <library_effects> EffectsExporter ee(&sw, this->export_settings); ee.exportEffects(sce); // <library_materials> MaterialsExporter me(&sw, this->export_settings); me.exportMaterials(sce); // <library_geometries> if (bc_has_object_type(export_set, OB_MESH)) { GeometryExporter ge(&sw, this->export_settings); ge.exportGeom(sce); } // <library_animations> AnimationExporter ae(&sw, this->export_settings); ae.exportAnimations(sce); // <library_controllers> ArmatureExporter arm_exporter(&sw, this->export_settings); if (bc_has_object_type(export_set, OB_ARMATURE)) { arm_exporter.export_controllers(sce); } // <library_visual_scenes> SceneExporter se(&sw, &arm_exporter, this->export_settings); se.exportScene(sce); // <scene> std::string scene_name(translate_id(id_name(sce))); COLLADASW::Scene scene(&sw, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, scene_name)); scene.add(); // close <Collada> sw.endDocument(); }
bool scene::load (const std::string& Scene) { // try opening scene TiXmlDocument xml_shader(Scene.c_str()); if (!xml_shader.LoadFile()) { log() << error << "couldn't load shader " << Scene << ", is it a valid XML file?" << std::endl; return false; } // start parsing basic shader information std::string scene_name (""); std::string scene_description (""); std::string scene_authors (""); TiXmlNode* network_xml_node = 0; for (TiXmlAttribute* a = xml_shader.FirstChild()->ToElement()->FirstAttribute(); a; a = a->Next()) { // parse attributes const std::string name (a->Name()); if (name == "name") { scene_name = a->Value(); } else if (name == "authors") { scene_authors = a->Value(); } else { log() << error << "unhandled shader attribute : '" << name << "'" << std::endl; } } for (TiXmlNode* c = xml_shader.FirstChild()->FirstChild(); c; c = c->NextSibling()) { // parse child nodes const std::string element (c->Value()); if(element == "about") { if (c->FirstChild()) { scene_description = c->FirstChild()->ToText()->Value(); } } else if(element == "network") { network_xml_node = c; } else { log() << error << "unknown shader element '" << element << "' in " << Scene << std::endl; } } if (!network_xml_node) { log() << error << "no network block found in '" << Scene << "'." << std::endl; return false; } // scene could be loaded, initialize empty_scene(); // start loading content m_name = scene_name; set_description (scene_description); m_authors = scene_authors; log() << aspect << "loading shader '" << m_name << "'" << std::endl; // load blocks for (TiXmlNode* e = network_xml_node->FirstChild(); e; e = e->NextSibling()) { const std::string element (e->Value()); if(element == "block") { xml::attributes_t attributes; xml::get_attributes (*e->ToElement(), attributes); std::string id; if (!xml::get_attribute (*e->ToElement(), "id", id)) { log() << error << "block has undefined 'id' attribute." << std::endl; continue; } bool root_block = false; std::string root_value (""); if (xml::get_attribute (*e->ToElement(), "root", root_value)) { root_block = true; } bool rolled_block = false; std::string rolled_value (""); if (xml::get_attribute (*e->ToElement(), "rolled", rolled_value)) { rolled_block = true; } std::string position_sx; std::string position_sy; xml::get_attribute (*e->ToElement(), "position_x", position_sx); xml::get_attribute (*e->ToElement(), "position_y", position_sy); double position_x = 0; double position_y = 0; std::istringstream stream_x (position_sx.c_str()); stream_x >> position_x; std::istringstream stream_y (position_sy.c_str()); stream_y >> position_y; // create block shader_block* new_block = 0; if (!root_block) { new_block = new shader_block (id, ""); } else { //if (root_value == "RIB") { m_rib_root_block = new rib_root_block (id, this, m_system_functions, preferences); new_block = m_rib_root_block; for (TiXmlNode* c = e->FirstChild(); c; c = c->NextSibling()) { const std::string element (c->Value()); if (element == "rib_statements") { if (c->FirstChild()) { const std::string statements = c->FirstChild()->ToText()->Value(); m_rib_root_block->set_general_statements (trim (statements) + "\n"); } } else if (element == "imager_statement") { if (c->FirstChild()) { const std::string statement = c->FirstChild()->ToText()->Value(); m_rib_root_block->set_imager_statement (trim (statement)); } } /* else if (element == "AOV_preview") { if (c->FirstChild()) { const std::string AOV_preview = a->Value(); m_rib_root_block->set_AOV (!state.empty()); } } */ } //} } add_block (id, "", new_block); new_block->set_name (id); new_block->set_position (position_x, position_y); if (rolled_block) { set_block_rolled_state (new_block, true); } // load input and output properties if (!root_block) { new_block->load_from_xml (*e); } } else if (element == "group") {