def _create(self): #>> Quick links ============================================================================ d_closestInfo = self.d_closestInfo self.paramU = d_closestInfo[ 'parameterU'] #d_closestInfo['normalizedU'] self.paramV = d_closestInfo[ 'parameterV'] #d_closestInfo['normalizedV'] if self.b_attachControlLoc or not self.b_createControlLoc: try: #>>> Follicle ============================================================================ l_follicleInfo = NODES.createFollicleOnMesh( self.mi_targetSurface.mNode) mi_follicleAttachTrans = cgmMeta.asMeta(l_follicleInfo[1], 'cgmObject', setClass=True) mi_follicleAttachShape = cgmMeta.asMeta( l_follicleInfo[0], 'cgmNode') #> Name ---------------------------------------------------------------------------------- mi_follicleAttachTrans.doStore('cgmName', self.mi_obj) mi_follicleAttachTrans.addAttr('cgmTypeModifier', 'attach', lock=True) mi_follicleAttachTrans.doName() #>Set follicle value --------------------------------------------------------------------- mi_follicleAttachShape.parameterU = self.paramU mi_follicleAttachShape.parameterV = self.paramV self.mi_follicleAttachTrans = mi_follicleAttachTrans #link self.mi_follicleAttachShape = mi_follicleAttachShape #link self.mi_obj.connectChildNode(mi_follicleAttachTrans, "follicleAttach", "targetObject") self.md_return["follicleAttach"] = mi_follicleAttachTrans self.md_return[ "follicleAttachShape"] = mi_follicleAttachShape except Exception, error: raise StandardError, "!Attach Follicle! | %s" % (error)
def attach_toShape(obj = None, targetShape = None, connectBy = 'parent'): """ :parameters: obj - transform to attach targetShape(str) - Curve, Nurbs, Mesh connectBy(str) parent - parent to track transform parentGroup - parent to group and have group follow conPoint - just point contraint conPointGroup - pointConstrain group conPointOrientGroup - point/orient constrain group conParentGroup - parent Constrain group None - just the tracker nodes :returns: resulting dat """ try: _str_func = 'attach_toShape' mObj = cgmMeta.validateObjArg(obj,'cgmObject') targetShape = VALID.mNodeString(targetShape) log.debug("targetShape: {0}".format(targetShape)) #Get our data... d_closest = DIST.get_closest_point_data(targetShape, mObj.mNode) log.debug("|{0}| >> jnt: {1} | {2}".format(_str_func,mObj.mNode, d_closest)) #pprint.pprint(d_closest) if d_closest['type'] in ['mesh','nurbsSurface']: log.debug("|{0}| >> Follicle mode...".format(_str_func)) _shape = SHAPES.get_nonintermediate(d_closest['shape'] ) log.debug("_shape: {0}".format(_shape)) l_follicleInfo = NODES.createFollicleOnMesh( _shape ) i_follicleTrans = cgmMeta.asMeta(l_follicleInfo[1],'cgmObject',setClass=True) i_follicleShape = cgmMeta.asMeta(l_follicleInfo[0],'cgmNode') #> Name... i_follicleTrans.doStore('cgmName',mObj) i_follicleTrans.doStore('cgmTypeModifier','surfaceTrack') i_follicleTrans.doName() _trackTransform = i_follicleTrans.mNode #>Set follicle value... if d_closest['type'] == 'mesh': i_follicleShape.parameterU = d_closest['parameterU'] i_follicleShape.parameterV = d_closest['parameterV'] else: i_follicleShape.parameterU = d_closest['normalizedU'] i_follicleShape.parameterV = d_closest['normalizedV'] _res = [i_follicleTrans.mNode, i_follicleShape.mNode] else: log.debug("|{0}| >> Curve mode...".format(_str_func)) #d_returnBuff = distance.returnNearestPointOnCurveInfo(obj,crv) _shape = SHAPES.get_nonintermediate(d_closest['shape'] ) mPOCI = cgmMeta.cgmNode(nodeType = 'pointOnCurveInfo') mc.connectAttr("%s.worldSpace"%_shape,"%s.inputCurve"%mPOCI.mNode) mPOCI.parameter = d_closest['parameter'] mTrack = mObj.doCreateAt() mTrack.doStore('cgmName',mObj) mTrack.doStore('cgmType','surfaceTrack') mTrack.doName() _trackTransform = mTrack.mNode mc.connectAttr("%s.position"%mPOCI.mNode,"%s.t"%_trackTransform) mPOCI.doStore('cgmName',mObj) mPOCI.doName() _res = [mTrack.mNode, mPOCI.mNode] if connectBy is None: return _res elif connectBy == 'parent': mObj.p_parent = _trackTransform return _res elif connectBy == 'conPoint': mc.pointConstraint(_trackTransform, mObj.mNode,maintainOffset = True) return _res elif connectBy == 'conParent': mc.parentConstraint(_trackTransform, mObj.mNode,maintainOffset = True) return _res elif connectBy == 'parentGroup': mGroup = mObj.doGroup(asMeta=True) #_grp = TRANS.group_me(obj,True) #TRANS.parent_set(_grp,_trackTransform) mGroup.p_parent = _trackTransform return _res + [mGroup.mNode] elif connectBy == 'conPointGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.pointConstraint(mLoc.mNode,mGroup.mNode) return _res + [mGroup.mNode] elif connectBy == 'conPointOrientGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.pointConstraint(mLoc.mNode,mGroup.mNode) mc.orientConstraint(mLoc.mNode,mGroup.mNode) return _res + [mGroup.mNode] elif connectBy == 'conParentGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.parentConstraint(mLoc.mNode,mGroup.mNode) return _res + [mGroup.mNode] else: raise NotImplementedError,"|{0}| >>invalid connectBy: {1}".format(_str_func,connectBy) #pprint.pprint(vars()) except Exception,err:cgmGEN.cgmExceptCB(Exception,err)
if self.b_pointAttach: mc.pointConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset=True) else: mc.parentConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset=True) except Exception, error: raise StandardError, "!Groups - no control Loc setup! | %s" % ( error) else: #Setup control loc stuff try: #>>> Follicle ============================================================================ l_follicleInfo = NODES.createFollicleOnMesh( self.mi_targetSurface.mNode) mi_follicleFollowTrans = cgmMeta.asMeta(l_follicleInfo[1], 'cgmObject', setClass=True) mi_follicleFollowShape = cgmMeta.asMeta( l_follicleInfo[0], 'cgmNode') #> Name ---------------------------------------------------------------------------------- mi_follicleFollowTrans.doStore('cgmName', self.mi_obj) mi_follicleFollowTrans.addAttr('cgmTypeModifier', 'follow', lock=True) mi_follicleFollowTrans.doName() #>Set follicle value --------------------------------------------------------------------- mi_follicleFollowShape.parameterU = self.paramU
def attach_toShape(obj=None, targetShape=None, connectBy='parent', driver=None): """ :parameters: obj - transform to attach targetShape(str) - Curve, Nurbs, Mesh connectBy(str) parent - parent to track transform parentGroup - parent to group and have group follow conPoint - just point contraint conPointGroup - pointConstrain group conPointOrientGroup - point/orient constrain group conParentGroup - parent Constrain group None - just the tracker nodes :returns: resulting dat """ try: _str_func = 'attach_toShape' mObj = cgmMeta.validateObjArg(obj, 'cgmObject') mDriver = cgmMeta.validateObjArg(driver, 'cgmObject', noneValid=True) targetShape = VALID.mNodeString(targetShape) log.debug("targetShape: {0}".format(targetShape)) #Get our data... d_closest = DIST.get_closest_point_data(targetShape, mObj.mNode) log.debug("|{0}| >> jnt: {1} | {2}".format(_str_func, mObj.mNode, d_closest)) #pprint.pprint(d_closest) md_res = {} if d_closest['type'] in ['mesh', 'nurbsSurface']: log.debug("|{0}| >> Follicle mode...".format(_str_func)) _shape = SHAPES.get_nonintermediate(d_closest['shape']) log.debug("_shape: {0}".format(_shape)) l_follicleInfo = NODES.createFollicleOnMesh(_shape) i_follicleTrans = cgmMeta.asMeta(l_follicleInfo[1], 'cgmObject', setClass=True) i_follicleShape = cgmMeta.asMeta(l_follicleInfo[0], 'cgmNode') #> Name... i_follicleTrans.doStore('cgmName', mObj) i_follicleTrans.doStore('cgmTypeModifier', 'surfaceTrack') i_follicleTrans.doName() _trackTransform = i_follicleTrans.mNode #>Set follicle value... if d_closest['type'] == 'mesh': i_follicleShape.parameterU = d_closest['parameterU'] i_follicleShape.parameterV = d_closest['parameterV'] else: i_follicleShape.parameterU = d_closest['normalizedU'] i_follicleShape.parameterV = d_closest['normalizedV'] _res = [i_follicleTrans.mNode, i_follicleShape.mNode] md_res['mFollicle'] = i_follicleTrans md_res['mFollicleShape'] = i_follicleShape else: log.debug("|{0}| >> Curve mode...".format(_str_func)) #d_returnBuff = distance.returnNearestPointOnCurveInfo(obj,crv) _shape = SHAPES.get_nonintermediate(d_closest['shape']) mPOCI = cgmMeta.cgmNode(nodeType='pointOnCurveInfo') mc.connectAttr("%s.worldSpace" % _shape, "%s.inputCurve" % mPOCI.mNode) mPOCI.parameter = d_closest['parameter'] mTrack = mObj.doCreateAt() mTrack.doStore('cgmName', mObj) mTrack.doStore('cgmType', 'surfaceTrack') mTrack.doName() _trackTransform = mTrack.mNode mc.connectAttr("%s.position" % mPOCI.mNode, "%s.t" % _trackTransform) mPOCI.doStore('cgmName', mObj) mPOCI.doName() _res = [mTrack.mNode, mPOCI.mNode] if mDriver: if d_closest['type'] in ['nurbsSurface']: mFollicle = i_follicleTrans mFollShape = i_follicleShape minU = ATTR.get(_shape, 'minValueU') maxU = ATTR.get(_shape, 'maxValueU') minV = ATTR.get(_shape, 'minValueV') maxV = ATTR.get(_shape, 'maxValueV') mDriverLoc = mDriver.doLoc() mc.pointConstraint(mDriver.mNode, mDriverLoc.mNode) #mLoc = mObj.doLoc() str_baseName = "{0}_to_{1}".format(mDriver.p_nameBase, mObj.p_nameBase) mPlug_normalizedU = cgmMeta.cgmAttr( mDriverLoc.mNode, "{0}_normalizedU".format(str_baseName), attrType='float', hidden=False, lock=False) mPlug_sumU = cgmMeta.cgmAttr(mDriverLoc.mNode, "{0}_sumU".format(str_baseName), attrType='float', hidden=False, lock=False) mPlug_normalizedV = cgmMeta.cgmAttr( mDriverLoc.mNode, "{0}_normalizedV".format(str_baseName), attrType='float', hidden=False, lock=False) mPlug_sumV = cgmMeta.cgmAttr(mDriverLoc.mNode, "{0}_sumV".format(str_baseName), attrType='float', hidden=False, lock=False) #res_closest = DIST.create_closest_point_node(mLoc.mNode, mCrv_reparam.mNode,True) log.debug("|{0}| >> Closest info {1}".format(_str_func, _res)) srfNode = mc.createNode('closestPointOnSurface') mc.connectAttr("%s.worldSpace[0]" % _shape, "%s.inputSurface" % srfNode) mc.connectAttr("%s.translate" % mDriverLoc.mNode, "%s.inPosition" % srfNode) #mc.connectAttr("%s.position" % srfNode, "%s.translate" % mLoc.mNode, f=True) #mClosestPoint = cgmMeta.validateObjArg(srfNode,setClass=True) #mClosestPoint.doStore('cgmName',mObj) #mClosestPoint.doName() log.debug("|{0}| >> paramU {1}.parameterU | {2}".format( _str_func, srfNode, ATTR.get(srfNode, 'parameterU'))) log.debug("|{0}| >> paramV {1}.parameterV | {2}".format( _str_func, srfNode, ATTR.get(srfNode, 'parameterV'))) l_argBuild = [] mPlug_uSize = cgmMeta.cgmAttr(mDriverLoc.mNode, "{0}_uSize".format(str_baseName), attrType='float', hidden=False, lock=False) mPlug_vSize = cgmMeta.cgmAttr(mDriverLoc.mNode, "{0}_vSize".format(str_baseName), attrType='float', hidden=False, lock=False) l_argBuild.append("{0} = {1} - {2}".format( mPlug_vSize.p_combinedName, maxV, minV)) l_argBuild.append("{0} = {1} - {2}".format( mPlug_uSize.p_combinedName, maxU, minU)) l_argBuild.append("{0} = {1} + {2}.parameterU".format( mPlug_sumU.p_combinedName, minU, srfNode)) l_argBuild.append("{0} = {1} / {2}".format( mPlug_normalizedU.p_combinedName, mPlug_sumU.p_combinedName, mPlug_uSize.p_combinedName)) l_argBuild.append("{0} = {1} + {2}.parameterV".format( mPlug_sumV.p_combinedName, minV, srfNode)) l_argBuild.append("{0} = {1} / {2}".format( mPlug_normalizedV.p_combinedName, mPlug_sumV.p_combinedName, mPlug_vSize.p_combinedName)) for arg in l_argBuild: log.debug("|{0}| >> Building arg: {1}".format( _str_func, arg)) NODEFACTORY.argsToNodes(arg).doBuild() ATTR.connect(mPlug_normalizedU.p_combinedShortName, '{0}.parameterU'.format(mFollShape.mNode)) ATTR.connect(mPlug_normalizedV.p_combinedShortName, '{0}.parameterV'.format(mFollShape.mNode)) md_res['mDriverLoc'] = mDriverLoc elif d_closest['type'] in ['curve', 'nurbsCurve']: mDriverLoc = mDriver.doLoc() mc.pointConstraint(mDriver.mNode, mDriverLoc.mNode) _resClosest = DIST.create_closest_point_node( mDriverLoc.mNode, _shape, True) _loc = _resClosest[0] md_res['mDriverLoc'] = mDriverLoc md_res['mDrivenLoc'] = cgmMeta.asMeta(_loc) md_res['mTrack'] = mTrack else: log.warning( cgmGEN.logString_msg( _str_func, "Shape type not currently supported for driver setup. Type: {0}" .format(d_closest['type']))) #if connectBy is None: #return _res if connectBy == 'parent': mObj.p_parent = _trackTransform elif connectBy == 'conPoint': mc.pointConstraint(_trackTransform, mObj.mNode, maintainOffset=True) elif connectBy == 'conParent': mc.parentConstraint(_trackTransform, mObj.mNode, maintainOffset=True) elif connectBy == 'parentGroup': mGroup = mObj.doGroup(asMeta=True) #_grp = TRANS.group_me(obj,True) #TRANS.parent_set(_grp,_trackTransform) mGroup.p_parent = _trackTransform _res = _res + [mGroup.mNode] elif connectBy == 'conPointGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.pointConstraint(mLoc.mNode, mGroup.mNode) _res = _res + [mGroup.mNode] elif connectBy == 'conPointOrientGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.pointConstraint(mLoc.mNode, mGroup.mNode) mc.orientConstraint(mLoc.mNode, mGroup.mNode) _res = _res + [mGroup.mNode] elif connectBy == 'conParentGroup': mLoc = mObj.doLoc() mLoc.p_parent = _trackTransform mGroup = mObj.doGroup(asMeta=True) mc.parentConstraint(mLoc.mNode, mGroup.mNode) _res = _res + [mGroup.mNode] elif connectBy is None: pass else: raise NotImplementedError, "|{0}| >>invalid connectBy: {1}".format( _str_func, connectBy) if md_res: return _res, md_res return _res #pprint.pprint(vars()) except Exception, err: cgmGEN.cgmExceptCB(Exception, err)