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', (-1.85, -0.2, 1.05), (2, 0.8, 0.12), '9b7359', -1.5708) box('desk_leg_0', (-1.57, 0.72, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_1', (-2.13, 0.72, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_2', (-1.57, -1.12, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('desk_leg_3', (-2.13, -1.12, 0.595), (0.1, 0.1, 0.79), '9b7359', -1.5708) box('chair_leg_0', (-0.92, -0.53, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_1', (-0.48, -0.53, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_2', (-0.92, -0.07, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_leg_3', (-0.48, -0.07, 0.4), (0.08, 0.08, 0.4), '9b7359', -4.7124) box('chair_seat', (-0.7, -0.3, 0.65), (0.64, 0.62, 0.14), 'cb8d74', -4.7124) box('chair_back', (-0.45, -0.3, 0.97), (0.64, 0.12, 0.66), 'cb8d74', -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), 'ece3d0', -1.5708) box('storage_body', (-0.35, -1.9, 0.6), (0.72, 0.8, 0.8), '9b7359', -1.5708) box('storage_door_0', (-0.03, -1.61, 0.6), (0.325, 0.035, 0.71), 'ece3d0', -1.5708) box('storage_handle_0', (0.0, -1.56, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) box('storage_door_1', (-0.03, -2.19, 0.6), (0.325, 0.035, 0.71), 'ece3d0', -1.5708) box('storage_handle_1', (0.0, -2.24, 0.64), (0.04, 0.04, 0.18), '504945', -1.5708) cylinder('plant_pot', (-0.35, -1.9, 1.0975), 0.127, 0.185, 'cb8d74') cylinder('plant_stem', (-0.35, -1.9, 1.26), 0.025, 0.235, '6d8051') box('plant_leaf_0', (-0.35, -1.805, 1.3775), (0.15, 0.17, 0.25), '739662', -1.5708) box('plant_leaf_1', (-0.38, -1.995, 1.3775), (0.15, 0.17, 0.25), '739662', -2.3708) box('plant_leaf_2', (-0.41, -1.9, 1.3775), (0.15, 0.17, 0.25), '739662', -3.1708) box('shelf_side_0', (-1.95, 1.85, 1.2), (0.08, 0.48, 2.2), '9b7359', -1.5708) box('shelf_side_1', (-1.95, 0.15, 1.2), (0.08, 0.48, 2.2), '9b7359', -1.5708) box('shelf_level_0', (-1.95, 1.0, 0.24), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_0_0', (-1.89, 1.0, 0.39), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_0_1', (-1.83, 1.0, 0.4075), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_0_2', (-1.77, 1.0, 0.425), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('books_0_3', (-1.71, 1.0, 0.4425), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_0_4', (-1.65, 1.0, 0.46), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('shelf_level_1', (-1.95, 1.0, 0.86), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_1_0', (-1.89, 1.0, 1.005), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_1_1', (-1.83, 1.0, 1.0225), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_1_2', (-1.77, 1.0, 1.04), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('books_1_3', (-1.71, 1.0, 1.0575), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_1_4', (-1.65, 1.0, 1.075), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('shelf_level_2', (-1.95, 1.0, 1.52), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_2_0', (-1.89, 1.0, 1.665), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_2_1', (-1.83, 1.0, 1.6825), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_2_2', (-1.77, 1.0, 1.7), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('books_2_3', (-1.71, 1.0, 1.7175), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_2_4', (-1.65, 1.0, 1.735), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('shelf_level_3', (-1.95, 1.0, 2.18), (0.44, 0.08, 0.48), '9b7359', -1.5708) box('books_3_0', (-1.89, 1.0, 2.325), (0.08, 0.22, 0.22), '859eae', -1.5708) box('books_3_1', (-1.83, 1.0, 2.3425), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_3_2', (-1.77, 1.0, 2.36), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) box('books_3_3', (-1.71, 1.0, 2.3775), (0.08, 0.22, 0.315), 'ece3d0', -1.5708) box('books_3_4', (-1.65, 1.0, 2.395), (0.08, 0.22, 0.27), 'cb8d74', -1.5708) cylinder('lamp_base', (-2.12, -0.55, 0.235), 0.23, 0.07, '514b47') cylinder('lamp_stem', (-2.12, -0.55, 0.92), 0.035, 1.45, '514b47') cylinder('lamp_shade', (-2.12, -0.55, 1.65), 0.26, 0.35, 'ece3d0') box('rug', (0.35, -0.45, 0.22), (1.6, 1.3, 0.04), '859eae', -1.5708) box('artwork_frame', (-2.59, -0.55, 2.2), (0.95, 0.065, 0.7), '9b7359', -1.5708) box('artwork_canvas', (-2.547, -0.55, 2.2), (0.83, 0.025, 0.58), 'ece3d0', -1.5708) box('artwork_shape', (-2.527, -0.62, 2.2), (0.37, 0.02, 0.33), 'cb8d74', -1.5708) bpy.context.view_layer.update()