import rhinoscriptsyntax as rs import scriptcontext as sc import System.Drawing import DM_lib as dm #image path image_path = r"/Volumes/app/WWW/afn2023/DM2/HUE 9 /herr-der-triebe-picture-1079060484.jpg" # UN dimensions width = 87.5 # Meters height = 156 # Meters depth = 11 # Meters origin = dm.getUnoCoord(0, 0, 0) # Building origin # Vectors for directions lengthVec = rs.VectorUnitize(rs.VectorSubtract(dm.getUnoCoord(1, 0, 0), dm.getUnoCoord(0, 0, 0))) # X-axis depthVec = rs.VectorUnitize(rs.VectorSubtract(dm.getUnoCoord(0, 1, 0), dm.getUnoCoord(0, 0, 0))) # Y-axis zVec = [0, 0, 1] # Z-axis (height) # Image grid resolution pixel_step_x = 1 # Horizontal step (meters per point) pixel_step_y = 1 # Vertical step (meters per point) #UN bounding building def create_building_box(origin, width, height, depth): p0 = origin p1 = rs.PointAdd(p0, rs.VectorScale(lengthVec, width)) # Along X p2 = rs.PointAdd(p1, rs.VectorScale(depthVec, depth)) # Along Y p3 = rs.PointAdd(p0, rs.VectorScale(depthVec, depth)) p4 = rs.PointAdd(p0, rs.VectorScale(zVec, height)) # Top points p5 = rs.PointAdd(p1, rs.VectorScale(zVec, height)) p6 = rs.PointAdd(p2, rs.VectorScale(zVec, height)) p7 = rs.PointAdd(p3, rs.VectorScale(zVec, height)) box_edges = [ [p0, p1], [p1, p2], [p2, p3], [p3, p0], # Bottom face [p4, p5], [p5, p6], [p6, p7], [p7, p4], # Top face [p0, p4], [p1, p5], [p2, p6], [p3, p7], # Vertical edges ] for edge in box_edges: rs.AddLine(edge[0], edge[1]) return [p0, p1, p2, p3, p4, p5, p6, p7] #image on the front face of the building def map_image_to_front_face(image, front_bottom_left, width, height, step_x, step_y): img_width, img_height = image.Width, image.Height print("Image dimensions:", img_width, "x", img_height) #Scale the image pixels to fit the front face scale_x = img_width / (width / step_x) scale_y = img_height / (height / step_y) rs.EnableRedraw(True) # Disable redraw for performance # Loop through the grid and map image pixels to the front face for y in range(0, int(height / step_y)): for x in range(0, int(width / step_x)): # Calculate point position on the front face point_x = front_bottom_left[0] + x * step_x * lengthVec[0] point_y = front_bottom_left[1] + x * step_x * lengthVec[1] point_z = front_bottom_left[2] + y * step_y pixel_x = min(int(x * scale_x), img_width - 1) pixel_y = img_height - 1 - min(int(y * scale_y), img_height - 1) # Flip vertically color = image.GetPixel(pixel_x, pixel_y) # Add a colored point at the grid position to recreate the image point = rs.AddPoint([point_x, point_y, point_z]) if point: rs.ObjectColor(point, [color.R, color.G, color.B]) rs.EnableRedraw(True) # Re-enable redraw print("Image successfully mapped to the building's front face.") # Main Execution if __name__ == "__main__": image = System.Drawing.Bitmap(image_path) if image: print("Image loaded successfully.") box_corners = create_building_box(origin, width, height, depth) front_bottom_left = box_corners[0] # Bottom-left corner of the front face map_image_to_front_face(image, front_bottom_left, width, height, pixel_step_x, pixel_step_y) else: print("Error: Unable to load the image file. Please check the path.") def create_exact_horizontal_curves(corners, height, offset, levels=4): level_heights = [height * i / (levels - 1) for i in range(levels)] curves = [] for level in level_heights: h0 = rs.PointAdd(corners[0], rs.VectorScale(rs.VectorAdd(lengthVec, depthVec), -offset)) # Bottom-left h1 = rs.PointAdd(corners[1], rs.VectorScale(rs.VectorAdd(lengthVec, rs.VectorScale(depthVec, -1)), offset)) # Bottom-right h2 = rs.PointAdd(corners[2], rs.VectorScale(rs.VectorAdd(lengthVec, depthVec), offset)) # Top-right h3 = rs.PointAdd(corners[3], rs.VectorScale(rs.VectorAdd(rs.VectorScale(lengthVec, -1), depthVec), offset)) # Top-left h0 = rs.PointAdd(h0, rs.VectorScale(zVec, level)) h1 = rs.PointAdd(h1, rs.VectorScale(zVec, level)) h2 = rs.PointAdd(h2, rs.VectorScale(zVec, level)) h3 = rs.PointAdd(h3, rs.VectorScale(zVec, level)) curve = rs.AddCurve([h0, h1, h2, h3, h0]) if curve: curves.append(curve) print("Added horizontal curve at height {} with {} meters offset.".format(level, offset)) return curves if __name__ == "__main__": # Define the offset for the horizontal curves offset = 8.0 box_corners = create_building_box(origin, width, height, depth) # Create horizontal curves with the specified offset curves = create_exact_horizontal_curves(box_corners, height, offset, levels=4)