static void ReadSkeletonDefinition(BinaryReader sr, SpatialSkeletonAsset skeletonAsset) { // Read skeleton definition int jointCount = sr.ReadInt32(); skeletonAsset.jointNames = new string[jointCount]; for (int i = 0; i < jointCount; ++i) { string name = SpatialUtils.readString(sr); skeletonAsset.jointNames[i] = name; } int parentCount = sr.ReadInt32(); skeletonAsset.parents = new int[parentCount]; for (int i = 0; i < parentCount; ++i) { int parent = sr.ReadInt32(); skeletonAsset.parents[i] = parent; } skeletonAsset.refSkeleton = new BoneData[jointCount]; for (int b = 0; b < jointCount; ++b) { skeletonAsset.refSkeleton[b] = new BoneData(); SpatialUtils.readBoneData(sr, skeletonAsset.refSkeleton[b], skeletonAsset.jointNames[b]); } }
static void VisualizeFrame() { string[] filters = { "Replay Files", "dat" }; string fileName = EditorUtility.OpenFilePanelWithFilters( "Load Replay", ".", filters); if (fileName.Length == 0) { return; } try { using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { using (BinaryReader sr = new BinaryReader(fs)) { int version = sr.ReadInt32(); Debug.LogFormat("Version {0}", version); int frameCount = sr.ReadInt32(); Debug.LogFormat("Read {0} frames", frameCount); int deviceOrientation = sr.ReadInt32(); Debug.LogFormat("Device Orientation {0}", deviceOrientation); float fovX = sr.ReadSingle(); float fovY = sr.ReadSingle(); // Read skeleton definition int jointCount = sr.ReadInt32(); string[] jointNames = new string[jointCount]; for (int i = 0; i < jointCount; ++i) { string name = SpatialUtils.readString(sr); jointNames[i] = name; } int parentCount = sr.ReadInt32(); int[] parents = new int[parentCount]; for (int i = 0; i < parentCount; ++i) { int parent = sr.ReadInt32(); parents[i] = parent; } Transform[] neutralSkeleton = SpatialUtils.createSkeleton(jointNames, parents); neutralSkeleton[0].name = "netural_" + neutralSkeleton[0].name; FramePose neutralPose = new FramePose(); neutralPose.init(jointCount); // Read neutral skeleton transforms for (int b = 0; b < jointCount; ++b) { SpatialUtils.readBoneData(sr, neutralPose.m_bones[b], jointNames[b]); } visualizeFramePose(neutralPose, neutralSkeleton); // Create skeleton structure Transform[] skeleton = SpatialUtils.createSkeleton(jointNames, parents); FramePose pose = new FramePose(); pose.init(jointCount); // Create Camera Transform Transform cameraTransform = GameObject.CreatePrimitive(PrimitiveType.Cube).transform; cameraTransform.name = "Camera Transform"; cameraTransform.localScale = Vector3.one * 0.01f; cameraTransform.parent = null; // PER FRAME DATA STARTS HERE for (int f = 0; f < frameCount; ++f) { // Update skeleton and camera! uint skeletonCount = sr.ReadUInt32(); for (int i = 0; i < skeletonCount; ++i) { for (int b = 0; b < jointCount; ++b) { SpatialUtils.readBoneData(sr, pose.m_bones[b], jointNames[b]); } visualizeFramePose(pose, skeleton); } Vector3 pos = Vector3.zero; Vector3 rot = Vector3.zero; SpatialUtils.readCameraTransform(sr, ref pos, ref rot); Transform t = GameObject.CreatePrimitive(PrimitiveType.Cube).transform; t.name = f.ToString(); t.localScale = Vector3.one * 0.01f; t.parent = cameraTransform; t.position = pos; t.rotation = Quaternion.identity; t.Rotate(Vector3.forward, rot.z); t.Rotate(Vector3.up, rot.y); t.Rotate(Vector3.right, rot.x); /* * cameraTransform.position = pos; * cameraTransform.rotation = Quaternion.identity; * cameraTransform.Rotate(Vector3.forward, rot.z); * cameraTransform.Rotate(Vector3.up, rot.y); * cameraTransform.Rotate(Vector3.right, rot.x); */ } } } } catch (Exception e) { Debug.LogWarningFormat("Error parsing {0} with exception: {1}", fileName, e); } }