本文整理汇总了Python中bpy.context方法的典型用法代码示例。如果您正苦于以下问题:Python bpy.context方法的具体用法?Python bpy.context怎么用?Python bpy.context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bpy
的用法示例。
在下文中一共展示了bpy.context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_key_coords
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def get_key_coords(ob=None, key='Basis', proxy=False):
'''Creates an N x 3 numpy array of vertex coords.
from shape keys'''
if key is None:
return get_coords(ob)
if proxy:
mesh = proxy.to_mesh(bpy.context.scene, True, 'PREVIEW')
verts = mesh.data.shape_keys.key_blocks[key].data
else:
verts = ob.data.shape_keys.key_blocks[key].data
v_count = len(verts)
coords = np.zeros(v_count * 3, dtype=np.float32)
verts.foreach_get("co", coords)
if proxy:
bpy.data.meshes.remove(mesh)
return coords.reshape(v_count, 3)
示例2: get_coords
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def get_coords(ob=None, proxy=False):
'''Creates an N x 3 numpy array of vertex coords. If proxy is used the
coords are taken from the object specified with modifiers evaluated.
For the proxy argument put in the object: get_coords(ob, proxy_ob)'''
if ob is None:
ob = bpy.context.object
if proxy:
mesh = proxy.to_mesh(bpy.context.scene, True, 'PREVIEW')
verts = mesh.vertices
else:
verts = ob.data.vertices
v_count = len(verts)
coords = np.zeros(v_count * 3, dtype=np.float32)
verts.foreach_get("co", coords)
if proxy:
bpy.data.meshes.remove(mesh)
return coords.reshape(v_count, 3)
示例3: get_bmesh
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def get_bmesh(ob=None):
'''Returns a bmesh. Works either in edit or object mode.
ob can be either an object or a mesh.'''
obm = bmesh.new()
if ob is None:
mesh = bpy.context.object.data
if 'data' in dir(ob):
mesh = ob.data
if ob.mode == 'OBJECT':
obm.from_mesh(mesh)
elif ob.mode == 'EDIT':
obm = bmesh.from_edit_mesh(mesh)
else:
mesh = ob
obm.from_mesh(mesh)
return obm
示例4: reassign_mats
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def reassign_mats(ob=None, type=None):
'''Resets materials based on stored face indices'''
if ob is None:
ob = bpy.context.object
if type == 'off':
ob.data.polygons.foreach_set('material_index', data[ob.name]['mat_index'])
ob.data.update()
idx = ob.data.materials.find(data[ob.name]['material'].name)
if idx != -1:
ob.data.materials.pop(idx, update_data=True)
bpy.data.materials.remove(data[ob.name]['material'])
del(data[ob.name])
if type == 'on':
idx = ob.data.materials.find(data[ob.name]['material'].name)
mat_idx = np.zeros(len(ob.data.polygons), dtype=np.int32) + idx
ob.data.polygons.foreach_set('material_index', mat_idx)
ob.data.update()
示例5: dynamic_tension_handler
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def dynamic_tension_handler(scene):
stretch = bpy.context.scene.dynamic_tension_map_max_stretch / 100
items = data.items()
if len(items) == 0:
for i in bpy.data.objects:
i.dynamic_tension_map_on = False
for i in bpy.app.handlers.scene_update_post:
if i.__name__ == 'dynamic_tension_handler':
bpy.app.handlers.scene_update_post.remove(i)
for i, value in items:
if i in bpy.data.objects:
update(ob=bpy.data.objects[i], max_stretch=stretch, bleed=0.2)
else:
del(data[i])
break
示例6: draw
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def draw(self, context):
#addon_updater_ops.check_for_update_background()
layout = self.layout
if get_addon_prefs(context).show_donate_icon:
row = layout.row()
row.alignment = "CENTER"
pcoll = preview_collections["main"]
donate_icon = pcoll["donate_icon"]
twitter_icon = pcoll["twitter_icon"]
row.operator("coa_operator.coa_donate",text="Show Your Love",icon_value=donate_icon.icon_id,emboss=True)
row = layout.row()
row.alignment = "CENTER"
row.scale_x = 1.75
op = row.operator("coa_operator.coa_tweet",text="Tweet",icon_value=twitter_icon.icon_id,emboss=True)
op.link = "https://www.youtube.com/ndee85"
op.text = "Check out CutoutAnimation Tools Addon for Blender by Andreas Esau."
op.hashtags = "b3d,coatools"
op.via = "ndee85"
addon_updater_ops.update_notice_box_ui(self, context)
示例7: draw_item
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
ob = data
slot = item
col = layout.row(align=True)
if item.name not in ["NO ACTION","Restpose"]:
col.label(icon="ACTION")
col.prop(item,"name",emboss=False,text="")
elif item.name == "NO ACTION":
col.label(icon="RESTRICT_SELECT_ON")
col.label(text=item.name)
elif item.name == "Restpose":
col.label(icon="ARMATURE_DATA")
col.label(text=item.name)
if context.scene.coa_nla_mode == "NLA" and item.name not in ["NO ACTION","Restpose"]:
col = layout.row(align=False)
op = col.operator("coa_operator.create_nla_track",icon="NLA",text="")
op.anim_collection_name = item.name
### Custom template_list look for event lists
示例8: change_weight_mode
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def change_weight_mode(self,context,mode):
if self.sprite_object.coa_edit_weights:
armature = get_armature(self.sprite_object)
armature.select = True
bpy.ops.view3d.localview()
bpy.context.space_data.viewport_shade = 'TEXTURED'
### zoom to selected mesh/sprite
for obj in bpy.context.selected_objects:
obj.select = False
obj = bpy.data.objects[context.active_object.name]
obj.select = True
context.scene.objects.active = obj
bpy.ops.view3d.view_selected()
### set uv image
set_uv_image(obj)
bpy.ops.object.mode_set(mode=mode)
示例9: remove_base_mesh
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def remove_base_mesh(obj):
bpy.ops.object.mode_set(mode="EDIT")
bm = bmesh.from_edit_mesh(obj.data)
bm.verts.ensure_lookup_table()
verts = []
if "coa_base_sprite" in obj.vertex_groups:
v_group_idx = obj.vertex_groups["coa_base_sprite"].index
for i,vert in enumerate(obj.data.vertices):
for g in vert.groups:
if g.group == v_group_idx:
verts.append(bm.verts[i])
break
bmesh.ops.delete(bm,geom=verts,context=1)
bm = bmesh.update_edit_mesh(obj.data)
bpy.ops.object.mode_set(mode="OBJECT")
示例10: check_region
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def check_region(context,event):
in_view_3d = False
if context.area != None:
if context.area.type == "VIEW_3D":
t_panel = context.area.regions[1]
n_panel = context.area.regions[3]
view_3d_region_x = Vector((context.area.x + t_panel.width, context.area.x + context.area.width - n_panel.width))
view_3d_region_y = Vector((context.region.y, context.region.y+context.region.height))
if event.mouse_x > view_3d_region_x[0] and event.mouse_x < view_3d_region_x[1] and event.mouse_y > view_3d_region_y[0] and event.mouse_y < view_3d_region_y[1]:
in_view_3d = True
else:
in_view_3d = False
else:
in_view_3d = False
return in_view_3d
示例11: create_action
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def create_action(context,item=None,obj=None):
sprite_object = get_sprite_object(context.active_object)
if len(sprite_object.coa_anim_collections) < 3:
bpy.ops.coa_tools.add_animation_collection()
if item == None:
item = sprite_object.coa_anim_collections[sprite_object.coa_anim_collections_index]
if obj == None:
obj = context.active_object
action_name = item.name + "_" + obj.name
if action_name not in bpy.data.actions:
action = bpy.data.actions.new(action_name)
else:
action = bpy.data.actions[action_name]
action.use_fake_user = True
if obj.animation_data == None:
obj.animation_data_create()
obj.animation_data.action = action
context.scene.update()
示例12: create_armature
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def create_armature(context):
obj = bpy.context.active_object
sprite_object = get_sprite_object(obj)
armature = get_armature(sprite_object)
if armature != None:
context.scene.objects.active = armature
armature.select = True
return armature
else:
amt = bpy.data.armatures.new("Armature")
armature = bpy.data.objects.new("Armature",amt)
armature.parent = sprite_object
context.scene.objects.link(armature)
context.scene.objects.active = armature
armature.select = True
amt.draw_type = "BBONE"
return armature
示例13: set_view
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def set_view(screen,mode):
if mode == "2D":
active_space_data = bpy.context.space_data
if active_space_data != None:
if hasattr(active_space_data,"region_3d"):
region_3d = active_space_data.region_3d
bpy.ops.view3d.viewnumpad(type='FRONT')
if region_3d.view_perspective != "ORTHO":
bpy.ops.view3d.view_persportho()
elif mode == "3D":
active_space_data = bpy.context.space_data
if active_space_data != None:
if hasattr(active_space_data,"region_3d"):
region_3d = active_space_data.region_3d
if region_3d.view_perspective == "ORTHO":
bpy.ops.view3d.view_persportho()
示例14: set_uv_default_coords
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def set_uv_default_coords(context,obj):
uv_coords = obj.data.uv_layers[obj.data.uv_layers.active.name].data
### add uv items
for i in range(len(uv_coords)-len(obj.coa_uv_default_state)):
item = obj.coa_uv_default_state.add()
### remove unneeded uv items
if len(uv_coords) < len(obj.coa_uv_default_state):
for i in range(len(obj.coa_uv_default_state) - len(uv_coords)):
obj.coa_uv_default_state.remove(0)
### set default uv coords
frame_size = Vector((1 / obj.coa_tiles_x,1 / obj.coa_tiles_y))
pos_x = frame_size.x * (obj.coa_sprite_frame % obj.coa_tiles_x)
pos_y = frame_size.y * -int(int(obj.coa_sprite_frame) / int(obj.coa_tiles_x))
frame = Vector((pos_x,pos_y))
offset = Vector((0,1-(1/obj.coa_tiles_y)))
for i,coord in enumerate(uv_coords):
uv_vec_x = (coord.uv[0] - frame[0]) * obj.coa_tiles_x
uv_vec_y = (coord.uv[1] - offset[1] - frame[1]) * obj.coa_tiles_y
uv_vec = Vector((uv_vec_x,uv_vec_y))
obj.coa_uv_default_state[i].uv = uv_vec
示例15: set_modulate_color
# 需要导入模块: import bpy [as 别名]
# 或者: from bpy import context [as 别名]
def set_modulate_color(obj,context,color):
r_engine = context.scene.render.engine
if r_engine in ["BLENDER_INTERNAL","BLENDER_GAME"]:
if obj.type == "MESH":
if not obj.material_slots[0].material.use_object_color:
obj.material_slots[0].material.use_object_color = True
obj.color[:3] = color
elif r_engine in ["CYCLES"]:
if obj.type == "MESH":
node_color_modulate = None
node_tree = obj.active_material.node_tree
if node_tree != None:
for node in node_tree.nodes:
if "coa_modulate_color" in node:
node_color_modulate = node
break
if node_color_modulate != None:
node_color_modulate.outputs[0].default_value[:3] = color