diff options
Diffstat (limited to 'intern/cycles/blender/blender_util.h')
-rw-r--r-- | intern/cycles/blender/blender_util.h | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index fbcbe15ec5a..bd4852d08e1 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -33,13 +33,15 @@ extern "C" { void BLI_timestr(double _time, char *str); void BKE_image_user_frame_calc(void *iuser, int cfra, int fieldnr); void BKE_image_user_file_path(void *iuser, void *ima, char *path); +unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame); +float *BKE_image_get_float_pixels_for_frame(void *image, int frame); } CCL_NAMESPACE_BEGIN -static inline BL::Mesh object_to_mesh(BL::Object self, BL::Scene scene, bool apply_modifiers, bool render) +static inline BL::Mesh object_to_mesh(BL::BlendData data, BL::Object object, BL::Scene scene, bool apply_modifiers, bool render) { - return self.to_mesh(scene, apply_modifiers, (render)? 2: 1); + return data.meshes.new_from_object(scene, object, apply_modifiers, (render)? 2: 1, true); } static inline void colorramp_to_array(BL::ColorRamp ramp, float4 *data, int size) @@ -100,6 +102,22 @@ static inline string image_user_file_path(BL::ImageUser iuser, BL::Image ima, in return string(filepath); } +static inline int image_user_frame_number(BL::ImageUser iuser, int cfra) +{ + BKE_image_user_frame_calc(iuser.ptr.data, cfra, 0); + return iuser.frame_current(); +} + +static inline unsigned char *image_get_pixels_for_frame(BL::Image image, int frame) +{ + return BKE_image_get_pixels_for_frame(image.ptr.data, frame); +} + +static inline float *image_get_float_pixels_for_frame(BL::Image image, int frame) +{ + return BKE_image_get_float_pixels_for_frame(image.ptr.data, frame); +} + /* Utilities */ static inline Transform get_transform(BL::Array<float, 16> array) @@ -184,30 +202,60 @@ static inline uint get_layer(BL::Array<int, 20> array, BL::Array<int, 8> local_a return layer; } -#if 0 static inline float3 get_float3(PointerRNA& ptr, const char *name) { float3 f; RNA_float_get_array(&ptr, name, &f.x); return f; } -#endif + +static inline void set_float3(PointerRNA& ptr, const char *name, float3 value) +{ + RNA_float_set_array(&ptr, name, &value.x); +} + +static inline float4 get_float4(PointerRNA& ptr, const char *name) +{ + float4 f; + RNA_float_get_array(&ptr, name, &f.x); + return f; +} + +static inline void set_float4(PointerRNA& ptr, const char *name, float4 value) +{ + RNA_float_set_array(&ptr, name, &value.x); +} static inline bool get_boolean(PointerRNA& ptr, const char *name) { return RNA_boolean_get(&ptr, name)? true: false; } +static inline void set_boolean(PointerRNA& ptr, const char *name, bool value) +{ + RNA_boolean_set(&ptr, name, (int)value); +} + static inline float get_float(PointerRNA& ptr, const char *name) { return RNA_float_get(&ptr, name); } +static inline void set_float(PointerRNA& ptr, const char *name, float value) +{ + RNA_float_set(&ptr, name, value); +} + static inline int get_int(PointerRNA& ptr, const char *name) { return RNA_int_get(&ptr, name); } +static inline void set_int(PointerRNA& ptr, const char *name, int value) +{ + RNA_int_set(&ptr, name, value); +} + static inline int get_enum(PointerRNA& ptr, const char *name) { return RNA_enum_get(&ptr, name); @@ -224,6 +272,32 @@ static inline string get_enum_identifier(PointerRNA& ptr, const char *name) return string(identifier); } +static inline void set_enum(PointerRNA& ptr, const char *name, int value) +{ + RNA_enum_set(&ptr, name, value); +} + +static inline void set_enum(PointerRNA& ptr, const char *name, const string &identifier) +{ + RNA_enum_set_identifier(&ptr, name, identifier.c_str()); +} + +static inline string get_string(PointerRNA& ptr, const char *name) +{ + char cstrbuf[1024]; + char *cstr = RNA_string_get_alloc(&ptr, name, cstrbuf, sizeof(cstrbuf)); + string str(cstr); + if (cstr != cstrbuf) + MEM_freeN(cstr); + + return str; +} + +static inline void set_string(PointerRNA& ptr, const char *name, const string &value) +{ + RNA_string_set(&ptr, name, value.c_str()); +} + /* Relative Paths */ static inline string blender_absolute_path(BL::BlendData b_data, BL::ID b_id, const string& path) @@ -242,6 +316,20 @@ static inline string blender_absolute_path(BL::BlendData b_data, BL::ID b_id, co return path; } +/* Texture Space */ + +static inline void mesh_texture_space(BL::Mesh b_mesh, float3& loc, float3& size) +{ + loc = get_float3(b_mesh.texspace_location()); + size = get_float3(b_mesh.texspace_size()); + + if(size.x != 0.0f) size.x = 0.5f/size.x; + if(size.y != 0.0f) size.y = 0.5f/size.y; + if(size.z != 0.0f) size.z = 0.5f/size.z; + + loc = loc*size - make_float3(0.5f, 0.5f, 0.5f); +} + /* ID Map * * Utility class to keep in sync with blender data. |