From 48c9da843c40ff8a97b462d8539185b662ba1567 Mon Sep 17 00:00:00 2001 From: Campbell Barton <ideasman42@gmail.com> Date: Mon, 25 Jul 2011 08:48:58 +0000 Subject: [PATCH] swap vector multiplication order, also some style changes --- io_export_pc2.py | 62 +++++++------ io_export_unreal_psk_psa.py | 49 +++++++--- io_import_images_as_planes.py | 80 ++++++++++------- io_mesh_raw/export_raw.py | 2 +- io_scene_map/export_map.py | 4 +- io_shape_mdd/export_mdd.py | 10 +-- light_field_tools/light_field_tools.py | 11 +-- mesh_bsurfaces.py | 34 +++---- mesh_looptools.py | 118 +++++++++++++------------ object_add_chain.py | 54 +++++++---- object_fracture/fracture_ops.py | 12 +-- object_grease_scatter.py | 6 +- render_povray/render.py | 4 +- space_view3d_math_vis/draw.py | 14 +-- space_view3d_panel_measure.py | 20 ++--- space_view3d_spacebar_menu.py | 2 +- 16 files changed, 276 insertions(+), 206 deletions(-) diff --git a/io_export_pc2.py b/io_export_pc2.py index f91706523..2ef701b1c 100644 --- a/io_export_pc2.py +++ b/io_export_pc2.py @@ -49,7 +49,7 @@ from bpy_extras.io_utils import ExportHelper def getSampling(start, end, sampling): samples = [start - sampling + x * sampling - for x in range(start, int((end-start)*1/sampling)+1)] + for x in range(start, int((end-start) * 1.0 / sampling) + 1)] return samples def do_export(context, props, filepath): @@ -113,40 +113,46 @@ class Export_pc2(bpy.types.Operator, ExportHelper): filename_ext = ".pc2" rot_x90 = BoolProperty(name="Convert to Y-up", - description="Rotate 90 degrees around X to convert to y-up", - default=True) + description="Rotate 90 degrees around X to convert to y-up", + default=True, + ) world_space = BoolProperty(name="Export into Worldspace", - description="Transform the Vertexcoordinates into Worldspace", - default=False) + description="Transform the Vertexcoordinates into Worldspace", + default=False, + ) apply_modifiers = BoolProperty(name="Apply Modifiers", - description="Applies the Modifiers", - default=True) + description="Applies the Modifiers", + default=True, + ) range_start = IntProperty(name='Start Frame', - description='First frame to use for Export', - default=1) + description='First frame to use for Export', + default=1, + ) range_end = IntProperty(name='End Frame', - description='Last frame to use for Export', - default=250) + description='Last frame to use for Export', + default=250, + ) sampling = EnumProperty(name='Sampling', - description='Sampling --> frames per sample (0.1 yields 10 samples per frame)', - items=[ - ('0.01', '0.01', ''), - ('0.05', '0.05', ''), - ('0.1', '0.1', ''), - ('0.2', '0.2', ''), - ('0.25', '0.25', ''), - ('0.5', '0.5', ''), - ('1', '1', ''), - ('2', '2', ''), - ('3', '3', ''), - ('4', '4', ''), - ('5', '5', ''), - ('10', '10', '')], - default='1') + description='Sampling --> frames per sample (0.1 yields 10 samples per frame)', + items=(('0.01', '0.01', ''), + ('0.05', '0.05', ''), + ('0.1', '0.1', ''), + ('0.2', '0.2', ''), + ('0.25', '0.25', ''), + ('0.5', '0.5', ''), + ('1', '1', ''), + ('2', '2', ''), + ('3', '3', ''), + ('4', '4', ''), + ('5', '5', ''), + ('10', '10', ''), + ), + default='1', + ) @classmethod def poll(cls, context): - return context.active_object.type in ['MESH', 'CURVE', 'SURFACE', 'FONT'] + return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'} def execute(self, context): start_time = time.time() @@ -176,7 +182,7 @@ class Export_pc2(bpy.types.Operator, ExportHelper): return {'RUNNING_MODAL'} elif False: # Redo popup - return wm.invoke_props_popup(self, event) # + return wm.invoke_props_popup(self, event) elif False: return self.execute(context) diff --git a/io_export_unreal_psk_psa.py b/io_export_unreal_psk_psa.py index 0e5d283ab..4363fc853 100644 --- a/io_export_unreal_psk_psa.py +++ b/io_export_unreal_psk_psa.py @@ -775,7 +775,7 @@ def parse_meshes(blender_meshes, psk_file): # Transform position for export #vpos = vert.co * object_material_index - vpos = vert.co * current_obj.matrix_local + vpos = current_obj.matrix_local * vert.co # Create the point p = VPoint() p.Point.X = vpos.x @@ -891,7 +891,7 @@ def parse_meshes(blender_meshes, psk_file): vert_weight = vgroup.weight if(obvgroup.index == vgroup.group): p = VPoint() - vpos = current_vert.co * current_obj.matrix_local + vpos = current_obj.matrix_local * current_vert.co p.Point.X = vpos.x p.Point.Y = vpos.y p.Point.Z = vpos.z @@ -968,14 +968,14 @@ def parse_bone(blender_bone, psk_file, psa_file, parent_id, is_root_bone, parent quat = make_fquat(quat_root.to_quaternion()) #print("DIR:",dir(child_parent.matrix.to_quaternion())) quat_parent = child_parent.matrix.to_quaternion().inverted() - parent_head = child_parent.head * quat_parent - parent_tail = child_parent.tail * quat_parent + parent_head = quat_parent * child_parent.head + parent_tail = quat_parent * child_parent.tail set_position = (parent_tail - parent_head) + blender_bone.head else: # ROOT BONE #This for root - set_position = blender_bone.head * parent_matrix #ARMATURE OBJECT Locction + set_position = parent_matrix * blender_bone.head #ARMATURE OBJECT Locction rot_mat = blender_bone.matrix * parent_matrix.to_3x3() #ARMATURE OBJECT Rotation #print(dir(rot_mat)) @@ -1894,13 +1894,36 @@ class ExportUDKAnimData(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - filepath = StringProperty(name="File Path", description="Filepath used for exporting the PSA file", maxlen= 1024, default= "", subtype='FILE_PATH') - filter_glob = StringProperty(default="*.psk;*.psa", options={'HIDDEN'}) - pskexportbool = BoolProperty(name="Export PSK", description="Export Skeletal Mesh", default= True) - psaexportbool = BoolProperty(name="Export PSA", description="Export Action Set (Animation Data)", default= True) - - actionexportall = BoolProperty(name="All Actions", description="This will export all the actions that matches the current armature.", default=False) - ignoreactioncountexportbool = BoolProperty(name="Ignore Action Group Count", description="It will ignore action group count but as long it matches the armature bone count to over ride the animation data.", default= False) + filepath = StringProperty( + name="File Path", + description="Filepath used for exporting the PSA file", + maxlen= 1024, + subtype='FILE_PATH', + ) + filter_glob = StringProperty( + default="*.psk;*.psa", + options={'HIDDEN'}, + ) + pskexportbool = BoolProperty( + name="Export PSK", + description="Export Skeletal Mesh", + default= True, + ) + psaexportbool = BoolProperty( + name="Export PSA", + description="Export Action Set (Animation Data)", + default= True, + ) + actionexportall = BoolProperty( + name="All Actions", + description="This will export all the actions that matches the current armature.", + default=False, + ) + ignoreactioncountexportbool = BoolProperty( + name="Ignore Action Group Count", + description="It will ignore action group count but as long it matches the armature bone count to over ride the animation data.", + default= False, + ) @classmethod def poll(cls, context): @@ -1927,7 +1950,7 @@ class ExportUDKAnimData(bpy.types.Operator): bpy.context.scene.unrealignoreactionmatchcount = True else: bpy.context.scene.unrealignoreactionmatchcount = False - + write_data(self.filepath, context) self.report({'WARNING', 'INFO'}, exportmessage) diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py index 4ede9e93d..4770ceb9f 100644 --- a/io_import_images_as_planes.py +++ b/io_import_images_as_planes.py @@ -232,18 +232,25 @@ class IMPORT_OT_image_to_plane(bpy.types.Operator, ImportHelper, AddObjectHelper bl_options = {'REGISTER', 'UNDO'} ## OPTIONS ## - all_in_directory = BoolProperty(name="All in directory", - description="Import all image files (of the selected type)" \ - " in this directory.", - default=False) - align = BoolProperty(name='Align Planes', - description='Create Planes in a row', - default=True) - align_offset = FloatProperty(name='Offset', - description='Space between Planes', - min=0, soft_min=0, - default=0.1) - extEnum = [ + all_in_directory = BoolProperty( + name="All in directory", + description=("Import all image files (of the selected type) " + "in this directory."), + default=False, + ) + align = BoolProperty( + name='Align Planes', + description='Create Planes in a row', + default=True, + ) + align_offset = FloatProperty( + name='Offset', + description='Space between Planes', + min=0, + soft_min=0, + default=0.1, + ) + extEnum = ( ('*', 'All image formats', 'Import all know image (or movie) formats.'), ('jpeg', 'JPEG (.jpg, .jpeg, .jpe)', @@ -260,35 +267,44 @@ class IMPORT_OT_image_to_plane(bpy.types.Operator, ImportHelper, AddObjectHelper ('bmp', 'BMP (.bmp, .dib)', 'Windows Bitmap'), ('cin', 'CIN (.cin)', ''), ('dpx', 'DPX (.dpx)', 'DPX (Digital Picture Exchange)'), - ('psd', 'PSD (.psd)', 'Photoshop Document')] - extension = EnumProperty(name="Extension", - description="Only import files of this type.", - items=extEnum) + ('psd', 'PSD (.psd)', 'Photoshop Document'), + ) + extension = EnumProperty( + name="Extension", + description="Only import files of this type.", + items=extEnum) use_dimension = BoolProperty(name="Use image dimensions", - description="Use the images pixels to derive the size of the plane.", - default=False) + description="Use the images pixels to derive the size of the plane.", + default=False) factor = IntProperty(name="Pixels/BU", - description="Number of pixels per Blenderunit.", - min=1, - default=500) + description="Number of pixels per Blenderunit.", + min=1, + default=500, + ) ## MATERIAL OPTIONS ## - use_shadeless = BoolProperty(name="Shadeless", - description="Set material to shadeless", - default=False) - use_transparency = BoolProperty(name="Use alpha", - description="Use alphachannel for transparency.", - default=False) - tEnum = [ + use_shadeless = BoolProperty( + name="Shadeless", + description="Set material to shadeless", + default=False, + ) + use_transparency = BoolProperty( + name="Use alpha", + description="Use alphachannel for transparency.", + default=False, + ) + tEnum = ( ('Z_TRANSPARENCY', 'Z Transparency', 'Use alpha buffer for transparent faces'), ('RAYTRACE', 'Raytrace', - 'Use raytracing for transparent refraction rendering.')] - transparency_method = EnumProperty(name="Transp. Method", - description="Transparency Method", - items=tEnum) + 'Use raytracing for transparent refraction rendering.')) + transparency_method = EnumProperty( + name="Transp. Method", + description="Transparency Method", + items=tEnum, + ) ## IMAGE OPTIONS ## use_premultiply = BoolProperty(name="Premultiply", diff --git a/io_mesh_raw/export_raw.py b/io_mesh_raw/export_raw.py index 6a332fd54..b44fbda26 100644 --- a/io_mesh_raw/export_raw.py +++ b/io_mesh_raw/export_raw.py @@ -52,7 +52,7 @@ def faceToTriangles(face): def faceValues(face, mesh, matrix): fv = [] for verti in face.vertices: - fv.append((mesh.vertices[verti].co * matrix)[:]) + fv.append((matrix * mesh.vertices[verti].co)[:]) return fv diff --git a/io_scene_map/export_map.py b/io_scene_map/export_map.py index b8f91ed4b..5373d21f2 100644 --- a/io_scene_map/export_map.py +++ b/io_scene_map/export_map.py @@ -402,10 +402,10 @@ NULL # add nmapping 0 0 ? if PREF_GRID_SNAP: file.write(" ( %d %d %d 0 0 )" % - round_vec(p.co.xyz * mat)) + round_vec(mat * p.co.xyz)) else: file.write(' ( %.6f %.6f %.6f 0 0 )' % - (p.co.xyz * mat)[:]) + (mat * p.co.xyz)[:]) # Move to next line if u_iter == u: diff --git a/io_shape_mdd/export_mdd.py b/io_shape_mdd/export_mdd.py index 2a8980cd1..9b0ad8b6d 100644 --- a/io_shape_mdd/export_mdd.py +++ b/io_shape_mdd/export_mdd.py @@ -70,11 +70,11 @@ def save(operator, context, filepath="", frame_start=1, frame_end=300, fps=25): me = obj.to_mesh(scene, True, 'PREVIEW') #Flip y and z - mat_flip = mathutils.Matrix(((1.0, 0.0, 0.0, 0.0), \ - (0.0, 0.0, 1.0, 0.0), \ - (0.0, 1.0, 0.0, 0.0), \ - (0.0, 0.0, 0.0, 1.0), \ - )) + mat_flip = mathutils.Matrix(((1.0, 0.0, 0.0, 0.0), + (0.0, 0.0, 1.0, 0.0), + (0.0, 1.0, 0.0, 0.0), + (0.0, 0.0, 0.0, 1.0), + )) numverts = len(me.vertices) diff --git a/light_field_tools/light_field_tools.py b/light_field_tools/light_field_tools.py index 3c2636e7a..7e84986bd 100644 --- a/light_field_tools/light_field_tools.py +++ b/light_field_tools/light_field_tools.py @@ -107,10 +107,11 @@ class OBJECT_OT_create_lightfield_rig(bpy.types.Operator): mesh = self.baseObject.data verts = [] row_length = scene.lightfield.row_length - + matrix = self.baseObject.matrix_local.copy() for vert in mesh.vertices: # world/parent origin - co = vert.co * self.baseObject.matrix_local + # ???, normal and co are in different spaces, sure you want this? + co = matrix * vert.co normal = vert.normal verts.append([co, normal]) @@ -311,15 +312,15 @@ class OBJECT_OT_create_lightfield_basemesh(bpy.types.Operator): def getWidth(self, obj): mat = obj.matrix_local mesh = obj.data - v0 = mesh.vertices[mesh.edges[0].vertices[0]].co * mat - v1 = mesh.vertices[mesh.edges[0].vertices[1]].co * mat + v0 = mat * mesh.vertices[mesh.edges[0].vertices[0]].co + v1 = mat * mesh.vertices[mesh.edges[0].vertices[1]].co return (v0-v1).length def getCamVec(self, obj, angle): width = self.getWidth(obj) itmat = obj.matrix_local.inverted().transposed() - normal = (obj.data.faces[0].normal * itmat).normalized() + normal = (itmat * obj.data.faces[0].normal.normalized() vl = (width/2) * (1/math.tan(math.radians(angle/2))) return normal*vl diff --git a/mesh_bsurfaces.py b/mesh_bsurfaces.py index 645138bc9..2bb0fc0ee 100644 --- a/mesh_bsurfaces.py +++ b/mesh_bsurfaces.py @@ -113,15 +113,15 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): #### Calculates length of a chain of points. def get_chain_length(self, object, verts_ordered): - matrix = object.matrix_world + matrix = object.matrix_world.copy() edges_lengths = [] edges_lengths_sum = 0 for i in range(0, len(verts_ordered)): if i == 0: - prev_v_co = verts_ordered[i].co * matrix + prev_v_co = matrix * verts_ordered[i].co else: - v_co = verts_ordered[i].co * matrix + v_co = matrix * verts_ordered[i].co v_difs = [prev_v_co[0] - v_co[0], prev_v_co[1] - v_co[1], prev_v_co[2] - v_co[2]] edge_length = abs(sqrt(v_difs[0] * v_difs[0] + v_difs[1] * v_difs[1] + v_difs[2] * v_difs[2])) @@ -334,11 +334,11 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): points_B = [] points_first_stroke_tips = [] - points_A.append(self.main_object.data.vertices[verts_tips_parsed_idx[0]].co * self.main_object.matrix_world) - points_A.append(self.main_object.data.vertices[middle_vertex_idx].co * self.main_object.matrix_world) + points_A.append(self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_parsed_idx[0]].co) + points_A.append(self.main_object.matrix_world * self.main_object.data.vertices[middle_vertex_idx].co) - points_B.append(self.main_object.data.vertices[verts_tips_parsed_idx[1]].co * self.main_object.matrix_world) - points_B.append(self.main_object.data.vertices[middle_vertex_idx].co * self.main_object.matrix_world) + points_B.append(self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_parsed_idx[1]].co) + points_B.append(self.main_object.matrix_world * self.main_object.data.vertices[middle_vertex_idx].co) points_first_stroke_tips.append(ob_gp_strokes.data.splines[0].bezier_points[0].co) points_first_stroke_tips.append(ob_gp_strokes.data.splines[0].bezier_points[len(ob_gp_strokes.data.splines[0].bezier_points) - 1].co) @@ -363,7 +363,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): prev_dist = 999999999999 for i in range(0, len(verts_tips_same_chain_idx)): for v_idx in range(0, len(verts_tips_same_chain_idx[i])): - dist = self.pts_distance(first_sketched_point_first_stroke_co, self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co * self.main_object.matrix_world) + dist = self.pts_distance(first_sketched_point_first_stroke_co, self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co) if dist < prev_dist: prev_dist = dist @@ -379,7 +379,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): prev_dist = 999999999999 for i in range(0, len(verts_tips_same_chain_idx)): for v_idx in range(0, len(verts_tips_same_chain_idx[i])): - dist = self.pts_distance(last_sketched_point_first_stroke_co, self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co * self.main_object.matrix_world) + dist = self.pts_distance(last_sketched_point_first_stroke_co, self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co) if dist < prev_dist: prev_dist = dist @@ -391,7 +391,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): prev_dist = 999999999999 for i in range(0, len(verts_tips_same_chain_idx)): for v_idx in range(0, len(verts_tips_same_chain_idx[i])): - dist = self.pts_distance(first_sketched_point_last_stroke_co, self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co * self.main_object.matrix_world) + dist = self.pts_distance(first_sketched_point_last_stroke_co, self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_same_chain_idx[i][v_idx]].co) if dist < prev_dist: prev_dist = dist @@ -405,7 +405,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): # Determine if the single selection will be treated as U or as V. edges_sum = 0 for i in all_selected_edges_idx: - edges_sum += self.pts_distance(self.main_object.data.vertices[self.main_object.data.edges[i].vertices[0]].co * self.main_object.matrix_world, self.main_object.data.vertices[self.main_object.data.edges[i].vertices[1]].co * self.main_object.matrix_world) + edges_sum += self.pts_distance(self.main_object.matrix_world * self.main_object.data.vertices[self.main_object.data.edges[i].vertices[0]].co, self.main_object.matrix_world * self.main_object.data.vertices[self.main_object.data.edges[i].vertices[1]].co) average_edge_length = edges_sum / len(all_selected_edges_idx) @@ -430,8 +430,8 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): selection_U_exists = True selection_V_exists = False - points_tips.append(self.main_object.data.vertices[verts_tips_same_chain_idx[nearest_tip_first_st_first_pt_idx][0]].co * self.main_object.matrix_world) - points_tips.append(self.main_object.data.vertices[verts_tips_same_chain_idx[nearest_tip_first_st_first_pt_idx][1]].co * self.main_object.matrix_world) + points_tips.append(self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_same_chain_idx[nearest_tip_first_st_first_pt_idx][0]].co) + points_tips.append(self.main_object.matrix_world * self.main_object.data.vertices[verts_tips_same_chain_idx[nearest_tip_first_st_first_pt_idx][1]].co) points_first_stroke_tips.append(ob_gp_strokes.data.splines[0].bezier_points[0].co) points_first_stroke_tips.append(ob_gp_strokes.data.splines[0].bezier_points[len(ob_gp_strokes.data.splines[0].bezier_points) - 1].co) @@ -565,7 +565,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): if selection_type == "TWO_NOT_CONNECTED": if selection_U2_exists: for i in range(0, len(sketched_splines_parsed[len(sketched_splines_parsed) - 1])): - sketched_splines_parsed[len(sketched_splines_parsed) - 1][i] = verts_ordered_U2[i].co * self.main_object.matrix_world + sketched_splines_parsed[len(sketched_splines_parsed) - 1][i] = self.main_object.matrix_world * verts_ordered_U2[i].co #### Create temporary curves along the "control-points" found on the sketched curves and the mesh selection. @@ -582,7 +582,7 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): if selection_U_exists: ob_ctrl_pts.data.vertices.add(1) last_v = ob_ctrl_pts.data.vertices[len(ob_ctrl_pts.data.vertices) - 1] - last_v.co = verts_ordered_U[i].co * self.main_object.matrix_world + last_v.co = self.main_object.matrix_world * verts_ordered_U[i].co vert_num_in_spline += 1 @@ -675,12 +675,12 @@ class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator): # Set the first and last verts of each spline to the locations of the respective verts in the selections. if selection_V_exists: for i in range(0, len(surface_splines_parsed[0])): - surface_splines_parsed[len(surface_splines_parsed) - 1][i] = verts_ordered_V[i].co * self.main_object.matrix_world + surface_splines_parsed[len(surface_splines_parsed) - 1][i] = self.main_object.matrix_world * verts_ordered_V[i].co if selection_type == "TWO_NOT_CONNECTED": if selection_V2_exists: for i in range(0, len(surface_splines_parsed[0])): - surface_splines_parsed[0][i] = verts_ordered_V2[i].co * self.main_object.matrix_world + surface_splines_parsed[0][i] = self.main_object.matrix_world * verts_ordered_V2[i].co #### Delete object with control points and object from grease pencil convertion. diff --git a/mesh_looptools.py b/mesh_looptools.py index 2a403dd31..7d385897c 100644 --- a/mesh_looptools.py +++ b/mesh_looptools.py @@ -206,7 +206,7 @@ def calculate_linear_splines(mesh_mod, tknots, knots): # calculate a best-fit plane to the given vertices def calculate_plane(mesh_mod, loop, method="best_fit", object=False): # getting the vertex locations - locs = [mathutils.Vector(mesh_mod.vertices[v].co[:]) for v in loop[0]] + locs = [mesh_mod.vertices[v].co.copy() for v in loop[0]] # calculating the center of masss com = mathutils.Vector() @@ -217,8 +217,10 @@ def calculate_plane(mesh_mod, loop, method="best_fit", object=False): if method == 'best_fit': # creating the covariance matrix - mat = mathutils.Matrix([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0]]) + mat = mathutils.Matrix(((0.0, 0.0, 0.0), + (0.0, 0.0, 0.0), + (0.0, 0.0, 0.0), + )) for loc in locs: mat[0][0] += (loc[0]-x)**2 mat[0][1] += (loc[0]-x)*(loc[1]-y) @@ -236,20 +238,20 @@ def calculate_plane(mesh_mod, loop, method="best_fit", object=False): mat.invert() except: if sum(mat[0]) == 0.0: - normal = mathutils.Vector([1.0, 0.0, 0.0]) + normal = mathutils.Vector((1.0, 0.0, 0.0)) elif sum(mat[1]) == 0.0: - normal = mathutils.Vector([0.0, 1.0, 0.0]) + normal = mathutils.Vector((0.0, 1.0, 0.0)) elif sum(mat[2]) == 0.0: - normal = mathutils.Vector([0.0, 0.0, 1.0]) + normal = mathutils.Vector((0.0, 0.0, 1.0)) if not normal: itermax = 500 iter = 0 - vec = mathutils.Vector([1.0, 1.0, 1.0]) - vec2 = (vec*mat)/(vec*mat).length + vec = mathutils.Vector((1.0, 1.0, 1.0)) + vec2 = (mat * vec)/(mat * vec).length while vec != vec2 and iter<itermax: iter += 1 vec = vec2 - vec2 = (vec*mat)/(vec*mat).length + vec2 = (mat * vec)/(mat * vec).length normal = vec2 elif method == 'normal': @@ -265,9 +267,10 @@ def calculate_plane(mesh_mod, loop, method="best_fit", object=False): # calculate view normal rotation = bpy.context.space_data.region_3d.view_matrix.to_3x3().\ inverted() - normal = mathutils.Vector([0.0, 0.0, 1.0]) * rotation + normal = rotation * mathutils.Vector((0.0, 0.0, 1.0)) if object: - normal *= object.matrix_world.inverted().to_euler().to_matrix() + normal = object.matrix_world.inverted().to_euler().to_matrix() * \ + normal return(com, normal) @@ -787,7 +790,7 @@ interpolation, cubic_strength, min_width, max_vert_index): y = ay+by*m+cy*m**2+dy*m**3 az,bz,cz,dz,tz = splines[line][2] z = az+bz*m+cz*m**2+dz*m**3 - return mathutils.Vector([x,y,z]) + return mathutils.Vector((x, y, z)) # no interpolation needed if segments == 1: @@ -810,9 +813,9 @@ interpolation, cubic_strength, min_width, max_vert_index): splines = False # create starting situation - virtual_width = [(mathutils.Vector(mesh.vertices[lines[i][0]].co) - \ - mathutils.Vector(mesh.vertices[lines[i+1][0]].co)).length for i \ - in range(len(lines)-1)] + virtual_width = [(mesh.vertices[lines[i][0]].co - + mesh.vertices[lines[i+1][0]].co).length for i + in range(len(lines)-1)] new_verts = [get_location(0, seg, splines) for seg in range(1, segments)] first_line_indices = [i for i in range(max_vert_index+1, @@ -880,7 +883,7 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): # calculate loop centers centers = [] for loop in [loop1, loop2]: - center = mathutils.Vector([0,0,0]) + center = mathutils.Vector() for vertex in loop: center += mesh.vertices[vertex].co center /= len(loop) @@ -889,7 +892,7 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): for vertex in loop: if mesh.vertices[vertex].co == centers[i]: # prevent zero-length vectors in angle comparisons - centers[i] += mathutils.Vector([0.01, 0, 0]) + centers[i] += mathutils.Vector((0.01, 0, 0)) break center1, center2 = centers @@ -898,8 +901,9 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): normal_plurity = False for i, loop in enumerate([loop1, loop2]): # covariance matrix - mat = mathutils.Matrix(((0.0, 0.0, 0.0), (0.0, 0.0, 0.0), - (0.0, 0.0, 0.0))) + mat = mathutils.Matrix(((0.0, 0.0, 0.0), + (0.0, 0.0, 0.0), + (0.0, 0.0, 0.0))) x, y, z = centers[i] for loc in [mesh.vertices[vertex].co for vertex in loop]: mat[0][0] += (loc[0]-x)**2 @@ -919,20 +923,20 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): mat.invert() except: if sum(mat[0]) == 0: - normal = mathutils.Vector([1.0, 0.0, 0.0]) + normal = mathutils.Vector((1.0, 0.0, 0.0)) elif sum(mat[1]) == 0: - normal = mathutils.Vector([0.0, 1.0, 0.0]) + normal = mathutils.Vector((0.0, 1.0, 0.0)) elif sum(mat[2]) == 0: - normal = mathutils.Vector([0.0, 0.0, 1.0]) + normal = mathutils.Vector((0.0, 0.0, 1.0)) if not normal: itermax = 500 iter = 0 - vec = mathutils.Vector([1.0, 1.0, 1.0]) - vec2 = (vec*mat)/(vec*mat).length + vec = mathutils.Vector((1.0, 1.0, 1.0)) + vec2 = (mat * vec)/(mat * vec).length while vec != vec2 and iter<itermax: iter+=1 vec = vec2 - vec2 = (vec*mat)/(vec*mat).length + vec2 = (mat * vec)/(mat * vec).length normal = vec2 normals.append(normal) # have plane normals face in the same direction (maximum angle: 90 degrees) @@ -946,7 +950,7 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): # rotation matrix, representing the difference between the plane normals axis = normals[0].cross(normals[1]) axis = mathutils.Vector([loc if abs(loc) > 1e-8 else 0 for loc in axis]) - if axis.angle(mathutils.Vector([0, 0, 1]), 0) > 1.5707964: + if axis.angle(mathutils.Vector((0, 0, 1)), 0) > 1.5707964: axis.negate() angle = normals[0].dot(normals[1]) rotation_matrix = mathutils.Matrix.Rotation(angle, 4, axis) @@ -960,9 +964,9 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): # match start vertex of loop1 with loop2 target_vector = mesh.vertices[loop2[0]].co - center2 - dif_angles = [[((mesh.vertices[vertex].co - center1) * \ - rotation_matrix).angle(target_vector, 0), False, i] for \ - i, vertex in enumerate(loop1)] + dif_angles = [[(rotation_matrix * (mesh.vertices[vertex].co - center1) + ).angle(target_vector, 0), False, i] for + i, vertex in enumerate(loop1)] dif_angles.sort() if len(loop1) != len(loop2): angle_limit = dif_angles[0][0] * 1.2 # 20% margin @@ -1036,8 +1040,8 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): if len(loop1) - shifting < len(loop2): shifting = False break - to_last, to_first = [((mesh.vertices[loop1[-1]].co - \ - center1) * rotation_matrix).angle((mesh.\ + to_last, to_first = [(rotation_matrix * + (mesh.vertices[loop1[-1]].co - center1)).angle((mesh.\ vertices[loop2[i]].co - center2), 0) for i in [-1, 0]] if to_first < to_last: loop1 = [loop1[-1]] + loop1[:-1] @@ -1067,9 +1071,10 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): tri, quad = 0, 1 elif prev_vert2 == len(loop2) - 1 and loop2_circular: # at end of loop2, but circular, so check with first vert - tri, quad = [(mathutils.Vector(mesh.vertices[loop1[i+1]].\ - co) - mathutils.Vector(mesh.vertices[loop2[j]].co)).\ - length for j in [prev_vert2, 0]] + tri, quad = [(mesh.vertices[loop1[i+1]].co - + mesh.vertices[loop2[j]].co).length + for j in [prev_vert2, 0]] + circle_full = 2 elif len(loop1) - 1 - i == len(loop2) - 1 - prev_vert2 and \ not circle_full: @@ -1077,9 +1082,9 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse): tri, quad = 1, 0 else: # calculate if tri or quad gives shortest edge - tri, quad = [(mathutils.Vector(mesh.vertices[loop1[i+1]].\ - co) - mathutils.Vector(mesh.vertices[loop2[j]].co)).\ - length for j in range(prev_vert2, prev_vert2+2)] + tri, quad = [(mesh.vertices[loop1[i+1]].co - + mesh.vertices[loop2[j]].co).length + for j in range(prev_vert2, prev_vert2+2)] # triangle if tri < quad: @@ -1138,7 +1143,7 @@ edgekey_to_edge): for key, vectors in dic.items(): #if type(vectors) == type([]) and len(vectors) > 1: if len(vectors) > 1: - average = mathutils.Vector([0, 0, 0]) + average = mathutils.Vector() for vector in vectors: average += vector average /= len(vectors) @@ -1176,8 +1181,8 @@ edgekey_to_edge): # average face coordinates, if connected to more than 1 valid face if len(faces) > 1: - face_normal = mathutils.Vector([0, 0, 0]) - face_center = mathutils.Vector([0, 0, 0]) + face_normal = mathutils.Vector() + face_center = mathutils.Vector() for face in faces: face_normal += face.normal face_center += face.center @@ -1248,19 +1253,19 @@ edgekey_to_edge): for vertex, values in edge_vectors.items(): # vertex normal doesn't matter, just assign a random vector to it if not connection_vectors[vertex]: - vertex_normals[vertex] = [mathutils.Vector([1, 0, 0])] + vertex_normals[vertex] = [mathutils.Vector((1, 0, 0))] continue # calculate to what location the vertex is connected, # used to determine what way to flip the normal - connected_center = mathutils.Vector([0, 0, 0]) + connected_center = mathutils.Vector() for v in connections[vertex]: connected_center += mesh.vertices[v].co if len(connections[vertex]) > 1: connected_center /= len(connections[vertex]) if len(connections[vertex]) == 0: # shouldn't be possible, but better safe than sorry - vertex_normals[vertex] = [mathutils.Vector([1, 0, 0])] + vertex_normals[vertex] = [mathutils.Vector((1, 0, 0))] continue # can't do proper calculations, because of zero-length vector @@ -1402,8 +1407,8 @@ def bridge_match_loops(mesh, loops): normals = [] centers = [] for vertices, circular in loops: - normal = mathutils.Vector([0, 0, 0]) - center = mathutils.Vector([0, 0, 0]) + normal = mathutils.Vector() + center = mathutils.Vector() for vertex in vertices: normal += mesh.vertices[vertex].normal center += mesh.vertices[vertex].co @@ -1563,7 +1568,7 @@ def bridge_sort_loops(mesh, loops, loft_loop): # simplify loops to single points, and prepare for pathfinding x, y, z = [[sum([mesh.vertices[i].co[j] for i in loop[0]]) / \ len(loop[0]) for loop in loops] for j in range(3)] - nodes = [mathutils.Vector([x[i], y[i], z[i]]) for i in range(len(loops))] + nodes = [mathutils.Vector((x[i], y[i], z[i])) for i in range(len(loops))] active_node = 0 open = [i for i in range(1, len(loops))] @@ -1599,15 +1604,14 @@ def bridge_sort_loops(mesh, loops, loft_loop): def circle_3d_to_2d(mesh_mod, loop, com, normal): # project vertices onto the plane verts = [mesh_mod.vertices[v] for v in loop[0]] - verts_projected = [[mathutils.Vector(v.co[:]) - \ - (mathutils.Vector(v.co[:])-com).dot(normal)*normal, v.index] \ - for v in verts] - + verts_projected = [[v.co - (v.co - com).dot(normal) * normal, v.index] + for v in verts] + # calculate two vectors (p and q) along the plane - m = mathutils.Vector([normal[0]+1.0, normal[1], normal[2]]) + m = mathutils.Vector((normal[0] + 1.0, normal[1], normal[2])) p = m - (m.dot(normal) * normal) if p.dot(p) == 0.0: - m = mathutils.Vector([normal[0], normal[1]+1.0, normal[2]]) + m = mathutils.Vector((normal[0], normal[1] + 1.0, normal[2])) p = m - (m.dot(normal) * normal) q = p.cross(normal) @@ -1637,9 +1641,11 @@ def circle_calculate_best_fit(locs_2d): d = (v[0]**2-2.0*x0*v[0]+v[1]**2-2.0*y0*v[1]+x0**2+y0**2)**0.5 jmat.append([(x0-v[0])/d, (y0-v[1])/d, -1.0]) k.append(-(((v[0]-x0)**2+(v[1]-y0)**2)**0.5-r)) - jmat2 = mathutils.Matrix([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], \ - [0.0, 0.0, 0.0]]) - k2 = mathutils.Vector([0.0, 0.0, 0.0]) + jmat2 = mathutils.Matrix(((0.0, 0.0, 0.0), + (0.0, 0.0, 0.0), + (0.0, 0.0, 0.0), + )) + k2 = mathutils.Vector((0.0, 0.0, 0.0)) for i in range(len(jmat)): k2 += mathutils.Vector(jmat[i])*k[i] jmat2[0][0] += jmat[i][0]**2 @@ -1655,7 +1661,7 @@ def circle_calculate_best_fit(locs_2d): jmat2.invert() except: pass - dx0, dy0, dr = k2 * jmat2 + dx0, dy0, dr = jmat2 * k2 x0 += dx0 y0 += dy0 r += dr diff --git a/object_add_chain.py b/object_add_chain.py index a173af273..c257b2060 100644 --- a/object_add_chain.py +++ b/object_add_chain.py @@ -37,8 +37,12 @@ def Add_Chain(): ##Adds Empty to scene - bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=(0, 0, 0), -rotation=(0, 0, 0),) + bpy.ops.object.add(type='EMPTY', + view_align=False, + enter_editmode=False, + location=(0, 0, 0), + rotation=(0, 0, 0), + ) ##Changes name of Empty to rot_link adds variable emp emp = bpy.context.object @@ -48,22 +52,31 @@ rotation=(0, 0, 0),) emp.rotation_euler = [1.570796, 0, 0] ##Adds Curve Path to scene - bpy.ops.curve.primitive_nurbs_path_add( view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0),) + bpy.ops.curve.primitive_nurbs_path_add(view_align=False, + enter_editmode=False, + location=(0, 0, 0), + rotation=(0, 0, 0), + ) ##Change Curve name to deform adds variable curv curv = bpy.context.object curv.name = "deform" ##Inserts Torus primitive - bpy.ops.mesh.primitive_torus_add( - major_radius=1, minor_radius=0.25, major_segments=12, minor_segments=4, - use_abso=False, abso_major_rad=1, abso_minor_rad=0.5) + bpy.ops.mesh.primitive_torus_add(major_radius=1, + minor_radius=0.25, + major_segments=12, + minor_segments=4, + use_abso=False, + abso_major_rad=1, + abso_minor_rad=0.5, + ) ##Positions Torus primitive to center of scene - bpy.context.active_object.location = [0, 0, 0] + bpy.context.active_object.location = 0.0, 0.0, 0.0 ##Reseting Torus rotation in case of 'Align to view' option enabled - bpy.context.active_object.rotation_euler = [0, 0, 0] + bpy.context.active_object.rotation_euler = 0.0, 0.0, 0.0 ##Changes Torus name to chain adds variable tor @@ -86,13 +99,22 @@ rotation=(0, 0, 0),) ##Toggle into editmode bpy.ops.object.editmode_toggle() + ## TODO, may be better to move objects directly. ##Translate curve object - bpy.ops.transform.translate( - value=(2, 0, 0), constraint_axis=(True, 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) + bpy.ops.transform.translate(value=(2, 0, 0), + constraint_axis=(True, 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, + ) ##Toggle into objectmode bpy.ops.object.editmode_toggle() @@ -104,11 +126,11 @@ rotation=(0, 0, 0),) array = tor.modifiers['Array'] ##Change Array Modifier Parameters - array.fit_type = ('FIT_CURVE') + array.fit_type = 'FIT_CURVE' array.curve = curv array.offset_object = emp array.use_object_offset = True - array.relative_offset_displace = [ 0.549, 0, 0 ] + array.relative_offset_displace = 0.549, 0.0, 0.0 ##Add curve modifier bpy.ops.object.modifier_add(type='CURVE') diff --git a/object_fracture/fracture_ops.py b/object_fracture/fracture_ops.py index 69fd49daf..f5de1d972 100644 --- a/object_fracture/fracture_ops.py +++ b/object_fracture/fracture_ops.py @@ -38,10 +38,8 @@ def create_cutter(context, crack_type, scale, roughness): False, False, False, False)) for v in context.scene.objects.active.data.vertices: - v.co[0] += 1 - v.co[0] *= scale - v.co[1] *= scale - v.co[2] *= scale + v.co[0] += 1.0 + v.co *= scale bpy.ops.object.editmode_toggle() bpy.ops.mesh.faces_shade_smooth() @@ -76,10 +74,8 @@ def create_cutter(context, crack_type, scale, roughness): bpy.ops.object.editmode_toggle() for v in context.scene.objects.active.data.vertices: - v.co[0] += 1 - v.co[0] *= scale - v.co[1] *= scale - v.co[2] *= scale + v.co[0] += 1.0 + v.co *= scale if crack_type == 'SPHERE_ROUGH': for v in context.scene.objects.active.data.vertices: diff --git a/object_grease_scatter.py b/object_grease_scatter.py index 2557f043a..139ca7a8e 100644 --- a/object_grease_scatter.py +++ b/object_grease_scatter.py @@ -182,7 +182,7 @@ def _main(self, DENSITY=1.0, SCALE=0.6, RAND_LOC=0.8, RAND_ALIGN=0.75): m_alt_2 = Matrix.Rotation(radians(-22.5), 3, n) for _m in mats: for m in (_m, m_alt_1 * _m, m_alt_2 * _m): - hit, nor, ind = ray(pofs, pofs + (n_seek * m)) + hit, nor, ind = ray(pofs, pofs + (m * n_seek)) if ind != -1: dist = (pofs - hit).length if dist < best_dist: @@ -320,13 +320,13 @@ def _main(self, DENSITY=1.0, SCALE=0.6, RAND_LOC=0.8, RAND_ALIGN=0.75): # make 2 angles and blend angle = radians(uniform(-180, 180.0)) - angle_aligned = -(ori.angle(Vector((0.0, 1.0, 0.0)) * quat, radians(180.0))) + angle_aligned = -(ori.angle(quat * Vector((0.0, 1.0, 0.0)), radians(180.0))) quat = Quaternion(no, (angle * (1.0 - RAND_ALIGN)) + (angle_aligned * RAND_ALIGN)).cross(quat) f = uniform(0.1, 1.2) * SCALE - coords.append([co + ((tri[0] * f) * quat), co + ((tri[1] * f) * quat), co + ((tri[2] * f) * quat)]) + coords.append([co + (quat * (tri[0] * f)), co + (quat * (tri[1] * f)), co + (quat * (tri[2] * f))]) # face_ind.append([i*3, i*3+1, i*3+2]) apply_faces(coords) diff --git a/render_povray/render.py b/render_povray/render.py index f651a6fb6..6cdc21937 100644 --- a/render_povray/render.py +++ b/render_povray/render.py @@ -430,9 +430,9 @@ def write_pov(filename, scene=None, info_callback=None): #Could use brilliance 2(or varying around 2 depending on ior or factor) too. elif material.specular_shader == 'TOON': - tabWrite("phong %.3g\n" % (material.specular_intensity * 2)) + tabWrite("phong %.3g\n" % (material.specular_intensity * 2.0)) # use extreme phong_size - tabWrite("phong_size %.3g\n" % (0.1 + material.specular_toon_smooth / 2)) + tabWrite("phong_size %.3g\n" % (0.1 + material.specular_toon_smooth / 2.0)) elif material.specular_shader == 'WARDISO': # find best suited default constant for brilliance Use both phong and diff --git a/space_view3d_math_vis/draw.py b/space_view3d_math_vis/draw.py index 9d3b436e8..dd544d38c 100644 --- a/space_view3d_math_vis/draw.py +++ b/space_view3d_math_vis/draw.py @@ -110,7 +110,7 @@ def draw_callback_view(self, context): bb = [Vector() for i in range(8)] def draw_matrix(mat): - zero_tx = zero * mat + zero_tx = mat * zero glLineWidth(2.0) @@ -118,39 +118,39 @@ def draw_callback_view(self, context): glColor3f(1.0, 0.2, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(x_p * mat)) + glVertex3f(*(mat * x_p)) glEnd() glColor3f(0.6, 0.0, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(x_n * mat)) + glVertex3f(*(mat * x_n)) glEnd() # y glColor3f(0.2, 1.0, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(y_p * mat)) + glVertex3f(*(mat * y_p)) glEnd() glColor3f(0.0, 0.6, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(y_n * mat)) + glVertex3f(*(mat * y_n)) glEnd() # z glColor3f(0.2, 0.2, 1.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(z_p * mat)) + glVertex3f(*(mat * z_p)) glEnd() glColor3f(0.0, 0.0, 0.6) glBegin(GL_LINES) glVertex3f(*(zero_tx)) - glVertex3f(*(z_n * mat)) + glVertex3f(*(mat * z_n)) glEnd() # bounding box diff --git a/space_view3d_panel_measure.py b/space_view3d_panel_measure.py index 6bf8d6ba2..69a449a94 100644 --- a/space_view3d_panel_measure.py +++ b/space_view3d_panel_measure.py @@ -269,7 +269,7 @@ def getMeasurePoints(context): return (p1, p2, COLOR_LOCAL) else: - p1 = vert_loc * obj.matrix_world + p1 = obj.matrix_world * vert_loc p2 = cur_loc return (p1, p2, COLOR_GLOBAL) @@ -288,8 +288,8 @@ def getMeasurePoints(context): return (p1, p2, COLOR_LOCAL) else: - p1 = vert1_loc * obj.matrix_world - p2 = vert2_loc * obj.matrix_world + p1 = obj.matrix_world * vert1_loc + p2 = obj.matrix_world * vert2_loc return (p1, p2, COLOR_GLOBAL) else: @@ -350,10 +350,10 @@ def faceAreaGlobal(face, obj): v4 = obj.data.vertices[v4] # Apply transform matrix to vertex coordinates. - v1 = v1.co * mat - v2 = v2.co * mat - v3 = v3.co * mat - v4 = v4.co * mat + v1 = mat * v1.co + v2 = mat * v2.co + v3 = mat * v3.co + v4 = mat * v4.co vec1 = v2 - v1 vec2 = v4 - v1 @@ -381,9 +381,9 @@ def faceAreaGlobal(face, obj): v3 = obj.data.vertices[v3] # Apply transform matrix to vertex coordinates. - v1 = v1.co * mat - v2 = v2.co * mat - v3 = v3.co * mat + v1 = mat * v1.co + v2 = mat * v2.co + v3 = mat * v3.co vec1 = v3 - v2 vec2 = v1 - v2 diff --git a/space_view3d_spacebar_menu.py b/space_view3d_spacebar_menu.py index c4ba950e5..24082cd34 100644 --- a/space_view3d_spacebar_menu.py +++ b/space_view3d_spacebar_menu.py @@ -1478,7 +1478,7 @@ def edgeIntersect(context, operator): return point = line[0].lerp(line[1], 0.5) - context.scene.cursor_location = point * obj.matrix_world + context.scene.cursor_location = obj.matrix_world * point class VIEW3D_OT_CursorToEdgeIntersection(bpy.types.Operator): "Finds the mid-point of the shortest distance between two edges" -- GitLab