def makeCamPlaneForDrawing(self): drawPlaneGroup = pm.createNode( "transform" ); size = 1024 planeList = pm.polyPlane( w=size,h=size, sx=1,sy=1, n="drawPlane", axis=[0,0,1] ) #print( planeList ) planeXform = planeList[0] planeShape = planeXform.getShape() planeShape.overrideEnabled.set(1) planeShape.overrideShading.set(0) locatorXform = pm.spaceLocator(n="drawPlaneLocator") locatorShape = locatorXform.getShape() locatorShape.localScale.set( [128,128,128] ) camList = pm.camera( name="drawPlaneCam" ) #print( camList ) camXform = camList[0] camXform.tz.set(256) pm.parent( planeXform, locatorXform ) pm.parent( locatorXform, drawPlaneGroup ) pm.parent( camXform, drawPlaneGroup ) pm.orientConstraint( camXform, planeXform, ) ##aimVector=[0,1,0], upVector=[0,0,1] ) ## Look through cam pm.select( camXform ) panel = pm.getPanel( withFocus=True ) pm.mel.eval( "lookThroughSelected 0 " + panel +";") pm.makeLive( planeXform )
def create_locator(name): pm.select(None) global THU_MFT_LOCATOR_MATERIAL_NAME, THU_MFT_LOCATOR_ATTR try: material = pm.PyNode(THU_MFT_LOCATOR_MATERIAL_NAME) except: material = pm.createSurfaceShader( 'lambert', name=THU_MFT_LOCATOR_MATERIAL_NAME)[0] material.color.set((1, 0, 0)) material.transparency.set((0.8, 0.8, 0.8)) loc_name = '%s_%s' % (name, THU_MFT_LOCATOR_ATTR) try: locator_trans = pm.PyNode(loc_name) except: locator_trans = pm.polyPlane(name=loc_name, sw=1, sh=1)[0] pm.sets(material.shadingGroups()[0], edit=True, forceElement=locator_trans) if (not locator_trans.hasAttr(THU_MFT_LOCATOR_ATTR)): locator_trans.addAttr(THU_MFT_LOCATOR_ATTR, dt='string') locator_trans.setAttr(THU_MFT_LOCATOR_ATTR, name) return locator_trans
def create_locator( name ) : pm.select( None ) global THU_MFT_LOCATOR_MATERIAL_NAME, THU_MFT_LOCATOR_ATTR try : material = pm.PyNode( THU_MFT_LOCATOR_MATERIAL_NAME ) except : material = pm.createSurfaceShader( 'lambert', name=THU_MFT_LOCATOR_MATERIAL_NAME )[0] material.color.set( ( 1, 0, 0 ) ) material.transparency.set( ( 0.8, 0.8, 0.8 ) ) loc_name = '%s_%s' % ( name, THU_MFT_LOCATOR_ATTR ) try : locator_trans = pm.PyNode( loc_name ) except : locator_trans = pm.polyPlane( name=loc_name, sw=1, sh=1 )[0] pm.sets( material.shadingGroups()[0], edit=True, forceElement=locator_trans ) if( not locator_trans.hasAttr( THU_MFT_LOCATOR_ATTR ) ) : locator_trans.addAttr( THU_MFT_LOCATOR_ATTR, dt='string' ) locator_trans.setAttr( THU_MFT_LOCATOR_ATTR, name ) return locator_trans
def create_mesh( xml_path, name, locator=None ) : pm.select( None ) tree = et.parse( xml_path ) root_keys = tree.getroot().keys() if( not 'imagePath' in root_keys ) : pm.error( 'The XML file does not appear to be a Texture Packer XML' ) texture_size = ( tree.getroot().get( 'width' ), tree.getroot().get( 'height' ) ) sprite = tree.find( ".//*[@n='%s']" % ( name ) ) material = create_material( xml_path ) if( not len( material.shadingGroups() ) ) : pm.error( 'Material %s is not connected to a Shading Group. Aborting.' ) plane_name = __get_filename_noext( name ) + '_G' if( locator ) : plane_name = '%s_%s' % ( locator.name(), plane_name ) try : plane_trans = pm.PyNode( plane_name ) except : # v = pm.datatypes.Vector( float(sprite.get('w')) / 100.0, float(sprite.get('h')) / 100.0 ) # v = v.normal() w_scale = float(sprite.get('w')) / 100.0 h_scale = float(sprite.get('h')) / 100.0 w_h = w_scale / h_scale h_w = h_scale / w_scale if( w_h > h_w ) : wp = 1.0 / w_h # print wp w_scale = 1.0 h_scale = 1.0 / w_h # print 'w_h', w_scale, h_scale else : hp = 1.0 / h_w # print hp h_scale = 1.0 w_scale = 1.0 / h_w # print w_h, h_w # print 'h_w', w_scale, h_scale plane_trans = pm.polyPlane( name=plane_name, sw=1, sh=1, w=w_scale, h=h_scale )[0] plane_shape = plane_trans.getShape() if( not plane_trans.hasAttr( THU_MFT_SPRITE_ATTR ) ) : plane_trans.addAttr( THU_MFT_SPRITE_ATTR, dt='string' ) plane_trans.setAttr( THU_MFT_SPRITE_ATTR, name.replace( '.png', '' ) ) pm.sets( material.shadingGroups()[0], edit=True, forceElement=plane_trans ) sx = ( float( sprite.get( 'x' ) ) / float( texture_size[0] ) ) sy = 1 - ( float( sprite.get( 'y' ) ) / float( texture_size[1] ) ) sw = ( float( sprite.get( 'w' ) ) / float( texture_size[0] ) ) sh = ( float( sprite.get( 'h' ) ) / float( texture_size[1] ) ) uv_positions = ( ( sx, sy - sh ), ( sx + sw, sy - sh ), ( sx, sy ), ( sx + sw, sy ) ) for uv, uv_position in zip( plane_shape.uvs, uv_positions ) : pm.polyEditUV( uv, r=False, u=uv_position[0], v=uv_position[1] ) if( locator ) : # print locator plane_trans.setParent( locator ) plane_trans.setTranslation( ( 0, 0, 0 ) ) plane_trans.setRotation( ( 0, 0, 0 ) ) plane_trans.setScale( ( 1, 1, 1 ) ) locator_bounds = locator.getBoundingBox() plane_bounds = plane_trans.getBoundingBox() if( plane_bounds.width() > plane_bounds.height() ) : pass else : s = locator_bounds.height() / plane_bounds.height() # plane_trans.setScale( (s, s, s) ) pm.select( plane_trans ) return plane_trans
def create_mesh(xml_path, name, locator=None): pm.select(None) tree = et.parse(xml_path) root_keys = tree.getroot().keys() if (not 'imagePath' in root_keys): pm.error('The XML file does not appear to be a Texture Packer XML') texture_size = (tree.getroot().get('width'), tree.getroot().get('height')) sprite = tree.find(".//*[@n='%s']" % (name)) material = create_material(xml_path) if (not len(material.shadingGroups())): pm.error('Material %s is not connected to a Shading Group. Aborting.') plane_name = __get_filename_noext(name) + '_G' if (locator): plane_name = '%s_%s' % (locator.name(), plane_name) try: plane_trans = pm.PyNode(plane_name) except: # v = pm.datatypes.Vector( float(sprite.get('w')) / 100.0, float(sprite.get('h')) / 100.0 ) # v = v.normal() w_scale = float(sprite.get('w')) / 100.0 h_scale = float(sprite.get('h')) / 100.0 w_h = w_scale / h_scale h_w = h_scale / w_scale if (w_h > h_w): wp = 1.0 / w_h # print wp w_scale = 1.0 h_scale = 1.0 / w_h # print 'w_h', w_scale, h_scale else: hp = 1.0 / h_w # print hp h_scale = 1.0 w_scale = 1.0 / h_w # print w_h, h_w # print 'h_w', w_scale, h_scale plane_trans = pm.polyPlane(name=plane_name, sw=1, sh=1, w=w_scale, h=h_scale)[0] plane_shape = plane_trans.getShape() if (not plane_trans.hasAttr(THU_MFT_SPRITE_ATTR)): plane_trans.addAttr(THU_MFT_SPRITE_ATTR, dt='string') plane_trans.setAttr(THU_MFT_SPRITE_ATTR, name.replace('.png', '')) pm.sets(material.shadingGroups()[0], edit=True, forceElement=plane_trans) sx = (float(sprite.get('x')) / float(texture_size[0])) sy = 1 - (float(sprite.get('y')) / float(texture_size[1])) sw = (float(sprite.get('w')) / float(texture_size[0])) sh = (float(sprite.get('h')) / float(texture_size[1])) uv_positions = ((sx, sy - sh), (sx + sw, sy - sh), (sx, sy), (sx + sw, sy)) for uv, uv_position in zip(plane_shape.uvs, uv_positions): pm.polyEditUV(uv, r=False, u=uv_position[0], v=uv_position[1]) if (locator): # print locator plane_trans.setParent(locator) plane_trans.setTranslation((0, 0, 0)) plane_trans.setRotation((0, 0, 0)) plane_trans.setScale((1, 1, 1)) locator_bounds = locator.getBoundingBox() plane_bounds = plane_trans.getBoundingBox() if (plane_bounds.width() > plane_bounds.height()): pass else: s = locator_bounds.height() / plane_bounds.height() # plane_trans.setScale( (s, s, s) ) pm.select(plane_trans) return plane_trans