static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.U2D.SpriteBone o; o = new UnityEngine.U2D.SpriteBone(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static void CalculateLocaltoWorldMatrix(int i, SpriteRect spriteRect, float definitionScale, float pixelsPerUnit, List <UnityEngine.U2D.SpriteBone> spriteBone, ref UnityEngine.U2D.SpriteBone?[] outpriteBone, ref NativeArray <Matrix4x4> bindPose) { if (outpriteBone[i] != null) { return; } UnityEngine.U2D.SpriteBone sp = spriteBone[i]; var isRoot = sp.parentId == -1; var position = isRoot ? (spriteBone[i].position - Vector3.Scale(spriteRect.rect.size, spriteRect.pivot)) : spriteBone[i].position; position.z = 0f; sp.position = position * definitionScale / pixelsPerUnit; sp.length = spriteBone[i].length * definitionScale / pixelsPerUnit; outpriteBone[i] = sp; // Calculate bind poses var worldPosition = Vector3.zero; var worldRotation = Quaternion.identity; if (sp.parentId == -1) { worldPosition = sp.position; worldRotation = sp.rotation; } else { if (outpriteBone[sp.parentId] == null) { CalculateLocaltoWorldMatrix(sp.parentId, spriteRect, definitionScale, pixelsPerUnit, spriteBone, ref outpriteBone, ref bindPose); } var parentBindPose = bindPose[sp.parentId]; var invParentBindPose = Matrix4x4.Inverse(parentBindPose); worldPosition = invParentBindPose.MultiplyPoint(sp.position); worldRotation = sp.rotation * invParentBindPose.rotation; } // Practically Matrix4x4.SetTRInverse var rot = Quaternion.Inverse(worldRotation); Matrix4x4 mat = Matrix4x4.identity; mat = Matrix4x4.Rotate(rot); mat = mat * Matrix4x4.Translate(-worldPosition); bindPose[i] = mat; }