def zProxySelectEvent_OnEvent(ctxt): # get thhe change mode, ignore removed events # changeMode = ctxt.GetAttribute('ChangeType') if changeMode == 1: return # step through all the items in the selection # sel = dispatch('XSI.Collection') sel.AddItems(xsi.selection) for item in sel: # skip anything other than an object selection # if item.Type != 'polymsh' and item.Type != 'surfmsh': continue # get the property # prop = item.Properties('zProxySelect') # skip over the object if the prop is not found # if not prop: continue prop = dispatch(prop) # get the item list # for target in prop.Target.Value.split(','): targetObject = prop.Model.FindChild(target) # skip if the object isn't found # if not targetObject: log('Unable to locate "%s"' % targetObject, c.siWarning) continue # select it # if not targetObject.Properties('zProxySelect'): targetObject.Selected = True # deselect the original object # if prop.Deselect.Value: item.Selected = False
def zApplyProxySelect_Execute(objects, inspect): # make sure we have some objects # if not objects.Count: log('zProxySelect: No objects given.', c.siWarning) return False # create an output collection # col = dispatch('XSI.Collection') # step through the objects collection # for item in objects: # add the property # prop = item.Properties('zProxySelect') if not prop: prop = item.AddProperty('zProxySelect', False) prop = dispatch(prop) else: log('"%s" all ready has a zProxySelect property. Skipping.' % \ item.FullName, c.siWarning) # add it to the collection # col.Add(prop) # inspect the collection # if inspect: xsi.InspectObj(col, None, 'zProxySelects', c.siFollow) # return the collection # return col
def zProxySelectMenu_Init(ctxt): ''' !! Doesn't work when anchored to the select menu ''' menu = ctxt.Source # Submenu # # sub = menu.AddItem('zProxySelect', c.siMenuItemSubmenu) # add commands to enable and disable the event # enable = menu.AddCommandItem("Enable", "zEnableProxySelect") enable = dispatch(enable) disable = menu.AddCommandItem("Disable", "zDisableProxySelect") disable = dispatch(disable) # get the state of the event # proxyEnabled = bool(1-int(xsi.EventInfos('zProxySelectEvent').Mute)) if proxyEnabled: enable.Enabled = False disable.Enabled = True else: enable.Enabled = True disable.Enabled = False menu.AddSeparatorItem() menu.AddCommandItem('Apply', 'zApplyProxySelect')
def zProxySelect_Pick_OnClicked(): prop = PPG.Inspected(0) # pick elements # picked = dispatch('XSI.Collection') while True: picker = xsi.PickElement(None, 'Pick Target Items', 'Pick Target Items') # catch right clicks # if not picker[0]: break # make sure there is no proxy selector on the object # if picker[2].Properties('zProxySelect'): log('Unable to add "%s" to item list. ' % picker[2].FullName + \ 'All ready has zProxySelect item.\nWould cause a undesired ' + \ 'behavior', c.siWarning) continue # add picked items to the selection # picked.Add(picker[2]) # exit if we don't have any items # if not picked.Count: log('Canceled.', c.siWarning) return False # store the names # pickedString = '' for item in picked: pickedString += item.Name + ',' pickedString = pickedString[:-1] prop.Target.Value = pickedString
def zLoadCharacterPoseGUI_PickPath_OnClicked(): # get the ppg # prop = PPG.Inspected(0) prop = dispatch(prop) # get the initial directories # init_dir = xsi.ActiveProject.Path init_file = '' if prop.PosePath.Value: init_dir = os.path.dirname(prop.PosePath.Value) init_file = os.path.basename(prop.PosePath.Value) # get a file browser # fb = XSIUIToolkit.FileBrowser fb.DialogTitle = "Select the Pose (.zpose.xml)..." fb.InitialDirectory = init_dir fb.FileBaseName = init_file fb.Filter = "Zoogloo Pose Shape (*.xml)|*.xml|All Files (*.*)|*.*||" fb.ShowOpen() # get the filename # if not fb.FilePathName: return False # set the value # prop.PosePath.Value = fb.FilePathName
def SetCenterVectorFromNode(self, XSINode): '''Set the center vector from the global transform of an XSI node''' # dispatch the node # XSINode = dispatch(XSINode) log('Set Center Reference from Node: %s' % XSINode, c.siVerbose) v = XSIMath.CreateVector3() XSINode.Kinematics.Global.Transform.GetTranslation(v) self.centerVector = v
def zSaveCharacterPoseGUI_PickSet_OnClicked(): prop = PPG.Inspected(0) prop = dispatch(prop) picker = xsi.PickElement(c.siPropertyFilter, 'Pick Character Set') if not picker[0]: log('Cancelled.') return False # set the value # prop.CharacterSet.Value = picker[2].FullName
def zPickWalk_Execute(direction, addToSelection): # cache the selection # sel = dispatch('XSI.Collection') sel.AddItems(xsi.selection) # create collections to hold selects # col_sel = dispatch('XSI.Collection') # step through each item in the selection # for item in sel: # get the property # prop = item.Properties('zPickWalk') # skip over the object if the prop is not found # if not prop: continue # do the dispatch hack # prop = dispatch(prop) # get the target name # targetName = prop.Parameters(direction).Value # skip if there are no targets # if not targetName: continue # find the node # targetObject = prop.Model.FindChild(targetName) # skip if the object isn't found # if not targetObject: log('Unable to locate "%s"' % targetObject, c.siWarning) continue # select it # # targetObject.Selected = True col_sel.Add(targetObject) # deselect the original object # # if not addToSelection: # # item.Selected = False # if we are adding to the selection keep the original item # if addToSelection: col_sel.Add(item) # use SelectObj command to trigger any transform setups, they are ignored # when going through the object model xsi.SelectObj(col_sel)
def doc2pdf (input, output): w=dispatch ("word.application") try: #open a file doc=w.documents.open (input, readonly=1) #Convert files doc.exportasfixedformat (output, constants.wdexportformatpdf, item=constants.wdexportdocumentwithmarkup, createbookmarks=constants.wdexportcreateheadingbookmarks) return true except: return false finally: w.quit (constants.wddonotsavechanges)
def zPoserLoadGUI_UpdateModel_OnClicked(): ppg = PPG.Inspected(0) ppg = dispatch(ppg) # get the model from the selection # if not xsi.selection.Count: log('Nothing selected.', c.siError) return False if xsi.selection(0).type == '#model': ppg.ModelName.Value = xsi.selection(0).Name else: ppg.ModelName.Value = xsi.selection(0).Model.Name
def zSaveCharacterPoseGUI_PickPath_OnClicked(): # get the ppg # prop = PPG.Inspected(0) prop = dispatch(prop) # get the current path # path_current = xsi.ActiveProject.Path if prop.PosePath.Value: path_current = prop.PosePath.Value # folder picker # folder = XSIUIToolkit.PickFolder(path_current, 'Pick Output folder...') if folder: prop.PosePath.Value = folder
def zPickWalkInstall_Execute(): # create a collection to hold the properties # col = dispatch('XSI.Collection') # step through the selection # for item in xsi.selection: # get or create the property # prop = item.Properties('zPickWalk') if not prop: prop = item.AddProperty('zPickWalk') # add it to the collection # col.Add(prop) # inspect the properties # xsi.InspectObj(col, '', '', c.siLockAndForceNew)
def walkProp(Prop): # get the nested properties # nested = Prop.NestedObjects # skip if there is nothing there # if not nested.Count: return # step through the nested items # for item in nested: # catch the properties # if item.type == 'customparamset': prop = dispatch(item) log('SubSet: %s' % prop.FullName, c.siVerbose) # walk through the prop # walkProp(prop) else: # add to the keyable parameters list # all_params.append(item.MasterParameter)
def zPoserSaveGUI_Translation_OnChanged(): ppg = PPG.Inspected(0) ppg = dispatch(ppg) if not ppg.Translation.Value: ppg.PosX.ReadOnly = True ppg.PosY.ReadOnly = True ppg.PosZ.ReadOnly = True else: ppg.PosX.ReadOnly = False ppg.PosY.ReadOnly = False ppg.PosZ.ReadOnly = False # draw the layout # zPoserGUI_DrawLayout( ppg.PPGLayout, showPos=ppg.Translation.Value, showRot=ppg.Rotation.Value, showScl=ppg.Scale.Value ) PPG.Refresh()
def zTailCurve_Define(ctxt): prop = ctxt.Source prop.AddParameter3("Segments", c.siUInt2, 6, 1, 20) # prop.AddParameter3("IkCons", c.siUInt2, 4, 3, 10) fcv = prop.AddFCurveParameter("Falloff").Value fcv = dispatch(fcv) fcv.BeginEdit() fcv.RemoveKeys() fcv.AddKey(0,0) fcv.AddKey(100,100) fcv.Keys(0).RightTanY = 20 fcv.Keys(0).RightTanX = 20 fcv.Keys(1).LeftTanY = -20 fcv.Keys(1).LeftTanX = -20 # lock the key times and values # fcv.EndEdit() return True
def zBuildTailRig_Execute(curve, conSize, basename): # make sure it has the property # prop = curve.Properties('zTailCurve') if not prop: msg = 'Property "zTailCurve" not found on "%s"' % curve log(msg, c.siError) raise zTailError, msg prop = dispatch(prop) # make sure the scale is one # vScale = XSIMath.CreateVector3() curve.Kinematics.Global.Transform.GetScaling(vScale) vUnit = XSIMath.CreateVector3(1,1,1) if vScale.Length() != vUnit.Length(): msg = 'Scale of curve "%s" must be 1.' % curve log(msg, c.siError) raise zTailError, msg # make sure we have 4 or more points on the curve # if curve.ActivePrimitive.Geometry.Points.Count < 4: msg = 'Generating curves must have at least 4 points.' log(msg, c.siError) raise zTailError, msg # get the vars # segments = prop.Segments.Value # IkCons = prop.IkCons.Value fcv = prop.Falloff.Value # create a new output class # outClass = zTailClass() # get the geometry object # geom = curve.ActivePrimitive.Geometry # get the curve object # crv = geom.Curves(0) # get the global position # vGlobal = XSIMath.CreateVector3() curve.Kinematics.Global.Transform.GetTranslation(vGlobal) #------------------------------------------------------------------------- # create a node stack # main_node = xsi.ActiveSceneRoot.AddNull('%s_Bunch' % basename) dnt_node = main_node.AddNull('%s_DoNotTouch' % basename) skel_node = main_node.AddNull('%s_Sekelton' % basename) con_node = main_node.AddNull('%s_Controls' % basename) main_node.primary_icon.Value = 0 main_node.Properties('Visibility').Parameters('viewvis').Value = False main_node.Properties('Visibility').Parameters('rendvis').Value = False dnt_node.primary_icon.Value = 0 dnt_node.Properties('Visibility').Parameters('viewvis').Value = False dnt_node.Properties('Visibility').Parameters('rendvis').Value = False skel_node.primary_icon.Value = 0 skel_node.Properties('Visibility').Parameters('viewvis').Value = False skel_node.Properties('Visibility').Parameters('rendvis').Value = False con_node.primary_icon.Value = 0 con_node.Properties('Visibility').Parameters('viewvis').Value = False con_node.Properties('Visibility').Parameters('rendvis').Value = False #------------------------------------------------------------------------- # build a curve to shrink on the spline ik curve # # draw 2 curves, one for the control curve and one to shrink on top # crvLength = crv.Length pointCount = geom.Points.Count segmentLength = 1.0/(geom.Points.Count-1)*crvLength vCrv = XSIMath.CreateVector3() # build a point list # pointList = [0,0,0,1] for p in xrange(pointCount-1): pointList += [0, segmentLength*(p+1), 0, 1] # since the points are drawn through the control curve, add a bunch of points # to lessen the deviation from the original curve pointList2 = [0,0,0,1] count = 25 for p in xrange(count): segmentLength2 = 1.0/(count)*crvLength pointList2 += [0, segmentLength2*(p+1), 0, 1] # draw the curves # controlCurve = dnt_node.AddNurbsCurve(pointList) controlCurve.Name = '%s_SourceCurve' % basename shrinkCurve = dnt_node.AddNurbsCurve(pointList2) shrinkCurve.Name = '%s_ShrunkCurve' % basename # turn off the selectability of the source curve # controlCurve.Properties('Visibility').selectability.Value = 0 shrinkCurve.Properties('Visibility').viewvis.Value = 0 # put them in the out class # outClass.controlCurve = controlCurve outClass.shrinkCurve = shrinkCurve # shrink wrap the curve # op = xsi.ApplyOp('CrvDeform', '%s;%s' % (shrinkCurve.FullName, controlCurve.FullName), c.siNode, c.siPersistentOperation) # realign the control curve # controlCurve.ActivePrimitive.Geometry.Points.PositionArray = \ geom.Points.PositionArray #--------------------------------------# # create control clusters on the control curve # controlGeom = controlCurve.ActivePrimitive.Geometry for p in xrange(controlGeom.Points.Count): # create the cluster # cls = controlGeom.AddCluster(c.siVertexCluster, '%s%s_Cls' % (basename, p), [p]) # create the con # conStack = xsi.zCreateCon(con_node, '%sIk%s' % (basename, p), 'Mid', 0, 2*conSize, 1, 1, 0) # add a transform setup # ts = conStack(2).AddProperty('Transform Setup', False) ts = dispatch(ts) ts.tool.Value = 4 ts.translate.Value = 2 ts.xaxis.Value = True ts.yaxis.Value = True ts.zaxis.Value = True # align the stack to the point # pa = controlGeom.Points.PositionArray trans = conStack(1).Kinematics.Global.Transform localPointVector = XSIMath.CreateVector3(pa[0][p], pa[1][p], pa[2][p]) localPointVector.AddInPlace(vGlobal) trans.SetTranslation(localPointVector) conStack(1).Kinematics.Global.Transform = trans # create the cluster centers # cls.CenterReference = conStack(3) # put the stacks in the out class # outClass.controls.append(conStack(1)) #----------------------------------------# # draw a quide line through the controls # pointList = [] for con in outClass.controls: v = XSIMath.CreateVector3() con.Kinematics.Global.Transform.GetTranslation(v) pointList += [v.X, v.Y, v.Z, 1] guideCurve = dnt_node.AddNurbsCurve(pointList, None, False, 1) guideCurve.Name = '%s_CurveHull' % basename guideCurve.Properties('Visibility').selectability.Value = False outClass.guideCurve = guideCurve # create clusters at each center # guideClusters = dnt_node.AddNull('%s_HullClusters' % basename) guideClusters.primary_icon.Value = 0 guideClusters.Properties('Visibility').Parameters('viewvis').Value = False guideClusters.Properties('Visibility').Parameters('rendvis').Value = False for p in xrange(guideCurve.ActivePrimitive.Geometry.Points.Count): # create the cluster # cls = guideCurve.ActivePrimitive.Geometry.AddCluster(c.siVertexCluster, '%sHull%s_Cls' % (basename, p), [p]) # create a cluster center # clsCenter = guideClusters.AddNull('%s_HullClsCenter%s' % (basename, p)) clsCenter.primary_icon.Value = 0 clsCenter.Properties('Visibility').Parameters('viewvis').Value = False clsCenter.Properties('Visibility').Parameters('rendvis').Value = False # constrain it to the controller # clsCenter.Kinematics.AddConstraint('Pose', outClass.controls[p].Children(0).Children(0), False) # create the cluster centers # cls.CenterReference = clsCenter # add to the outClass # outClass.guideClusterGroup = guideClusters #------------------------------------------------------------------------- # build the skeleton # chainRootIk = None chainRootFk = None chainRootSkel = None vPrev = None wPercPrev = None shrinkCrv = shrinkCurve.ActivePrimitive.Geometry.Curves(0) weighted_percs = [0.0] * (segments+1) # null_stack = [] for i in xrange(segments+1): # start # uValue = float(i)/float(segments) perc = uValue*100 # get the weighted percentage # wPerc = fcv.Eval(perc) # store the weighted percentage # weighted_percs[i] = wPerc # start # if i == 0: # get the current positon on the curve # v = shrinkCrv.EvaluatePositionFromPercentage(0)[0] # add the global transform to the current position on curve # v.AddInPlace(vGlobal) # store it as the previous position vector # vPrev = v log('Start: 0%% (w:%0.2f%%) Pos:<%0.2f, %0.2f, %0.2f>' % \ (wPerc, v.X, v.Y, v.Z), c.siVerbose) else: # get the current positon on the curve # v = shrinkCrv.EvaluatePositionFromPercentage(wPerc)[0] # add the global transform to the current position on curve # v.AddInPlace(vGlobal) log('%d: %0.2f%% (w:%0.2f%%) Pos:<%0.2f, %0.2f, %0.2f>' % \ (i,perc,wPerc,v.X, v.Y, v.Z), c.siVerbose) # add the chain root if it doesn't exist # if not chainRootSkel: #------------------------------------------------------------- # draw the ik chain root # chainRootIk = dnt_node.Add2DChain( vPrev, v, XSIMath.CreateVector3(-1,0,0), c.si2DChainNormalRadian ) chainRootIk = dispatch(chainRootIk) # constrain the root to the path # cns = chainRootIk.Kinematics.AddConstraint('Path', shrinkCurve, False) # rename # chainRootIk.Name = '%sIk_Root' % basename chainRootIk.Bones(0).Name = '%s1Ik_Bone' % basename chainRootIk.effector.Name = '%sIk_Eff' % basename #------------------------------------------------------------- # draw the fk chain root # chainRootFk = con_node.Add2DChain( vPrev, v, XSIMath.CreateVector3(-1,0,0), c.si2DChainNormalRadian ) chainRootFk = dispatch(chainRootFk) # rename # chainRootFk.Name = '%sFk_Root' % basename chainRootFk.Bones(0).Name = '%s1Fk_Con' % basename chainRootFk.effector.Name = '%sFk_Eff' % basename #------------------------------------------------------------- # draw the skeleton chain root # chainRootSkel = skel_node.Add2DChain( vPrev, v, XSIMath.CreateVector3(-1,0,0), c.si2DChainNormalRadian ) chainRootSkel = dispatch(chainRootSkel) # rename # chainRootSkel.Name = '%s_Root' % basename chainRootSkel.Bones(0).Name = '%s1_Bone' % basename chainRootSkel.effector.Name = '%s_Eff' % basename #------------------------------------------------------------- # create fk switch on chain root # propAnim = chainRootFk.AddProperty('CustomProperty', False, 'zAnim') propAnim = dispatch(propAnim) fkswitch = propAnim.AddParameter3('Fk_Ik', c.siFloat, 1, 0, 1) twist = propAnim.AddParameter3('Twist', c.siFloat, 0, -90, 90) # add to the out class # outClass.zAnim = propAnim # turn on the secondary display for the ik bone # bone_ik = dispatch(chainRootIk.bones(0)) bone_ik.shadow_icon.Value = 1 bone_ik.shadow_colour_custom.Value = 1 bone_fk = dispatch(chainRootFk.bones(0)) bone_fk.shadow_icon.Value = 1 bone_fk.shadow_colour_custom.Value = 1 # add a proxy param to the fk bone for the ik/fk slider # prop = bone_fk.AddProperty('CustomProperty', False, 'zAnim') prop = dispatch(prop) prop.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') propDi = bone_fk.AddProperty('CustomProperty', False, 'DisplayInfo_zAnim') propDi = dispatch(propDi) propDi.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') # add a transform setup to the bone # ts = bone_fk.AddProperty('Transform Setup', False) ts = dispatch(ts) ts.tool.Value = 3 ts.rotate.Value = 3 ts.xaxis.Value = True ts.yaxis.Value = True ts.zaxis.Value = True # all other bones # else: # add the bone # boneIk = chainRootIk.AddBone(v) boneFk = chainRootFk.AddBone(v) boneSkel = chainRootSkel.AddBone(v) # rename # segment_number = boneSkel.root.Bones.Count boneIk.Name = '%s%sIk_Bone' % (basename, segment_number) boneFk.Name = '%s%sFk_Con' % (basename, segment_number) boneSkel.Name = '%s%s_Bone' % (basename, segment_number) # turn on the secondary display for the boneIk # boneIk.shadow_icon.Value = 1 boneIk.shadow_colour_custom.Value = 1 boneFk.shadow_icon.Value = 1 boneFk.shadow_colour_custom.Value = 1 # add a proxy param to the fk bone for the ik/fk slider # prop = boneFk.AddProperty('CustomProperty', False, 'zAnim') prop = dispatch(prop) prop.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') propDi = boneFk.AddProperty('CustomProperty', False, 'DisplayInfo_zAnim') propDi = dispatch(propDi) propDi.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') # add a transform setup to the fk bone # ts = boneFk.AddProperty('Transform Setup', False) ts = dispatch(ts) ts.tool.Value = 3 ts.rotate.Value = 3 ts.xaxis.Value = True ts.yaxis.Value = True ts.zaxis.Value = True # store the previously weighted percentage # wPercPrev = wPerc #------------------------------------------------------------------------- # constraint the ik chain to the path for i in xrange(chainRootIk.Bones.Count): # add the path constraint # cns = chainRootIk.Bones(i).Kinematics.AddConstraint('Path', shrinkCurve, False) cns = dispatch(cns) cns.perc.Value = weighted_percs[i] # constrain the effector # cns = chainRootIk.effector.Kinematics.AddConstraint('Path', shrinkCurve, False) cns = dispatch(cns) cns.perc.Value = 100 #------------------------------------------------------------------------- # create a twist heirarchy # twisters = dispatch('XSI.Collection') parent = dnt_node for i in xrange(chainRootIk.Bones.Count): # create the twist node # twist = parent.AddNull('%s%s_Twist' % (basename, i)) # pose constrain it to the corresponding bone # cns = twist.Kinematics.AddConstraint('Pose', chainRootIk.Bones(i), False) cns = dispatch(cns) # add the twist # cns.rotx.AddExpression( '%s * %s / %s' % (outClass.zAnim.Twist.FullName, i+1, segments) ) # make the current twist the new parent # parent = twist # add it to the collection # twisters.Add(twist) # turn off the null icon # twist.primary_icon.Value = 0 twist.Properties('Visibility').Parameters('viewvis').Value = False twist.Properties('Visibility').Parameters('rendvis').Value = False #------------------------------------------------------------- # constrain the skeleton chain to the twisters and fk # cns_root_ik = chainRootSkel.Kinematics.AddConstraint('Pose', chainRootIk, False) cns_root_fk = chainRootSkel.Kinematics.AddConstraint('Pose', chainRootFk, False) cns_root_ik = dispatch(cns_root_ik) cns_root_fk = dispatch(cns_root_fk) cns_root_fk.cnspos.Value = False cns_root_ik.cnspos.Value = False cns_root_ik.blendweight.AddExpression( '1 - ' + propAnim.Fk_Ik.FullName ) for i in xrange(chainRootSkel.Bones.Count): cns_bone_ik = chainRootSkel.Bones(i).Kinematics.AddConstraint('Pose', twisters(i), False) cns_bone_fk = chainRootSkel.Bones(i).Kinematics.AddConstraint('Pose', chainRootFk.Bones(i), False) cns_bone_ik = dispatch(cns_bone_ik) cns_bone_fk = dispatch(cns_bone_fk) cns_bone_fk.cnspos.Value = False cns_bone_ik.cnspos.Value = False # hook it up to the ik/fk slider # since xsi constraints aren't blended like maya, we only need to # hook up the expression to the second constraint, since at 100% # it'll take control cns_bone_fk.blendweight.AddExpression( '1 - ' + outClass.zAnim.Fk_Ik.FullName ) #------------------------------------------------------------------------- # align the chain root # xsi.zgAlignChainRoot(chainRootIk) xsi.zgAlignChainRoot(chainRootFk) xsi.zgAlignChainRoot(chainRootSkel) # neutral pose the bones # col = dispatch('XSI.Collection') # for item in null_stack: # col.AddItems(item) col.AddItems(chainRootIk.Bones) col.AddItems(chainRootFk.Bones) col.AddItems(chainRootSkel.Bones) xsi.SetNeutralPose(col, c.siSRT, False) # put the effector under the last bone # chainRootIk.Bones(chainRootIk.Bones.Count-1).AddChild(chainRootIk.effector) chainRootFk.Bones(chainRootFk.Bones.Count-1).AddChild(chainRootFk.effector) chainRootSkel.Bones(chainRootSkel.Bones.Count-1).AddChild(chainRootSkel.effector) # turn off chain roots and effectors # chainRootIk.primary_icon.Value = 0 chainRootIk.Properties('Visibility').Parameters('viewvis').Value = False chainRootIk.Properties('Visibility').Parameters('rendvis').Value = False chainRootFk.primary_icon.Value = 0 chainRootFk.Properties('Visibility').Parameters('viewvis').Value = False chainRootFk.Properties('Visibility').Parameters('rendvis').Value = False chainRootSkel.primary_icon.Value = 0 chainRootSkel.Properties('Visibility').Parameters('viewvis').Value = False chainRootSkel.Properties('Visibility').Parameters('rendvis').Value = False chainRootIk.effector.primary_icon.Value = 0 chainRootIk.effector.Properties('Visibility').Parameters('viewvis').Value = False chainRootIk.effector.Properties('Visibility').Parameters('rendvis').Value = False chainRootFk.effector.primary_icon.Value = 0 chainRootFk.effector.Properties('Visibility').Parameters('viewvis').Value = False chainRootFk.effector.Properties('Visibility').Parameters('rendvis').Value = False chainRootSkel.effector.primary_icon.Value = 0 chainRootSkel.effector.Properties('Visibility').Parameters('viewvis').Value = False chainRootSkel.effector.Properties('Visibility').Parameters('rendvis').Value = False # turn fk bones into boxes # for bone in chainRootFk.Bones: bone = dispatch(bone) bone.primary_icon.Value = 6 # turn skel bone into wedges # for bone in chainRootSkel.Bones: bone = dispatch(bone) bone.primary_icon.Value = 4 # add the fkswitch to the cons # for con in outClass.controls: # add a proxy param to the bone to the ik/fk slider # prop = con.Children(0).AddProperty('CustomProperty', False, 'zAnim') prop = dispatch(prop) prop.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') prop.AddProxyParameter(outClass.zAnim.Twist, None, 'Twist') propDi = con.Children(0).AddProperty('CustomProperty', False, 'DisplayInfo_zAnim') propDi = dispatch(propDi) propDi.AddProxyParameter(outClass.zAnim.Fk_Ik, None, 'Fk_Ik') propDi.AddProxyParameter(outClass.zAnim.Twist, None, 'Twist') # put the root in the out class # outClass.chainRootIk = chainRootIk outClass.chainRootSkel = chainRootSkel # add the pickwalker to the controls # lastCon = None lastProp = None for con in outClass.controls: con = con.Children(0) # add the property # prop = con.AddProperty('zPickWalk') prop = dispatch(prop) # add the previous (up) con # if lastCon: prop.Up.Value = lastCon.Name # add the next (down) con # if lastProp: lastProp.Down.Value = con.Name # set the last con # lastCon = con # set the last prop # lastProp = prop # add the pickwalker to the bone controls # lastBone = None lastProp = None for bone in chainRootIk.bones: # add the property # prop = bone.AddProperty('zPickWalk') prop = dispatch(prop) # add the previous (up) con # if lastBone: prop.Up.Value = lastBone.Name # add the next (down) con # if lastProp: lastProp.Down.Value = bone.Name # set the last con # lastBone = bone # set the last prop # lastProp = prop # align the fk chain to the ik chain # chainRootFk.Kinematics.Global.Transform = chainRootIk.Kinematics.Global.Transform for b in xrange(chainRootFk.Bones.Count): bone_fk = dispatch(chainRootFk.Bones(b)) bone_ik = dispatch(chainRootIk.Bones(b)) bone_fk.Kinematics.Global.RotX.Value = bone_ik.Kinematics.Global.RotX.Value bone_fk.Kinematics.Global.RotY.Value = bone_ik.Kinematics.Global.RotY.Value bone_fk.Kinematics.Global.RotZ.Value = bone_ik.Kinematics.Global.RotZ.Value # export the python object # import win32com.server return win32com.server.util.wrap(outClass)
def zLoadProxySelectMap_Execute(filename, model): # if we don't have a model use the scene root # if not model: model = xsi.ActiveSceneRoot # make sure we have a model # if model.Type != '#model': log('Model argument is not of type "model".', c.siError) return False # make sure the file exists # if not os.path.exists(filename): log('File doesn\'t exist: %s' % filename, c.siError) return False # initialize a progress bar # pb = XSIUIToolkit.ProgressBar pb.Caption = 'Parsing: ' + os.path.basename(filename) pb.Step = 1 if xsi.Interactive: pb.Visible = True # read in the xml file # tStart = time.time() xml = dom.parse(filename) doc = xml.documentElement tParse = time.time() - tStart log('Time to parse file: %02d:%02d.%02d' % (int(tParse/60), tParse%60, tParse%1*100)) # count all the elements # proxyCount = len(doc.getElementsByTagName('proxy')) # update progress bar # pb.Maximum = proxyCount import locale locale.setlocale(locale.LC_ALL, '') pb.StatusText = 'Processing: %s proxies' % locale.format('%d', proxyCount, True) # step through the geometry # tApply = time.time() x_proxies = xml.getElementsByTagName('proxy') for x_proxy in x_proxies: # check for cancel # if pb.CancelPressed: return False # increment the pb # pb.Increment() # create the proxy selecter # source = model.FindChild(x_proxy.getAttribute('source')) target = model.FindChild(x_proxy.getAttribute('target')) # log('Application.zCreateProxySelect("%s", "%s")' % (source, target)) # make sure the items exist # if not source: log('No source object specified.', c.siError) return False if not target: log('No target object specified.', c.siError) return False # xsi.zCreateProxySelect(source, target) # apply the proxy prop # prop = source.AddProperty('zProxySelect') prop = dispatch(prop) prop.Target.Value = target.Name # get the time to apply the weights # tElapse = time.time() - tApply log('Time to apply proxies: %02d:%02d.%02d' % (int(tElapse/60), tElapse%60, tElapse%1*100)) # get the total time # tTotal = time.time() - tStart log('Total Elapsed time: %02d:%02d.%02d' % (int(tTotal/60), tTotal%60, tTotal%1*100)) # def zCreateProxySelect_Init(ctxt): # oCmd = ctxt.Source # oCmd.Description = "" # # oCmd.SetFlag(constants.siNoLogging,false) # # oArgs = oCmd.Arguments # oArgs.AddObjectArgument('source_obj') # oArgs.AddObjectArgument('target_obj') # # return true # # # def zCreateProxySelect_Execute(source_obj, target_obj): # # # apply the proxy prop # # prop = source_obj.AddProperty('zProxySelect') # prop = dispatch(prop) # prop.Target.Value = target_obj # # # apply the proxy selection # # # xsi.zApplyProxySelect(source_obj, False)
def zPoserSave_Execute(): # get the property # prop = xsi.ActiveSceneRoot.Properties('zPoserSaveGUI') if not prop: log('Uable to locate property "zPoserSaveGUI" on Scene_Root.', c.siError) return False # make sure we have a pose name # if not prop.PoseName.Value: log('Missing a pose name.', c.siError) return False # make sure the path exists if not os.path.exists(prop.PosePath.Value): log('Unable to find path: %s' % prop.PosePath.Value, c.siError) return False # replace all slashes in poseName to os specific slashes # poseName = prop.PoseName.Value poseName = poseName.replace('\\', os.sep) poseName = poseName.replace('/', os.sep) # build the path to the pose if it doesn't exist # posePath = prop.PosePath.Value + os.sep + poseName + '.xml' poseDir = os.path.dirname(posePath) if not os.path.exists(poseDir): log('Making directory: %s' % poseDir) os.mkdir(poseDir) # create an xml doc # impl = dom.getDOMImplementation() docType = impl.createDocumentType('zPoser', '-//Zoogloo LLC//zPoser//EN' , 'http://portal.zoogloo.net/dtds/zPoser.dtd') doc = impl.createDocument(None, "zPoser", None) top = doc.documentElement top.setAttribute('name', os.path.basename(poseName)) top.setAttribute('image', prop.Image.Value) top.setAttribute('date', time.asctime()) # process character set if prop.CharacterSet.Value and prop.SetName.Value: # get the character set # col = dispatch('XSI.Collection') col.SetAsText(prop.SetName.Value) cset = col(0) # step through the set # all_params = [] def walkProp(Prop): # get the nested properties # nested = Prop.NestedObjects # skip if there is nothing there # if not nested.Count: return # step through the nested items # for item in nested: # catch the properties # if item.type == 'customparamset': prop = dispatch(item) log('SubSet: %s' % prop.FullName, c.siVerbose) # walk through the prop # walkProp(prop) else: # add to the keyable parameters list # all_params.append(item.MasterParameter) # walk the character set # walkProp(cset) log('Params in CharSet: %d' % len(all_params), c.siVerbose) # create a dictionary of objects # obj_dict = {} # step through the parameters # for param in all_params: # log('%s : %s' % (param.MasterParameter, param.Value)) # master_param = param.MasterParameter obj = param.Parent3DObject # see if the object exists in the ob dictionary # if not obj.Name in obj_dict.keys(): # create an object item in the xml file # xml_obj = doc.createElement('object') top.appendChild(xml_obj) xml_obj.setAttribute('name', obj.Name) # add the xml to the object dictionary # obj_dict[obj.Name] = xml_obj # get the owner name # splits = param.FullName.split('.')[2:-1] owner = '.'.join(splits) # add the param # xml_obj = obj_dict.get(obj.Name) xml_chnl = doc.createElement('channel') xml_obj.appendChild(xml_chnl) xml_chnl.setAttribute('name', param.ScriptName) xml_chnl.setAttribute('owner', owner) xml_chnl.setAttribute('value', str(param.Value)) # store the other parameters # if prop.Scale.Value or prop.Rotation.Value or prop.Translation.Value: # step through the objects # for item in xsi.selection: # create an object item in the xml file # obj = doc.createElement('object') top.appendChild(obj) obj.setAttribute('name', item.Name) # get the coordinate space # # owner = None # if prop.Space.Value == 'Local': # owner = 'kine.local' # elif prop.Space.Value == 'Global': # owner = 'kine.global' # get the owner name # splits = param.FullName.split('.')[2:-1] owner = '.'.join(splits) # step through the channels # if prop.Scale.Value: if prop.SclX.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'sclx') chnl.setAttribute('value', str(space.sclx.Value)) if prop.SclY.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'scly') chnl.setAttribute('value', str(space.scly.Value)) if prop.SclZ.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'sclz') chnl.setAttribute('value', str(space.sclz.Value)) if prop.Rotation.Value: if prop.RotX.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'rotx') chnl.setAttribute('value', str(space.rotx.Value)) if prop.RotY.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'roty') chnl.setAttribute('value', str(space.roty.Value)) if prop.RotZ.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'rotz') chnl.setAttribute('value', str(space.rotz.Value)) if prop.Translation.Value: if prop.PosX.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'posx') chnl.setAttribute('value', str(space.posx.Value)) if prop.PosY.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'posy') chnl.setAttribute('value', str(space.posy.Value)) if prop.PosZ.Value: chnl = doc.createElement('channel') obj.appendChild(chnl) chnl.setAttribute('owner', prop.Space.Value) chnl.setAttribute('name', 'posz') chnl.setAttribute('value', str(space.posz.Value)) # write it to disk # fh = open(posePath, 'w') fh.write('<?xml version="1.0" encoding="utf-8"?>\n') docType.writexml(fh, indent='', addindent='\t', newl='\n') top.writexml(fh, indent='', addindent='\t', newl='\n') fh.close()
def SetCenterVector(self, XSIVector3): '''Set the center vector from an XSI Vector3''' # dispatch the vector # XSIVector3 = dispatch(XSIVector3) self.centerVector = XSIVector3
def Rig(self): # draw the OFFSET null # # TODO: add class variable for the OFFSET name offsetRest = self.character.model.AddNull(xsi.zMapName('offset', 'Home', 'Middle')) offsetRest.primary_icon.Value = 0 offsetRest.Properties('Visibility').Parameters('viewvis').Value = False offsetRest.Properties('Visibility').Parameters('rendvis').Value = False offsetGrip = offsetRest.AddNull(xsi.zMapName('offset', 'Control', 'Middle')) offsetRest.primary_icon.Value = 0 offsetRest.Properties('Visibility').Parameters('viewvis').Value = False offsetRest.Properties('Visibility').Parameters('rendvis').Value = False self.offsetNode = offsetGrip offsetHook = offsetGrip.AddNull(xsi.zMapName('offset', 'Hook', 'Middle')) offsetHook.primary_icon.Value = 0 offsetHook.Properties('Visibility').Parameters('viewvis').Value = False offsetHook.Properties('Visibility').Parameters('rendvis').Value = False # add it to the controls group # self.character.groupControls.AddMember(offsetGrip) # add to character set # stackSet = self.character.charSet.AddSubset('Stack') stackSet.AddNodePosRot(self.offsetNode) # draw the ALL null # # TODO: add class variable for the ALL name allRest = offsetHook.AddNull(xsi.zMapName('all', 'Home', 'Middle')) allRest.primary_icon.Value = 0 allRest.Properties('Visibility').Parameters('viewvis').Value = False allRest.Properties('Visibility').Parameters('rendvis').Value = False allGrip = allRest.AddGeometry('Text', 'NurbsCurve', xsi.zMapName('all', 'Control', 'Middle')) allGrip.text = "_RTF_{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fnil\\fprq5\\fcharset0 Arial;}}\r\n\\viewkind4\\uc1\\pard\\qc\\lang1033\\b\\f0\\fs20 %s\\b0\\par\r\n}\r\n" % \ (self.character.info.Prefix.Value + '1') self.allNode = allGrip # move it below the character # allGrip.Kinematics.Global.Parameters('posy').Value = -40 * self.character.scaler xsi.ResetTransform(allGrip, "siCtr", "siTrn", "siXYZ") xsi.SetValue('%s.TextToCurveList.fitsize' % allGrip.FullName, 25*self.character.scaler) # add a defalut transform setup # manip = allGrip.AddProperty('Transform Setup', False) manip = dispatch(manip) manip.tool.Value = 4 self.character.groupControls.AddMember(allGrip) # add a hook to the all control # allHook = allGrip.AddNull(xsi.zMapName('all', 'Hook', 'Middle')) allHook.primary_icon.Value = 0 allHook.Properties('Visibility').Parameters('viewvis').Value = False allHook.Properties('Visibility').Parameters('rendvis').Value = False # add to character set # stackSet.AddNodePosRot(self.allNode) # change the color of the all node # # TODO: add class variable for the all wire color disp = allGrip.AddProperty('Display Property', False) disp = dispatch(disp) disp.wirecolorr.Value = 1 disp.wirecolorg.Value = 0.5 disp.wirecolorb.Value = 0 # add a SCALE controller # # TODO: add class variable for the scale name scaleRest = allHook.AddNull(xsi.zMapName('scale', 'Home', 'Middle')) scaleRest.primary_icon.Value = 0 scaleRest.Properties('Visibility').Parameters('viewvis').Value = False scaleRest.Properties('Visibility').Parameters('rendvis').Value = False scaleGrip = scaleRest.AddNull(xsi.zMapName('scale', 'Control', 'Middle')) scaleGrip.primary_icon.Value = 0 scaleGrip.Properties('Visibility').Parameters('viewvis').Value = False scaleGrip.Properties('Visibility').Parameters('rendvis').Value = False self.scaleNode = scaleGrip scaleHook = scaleGrip.AddNull(xsi.zMapName('scale', 'Hook', 'Middle')) scaleHook.primary_icon.Value = 0 scaleHook.Properties('Visibility').Parameters('viewvis').Value = False scaleHook.Properties('Visibility').Parameters('rendvis').Value = False # add a default transform to the scale control # manip = scaleGrip.AddProperty('Transform Setup', False) manip = dispatch(manip) manip.tool.Value = 2 # add to the controls group # self.character.groupControls.AddMember(scaleGrip) # add to character set # # stackSet.AddParams('%(item)s.kine.global.sclx, %(item)s.kine.global.scly, %(item)s.kine.global.sclz' % {'item': scaleGrip}) stackSet.AddNodeScl(scaleGrip) # create a FLIGHT con # # TODO: pass the con class # flightStack = xsi.zCreateCon(scaleHook, 'flight', 'Middle', 5, 30*self.character.scaler, 0.2, 0.7, 0.6) # adjust the position of the stack trans = flightStack(1).Kinematics.Global.Transform trans.SetTranslation(self.centerVector) flightStack(1).Kinematics.Global.Transform = trans flightStack(1).Kinematics.Global.Parameters('rotx').Value = 0 flightStack(1).Kinematics.Global.Parameters('roty').Value = -90 flightStack(1).Kinematics.Global.Parameters('rotz').Value = 0 flightStack(2).Kinematics.Local.Parameters('posx').Value = 8*self.character.scaler xsi.ResetTransform(flightStack(2), c.siCtr, c.siTrn, c.siXYZ) self.flightNode = flightStack(2) # add to the controls group # self.character.groupControls.AddMember(flightStack(2)) # add to character set # stackSet.AddNodePosRot(self.flightNode) # add the CENTER node # self.centerNode = flightStack(3).AddNull(xsi.zMapName('center', 'Null', 'None')) self.centerNode.Kinematics.Global.Transform = flightStack(1).Kinematics.Global.Transform self.centerNode.primary_icon.Value = 0 self.centerNode.Properties('Visibility').Parameters('viewvis').Value = False self.centerNode.Properties('Visibility').Parameters('rendvis').Value = False # draw a CONTROLS node # self.controlsNode = self.centerNode.AddNull(xsi.zMapName('Controls', 'Branch', 'None')) self.controlsNode.primary_icon.Value = 0 self.controlsNode.Properties('Visibility').Parameters('viewvis').Value = False self.controlsNode.Properties('Visibility').Parameters('rendvis').Value = False # add LOWER and UPPER body groups # self.lowerBodyNode = self.controlsNode.AddNull(xsi.zMapName('LowerBody', 'Branch', 'None')) self.lowerBodyNode.primary_icon.Value = 0 self.lowerBodyNode.Properties('Visibility').Parameters('viewvis').Value = False self.lowerBodyNode.Properties('Visibility').Parameters('rendvis').Value = False self.upperBodyNode = self.controlsNode.AddNull(xsi.zMapName('UpperBody', 'Branch', 'None')) self.upperBodyNode.primary_icon.Value = 0 self.upperBodyNode.Properties('Visibility').Parameters('viewvis').Value = False self.upperBodyNode.Properties('Visibility').Parameters('rendvis').Value = False # draw a SKELETON node # self.skeletonNode = self.centerNode.AddNull(xsi.zMapName('Skeleton', 'Branch', 'None')) self.skeletonNode.primary_icon.Value = 0 self.skeletonNode.Properties('Visibility').Parameters('viewvis').Value = False self.skeletonNode.Properties('Visibility').Parameters('rendvis').Value = False # create a do not touch node # self.doNotTouch = self.character.model.AddNull(xsi.zMapName('DoNotTouchThis', 'Branch', 'None')) self.doNotTouch.primary_icon.Value = 0 self.doNotTouch.Properties('Visibility').Parameters('viewvis').Value = False self.doNotTouch.Properties('Visibility').Parameters('rendvis').Value = False # create a do not touch node # self.deformersNode = self.doNotTouch.AddNull(xsi.zMapName('Deformers', 'Branch', 'None')) self.deformersNode.primary_icon.Value = 0 self.deformersNode.Properties('Visibility').Parameters('viewvis').Value = False self.deformersNode.Properties('Visibility').Parameters('rendvis').Value = False # constrain the scale of the do not touch to the scale node # self.doNotTouch.Kinematics.AddConstraint('Scaling', self.scaleNode, False) # create nodes for the geometry # self.geometryRender = self.doNotTouch.AddNull(xsi.zMapName('GeometryRender', 'Branch', 'None')) self.geometryRender.primary_icon.Value = 0 self.geometryRender.Properties('Visibility').Parameters('viewvis').Value = False self.geometryRender.Properties('Visibility').Parameters('rendvis').Value = False self.geometryAnim = self.doNotTouch.AddNull(xsi.zMapName('GeometryAnim', 'Branch', 'None')) self.geometryAnim.primary_icon.Value = 0 self.geometryAnim.Properties('Visibility').Parameters('viewvis').Value = False self.geometryAnim.Properties('Visibility').Parameters('rendvis').Value = False