mtex buffer copy & paste back for materials.
This commit is contained in:
@@ -23,6 +23,16 @@ from rna_prop_ui import PropertyPanel
|
||||
narrowui = 180
|
||||
|
||||
|
||||
class TEXTURE_MT_specials(bpy.types.Menu):
|
||||
bl_label = "Texture Specials"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("material.mtex_copy", icon='COPYDOWN')
|
||||
layout.operator("material.mtex_paste", icon='PASTEDOWN')
|
||||
|
||||
|
||||
def active_node_mat(mat):
|
||||
if mat:
|
||||
mat_node = mat.active_node_material
|
||||
@@ -103,6 +113,7 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
|
||||
col = row.column(align=True)
|
||||
col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
|
||||
col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
|
||||
col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
|
||||
|
||||
if wide_ui:
|
||||
split = layout.split(percentage=0.65)
|
||||
@@ -958,6 +969,8 @@ class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel):
|
||||
|
||||
|
||||
classes = [
|
||||
TEXTURE_MT_specials,
|
||||
|
||||
TEXTURE_PT_context_texture,
|
||||
TEXTURE_PT_preview,
|
||||
|
||||
|
@@ -83,6 +83,10 @@ void free_matcopybuf(void);
|
||||
void copy_matcopybuf(struct Material *ma);
|
||||
void paste_matcopybuf(struct Material *ma);
|
||||
|
||||
void clear_mat_mtex_copybuf(void);
|
||||
void copy_mat_mtex_copybuf(struct ID *id);
|
||||
void paste_mat_mtex_copybuf(struct ID *id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1247,6 +1247,7 @@ static short matcopied=0;
|
||||
void clear_matcopybuf(void)
|
||||
{
|
||||
memset(&matcopybuf, 0, sizeof(Material));
|
||||
matcopied= 0;
|
||||
}
|
||||
|
||||
void free_matcopybuf(void)
|
||||
@@ -1273,6 +1274,8 @@ void free_matcopybuf(void)
|
||||
matcopybuf.nodetree= NULL;
|
||||
}
|
||||
// default_mtex(&mtexcopybuf);
|
||||
|
||||
matcopied= 0;
|
||||
}
|
||||
|
||||
void copy_matcopybuf(Material *ma)
|
||||
@@ -1346,3 +1349,70 @@ void paste_matcopybuf(Material *ma)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -48,6 +48,9 @@ void WORLD_OT_new(struct wmOperatorType *ot);
|
||||
void MATERIAL_OT_copy(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_remove(struct wmOperatorType *ot);
|
||||
|
||||
|
@@ -55,6 +55,9 @@ void ED_operatortypes_render(void)
|
||||
|
||||
WM_operatortype_append(MATERIAL_OT_copy);
|
||||
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_remove);
|
||||
|
@@ -820,3 +820,59 @@ void MATERIAL_OT_paste(wmOperatorType *ot)
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int copy_material_mtex_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
|
||||
|
||||
if(ma==NULL)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
copy_mat_mtex_copybuf(&ma->id);
|
||||
|
||||
WM_event_add_notifier(C, NC_MATERIAL, ma);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void MATERIAL_OT_mtex_copy(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Copy Material Texture Settings";
|
||||
ot->idname= "MATERIAL_OT_mtex_copy";
|
||||
ot->description="Copy the material texture settings and nodes";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= copy_material_mtex_exec;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int paste_material_mtex_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
|
||||
|
||||
if(ma==NULL)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
paste_mat_mtex_copybuf(&ma->id);
|
||||
|
||||
WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING_DRAW, ma);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void MATERIAL_OT_mtex_paste(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name= "Paste Material Texture Settings";
|
||||
ot->idname= "MATERIAL_OT_mtex_paste";
|
||||
ot->description="Copy the material texture settings and nodes";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= paste_material_mtex_exec;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_sequencer.h" /* free seq clipboard */
|
||||
#include "BKE_material.h" /* clear_matcopybuf */
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
@@ -154,8 +155,9 @@ void WM_init(bContext *C, int argc, char **argv)
|
||||
UI_init();
|
||||
}
|
||||
|
||||
// clear_matcopybuf(); /* XXX */
|
||||
|
||||
clear_matcopybuf();
|
||||
clear_mat_mtex_copybuf();
|
||||
|
||||
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// init_node_butfuncs();
|
||||
|
Reference in New Issue
Block a user