def __init__(self, mayaSelection, fileDir, fileStem, startFrame=None, endFrame=None, arbAttrs=None, geoFileOptions=None, boundsWriteMode='all', mayaParent=None): self.mayaSelection = mayaSelection self.mayaParent = mayaParent self.fileDir = fileDir self.fileStem = fileStem self.startFrame = startFrame self.endFrame = endFrame self.arbAttrs = arbAttrs self.geoFileOptions = geoFileOptions self.boundsWriteMode = boundsWriteMode self.childHandlers = [] self.mayaChannelData = [] self.numChannels = 0 self.rangeMaxBoundsList = [] # iterate over the hierachy and create scenegraphXML element to hold data for # any Maya nodes that need to be written out to scenegraphXML # 遍历层次结构并创建scenegraphXML元素来保存需要写入scenegraphXML的任何Maya节点的数据 # create root element for scenegraphXML data # 为scenegraphXML数据创建根元素 self.root = scenegraphXML.ScenegraphRoot() # if required, create channel data handler for animation data # 如果需要,为动画数据创建通道数据处理程序 # if startFrame is not None and endFrame is not None: # 如果startFrame不为None且endFrame不为None chanPath = self.fileStem if self.fileDir is not None: chanPath = os.path.join(self.fileDir, chanPath) if self.isStatic(): frameNo = self.getStaticFrameNo() self.root.channelData = scenegraphXML.ChannelData(frameNo, frameNo) else: self.root.channelData = scenegraphXML.ChannelData( startFrame, endFrame, chanPath) # iterate through the Maya selection list creating a SgXML hierarchy for each # instance and add them to the root SgXML element # 遍历Maya选择列表,为每个实例创建SgXML层次结构并将其添加到根SgXML元素 for curMayaElement in self.mayaSelection: curInstance = self.createSgXMLHierarchy(curMayaElement) self.root.addInstance(curInstance)
def publish(self, settings, item): import scenegraphXML as sgxml import tempfile publisher = self.parent publish_path = item.properties["path"] publish_folder = os.path.dirname(publish_path) self.parent.ensure_folder_exists(publish_folder) assembly = item.properties['name'] try: root = sgxml.ScenegraphRoot() component_list = [] #maya2scenegraphXML.setAssembly([assembly]) for child_item in item.children: abc_path = child_item.properties['path'] component = child_item.properties['name'] matrix = child_item.properties['matrix'] component_ref = sgxml.Reference(name=component, refType='abc', refFile=abc_path) component_ref.setXform(value=matrix) component_list.append(component_ref) root.setInstanceList(component_list) start_frame, end_frame = _find_scene_animation_range() if start_frame and end_frame: fileDir, fileStem = os.path.split(publish_path) if fileStem.endswith('.xml'): fileStem = fileStem[:-4] root.channelData = sgxml.ChannelData(start_frame, end_frame, fileStem) else: root.channelData = sgxml.ChannelData(1001, 1001) root.writeXMLFile(os.path.join(tempfile.gettempdir(), publish_path)) except Exception as e: self.logger.error("Failed to export Geometry: %s" % e) return super(MayaSessionShotScenegraphXMLPublishPlugin, self).publish(settings, item)
def __init__(self, mayaSelection, fileDir, fileStem, startFrame=None, endFrame=None, arbAttrs=None, geoFileOptions=None, boundsWriteMode='all', mayaParent=None): self.mayaSelection = mayaSelection self.mayaParent = mayaParent self.fileDir = fileDir self.fileStem = fileStem self.startFrame = startFrame self.endFrame = endFrame self.arbAttrs = arbAttrs self.geoFileOptions = geoFileOptions self.boundsWriteMode = boundsWriteMode self.childHandlers = [] self.mayaChannelData = [] self.numChannels = 0 self.rangeMaxBoundsList = [] # iterate over the hierachy and create scenegraphXML element to hold data for # any Maya nodes that need to be written out to scenegraphXML # create root element for scenegraphXML data self.root = scenegraphXML.ScenegraphRoot() # if required, create channel data handler for animation data #if startFrame is not None and endFrame is not None: chanPath = self.fileStem if self.fileDir is not None: chanPath = self.fileDir + '/' + chanPath if self.isStatic(): frameNo = self.getStaticFrameNo() self.root.channelData = scenegraphXML.ChannelData(frameNo, frameNo) else: self.root.channelData = scenegraphXML.ChannelData( startFrame, endFrame, chanPath) # iterate through the Maya selection list creating a SgXML hierarchy for each # instance and add them to the root SgXML element for curMayaElement in self.mayaSelection: curInstance = self.createSgXMLHierarchy(curMayaElement) self.root.addInstance(curInstance)
# Copyright (c) 2012 The Foundry Visionmongers Ltd. All Rights Reserved. """ simple_sgxml.py Simple example script using scenegraphXML.py """ import os import tempfile import scenegraphXML as sgxml # declare the ScenegraphRoot root = sgxml.ScenegraphRoot() # declare elements for the hierarchy group1 = sgxml.Group(name="group1") group1.setBounds(value=[-1.0, 1.0, -1.0, 1.0, -1.0, 2.0]) group1.setXform(value=[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) group2 = sgxml.Group(name="group2") group2.setXform(value=[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]) xmlref1 = sgxml.Reference(name='xmlref1', refFile=os.path.join(tempfile.gettempdir(), 'subscene1.xml')) xmlref2 = sgxml.Reference(name='xmlref2', refFile=os.path.join(tempfile.gettempdir(), 'subscene2.xml')) xmlref2.setXform(value=[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 30, 1])