def ClusterCenterTarget(inPntSubComponent=None, inTarget=None, inName="PntCls"): if not inPntSubComponent: sel = XSI.Selection(0) if not sel or not sel.Type == "pntSubComponent": XSI.LogMessage( "[ClusterCenterTarget] Invalid Selection : Need some points selected ---> Aborted!" ) return else: inPntSubComponent = sel.SubComponent if not inTarget: pick = PickElement(constants.siObjectFilter, "Pick Target Object") if not pick: XSI.LogMessage( "[ClusterCenterTarget] Invalid Target : Need one target object ---> Aborted!" ) return else: inTarget = pick obj = inPntSubComponent.Parent3DObject geo = obj.ActivePrimitive.Geometry elem = inPntSubComponent.ElementArray cls = geo.AddCluster(constants.siVertexCluster, inName, elem) XSI.ApplyOp("ClusterCenter", str(cls) + ";" + str(inTarget), 0, 0, None, 2)
def bbppTransformation_DeleteCorrespondancePoints_OnClicked( ): oModel = PPG.Inspected(0).Parent3DObject if XSI.Selection.Count == 0: oElem = bPickElement(constants.siNullFilter,"Pick Point to Delete") else: oElem = XSI.Selection(0) if not oElem: XSI.LogMessage("bbppTransformation Delete Points : Operation Aborted !", constants.siInfo) return if oElem.Model.FullName == oModel.FullName and oElem.Type == "null": if oElem.Name.find("Start") != -1: sSplit = oElem.Name.split("Start") oOther = oModel.FindChild("End"+sSplit[1]) oCurve = oModel.FindChild("Link"+sSplit[1]) elif oElem.Name.find("End") != -1: sSplit = oElem.Name.split("End") oOther = oModel.FindChild("Start"+sSplit[1]) oCurve = oModel.FindChild("Link"+sSplit[1]) XSI.DeleteObj(str(oElem) + "," + str(oOther) + "," + str(oCurve)) else: XSI.LogMessage("bbppTransformation Delete Points : Invalid Selection ---> Nothing Deleted!", constants.siError)
def CreateClusterFromSelection(name='ClsFromSelection'): """ Create cluster from selection """ selection = XSI.Selection(0) if not selection: XSI.LogMessage( '[Utils] CreateClusterFromSelection failed as nothing selected !') return None obj = selection.SubComponent.Parent3DObject if obj.ActivePrimitive.Geometry.Clusters(name): cluster = obj.ActivePrimitive.Geometry.Clusters(name) return cluster if selection.Type == 'pntSubComponent': sub = selection.SubComponent if sub.Parent3DObject.FullName == obj.FullName: cluster = sub.CreateCluster(name) return cluster elif selection.Type == 'polySubComponent': sub = selection.SubComponent if sub.Parent3DObject.FullName == obj.FullName: cluster = sub.CreateCluster(name) return cluster
def WeightMapEditor_ChangeTargetGeometry_OnClicked(): sel = XSI.Selection(0) if not sel or not sel.IsClassOf(constants.siX3DObjectID): sel = uti.PickElement(constants.siGeometryFilter, "Pick Geometry Object") if sel: PPG.Inspected(0).Parameters("TargetObject").Value = sel.FullName WeightMapEditor_RebuildLayout(PPG.Inspected(0)) PPG.Refresh()
def Cloth_GetBuilder(context): mesh = XSI.Selection(0) if not mesh or not mesh.type == 'polymsh': XSIUIToolKit.MsgBox('Select PolygonMesh and try again...', constants.siMsgOkOnly, 'ClothTools') return prop = mesh.Properties('Cloth_Rigger') if not prop: prop = mesh.AddProperty('Cloth_Rigger') XSI.InspectObj(prop, '', '', constants.siLock)
def OnWeightMapEditorMenu(in_ctxt): root = XSI.ActiveSceneRoot prop = root.Properties("WeightMapEditor") if not prop: prop = root.AddProperty("WeightMapEditor") XSI.InspectObj(prop, None, None, constants.siLock) obj = XSI.Selection(0).SubComponent.Parent3DObject prop.Parameters("TargetObject").Value = obj.FullName WeightMapEditor_RebuildLayout(prop)
def Cloth_GetControl(context): model = XSI.Selection(0) if not model or not model.type == '#model': XSIUIToolKit.MsgBox('Select Model and try again...', constants.siMsgOkOnly, 'ClothTools') return prop = model.Properties('ClothControl') if not prop: prop = model.AddProperty('Cloth_Control', False, 'ClothControl') XSI.InspectObj(prop, '', '', constants.siLock)
def WeightMapEditor_RebuildLayout(inPPG): wmlist = [] if inPPG.Parameters("TargetObject").Value == "": sel = XSI.Selection(0) if not sel or not sel.IsClassOf(constants.siX3DObjectID): sel = uti.PickElement(constants.siGeometryFilter, "Pick Geometry Object") if sel: inPPG.Parameters("TargetObject").Value = sel.FullName wmlist = BuildListWeightMaps(sel, inPPG) else: obj = XSI.Dictionary.GetObject(inPPG.Parameters("TargetObject").Value) wmlist = BuildListWeightMaps(obj, inPPG) layout = inPPG.PPGLayout layout.Clear() layout.AddGroup("Target Object") layout.AddRow() item = layout.AddItem("TargetObject") item.SetAttribute(constants.siUINoLabel, True) layout.AddButton("ChangeTargetGeometry", "CHANGE") layout.EndRow() layout.EndGroup() layout.AddGroup("Weight Maps") if len(wmlist) == 0: layout.AddStaticText("This object contains no weightmap") return item = layout.AddEnumControl("WeightMapChooser", wmlist, "List", constants.siControlListBox) item.SetAttribute(constants.siUINoLabel, True) #layout.AddItem("WeightMapList") layout.EndGroup() layout.AddGroup("Set Weight On Selected Points") layout.AddRow() item = layout.AddItem("Weight") item.SetAttribute(constants.siUINoLabel, True) layout.AddButton("SetWeightOnSelectedPoints", "SET") layout.AddButton("AddWeightOnSelectedPoints", "ADD") layout.AddButton("SubWeightOnSelectedPoints", "SUB") layout.EndRow() layout.EndGroup()
def ELIWeightMapEditor_SubWeightOnSelectedPoints_OnClicked(): sel = XSI.Selection(0) if not sel.Type == "pntSubComponent": XSI.LogMessage("Select some points on Target Object!!", constants.siWarning) return sub = sel.SubComponent obj = sub.Parent3DObject if not obj.FullName == PPG.Inspected(0).Parameters("TargetObject").Value: XSI.LogMessage("Selected Points are not on Target Geometry...", constants.siWarning) XSI.SelectObj(obj) WeightMapEditor_RebuildLayout(PPG.Inspected(0)) return else: wmname = GetUISelectedWeightMap(PPG.Inspected(0)) XSI.LogMessage(wmname) wm = XSI.Dictionary.GetObject(wmname) uti.SubWeightOnSelectedPoints(wm, PPG.Weight.Value, sub)
def SetWeightOnSelectedPoints(weightmap, weight=0, pntsubcomponent=None): if not weightmap or not weightmap.Type == "wtmap": XSI.LogMessage( "[SetWeightOnSelectedPoints] Invalid Weight Map ---> Aborted!") return if not pntsubcomponent: sel = XSI.Selection(0) if not sel or not sel.Type == "pntSubComponent": XSI.LogMessage( "[SetWeightOnSelectedPoints] Invalid Selection : Need some points selected ---> Aborted!" ) return else: pntsubcomponent = sel.SubComponent weights = [w for w in weightmap.Elements.Array[0]] # process for i in pntsubcomponent.ComponentCollection.IndexArray: weights[i] = weight weightmap.Elements.Array = weights
def bbppTransformation_BuildOutputMesh_OnClicked( ): oPPG = PPG.Inspected(0) oModel = oPPG.Parent3DObject oStartCloud = oModel.FindChild("StartCloud") oEndCloud = oModel.FindChild("EndCloud") oStartGrp = oModel.Groups("Start"); oEndGrp = oModel.Groups("End"); # does geometry exists? oStartGeomStatic = bbppTransformation_StartGeometryStaticExist(oPPG) oEndGeomStatic = bbppTransformation_EndGeometryStaticExist(oPPG) if not oStartGeomStatic or not oEndGeomStatic: XSI.LogMessage("bbppTransformation Geometry Does not exist ---> Can't build Output Mesh!", constants.siError) return if oPPG.AnimatedTransformation.Value: oStartGeomAnimated = bbppTransformation_StartGeometryAnimatedExist(oPPG) oEndGeomAnimated = bbppTransformation_EndGeometryAnimatedExist(oPPG) if not oStartGeomAnimated or not oEndGeomAnimated: XSI.LogMessage("bbppTransformation Geometry Does not exist ---> Can't build Output Mesh!", constants.siError) return # create start geometry point cloud if not oStartCloud: # create emission node oStartCloud = XSI.GetPrim("PointCloud", "StartCloud", oModel) oIceTree = XSI.ApplyOp("ICETree", oStartCloud, "siNode", "", "", 0) oEmit = XSI.AddICECompoundNode("bbpp Emit From Points", oIceTree) XSI.ConnectICENodes(str(oIceTree) + ".port1", str(oEmit) + ".add") oGet1 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet1) + ".reference", oStartGeomStatic.FullName) XSI.ConnectICENodes(str(oEmit) + ".Emiter", str(oGet1) + ".outname") XSI.SetValue(str(oEmit) + ".Color_red", 0.9) XSI.SetValue(str(oEmit) + ".Color_green", 0.4) XSI.SetValue(str(oEmit) + ".Color_blue", 0.1) # create blend node oBlend = XSI.AddICECompoundNode("bbpp Blend Cloud", oIceTree) XSI.AddPortToICENode(str(oIceTree) + ".port1", "siNodePortDataInsertionLocationAfter") XSI.ConnectICENodes(str(oIceTree) + ".port2", str(oBlend) + ".Execute") oGet2 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet2) + ".reference", str(oStartGrp)) XSI.ConnectICENodes(str(oBlend) + ".Start_Cloud", str(oGet2) + ".outname") oGet3 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet3) + ".reference", str(oEndGrp)) XSI.ConnectICENodes(str(oBlend) + ".End_Cloud", str(oGet3) + ".outname") oGet4 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet4) + ".reference", oEndGeomStatic.FullName) XSI.ConnectICENodes(str(oBlend) + ".Target_Geometry", str(oGet4) + ".value") # connect timer oTimer = XSI.AddICECompoundNode("bbpp Transformation Timer", oIceTree) XSI.ConnectICENodes(str(oBlend) + ".Blend", str(oTimer) + ".Blend") oGet5 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet5) + ".reference", oPPG.StartFrame.FullName) oGet6 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet6) + ".reference", oPPG.EndFrame.FullName) XSI.ConnectICENodes(str(oTimer) + ".Start_Frame", str(oGet5) + ".value") XSI.ConnectICENodes(str(oTimer) + ".End_Frame", str(oGet6) + ".value") # create end geometry point cloud if not oEndCloud: # create emission node oEndCloud = XSI.GetPrim("PointCloud", "EndCloud", oModel) oIceTree = XSI.ApplyOp("ICETree", oEndCloud, "siNode", "", "", 0) oEmit = XSI.AddICECompoundNode("bbpp Emit From Points", oIceTree) XSI.ConnectICENodes(str(oIceTree) + ".port1", str(oEmit) + ".add") oGet1 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet1) + ".reference", oEndGeomStatic.FullName) XSI.ConnectICENodes(str(oEmit) + ".Emiter", str(oGet1) + ".outname") XSI.SetValue(str(oEmit) + ".Color_red", 0.1) XSI.SetValue(str(oEmit) + ".Color_green", 0.9) XSI.SetValue(str(oEmit) + ".Color_blue", 0.4) # create blend node oBlend = XSI.AddICECompoundNode("bbpp Blend Cloud", oIceTree) XSI.AddPortToICENode(str(oIceTree) + ".port1", "siNodePortDataInsertionLocationAfter") XSI.ConnectICENodes(str(oIceTree) + ".port2", str(oBlend) + ".Execute") oGet2 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet2) + ".reference", str(oEndGrp)) XSI.ConnectICENodes(str(oBlend) + ".Start_Cloud", str(oGet2) + ".outname") oGet3 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet3) + ".reference", str(oStartGrp)) XSI.ConnectICENodes(str(oBlend) + ".End_Cloud", str(oGet3) + ".outname") oGet4 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet4) + ".reference", oStartGeomStatic.FullName) XSI.ConnectICENodes(str(oBlend) + ".Target_Geometry", str(oGet4) + ".value") # connect timer oTimer = XSI.AddICECompoundNode("bbpp Transformation Timer", oIceTree) XSI.ConnectICENodes(str(oBlend) + ".Blend", str(oTimer) + ".Blend") oGet5 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet5) + ".reference", oPPG.StartFrame.FullName) oGet6 = XSI.AddICENode("GetDataNode", oIceTree) XSI.SetValue(str(oGet6) + ".reference", oPPG.EndFrame.FullName) XSI.ConnectICENodes(str(oTimer) + ".Start_Frame", str(oGet5) + ".value") XSI.ConnectICENodes(str(oTimer) + ".End_Frame", str(oGet6) + ".value") XSI.SetValue(str(oTimer) + ".Revert", True) # create Blob Mesh # delete it if already exists bbppTransformation_BlobGeometryExist(oPPG) XSI.SelectObj(str(oStartCloud) + "," + str(oEndCloud)) XSI.Create_Polygonizer_Polymesh() oBlob = XSI.Selection(0) oBlob.Name = "OutputMesh" oModel.AddChild(oBlob) oBlobOp = oBlob.ActivePrimitive.ConstructionHistory.Find("Polygonizer") # create expression for in-between #-------------------------------------- # detail sStartFrame = oPPG.StartFrame.FullName sEndFrame = oPPG.EndFrame.FullName sTimelapse = sEndFrame+" - "+sStartFrame oExpr = "(1 - sin(cond(FC>"+sStartFrame+",cond(Fc<"+sEndFrame+",(Fc - "+sStartFrame+")/("+sTimelapse+"),1),0)*180)) *2 + 2" oBlobOp.Parameters("Detail").AddExpression(oExpr) # blur isofield oExpr = "sin(cond(FC>"+sStartFrame+",cond(Fc<"+sEndFrame+",(Fc - "+sStartFrame+")/("+sTimelapse+"),1),0)*180)/2" oBlobOp.Parameters("BlurIsofieldStrength").AddExpression(oExpr) # smooth mesh oExpr = "sin(cond(FC>"+sStartFrame+",cond(Fc<"+sEndFrame+",(Fc - "+sStartFrame+")/("+sTimelapse+"),1),0)*180)*4+2" oBlobOp.Parameters("SmoothMeshStrength").AddExpression(oExpr) # isolevel oBlobOp.Parameters("Isolevel").Value = 1
def WeightMapEditor_WeightMapChooser_OnChanged(): sel = XSI.Selection(0) wmname = GetUISelectedWeightMap(PPG.Inspected(0)) wm = XSI.Dictionary.GetObject(wmname) XSI.SelectObj(wm) XSI.SelectObj(sel)