def MakeMesh(self, size, loc, name): ''' Creates cubes with specified dimentions and location in inches. ''' #Convert Inches to Meter size = scaleConverter.ImperialToMetric(size) loc = scaleConverter.ImperialToMetric(loc) #verts = LowerBackLeft, LowerBackRight, LowerFrontLeft, LowerFrontRight verts = [(0, 0, 0), (size[0], 0, 0), (0, size[1], 0), (size[0], size[1], 0), (0, 0, size[2]), (size[0], 0, size[2]), (0, size[1], size[2]), (size[0], size[1], size[2])] #Faces = BotomVerts, TopVerts, FrontVerts, BackVerts, LeftVerts, RightVerts faces = [(0, 1, 3, 2), (4, 5, 7, 6), (2, 3, 7, 6), (0, 1, 5, 4), (0, 2, 6, 4), (1, 3, 7, 5)] #Define mesh and object mesh = bpy.data.meshes.new(name) object = bpy.data.objects.new(name, mesh) object.location = (loc) bpy.context.scene.objects.link(object) #Create mesh mesh.from_pydata(verts, [], faces) mesh.update(calc_edges=True) return (object)
def Size(self, size=None): if size is None: #Get XYZ of every vert vertXYZ = [] for vertex in self.object.data.vertices: vertXYZ.append(vertex.co) #Calc size of object in meters minVertXYZ = min(vertXYZ) maxVertXYZ = max(vertXYZ) return (maxVertXYZ[0] - minVertXYZ[0], maxVertXYZ[1] - minVertXYZ[1], maxVertXYZ[2] - minVertXYZ[2]) else: #Change size of mesh size = scaleConverter.ImperialToMetric(size) for vertex in self.object.data.vertices: if vertex.co.x != size[0] and vertex.co.x > 0: vertex.co.x = size[0] for vertex in self.object.data.vertices: if vertex.co.y != size[1] and vertex.co.y > 0: vertex.co.y = size[1] for vertex in self.object.data.vertices: if vertex.co.z != size[2] and vertex.co.z > 0: vertex.co.z = size[2]
import bpy import scaleConverter #Values are in inches x, y, z = (1, 4, 3) #Convert inches to Metric x, y, z = scaleConverter.ImperialToMetric([x, y, z]) #Define cube vertex and face data #verts = LowerBackLeft, LowerBackRight, LowerFrontLeft, LowerFrontRight verts = [(0, 0, 0), (x, 0, 0), (0, y, 0), (x, y, 0), (0, 0, z), (x, 0, z), (0, y, z), (x, y, z)] #Faces = BotomVerts, TopVerts, FrontVerts, BackVerts, LeftVerts, RightVerts faces = [(0, 1, 3, 2), (4, 5, 7, 6), (2, 3, 7, 6), (0, 1, 5, 4), (0, 2, 6, 4), (1, 3, 7, 5)] #Define mesh and object mesh = bpy.data.meshes.new("floor") object = bpy.data.objects.new("floor", mesh) #Set location and scene of object object.location = (0, 0, 0) bpy.context.scene.objects.link(object) #Create mesh mesh.from_pydata(verts, [], faces) mesh.update(calc_edges=True) object.select = False