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


Python Vector.angle方法代码示例

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


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

示例1: test_orthogonal

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def test_orthogonal(self):

        angle_90d = math.pi / 2.0
        for v in vector_data:
            v = Vector(v)
            if v.length_squared != 0.0:
                self.assertAlmostEqual(v.angle(v.orthogonal()), angle_90d)
开发者ID:Ichthyostega,项目名称:blender,代码行数:9,代码来源:bl_pyapi_mathutils.py

示例2: viewrotate_apply

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def viewrotate_apply(self, context, event):
        # FIXME
        vod = self.vod
        x, y = event.x, event.y
        if context.user_preferences.inputs.view_rotate_method == 'TRACKBALL':
            newvec = calctrackballvec(context.region, event.x, event.y)
            dvec = newvec - vod.trackvec
            angle = (dvec.length / (2.0 * TRACKBALLSIZE)) * math.pi
            angle = angle_wrap_rad(angle)

            axis = vod.trackvec.cross(newvec)
            q1 = Quaternion(axis, angle)
            vod.viewquat = q1 * vod.oldquat

            self.viewrotate_apply_dyn_ofs(vod.viewquat)
        else:
            zvec_global = Vector([0, 0, 1])
            sensitivity = 0.007
            m = vod.viewquat.to_matrix()
            m_inv = m.inverted()

            if (zvec_global - m_inv.col[2]).length > 0.001:
                xaxis = zvec_global.closs(m_inv.col[0])
                if xaxis.dot(m_inv.col[0]) < 0:
                    xaxis.negate()
                fac = zvec_global.angle(m_inv.col[2]) / math.pi
                fac = abs(fac - 0.5) * 2
                fac *= fac
                xaxis = xaxis.lerp(m_inv.col[0], fac)
            else:
                xaxis = m_inv[0].copy()
            quat_local_x = Quaternion(xaxis, sensitivity * - (y - vod.oldy))
            quat_local_x = vod.viewquat * quat_local_x

            def axis_angle_to_quat_single(axis, angle):
                angle_half = angle * 0.5
                angle_cos = math.cos(angle_half)
                angle_sin = math.sin(angle_half)
                axis_index = ['X', 'Y', 'Z'].index(axis)
                q = Quaternion([angle_cos, 0, 0, 0])
                q[axis_index + 1] = angle_sin
                return q
            quat_global_z = axis_angle_to_quat_single(
                'Z', sensitivity * vod.reverse * (x - vod.oldx))
            vod.viewquat = quat_local_x * quat_global_z

            self.viewrotate_apply_dyn_ofs(vod.viewquat)

        vod.viewquat.normalize()
        context.region_data.view_rotation = vod.viewquat.inverted()
        if vod.axis_snap:
            self.viewrotate_apply_snap(vod)

        vod.oldx = x
        vod.oldy = y

        ED_view3d_camera_lock_sync(vod.v3d, context.region_data)

        context.region.tag_redraw()
        pass
开发者ID:Italic-,项目名称:blenderpython,代码行数:62,代码来源:__init__.py

示例3: draw_gems

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def draw_gems(self, context, ratio_w=1, ratio_h=1):
        from_scene_scale = unit.Scale(context).from_scene

        view_normal = Vector((0.0, 0.0, 1.0)) @ self.region_3d.view_matrix
        angle_thold = pi / 1.8

        fontid = 0
        blf.size(fontid, self.prefs.view_font_size_gem_size, 72)
        blf.color(fontid, 0.0, 0.0, 0.0, 1.0)

        shader = gpu.shader.from_builtin("2D_UNIFORM_COLOR")
        depsgraph = context.depsgraph

        for dup in depsgraph.object_instances:

            if dup.is_instance:
                ob = dup.instance_object.original
            else:
                ob = dup.object.original

            if "gem" not in ob or (self.use_select and not ob.select_get()):
                continue

            shader.bind()

            ob_stone = ob["gem"]["stone"]
            ob_cut = ob["gem"]["cut"]
            ob_size = tuple(round(x, 2) for x in from_scene_scale(ob.dimensions, batch=True))

            for stone, cut, size, size_fmt, color in self.gems_raw:
                if ob_stone == stone and ob_cut == cut and ob_size == size:
                    shader.uniform_float("color", color)
                    break

            me = ob.to_mesh(depsgraph, True)
            me.transform(dup.matrix_world)
            verts = me.vertices

            for poly in me.polygons:
                if view_normal.angle(poly.normal) < angle_thold:
                    cos = [
                        loc_3d_to_2d(self.region, self.region_3d, verts[v].co, ratio_w, ratio_h)
                        for v in poly.vertices
                    ]
                    batch = batch_for_shader(shader, "TRI_FAN", {"pos": cos})
                    batch.draw(shader)

            bpy.data.meshes.remove(me)

            # Size
            # -----------------------------

            ob_loc = dup.matrix_world.translation.to_tuple()
            loc_x, loc_y = loc_3d_to_2d(self.region, self.region_3d, ob_loc, ratio_w, ratio_h)
            dim_x, dim_y = blf.dimensions(fontid, size_fmt)

            blf.position(fontid, loc_x - dim_x / 2, loc_y - dim_y / 2, 0.0)
            blf.draw(fontid, size_fmt)
开发者ID:mrachinskiy,项目名称:jewelcraft,代码行数:60,代码来源:offscreen.py

示例4: set_bonded

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
def set_bonded(atom,b):
    """Sets the positions of all atoms bonded to atom.
    
    atom: Atom object
    rotate: Boolean defining whether or not to rotate tetrahedron around the z-axis
    b: bond length
    """
    x = 0
    y = 0
    z = 0
    b = b*sqrt(atom.radius)
    
    bonds = atom.bonds
    
    #Differences in position between central atom and bonded atom
    for item in bonds:
        if isinstance(item, Atom):
            x = atom.pos[0] - item.pos[0]
            y = atom.pos[1] - item.pos[1]
            z = atom.pos[2] - item.pos[2]
            break
   
    n = math.radians(109.5)
    n2 = pi*2/3

    #Represents tetrahedron base centered at (0,0,0)
    v1 = Vector((b*sin(n),0,b*cos(n)))
    v2 = Vector((b*cos(n2),b*sin(n2),b*cos(n)))
    v3 = Vector((b*cos(2*n2),b*sin(2*n2),b*cos(n)))
    
    offset = (Vector((atom.pos)))

    top= Vector((0,0,-b))
    diff = Vector((x,y,z))

    axis = top.cross(diff)
    a = -(top.angle(diff, 0))
    
    m = Matrix.Rotation(a,3,axis)
    #Rotates the tetrahedron base to align itself with the starting vector
    v1 = v1*m
    v2 = v2*m
    v3 = v3*m
    
    #Sets the positions of bonded atoms to locations in the tetrahedron, scales bond lengths and moves tetrahedron
    if len(bonds) >1:
        if isinstance(bonds[1], Atom):
            bonds[1].pos = v1*sqrt(bonds[1].radius)+offset
    if len(bonds) >2:
        if isinstance(bonds[2], Atom):
            bonds[2].pos = v2*sqrt(bonds[2].radius)+offset
    if len(bonds)>3:
        if isinstance(bonds[3],Atom):
            bonds[3].pos = v3*sqrt(bonds[3].radius)+offset
开发者ID:ETumang,项目名称:MolecularModeling,代码行数:56,代码来源:moleculeDisplay.py

示例5: calcFaceByNormal

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def calcFaceByNormal(self, points, normal, face):
        a = [ t - u for t,u in zip(points[1], points[0])]   # vector a = point[1] - point[0]
        b = [ t - u for t,u in zip(points[2], points[0])]   # vector b = point[2] - point[0]
        # normal = a x b = (a2b3-a3b2)i-(a1b3-a3b1)j+(a1b2-a2b1)k.
        myNormal = Vector([a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]])
        angle = myNormal.angle(Vector(normal))

        # if vectors are in opposite direction change points order
        if angle > math.pi/2 or angle < -math.pi/2:
            return (face[1], face[0], face[2])
        return face
开发者ID:aquilart,项目名称:oni2,代码行数:13,代码来源:oni_types.py

示例6: getValues

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
def getValues():
	'''Return mesh data values (z, slope or az) for classification'''
	scn = bpy.context.scene
	obj = scn.objects.active
	#make a temp mesh with modifiers apply
	#mesh = obj.data #modifiers not apply
	mesh = obj.to_mesh(scn, apply_modifiers=True, settings='PREVIEW')
	mesh.transform(obj.matrix_world)
	#
	mode = scn.analysisMode
	if mode == 'HEIGHT':
		values = [vertex.co.z for vertex in mesh.vertices]
	elif mode == 'SLOPE':
		z = Vector((0,0,1))
		m = obj.matrix_world
		values =  [math.degrees(z.angle(m * face.normal)) for face in mesh.polygons]
	elif mode == 'ASPECT':
		y = Vector((0,1,0))
		m = obj.matrix_world
		#values =  [math.degrees(y.angle(m * face.normal)) for face in mesh.polygons]
		values = []
		for face in mesh.polygons:
			normal = face.normal.copy()
			normal.z = 0 #project vector into XY plane
			try:
				a = math.degrees(y.angle(m * normal))
			except ValueError:
				pass#zero length vector as no angle
			else:
				#returned angle is between 0° (north) to 180° (south)
				#we must correct it to get angle between 0 to 360°
				if normal.x <0:
					a = 360 - a
				values.append(a)
	values.sort()
	#remove temp mesh
	bpy.data.meshes.remove(mesh)

	return values
开发者ID:jmhehir,项目名称:BlenderGIS,代码行数:41,代码来源:reclassify.py

示例7: calcRotAngle

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def calcRotAngle(self, axis, nor_x, nor_y, nor_z):
        theta = 0
        vector_z = Vector((0.0, 0.0, 1.0))
        vector_n = None
        vector_cross = None

        if axis == 'X':
            vector_n = Vector((0.0, nor_y, nor_z))
            theta = vector_z.angle(vector_n, 999)
            vector_cross = vector_n.cross(vector_z)
            if vector_cross.x < 0:
                theta = -(theta)
        elif axis == 'Y':
            vector_n = Vector((nor_x, 0.0, nor_z))
            theta = vector_z.angle(vector_n, 999)
            vector_cross = vector_n.cross(vector_z)
            if vector_cross.y < 0:
                theta = -(theta)
        else:
            pass

        return theta
开发者ID:Italic-,项目名称:blenderpython,代码行数:24,代码来源:uv_prj_from_normal.py

示例8: vec_roll_to_mat3

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
def vec_roll_to_mat3(vec, roll):
	target = Vector((0,1,0))
	nor = vec.normalized()
	axis = target.cross(nor)
	if axis.dot(axis) > 0.000001:
		axis.normalize()
		theta = target.angle(nor)
		bMatrix = Matrix.Rotation(theta, 3, axis)
	else:
		updown = 1 if target.dot(nor) > 0 else -1
		bMatrix = Matrix.Scale(updown, 3)
	rMatrix = Matrix.Rotation(roll, 3, nor)
	mat = rMatrix * bMatrix
	return mat
开发者ID:uthaman22,项目名称:asstools,代码行数:16,代码来源:iqe_import.py

示例9: modal_rotate_tool

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def modal_rotate_tool(self, context, eventd):
        cx,cy = self.action_center
        mx,my = eventd['mouse']
        px,py = self.prev_pos #mode_pos

        if eventd['press'] in {'RET', 'NUMPAD_ENTER', 'LEFTMOUSE'}:
            self.tool_fn('commit', eventd)
            return 'main'

        if eventd['press'] in {'ESC', 'RIGHTMOUSE'}:
            self.tool_fn('undo', eventd)
            return 'main'

        if eventd['type'] == 'MOUSEMOVE':
            vp = Vector((px-cx,py-cy,0))
            vm = Vector((mx-cx,my-cy,0))
            ang = vp.angle(vm) * (-1 if vp.cross(vm).z<0 else 1)
            self.tool_rot += ang
            self.tool_fn(self.tool_rot, eventd)
            self.prev_pos = (mx,my)
            return ''

        return ''
开发者ID:tomjpsun,项目名称:retopoflow,代码行数:25,代码来源:polystrips_ui_tools.py

示例10: bake

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def bake(self, context, samples=False):
        ''' bake a driver to an action fcurve'''

        # REFACTO add flag to convert between kfs and samples
        def get_action_fcurve(driver):
            obj = driver.fcurve.id_data
            action = obj.animation_data.action # will have animation_data from driver
            if action is None:
                action = obj.animation_data.action = bpy.data.actions.new("%s (BFD)" % obj.name)
            fc = [fc for fc in action.fcurves if fc.data_path == driver.fcurve.data_path and fc.array_index == driver.fcurve.array_index]
            if len(fc):
                return fc[0]
            fc = action.fcurves.new(driver.data_path, driver.array_index)
            return fc

        scene = context.scene
        frame = self.f
        frame_end = self.f + self.bakeframes[self.pc] - 1
        # bake to scene frame range
        self.driver.edit_driver_baking = True
        setattr(self.driver, "bake_pc", self.pc / self.chunks)
        driver = self.driver.fcurve
        obj = driver.id_data

        #action = speaker.animation_data.action

        # make an unbaked fcurve for the driver.
        # check whether there is already an fcurve

        coords = []
        while frame <= frame_end:
            scene.frame_set(frame)
            co = (frame, self.driver.value)
            v = Vector(co)
            if len(coords) > 1:  # enough to linear test
                v1 = Vector(coords[-1]) - v
                v2 = Vector(coords[-2]) - v
                if v1.length and v2.length and v1.angle(v2) < 0.001:
                    coords[-1] = co
                else:
                    coords.append(co)
            else:
                coords.append(co)
            # quick fix try array, then without
            #REFACTO 
            frame += 1
            '''
            # frame by frame kfi
            if self.driver.is_vector:
                driver.id_data.keyframe_insert(driver.data_path,
                                               index=driver.array_index)
            else:
                driver.id_data.keyframe_insert(driver.data_path)

            frame += 1 # REFACTO 
            '''

        fc = get_action_fcurve(self.driver)
        l = len(coords)
        #x = []  # refactor got keyframe_points.foreach_set
        for i in range(l):
            fc.keyframe_points.insert(*coords[i])
        
        if samples:
            fc.convert_to_samples(self.f, frame_end)
        return True
开发者ID:Italic-,项目名称:blenderpython,代码行数:68,代码来源:sounddriver.py

示例11: create_mesh

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]

#.........这里部分代码省略.........
        surface.select = True 

        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
        # sum((v.co for v in mesh.vertices), Vector()) / len(mesh.vertices)

        if use_smooth:
            for polygon in surface.data.polygons:
                polygon.use_smooth = True

        surface.location = Vector((0.0, image_x_offset, 0.0)) 
        image_x_offset += image_x_size / 2.0 + image_x_offset_gap

        #print("passed - create_mesh ---- 3")


        
    object_center_vec = Vector((0.0,0.0,0.0))
    object_size = (sum(AFMdata.x_size) * scale_size 
                   +image_x_offset_gap * (len(data_list)-1))

    # ------------------------------------------------------------------------
    # CAMERA AND LAMP
    camera_factor = 20.0
    
    # If chosen a camera is put into the scene.
    if use_camera == True:

        # Assume that the object is put into the global origin. Then, the
        # camera is moved in x and z direction, not in y. The object has its
        # size at distance sqrt(object_size) from the origin. So, move the
        # camera by this distance times a factor of camera_factor in x and z.
        # Then add x, y and z of the origin of the object.
        object_camera_vec = Vector((sqrt(object_size) * camera_factor,
                                    0.0,
                                    sqrt(object_size) * camera_factor))
        camera_xyz_vec = object_center_vec + object_camera_vec

        # Create the camera
        current_layers=bpy.context.scene.layers 
        camera_data = bpy.data.cameras.new("A_camera")
        camera_data.lens = 45
        camera_data.clip_end = 50000.0
        camera = bpy.data.objects.new("A_camera", camera_data)
        camera.location = camera_xyz_vec
        camera.layers = current_layers
        bpy.context.scene.objects.link(camera) 

        # Here the camera is rotated such it looks towards the center of
        # the object. The [0.0, 0.0, 1.0] vector along the z axis
        z_axis_vec             = Vector((0.0, 0.0, 1.0))
        # The angle between the last two vectors
        angle                  = object_camera_vec.angle(z_axis_vec, 0)
        # The cross-product of z_axis_vec and object_camera_vec
        axis_vec               = z_axis_vec.cross(object_camera_vec)
        # Rotate 'axis_vec' by 'angle' and convert this to euler parameters.
        # 4 is the size of the matrix.
        camera.rotation_euler  = Matrix.Rotation(angle, 4, axis_vec).to_euler()

        # Rotate the camera around its axis by 90° such that we have a nice
        # camera position and view onto the object.
        bpy.ops.object.select_all(action='DESELECT')        
        camera.select = True         
        bpy.ops.transform.rotate(value=(90.0*2*pi/360.0),
                                 axis=object_camera_vec,
                                 constraint_axis=(False, False, False),
                                 constraint_orientation='GLOBAL',
                                 mirror=False, proportional='DISABLED',
                                 proportional_edit_falloff='SMOOTH',
                                 proportional_size=1, snap=False,
                                 snap_target='CLOSEST', snap_point=(0, 0, 0),
                                 snap_align=False, snap_normal=(0, 0, 0),
                                 release_confirm=False)

    # Here a lamp is put into the scene, if chosen.
    if use_lamp == True:

        # This is the distance from the object measured in terms of %
        # of the camera distance. It is set onto 50% (1/2) distance.
        lamp_dl = sqrt(object_size) * 15 * 0.5
        # This is a factor to which extend the lamp shall go to the right
        # (from the camera  point of view).
        lamp_dy_right = lamp_dl * (3.0/4.0)

        # Create x, y and z for the lamp.
        object_lamp_vec = Vector((lamp_dl,lamp_dy_right,lamp_dl))
        lamp_xyz_vec = object_center_vec + object_lamp_vec

        # Create the lamp
        current_layers=bpy.context.scene.layers
        lamp_data = bpy.data.lamps.new(name="A_lamp", type="POINT")
        lamp_data.distance = 5000.0
        lamp_data.energy = 3.0
        lamp_data.shadow_method = 'RAY_SHADOW'        
        lamp = bpy.data.objects.new("A_lamp", lamp_data)
        lamp.location = lamp_xyz_vec
        lamp.layers = current_layers
        bpy.context.scene.objects.link(lamp)         

        bpy.context.scene.world.light_settings.use_ambient_occlusion = True
        bpy.context.scene.world.light_settings.ao_factor = 0.1      
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:104,代码来源:import_gwyddion.py

示例12: import_xyz

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]

#.........这里部分代码省略.........
    object_size = max(object_size_vec).length

    # ------------------------------------------------------------------------
    # CAMERA AND LAMP
    camera_factor = 20.0

    # If chosen a camera is put into the scene.
    if use_camera == True:

        # Assume that the object is put into the global origin. Then, the
        # camera is moved in x and z direction, not in y. The object has its
        # size at distance sqrt(object_size) from the origin. So, move the
        # camera by this distance times a factor of camera_factor in x and z.
        # Then add x, y and z of the origin of the object.
        object_camera_vec = Vector((sqrt(object_size) * camera_factor,
                                    0.0,
                                    sqrt(object_size) * camera_factor))
        camera_xyz_vec = object_center_vec + object_camera_vec

        # Create the camera
        current_layers=bpy.context.scene.layers 
        camera_data = bpy.data.cameras.new("A_camera")
        camera_data.lens = 45
        camera_data.clip_end = 500.0
        camera = bpy.data.objects.new("A_camera", camera_data)
        camera.location = camera_xyz_vec
        camera.layers = current_layers
        bpy.context.scene.objects.link(camera) 

        # Here the camera is rotated such it looks towards the center of
        # the object. The [0.0, 0.0, 1.0] vector along the z axis
        z_axis_vec             = Vector((0.0, 0.0, 1.0))
        # The angle between the last two vectors
        angle                  = object_camera_vec.angle(z_axis_vec, 0)
        # The cross-product of z_axis_vec and object_camera_vec
        axis_vec               = z_axis_vec.cross(object_camera_vec)
        # Rotate 'axis_vec' by 'angle' and convert this to euler parameters.
        # 4 is the size of the matrix.
        camera.rotation_euler  = Matrix.Rotation(angle, 4, axis_vec).to_euler()

        # Rotate the camera around its axis by 90° such that we have a nice
        # camera position and view onto the object.
        bpy.ops.object.select_all(action='DESELECT')        
        camera.select = True         
        bpy.ops.transform.rotate(value=(90.0*2*pi/360.0),
                                 axis=object_camera_vec,
                                 constraint_axis=(False, False, False),
                                 constraint_orientation='GLOBAL',
                                 mirror=False, proportional='DISABLED',
                                 proportional_edit_falloff='SMOOTH',
                                 proportional_size=1, snap=False,
                                 snap_target='CLOSEST', snap_point=(0, 0, 0),
                                 snap_align=False, snap_normal=(0, 0, 0),
                                 release_confirm=False)

    # Here a lamp is put into the scene, if chosen.
    if use_lamp == True:

        # This is the distance from the object measured in terms of %
        # of the camera distance. It is set onto 50% (1/2) distance.
        lamp_dl = sqrt(object_size) * 15 * 0.5
        # This is a factor to which extend the lamp shall go to the right
        # (from the camera  point of view).
        lamp_dy_right = lamp_dl * (3.0/4.0)

        # Create x, y and z for the lamp.
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:70,代码来源:import_xyz.py

示例13: import_pdb

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]

#.........这里部分代码省略.........

    # ------------------------------------------------------------------------
    # CAMERA AND LAMP

    camera_factor = 15.0

    # If chosen a camera is put into the scene.
    if use_camera == True:

        # Assume that the object is put into the global origin. Then, the
        # camera is moved in x and z direction, not in y. The object has its
        # size at distance sqrt(object_size) from the origin. So, move the
        # camera by this distance times a factor of camera_factor in x and z.
        # Then add x, y and z of the origin of the object.
        object_camera_vec = Vector((sqrt(object_size) * camera_factor,
                                    0.0,
                                    sqrt(object_size) * camera_factor))
        camera_xyz_vec = object_center_vec + object_camera_vec

        # Create the camera
        current_layers=bpy.context.scene.layers 
        camera_data = bpy.data.cameras.new("A_camera")
        camera_data.lens = 45
        camera_data.clip_end = 500.0
        camera = bpy.data.objects.new("A_camera", camera_data)
        camera.location = camera_xyz_vec
        camera.layers = current_layers
        bpy.context.scene.objects.link(camera)

        # Here the camera is rotated such it looks towards the center of
        # the object. The [0.0, 0.0, 1.0] vector along the z axis
        z_axis_vec             = Vector((0.0, 0.0, 1.0))
        # The angle between the last two vectors
        angle                  = object_camera_vec.angle(z_axis_vec, 0)
        # The cross-product of z_axis_vec and object_camera_vec
        axis_vec               = z_axis_vec.cross(object_camera_vec)
        # Rotate 'axis_vec' by 'angle' and convert this to euler parameters.
        # 4 is the size of the matrix.
        camera.rotation_euler  = Matrix.Rotation(angle, 4, axis_vec).to_euler()

        # Rotate the camera around its axis by 90° such that we have a nice
        # camera position and view onto the object.
        bpy.ops.object.select_all(action='DESELECT')        
        camera.select = True 
        bpy.ops.transform.rotate(value=(90.0*2*pi/360.0),
                                 axis=object_camera_vec,
                                 constraint_axis=(False, False, False),
                                 constraint_orientation='GLOBAL',
                                 mirror=False, proportional='DISABLED',
                                 proportional_edit_falloff='SMOOTH',
                                 proportional_size=1, snap=False,
                                 snap_target='CLOSEST', snap_point=(0, 0, 0),
                                 snap_align=False, snap_normal=(0, 0, 0),
                                 release_confirm=False)

    # Here a lamp is put into the scene, if chosen.
    if use_lamp == True:

        # This is the distance from the object measured in terms of %
        # of the camera distance. It is set onto 50% (1/2) distance.
        lamp_dl = sqrt(object_size) * 15 * 0.5
        # This is a factor to which extend the lamp shall go to the right
        # (from the camera  point of view).
        lamp_dy_right = lamp_dl * (3.0/4.0)

        # Create x, y and z for the lamp.
开发者ID:ubuntunux,项目名称:Blender,代码行数:70,代码来源:import_pdb.py

示例14: camera_light_source

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
def camera_light_source(use_camera,
                        use_light,
                        object_center_vec,
                        object_size):

    camera_factor = 15.0

    # If chosen a camera is put into the scene.
    if use_camera == True:

        # Assume that the object is put into the global origin. Then, the
        # camera is moved in x and z direction, not in y. The object has its
        # size at distance sqrt(object_size) from the origin. So, move the
        # camera by this distance times a factor of camera_factor in x and z.
        # Then add x, y and z of the origin of the object.
        object_camera_vec = Vector((sqrt(object_size) * camera_factor,
                                    0.0,
                                    sqrt(object_size) * camera_factor))
        camera_xyz_vec = object_center_vec + object_camera_vec

        # Create the camera
        camera_data = bpy.data.cameras.new("A_camera")
        camera_data.lens = 45
        camera_data.clip_end = 500.0
        camera = bpy.data.objects.new("A_camera", camera_data)
        camera.location = camera_xyz_vec
        bpy.context.collection.objects.link(camera)

        # Here the camera is rotated such it looks towards the center of
        # the object. The [0.0, 0.0, 1.0] vector along the z axis
        z_axis_vec             = Vector((0.0, 0.0, 1.0))
        # The angle between the last two vectors
        angle                  = object_camera_vec.angle(z_axis_vec, 0)
        # The cross-product of z_axis_vec and object_camera_vec
        axis_vec               = z_axis_vec.cross(object_camera_vec)
        # Rotate 'axis_vec' by 'angle' and convert this to euler parameters.
        # 4 is the size of the matrix.
        camera.rotation_euler  = Matrix.Rotation(angle, 4, axis_vec).to_euler()

        # Rotate the camera around its axis by 90° such that we have a nice
        # camera position and view onto the object.
        bpy.ops.object.select_all(action='DESELECT')
        camera.select_set(True)
        
        # Rotate the camera around its axis 'object_camera_vec' by 90° such 
        # that we have a nice camera view onto the object.
        matrix_rotation = Matrix.Rotation(90/360*2*pi, 4, object_camera_vec)
        rotate_object(matrix_rotation, camera)

    # Here a lamp is put into the scene, if chosen.
    if use_light == True:

        # This is the distance from the object measured in terms of %
        # of the camera distance. It is set onto 50% (1/2) distance.
        light_dl = sqrt(object_size) * 15 * 0.5
        # This is a factor to which extend the lamp shall go to the right
        # (from the camera  point of view).
        light_dy_right = light_dl * (3.0/4.0)

        # Create x, y and z for the lamp.
        object_light_vec = Vector((light_dl,light_dy_right,light_dl))
        light_xyz_vec = object_center_vec + object_light_vec

        # Create the lamp
        light_data = bpy.data.lights.new(name="A_light", type="SUN")
        light_data.distance = 500.0
        light_data.energy = 3.0
        lamp = bpy.data.objects.new("A_light", light_data)
        lamp.location = light_xyz_vec
        bpy.context.collection.objects.link(lamp)

        # Some settings for the World: a bit ambient occlusion
        bpy.context.scene.world.light_settings.use_ambient_occlusion = True
        bpy.context.scene.world.light_settings.ao_factor = 0.2
        # Some properties for cycles
        lamp.data.use_nodes = True
        lmp_P_BSDF = lamp.data.node_tree.nodes['Emission']
        lmp_P_BSDF.inputs['Strength'].default_value = 5
开发者ID:sambler,项目名称:myblenderaddons,代码行数:80,代码来源:xyz_import.py

示例15: pose_layer

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import angle [as 别名]
    def pose_layer(self, armature, bone_name, plane, tex, key):
        
        ox,oy,width,height = tex['rect']
    ##            bpy.ops.object.select_all(action='DESELECT')
        bpy.context.scene.objects.active = bpy.data.objects[armature.name]
        #bpy.ops.object.select_pattern(pattern=str(armature.name), case_sensitive=False, extend=True)
        bpy.ops.object.mode_set(mode='POSE')

        #set index
        bone = bpy.context.object.pose.bones[bone_name]
        index = key['index']

        
        if 'loc' in key:
            loc = key['loc']
    ##                loc = self.transformPoint(loc[0], loc[1], width, height)
            bone.location.x = loc[0]
            bone.location.y = -loc[1]
            bone.keyframe_insert(data_path="location", frame=index)
            self.report({'INFO'}, "  bone loc: {0} index: {1}".format(bone_name, index))

        scale = None
        
    ##            http://www.senocular.com/flash/tutorials/transformmatrix/
        if 'skew' in key :
            skew = key['skew']
            scale = (1,1)
            if 'scale' in key:
                scale = key['scale']

            #origin
            #ox, oy = self.transformPoint(ox, oy, width , height)

            #work out longest vector
            v = Vector((ox - width, 0.0,0.0))
            if height > width:
                v = Vector((0.0, oy - height, 0.0))
            
            m = mathutils.Matrix.Identity(3)
            m[0][0] = scale[0]
            m[1][1] = scale[1]
            m[0][1] = skew[0]
            m[1][0] = skew[1]

            r = m * v
            avg = v.angle(r)
            c = v.cross(r)

##            #y transform
##            y = Vector((1.0, 0.0, 0.0))
##            v = m * y
##            angle = v.angle(y)
##            c = v.cross(y)
##
##            #x transform
##            x = Vector((0.0, 1.0, 0.0))
##            v = m * x
##            angle2 = v.angle(x)

##            self.report({'INFO'}, "  angle: {0} angle2: {1}".format(angle, angle2))

##            avg = (angle + angle2)/2.0
            if c[2] < 0:
                avg *= -1

            bone.rotation_euler.z = avg
            bone.keyframe_insert(data_path="rotation_euler", frame=index)

        if 'scale' in key:
            if scale is None:
                scale = key['scale']
            bone.scale.x = scale[0]
            bone.scale.y = scale[1]
            bone.keyframe_insert(data_path="scale", frame=index)

        relative_parent = True

        if 'pivot' in key:
            pivot = key['pivot']
            #pivot is actually the same as origin (just updated in case of switching symbols per layer)
            
            #invertY 
            ox, oy = self.transformPoint(pivot[0], pivot[1], width , height)

            #tail position in image coordinates
            tx = width / 2.0
            ty = height / 2.0

            if not relative_parent:
                #set origin
                plane.location.x =  - ox + tx
                plane.location.y =  - oy
            else:
                bpy.data.armatures[armature.name].bones[bone_name].use_relative_parent = True
                bpy.data.armatures[armature.name].bones[bone_name].use_local_location = False
                plane.location.x =  (-width /2 )+ox
                plane.location.y =  (+height/2) - oy
            plane.keyframe_insert(data_path="location", frame=index)
开发者ID:dmg46664,项目名称:flumpkit,代码行数:100,代码来源:import_scripts.py


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