public override void WillCreateLink(ref VFXSlot myInput, ref VFXSlot otherOutput) { if (!myInput.IsMasterSlot()) { return; } //Since every input will change at the same time the metric to change is : // if we have no input links yet var myInputCopy = myInput; bool hasLink = inputPorts.Any(t => t.model != myInputCopy && t.model.HasLink()); int index = model.GetSlotIndex(myInput); if (model.staticSlotIndex.Contains(index)) { return; } // The new link is impossible if we don't change (case of a vector3 trying to be linked to a vector4) bool linkImpossibleNow = !myInput.CanLink(otherOutput) || !otherOutput.CanLink(myInput); var bestAffinity = model.GetBestAffinityType(otherOutput.property.type); if ((!hasLink || linkImpossibleNow) && bestAffinity != null) { model.SetOperandType(bestAffinity); myInput = model.GetInputSlot(index); } }
public override void WillCreateLink(ref VFXSlot myInput, ref VFXSlot otherOutput) { if (!myInput.IsMasterSlot()) { return; } var bestAffinityType = model.GetBestAffinityType(otherOutput.property.type); if (bestAffinityType != null) { int index = model.GetSlotIndex(myInput); model.SetOperandType(index, bestAffinityType); myInput = model.GetInputSlot(index); } }
public string ComputeSlotPath(VFXSlot slot) { if (slot.IsMasterSlot()) { return(string.Empty); } var parent = slot.GetParent(); var name = slot.name; while (!parent.IsMasterSlot()) { name = string.Format("{0}.{1}", parent.name, name); parent = parent.GetParent(); } return(name); }
public override void WillCreateLink(ref VFXSlot myInput, ref VFXSlot otherOutput) { if (!myInput.IsMasterSlot()) { return; } int inputIndex = model.GetSlotIndex(myInput); IVFXOperatorNumericUnifiedConstrained constraintInterface = model as IVFXOperatorNumericUnifiedConstrained; if (!constraintInterface.slotIndicesThatMustHaveSameType.Contains(inputIndex)) { base.WillCreateLink(ref myInput, ref otherOutput); return; } bool scalar = constraintInterface.slotIndicesThatCanBeScalar.Contains(inputIndex); if (scalar) { var bestAffinityType = model.GetBestAffinityType(otherOutput.property.type); VFXSlot otherSlotWithConstraint = model.inputSlots.Where((t, i) => constraintInterface.slotIndicesThatMustHaveSameType.Contains(i)).FirstOrDefault(); if (otherSlotWithConstraint == null || otherSlotWithConstraint.property.type == bestAffinityType) { model.SetOperandType(inputIndex, bestAffinityType); myInput = model.GetInputSlot(inputIndex); } else if (!myInput.CanLink(otherOutput) || !otherOutput.CanLink(myInput)) // if the link is invalid if we don't change the type, change the type to the matching scalar { var bestScalarAffinityType = model.GetBestAffinityType(GetMatchingScalar(otherOutput.property.type)); if (bestScalarAffinityType != null) { model.SetOperandType(inputIndex, bestScalarAffinityType); myInput = model.GetInputSlot(inputIndex); } } return; // never change the type of other constraint if the linked slot is scalar } VFXSlot input = myInput; bool hasLinks = model.inputSlots.Where((t, i) => t != input && t.HasLink(true) && constraintInterface.slotIndicesThatMustHaveSameType.Contains(i) && !constraintInterface.slotIndicesThatCanBeScalar.Contains(i)).Count() > 0; bool linkPossible = myInput.CanLink(otherOutput) && otherOutput.CanLink(myInput); if (!hasLinks || !linkPossible) //Change the type if other type having the same constraint have no link or if the link will fail if we don't { var bestAffinityType = model.GetBestAffinityType(otherOutput.property.type); if (bestAffinityType != null) { foreach (int slotIndex in constraintInterface.slotIndicesThatMustHaveSameType) { if (!constraintInterface.slotIndicesThatCanBeScalar.Contains(slotIndex) || GetMatchingScalar(bestAffinityType) != model.GetInputSlot(slotIndex).property.type) { model.SetOperandType(slotIndex, bestAffinityType); } } myInput = model.GetInputSlot(inputIndex); } } }