def saveLights(self):
# We'll now save the lights down to a JSON file that can be shared as a preset
# The properties dictionary will hold all the light properties to save down
properties = {}
# First lets get all the light widgets that exist in our manager
for lightWidget in self.findChildren(LightWidget):
# For each widget we can get its' light object
light = lightWidget.light
# Then we need to get its transform node
transform = light.getTransform()
# Finally we add it to the dictionary.
# The key will be the name of the transform which we get by converting the node to a string
# Then we simply query the attributes of the light that we want to save down
properties[str(transform)] = {
'translate': list(transform.translate.get()),
'rotation': list(transform.rotate.get()),
'lightType': pm.objectType(light),
'intensity': light.intensity.get(),
'color': light.color.get()
}
# We fetch the light manager directory to save in
directory = self.getDirectory()
# We then construct the name of the lightFile to save
# We'll be using time.strftime to construct a name using the current time
# %m%d will give 0701 for July 1st (month and day)
# so we'd end up with a name like lightFile_0701.json stored in our directory
lightFile = os.path.join(directory, 'lightFile_%s.json' % time.strftime('%m%d'))
# Next we open the file to write
with open(lightFile, 'w') as f:
# Then we use json to write out our file to this location
json.dump(properties, f, indent=4)
# A helpful logger call tells us where the file was saved to.
logger.info('Saving file to %s' % lightFile)
lightManager2016Below.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录