def overturn(colors, materials): color = colors.pop() material = materials.pop() theta = rand(45, 50) width = rand(.9, 1.) height = width * rand(.9, .95) init_orn = (0, 0, rand(-15, 15)) case_occluders = [] for i in range(4): if i == 0: joint_pattern = [(90, 90, 50), (90, -90, 350), (-90, -90, 50)] elif i == 1: joint_pattern = [(90, 90, 50), (90, -theta, 350), (-theta, -theta, 50)] elif i == 2: joint_pattern = [(90, 90, 50), (90, -theta, 350), (-theta, -theta, 50), (-theta, 90, 350), (90, 90, 50)] else: joint_pattern = [(90, 90, 50), (90, -90, 350), (-90, -90, 50), (-90, 90, 350), (90, 90, 50)] occluder = dict(shape="cube", color=color, joint="revolute", material=material, init_pos=(.2, rand(-.1, .1), 0), init_orn=init_orn, scale=(OCCLUDER_HALF_WIDTH, width, height), joint_pattern=joint_pattern) case_occluders.append([occluder]) return case_occluders
def adjust_ground(): theta = rand(-np.pi / 3, np.pi / 3) depth = 15 shift = rand(28, 32) bpy.context.view_layer.objects.active = bpy.data.objects["Ground"] bpy.context.object.rotation_mode = 'XYZ' bpy.context.object.rotation_euler = [0, 0, np.pi + theta] bpy.context.object.location = [ -depth * np.cos(theta) + shift * np.sin(theta), -depth * np.sin(theta) - shift * np.cos(theta), 0 ]
def delay(colors, materials): color1 = colors.pop() material1 = materials.pop() init_orn1 = (0, 0, rand(-10, 10)) big = dict(shape="cube", color=color1, joint="revolute", material=material1, init_orn=init_orn1, init_pos=(.2, 0, 0), scale=(OCCLUDER_HALF_WIDTH, rand(1.4, 1.45), rand(.8, .9)), joint_pattern=[(0, 0, 600), (0, 90, 200), (90, 90, 50)]) return [[big] for _ in range(2)]
def disappear_fixed(colors, materials): color = colors.pop() material = materials.pop() final_t = int(rand(10, 20)) width = rand(.8, .9) height = width * rand(.8, .85) init_orn = (0, 0, rand(-15, 15)) occluder = dict(shape="cube", color=color, joint="revolute", material=material, init_pos=(.2, rand(-.2, .2), 0), init_orn=init_orn, scale=(OCCLUDER_HALF_WIDTH, width, height), joint_pattern=[(0, 0, 700), (0, 90, 250 - final_t), (90, 90, final_t)]) return [[occluder] for _ in range(5)]
def block(colors, materials): color1 = colors.pop() material1 = materials.pop() width = rand(1.05, 1.15) height = rand(.6, .65) init_orn1 = (0, 0, rand(-10, 10)) occluder = dict(shape="cube", color=color1, joint="revolute", material=material1, init_orn=init_orn1, init_pos=(.2, 0, 0), scale=(OCCLUDER_HALF_WIDTH, width, height), joint_pattern=[(90, 90, 50), (90, 0, 150), (0, 0, 300), (0, 90, 150), (90, 90, 50)]) return [[occluder] for _ in range(2)]
def discontinuous(colors, materials): color1, color2 = colors.pop(), colors.pop() material1, material2 = materials.pop(), materials.pop() width = rand(.44, .46) height = rand(.6, .65) init_orn1 = (0, 0, rand(-10, 10)) init_orn2 = (0, 0, rand(-10, 10)) init_y = rand(.9, .95) left = dict(shape="cube", color=color1, joint="revolute", material=material1, init_orn=init_orn1, init_pos=(.2, -init_y, 0), scale=(OCCLUDER_HALF_WIDTH, width, height), joint_pattern=[(0, 0, 900), (0, 90, 150), (90, 90, 50)]) right = dict(shape="cube", color=color2, joint="revolute", material=material2, init_orn=init_orn2, init_pos=(.2, init_y, 0), scale=(OCCLUDER_HALF_WIDTH, width, height), joint_pattern=[(0, 0, 900), (0, 90, 150), (90, 90, 50)]) init_orn3 = (0, 0, rand(-10, 10)) big = dict(shape="cube", color=color1, joint="revolute", material=material1, init_orn=init_orn3, init_pos=(.2, 0, 0), scale=(OCCLUDER_HALF_WIDTH, rand(1.35, 1.4), rand(.6, .65)), joint_pattern=[(0, 0, 900), (0, 90, 150), (90, 90, 50)]) return [[left, right] for _ in range(4)] + [[big] for _ in range(2)]
def get_occluders(colors, materials): occluders = [] occluder_rand = rand(0, 1) init_pos = (rand(-.5, .5), rand(-1., 1.), 0) half_width = rand(.5, 1.5) half_height = rand(.5, 1.) scale = (OCCLUDER_HALF_WIDTH, half_width, half_height) init_orn = (0, 0, rand(-20, 20)) if occluder_rand < .85: # rotating occluder joint_rand = rand(0, 1) joint_t = np.random.randint(10, 25) if joint_rand < 1 / 6: joint_pattern = [(90, 90, joint_t), (90, 0, 250 - joint_t), (0, 90, 250 - joint_t), (90, 90, joint_t)] elif joint_rand < 1 / 3: joint_pattern = [(90, 90, joint_t), (90, 0, 250 - joint_t), (0, -90, 250 - joint_t), (-90, -90, joint_t)] elif joint_rand < .5: joint_pattern = [(-90, -90, joint_t), (-90, 0, 250 - joint_t), (0, 90, 250 - joint_t), (90, 90, joint_t)] elif joint_rand < 2 / 3: joint_pattern = [(-90, -90, joint_t), (-90, 0, 250 - joint_t), (0, -90, 250 - joint_t), (-90, -90, joint_t)] elif joint_rand < 5 / 6: joint_pattern = [(0, 0, joint_t), (0, 90, 250 - joint_t), (90, 0, 250 - joint_t), (0, 0, joint_t)] else: joint_pattern = [(0, 0, joint_t), (0, -90, 250 - joint_t), (-90, 0, 250 - joint_t), (0, 0, joint_t)] occluder = dict(shape="cube", color=colors.pop(), joint="revolute", material=materials.pop(), init_pos=init_pos, init_orn=init_orn, scale=scale, joint_pattern=joint_pattern) occluders.append(occluder) elif occluder_rand < .9: # sliding occluder joint_rand = rand(0, 1) if joint_rand < .25: joint_pattern = [(rand(.6, 1.2), 0, 250), (0, rand(.6, 1.2), 250)] elif joint_rand < .5: joint_pattern = [(rand(.6, 1.2), 0, 250), (0, rand(-1.2, -.6), 250)] elif joint_rand < .75: joint_pattern = [(rand(-1.2, -.6), 0, 250), (0, rand(.6, 1.2), 250)] else: joint_pattern = [(rand(-1.2, -.6), 0, 250), (0, rand(-1.2, -.6), 250)] occluder = dict(shape="cube", color=colors.pop(), joint="prismatic", material=materials.pop(), init_pos=init_pos, init_orn=init_orn, scale=scale, joint_pattern=joint_pattern) occluders.append(occluder) return occluders
def get_objects(colors, materials): objects = [] n_objects = np.random.randint(2, 3) for obj_id in range(n_objects): side_rand = rand(0, 1) size = rand(.2, .4) """ while True: # Number of ShapeNet shapes cat_id = np.random.randint(17) if cat_id % 5 != 0: break shape = random_shape_net(cat_id, True) """ shape = default_shapes[random.randint(0, len(default_shapes) - 1)] pos_z = SHAPE_DIMENSIONS[shape][2] * size scale = repeat_scale(size) orn_z = rand(-180, 180) if side_rand < .4: init_pos = (rand(-2.5, .5), rand(-4, -2), pos_z) init_v = (rand(-.6, .6), rand(.5, 1.5), 0) elif side_rand < .8: init_pos = (rand(-2.5, .5), rand(2, 4), pos_z) init_v = (rand(-.6, .6), rand(-1.5, -.5), 0) else: init_pos = (rand(-1.5, 0), rand(-.8, .8), pos_z) init_v = (rand(-.6, .6), rand(-1.5, 1.5), 0) color = colors.pop() backward_rand = rand(0, 1) if backward_rand < .4: backward_time = np.random.randint(200, 300) material = materials.pop() mid_pos = get_prospective_location(init_pos, init_v, backward_time / 100) object_orginal = dict(shape=shape, color=color, material=material, init_pos=init_pos, init_orn=(0, 0, orn_z), scale=scale, init_v=init_v, disappear_time=backward_time) object_stop = dict(shape=shape, color=color, material=material, init_pos=mid_pos, init_orn=(0, 0, orn_z), scale=scale, init_v=[0, 0, 0], appear_time=backward_time, disappear_time=backward_time + 50) object_backward = dict(shape=shape, color=color, material=material, init_pos=mid_pos, init_orn=(0, 0, orn_z), scale=scale, init_v=[-x for x in init_v], appear_time=backward_time + 50) for o in [object_orginal, object_stop, object_backward]: objects.append(o) continue object = dict(shape=shape, color=color, material=materials.pop(), init_pos=init_pos, init_orn=(0, 0, orn_z), scale=scale, init_v=init_v) objects.append(object) return objects