diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-08-26 14:04:24 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-08-26 14:31:08 +0400 |
commit | 0e3fa0b7618fa86e97c5f46ae7208c082fd26eb7 (patch) | |
tree | 447fcae65fe6bf4086a79e03a82abb7a4138897b /source/blender/blenkernel/intern/unit.c | |
parent | 600248783b50ddef9b809b0d4c7abd9a9b20fda3 (diff) |
Fix T41590: When scene scale is not 1.0, and units are "None," Blender assumes translations are in meters.
Turned out there were several issues in handling of scale parameter by numinput.
Fixed that by factorizing more some code in common with 'usual' numbuttons eval code
(new `bUnit_getScaleUnit()` helper will return valid scaled value, depending on
given system and type).
Now, numinput behaves as expected - using default unit amended by scale in case no unit is given
(i.e. entering '20' with a scale of 0.01 will give you 20cm, and '20cm' as well!).
Diffstat (limited to 'source/blender/blenkernel/intern/unit.c')
-rw-r--r-- | source/blender/blenkernel/intern/unit.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 98b16b022cd..cdaf72aa191 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -37,6 +37,8 @@ #include "BKE_unit.h" /* own include */ +#include "DNA_scene_types.h" + #ifdef WIN32 # include "BLI_winstuff.h" #endif @@ -789,6 +791,29 @@ double bUnit_BaseScalar(int system, int type) return unit_default(usys)->scalar; } +double bUnit_getScaleUnit(UnitSettings *unit, const int unit_type, double value) +{ + if (unit->system == USER_UNIT_NONE) { + /* Never apply scale_length when not using a unit setting! */ + return value; + } + + switch (unit_type) { + case B_UNIT_LENGTH: + return value * (double)unit->scale_length; + case B_UNIT_CAMERA: + return value * (double)unit->scale_length; + case B_UNIT_AREA: + return value * pow(unit->scale_length, 2); + case B_UNIT_VOLUME: + return value * pow(unit->scale_length, 3); + case B_UNIT_MASS: + return value * pow(unit->scale_length, 3); + default: + return value; + } +} + /* external access */ bool bUnit_IsValid(int system, int type) { |