private void SetChildTransform(SkeletonJoint child, AMCFrame frame, Vector4 p) { float[] data = frame.GetValue(child.Name).Data; Vector3 rot3x1 = Vector3.zero; int idx = 0; for (int i = 0; data.Length != 0 && i < child.Dof.Length; i++) { if (asfReader.DOFMap.TryGetValue(child.Dof[i], out int dim)) { rot3x1[dim] = data[idx]; idx++; } } Matrix4x4 M = (rot3x1 * Mathf.Deg2Rad).Euler2Mat(); child.L = child.B * child.C * M * child.CInv; child.G = child.Parent.G * child.L; child.Coordinate = child.G * p; if (child.Children == null) { return; } foreach (SkeletonJoint childOfChild in child.Children) { SetChildTransform(childOfChild, frame, p); } }
public void ReadAMCFrame(AMCFrame frame) { if (!IsAMCStreamOpen || loopEnded) { return; } int valuesRead = 0; string[] tokens = GetLineTokens(amcReader); for (int i = 0; i < ValuesPerFrame; i++) { if (tokens == null) { break; } tokens = GetLineTokens(amcReader); for (int j = 1; j < tokens.Length; j++) { float val = float.Parse(tokens[j], CultureInfo.InvariantCulture); frame.SetValue(tokens[0], j - 1, val); } valuesRead++; } loopEnded = valuesRead != ValuesPerFrame; }
public Dictionary <string, SkeletonJoint> SetSkeleton() { AMCFrame frame = frameBuffer.CurrentFrame; if (frame == null) { return(null); } SetRootTransform(frame); return(skeletonJointDict); }
public AMCFrameBuffer(long size, AMCReader amcReader) { bufferSize = size; this.amcReader = amcReader; frameBuffer = new LinkedList <AMCFrame>(); var template = amcReader.templateValueDict; for (int i = 0; i < bufferSize; i++) { AMCFrame frame = new AMCFrame(template); frameBuffer.AddLast(frame); } }
private AMCFrame Smooth(int order) { AMCFrame res = new AMCFrame(amcReader.templateValueDict); var frameData = res.Get(); var node = frameBuffer.Last; for (int i = 0; i < order; i++) { AMCFrame cur = node.Value; var newData = cur.Get(); frameData.Add(newData); node = node.Previous; } frameData.Div(order); return(res); }
public void SetSkeleton <TRes>(out TRes data) { AMCFrame frame = frameBuffer.CurrentFrame; if (frame == null) { data = default; return; } SetRootTransform(frame); if (!typeof(TRes).IsAssignableFrom(mocapConverter.GetConvertReturnType())) { Debug.LogWarning("Wrong format for Convert return type"); data = default; return; } data = (TRes)mocapConverter.Convert(skeletonJointDict); }
private void SetRootTransform(AMCFrame frame) { Vector4 point = MotionUtil.LastOne; SkeletonJoint root = skeletonJointDict[ROOTKEY]; float[] vals = frame.GetValue(ROOTKEY).Data; float px = vals[0] * AcclaimSkeleton.METER_SCALE; float py = vals[1] * AcclaimSkeleton.METER_SCALE; float pz = vals[2] * AcclaimSkeleton.METER_SCALE; Vector3 transOffset = new Vector3(px, py, pz); Vector3 rot3x1 = new Vector3(vals[3], vals[4], vals[5]); Matrix4x4 M = (rot3x1 * Mathf.Deg2Rad).Euler2Mat(); //root.LocalRotation = root.C * M * root.CInv; root.L = root.B * root.C * M * root.CInv; root.G = root.L * Matrix4x4.Translate(transOffset); root.Coordinate = root.G * point; foreach (SkeletonJoint child in root.Children) { SetChildTransform(child, frame, point); } }