本文整理汇总了Python中mathutils.Matrix.identity方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.identity方法的具体用法?Python Matrix.identity怎么用?Python Matrix.identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Matrix
的用法示例。
在下文中一共展示了Matrix.identity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getmat
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def getmat(bone, active, context, ignoreparent):
'''Helper function for visual transform copy,
gets the active transform in bone space
'''
data_bone = context.active_object.data.bones[bone.name]
#all matrices are in armature space unless commented otherwise
otherloc = active.matrix # final 4x4 mat of target, location.
bonemat_local = Matrix(data_bone.matrix_local) # self rest matrix
if data_bone.parent:
parentposemat = Matrix(
context.active_object.pose.bones[data_bone.parent.name].matrix)
parentbonemat = Matrix(data_bone.parent.matrix_local)
else:
parentposemat = bonemat_local.copy()
parentbonemat = bonemat_local.copy()
# FIXME! why copy from the parent if setting identity ?, Campbell
parentposemat.identity()
parentbonemat.identity()
if parentbonemat == parentposemat or ignoreparent:
newmat = bonemat_local.inverted() * otherloc
else:
bonemat = parentbonemat.inverted() * bonemat_local
newmat = bonemat.inverted() * parentposemat.inverted() * otherloc
return newmat
示例2: _parseVertices
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def _parseVertices( self, mesh ):
'''
Extract the vertices from a blender mesh
'''
transform = Matrix().to_4x4()
transform.identity()
if not self.export_config.export_rot:
transform = self.export_config.global_matrix.to_4x4() * self.matrix_world
self.vertices = [transform * v.co for v in mesh.vertices]
示例3: to_avango_mesh
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def to_avango_mesh(obj, global_matrix):
local_matrix = obj.matrix_local
new_local = change_coordinate_system(global_matrix, local_matrix)
if obj.type == 'MESH':
if obj.find_armature() is None:
parent = 'null'
blender_obj = obj
if obj.name in bpy.data.objects:
blender_obj = bpy.data.objects[obj.name]
if blender_obj.parent:
parent = blender_obj.parent.name
filename = obj.name + '.obj'
bpy.ops.object.select_all(action='DESELECT')
# scene.objects.active = blender_obj
blender_obj.select = True
world = blender_obj.matrix_world.copy()
if not blender_obj.animation_data is None:
for f in blender_obj.animation_data.action.fcurves:
f.mute = True
Matrix.identity(blender_obj.matrix_world)
bpy.ops.export_scene.obj(
filepath=g_tmp_filepath + '/' + filename,
check_existing=False,
use_selection=True,
use_normals=True,
use_triangles=True,
use_uvs=True,
use_materials=False,
axis_forward='-Z',
axis_up='Y',
path_mode='AUTO', )
blender_obj.matrix_world = world
if not blender_obj.animation_data is None:
for f in blender_obj.animation_data.action.fcurves:
f.mute = False
blender_obj.select = False
if len(blender_obj.material_slots) > 0:
material = blender_obj.material_slots[0].material.name
else:
material = "default_material"
return {
'type': 'Mesh',
'name': obj.name,
'file': filename,
'parent': parent,
'transform': matrixToList(new_local),
'material': material,
'has_armature': False,
}
else:
arma = obj.find_armature()
parent = 'null'
# blender_obj = obj
# if obj.name in bpy.data.objects:
# blender_obj = bpy.data.objects[obj.name]
if arma.parent:
parent = arma.parent.name
filename = obj.name + '.fbx'
bpy.ops.object.select_all(action='DESELECT')
obj.select = True
arma.select = True
world = arma.matrix_world.copy()
Matrix.identity(arma.matrix_world)
bpy.ops.export_scene.fbx(
filepath=g_tmp_filepath + '/' + filename,
check_existing=False,
use_selection=True,
version='BIN7400',
use_mesh_modifiers=False,
add_leaf_bones=False,
bake_anim=False,
use_anim=False,
use_anim_action_all=False,
axis_forward='-Z',
axis_up='Y',
path_mode='AUTO',
embed_textures=True, )
arma.matrix_world = world
obj.select = False
arma.select = False
materials = []
if len(obj.material_slots) > 0:
for mat in obj.material_slots:
materials.append(mat.material.name)
else:
materials = ["default_material"]
return {
'type': 'Mesh',
#.........这里部分代码省略.........
示例4: anim_data
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def anim_data(armature, bone_ids):
armature_data = {}
armature_data["skeleton"] = {}
ids = 0
armature_data["bone_hierachy"] = {}
for i in range(0, len(armature.bones)):
armature_data["bone_hierachy"][i] = []
for bone in armature.bones:
bone_data = {}
if bone.name not in bone_ids:
bone_ids[bone.name] = ids
ids += 1
bone_data["id"] = bone_ids[bone.name]
parent = bone.parent
parent_transformation = Matrix()
parent_transformation.identity()
if parent is None:
bone_data["parent"] = None
else:
if parent.name not in bone_ids:
bone_ids[parent.name] = ids
ids += 1
bone_data["parent"] = bone_ids[parent.name]
parent_transformation = armature.bones[bone_data["parent"]].matrix_local
armature_data["bone_hierachy"][bone_data["parent"]].append(bone_data["id"])
transformation = parent_transformation.inverted() * bone.matrix_local
rot = transformation.to_quaternion()
rot.normalize()
bone_data["rotation"] = [rot.w, rot.x, rot.y, rot.z]
pos = transformation.to_translation()
bone_data["translation"] = [pos.x, pos.y, pos.z]
scale = transformation.to_scale()
bone_data["scale"] = [scale.x, scale.y, scale.z]
armature_data["skeleton"][bone_ids[bone.name]] = bone_data
armature_data["animations"] = {}
for action in bpy.data.actions:
armature_data["animations"][action.name] = {}
frame_range = action.frame_range
armature_data["animations"][action.name]["length"] = frame_range[1] - frame_range[0]
armature_data["animations"][action.name]["tracks"] = {}
old_name = ""
for fcu in action.fcurves:
bone_name = fcu.data_path
bone_name = bone_name[12:len(bone_name)]
bone_name = bone_name[0:bone_name.find("\"")]
bone_id = bone_ids[bone_name]
if bone_name not in armature_data["animations"][action.name]["tracks"]:
armature_data["animations"][action.name]["tracks"][bone_name] = {}
armature_data["animations"][action.name]["tracks"][bone_name]["id"] = bone_id
transformation_name = fcu.data_path
transformation_name = transformation_name[transformation_name.rfind(".") + 1:len(transformation_name)]
trans = armature_data["animations"][action.name]["tracks"][bone_name]
if transformation_name not in trans:
trans[transformation_name] = []
index = 0
for keyframe in fcu.keyframe_points:
if transformation_name != old_name:
trans[transformation_name].append({});
trans[transformation_name][-1]["frame"] = keyframe.co.x - frame_range[0]
trans[transformation_name][-1]["data"] = []
trans[transformation_name][index]["data"].append(keyframe.co.y)
index += 1
old_name = transformation_name
return armature_data
示例5: engine_update
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def engine_update(engine, data, scene):
# if hasattr(engine, "session"):
# print("update " + engine.session['uuid'])
# b_space_view_3d = context.space_data
# rv3d = b_space_view_3d.region_3d
# self.camera.NearClip.value = b_space_view_3d.clip_start
# self.camera.FarClip.value = b_space_view_3d.clip_end
# xs = matrix_to_list(rv3d.view_matrix)
# print(xs)
# #self.camera.Transform.value = av.transpose(
# av.from_list(xs))
# self.camera.Transform.value = av.transpose(
# av.inverse(av.from_list(xs)))
for o in scene.objects:
if o.name not in g_cached_objects:
if o.type == 'LAMP':
bl_lamp = bpy.data.lamps[o.data.name]
light = av.nodes.LightNode(
Type=from_blender_lamp_type(o.data.type),
Name=o.name,
Color=from_blender_color(bl_lamp.color),
Brightness=bl_lamp.energy,
Transform=from_blender_matrix4(o.matrix_world)
)
g_cached_objects[o.name] = light
g_graph.Root.value.Children.value.append(light)
elif o.type == 'MESH':
# parent = 'null'
# if o.parent:
# parent = o.parent.name
# matrix = o.matrix_world
filename = o.name + '.obj'
path = '/tmp/'
if not os.path.exists(path):
os.makedirs(path)
bpy.ops.object.select_all(action='DESELECT')
# scene.objects.active = o
o.select = True
world = o.matrix_world.copy()
Matrix.identity(o.matrix_world)
bpy.ops.export_scene.obj(
filepath=path+filename,
check_existing=False,
use_selection=True,
use_normals=True,
use_triangles=True,
use_uvs=True,
use_materials=True,
axis_forward='Y',
axis_up='Z',
path_mode='AUTO'
)
o.matrix_world = world
o.select = False
mesh = g_loader.create_geometry_from_file(
o.name,
path+filename,
av.LoaderFlags.NORMALIZE_SCALE)
for slot in o.material_slots:
# material = o.material_slots['Material'].material
material = o.material_slots[0].material
amaterial = material.avango
col = slot.material.diffuse_color
mesh.Material.value.set_uniform("Color",
av.Vec4(col.r,
col.g,
col.b, 1.0))
if slot.material.avango.use_color_texture:
mesh.Material.value.set_uniform("ColorMap",
texture_filepath(slot.material.avango.color_texture))
mesh.Material.value.set_uniform("Roughness",
amaterial.roughness)
if slot.material.avango.use_roughness_texture:
mesh.Material.value.set_uniform("RoughnessMap",
texture_filepath(slot.material.avango.roughness_texture))
mesh.Material.value.set_uniform("Metalness",
float(amaterial.metalness))
if slot.material.avango.use_metalness_texture:
mesh.Material.value.set_uniform("MetalnessMap",
texture_filepath(slot.material.avango.metalness_texture))
mesh.Material.value.set_uniform("Emissivity",
amaterial.emissivity)
mesh.Material.value.set_uniform("Opacity",
amaterial.opacity)
g_cached_objects[o.name] = mesh
g_graph.Root.value.Children.value.append(mesh)
elif o.type == 'CAMERA':
bl_camera = bpy.data.cameras[o.data.name]
acamera = bl_camera.avango
screen = av.nodes.ScreenNode(
Name="screen",
Width=2,
Height=1.5,
#.........这里部分代码省略.........
示例6: load
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
#.........这里部分代码省略.........
# ...
for bone_name in bone_channels:
# bone_name = channel[0]
if bone_name in armature.data.bones:
# print('%r is in armature %r' % (bone_name, armature.name))
'''
NOTE: skipped for now as no data needs to be readed
stream_count = bone_channels[bone_name][0]
keyframe_count = bone_channels[bone_name][1]
'''
streams = bone_channels[bone_name][2]
# print(' channel %r - streams %s - keyframes %s' % (bone_name, stream_count, keyframe_count))
# CREATE ANIMATION GROUP
anim_group = anim_action.groups.new(bone_name)
armature.pose.bones[bone_name].rotation_mode = 'XYZ' # Set rotation mode.
active_bone = armature.data.bones[bone_name]
# parent_bone = active_bone.parent
# CREATE FCURVES
(pos_fcurves,
rot_fcurves,
sca_fcurves) = _create_fcurves(anim_action, anim_group, str('pose.bones["' + bone_name + '"]'))
# GET BONE REST POSITION MATRIX
bone_rest_matrix = active_bone.matrix_local
bone_rest_matrix_scs = bones[bone_name][1].transposed()
parent_bone_name = bones[bone_name][0]
if parent_bone_name in bones:
parent_bone_rest_matrix_scs = bones[parent_bone_name][1].transposed()
else:
parent_bone_rest_matrix_scs = Matrix()
parent_bone_rest_matrix_scs.identity()
# if bone_name in ('LeftHand1', 'LeftHand'):
# print('\n %r - bone_rest_matrix_scs:\n%s' % (bone_name, bone_rest_matrix_scs))
# print(' %r - bone_rest_matrix:\n%s' % (bone_name, bone_rest_matrix))
# print(' %r - parent_bone_rest_matrix_scs:\n%s' % (bone_name, parent_bone_rest_matrix_scs))
for key_time_i, key_time in enumerate(streams[0]):
# print(' key_time: %s' % str(key_time[0]))
# keyframe = key_time_i * (key_time[0] * 10) ## TODO: Do proper timing...
keyframe = key_time_i + 1
# GET BONE ANIMATION MATRIX
bone_animation_matrix_scs = streams[1][key_time_i].transposed()
# if bone_name in ('LeftHand1', 'LeftHand') and key_time_i == 0: print(' %r - bone_animation_matrix_scs (%i):\n%s' % (
# bone_name, key_time_i, bone_animation_matrix_scs))
# CREATE DELTA MATRIX
delta_matrix = _get_delta_matrix(bone_rest_matrix, bone_rest_matrix_scs,
parent_bone_rest_matrix_scs, bone_animation_matrix_scs, import_scale)
# DECOMPOSE ANIMATION MATRIX
location, rotation, scale = delta_matrix.decompose()
# if bone_name in ('left_leg', 'root') and key_time_i == 0: print(' location:\n%s' % str(location))
rotation = rotation.to_euler('XYZ')
# BUILD TRANSLATION CURVES
pos_fcurves[0].keyframe_points.insert(frame=float(keyframe), value=location[0], options={'FAST'})
pos_fcurves[1].keyframe_points.insert(frame=float(keyframe), value=location[1], options={'FAST'})
pos_fcurves[2].keyframe_points.insert(frame=float(keyframe), value=location[2], options={'FAST'})
# BUILD ROTATION CURVES
rot_fcurves[0].keyframe_points.insert(frame=float(keyframe), value=rotation[0], options={'FAST'})
示例7: load
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
#.........这里部分代码省略.........
if len(bone_channels) > 0:
for bone_name in bone_channels:
if bone_name in armature.data.bones:
'''
NOTE: skipped for now as no data needs to be readed
stream_count = bone_channels[bone_name][0]
keyframe_count = bone_channels[bone_name][1]
'''
streams = bone_channels[bone_name][2]
# CREATE ANIMATION GROUP
anim_group = anim_action.groups.new(bone_name)
armature.pose.bones[bone_name].rotation_mode = 'XYZ' # Set rotation mode.
# use pose bone scale set on PIS import
init_scale = Vector((1, 1, 1))
if _BONE_consts.init_scale_key in armature.pose.bones[bone_name]:
init_scale = armature.pose.bones[bone_name][_BONE_consts.init_scale_key]
# CREATE FCURVES
(pos_fcurves,
rot_fcurves,
sca_fcurves) = _create_fcurves(anim_action, anim_group, str('pose.bones["' + bone_name + '"]'), rot_euler=True)
# GET BONE REST POSITION MATRIX
bone_rest_matrix_scs = bones[bone_name][1].transposed()
parent_bone_name = bones[bone_name][0]
if parent_bone_name in bones:
parent_bone_rest_matrix_scs = bones[parent_bone_name][1].transposed()
else:
parent_bone_rest_matrix_scs = Matrix()
parent_bone_rest_matrix_scs.identity()
for key_time_i, key_time in enumerate(streams[0]):
keyframe = key_time_i + 1
# GET BONE ANIMATION MATRIX
bone_animation_matrix_scs = streams[1][key_time_i].transposed()
# CREATE DELTA MATRIX
delta_matrix = _get_delta_matrix(bone_rest_matrix_scs, parent_bone_rest_matrix_scs, bone_animation_matrix_scs,
import_scale)
# DECOMPOSE ANIMATION MATRIX
location, rotation, scale = delta_matrix.decompose()
# CALCULATE CURRENT SCALE - subtract difference between initial bone scale and current scale from 1
# NOTE: if imported PIS had initial bone scale different than 1,
# initial scale was saved into pose bones custom properties and
# has to be used here as bones after import in Blender always have scale of 1
scale = Vector((1 + scale[0] - init_scale[0],
1 + scale[1] - init_scale[1],
1 + scale[2] - init_scale[2]))
# NOTE: this scaling rotation switch came from UK variants which had scale -1
loc, rot, sca = bone_rest_matrix_scs.decompose()
if sca.y < 0:
rotation.y *= -1
if sca.z < 0:
rotation.z *= -1
rotation = rotation.to_euler('XYZ')
# BUILD TRANSFORMATION CURVES
示例8: MakeZero
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
def MakeZero():
m = Matrix()
m.identity()
m[0][0], m[1][1], m[2][2], m[3][3] = 0.0, 0.0, 0.0, 0.0
return m
示例9: to_json
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
#.........这里部分代码省略.........
matrix = bpy.data.objects[obj.referenced_object].matrix_local
if lamp is not None:
return {
'name' : obj.name,
'type' : ty,
'color' : [ lamp.color.r, lamp.color.g, lamp.color.b],
'distance' : lamp.distance,
'parent' : parent,
'transform' : matrixToList(matrix),
'energy' : lamp.energy
}
else:
return {
'name' : obj.name,
'type' : ty
}
if isinstance(obj, field_container.Mesh):
parent = 'null'
blender_obj = None
if obj.referenced_object in bpy.data.objects:
blender_obj = bpy.data.objects[obj.referenced_object]
if blender_obj.parent:
parent = blender_obj.parent.name
matrix = blender_obj.matrix_local
filename = obj.name + '.obj'
if (obj.is_animation_hack):
filename = obj.name + '.md5mesh'
else:
splittedPath = filepath.split('/')
path = ''
for x in range(1, len(splittedPath)-1):
path += '/' + splittedPath[x]
if not os.path.exists(path + '/tmp'):
os.makedirs(path + '/tmp')
path += bpy.path.abspath('/tmp/')
bpy.ops.object.select_all(action='DESELECT')
# scene.objects.active = blender_obj
blender_obj.select = True
world = blender_obj.matrix_world.copy()
Matrix.identity(blender_obj.matrix_world)
bpy.ops.export_scene.obj(
filepath= path + filename,
check_existing=False,
use_selection=True,
use_normals=True,
use_triangles=True,
use_uvs=True,
use_materials=True,
axis_forward='Y',
axis_up='Z',
path_mode='AUTO'
)
blender_obj.matrix_world = world
blender_obj.select = False
return {
'type' : 'Mesh',
'name' : obj.name,
'file' : 'tmp/' + filename,
'parent' : parent,
'transform' : matrixToList(matrix)
}
if isinstance(obj, field_container.Screen):
parent = 'null'
matrix = []
if obj.referenced_object in bpy.data.objects:
if bpy.data.objects[obj.referenced_object].parent:
parent = bpy.data.objects[obj.referenced_object].parent.name
matrix = bpy.data.objects[obj.referenced_object].matrix_local
return {
'type' : 'Screen',
'name' : obj.name,
'parent' : parent,
'transform' : matrixToList(matrix)
}
if isinstance(obj, field_container.Transform):
parent = 'null'
if obj.referenced_object in bpy.data.objects:
if bpy.data.objects[obj.referenced_object].parent:
parent = bpy.data.objects[obj.referenced_object].parent.name
matrix = bpy.data.objects[obj.referenced_object].matrix_local
return {
'type' : 'Transform',
'parent' : parent,
'transform' : matrixToList(matrix),
'name' : obj.name
}
raise TypeError(repr(obj) + ' is not JSON serializable')
示例10: to_json
# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import identity [as 别名]
#.........这里部分代码省略.........
if lamp.shadow_method == 'NOSHADOW':
enable_shadows = False
return {
'name': obj.name,
'parent': parent,
'transform': matrixToList(matrix),
'type': lamp.type,
'color': [lamp.color.r, lamp.color.g, lamp.color.b],
'brightness': lamp.energy,
'enable_shadows': enable_shadows,
}
if obj.type == 'MESH':
if obj.find_armature() is None:
parent = 'null'
blender_obj = obj
if obj.name in bpy.data.objects:
blender_obj = bpy.data.objects[obj.name]
if blender_obj.parent:
parent = blender_obj.parent.name
matrix = blender_obj.matrix_local if blender_obj.parent else rot_x_neg90(blender_obj.matrix_local)
filename = obj.name + '.obj'
bpy.ops.object.select_all(action='DESELECT')
# scene.objects.active = blender_obj
blender_obj.select = True
world = blender_obj.matrix_world.copy()
if not blender_obj.animation_data is None:
for f in blender_obj.animation_data.action.fcurves:
f.mute = True
Matrix.identity(blender_obj.matrix_world)
bpy.ops.export_scene.obj(
filepath=g_tmp_filepath + filename,
check_existing=False,
use_selection=True,
use_normals=True,
use_triangles=True,
use_uvs=True,
use_materials=False,
axis_forward='Y',
axis_up='Z',
path_mode='AUTO', )
blender_obj.matrix_world = world
if not blender_obj.animation_data is None:
for f in blender_obj.animation_data.action.fcurves:
f.mute = False
blender_obj.select = False
if len(blender_obj.material_slots) > 0:
material = blender_obj.material_slots[0].material.name
else:
material = "default_material"
return {
'type': 'Mesh',
'name': obj.name,
'file': 'tmp/' + filename,
'parent': parent,
'transform': matrixToList(matrix),
'material': material,
'has_armature': False,