size_t get_rendering_thread_count(const ParamArray& params) { const size_t core_count = System::get_logical_cpu_core_count(); static const char* ThreadCountParameterName = "rendering_threads"; if (!params.strings().exist(ThreadCountParameterName)) return core_count; const string thread_count_str = params.strings().get<string>(ThreadCountParameterName); if (thread_count_str == "auto") return core_count; bool conversion_failed = false; size_t thread_count; try { const int num_threads = from_string<int>(thread_count_str); if (num_threads < 0) { // If num_threads is negative, use all cores except -num_threads. thread_count = max(static_cast<int>(core_count) + num_threads, 1); } else thread_count = num_threads; } catch (const ExceptionStringConversionError&) { conversion_failed = true; } if (conversion_failed || thread_count == 0) { RENDERER_LOG_ERROR( "invalid value \"%s\" for parameter \"%s\", using default value \"%s\".", thread_count_str.c_str(), ThreadCountParameterName, "auto"); return core_count; } return thread_count; }
size_t FrameRendererBase::get_rendering_thread_count(const ParamArray& params) { const size_t core_count = System::get_logical_cpu_core_count(); static const char* ThreadCountParameterName = "rendering_threads"; if (!params.strings().exist(ThreadCountParameterName)) return core_count; const string thread_count_str = params.strings().get<string>(ThreadCountParameterName); if (thread_count_str == "auto") return core_count; bool conversion_failed = false; size_t thread_count; try { thread_count = from_string<size_t>(thread_count_str); } catch (const ExceptionStringConversionError&) { conversion_failed = true; } if (conversion_failed || thread_count == 0) { RENDERER_LOG_ERROR( "invalid value \"%s\" for parameter \"%s\", using default value \"%s\".", thread_count_str.c_str(), ThreadCountParameterName, "auto"); return core_count; } return thread_count; }
Impl( const char* type, const char* shader, const char* layer, const ParamArray& params) : m_type(type) , m_shader(shader) { for (const_each<StringDictionary> i = params.strings(); i; ++i) { try { ShaderParamParser parser(i.it().value()); switch (parser.param_type()) { case OSLParamTypeColor: { float r, g, b; parser.parse_three_values<float>(r, g, b, true); m_params.insert(ShaderParam::create_color_param(i.it().key(), r, g, b)); } break; case OSLParamTypeColorArray: { vector<float> values; parser.parse_float3_array(values); m_params.insert(ShaderParam::create_color_array_param(i.it().key(), values)); } break; case OSLParamTypeFloat: { const float val = parser.parse_one_value<float>(); m_params.insert(ShaderParam::create_float_param(i.it().key(), val)); } break; case OSLParamTypeFloatArray: { vector<float> values; parser.parse_float_array(values); m_params.insert(ShaderParam::create_float_array_param(i.it().key(), values)); } break; case OSLParamTypeInt: { const int val = parser.parse_one_value<int>(); m_params.insert(ShaderParam::create_int_param(i.it().key(), val)); } break; case OSLParamTypeMatrix: { float val[16]; parser.parse_n_values(16, val); m_params.insert(ShaderParam::create_matrix_param(i.it().key(), val)); } break; case OSLParamTypeNormal: { float x, y, z; parser.parse_three_values<float>(x, y, z); m_params.insert(ShaderParam::create_normal_param(i.it().key(), x, y, z)); } break; case OSLParamTypeNormalArray: { vector<float> values; parser.parse_float3_array(values); m_params.insert(ShaderParam::create_normal_array_param(i.it().key(), values)); } break; case OSLParamTypePoint: { float x, y, z; parser.parse_three_values<float>(x, y, z); m_params.insert(ShaderParam::create_point_param(i.it().key(), x, y, z)); } break; case OSLParamTypePointArray: { vector<float> values; parser.parse_float3_array(values); m_params.insert(ShaderParam::create_point_array_param(i.it().key(), values)); } break; case OSLParamTypeString: { m_params.insert( ShaderParam::create_string_param( i.it().key(), parser.parse_string_value().c_str())); } break; case OSLParamTypeVector: { float x, y, z; parser.parse_three_values<float>(x, y, z); m_params.insert(ShaderParam::create_vector_param(i.it().key(), x, y, z)); } break; case OSLParamTypeVectorArray: { vector<float> values; parser.parse_float3_array(values); m_params.insert(ShaderParam::create_vector_array_param(i.it().key(), values)); } break; default: RENDERER_LOG_ERROR( "error adding OSL param %s, of unknown type %s; will use the default value.", i.it().key(), i.it().value()); break; } } catch (const ExceptionOSLParamParseError&) { RENDERER_LOG_ERROR( "error parsing OSL param value, param = %s, value = %s; will use the default value.", i.it().key(), i.it().value()); } } }
void MaterialCollectionItem::slot_import_disney() { #ifdef APPLESEED_WITH_DISNEY_MATERIAL QString filepath = get_open_filename( 0, "Import...", "Disney Material (*.dmt);;All Files (*.*)", m_editor_context.m_settings, SETTINGS_FILE_DIALOG_PROJECTS); if (!filepath.isEmpty()) { filepath = QDir::toNativeSeparators(filepath); const bf::path root_path(Application::get_root_path()); const bf::path schema_file_path = root_path / "schemas" / "settings.xsd"; SettingsFileReader reader(global_logger()); ParamArray parameters; const bool success = reader.read( filepath.toStdString().c_str(), schema_file_path.string().c_str(), parameters); if (!success) { show_error_message_box( "Importing Error", "Failed to import the Disney Material file " + filepath.toStdString()); return; } string name = parameters.get("__name"); const string model = parameters.get("__model"); parameters.strings().remove("__name"); parameters.strings().remove("__model"); if (model != "disney_material") { show_error_message_box( "Importing Error", "Material model " + model + " is not supported."); return; } // If there is already a material with the same name, rename the imported material. for (const_each<MaterialContainer> i = m_parent.materials(); i; ++i) { if (strcmp(i->get_name(), name.c_str()) == 0) { name = make_unique_name(name, m_parent.materials()); break; } } auto_release_ptr<Material> material = DisneyMaterialFactory().create(name.c_str(), parameters); Material* material_ptr = material.get(); add_item(material_ptr); EntityTraits<Material>::insert_entity(material, m_parent); m_editor_context.m_project_builder.notify_project_modification(); m_editor_context.m_project_explorer.select_entity(material_ptr->get_uid()); } #endif }