Exemple #1
0
def Cloth_Clean_Execute(prop):

    #if cloth op, we store a preset
    Cloth_Rigger_WriteXML(prop)

    obj = prop.Parent3DObject
    trees = obj.ActivePrimitive.ICETrees

    syflex_op = Cloth.GetClothOperator(obj)
    if syflex_op:
        XSI.DeleteObj(syflex_op)

    if trees.Count > 0:
        restore = obj.ActivePrimitive.ICETrees.Find('ClothRestore')
        if restore:
            XSI.DeleteObj(restore)

        correct = obj.ActivePrimitive.ICETrees.Find('ClothCorrectStiffness')
        if correct:
            XSI.DeleteObj(correct)

        init = obj.ActivePrimitive.ICETrees.Find('ClothInit')
        if init:
            XSI.DeleteObj(init)

    model = obj.Model
    target = model.FindChild('{}_Target'.format(obj.Name))
    if target:
        XSI.DeleteObj(target)
Exemple #2
0
def Cloth_Control_SetDampingPercentage_OnClicked():
	prop = PPG.Inspected(0)
	
	tmp = XSI.ActiveSceneRoot.AddProperty("CustomProperty", false, "Cloth_Control_SetDampingPercentage")
	p = tmp.AddParameter3( "Value", constants.siFloat, 100, 1, 1000, False, False )
	layout = tmp.PPGLayout
	layout.Clear()
	layout.AddGroup("Set Damping : Stiffness divided by ")
	layout.AddItem( "Value")
	layout.EndGroup()
	
	bCancelled  = XSI.InspectObj(tmp, None, "Set Syflex Damping", constants.siModal, False)
	if not bCancelled:
		prop.StretchDamping.Value = prop.StretchStiffness.Value / p.Value
		prop.ShearDamping.Value = prop.ShearStiffness.Value / p.Value
		prop.BendDamping.Value = prop.BendStiffness.Value / p.Value
		Cloth_Control_StretchDamping_OnChanged()
		Cloth_Control_ShearDamping_OnChanged()
		Cloth_Control_BendDamping_OnChanged()

		XSI.DeleteObj(tmp)

	else:
		XSI.DeleteObj(tmp)
		XSI.LogMessage("[Cloth_Control]Set Syflex Damping Aborted..")
Exemple #3
0
def Cloth_DeformOutputMesh(prop):
    out = Cloth_GetOutputMesh(prop)
    cloth = prop.Parent3DObject

    if not out:
        XSI.LogMessage(
            '[Cloth_Rigger]There is no Output Mesh set for "{}"'.format(
                cloth.FullName), constants.siWarning)
        return

    # delete cage if already exists
    cage = out.ActivePrimitive.ConstructionHistory.Find('cagedeformop')

    if cage:
        XSI.DeleteObj(cage)

    # delete all cagedeform cluster
    all_clusters = out.ActivePrimitive.Geometry.Clusters
    for cluster in all_clusters:
        if not cluster.Name.find('CageWeightCls') == -1:
            XSI.DeleteObj(cluster)

    cage = XSI.ApplyDeformByCage('{};{}'.format(out.FullName, cloth.FullName),
                                 constants.siConstructionModeAnimation)(0)
    cage.Strength = 10
    cage.Falloff = 0.2

    # Deactivate EnvelopeOp
    env = out.ActivePrimitive.ConstructionHistory.Find('envelopop')
    if env:
        env.Mute = True
Exemple #4
0
def ReorderCurveGroup(model, _type):
    """ Reorder curve group
	:param Model model: SDK Model object
	:param int _type: rig element type
	"""
    if _type not in [ID_SKELETON, ID_MUSCLE]:
        return

    if _type == ID_SKELETON:
        emit_ref = 'this_model.Guide_Curves'
        prop_name = 'RigElement'
        grp_name = 'Guide_Curves'

    elif _type == ID_MUSCLE:
        emit_ref = 'this_model.Muscle_Curves'
        prop_name = 'MuscleElement'
        grp_name = 'Muscle_Curves'

    # get all guide curves
    guides = [
        g for g in model.FindChildren2('*_Crv', '', constants.siCurveFamily,
                                       True) if g.Properties(prop_name)
    ]

    if guides and len(guides) > 1:
        # get guide curve group
        grp = model.Groups(grp_name)

        cloud = model.AddPrimitive('PointCloud', 'ICE_Correct')
        tree = ICETree.CreateICETree(cloud, 'Emit', 0)

        emit = XSI.AddICECompoundNode('IRCorrectEmit', tree)
        XSI.ConnectICENodes('{}.port1'.format(tree), '{}.Execute'.format(emit))
        XSI.SetValue('{}.Reference'.format(emit), emit_ref, None)

        # get point cloud data
        cloud_geom = cloud.ActivePrimitive.Geometry
        positions_attr = cloud_geom.GetICEAttributeFromName('PointPosition')
        positions = positions_attr.DataArray
        indices_attr = cloud_geom.GetICEAttributeFromName('ShowGuideID')
        indices = indices_attr.DataArray
        sorted_guides = [g for g in guides]

        for guide in guides:
            geom = guide.ActivePrimitive.Geometry
            closest_indices = [
                FindClosestIndex(p.Position, positions, indices)
                for p in geom.Points
            ]
            r = max(set(closest_indices), key=closest_indices.count)
            sorted_guides[r] = guide

        if grp:
            XSI.DeleteObj(grp)

        Utils.GroupSetup(model, sorted_guides, grp_name)
        XSI.DeleteObj(cloud)
Exemple #5
0
def Cloth_ApplySyflexOp(obj):
    syflex_op = obj.ActivePrimitive.ConstructionHistory.Find('syCloth')
    if syflex_op:
        XSI.DeleteObj(syflex_op)

    cloth_cluster = obj.ActivePrimitive.Geometry.Clusters('ClothCls')
    if not cloth_cluster:
        cloth_cluster = Utils.CreateCompleteButNotAlwaysCluster(
            obj, constants.siVertexCluster, 'ClothCls')

    mass_map = Utils.GetWeightMap(obj, 'MassMap', 1, 0, 1, cloth_cluster)
    stiffness_map = Utils.GetWeightMap(obj, 'StiffMap', 1, 0, 1, cloth_cluster)
    restore_map = Utils.GetWeightMap(obj, 'RestoreMap', 0, 0, 1, cloth_cluster)

    XSI.FreezeObj(mass_map.FullName + "," + stiffness_map.FullName)
    syflex_op = XSI.ApplyOp(
        'syCloth', ';'.join(obj.FullName, mass_map.FullName,
                            stiffness_map.FullName), 3, 0, None, 2)(0)
    stf = XSI.ApplyOperator('syProperties', syflex_op)
    start_frame = Utils.GetStartFrame()
    syflex_op.Parameters('FirstFrame').Value = start_frame
    XSI.SaveKey(syflex_op.Parameters('Update'), 1, 1)

    stf.Parameters('Density').Value = 0.5
    stf.Parameters('StretchStiffness').Value = 1
    stf.Parameters('ShearStiffness').Value = 0.2
    stf.Parameters('BendStiffness').Value = 0.1
    stf.Parameters('StretchDamping').Value = 0.1
    stf.Parameters('ShearDamping').Value = 0.02
    stf.Parameters('BendDamping').Value = 0.01

    return syflex_op
Exemple #6
0
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)
Exemple #7
0
def Cloth_Control_DeleteAllCorrectivePush_OnClicked():
	prop = PPG.Inspected(0)
	layout = prop.PPGLayout
	clothes = Cloth_Control_GetClothObjects(prop)
	
	if len(clothes) == 1:
		delete = XSIUIToolkit.Msgbox( "Do you realy want to delete ALL corrective push maps", constants.siMsgYesNo | constants.siMsgQuestion, "Delete Corrective Push" ) 

		if delete == constants.siMsgYes:
			tree = clothes[0].ActivePrimitive.ICETrees("CorrectivePush")
			if tree:
				XSI.DeleteObj(tree)
			cls = clothes[0].ActivePrimitive.Geometry.Clusters("CorrectivePushCls")
			if cls:
				XSI.DeleteObj(cls)
		
		pushlist = []
		pro.UpdateListItemsUI( layout.Item("CorrectivePushList"), prop.Parameters("CorrectivePushList"), pushlist);
		PPG.Refresh()
		
	else:
		XSI.LogMessage("[Cloth_Control] Delete ALL Corrective Push only works in Single Item Mode!!", constants.siError)
Exemple #8
0
def CreateSkeletonCloud(model):
    cloud = model.FindChild('ICE_Skeleton')
    if cloud:
        XSI.DeleteObj(cloud)

    cloud = model.AddPrimitive('PointCloud', 'ICE_Skeleton')
    tree = ICETree.CreateICETree(cloud, 'Emit', 0)

    emit = XSI.AddICECompoundNode('IRBuildSkeleton', tree)
    XSI.ConnectICENodes('{}.port1'.format(tree), '{}.Execute'.format(emit))

    tree = ICETree.CreateICETree(cloud, 'Deform', 2)
    deform = XSI.AddICECompoundNode('IRDeformSkeleton', tree)
    XSI.ConnectICENodes('{}.port1'.format(tree), '{}.Execute'.format(deform))

    return cloud
Exemple #9
0
def bbppTransformation_BlobGeometryExist(inPPG):
	oOutputMesh = inPPG.Parent3DObject.FindChild("OutputMesh")
	if oOutputMesh:
		XSI.DeleteObj(oOutputMesh)
Exemple #10
0
def CreateEnvelopeNullsFromSkeletonCloud(model):
    cloud = model.FindChild('ICE_Skeleton')
    grp = Utils.GroupSetup(model, None, 'Envelope')

    root = model.FindChild('Envelopes', constants.siNullPrimType)
    if root:
        XSI.SelectObj(root, 'BRANCH')
        XSI.DeleteObj()

    root = model.AddNull('Envelopes')
    idx = 0
    attrs = cloud.ActivePrimitive.ICEAttributes
    pos = attrs('PointPosition').DataArray
    scl = attrs('Scale').DataArray
    ori = attrs('Orientation').DataArray

    # we have to display this attribute for accessing it
    emit = cloud.ActivePrimitive.ICETrees(1)
    node = emit.Nodes(0)
    XSI.LogMessage(node)
    XSI.SetValue('{}.Show_Name'.format(node), True, '')
    skeleton_name = cloud.ActivePrimitive.GetICEAttributeFromName(
        'SkeletonName').DataArray
    XSI.SetValue('{}.Show_Name'.format(node), False, '')

    group = Utils.GroupSetup(model, None, 'Envelope')

    t = XSIMath.CreateTransform()
    last_name = ''
    sub_index = 1
    for idx in xrange(cloud.ActivePrimitive.Geometry.Points.Count):
        p = pos[idx]
        o = ori[idx]
        s = scl[idx]
        t.SetTranslation(p)
        t.SetRotation(o)
        t.SetScaling(s)
        '''
		n = root.AddNull("Buffer"+str(id))
		tr = tree.CreateICETree(n,"Kinematics")
		node = xsi.AddICECompoundNode("BindTransformToPoint", str(tr))
		xsi.ConnectICENodes(str(tr)+".port1", str(node)+".Execute")
		xsi.SetValue(str(node)+".ID", id, "")
		'''
        current_name = skeleton_name[idx]
        if not skeleton_name:
            XSI.LogMessage('You need to display SkeletonName ICE Attribute !',
                           constants.siWarning)
            break
        else:
            if not current_name == last_name:
                last_name = current_name
                sub_index = 1

            n = root.AddNull('{}{}_Env'.format(current_name, sub_index))
            n.ActivePrimitive.Primary_Icon = 4
            group.AddMember(n)
            n.Kinematics.Global.Transform = t
            idx += 1
            sub_index += 1

    return grp
Exemple #11
0
def DeleteSkeletonCloud(model):
    cloud = model.FindChild('ICE_Skeleton')
    if cloud:
        XSI.DeleteObj(cloud)
Exemple #12
0
def Delete(obj, mode, frame):
	log_state = Utils.SetScriptingLogState(False)
	
	command_name = 'Cloth_CorrectiveSmooth'
	cluster_name = 'CorrectiveSmoothCls'
	if mode == 'Push':
		command_name = 'Cloth_CorrectivePush'
		cluster_name = 'CorrectivePushCls'
	elif mode == 'Shape':
		command_name = 'Cloth_CorrectiveShape'
		cluster_name = 'CorrectiveShapeCls'
	
	if not obj or not obj.Type == 'polymsh':
		XSI.LogMessage(command_name + " ---> Invalid Object", constants.siError)
		return
	
	prim = obj.ActivePrimitive
	
	# get Cluster
	cluster = Utils.CreateAlwaysCompleteCluster(obj, constants.siVertexCluster, cluster_name)

	# check if a weight map already exists for this frame
	exist = False
	if cluster.Properties('Frame{}'.format(frame)):
		exist = True
		toolkit = Dispatch('XSI.UIToolkit')
		button_pressed = toolkit.MsgBox(
			'Do you really want to delete delete Frame{}'.format(frame),
			constants.siMsgOkCancel, 'Delete Corrective Push'
		)
	
		if button_pressed == constants.siMsgCancel:
			XSI.LogMessage("Delete Secondary " + mode + " cancelled by the user!!", constants.siInfo)
			return
	
	if not exist:
		XSI.LogMessage("Frame" + str(frame) + " doesn't exist on " + str(obj) + " ---> Delete Corrective " + mode + " aborted...")
		return
	
	else:
		XSI.DeleteObj(cluster.Properties('Frame{}'.format(frame)))

	tree = prim.ICETrees('Corrective{}'.format(mode))
	compound = tree.CompoundNodes('Corrective{}'.format(mode))

	# first delete corresponding GetDataNode
	get_nodes = tree.DataProviderNodes
	for get_node in get_nodes:
		if not get_node.Parameters('Reference').Value.find(str(frame)) == -1:
			XSI.LogMessage('Delete Get Data Node "{}"'.format(get_node.Parameters('Reference').Value))
			XSI.DeleteObj(get_node)

	# delete Corresponding MultiplyByScalarNode
	multiply_nodes = compound.Nodes.Filter('MultiplyByScalarNode')
	for multiply_node in multiply_nodes:
		inputs = multiply_node.InputPorts
	
		if not inputs(0).IsConnected:	
			XSI.LogMessage('Delete MultiplyByScalar Node : {}'.format(multiply_node))
			XSI.DeleteObj(multiply_node)

	Utils.SetScriptingLogState(log_state)
Exemple #13
0
def CorrectShape(obj, cls, frame):
	prim = obj.ActivePrimitive
	tree = prim.ICETrees.Find("CorrectiveShape")
	exist = False
	basePos = None
	secondPos = None
	
	if tree:
		if cls.Properties("Frame"+str(frame)):
			exist = True
			toolkit = Dispatch("XSI.UIToolkit")
			buttonPressed = toolkit.MsgBox( "A corrective shape already exists for this frame\n Would you replace it??",
				constants.siMsgOkCancel, "Corrective Shape")

			if buttonPressed == constants.siMsgCancel:
				XSI.LogMessage("Store Secondary Shape cancelled by You, F**k TYou!!", constants.siInfo)
				return
			
		compound = tree.CompoundNodes("CorrectiveShape")
		
	if not exist:
		compound.InputPorts("Mute").Value = True
		XSI.DeactivateAbove(tree, True)
		basePoints = prim.Geometry.Points
		basePos = basePoints.PositionArray
		XSI.DeactivateAbove(tree, False)
		secondPoints = prim.Geometry.Points
		secondPos = secondPoints.PositionArray
		if not exist:
			compound.InputPorts("Mute").Value = False
	
	else:
		op = prim.ConstructionHistory.Find("AnimationMarker")
		XSI.DeactivateAbove(op, True)
		basePoints = prim.Geometry.Points
		basePos = basePoints.PositionArray
		XSI.DeactivateAbove(op, False)
		secondPoints = prim.Geometry.Points
		secondPos = secondPoints.PositionArray
	
	l = len(basePos[0])
	delta = [0] * 3 * l
			
	for a in range(l):
		delta[a*3] = secondPos[0][a]-basePos[0][a]
		delta[a*3+1] = secondPos[1][a]-basePos[1][a]
		delta[a*3+2] = secondPos[2][a]-basePos[2][a]

	if not exist:
		shapeNode = Dispatch(cls.AddProperty("SimpleDeformShape", 0, "Frame"+str(frame)))
		shapeNode.Elements.Array = delta
		
	else:
		shapeNode = Dispatch(cls.Properties("Frame"+str(frame)))
		shapeNode.Elements.Array = delta

	if not tree:
		tree = ICETree.CreateIceTree(obj, "CorrectiveShape", 2)
		t = str(tree)
		set = XSI.AddICENode("SetOneDataNode", t)
		set.Parameters("Reference").Value = "Self.PointPosition"
		ifnode = XSI.AddIceNode("IfNode", t)
		
		XSI.ConnectICENodes(t + ".port1", str(ifnode) + ".Result")
		XSI.ConnectICENodes(str(ifnode) + ".IfFalse", str(set) + ".Value")
		
		get = XSI.AddICENode("GetDataNode", t)
		get.Parameters("Reference").Value = "Self.PointPosition"

		add = XSI.AddIceNode("AddNode", t)
		
		XSI.ConnectIceNodes(str(add) + ".Value1", str(get) + ".Value")
		XSI.ConnectIceNodes(str(set) + ".Source", str(add) + ".Result")
		
		compound = XSI.CreateICECompoundNode(str(get) + "," + str(set) + "," + str(add) + "," + str(ifnode), None)
		XSI.EditICECompoundProperties(str(compound), "CorrectiveShape", "", "", "", "", "", 1, 0, "", 4, 6732954)
		XSI.AddExposedParamToICECompoundNode(str(ifnode) + ".Condition", str(compound), None, "Mute")

	if not exist:
		compound = Dispatch(tree.Nodes("CorrectiveShape"))
		add = compound.Nodes.Filter("AddNode")(0)
		
		mult = XSI.AddIceNode("MultiplyByScalarNode", str(compound))
		
		addInputs = add.InputPorts
		checkPorts = -1
		p = 0
		for i in addInputs:
			if not i.IsConnected:
				checkPorts = p
				break
			p += 1
				
		if not checkPorts == -1:
			XSI.ConnectIceNodes(str(add) + ".Value" + str(checkPorts + 1), str(mult) + ".Result")

		else:
			index = add.InputPorts.Count
			XSI.AddPortToICENode(str(add) + ".Value" + str(index), constants.siNodePortDataInsertionLocationAfter)
			XSI.ConnectICENodes (str(add) + ".Value" + str(index + 1), str(mult) + ".Result")
		
		shapeStr = "Self.cls.CorrectiveShapeCls."+shapeNode.Name+".positions"
		getShape = XSI.AddIceNode("GetDataNode", str(tree))
		getShape.Parameters("Reference").Value = shapeStr
		
		inputs = compound.InputPorts
		count = 0

		for i in inputs:
			if i.Name.find("Position") > -1:
				count += 1
		
		XSI.AddExposedParamToICECompoundNode(str(mult) + ".value", str(compound), None, "Position")
		XSI.EditExposedParamInICECompoundNode(str(compound) + ".Position", "Position" + str(frame), "0", "0", None, None, 0, "")
		XSI.AddExposedParamToICECompoundNode(str(mult) + ".Factor", str(compound), None, "Factor")
		XSI.EditExposedParamInICECompoundNode(str(compound) + ".Factor", "Frame" + str(frame), "0", "1", None, None, 0, "")
		
		XSI.ConnectICENodes(str(compound) + ".Position" + str(frame), str(getShape) + ".value")
		
		XSI.InspectObj(compound, None, None, constants.siLock)
		
	# delete all nodes between secondary shape modeling and animation markers
	for h in prim.ConstructionHistory:
		if h.FullName.find('marker') == -1:
			XSI.DeleteObj(h)
		if h.Name == 'Animation':
			break