diff options
47 files changed, 1310 insertions, 838 deletions
diff --git a/build_files/build_environment/install_deps.sh b/build_files/build_environment/install_deps.sh index 6b9ac8f00fc..b3d659313d4 100755 --- a/build_files/build_environment/install_deps.sh +++ b/build_files/build_environment/install_deps.sh @@ -3342,7 +3342,15 @@ install_ARCH() { OGG_DEV="libogg" THEORA_DEV="libtheora" - _packages="base-devel git cmake \ + BASE_DEVEL="base-devel" + + # Avoid conflicts when gcc-multilib is installed + pacman -Qi gcc-multilib &>/dev/null + if [ $? -eq 0 ]; then + BASE_DEVEL=`pacman -Sgq base-devel | sed -e 's/^gcc$/gcc-multilib/g' | paste -s -d' '` + fi + + _packages="$BASE_DEVEL git cmake \ libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \ $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw intel-tbb \ libxml2 yaml-cpp tinyxml python-requests jemalloc" diff --git a/doc/python_api/rst/bge_types/bge.types.KX_LightObject.rst b/doc/python_api/rst/bge_types/bge.types.KX_LightObject.rst index 5ba7f3b8e34..6748df13873 100644 --- a/doc/python_api/rst/bge_types/bge.types.KX_LightObject.rst +++ b/doc/python_api/rst/bge_types/bge.types.KX_LightObject.rst @@ -60,37 +60,37 @@ base class --- :class:`KX_GameObject` :type: float (read only) - ..attribute:: shadowFrustumSize + .. attribute:: shadowFrustumSize Size of the frustum used for creating the shadowmap. :type: float (read only) - ..attribute:: shadowBindId + .. attribute:: shadowBindId The OpenGL shadow texture bind number/id. :type: int (read only) - ..attribute:: shadowMapType + .. attribute:: shadowMapType The shadow shadow map type (0 -> Simple; 1 -> Variance) :type: int (read only) - ..attribute:: shadowBias + .. attribute:: shadowBias The shadow buffer sampling bias. :type: float (read only) - ..attribute:: shadowBleedBias + .. attribute:: shadowBleedBias The bias for reducing light-bleed on variance shadow maps. :type: float (read only) - ..attribute:: useShadow + .. attribute:: useShadow Returns True if the light has Shadow option activated, else returns False. diff --git a/extern/curve_fit_nd/intern/curve_fit_cubic.c b/extern/curve_fit_nd/intern/curve_fit_cubic.c index b97763460a3..473e4ca5b8c 100644 --- a/extern/curve_fit_nd/intern/curve_fit_cubic.c +++ b/extern/curve_fit_nd/intern/curve_fit_cubic.c @@ -429,14 +429,43 @@ static double points_calc_circumference_factor( * (tangents that point away from each other). * We could try support this but will likely cause extreme >1 scales which could cause other issues. */ // assert(angle >= len_tangent); - double factor = (angle / len_tangent) / (M_PI / 2); - factor = 1.0 - pow(1.0 - factor, 1.75); - assert(factor < 1.0 + DBL_EPSILON); + double factor = (angle / len_tangent); + assert(factor < (M_PI / 2) + DBL_EPSILON); return factor; } else { /* tangents are exactly aligned (think two opposite sides of a circle). */ - return 1.0; + return (M_PI / 2); + } +} + +/** + * Return the value which the distance between points will need to be scaled by, + * to define a handle, given both points are on a perfect circle. + * + * \note the return value will need to be multiplied by 1.3... for correct results. + */ +static double points_calc_circle_tangent_factor( + const double tan_l[], + const double tan_r[], + const uint dims) +{ + const double angle_sin = len_vnvn(tan_l, tan_r, dims) / 2.0; + if (angle_sin != 0.0) { + const double tan_dot = dot_vnvn(tan_l, tan_r, dims); + double scale; + if (tan_dot > -1.0) { + const double angle = acos(tan_dot) / 2.0; + const double angle_cos = cos(angle); + scale = (1.0 - angle_cos) / (angle_sin * 2.0); + } + else { + scale = 1.0 / 2.0; + } + return (scale / angle_sin); + } + else { + return (1.0 / 3.0) * 0.75; } } @@ -451,9 +480,20 @@ static double points_calc_cubic_scale( const double coords_length, uint dims) { const double len_direct = len_vnvn(v_l, v_r, dims); - const double len_circle_factor = points_calc_circumference_factor(tan_l, tan_r, dims) * 1.75; - const double len_points = min(coords_length, len_circle_factor * len_direct); - return (len_direct + ((len_points - len_direct) * len_circle_factor)) / 3.0; + const double len_circle_factor = points_calc_circle_tangent_factor(tan_l, tan_r, dims); + + /* if this curve is a circle, this value doesn't need modification */ + const double len_circle_handle = (len_direct * (len_circle_factor / 0.75)); + + /* scale by the difference from the circumference distance */ + const double len_circle = len_direct * points_calc_circumference_factor(tan_l, tan_r, dims); + double scale_handle = (coords_length / len_circle); + + /* Could investigate an accurate calculation here, + * though this gives close results */ + scale_handle = ((scale_handle - 1.0) * 1.75) + 1.0; + + return len_circle_handle * scale_handle; } static void cubic_from_points_fallback( diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h index 7fc8d2b5706..46bef96dc3f 100644 --- a/intern/cycles/kernel/kernel_compat_cpu.h +++ b/intern/cycles/kernel/kernel_compat_cpu.h @@ -109,6 +109,12 @@ template<typename T> struct texture_image { return make_float4(r.x*f, r.y*f, r.z*f, r.w*f); } + ccl_always_inline float4 read(uchar r) + { + float f = r*(1.0f/255.0f); + return make_float4(f, f, f, 1.0); + } + ccl_always_inline float4 read(float r) { /* TODO(dingto): Optimize this, so interpolation @@ -479,6 +485,7 @@ typedef texture<int> texture_int; typedef texture<uint4> texture_uint4; typedef texture<uchar4> texture_uchar4; typedef texture_image<float> texture_image_float; +typedef texture_image<uchar> texture_image_uchar; typedef texture_image<float4> texture_image_float4; typedef texture_image<uchar4> texture_image_uchar4; @@ -490,17 +497,20 @@ typedef texture_image<uchar4> texture_image_uchar4; #define kernel_tex_lookup(tex, t, offset, size) (kg->tex.lookup(t, offset, size)) #define kernel_tex_image_interp(tex, x, y) \ - ((tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp(x, y) : \ + ((tex >= TEX_IMAGE_BYTE_START_CPU) ? kg->texture_byte_images[tex - TEX_IMAGE_BYTE_START_CPU].interp(x, y) : \ + (tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp(x, y) : \ (tex >= TEX_IMAGE_BYTE4_START_CPU) ? kg->texture_byte4_images[tex - TEX_IMAGE_BYTE4_START_CPU].interp(x, y) : \ kg->texture_float4_images[tex].interp(x, y)) #define kernel_tex_image_interp_3d(tex, x, y, z) \ - ((tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp_3d(x, y, z) : \ + ((tex >= TEX_IMAGE_BYTE_START_CPU) ? kg->texture_byte_images[tex - TEX_IMAGE_BYTE_START_CPU].interp_3d(x, y, z) : \ + (tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp_3d(x, y, z) : \ (tex >= TEX_IMAGE_BYTE4_START_CPU) ? kg->texture_byte4_images[tex - TEX_IMAGE_BYTE4_START_CPU].interp_3d(x, y, z) : \ kg->texture_float4_images[tex].interp_3d(x, y, z)) #define kernel_tex_image_interp_3d_ex(tex, x, y, z, interpolation) \ - ((tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp_3d_ex(x, y, z, interpolation) : \ + ((tex >= TEX_IMAGE_BYTE_START_CPU) ? kg->texture_byte_images[tex - TEX_IMAGE_BYTE_START_CPU].interp_3d_ex(x, y, z, interpolation) : \ + (tex >= TEX_IMAGE_FLOAT_START_CPU) ? kg->texture_float_images[tex - TEX_IMAGE_FLOAT_START_CPU].interp_3d_ex(x, y, z, interpolation) : \ (tex >= TEX_IMAGE_BYTE4_START_CPU) ? kg->texture_byte4_images[tex - TEX_IMAGE_BYTE4_START_CPU].interp_3d_ex(x, y, z, interpolation) : \ kg->texture_float4_images[tex].interp_3d_ex(x, y, z, interpolation)) diff --git a/intern/cycles/kernel/kernel_globals.h b/intern/cycles/kernel/kernel_globals.h index 3af44e06179..c44ea1b051f 100644 --- a/intern/cycles/kernel/kernel_globals.h +++ b/intern/cycles/kernel/kernel_globals.h @@ -35,6 +35,7 @@ typedef struct KernelGlobals { texture_image_uchar4 texture_byte4_images[TEX_NUM_BYTE4_IMAGES_CPU]; texture_image_float4 texture_float4_images[TEX_NUM_FLOAT4_IMAGES_CPU]; texture_image_float texture_float_images[TEX_NUM_FLOAT_IMAGES_CPU]; + texture_image_uchar texture_byte_images[TEX_NUM_BYTE_IMAGES_CPU]; # define KERNEL_TEX(type, ttype, name) ttype name; # define KERNEL_IMAGE_TEX(type, ttype, name) diff --git a/intern/cycles/kernel/kernels/cpu/kernel.cpp b/intern/cycles/kernel/kernels/cpu/kernel.cpp index 960012e95e3..365ce891354 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel.cpp +++ b/intern/cycles/kernel/kernels/cpu/kernel.cpp @@ -138,6 +138,22 @@ void kernel_tex_copy(KernelGlobals *kg, tex->extension = extension; } } + else if(strstr(name, "__tex_image_byte")) { + texture_image_uchar *tex = NULL; + int id = atoi(name + strlen("__tex_image_byte_")); + int array_index = id - TEX_IMAGE_BYTE_START_CPU; + + if(array_index >= 0 && array_index < TEX_NUM_BYTE_IMAGES_CPU) { + tex = &kg->texture_byte_images[array_index]; + } + + if(tex) { + tex->data = (uchar*)mem; + tex->dimensions_set(width, height, depth); + tex->interpolation = interpolation; + tex->extension = extension; + } + } else assert(0); } diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp index 0d62c1b72de..558f5e59342 100644 --- a/intern/cycles/render/buffers.cpp +++ b/intern/cycles/render/buffers.cpp @@ -194,13 +194,13 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int else if(type == PASS_BVH_TRAVERSAL_STEPS) { for(int i = 0; i < size; i++, in += pass_stride, pixels++) { float f = *in; - pixels[0] = f; + pixels[0] = f*scale; } } else if(type == PASS_RAY_BOUNCES) { for(int i = 0; i < size; i++, in += pass_stride, pixels++) { float f = *in; - pixels[0] = f; + pixels[0] = f*scale; } } #endif diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 0985cca5bb6..898e00fdcd9 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -43,40 +43,50 @@ ImageManager::ImageManager(const DeviceInfo& info) tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CPU; tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CPU; tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CPU; + tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CPU; tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CPU; tex_image_float_start = TEX_IMAGE_FLOAT_START_CPU; + tex_image_byte_start = TEX_IMAGE_BYTE_START_CPU; } /* CUDA (Fermi) */ else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && !info.extended_images) { tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA; tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA; tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA; + tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA; tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA; tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA; + tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA; } /* CUDA (Kepler and above) */ else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && info.extended_images) { tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER; tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER; tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_CUDA_KEPLER; + tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_CUDA_KEPLER; tex_image_byte4_start = TEX_IMAGE_BYTE4_START_CUDA_KEPLER; tex_image_float_start = TEX_IMAGE_FLOAT_START_CUDA_KEPLER; + tex_image_byte_start = TEX_IMAGE_BYTE_START_CUDA_KEPLER; } /* OpenCL */ else if(info.pack_images) { tex_num_images[IMAGE_DATA_TYPE_BYTE4] = TEX_NUM_BYTE4_IMAGES_OPENCL; tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = TEX_NUM_FLOAT4_IMAGES_OPENCL; tex_num_images[IMAGE_DATA_TYPE_FLOAT] = TEX_NUM_FLOAT_IMAGES_OPENCL; + tex_num_images[IMAGE_DATA_TYPE_BYTE] = TEX_NUM_BYTE_IMAGES_OPENCL; tex_image_byte4_start = TEX_IMAGE_BYTE4_START_OPENCL; tex_image_float_start = TEX_IMAGE_FLOAT_START_OPENCL; + tex_image_byte_start = TEX_IMAGE_BYTE_START_OPENCL; } /* Should never happen */ else { tex_num_images[IMAGE_DATA_TYPE_BYTE4] = 0; tex_num_images[IMAGE_DATA_TYPE_FLOAT4] = 0; tex_num_images[IMAGE_DATA_TYPE_FLOAT] = 0; + tex_num_images[IMAGE_DATA_TYPE_BYTE] = 0; tex_image_byte4_start = 0; tex_image_float_start = 0; + tex_image_byte_start = 0; assert(0); } } @@ -137,8 +147,13 @@ ImageManager::ImageDataType ImageManager::get_image_metadata(const string& filen else return IMAGE_DATA_TYPE_FLOAT; } - else - return IMAGE_DATA_TYPE_BYTE4; + else { + if(channels > 1) + return IMAGE_DATA_TYPE_BYTE4; + else + return IMAGE_DATA_TYPE_BYTE; + } + } ImageInput *in = ImageInput::create(filename); @@ -192,12 +207,16 @@ ImageManager::ImageDataType ImageManager::get_image_metadata(const string& filen else return IMAGE_DATA_TYPE_FLOAT; } - else - return IMAGE_DATA_TYPE_BYTE4; + else { + if(channels > 1) + return IMAGE_DATA_TYPE_BYTE4; + else + return IMAGE_DATA_TYPE_BYTE; + } } /* We use a consecutive slot counting scheme on the devices, in order - * float4, byte4, float. + * float4, byte4, float, byte. * These functions convert the slot ids from ImageManager "images" ones * to device ones and vice versa. */ int ImageManager::type_index_to_flattened_slot(int slot, ImageDataType type) @@ -206,14 +225,19 @@ int ImageManager::type_index_to_flattened_slot(int slot, ImageDataType type) return slot + tex_image_byte4_start; else if(type == IMAGE_DATA_TYPE_FLOAT) return slot + tex_image_float_start; + else if(type == IMAGE_DATA_TYPE_BYTE) + return slot + tex_image_byte_start; else return slot; } int ImageManager::flattened_slot_to_type_index(int flat_slot, ImageDataType *type) { - if(flat_slot >= tex_image_float_start) - { + if(flat_slot >= tex_image_byte_start) { + *type = IMAGE_DATA_TYPE_BYTE; + return flat_slot - tex_image_byte_start; + } + else if(flat_slot >= tex_image_float_start) { *type = IMAGE_DATA_TYPE_FLOAT; return flat_slot - tex_image_float_start; } @@ -233,6 +257,8 @@ string ImageManager::name_from_type(int type) return "float4"; else if(type == IMAGE_DATA_TYPE_FLOAT) return "float"; + else if(type == IMAGE_DATA_TYPE_BYTE) + return "byte"; else return "byte4"; } @@ -268,18 +294,20 @@ int ImageManager::add_image(const string& filename, if(type == IMAGE_DATA_TYPE_FLOAT || type == IMAGE_DATA_TYPE_FLOAT4) is_float = true; - /* No float textures on GPU yet */ + /* No float and byte textures on GPU yet */ if(type == IMAGE_DATA_TYPE_FLOAT && tex_num_images[type] == 0) type = IMAGE_DATA_TYPE_FLOAT4; + if(type == IMAGE_DATA_TYPE_BYTE && tex_num_images[type] == 0) + type = IMAGE_DATA_TYPE_BYTE4; /* Fnd existing image. */ for(slot = 0; slot < images[type].size(); slot++) { img = images[type][slot]; if(img && image_equals(img, - filename, - builtin_data, - interpolation, - extension)) + filename, + builtin_data, + interpolation, + extension)) { if(img->frame != frame) { img->frame = frame; @@ -358,10 +386,10 @@ void ImageManager::remove_image(const string& filename, for(int type = 0; type < IMAGE_DATA_NUM_TYPES; type++) { for(slot = 0; slot < images[type].size(); slot++) { if(images[type][slot] && image_equals(images[type][slot], - filename, - builtin_data, - interpolation, - extension)) + filename, + builtin_data, + interpolation, + extension)) { remove_image(type_index_to_flattened_slot(slot, (ImageDataType)type)); return; @@ -382,10 +410,10 @@ void ImageManager::tag_reload_image(const string& filename, for(size_t type = 0; type < IMAGE_DATA_NUM_TYPES; type++) { for(size_t slot = 0; slot < images[type].size(); slot++) { if(images[type][slot] && image_equals(images[type][slot], - filename, - builtin_data, - interpolation, - extension)) + filename, + builtin_data, + interpolation, + extension)) { images[type][slot]->need_load = true; break; @@ -466,10 +494,10 @@ bool ImageManager::file_load_byte4_image(Image *img, device_vector<uchar4>& tex_ int scanlinesize = width*components*sizeof(uchar); in->read_image(TypeDesc::UINT8, - (uchar*)pixels + (((size_t)height)-1)*scanlinesize, - AutoStride, - -scanlinesize, - AutoStride); + (uchar*)pixels + (((size_t)height)-1)*scanlinesize, + AutoStride, + -scanlinesize, + AutoStride); } else { in->read_image(TypeDesc::UINT8, (uchar*)pixels); @@ -531,6 +559,44 @@ bool ImageManager::file_load_byte4_image(Image *img, device_vector<uchar4>& tex_ return true; } +bool ImageManager::file_load_byte_image(Image *img, device_vector<uchar>& tex_img) +{ + ImageInput *in = NULL; + int width, height, depth, components; + + if(!file_load_image_generic(img, &in, width, height, depth, components)) + return false; + + /* read BW pixels */ + uchar *pixels = (uchar*)tex_img.resize(width, height, depth); + if(pixels == NULL) { + return false; + } + + if(in) { + if(depth <= 1) { + int scanlinesize = width*components*sizeof(uchar); + + in->read_image(TypeDesc::UINT8, + (uchar*)pixels + (((size_t)height)-1)*scanlinesize, + AutoStride, + -scanlinesize, + AutoStride); + } + else { + in->read_image(TypeDesc::UINT8, (uchar*)pixels); + } + + in->close(); + delete in; + } + else { + builtin_image_pixels_cb(img->filename, img->builtin_data, pixels); + } + + return true; +} + bool ImageManager::file_load_float4_image(Image *img, device_vector<float4>& tex_img) { ImageInput *in = NULL; @@ -559,10 +625,10 @@ bool ImageManager::file_load_float4_image(Image *img, device_vector<float4>& tex int scanlinesize = width*components*sizeof(float); in->read_image(TypeDesc::FLOAT, - (uchar*)readpixels + (height-1)*scanlinesize, - AutoStride, - -scanlinesize, - AutoStride); + (uchar*)readpixels + (height-1)*scanlinesize, + AutoStride, + -scanlinesize, + AutoStride); } else { in->read_image(TypeDesc::FLOAT, (uchar*)readpixels); @@ -749,7 +815,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, ImageD img->extension); } } - else { + else if(type == IMAGE_DATA_TYPE_BYTE4) { device_vector<uchar4>& tex_img = dscene->tex_byte4_image[slot]; if(tex_img.device_pointer) { @@ -775,6 +841,29 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, ImageD img->extension); } } + else { + device_vector<uchar>& tex_img = dscene->tex_byte_image[slot]; + + if(tex_img.device_pointer) { + thread_scoped_lock device_lock(device_mutex); + device->tex_free(tex_img); + } + + if(!file_load_byte_image(img, tex_img)) { + /* on failure to load, we set a 1x1 pixels pink image */ + uchar *pixels = (uchar*)tex_img.resize(1, 1); + + pixels[0] = (TEX_IMAGE_MISSING_R * 255); + } + + if(!pack_images) { + thread_scoped_lock device_lock(device_mutex); + device->tex_alloc(name.c_str(), + tex_img, + img->interpolation, + img->extension); + } + } img->need_load = false; } @@ -799,9 +888,6 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD } tex_img.clear(); - - delete images[type][slot]; - images[type][slot] = NULL; } else if(type == IMAGE_DATA_TYPE_FLOAT) { device_vector<float>& tex_img = dscene->tex_float_image[slot]; @@ -812,11 +898,8 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD } tex_img.clear(); - - delete images[type][slot]; - images[type][slot] = NULL; } - else { + else if(type == IMAGE_DATA_TYPE_BYTE4) { device_vector<uchar4>& tex_img = dscene->tex_byte4_image[slot]; if(tex_img.device_pointer) { @@ -825,10 +908,20 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD } tex_img.clear(); + } + else { + device_vector<uchar>& tex_img = dscene->tex_byte_image[slot]; - delete images[type][slot]; - images[type][slot] = NULL; + if(tex_img.device_pointer) { + thread_scoped_lock device_lock(device_mutex); + device->tex_free(tex_img); + } + + tex_img.clear(); } + + delete images[type][slot]; + images[type][slot] = NULL; } } diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index cf5a6e9523f..53f739cd356 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -40,6 +40,7 @@ public: IMAGE_DATA_TYPE_FLOAT4 = 0, IMAGE_DATA_TYPE_BYTE4 = 1, IMAGE_DATA_TYPE_FLOAT = 2, + IMAGE_DATA_TYPE_BYTE = 3, IMAGE_DATA_NUM_TYPES }; @@ -97,6 +98,7 @@ private: int tex_num_images[IMAGE_DATA_NUM_TYPES]; int tex_image_byte4_start; int tex_image_float_start; + int tex_image_byte_start; thread_mutex device_mutex; int animation_frame; @@ -106,6 +108,7 @@ private: bool file_load_image_generic(Image *img, ImageInput **in, int &width, int &height, int &depth, int &components); bool file_load_byte4_image(Image *img, device_vector<uchar4>& tex_img); + bool file_load_byte_image(Image *img, device_vector<uchar>& tex_img); bool file_load_float4_image(Image *img, device_vector<float4>& tex_img); bool file_load_float_image(Image *img, device_vector<float>& tex_img); diff --git a/intern/cycles/render/integrator.cpp b/intern/cycles/render/integrator.cpp index be8fd552e78..fd4f34c8990 100644 --- a/intern/cycles/render/integrator.cpp +++ b/intern/cycles/render/integrator.cpp @@ -126,7 +126,7 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT; kintegrator->use_ambient_occlusion = - ((dscene->data.film.pass_flag & PASS_AO) || dscene->data.background.ao_factor != 0.0f); + ((Pass::contains(scene->film->passes, PASS_AO)) || dscene->data.background.ao_factor != 0.0f); kintegrator->sample_clamp_direct = (sample_clamp_direct == 0.0f)? FLT_MAX: sample_clamp_direct*3.0f; kintegrator->sample_clamp_indirect = (sample_clamp_indirect == 0.0f)? FLT_MAX: sample_clamp_indirect*3.0f; diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index 34050851d8e..435d7a396c5 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -112,6 +112,7 @@ public: device_vector<uchar4> tex_byte4_image[TEX_NUM_BYTE4_IMAGES_CPU]; device_vector<float4> tex_float4_image[TEX_NUM_FLOAT4_IMAGES_CPU]; device_vector<float> tex_float_image[TEX_NUM_FLOAT_IMAGES_CPU]; + device_vector<uchar> tex_byte_image[TEX_NUM_BYTE_IMAGES_CPU]; /* opencl images */ device_vector<uchar4> tex_image_byte4_packed; diff --git a/intern/cycles/util/util_texture.h b/intern/cycles/util/util_texture.h index e5a36ddd0cb..2a1cfca4fdd 100644 --- a/intern/cycles/util/util_texture.h +++ b/intern/cycles/util/util_texture.h @@ -25,29 +25,37 @@ CCL_NAMESPACE_BEGIN #define TEX_NUM_BYTE4_IMAGES_CPU 1024 #define TEX_NUM_FLOAT4_IMAGES_CPU 1024 #define TEX_NUM_FLOAT_IMAGES_CPU 1024 +#define TEX_NUM_BYTE_IMAGES_CPU 1024 #define TEX_IMAGE_BYTE4_START_CPU TEX_NUM_FLOAT4_IMAGES_CPU -#define TEX_IMAGE_FLOAT_START_CPU TEX_NUM_FLOAT4_IMAGES_CPU + TEX_NUM_BYTE4_IMAGES_CPU +#define TEX_IMAGE_FLOAT_START_CPU (TEX_NUM_FLOAT4_IMAGES_CPU + TEX_NUM_BYTE4_IMAGES_CPU) +#define TEX_IMAGE_BYTE_START_CPU (TEX_NUM_FLOAT4_IMAGES_CPU + TEX_NUM_BYTE4_IMAGES_CPU + TEX_NUM_BYTE_IMAGES_CPU) /* CUDA (Fermi) */ #define TEX_NUM_BYTE4_IMAGES_CUDA 88 #define TEX_NUM_FLOAT4_IMAGES_CUDA 5 #define TEX_NUM_FLOAT_IMAGES_CUDA 0 +#define TEX_NUM_BYTE_IMAGES_CUDA 0 #define TEX_IMAGE_BYTE4_START_CUDA TEX_NUM_FLOAT4_IMAGES_CUDA -#define TEX_IMAGE_FLOAT_START_CUDA TEX_NUM_FLOAT4_IMAGES_CUDA + TEX_NUM_BYTE4_IMAGES_CUDA +#define TEX_IMAGE_FLOAT_START_CUDA (TEX_NUM_FLOAT4_IMAGES_CUDA + TEX_NUM_BYTE4_IMAGES_CUDA) +#define TEX_IMAGE_BYTE_START_CUDA (TEX_NUM_FLOAT4_IMAGES_CUDA + TEX_NUM_BYTE4_IMAGES_CUDA + TEX_NUM_BYTE_IMAGES_CUDA) /* CUDA (KEPLER and above) */ #define TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER 145 #define TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER 5 #define TEX_NUM_FLOAT_IMAGES_CUDA_KEPLER 0 +#define TEX_NUM_BYTE_IMAGES_CUDA_KEPLER 0 #define TEX_IMAGE_BYTE4_START_CUDA_KEPLER TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER -#define TEX_IMAGE_FLOAT_START_CUDA_KEPLER TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER + TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER +#define TEX_IMAGE_FLOAT_START_CUDA_KEPLER (TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER + TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER) +#define TEX_IMAGE_BYTE_START_CUDA_KEPLER (TEX_NUM_FLOAT4_IMAGES_CUDA_KEPLER + TEX_NUM_BYTE4_IMAGES_CUDA_KEPLER + TEX_NUM_BYTE_IMAGES_CUDA_KEPLER) /* OpenCL */ #define TEX_NUM_BYTE4_IMAGES_OPENCL 1024 #define TEX_NUM_FLOAT4_IMAGES_OPENCL 1024 #define TEX_NUM_FLOAT_IMAGES_OPENCL 0 +#define TEX_NUM_BYTE_IMAGES_OPENCL 0 #define TEX_IMAGE_BYTE4_START_OPENCL TEX_NUM_FLOAT4_IMAGES_OPENCL -#define TEX_IMAGE_FLOAT_START_OPENCL TEX_NUM_FLOAT4_IMAGES_OPENCL + TEX_NUM_BYTE4_IMAGES_OPENCL +#define TEX_IMAGE_FLOAT_START_OPENCL (TEX_NUM_FLOAT4_IMAGES_OPENCL + TEX_NUM_BYTE4_IMAGES_OPENCL) +#define TEX_IMAGE_BYTE_START_OPENCL (TEX_NUM_FLOAT4_IMAGES_OPENCL + TEX_NUM_BYTE4_IMAGES_OPENCL + TEX_NUM_BYTE_IMAGES_OPENCL) /* Color to use when textures are not found. */ diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py index e2785d55296..d190ddc6f2f 100644 --- a/release/scripts/modules/bpy/utils/__init__.py +++ b/release/scripts/modules/bpy/utils/__init__.py @@ -305,15 +305,21 @@ def script_paths(subdir=None, user_pref=True, check_all=False): """ scripts = list(_scripts) - if check_all: - # all possible paths - base_paths = tuple(_os.path.join(resource_path(res), "scripts") - for res in ('LOCAL', 'USER', 'SYSTEM')) - else: - # only paths blender uses - base_paths = _bpy_script_paths() + # Only paths Blender uses. + # + # Needed this is needed even when 'check_all' is enabled, + # so the 'BLENDER_SYSTEM_SCRIPTS' environment variable will be used. + base_paths = _bpy_script_paths() - for path in base_paths + (script_path_user(), script_path_pref()): + if check_all: + # All possible paths, no duplicates, keep order. + base_paths = ( + *(path for path in (_os.path.join(resource_path(res), "scripts") + for res in ('LOCAL', 'USER', 'SYSTEM')) if path not in base_paths), + *base_paths, + ) + + for path in (*base_paths, script_path_user(), script_path_pref()): if path: path = _os.path.normpath(path) if path not in scripts and _os.path.isdir(path): diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 21585a160dd..2215fbfbd7d 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -119,7 +119,8 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain); /* (MAX_ID_NAME - 2) + 3 */ void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id); -void BKE_library_make_local(struct Main *bmain, struct Library *lib, bool untagged_only, bool set_fake); +void BKE_library_make_local( + struct Main *bmain, const struct Library *lib, const bool untagged_only, const bool set_fake); typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *); typedef void (*BKE_library_free_notifier_reference_cb)(const void *); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 564c670fb3a..1a3afbb876e 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -41,6 +41,7 @@ #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_ghash.h" +#include "BLI_task.h" #include "BLI_utildefines.h" #include "DNA_anim_types.h" @@ -48,6 +49,7 @@ #include "DNA_constraint_types.h" #include "DNA_mesh_types.h" #include "DNA_lattice_types.h" +#include "DNA_listBase.h" #include "DNA_meshdata_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -854,6 +856,32 @@ static void pchan_bone_deform(bPoseChannel *pchan, bPoseChanDeform *pdef_info, f (*contrib) += weight; } +typedef struct ArmatureBBoneDefmatsData { + bPoseChanDeform *pdef_info_array; + DualQuat *dualquats; + bool use_quaternion; +} ArmatureBBoneDefmatsData; + +static void armature_bbone_defmats_cb(void *userdata, Link *iter, int index) +{ + ArmatureBBoneDefmatsData *data = userdata; + bPoseChannel *pchan = (bPoseChannel *)iter; + + if (!(pchan->bone->flag & BONE_NO_DEFORM)) { + bPoseChanDeform *pdef_info = &data->pdef_info_array[index]; + const bool use_quaternion = data->use_quaternion; + + if (pchan->bone->segments > 1) { + pchan_b_bone_defmats(pchan, pdef_info, use_quaternion); + } + + if (use_quaternion) { + pdef_info->dual_quat = &data->dualquats[index]; + mat4_to_dquat(pdef_info->dual_quat, pchan->bone->arm_mat, pchan->chan_mat); + } + } +} + void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts, int deformflag, float (*prevCos)[3], const char *defgrp_name) @@ -897,19 +925,10 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float pdef_info_array = MEM_callocN(sizeof(bPoseChanDeform) * totchan, "bPoseChanDeform"); - totchan = 0; - pdef_info = pdef_info_array; - for (pchan = armOb->pose->chanbase.first; pchan; pchan = pchan->next, pdef_info++) { - if (!(pchan->bone->flag & BONE_NO_DEFORM)) { - if (pchan->bone->segments > 1) - pchan_b_bone_defmats(pchan, pdef_info, use_quaternion); - - if (use_quaternion) { - pdef_info->dual_quat = &dualquats[totchan++]; - mat4_to_dquat(pdef_info->dual_quat, pchan->bone->arm_mat, pchan->chan_mat); - } - } - } + ArmatureBBoneDefmatsData data = { + .pdef_info_array = pdef_info_array, .dualquats = dualquats, .use_quaternion = use_quaternion + }; + BLI_task_parallel_listbase(&armOb->pose->chanbase, &data, armature_bbone_defmats_cb, totchan > 512); /* get the def_nr for the overall armature vertex group if present */ armature_def_nr = defgroup_name_index(target, defgrp_name); diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 4605a12f9a0..bedf262541f 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -492,6 +492,9 @@ static void blendfile_write_partial_cb(void *UNUSED(handle), Main *UNUSED(bmain) /* only tag for need-expand if not done, prevents eternal loops */ if ((id->tag & LIB_TAG_DOIT) == 0) id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT; + + if (id->lib && (id->lib->id.tag & LIB_TAG_DOIT) == 0) + id->lib->id.tag |= LIB_TAG_DOIT; } } diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 88be7328492..7821946eb6e 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -397,7 +397,7 @@ static BVHTree *bvhtree_from_editmesh_verts_create_tree( int i; BM_mesh_elem_table_ensure(em->bm, BM_VERT); if (verts_mask) { - BLI_assert(IN_RANGE(verts_num_active, -1, verts_num)); + BLI_assert(IN_RANGE_INCL(verts_num_active, 0, verts_num)); } else { verts_num_active = verts_num; @@ -430,7 +430,7 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree( int i; if (vert) { if (verts_mask) { - BLI_assert(IN_RANGE(verts_num_active, -1, verts_num)); + BLI_assert(IN_RANGE_INCL(verts_num_active, 0, verts_num)); } else { verts_num_active = verts_num; @@ -688,7 +688,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree( if (faces_num) { if (faces_mask) { - BLI_assert(IN_RANGE(faces_num_active, -1, faces_num)); + BLI_assert(IN_RANGE_INCL(faces_num_active, 0, faces_num)); } else { faces_num_active = faces_num; @@ -842,7 +842,7 @@ static BVHTree *bvhtree_from_editmesh_looptri_create_tree( if (looptri_num) { if (looptri_mask) { - BLI_assert(IN_RANGE(looptri_num_active, -1, looptri_num)); + BLI_assert(IN_RANGE_INCL(looptri_num_active, 0, looptri_num)); } else { looptri_num_active = looptri_num; @@ -892,7 +892,7 @@ static BVHTree *bvhtree_from_mesh_looptri_create_tree( if (looptri_num) { if (looptri_mask) { - BLI_assert(IN_RANGE(looptri_num_active, -1, looptri_num)); + BLI_assert(IN_RANGE_INCL(looptri_num_active, 0, looptri_num)); } else { looptri_num_active = looptri_num; diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index f4a07539218..ff036828ebd 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -85,7 +85,7 @@ /* could enable at some point but for now there are far too many conversions */ #ifdef __GNUC__ -# pragma GCC diagnostic ignored "-Wdouble-promotion" +//# pragma GCC diagnostic ignored "-Wdouble-promotion" #endif /* precalculated gaussian factors for 5x super sampling */ @@ -123,7 +123,7 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* dissolve inline function */ -BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const int is_log) +BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const bool is_log) { *r_value = (is_log) ? (*r_value) * (powf(MIN_WETNESS, 1.0f / (1.2f * time / scale))) : @@ -144,13 +144,12 @@ typedef struct Bounds3D { typedef struct VolumeGrid { int dim[3]; - Bounds3D grid_bounds; /* whole grid bounds */ + Bounds3D grid_bounds; /* whole grid bounds */ - Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */ - int *s_pos; /* (x*y*z) t_index begin id */ - int *s_num; /* (x*y*z) number of t_index points */ - int *t_index; /* actual surface point index, - * access: (s_pos+s_num) */ + Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */ + int *s_pos; /* (x*y*z) t_index begin id */ + int *s_num; /* (x*y*z) number of t_index points */ + int *t_index; /* actual surface point index, access: (s_pos + s_num) */ } VolumeGrid; typedef struct Vec3f { @@ -165,21 +164,20 @@ typedef struct BakeAdjPoint { /* Surface data used while processing a frame */ typedef struct PaintBakeNormal { float invNorm[3]; /* current pixel world-space inverted normal */ - float normal_scale; /* normal directional scale for displace mapping */ + float normal_scale; /* normal directional scale for displace mapping */ } PaintBakeNormal; /* Temp surface data used to process a frame */ typedef struct PaintBakeData { /* point space data */ PaintBakeNormal *bNormal; - int *s_pos; /* index to start reading point sample realCoord */ - int *s_num; /* num of realCoord samples */ - Vec3f *realCoord; /* current pixel center world-space coordinates for each sample - * ordered as (s_pos+s_num)*/ + int *s_pos; /* index to start reading point sample realCoord */ + int *s_num; /* num of realCoord samples */ + Vec3f *realCoord; /* current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */ Bounds3D mesh_bounds; /* adjacency info */ - BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */ + BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */ double average_dist; /* space partitioning */ VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ @@ -188,7 +186,7 @@ typedef struct PaintBakeData { Vec3f *velocity; /* speed vector in global space movement per frame, if required */ Vec3f *prev_velocity; float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge - * 3 float dir vec + 1 float str */ + * 3 float dir vec + 1 float str */ MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */ float prev_obmat[4][4]; /* previous frame object matrix */ int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */ @@ -201,8 +199,7 @@ typedef struct PaintUVPoint { unsigned int tri_index, pixel_index; /* tri index on domain derived mesh */ unsigned int v1, v2, v3; /* vertex indexes */ - unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, - * but it's neighboring pixel is */ + unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, but it's neighboring pixel is */ } PaintUVPoint; typedef struct ImgSeqFormatData { @@ -214,8 +211,7 @@ typedef struct ImgSeqFormatData { #define ADJ_ON_MESH_EDGE (1 << 0) typedef struct PaintAdjData { - int *n_target; /* array of neighboring point indexes, - * for single sample use (n_index + neigh_num) */ + int *n_target; /* array of neighboring point indexes, for single sample use (n_index + neigh_num) */ int *n_index; /* index to start reading n_target for each point */ int *n_num; /* num of neighs for each point */ int *flags; /* vertex adjacency flags */ @@ -239,11 +235,10 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface) return 0; /* not supported atm */ } else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - if (!surface->canvas->dm) return 0; /* invalid derived mesh */ - return surface->canvas->dm->getNumVerts(surface->canvas->dm); + return (surface->canvas->dm) ? surface->canvas->dm->getNumVerts(surface->canvas->dm) : 0; } - else - return 0; + + return 0; } /* checks whether surface's format/type has realtime preview */ @@ -253,32 +248,16 @@ bool dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) return false; } else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WAVE) - { - return false; - } - else { - return true; - } - } - else { - return true; + return !ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE); } + + return true; } /* get currently active surface (in user interface) */ DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) { - DynamicPaintSurface *surface = canvas->surfaces.first; - int i; - - for (i = 0; surface; surface = surface->next) { - if (i == canvas->active_sur) - return surface; - i++; - } - return NULL; + return BLI_findlink(&canvas->surfaces, canvas->active_sur); } /* set preview to first previewable surface */ @@ -292,8 +271,9 @@ void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) surface->flags |= MOD_DPAINT_PREVIEW; done = true; } - else + else { surface->flags &= ~MOD_DPAINT_PREVIEW; + } } } @@ -325,8 +305,9 @@ bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object Mesh *me = ob->data; return (CustomData_get_named_layer_index(&me->ldata, CD_MLOOPCOL, name) != -1); } - else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) - return (defgroup_name_index(ob, surface->output_name) != -1); + else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { + return (defgroup_name_index(ob, name) != -1); + } } return false; @@ -334,15 +315,16 @@ bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object static bool surface_duplicateOutputExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; + DynamicPaintSurface *t_surface = arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; for (; surface; surface = surface->next) { - if (surface != t_surface && surface->type == t_surface->type && - surface->format == t_surface->format) - { - if (surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) return true; - if (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)) return true; + if (surface != t_surface && surface->type == t_surface->type && surface->format == t_surface->format) { + if ((surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) || + (surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2))) + { + return true; + } } } return false; @@ -352,20 +334,25 @@ static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *base { char name[64]; BLI_strncpy(name, basename, sizeof(name)); /* in case basename is surface->name use a copy */ - if (!output) - BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', surface->output_name, sizeof(surface->output_name)); - if (output) - BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', surface->output_name2, sizeof(surface->output_name2)); + if (output == 0) { + BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', + surface->output_name, sizeof(surface->output_name)); + } + else if (output == 1) { + BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.', + surface->output_name2, sizeof(surface->output_name2)); + } } static bool surface_duplicateNameExists(void *arg, const char *name) { - DynamicPaintSurface *t_surface = (DynamicPaintSurface *)arg; + DynamicPaintSurface *t_surface = arg; DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; for (; surface; surface = surface->next) { - if (surface != t_surface && STREQ(name, surface->name)) return true; + if (surface != t_surface && STREQ(name, surface->name)) + return true; } return false; } @@ -420,9 +407,7 @@ void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) static int surface_totalSamples(DynamicPaintSurface *surface) { - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && - surface->flags & MOD_DPAINT_ANTIALIAS) - { + if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->flags & MOD_DPAINT_ANTIALIAS) { return (surface->data->total_points * 5); } if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && @@ -436,6 +421,7 @@ static int surface_totalSamples(DynamicPaintSurface *surface) static void blendColors(const float t_color[3], float t_alpha, const float s_color[3], float s_alpha, float result[4]) { + /* Same thing as BLI's blend_color_mix_float(), but for non-premultiplied alpha. */ int i; float i_alpha = 1.0f - s_alpha; float f_alpha = t_alpha * i_alpha + s_alpha; @@ -508,15 +494,11 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Scene *scen /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) + brushObj = go->ob; } - else + else { brushObj = base->object; - - if (!brushObj) { - if (surface->brush_group) go = go->next; - else base = base->next; - continue; } if (surface->brush_group) @@ -524,6 +506,10 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Scene *scen else base = base->next; + if (!brushObj) { + continue; + } + md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md; @@ -546,50 +532,52 @@ static int brush_usesMaterial(DynamicPaintBrushSettings *brush, Scene *scene) } /* check whether two bounds intersect */ -static int boundsIntersect(Bounds3D *b1, Bounds3D *b2) +static bool boundsIntersect(Bounds3D *b1, Bounds3D *b2) { - int i = 2; - if (!b1->valid || !b2->valid) return 0; - for (; i >= 0; i -= 1) - if (!(b1->min[i] <= b2->max[i] && b1->max[i] >= b2->min[i])) return 0; - return 1; + if (!b1->valid || !b2->valid) + return false; + for (int i = 2; i--;) { + if (!(b1->min[i] <= b2->max[i] && b1->max[i] >= b2->min[i])) + return false; + } + return true; } /* check whether two bounds intersect inside defined proximity */ -static int boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, float dist) +static bool boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, const float dist) { - int i = 2; - if (!b1->valid || !b2->valid) return 0; - for (; i >= 0; i -= 1) - if (!(b1->min[i] <= (b2->max[i] + dist) && b1->max[i] >= (b2->min[i] - dist))) return 0; - return 1; + if (!b1->valid || !b2->valid) + return false; + for (int i = 2; i--;) { + if (!(b1->min[i] <= (b2->max[i] + dist) && b1->max[i] >= (b2->min[i] - dist))) + return false; + } + return true; } /* check whether bounds intersects a point with given radius */ -static int boundIntersectPoint(Bounds3D *b, float point[3], float radius) +static bool boundIntersectPoint(Bounds3D *b, float point[3], const float radius) { - int i = 2; - if (!b->valid) return 0; - for (; i >= 0; i -= 1) - if (!(b->min[i] <= (point[i] + radius) && b->max[i] >= (point[i] - radius))) return 0; - return 1; + if (!b->valid) + return false; + for (int i = 2; i--;) { + if (!(b->min[i] <= (point[i] + radius) && b->max[i] >= (point[i] - radius))) + return false; + } + return true; } /* expand bounds by a new point */ static void boundInsert(Bounds3D *b, float point[3]) { - int i = 2; if (!b->valid) { copy_v3_v3(b->min, point); copy_v3_v3(b->max, point); b->valid = 1; + return; } - else { - for (; i >= 0; i -= 1) { - if (point[i] < b->min[i]) b->min[i] = point[i]; - if (point[i] > b->max[i]) b->max[i] = point[i]; - } - } + + minmax_v3v3_v3(b->min, b->max, point); } static float getSurfaceDimension(PaintSurfaceData *sData) @@ -636,7 +624,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) bData->grid = MEM_callocN(sizeof(VolumeGrid), "Surface Grid"); grid = bData->grid; - if (grid && grid_bounds) { + { int i, error = 0; float dim_factor, volume, dim[3]; float td[3]; @@ -659,6 +647,8 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) boundInsert(&grid->grid_bounds, grid_bounds[i].max); } + MEM_freeN(grid_bounds); + /* get dimensions */ sub_v3_v3v3(dim, grid->grid_bounds.max, grid->grid_bounds.min); copy_v3_v3(td, dim); @@ -666,11 +656,13 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* deactivate zero axises */ for (i = 0; i < 3; i++) { - if (td[i] < min_dim) { td[i] = 1.0f; axis -= 1; } + if (td[i] < min_dim) { + td[i] = 1.0f; + axis--; + } } if (axis == 0 || max_fff(td[0], td[1], td[2]) < 0.0001f) { - MEM_freeN(grid_bounds); MEM_freeN(bData->grid); bData->grid = NULL; return; @@ -764,8 +756,10 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) } } - if (temp_s_num) MEM_freeN(temp_s_num); - if (temp_t_index) MEM_freeN(temp_t_index); + if (temp_s_num) + MEM_freeN(temp_s_num); + if (temp_t_index) + MEM_freeN(temp_t_index); /* free per thread s_num values */ grid->s_num = MEM_reallocN(grid->s_num, sizeof(int) * grid_cells); @@ -775,8 +769,6 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) freeGrid(sData); } } - - if (grid_bounds) MEM_freeN(grid_bounds); } /***************************** Freeing data ******************************/ @@ -791,10 +783,8 @@ void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd) if (pmd->brush->paint_ramp) MEM_freeN(pmd->brush->paint_ramp); - pmd->brush->paint_ramp = NULL; if (pmd->brush->vel_ramp) MEM_freeN(pmd->brush->vel_ramp); - pmd->brush->vel_ramp = NULL; MEM_freeN(pmd->brush); pmd->brush = NULL; @@ -804,10 +794,14 @@ void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd) static void dynamicPaint_freeAdjData(PaintSurfaceData *data) { if (data->adj_data) { - if (data->adj_data->n_index) MEM_freeN(data->adj_data->n_index); - if (data->adj_data->n_num) MEM_freeN(data->adj_data->n_num); - if (data->adj_data->n_target) MEM_freeN(data->adj_data->n_target); - if (data->adj_data->flags) MEM_freeN(data->adj_data->flags); + if (data->adj_data->n_index) + MEM_freeN(data->adj_data->n_index); + if (data->adj_data->n_num) + MEM_freeN(data->adj_data->n_num); + if (data->adj_data->n_target) + MEM_freeN(data->adj_data->n_target); + if (data->adj_data->flags) + MEM_freeN(data->adj_data->flags); MEM_freeN(data->adj_data); data->adj_data = NULL; } @@ -817,15 +811,24 @@ static void free_bakeData(PaintSurfaceData *data) { PaintBakeData *bData = data->bData; if (bData) { - if (bData->bNormal) MEM_freeN(bData->bNormal); - if (bData->s_pos) MEM_freeN(bData->s_pos); - if (bData->s_num) MEM_freeN(bData->s_num); - if (bData->realCoord) MEM_freeN(bData->realCoord); - if (bData->bNeighs) MEM_freeN(bData->bNeighs); - if (bData->grid) freeGrid(data); - if (bData->prev_verts) MEM_freeN(bData->prev_verts); - if (bData->velocity) MEM_freeN(bData->velocity); - if (bData->prev_velocity) MEM_freeN(bData->prev_velocity); + if (bData->bNormal) + MEM_freeN(bData->bNormal); + if (bData->s_pos) + MEM_freeN(bData->s_pos); + if (bData->s_num) + MEM_freeN(bData->s_num); + if (bData->realCoord) + MEM_freeN(bData->realCoord); + if (bData->bNeighs) + MEM_freeN(bData->bNeighs); + if (bData->grid) + freeGrid(data); + if (bData->prev_verts) + MEM_freeN(bData->prev_verts); + if (bData->velocity) + MEM_freeN(bData->velocity); + if (bData->prev_velocity) + MEM_freeN(bData->prev_velocity); MEM_freeN(data->bData); data->bData = NULL; @@ -835,12 +838,11 @@ static void free_bakeData(PaintSurfaceData *data) /* free surface data if it's not used anymore */ static void surface_freeUnusedData(DynamicPaintSurface *surface) { - if (!surface->data) return; + if (!surface->data) + return; /* free bakedata if not active or surface is baked */ - if (!(surface->flags & MOD_DPAINT_ACTIVE) || - (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) - { + if (!(surface->flags & MOD_DPAINT_ACTIVE) || (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) { free_bakeData(surface->data); } } @@ -848,7 +850,9 @@ static void surface_freeUnusedData(DynamicPaintSurface *surface) void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) { PaintSurfaceData *data = surface->data; - if (!data) return; + if (!data) + return; + if (data->format_data) { /* format specific free */ if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { @@ -861,7 +865,8 @@ void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface) MEM_freeN(data->format_data); } /* type data */ - if (data->type_data) MEM_freeN(data->type_data); + if (data->type_data) + MEM_freeN(data->type_data); dynamicPaint_freeAdjData(data); /* bake data */ free_bakeData(data); @@ -1224,31 +1229,24 @@ static void dynamicPaint_allocateSurfaceType(DynamicPaintSurface *surface) break; } - if (sData->type_data == NULL) setError(surface->canvas, N_("Not enough free memory")); + if (sData->type_data == NULL) + setError(surface->canvas, N_("Not enough free memory")); } -static int surface_usesAdjDistance(DynamicPaintSurface *surface) +static bool surface_usesAdjDistance(DynamicPaintSurface *surface) { - if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && surface->effect) return 1; - if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) return 1; - return 0; + return ((surface->type == MOD_DPAINT_SURFACE_T_PAINT && surface->effect) || + (surface->type == MOD_DPAINT_SURFACE_T_WAVE)); } -static int surface_usesAdjData(DynamicPaintSurface *surface) +static bool surface_usesAdjData(DynamicPaintSurface *surface) { - if (surface_usesAdjDistance(surface)) return 1; - if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && - surface->flags & MOD_DPAINT_ANTIALIAS) - { - return 1; - } - else { - return 0; - } + return (surface_usesAdjDistance(surface) || + (surface->format == MOD_DPAINT_SURFACE_F_VERTEX && surface->flags & MOD_DPAINT_ANTIALIAS)); } /* initialize surface adjacency data */ -static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int force_init) +static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const bool force_init) { PaintSurfaceData *sData = surface->data; DerivedMesh *dm = surface->canvas->dm; @@ -1256,20 +1254,24 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for int *temp_data; int neigh_points = 0; - if (!surface_usesAdjData(surface) && !force_init) return; + if (!surface_usesAdjData(surface) && !force_init) + return; if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { /* For vertex format, neighbors are connected by edges */ neigh_points = 2 * dm->getNumEdges(dm); } - else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) + else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { neigh_points = sData->total_points * 8; + } - if (!neigh_points) return; + if (!neigh_points) + return; /* allocate memory */ ad = sData->adj_data = MEM_callocN(sizeof(PaintAdjData), "Surface Adj Data"); - if (!ad) return; + if (!ad) + return; ad->n_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Index"); ad->n_num = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Counts"); temp_data = MEM_callocN(sizeof(int) * sData->total_points, "Temp Adj Data"); @@ -1280,7 +1282,8 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* in case of allocation error, free memory */ if (!ad->n_index || !ad->n_num || !ad->n_target || !temp_data) { dynamicPaint_freeAdjData(sData); - if (temp_data) MEM_freeN(temp_data); + if (temp_data) + MEM_freeN(temp_data); setError(surface->canvas, N_("Not enough free memory")); return; } @@ -1308,8 +1311,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* also add number of vertices to temp_data * to locate points on "mesh edge" */ for (i = 0; i < numOfPolys; i++) { - int j = 0; - for (; j < mpoly[i].totloop; j++) { + for (int j = 0; j < mpoly[i].totloop; j++) { temp_data[mloop[mpoly[i].loopstart + j].v]++; } } @@ -1317,9 +1319,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for /* now check if total number of edges+faces for * each vertex is even, if not -> vertex is on mesh edge */ for (i = 0; i < sData->total_points; i++) { - if ((temp_data[i] % 2) || - (temp_data[i] < 4)) - { + if ((temp_data[i] % 2) || (temp_data[i] < 4)) { ad->flags[i] |= ADJ_ON_MESH_EDGE; } @@ -1370,8 +1370,9 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface if (surface->init_color_type == MOD_DPAINT_INITIAL_NONE) return; + /* Single color */ - else if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { + if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { /* apply color to every surface point */ #pragma omp parallel for schedule(static) for (i = 0; i < sData->total_points; i++) { @@ -1389,12 +1390,14 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface char uvname[MAX_CUSTOMDATA_LAYER_NAME]; - if (!tex) return; + if (!tex) + return; /* get uv map */ CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, surface->init_layername, uvname); mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname); - if (!mloopuv) return; + if (!mloopuv) + return; /* for vertex surface loop through tfaces and find uv color * that provides highest alpha */ @@ -1462,7 +1465,8 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface const MLoop *mloop = dm->getLoopArray(dm); const int totloop = dm->getNumLoops(dm); const MLoopCol *col = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, surface->init_layername); - if (!col) return; + if (!col) + return; #pragma omp parallel for schedule(static) for (i = 0; i < totloop; i++) { @@ -1474,7 +1478,8 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; MLoopCol *col = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, surface->init_layername); - if (!col) return; + if (!col) + return; #pragma omp parallel for schedule(static) for (i = 0; i < sData->total_points; i++) { @@ -1527,20 +1532,24 @@ bool dynamicPaint_resetSurface(const Scene *scene, DynamicPaintSurface *surface) { int numOfPoints = dynamicPaint_surfaceNumOfPoints(surface); /* free existing data */ - if (surface->data) dynamicPaint_freeSurfaceData(surface); + if (surface->data) + dynamicPaint_freeSurfaceData(surface); /* don't reallocate for image sequence types. they get handled only on bake */ - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return true; - if (numOfPoints < 1) return false; + if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) + return true; + if (numOfPoints < 1) + return false; /* allocate memory */ surface->data = MEM_callocN(sizeof(PaintSurfaceData), "PaintSurfaceData"); - if (!surface->data) return false; + if (!surface->data) + return false; /* allocate data depending on surface type and format */ surface->data->total_points = numOfPoints; dynamicPaint_allocateSurfaceType(surface); - dynamicPaint_initAdjacencyData(surface, 0); + dynamicPaint_initAdjacencyData(surface, false); /* set initial color */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) @@ -1567,7 +1576,8 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri { PaintSurfaceData *sData = surface->data; - if (!sData || surface->format != MOD_DPAINT_SURFACE_F_VERTEX) return; + if (!sData || surface->format != MOD_DPAINT_SURFACE_F_VERTEX) + return; /* displace paint */ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { @@ -1591,9 +1601,8 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri /* * Apply canvas data to the object derived mesh */ -static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, - Object *ob, - DerivedMesh *dm) +static DerivedMesh *dynamicPaint_Modifier_apply( + DynamicPaintModifierData *pmd, Object *ob, DerivedMesh *dm) { DerivedMesh *result = CDDM_copy(dm); @@ -1607,7 +1616,8 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, PaintSurfaceData *sData = surface->data; if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && sData) { - if (!(surface->flags & (MOD_DPAINT_ACTIVE))) continue; + if (!(surface->flags & MOD_DPAINT_ACTIVE)) + continue; /* process vertex surface previews */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { @@ -1627,7 +1637,8 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, #pragma omp parallel for schedule(static) for (i = 0; i < sData->total_points; i++) { /* blend dry and wet layer */ - blendColors(pPoint[i].color, pPoint[i].color[3], pPoint[i].e_color, pPoint[i].e_color[3], &fcolor[i * 4]); + blendColors(pPoint[i].color, pPoint[i].color[3], + pPoint[i].e_color, pPoint[i].e_color[3], &fcolor[i * 4]); } /* viewport preview */ @@ -1647,17 +1658,17 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, /* Save preview results to weight layer to be * able to share same drawing methods */ col = CustomData_get_layer(&result->loopData, CD_PREVIEW_MLOOPCOL); - if (!col) - col = CustomData_add_layer(&result->loopData, CD_PREVIEW_MLOOPCOL, CD_CALLOC, - NULL, totloop); + if (!col) { + col = CustomData_add_layer( + &result->loopData, CD_PREVIEW_MLOOPCOL, CD_CALLOC, NULL, totloop); + } if (col) { #pragma omp parallel for schedule(static) for (i = 0; i < totpoly; i++) { - int j = 0; Material *material = give_current_material(ob, mp[i].mat_nr + 1); - for (; j < mp[i].totloop; j++) { + for (int j = 0; j < mp[i].totloop; j++) { int l_index = mp[i].loopstart + j; int v_index = mloop[l_index].v; @@ -1683,9 +1694,10 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, rgb_float_to_uchar((unsigned char *)&col[l_index].r, c); } else { - col[l_index].r = - col[l_index].g = - col[l_index].b = FTOCHAR(pPoint[v_index].wetness); + const char c = FTOCHAR(pPoint[v_index].wetness); + col[l_index].r = c; + col[l_index].g = c; + col[l_index].b = c; col[l_index].a = 255; } } @@ -1699,15 +1711,16 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, /* paint layer */ col = CustomData_get_layer_named(&result->loopData, CD_MLOOPCOL, surface->output_name); /* if output layer is lost from a constructive modifier, re-add it */ - if (!col && dynamicPaint_outputLayerExists(surface, ob, 0)) - col = CustomData_add_layer_named(&result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name); + if (!col && dynamicPaint_outputLayerExists(surface, ob, 0)) { + col = CustomData_add_layer_named( + &result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name); + } /* apply color */ if (col) { #pragma omp parallel for schedule(static) for (i = 0; i < totloop; i++) { int index = mloop[i].v * 4; - rgb_float_to_uchar((unsigned char *)&col[i].r, &fcolor[index]); - col[i].a = FTOCHAR(fcolor[index + 3]); /* IS THIS NEEDED? */ + rgba_float_to_uchar((unsigned char *)&col[i].r, &fcolor[index]); } } @@ -1716,16 +1729,18 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, /* wet layer */ col = CustomData_get_layer_named(&result->loopData, CD_MLOOPCOL, surface->output_name2); /* if output layer is lost from a constructive modifier, re-add it */ - if (!col && dynamicPaint_outputLayerExists(surface, ob, 1)) - col = CustomData_add_layer_named(&result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name2); + if (!col && dynamicPaint_outputLayerExists(surface, ob, 1)) { + col = CustomData_add_layer_named( + &result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name2); + } /* apply color */ if (col) { #pragma omp parallel for schedule(static) for (i = 0; i < totloop; i++) { - int index = mloop[i].v; - col[i].r = - col[i].g = - col[i].b = FTOCHAR(pPoint[index].wetness); + const char c = FTOCHAR(pPoint[mloop[i].v].wetness); + col[i].r = c; + col[i].g = c; + col[i].b = c; col[i].a = 255; } } @@ -1748,9 +1763,10 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, } /* apply weights into a vertex group, if doesnt exists add a new layer */ - if (defgrp_index != -1 && !dvert && (surface->output_name[0] != '\0')) + if (defgrp_index != -1 && !dvert && (surface->output_name[0] != '\0')) { dvert = CustomData_add_layer_named(&result->vertData, CD_MDEFORMVERT, CD_CALLOC, NULL, sData->total_points, surface->output_name); + } if (defgrp_index != -1 && dvert) { int i; for (i = 0; i < sData->total_points; i++) { @@ -1759,7 +1775,6 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, /* skip if weight value is 0 and no existing weight is found */ if ((def_weight != NULL) || (weight[i] != 0.0f)) { - /* if not found, add a weight for it */ if (def_weight == NULL) { def_weight = defvert_verify_index(dv, defgrp_index); @@ -1801,7 +1816,8 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, } /* make a copy of dm to use as brush data */ if (pmd->brush) { - if (pmd->brush->dm) pmd->brush->dm->release(pmd->brush->dm); + if (pmd->brush->dm) + pmd->brush->dm->release(pmd->brush->dm); pmd->brush->dm = CDDM_copy(result); } @@ -1839,7 +1855,8 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene canvas_copyDerivedMesh(canvas, dm); /* in case image sequence baking, stop here */ - if (canvas->flags & MOD_DPAINT_BAKING) return; + if (canvas->flags & MOD_DPAINT_BAKING) + return; /* loop through surfaces */ for (; surface; surface = surface->next) { @@ -1850,17 +1867,20 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene surface_freeUnusedData(surface); /* image sequences are handled by bake operator */ - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) continue; - if (!(surface->flags & MOD_DPAINT_ACTIVE)) continue; + if ((surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) || !(surface->flags & MOD_DPAINT_ACTIVE)) + continue; /* make sure surface is valid */ no_surface_data = surface->data == NULL; - if (!dynamicPaint_checkSurfaceData(scene, surface)) continue; + if (!dynamicPaint_checkSurfaceData(scene, surface)) + continue; /* limit frame range */ CLAMP(current_frame, surface->start_frame, surface->end_frame); - if (no_surface_data || current_frame != surface->current_frame || (int)scene->r.cfra == surface->start_frame) { + if (no_surface_data || current_frame != surface->current_frame || + (int)scene->r.cfra == surface->start_frame) + { PointCache *cache = surface->pointcache; PTCacheID pid; surface->current_frame = current_frame; @@ -1943,8 +1963,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh x = px + neighX[n_index]; y = py + neighY[n_index]; - if (x < 0 || x >= w) return OUT_OF_TEXTURE; - if (y < 0 || y >= h) return OUT_OF_TEXTURE; + if (x < 0 || x >= w || y < 0 || y >= h) + return OUT_OF_TEXTURE; tPoint = &tempPoints[x + w * y]; /* UV neighbor */ cPoint = &tempPoints[px + w * py]; /* Origin point */ @@ -1993,8 +2013,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh /* distances only used for comparison */ float dist_squared, t_dist_squared; - int i, edge1_index, edge2_index, - e1_index, e2_index, target_tri; + int i, edge1_index, edge2_index; + int e1_index, e2_index, target_tri; float closest_point[2], lambda, dir_vec[2]; int target_uv1 = 0, target_uv2 = 0, final_pixel[2], final_index; @@ -2050,33 +2070,28 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh target_tri = -1; for (i = 0; i < tottri; i++) { + const int v0 = mloop[mlooptri[i].tri[0]].v; + const int v1 = mloop[mlooptri[i].tri[1]].v; + const int v2 = mloop[mlooptri[i].tri[2]].v; /* * Check if both edge vertices share this face */ - if ((e1_index == mloop[mlooptri[i].tri[0]].v || e1_index == mloop[mlooptri[i].tri[1]].v || e1_index == mloop[mlooptri[i].tri[2]].v) && - (e2_index == mloop[mlooptri[i].tri[0]].v || e2_index == mloop[mlooptri[i].tri[1]].v || e2_index == mloop[mlooptri[i].tri[2]].v)) - { - if (i == cPoint->tri_index) continue; + if (ELEM(e1_index, v0, v1, v2) && ELEM(e2_index, v0, v1, v2)) { + if (i == cPoint->tri_index) + continue; target_tri = i; - /* - * Get edge UV index - */ - if (e1_index == mloop[mlooptri[i].tri[0]].v) target_uv1 = 0; - else if (e1_index == mloop[mlooptri[i].tri[1]].v) target_uv1 = 1; - else if (e1_index == mloop[mlooptri[i].tri[2]].v) target_uv1 = 2; - - if (e2_index == mloop[mlooptri[i].tri[0]].v) target_uv2 = 0; - else if (e2_index == mloop[mlooptri[i].tri[1]].v) target_uv2 = 1; - else if (e2_index == mloop[mlooptri[i].tri[2]].v) target_uv2 = 2; - + /* Get edge UV index */ + target_uv1 = (e1_index == v0) ? 0 : ((e1_index == v1) ? 1 : 2); + target_uv2 = (e2_index == v0) ? 0 : ((e2_index == v1) ? 1 : 2); break; } } /* If none found pixel is on mesh edge */ - if (target_tri == -1) return ON_MESH_EDGE; + if (target_tri == -1) + return ON_MESH_EDGE; /* * If target face is connected in UV space as well, just use original index @@ -2104,8 +2119,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh closest_point, pixel, mloopuv[mlooptri[cPoint->tri_index].tri[edge1_index]].uv, mloopuv[mlooptri[cPoint->tri_index].tri[edge2_index]].uv); - if (lambda < 0.0f) lambda = 0.0f; - if (lambda > 1.0f) lambda = 1.0f; + CLAMP(lambda, 0.0f, 1.0f); sub_v2_v2v2( dir_vec, @@ -2119,26 +2133,25 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh pixel[0] = (pixel[0] * (float)w) - 0.5f; pixel[1] = (pixel[1] * (float)h) - 0.5f; - final_pixel[0] = (int)floor(pixel[0]); - final_pixel[1] = (int)floor(pixel[1]); + final_pixel[0] = (int)floorf(pixel[0]); + final_pixel[1] = (int)floorf(pixel[1]); /* If current pixel uv is outside of texture */ - if (final_pixel[0] < 0 || final_pixel[0] >= w) return OUT_OF_TEXTURE; - if (final_pixel[1] < 0 || final_pixel[1] >= h) return OUT_OF_TEXTURE; + if (final_pixel[0] < 0 || final_pixel[0] >= w || final_pixel[1] < 0 || final_pixel[1] >= h) + return OUT_OF_TEXTURE; final_index = final_pixel[0] + w * final_pixel[1]; /* If we ended up to our origin point ( mesh has smaller than pixel sized faces) */ - if (final_index == (px + w * py)) return NOT_FOUND; + if (final_index == (px + w * py)) + return NOT_FOUND; /* If found pixel still lies on wrong face ( mesh has smaller than pixel sized faces) */ - if (tempPoints[final_index].tri_index != target_tri) { + if (tempPoints[final_index].tri_index != target_tri) return NOT_FOUND; - } - /* - * If final point is an "edge pixel", use it's "real" neighbor instead - */ - if (tempPoints[final_index].neighbour_pixel != -1) final_index = cPoint->neighbour_pixel; + /* If final point is an "edge pixel", use it's "real" neighbor instead */ + if (tempPoints[final_index].neighbour_pixel != -1) + final_index = cPoint->neighbour_pixel; return final_index; } @@ -2163,7 +2176,7 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) int tottri; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; int active_points = 0; - int error = 0; + bool error = false; PaintSurfaceData *sData; DynamicPaintCanvasSettings *canvas = surface->canvas; @@ -2208,20 +2221,24 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) printf("DynamicPaint: Preparing UV surface of %ix%i pixels and %i tris.\n", w, h, tottri); /* Init data struct */ - if (surface->data) dynamicPaint_freeSurfaceData(surface); + if (surface->data) + dynamicPaint_freeSurfaceData(surface); sData = surface->data = MEM_callocN(sizeof(PaintSurfaceData), "PaintSurfaceData"); if (!surface->data) return setError(canvas, N_("Not enough free memory")); aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; tempPoints = (struct PaintUVPoint *) MEM_callocN(w * h * sizeof(struct PaintUVPoint), "Temp PaintUVPoint"); - if (!tempPoints) error = 1; + if (!tempPoints) + error = true; final_index = (int *) MEM_callocN(w * h * sizeof(int), "Temp UV Final Indexes"); - if (!final_index) error = 1; + if (!final_index) + error = true; tempWeights = (struct Vec3f *) MEM_mallocN(w * h * aa_samples * sizeof(struct Vec3f), "Temp bWeights"); - if (!tempWeights) error = 1; + if (!tempWeights) + error = true; /* * Generate a temporary bounding box array for UV faces to optimize @@ -2229,10 +2246,11 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) */ if (!error) { faceBB = (struct Bounds2D *) MEM_mallocN(tottri * sizeof(struct Bounds2D), "MPCanvasFaceBB"); - if (!faceBB) error = 1; + if (!faceBB) + error = true; } - if (!error) + if (!error) { for (ty = 0; ty < tottri; ty++) { int i; @@ -2240,18 +2258,11 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) copy_v2_v2(faceBB[ty].max, mloopuv[mlooptri[ty].tri[0]].uv); for (i = 1; i < 3; i++) { - CLAMP_MAX(faceBB[ty].min[0], mloopuv[mlooptri[ty].tri[i]].uv[0]); - CLAMP_MAX(faceBB[ty].min[1], mloopuv[mlooptri[ty].tri[i]].uv[1]); - CLAMP_MIN(faceBB[ty].max[0], mloopuv[mlooptri[ty].tri[i]].uv[0]); - CLAMP_MIN(faceBB[ty].max[1], mloopuv[mlooptri[ty].tri[i]].uv[1]); + minmax_v2v2_v2(faceBB[ty].min, faceBB[ty].max, mloopuv[mlooptri[ty].tri[i]].uv); } } - /* - * Loop through every pixel and check - * if pixel is uv-mapped on a canvas face. - */ - if (!error) { + /* Loop through every pixel and check if pixel is uv-mapped on a canvas face. */ #pragma omp parallel for schedule(static) for (ty = 0; ty < h; ty++) { int tx; @@ -2259,11 +2270,7 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) int i, sample; int index = tx + w * ty; PaintUVPoint *tPoint = (&tempPoints[index]); - - bool isInside = false; /* if point is inside a uv face */ - - float d1[2], d2[2], d3[2], point[5][2]; - float dot00, dot01, dot02, dot11, dot12, invDenom, u, v; + float point[5][2]; /* Init per pixel settings */ tPoint->tri_index = -1; @@ -2293,54 +2300,31 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) /* Loop through samples, starting from middle point */ for (sample = 0; sample < 5; sample++) { - /* Loop through every face in the mesh */ for (i = 0; i < tottri; i++) { - /* Check uv bb */ - if (faceBB[i].min[0] > (point[sample][0])) continue; - if (faceBB[i].min[1] > (point[sample][1])) continue; - if (faceBB[i].max[0] < (point[sample][0])) continue; - if (faceBB[i].max[1] < (point[sample][1])) continue; - - /* Calculate point inside a triangle check - * for uv0, 1, 2 */ - sub_v2_v2v2(d1, mloopuv[mlooptri[i].tri[2]].uv, mloopuv[mlooptri[i].tri[0]].uv); /* uv2 - uv0 */ - sub_v2_v2v2(d2, mloopuv[mlooptri[i].tri[1]].uv, mloopuv[mlooptri[i].tri[0]].uv); /* uv1 - uv0 */ - sub_v2_v2v2(d3, point[sample], mloopuv[mlooptri[i].tri[0]].uv); /* point - uv0 */ - - dot00 = d1[0] * d1[0] + d1[1] * d1[1]; - dot01 = d1[0] * d2[0] + d1[1] * d2[1]; - dot02 = d1[0] * d3[0] + d1[1] * d3[1]; - dot11 = d2[0] * d2[0] + d2[1] * d2[1]; - dot12 = d2[0] * d3[0] + d2[1] * d3[1]; - - invDenom = (dot00 * dot11 - dot01 * dot01); - invDenom = invDenom ? 1.0f / invDenom : 1.0f; - u = (dot11 * dot02 - dot01 * dot12) * invDenom; - v = (dot00 * dot12 - dot01 * dot02) * invDenom; - - if ((u > 0) && (v > 0) && (u + v < 1)) { isInside = true; } /* is inside a triangle */ - - /* - * If point was inside the face - */ - if (isInside) { + if ((faceBB[i].min[0] > (point[sample][0])) || + (faceBB[i].min[1] > (point[sample][1])) || + (faceBB[i].max[0] < (point[sample][0])) || + (faceBB[i].max[1] < (point[sample][1]))) + { + continue; + } - float uv1co[2], uv2co[2], uv3co[2], uv[2]; - int j; + const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv; + const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv; + const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv; - /* Get triagnle uvs */ - copy_v2_v2(uv1co, mloopuv[mlooptri[i].tri[0]].uv); - copy_v2_v2(uv2co, mloopuv[mlooptri[i].tri[1]].uv); - copy_v2_v2(uv3co, mloopuv[mlooptri[i].tri[2]].uv); + /* If point is inside the face */ + if (isect_point_tri_v2(point[sample], uv1, uv2, uv3) != 0) { + float uv[2]; /* Add b-weights per anti-aliasing sample */ - for (j = 0; j < aa_samples; j++) { + for (int j = 0; j < aa_samples; j++) { uv[0] = point[0][0] + jitter5sample[j * 2] / w; uv[1] = point[0][1] + jitter5sample[j * 2 + 1] / h; - barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index * aa_samples + j].v); + barycentric_weights_v2(uv1, uv2, uv3, uv, tempWeights[index * aa_samples + j].v); } /* Set surface point face values */ @@ -2396,21 +2380,18 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) /* if neighbor has index */ if (tempPoints[ind].tri_index != -1) { - - float uv1co[2], uv2co[2], uv3co[2], uv[2]; - int i = tempPoints[ind].tri_index, j; + float uv[2]; + const int i = tempPoints[ind].tri_index; + const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv; + const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv; + const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv; /* Now calculate pixel data for this pixel as it was on polygon surface */ - copy_v2_v2(uv1co, mloopuv[mlooptri[i].tri[0]].uv); - copy_v2_v2(uv2co, mloopuv[mlooptri[i].tri[1]].uv); - copy_v2_v2(uv3co, mloopuv[mlooptri[i].tri[2]].uv); - /* Add b-weights per anti-aliasing sample */ - for (j = 0; j < aa_samples; j++) { - + for (int j = 0; j < aa_samples; j++) { uv[0] = point[0] + jitter5sample[j * 2] / w; uv[1] = point[1] + jitter5sample[j * 2 + 1] / h; - barycentric_weights_v2(uv1co, uv2co, uv3co, uv, tempWeights[index * aa_samples + j].v); + barycentric_weights_v2(uv1, uv2, uv3, uv, tempWeights[index * aa_samples + j].v); } /* Set values */ @@ -2461,7 +2442,7 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) } /* allocate memory */ sData->total_points = w * h; - dynamicPaint_initAdjacencyData(surface, 1); + dynamicPaint_initAdjacencyData(surface, true); if (sData->adj_data) { PaintAdjData *ed = sData->adj_data; @@ -2503,7 +2484,8 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) f_data->uv_p = MEM_callocN(active_points * sizeof(struct PaintUVPoint), "PaintUVPoint"); f_data->barycentricWeights = MEM_callocN(active_points * aa_samples * sizeof(struct Vec3f), "PaintUVPoint"); - if (!f_data->uv_p || !f_data->barycentricWeights) error = 1; + if (!f_data->uv_p || !f_data->barycentricWeights) + error = 1; } else { error = 1; @@ -2514,8 +2496,10 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) /* in case of allocation error, free everything */ if (error) { if (f_data) { - if (f_data->uv_p) MEM_freeN(f_data->uv_p); - if (f_data->barycentricWeights) MEM_freeN(f_data->barycentricWeights); + if (f_data->uv_p) + MEM_freeN(f_data->uv_p); + if (f_data->barycentricWeights) + MEM_freeN(f_data->barycentricWeights); MEM_freeN(f_data); } } @@ -2527,7 +2511,8 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) for (index = 0; index < (w * h); index++) { if (tempPoints[index].tri_index != -1) { memcpy(&f_data->uv_p[cursor], &tempPoints[index], sizeof(PaintUVPoint)); - memcpy(&f_data->barycentricWeights[cursor * aa_samples], &tempWeights[index * aa_samples], sizeof(Vec3f) * aa_samples); + memcpy(&f_data->barycentricWeights[cursor * aa_samples], &tempWeights[index * aa_samples], + sizeof(Vec3f) * aa_samples); cursor++; } } @@ -2537,10 +2522,14 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) if (error == 1) setError(canvas, N_("Not enough free memory")); - if (faceBB) MEM_freeN(faceBB); - if (tempPoints) MEM_freeN(tempPoints); - if (tempWeights) MEM_freeN(tempWeights); - if (final_index) MEM_freeN(final_index); + if (faceBB) + MEM_freeN(faceBB); + if (tempPoints) + MEM_freeN(tempPoints); + if (tempWeights) + MEM_freeN(tempWeights); + if (final_index) + MEM_freeN(final_index); /* Init surface type data */ if (!error) { @@ -2551,19 +2540,21 @@ int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface) * For debug, output pixel statuses to the color map * -----------------------------------------------------------------*/ #pragma omp parallel for schedule(static) - for (index = 0; index < sData->total_points; index++) - { + for (index = 0; index < sData->total_points; index++) { ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; PaintUVPoint *uvPoint = &((PaintUVPoint *)f_data->uv_p)[index]; PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; pPoint->alpha = 1.0f; /* Every pixel that is assigned as "edge pixel" gets blue color */ - if (uvPoint->neighbour_pixel != -1) pPoint->color[2] = 1.0f; + if (uvPoint->neighbour_pixel != -1) + pPoint->color[2] = 1.0f; /* and every pixel that finally got an polygon gets red color */ - if (uvPoint->tri_index != -1) pPoint->color[0] = 1.0f; + if (uvPoint->tri_index != -1) + pPoint->color[0] = 1.0f; /* green color shows pixel face index hash */ - if (uvPoint->tri_index != -1) pPoint->color[1] = (float)(uvPoint->tri_index % 255) / 256.0f; + if (uvPoint->tri_index != -1) + pPoint->color[1] = (float)(uvPoint->tri_index % 255) / 256.0f; } #endif @@ -2592,7 +2583,8 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam } /* if selected format is openexr, but current build doesnt support one */ #ifndef WITH_OPENEXR - if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG; + if (format == R_IMF_IMTYPE_OPENEXR) + format = R_IMF_IMTYPE_PNG; #endif BLI_strncpy(output_file, filename, sizeof(output_file)); BKE_image_path_ensure_ext_from_imtype(output_file, format); @@ -2619,9 +2611,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam PaintPoint *point = &((PaintPoint *)sData->type_data)[index]; float value = (point->wetness > 1.0f) ? 1.0f : point->wetness; - ibuf->rect_float[pos] = value; - ibuf->rect_float[pos + 1] = value; - ibuf->rect_float[pos + 2] = value; + copy_v3_fl(&ibuf->rect_float[pos], value); ibuf->rect_float[pos + 3] = 1.0f; } } @@ -2635,9 +2625,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam /* Multiply color by alpha if enabled */ if (surface->flags & MOD_DPAINT_MULALPHA) { - ibuf->rect_float[pos] *= ibuf->rect_float[pos + 3]; - ibuf->rect_float[pos + 1] *= ibuf->rect_float[pos + 3]; - ibuf->rect_float[pos + 2] *= ibuf->rect_float[pos + 3]; + mul_v3_fl(&ibuf->rect_float[pos], ibuf->rect_float[pos + 3]); } } /* displace */ @@ -2652,9 +2640,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos] = depth; - ibuf->rect_float[pos + 1] = depth; - ibuf->rect_float[pos + 2] = depth; + copy_v3_fl(&ibuf->rect_float[pos], depth); ibuf->rect_float[pos + 3] = 1.0f; } /* waves */ @@ -2666,9 +2652,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam depth = (0.5f + depth / 2.0f); CLAMP(depth, 0.0f, 1.0f); - ibuf->rect_float[pos] = depth; - ibuf->rect_float[pos + 1] = depth; - ibuf->rect_float[pos + 2] = depth; + copy_v3_fl(&ibuf->rect_float[pos], depth); ibuf->rect_float[pos + 3] = 1.0f; } } @@ -2762,9 +2746,11 @@ static void dynamicPaint_doMaterialTex( if (mat == NULL) { if (bMats->ob_mats) { int mat_nr = mpoly[mlooptri[triIndex].poly].mat_nr; - if (mat_nr >= (*give_totcolp(brushOb))) return; + if (mat_nr >= (*give_totcolp(brushOb))) + return; mat = bMats->ob_mats[mat_nr]; - if (mat == NULL) return; /* No material assigned */ + if (mat == NULL) + return; /* No material assigned */ } else { return; @@ -2777,7 +2763,7 @@ static void dynamicPaint_doMaterialTex( /***************************** Ray / Nearest Point Utils ******************************/ -/* A modified callback to bvh tree raycast. The tree must bust have been built using bvhtree_from_mesh_looptri. +/* A modified callback to bvh tree raycast. The tree must have been built using bvhtree_from_mesh_looptri. * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. * * To optimize brush detection speed this doesn't calculate hit coordinates or normal. @@ -2803,10 +2789,9 @@ static void mesh_tris_spherecast_dp(void *userdata, int index, const BVHTreeRay hit->dist = dist; hit->no[0] = 0.0f; } - } -/* A modified callback to bvh tree nearest point. The tree must bust have been built using bvhtree_from_mesh_looptri. +/* A modified callback to bvh tree nearest point. The tree must have been built using bvhtree_from_mesh_looptri. * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. * * To optimize brush detection speed this doesn't calculate hit normal. @@ -2915,7 +2900,8 @@ static void dynamicPaint_mixPaintColors( static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, DynamicPaintBrushSettings *brush, float isect_height) { float isect_change = isect_height - wPoint->brush_isect; - int hit = 0; + bool hit = false; + /* intersection marked regardless of brush type or hit */ wPoint->brush_isect = isect_height; wPoint->state = DPAINT_WAVE_ISECT_CHANGED; @@ -2924,9 +2910,9 @@ static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, DynamicPaintBrush /* determine hit depending on wave_factor */ if (brush->wave_factor > 0.0f && wPoint->height > isect_height) - hit = 1; + hit = true; else if (brush->wave_factor < 0.0f && wPoint->height < isect_height) - hit = 1; + hit = true; if (hit) { if (brush->wave_type == MOD_DPAINT_WAVEB_DEPTH) { @@ -2948,8 +2934,9 @@ static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, DynamicPaintBrush /* * add brush results to the surface data depending on surface type */ -static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned int index, DynamicPaintBrushSettings *brush, - float paint[3], float influence, float depth, float vel_factor, float timescale) +static void dynamicPaint_updatePointData( + DynamicPaintSurface *surface, unsigned int index, DynamicPaintBrushSettings *brush, + float paint[3], float influence, float depth, float vel_factor, float timescale) { PaintSurfaceData *sData = surface->data; float strength; @@ -2969,9 +2956,7 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned if (do_colorband(brush->vel_ramp, vel_factor, coba_res)) { if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) { - paint[0] = coba_res[0]; - paint[1] = coba_res[1]; - paint[2] = coba_res[2]; + copy_v3_v3(paint, coba_res); } if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA) strength *= coba_res[3]; @@ -2982,12 +2967,10 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned /* mix paint surface */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - float paintWetness = brush->wetness * strength; float paintAlpha = strength; dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, &paintAlpha, &paintWetness, ×cale); - } /* displace surface */ else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) { @@ -3002,10 +2985,10 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned if (brush->flags & MOD_DPAINT_ERASE) { value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; + CLAMP_MIN(value[index], 0.0f); } else { - if (value[index] < depth) value[index] = depth; + CLAMP_MIN(value[index], depth); } } /* vertex weight group surface */ @@ -3014,10 +2997,10 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned if (brush->flags & MOD_DPAINT_ERASE) { value[index] *= (1.0f - strength); - if (value[index] < 0.0f) value[index] = 0.0f; + CLAMP_MIN(value[index], 0.0f); } else { - if (value[index] < strength) value[index] = strength; + CLAMP_MIN(value[index], strength); } } /* wave surface */ @@ -3026,8 +3009,7 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned CLAMP(depth, 0.0f - brush->wave_clamp, brush->wave_clamp); } - dynamicPaint_mixWaveHeight(&((PaintWavePoint *)sData->type_data)[index], - brush, 0.0f - depth); + dynamicPaint_mixWaveHeight(&((PaintWavePoint *)sData->type_data)[index], brush, 0.0f - depth); } /* doing velocity based painting */ @@ -3037,17 +3019,18 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned } /* checks whether surface and brush bounds intersect depending on brush type */ -static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius) +static bool meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius) { if (brush->collision == MOD_DPAINT_COL_VOLUME) return boundsIntersect(b1, b2); else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST) return boundsIntersectDist(b1, b2, brush_radius); - else return 1; + return true; } /* calculate velocity for mesh vertices */ -static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale) +static void dynamicPaint_brushMeshCalculateVelocity( + Scene *scene, Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale) { int i; float prev_obmat[4][4]; @@ -3069,7 +3052,8 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe( + scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_p = CDDM_copy(brush->dm); numOfVerts_p = dm_p->getNumVerts(dm_p); mvert_p = dm_p->getVertArray(dm_p); @@ -3079,13 +3063,15 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe( + scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_c = brush->dm; numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); (*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c * sizeof(Vec3f), "Dynamic Paint brush velocity"); - if (!(*brushVel)) return; + if (!(*brushVel)) + return; /* if mesh is constructive -> num of verts has changed, * only use current frame derived mesh */ @@ -3129,13 +3115,15 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, /* previous frame dm */ scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe( + scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); copy_m4_m4(prev_obmat, ob->obmat); /* current frame dm */ scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe( + scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); /* calculate speed */ mul_m4_v3(prev_obmat, prev_loc); @@ -3166,7 +3154,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, if (brush->flags & MOD_DPAINT_USES_VELOCITY) dynamicPaint_brushMeshCalculateVelocity(scene, brushOb, brush, &brushVelocity, timescale); - if (!brush->dm) return 0; + if (!brush->dm) + return 0; + { BVHTreeFromMesh treeData = {NULL}; float avg_brushNor[3] = {0.0f}; @@ -3220,8 +3210,11 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, int id; /* check grid cell bounding box */ - if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) + if (!grid->s_num[c_index] || + !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius)) + { continue; + } /* loop through cell points and process brush */ #pragma omp parallel for schedule(static) @@ -3282,7 +3275,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* Check volume collision */ if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_tris_spherecast_dp, &treeData) != -1) { + BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, + &hit, mesh_tris_spherecast_dp, &treeData); + if (hit.index != -1) { /* We hit a triangle, now check if collision point normal is facing the point */ /* For optimization sake, hit point normal isn't calculated in ray cast loop */ @@ -3308,7 +3303,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, hit.index = -1; hit.dist = BVH_RAYCAST_DIST_MAX; - BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, &hit, mesh_tris_spherecast_dp, &treeData); + BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_dir, 0.0f, + &hit, mesh_tris_spherecast_dp, &treeData); if (hit.index != -1) { /* Add factor on supersample filter */ @@ -3336,7 +3332,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* If pure distance proximity, find the nearest point on the mesh */ if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { - if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_tris_nearest_point_dp, &treeData) != -1) { + BLI_bvhtree_find_nearest(treeData.tree, ray_start, + &nearest, mesh_tris_nearest_point_dp, &treeData); + if (nearest.index != -1) { proxDist = sqrtf(nearest.dist_sq); copy_v3_v3(hitCo, nearest.co); tri = nearest.index; @@ -3359,7 +3357,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, hit.dist = brush_radius; /* Do a face normal directional raycast, and use that distance */ - if (BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_tris_spherecast_dp, &treeData) != -1) { + BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, + &hit, mesh_tris_spherecast_dp, &treeData); + if (hit.index != -1) { proxDist = hit.dist; madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */ tri = hit.index; @@ -3386,7 +3386,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* mix final sample strength depending on brush settings */ if (hit_found) { /* if "negate volume" enabled, negate all factors within volume*/ - if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { + if (brush->collision == MOD_DPAINT_COL_VOLDIST && + brush->flags & MOD_DPAINT_NEGATE_VOLUME) + { volume_factor = 1.0f - volume_factor; if (inner_proximity) proximity_factor = 1.0f - proximity_factor; @@ -3398,10 +3400,14 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } else if (hit_found == HIT_PROXIMITY) { /* apply falloff curve to the proximity_factor */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - proximity_factor), prox_colorband)) + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && + do_colorband(brush->paint_ramp, (1.0f - proximity_factor), prox_colorband)) + { proximity_factor = prox_colorband[3]; - else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) + } + else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) { proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; + } /* apply sample */ sampleStrength = proximity_factor; } @@ -3473,7 +3479,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } /* Sample proximity colorband if required */ - if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { + if ((hit_found == HIT_PROXIMITY) && + (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) + { if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { sampleColor[0] = prox_colorband[0]; sampleColor[1] = prox_colorband[1]; @@ -3496,7 +3504,6 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* if any sample was inside paint range */ if (brushStrength > 0.0f || depth > 0.0f) { - /* apply supersampling results */ if (samples > 1) { brushStrength /= total_sample; @@ -3516,7 +3523,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, depth /= bData->bNormal[index].normal_scale * total_sample; } - dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale); + dynamicPaint_updatePointData(surface, index, brush, paintColor, + brushStrength, depth, velocity_val, timescale); } } } @@ -3553,7 +3561,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, int invalidParticles = 0; int p = 0; - float solidradius = surface->radius_scale * ((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); + float solidradius = surface->radius_scale * + ((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius); float smooth = brush->particle_smooth * surface->radius_scale; float range = solidradius + smooth; @@ -3561,7 +3570,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, Bounds3D part_bb = {0}; - if (psys->totpart < 1) return 1; + if (psys->totpart < 1) + return 1; /* * Build a kd-tree to optimize distance search @@ -3571,18 +3581,24 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* loop through particles and insert valid ones to the tree */ p = 0; for (ParticleData *pa = psys->particles; p < psys->totpart; p++, pa++) { - /* Proceed only if particle is active */ - if (pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) continue; - else if (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) continue; - else if (pa->flag & PARS_UNEXIST) continue; + if ((pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) || + (pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) || + (pa->flag & PARS_UNEXIST)) + { + continue; + } /* for debug purposes check if any NAN particle proceeds * For some reason they get past activity check, this should rule most of them out */ - if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) { invalidParticles++; continue; } + if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) { + invalidParticles++; + continue; + } /* make sure particle is close enough to canvas */ - if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range)) continue; + if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range)) + continue; BLI_kdtree_insert(tree, p, pa->state.co); @@ -3643,7 +3659,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* Find nearest particle and get distance to it */ BLI_kdtree_find_nearest(tree, bData->realCoord[bData->s_pos[index]].v, &nearest); /* if outside maximum range, no other particle can influence either */ - if (nearest.dist > range) continue; + if (nearest.dist > range) + continue; if (brush->flags & MOD_DPAINT_PART_RAD) { /* use particles individual size */ @@ -3724,11 +3741,14 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, } /* do smoothness if enabled */ - if (smooth_range < 0.0f) smooth_range = 0.0f; - if (smooth) smooth_range /= smooth; + if (smooth_range < 0.0f) + smooth_range = 0.0f; + if (smooth) + smooth_range /= smooth; str = 1.0f - smooth_range; /* if influence is greater, use this one */ - if (str > strength) strength = str; + if (str > strength) + strength = str; } } @@ -3749,8 +3769,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, velocity_val = len_v3(velocity); /* store brush velocity for smudge */ - if ( (surface->type == MOD_DPAINT_SURFACE_T_PAINT) && - (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)) + if ((surface->type == MOD_DPAINT_SURFACE_T_PAINT) && + (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)) { copy_v3_v3(&bData->brush_velocity[index * 4], velocity); mul_v3_fl(&bData->brush_velocity[index * 4], 1.0f / velocity_val); @@ -3761,8 +3781,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { copy_v3_v3(paintColor, &brush->r); } - else if ( (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) || - (surface->type == MOD_DPAINT_SURFACE_T_WAVE)) + else if ((surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) || + (surface->type == MOD_DPAINT_SURFACE_T_WAVE)) { /* get displace depth */ disp_intersect = (1.0f - sqrtf(disp_intersect / radius)) * radius; @@ -3770,7 +3790,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, if (depth < 0.0f) depth = 0.0f; } - dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); + dynamicPaint_updatePointData(surface, index, brush, paintColor, + strength, depth, velocity_val, timescale); } } } @@ -3782,8 +3803,9 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, } /* paint a single point of defined proximity radius to the surface */ -static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush, - Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale) +static int dynamicPaint_paintSinglePoint( + DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush, + Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale) { int index; float brush_radius = brush->paint_distance * surface->radius_scale; @@ -3803,7 +3825,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po float colorband[4] = {0.0f}; float strength; - if (distance > brush_radius) continue; + if (distance > brush_radius) + continue; /* Smooth range or color ramp */ if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH || @@ -3830,12 +3853,16 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po copy_v3_v3(hit_coord, mvert[0].co); mul_m4_v3(brushOb->obmat, hit_coord); - dynamicPaint_doMaterialTex(bMats, paintColor, &alpha_factor, brushOb, bData->realCoord[bData->s_pos[index]].v, hit_coord, 0, brush->dm); + dynamicPaint_doMaterialTex(bMats, paintColor, &alpha_factor, brushOb, + bData->realCoord[bData->s_pos[index]].v, hit_coord, 0, brush->dm); } /* color ramp */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f - strength), colorband)) + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && + do_colorband(brush->paint_ramp, (1.0f - strength), colorband)) + { strength = colorband[3]; + } if (brush->flags & MOD_DPAINT_USES_VELOCITY) { float velocity[3]; @@ -3881,7 +3908,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* get displace depth */ float disp_intersect = (1.0f - sqrtf((brush_radius - distance) / brush_radius)) * brush_radius; depth = (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale; - if (depth < 0.0f) depth = 0.0f; + CLAMP_MIN(depth, 0.0f); } dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale); } @@ -3896,7 +3923,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po /* * Calculate current frame distances and directions for adjacency data */ -static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int force_init) +static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, const bool force_init) { PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -3905,11 +3932,14 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int Vec3f *realCoord = bData->realCoord; int index; - if ((!surface_usesAdjDistance(surface) && !force_init) || !sData->adj_data) return; + if ((!surface_usesAdjDistance(surface) && !force_init) || !sData->adj_data) + return; - if (bData->bNeighs) MEM_freeN(bData->bNeighs); + if (bData->bNeighs) + MEM_freeN(bData->bNeighs); bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets * sizeof(struct BakeAdjPoint), "PaintEffectBake"); - if (!bNeighs) return; + if (!bNeighs) + return; #pragma omp parallel for schedule(static) for (index = 0; index < sData->total_points; index++) { @@ -3925,7 +3955,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int /* dist */ bNeighs[n_index].dist = len_v3(bNeighs[n_index].dir); /* normalize dir */ - if (bNeighs[n_index].dist) mul_v3_fl(bNeighs[n_index].dir, 1.0f / bNeighs[n_index].dist); + if (bNeighs[n_index].dist) + mul_v3_fl(bNeighs[n_index].dir, 1.0f / bNeighs[n_index].dist); } } @@ -3943,7 +3974,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, int } /* find two adjacency points (closest_id) and influence (closest_d) to move paint towards when affected by a force */ -static void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, float force[3], float closest_d[2], int closest_id[2]) +static void surface_determineForceTargetPoints( + PaintSurfaceData *sData, int index, float force[3], float closest_d[2], int closest_id[2]) { BakeAdjPoint *bNeighs = sData->bData->bNeighs; int numOfNeighs = sData->adj_data->n_num[index]; @@ -3957,10 +3989,14 @@ static void surface_determineForceTargetPoints(PaintSurfaceData *sData, int inde int n_index = sData->adj_data->n_index[index] + i; float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); - if (dir_dot > closest_d[0] && dir_dot > 0.0f) { closest_d[0] = dir_dot; closest_id[0] = n_index; } + if (dir_dot > closest_d[0] && dir_dot > 0.0f) { + closest_d[0] = dir_dot; + closest_id[0] = n_index; + } } - if (closest_d[0] < 0.0f) return; + if (closest_d[0] < 0.0f) + return; /* find second closest neigh */ for (i = 0; i < numOfNeighs; i++) { @@ -3968,7 +4004,8 @@ static void surface_determineForceTargetPoints(PaintSurfaceData *sData, int inde float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); float closest_dot = dot_v3v3(bNeighs[n_index].dir, bNeighs[closest_id[0]].dir); - if (n_index == closest_id[0]) continue; + if (n_index == closest_id[0]) + continue; /* only accept neighbor at "other side" of the first one in relation to force dir * so make sure angle between this and closest neigh is greater than first angle */ @@ -4019,12 +4056,13 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus int index, steps, step; float eff_scale, max_velocity = 0.0f; - if (!sData->adj_data) return; + if (!sData->adj_data) + return; /* find max velocity */ for (index = 0; index < sData->total_points; index++) { float vel = bData->brush_velocity[index * 4 + 3]; - if (vel > max_velocity) max_velocity = vel; + CLAMP_MIN(max_velocity, vel); } steps = (int)ceil(max_velocity / bData->average_dist * timescale); @@ -4032,7 +4070,6 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus eff_scale = brush->smudge_strength / (float)steps * timescale; for (step = 0; step < steps; step++) { - for (index = 0; index < sData->total_points; index++) { int i; PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index]; @@ -4042,7 +4079,8 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus int closest_id[2]; float closest_d[2]; - if (!smudge_str) continue; + if (!smudge_str) + continue; /* get force affect points */ surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id); @@ -4056,7 +4094,8 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]]; /* just skip if angle is too extreme */ - if (dir_dot <= 0.0f) continue; + if (dir_dot <= 0.0f) + continue; dir_factor = dir_dot * speed_scale; CLAMP_MAX(dir_factor, brush->smudge_strength); @@ -4079,7 +4118,8 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus * Prepare data required by effects for current frame. * Returns number of steps required */ -static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) +static int dynamicPaint_prepareEffectStep( + DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) { double average_force = 0.0f; float shrink_speed = 0.0f, spread_speed = 0.0f; @@ -4137,7 +4177,8 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s /* force strength */ (*force)[index * 4 + 3] = len_v3(forc); /* normalize and copy */ - if ((*force)[index * 4 + 3]) mul_v3_fl(forc, 1.0f / (*force)[index * 4 + 3]); + if ((*force)[index * 4 + 3]) + mul_v3_fl(forc, 1.0f / (*force)[index * 4 + 3]); copy_v3_v3(&((*force)[index * 4]), forc); } @@ -4171,7 +4212,8 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s /** * Processes active effect step. */ -static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force, PaintPoint *prevPoint, float timescale, float steps) +static void dynamicPaint_doEffectStep( + DynamicPaintSurface *surface, float *force, PaintPoint *prevPoint, float timescale, float steps) { PaintSurfaceData *sData = surface->data; BakeAdjPoint *bNeighs = sData->bData->bNeighs; @@ -4179,7 +4221,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force int index; timescale /= steps; - if (!sData->adj_data) return; + if (!sData->adj_data) + return; /* * Spread Effect @@ -4208,17 +4251,20 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f)) * 0.25f * surface->color_spread_speed; /* do color mixing */ - if (color_mix) mixColors(pPoint->e_color, pPoint->e_color[3], ePoint->e_color, ePoint->e_color[3], color_mix); + if (color_mix) + mixColors(pPoint->e_color, pPoint->e_color[3], ePoint->e_color, ePoint->e_color[3], color_mix); /* Only continue if surrounding point has higher wetness */ - if (ePoint->wetness < pPoint->wetness || ePoint->wetness < MIN_WETNESS) continue; + if (ePoint->wetness < pPoint->wetness || ePoint->wetness < MIN_WETNESS) + continue; w_factor = 1.0f / numOfNeighs * MIN2(ePoint->wetness, 1.0f) * speed_scale; CLAMP(w_factor, 0.0f, 1.0f); /* mix new wetness and color */ pPoint->wetness = (1.0f - w_factor) * pPoint->wetness + w_factor * ePoint->wetness; - pPoint->e_color[3] = mixColors(pPoint->e_color, pPoint->e_color[3], ePoint->e_color, ePoint->e_color[3], w_factor); + pPoint->e_color[3] = mixColors(pPoint->e_color, pPoint->e_color[3], ePoint->e_color, ePoint->e_color[3], + w_factor); } } } @@ -4249,7 +4295,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force /* Check if neighboring point has lower alpha, * if so, decrease this point's alpha as well*/ - if (pPoint->color[3] <= 0.0f && pPoint->e_color[3] <= 0.0f && pPoint->wetness <= 0.0f) continue; + if (pPoint->color[3] <= 0.0f && pPoint->e_color[3] <= 0.0f && pPoint->wetness <= 0.0f) + continue; /* decrease factor for dry paint alpha */ a_factor = (1.0f - ePoint->color[3]) / numOfNeighs * (pPoint->color[3] - ePoint->color[3]) * speed_scale; @@ -4289,7 +4336,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force /* adjust drip speed depending on wetness */ float w_factor = pPoint_prev->wetness - 0.025f; - if (w_factor <= 0) continue; + if (w_factor <= 0) + continue; CLAMP(w_factor, 0.0f, 1.0f); /* get force affect points */ @@ -4305,7 +4353,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force float e_wet = ePoint->wetness; /* just skip if angle is too extreme */ - if (dir_dot <= 0.0f) continue; + if (dir_dot <= 0.0f) + continue; dir_factor = dir_dot * MIN2(speed_scale, 1.0f) * w_factor; CLAMP_MAX(dir_factor, 0.5f); @@ -4317,7 +4366,8 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force /* mix new color */ a_factor = dir_factor / pPoint_prev->wetness; CLAMP(a_factor, 0.0f, 1.0f); - mixColors(ePoint->e_color, ePoint->e_color[3], pPoint_prev->e_color, pPoint_prev->e_color[3], a_factor); + mixColors(ePoint->e_color, ePoint->e_color[3], pPoint_prev->e_color, pPoint_prev->e_color[3], + a_factor); /* dripping is supposed to preserve alpha level */ if (pPoint_prev->e_color[3] > ePoint->e_color[3]) { ePoint->e_color[3] += a_factor * pPoint_prev->e_color[3]; @@ -4348,7 +4398,8 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal /* allocate memory */ PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points * sizeof(PaintWavePoint), "Temp previous points for wave simulation"); - if (!prevPoint) return; + if (!prevPoint) + return; /* calculate average neigh distance (single thread) */ for (index = 0; index < sData->total_points; index++) { @@ -4372,7 +4423,6 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal damp_factor = pow((1.0f - surface->wave_damping), timescale * surface->wave_timescale); for (ss = 0; ss < steps; ss++) { - /* copy previous frame data */ memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(PaintWavePoint)); @@ -4384,7 +4434,8 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal int numOfN = 0, numOfRN = 0; int i; - if (wPoint->state > 0) continue; + if (wPoint->state > 0) + continue; /* calculate force from surrounding points */ for (i = 0; i < numOfNeighs; i++) { @@ -4392,8 +4443,9 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal float dist = bNeighs[n_index].dist * wave_scale; PaintWavePoint *tPoint = &prevPoint[sData->adj_data->n_target[n_index]]; - if (!dist || tPoint->state > 0) continue; - if (dist < min_dist) dist = min_dist; + if (!dist || tPoint->state > 0) + continue; + CLAMP_MIN(dist, min_dist); avg_dist += dist; numOfN++; @@ -4413,7 +4465,8 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal { /* if open borders, apply a fake height to keep waves going on */ avg_n_height = (numOfRN) ? avg_n_height / numOfRN : 0.0f; - wPoint->height = (dt * wave_speed * avg_n_height + wPoint->height * avg_dist) / (avg_dist + dt * wave_speed); + wPoint->height = (dt * wave_speed * avg_n_height + wPoint->height * avg_dist) / + (avg_dist + dt * wave_speed); } /* else do wave eq */ else { @@ -4432,8 +4485,10 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal if (wave_max_slope && avg_dist) { float max_offset = wave_max_slope * avg_dist; float offset = (numOfN) ? (avg_height / numOfN - wPoint->height) : 0.0f; - if (offset > max_offset) wPoint->height += offset - max_offset; - if (offset < -max_offset) wPoint->height += offset + max_offset; + if (offset > max_offset) + wPoint->height += offset - max_offset; + if (offset < -max_offset) + wPoint->height += offset + max_offset; } } } @@ -4470,8 +4525,10 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time int i; float dry_ratio, f_color[4]; float p_wetness = pPoint->wetness; - value_dissolve(&pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG)); - if (pPoint->wetness < 0.0f) pPoint->wetness = 0.0f; + + value_dissolve(&pPoint->wetness, surface->dry_speed, timescale, + (surface->flags & MOD_DPAINT_DRY_LOG) != 0); + CLAMP_MIN(pPoint->wetness, 0.0f); if (pPoint->wetness < surface->color_dry_threshold) { dry_ratio = pPoint->wetness / p_wetness; @@ -4494,7 +4551,8 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time * with these new alpha values. (wet layer color doesnt change)*/ if (pPoint->color[3]) { for (i = 0; i < 3; i++) { - pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_color[3]) / (pPoint->color[3] * (1.0f - pPoint->e_color[3])); + pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_color[3]) / + (pPoint->color[3] * (1.0f - pPoint->e_color[3])); } } } @@ -4514,28 +4572,29 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time } if (surface->flags & MOD_DPAINT_DISSOLVE) { - value_dissolve(&pPoint->color[3], surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG)); + value_dissolve(&pPoint->color[3], surface->diss_speed, timescale, + (surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0); CLAMP_MIN(pPoint->color[3], 0.0f); - value_dissolve(&pPoint->e_color[3], surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG)); + value_dissolve(&pPoint->e_color[3], surface->diss_speed, timescale, + (surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0); CLAMP_MIN(pPoint->e_color[3], 0.0f); } } /* dissolve for float types */ else if (surface->flags & MOD_DPAINT_DISSOLVE && - (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || - surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) + (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || surface->type == MOD_DPAINT_SURFACE_T_WEIGHT)) { float *point = &((float *)sData->type_data)[index]; /* log or linear */ - value_dissolve(point, surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG)); + value_dissolve(point, surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0); CLAMP_MIN(*point, 0.0f); } } } -static int dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob) +static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob) { PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -4544,50 +4603,26 @@ static int dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob int numOfVerts = dm->getNumVerts(dm); int i; - int ret = 0; + bool ret = false; - if (!bData->prev_verts) return 1; + if (!bData->prev_verts) + return true; /* matrix comparison */ - for (i = 0; i < 4; i++) { - int j; - for (j = 0; j < 4; j++) - if (bData->prev_obmat[i][j] != ob->obmat[i][j]) return 1; - } + if (!equals_m4m4(bData->prev_obmat, ob->obmat)) + return true; /* vertices */ #pragma omp parallel for schedule(static) for (i = 0; i < numOfVerts; i++) { - int j; - for (j = 0; j < 3; j++) - if (bData->prev_verts[i].co[j] != mvert[i].co[j]) { - ret = 1; - break; - } + if (!equals_v3v3(bData->prev_verts[i].co, mvert[i].co)) { + ret = true; + } } return ret; } -static int surface_needsVelocityData(DynamicPaintSurface *surface, const Scene *scene) -{ - if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) - return 1; - - if (surface_getBrushFlags(surface, scene) & BRUSH_USES_VELOCITY) - return 1; - - return 0; -} - -static int surface_needsAccelerationData(DynamicPaintSurface *surface) -{ - if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) - return 1; - - return 0; -} - /* Prepare for surface step by creating PaintBakeNormal data */ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Scene *scene, Object *ob) { @@ -4596,15 +4631,16 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce PaintBakeData *bData = sData->bData; DerivedMesh *dm = surface->canvas->dm; int index, new_bdata = 0; - int do_velocity_data = surface_needsVelocityData(surface, scene); - int do_accel_data = surface_needsAccelerationData(surface); + const bool do_velocity_data = ((surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) || + (surface_getBrushFlags(surface, scene) & BRUSH_USES_VELOCITY)); + const bool do_accel_data = (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) != 0; int canvasNumOfVerts = dm->getNumVerts(dm); MVert *mvert = dm->getVertArray(dm); Vec3f *canvas_verts; if (bData) { - int surface_moved = dynamicPaint_surfaceHasMoved(surface, ob); + const bool surface_moved = dynamicPaint_surfaceHasMoved(surface, ob); /* get previous speed for accelertaion */ if (do_accel_data && bData->prev_velocity && bData->velocity) @@ -4620,13 +4656,15 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce } canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts * sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts"); - if (!canvas_verts) return 0; + if (!canvas_verts) + return 0; /* allocate memory if required */ if (!bData) { sData->bData = bData = (struct PaintBakeData *) MEM_callocN(sizeof(struct PaintBakeData), "Dynamic Paint bake data"); if (!bData) { - if (canvas_verts) MEM_freeN(canvas_verts); + if (canvas_verts) + MEM_freeN(canvas_verts); return 0; } @@ -4639,11 +4677,16 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce /* if any allocation failed, free everything */ if (!bData->bNormal || !bData->s_pos || !bData->s_num || !bData->realCoord || !canvas_verts) { - if (bData->bNormal) MEM_freeN(bData->bNormal); - if (bData->s_pos) MEM_freeN(bData->s_pos); - if (bData->s_num) MEM_freeN(bData->s_num); - if (bData->realCoord) MEM_freeN(bData->realCoord); - if (canvas_verts) MEM_freeN(canvas_verts); + if (bData->bNormal) + MEM_freeN(bData->bNormal); + if (bData->s_pos) + MEM_freeN(bData->s_pos); + if (bData->s_num) + MEM_freeN(bData->s_num); + if (bData->realCoord) + MEM_freeN(bData->realCoord); + if (canvas_verts) + MEM_freeN(canvas_verts); return setError(surface->canvas, N_("Not enough free memory")); } @@ -4731,7 +4774,8 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce int t_index = adj_data->n_index[index] + (ss - 1); /* get vertex position at 1/3 of each neigh edge */ mul_v3_fl(bData->realCoord[bData->s_pos[index] + ss].v, 2.0f / 3.0f); - madd_v3_v3fl(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[adj_data->n_target[t_index]].v, 1.0f / 3.0f); + madd_v3_v3fl(bData->realCoord[bData->s_pos[index] + ss].v, + canvas_verts[adj_data->n_target[t_index]].v, 1.0f / 3.0f); } } @@ -4760,8 +4804,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce normal_short_to_float_v3(n1, mvert[tPoint->v1].no); normal_short_to_float_v3(n2, mvert[tPoint->v2].no); normal_short_to_float_v3(n3, mvert[tPoint->v3].no); - interp_v3_v3v3v3(temp_nor, - n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); + interp_v3_v3v3v3(temp_nor, n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v); } mul_v3_v3(temp_nor, ob->size); @@ -4779,7 +4822,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce /* generate surface space partitioning grid */ surfaceGenerateGrid(surface); /* calculate current frame adjacency point distances and global dirs */ - dynamicPaint_prepareAdjacencyData(surface, 0); + dynamicPaint_prepareAdjacencyData(surface, false); /* Copy current frame vertices to check against in next frame */ copy_m4_m4(bData->prev_obmat, ob->obmat); @@ -4799,7 +4842,8 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su PaintBakeData *bData = sData->bData; DynamicPaintCanvasSettings *canvas = surface->canvas; int ret = 1; - if (sData->total_points < 1) return 0; + if (sData->total_points < 1) + return 0; dynamicPaint_surfacePreStep(surface, timescale); /* @@ -4825,24 +4869,23 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su brushObj = NULL; /* select object */ if (surface->brush_group) { - if (go->ob) brushObj = go->ob; + if (go->ob) + brushObj = go->ob; } else brushObj = base->object; - if (!brushObj) { - /* skip item */ - if (surface->brush_group) go = go->next; - else base = base->next; - continue; - } - /* next item */ if (surface->brush_group) go = go->next; else base = base->next; + if (!brushObj) { + /* skip item */ + continue; + } + /* check if target has an active dp modifier */ md = modifiers_findByType(brushObj, eModifierType_DynamicPaint); if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) { @@ -4857,15 +4900,16 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su bData->brush_velocity = MEM_callocN(sData->total_points * sizeof(float) * 4, "Dynamic Paint brush velocity"); /* init adjacency data if not already */ if (!sData->adj_data) - dynamicPaint_initAdjacencyData(surface, 1); + dynamicPaint_initAdjacencyData(surface, true); if (!bData->bNeighs) - dynamicPaint_prepareAdjacencyData(surface, 1); + dynamicPaint_prepareAdjacencyData(surface, true); } /* update object data on this subframe */ if (subframe) { scene_setSubframe(scene, subframe); - BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, + BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } /* Prepare materials if required */ if (brush_usesMaterial(brush, scene)) @@ -4874,12 +4918,13 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* Apply brush on the surface depending on it's collision type */ /* Particle brush: */ if (brush->collision == MOD_DPAINT_COL_PSYS) { - if (brush->psys && brush->psys->part && ELEM(brush->psys->part->type, PART_EMITTER, PART_FLUID) && + if (brush->psys && brush->psys->part && + ELEM(brush->psys->part->type, PART_EMITTER, PART_FLUID) && psys_check_enabled(brushObj, brush->psys)) { - /* Paint a particle system */ - BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt, + BKE_scene_frame_get(scene), ADT_RECALC_ANIM); dynamicPaint_paintParticles(surface, brush->psys, brush, timescale); } } @@ -4899,7 +4944,8 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (subframe) { scene->r.cfra = scene_frame; scene->r.subframe = scene_subframe; - BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, + BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } /* process special brush effects, like smudge */ @@ -4939,8 +4985,10 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su } /* Free temporary effect data */ - if (prevPoint) MEM_freeN(prevPoint); - if (force) MEM_freeN(force); + if (prevPoint) + MEM_freeN(prevPoint); + if (force) + MEM_freeN(force); } } @@ -4968,7 +5016,8 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje for (st = 1; st <= surface->substeps; st++) { float subframe = ((float) st) / (surface->substeps + 1); - if (!dynamicPaint_doStep(scene, cObject, surface, timescale, subframe)) return 0; + if (!dynamicPaint_doStep(scene, cObject, surface, timescale, subframe)) + return 0; } } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 9e81cded9f5..961b45df4e6 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1783,7 +1783,7 @@ void BKE_main_id_clear_newpoins(Main *bmain) } } -static void lib_indirect_test_id(ID *id, Library *lib) +static void lib_indirect_test_id(ID *id, const Library *lib) { #define LIBTAG(a) \ if (a && a->id.lib) { a->id.tag &= ~LIB_TAG_INDIRECT; a->id.tag |= LIB_TAG_EXTERN; } (void)0 @@ -1830,9 +1830,14 @@ static void lib_indirect_test_id(ID *id, Library *lib) #undef LIBTAG } -/* if lib!=NULL, only all from lib local - * bmain is almost certainly G.main */ -void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only, bool set_fake) +/** Make linked datablocks local. + * + * \param bmain Almost certainly G.main. + * \param lib If not NULL, only make local datablocks from this library. + * \param untagged_only If true, only make local datablocks not tagged with LIB_TAG_PRE_EXISTING. + * \param set_fake If true, set fake user on all localized datablocks (except group and objects ones). + */ +void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged_only, const bool set_fake) { ListBase *lbarray[MAX_LIBARRAY]; ID *id, *idn; diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 6fb983a622e..6d6fbe4e7af 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -246,6 +246,9 @@ bool is_negative_m4(float mat[4][4]); bool is_zero_m3(float mat[3][3]); bool is_zero_m4(float mat[4][4]); +bool equals_m3m3(float mat1[3][3], float mat2[3][3]); +bool equals_m4m4(float mat1[4][4], float mat2[4][4]); + /* SpaceTransform helper */ typedef struct SpaceTransform { float local2target[4][4]; diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h index 4cf1d8baaf0..c511ec432ee 100644 --- a/source/blender/blenlib/BLI_task.h +++ b/source/blender/blenlib/BLI_task.h @@ -21,6 +21,9 @@ #ifndef __BLI_TASK_H__ #define __BLI_TASK_H__ +struct Link; +struct ListBase; + /** \file BLI_task.h * \ingroup bli */ @@ -129,6 +132,15 @@ void BLI_task_parallel_range( TaskParallelRangeFunc func, const bool use_threading); +typedef void (*TaskParallelListbaseFunc)(void *userdata, + struct Link *iter, + int index); +void BLI_task_parallel_listbase( + struct ListBase *listbase, + void *userdata, + TaskParallelListbaseFunc func, + const bool use_threading); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 52ff6fd3e8a..0e3f905ef16 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -1828,6 +1828,21 @@ bool is_zero_m4(float mat[4][4]) is_zero_v4(mat[3])); } +bool equals_m3m3(float mat1[3][3], float mat2[3][3]) +{ + return (equals_v3v3(mat1[0], mat2[0]) && + equals_v3v3(mat1[1], mat2[1]) && + equals_v3v3(mat1[2], mat2[2])); +} + +bool equals_m4m4(float mat1[4][4], float mat2[4][4]) +{ + return (equals_v4v4(mat1[0], mat2[0]) && + equals_v4v4(mat1[1], mat2[1]) && + equals_v4v4(mat1[2], mat2[2]) && + equals_v4v4(mat1[3], mat2[3])); +} + /* make a 4x4 matrix out of 3 transform components */ /* matrices are made in the order: scale * rot * loc */ /* TODO: need to have a version that allows for rotation order... */ diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index bebf331e0c1..247f1af846e 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -28,6 +28,8 @@ #include "MEM_guardedalloc.h" +#include "DNA_listBase.h" + #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_task.h" @@ -750,16 +752,13 @@ size_t BLI_task_pool_tasks_done(TaskPool *pool) * * Main functions: * - #BLI_task_parallel_range + * - #BLI_task_parallel_listbase (#ListBase - double linked list) * * TODO: - * - #BLI_task_parallel_foreach_listbase (#ListBase - double linked list) * - #BLI_task_parallel_foreach_link (#Link - single linked list) * - #BLI_task_parallel_foreach_ghash/gset (#GHash/#GSet - hash & set) * - #BLI_task_parallel_foreach_mempool (#BLI_mempool - iterate over mempools) * - * Possible improvements: - * - * - Chunk iterations to reduce number of spin locks. */ /* Allows to avoid using malloc for userdata_chunk in tasks, when small enough. */ @@ -777,29 +776,23 @@ typedef struct ParallelRangeState { int iter; int chunk_size; + SpinLock lock; } ParallelRangeState; BLI_INLINE bool parallel_range_next_iter_get( ParallelRangeState * __restrict state, int * __restrict iter, int * __restrict count) { - uint32_t n, olditer, previter, newiter; - - if (state->iter >= state->stop) { - return false; + bool result = false; + BLI_spin_lock(&state->lock); + if (state->iter < state->stop) { + *count = min_ii(state->chunk_size, state->stop - state->iter); + *iter = state->iter; + state->iter += *count; + result = true; } - - do { - olditer = state->iter; - n = min_ii(state->chunk_size, state->stop - state->iter); - newiter = olditer + n; - previter = atomic_cas_uint32((uint32_t *)&state->iter, olditer, newiter); - } while (UNLIKELY(previter != olditer)); - - *iter = previter; - *count = n; - - return (n != 0); + BLI_spin_unlock(&state->lock); + return result; } static void parallel_range_func( @@ -904,6 +897,7 @@ static void task_parallel_range_ex( */ num_tasks = num_threads * 2; + BLI_spin_init(&state.lock); state.start = start; state.stop = stop; state.userdata = userdata; @@ -922,19 +916,20 @@ static void task_parallel_range_ex( num_tasks = min_ii(num_tasks, (stop - start) / state.chunk_size); for (i = 0; i < num_tasks; i++) { - /* Use this pool's pre-allocated tasks. */ - BLI_task_pool_push_from_thread(task_pool, - parallel_range_func, - NULL, false, - TASK_PRIORITY_HIGH, 0); + BLI_task_pool_push(task_pool, + parallel_range_func, + NULL, false, + TASK_PRIORITY_HIGH); } BLI_task_pool_work_and_wait(task_pool); BLI_task_pool_free(task_pool); + + BLI_spin_end(&state.lock); } /** - * This function allows to parallelized for loops in a similar way to OpenMP's 'parallel for' statement. + * This function allows to parallelize for loops in a similar way to OpenMP's 'parallel for' statement. * * \param start First index to process. * \param stop Index to stop looping (excluded). @@ -985,3 +980,115 @@ void BLI_task_parallel_range( #undef MALLOCA #undef MALLOCA_FREE +typedef struct ParallelListbaseState { + void *userdata; + TaskParallelListbaseFunc func; + + int chunk_size; + int index; + Link *link; + SpinLock lock; +} ParallelListState; + +BLI_INLINE Link *parallel_listbase_next_iter_get( + ParallelListState * __restrict state, + int * __restrict index, + int * __restrict count) +{ + int task_count = 0; + BLI_spin_lock(&state->lock); + Link *result = state->link; + if (LIKELY(result != NULL)) { + *index = state->index; + while (state->link != NULL && task_count < state->chunk_size) { + ++task_count; + state->link = state->link->next; + } + state->index += task_count; + } + BLI_spin_unlock(&state->lock); + *count = task_count; + return result; +} + +static void parallel_listbase_func( + TaskPool * __restrict pool, + void *UNUSED(taskdata), + int UNUSED(threadid)) +{ + ParallelListState * __restrict state = BLI_task_pool_userdata(pool); + Link *link; + int index, count; + + while ((link = parallel_listbase_next_iter_get(state, &index, &count)) != NULL) { + for (int i = 0; i < count; ++i) { + state->func(state->userdata, link, index + i); + link = link->next; + } + } +} + +/** + * This function allows to parallelize for loops over ListBase items. + * + * \param listbase The double linked list to loop over. + * \param userdata Common userdata passed to all instances of \a func. + * \param func Callback function. + * \param use_threading If \a true, actually split-execute loop in threads, else just do a sequential forloop + * (allows caller to use any kind of test to switch on parallelization or not). + * + * \note There is no static scheduling here, since it would need another full loop over items to count them... + */ +void BLI_task_parallel_listbase( + struct ListBase *listbase, + void *userdata, + TaskParallelListbaseFunc func, + const bool use_threading) +{ + TaskScheduler *task_scheduler; + TaskPool *task_pool; + ParallelListState state; + int i, num_threads, num_tasks; + + if (BLI_listbase_is_empty(listbase)) { + return; + } + + if (!use_threading) { + i = 0; + for (Link *link = listbase->first; link != NULL; link = link->next, ++i) { + func(userdata, link, i); + } + return; + } + + task_scheduler = BLI_task_scheduler_get(); + task_pool = BLI_task_pool_create(task_scheduler, &state); + num_threads = BLI_task_scheduler_num_threads(task_scheduler); + + /* The idea here is to prevent creating task for each of the loop iterations + * and instead have tasks which are evenly distributed across CPU cores and + * pull next iter to be crunched using the queue. + */ + num_tasks = num_threads * 2; + + state.index = 0; + state.link = listbase->first; + state.userdata = userdata; + state.func = func; + state.chunk_size = 32; + BLI_spin_init(&state.lock); + + for (i = 0; i < num_tasks; i++) { + /* Use this pool's pre-allocated tasks. */ + BLI_task_pool_push_from_thread(task_pool, + parallel_listbase_func, + NULL, false, + TASK_PRIORITY_HIGH, 0); + } + + BLI_task_pool_work_and_wait(task_pool); + BLI_task_pool_free(task_pool); + + BLI_spin_end(&state.lock); +} diff --git a/source/blender/bmesh/intern/bmesh_iterators.c b/source/blender/bmesh/intern/bmesh_iterators.c index 4ba462f2165..cc79e28a361 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.c +++ b/source/blender/bmesh/intern/bmesh_iterators.c @@ -272,7 +272,7 @@ int BM_iter_mesh_bitmap_from_filter( } } - return i; + return bitmap_enabled; } /** diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index e3be4db804b..b120b48447f 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -1042,13 +1042,14 @@ void bmo_create_cube_exec(BMesh *bm, BMOperator *op) float off = BMO_slot_float_get(op->slots_in, "size") / 2.0f; const bool calc_uvs = BMO_slot_bool_get(op->slots_in, "calc_uvs"); int i, x, y, z; + /* rotation order set to match 'BM_mesh_calc_uvs_cube' */ const char faces[6][4] = { - {1, 3, 2, 0}, - {3, 7, 6, 2}, - {7, 5, 4, 6}, - {5, 1, 0, 4}, - {0, 2, 6, 4}, - {5, 7, 3, 1}, + {0, 1, 3, 2}, + {2, 3, 7, 6}, + {6, 7, 5, 4}, + {4, 5, 1, 0}, + {2, 6, 4, 0}, + {7, 3, 1, 5}, }; BMO_slot_mat4_get(op->slots_in, "matrix", mat); @@ -1093,7 +1094,8 @@ void bmo_create_cube_exec(BMesh *bm, BMOperator *op) /** * Fills first available UVmap with cube-like UVs for all faces OpFlag-ged by given flag. * - * \note Expects tagged faces to be six quads... + * \note Expects tagged faces to be six quads. + * \note Caller must order faces for correct alignment. * * \param bm The BMesh to operate on. * \param oflag The flag to check faces with. diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c index e6437aa6c59..9d1f7fa45d2 100644 --- a/source/blender/bmesh/tools/bmesh_intersect.c +++ b/source/blender/bmesh/tools/bmesh_intersect.c @@ -85,6 +85,8 @@ /* insert bl_debug_draw_quad_clear... here */ #endif +// #define USE_DUMP + static void tri_v3_scale( float v1[3], float v2[3], float v3[3], const float t) @@ -652,7 +654,7 @@ static void bm_isect_tri_tri( #endif if (e) { #ifdef USE_DUMP - printf(" adding to edge %d\n", BM_elem_index_get(e)); + printf("# adding to edge %d\n", BM_elem_index_get(e)); #endif edge_verts_add(s, e, fv_b[i_b], true); } @@ -769,16 +771,13 @@ static void bm_isect_tri_tri( continue; iv = bm_isect_edge_tri(s, fv_b[i_e0], fv_b[i_e1], fv_a, a_index, f_a_cos, f_a_nor, &side); if (iv) { - /* check this wasn't handled above */ - if (!(side >= IX_EDGE_TRI_EDGE0 && side <= IX_EDGE_TRI_EDGE2)) { - BLI_assert(BLI_array_findindex((void **)iv_ls_a, STACK_SIZE(iv_ls_a), iv) == -1); - BLI_assert(BLI_array_findindex((void **)iv_ls_b, STACK_SIZE(iv_ls_b), iv) == -1); - STACK_PUSH(iv_ls_a, iv); - STACK_PUSH(iv_ls_b, iv); + BLI_assert(BLI_array_findindex((void **)iv_ls_a, STACK_SIZE(iv_ls_a), iv) == -1); + BLI_assert(BLI_array_findindex((void **)iv_ls_b, STACK_SIZE(iv_ls_b), iv) == -1); + STACK_PUSH(iv_ls_a, iv); + STACK_PUSH(iv_ls_b, iv); #ifdef USE_DUMP - printf(" ('EDGE-RAY-B', %d),\n", side); + printf(" ('EDGE-TRI-B', %d),\n", side); #endif - } } } } @@ -873,7 +872,7 @@ static void raycast_callback(void *userdata, #endif #ifdef USE_DUMP - printf("%s: Adding depth %f\n", __func__, depth); + printf("%s: Adding depth %f\n", __func__, dist); #endif BLI_buffer_append(raycast_data->z_buffer, float, dist); } @@ -909,7 +908,7 @@ static int isect_bvhtree_point_v3( &raycast_data); #ifdef USE_DUMP - printf("%s: Total intersections: %d\n", __func__, raycast_data.num_isect); + printf("%s: Total intersections: %d\n", __func__, z_buffer.count); #endif int num_isect; diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 40376c38c3b..823cde75334 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -39,6 +39,8 @@ #include "BLI_math_base.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "BKE_context.h" #include "BKE_fcurve.h" #include "BKE_main.h" @@ -685,7 +687,7 @@ static void ed_marker_move_update_header(bContext *C, wmOperator *op) MarkerMove *mm = op->customdata; TimeMarker *marker, *selmarker = NULL; const int offs = RNA_int_get(op->ptr, "frames"); - char str[256]; + char str[UI_MAX_DRAW_STR]; char str_offs[NUM_STR_REP_LEN]; int totmark; const bool use_time = ed_marker_move_use_time(mm); @@ -710,14 +712,14 @@ static void ed_marker_move_update_header(bContext *C, wmOperator *op) if (totmark == 1 && selmarker) { /* we print current marker value */ if (use_time) { - BLI_snprintf(str, sizeof(str), "Marker %.2f offset %s", FRA2TIME(selmarker->frame), str_offs); + BLI_snprintf(str, sizeof(str), IFACE_("Marker %.2f offset %s"), FRA2TIME(selmarker->frame), str_offs); } else { - BLI_snprintf(str, sizeof(str), "Marker %d offset %s", selmarker->frame, str_offs); + BLI_snprintf(str, sizeof(str), IFACE_("Marker %d offset %s"), selmarker->frame, str_offs); } } else { - BLI_snprintf(str, sizeof(str), "Marker offset %s", str_offs); + BLI_snprintf(str, sizeof(str), IFACE_("Marker offset %s"), str_offs); } ED_area_headerprint(CTX_wm_area(C), str); diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 218f215a350..6afc5a357c8 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -291,12 +291,8 @@ void preEditBoneDuplicate(ListBase *editbones) /** * Helper function for #postEditBoneDuplicate, * return the destination pchan from the original. - * - * \param use_orig_fallback: return the input value if no new channel is found. */ -static bPoseChannel *pchan_duplicate_map( - const bPose *pose, GHash *name_map, - bPoseChannel *pchan_src, bool use_orig_fallback) +static bPoseChannel *pchan_duplicate_map(const bPose *pose, GHash *name_map, bPoseChannel *pchan_src) { bPoseChannel *pchan_dst = NULL; const char *name_src = pchan_src->name; @@ -305,7 +301,7 @@ static bPoseChannel *pchan_duplicate_map( pchan_dst = BKE_pose_channel_find_name(pose, name_dst); } - if ((pchan_dst == NULL) && use_orig_fallback) { + if (pchan_dst == NULL) { pchan_dst = pchan_src; } @@ -325,6 +321,9 @@ void postEditBoneDuplicate(struct ListBase *editbones, Object *ob) for (EditBone *ebone_src = editbones->first; ebone_src; ebone_src = ebone_src->next) { EditBone *ebone_dst = ebone_src->temp.ebone; + if (!ebone_dst) { + ebone_dst = ED_armature_bone_get_mirrored(editbones, ebone_src); + } if (ebone_dst) { BLI_ghash_insert(name_map, ebone_src->name, ebone_dst->name); } @@ -338,7 +337,7 @@ void postEditBoneDuplicate(struct ListBase *editbones, Object *ob) bPoseChannel *pchan_dst = BKE_pose_channel_find_name(ob->pose, ebone_dst->name); if (pchan_dst) { if (pchan_src->custom_tx) { - pchan_dst->custom_tx = pchan_duplicate_map(ob->pose, name_map, pchan_src->custom_tx, true); + pchan_dst->custom_tx = pchan_duplicate_map(ob->pose, name_map, pchan_src->custom_tx); } } } @@ -682,7 +681,7 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op) } } - /* Run though the list and fix the pointers */ + /* Run through the list and fix the pointers */ for (ebone_iter = arm->edbo->first; ebone_iter && ebone_iter != ebone_first_dupe; ebone_iter = ebone_iter->next) { if (ebone_iter->temp.ebone) { /* copy all flags except for ... */ diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index a984e5d1ccd..dca9aa3e446 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -762,7 +762,7 @@ typedef struct tPoseLib_PreviewData { char searchstr[64]; /* (Part of) Name to search for to filter poses that get shown */ char searchold[64]; /* Previously set searchstr (from last loop run), so that we can detected when to rebuild searchp */ - char headerstr[200]; /* Info-text to print in header */ + char headerstr[UI_MAX_DRAW_STR]; /* Info-text to print in header */ } tPoseLib_PreviewData; /* defines for tPoseLib_PreviewData->state values */ @@ -1016,7 +1016,7 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) if (pld->state == PL_PREVIEW_RUNNING) { if (pld->flag & PL_PREVIEW_SHOWORIGINAL) { BLI_strncpy(pld->headerstr, - "PoseLib Previewing Pose: [Showing Original Pose] | Use Tab to start previewing poses again", + IFACE_("PoseLib Previewing Pose: [Showing Original Pose] | Use Tab to start previewing poses again"), sizeof(pld->headerstr)); ED_area_headerprint(pld->sa, pld->headerstr); } @@ -1041,16 +1041,16 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) BLI_strncpy(markern, pld->marker ? pld->marker->name : "No Matches", sizeof(markern)); BLI_snprintf(pld->headerstr, sizeof(pld->headerstr), - "PoseLib Previewing Pose: Filter - [%s] | " - "Current Pose - \"%s\" | " - "Use ScrollWheel or PageUp/Down to change", + IFACE_("PoseLib Previewing Pose: Filter - [%s] | " + "Current Pose - \"%s\" | " + "Use ScrollWheel or PageUp/Down to change"), tempstr, markern); ED_area_headerprint(pld->sa, pld->headerstr); } else { BLI_snprintf(pld->headerstr, sizeof(pld->headerstr), - "PoseLib Previewing Pose: \"%s\" | " - "Use ScrollWheel or PageUp/Down to change", + IFACE_("PoseLib Previewing Pose: \"%s\" | " + "Use ScrollWheel or PageUp/Down to change"), pld->marker->name); ED_area_headerprint(pld->sa, pld->headerstr); } diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c index 16ba1483e38..9ef46c63f0f 100644 --- a/source/blender/editors/armature/pose_slide.c +++ b/source/blender/editors/armature/pose_slide.c @@ -51,6 +51,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "UI_interface.h" + #include "ED_armature.h" #include "ED_keyframes_draw.h" #include "ED_markers.h" @@ -544,7 +546,7 @@ static void pose_slide_reset(tPoseSlideOp *pso) /* draw percentage indicator in header */ static void pose_slide_draw_status(tPoseSlideOp *pso) { - char status_str[256]; + char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; switch (pso->mode) { diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c index 561a8e4b61c..df05397258c 100644 --- a/source/blender/editors/gpencil/gpencil_brush.c +++ b/source/blender/editors/gpencil/gpencil_brush.c @@ -906,7 +906,7 @@ static void gpencil_toggle_brush_cursor(bContext *C, bool enable) static void gpsculpt_brush_header_set(bContext *C, tGP_BrushEditData *gso) { const char *brush_name = NULL; - char str[256] = ""; + char str[UI_MAX_DRAW_STR] = ""; RNA_enum_name(rna_enum_gpencil_sculpt_brush_items, gso->brush_type, &brush_name); diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index 37e9a0edd00..242cbf79a83 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -44,6 +44,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "UI_interface.h" + #include "ED_mesh.h" #include "ED_numinput.h" #include "ED_screen.h" @@ -72,14 +74,12 @@ typedef struct { float segments; /* Segments as float so smooth mouse pan works in small increments */ } BevelData; -#define HEADER_LENGTH 180 - static void edbm_bevel_update_header(bContext *C, wmOperator *op) { const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), " "Vertex Only: %s (V), Offset: %s, Segments: %d"); - char msg[HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); @@ -98,7 +98,7 @@ static void edbm_bevel_update_header(bContext *C, wmOperator *op) RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str); - BLI_snprintf(msg, HEADER_LENGTH, str, type_str, + BLI_snprintf(msg, sizeof(msg), str, type_str, WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")), WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")), offset_str, RNA_int_get(op->ptr, "segments")); diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c index 097117cce6b..3e0747f055f 100644 --- a/source/blender/editors/mesh/editmesh_inset.c +++ b/source/blender/editors/mesh/editmesh_inset.c @@ -44,6 +44,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "UI_interface.h" + #include "ED_mesh.h" #include "ED_numinput.h" #include "ED_screen.h" @@ -54,8 +56,6 @@ #include "mesh_intern.h" /* own include */ -#define HEADER_LENGTH 180 - typedef struct { float old_thickness; float old_depth; @@ -83,7 +83,7 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C) const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RClick), Thickness: %s, " "Depth (Ctrl to tweak): %s (%s), Outset (O): (%s), Boundary (B): (%s), Individual (I): (%s)"); - char msg[HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); @@ -95,7 +95,7 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C) BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness")); BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth")); } - BLI_snprintf(msg, HEADER_LENGTH, str, + BLI_snprintf(msg, sizeof(msg), str, flts_str, flts_str + NUM_STR_REP_LEN, WM_bool_as_string(opdata->modify_depth), diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index 31e1a22fe74..f1c1e4105d0 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -47,6 +47,8 @@ #include "BIF_gl.h" +#include "UI_interface.h" + #include "ED_screen.h" #include "ED_space_api.h" #include "ED_view3d.h" @@ -780,7 +782,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) if (show_cuts) { Scene *sce = CTX_data_scene(C); - char buf[64 + NUM_STR_REP_LEN * 2]; + char buf[UI_MAX_DRAW_STR]; char str_rep[NUM_STR_REP_LEN * 2]; if (hasNumInput(&lcd->num)) { outputNumInput(&lcd->num, str_rep, &sce->unit); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 3511480821a..ab8b7d4e138 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -635,8 +635,8 @@ void ED_area_headerprint(ScrArea *sa, const char *str) if (ar->regiontype == RGN_TYPE_HEADER) { if (str) { if (ar->headerstr == NULL) - ar->headerstr = MEM_mallocN(256, "headerprint"); - BLI_strncpy(ar->headerstr, str, 256); + ar->headerstr = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint"); + BLI_strncpy(ar->headerstr, str, UI_MAX_DRAW_STR); } else if (ar->headerstr) { MEM_freeN(ar->headerstr); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 7d663a034ee..88b3bc5d8fd 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -41,6 +41,7 @@ #include "BLI_utildefines.h" #include "BLI_threads.h" +#include "BLT_translation.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -60,6 +61,7 @@ #include "BKE_paint.h" #include "BKE_texture.h" +#include "UI_interface.h" #include "UI_view2d.h" #include "ED_image.h" @@ -1167,20 +1169,17 @@ typedef struct { static void sample_color_update_header(SampleColorData *data, bContext *C) { -#define HEADER_LENGTH 150 - char msg[HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); if (sa) { - BLI_snprintf(msg, HEADER_LENGTH, - "Sample color for %s", + BLI_snprintf(msg, sizeof(msg), + IFACE_("Sample color for %s"), !data->sample_palette ? - "Brush. Use Left Click to sample for palette instead" : - "Palette. Use Left Click to sample more colors"); + IFACE_("Brush. Use Left Click to sample for palette instead") : + IFACE_("Palette. Use Left Click to sample more colors")); ED_area_headerprint(sa, msg); } - -#undef HEADER_LENGTH } static int sample_color_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index aff0a4c3d44..e810f4db7dd 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -197,6 +197,19 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d dx += BLF_width(blf_mono_font, str, sizeof(str)); } + if (channels == 1 && (cp != NULL || fp != NULL)) { + if (fp != NULL) { + BLI_snprintf(str, sizeof(str), " Val:%-.3f |", fp[0]); + } + else if (cp != NULL) { + BLI_snprintf(str, sizeof(str), " Val:%-.3f |", cp[0] / 255.0f); + } + glColor3ub(255, 255, 255); + BLF_position(blf_mono_font, dx, dy, 0); + BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + dx += BLF_width(blf_mono_font, str, sizeof(str)); + } + if (channels >= 3) { glColor3ubv(red); if (fp) diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 88bab733013..8db5a8f9bd3 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -2826,8 +2826,8 @@ typedef struct ImageSampleInfo { int *zp; float *zfp; - int draw; - int color_manage; + bool draw; + bool color_manage; int use_default_view; } ImageSampleInfo; @@ -2901,7 +2901,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event if (ibuf == NULL) { ED_space_image_release_buffer(sima, ibuf, lock); - info->draw = 0; + info->draw = false; return; } @@ -2918,7 +2918,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event info->x = x; info->y = y; - info->draw = 1; + info->draw = true; info->channels = ibuf->channels; info->colp = NULL; @@ -2951,10 +2951,24 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event if (ibuf->rect_float) { fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); - info->colf[0] = fp[0]; - info->colf[1] = fp[1]; - info->colf[2] = fp[2]; - info->colf[3] = fp[3]; + if (ibuf->channels == 4) { + info->colf[0] = fp[0]; + info->colf[1] = fp[1]; + info->colf[2] = fp[2]; + info->colf[3] = fp[3]; + } + else if (ibuf->channels == 3) { + info->colf[0] = fp[0]; + info->colf[1] = fp[1]; + info->colf[2] = fp[2]; + info->colf[3] = 1.0f; + } + else { + info->colf[0] = fp[0]; + info->colf[1] = fp[0]; + info->colf[2] = fp[0]; + info->colf[3] = 1.0f; + } info->colfp = info->colf; copy_v4_v4(info->linearcol, info->colf); @@ -2965,10 +2979,16 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event if (ibuf->zbuf) { info->z = ibuf->zbuf[y * ibuf->x + x]; info->zp = &info->z; + if (ibuf->zbuf == (int*)ibuf->rect) { + info->colp = NULL; + } } if (ibuf->zbuf_float) { info->zf = ibuf->zbuf_float[y * ibuf->x + x]; info->zfp = &info->zf; + if (ibuf->zbuf_float == ibuf->rect_float) { + info->colfp = NULL; + } } if (curve_mapping && ibuf->channels == 4) { diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 8cf0043fd29..6e0b2e6d9c6 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -416,12 +416,10 @@ void NODE_OT_link_viewer(wmOperatorType *ot) static void node_link_update_header(bContext *C, bNodeLinkDrag *UNUSED(nldrag)) { -#define HEADER_LENGTH 256 - char header[HEADER_LENGTH]; + char header[UI_MAX_DRAW_STR]; - BLI_strncpy(header, IFACE_("LMB: drag node link, RMB: cancel"), HEADER_LENGTH); + BLI_strncpy(header, IFACE_("LMB: drag node link, RMB: cancel"), sizeof(header)); ED_area_headerprint(CTX_wm_area(C), header); -#undef HEADER_LENGTH } static int node_count_links(bNodeTree *ntree, bNodeSocket *sock) diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index e3cdedf042b..8ae89941bdb 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -1506,23 +1506,20 @@ static int sequencer_slip_exec(bContext *C, wmOperator *op) static void sequencer_slip_update_header(Scene *scene, ScrArea *sa, SlipData *data, int offset) { -#define HEADER_LENGTH 40 - char msg[HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; if (sa) { if (hasNumInput(&data->num_input)) { char num_str[NUM_STR_REP_LEN]; outputNumInput(&data->num_input, num_str, &scene->unit); - BLI_snprintf(msg, HEADER_LENGTH, "Trim offset: %s", num_str); + BLI_snprintf(msg, sizeof(msg), IFACE_("Trim offset: %s"), num_str); } else { - BLI_snprintf(msg, HEADER_LENGTH, "Trim offset: %d", offset); + BLI_snprintf(msg, sizeof(msg), IFACE_("Trim offset: %d"), offset); } } ED_area_headerprint(sa, msg); - -#undef HEADER_LENGTH } static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *event) diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 345e47940d5..a73a055c5c8 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -713,6 +713,8 @@ static void update_tface_color_layer(DerivedMesh *dm, bool use_mcol) } } } + + dm->dirty |= DM_DIRTY_MCOL_UPDATE_DRAW; } static DMDrawOption draw_tface_mapped__set_draw(void *userData, int origindex, int UNUSED(mat_nr)) @@ -999,7 +1001,16 @@ static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d else { userData.me = NULL; - update_tface_color_layer(dm, !(ob->mode & OB_MODE_TEXTURE_PAINT)); + if ((ob->mode & OB_MODE_ALL_PAINT) == 0) { + + /* Note: this isn't efficient and runs on every redraw, + * its needed so material colors are used for vertex colors. + * In the future we will likely remove 'texface' so, just avoid running this where possible, + * (when vertex paint or weight paint are used). */ + + update_tface_color_layer(dm, !(ob->mode & OB_MODE_TEXTURE_PAINT)); + } + dm->drawFacesTex( dm, draw_tface__set_draw, compareDrawOptions, &userData, dm_draw_flag); diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index 6789970d00f..dfa76753f64 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -35,6 +35,8 @@ #include "BLI_math.h" #include "BLI_blenlib.h" +#include "BLT_translation.h" + #include "BKE_context.h" #include "BKE_unit.h" #include "BKE_gpencil.h" @@ -720,13 +722,13 @@ static bool view3d_ruler_item_mousemove( static void view3d_ruler_header_update(ScrArea *sa) { - const char *text = "Ctrl+LMB: Add, " - "Del: Remove, " - "Ctrl+Drag: Snap, " - "Shift+Drag: Thickness, " - "Ctrl+C: Copy Value, " - "Enter: Store, " - "Esc: Cancel"; + const char *text = IFACE_("Ctrl+LMB: Add, " + "Del: Remove, " + "Ctrl+Drag: Snap, " + "Shift+Drag: Thickness, " + "Ctrl+C: Copy Value, " + "Enter: Store, " + "Esc: Cancel"); ED_area_headerprint(sa, text); } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 29c152c2f6e..5c0c0bcd6c1 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -80,6 +80,7 @@ #include "WM_api.h" #include "UI_view2d.h" +#include "UI_interface.h" #include "UI_interface_icons.h" #include "UI_resources.h" @@ -93,8 +94,6 @@ /* Disabling, since when you type you know what you are doing, and being able to set it to zero is handy. */ // #define USE_NUM_NO_ZERO -#define MAX_INFO_LEN 256 - static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg); static void doEdgeSlide(TransInfo *t, float perc); static void doVertSlide(TransInfo *t, float perc); @@ -2910,7 +2909,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) float pivot[3]; float warp_end_radius[3]; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; const struct BendCustomData *data = t->custom.mode.data; const bool is_clamp = (t->flag & T_ALT_TRANSFORM) == 0; @@ -2948,13 +2947,13 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %s Radius: %s Alt, Clamp %s"), + BLI_snprintf(str, sizeof(str), IFACE_("Bend Angle: %s Radius: %s Alt, Clamp %s"), &c[0], &c[NUM_STR_REP_LEN], WM_bool_as_string(is_clamp)); } else { /* default header print */ - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %.3f Radius: %.4f, Alt, Clamp %s"), + BLI_snprintf(str, sizeof(str), IFACE_("Bend Angle: %.3f Radius: %.4f, Alt, Clamp %s"), RAD2DEGF(values.angle), values.scale * data->warp_init_dist, WM_bool_as_string(is_clamp)); } @@ -3104,7 +3103,7 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3]; float value; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; const bool is_local_center = transdata_check_local_center(t, t->around); copy_m3_m4(persmat, t->viewmat); @@ -3124,11 +3123,11 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Shear: %s %s"), c, t->proptext); } else { /* default header print */ - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %.3f %s (Press X or Y to set shear axis)"), value, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Shear: %.3f %s (Press X or Y to set shear axis)"), value, t->proptext); } unit_m3(smat); @@ -3228,7 +3227,7 @@ static void initResize(TransInfo *t) t->num.unit_type[2] = B_UNIT_NONE; } -static void headerResize(TransInfo *t, const float vec[3], char str[MAX_INFO_LEN]) +static void headerResize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; size_t ofs = 0; @@ -3244,32 +3243,32 @@ static void headerResize(TransInfo *t, const float vec[3], char str[MAX_INFO_LEN if (t->con.mode & CON_APPLY) { switch (t->num.idx_max) { case 0: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s%s %s"), + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Scale: %s%s %s"), &tvec[0], t->con.text, t->proptext); break; case 1: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s : %s%s %s"), + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Scale: %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); break; case 2: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s : %s : %s%s %s"), &tvec[0], + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Scale: %s : %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); break; } } else { if (t->flag & T_2D_EDIT) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale X: %s Y: %s%s %s"), + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Scale X: %s Y: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale X: %s Y: %s Z: %s%s %s"), + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Scale X: %s Y: %s Z: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } } if (t->flag & T_PROP_EDIT_ALL) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } } @@ -3394,7 +3393,7 @@ static void applyResize(TransInfo *t, const int mval[2]) TransData *td; float mat[3][3]; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; if (t->flag & T_AUTOVALUES) { copy_v3_v3(t->values, t->auto_values); @@ -3512,7 +3511,7 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) TransData *td; float size[3], mat[3][3]; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; copy_v3_fl(size, t->values[0]); @@ -3610,7 +3609,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) float vec[3]; float ratio, radius; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; TransData *td = t->data; ratio = t->values[0]; @@ -3629,11 +3628,11 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("To Sphere: %s %s"), c, t->proptext); } else { /* default header print */ - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); } @@ -3964,7 +3963,7 @@ static void applyRotationValue(TransInfo *t, float angle, float axis[3]) static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float final; @@ -3995,15 +3994,15 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %.2f%s %s"), + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Rot: %.2f%s %s"), RAD2DEGF(final), t->con.text, t->proptext); } if (t->flag & T_PROP_EDIT_ALL) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } applyRotationValue(t, final, t->axis); @@ -4074,7 +4073,7 @@ static void applyTrackballValue(TransInfo *t, const float axis1[3], const float static void applyTrackball(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float axis1[3], axis2[3]; #if 0 /* UNUSED */ @@ -4100,16 +4099,16 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %s %s %s"), + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Trackball: %s %s %s"), &c[0], &c[NUM_STR_REP_LEN], t->proptext); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %.2f %.2f %s"), + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Trackball: %.2f %.2f %s"), RAD2DEGF(phi[0]), RAD2DEGF(phi[1]), t->proptext); } if (t->flag & T_PROP_EDIT_ALL) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } #if 0 /* UNUSED */ @@ -4206,7 +4205,7 @@ static void initTranslation(TransInfo *t) } } -static void headerTranslation(TransInfo *t, const float vec[3], char str[MAX_INFO_LEN]) +static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR]) { size_t ofs = 0; char tvec[NUM_STR_REP_LEN * 3]; @@ -4268,15 +4267,15 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[MAX_INF if (t->con.mode & CON_APPLY) { switch (t->num.idx_max) { case 0: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s (%s)%s %s %s", + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, "D: %s (%s)%s %s %s", &tvec[0], distvec, t->con.text, t->proptext, autoik); break; case 1: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s D: %s (%s)%s %s %s", + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, "D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext, autoik); break; case 2: - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s D: %s D: %s (%s)%s %s %s", + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, "D: %s D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, autoik); break; @@ -4284,18 +4283,18 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[MAX_INF } else { if (t->flag & T_2D_EDIT) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "Dx: %s Dy: %s (%s)%s %s", + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, autoik); } } if (t->flag & T_PROP_EDIT_ALL) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } if (t->spacetype == SPACE_NODE) { @@ -4304,11 +4303,11 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[MAX_INF if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { const char *str_old = BLI_strdup(str); const char *str_dir = (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT) ? IFACE_("right") : IFACE_("left"); - char str_km[MAX_INFO_LEN]; + char str_km[64]; WM_modalkeymap_items_to_string(t->keymap, TFM_MODAL_INSERTOFS_TOGGLE_DIR, true, sizeof(str_km), str_km); - ofs += BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Auto-offset set to %s - press %s to toggle direction | %s"), + ofs += BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("Auto-offset set to %s - press %s to toggle direction | %s"), str_dir, str_km, str_old); MEM_freeN((void *)str_old); @@ -4376,7 +4375,7 @@ static void applyTranslationValue(TransInfo *t, const float vec[3]) static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; float value_final[3]; if (t->flag & T_AUTOVALUES) { @@ -4468,7 +4467,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) { float distance; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; size_t ofs = 0; TransData *td = t->data; @@ -4481,29 +4480,29 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = -distance; /* header print for NumInput */ - ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), sizeof(str) - ofs); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", c); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, " %s", c); } else { /* default header print */ - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %.4f", distance); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, " %.4f", distance); } if (t->proptext[0]) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", t->proptext); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, " %s", t->proptext); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, ", ("); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, ", ("); if (t->keymap) { wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE); if (kmi) { - ofs += WM_keymap_item_to_string(kmi, false, MAX_INFO_LEN - ofs, str + ofs); + ofs += WM_keymap_item_to_string(kmi, false, sizeof(str) - ofs, str + ofs); } } - BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Even Thickness %s"), + BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_(" or Alt) Even Thickness %s"), WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0)); /* done with header string */ @@ -4563,7 +4562,7 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) { TransData *td = t->data; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; float final; @@ -4580,13 +4579,13 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %s° %s"), &c[0], t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Tilt: %s° %s"), &c[0], t->proptext); /* XXX For some reason, this seems needed for this op, else RNA prop is not updated... :/ */ t->values[0] = final; } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -4644,7 +4643,7 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float ratio; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; ratio = t->values[0]; @@ -4659,10 +4658,10 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c); + BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %s"), c); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %3f"), ratio); + BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } for (i = 0; i < t->total; i++, td++) { @@ -4724,7 +4723,7 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) float ratio; int i; bool initial_feather = false; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; ratio = t->values[0]; @@ -4739,10 +4738,10 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %s"), c); + BLI_snprintf(str, sizeof(str), IFACE_("Feather Shrink/Fatten: %s"), c); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %3f"), ratio); + BLI_snprintf(str, sizeof(str), IFACE_("Feather Shrink/Fatten: %3f"), ratio); } /* detect if no points have feather yet */ @@ -4824,7 +4823,7 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float ratio; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; ratio = t->values[0]; @@ -4839,10 +4838,10 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c); + BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %s"), c); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %3f"), ratio); + BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } for (i = 0; i < t->total; i++, td++) { @@ -4897,7 +4896,7 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) float vec[3], axis[3]; float distance; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; TransData *td = t->data; distance = t->values[0]; @@ -4914,11 +4913,11 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext); } else { /* default header print */ - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext); } if (t->con.applyRot && t->con.mode & CON_APPLY) { @@ -4989,7 +4988,7 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float weight; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; weight = t->values[0]; @@ -5008,16 +5007,16 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); if (weight >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: +%s %s"), c, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: %s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %s %s"), c, t->proptext); } else { /* default header print */ if (weight >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%.3f %s"), weight, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: +%.3f %s"), weight, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -5069,7 +5068,7 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float crease; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; crease = t->values[0]; @@ -5088,16 +5087,16 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); if (crease >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Crease: +%s %s"), c, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: %s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Crease: %s %s"), c, t->proptext); } else { /* default header print */ if (crease >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%.3f %s"), crease, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Crease: +%.3f %s"), crease, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: %.3f %s"), crease, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Crease: %.3f %s"), crease, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -5151,7 +5150,7 @@ static void initBoneSize(TransInfo *t) t->num.unit_type[2] = B_UNIT_NONE; } -static void headerBoneSize(TransInfo *t, const float vec[3], char str[MAX_INFO_LEN]) +static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; if (hasNumInput(&t->num)) { @@ -5166,13 +5165,13 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[MAX_INFO_L /* hmm... perhaps the y-axis values don't need to be shown? */ if (t->con.mode & CON_APPLY) { if (t->num.idx_max == 0) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext); + BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB: %s : %s : %s%s %s"), + BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s : %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"), + BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } } @@ -5203,7 +5202,7 @@ static void applyBoneSize(TransInfo *t, const int mval[2]) float size[3], mat[3][3]; float ratio; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; // TRANSFORM_FIX_ME MOVE TO MOUSE INPUT /* for manipulator, center handle, the scaling can't be done relative to center */ @@ -5282,7 +5281,7 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float ratio; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; ratio = t->values[0]; @@ -5297,10 +5296,10 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %s"), c); + BLI_snprintf(str, sizeof(str), IFACE_("Envelope: %s"), c); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %3f"), ratio); + BLI_snprintf(str, sizeof(str), IFACE_("Envelope: %3f"), ratio); } for (i = 0; i < t->total; i++, td++) { @@ -6959,7 +6958,7 @@ static void doEdgeSlide(TransInfo *t, float perc) static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float final; EdgeSlideData *sld = t->custom.mode.data; @@ -6982,20 +6981,20 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = final; /* header string */ - ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Edge Slide: "), MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Edge Slide: "), sizeof(str) - ofs); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - ofs += BLI_strncpy_rlen(str + ofs, &c[0], MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%.4f ", final); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%.4f ", final); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(E)ven: %s, "), WM_bool_as_string(use_even)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("(E)ven: %s, "), WM_bool_as_string(use_even)); if (use_even) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(F)lipped: %s, "), WM_bool_as_string(flipped)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("(F)lipped: %s, "), WM_bool_as_string(flipped)); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp)); /* done with header string */ /* do stuff here */ @@ -7527,7 +7526,7 @@ static void doVertSlide(TransInfo *t, float perc) static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float final; VertSlideData *sld = t->custom.mode.data; @@ -7550,20 +7549,20 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = final; /* header string */ - ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vert Slide: "), MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vert Slide: "), sizeof(str) - ofs); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c, &t->scene->unit); - ofs += BLI_strncpy_rlen(str + ofs, &c[0], MAX_INFO_LEN - ofs); + ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs); } else { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%.4f ", final); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%.4f ", final); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(E)ven: %s, "), WM_bool_as_string(use_even)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("(E)ven: %s, "), WM_bool_as_string(use_even)); if (use_even) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("(F)lipped: %s, "), WM_bool_as_string(flipped)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("(F)lipped: %s, "), WM_bool_as_string(flipped)); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp)); + ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, IFACE_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp)); /* done with header string */ /* do stuff here */ @@ -7607,7 +7606,7 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) { TransData *td = t->data; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; float final; @@ -7624,10 +7623,10 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %s"), &c[0]); + BLI_snprintf(str, sizeof(str), IFACE_("Roll: %s"), &c[0]); } else { - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %.2f"), RAD2DEGF(final)); + BLI_snprintf(str, sizeof(str), IFACE_("Roll: %.2f"), RAD2DEGF(final)); } /* set roll values */ @@ -7675,7 +7674,7 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) TransData *td = t->data; float time; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; float fac = 0.1f; @@ -7704,16 +7703,16 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) outputNumInput(&(t->num), c, &t->scene->unit); if (time >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Time: +%s %s"), c, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: %s %s"), c, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Time: %s %s"), c, t->proptext); } else { /* default header print */ if (time >= 0.0f) - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%.3f %s"), time, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Time: +%.3f %s"), time, t->proptext); else - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: %.3f %s"), time, t->proptext); + BLI_snprintf(str, sizeof(str), IFACE_("Time: %.3f %s"), time, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -7759,7 +7758,7 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) TransData *td; float size[3], mat[3][3]; int i; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; /* * OPTIMIZATION: @@ -7777,7 +7776,7 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) t->con.applySize(t, NULL, mat); } - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Mirror%s"), t->con.text); + BLI_snprintf(str, sizeof(str), IFACE_("Mirror%s"), t->con.text); for (i = 0, td = t->data; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -7906,7 +7905,7 @@ static void initSeqSlide(TransInfo *t) t->num.unit_type[1] = B_UNIT_NONE; } -static void headerSeqSlide(TransInfo *t, const float val[2], char str[MAX_INFO_LEN]) +static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; size_t ofs = 0; @@ -7918,15 +7917,15 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[MAX_INFO_L BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]); } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text); + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text); if (t->keymap) { wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE); if (kmi) { - ofs += WM_keymap_item_to_string(kmi, false, MAX_INFO_LEN - ofs, str + ofs); + ofs += WM_keymap_item_to_string(kmi, false, UI_MAX_DRAW_STR - ofs, str + ofs); } } - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Expand to fit %s"), + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" or Alt) Expand to fit %s"), WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0)); } @@ -7948,7 +7947,7 @@ static void applySeqSlideValue(TransInfo *t, const float val[2]) static void applySeqSlide(TransInfo *t, const int mval[2]) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; snapSequenceBounds(t, mval); @@ -8127,7 +8126,7 @@ static void initTimeTranslate(TransInfo *t) t->num.unit_type[0] = B_UNIT_NONE; } -static void headerTimeTranslate(TransInfo *t, char str[MAX_INFO_LEN]) +static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; int ofs = 0; @@ -8166,10 +8165,10 @@ static void headerTimeTranslate(TransInfo *t, char str[MAX_INFO_LEN]) BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); } - ofs += BLI_snprintf(str, MAX_INFO_LEN, IFACE_("DeltaX: %s"), &tvec[0]); + ofs += BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("DeltaX: %s"), &tvec[0]); if (t->flag & T_PROP_EDIT_ALL) { - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, UI_MAX_DRAW_STR - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } } @@ -8231,7 +8230,7 @@ static void applyTimeTranslateValue(TransInfo *t) static void applyTimeTranslate(TransInfo *t, const int mval[2]) { View2D *v2d = (View2D *)t->view; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; /* calculate translation amount from mouse movement - in 'time-grid space' */ if (t->flag & T_MODAL) { @@ -8323,7 +8322,7 @@ static void initTimeSlide(TransInfo *t) t->num.unit_type[0] = B_UNIT_NONE; } -static void headerTimeSlide(TransInfo *t, const float sval, char str[MAX_INFO_LEN]) +static void headerTimeSlide(TransInfo *t, const float sval, char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; @@ -8343,7 +8342,7 @@ static void headerTimeSlide(TransInfo *t, const float sval, char str[MAX_INFO_LE BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); } - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("TimeSlide: %s"), &tvec[0]); + BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("TimeSlide: %s"), &tvec[0]); } static void applyTimeSlideValue(TransInfo *t, float sval) @@ -8400,7 +8399,7 @@ static void applyTimeSlide(TransInfo *t, const int mval[2]) const float *range = t->custom.mode.data; float minx = range[0]; float maxx = range[1]; - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; /* calculate mouse co-ordinates */ UI_view2d_region_to_view(v2d, mval[0], mval[1], &cval[0], &cval[1]); @@ -8473,7 +8472,7 @@ static void initTimeScale(TransInfo *t) t->num.unit_type[0] = B_UNIT_NONE; } -static void headerTimeScale(TransInfo *t, char str[MAX_INFO_LEN]) +static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; @@ -8482,7 +8481,7 @@ static void headerTimeScale(TransInfo *t, char str[MAX_INFO_LEN]) else BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values[0]); - BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleX: %s"), &tvec[0]); + BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleX: %s"), &tvec[0]); } static void applyTimeScaleValue(TransInfo *t) @@ -8526,7 +8525,7 @@ static void applyTimeScaleValue(TransInfo *t) static void applyTimeScale(TransInfo *t, const int UNUSED(mval[2])) { - char str[MAX_INFO_LEN]; + char str[UI_MAX_DRAW_STR]; /* handle numeric-input stuff */ t->vec[0] = t->values[0]; @@ -8558,5 +8557,3 @@ bool checkUseAxisMatrix(TransInfo *t) return false; } - -#undef MAX_INFO_LEN diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 20a8ab5c98c..59442e89787 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -46,6 +46,8 @@ #include "BLI_math_vector.h" #include "BLI_string.h" +#include "BLT_translation.h" + #include "BIF_gl.h" #include "BKE_context.h" @@ -54,6 +56,8 @@ #include "BKE_mesh_mapping.h" #include "BKE_editmesh.h" +#include "UI_interface.h" + #include "ED_mesh.h" #include "ED_uvedit.h" #include "ED_screen.h" @@ -259,25 +263,24 @@ static void stitch_preview_delete(StitchPreviewer *stitch_preview) } } -#define HEADER_LENGTH 256 - /* This function updates the header of the UV editor when the stitch tool updates its settings */ static void stitch_update_header(StitchState *state, bContext *C) { - static char str[] = + const char *str = IFACE_( "Mode(TAB) %s, " "(S)nap %s, " "(M)idpoints %s, " "(L)imit %.2f (Alt Wheel adjust) %s, " "Switch (I)sland, " - "shift select vertices"; + "shift select vertices" + ); - char msg[HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); if (sa) { - BLI_snprintf(msg, HEADER_LENGTH, str, - state->mode == STITCH_VERT ? "Vertex" : "Edge", + BLI_snprintf(msg, sizeof(msg), str, + state->mode == STITCH_VERT ? IFACE_("Vertex") : IFACE_("Edge"), WM_bool_as_string(state->snap_islands), WM_bool_as_string(state->midpoints), state->limit_dist, diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 768624b1968..8e4ba4c0afa 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -49,6 +49,8 @@ #include "BLI_uvproject.h" #include "BLI_string.h" +#include "BLT_translation.h" + #include "BKE_cdderivedmesh.h" #include "BKE_subsurf.h" #include "BKE_context.h" @@ -62,6 +64,8 @@ #include "PIL_time.h" +#include "UI_interface.h" + #include "ED_image.h" #include "ED_mesh.h" #include "ED_screen.h" @@ -554,12 +558,13 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interac RNA_int_set(op->ptr, "iterations", ms->i); if (interactive && (PIL_check_seconds_timer() - ms->lasttime > 0.5)) { - char str[100]; + char str[UI_MAX_DRAW_STR]; param_flush(ms->handle); if (sa) { - BLI_snprintf(str, sizeof(str), "Minimize Stretch. Blend %.2f (Press + and -, or scroll wheel to set)", ms->blend); + BLI_snprintf(str, sizeof(str), + IFACE_("Minimize Stretch. Blend %.2f (Press + and -, or scroll wheel to set)"), ms->blend); ED_area_headerprint(sa, str); } diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 5041eebd126..2e4a4b63b7a 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -405,18 +405,38 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) /* BKE_main_unlock(bmain); */ - wm_link_append_data_free(lapp_data); - /* mark all library linked objects to be updated */ BKE_main_lib_objects_recalc_all(bmain); IMB_colormanagement_check_file_config(bmain); /* append, rather than linking */ if ((flag & FILE_LINK) == 0) { - bool set_fake = RNA_boolean_get(op->ptr, "set_fake"); - BKE_library_make_local(bmain, NULL, true, set_fake); + const bool set_fake = RNA_boolean_get(op->ptr, "set_fake"); + const bool use_recursive = RNA_boolean_get(op->ptr, "use_recursive"); + + if (use_recursive) { + BKE_library_make_local(bmain, NULL, true, set_fake); + } + else { + LinkNode *itemlink; + GSet *done_libraries = BLI_gset_new_ex(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, + __func__, lapp_data->num_libraries); + + for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) { + ID *new_id = ((WMLinkAppendDataItem *)(itemlink->link))->new_id; + + if (new_id && !BLI_gset_haskey(done_libraries, new_id->lib)) { + BKE_library_make_local(bmain, new_id->lib, true, set_fake); + BLI_gset_insert(done_libraries, new_id->lib); + } + } + + BLI_gset_free(done_libraries, NULL); + } } + wm_link_append_data_free(lapp_data); + /* important we unset, otherwise these object wont * link into other scenes from this blend file */ BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); @@ -493,5 +513,8 @@ void WM_OT_append(wmOperatorType *ot) FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); wm_link_append_properties_common(ot, false); - RNA_def_boolean(ot->srna, "set_fake", false, "Fake User", "Set Fake User for appended items (except Objects and Groups)"); + RNA_def_boolean(ot->srna, "set_fake", false, "Fake User", + "Set Fake User for appended items (except Objects and Groups)"); + RNA_def_boolean(ot->srna, "use_recursive", true, "Localize All", + "Localize all appended data, including those indirectly linked from other libraries"); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 37919a79e16..6ef8965a408 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2845,7 +2845,6 @@ void WM_OT_straightline_gesture(wmOperatorType *ot) #define WM_RADIAL_CONTROL_DISPLAY_SIZE (200 * U.pixelsize) #define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE (35 * U.pixelsize) #define WM_RADIAL_CONTROL_DISPLAY_WIDTH (WM_RADIAL_CONTROL_DISPLAY_SIZE - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) -#define WM_RADIAL_CONTROL_HEADER_LENGTH 180 #define WM_RADIAL_MAX_STR 10 typedef struct { @@ -2871,7 +2870,7 @@ typedef struct { static void radial_control_update_header(wmOperator *op, bContext *C) { RadialControl *rc = op->customdata; - char msg[WM_RADIAL_CONTROL_HEADER_LENGTH]; + char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); Scene *scene = CTX_data_scene(C); @@ -2879,34 +2878,33 @@ static void radial_control_update_header(wmOperator *op, bContext *C) if (hasNumInput(&rc->num_input)) { char num_str[NUM_STR_REP_LEN]; outputNumInput(&rc->num_input, num_str, &scene->unit); - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %s", RNA_property_ui_name(rc->prop), num_str); - ED_area_headerprint(sa, msg); + BLI_snprintf(msg, sizeof(msg), "%s: %s", RNA_property_ui_name(rc->prop), num_str); } else { const char *ui_name = RNA_property_ui_name(rc->prop); switch (rc->subtype) { case PROP_NONE: case PROP_DISTANCE: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %0.4f", ui_name, rc->current_value); + BLI_snprintf(msg, sizeof(msg), "%s: %0.4f", ui_name, rc->current_value); break; case PROP_PIXEL: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %d", ui_name, (int)rc->current_value); /* XXX: round to nearest? */ + BLI_snprintf(msg, sizeof(msg), "%s: %d", ui_name, (int)rc->current_value); /* XXX: round to nearest? */ break; case PROP_PERCENTAGE: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %3.1f%%", ui_name, rc->current_value); + BLI_snprintf(msg, sizeof(msg), "%s: %3.1f%%", ui_name, rc->current_value); break; case PROP_FACTOR: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %1.3f", ui_name, rc->current_value); + BLI_snprintf(msg, sizeof(msg), "%s: %1.3f", ui_name, rc->current_value); break; case PROP_ANGLE: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value)); + BLI_snprintf(msg, sizeof(msg), "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value)); break; default: - BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s", ui_name); /* XXX: No value? */ + BLI_snprintf(msg, sizeof(msg), "%s", ui_name); /* XXX: No value? */ break; } - ED_area_headerprint(sa, msg); } + ED_area_headerprint(sa, msg); } } |