Fix [#21708] Copy/Paste Texture channels for Lamps/World not working
This commit is contained in:
@@ -29,8 +29,8 @@ class TEXTURE_MT_specials(bpy.types.Menu):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
layout.operator("material.mtex_copy", icon='COPYDOWN')
|
layout.operator("texture.slot_copy", icon='COPYDOWN')
|
||||||
layout.operator("material.mtex_paste", icon='PASTEDOWN')
|
layout.operator("texture.slot_paste", icon='PASTEDOWN')
|
||||||
|
|
||||||
|
|
||||||
class TEXTURE_MT_envmap_specials(bpy.types.Menu):
|
class TEXTURE_MT_envmap_specials(bpy.types.Menu):
|
||||||
|
@@ -1345,70 +1345,3 @@ void paste_matcopybuf(Material *ma)
|
|||||||
scrarea_queue_winredraw(curarea);
|
scrarea_queue_winredraw(curarea);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static short mtexcopied=0; /* must be reset on file load */
|
|
||||||
static MTex mtexcopybuf;
|
|
||||||
|
|
||||||
void clear_mat_mtex_copybuf(void)
|
|
||||||
{ /* use for file reload */
|
|
||||||
mtexcopied= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void copy_mat_mtex_copybuf(ID *id)
|
|
||||||
{
|
|
||||||
MTex **mtex= NULL;
|
|
||||||
|
|
||||||
switch(GS(id->name)) {
|
|
||||||
case ID_MA:
|
|
||||||
mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
|
|
||||||
break;
|
|
||||||
case ID_LA:
|
|
||||||
// la->mtex[(int)la->texact] // TODO
|
|
||||||
break;
|
|
||||||
case ID_WO:
|
|
||||||
// mtex= wrld->mtex[(int)wrld->texact]; // TODO
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mtex && *mtex) {
|
|
||||||
memcpy(&mtexcopybuf, *mtex, sizeof(MTex));
|
|
||||||
mtexcopied= 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mtexcopied= 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void paste_mat_mtex_copybuf(ID *id)
|
|
||||||
{
|
|
||||||
MTex **mtex= NULL;
|
|
||||||
|
|
||||||
if(mtexcopied == 0 || mtexcopybuf.tex==NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch(GS(id->name)) {
|
|
||||||
case ID_MA:
|
|
||||||
mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
|
|
||||||
break;
|
|
||||||
case ID_LA:
|
|
||||||
// la->mtex[(int)la->texact] // TODO
|
|
||||||
break;
|
|
||||||
case ID_WO:
|
|
||||||
// mtex= wrld->mtex[(int)wrld->texact]; // TODO
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mtex) {
|
|
||||||
if(*mtex==NULL) {
|
|
||||||
*mtex= MEM_mallocN(sizeof(MTex), "mtex copy");
|
|
||||||
}
|
|
||||||
else if((*mtex)->tex) {
|
|
||||||
(*mtex)->tex->id.us--;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(*mtex, &mtexcopybuf, sizeof(MTex));
|
|
||||||
|
|
||||||
id_us_plus((ID *)mtexcopybuf.tex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -81,4 +81,6 @@ void ED_preview_icon_job(const struct bContext *C, void *owner, struct ID *id, u
|
|||||||
|
|
||||||
void ED_preview_draw(const struct bContext *C, void *idp, void *parentp, void *slot, rcti *rect);
|
void ED_preview_draw(const struct bContext *C, void *idp, void *parentp, void *slot, rcti *rect);
|
||||||
|
|
||||||
|
void ED_render_clear_mtex_copybuf(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -48,12 +48,12 @@ void WORLD_OT_new(struct wmOperatorType *ot);
|
|||||||
void MATERIAL_OT_copy(struct wmOperatorType *ot);
|
void MATERIAL_OT_copy(struct wmOperatorType *ot);
|
||||||
void MATERIAL_OT_paste(struct wmOperatorType *ot);
|
void MATERIAL_OT_paste(struct wmOperatorType *ot);
|
||||||
|
|
||||||
void MATERIAL_OT_mtex_copy(struct wmOperatorType *ot);
|
|
||||||
void MATERIAL_OT_mtex_paste(struct wmOperatorType *ot);
|
|
||||||
|
|
||||||
void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
|
void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
|
||||||
void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
|
void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
|
||||||
|
|
||||||
|
|
||||||
|
void TEXTURE_OT_slot_copy(struct wmOperatorType *ot);
|
||||||
|
void TEXTURE_OT_slot_paste(struct wmOperatorType *ot);
|
||||||
void TEXTURE_OT_slot_move(struct wmOperatorType *ot);
|
void TEXTURE_OT_slot_move(struct wmOperatorType *ot);
|
||||||
void TEXTURE_OT_envmap_save(struct wmOperatorType *ot);
|
void TEXTURE_OT_envmap_save(struct wmOperatorType *ot);
|
||||||
void TEXTURE_OT_envmap_clear(struct wmOperatorType *ot);
|
void TEXTURE_OT_envmap_clear(struct wmOperatorType *ot);
|
||||||
|
@@ -54,9 +54,6 @@ void ED_operatortypes_render(void)
|
|||||||
WM_operatortype_append(MATERIAL_OT_copy);
|
WM_operatortype_append(MATERIAL_OT_copy);
|
||||||
WM_operatortype_append(MATERIAL_OT_paste);
|
WM_operatortype_append(MATERIAL_OT_paste);
|
||||||
|
|
||||||
WM_operatortype_append(MATERIAL_OT_mtex_copy);
|
|
||||||
WM_operatortype_append(MATERIAL_OT_mtex_paste);
|
|
||||||
|
|
||||||
WM_operatortype_append(SCENE_OT_render_layer_add);
|
WM_operatortype_append(SCENE_OT_render_layer_add);
|
||||||
WM_operatortype_append(SCENE_OT_render_layer_remove);
|
WM_operatortype_append(SCENE_OT_render_layer_remove);
|
||||||
|
|
||||||
@@ -64,6 +61,8 @@ void ED_operatortypes_render(void)
|
|||||||
WM_operatortype_append(SCENE_OT_render_data_set_quicktime_codec);
|
WM_operatortype_append(SCENE_OT_render_data_set_quicktime_codec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
WM_operatortype_append(TEXTURE_OT_slot_copy);
|
||||||
|
WM_operatortype_append(TEXTURE_OT_slot_paste);
|
||||||
WM_operatortype_append(TEXTURE_OT_slot_move);
|
WM_operatortype_append(TEXTURE_OT_slot_move);
|
||||||
WM_operatortype_append(TEXTURE_OT_envmap_save);
|
WM_operatortype_append(TEXTURE_OT_envmap_save);
|
||||||
WM_operatortype_append(TEXTURE_OT_envmap_clear);
|
WM_operatortype_append(TEXTURE_OT_envmap_clear);
|
||||||
|
@@ -1030,57 +1030,153 @@ void MATERIAL_OT_paste(wmOperatorType *ot)
|
|||||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_material_mtex_exec(bContext *C, wmOperator *op)
|
|
||||||
|
static short mtexcopied=0; /* must be reset on file load */
|
||||||
|
static MTex mtexcopybuf;
|
||||||
|
|
||||||
|
void ED_render_clear_mtex_copybuf(void)
|
||||||
|
{ /* use for file reload */
|
||||||
|
mtexcopied= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void copy_mtex_copybuf(ID *id)
|
||||||
{
|
{
|
||||||
Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
|
MTex **mtex= NULL;
|
||||||
|
|
||||||
if(ma==NULL)
|
switch(GS(id->name)) {
|
||||||
|
case ID_MA:
|
||||||
|
mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
|
||||||
|
break;
|
||||||
|
case ID_LA:
|
||||||
|
mtex= &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
|
||||||
|
// la->mtex[(int)la->texact] // TODO
|
||||||
|
break;
|
||||||
|
case ID_WO:
|
||||||
|
mtex= &(((World *)id)->mtex[(int)((World *)id)->texact]);
|
||||||
|
// mtex= wrld->mtex[(int)wrld->texact]; // TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mtex && *mtex) {
|
||||||
|
memcpy(&mtexcopybuf, *mtex, sizeof(MTex));
|
||||||
|
mtexcopied= 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mtexcopied= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void paste_mtex_copybuf(ID *id)
|
||||||
|
{
|
||||||
|
MTex **mtex= NULL;
|
||||||
|
|
||||||
|
if(mtexcopied == 0 || mtexcopybuf.tex==NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch(GS(id->name)) {
|
||||||
|
case ID_MA:
|
||||||
|
mtex= &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
|
||||||
|
break;
|
||||||
|
case ID_LA:
|
||||||
|
mtex= &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
|
||||||
|
// la->mtex[(int)la->texact] // TODO
|
||||||
|
break;
|
||||||
|
case ID_WO:
|
||||||
|
mtex= &(((World *)id)->mtex[(int)((World *)id)->texact]);
|
||||||
|
// mtex= wrld->mtex[(int)wrld->texact]; // TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mtex) {
|
||||||
|
if(*mtex==NULL) {
|
||||||
|
*mtex= MEM_mallocN(sizeof(MTex), "mtex copy");
|
||||||
|
}
|
||||||
|
else if((*mtex)->tex) {
|
||||||
|
(*mtex)->tex->id.us--;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(*mtex, &mtexcopybuf, sizeof(MTex));
|
||||||
|
|
||||||
|
id_us_plus((ID *)mtexcopybuf.tex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int copy_mtex_exec(bContext *C, wmOperator *op)
|
||||||
|
{
|
||||||
|
ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
|
||||||
|
|
||||||
|
if(id==NULL) {
|
||||||
|
/* copying empty slot */
|
||||||
|
ED_render_clear_mtex_copybuf();
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
|
|
||||||
copy_mat_mtex_copybuf(&ma->id);
|
copy_mtex_copybuf(id);
|
||||||
|
|
||||||
WM_event_add_notifier(C, NC_MATERIAL, ma);
|
WM_event_add_notifier(C, NC_TEXTURE, NULL);
|
||||||
|
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MATERIAL_OT_mtex_copy(wmOperatorType *ot)
|
static int copy_mtex_poll(bContext *C)
|
||||||
|
{
|
||||||
|
ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
|
||||||
|
|
||||||
|
return (id != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TEXTURE_OT_slot_copy(wmOperatorType *ot)
|
||||||
{
|
{
|
||||||
/* identifiers */
|
/* identifiers */
|
||||||
ot->name= "Copy Material Texture Settings";
|
ot->name= "Copy Texture Slot Settings";
|
||||||
ot->idname= "MATERIAL_OT_mtex_copy";
|
ot->idname= "TEXTURE_OT_slot_copy";
|
||||||
ot->description="Copy the material texture settings and nodes";
|
ot->description="Copy the material texture settings and nodes";
|
||||||
|
|
||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->exec= copy_material_mtex_exec;
|
ot->exec= copy_mtex_exec;
|
||||||
|
ot->poll= copy_mtex_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int paste_material_mtex_exec(bContext *C, wmOperator *op)
|
static int paste_mtex_exec(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
|
ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
|
||||||
|
|
||||||
|
if(id==NULL) {
|
||||||
Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
|
Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
|
||||||
|
Lamp *la= CTX_data_pointer_get_type(C, "lamp", &RNA_Lamp).data;
|
||||||
|
World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data;
|
||||||
|
|
||||||
if(ma==NULL)
|
if (ma)
|
||||||
|
id = &ma->id;
|
||||||
|
else if (la)
|
||||||
|
id = &la->id;
|
||||||
|
else if (wo)
|
||||||
|
id = &wo->id;
|
||||||
|
|
||||||
|
if (id==NULL)
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
|
|
||||||
paste_mat_mtex_copybuf(&ma->id);
|
paste_mtex_copybuf(id);
|
||||||
|
|
||||||
WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING_DRAW, ma);
|
WM_event_add_notifier(C, NC_TEXTURE|ND_SHADING_DRAW, NULL);
|
||||||
|
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MATERIAL_OT_mtex_paste(wmOperatorType *ot)
|
void TEXTURE_OT_slot_paste(wmOperatorType *ot)
|
||||||
{
|
{
|
||||||
/* identifiers */
|
/* identifiers */
|
||||||
ot->name= "Paste Material Texture Settings";
|
ot->name= "Paste Texture Slot Settings";
|
||||||
ot->idname= "MATERIAL_OT_mtex_paste";
|
ot->idname= "TEXTURE_OT_slot_paste";
|
||||||
ot->description="Copy the material texture settings and nodes";
|
ot->description="Copy the texture settings and nodes";
|
||||||
|
|
||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->exec= paste_material_mtex_exec;
|
ot->exec= paste_mtex_exec;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||||
|
@@ -155,7 +155,7 @@ void WM_init(bContext *C, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear_matcopybuf();
|
clear_matcopybuf();
|
||||||
clear_mat_mtex_copybuf();
|
ED_render_clear_mtex_copybuf();
|
||||||
|
|
||||||
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user