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), 'ece3d0', 0) box('wall_back', (0, 2.7, 1.7), (5.6, 0.15, 3), '859eae', 0) box('wall_side', (-2.7, 0, 1.7), (0.15, 5.6, 3), '859eae', 0) box('trim_back', (0, 2.595, 0.29), (5.2, 0.05, 0.18), 'ece3d0', 0) box('trim_side', (-2.595, 0, 0.29), (0.05, 5.2, 0.18), 'ece3d0', 0) box('desk_top', (-0.25, 1.85, 1.05), (1.9, 0.8, 0.12), '9b7359', -1.5708) box('desk_leg_0', (-0.97, 1.58, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_1', (0.47, 1.58, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_2', (-0.97, 2.12, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_3', (0.47, 2.12, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('chair_leg_0', (0.02, 0.77, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_1', (0.02, 0.43, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_2', (-0.32, 0.77, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_3', (-0.32, 0.43, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_seat', (-0.15, 0.6, 0.65), (0.64, 0.62, 0.14), 'cb8d74', -4.7124) box('chair_back', (-0.15, 0.38, 0.97), (0.64, 0.12, 0.66), 'cb8d74', -4.7124) box('monitor_foot', (-0.25, 1.85, 1.145), (0.38, 0.25, 0.08), '4c515a', -1.5708) box('monitor_stand', (-0.25, 1.97, 1.33), (0.09, 0.07, 0.32), '4c515a', -1.5708) box('monitor_frame', (-0.25, 1.97, 1.61), (0.85, 0.09, 0.5), '4c515a', -1.5708) box('monitor_screen', (-0.25, 1.92, 1.61), (0.77, 0.02, 0.42), 'a5c6ce', -1.5708) box('keyboard', (-0.25, 1.63, 1.13), (0.5, 0.18, 0.04), 'ece3d0', -1.5708) box('storage_body', (1.95, 0.45, 0.6), (0.72, 0.8, 0.8), '9b7359', -1.5708) box('storage_door_0', (1.77, 0.035, 0.6), (0.325, 0.035, 0.71), 'ece3d0', -1.5708) box('storage_handle_0', (1.87, -0.0, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) box('storage_door_1', (2.13, 0.035, 0.6), (0.325, 0.035, 0.71), 'ece3d0', -1.5708) box('storage_handle_1', (2.03, -0.0, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) cylinder('plant_pot', (1.95, 0.45, 1.0975), 0.127, 0.195, 'cb8d74') cylinder('plant_stem', (1.95, 0.45, 1.26), 0.025, 0.19, '6d8051') box('plant_leaf_0', (1.89, 0.45, 1.39), (0.15, 0.17, 0.25), '739662', -1.5708) box('plant_leaf_1', (2.01, 0.46, 1.39), (0.15, 0.17, 0.25), '739662', -2.3708) box('plant_leaf_2', (1.95, 0.5, 1.39), (0.15, 0.17, 0.25), '739662', -3.1708) box('shelf_side_0', (-2.15, 1.9, 1.1), (0.08, 0.48, 2.2), '9b7359', -1.5708) box('shelf_side_1', (-1.6, 1.9, 1.1), (0.08, 0.48, 2.2), '9b7359', -1.5708) box('shelf_level_0', (-1.85, 1.9, 0.24), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_0_0', (-2.09, 1.9, 0.39), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_0_1', (-1.97, 1.9, 0.4075), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_0_2', (-1.85, 1.9, 0.425), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('books_0_3', (-2.09, 1.9, 0.49), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_0_4', (-1.97, 1.9, 0.5075), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_0_5', (-1.85, 1.9, 0.525), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('shelf_level_1', (-1.85, 1.9, 0.88), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_1_0', (-2.09, 1.9, 1.03), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_1_1', (-1.97, 1.9, 1.0475), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_1_2', (-1.85, 1.9, 1.065), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('books_1_3', (-2.09, 1.9, 1.13), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_1_4', (-1.97, 1.9, 1.1475), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_1_5', (-1.85, 1.9, 1.165), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('shelf_level_2', (-1.85, 1.9, 1.52), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_2_0', (-2.09, 1.9, 1.67), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_2_1', (-1.97, 1.9, 1.6875), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_2_2', (-1.85, 1.9, 1.705), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('books_2_3', (-2.09, 1.9, 1.77), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_2_4', (-1.97, 1.9, 1.7875), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_2_5', (-1.85, 1.9, 1.805), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('shelf_level_3', (-1.85, 1.9, 2.16), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_3_0', (-2.09, 1.9, 2.31), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_3_1', (-1.97, 1.9, 2.3275), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_3_2', (-1.85, 1.9, 2.345), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('books_3_3', (-2.09, 1.9, 2.41), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_3_4', (-1.97, 1.9, 2.4275), (0.08, 0.22, 0.255), 'ece3d0', -1.5708) box('books_3_5', (-1.85, 1.9, 2.445), (0.08, 0.22, 0.29), 'cb8d74', -1.5708) box('rug', (0.3, -0.7, 0.22), (2.0, 1.3, 0.04), 'cb8d74', -1.5708) cylinder('lamp_base', (-1.9, -1.0, 0.235), 0.23, 0.07, '514b47') cylinder('lamp_stem', (-1.9, -1.0, 0.92), 0.035, 1.44, '514b47') cylinder('lamp_shade', (-1.9, -1.0, 1.65), 0.26, 0.35, 'ece3d0') box('artwork_frame', (0.7, 2.59, 2.2), (0.95, 0.065, 0.7), '9b7359', -1.5708) box('artwork_canvas', (0.7,