Python mathutils.Matrix.Translation() Examples
The following are 30
code examples of mathutils.Matrix.Translation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mathutils.Matrix
, or try the search function
.
Example #1
Source File: archipack_cutter.py From archipack with GNU General Public License v3.0 | 6 votes |
def from_spline(self, context, wM, resolution, spline): pts = self.coords_from_spline( spline, wM, resolution, ccw=(self.operation == 'INTERSECTION'), cw=(self.operation != 'INTERSECTION'), close=True ) # pretranslate o = self.find_in_selection(context, self.auto_update) o.matrix_world = Matrix.Translation(pts[0].copy()) self.auto_update = False self.from_points(pts) self.auto_update = True self.update_parent(context, o)
Example #2
Source File: gltf2_blender_extract.py From glTF-Blender-IO with Apache License 2.0 | 6 votes |
def convert_swizzle_normal(loc, armature, blender_object, export_settings): """Convert a normal data from Blender coordinate system to glTF coordinate system.""" if (not armature) or (not blender_object): # Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents if export_settings[gltf2_blender_export_keys.YUP]: return Vector((loc[0], loc[2], -loc[1])) else: return Vector((loc[0], loc[1], loc[2])) else: # Mesh is skined, we have to apply armature transforms on data apply_matrix = (armature.matrix_world.inverted() @ blender_object.matrix_world).to_3x3().inverted() apply_matrix.transpose() new_loc = ((armature.matrix_world.to_3x3() @ apply_matrix).to_4x4() @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation() new_loc.normalize() if export_settings[gltf2_blender_export_keys.YUP]: return Vector((new_loc[0], new_loc[2], -new_loc[1])) else: return Vector((new_loc[0], new_loc[1], new_loc[2]))
Example #3
Source File: gltf2_blender_extract.py From glTF-Blender-IO with Apache License 2.0 | 6 votes |
def convert_swizzle_location(loc, armature, blender_object, export_settings): """Convert a location from Blender coordinate system to glTF coordinate system.""" if (not armature) or (not blender_object): # Classic case. Mesh is not skined, no need to apply armature transfoms on vertices / normals / tangents if export_settings[gltf2_blender_export_keys.YUP]: return Vector((loc[0], loc[2], -loc[1])) else: return Vector((loc[0], loc[1], loc[2])) else: # Mesh is skined, we have to apply armature transforms on data apply_matrix = armature.matrix_world.inverted() @ blender_object.matrix_world new_loc = (armature.matrix_world @ apply_matrix @ Matrix.Translation(Vector((loc[0], loc[1], loc[2])))).to_translation() if export_settings[gltf2_blender_export_keys.YUP]: return Vector((new_loc[0], new_loc[2], -new_loc[1])) else: return Vector((new_loc[0], new_loc[1], new_loc[2]))
Example #4
Source File: import_svg.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _doCreateGeom(self, instancing): """ Create real geometries """ rect = SVGRectFromNode(self._node, self._context) self._pushRect(rect) matrix = self.getNodeMatrix() # Better Inkscape compatibility: match document origin with # 3D space origin. if self._node.getAttribute('inkscape:version'): raw_height = self._node.getAttribute('height') document_height = SVGParseCoord(raw_height, 1.0) matrix = matrix * Matrix.Translation([0.0, -document_height , 0.0]) self._pushMatrix(matrix) super()._doCreateGeom(False) self._popRect() self._popMatrix()
Example #5
Source File: import_svg.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def SVGTransformRotate(params): """ skewX SVG transform command """ ang = float(params[0]) * pi / 180.0 cx = cy = 0.0 if len(params) >= 3: cx = float(params[1]) cy = float(params[2]) tm = Matrix.Translation(Vector((cx, cy, 0.0))) rm = Matrix.Rotation(ang, 4, Vector((0.0, 0.0, 1.0))) return tm * rm * tm.inverted()
Example #6
Source File: model.py From BlenderTools with GNU General Public License v2.0 | 6 votes |
def draw_model_box(mat, scs_globals): """ Draw Cube for Model locator. :param mat: :param scs_globals: :return: """ mat1 = mat @ (Matrix.Translation((0.0, 0.0, 0.0)) @ Matrix.Scale(scs_globals.locator_size / 5, 4, (1.0, 0.0, 0.0)) @ Matrix.Scale(scs_globals.locator_size / 5, 4, (0.0, 1.0, 0.0)) @ Matrix.Scale(scs_globals.locator_size / 5, 4, (0.0, 0.0, 1.0))) cube_vertices, cube_faces, cube_wire_lines = _primitive.get_box_data() _primitive.draw_polygon_object(mat1, cube_vertices, cube_faces, scs_globals.locator_coll_face_color, False, True, wire_lines=cube_wire_lines, wire_color=scs_globals.locator_model_wire_color)
Example #7
Source File: floorplan_types.py From building_tools with MIT License | 6 votes |
def random_scale_and_translate(bm, middle_edge): """scale and translate an edge randomly along its axis """ verts = list(middle_edge.verts) length = middle_edge.calc_length() median = calc_edge_median(middle_edge) axis = Vector((1, 0, 0)) if verts[0].co.y == verts[1].co.y else Vector((0, 1, 0)) scale_factor = clamp(random.random() * 3, 1, 2.95) bmesh.ops.scale( bm, verts=verts, vec=axis * scale_factor, space=Matrix.Translation(-median) ) if random.choice([0, 1]): rand_offset = random.random() * length bmesh.ops.translate(bm, verts=verts, vec=axis * rand_offset)
Example #8
Source File: import_x3d.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def importViewpoint(bpyscene, node, ancestry, global_matrix): name = node.getDefName() if not name: name = 'Viewpoint' fieldOfView = node.getFieldAsFloat('fieldOfView', 0.785398, ancestry) # max is documented to be 1.0 but some files have higher. # jump = node.getFieldAsBool('jump', True, ancestry) orientation = node.getFieldAsFloatTuple('orientation', (0.0, 0.0, 1.0, 0.0), ancestry) position = node.getFieldAsFloatTuple('position', (0.0, 0.0, 0.0), ancestry) description = node.getFieldAsString('description', '', ancestry) bpycam = bpy.data.cameras.new(name) bpycam.angle = fieldOfView mtx = Matrix.Translation(Vector(position)) * translateRotation(orientation) bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, bpycam) bpyscene.objects.link(bpyob).select = True bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix)
Example #9
Source File: import_x3d.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def importLamp_PointLight(node, ancestry): vrmlname = node.getDefName() if not vrmlname: vrmlname = 'PointLight' # ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0, ancestry) # TODO # attenuation = node.getFieldAsFloatTuple('attenuation', (1.0, 0.0, 0.0), ancestry) # TODO color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry) # is_on = node.getFieldAsBool('on', True, ancestry) # TODO radius = node.getFieldAsFloat('radius', 100.0, ancestry) bpylamp = bpy.data.lamps.new(vrmlname, 'POINT') bpylamp.energy = intensity bpylamp.distance = radius bpylamp.color = color mtx = Matrix.Translation(Vector(location)) return bpylamp, mtx
Example #10
Source File: clip.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _findOrCreateCamera(context): scene = context.scene if scene.camera: return scene.camera cam = bpy.data.cameras.new(name="Camera") camob = bpy.data.objects.new(name="Camera", object_data=cam) scene.objects.link(camob) scene.camera = camob camob.matrix_local = (Matrix.Translation((7.481, -6.508, 5.344)) * Matrix.Rotation(0.815, 4, 'Z') * Matrix.Rotation(0.011, 4, 'Y') * Matrix.Rotation(1.109, 4, 'X')) return camob
Example #11
Source File: mesh.py From jewelcraft with GNU General Public License v3.0 | 6 votes |
def face_pos(): depsgraph = bpy.context.evaluated_depsgraph_get() mats = [] for ob in bpy.context.objects_in_mode: ob.update_from_editmode() depsgraph.update() ob_eval = ob.evaluated_get(depsgraph) me = ob_eval.to_mesh() me.transform(ob.matrix_world) for poly in me.polygons: if poly.select: mat_loc = Matrix.Translation(poly.center) mat_rot = poly.normal.to_track_quat("Z", "Y").to_matrix().to_4x4() mat = mat_loc @ mat_rot mats.append(mat) ob_eval.to_mesh_clear() return mats
Example #12
Source File: transform.py From object_alignment with GNU General Public License v3.0 | 5 votes |
def apply_transform(obj:Object, location:bool=True, rotation:bool=True, scale:bool=True): """ apply object transformation to mesh """ loc, rot, scale = obj.matrix_world.decompose() obj.matrix_world = Matrix.Identity(4) m = obj.data s_mat_x = Matrix.Scale(scale.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(scale.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(scale.z, 4, Vector((0, 0, 1))) if scale: m.transform(mathutils_mult(s_mat_x, s_mat_y, s_mat_z)) else: obj.scale = scale if rotation: m.transform(rot.to_matrix().to_4x4()) else: obj.rotation_euler = rot.to_euler() if location: m.transform(Matrix.Translation(loc)) else: obj.location = loc
Example #13
Source File: CameraModule.py From BlenderProc with GNU General Public License v3.0 | 5 votes |
def _cam2world_matrix_from_cam_extrinsics(self, config): """ Determines camera extrinsics by using the given config and returns them in form of a cam to world frame transformation matrix. :param config: The configuration object. :return: The cam to world transformation matrix. """ if not config.has_param("cam2world_matrix"): position = Utility.transform_point_to_blender_coord_frame(config.get_vector3d("location", [0, 0, 0]), self.source_frame) # Rotation rotation_format = config.get_string("rotation/format", "euler") value = config.get_vector3d("rotation/value", [0, 0, 0]) if rotation_format == "euler": # Rotation, specified as euler angles rotation_euler = Utility.transform_point_to_blender_coord_frame(value, self.source_frame) elif rotation_format == "forward_vec": # Rotation, specified as forward vector forward_vec = Vector(Utility.transform_point_to_blender_coord_frame(value, self.source_frame)) # Convert forward vector to euler angle (Assume Up = Z) rotation_euler = forward_vec.to_track_quat('-Z', 'Y').to_euler() elif rotation_format == "look_at": # Compute forward vector forward_vec = value - position forward_vec.normalize() # Convert forward vector to euler angle (Assume Up = Z) rotation_euler = forward_vec.to_track_quat('-Z', 'Y').to_euler() else: raise Exception("No such rotation format:" + str(rotation_format)) rotation_matrix = Euler(rotation_euler, 'XYZ').to_matrix() if rotation_format == "look_at" or rotation_format == "forward_vec": inplane_rot = config.get_float("rotation/inplane_rot", 0.0) rotation_matrix = rotation_matrix @ Euler((0.0, 0.0, inplane_rot)).to_matrix() cam2world_matrix = Matrix.Translation(Vector(position)) @ rotation_matrix.to_4x4() else: cam2world_matrix = Matrix(np.array(config.get_list("cam2world_matrix")).reshape(4, 4).astype(np.float32)) return cam2world_matrix
Example #14
Source File: object_drop.py From BlenderGIS with GNU General Public License v3.0 | 5 votes |
def get_align_matrix(location, normal): up = Vector((0, 0, 1)) angle = normal.angle(up) axis = up.cross(normal) mat_rot = Matrix.Rotation(angle, 4, axis) mat_loc = Matrix.Translation(location) mat_align = mat_rot @ mat_loc return mat_align
Example #15
Source File: utils.py From se-blender with GNU General Public License v2.0 | 5 votes |
def trans(vector): return Matrix.Translation(vector)
Example #16
Source File: utils.py From se-blender with GNU General Public License v2.0 | 5 votes |
def transX(x): return Matrix.Translation((x, 0, 0))
Example #17
Source File: mapping3d.py From BlendLuxCore with GNU General Public License v3.0 | 5 votes |
def export(self, exporter, depsgraph, props, luxcore_name=None, output_socket=None): mapping_type, uvindex, input_mapping = self.inputs["3D Mapping (optional)"].export(exporter, depsgraph, props) # Use the mapping type of this node only when mapping type is not # already set by previous mapping node if not self.inputs["3D Mapping (optional)"].is_linked: mapping_type = self.mapping_type uvindex = self.uvindex # create a location matrix tex_loc = Matrix.Translation(self.translate) # create an identity matrix tex_sca = Matrix() tex_sca[0][0] = self.uniform_scale if self.use_uniform_scale else self.scale[0] # X tex_sca[1][1] = self.uniform_scale if self.use_uniform_scale else self.scale[1] # Y tex_sca[2][2] = self.uniform_scale if self.use_uniform_scale else self.scale[2] # Z # Prevent "singular matrix in matrixinvert" error (happens if a scale axis equals 0) for i in range(3): if tex_sca[i][i] == 0: tex_sca[i][i] = 0.0000000001 # create a rotation matrix tex_rot0 = Matrix.Rotation(self.rotate[0], 4, "X") tex_rot1 = Matrix.Rotation(self.rotate[1], 4, "Y") tex_rot2 = Matrix.Rotation(self.rotate[2], 4, "Z") tex_rot = tex_rot0 @ tex_rot1 @ tex_rot2 # combine transformations transformation = tex_loc @ tex_rot @ tex_sca # Transform input matrix output_mapping = input_mapping @ transformation return mapping_type, uvindex, output_mapping
Example #18
Source File: BopWriter.py From BlenderProc with GNU General Public License v3.0 | 5 votes |
def _get_frame_gt(self): """ Returns GT annotations for the active camera. :return: A list of GT annotations. """ camera_rotation = self._get_camera_attribute(self.cam_pose, 'rotation_euler') camera_translation = self._get_camera_attribute(self.cam_pose, 'location') H_c2w = Matrix.Translation(Vector(camera_translation)) @ Euler( camera_rotation, 'XYZ').to_matrix().to_4x4() # Blender to opencv coordinates. H_c2w_opencv = H_c2w @ Matrix.Rotation(math.radians(-180), 4, "X") frame_gt = [] for idx, obj in enumerate(self.dataset_objects): object_rotation = self._get_object_attribute(obj, 'rotation_euler') object_translation = self._get_object_attribute(obj, 'location') H_m2w = Matrix.Translation(Vector(object_translation)) @ Euler( object_rotation, 'XYZ').to_matrix().to_4x4() cam_H_m2c = (H_m2w.inverted() @ H_c2w_opencv).inverted() cam_R_m2c = cam_H_m2c.to_quaternion().to_matrix() cam_R_m2c = list(cam_R_m2c[0]) + list(cam_R_m2c[1]) + list(cam_R_m2c[2]) cam_t_m2c = list(cam_H_m2c.to_translation() * 1000.) # ignore examples that fell through the plane if not np.linalg.norm(cam_t_m2c) > self._ignore_dist_thres * 1000.: frame_gt.append({ 'cam_R_m2c': cam_R_m2c, 'cam_t_m2c': cam_t_m2c, 'obj_id': self._get_object_attribute(obj, 'id') }) else: print('ignored obj, ', self._get_object_attribute(obj, 'id')) return frame_gt
Example #19
Source File: utils.py From se-blender with GNU General Public License v2.0 | 5 votes |
def transY(y): return Matrix.Translation((0, y, 0))
Example #20
Source File: toolpath.py From curve_cad with GNU General Public License v3.0 | 5 votes |
def execute(self, context): if bpy.context.object.type != 'EMPTY' or bpy.context.object.empty_display_type != 'CUBE': self.report({'WARNING'}, 'Active object must be an empty of display type cube') return {'CANCELLED'} selection = bpy.context.selected_objects[:] workspace = bpy.context.object aabb = internal.AABB(center=Vector((0.0, 0.0, 0.0)), dimensions=Vector((1.0, 1.0, 1.0))*workspace.empty_display_size) toolpath = internal.addObject('CURVE', 'Truncated Toolpath') for curve in selection: if curve.type == 'CURVE': transform = workspace.matrix_world.inverted()@curve.matrix_world inverse_transform = Matrix.Translation(-toolpath.location)@workspace.matrix_world curve_traces = [] for spline in curve.data.splines: if spline.type == 'POLY': curve_traces += internal.truncateToFitBox(transform, spline, aabb) for trace in curve_traces: i = len(trace[0])-1 while i > 1: if (trace[0][i-1]-trace[0][i]).length < self.min_dist: trace[0].pop(i-1) trace[1].pop(i-1) i -= 1 if self.z_hop: begin = Vector(trace[0][0]) end = Vector(trace[0][-1]) begin.z = end.z = workspace.empty_display_size trace[0].insert(0, begin) trace[1].insert(0, 1.0) trace[0].append(end) trace[1].append(1.0) internal.addPolygonSpline(toolpath, False, [inverse_transform@vertex for vertex in trace[0]], trace[1]) return {'FINISHED'}
Example #21
Source File: archipack_fence.py From archipack with GNU General Public License v3.0 | 5 votes |
def from_spline(self, context, wM, resolution, spline): o = self.find_in_selection(context) if o is None: return auto_update = self.auto_update self.auto_update = False pts = self.coords_from_spline(spline, wM, resolution) self.n_parts = len(pts) - 1 self.update_parts() if len(pts) < 1: return if self.user_path_reverse: pts = list(reversed(pts)) o.matrix_world = Matrix.Translation(pts[0].copy()) p0 = pts.pop(0) a0 = 0 for i, p1 in enumerate(pts): dp = p1 - p0 da = atan2(dp.y, dp.x) - a0 if da > pi: da -= 2 * pi if da < -pi: da += 2 * pi p = self.parts[i] p.length = dp.to_2d().length p.dz = dp.z p.a0 = da a0 += da p0 = p1 self.auto_update = auto_update
Example #22
Source File: transform.py From object_alignment with GNU General Public License v3.0 | 5 votes |
def setObjOrigin(obj:Object, loc:Vector): """ set object origin """ l, r, s = obj.matrix_world.decompose() l_mat = Matrix.Translation(l) r_mat = r.to_matrix().to_4x4() s_mat_x = Matrix.Scale(s.x, 4, Vector((1, 0, 0))) s_mat_y = Matrix.Scale(s.y, 4, Vector((0, 1, 0))) s_mat_z = Matrix.Scale(s.z, 4, Vector((0, 0, 1))) s_mat = mathutils_mult(s_mat_x, s_mat_y, s_mat_z) m = obj.data mx = mathutils_mult((obj.matrix_world.translation-loc), l_mat, r_mat, s_mat.inverted()) mx = mathutils_mult((obj.matrix_world.translation-loc), l_mat, r_mat, s_mat.inverted()) m.transform(Matrix.Translation(mx)) obj.matrix_world.translation = loc
Example #23
Source File: archipack_wall2.py From archipack with GNU General Public License v3.0 | 5 votes |
def from_spline(self, wM, resolution, spline): pts = self.coords_from_spline( spline, wM, resolution, ccw=True ) # translation of target object tM = Matrix.Translation(pts[0].copy()) self.auto_update = False self.from_points(pts, spline.use_cyclic_u) self.auto_update = True return tM
Example #24
Source File: archipack_custom.py From archipack with GNU General Public License v3.0 | 5 votes |
def add_vertex_groups(self, o, d, center): vgroups = {vgroup.name: vgroup.index for vgroup in o.vertex_groups} # matrix to retrieve vertex distance from center tM = Matrix.Translation(center) rM_top = Matrix.Rotation(-pi / 2, 4, Vector((0, 1, 0))) rM_front = Matrix.Rotation(pi / 2, 4, Vector((0, 0, 1))) rM_back = Matrix.Rotation(-pi / 2, 4, Vector((0, 0, 1))) rM_left = Matrix.Rotation(pi, 4, Vector((0, 0, 1))) rM_right = Matrix.Rotation(0, 4, Vector((0, 0, 1))) itM = [(tM * rM).inverted() * o.matrix_world for rM in [rM_left, rM_right, rM_back, rM_front, rM_top]] limit = [ self.x_min, self.x_max, self.y_min, self.y_max, self.z_max, ] soft = [ self.x_soft, self.x_soft, self.y_soft, self.y_soft, self.z_soft, ] for i, group_name in enumerate(['left', 'right', 'back', 'front', 'top']): if group_name not in vgroups: g = o.vertex_groups.new() g.name = group_name else: g = o.vertex_groups[group_name] self.weight(o, g, itM[i], soft[i], limit[i])
Example #25
Source File: importer.py From cats-blender-plugin with MIT License | 5 votes |
def __assignToArmatureSimple(self, armObj, reset_transform=True): logging.info(' - assigning to armature "%s"', armObj.name) pose_bones = armObj.pose.bones if self.__bone_mapper: pose_bones = self.__bone_mapper(armObj) matmul = bpyutils.matmul pose_data = {} for b in self.__vpd_file.bones: bone = pose_bones.get(b.bone_name, None) if bone is None: logging.warning(' * Bone not found: %s', b.bone_name) continue converter = self.__bone_util_cls(bone, self.__scale) loc = converter.convert_location(b.location) rot = converter.convert_rotation(b.rotation) assert(bone not in pose_data) pose_data[bone] = matmul(Matrix.Translation(loc), rot.to_matrix().to_4x4()) for bone in armObj.pose.bones: vpd_pose = pose_data.get(bone, None) if vpd_pose: bone.matrix_basis = vpd_pose elif reset_transform: bone.matrix_basis.identity() if armObj.pose_library is None: armObj.pose_library = bpy.data.actions.new(name='PoseLib') frames = [m.frame for m in armObj.pose_library.pose_markers] frame_max = max(frames) if len(frames) else 0 bpy.ops.poselib.pose_add(frame=frame_max+1, name=self.__pose_name)
Example #26
Source File: view.py From cats-blender-plugin with MIT License | 5 votes |
def __matrix_compose(loc, rot, scale): return matmul(matmul(Matrix.Translation(loc), rot.to_matrix().to_4x4()), Matrix([(scale[0],0,0,0), (0,scale[1],0,0), (0,0,scale[2],0), (0,0,0,1)]))
Example #27
Source File: archipack_roof.py From archipack with GNU General Public License v3.0 | 5 votes |
def create(self, context): curve = context.active_object m = bpy.data.meshes.new("Roof") o = bpy.data.objects.new("Roof", m) d = m.archipack_roof.add() # make manipulators selectable d.manipulable_selectable = True d.user_defined_path = curve.name context.scene.objects.link(o) o.select = True context.scene.objects.active = o d.update_path(context) spline = curve.data.splines[0] if spline.type == 'POLY': pt = spline.points[0].co elif spline.type == 'BEZIER': pt = spline.bezier_points[0].co else: pt = Vector((0, 0, 0)) # pretranslate o.matrix_world = curve.matrix_world * Matrix.Translation(pt) o.select = True context.scene.objects.active = o return o # ----------------------------------------------------- # Execute # -----------------------------------------------------
Example #28
Source File: archipack_molding.py From archipack with GNU General Public License v3.0 | 5 votes |
def from_spline(self, context, wM, resolution, spline): o = self.find_in_selection(context) if o is None: return pts = self.coords_from_spline(spline, wM, resolution) auto_update = self.auto_update self.auto_update = False self.n_parts = len(pts) - 1 self.update_parts() if len(pts) < 1: return if self.user_path_reverse: pts = list(reversed(pts)) o.matrix_world = Matrix.Translation(pts[0].copy()) p0 = pts.pop(0) a0 = 0 for i, p1 in enumerate(pts): dp = p1 - p0 da = atan2(dp.y, dp.x) - a0 if da > pi: da -= 2 * pi if da < -pi: da += 2 * pi p = self.parts[i] p.length = dp.to_2d().length p.dz = dp.z p.a0 = da a0 += da p0 = p1 self.auto_update = auto_update
Example #29
Source File: archipack_custom.py From archipack with GNU General Public License v3.0 | 5 votes |
def create(self, context): act = context.active_object d = archipack_custom.datablock(act) if not d: d = act.data.archipack_custom.add() if archipack_custom_part.filter(act): act.data.archipack_custom_part.remove(0) # 2d bound, bottom of geometry bound = Vector(act.bound_box[0]) + Vector(act.bound_box[7]) center = act.matrix_world * (0.5 * bound) altitude = act.bound_box[0][2] itM = (Matrix.Translation(Vector((0, 0, altitude))) * act.matrix_world).inverted() d.auto_update = False d.last_size = act.dimensions.copy() d.x = act.dimensions.x d.y = act.dimensions.y d.z = act.dimensions.z d.altitude = altitude sel = [o for o in context.selected_objects if o.type == 'MESH'] names = [o.name for o in sel] sel.extend([c for c in act.children if c.name not in names and c.type == 'MESH']) for o in sel: self.add_vertex_groups(o, d, center) if o.name != act.name: if archipack_custom.filter(o): o.data.archipack_custom.remove(0) if not archipack_custom_part.filter(o): o.data.archipack_custom_part.add() dc = archipack_custom_part.datablock(o) dc.pivot_location = itM * o.matrix_world.translation self.clear_parent_inverse(o) d.auto_update = True return act
Example #30
Source File: archipack_floor.py From archipack with GNU General Public License v3.0 | 5 votes |
def from_spline(self, context, wM, resolution, spline): pts = self.coords_from_spline( spline, wM, resolution, ccw=True, close=True ) # pretranslate o = self.find_in_selection(context) o.matrix_world = Matrix.Translation(pts[0].copy()) self.from_points(pts)