Cycles: support for image sequences in image/environment texture node.

This commit is contained in:
Brecht Van Lommel 2012-06-04 19:38:33 +00:00
parent d9589bf0dd
commit 4e338e894f
11 changed files with 172 additions and 75 deletions

@ -106,7 +106,7 @@ static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_map
mapping->max = get_float3(b_mapping.max());
}
static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNode b_node)
static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNode b_node)
{
ShaderNode *node = NULL;
@ -343,7 +343,7 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader
ImageTextureNode *image = new ImageTextureNode();
/* todo: handle generated/builtin images */
if(b_image)
image->filename = blender_absolute_path(b_data, b_image, b_image.filepath());
image->filename = image_user_file_path(b_image_node.image_user(), b_image, b_scene.frame_current());
image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()];
get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping());
node = image;
@ -354,7 +354,7 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader
BL::Image b_image(b_env_node.image());
EnvironmentTextureNode *env = new EnvironmentTextureNode();
if(b_image)
env->filename = blender_absolute_path(b_data, b_image, b_image.filepath());
env->filename = image_user_file_path(b_env_node.image_user(), b_image, b_scene.frame_current());
env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()];
get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping());
@ -530,7 +530,7 @@ static void set_default_value(ShaderInput *input, BL::NodeSocket sock)
}
}
static void add_nodes(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map)
static void add_nodes(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map)
{
/* add nodes */
BL::ShaderNodeTree::nodes_iterator b_node;
@ -578,10 +578,10 @@ static void add_nodes(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNodeTr
set_default_value(proxy->inputs[0], b_output->group_socket());
}
add_nodes(b_data, graph, b_group_ntree, group_sockmap);
add_nodes(b_data, b_scene, graph, b_group_ntree, group_sockmap);
}
else {
ShaderNode *node = add_node(b_data, graph, BL::ShaderNode(*b_node));
ShaderNode *node = add_node(b_data, b_scene, graph, BL::ShaderNode(*b_node));
if(node) {
BL::Node::inputs_iterator b_input;
@ -671,7 +671,7 @@ void BlenderSync::sync_materials()
PtrSockMap sock_to_node;
BL::ShaderNodeTree b_ntree(b_mat->node_tree());
add_nodes(b_data, graph, b_ntree, sock_to_node);
add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node);
}
else {
ShaderNode *closure, *out;
@ -712,7 +712,7 @@ void BlenderSync::sync_world()
PtrSockMap sock_to_node;
BL::ShaderNodeTree b_ntree(b_world.node_tree());
add_nodes(b_data, graph, b_ntree, sock_to_node);
add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node);
}
else if(b_world) {
ShaderNode *closure, *out;
@ -771,7 +771,7 @@ void BlenderSync::sync_lamps()
PtrSockMap sock_to_node;
BL::ShaderNodeTree b_ntree(b_lamp->node_tree());
add_nodes(b_data, graph, b_ntree, sock_to_node);
add_nodes(b_data, b_scene, graph, b_ntree, sock_to_node);
}
else {
ShaderNode *closure, *out;

@ -53,6 +53,7 @@ int rna_Object_is_deform_modified(void *ob, void *scene, int settings);
void BLI_timestr(double _time, char *str);
void rna_ColorRamp_eval(void *coba, float position, float color[4]);
void rna_Scene_frame_set(void *scene, int frame, float subframe);
void BKE_image_user_file_path(void *iuser, void *ima, int cfra, char *path);
}
@ -101,6 +102,13 @@ static inline bool BKE_object_is_deform_modified(BL::Object self, BL::Scene scen
return rna_Object_is_deform_modified(self.ptr.data, scene.ptr.data, (preview)? (1<<0): (1<<1))? true: false;
}
static inline string image_user_file_path(BL::ImageUser iuser, BL::Image ima, int cfra)
{
char filepath[1024];
BKE_image_user_file_path(iuser.ptr.data, ima.ptr.data, cfra, filepath);
return string(filepath);
}
static inline void scene_frame_set(BL::Scene scene, int frame)
{
rna_Scene_frame_set(scene.ptr.data, frame, 0.0f);

@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 263
#define BLENDER_SUBVERSION 8
#define BLENDER_SUBVERSION 9
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0

@ -157,6 +157,7 @@ void BKE_image_assign_ibuf(struct Image *ima, struct ImBuf *ibuf);
void BKE_image_user_frame_calc(struct ImageUser *iuser, int cfra, int fieldnr);
void BKE_image_user_check_frame_calc(struct ImageUser *iuser, int cfra, int fieldnr);
int BKE_image_user_frame_get(const struct ImageUser *iuser, int cfra, int fieldnr);
void BKE_image_user_file_path(struct ImageUser *iuser, struct Image *ima, int cfra, char *path);
/* sets index offset for multilayer files */
struct RenderPass *BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser);

@ -2084,8 +2084,7 @@ static void image_initialize_after_load(Image *ima, ImBuf *ibuf)
static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
{
struct ImBuf *ibuf;
unsigned short numlen;
char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
char name[FILE_MAX];
int flag;
/* XXX temp stuff? */
@ -2093,11 +2092,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
ima->tpageflag |= IMA_TPAGE_REFRESH;
ima->lastframe = frame;
BLI_strncpy(name, ima->name, sizeof(name));
BLI_stringdec(name, head, tail, &numlen);
BLI_stringenc(name, head, tail, numlen, frame);
BLI_path_abs(name, ID_BLEND_PATH(G.main, &ima->id));
BKE_image_user_file_path(iuser, ima, frame, name);
flag = IB_rect | IB_multilayer;
if (ima->flag & IMA_DO_PREMUL)
@ -2209,8 +2204,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame)
if (ima->anim == NULL) {
char str[FILE_MAX];
BLI_strncpy(str, ima->name, FILE_MAX);
BLI_path_abs(str, ID_BLEND_PATH(G.main, &ima->id));
BKE_image_user_file_path(iuser, ima, frame, str);
/* FIXME: make several stream accessible in image editor, too*/
ima->anim = openanim(str, IB_rect, 0);
@ -2273,8 +2267,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
flag |= IB_premul;
/* get the right string */
BLI_strncpy(str, ima->name, sizeof(str));
BLI_path_abs(str, ID_BLEND_PATH(G.main, &ima->id));
BKE_image_user_file_path(iuser, ima, cfra, str);
/* read ibuf */
ibuf = IMB_loadiffname(str, flag);
@ -2748,6 +2741,29 @@ void BKE_image_user_check_frame_calc(ImageUser *iuser, int cfra, int fieldnr)
}
}
void BKE_image_user_file_path(ImageUser *iuser, Image *ima, int cfra, char *filepath)
{
BLI_strncpy(filepath, ima->name, FILE_MAX);
if (ima->source == IMA_SRC_SEQUENCE) {
char head[FILE_MAX], tail[FILE_MAX];
unsigned short numlen;
int frame;
if(iuser) {
BKE_image_user_frame_calc(iuser, cfra, 0);
frame = iuser->framenr;
}
else {
}
BLI_stringdec(filepath, head, tail, &numlen);
BLI_stringenc(filepath, head, tail, numlen, frame);
}
BLI_path_abs(filepath, ID_BLEND_PATH(G.main, &ima->id));
}
int BKE_image_has_alpha(struct Image *image)
{
ImBuf *ibuf;

@ -6897,6 +6897,22 @@ static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree)
}
}
static void do_version_ntree_image_user_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
{
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) {
NodeTexImage *tex = node->storage;
tex->iuser.frames= 1;
tex->iuser.sfra= 1;
tex->iuser.fie_ima= 2;
tex->iuser.ok= 1;
}
}
}
static void do_versions(FileData *fd, Library *lib, Main *main)
{
/* WATCH IT!!!: pointers from libdata have not been converted */
@ -7608,6 +7624,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 9)) {
bNodeTreeType *ntreetype = ntreeGetType(NTREE_SHADER);
if (ntreetype && ntreetype->foreach_nodetree)
ntreetype->foreach_nodetree(main, NULL, do_version_ntree_image_user_264);
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
{

@ -1188,6 +1188,47 @@ static void node_common_set_butfunc(bNodeType *ntype)
}
/* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *imaptr, PointerRNA *iuserptr)
{
uiLayout *col;
int source;
if(!imaptr->data)
return;
col = uiLayoutColumn(layout, 0);
uiItemR(col, imaptr, "source", 0, "", ICON_NONE);
source = RNA_enum_get(imaptr, "source");
if (source == IMA_SRC_SEQUENCE) {
/* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
Scene *scene = CTX_data_scene(C);
ImageUser *iuser = iuserptr->data;
char numstr[32];
const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0);
BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr);
uiItemL(layout, numstr, ICON_NONE);
}
if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
col = uiLayoutColumn(layout, 1);
uiItemR(col, iuserptr, "frame_duration", 0, NULL, ICON_NONE);
uiItemR(col, iuserptr, "frame_start", 0, NULL, ICON_NONE);
uiItemR(col, iuserptr, "frame_offset", 0, NULL, ICON_NONE);
uiItemR(col, iuserptr, "use_cyclic", 0, NULL, ICON_NONE);
uiItemR(col, iuserptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
}
col = uiLayoutColumn(layout, 0);
if (RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER)
uiItemR(col, iuserptr, "layer", 0, NULL, ICON_NONE);
}
static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = ptr->data;
@ -1259,16 +1300,25 @@ static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), Po
static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
PointerRNA imaptr = RNA_pointer_get(ptr, "image");
PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
}
node_buts_image_user(layout, C, &imaptr, &iuserptr);
}
static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
PointerRNA imaptr = RNA_pointer_get(ptr, "image");
PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE);
uiItemR(layout, ptr, "projection", 0, "", ICON_NONE);
node_buts_image_user(layout, C, &imaptr, &iuserptr);
}
static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
@ -1391,11 +1441,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
uiLayout *col;
bNode *node = ptr->data;
PointerRNA imaptr;
PropertyRNA *prop;
int source;
uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL);
@ -1405,35 +1453,7 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *
if (!prop || RNA_property_type(prop) != PROP_POINTER) return;
imaptr = RNA_property_pointer_get(ptr, prop);
col = uiLayoutColumn(layout, 0);
uiItemR(col, &imaptr, "source", 0, NULL, ICON_NONE);
source = RNA_enum_get(&imaptr, "source");
if (source == IMA_SRC_SEQUENCE) {
/* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
Scene *scene = CTX_data_scene(C);
ImageUser *iuser = node->storage;
char numstr[32];
const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0);
BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr);
uiItemL(layout, numstr, ICON_NONE);
}
if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
col = uiLayoutColumn(layout, 1);
uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "use_auto_refresh", UI_ITEM_R_ICON_ONLY, NULL, ICON_NONE);
}
col = uiLayoutColumn(layout, 0);
if (RNA_enum_get(&imaptr, "type") == IMA_TYPE_MULTILAYER)
uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
node_buts_image_user(layout, C, &imaptr, ptr);
}
static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)

@ -563,6 +563,7 @@ typedef struct NodeTexSky {
typedef struct NodeTexImage {
NodeTexBase base;
ImageUser iuser;
int color_space, pad;
} NodeTexImage;
@ -572,6 +573,7 @@ typedef struct NodeTexChecker {
typedef struct NodeTexEnvironment {
NodeTexBase base;
ImageUser iuser;
int color_space, projection;
} NodeTexEnvironment;

@ -1429,6 +1429,12 @@ static void def_sh_tex_environment(StructRNA *srna)
RNA_def_property_ui_text(prop, "Projection", "Projection of the input image");
RNA_def_property_update(prop, 0, "rna_Node_update");
prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "iuser");
RNA_def_property_ui_text(prop, "Image User",
"Parameters defining which layer, pass and frame of the image is displayed");
RNA_def_property_update(prop, 0, "rna_Node_update");
}
static void def_sh_tex_image(StructRNA *srna)
@ -1458,6 +1464,13 @@ static void def_sh_tex_image(StructRNA *srna)
RNA_def_property_enum_items(prop, prop_color_space_items);
RNA_def_property_ui_text(prop, "Color Space", "Image file color space");
RNA_def_property_update(prop, 0, "rna_Node_update");
prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "iuser");
RNA_def_property_ui_text(prop, "Image User",
"Parameters defining which layer, pass and frame of the image is displayed");
RNA_def_property_update(prop, 0, "rna_Node_update");
}
static void def_sh_tex_gradient(StructRNA *srna)
@ -1830,29 +1843,10 @@ static void def_cmp_levels(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_image(StructRNA *srna)
static void def_node_image_user(StructRNA *srna)
{
PropertyRNA *prop;
#if 0
static EnumPropertyItem type_items[] = {
{IMA_SRC_FILE, "IMAGE", 0, "Image", ""},
{IMA_SRC_MOVIE, "MOVIE", "Movie", ""},
{IMA_SRC_SEQUENCE, "SEQUENCE", "Sequence", ""},
{IMA_SRC_GENERATED, "GENERATED", "Generated", ""},
{0, NULL, 0, NULL, NULL}
};
#endif
prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Image");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_struct_sdna_from(srna, "ImageUser", "storage");
prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "frames");
RNA_def_property_range(prop, 0, MAXFRAMEF);
@ -1893,6 +1887,31 @@ static void def_cmp_image(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_image_layer_update");
}
static void def_cmp_image(StructRNA *srna)
{
PropertyRNA *prop;
#if 0
static EnumPropertyItem type_items[] = {
{IMA_SRC_FILE, "IMAGE", 0, "Image", ""},
{IMA_SRC_MOVIE, "MOVIE", "Movie", ""},
{IMA_SRC_SEQUENCE, "SEQUENCE", "Sequence", ""},
{IMA_SRC_GENERATED, "GENERATED", "Generated", ""},
{0, NULL, 0, NULL, NULL}
};
#endif
prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Image");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_struct_sdna_from(srna, "ImageUser", "storage");
def_node_image_user(srna);
}
static void def_cmp_render_layers(StructRNA *srna)
{
PropertyRNA *prop;
@ -3454,7 +3473,7 @@ static void def_tex_image(StructRNA *srna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
/* is this supposed to be exposed? not sure.. */
#if 0
prop = RNA_def_property(srna, "settings", PROP_POINTER, PROP_NONE);

@ -46,6 +46,10 @@ static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode* no
default_color_mapping(&tex->base.color_mapping);
tex->color_space = SHD_COLORSPACE_COLOR;
tex->projection = SHD_PROJ_EQUIRECTANGULAR;
tex->iuser.frames= 1;
tex->iuser.sfra= 1;
tex->iuser.fie_ima= 2;
tex->iuser.ok= 1;
node->storage = tex;
}

@ -46,6 +46,10 @@ static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode* node, bN
default_tex_mapping(&tex->base.tex_mapping);
default_color_mapping(&tex->base.color_mapping);
tex->color_space = SHD_COLORSPACE_COLOR;
tex->iuser.frames= 1;
tex->iuser.sfra= 1;
tex->iuser.fie_ima= 2;
tex->iuser.ok= 1;
node->storage = tex;
}