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


Python Vector.normalized方法代码示例

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


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

示例1: stroke_normal

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
def stroke_normal(it):
    """
    Compute the 2D normal at the stroke vertex pointed by the iterator
    'it'.  It is noted that Normal2DF0D computes normals based on
    underlying FEdges instead, which is inappropriate for strokes when
    they have already been modified by stroke geometry modifiers.
    """
    # first stroke segment
    it_next = it.incremented()
    if it.is_begin:
        e = it_next.object.point_2d - it.object.point_2d
        n = Vector((e[1], -e[0]))
        return n.normalized()
    # last stroke segment
    it_prev = it.decremented()
    if it_next.is_end:
        e = it.object.point_2d - it_prev.object.point_2d
        n = Vector((e[1], -e[0]))
        return n.normalized()
    # two subsequent stroke segments
    e1 = it_next.object.point_2d - it.object.point_2d
    e2 = it.object.point_2d - it_prev.object.point_2d
    n1 = Vector((e1[1], -e1[0])).normalized()
    n2 = Vector((e2[1], -e2[0])).normalized()
    n = (n1 + n2)
    return n.normalized()
开发者ID:linkedinyou,项目名称:blender-git,代码行数:28,代码来源:utils.py

示例2: proj_z

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
 def proj_z(self, t, dz0, next=None, dz1=0):
     """
         length of projection along crossing line / circle
         deformation unit vector for profil in z axis at line / line intersection
         so f(y) = position of point in yz plane
     """
     return Vector((0, 1)), 1
     """
         NOTE (to myself):
           In theory this is how it has to be done so sections follow path,
           but in real world results are better when sections are z-up.
           So return a dumb 1 so f(y) = y
     """
     if next is None:
         dz = dz0 / self.length
     else:
         dz = (dz1 + dz0) / (self.length + next.length)
     return Vector((0, 1)), sqrt(1 + dz * dz)
     # 1 / sqrt(1 + (dz0 / self.length) * (dz0 / self.length))
     if next is None:
         return Vector((-dz0, self.length)).normalized(), 1
     v0 = Vector((self.length, dz0))
     v1 = Vector((next.length, dz1))
     direction = Vector((-dz0, self.length)).normalized() + Vector((-dz1, next.length)).normalized()
     adj = v0 * v1
     hyp = (v0.length * v1.length)
     c = min(1, max(-1, adj / hyp))
     size = -cos(pi - 0.5 * acos(c))
     return direction.normalized(), size
开发者ID:sambler,项目名称:myblenderaddons,代码行数:31,代码来源:archipack_2d.py

示例3: add_torus

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
 def add_torus(self, majSeg, minSeg, majRad, minRad):
     lv = []
     circ = math.pi*2
     majCirc = circ/majSeg
     minCirc = circ/minSeg
     index = 0
     rings = []
     for maj in range(majSeg):
         majTheta = majCirc*maj
         dx = math.cos(majTheta) * majRad
         dy = math.sin(majTheta) * majRad
         n = Vector((dx, dy, 0))
         minorRing = []
         for min in range(minSeg):
             minTheta = minCirc*min
             dn = math.cos(minTheta) * minRad
             dz = math.sin(minTheta) * minRad
             co = n + n.normalized() * dn + Vector((0, 0, dz))
             co = co.to_tuple()
             lv.append(self.new_vertex((Vector((co)))))
             minorRing.append(index)
             index += 1
         rings.append(minorRing)
     for ri in range(len(rings)-1):
         ring = rings[ri]
         nextRing = rings[ri+1]
         for i in range(len(ring)-1):
             self.new_face([lv[ring[i]], lv[nextRing[i]], lv[nextRing[i+1]], lv[ring[i+1]]])
         self.new_face([lv[ring[0]], lv[ring[len(ring)-1]], lv[nextRing[len(nextRing)-1]], lv[nextRing[0]]])
     ring = rings[len(rings)-1]
     nextRing = rings[0]
     for i in range(len(ring)-1):
         self.new_face([lv[ring[i]], lv[nextRing[i]], lv[nextRing[i+1]], lv[ring[i+1]]])
     self.new_face([lv[ring[0]], lv[ring[len(ring)-1]], lv[nextRing[len(nextRing)-1]], lv[nextRing[0]]])
开发者ID:JustPowell,项目名称:Surfaces-Modeling-Coursework,代码行数:36,代码来源:mesh.py

示例4: getVector

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
 def getVector(self, point):
     vect = Vector((0.0, 0.0, 0.0))
     for n in range(0, len(self.guides)):
         guide = self.guides[n]
         weight = self.weights[n]
         vect += guide.getVector(point).normalized() * weight
     return vect.normalized()
开发者ID:tigertowel,项目名称:BlenderTreeCurves,代码行数:9,代码来源:Guides.py

示例5: pass_line

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
def pass_line(vecs, is_closed_line):
    line_length = 0.0
    line_data = []
    vecs_len = len(vecs)

    for i, vec in enumerate(vecs):
        #if i == vecs_len - 1 and is_closed_line is False:
            #line_data.append((vec, line_length, 0.0, None))
        #else:
        vec_area = None
        if i == vecs_len - 1:
            if is_closed_line:
                vec_area = vecs[0] - vec
            else:
                vec_area = Vector( (0.0, 0.0, 0.0) )
        else:
            vec_area = vecs[i+1] - vec

        area_length = vec_area.length

        vec_dir = None
        if i == vecs_len - 1:
            vec_dir = (vec - vecs[i-1]).normalized()
        else:
            vec_dir = vec_area.normalized()

        line_data.append((vec.copy(), line_length, area_length, vec_dir))

        line_length += area_length

    # last point line of closed curve
    if is_closed_line:
        vec_area = vecs[0] - vecs[-1]
        area_length = vec_area.length
        vec_dir = vec_area.normalized()
        line_data.append((vecs[0], line_length, 0.0, None))

    return line_data
开发者ID:Italic-,项目名称:blenderpython,代码行数:40,代码来源:mi_curve_main.py

示例6: torus

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
def torus(majSeg, minSeg, majRad, minRad):
    lp = []
    lf = []
    
    circ = math.pi*2
    majCirc = circ/majSeg
    minCirc = circ/minSeg
    
    index = 0
    
    rings = []
    
    for maj in range(majSeg):
        majTheta = majCirc*maj
        dx = math.cos(majTheta) * majRad
        dy = math.sin(majTheta) * majRad
        n = Vector((dx, dy, 0))
        
        minorRing = []
        for min in range(minSeg):
            minTheta = minCirc*min
            dn = math.cos(minTheta) * minRad
            dz = math.sin(minTheta) * minRad
            
            co = n + n.normalized() * dn + Vector((0, 0, dz))
            co = co.to_tuple()
            lp.append(co)
            minorRing.append(index)
            index += 1
        rings.append(minorRing)
    
    for ri in range(len(rings)-1):
        ring = rings[ri]
        nextRing = rings[ri+1]
        for i in range(len(ring)-1):
            lf.append((ring[i], nextRing[i], nextRing[i+1], ring[i+1]))
        lf.append((ring[0], ring[len(ring)-1], nextRing[len(nextRing)-1], nextRing[0]))
    ring = rings[len(rings)-1]
    nextRing = rings[0]
    for i in range(len(ring)-1):
        lf.append((ring[i], nextRing[i], nextRing[i+1], ring[i+1]))
    lf.append((ring[0], ring[len(ring)-1], nextRing[len(nextRing)-1], nextRing[0]))
    
    return lp, lf   
开发者ID:JustPowell,项目名称:Surfaces-Modeling-Coursework,代码行数:46,代码来源:common.py

示例7: execute

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

        mesh = context.object.data

        mesh.use_auto_smooth = True
        bpy.ops.mesh.customdata_custom_splitnormals_clear()

        bm = bmesh.new()
        bm.from_mesh(mesh)
        bm.verts.ensure_lookup_table()

        nor_weighted = []
        for v in bm.verts:
            max_area = 0
            areas = {}
            for i, f in enumerate(v.link_faces):

                if f.smooth:
                    area = f.calc_area()
                    areas[i] = area

                    if area > max_area:
                        max_area = area

            normal = Vector()
            for i, f in enumerate(v.link_faces):
                if f.smooth:
                    perc = areas[i] / max_area
                    normal += perc * f.normal

            nor_weighted.extend(normal.normalized())

        bm.free()

        nor_list = [(0,)] * len(mesh.loops)
        for poly in mesh.polygons:

            l_s = poly.loop_start
            l_e = poly.loop_start + poly.loop_total - 1

            curr_l = l_s
            prev_l = l_e
            while curr_l <= l_e:

                curr_loop = mesh.loops[curr_l]
                prev_loop = mesh.loops[prev_l]

                # if at least one edge of this corner doesn't use sharp edge
                # apply calculated weighted normal
                if not mesh.edges[curr_loop.edge_index].use_edge_sharp or not mesh.edges[prev_loop.edge_index].use_edge_sharp:

                    curr_n = nor_weighted[curr_loop.vertex_index * 3:curr_loop.vertex_index * 3 + 3]
                    nor_list[curr_l] = curr_n

                else:

                    nor_list[curr_l] = curr_loop.normal

                prev_l = curr_l
                curr_l += 1

        bpy.ops.mesh.customdata_custom_splitnormals_add()
        mesh.normals_split_custom_set(nor_list)
        mesh.free_normals_split()

        return {'FINISHED'}
开发者ID:Italic-,项目名称:blenderpython,代码行数:68,代码来源:mesh_weighted_normals.py

示例8: noise

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
def noise(var=1):
    rand = Vector((r.gauss(0, 1), r.gauss(0, 1), r.gauss(0, 1)))
    vec = rand.normalized() * var
    return vec
开发者ID:fjuhec,项目名称:blender-addons,代码行数:6,代码来源:add_curve_spirofit_bouncespline.py

示例9: execute

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
	def execute(self, context):
		mesh = context.active_object.data
		
		mesh.update()
		mesh.calc_normals_split()
		
		# store old normals
		normslist = []
		loopnorms = [v.normal for v in mesh.loops]
		loopcount = 0
		for f in mesh.polygons:
			fvns = []
			for i in range(len(f.vertices)):
				fvns.append(loopnorms[loopcount].copy())
				loopcount += 1
			normslist.append(fvns)
		del loopnorms[:]
		
		# clear old normals
		emptynormslist = tuple(tuple((0,0,0)) for v in mesh.vertices)
		for e in mesh.edges:
			if e.use_edge_sharp:
				e.use_edge_sharp = False
		
		mesh.validate(clean_customdata=False)
		if mesh.use_auto_smooth:
			mesh.use_auto_smooth = False
		if mesh.show_edge_sharp:
			mesh.show_edge_sharp = False
		mesh.normals_split_custom_set_from_vertices(emptynormslist)
		mesh.free_normals_split()
		mesh.update()
		
		# gather old split normals
		rawnormslist = [[] for v in mesh.vertices]
		
		faceslist = [f for f in mesh.polygons]
		fcount = 0
		for f in faceslist:
			newfn = []
			vcount = 0
			for v in f.vertices:
				rawnormslist[v].append(normslist[fcount][vcount])
				vcount += 1
			fcount += 1
		
		# average split normals for new list
		procnormslist = []
		for vl in rawnormslist:
			tempv = Vector((0.0,0.0,0.0))
			for v in vl:
				tempv = tempv + v
			tempv = tempv.normalized()
			procnormslist.append(tempv)
		
		vertslist = [v for v in mesh.vertices]
		vcount = 0
		for v in vertslist:
			v.normal = procnormslist[vcount]
			vcount += 1
		
		del rawnormslist[:]
		del procnormslist[:]
		del faceslist[:]
		del vertslist[:]
		
		return {'FINISHED'}
开发者ID:dfelinto,项目名称:blenderpython,代码行数:69,代码来源:normeditor_functions.py

示例10: determine_influence

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
    def determine_influence(self, octree, falloff_curve,
                            ignore_backfacing=False, mesh_object=None):
        coordinate_map = octree.coordinate_map
        map_manager = MapManager()
        primary_brush = self.primary_brush
        vertex_filter = VertexFilter()
        vertex_filter.mesh_object = mesh_object

        # Determine the primary brush's influence.
        center = primary_brush.center
        radius = primary_brush.radius
        vertex_filter.indices = octree.get_indices_in_box(center, radius)
        vertex_filter.coordinate_map = coordinate_map
        distance_map = vertex_filter.discard_outside_of_sphere(center, radius)
        primary_brush.indices = vertex_filter.indices

        # Only proceed if at least one vertex is within the primary brush's
        # influence.
        if primary_brush.indices:
            # Create the falloff map for the vertex indices that are within the
            # primary brush's influence.
            map_manager.map_ = distance_map
            map_manager.clip_domain(primary_brush.indices, 'RETAIN')
            primary_brush.falloff_map =\
                falloff_curve.get_falloff_map_from_distance_map(
                    distance_map, radius
                )

            # Calculate the primary brush's normal.
            primary_brush_falloff_map = primary_brush.falloff_map
            primary_brush_normal = primary_brush.normal
            normal = Vector((0, 0, 0))
            normal_sampling_radius = 0.333 * radius
            model_matrix = bpy.context.active_object.matrix_world
            vertices = bpy.context.active_object.data.vertices
            for vertex_index, distance in distance_map.items():
                # Only vertices within the normal sampling radius contribute to
                # the primary brush's normal.
                if distance <= normal_sampling_radius:
                    # Disregard vertices that face away from the primary
                    # brush's initial normal.
                    vertex_normal = model_matrix * (
                        vertices[vertex_index].normal
                    ).normalized()
                    if vertex_normal.dot(primary_brush_normal) > 0:
                        # Each vertex normal contributes in proportion to its
                        # falloff value.
                        normal += vertex_normal * (
                            primary_brush_falloff_map[vertex_index]
                        )
            normal.normalize()
            if normal.length_squared > 0:
                primary_brush.normal = normal.normalized()

            # Discard vertices facing away from the primary brush, if
            # necessary.
            if ignore_backfacing:
                vertex_filter.indices = primary_brush.indices
                vertex_filter.discard_backfacing(primary_brush.normal, 'WORLD')
                primary_brush.indices = vertex_filter.indices

        # Determine each derived brush's influence.
        self.update_derived()
        for brush in self.derived_brushes:
            # Determine which vertex indices are within the brush's influence.
            center = brush.center
            radius = brush.radius
            vertex_filter.indices = octree.get_indices_in_box(center, radius)
            vertex_filter.coordinate_map = octree.coordinate_map
            distance_map =\
                vertex_filter.discard_outside_of_sphere(center, radius)
            if ignore_backfacing:
                vertex_filter.discard_backfacing(brush.normal, 'WORLD')
            brush.indices = vertex_filter.indices

            # Only proceed if at least one vertex is within the brush's
            # influence.
            if primary_brush.indices:
                # Create the falloff map for the vertex indices that are within
                # the brush's influence.
                map_manager.map_ = distance_map
                map_manager.clip_domain(brush.indices, 'RETAIN')
                brush.falloff_map =\
                    falloff_curve.get_falloff_map_from_distance_map(
                        distance_map, radius
                    )
开发者ID:Italic-,项目名称:blenderpython,代码行数:88,代码来源:Brushes.py

示例11: calc_weighted_normal

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
    def calc_weighted_normal(bm, vert_index, edge_index):
        """Calculates weighted normal for given combination of vertex and edge index.
        WARNING: There is no safety chec if thoose two belongs together.

        :param bm: bmesh object
        :type bm: bmesh
        :param vert_index: index of the vertex to calculate normal for
        :type vert_index: int
        :param edge_index: index of the edge to use for calculation (vertex has to belong to this edge)
        :returns: Vector
        """
        normal_hash = str(vert_index) + ":" + str(edge_index)

        if normal_hash in WeightNormalsCalculator.cache:
            return WeightNormalsCalculator.cache[normal_hash]

        edge = bm.edges[edge_index]
        vert = bm.verts[vert_index]

        selected_faces = []

        # edge.seam = True
        # edge.select_set(True)

        for f in edge.link_faces:

            if not f.select:

                f.select = True
                selected_faces.append(f)

        # select linked faces of already selected edges
        # until every smooth face around current loop is selected
        more_selected = 1
        while more_selected > 0:

            more_selected = 0
            for edge1 in vert.link_edges:

                if edge1.smooth and edge1.select:

                    for f in edge1.link_faces:

                        if not f.select:

                            f.select = True
                            selected_faces.append(f)

                            more_selected += 1

        # calc areas
        max_area = 0
        areas = {}
        for i, f in enumerate(selected_faces):
            area = f.calc_area()
            areas[i] = area

            if area > max_area:
                max_area = area

        # calc normal
        normal = Vector()
        for i, f in enumerate(selected_faces):
            perc = areas[i] / max_area
            f.normal_update()
            normal += perc * f.normal

            # also unselect all the faces
            f.select = False

        WeightNormalsCalculator.cache[normal_hash] = normal.normalized()

        return normal.normalized()
开发者ID:mkbreuer,项目名称:ToolPlus,代码行数:75,代码来源:display_normals_weighted.py

示例12: generate_newnormals

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
def generate_newnormals(self, context):
    genmode = context.window_manager.vn_genmode
    me = context.active_object.data
    bm = bmesh.new()

    if context.mode == 'EDIT_MESH':
        bm = bmesh.from_edit_mesh(me)
    else:
        bm.from_mesh(me)

    me.update()

    faces_list = [f for f in bm.faces]
    verts_list = [v for v in bm.verts]

    # DEFAULT: Blender default
    if (genmode == 'DEFAULT'):
        wasobjmode = (context.mode == 'OBJECT')

        if wasobjmode:
            bpy.ops.object.mode_set(mode='EDIT')
            bm = bmesh.from_edit_mesh(me)
            me.update()
            faces_list = [f for f in bm.faces]
            verts_list = [v for v in bm.verts]

        bpy.ops.mesh.normals_make_consistent()

        if context.window_manager.edit_splitnormals:
            normals_data.cust_normals_ppoly.clear()
            for i in range(len(faces_list)):
                faceverts = [v for v in faces_list[i].verts]
                normals_data.cust_normals_ppoly.append([])
                for j in range(len(faceverts)):
                    normals_data.cust_normals_ppoly[len(normals_data.cust_normals_ppoly) - 1].append(faceverts[j].normal.copy())
        else:
            normals_data.cust_normals_pvertex.clear()
            for i in range(len(verts_list)):
                normals_data.cust_normals_pvertex.append(verts_list[i].normal.copy())

        if wasobjmode:
            bpy.ops.object.mode_set(mode='OBJECT')

    # UPVECT: custom direction
    elif (genmode == 'UPVECT'):
        if context.window_manager.edit_splitnormals:
            if context.window_manager.vn_genselectiononly:
                for i in range(len(normals_data.cust_normals_ppoly)):
                    for j in range(len(normals_data.cust_normals_ppoly[i])):
                        if faces_list[i].verts[j].select:
                            normals_data.cust_normals_ppoly[i][j] = Vector(context.window_manager.vn_dirvector)
            else:
                for i in range(len(normals_data.cust_normals_ppoly)):
                    for j in range(len(normals_data.cust_normals_ppoly[i])):
                        normals_data.cust_normals_ppoly[i][j] = Vector(context.window_manager.vn_dirvector)
        else:
            if context.window_manager.vn_genselectiononly:
                for i in range(len(verts_list)):
                    if verts_list[i].select:
                        normals_data.cust_normals_pvertex[i] = Vector(context.window_manager.vn_dirvector)
            else:
                for i in range(len(verts_list)):
                    normals_data.cust_normals_pvertex[i] = Vector(context.window_manager.vn_dirvector)

    # BENT: Bent from point (3D cursor)
    elif (genmode == 'BENT'):
        cursorloc = context.scene.cursor_location
        if context.window_manager.edit_splitnormals:
            if context.window_manager.vn_genselectiononly:
                for i in range(len(normals_data.cust_normals_ppoly)):
                    for j in range(len(normals_data.cust_normals_ppoly[i])):
                        if not (faces_list[i].hide) and faces_list[i].select:
                            tempv = Vector(faces_list[i].verts[j].co) - cursorloc
                            tempv = tempv.normalized()
                            normals_data.cust_normals_ppoly[i][j] = tempv.copy()
            else:
                for i in range(len(faces_list)):
                    for j in range(len(faces_list[i].verts)):
                        tempv = Vector(vd.vpos) - cursorloc
                        tempv = tempv.normalized()
                        normals_data.cust_normals_ppoly[i][j] = tempv.copy()
        else:
            if context.window_manager.vn_genselectiononly:
                for i in range(len(verts_list)):
                    if verts_list[i].select:
                        tempv = Vector(verts_list[i].co) - cursorloc
                        tempv = tempv.normalized()
                        tempv = (normals_data.cust_normals_pvertex[i] * (1.0 - context.window_manager.vn_genbendingratio)) + (tempv * (context.window_manager.vn_genbendingratio))
                        normals_data.cust_normals_pvertex[i] = tempv
            else:
                for i in range(len(verts_list)):
                    tempv = Vector(verts_list[i].co) - cursorloc
                    tempv = tempv.normalized()
                    tempv = (normals_data.cust_normals_pvertex[i] * (1.0 - context.window_manager.vn_genbendingratio)) + (tempv * (context.window_manager.vn_genbendingratio))
                    normals_data.cust_normals_pvertex[i] = tempv

    # G_FOLIAGE: combination of bent and up-vector for ground foliage
    elif (genmode == 'G_FOLIAGE'):
        ignorehidden = context.window_manager.vn_genignorehidden
        cursorloc = Vector(context.window_manager.vn_centeroffset)
#.........这里部分代码省略.........
开发者ID:meta-androcto,项目名称:blenderpython,代码行数:103,代码来源:editorfunctions.py

示例13: bevel

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

#.........这里部分代码省略.........
            vr02 = va2 - va0
            vr0c = vac - va0

            if beveltype == 'vert':
                vflags[vindex] = VERT
            elif e1.select and e2.select:
                tmp = [len(efdict[e1.key]), len(efdict[e2.key])]
                if tmp[0] == 1 and tmp[1] == 1:
                    vflags[vindex] = VERT
                elif tmp[0] == 2 and tmp[1] == 1:
                    ea, eb, vra, vrb = e2, e1, vr02, vr01
                    vflags[vindex] = EDGE
                elif tmp[0] == 1 and tmp[1] == 2:
                    ea, eb, vra, vrb = e1, e2, vr01, vr02
                    vflags[vindex] = EDGE
                else:
                    vflags[vindex] = FACE
            elif not e1.select and not e2.select:
                vflags[vindex] = VERT
            else:
                eb = e1 if e1.select else e2
                if len(efdict[eb.key]) == 1:
                    vflags[vindex] = VERT
                else:
                    vflags[vindex] = EDGE
                    if e1.select:
                        ea, eb, vra, vrb = e2, e1, vr02, vr01
                    else:
                        ea, eb, vra, vrb = e1, e2, vr01, vr02

            if vflags[vindex] == FACE:
                # 両方のエッジが選択
                # エッジの角度が180度以上になる場合は予期しない結果になる
                vr010c_cross = vr01.cross(vr0c).normalized()
                angle = vr01.angle(vr02)
                q = axis_angle_to_quat(vr010c_cross, angle / 2)
                v = q * vr01 
                v.normalize()
                if angle > SMALL_NUMBER:
                    s = math.sin(angle / 2)
                    v *= 1.0 / s
                else:
                    v = Vector((0, 0, 0))
                #co = va0 + v # absolute coordinate
                co = va0.copy()

                bevelvert = BVert(v, co, bevelvertindex,
                                  vindex, e1.index, findex)# e1, e2どちらを優先しても可
                bevelvert.ebi = e2.index
                bevelvert.f = FACE
                bevelverts.append(bevelvert)
                vcor[vindex].append(bevelvert.vi) # == bevelvertindex
                #vflags[vindex] = FACE
                bevelvertindex += 1
            elif vflags[vindex] == VERT:
                # 両方のエッジが非選択
                # 頂点をエッジに沿って分割
                for ea, eb, v in [(e1, e2, vr01), (e2, e1, vr02)]:
                    vei = vevparallel[vindex][ea.index]
                    if not vei:
                        v = v.normalized()
                        #co = va0 + v
                        co = va0.copy()
                        bevelvert = BVert(v, co, bevelvertindex,
                                          vindex, ea.index, findex)
                        bevelvert.ebi = eb.index # bevelされた辺
开发者ID:TomACPace,项目名称:blenderpython,代码行数:70,代码来源:__init__.py

示例14: getNormalizedVector

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import normalized [as 别名]
 def getNormalizedVector(sefl, vector):
     v = Vector(vector)
     return v.normalized()
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:5,代码来源:EdgeRoundifier.py

示例15: main

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

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

        # Pretend that the most unique angle is ages away to start the loop off
        mostUniqueAngle = -1.0

        # This is popped
        tempMeshFaces = meshFaces[:]



        # This while only gathers projection vecs, faces are assigned later on.
        while 1:
            # If theres none there then start with the largest face

            # add all the faces that are close.
            for fIdx in range(len(tempMeshFaces)-1, -1, -1):
                # Use half the angle limit so we don't overweight faces towards this
                # normal and hog all the faces.
                if newProjectVec.dot(tempMeshFaces[fIdx].no) > USER_PROJECTION_LIMIT_HALF_CONVERTED:
                    newProjectMeshFaces.append(tempMeshFaces.pop(fIdx))

            # Add the average of all these faces normals as a projectionVec
            averageVec = Vector((0.0, 0.0, 0.0))
            if user_area_weight == 0.0:
                for fprop in newProjectMeshFaces:
                    averageVec += fprop.no
            elif user_area_weight == 1.0:
                for fprop in newProjectMeshFaces:
                    averageVec += fprop.no * fprop.area
            else:
                for fprop in newProjectMeshFaces:
                    averageVec += fprop.no * ((fprop.area * user_area_weight) + (1.0 - user_area_weight))

            if averageVec.x != 0 or averageVec.y != 0 or averageVec.z != 0: # Avoid NAN
                projectVecs.append(averageVec.normalized())


            # Get the next vec!
            # Pick the face thats most different to all existing angles :)
            mostUniqueAngle = 1.0 # 1.0 is 0d. no difference.
            mostUniqueIndex = 0 # dummy

            for fIdx in range(len(tempMeshFaces)-1, -1, -1):
                angleDifference = -1.0 # 180d difference.

                # Get the closest vec angle we are to.
                for p in projectVecs:
                    temp_angle_diff= p.dot(tempMeshFaces[fIdx].no)

                    if angleDifference < temp_angle_diff:
                        angleDifference= temp_angle_diff

                if angleDifference < mostUniqueAngle:
                    # We have a new most different angle
                    mostUniqueIndex = fIdx
                    mostUniqueAngle = angleDifference

            if mostUniqueAngle < USER_PROJECTION_LIMIT_CONVERTED:
                #print 'adding', mostUniqueAngle, USER_PROJECTION_LIMIT, len(newProjectMeshFaces)
                # Now weight the vector to all its faces, will give a more direct projection
                # if the face its self was not representative of the normal from surrounding faces.

                newProjectVec = tempMeshFaces[mostUniqueIndex].no
                newProjectMeshFaces = [tempMeshFaces.pop(mostUniqueIndex)]


            else:
开发者ID:YasirArafath,项目名称:blender-git,代码行数:70,代码来源:uvcalc_smart_project.py


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