def test_probabilistic_complex_sequence(): def foo(parameters): print(parameters) return class TestGenerator: def __init__(self, num, length): self._num = num self._len = length return def get_sequence(self): return sequence.ActionNTimesWithSimilarParameters( foo, self._num, self._len) a = TestGenerator(1, 1) b = TestGenerator(2, 2) c = TestGenerator(3, 3) logs = [1, 2, 3] probabilities = np.array([[0, 0.5, 0.5], [0.2, 0, 0.8], [0.5, 0.5, 0]]) _sequence = complex_sequence.ProbabilisticComplexSequence( 0, [a, b, c], logs, probabilities, 10) def snapshot(index): return def check(): return True sequence.handle(_sequence, check, snapshot) print(_sequence.logs_note) return
def test_no_motion(): no_motion = t_generator.NoMotion(min_frames=20, max_frames=40) a = [0] def snapshot(index): a[0] += 1 return def check(): return True sequence.handle(no_motion.get_sequence(), check, snapshot) print(a[0]) return
def test_direct_object_motion(): _object = bpy.data.objects['Sphere'] _sequence = b_sequence.DirectObjectMotion(_object=_object, distance=2, local_direction=mathutils.Vector((0,1,0)), min_step=0.1, max_step=0.2) def check(): return True def snapshot(index): print(_object.location) sequence.handle(_sequence, check, snapshot) return
def test_unite_parameters(): """ test ActionNTimesWithSimilarParameters """ a = [0, 0] def a_action(parameters): a = parameters a[0] += 1 def b_action(parameters): a = parameters a[1] += 1 _sequences = [ sequence.ActionNTimesWithSimilarParameters(a_action, a, 5), sequence.ActionNTimesWithSimilarParameters(b_action, a, 5) ] _sequence = sequence.Unite(_sequences) def snapshot(index): print(a) def check(): return True result = sequence.handle(_sequence, check, snapshot) print(result) return
def test_z_sitting_x_rotation(): _object = bpy.data.objects['Sphere'] _sequence = b_sequence.ZSittingXRotation(_object=_object, is_increase=True, limit_angle=90, min_d_angle=5, max_d_angle=5, z_level=0) def check(): return True def snapshot(index): print(str(_object.location) + " " + str(_object.rotation_euler)) sequence.handle(_sequence, check, snapshot) return
def test_zero_z_sitting_x_rotation_1(): _object = bpy.data.objects['Sphere'] sitting_up = t_generator.ZeroZSittingXRotation(_object=_object, limit_angle=90, is_increase=True, min_d_angle=2, max_d_angle=3) def snapshot(index): print(_object.location) return def check(): return True sequence.handle(sitting_up.get_sequence(), check, snapshot) return
def test_zero_z_sitting_x_rotation_2(): _object = bpy.data.objects['Sphere'] lying_down = t_generator.ZeroZSittingXRotation(_object=_object, limit_angle=0, is_increase=False, min_d_angle=-3, max_d_angle=-2) def snapshot(index): print(_object.location) return def check(): return True sequence.handle(lying_down.get_sequence(), check, snapshot) return
def test_direct_object_motion_generator_2(): _object = bpy.data.objects['Sphere'] x_back_motion = t_generator.DirectObjectMotionGenerator( _object=_object, local_direction=mathutils.Vector((-1, 0, 0)), distance=1.5, min_step=0.1, max_step=0.3) def snapshot(index): print(_object.location) return def check(): return True sequence.handle(x_back_motion.get_sequence(), check, snapshot) return
def test_z_rotation_motion(): _object = bpy.data.objects['Sphere'] z_rotation = t_generator.ZRotationMotion(_object=_object, min_angle=30, max_angle=60, min_d_angle=2, max_d_angle=3) def snapshot(index): print( str(math.degrees(_object.rotation_euler.x)) + " " + str(math.degrees(_object.rotation_euler.y)) + " " + str(math.degrees(_object.rotation_euler.z))) return def check(): return True sequence.handle(z_rotation.get_sequence(), check, snapshot) return
def test_handles_check(): a = [0] def a_action(parameters): a = parameters a[0] += 1 _sequence = sequence.ActionNTimesWithSimilarParameters(a_action, a, 10) def snapshot(index): print(a[0]) def check(): return a[0] < 6 result = sequence.handle(_sequence, check, snapshot) print(result) return
def test_action_n_times_with_similar_parameters(): """ test ActionNTimesWithSimilarParameters """ a = [0] def a_action(parameters): a = parameters a[0] += 1 _sequence = sequence.ActionNTimesWithSimilarParameters(a_action, a, 10) def snapshot(index): print(a[0]) def check(): return True result = sequence.handle(_sequence, check, snapshot) print(result) return
def test_action_n_times_with_differnt_parameters(): """ test ActionNTimesWithDifferentParameters """ a = [0, 0, 0, 0, 0] p = [(a, 0), (a, 1), (a, 2), (a, 3), (a, 4)] def a_action(parameters): a, ind = parameters a[ind] += 1 _sequence = sequence.ActionNTimesWithDifferentParameters(a_action, p) def snapshot(index): print(a) def check(): return True result = sequence.handle(_sequence, check, snapshot) print(result) return
def go(): """ Main function for task 2""" # ellipsoid _object = bpy.data.objects['Sphere'] # generators no_motion = t_generator.NoMotion(min_frames=20, max_frames=40) lying_forward_motion = t_generator.DirectObjectMotionGenerator( _object=_object, local_direction=mathutils.Vector((0, 1, 0)), distance=1.5, min_step=0.1, max_step=0.3) sitting_forward_motion = t_generator.DirectObjectMotionGenerator( _object=_object, local_direction=mathutils.Vector((-1, 0, 0)), distance=1, min_step=0.1, max_step=0.2) sitting_z_rotation = t_generator.ZRotationMotion(_object=_object, min_angle=30, max_angle=60, min_d_angle=2, max_d_angle=3) lying_z_rotation = t_generator.ZRotationMotion(_object=_object, min_angle=20, max_angle=40, min_d_angle=1.5, max_d_angle=2) sitting_up = t_generator.ZeroZSittingXRotation(_object=_object, limit_angle=90, is_increase=True, min_d_angle=2, max_d_angle=3) lying_down = t_generator.ZeroZSittingXRotation(_object=_object, limit_angle=0, is_increase=False, min_d_angle=-3, max_d_angle=-2) # ProbabilisticComplexSequence generators = [ no_motion, lying_forward_motion, lying_z_rotation, sitting_up, no_motion, sitting_forward_motion, sitting_z_rotation, lying_down ] log_ids = [1, 2, 3, 4, 5, 6, 5, 7] probabilities = np.array( [[0.4, 0.2, 0.2, 0.2, 0, 0, 0, 0], [0.2, 0.3, 0.3, 0.2, 0, 0, 0, 0], [0.2, 0.2, 0.4, 0.2, 0, 0, 0, 0], [0, 0, 0, 0, 0.45, 0.45, 0.1, 0], [0, 0, 0, 0, 0.2, 0.4, 0.1, 0.3], [0, 0, 0, 0, 0.2, 0.2, 0.3, 0.3], [0, 0, 0, 0, 0.1, 0.2, 0.3, 0.4], [0.45, 0.45, 0.1, 0, 0, 0, 0, 0]], dtype=np.float) def init(): # scale scale_x = random.uniform(0.1, 0.15) scale_y = random.uniform(0.25, 0.35) scale_z = random.uniform(scale_x - 0.025, scale_x + 0.025) location_x = random.uniform(-1, 1) location_y = random.uniform(-1, 1) rotation_y = math.radians(0.0) rotation_z = random.uniform(math.radians(0), math.radians(360)) location_z = scale_z rotation_x = math.radians(0.0) state = random.choice([0, 1, 2, 3]) if random.choice([True, False]): location_z = scale_y rotation_x = math.radians(90.0) state = random.choice([4, 5, 6, 7]) b_action.set_location((_object, location_x, location_y, location_z)) b_action.set_rotation((_object, rotation_x, rotation_y, rotation_z)) _object.scale = (scale_x, scale_y, scale_z) return state # prepare for sequence's host journal = [] n_modulation = 2 performances_per_modulation = 50 min_limit_of_log_id = 0 all_notes_stat = [0] * max(log_ids) note_stats = [] def check(): x = _object.location.x y = _object.location.y return (-8.3 < x < 8.3) and (-6.0 < y < 6.0) # init nodes b_nodes.init_for_z_depth_with_noise(count_z_depth_parameters(15, 3, 0)) # main part i_modulation = 0 while min(all_notes_stat ) < min_limit_of_log_id or i_modulation < n_modulation: init_state = init() pcs = complex_sequence.ProbabilisticComplexSequence( init_state, generators, log_ids, probabilities, performances_per_modulation) def snapshot(index): generate_image(i_modulation, index) return res = sequence.handle(pcs, check, snapshot) if not res: pcs.logs_note.pop() journal.append(pcs.logs_note) note_stat = [0] * max(log_ids) for log in pcs.logs_note: note_stat[log - 1] += 1 note_stats.append(note_stat) for log_id in range(len(all_notes_stat)): all_notes_stat[log_id] += note_stat[log_id] i_modulation += 1 i_modulation = 0 for logs_note in journal: save_log_file(i_modulation, logs_note) i_modulation += 1 save_stats_file(note_stats, all_notes_stat) return