| 37 | } |
| 38 | |
| 39 | VtValue |
| 40 | UsdPythonToSdfType(TfPyObjWrapper pyVal, SdfValueTypeName const &targetType) |
| 41 | { |
| 42 | using namespace pxr_boost::python; |
| 43 | |
| 44 | // Extract VtValue from python object. |
| 45 | VtValue val; |
| 46 | { |
| 47 | TfPyLock lock; |
| 48 | val = extract<VtValue>(pyVal.Get())(); |
| 49 | } |
| 50 | |
| 51 | // Attempt to cast the value to what we want. Get a default value for this |
| 52 | // attribute's type name. |
| 53 | VtValue defVal = targetType.GetDefaultValue(); |
| 54 | |
| 55 | // Attempt to cast the given value to the default value's type -- this |
| 56 | // will convert python buffer protocol objects (e.g. numpy arrays) to the |
| 57 | // appropriate typed VtArray when possible. If casting fails, attempt to |
| 58 | // continue with the given value. Deeper in the 'Set()' implementation, |
| 59 | // we'll issue a detailed type mismatch error. |
| 60 | VtValue cast = VtValue::CastToTypeOf(val, defVal); |
| 61 | if (!cast.IsEmpty()) |
| 62 | cast.Swap(val); |
| 63 | |
| 64 | return val; |
| 65 | } |
| 66 | |
| 67 | bool |
| 68 | UsdPythonToMetadataValue( |