def faces(self): faces = [] segmentAngle = 2*np.pi/self.numSegments ringAngle = np.pi/self.numRings for i_seg in range(self.numSegments): # faces of the lowest ring have to be computed differently mu_i = -np.pi/2 nu_i = i_seg*segmentAngle mu_ip1 = ringAngle - np.pi/2 nu_ip1 = (i_seg+1)*segmentAngle v0_normalized = np.array([np.cos(mu_ip1)*np.cos(nu_ip1), np.cos(mu_ip1)*np.sin(nu_ip1), np.sin(mu_ip1)], dtype=np.float) v1_normalized = np.array([np.cos(mu_i)*np.cos(nu_ip1), np.cos(mu_i)*np.sin(nu_ip1), np.sin(mu_i)], dtype=np.float) v2_normalized = np.array([np.cos(mu_ip1)*np.cos(nu_i), np.cos(mu_ip1)*np.sin(nu_i), np.sin(mu_ip1)], dtype=np.float) v0 = v0_normalized*self.size/2 + self.center v1 = v1_normalized*self.size/2 + self.center v2 = v2_normalized*self.size/2 + self.center faces.append(baseclasses.Face(v0, v1, v2, self.texture)) # rest of the rings for i_ring in range(1, self.numRings): mu_i = i_ring*ringAngle - np.pi/2 nu_i = i_seg*segmentAngle mu_ip1 = (i_ring+1)*ringAngle - np.pi/2 nu_ip1 = (i_seg+1)*segmentAngle v0_normalized = np.array([np.cos(mu_i)*np.cos(nu_ip1), np.cos(mu_i)*np.sin(nu_ip1), np.sin(mu_i)], dtype=np.float) v1_normalized = np.array([np.cos(mu_i)*np.cos(nu_i), np.cos(mu_i)*np.sin(nu_i), np.sin(mu_i)], dtype=np.float) v2_normalized = np.array([np.cos(mu_ip1)*np.cos(nu_ip1), np.cos(mu_ip1)*np.sin(nu_ip1), np.sin(mu_ip1)], dtype=np.float) v0 = v0_normalized*self.size/2 + self.center v1 = v1_normalized*self.size/2 + self.center v2 = v2_normalized*self.size/2 + self.center faces.append(baseclasses.Face(v0, v1, v2, self.texture)) return faces
def faces(self): faces = [] rad2 = self.radius2 if self.radius2 else self.radius ratio = self.truncation_ratio # sides angle = 2*np.pi/self.numSides for i in range(self.numSides): v0 = self.center + np.array([self.radius*np.cos((i+1)*angle), rad2*np.sin((i+1)*angle), -self.height/2], dtype=np.float) v1 = self.center + np.array([self.radius*np.cos((i)*angle), rad2*np.sin((i)*angle), -self.height/2], dtype=np.float) v2 = self.center + np.array([ratio*self.radius*np.cos((i+1)*angle), ratio*rad2*np.sin((i+1)*angle), +self.height/2], dtype=np.float) faces.append(baseclasses.Face(v0, v1, v2, self.texture["sides"])) # top - only if the truncation_ratio is not 0 if ratio: v0 = self.center + np.array([self.radius, -self.radius, self.height/2], dtype=np.float) v1 = self.center + np.array([-self.radius, -self.radius, self.height/2], dtype=np.float) v2 = self.center + np.array([self.radius, self.radius, self.height/2], dtype=np.float) faces.append(baseclasses.Face(v0, v1, v2, self.texture["top"])) # bottom v0 = self.center + np.array([self.radius, self.radius, -self.height/2], dtype=np.float) v1 = self.center + np.array([-self.radius, self.radius, -self.height/2], dtype=np.float) v2 = self.center + np.array([self.radius, -self.radius, -self.height/2], dtype=np.float) faces.append(baseclasses.Face(v0, v1, v2, self.texture["bottom"])) return faces
def faces(self): """ \brief Return the faces described by 3 verticies and the texture order: front, back, right, left, bottom, top """ verts = self.verticies return [baseclasses.Face(verts[0], verts[1], verts[3], self.texture["front"]), baseclasses.Face(verts[5], verts[4], verts[6], self.texture["back"]), baseclasses.Face(verts[4], verts[0], verts[7], self.texture["right"]), baseclasses.Face(verts[1], verts[5], verts[2], self.texture["left"]), baseclasses.Face(verts[4], verts[5], verts[0], self.texture["bottom"]), baseclasses.Face(verts[3], verts[2], verts[7], self.texture["top"])]
import helper if __name__ == "__main__": # create a single step, inner radius 64, outer radius 256 r1 = 64.0 r2 = 256.0 stepheight = 24.0 theta = math.radians(15) rot_matrix = helper.RotationMatrixZ(theta) v0 = np.array([r1, 0, 0], dtype=np.float64) v1 = np.array([r2, 0, 0], dtype=np.float64) v2 = v0 @ rot_matrix v3 = v1 @ rot_matrix v4 = v0 + [0, 0, stepheight] v5 = v1 + [0, 0, stepheight] f0 = baseclasses.Face(v0, v1, v2, "trak6x/base-base1c") f1 = f0.flipped() f1.move([0, 0, stepheight]) f2 = baseclasses.Face(v0, v2, v4) f3 = baseclasses.Face(v0, v4, v1, "trak6x/base-base1c") f4 = f3.flipped().rotated_point([0, 0, 0], rot_matrix) f5 = baseclasses.Face(v1, v5, v3) step = baseclasses.Brush([f0, f1, f2, f3, f4, f5]) # inner and outer ramps, 8 units wide ramp_width = 8.0 v6 = np.array([r1 - ramp_width, 0, -stepheight]) v7 = v6 @ rot_matrix + [0, 0, stepheight] v8 = np.array([r1 - ramp_width, 0, stepheight]) v9 = v8 @ rot_matrix + [0, 0, stepheight] v10 = v0 - [0, 0, stepheight] v11 = v2 + [0, 0, 2 * stepheight]
import sys import os # put parent directory into PYTHONPATH, remove this when this library has a proper setup.py sys.path.append(os.path.join(os.path.dirname(__file__), "..")) import baseclasses import primitives import modifiers import assets if __name__ == "__main__": # create a single step step = primitives.Cuboid([0, 0, 8], [32, 128, 16], "trak6x/base-base1b") # use the array modifier to repeat the step steps = modifiers.Array(step, 16, [1, 0, 1.5], relative=True) # create a support beam by cutting a cuboid twice temp = primitives.Cuboid([248, 0, 176], [496, 16, 368], "trak6x/base-base1c") support_beam = temp.cutted( baseclasses.Face([8, 0, 8], [8, 32, 8], [40, 0, 32], "trak6x/base-base1c"), baseclasses.Face([496, 0, 352], [496, 32, 352], [24, 0, 0], "trak6x/base-base1c")) # use the ObjectWriter to save the objects into a .map file # also group them into the func_group "Stairs" writer = assets.ObjectWriter([steps, support_beam], group="Stairs") with open("simple_stairs.map", "w") as f: writer.write(f)