Example #1
0
def fromBlenderToGeneticInstance(tree_creator, genetic_instance):
    """ Writes the current Tree Creator parameters to the GeneticInstance """

    # LSystem part
    genetic_instance.lsystem.clear()
    genetic_instance.lsystem.setIterations(tree_creator.iterations)

    # NOTE: it is important that the defines are created before the productions or the axioms, so they can be used by them
    for (def_name,def_value) in iterateOverDefines(tree_creator):
        if not getattr(tree_creator,def_name) is "":
            genetic_instance.lsystem.addGlobalDefine(getattr(tree_creator,def_name),getattr(tree_creator,def_value))

    genetic_instance.lsystem.setAxiomFromString(tree_creator.axiom)

    for (namep,namec,names) in iterateOverProductions(tree_creator):
        if not getattr(tree_creator,namep) is "" and not getattr(tree_creator,namep) is "":
            rule = getattr(tree_creator,namep)+":"+getattr(tree_creator,namec)+"->"+getattr(tree_creator,names)
            genetic_instance.lsystem.addProductionFromString(rule)

    # Turtle parameters part
    tp = genetic_instance.turtleParameters
    tp.branch_radius = tree_creator.defaultRadius
    tp.tropism_susceptibility = tree_creator.tropism_susceptibility
    tp.use_canopy = tree_creator.canopy
    tp.details_scale = tree_creator.details_scale
    tp.trunk_material_choice = DetailsHandler.indexOfMaterial(tree_creator.trunk_material)
    tp.leaf_material_choice = DetailsHandler.indexOfMaterial(tree_creator.leaf_material)
    tp.leaf_choice =  DetailsHandler.indexOfLeafModel(tree_creator.leaf_object_name)
    tp.bulb_choice =  DetailsHandler.indexOfBulbModel(tree_creator.bulb_object_name)
    tp.flower_choice =  DetailsHandler.indexOfFlowerModel(tree_creator.flower_object_name)
    tp.fruit_choice =  DetailsHandler.indexOfFruitModel(tree_creator.fruit_object_name)