public int GetSlotIndex(VFXSlot slot) { var slotList = slot.direction == VFXSlot.Direction.kInput ? m_InputSlots : m_OutputSlots; return(slotList.IndexOf(slot)); }
protected bool SyncSlots(VFXSlot.Direction direction, bool notify) { bool isInput = direction == VFXSlot.Direction.kInput; var expectedProperties = (isInput ? inputProperties : outputProperties).ToArray(); int nbSlots = isInput ? GetNbInputSlots() : GetNbOutputSlots(); var currentSlots = isInput ? inputSlots : outputSlots; // check all slots owner (TODO Still useful?) for (int i = 0; i < nbSlots; ++i) { VFXSlot slot = currentSlots[i]; var slotOwner = slot.owner as VFXSlotContainerModel <ParentType, ChildrenType>; if (slotOwner != this) { Debug.LogError("Slot :" + slot.name + " of Container" + name + "Has a wrong owner."); slot.SetOwner(this); // make sure everything works even if the owner was lost for some reason. } } bool recreate = false; if (nbSlots != expectedProperties.Length) { recreate = true; } else { for (int i = 0; i < nbSlots; ++i) { if (!currentSlots[i].property.Equals(expectedProperties[i].property)) { recreate = true; break; } } } if (recreate) { var existingSlots = new List <VFXSlot>(currentSlots); // Remove all slots for (int i = nbSlots - 1; i >= 0; --i) { InnerRemoveSlot(currentSlots[i], false); } var newSlotCount = expectedProperties.Length; var newSlots = new VFXSlot[newSlotCount]; var createdSlots = new List <VFXSlot>(newSlotCount); // Reuse slots that already exists or create a new one if not for (int i = 0; i < newSlotCount; ++i) { var p = expectedProperties[i]; var slot = existingSlots.Find(s => p.property.Equals(s.property)); if (slot != null) { slot.UpdateAttributes(p.property.attributes, notify); existingSlots.Remove(slot); } else { slot = VFXSlot.Create(p, direction); createdSlots.Add(slot); } newSlots[i] = slot; } for (int i = 0; i < createdSlots.Count; ++i) { var dstSlot = createdSlots[i]; // Try to keep links and value for slots of same name and compatible types var srcSlot = existingSlots.FirstOrDefault(s => s.property.name == dstSlot.property.name); // Find the first slot with same type (should perform a more clever selection based on name distance) if (srcSlot == null) { srcSlot = existingSlots.FirstOrDefault(s => s.property.type == dstSlot.property.type); } // Try to find a slot that can be implicitely converted if (srcSlot == null) { srcSlot = existingSlots.FirstOrDefault(s => VFXConverter.CanConvertTo(s.property.type, dstSlot.property.type)); } if (srcSlot != null) { VFXSlot.CopyLinksAndValue(dstSlot, srcSlot, notify); srcSlot.UnlinkAll(true, notify); existingSlots.Remove(srcSlot); } } // Remove all remaining links foreach (var slot in existingSlots) { slot.UnlinkAll(true, notify); } // Add all slots foreach (var s in newSlots) { InnerAddSlot(s, -1, false); } if (notify) { Invalidate(InvalidationCause.kStructureChanged); } } else { // Update properties for (int i = 0; i < nbSlots; ++i) { VFXProperty prop = currentSlots[i].property; currentSlots[i].UpdateAttributes(expectedProperties[i].property.attributes, notify); } } return(recreate); }
public static void MigrateBlockTShapeFromShape(VFXBlock to, VFXBlock from) { var fromSettings = from.GetSettings(true); var toSettings = to.GetSettings(true); foreach (var fromSetting in fromSettings) { var toSetting = toSettings.FirstOrDefault(o => o.name.Equals(fromSetting.name, StringComparison.InvariantCultureIgnoreCase)); if (toSetting.field != null) { to.SetSettingValue(toSetting.name, fromSetting.value); } } if (from.inputSlots.Count != to.inputSlots.Count) { throw new InvalidOperationException(); } for (int i = 0; i < from.inputSlots.Count; ++i) { var fromInputSlot = from.inputSlots[i]; var toInputSlot = to.inputSlots[i]; if (toInputSlot.property.type == fromInputSlot.property.type) { VFXSlot.CopyLinksAndValue(toInputSlot, fromInputSlot, true); } else if (toInputSlot.property.type == typeof(TArcSphere)) { MigrateTArcSphereFromArcSphere(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TArcCircle)) { MigrateTArcCircleFromArcCircle(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TArcTorus)) { MigrateTArcTorusFromArcTorus(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TArcCone)) { //There wasn't a TArcCylinder type MigrateTArcConeFromArcCone(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TSphere)) { MigrateTSphereFromSphere(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TCircle)) { MigrateTCircleFromCircle(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TTorus)) { MigrateTTorusFromTorus(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TCone) && fromInputSlot.property.type == typeof(Cone)) { //Actually, no reference of this case MigrateTConeFromCone(toInputSlot, fromInputSlot); } else if (toInputSlot.property.type == typeof(TCone) && fromInputSlot.property.type == typeof(Cylinder)) { MigrateTConeFromCylinder(toInputSlot, fromInputSlot); } else { throw new NotImplementedException(); } } }
public virtual void RemoveSlot(VFXSlot slot) { InnerRemoveSlot(slot, true); }
public uint FindReducedExpressionIndexFromSlotCPU(VFXSlot slot) { RecompileIfNeeded(false, true); return(compiledData.FindReducedExpressionIndexFromSlotCPU(slot)); }
public virtual void OnCopyLinksOtherSlot(VFXSlot mySlot, VFXSlot prevOtherSlot, VFXSlot newOtherSlot) { }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { if (expression.valueType == VFXValueType.Float3) { return(VFXOperatorUtility.CastFloat(expression, VFXValueType.Float4, 1.0f)); } return(base.ConvertExpression(expression, sourceSlot)); }
private static void CollectExposedDesc(List <VFXMapping> outExposedParameters, string name, VFXSlot slot, VFXExpressionGraph graph) { var expression = slot.valueType != VFXValueType.None ? slot.GetInExpression() : null; if (expression != null) { var exprIndex = graph.GetFlattenedIndex(expression); if (exprIndex == -1) { throw new InvalidOperationException("Unable to retrieve value from exposed for " + name); } outExposedParameters.Add(new VFXMapping() { name = name, index = exprIndex }); } else { foreach (var child in slot.children) { CollectExposedDesc(outExposedParameters, name + "_" + child.name, child, graph); } } }
public SortingCriterion() { sortCriterion = SortCriteria.DistanceToCamera; sortKeySlot = null; }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { if (sourceSlot != null) { if (sourceSlot.GetType() == typeof(VFXSlotDirection)) { return(expression); //avoid multiple normalization } if (sourceSlot.property.attributes != null && sourceSlot.property.attributes.OfType <NormalizeAttribute>().Any()) { return(expression); //avoid multiple normalization form Normalize attribute (rarely used for output slot) } } if (expression.valueType == VFXValueType.Float4) { expression = VFXOperatorUtility.CastFloat(expression, VFXValueType.Float3); } return(ApplyPatchExpression(expression)); }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { return(ConvertExpressionToVector3(expression)); }
public static void MigrateTConeFromCylinder(VFXSlot to, VFXSlot from) { var lastModel = from.owner as VFXModel; while (!(lastModel.GetParent() is VFXGraph)) { lastModel = lastModel.GetParent(); } var basePosition = lastModel.position; var graph = lastModel.GetParent() as VFXGraph; var to_center = to[0][0]; var to_baseRadius = to[1]; var to_topRadius = to[2]; var to_height = to[3]; var refSlot = from.refSlot; VFXSlot.CopySpace(to, refSlot, true); if (from.HasLink(false)) { var parentCenter = refSlot[0]; var parentRadius = refSlot[1]; var parentHeight = refSlot[2]; var correctedPosition = CorrectPositionFromCylinderToCone(graph, basePosition, parentHeight, parentCenter); correctedPosition.Link(to_center); to_baseRadius.Link(parentRadius, true); to_topRadius.Link(parentRadius, true); to_height.Link(parentHeight, true); } else { var center = from[0]; var radius = from[1]; var height = from[2]; var value = new TCone() { transform = new Transform() { position = (Vector3)center.value - new Vector3(0, (float)height.value * 0.5f, 0), scale = Vector3.one }, height = (float)height.value, baseRadius = (float)radius.value, topRadius = (float)radius.value, }; to.value = value; if (from.HasLink(true)) { var correctedPosition = CorrectPositionFromCylinderToCone(graph, basePosition, height, center); correctedPosition.Link(to_center); } VFXSlot.CopyLinksAndValue(to_baseRadius, radius, true); VFXSlot.CopyLinksAndValue(to_topRadius, radius, true); VFXSlot.CopyLinksAndValue(to_height, height, true); } }
private static VFXSlot CorrectPositionFromCylinderToCone(VFXGraph graph, Vector2 basePosition, VFXSlot height, VFXSlot center) { var inlineHeight = ScriptableObject.CreateInstance <VFXInlineOperator>(); inlineHeight.SetSettingValue("m_Type", (SerializableType)typeof(float)); inlineHeight.position = basePosition - new Vector2(700.0f, -151.0f); VFXSlot.CopyLinksAndValue(inlineHeight.inputSlots[0], height, true); graph.AddChild(inlineHeight); var halfHeight = ScriptableObject.CreateInstance <Operator.Multiply>(); halfHeight.SetOperandType(0, typeof(float)); halfHeight.SetOperandType(1, typeof(float)); halfHeight.inputSlots[0].Link(inlineHeight.outputSlots[0]); halfHeight.inputSlots[1].value = 0.5f; halfHeight.position = basePosition - new Vector2(480.0f, -111.0f); graph.AddChild(halfHeight); var inlinePosition = ScriptableObject.CreateInstance <VFXInlineOperator>(); inlinePosition.SetSettingValue("m_Type", (SerializableType)typeof(Position)); inlinePosition.position = basePosition - new Vector2(555.0f, -20.0f); VFXSlot.CopyLinksAndValue(inlinePosition.inputSlots[0], center, true); graph.AddChild(inlinePosition); var correctedPosition = ScriptableObject.CreateInstance <Operator.Subtract>(); correctedPosition.SetOperandType(0, typeof(Position)); correctedPosition.SetOperandType(1, typeof(Position)); VFXSlot.CopySpace(correctedPosition.inputSlots[0], inlinePosition.outputSlots[0], true); VFXSlot.CopySpace(correctedPosition.inputSlots[1], inlinePosition.outputSlots[0], true); correctedPosition.inputSlots[0].Link(inlinePosition.outputSlots[0]); correctedPosition.inputSlots[1][0][1].Link(halfHeight.outputSlots[0]); correctedPosition.position = basePosition - new Vector2(282.0f, -20.0f); graph.AddChild(correctedPosition); return(correctedPosition.outputSlots[0]); }
public virtual VFXCoordinateSpace GetOutputSpaceFromSlot(VFXSlot slot) { return((VFXCoordinateSpace)int.MaxValue); }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { if (expression.valueType == VFXValueType.Matrix4x4) { return(expression); } throw new Exception("Unexpected type of expression " + expression); }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { if (expression.valueType == VFXValueType.Int32) { return(expression); } if (expression.valueType == VFXValueType.Uint32) { return(new VFXExpressionCastUintToInt(expression)); } if (expression.valueType == VFXValueType.Float) { return(new VFXExpressionCastFloatToInt(expression)); } if (expression.valueType == VFXValueType.Float2 || expression.valueType == VFXValueType.Float3 || expression.valueType == VFXValueType.Float4) { return(new VFXExpressionCastFloatToInt(expression.x)); } throw new Exception("Unexpected type of expression " + expression); }
public override VFXCoordinateSpace GetOutputSpaceFromSlot(VFXSlot slot) { return(VFXCoordinateSpace.Local); }
private static void CollectExposedExpression(List <VFXExpression> expressions, VFXSlot slot) { var expression = slot.valueType != VFXValueType.None ? slot.GetInExpression() : null; if (expression != null) { expressions.Add(expression); } else { foreach (var child in slot.children) { CollectExposedExpression(expressions, child); } } }
public static void ReplaceModel(VFXModel dst, VFXModel src, bool notify = true) { // UI dst.m_UIPosition = src.m_UIPosition; dst.m_UICollapsed = src.m_UICollapsed; dst.m_UISuperCollapsed = src.m_UISuperCollapsed; if (notify) { dst.Invalidate(InvalidationCause.kUIChanged); } VFXGraph graph = src.GetGraph(); if (graph != null && graph.UIInfos != null && graph.UIInfos.groupInfos != null) { // Update group nodes foreach (var groupInfo in graph.UIInfos.groupInfos) { if (groupInfo.contents != null) { for (int i = 0; i < groupInfo.contents.Length; ++i) { if (groupInfo.contents[i].model == src) { groupInfo.contents[i].model = dst; } } } } } if (dst is VFXBlock && src is VFXBlock) { ((VFXBlock)dst).enabled = ((VFXBlock)src).enabled; } // Unlink everything if (src is IVFXSlotContainer) { var slotContainer = src as IVFXSlotContainer; VFXSlot slotToClean = null; do { slotToClean = slotContainer.inputSlots.Concat(slotContainer.outputSlots).FirstOrDefault(o => o.HasLink(true)); if (slotToClean) { slotToClean.UnlinkAll(true, true); } }while (slotToClean != null); } // Replace model var parent = src.GetParent(); int index = parent.GetIndex(src); src.Detach(notify); if (parent) { parent.AddChild(dst, index, notify); } }
public virtual void AddSlot(VFXSlot slot, int index = -1) { InnerAddSlot(slot, index, true); }
sealed protected override VFXExpression ConvertExpression(VFXExpression expression, VFXSlot sourceSlot) { if (expression.valueType == VFXValueType.Float3) { return(expression); } if (expression.valueType == VFXValueType.Float) { return(new VFXExpressionCombine(expression, expression, expression)); } if (expression.valueType == VFXValueType.Uint32) { var floatExpression = new VFXExpressionCastUintToFloat(expression); return(new VFXExpressionCombine(floatExpression, floatExpression, floatExpression)); } if (expression.valueType == VFXValueType.Int32) { var floatExpression = new VFXExpressionCastIntToFloat(expression); return(new VFXExpressionCombine(floatExpression, floatExpression, floatExpression)); } if (expression.valueType == VFXValueType.Float4) { return(new VFXExpressionCombine(expression.x, expression.y, expression.z)); } throw new Exception("Unexpected type of expression " + expression + "valueType" + expression.valueType); }
public virtual void OnCopyLinksMySlot(VFXSlot myPrevSlot, VFXSlot myNewSlot, VFXSlot otherSlot) { }
public override void OnCopyLinksMySlot(VFXSlot myPrevSlot, VFXSlot myNewSlot, VFXSlot otherSlot) { foreach (var node in nodes) { if (node.linkedSlots != null) { for (int i = 0; i < node.linkedSlots.Count; ++i) { if (node.linkedSlots[i].outputSlot == myPrevSlot && node.linkedSlots[i].inputSlot == otherSlot) { node.linkedSlots[i] = new NodeLinkedSlot() { outputSlot = myNewSlot, inputSlot = otherSlot }; return; } } } } }