public void Record(Transform trans, PoseBoneMatrix last) { //r = trans.localRotation.eulerAngles; t = trans.localPosition; r = trans.localRotation; s = trans.localScale; tag = PoseBoneMatrix.changetag.All; if (last == null) { tag = PoseBoneMatrix.changetag.All; } else { tag = PoseBoneMatrix.changetag.NoChange; //float decr=Vector3.Angle(bonesinfo[i].r,last.bonesinfo[i].r); //Debug.LogWarning("decr="+decr); if (!QuaternionEqual(r, last.r)) { tag |= PoseBoneMatrix.changetag.Rotate; } if (t != last.t) { tag |= PoseBoneMatrix.changetag.Trans; } if (s != last.s) { tag |= PoseBoneMatrix.changetag.Scale; } //if(bonesinfo[i].tag!= PoseBoneMatrix.changetag.All) //{ // // Debug.LogWarning("fid=" + _fid + " bone=" + i); //} } }
public void UpdateTranLerp(Transform trans, PoseBoneMatrix mix, float lerp) { trans.localScale = Vector3.Lerp(s, mix.s, lerp); trans.localPosition = Vector3.Lerp(t, mix.t, lerp); if (r.z != 0 && mix.r.z != 0) //Debug.Log("have wrong.see it:" + mix.r + ',' + r); trans.localRotation = Quaternion.Lerp(r, mix.r, lerp); }
public void UpdateTranLerp(Transform trans, PoseBoneMatrix mix, float lerp) { trans.localScale = Vector3.Lerp(s, mix.s, lerp); trans.localPosition = Vector3.Lerp(t, mix.t, lerp); if (r.z != 0 && mix.r.z != 0) { //Debug.Log("have wrong.see it:" + mix.r + ',' + r); trans.localRotation = Quaternion.Lerp(r, mix.r, lerp); } }
public static PoseBoneMatrix Lerp(PoseBoneMatrix left, PoseBoneMatrix right, float lerp) { PoseBoneMatrix m = new PoseBoneMatrix(); m.r = Quaternion.Lerp(left.r, right.r, lerp); if (float.IsNaN(m.r.x)) { m.r = Quaternion.identity; } m.t = Vector3.Lerp(left.t, right.t, lerp); return(m); }
public object Clone() { PoseBoneMatrix bm = new PoseBoneMatrix(); bm.r = this.r; if (r.w == 0) { bm.r = Quaternion.identity; } bm.t = this.t; return(bm); }
public void Load(System.IO.Stream stream, PoseBoneMatrix last) { { byte[] buf = new byte[16]; stream.Read(buf, 0, 16); r = buf.ToQuaternion(0); } { byte[] buf = new byte[12]; stream.Read(buf, 0, 12); t = buf.ToVector3(0); } }
public static Frame Lerp(Frame left, Frame right, float lerp) { Frame f = new Frame(); f.key = false; f.fid = left.fid; //f.bonesinfo = new PoseBoneMatrix[left.bonesinfo.Length]; f.bonesinfo = new List <PoseBoneMatrix>(left.bonesinfo); for (int i = 0; i < f.bonesinfo.Count; i++) { f.bonesinfo[i] = PoseBoneMatrix.Lerp(left.bonesinfo[i], right.bonesinfo[i], lerp); } return(f); }
public Frame(Frame last, int _fid, IList <Transform> trans) { //Debug.LogWarning("bones=" + trans.Length); this.fid = _fid; this.key = true; //bonesinfo = new PoseBoneMatrix[trans.Count]; for (int i = 0; i < trans.Count; i++) { PoseBoneMatrix b = new PoseBoneMatrix(); bonesinfo.Add(b); bonesinfo[i].Record(trans[i], last == null ? null : last.bonesinfo[i]); } }
public Frame(Frame last, int _fid, IList<Transform> trans) { //Debug.LogWarning("bones=" + trans.Length); this.fid = _fid; this.key = true; //bonesinfo = new PoseBoneMatrix[trans.Count]; for (int i = 0; i < trans.Count; i++) { PoseBoneMatrix b = new PoseBoneMatrix(); bonesinfo.Add(b); bonesinfo[i].Record(trans[i], last == null ? null : last.bonesinfo[i]); } }
public Frame(AniClip clip, AniPlayer player, Frame last, int _fid, Transform root, IList <Transform> trans) { //Debug.LogWarning("bones=" + trans.Length); this.fid = _fid; this.key = true; this.boneinfo = clip.boneinfo; //bonesinfo = new PoseBoneMatrix[trans.Count]; for (int i = 0; i < trans.Count; i++) { PoseBoneMatrix b = new PoseBoneMatrix(); bonesinfo.Add(b); string bone = this.boneinfo[i]; var tbone = player.getbone(bone); bonesinfo[i].Record(root, trans[i], tbone == null?Matrix4x4.identity:tbone.tpose, last == null ? null : last.bonesinfo[i]); } }
public void Record(Transform root, Transform trans, Matrix4x4 tpose, PoseBoneMatrix last) { root.localScale.Set(1.0f, 1.0f, 1.0f); // var mat = root.localToWorldMatrix; var mat2 = trans.localToWorldMatrix; mat = mat.inverse * mat2; mat = mat * tpose; Vector3 vy = mat.GetColumn(1); Vector3 vz = mat.GetColumn(2); this.r = Quaternion.LookRotation(vz, vy); this.t = mat.GetColumn(3); //UnityEngine.Debug.Log("name:" + trans.name + " x:" + this.t.x + " y:" + this.t.y + " z:" + this.t.z); }
public void Save(System.IO.Stream stream, PoseBoneMatrix last) { byte[] btag = new byte[2]; btag[0] = (byte)tag; btag[1] = last == null ? (byte)(PoseBoneMatrix.changetag.All) : (byte)tag; stream.Write(btag, 0, 2); if (last == null || (tag & PoseBoneMatrix.changetag.Rotate) > 0) { byte[] buf = BitHelper.getBytes(r); stream.Write(buf, 0, 16); } if (last == null || (tag & PoseBoneMatrix.changetag.Trans) > 0) { byte[] buf = BitHelper.getBytes(t); stream.Write(buf, 0, 12); } if (last == null || (tag & PoseBoneMatrix.changetag.Scale) > 0) { byte[] buf = BitHelper.getBytes(s); stream.Write(buf, 0, 12); } }
public void Load(System.IO.Stream stream, PoseBoneMatrix last) { byte[] btag = new byte[2]; stream.Read(btag, 0, 2); this.tag = (PoseBoneMatrix.changetag)btag[0]; PoseBoneMatrix.changetag savetag = (PoseBoneMatrix.changetag)btag[1]; //Debug.LogWarning("savetag=" + this.tag + "|" + savetag); if ((savetag & PoseBoneMatrix.changetag.Rotate) > 0) { byte[] buf = new byte[16]; stream.Read(buf, 0, 16); r = BitHelper.ToQuaternion(buf, 0); } else { r = last.r; } if ((savetag & PoseBoneMatrix.changetag.Trans) > 0) { byte[] buf = new byte[12]; stream.Read(buf, 0, 12); t = BitHelper.ToVector3(buf, 0); } else { t = last.t; } if ((savetag & PoseBoneMatrix.changetag.Scale) > 0) { byte[] buf = new byte[12]; stream.Read(buf, 0, 12); s = BitHelper.ToVector3(buf, 0); } else { s = last.s; } }
public void Tag(PoseBoneMatrix last) { if (last == null) { tag = PoseBoneMatrix.changetag.All; } else { tag = PoseBoneMatrix.changetag.NoChange; if (r != last.r) { tag |= PoseBoneMatrix.changetag.Rotate; } if (t != last.t) { tag |= PoseBoneMatrix.changetag.Trans; } if (s != last.s) { tag |= PoseBoneMatrix.changetag.Scale; } } }
public void Record(Transform trans, PoseBoneMatrix last) { //r = trans.localRotation.eulerAngles; t = trans.localPosition; r = trans.localRotation; s = trans.localScale; tag = PoseBoneMatrix.changetag.All; if (last == null) tag = PoseBoneMatrix.changetag.All; else { tag = PoseBoneMatrix.changetag.NoChange; //float decr=Vector3.Angle(bonesinfo[i].r,last.bonesinfo[i].r); //Debug.LogWarning("decr="+decr); if (!QuaternionEqual(r, last.r)) { tag |= PoseBoneMatrix.changetag.Rotate; } if (t != last.t) { tag |= PoseBoneMatrix.changetag.Trans; } if (s != last.s) { tag |= PoseBoneMatrix.changetag.Scale; } //if(bonesinfo[i].tag!= PoseBoneMatrix.changetag.All) //{ // // Debug.LogWarning("fid=" + _fid + " bone=" + i); //} } }
public static PoseBoneMatrix Lerp(PoseBoneMatrix left, PoseBoneMatrix right, float lerp) { PoseBoneMatrix m = new PoseBoneMatrix(); m.tag = changetag.All; m.r = Quaternion.Lerp(left.r, right.r, lerp); if (float.IsNaN(m.r.x)) { m.r = Quaternion.identity; } m.t = Vector3.Lerp(left.t, right.t, lerp); m.s = Vector3.Lerp(left.s, right.s, lerp); return m; }
public void Save(System.IO.Stream stream, PoseBoneMatrix last) { stream.Write(r.GetBytes(), 0, 16); stream.Write(t.GetBytes(), 0, 12); }
public object Clone() { PoseBoneMatrix bm = new PoseBoneMatrix(); bm.tag = this.tag; bm.r = this.r; if (r.w == 0) { bm.r = Quaternion.identity; } bm.s = this.s; bm.t = this.t; return bm; }
public void Tag(PoseBoneMatrix last) { if (last == null) tag = PoseBoneMatrix.changetag.All; else { tag = PoseBoneMatrix.changetag.NoChange; if (r != last.r) { tag |= PoseBoneMatrix.changetag.Rotate; } if (t != last.t) { tag |= PoseBoneMatrix.changetag.Trans; } if (s != last.s) { tag |= PoseBoneMatrix.changetag.Scale; } } }
public static Frame Lerp(Frame left, Frame right, float lerp) { Frame f = new Frame(); f.key = false; f.fid = left.fid; if (left.boneinfo != null && right.boneinfo != null && left.bonehash != right.bonehash) { Dictionary <string, int3> rebone = new Dictionary <string, int3>(); for (int i = 0; i < left.boneinfo.Count; i++) { string b = left.boneinfo[i]; int3 it = new int3(rebone.Count, i, -1); rebone[b] = it; } for (int i = 0; i < right.boneinfo.Count; i++) { string b = right.boneinfo[i]; if (rebone.ContainsKey(b) == false) { int3 it = new int3(rebone.Count, -1, i); rebone[b] = it; } else { rebone[b].boneright = i; } } //Debug.LogWarning("bone mix:"+rebone.Count); f.boneinfo = new List <string>(rebone.Keys); f.bonesinfo = new List <PoseBoneMatrix>(new PoseBoneMatrix[rebone.Count]); foreach (var v in rebone.Values) { if (v.boneleft == -1) { f.bonesinfo[v.idnew] = right.bonesinfo[v.boneright].Clone() as PoseBoneMatrix; } else if (v.boneright == -1) { f.bonesinfo[v.idnew] = left.bonesinfo[v.boneleft].Clone() as PoseBoneMatrix; } else { //Debug.Log("bc:" + v.idnew + "/" + f.bonesinfo.Count); //Debug.Log("lb:" + v.boneleft + "/" + left.bonesinfo.Count); //Debug.Log("rb:" + v.boneright + "/" + right.bonesinfo.Count); f.bonesinfo[v.idnew] = PoseBoneMatrix.Lerp(left.bonesinfo[v.boneleft], right.bonesinfo[v.boneright], lerp); } } } else { //single mix //f.bonesinfo = new PoseBoneMatrix[left.bonesinfo.Length]; f.bonesinfo = new List <PoseBoneMatrix>(left.bonesinfo); if (left.boneinfo != null) { f.boneinfo = left.boneinfo; f.bonehash = left.bonehash; } for (int i = 0; i < f.bonesinfo.Count; i++) { f.bonesinfo[i] = PoseBoneMatrix.Lerp(left.bonesinfo[i], right.bonesinfo[i], lerp); } } return(f); }