move material to layer feature
3.1.0 - added: Feature to move all strokes using active material to an existing or new layer (material dropdown menu > `Move Material To Layer`)
This commit is contained in:
@@ -2,12 +2,13 @@ import bpy, os
|
||||
import numpy as np
|
||||
import bmesh
|
||||
import mathutils
|
||||
from mathutils import Vector
|
||||
import math
|
||||
from math import sqrt
|
||||
from sys import platform
|
||||
import subprocess
|
||||
|
||||
from math import sqrt
|
||||
from mathutils import Vector
|
||||
from sys import platform
|
||||
|
||||
|
||||
|
||||
""" def get_gp_parent(layer) :
|
||||
@@ -263,55 +264,6 @@ def remapping(value, leftMin, leftMax, rightMin, rightMax):
|
||||
### GP funcs
|
||||
# -----------------
|
||||
|
||||
""" V1
|
||||
def get_gp_draw_plane(obj=None):
|
||||
''' return tuple with plane coordinate and normal
|
||||
of the curent drawing accordign to geometry'''
|
||||
|
||||
context = bpy.context
|
||||
settings = context.scene.tool_settings
|
||||
orient = settings.gpencil_sculpt.lock_axis #'VIEW', 'AXIS_Y', 'AXIS_X', 'AXIS_Z', 'CURSOR'
|
||||
loc = settings.gpencil_stroke_placement_view3d #'ORIGIN', 'CURSOR', 'SURFACE', 'STROKE'
|
||||
if obj:
|
||||
mat = obj.matrix_world
|
||||
else:
|
||||
mat = context.object.matrix_world if context.object else None
|
||||
|
||||
# -> placement
|
||||
if loc == "CURSOR":
|
||||
plane_co = context.scene.cursor.location
|
||||
|
||||
else: # ORIGIN (also on origin if set to 'SURFACE', 'STROKE')
|
||||
if not context.object:
|
||||
plane_co = None
|
||||
else:
|
||||
plane_co = context.object.matrix_world.to_translation()# context.object.location
|
||||
|
||||
# -> orientation
|
||||
if orient == 'VIEW':
|
||||
#only depth is important, no need to get view vector
|
||||
plane_no = None
|
||||
|
||||
elif orient == 'AXIS_Y':#front (X-Z)
|
||||
plane_no = Vector((0,1,0))
|
||||
plane_no.rotate(mat)
|
||||
|
||||
elif orient == 'AXIS_X':#side (Y-Z)
|
||||
plane_no = Vector((1,0,0))
|
||||
plane_no.rotate(mat)
|
||||
|
||||
elif orient == 'AXIS_Z':#top (X-Y)
|
||||
plane_no = Vector((0,0,1))
|
||||
plane_no.rotate(mat)
|
||||
|
||||
elif orient == 'CURSOR':
|
||||
plane_no = Vector((0,0,1))
|
||||
plane_no.rotate(context.scene.cursor.matrix)
|
||||
|
||||
return plane_co, plane_no
|
||||
"""
|
||||
|
||||
## V2
|
||||
def get_gp_draw_plane(obj=None, orient=None):
|
||||
''' return tuple with plane coordinate and normal
|
||||
of the curent drawing according to geometry'''
|
||||
@@ -459,14 +411,14 @@ def get_gp_datas(selection=True):
|
||||
print('EOL. No active GP object')
|
||||
return []
|
||||
|
||||
def get_gp_layer(gp_data_block,name) :
|
||||
def get_gp_layer(gp_data_block, name) :
|
||||
gp_layer = gp_data_block.layers.get(name)
|
||||
if not gp_layer :
|
||||
gp_layer = gp_data_block.layers.new(name)
|
||||
|
||||
return gp_layer
|
||||
|
||||
def get_gp_frame(layer,frame_nb = None) :
|
||||
def get_gp_frame(layer, frame_nb=None) :
|
||||
scene = bpy.context.scene
|
||||
if not frame_nb :
|
||||
frame_nb = scene.frame_current
|
||||
@@ -532,9 +484,72 @@ def selected_strokes(frame):
|
||||
stlist.append(s)
|
||||
return stlist
|
||||
|
||||
from math import sqrt
|
||||
from mathutils import Vector
|
||||
## Copy stroke to a frame
|
||||
|
||||
def copy_stroke_to_frame(s, frame, select=True):
|
||||
'''Copy stroke to given frame
|
||||
return created stroke
|
||||
'''
|
||||
|
||||
ns = frame.strokes.new()
|
||||
|
||||
## Set strokes attr
|
||||
stroke_attr = [
|
||||
'line_width',
|
||||
'material_index',
|
||||
'draw_cyclic',
|
||||
'use_cyclic',
|
||||
'uv_scale',
|
||||
'uv_rotation',
|
||||
'hardness',
|
||||
'uv_translation',
|
||||
'vertex_color_fill',
|
||||
]
|
||||
|
||||
for attr in stroke_attr:
|
||||
if not hasattr(s, attr):
|
||||
continue
|
||||
# print(f'transfer stroke {attr}') # Dbg
|
||||
setattr(ns, attr, getattr(s, attr))
|
||||
|
||||
## create points
|
||||
point_count = len(s.points)
|
||||
ns.points.add(len(s.points))
|
||||
|
||||
## Set points attr
|
||||
# for p, np in zip(s.points, ns.points):
|
||||
flat_list = [0.0] * point_count
|
||||
flat_uv_fill_list = [0.0, 0.0] * point_count
|
||||
flat_vector_list = [0.0, 0.0, 0.0] * point_count
|
||||
flat_color_list = [0.0, 0.0, 0.0, 0.0] * point_count
|
||||
|
||||
single_attr = [
|
||||
'pressure',
|
||||
'strength',
|
||||
'uv_factor',
|
||||
'uv_rotation',
|
||||
]
|
||||
|
||||
for attr in single_attr:
|
||||
# print(f'transfer point {attr}') # Dbg
|
||||
s.points.foreach_get(attr, flat_list)
|
||||
ns.points.foreach_set(attr, flat_list)
|
||||
|
||||
# print(f'transfer point co') # Dbg
|
||||
s.points.foreach_get('co', flat_vector_list)
|
||||
ns.points.foreach_set('co', flat_vector_list)
|
||||
|
||||
# print(f'transfer point uv_fill') # Dbg
|
||||
s.points.foreach_get('uv_fill', flat_uv_fill_list)
|
||||
ns.points.foreach_set('uv_fill', flat_uv_fill_list)
|
||||
|
||||
# print(f'transfer point vertex_color') # Dbg
|
||||
s.points.foreach_get('vertex_color', flat_color_list)
|
||||
ns.points.foreach_set('vertex_color', flat_color_list)
|
||||
|
||||
ns.select = select
|
||||
ns.points.update()
|
||||
return ns
|
||||
|
||||
# -----------------
|
||||
### Vector utils 3d
|
||||
|
||||
Reference in New Issue
Block a user