import bpy import math def material(color): mat = bpy.data.materials.get(color) if mat is None: mat = bpy.data.materials.new(color) rgb = [int(color[i:i+2], 16) / 255 for i in (0, 2, 4)] linear = tuple(v / 12.92 if v < 0.04045 else ((v + 0.055) / 1.055) ** 2.4 for v in rgb) mat.diffuse_color = linear + (1,) return mat def box(name, loc, size, color, angle=0): bpy.ops.mesh.primitive_cube_add(size=1, location=loc) obj = bpy.context.object obj.name = name obj.dimensions = size bpy.ops.object.transform_apply(location=False, rotation=False, scale=True) obj.rotation_euler.z = angle obj.data.materials.append(material(color)) bevel = obj.modifiers.new('edge', 'BEVEL') bevel.width = min(0.025, min(size) / 5) bevel.segments = 1 return obj def cylinder(name, loc, radius, depth, color): bpy.ops.mesh.primitive_cylinder_add(vertices=10, radius=radius, depth=depth, location=loc) obj = bpy.context.object obj.name = name obj.data.materials.append(material(color)) return obj box('floor', (0, 0, 0.1), (5.6, 5.6, 0.2), 'ece1af', 0) box('wall_back', (0, 2.7, 1.7), (5.6, 0.15, 3), 'a799be', 0) box('wall_side', (-2.7, 0, 1.7), (0.15, 5.6, 3), 'a799be', 0) box('trim_back', (0, 2.595, 0.29), (5.2, 0.05, 0.18), 'ece1af', 0) box('trim_side', (-2.595, 0, 0.29), (0.05, 5.2, 0.18), 'ece1af', 0) box('desk_top', (-1.85, -0.2, 1.05), (2, 0.8, 0.12), '927861', -1.5708) box('desk_leg_0', (-1.57, 0.72, 0.595), (0.1, 0.1, 0.79), '927861', -1.5708) box('desk_leg_1', (-2.13, 0.72, 0.595), (0.1, 0.1, 0.79), '927861', -1.5708) box('desk_leg_2', (-1.57, -1.12, 0.595), (0.1, 0.1, 0.79), '927861', -1.5708) box('desk_leg_3', (-2.13, -1.12, 0.595), (0.1, 0.1, 0.79), '927861', -1.5708) box('chair_leg_0', (-0.92, -0.53, 0.4), (0.08, 0.08, 0.4), '927861', -4.7124) box('chair_leg_1', (-0.48, -0.53, 0.4), (0.08, 0.08, 0.4), '927861', -4.7124) box('chair_leg_2', (-0.92, -0.17, 0.4), (0.08, 0.08, 0.4), '927861', -4.7124) box('chair_leg_3', (-0.48, -0.17, 0.4), (0.08, 0.08, 0.4), '927861', -4.7124) box('chair_seat', (-0.7, -0.35, 0.65), (0.64, 0.62, 0.14), 'cf8596', -4.7124) box('chair_back', (-0.55, -0.2, 0.97), (0.64, 0.12, 0.66), 'cf8596', -4.7124) box('monitor_foot', (-1.93, -0.2, 1.145), (0.38, 0.25, 0.08), '4c515a', -1.5708) box('monitor_stand', (-1.97, -0.2, 1.33), (0.09, 0.07, 0.32), '4c515a', -1.5708) box('monitor_frame', (-1.99, -0.2, 1.57), (0.85, 0.09, 0.5), '4c515a', -1.5708) box('monitor_screen', (-1.95, -0.2, 1.57), (0.77, 0.02, 0.42), 'a5c6ce', -1.5708) box('keyboard', (-1.63, -0.2, 1.13), (0.5, 0.18, 0.04), 'ece1af', -1.5708) box('storage_body', (-0.35, -1.9, 0.6), (0.72, 0.8, 0.8), '927861', -1.5708) box('storage_door_0', (-0.035, -1.66, 0.6), (0.325, 0.035, 0.71), 'ece1af', -1.5708) box('storage_handle_0', (0.0, -1.84, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) box('storage_door_1', (-0.035, -2.14, 0.6), (0.325, 0.035, 0.71), 'ece1af', -1.5708) box('storage_handle_1', (0.0, -2.06, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) cylinder('plant_pot', (-0.35, -1.9, 1.1), 0.155, 0.2, 'cf8596') cylinder('plant_stem', (-0.35, -1.9, 1.35), 0.035, 0.25, '6d8051') box('plant_leaf_0', (-0.35, -1.79, 1.5), (0.25, 0.17, 0.3), '739662', -1.5708) box('plant_leaf_1', (-0.41, -1.89, 1.5), (0.25, 0.17, 0.3), '739662', -2.3708) box('plant_leaf_2', (-0.39, -2.01, 1.5), (0.25, 0.17, 0.3), '739662', -3.1708) box('shelf_side_0', (-1.9, 2.45, 1.19), (0.08, 0.48, 2.38), '927861', -1.5708) box('shelf_side_1', (-1.9, 1.55, 1.19), (0.08, 0.48, 2.38), '927861', -1.5708) box('shelf_level_0', (-1.9, 2, 0.24), (0.88, 0.48, 0.08), '927861', -1.5708) box('books_0_0', (-1.9, 2.2, 0.37), (0.08, 0.22, 0.22), 'a799be', -1.5708) box('books_0_1', (-1.9, 1.9, 0.405), (0.08, 0.22, 0.27), 'ece1af', -1.5708) box('books_0_2', (-1.9, 2.1, 0.44), (0.08, 0.22, 0.32), 'cf8596', -1.5708) box('shelf_level_1', (-1.9, 2, 1.18), (0.88, 0.48, 0.08), '927861', -1.5708) box('books_1_0', (-1.9, 2.2, 1.27), (0.08, 0.22, 0.22), 'a799be', -1.5708) box('books_1_1', (-1.9, 1.9, 1.305), (0.08, 0.22, 0.27), 'ece1af', -1.5708) box('books_1_2', (-1.9, 2.1, 1.34), (0.08, 0.22, 0.32), 'cf8596', -1.5708) box('shelf_level_2', (-1.9, 2, 2.12), (0.88, 0.48, 0.08), '927861', -1.5708) box('books_2_0', (-1.9, 2.2, 2.21), (0.08, 0.22, 0.22), 'a799be', -1.5708) box('books_2_1', (-1.9, 1.9, 2.245), (0.08, 0.22, 0.27), 'ece1af', -1.5708) box('books_2_2', (-1.9, 2.1, 2.28), (0.08, 0.22, 0.32), 'cf8596', -1.5708) box('shelf_level_3', (-1.9, 2, 3.06), (0.88, 0.48, 0.08), '927861', -1.5708) box('books_3_0', (-1.9, 2.2, 3.15), (0.08, 0.22, 0.22), 'a799be', -1.5708) box('books_3_1', (-1.9, 1.9, 3.185), (0.08, 0.22, 0.27), 'ece1af', -1.5708) box('books_3_2', (-1.9, 2.1, 3.22), (0.08, 0.22, 0.32), 'cf8596', -1.5708) cylinder('lamp_base', (-2.02, -0.9, 0.235), 0.23, 0.07, '514b47') cylinder('lamp_stem', (-2.02, -0.9, 0.925), 0.035, 1.45, '514b47') cylinder('lamp_shade', (-2.02, -0.9, 1.65), 0.26, 0.35, 'ece1af') box('rug', (0.9, 0.4, 0.22), (2.0, 1.3, 0.04), 'cf8596', -1.5708) bpy.context.view_layer.update()