public override bool Sync() { IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (IsChanged) { Length = FNodeIn.SliceCount; using (var writer = GetWriter()) { object usI; FNodeIn.GetUpstreamInterface(out usI); var upstreamInterface = usI as IGenericIO; for (int i = 0; i < Length; i++) { int usS; var result = default(T); if (upstreamInterface != null) { FNodeIn.GetUpsreamSlice(i, out usS); result = (T)upstreamInterface.GetSlice(usS); } writer.Write(result); } } } return(base.Sync()); }
public override bool Sync() { IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (IsChanged) { Length = FNodeIn.SliceCount; using (var writer = GetWriter()) { object usI; FNodeIn.GetUpstreamInterface(out usI); var upstreamInterface = usI as IGenericIO; for (int i = 0; i < Length; i++) { int usS; T result = new T(); if (upstreamInterface != null) { FNodeIn.GetUpsreamSlice(i, out usS); IDX11ResourceDataProvider res = (IDX11ResourceDataProvider)upstreamInterface.GetSlice(usS); if (result == null) { res = new T(); } result.Assign(res); } writer.Write(result); } } } return(base.Sync()); }
//called when data for any output pin is requested public void Evaluate(int spreadMax) { object myData; FX.GetUpstreamInterface(out myData); if (myData == null) { return; } int upSlice; FX.GetUpsreamSlice(0, out upSlice); var myValueData = myData as IValueData; if (myValueData != null) { double x; myValueData.GetValue(upSlice, out x); FValueOut[0] = x; } var myColorData = myData as IColorData; if (myColorData != null) { RGBAColor x; myColorData.GetColor(upSlice, out x); FColorOut[0] = x; } }
public void Evaluate(int SpreadMax) { if (V1SkeletonIn.SliceCount == 0) { FOut.SliceCount = 0; return; } if (V1SkeletonIn.PinIsChanged || FCopy.IsChanged) { if (!V1SkeletonIn.IsConnected) { FOut.Stream.IsChanged = false; return; } object usinterface; V1SkeletonIn.GetUpstreamInterface(out usinterface); var skeletonin = (ISkeleton)usinterface; if (FCopy[0]) { FOut[0] = skeletonin.DeepCopy(); } else { FOut[0] = skeletonin; } } else { FOut.Stream.IsChanged = false; } }
public object GetUpstreamInterface() { object usi; Pin.GetUpstreamInterface(out usi); return(usi); }
public ISpread <T> TryTypedSpread <T>() { var type = typeof(T); object upData; NodeIn.GetUpstreamInterface(out upData); var stream = upData as IInStream <T>; if (stream != null) { return(GetGenericSpread <T>(upData)); } if (type == typeof(float) || type == typeof(double)) { return(GetValueSpread <T>(upData)); } if (type == typeof(RGBAColor)) { return(GetColorSpread <T>(upData)); } if (type == typeof(string)) { return(GetStringSpread <T>(upData)); } if (type == typeof(System.Runtime.InteropServices.ComTypes.IStream)) { return(GetRawSpread <T>(upData)); } return(null); }
public override bool Sync() { IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (IsChanged) { Length = FNodeIn.SliceCount; FSubscriptions.ResizeAndDispose( Length, slice => { return(new Subscription <Keyboard, KeyNotification>( keyboard => keyboard.KeyNotifications, (keyboard, n) => { var keyboardState = this.Buffer[slice]; IEnumerable <Keys> keys; switch (n.Kind) { case KeyNotificationKind.KeyDown: var downNotification = n as KeyDownNotification; keys = keyboardState.KeyCodes.Concat(new [] { downNotification.KeyCode }); keyboardState = new KeyboardState(keys, keyboard.CapsLock, keyboardState.Time + 1); break; case KeyNotificationKind.KeyUp: var upNotification = n as KeyUpNotification; keys = keyboardState.KeyCodes.Except(new[] { upNotification.KeyCode }); keyboardState = new KeyboardState(keys, keyboardState.CapsLock, keyboardState.Time + 1); break; } this.Buffer[slice] = keyboardState; } )); } ); using (var writer = GetWriter()) { object usI; FNodeIn.GetUpstreamInterface(out usI); var upstreamInterface = usI as IGenericIO; for (int i = 0; i < Length; i++) { int usS; var keyboard = Keyboard.Empty; if (upstreamInterface != null) { FNodeIn.GetUpsreamSlice(i, out usS); keyboard = (Keyboard)upstreamInterface.GetSlice(usS); } writer.Write(KeyboardState.Empty); FSubscriptions[i].Update(keyboard); } } } return(base.Sync()); }
public override bool Sync() { var nodeConnectionChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (nodeConnectionChanged) { Length = FNodeIn.SliceCount; FSubscriptions.ResizeAndDispose( Length, slice => { return(new Subscription <Keyboard, KeyNotification>( keyboard => keyboard.KeyNotifications, (keyboard, n) => { var keyboardState = this.Buffer[slice]; IEnumerable <Keys> keys; switch (n.Kind) { case KeyNotificationKind.KeyDown: var downNotification = n as KeyDownNotification; keys = keyboardState.KeyCodes.Concat(new [] { downNotification.KeyCode }); keyboardState = new KeyboardState(keys, keyboard.CapsLock, keyboardState.Time + 1); break; case KeyNotificationKind.KeyUp: var upNotification = n as KeyUpNotification; keys = keyboardState.KeyCodes.Except(new[] { upNotification.KeyCode }); keyboardState = new KeyboardState(keys, keyboardState.CapsLock, keyboardState.Time + 1); break; } SetKeyboardState(slice, keyboardState); } )); } ); object usI; FNodeIn.GetUpstreamInterface(out usI); var stream = usI as MemoryIOStream <Keyboard>; for (int i = 0; i < Length; i++) { int usS; var keyboard = Keyboard.Empty; if (stream != null) { FNodeIn.GetUpsreamSlice(i, out usS); keyboard = stream[usS]; } if (FSubscriptions[i].Update(keyboard)) { SetKeyboardState(i, KeyboardState.Empty); } } } return(base.Sync()); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs if (FSkeletonInput.PinIsChanged) { if (FSkeletonInput.IsConnected) { object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); inputSkeleton = (Skeleton)currInterface; } else { inputSkeleton = null; } } if (FSkeletonInput.PinIsChanged || FJointNameInput.PinIsChanged) { if (inputSkeleton != null) { string jointName; IJoint currJoint; FParentNameOutput.SliceCount = FJointNameInput.SliceCount; FBaseTransformOutput.SliceCount = FJointNameInput.SliceCount; FAnimationTransformOutput.SliceCount = FJointNameInput.SliceCount; for (int i = 0; i < FJointNameInput.SliceCount; i++) { FJointNameInput.GetString(i, out jointName); if (inputSkeleton.JointTable.ContainsKey(jointName)) { currJoint = (IJoint)inputSkeleton.JointTable[jointName]; if (currJoint.Parent != null) { FParentNameOutput.SetString(i, currJoint.Parent.Name); } else { FParentNameOutput.SetString(i, ""); } FJointIdOutput.SetValue(i, currJoint.Id); FBaseTransformOutput.SetMatrix(i, VMath.Rotate(currJoint.Rotation) * currJoint.BaseTransform); FAnimationTransformOutput.SetMatrix(i, currJoint.AnimationTransform); } else { FJointIdOutput.SetValue(i, -1); FBaseTransformOutput.SetMatrix(i, VMath.IdentityMatrix); FAnimationTransformOutput.SetMatrix(i, VMath.IdentityMatrix); } } } } }
public void ConnectPin(IPluginIO Pin) { //cache a reference to the upstream interface when the NodeInput pin is being connected if (Pin == FPinInConnection) { object usI; FPinInConnection.GetUpstreamInterface(out usI); FConnectionObject = usI as AbstractDbConnection <D>; } }
public bool Sync() { IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (IsChanged) { object usI; FNodeIn.GetUpstreamInterface(out usI); FNodeIn.GetUpStreamSlices(out FLength, out FUpStreamSlices); // Check fastest way first: TUpstream == T var wrapper = usI as DynamicTypeWrapper; if (wrapper != null) { usI = wrapper.Value; } FUpstreamStream = usI as MemoryIOStream <T>; if (FUpstreamStream == null) { // TUpstream is a subtype of T // Copy the upstream stream through the covariant IEnumerable interface var enumerable = usI as IEnumerable <T>; if (enumerable != null) { FUpstreamStream = enumerable.ToStream(); } if (FUpstreamStream == null) { // TUpstream to T needs explicit cast // For example TUpstream is a value type and T is a reference type var objects = usI as IEnumerable; if (objects != null) { FUpstreamStream = objects.Cast <T>().ToStream(); } else { // Not connected FUpstreamStream = FNullStream; FUpstreamStream.Length = FLength; using (var writer = FUpstreamStream.GetWriter()) while (!writer.Eos) { writer.Write(FDefaultValue); } } } } } return(IsChanged); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FSkeletonInput.PinIsChanged) { if (FSkeletonInput.IsConnected) { object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); FSkeleton = (Skeleton)currInterface; } else { FSkeleton = null; } } if (FSkeletonInput.PinIsChanged) { if (FSkeleton != null) { int key_count = FSkeleton.JointTable.Keys.Count; string[] key_list = new string[key_count]; FSkeleton.JointTable.Keys.CopyTo(key_list, 0); FJointNameOutput.SliceCount = key_count; FParentNameOutput.SliceCount = key_count; for (int i = 0; i < key_count; i++) { FJointNameOutput.SetString(i, key_list[i]); IJoint joint = null; FSkeleton.JointTable.TryGetValue(key_list[i], out joint); string pname = ""; if (joint != null && joint.Parent != null) { pname = joint.Parent.Name; } FParentNameOutput.SetString(i, pname); } } } }
public bool Sync() { IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (IsChanged) { object usI; FNodeIn.GetUpstreamInterface(out usI); // Check fastest way first: TUpstream == T FUpstreamStream = usI as MemoryIOStream <T>; if (FUpstreamStream != null) { FNodeIn.GetUpStreamSlices(out FLength, out FUpStreamSlices); } else { FLength = FNodeIn.SliceCount; // TUpstream is a subtype of T var enumerable = usI as IEnumerable <T>; if (enumerable != null) { FUpstreamStream = new MemoryIOStream <T>(FLength); FUpstreamStream.Length = FLength; using (var writer = FUpstreamStream.GetWriter()) foreach (var item in enumerable) { writer.Write(item); } } else { // Not connected FUpstreamStream = FNullStream; FUpstreamStream.Length = FLength; } } } return(IsChanged); }
public void Evaluate(int spreadmax) { if (FUpdate[0]) { object data; FInput.GetUpstreamInterface(out data); FName.SliceCount = 0; FAssembly.SliceCount = 0; FLocation.SliceCount = 0; if (data != null) { var t = data.GetType(); FName.Add(t.FullName); FAssembly.Add(t.Assembly.FullName); FLocation.Add(t.Assembly.Location); if (t.Name.Contains("DynamicTypeWrapper")) { t = t.GetField("Value").GetValue(data).GetType(); FName.Add(t.FullName); FAssembly.Add(t.Assembly.FullName); FLocation.Add(t.Assembly.Location); } if (t.IsGenericType) { foreach (var it in t.GetGenericArguments()) { FName.Add(it.FullName); FAssembly.Add(it.Assembly.FullName); FLocation.Add(it.Assembly.Location); } } } } }
//called when data for any output pin is requested public void Evaluate(int spreadMax) { object myData; FX.GetUpstreamInterface(out myData); if (myData == null) { FOutput[0] = "not connected"; return; } int upSlice; FX.GetUpsreamSlice(0, out upSlice); var myValueData = myData as IValueData; if (myValueData != null) { double x; myValueData.GetValue(upSlice, out x); FOutput[0] = "value: " + x.ToString(); FValueOut[0] = x; return; } var myStringData = myData as IStringData; if (myStringData != null) { string x; myStringData.GetString(upSlice, out x); FOutput[0] = "string: " + x.ToString(); return; } var myColorData = myData as IColorData; if (myColorData != null) { RGBAColor x; myColorData.GetColor(upSlice, out x); FOutput[0] = "color: " + x.ToString(); FColorOut[0] = x; return; } var myRawData = myData as IRawData; if (myRawData != null) { IStream x; myRawData.GetData(upSlice, out x); FOutput[0] = "raw: " + x.ToString(); return; } var myFooData = myData as IEnumerable <object>; if (myFooData != null && myFooData.Any()) { var spread = myFooData.ToSpread(); FOutput[0] = spread[upSlice].ToString(); return; } FLogger.Log(LogType.Debug, myData.ToString()); FOutput[0] = "unknown data"; }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs bool recalculate = false; if (FJointNameInput.PinIsChanged) { jointNames = new List <string>(); string jointName; for (int i = 0; i < FJointNameInput.SliceCount; i++) { FJointNameInput.GetString(i, out jointName); jointNames.Add(jointName); } recalculate = true; if (jointNames.Count == 1 && string.IsNullOrEmpty(jointNames[0])) { jointsSelected = false; } else { jointsSelected = true; } } if (FSkeletonInput.PinIsChanged) { if (FSkeletonInput.IsConnected) { object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); inputSkeleton = (Skeleton)currInterface; // if there are no specific joints selected via input pin, collect them all if (jointNames == null || !jointsSelected) { jointNames = new List <string>(); foreach (KeyValuePair <string, IJoint> pair in inputSkeleton.JointTable) { // Only add those with a valid array index. // It's not a must that all bones are used as skinning matrices. if (pair.Value.Id >= 0) { jointNames.Add(pair.Key); } } } } else { inputSkeleton = null; } recalculate = true; } if (FInverseBindPoseInput.PinIsChanged) { recalculate = true; } if (FOutputModeInput.PinIsChanged) { FOutputModeInput.GetOrd(0, out outputMode); recalculate = true; } if (recalculate && inputSkeleton != null) { inputSkeleton.CalculateCombinedTransforms(); int jointCount; if (outputMode == OUTPUT_MODE_DYNAMIC) { jointCount = jointNames.Count; } else { jointCount = 60; } FTransformOutput.SliceCount = jointCount; IJoint currJoint; Matrix4x4 currIBPMatrix; int i = 0; for (i = 0; i < jointNames.Count; i++) { currJoint = inputSkeleton.JointTable[jointNames[i]]; if (currJoint != null) { int sliceIndex; if (outputMode == OUTPUT_MODE_STATIC) { sliceIndex = currJoint.Id; } else { sliceIndex = i; } FInverseBindPoseInput.GetMatrix(sliceIndex, out currIBPMatrix); FTransformOutput.SetMatrix(sliceIndex, currIBPMatrix * currJoint.CombinedTransform); } } // Pad remaining slices with Identity Matrices for (int j = i; j < jointCount; j++) { FTransformOutput.SetMatrix(j, VMath.IdentityMatrix); } } }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs if (FSkeletonInput.PinIsChanged || !initialized) { jointPositions = new Dictionary <string, Vector3D>(); object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); try { skeleton = (Skeleton)currInterface; } catch (Exception e) { FHost.Log(TLogType.Error, e.Message); } rootJoint = (IJoint)skeleton.Root; if (!initialized && configSelectedNames != null) { selectedJoints.Clear(); IJoint currJoint; for (int i = 0; i < configSelectedNames.Length; i++) { if (string.IsNullOrEmpty(configSelectedNames[i])) { break; } if (skeleton.JointTable.ContainsKey(configSelectedNames[i])) { currJoint = skeleton.JointTable[configSelectedNames[i]]; if (currJoint != null) { selectedJoints.Add(currJoint); } } } } //redraw gui only if anything changed Invalidate(); } if (selectedJoints.Count > 0) { FJointNameOutput.SliceCount = selectedJoints.Count; for (int i = 0; i < selectedJoints.Count; i++) { FJointNameOutput.SetString(i, selectedJoints[i].Name); } } else { FJointNameOutput.SetString(0, ""); } buildConfig(); initialized = true; }
public override bool Sync() { var nodeConnectionChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate(); if (nodeConnectionChanged) { Length = FNodeIn.SliceCount; FRawMouseWheels.SliceCount = Length; FSubscriptions.ResizeAndDispose( Length, slice => { return(new Subscription <Mouse, MouseNotification>( mouse => mouse.MouseNotifications, (mouse, n) => { var position = new Vector2D(n.Position.X, n.Position.Y); var clientArea = new Vector2D(n.ClientArea.Width - 1, n.ClientArea.Height - 1); var normalizedPosition = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float); var mouseState = this.Buffer[slice]; switch (n.Kind) { case MouseNotificationKind.MouseDown: var downNotification = n as MouseButtonNotification; mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons | downNotification.Buttons, mouseState.MouseWheel); break; case MouseNotificationKind.MouseUp: var upNotification = n as MouseButtonNotification; mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons & ~upNotification.Buttons, mouseState.MouseWheel); break; case MouseNotificationKind.MouseMove: mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons, mouseState.MouseWheel); break; case MouseNotificationKind.MouseWheel: var wheelNotification = n as MouseWheelNotification; FRawMouseWheels[slice] += wheelNotification.WheelDelta; var wheel = (int)Math.Round((float)FRawMouseWheels[slice] / Const.WHEEL_DELTA); mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons, wheel); break; } SetMouseState(slice, ref mouseState); } )); } ); object usI; FNodeIn.GetUpstreamInterface(out usI); var upstreamInterface = usI as IGenericIO; var emptyMouseState = new MouseState(); for (int i = 0; i < Length; i++) { int usS; var mouse = Mouse.Empty; if (upstreamInterface != null) { FNodeIn.GetUpsreamSlice(i, out usS); mouse = (Mouse)upstreamInterface.GetSlice(usS); } SetMouseState(i, ref emptyMouseState); FSubscriptions[i].Update(mouse); } } return(base.Sync()); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs bool recalculate = false; bool chainRangeChanged = false; bool recalculateOrientation = false; if (FChainStart.PinIsChanged) { FChainStart.GetString(0, out chainStart); recalculate = true; chainRangeChanged = true; } if (FChainEnd.PinIsChanged) { FChainEnd.GetString(0, out chainEnd); recalculate = true; chainRangeChanged = true; } object currInterface; if (FPoseInput.PinIsChanged || chainRangeChanged) { if (FPoseInput.IsConnected) { FPoseInput.GetUpstreamInterface(out currInterface); Skeleton s = (Skeleton)currInterface; if (outputSkeleton == null || !s.Uid.Equals(outputSkeleton.Uid)) { outputSkeleton = (Skeleton)((Skeleton)currInterface).DeepCopy(); outputSkeleton.BuildJointTable(); workingSkeleton = (Skeleton)outputSkeleton.DeepCopy(); workingSkeleton.BuildJointTable(); chainRangeChanged = true; } else { foreach (KeyValuePair <string, IJoint> pair in s.JointTable) { if (!jointChain.Exists(delegate(IJoint j) { return(j.Name == pair.Key); })) { outputSkeleton.JointTable[pair.Key].BaseTransform = pair.Value.BaseTransform; outputSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform; workingSkeleton.JointTable[pair.Key].BaseTransform = pair.Value.BaseTransform; workingSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform; } outputSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints; workingSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints; } } workingSkeleton.CalculateCombinedTransforms(); recalculate = true; } else { outputSkeleton = null; } } if (FVelocityInput.PinIsChanged) { double x; FVelocityInput.GetValue(0, out x); iterationsPerFrame = (int)(x * 10); } if (iterationsPerFrame > 0) { if (FTargetInput.PinIsChanged) { targetPosW = new Vector3D(); FTargetInput.GetValue3D(0, out targetPosW.x, out targetPosW.y, out targetPosW.z); recalculate = true; } if (FEpsilonInput.PinIsChanged) { FEpsilonInput.GetValue(0, out epsilon); recalculate = true; } if (FPoleTargetInput.PinIsChanged || FEnablePoleTargetInput.PinIsChanged) { double x; FEnablePoleTargetInput.GetValue(0, out x); enablePoleTarget = x > 0.0; poleTargetW = new Vector3D(); FPoleTargetInput.GetValue3D(0, out poleTargetW.x, out poleTargetW.y, out poleTargetW.z); recalculateOrientation = true; } if (chainRangeChanged && outputSkeleton != null) { initRotations(); } double delta = VMath.Dist(endPosW, targetPosW); if ((delta > epsilon || recalculate) && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd)) { List <Vector2D> constraints = new List <Vector2D>(); for (int i = 0; i < iterationsPerFrame; i++) { for (int j = 0; j < 3; j++) { IJoint currJoint = workingSkeleton.JointTable[chainEnd]; endPosW = currJoint.CombinedTransform * new Vector3D(0); while (currJoint.Name != chainStart) { currJoint = currJoint.Parent; Vector3D rotationAxis = new Vector3D(0, 0, 0); rotationAxis[j] = 1; double torque = calculateTorque(currJoint, rotationAxis); Vector3D rot = rotations[currJoint.Name]; if ((rot[j] + torque) < currJoint.Constraints[j].x * 2 * Math.PI || (rot[j] + torque) > currJoint.Constraints[j].y * 2 * Math.PI) { torque = 0; } Matrix4x4 newTransform = VMath.Rotate(torque * rotationAxis.x, torque * rotationAxis.y, torque * rotationAxis.z) * currJoint.AnimationTransform; Vector3D testVec = newTransform * new Vector3D(0); if (!Double.IsInfinity(testVec.x) && !Double.IsNaN(testVec.x)) // an evil bug fix, to avoid n.def. values in animation transform matrix. the actual reason, why this would happen has not been found yet. { rot[j] += torque; rotations[currJoint.Name] = rot; currJoint.AnimationTransform = newTransform; outputSkeleton.JointTable[currJoint.Name].AnimationTransform = currJoint.AnimationTransform; } } } try { Matrix4x4 pre; if (workingSkeleton.JointTable[chainStart].Parent != null) { pre = workingSkeleton.JointTable[chainStart].Parent.CombinedTransform; } else { pre = VMath.IdentityMatrix; } ((JointInfo)workingSkeleton.JointTable[chainStart]).CalculateCombinedTransforms(pre); } catch (Exception) { workingSkeleton.CalculateCombinedTransforms(); } } FPoseOutput.MarkPinAsChanged(); } if ((recalculate || recalculateOrientation) && enablePoleTarget && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd)) { endPosW = workingSkeleton.JointTable[chainEnd].CombinedTransform * new Vector3D(0); Vector3D poleTargetLocal = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * poleTargetW; Vector3D t = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * endPosW; // endpoint in local coords Vector3D a = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * (workingSkeleton.JointTable[chainStart].Children[0].CombinedTransform * new Vector3D(0)); // next child in local coords Vector3D x = t * ((a.x * t.x + a.y * t.y + a.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2)); Vector3D y = t * ((poleTargetLocal.x * t.x + poleTargetLocal.y * t.y + poleTargetLocal.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2)); Vector3D c = poleTargetLocal - y; Vector3D b = a - x; double angle = vectorAngle(b, c); Vector3D n = new Vector3D(); n.x = c.y * b.z - c.z * b.y; n.y = c.z * b.x - c.x * b.z; n.z = c.x * b.y - c.y * b.x; n = n / VMath.Dist(new Vector3D(0), n); FDebugOutput.SetValue(0, angle); chainRotation = RotateAroundAxis(angle, n); FPoseOutput.MarkPinAsChanged(); } if (!enablePoleTarget) { chainRotation = VMath.IdentityMatrix; } outputSkeleton.JointTable[chainStart].AnimationTransform = chainRotation * outputSkeleton.JointTable[chainStart].AnimationTransform; } FPoseOutput.SetInterface(outputSkeleton); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs if (vertices.Count != FVerticesInput.SliceCount / 3) { vertices.Clear(); double x, y, z; for (int i = 0; i < FVerticesInput.SliceCount - 2; i += 3) { FVerticesInput.GetValue(i, out x); FVerticesInput.GetValue(i + 1, out y); FVerticesInput.GetValue(i + 2, out z); vertices.Add(new Vector3D(x, y, z)); } } if (FSkeletonInput.PinIsChanged) { if (FSkeletonInput.IsConnected) { object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); skeleton = (Skeleton)currInterface; } } double apply; FApplyInput.GetValue(0, out apply); if (apply == 1 && skeleton != null) { skeleton.CalculateCombinedTransforms(); skinWeights = new Dictionary <int, Dictionary <int, double> >(); Vector3D origin = new Vector3D(0); double d; for (int i = 0; i < vertices.Count; i++) { IJoint nearest = getNearestBone(vertices[i], skeleton.Root, out d); Dictionary <int, double> jointWeights = new Dictionary <int, double>(); jointWeights.Add(nearest.Id, 1.0); skinWeights.Add(i, jointWeights); } int sliceNum = 0; for (int i = 0; i < vertices.Count; i++) { if (!skinWeights.ContainsKey(i)) { continue; } IDictionaryEnumerator boneEnum = skinWeights[i].GetEnumerator(); while (boneEnum.MoveNext()) { FIndicesOutput.SliceCount = sliceNum + 1; FBindIndicesOutput.SliceCount = sliceNum + 1; FSkinWeightsOutput.SliceCount = sliceNum + 1; FIndicesOutput.SetValue(sliceNum, i); FBindIndicesOutput.SetValue(sliceNum, (int)boneEnum.Key); FSkinWeightsOutput.SetValue(sliceNum, (double)boneEnum.Value); sliceNum++; } } } }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs bool recalculate = false; if (FJointNameInput.PinIsChanged) { jointNames = new List <string>(); string jointName; for (int i = 0; i < FJointNameInput.SliceCount; i++) { FJointNameInput.GetString(i, out jointName); jointNames.Add(jointName); } recalculate = true; } if (FSkeletonInput.PinIsChanged || recalculate) { if (FSkeletonInput.IsConnected) { object currInterface; FSkeletonInput.GetUpstreamInterface(out currInterface); s = (Skeleton)currInterface; if (inputSkeleton == null || !s.Uid.Equals(inputSkeleton.Uid)) { inputSkeleton = (Skeleton)s.DeepCopy(); } else { foreach (KeyValuePair <string, IJoint> pair in s.JointTable) { if (!jointNames.Exists(delegate(string name) { return(name == pair.Key); })) { inputSkeleton.JointTable[pair.Key].BaseTransform = pair.Value.BaseTransform; inputSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform; } inputSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints; } } } else { inputSkeleton = null; } } if (FSkeletonInput.PinIsChanged || FAnimationTransformInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate) { if (inputSkeleton != null) { IJoint currJoint; for (int i = 0; i < jointNames.Count; i++) { currJoint = inputSkeleton.JointTable[jointNames[i]]; Matrix4x4 currAnimationT; Matrix4x4 currBaseT; string currParentName; if (currJoint != null) { if (FAnimationTransformInput.IsConnected) { FAnimationTransformInput.GetMatrix(i, out currAnimationT); currJoint.AnimationTransform = currAnimationT; } else { currJoint.AnimationTransform = s.JointTable[currJoint.Name].AnimationTransform; } if (FBaseTransformInput.IsConnected) { FBaseTransformInput.GetMatrix(i, out currBaseT); currJoint.BaseTransform = currBaseT; } else { currJoint.BaseTransform = s.JointTable[currJoint.Name].BaseTransform; } /*if (FRotationInput.IsConnected) * { * currRotation = new Vector3D(0); * FRotationInput.GetValue3D(i, out currRotation.x, out currRotation.y, out currRotation.z); * //currJoint.Rotation = currRotation; * * } */ /*if (FConstraintsInput.IsConnected) * { * currConstraints = new List<Vector2D>(); * Vector2D currConstraint; * for (int j=0; j<3; j++) * { * currConstraint = new Vector2D(0); * FConstraintsInput.GetValue2D(i*3, out currConstraint.x, out currConstraint.y); * currConstraints.Add(currConstraint); * } * currJoint.Constraints = currConstraints; * } */ FParentNameInput.GetString(i, out currParentName); if (currParentName != null && (FParentNameInput.SliceCount > 1 || !string.IsNullOrEmpty(currParentName))) { IJoint parent = inputSkeleton.JointTable[currParentName]; if (parent != null) { currJoint.Parent = parent; } } } } } FSkeletonOutput.MarkPinAsChanged(); } FSkeletonOutput.SetInterface(inputSkeleton); }