public override void estimate(MoveenSkelWithBonesEditor ed) { estimateImpl(ed); Vector3Entry entry2 = clone(); entry2.step = step * -1; entry2.estimateImpl(ed); if (quadraticEstimation > entry2.quadraticEstimation) { step = entry2.step; quadraticEstimation = entry2.quadraticEstimation; linearEstimation = entry2.linearEstimation; } }
private void collectEntries(object skel, float step, List <RegressionEntry> entries) { foreach (FieldInfo field in skel.GetType().GetFields()) { CustomSkelControlAttribute[] attr = (CustomSkelControlAttribute[])field.GetCustomAttributes(typeof(CustomSkelControlAttribute), true); if (attr.Length == 0 || !attr[0].solve) { continue; } if (field.FieldType == typeof(float)) { //radiuses float val = (float)field.GetValue(skel); float curStep = Math.Min(step, Math.Abs(val * 0.01f)); //to avoid abnormal value jumps when fails to reach minimum FloatEntry entry = new FloatEntry { currentValue = val, min = attr[0].min, max = attr[0].max, fieldInfo = field, targetObject = skel, step = curStep }; entry.estimate(this); // FloatEntry entry2 = entry.clone(); // entry2.step *= -1; // entry2.estimate(this); field.SetValue(skel, entry.currentValue); entries.Add(entry); // entries.Add(entry.linearEstimation < entry2.linearEstimation ? entry : entry2); } else if (field.FieldType == typeof(Vector3)) { //axes Vector3 val = (Vector3)field.GetValue(skel); float curStep = Math.Min(step, Math.Abs(val.length() * 0.01f)); //to avoid abnormal value jumps when fails to reach minimum Vector3Entry entryX = new Vector3Entry { currentValue = val, fieldInfo = field, targetObject = skel, step = new Vector3(curStep, 0, 0) }; entryX.estimate(this); Vector3Entry entryY = new Vector3Entry { currentValue = val, fieldInfo = field, targetObject = skel, step = new Vector3(0, curStep, 0) }; entryY.estimate(this); Vector3Entry entryZ = new Vector3Entry { currentValue = val, fieldInfo = field, targetObject = skel, step = new Vector3(0, 0, curStep) }; entryZ.estimate(this); field.SetValue(skel, val); if (entryX.quadraticEstimation < entryY.quadraticEstimation && entryX.quadraticEstimation < entryZ.quadraticEstimation) { entries.Add(entryX); } else if (entryY.quadraticEstimation < entryZ.quadraticEstimation) { entries.Add(entryY); } else { entries.Add(entryZ); } } else { collectEntries(field.GetValue(skel), step, entries); } } }