Reading/Writing a variation table
import Atoms
import AtomsCore
variations = Atoms.loadVariationFromFile("C:\\maya\\projects\\default\\assets\\archer_cloth\\variations.json")
#you can read also from a string with Atoms.loadVariationFromString
agent_types = variations.getAgentTypeNames()
for agent_type_name in agent_types:
agent_variations = variations.getAgentTypeVariation(agent_type_name)
# get all geos
for geo_name in agent_variations.getGeometryNames():
geo_data = agent_variations.getGeometry(geo_name)
geo_file = geo_data.getGeometryFile()
geo_filter = geo_data.getGeometryFilter()
print("Geometry: {} File: {} Filter: {}".format(geo_name, geo_file, geo_filter))
#get all materials
for material_name in agent_variations.getMaterialNames():
material_data = agent_variations.getMaterial(material_name)
material_file = material_data.getMaterialFile()
print("Material: {} File: {}".format(material_name, material_file))
for diffuse_id in range(material_data.getDiffuseSlotSize()):
diffuse_file = material_data.getDiffuseFile(diffuse_id)
diffuse_color = material_data.getDiffuseColor(diffuse_id)
print("\tDiffuse {} color {} {} {} File {}".format(diffuse_id, diffuse_color.getRed(), diffuse_color.getGreen(), diffuse_color.getBlue(), diffuse_file))
# iterate over each variation
for variation_name in agent_variations.getGroupNames():
variation_group = agent_variations.getGroup(variation_name)
print("Variation: {}".format(variation_name))
for comb_id in range(variation_group.numCombinations()):
combination = variation_group.getCombinationAtIndex(comb_id)
print("\tGeom: {} Material: {}".format(combination[0], combination[1]))
#You need to modify the variation table and save to disk using
#variations.writeToFile("C:\\maya\\projects\\default\\assets\\archer_cloth\\new_variations.json")
#or use variations.toString() to serialize it to a stringimport Atoms
import Atoms.ui.constants
variations = Atoms.Variations()
atv = Atoms.AgentTypeVariation()
varGeo1 = Atoms.VariationGeometry()
varGeo1.setGeometryFile("${ATOMS_DATA}/variations/geometries/atomsRobot/robot1_body.geos")
varGeo1.setGeometryFilter('*')
atv.setGeometry("body",varGeo1)
varGeo2 = Atoms.VariationGeometry()
varGeo2.setGeometryFile("${ATOMS_DATA}/variations/geometries/atomsRobot/robot1_head.geos")
atv.setGeometry("head",varGeo2)
material1 = Atoms.VariationMaterial()
material1.setMaterialFile("")
atv.setMaterial("robot1_material",material1)
geoGroup = Atoms.VariationGroup(atv)
geoGroup.addCombination("body","robot1_material")
geoGroup.addCombination("head","robot1_material")
atv.setGroup("Robot1", geoGroup)
atv.setLookFile("${ATOMS_DATA}/variations/materials/atomsRobot/lookFile.ass")
variations.setAgentTypeVariation("atomsRobot", atv)
variations.writeToFile("G:/myvariations.json")