当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.translation方法代码示例

本文整理汇总了Python中mathutils.Matrix.translation方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.translation方法的具体用法?Python Matrix.translation怎么用?Python Matrix.translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathutils.Matrix的用法示例。


在下文中一共展示了Matrix.translation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_trunk_mesh

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
def get_trunk_mesh(context, prefs):
    me = context.blend_data.meshes.new("temp_mesh")
    bm = bmesh.new()
    bm.from_mesh(me)
    mat = Matrix()
    tt = prefs.lp_Tree_Type

    if tt == "lp_Tree_Oak" or tt == "lp_Tree_Pine":
        segments = get_random(prefs.lp_Tree_Trunk_Segments_Min, prefs.lp_Tree_Trunk_Segments_Max)
        trunklen = uniform(prefs.lp_Tree_Trunk_Length_Min, prefs.lp_Tree_Trunk_Length_Max)
        prefs.trunk_depth = 2.0 * trunklen
        mat.translation = (0, 0, prefs.trunk_depth / 2)
        trunk_diameter1 = 0.15 * uniform(prefs.lp_Tree_Trunk_Diameter1_Min, prefs.lp_Tree_Trunk_Diameter1_Max)
        trunk_diameter2 = 0.15 * uniform(prefs.lp_Tree_Trunk_Diameter2_Min, prefs.lp_Tree_Trunk_Diameter2_Max)
        bmesh.ops.create_cone(
            bm,
            cap_ends=False,
            cap_tris=True,
            segments=segments,
            diameter1=trunk_diameter1,
            diameter2=trunk_diameter2,
            depth=prefs.trunk_depth,
            matrix=mat,
        )
    elif tt == "lp_Tree_Palm":
        prefs.palm_stages = get_random(prefs.lp_Tree_Palm_Trunk_Stages_Min, prefs.lp_Tree_Palm_Trunk_Stages_Max)
        segments = get_random(prefs.lp_Tree_Palm_Trunk_Segments_Min, prefs.lp_Tree_Palm_Trunk_Segments_Max)
        prefs.palm_stage_length = uniform(
            prefs.lp_Tree_Palm_Trunk_Stage_Length_Min, prefs.lp_Tree_Palm_Trunk_Stage_Length_Max
        )
        stage_length = prefs.palm_stage_length
        diameter1 = uniform(prefs.lp_Tree_Palm_Trunk_Diameter1_Min, prefs.lp_Tree_Palm_Trunk_Diameter1_Max)
        diameter2 = uniform(prefs.lp_Tree_Palm_Trunk_Diameter2_Min, prefs.lp_Tree_Palm_Trunk_Diameter1_Max)
        for i in range(0, prefs.palm_stages):
            scale = 1
            mat[0][0], mat[1][1], mat[2][2] = (scale, scale, scale)
            # e = Euler((0, uniform(0, 0.2), 0), 'XYZ')
            # mat = mat * e.to_matrix().to_4x4()
            mat.translation = (0, 0, (stage_length / 2 + i * stage_length))
            bmesh.ops.create_cone(
                bm,
                cap_ends=True,
                cap_tris=True,
                segments=segments,
                diameter1=diameter1,
                diameter2=diameter2,
                depth=stage_length,
                matrix=mat,
            )
            # mat = Matrix()

    bm.to_mesh(me)
    return me
开发者ID:meta-androcto,项目名称:blenderpython,代码行数:55,代码来源:createTreeObject.py

示例2: get_coconuts_mesh

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
def get_coconuts_mesh(context, prefs):
    me = context.blend_data.meshes.new('temp_mesh')
    bm = bmesh.new()
    bm.from_mesh(me)
    mat = Matrix()

    trunk_length = prefs.palm_stage_length * prefs.palm_stages

    coconutX = (0.29, -0.29, 0,     0)
    coconutY = (0,     0,    0.29, -0.29)
    coconutZ = trunk_length - 0.2

    coconuts = get_random(prefs.lp_Tree_Palm_Top_Coconuts_Min,
                          prefs.lp_Tree_Palm_Top_Coconuts_Max)

    for i in range(0, coconuts):
        mat.translation = (coconutX[i], coconutY[i], coconutZ)
        bmesh.ops.create_icosphere(
            bm,
            subdivisions=1,
            diameter=0.15,
            matrix=mat)

    bm.to_mesh(me)

    return me
开发者ID:luboslenco,项目名称:lowpolyfactory,代码行数:28,代码来源:createTreeObject.py

示例3: draw_cloud

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
def draw_cloud(bm, prefs, translation=(0, 0, 0)):
    mat = Matrix()
    mat.translation = translation
    smin = prefs.lp_Cloud_Scale_Min
    smax = prefs.lp_Cloud_Scale_Max
    sx = uniform(smin[0], smax[0])
    sy = uniform(smin[1], smax[1])
    sz = uniform(smin[2], smax[2])
    scale = (sx, sy, sz)
    mat[0][0], mat[1][1], mat[2][2] = scale[0], scale[1], scale[2]
    e = Euler((uniform(0, 3.14), uniform(0, 3.14), uniform(0, 3.14)), 'XYZ')
    mat = mat * e.to_matrix().to_4x4()
    bmesh.ops.create_icosphere(bm, subdivisions=prefs.lp_Cloud_Subdivisions,
                               diameter=1.0, matrix=mat)
    return scale
开发者ID:luboslenco,项目名称:lowpolyfactory,代码行数:17,代码来源:createCloudObject.py

示例4: get_bush_mesh

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
def get_bush_mesh(context, prefs):
    me = context.blend_data.meshes.new('temp_mesh')
    bm = bmesh.new()
    bm.from_mesh(me)
    mat = Matrix()
    smin = prefs.lp_Rock_Scale_Min
    smax = prefs.lp_Rock_Scale_Max
    sx = uniform(smin[0], smax[0])
    sy = uniform(smin[1], smax[1])
    sz = uniform(smin[2], smax[2])
    scale = (sx, sy, sz)
    mat[0][0], mat[1][1], mat[2][2] = (scale[0], scale[1], scale[2])
    diameter = uniform(0.45, 0.55)
    mat.translation = (0, 0, diameter * scale[2])
    bmesh.ops.create_icosphere(bm, subdivisions=prefs.lp_Bush_Subdivisions,
                               diameter=diameter, matrix=mat)
    bm.to_mesh(me)

    return me
开发者ID:luboslenco,项目名称:lowpolyfactory,代码行数:21,代码来源:createBushObject.py

示例5: test_matrix_translation

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
 def test_matrix_translation(self):
     mat = Matrix()
     mat.translation = Vector((1, 2, 3))
     self.assertEqual(mat[0][3], 1)
     self.assertEqual(mat[1][3], 2)
     self.assertEqual(mat[2][3], 3)
开发者ID:,项目名称:,代码行数:8,代码来源:

示例6: execute

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
    def execute(self, context):

        from .model import SelectModel
        from .rigid_bodies import SelectGeometry, AssignGeometry
        from .segments import SelectSegment

        C = bpy.context
        D = bpy.data

        model = C.active_object

        bone_name = C.active_bone.name
        pose_bone = C.active_object.pose.bones[bone_name]

        if not C.active_bone.parent:
            self.report({"ERROR"}, "Does not work for root segments")
            return {'CANCELLED'}

        parent_bone = C.active_object.pose.bones[C.active_bone.parent.name]
        parent_name = parent_bone.name

        parent_frame = model.matrix_world * parent_bone.matrix

        bone_world = model.matrix_world * pose_bone.matrix
        bone_to_parent = bone_world.inverted() * parent_frame
        parent_to_bone = parent_frame.inverted() * bone_world
        l = bone_to_parent.translation.length

        v1 = bone_to_parent.translation
        max_v1 = max(abs(i) for i in v1)
        v2 = parent_to_bone.translation
        max_v2 = max(abs(i) for i in v2)

        if max_v1 != 0:
            bpy.ops.curve.primitive_bezier_circle_add(radius=l / 20)
            print(l)

            bevel = C.active_object

            bezier = bpy.ops.curve.primitive_bezier_curve_add()

            bezier = C.active_object
            bezier.data.bevel_object = bevel

            bezier.matrix_world = bone_world

            print(bezier.matrix_world)
            # e= C.active_bone.RobotEditor.Euler

            bpy.ops.object.mode_set(mode="EDIT", toggle=False)

            a = bezier.data.splines[0].bezier_points[0]
            b = bezier.data.splines[0].bezier_points[1]

            a.co = (0, 0, 0)
            b.co = bone_to_parent.translation

            print(v1, max_v1)
            v1 = Vector([0.1 * i / max_v1 if abs(i) == max_v1 else 0.0 for i in v1])

            v2 = Vector([0.1 * i / max_v2 if abs(i) == max_v2 else 0.0 for i in v2])
            # v2 = Vector(v2)#.to_4d()
            # v2[3]=0.0

            a.handle_right = v1
            a.handle_left = -1 * v1
            print(v1, a.handle_right, a.handle_left)

            m = Matrix()
            m.translation = v2

            # m[3][3] = 0
            # b.co = (bone_to_parent *m).translation
            print(m, bone_to_parent.inverted() * parent_frame * m)
            b.handle_left = (bone_to_parent * m).translation
            m.translation = -1 * v2

            b.handle_right = (bone_to_parent * m).translation
            print(v2, b.handle_right, b.handle_left)

            # print(a.co,b.co)

            bpy.ops.object.mode_set(mode="OBJECT", toggle=False)
            bpy.ops.object.convert(target='MESH')
            bpy.ops.object.select_all(action='DESELECT')
            bevel.select = True
            bpy.ops.object.delete()

            SelectModel.run(model_name=model.name)
            SelectGeometry.run(mesh_name=bezier.name) #
            SelectSegment.run(segment_name=parent_name)
            AssignGeometry.run()
            SelectSegment.run(segment_name=bone_name)


        GenerateMeshFromJoint.run()

        return {'FINISHED'}
开发者ID:pfotzer,项目名称:BlenderRobotDesigner,代码行数:100,代码来源:mesh_generation.py

示例7: get_top_mesh

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import translation [as 别名]
def get_top_mesh(context, prefs):
    me = context.blend_data.meshes.new("temp_mesh")
    bm = bmesh.new()
    bm.from_mesh(me)
    mat = Matrix()
    tt = prefs.lp_Tree_Type

    if tt == "lp_Tree_Oak":
        mat.translation = (0, 0, prefs.trunk_depth)
        tsmin = prefs.lp_Tree_Top_Scale_Min
        tsmax = prefs.lp_Tree_Top_Scale_Max
        mat[0][0], mat[1][1], mat[2][2] = (
            uniform(tsmin[0], tsmax[0]),
            uniform(tsmin[1], tsmax[1]),
            uniform(tsmin[2], tsmax[2]),
        )
        bmesh.ops.create_icosphere(bm, subdivisions=prefs.lp_Tree_Top_Subdivisions, diameter=1.0, matrix=mat)
    elif tt == "lp_Tree_Pine":
        segments = get_random(prefs.lp_Tree_Top_Stage_Segments_Min, prefs.lp_Tree_Top_Stage_Segments_Max)
        stages = get_random(prefs.lp_Tree_Top_Stages_Min, prefs.lp_Tree_Top_Stages_Max)
        td = prefs.trunk_depth - 0.7
        sstep = uniform(prefs.lp_Tree_Top_Stage_Step_Min, prefs.lp_Tree_Top_Stage_Step_Max)
        ssmin = prefs.lp_Tree_Top_Stage_Size_Min
        ssmax = prefs.lp_Tree_Top_Stage_Size_Max
        ssize = (uniform(ssmin[0], ssmax[0]), uniform(ssmin[1], ssmax[1]), uniform(ssmin[2], ssmax[2]))
        for i in range(0, stages):
            mult = prefs.lp_Tree_Top_Stage_Shrink_Multiplier * (i / 4)
            sc = (1 - i * prefs.lp_Tree_Top_Stage_Shrink * mult) * 0.9
            if sc < 0.01:
                sc = 0.01
            mat[0][0], mat[1][1], mat[2][2] = (sc * ssize[0], sc * ssize[1], sc * ssize[2])
            mat.translation = (0, 0, (td + ((ssize[2] - 1) / 2) + i * sstep) * 0.85)
            if prefs.lp_Tree_Top_Rotate_Stages:
                e = Euler((0, 0, uniform(0, 3.14)), "XYZ")
                mat = mat * e.to_matrix().to_4x4()
            bmesh.ops.create_cone(
                bm,
                cap_ends=True,
                cap_tris=True,
                segments=segments,
                diameter1=(prefs.lp_Tree_Top_Stage_Diameter),
                diameter2=0,
                depth=(0.85),
                matrix=mat,
            )
            mat = Matrix()
    elif tt == "lp_Tree_Palm":
        trunk_length = prefs.palm_stage_length * prefs.palm_stages
        leaf_length = get_random(prefs.lp_Tree_Palm_Top_Leaf_Length_Min, prefs.lp_Tree_Palm_Top_Leaf_Length_Max)
        leaf_size = uniform(prefs.lp_Tree_Palm_Top_Leaf_Size_Min, prefs.lp_Tree_Palm_Top_Leaf_Size_Max)

        mat.translation = (0, 0, trunk_length)
        leaves = get_random(prefs.lp_Tree_Palm_Top_Leaves_Min, prefs.lp_Tree_Palm_Top_Leaves_Max)
        bmesh.ops.create_cone(
            bm,
            cap_ends=True,
            cap_tris=True,
            segments=leaves,
            diameter1=leaf_size,
            diameter2=leaf_size,
            depth=0.1,
            matrix=mat,
        )
        faces = bm.faces[:]
        for face in faces:
            nor = face.normal  # Asume normalized normal
            dir = (nor.x * 0.3, nor.y * 0.3, -0.12)
            if nor.z == 0:
                for i in range(0, leaf_length):
                    r = bmesh.ops.extrude_discrete_faces(bm, faces=[face])
                    bmesh.ops.translate(bm, vec=dir, verts=r["faces"][0].verts)
                    face = r["faces"][0]
                    dir = (dir[0], dir[1], dir[2] - 0.08)
                # Align last face verts
                mid = [0, 0, 0]
                for v in face.verts:
                    mid[0] += v.co.x
                    mid[1] += v.co.y
                    mid[2] += v.co.z
                mid[0] /= len(face.verts)
                mid[1] /= len(face.verts)
                mid[2] /= len(face.verts)
                for v in face.verts:
                    v.co.x, v.co.y, v.co.z = mid[0], mid[1], mid[2]

    bm.to_mesh(me)
    return me
开发者ID:meta-androcto,项目名称:blenderpython,代码行数:89,代码来源:createTreeObject.py


注:本文中的mathutils.Matrix.translation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。