JD2022-TU1/main/tools/legacy/ParseExampleTool/ParseExample/MyExamplesFile.h

241 lines
7 KiB
C++

#pragma once
#ifndef __EXAMPLESFILE_H__
#define __EXAMPLESFILE_H__
#ifdef _WIN32
#include <windows.h>
#endif
typedef unsigned long long u64;
typedef float f32;
typedef unsigned int u32;
// File header describing the file format of .e (example) files.
// This file format is used to prevent the need to use XED/XEF files in the intermediate steps
// of the pipeline.
// Format is:
// - 4 byte header tag - EX3 or EXD, identifies the data format
// - 64-bit unsigned integer - Count of frames
// - 64-bit unsigned integer - Offset in the file of the frame table
// - Array of frames - Either EXAMPLES_FRAME_TYPE_X360 or EXAMPLES_FRAME_TYPE_DURANGO, of the size referred to above, compressed with zlib
// - Frame table - 64-bit file-offset/size pairs, describing the compressed buffers in the file for each frame
// Note: currently the format is not fully padded to type-alignment, so use in-memory is not recommended!
const BYTE g_kExamplesMajorVersion = 0;
const BYTE g_kExamplesMinorVersion = 3;
#define EXAMPLES_VERSION ((WORD)g_kExamplesMajorVersion | ((WORD)g_kExamplesMinorVersion << 8))
#define EXAMPLES_LOWEST_VERSION EXAMPLES_VERSION // for now only support the latest version
#define EXAMPLES_GET_MINOR( v ) ((BYTE)(v>>8))
#define EXAMPLES_GET_MAJOR( v ) ((BYTE)v)
#if defined(TARGET_X360) && defined(TARGET_DURANGO)
#define TARGET_ALL
#endif
#if defined(TARGET_X360) && !defined(TARGET_ALL)
#include <DirectXMath.h>
using namespace DirectX; // brings XMVECTOR to the global scope
#include "NuiTools.h"
#elif defined(TARGET_DURANGO) && !defined(TARGET_ALL)
#ifdef _DEBUG
//#include <kinect/durango/nuicore.h>
//#define CHECK_SKEL_BONE_ORDER
#endif
#elif defined(TARGET_ALL)
#include <DirectXMath.h>
using namespace DirectX; // brings XMVECTOR to the global scope
#include "NuiTools.h"
#ifdef _DEBUG
//#include <..\..\extern\Kinect\Durango\NuiCore.h>
//#define CHECK_SKEL_BONE_ORDER
#endif
#endif
namespace Examples
{
__declspec(align(16)) struct ExampleHeader
{
WORD versionNumber;
CHAR headerTag[4];
CHAR padding[4];
UINT64 frameCount;
UINT64 frameTableOffset;
};
struct ExampleFrameTableEntry
{
UINT64 frameTime;
UINT64 frameOffset;
UINT64 frameSize;
};
#define EXAMPLES_FILE_HEADER_TAG_X360 "EX3"
#define DEPTH_FRAME_WIDTH_X360 320
#define DEPTH_FRAME_HEIGHT_X360 240
#if defined(TARGET_X360)
#define EXAMPLES_FRAME_TYPE_X360 NUI_SKELETON_FRAME
#endif
#define EXAMPLES_FILE_HEADER_TAG_DURANGO "EXD"
#define DEPTH_FRAME_WIDTH_DURANGO 512
#define DEPTH_FRAME_HEIGHT_DURANGO 424
#if defined(TARGET_DURANGO)
namespace Durango
{
const UINT32 BODY_PER_FRAME_COUNT = 6;
enum BodyTrackingState
{
eBodyTrackingState_NotTracked = 0,
eBodyTrackingState_Tracked
};
enum BodyJointTrackingState
{
eBodyJointTrackingState_NOT_TRACKED = 0,
eBodyJointTrackingState_INFERRED,
eBodyJointTrackingState_TRACKED
};
enum BodyJointIndicies
{
eBodyJointIndex_SPINE_BASE = 0,
eBodyJointIndex_SPINE_MID,
eBodyJointIndex_NECK,
eBodyJointIndex_HEAD,
eBodyJointIndex_SHOULDER_LEFT,
eBodyJointIndex_ELBOW_LEFT,
eBodyJointIndex_WRIST_LEFT,
eBodyJointIndex_HAND_LEFT,
eBodyJointIndex_SHOULDER_RIGHT,
eBodyJointIndex_ELBOW_RIGHT,
eBodyJointIndex_WRIST_RIGHT,
eBodyJointIndex_HAND_RIGHT,
eBodyJointIndex_HIP_LEFT,
eBodyJointIndex_KNEE_LEFT,
eBodyJointIndex_ANKLE_LEFT,
eBodyJointIndex_FOOT_LEFT,
eBodyJointIndex_HIP_RIGHT,
eBodyJointIndex_KNEE_RIGHT,
eBodyJointIndex_ANKLE_RIGHT,
eBodyJointIndex_FOOT_RIGHT,
eBodyJointIndex_SPINE_SHOULDER,
eBodyJointIndex_HAND_TIP_LEFT,
eBodyJointIndex_THUMB_LEFT,
eBodyJointIndex_HAND_TIP_RIGHT,
eBodyJointIndex_THUMB_RIGHT,
eBodyJointIndex_COUNT
};
struct Body
{
DirectX::XMVECTOR SkeletonJointPositions[eBodyJointIndex_COUNT];
BodyJointTrackingState SkeletonJointPositionTrackingStates[eBodyJointIndex_COUNT];
UINT64 TrackingID;
BodyTrackingState TrackingState;
};
struct BodyFrame
{
DirectX::XMVECTOR FloorClipPlane;
DirectX::XMVECTOR Up;
Body BodyData[BODY_PER_FRAME_COUNT];
UINT32 QualityFlags;
};
// Assert that the game and the tools joint positions are in the same order (enums match)
#ifdef CHECK_SKEL_BONE_ORDER
#define DUGAME(x) Microsoft::Xbox::Input::Nui::NUI_SKELETON_JOINT_ ## x
#define DUTOOL(x) Examples::Durango::eBodyJointIndex_ ## x
#define IDENTOSTR(x) #x
#define IDENTOSTR1(x) IDENTOSTR(x)
#define CHECK_SKEL_ENUM(x) static_assert( DUGAME(x) == DUTOOL(x), "Mismatched skeleton joint order between tools and game \"" IDENTOSTR1(x) "\" has a different value" )
CHECK_SKEL_ENUM(SPINE_BASE);
CHECK_SKEL_ENUM(SPINE_MID);
CHECK_SKEL_ENUM(NECK);
CHECK_SKEL_ENUM(HEAD);
CHECK_SKEL_ENUM(SHOULDER_LEFT);
CHECK_SKEL_ENUM(ELBOW_LEFT);
CHECK_SKEL_ENUM(WRIST_LEFT);
CHECK_SKEL_ENUM(HAND_LEFT);
CHECK_SKEL_ENUM(SHOULDER_RIGHT);
CHECK_SKEL_ENUM(ELBOW_RIGHT);
CHECK_SKEL_ENUM(WRIST_RIGHT);
CHECK_SKEL_ENUM(HAND_RIGHT);
CHECK_SKEL_ENUM(HIP_LEFT);
CHECK_SKEL_ENUM(KNEE_LEFT);
CHECK_SKEL_ENUM(ANKLE_LEFT);
CHECK_SKEL_ENUM(FOOT_LEFT);
CHECK_SKEL_ENUM(HIP_RIGHT);
CHECK_SKEL_ENUM(KNEE_RIGHT);
CHECK_SKEL_ENUM(ANKLE_RIGHT);
CHECK_SKEL_ENUM(FOOT_RIGHT);
CHECK_SKEL_ENUM(SPINE_SHOULDER);
CHECK_SKEL_ENUM(HAND_TIP_LEFT);
CHECK_SKEL_ENUM(THUMB_LEFT);
CHECK_SKEL_ENUM(HAND_TIP_RIGHT);
CHECK_SKEL_ENUM(THUMB_RIGHT);
#endif
};
#define EXAMPLES_FRAME_TYPE_DURANGO Durango::BodyFrame
#endif
#if defined(TARGET_X360) && !defined(TARGET_ALL)
#define EXAMPLES_FILE_HEADER_TAG EXAMPLES_FILE_HEADER_TAG_X360
#define DEPTH_FRAME_WIDTH DEPTH_FRAME_WIDTH_X360
#define DEPTH_FRAME_HEIGHT DEPTH_FRAME_HEIGHT_X360
#define EXAMPLES_FRAME_TYPE EXAMPLES_FRAME_TYPE_X360
#elif defined(TARGET_DURANGO) && !defined(TARGET_ALL)
#define EXAMPLES_FILE_HEADER_TAG EXAMPLES_FILE_HEADER_TAG_DURANGO
#define DEPTH_FRAME_WIDTH DEPTH_FRAME_WIDTH_DURANGO
#define DEPTH_FRAME_HEIGHT DEPTH_FRAME_HEIGHT_DURANGO
#define EXAMPLES_FRAME_TYPE EXAMPLES_FRAME_TYPE_DURANGO
#endif
// Remove this to disable transform from 16bit depth -> 8bit depth
#ifndef EXAMPLES_BYTE_DEPTH
#define EXAMPLES_BYTE_DEPTH
#define EXAMPLES_DEPTH_TYPE UINT8
#endif
#ifndef EXAMPLES_DEPTH_TYPE
#define EXAMPLES_DEPTH_TYPE UINT16
#endif
struct ExamplesCompressedFrame
{
BYTE* pData;
UINT64 dataSize;
};
struct ExamplesFrameBase
{
UINT32 frameNumber;
};
#if defined(TARGET_X360)
struct ExamplesFrameX360 : ExamplesFrameBase
{
EXAMPLES_DEPTH_TYPE depthFrame[DEPTH_FRAME_WIDTH_X360 * DEPTH_FRAME_HEIGHT_X360];
EXAMPLES_FRAME_TYPE_X360 skeletonFrame;
};
#endif
#if defined(TARGET_DURANGO)
struct ExamplesFrameDurango : ExamplesFrameBase
{
EXAMPLES_DEPTH_TYPE depthFrame[DEPTH_FRAME_WIDTH_DURANGO * DEPTH_FRAME_HEIGHT_DURANGO];
EXAMPLES_FRAME_TYPE_DURANGO skeletonFrame;
};
#endif
#if defined(TARGET_X360) && !defined(TARGET_ALL)
typedef ExamplesFrameX360 ExamplesFrame;
#elif defined(TARGET_DURANGO) && !defined(TARGET_ALL)
typedef ExamplesFrameDurango ExamplesFrame;
#endif
}; // namespace Examples
#endif // #ifndef __EXAMPLESFILE_H__