home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 11218 / CryRyseImport_fix35.7z / include / load_cryHeaders_.ms < prev   
Encoding:
Text File  |  2016-07-01  |  83.4 KB  |  2,567 lines

  1.  
  2. --//! Chunk type must fit into uint16.
  3. struct ChunkTypes
  4. (
  5.     ChunkType_ANY = 0,
  6.  
  7.     ChunkType_Mesh                         = 0xCCCC1000,                 --//!< Was 0xCCCC0000 in chunk files with versions <= 0x745.
  8.         --ChunkType_Mesh_OLD                      = 0xCCCC0000,
  9.         ChunkType_Mesh_OLD                  = #(#(0),#(52428)),
  10.     ChunkType_Helper                         = 0xCCCC0001,
  11.     ChunkType_VertAnim                     = 0xCCCC0002,
  12.     ChunkType_BoneAnim                     = 0xCCCC0003,
  13.     ChunkType_GeomNameList             = 0xCCCC0004,                 --obsolete
  14.     ChunkType_BoneNameList                 = 0xCCCC0005,
  15.     ChunkType_MtlList                         = 0xCCCC0006,               --obsolete
  16.     ChunkType_MRM                             = 0xCCCC0007,               --obsolete
  17.     ChunkType_SceneProps                 = 0xCCCC0008,                --obsolete
  18.     ChunkType_Light                         = 0xCCCC0009,                --obsolete
  19.     ChunkType_PatchMesh                 = 0xCCCC000A,               --not implemented
  20.     --ChunkType_Node                             = 0xCCCC000B,
  21.     ChunkType_Node                         = #(#(11),#(52428)),
  22.     ChunkType_Mtl                             = 0xCCCC000C,                  --obsolete
  23.     ChunkType_Controller                     = 0xCCCC000D,
  24.     --ChunkType_Timing                             = 0xCCCC000E,
  25.     ChunkType_Timing                         = #(#(14),#(52428)),
  26.     ChunkType_BoneMesh                     = 0xCCCC000F,
  27.     ChunkType_BoneLightBinding             = 0xCCCC0010,                 --obsolete. describes the lights binded to bones
  28.     ChunkType_MeshMorphTarget         = 0xCCCC0011,                  --describes a morph target of a mesh chunk
  29.     ChunkType_BoneInitialPos                 = 0xCCCC0012,                  --describes the initial position (4x3 matrix) of each bone; just an array of 4x3 matrices
  30.     ChunkType_SourceInfo                 = #(#(19),#(52428)),     --describes the source from which the cgf was exported: source max file, machine and user
  31.     --ChunkType_SourceInfo                     = 0xCCCC0013,                     --describes the source from which the cgf was exported: source max file, machine and user
  32.     --ChunkType_MtlName                         = 0xCCCC0014,                     --material name
  33.     ChunkType_MtlName                     = #(#(20),#(52428)),     --material name
  34.     ChunkType_ExportFlags                 = 0xCCCC0015,                 --Special export flags.
  35.     --ChunkType_DataStream                     = 0xCCCC0016,                     --Stream data.
  36.     ChunkType_DataStream                 = #(#(22),#(52428)),     --0xCCCC0016, --Stream data.
  37.     --ChunkType_MeshSubsets                     = 0xCCCC0017,                     --Array of mesh subsets.
  38.     ChunkType_MeshSubsets                 = #(#(23),#(52428)),     --0xCCCC0017, --Array of mesh subsets.
  39.     ChunkType_MeshPhysicsData         = 0xCCCC0018,                 --Physicalized mesh data.
  40.  
  41.     --//========================================
  42.     --//Bonelist Chunk Header
  43.     --//========================================
  44.     --CryHeaders.h 1033        
  45.  
  46.     --// this structure describes the bone names
  47.     --// it's followed by numEntities packed \0-terminated strings, the list terminated by double-\0
  48.     --these are the new compiled chunks for characters
  49.     --ChunkType_CompiledBones                     = 0xACDC0000, --ChunkType_CompiledBones = 0x2000,    //!< Was 0xACDC0000 in chunk files with versions <= 0x745.
  50.     ChunkType_CompiledBones                 = #(#(0),#(44252)),
  51.     ChunkType_CompiledPhysicalBones         = 0xACDC0001,
  52.     ChunkType_CompiledMorphTargets         = 0xACDC0002,
  53.     ChunkType_CompiledPhysicalProxies     = 0xACDC0003,
  54.     --ChunkType_CompiledIntFaces                     = 0xACDC0004,        --pie - the Int prob stands for "Internal" and these are probably used to compute the convex hull (we are not interested in that)
  55.     ChunkType_CompiledIntFaces             = #(#(4),#(44252)),
  56.     --ChunkType_CompiledIntSkinVertices             = 0xACDC0005,
  57.     ChunkType_CompiledIntSkinVertices     = #(#(5),#(44252)),
  58.     ChunkType_CompiledExt2IntMap         = 0xACDC0006,
  59.  
  60.         ChunkType_BreakablePhysics_OLD         = 0xAAFC0000,        --//!< Was 0xAAFC0000 in chunk files with versions <= 0x745.
  61.     ChunkType_BreakablePhysics             = 0xAAFC3000,        
  62.     ChunkType_FaceMap                         = 0xAAFC0001,        --//!< Obsolete.
  63.     ChunkType_MotionParameters             = 0xAAFC0002,
  64.     ChunkType_FootPlantInfo                     = 0xAAFC0003,       --//!< Obsolete.
  65.     ChunkType_BonesBoxes                     = 0xAAFC0004,
  66.     ChunkType_FoliageInfo                     = 0xAAFC0005,
  67.     ChunkType_Timestamp                         = 0xAAFC0006,
  68.     ChunkType_GlobalAnimationHeaderCAF = 0xAAFC0007,
  69.     ChunkType_GlobalAnimationHeaderAIM = 0xAAFC0008,
  70.     
  71.     ChunkType_BspTreeData                     = 0xAAFC0009
  72. )
  73.  
  74.  
  75. struct ECgfStreamType
  76. (
  77.     CGF_STREAM_POSITIONS         = #(#(),#()),    --0
  78.     CGF_STREAM_NORMALS         = #(),                --1
  79.     CGF_STREAM_TEXCOORDS     = #(),                --2
  80.     CGF_STREAM_COLORS             = #(),                --3
  81.     CGF_STREAM_COLORS2         = #(),                --4
  82.     CGF_STREAM_INDICES             = #(),                --5
  83.     CGF_STREAM_TANGENTS         = #(),                --6
  84.     CGF_STREAM__DUMMY0         = #(),                  --7        --//!< Used to be CGF_STREAM_SHCOEFFS, dummy is needed to keep existing assets loadable.
  85.     CGF_STREAM__DUMMY1         = #(),                  --8        --//!< Used to be CGF_STREAM_SHAPEDEFORMATION, dummy is needed to keep existing assets loadable.
  86.     CGF_STREAM_BONEMAPPING     = #(),                --9
  87.     CGF_STREAM_FACEMAP         = #(),                --10
  88.     CGF_STREAM_VERT_MATS     = #(),                --11
  89.     CGF_STREAM_QTANGENTS     = #(),                --12
  90.     CGF_STREAM_SKINDATA         = #(),                --13
  91.     CGF_STREAM_PS3EDGEDATA     = #(),                --14
  92.     CGF_STREAM_P3S_C4B_T2S     = #()                --15     --//!< Used to be CGF_STREAM_PS3EDGEDATA, dummy is needed to keep existing assets loadable.
  93. )
  94.  
  95. struct FILE_HEADER
  96. (
  97.     Signature                 = "",
  98.     _pad                         = 1,
  99.     FileType                 = 0,
  100.     Version                     = 0,
  101.     ChunkTableOffset     = 0
  102. )
  103.  
  104. -- //////////////////////////////////////////////////////////////////////////
  105. --//=======================================
  106. --ChunkTable File Constants (P)
  107. --//=======================================
  108.  
  109. struct CHUNK_TABLE_0744_0745
  110. (    
  111.     ChunkType                    = #(#(),#()),
  112.     ChunkVersion                = #(#(),#()),
  113.     FileOffset                    = #(#(),#()),
  114.     ChunkID                        = #(#(),#()),      --//new in version 0x0745
  115.     ChunkPlusDescr_size     = #()    
  116. )
  117.  
  118. -- //////////////////////////////////////////////////////////////////////////
  119. -- // Custom Attributes chunk description.
  120. -- //////////////////////////////////////////////////////////////////////////
  121.  
  122.  
  123. -- //!< Describes the source from which the cgf was exported: source max file, machine and user.
  124. fn read_FILE_HEADER \
  125.                                 &bstream: \
  126.                                 &struct2fill: \
  127.                                 global_Append: \
  128.                                 &STAT: =
  129. (
  130.     if struct2fill != unsupplied then
  131.     (
  132.         if struct2fill != undefined then
  133.         (
  134.             --pad
  135.             for i=1 to struct2fill._pad do
  136.             (
  137.                 readlong         bstream
  138.                 readshort     bstream
  139.             )
  140.             
  141.             struct2fill.Version                 = readshort bstream    
  142.                 readshort                             bstream --pad
  143.             struct2fill.ChunkTableOffset     = readlong bstream
  144.             
  145.             Append global_Append struct2fill            
  146.             return STAT = true;
  147.         )        
  148.     )
  149.     
  150.     STAT = false
  151. )
  152.  
  153. struct CHUNKTABLE_FILE_CONSTANTS
  154. (
  155.     tableStart = 0, --uint
  156.     nChunkTable_entries = 0
  157. )
  158.  
  159. fn read_CHUNKTABLE_FILE_CONSTANTS \
  160.                                                         &bstream: \
  161.                                                         &struct2read: \                                                        
  162.                                                         &struct2fill: \
  163.                                                         global_Append: \
  164.                                                         &STAT: =
  165. (    
  166.     if struct2read != undefined then
  167.     (
  168.         if struct2read != unsupplied then
  169.         (
  170.             fseek     bstream     struct2read.ChunkTableOffset     #seek_set
  171.             struct2fill.nChunkTable_entries         = readlong bstream
  172.             
  173.             struct2fill.tableStart                     = ftell bstream
  174.             
  175.             Append     global_Append     struct2fill
  176.             return STAT = true;
  177.         )
  178.     )
  179.     
  180.     STAT = false
  181. )
  182.  
  183. struct SOURCE_INFO
  184. (
  185.     source = "", --char 116
  186.         source_count = 116
  187. )
  188.  
  189. fn read_SOURCE_INFO \
  190.                                 &bstream: \
  191.                                 &fileHeader: \
  192.                                 &struct2read: \
  193.                                 global_Append: =
  194.  
  195. (
  196.     for i=1 to ::g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  197.     (
  198.         if struct2read.ChunkType[1][i] == 0x0013 AND \
  199.             struct2read.ChunkType[2][i] == 0xCCCC then
  200.         (
  201.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  202.                 
  203.             struct2fill = SOURCE_INFO() --create struct            
  204.             struct2fill.source = ReadFixedString \
  205.                                                             bstream:    &bstream \
  206.                                                             fixedLen:    &struct2fill.source_count --fill struct
  207.             
  208.             Append global_Append struct2fill
  209.         )
  210.     )    
  211. )
  212.  
  213. struct RANGE_ENTITY
  214. (
  215.     _name                     = "", --char name[32]
  216.         _name_count         = 32,
  217.     
  218.     start                         = 0, --int
  219.     end                         = 0 --int
  220. )
  221.  
  222. -- //! Timing Chunk Header.
  223. struct TIMING_CHUNK_DESC_0918
  224. (
  225.     chunkID                                 = 0, 
  226.     
  227. --     enum { VERSION = 0x0918 };
  228.  
  229.     _obsolete_SecsPerTick             = 0,       --//!< Always assumed to be 1/4800. --f32
  230.     _obsolete_TicksPerFrame         = 0,         --//!< Always assumed to be 160. --int32
  231.  
  232.     global_range,     --//!< Specifies time range of the animation, expressed in 'ticks' (1/4800th of a second). --struct RANGE_ENTITY  (see above)
  233.  
  234.     _obsolete_SubRanges             = 0         --int32
  235. )
  236.  
  237. -- //! Describes timing attributes of evenly sampled motion data. Used in .i_caf files.
  238. struct TIMING_CHUNK_DESC_0919
  239. (
  240.     chunkID                                 = 0, 
  241.     
  242. --     enum { VERSION = 0x0919 };
  243.  
  244.     numberOfSamples                 = 0,      --//!< Shall be >= 1. --int32
  245.     samplesPerSecond                 = 0,      --//!< Shall be > 0. --float
  246.     startTimeInSeconds                 = 0        --float
  247. )
  248.  
  249. fn read_ChunkTable_0744_0745 \
  250.                                             &bstream: \
  251.                                             &struct2read_A: \
  252.                                             &struct2read_B: \
  253.                                             &struct2fill: \
  254.                                             global_Append: \
  255.                                             &STAT: =
  256. (    
  257.     if struct2read_A != undefined then
  258.     (
  259.         if struct2read_A != unsupplied then
  260.         (
  261.             if struct2read_A.Version == 0x744 OR \
  262.                 struct2read_A.Version == 0x745 then
  263.             (    
  264.                 fseek bstream struct2read_B.tableStart #SeekSet
  265.                 
  266.                 for i=1 to struct2read_B.nChunkTable_entries do
  267.                 (
  268.                     --format "-------------------Begin reading table 0x745 here: %\n" (ftell bstream)
  269.                     
  270.                     Append struct2fill.ChunkType[1] (readshort bstream #unsigned)
  271.                     Append struct2fill.ChunkType[2] (readshort bstream #unsigned)
  272.                     
  273.                     Append struct2fill.ChunkVersion[1] (readshort bstream #unsigned)
  274.                     Append struct2fill.ChunkVersion[2] (readshort bstream #unsigned)
  275.                     
  276.                     Append struct2fill.FileOffset[1] (readlong bstream) --the offset we will read normally (not divided in high and low)        
  277.                     
  278.                     --Note, the ID for the chunks is new for version 0x745 !
  279.                     if struct2read_A.Version == 0x745 then
  280.                     (
  281.                         Append struct2fill.ChunkID[1] (readlong bstream) --read normally    
  282.                     )
  283.                     
  284.                     Append struct2fill.ChunkPlusDescr_size (readlong bstream) --the whole chunk size, including the chunk description
  285.                 )
  286.                 
  287.                 Append global_Append struct2fill
  288.                 return STAT = true;
  289.             )
  290.         )
  291.     )
  292.     
  293.     STAT = false
  294. )
  295.  
  296. -- //========================================
  297. -- //Material Chunk Header
  298. -- //========================================
  299.  
  300. -- #define MTL_NAME_CHUNK_DESC_0800_MAX_SUB_MATERIALS (32)
  301. struct MTL_NAME_CHUNK_DESC_0800
  302. (
  303.     type                                     = 0x0014,        --confirm 0x0014
  304.     version                                 = 0x0800,    
  305.     chunkID                                = 0,
  306.     
  307. --     enum {VERSION = 0x0800};
  308. --     enum EFlags
  309. --     {
  310. --         FLAG_MULTI_MATERIAL = 0x0001, //!< Have sub materials info.
  311. --         FLAG_SUB_MATERIAL   = 0x0002, //!< This is sub material.
  312. --         FLAG_SH_COEFFS      = 0x0004, //!< This material should get spherical harmonics coefficients computed.
  313. --         FLAG_SH_2SIDED      = 0x0008, //!< This material will be used as 2 sided in the sh precomputation.
  314. --         FLAG_SH_AMBIENT     = 0x0010, //!< This material will get an ambient sh term(to not shadow it entirely).
  315. --     };    
  316.  
  317.     nFlags                                 = 0,                   --//!< See EFlags.    --int
  318.     nFlags2                                 = 0,                     --int
  319.     _name                                 = "",                --//!< Material/shader name. char  name[128];
  320.         _name_count                     = 128,
  321.     nPhysicalizeType                     = 0,    --int
  322.     nSubMaterials                         = 0, --int
  323.     nSubMatChunkId                     = #(), --int   nSubMatChunkId[MTL_NAME_CHUNK_DESC_0800_MAX_SUB_MATERIALS];
  324.         nSubMatChunkId_count     = 32,
  325.     nAdvancedDataChunkId         = 0, --int
  326.     sh_opacity                             = 0, --float
  327.     reserve                                 = #(), --int   reserve[32]
  328.         reserve_count                 = 32
  329. )
  330.  
  331. struct MTL_NAME_CHUNK_DESC_0802
  332. (
  333.     type                                     = 0x0014,        --confirm 0x0014
  334.     version                                 = 0x0802,     --check that it is 0x0802
  335.     chunkID                                = 0,
  336.     
  337.     _name                                 = "", --char[128]
  338.         _name_count                     = 128, --chars
  339.     nSubmaterials                         = 0, --int,
  340.     unknown                             = 0 --int(?) -padding probably    
  341.     
  342.     --cryinfo
  343.     --// Data continues from here.
  344.     --// 1) if nSubMaterials is 0, this is a single-material: we store physicalization type of the material (int32).
  345.     --// 2) if nSubMaterials is not 0, this is a multi-material: we store nSubMaterials physicalization types (int32
  346.     --//    value for each sub-material). After the physicalization types we store chain of ASCIIZ names of sub-materials.
  347. )
  348.  
  349. fn read_MTL_NAME_CHUNK_DESC_0800 \
  350.                                                         &bstream: \
  351.                                                         &struct2fill: =
  352. (
  353.     struct2fill.nFlags                     = readlong bstream
  354.     struct2fill.nFlags2                 = readlong bstream                        
  355.                         
  356.     struct2fill._name = ReadFixedString \
  357.                                                         bstream:    &bstream \
  358.                                                         fixedLen:    &struct2fill._name_count
  359.                         
  360.     struct2fill.nPhysicalizeType     = readlong bstream
  361.     struct2fill.nSubMaterials         = readlong bstream
  362.                         
  363.     for i=1 to struct2fill.nSubMatChunkId_count do
  364.     (
  365.         Append struct2fill.nSubMatChunkId (readlong bstream)
  366.     )
  367.                         
  368.     struct2fill.nAdvancedDataChunkId     = readlong bstream
  369.     struct2fill.sh_opacity                     = readfloat bstream
  370.                         
  371.     for i=1 to struct2fill.reserve_count do
  372.     (
  373.         readlong bstream
  374.     )            
  375. )
  376.  
  377. fn read_MTL_NAME_CHUNK_DESC_0802 \
  378.                                                         &bstream: \
  379.                                                         &struct2fill: =
  380. (
  381.     struct2fill._name = ReadFixedString \
  382.                                                         bstream:    &bstream \
  383.                                                         fixedLen:    &struct2fill._name_count
  384.                         
  385.     struct2fill.nSubmaterials = readlong bstream
  386.     struct2fill.unknown = readlong bstream
  387.                         
  388.     --pad
  389.     readlong bstream -- this is probably always 0xFFFFFF
  390. )
  391.  
  392. struct CrySkinVtx
  393. (
  394.     bVolumetric     = 0,                 --int --not sure what this does
  395.     idx                 = point4,         --point4 -int
  396.     w                     = point4,         --point4 -float    
  397.     M                     = matrix3 0     --Matrix33 --I don't know what this is
  398. )
  399.  
  400. --//////////////////////////////// Unused yet ///////////////////////////////
  401.  
  402. --See CryHeaders.h 754
  403. -- //! Bonelist Chunk Header.
  404. -- //! This structure describes the bone names.
  405. -- //! It's followed by numEntities packed \0-terminated strings, the list terminated by double-\0.
  406. struct BONENAMELIST_CHUNK_DESC_0745
  407. (
  408. --     enum {VERSION = 0x0745};
  409.     numEntities = 0 --int
  410. )
  411.  
  412. struct COMPILED_BONE_CHUNK_DESC_0800
  413. (
  414. --     enum {VERSION=0x0800};
  415.  
  416.     reserved                 = #(),      --char reserved[32];
  417.         reserved_length     = 64         --64 bytes chunk
  418. )
  419. --////////////////////////End of Unused yet /////////////////////////////////
  420.  
  421.  
  422. --See CryHeaders.h 181
  423. --     --//! The compatible between 32- and 64-bits structure.
  424. -- struct CryBonePhysics_Comp
  425. -- {
  426. --     int nPhysGeom;            //!< Id of a separate mesh for this bone.
  427. --     // additional joint parameters.
  428. --     int   flags;
  429. --     float min[3],max[3];
  430. --     float spring_angle[3];
  431. --     float spring_tension[3];
  432. --     float damping[3];
  433. --     float framemtx[3][3];
  434.  
  435. --     AUTO_STRUCT_INFO;
  436. -- };
  437.  
  438. --0xACDC0000 See CryHeaders.h 254
  439. struct CryBoneDescData_Comp
  440. (
  441.     _filePos                            = 0, --pie
  442.     
  443.     chunkID                            = 0,
  444.     
  445.     reserved                         = 32,        --char reserved[32];
  446.     
  447.     m_nControllerID                 = 0,         --unsigned int --// unic id of bone (generated from bone name in the max)
  448.  
  449.     --// Physics info for different LOD.
  450.     --// LOD 0 is the physics of alive body, LOD 1 is the physics of a dead body.    
  451.     m_PhysInfo_length             = 2,
  452.     
  453.     
  454.     -- ////////////////// (struct) --CryBonePhysics_Comp m_PhysInfo[2]; //////////////////    
  455.         nPhysGeom                 = 0,         --int --// id of a separate mesh for this bone
  456.         --// additional joint parameters
  457.         flags                             = 0,         --int
  458.         
  459.         _min_length                 = 3,
  460.         _min                             = #(),     --array of float
  461.         
  462.         _max_length                 = 3,
  463.         _max                         = #(),     --array of float
  464.         
  465.         spring_angle_length         = 3,
  466.         spring_angle                 = #(),     --array of float
  467.         
  468.         spring_tension_length     = 3,
  469.         spring_tension             = #(),     --array of float
  470.         
  471.         damping_length             = 3,
  472.         damping                     = #(),     --array of float
  473.         
  474.         framemtx_length             = 3,
  475.         framemtx                     = #(#(), #(), #()), --3D array of float --float framemtx[3][3]
  476.     -- ///////////////////////////////////////////////////////////////////////////////////
  477.         
  478.     
  479.     m_fMass                         = 0.0,             --float
  480.     
  481.     m_DefaultW2B                 = Matrix3 1,     --Matrix34     --//!< Intitalpose matrix World2Bone.     --set to identity matrix
  482.     m_DefaultB2W                 = Matrix3 1,     --Matrix34     --//!< Intitalpose matrix Bone2World.     --set to identity matrix
  483.     
  484.     --m_DefaultW2B                 = BigMatrix 4 4,
  485.     --m_DefaultB2W                 = BigMatrix 4 4,    
  486.  
  487.     m_arrBoneName_length     = 256,
  488.     m_arrBoneName                 = "",
  489.  
  490.     m_nLimbId                         = 0,                 --int  --//!< Set by model state class.
  491.  
  492.     --//! This bone parent is this[m_nOffsetParent], 0 if the bone is root. Normally this is <= 0.
  493.     m_nOffsetParent                 = 0,                 --int
  494.  
  495.     --// The whole hierarchy of bones is kept in one big array that belongs to the ModelState
  496.     --// Each bone that has children has its own range of bone objects in that array,
  497.     --// and this points to the beginning of that range and defines the number of bones.
  498.     m_numChildren                 = 0,                 --unsigned  int
  499.     
  500.     --// the beginning of the subarray of children is at this[m_nOffsetChildren]
  501.     --// this is 0 if there are no children
  502.     m_nOffsetChildren             = 0                 --int
  503. )
  504.  
  505. --Here we read the mtl info
  506. fn read_CHUNK_0x0014 \
  507.                                     &bstream: \
  508.                                     &fileHeader: \
  509.                                     &struct2read: \
  510.                                     &global_Append: =
  511. (
  512.     --for i=1 to struct2read.ChunkType[1].count do
  513.     for i=1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  514.     (
  515.         if struct2read.ChunkType[1][i] == 0x0014 AND \
  516.             struct2read.ChunkType[2][i] == 0xCCCC then
  517.         (        
  518.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  519.             
  520.             if struct2read.ChunkVersion[1][i] == 0x0800 then --if Ox0800
  521.             (
  522.                 struct2fill = MTL_NAME_CHUNK_DESC_0800()
  523.                 
  524.                 A     = readshort bstream #unsigned --should be 0x0014
  525.                 B     = readshort bstream #unsigned --should be 0xCCCC
  526.                 C     = readshort bstream --should be 0x0800                
  527.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  528.                 F     = readlong bstream #unsigned
  529.                 ID = 0
  530.                 
  531.                 if fileHeader.version == 0x0745 then
  532.                 (
  533.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  534.                     
  535.                     --confirm we are on the right chunk
  536.                     if  A == 0x0014 AND \
  537.                         B == 0xCCCC AND \            
  538.                         C == 0x0800 AND \
  539.                         ID == struct2read.ChunkID[1][i] AND \
  540.                         F == struct2read.FileOffset[1][i] then
  541.                     (    
  542.                         --Store the Chunk ID
  543.                         struct2fill.chunkID = ID
  544.                         
  545.                         read_MTL_NAME_CHUNK_DESC_0800 \
  546.                                                                             bstream:    &bstream \
  547.                                                                             struct2fill:    &struct2fill
  548.                     )
  549.                 )
  550.                 else if fileHeader.version == 0x0744 then
  551.                 (
  552.                     --confirm we are on the right chunk
  553.                     if  A == 0x0014 AND \
  554.                         B == 0xCCCC AND \            
  555.                         C == 0x0800 AND \                        
  556.                         F == struct2read.FileOffset[1][i] then
  557.                     (
  558.                         read_MTL_NAME_CHUNK_DESC_0800 \
  559.                                                                             bstream:    &bstream \
  560.                                                                             struct2fill:    &struct2fill
  561.                     )
  562.                 )
  563.             )
  564.             else if struct2read.ChunkVersion[1][i] == 0x0802 then --if 0x0802
  565.             (
  566.                 struct2fill = MTL_NAME_CHUNK_DESC_0802()
  567.                 
  568.                 A     = readshort bstream #unsigned --should be 0x0014
  569.                 B     = readshort bstream #unsigned --should be 0xCCCC
  570.                 C     = readshort bstream --should be 0x0802                
  571.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  572.                 F     = readlong bstream #unsigned
  573.                 ID = 0
  574.                 
  575.                 if fileHeader.version == 0x0745 then
  576.                 (
  577.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  578.                     
  579.                     --confirm we are on the right chunk
  580.                     if  A == 0x0014 AND \
  581.                         B == 0xCCCC AND \            
  582.                         C == 0x0802 AND \
  583.                         ID == struct2read.ChunkID[1][i] AND \
  584.                         F == struct2read.FileOffset[1][i] then
  585.                     (        
  586.                         --Store the Chunk ID
  587.                         struct2fill.chunkID = ID
  588.                         
  589.                         read_MTL_NAME_CHUNK_DESC_0802 \
  590.                                                                             bstream:    &bstream \
  591.                                                                             struct2fill:    &struct2fill
  592.                     )
  593.                 )
  594.                 else if fileHeader.version == 0x0744 then
  595.                 (
  596.                     --confirm we are on the right chunk
  597.                     if  A == 0x0014 AND \
  598.                         B == 0xCCCC AND \            
  599.                         C == 0x0802 AND \                        
  600.                         F == struct2read.FileOffset[1][i] then
  601.                     (
  602.                         read_MTL_NAME_CHUNK_DESC_0802 \
  603.                                                                             bstream:    &bstream \
  604.                                                                             struct2fill:    &struct2fill
  605.                     )
  606.                 )                
  607.             )
  608.             
  609.             Append         global_Append     struct2fill
  610.         )
  611.     )
  612. )
  613.  
  614. struct EXPORT_FLAGS_CHUNK_DESC --0x0013 
  615. (
  616.     chunkID                                    = 0,
  617.     
  618. --     enum {VERSION = 0x0001};
  619. --     enum EFlags
  620. --     {
  621. --         MERGE_ALL_NODES          = 0x0001,
  622. --         HAVE_AUTO_LODS           = 0x0002,
  623. --         USE_CUSTOM_NORMALS       = 0x0004,
  624. --         WANT_F32_VERTICES        = 0x0008,
  625. --         EIGHT_WEIGHTS_PER_VERTEX = 0x0010,
  626. --     };
  627. --     enum ESrcFlags
  628. --     {
  629. --         FROM_MAX_EXPORTER = 0x0000,
  630. --         FROM_COLLADA_XSI  = 0x1001,
  631. --         FROM_COLLADA_MAX  = 0x1002,
  632. --         FROM_COLLADA_MAYA = 0x1003,
  633. --     };
  634.  
  635.     flags                                         = 0,                 --//!< @see EFlags --uint
  636.     rc_version                                 = #(),         --//!< Resource compiler version. --unsigned int rc_version[4] --uint
  637.         rc_version_count                 = 4,
  638.     
  639.     rc_version_string                     = "", --//!< Version as a string.    --char         rc_version_string[16]
  640.         rc_version_string_count        = 16,
  641.         
  642.     assetAuthorTool                         = 0, --uint
  643.     authorToolVersion                     = 0, --uint
  644.     reserved                                 = #(),             --unsigned int reserved[30]
  645.         reserved_count                    = 30
  646.     
  647. )
  648.  
  649.  
  650. fn fill_EXPORT_FLAGS_CHUNK_DESC \
  651.                                                     bstream \
  652.                                                     struct2fill =
  653. (
  654.     struct2fill.flags = readlong bstream #unsigned
  655.     
  656.     for i=1 to struct2fill.rc_version_count do
  657.     (
  658.         Append struct2fill.rc_version (readlong bstream #unsigned)
  659.     )
  660.  
  661.     struct2fill.rc_version_string = ReadFixedString \
  662.                                                                     bstream:    &bstream \
  663.                                                                     fixedLen:    &struct2fill.rc_version_string_count
  664.     
  665.     struct2fill.assetAuthorTool = readlong bstream #unsigned
  666.     struct2fill.authorToolVersion = readlong bstream #unsigned
  667.  
  668.     for i=1 to struct2fill.reserved_count do
  669.     (
  670.         readlong bstream #unsigned
  671.     )    
  672. )
  673.  
  674. fn read_EXPORT_FLAGS_CHUNK_DESC \
  675.                                                     &bstream: \
  676.                                                     &fileHeader: \
  677.                                                     &struct2read: \
  678.                                                     global_Append: =
  679. (
  680.     --for i=1 to struct2read.ChunkType[1].count do
  681.     for i=1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  682.     (
  683.         if struct2read.ChunkType[1][i] == 0x0015 AND \
  684.             struct2read.ChunkType[2][i] == 0xCCCC then
  685.         (
  686.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  687.             
  688.             if struct2read.ChunkVersion[1][i] == 0x0001 then --if Ox0001
  689.             (
  690.                 struct2fill = EXPORT_FLAGS_CHUNK_DESC()
  691.                 
  692.                 A     = readshort bstream #unsigned --should be 0x0015
  693.                 B     = readshort bstream #unsigned --should be 0xCCCC
  694.                 C     = readshort bstream --should be 0x0001                
  695.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  696.                 F     = readlong bstream #unsigned
  697.                 ID = 0
  698.                 
  699.                 if fileHeader.version == 0x0745 then
  700.                 (
  701.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  702.                     
  703.                     --confirm we are on the right chunk
  704.                     if  A == 0x0015 AND \
  705.                         B == 0xCCCC AND \            
  706.                         C == 0x0001 AND \
  707.                         ID == struct2read.ChunkID[1][i] AND \
  708.                         F == struct2read.FileOffset[1][i] then
  709.                     (    
  710.                         --Store the Chunk ID
  711.                         struct2fill.chunkID = ID
  712.                         
  713.                         fill_EXPORT_FLAGS_CHUNK_DESC \
  714.                                                                         bstream \
  715.                                                                         struct2fill
  716.                     )
  717.                 )
  718.                 else if fileHeader.version == 0x0744 then
  719.                 (
  720.                     --confirm we are on the right chunk
  721.                     if  A == 0x0015 AND \
  722.                         B == 0xCCCC AND \            
  723.                         C == 0x0001 AND \                        
  724.                         F == struct2read.FileOffset[1][i] then
  725.                     (
  726.                         fill_EXPORT_FLAGS_CHUNK_DESC \
  727.                                                                         bstream \
  728.                                                                         struct2fill
  729.                     )
  730.                 )
  731.                 
  732.                 Append         global_Append     struct2fill
  733.             )            
  734.         )
  735.     )
  736. )
  737.  
  738. -- //! Contain array of mesh subsets.
  739. -- //! Each subset holds an info about material id, indices ranges etc...
  740. struct MESH_PHYSICS_DATA_CHUNK_DESC_0800
  741. (
  742.     chunkID                            = 0,
  743.     
  744. --     enum {VERSION = 0x0800};
  745.  
  746.     nDataSize                         = 0,                  --//!< Size of physical data at the end of the chunk. --int
  747.     nFlags                             = 0,                        --int
  748.     nTetrahedraDataSize         = 0,    --int
  749.     nTetrahedraChunkId         = 0,     --//!< Chunk of physics Tetrahedra data. --int
  750.     reserved                         = #(),                --int reserved[2]
  751.         reserved_count             = 2,
  752.  
  753. --     // Data starts here at the end of the chunk.
  754. --     //char physicsData[nDataSize];
  755. --     //char tetrahedraData[nTetrahedraDataSize];
  756.     
  757.     physicsData                     = "",
  758.     tetrahedraData                 = ""
  759. )
  760.  
  761. fn fill_MESH_PHYSICS_DATA_CHUNK_DESC \
  762.                                                             bstream \
  763.                                                             struct2fill =
  764. (
  765.     struct2fill.nDataSize                 = readlong bstream
  766.     struct2fill.nFlags                         = readlong bstream
  767.     struct2fill.nTetrahedraDataSize     = readlong bstream
  768.     struct2fill.nTetrahedraChunkId     = readlong bstream
  769.     
  770.     for i=1 to struct2fill.reserved_count do
  771.     (
  772.         readlong bstream
  773.     )
  774.     
  775.     struct2fill.physicsData         = ReadFixedString \
  776.                                                                     bstream:    &bstream \
  777.                                                                     fixedLen:    &struct2fill.nDataSize
  778.     
  779.     struct2fill.tetrahedraData     = ReadFixedString \
  780.                                                                     bstream:    &bstream \
  781.                                                                     fixedLen:    &struct2fill.nTetrahedraDataSize
  782. )
  783.  
  784.  
  785. -- ////////////////////////////////////////////////////////////////////////// see CryHeaders.h 99
  786. -- enum EPhysicsGeomType
  787. -- {
  788. --     PHYS_GEOM_TYPE_NONE       = -1,
  789. --     PHYS_GEOM_TYPE_DEFAULT    = 0x1000 + 0,
  790. --     PHYS_GEOM_TYPE_NO_COLLIDE = 0x1000 + 1,
  791. --     PHYS_GEOM_TYPE_OBSTRUCT   = 0x1000 + 2,
  792.  
  793. --     PHYS_GEOM_TYPE_DEFAULT_PROXY = 0x1000 + 0x100, //!< Default physicalization, but only proxy (NoDraw geometry).
  794. -- };
  795.  
  796. --See CryHeaders.h 536
  797. -- struct MTL_NAME_CHUNK_DESC_0802
  798. -- {
  799. --     enum {VERSION = 0x0802};
  800.  
  801. --     char name[128];                 //!< Material/shader name.
  802. --     int  nSubMaterials;
  803.  
  804. --     // Data continues from here.
  805. --     // 1) if nSubMaterials is 0, this is a single-material: we store physicalization type of the material (int32).
  806. --     // 2) if nSubMaterials is not 0, this is a multi-material: we store nSubMaterials physicalization types (int32
  807. --     //    value for each sub-material). After the physicalization types we store chain of ASCIIZ names of sub-materials.
  808.  
  809. --     AUTO_STRUCT_INFO;
  810. -- };
  811.  
  812.  
  813. --See CryHeaders.h 709
  814. -- //! Contain array of mesh subsets.
  815. -- //! Each subset holds an info about material id, indices ranges etc...
  816. -- struct MESH_PHYSICS_DATA_CHUNK_DESC_0800
  817. -- {
  818. --     enum {VERSION = 0x0800};
  819.  
  820. --     int nDataSize;          //!< Size of physical data at the end of the chunk.
  821. --     int nFlags;
  822. --     int nTetrahedraDataSize;
  823. --     int nTetrahedraChunkId; //!< Chunk of physics Tetrahedra data.
  824. --     int reserved[2];
  825.  
  826. --     // Data starts here at the end of the chunk.
  827. --     //char physicsData[nDataSize];
  828. --     //char tetrahedraData[nTetrahedraDataSize];
  829.  
  830. --     AUTO_STRUCT_INFO;
  831. -- };
  832.  
  833. fn read_MESH_PHYSICS_DATA_CHUNK_DESC_0800 \
  834.                                                                         &bstream: \
  835.                                                                         &fileHeader: \
  836.                                                                         &struct2read: \
  837.                                                                         global_Append: =
  838. (
  839.     --for i=1 to struct2read.ChunkType[1].count do
  840.     for i=1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  841.     (
  842.         if struct2read.ChunkType[1][i] == 0x0018 AND \
  843.             struct2read.ChunkType[2][i] == 0xCCCC then
  844.         (
  845.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  846.             
  847.             if struct2read.ChunkVersion[1][i] == 0x0800 then --if 0x0800
  848.             (
  849.                 struct2fill = MESH_PHYSICS_DATA_CHUNK_DESC_0800()
  850.                 
  851.                 A     = readshort bstream #unsigned --should be 0x0018
  852.                 B     = readshort bstream #unsigned --should be 0xCCCC
  853.                 C     = readshort bstream --should be 0x0800                
  854.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  855.                 F     = readlong bstream #unsigned
  856.                 ID = 0
  857.                 
  858.                 if fileHeader.version == 0x0745 then
  859.                 (
  860.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  861.                     
  862.                     --confirm we are on the right chunk
  863.                     if  A == 0x0018 AND \
  864.                         B == 0xCCCC AND \            
  865.                         C == 0x0800 AND \
  866.                         ID == struct2read.ChunkID[1][i] AND \
  867.                         F == struct2read.FileOffset[1][i] then
  868.                     (        
  869.                         --Store the Chunk ID
  870.                         struct2fill.chunkID = ID
  871.                         
  872.                         fill_MESH_PHYSICS_DATA_CHUNK_DESC \
  873.                                                                                 bstream \
  874.                                                                                 struct2fill
  875.                     )
  876.                 )
  877.                 else if fileHeader.version == 0x0744 then
  878.                 (
  879.                     --confirm we are on the right chunk
  880.                     if  A == 0x0018 AND \
  881.                         B == 0xCCCC AND \            
  882.                         C == 0x0800 AND \                        
  883.                         F == struct2read.FileOffset[1][i] then
  884.                     (
  885.                         fill_MESH_PHYSICS_DATA_CHUNK_DESC \
  886.                                                                                 bstream \
  887.                                                                                 struct2fill
  888.                     )
  889.                 )
  890.                 
  891.                 Append         global_Append     struct2fill
  892.             )            
  893.         )
  894.     )
  895. )
  896.  
  897. fn fill_RANGE_ENTITY \
  898.                                 bstream \
  899.                                 struct2fill =
  900. (
  901.     struct2fill._name = ReadFixedString \
  902.                                                     bstream:    &bstream \
  903.                                                     fixedLen:    &struct2fill._name_count
  904.     
  905.     struct2fill.start = readlong bstream
  906.     struct2fill.end = readlong bstream
  907. )
  908.  
  909. fn fill_TIMING_CHUNK_DESC_0918 \
  910.                                                 bstream \
  911.                                                 struct2fill =
  912. (
  913.     struct2fill._obsolete_SecsPerTick = readfloat bstream --f32    
  914.     struct2fill._obsolete_TicksPerFrame = readlong bstream --int32
  915.     
  916.     struct2fill.global_range = RANGE_ENTITY()    
  917.     fill_RANGE_ENTITY \
  918.                                 bstream \
  919.                                 struct2fill.global_range
  920.     
  921.  
  922.     struct2fill._obsolete_SubRanges = ReadDouble bstream --int32    
  923. )
  924.  
  925. fn fill_TIMING_CHUNK_DESC_0919 \
  926.                                                 bstream \
  927.                                                 struct2fill =
  928. (
  929.     struct2fill._obsolete_SecsPerTick = readfloat bstream --f32    
  930.     struct2fill._obsolete_TicksPerFrame = readlong bstream --int32
  931.     
  932.     struct2fill.global_range = RANGE_ENTITY()    
  933.     fill_RANGE_ENTITY \
  934.                                 bstream \
  935.                                 struct2fill.global_range
  936.     
  937.  
  938.     struct2fill._obsolete_SubRanges = ReadDouble bstream --int32    
  939. )
  940.  
  941. fn read_TIMING_CHUNK_DESC_0918 \
  942.                                                     &bstream: \
  943.                                                     &fileHeader: \
  944.                                                     &struct2read: 
  945.                                                     global_Append: =
  946. (
  947.     --for i=1 to struct2read.ChunkType[1].count do
  948.     for i=1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  949.     (
  950.         if struct2read.ChunkType[1][i] == 0x000E AND \
  951.             struct2read.ChunkType[2][i] == 0xCCCC then
  952.         (
  953.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  954.             
  955.             if struct2read.ChunkVersion[1][i] == 0x0918 then --if 0x0918
  956.             (
  957.                 struct2fill = TIMING_CHUNK_DESC_0918()
  958.                 
  959.                 A     = readshort bstream #unsigned --should be 0x000E
  960.                 B     = readshort bstream #unsigned --should be 0xCCCC
  961.                 C     = readshort bstream --should be 0x0918                
  962.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  963.                 F     = readlong bstream #unsigned
  964.                 ID = 0
  965.                 
  966.                 if fileHeader.version == 0x0745 then
  967.                 (
  968.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  969.                     
  970.                     --confirm we are on the right chunk
  971.                     if  A == 0x000E AND \
  972.                         B == 0xCCCC AND \            
  973.                         C == 0x0918 AND \
  974.                         ID == struct2read.ChunkID[1][i] AND \
  975.                         F == struct2read.FileOffset[1][i] then
  976.                     (    
  977.                         struct2fill.chunkID = ID
  978.                         
  979.                         fill_TIMING_CHUNK_DESC_0918 \
  980.                                                                     bstream \
  981.                                                                     struct2fill
  982.                     )
  983.                 )
  984.                 else if fileHeader.version == 0x0744 then
  985.                 (
  986.                     --confirm we are on the right chunk
  987.                     if  A == 0x000E AND \
  988.                         B == 0xCCCC AND \            
  989.                         C == 0x0918 AND \                        
  990.                         F == struct2read.FileOffset[1][i] then
  991.                     (
  992.                         fill_TIMING_CHUNK_DESC_0918 \
  993.                                                                     bstream \
  994.                                                                     struct2fill
  995.                     )
  996.                 )
  997.             )
  998.             else if struct2read.ChunkVersion[1][i] == 0x0919 then --if 0x0001
  999.             (
  1000.                 struct2fill = TIMING_CHUNK_DESC_0919()
  1001.                 
  1002.                 A     = readshort bstream #unsigned --should be 0x000E
  1003.                 B     = readshort bstream #unsigned --should be 0xCCCC
  1004.                 C     = readshort bstream --should be 0x0919                
  1005.                     D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  1006.                 F     = readlong bstream #unsigned
  1007.                 ID = 0
  1008.                 
  1009.                 if fileHeader.version == 0x0745 then
  1010.                 (
  1011.                     ID = readlong bstream --chunk ID --//new in version 0x0745
  1012.                     
  1013.                     --confirm we are on the right chunk
  1014.                     if  A == 0x000E AND \
  1015.                         B == 0xCCCC AND \            
  1016.                         C == 0x0919 AND \
  1017.                         ID == struct2read.ChunkID[1][i] AND \
  1018.                         F == struct2read.FileOffset[1][i] then
  1019.                     (        
  1020.                         struct2fill.chunkID = ID
  1021.                         
  1022.                         fill_TIMING_CHUNK_DESC_0919 \
  1023.                                                                     bstream \
  1024.                                                                     struct2fill
  1025.                     )
  1026.                 )
  1027.                 else if fileHeader.version == 0x0744 then
  1028.                 (
  1029.                     --confirm we are on the right chunk
  1030.                     if  A == 0x000E AND \
  1031.                         B == 0xCCCC AND \            
  1032.                         C == 0x0919 AND \                        
  1033.                         F == struct2read.FileOffset[1][i] then
  1034.                     (
  1035.                         fill_TIMING_CHUNK_DESC_0919 \
  1036.                                                                     bstream \
  1037.                                                                     struct2fill
  1038.                     )
  1039.                 )                
  1040.             )            
  1041.             Append     global_Append struct2fill
  1042.         )
  1043.     )
  1044. )
  1045.  
  1046. --See CryHeaders.h 670
  1047. struct MeshSubset
  1048. (
  1049.     nFirstIndexId             = 0,
  1050.     nNumIndices             = 0,
  1051.     nFirstVertId             = 0,
  1052.     nNumVerts                 = 0,
  1053.     nMatID                     = 0, --//!< Material sub-object Id.
  1054.     fRadius                     = 0, --float
  1055.     vCenter                     = point3 --float[3] point3,
  1056. --         unknown                 = 0 --int
  1057. )
  1058.  
  1059. --See CryHeaders.h 683
  1060. struct MeshBoneIDs
  1061. (
  1062.     numBoneIDs                 = 0,         --uint32
  1063.     arrBoneIDs                     = #(),    --uint16
  1064.         arrBoneIDs_length     = 0x80    
  1065. )
  1066.  
  1067. --See CryHeaders.h 691
  1068. struct MeshSubsetTexelDensity
  1069. (
  1070.     texelDensity = 0 --float
  1071. )
  1072.  
  1073. --Cryheaders.h 655
  1074. --This is used to read the Subset Chunk Desc at 0xCCCC0017
  1075. struct MESH_SUBSETS_CHUNK_DESC_0800
  1076. (
  1077.     chunkID                                     = 0,
  1078.     
  1079.     type                                             = 0x0017,
  1080.     version                                         = 0x0800,
  1081.     
  1082.     nFlags                                         = 0,
  1083. --     enum EFlags
  1084. --     {
  1085. --         SH_HAS_DECOMPR_MAT                  = 0x0001, //!< Obsolete.
  1086. --         BONEINDICES                              = 0x0002,
  1087. --         HAS_SUBSET_TEXEL_DENSITY     = 0x0004,
  1088. --     };
  1089.     nCount                                         = 0, --Meshcount
  1090.         reserved                                 = 2, --int --pad
  1091.     
  1092.     MeshSubsetsArr                             = #(),
  1093.     ChunkHeadersArr                             = #(),    
  1094.     
  1095.     MeshBoneIDs                                 = 0, --if the mesh has bones, then this will be assigned the filled struct struct MeshBoneIDs (see the struct just above)
  1096.     MeshBoneSubsetsArr                     = #(),
  1097.     
  1098.     MeshSubsetTexelDensity                 = 0
  1099.     
  1100. )
  1101.  
  1102. ----------------------------------------------
  1103. --//! Stream chunk contains data about a mesh data stream (positions, normals, etc...).
  1104. struct STREAM_DATA_CHUNK_DESC_0800
  1105. (
  1106.     chunkID                                = 0,
  1107.     
  1108.     type                                     = 0x0016,
  1109.     version                                 = 0x0800,
  1110.     
  1111.     EFlags                                 = #(),             --Not implemented
  1112.     
  1113.     nFlags                                 = 0,                --int
  1114.     nStreamType                         = 0,              --int //!< Stream type one of ECgfStreamType.
  1115.     nCount                                 = 0,              --int //!< Number of elements.
  1116.     nElementSize                         = 0,              --int //!< Element Size.
  1117.     reserved                             = 2                --int
  1118.  
  1119.     --//! Data starts here at the end of the chunk.
  1120.     --//! char streamData[nCount*nElementSize];
  1121. )
  1122.  
  1123.  
  1124. -- //========================================
  1125. -- //Node Chunk Header
  1126. -- //========================================
  1127. --CryHeaders.h 586
  1128.  
  1129. --//! Compiled Mesh chunk -- that is the 0xCCCC0000
  1130. --WIP because I do not know what everything is here
  1131. -- //! Compiled Mesh chunk.
  1132. struct MESH_CHUNK_DESC_0801
  1133. (
  1134. --     //! Versions 0x0800 and 0x0801 are *exactly* the same.
  1135. --     //! Version number was increased from 0x0800 to 0x0801 just because
  1136. --     //! it was the only way to inform *old* (existing) executables that
  1137. --     //! NODE_CHUNK_DESC(!) chunk format was changed and cannot be read
  1138. --     //! by them (old CLoaderCGF::LoadNodeChunk() didn't check
  1139. --     //! NODE_CHUNK_DESC's version number).
  1140. --     enum {VERSION = 0x0801};
  1141. --     enum {COMPATIBLE_OLD_VERSION = 0x0800};
  1142.  
  1143. --     enum EFlags
  1144. --     {
  1145. --         MESH_IS_EMPTY           = 0x0001, //!< Empty mesh (no streams are saved).
  1146. --         HAS_TEX_MAPPING_DENSITY = 0x0002, //!< texMappingDensity contains a valid value.
  1147. --         HAS_EXTRA_WEIGHTS       = 0x0004, //!< The weight stream will have weights for influences 5-8.
  1148. --         HAS_FACE_AREA           = 0x0008, //!< geometricMeanFaceArea contains a valid value.
  1149. --     };
  1150.  
  1151.     nFlags                     = 0,             --//!< @see EFlags
  1152.     nFlags2                     = 0,
  1153.  
  1154. --     // Just for info.
  1155.     nVerts                     = 0,             --//!< Number of vertices.
  1156.     nIndices                 = 0,             --//!< Number of indices.
  1157.     nSubsets                 = 0,             --//!< Number of mesh subsets.
  1158.  
  1159.     nSubsetsChunkId     = 0,             --//!< Chunk id of subsets. (Must be ChunkType_MeshSubsets) (pie-meaning, in the file table chunk, this id, is that of the 0xCCCC0017)
  1160.     nVertAnimID             = 0,             --//!< id of the related vertAnim chunk if present. otherwise it is -1
  1161.  
  1162. --     //! ChunkIDs of data streams (Must be ChunkType_DataStream).
  1163. --     //! Index is one of ECgfStreamType values.
  1164. --    pie - meaning that, the values here, are the ChunkIDs of the table, and their position here in this Array, are the index of the
  1165. --    enum ECgfStreamType struct, see CryHeaders.h 78
  1166.     nStreamChunkID                        = #(),             --int nStreamChunkID[16];
  1167.         nStreamChunkID_count         = 16,
  1168.  
  1169. --     //! Chunk IDs of physical mesh data. (Must be ChunkType_MeshPhysicsData).
  1170.     nPhysicsDataChunkId                 = #(),             --int nPhysicsDataChunkId[4]
  1171.         nPhysicsDataChunkId_count     = 4,
  1172.  
  1173. --     //! Bounding box of the mesh.
  1174.     bboxMin                                 = point3,         --Vec3 bboxMin --point3
  1175.     bboxMax                                 = point3,         --Vec3 bboxMax --point3
  1176.  
  1177.     texMappingDensity                     = 0,         --float
  1178.     geometricMeanFaceArea             = 0,         --float
  1179.     reserved                                 = #(),     --int   reserved[31]
  1180.         reserved_count                     = 31
  1181. )
  1182.  
  1183. struct MESH_CHUNK_DESC_0745
  1184. (
  1185. --     //! Versions 0x0744 and 0x0745 are *exactly* the same.
  1186. --     //! Version number was increased from 0x0744 to 0x0745 just because
  1187. --     //! it was the only way to inform *old* (existing) executables that
  1188. --     //! NODE_CHUNK_DESC(!) chunk format was changed and cannot be read
  1189. --     //! by them (old CLoaderCGF::LoadNodeChunk() didn't check.
  1190. --     //! NODE_CHUNK_DESC's version number).
  1191.     
  1192. --     enum {VERSION = 0x0745};
  1193. --     enum {COMPATIBLE_OLD_VERSION = 0x0744};
  1194.  
  1195. --     enum EFlags1
  1196. --     {
  1197. --         FLAG1_BONE_INFO = 0x01,
  1198. --     };
  1199. --     enum EFlags2
  1200. --     {
  1201. --         FLAG2_HAS_VERTEX_COLOR = 0x01,
  1202. --         FLAG2_HAS_VERTEX_ALPHA = 0x02,
  1203. --         FLAG2_HAS_TOPOLOGY_IDS = 0x04,
  1204. --     };
  1205.     
  1206.     flags1             = 0, --unsigned char 
  1207.     flags2             = 0, --unsigned char
  1208.     nVerts             = 0, --int
  1209.     nTVerts             = 0, --int             --//!< Number of texture vertices (0 or nVerts).
  1210.     nFaces             = 0, --int
  1211.     VertAnimID     = 0 --int         --//!< Id of the related vertAnim chunk if present. otherwise it is -1.
  1212. )
  1213.  
  1214. struct NODE_CHUNK_DESC_0824
  1215. (
  1216.     
  1217. --     //! Versions 0x0823 and 0x0824 have exactly same layout.
  1218. --     //! The only difference between 0x0823 and 0x0824 is that some members.
  1219. --     //! are now named _obsoleteXXX_ and are not filled/used in 0x0824.
  1220. --     enum {VERSION = 0x0824};
  1221. --     enum {COMPATIBLE_OLD_VERSION = 0x0823};
  1222.  
  1223.     _name = "",    --char[64]
  1224.  
  1225.     ObjectID     = 0,                  --//!< ID of this node's object chunk (if present). --int
  1226.     ParentID     = 0,                 --//!< Chunk ID of the parent node's chunk. --int
  1227.     nChildren     = 0,              --//!< Number of child nodes. --int
  1228.     MatID         = 0,              --//!< Material chunk number. --int --pie-This is probably the number of 0xCCCC0014 instances in the chunk
  1229.  
  1230.     _obsoleteA_                     = #(),  --//!< uint8 IsGroupHead; uint8 IsGroupMember; uint8 _padding_[2]. not used anymore. --uint8 _obsoleteA_[4] uint8
  1231.         _obsoleteA_count         = 4,
  1232.     
  1233.     tm                                 = matrix3 0,  --//!< Transformation matrix. -float tm[4][4]
  1234.  
  1235.     _obsoleteB_                     = 0,           --//!< Position component of the matrix, stored as Vec3. not used anymore. --float _obsoleteB_[3]
  1236.         _obsoleteB_count         = 3,           
  1237.     _obsoleteC_                     = 0,           --//!< Rotation component of the matrix, stored as CryQuat. not used anymore. --float _obsoleteC_[4]
  1238.         _obsoleteC_count         = 4,  
  1239.     _obsoleteD_                     = 0,           --//!< Scale component of the matrix, stored as Vec3. not used anymore. --float _obsoleteD_[3]
  1240.         _obsoleteD_count         = 3, 
  1241.  
  1242.     pos_cont_id                     = 0,             --//!< Position controller chunk id. --int
  1243.     rot_cont_id                     = 0,            --//!< Rotation controller chunk id. --int
  1244.     scl_cont_id                     = 0,           --//!< Scale controller chunk id. --int
  1245.  
  1246.     PropStrLen                         = 0             --//!< Length of the property string. --int
  1247. )
  1248.  
  1249. struct FOLIAGE_INFO_CHUNK_DESC
  1250. (
  1251. --     enum {VERSION = 0x0001};
  1252.  
  1253.     nSpines             = 0, --int
  1254.     nSpineVtx         = 0, --int
  1255.     nSkinnedVtx     = 0, --int
  1256.     nBoneIds         = 0 --int
  1257. )
  1258.  
  1259. fn read_CGF_STREAM_POSITIONS \
  1260.                                                 &bstream: \
  1261.                                                 &struct2read: \
  1262.                                                 &info_MeshSubset: \
  1263.                                                 &StreamStruct2fill: =
  1264. (
  1265.     if struct2read.nStreamType == 0x00000000 then
  1266.     (
  1267.         if struct2read.nElementSize == 8 then
  1268.         (
  1269.             for v=1 to struct2read.nCount do
  1270.             (                                
  1271.                 x = (readHalfFloat bstream)
  1272.                 y = (readHalfFloat bstream)
  1273.                 z = (readHalfFloat bstream)
  1274.                                                         
  1275.                 w = readHalfFloat bstream --Probably the MatID for the mesh with these vertices (but not sure)
  1276.                                                         
  1277.                 Append StreamStruct2fill.CGF_STREAM_POSITIONS[1] [x, y, z]
  1278.                 Append StreamStruct2fill.CGF_STREAM_POSITIONS[2] w --this is always 1.0 so far in my tests (but what is it for?)
  1279.             )
  1280.         )
  1281.         if struct2read.nElementSize == 12 then
  1282.         (
  1283.             for v=1 to struct2read.nCount do
  1284.             (
  1285.                 x = (readfloat bstream)
  1286.                 y = (readfloat bstream)
  1287.                 z = (readfloat bstream)                    
  1288.                 
  1289.                 Append StreamStruct2fill.CGF_STREAM_POSITIONS[1] [x, y, z]
  1290.             )
  1291.         )
  1292.     )
  1293. )
  1294.  
  1295. fn read_CGF_STREAM_INDICES \
  1296.                                             &bstream: \
  1297.                                             &struct2read: \
  1298.                                             &info_MeshSubset: \
  1299.                                             &StreamStruct2fill: =
  1300. (    
  1301.     if struct2read.nStreamType == 0x00000005 then
  1302.     (        
  1303.         if ::rollout_Report.chk_Mesh_Report.state then
  1304.         (
  1305.             format "######### ftell bstream: %\n" (ftell bstream)
  1306.             format "#####################################\n"
  1307.             format "struct2read.nCount: %\n" struct2read.nCount
  1308.             format "#####################################\n"
  1309.         )
  1310.         
  1311.         local idx_offset = 1        
  1312.         if struct2read.nElementSize == 2 then --This is the size of each element to read
  1313.         (
  1314.             for v=1 to struct2read.nCount/3 do --this is the number of elements to read (3 for each face)
  1315.             (
  1316.                 --Remember max index is 1-based (NOT zero based !) thus we need to add +1 to each index
  1317.                 a         = (readshort bstream #unsigned)+idx_offset
  1318.                 b         = (readshort bstream #unsigned)+idx_offset
  1319.                 c         = (readshort bstream #unsigned)+idx_offset    
  1320.                 
  1321.                 Append StreamStruct2fill.CGF_STREAM_INDICES [a,b,c]
  1322.             )
  1323.         )
  1324.         else if struct2read.nElementSize == 4 then
  1325.         (
  1326.             for v=1 to struct2read.nCount/3 do --this is the number of elements to read (3 for each face)
  1327.             (
  1328.                 --Remember max index is 1-based (NOT zero based !) thus we need to add +1 to each index
  1329.                 a         = (readfloat bstream #unsigned)+idx_offset
  1330.                 b         = (readfloat bstream #unsigned)+idx_offset
  1331.                 c         = (readfloat bstream #unsigned)+idx_offset    
  1332.                 
  1333.                 Append StreamStruct2fill.CGF_STREAM_INDICES [a,b,c]
  1334.             )
  1335.         )
  1336.     )
  1337. )
  1338.  
  1339. fn read_CGF_STREAM_TEXCOORDS \
  1340.                                                     &bstream: \
  1341.                                                     &struct2read: \
  1342.                                                     &info_MeshSubset: \
  1343.                                                     &StreamStruct2fill: =
  1344. (
  1345.     if struct2read.nStreamType == 0x00000002 then
  1346.     (
  1347.         for v=1 to struct2read.nCount do
  1348.         (                            
  1349.             u = (readfloat bstream)
  1350.             v = (readfloat bstream)
  1351.             w = 0
  1352.             
  1353.             --UVW fix --for Ryse, we have to mirror the UVs vertically    
  1354.             if ::g_UVW_Flip_V OR (stricmp ::g_CryGame_dropDown_selection "Ryse") == 0 then
  1355.             (
  1356.                 point_3         = [u, (-v+1), w]
  1357.             )
  1358.             else
  1359.             (
  1360.                 point_3         = [u, v, w]
  1361.             )
  1362.  
  1363.             Append StreamStruct2fill.CGF_STREAM_TEXCOORDS point_3        
  1364.         )
  1365.     )
  1366. )
  1367.  
  1368.  
  1369. fn read_CGF_STREAM_NORMALS \
  1370.                                             &bstream: \
  1371.                                             &struct2read: \
  1372.                                             &info_MeshSubset: \
  1373.                                             &StreamStruct2fill: =
  1374. (
  1375.     if struct2read.nStreamType == 0x00000001 then
  1376.     (
  1377.         for v=1 to struct2read.nCount do
  1378.         (                                
  1379.             x = (readfloat bstream)
  1380.             y = (readfloat bstream)
  1381.             z = (readfloat bstream)
  1382.             
  1383.             Append StreamStruct2fill.CGF_STREAM_NORMALS [x, y, z]            
  1384.         )
  1385.     )
  1386. )
  1387.  
  1388. fn read_CGF_STREAM_BONEMAPPING \
  1389.                                                     &bstream: \
  1390.                                                     &struct2read: \
  1391.                                                     &info_MeshSubset: \
  1392.                                                     &StreamStruct2fill: =
  1393. (
  1394.     if struct2read.nStreamType == 0x00000009 then
  1395.     (
  1396.         --We will divide the weights below by this constant, to get a float
  1397.         local weight = 255.0
  1398.         
  1399.         for v=1 to struct2read.nCount do
  1400.         (
  1401.             --create struct instance
  1402.             inst_CrySkinVtx = CrySkinVtx()
  1403.             
  1404.             --We read the bone ids        
  1405.             br     = (readbyte bstream #unsigned)
  1406.             bg     = (readbyte bstream #unsigned)
  1407.             bb     = (readbyte bstream #unsigned)
  1408.             ba     = (readbyte bstream #unsigned)
  1409.             
  1410.             --We read the weights (and later divide them by 255.0 to get the real float weights)
  1411.             wr     = (readbyte bstream #unsigned)
  1412.             wg     = (readbyte bstream #unsigned)
  1413.             wb     = (readbyte bstream #unsigned)
  1414.             wa     = (readbyte bstream #unsigned)
  1415.             
  1416.             --We fill the struct point4 for ids, and point4 for weights
  1417.             inst_CrySkinVtx.idx     = [br, bg, bb, ba]
  1418.             inst_CrySkinVtx.w    = [ \
  1419.                                                 (wr/weight as float), \
  1420.                                                 (wg/weight as float), \
  1421.                                                 (wb/weight as float), \
  1422.                                                 (wa/weight as float) \
  1423.                                             ]
  1424.             
  1425.             --Append the final struct to ECgfStreamType
  1426.             Append         StreamStruct2fill.CGF_STREAM_BONEMAPPING         inst_CrySkinVtx
  1427.         )
  1428.     )
  1429. )
  1430.  
  1431.  
  1432. fn read_MESH_CHUNK_DESC_0801 \
  1433.                                                 &bstream: \
  1434.                                                 &struct2read: \
  1435.                                                 &info_MeshSubset: \
  1436.                                                 &Struct2fill: =
  1437. (        
  1438. --     enum EFlags
  1439. --     {
  1440. --         MESH_IS_EMPTY                           = 0x0001, //!< Empty mesh (no streams are saved).
  1441. --         HAS_TEX_MAPPING_DENSITY         = 0x0002, //!< texMappingDensity contains a valid value.
  1442. --         HAS_EXTRA_WEIGHTS                   = 0x0004, //!< The weight stream will have weights for influences 5-8.
  1443. --         HAS_FACE_AREA                           = 0x0008, //!< geometricMeanFaceArea contains a valid value.
  1444. --     };                        
  1445.                             
  1446.     struct2fill.nFlags                     = readlong bstream --@see EFlags
  1447.     struct2fill.nFlags2                 = readlong bstream
  1448.                             
  1449.     --Just for info.
  1450.     struct2fill.nVerts                     = readlong bstream --Number of vertices.
  1451.     struct2fill.nIndices                 = readlong bstream --Number of indices.
  1452.     struct2fill.nSubsets                 = readlong bstream --Number of mesh subsets.
  1453.                             
  1454.     struct2fill.nSubsetsChunkId     = readlong bstream --Chunk id of subsets. (Must be ChunkType_MeshSubsets)
  1455.     struct2fill.nVertAnimID             = readlong bstream --id of the related vertAnim chunk if present. otherwise it is -1
  1456.  
  1457. --     ChunkIDs of data streams (Must be ChunkType_DataStream).
  1458. --     Index is one of ECgfStreamType values.
  1459.     for i=1 to struct2fill.nStreamChunkID_count do
  1460.     (
  1461.         Append struct2fill.nStreamChunkID (readlong bstream)
  1462.     )
  1463.                             
  1464.     for i=1 to struct2fill.nPhysicsDataChunkId_count do
  1465.     (
  1466.         Append struct2fill.nPhysicsDataChunkId (readlong bstream)                            
  1467.     )
  1468.                             
  1469.     x = readfloat bstream
  1470.     y = readfloat bstream
  1471.     z = readfloat bstream
  1472.     struct2fill.bboxMin = [x,y,z]
  1473.                             
  1474.     x = readfloat bstream
  1475.     y = readfloat bstream
  1476.     z = readfloat bstream
  1477.     struct2fill.bboxMax = [x,y,z]
  1478.                             
  1479.     struct2fill.texMappingDensity             = readfloat bstream
  1480.     struct2fill.geometricMeanFaceArea     = readfloat bstream
  1481.                             
  1482.     for i=1 to struct2fill.reserved_count do
  1483.     (
  1484.         readlong bstream
  1485.     )    
  1486. )
  1487.  
  1488. fn read_NODE_CHUNK_DESC_0824 \
  1489.                                                 &bstream: \
  1490.                                                 &struct2read: \
  1491.                                                 &info_MeshSubset: \
  1492.                                                 &Struct2fill: =
  1493. (
  1494.     --Fill in here
  1495.     local fixedLen = 64
  1496.     struct2fill._name             = ReadFixedString \
  1497.                                                                 bstream:    &bstream \
  1498.                                                                 fixedLen:    &fixedLen
  1499.     
  1500.     struct2fill.ObjectID         = readlong bstream
  1501.     struct2fill.ParentID         = readlong bstream
  1502.     struct2fill.nChildren         = readlong bstream
  1503.     struct2fill.MatID             = readlong bstream
  1504.                             
  1505.     print struct2fill._name
  1506.                             
  1507.     for i=1 to struct2fill._obsoleteA_count do
  1508.     (
  1509.         readbyte bstream #unsigned
  1510.     )
  1511.                             
  1512.     ---------Fill Matrix3---------
  1513.     x = readfloat bstream
  1514.     y = readfloat bstream
  1515.     z = readfloat bstream
  1516.     struct2fill.tm.row1 = [x,y,z]
  1517.  
  1518.     x = readfloat bstream
  1519.     y = readfloat bstream
  1520.     z = readfloat bstream
  1521.     struct2fill.tm.row2 = [x,y,z]
  1522.  
  1523.     x = readfloat bstream
  1524.     y = readfloat bstream
  1525.     z = readfloat bstream
  1526.     struct2fill.tm.row3 = [x,y,z]
  1527.  
  1528.     x = readfloat bstream
  1529.     y = readfloat bstream
  1530.     z = readfloat bstream
  1531.     struct2fill.tm.row4 = [x,y,z]
  1532.     --------------------------------
  1533.                             
  1534.     for i=1 to struct2fill._obsoleteB_count do
  1535.     (
  1536.         readfloat bstream
  1537.     )
  1538.                             
  1539.     for i=1 to struct2fill._obsoleteC_count do
  1540.     (
  1541.         readfloat bstream
  1542.     )
  1543.                             
  1544.     for i=1 to struct2fill._obsoleteD_count do
  1545.     (
  1546.         readfloat bstream
  1547.     )
  1548.                             
  1549.     struct2fill.pos_cont_id         = readlong bstream
  1550.     struct2fill.rot_cont_id         = readlong bstream
  1551.     struct2fill.scl_cont_id         = readlong bstream
  1552.                             
  1553.     struct2fill.PropStrLen         = readlong bstream
  1554. )
  1555.  
  1556.  
  1557. --Note --CryHeaders.h 754
  1558. -- //! Bonelist Chunk Header.
  1559. -- //! This structure describes the bone names.
  1560. -- //! It's followed by numEntities packed \0-terminated strings, the list terminated by double-\0.
  1561.  
  1562.  
  1563. fn read_STREAM_DATA_CHUNK_DESC_0800 \
  1564.                                                             &bstream: \
  1565.                                                             &fileHeader: \
  1566.                                                             &struct2read: \                                                            
  1567.                                                             &info_MeshSubset: \
  1568.                                                             IDX: \
  1569.                                                             &IDx0017: \
  1570.                                                             &inst_ECgfStreamType: =
  1571. (
  1572.     --for i=IDX+1 to struct2read.ChunkType[1].count do
  1573.     for i=IDX+1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  1574.     (
  1575.         if struct2read.ChunkType[1][i] == 0x0016 AND \    --0x0016
  1576.             struct2read.ChunkType[2][i] == 0xCCCC then
  1577.         (
  1578.             
  1579.             --create runtime instance struct
  1580.             struct2fill = STREAM_DATA_CHUNK_DESC_0800()                    
  1581.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  1582.                     
  1583.             if struct2read.ChunkVersion[1][i] == 0x0802 then --if Ox0800
  1584.             (
  1585.                 --not implemented yet
  1586.             )
  1587.             else if struct2read.ChunkVersion[1][i] == 0x0800 then --if 0x0800
  1588.             (
  1589.                 A                 = readshort bstream #unsigned --should be 0x0016
  1590.                 B                 = readshort bstream #unsigned --should be 0xCCCC
  1591.                 C                 = readshort bstream --should be 0x0800                
  1592.                     D             = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  1593.                 F                 = readlong bstream #unsigned
  1594.                 IDx0016     = 0
  1595.                 
  1596.                 if ::rollout_Report.chk_Mesh_Report.state then
  1597.                 (
  1598.                     format "## A: %\n" A
  1599.                     format "## B: %\n" B
  1600.                     format "## C: %\n" C
  1601.                     format "## F: %\n" F
  1602.                     format "## IDx0016: %\n" IDx0016
  1603.                 )
  1604.                 
  1605.                 if fileHeader.version == 0x0745 then
  1606.                 (
  1607.                     IDx0016 = readlong bstream --chunk ID --//new in version 0x0745
  1608.                     
  1609.                     format "## IDx0016: %\n" IDx0016
  1610.                     
  1611.                                         
  1612.                     --confirm we are on the right chunk
  1613.                     if  A             == 0x0016 AND \
  1614.                         B             == 0xCCCC AND \            
  1615.                         C             == 0x0800 AND \
  1616.                         IDx0016    == struct2read.ChunkID[1][i] AND \
  1617.                         F             == struct2read.FileOffset[1][i] then
  1618.                     (
  1619.                         struct2fill.chunkID            = IDx0016
  1620.                         
  1621.                         if ::rollout_Report.chk_Mesh_Report.state then
  1622.                         (
  1623.                             format "#### ftell bstream: %\n" (ftell bstream)
  1624.                         )                        
  1625.                             
  1626.                         struct2fill.nFlags                 = readlong bstream
  1627.                         struct2fill.nStreamType     = readlong bstream                                
  1628.  
  1629.                         struct2fill.nCount                 = readlong bstream
  1630.                         struct2fill.nElementSize         = readlong bstream
  1631.                         
  1632.                         for x=1 to struct2fill.reserved do
  1633.                         (
  1634.                             readlong bstream
  1635.                         )
  1636.                                 
  1637.                         --read in CGF_STREAM_POSITIONS
  1638.                         read_CGF_STREAM_POSITIONS \
  1639.                                                                     bstream:                &bstream \
  1640.                                                                     struct2read:            &struct2fill \ --this is the struct we just filled and we will read from it to know hom much to read
  1641.                                                                     info_MeshSubset:    &info_MeshSubset \ --not used for now
  1642.                                                                     StreamStruct2fill:        &inst_ECgfStreamType
  1643.                                 
  1644.                         --read in CGF_STREAM_POSITIONS
  1645.                         read_CGF_STREAM_INDICES \
  1646.                                                                 bstream:                &bstream \
  1647.                                                                 struct2read:            &struct2fill \ --this is the struct we just filled and we will read from it to know hom much to read
  1648.                                                                 info_MeshSubset:    &info_MeshSubset \ --not used for now
  1649.                                                                 StreamStruct2fill:        &inst_ECgfStreamType                        
  1650.                         --UVWs
  1651.                         read_CGF_STREAM_TEXCOORDS \
  1652.                                                                     bstream:                &bstream \
  1653.                                                                     struct2read:            &struct2fill \ --this is the struct we just filled and we will read from it to know hom much to read
  1654.                                                                     info_MeshSubset:    &info_MeshSubset \ --not used for now
  1655.                                                                     StreamStruct2fill:        &inst_ECgfStreamType
  1656.                         --Normals
  1657.                         read_CGF_STREAM_NORMALS  \
  1658.                                                                     bstream:                &bstream \
  1659.                                                                     struct2read:            &struct2fill \ --this is the struct we just filled and we will read from it to know hom much to read
  1660.                                                                     info_MeshSubset:    &info_MeshSubset \ --not used for now
  1661.                                                                     StreamStruct2fill:        &inst_ECgfStreamType
  1662.                         --read bonemapping
  1663.                         read_CGF_STREAM_BONEMAPPING \
  1664.                                                                         bstream:                &bstream \
  1665.                                                                         struct2read:            &struct2fill \ --this is the struct we just filled and we will read from it to know hom much to read
  1666.                                                                         info_MeshSubset:    &info_MeshSubset \ --not used for now
  1667.                                                                         StreamStruct2fill:        &inst_ECgfStreamType                            
  1668.                     )
  1669.                     
  1670.                 )                    
  1671.                 else if fileHeader.version == 0x0744 then
  1672.                 (
  1673.                     --confirm we are on the right chunk
  1674.                     if  A == 0x0016 AND \
  1675.                         B == 0xCCCC AND \            
  1676.                         C == 0x0800 AND \                        
  1677.                         F == struct2read.FileOffset[1][i] then
  1678.                     (
  1679.                         -- not implemented yet
  1680.                     )
  1681.                 )
  1682.             )                    
  1683.             Append     info_MeshSubset.ChunkHeadersArr     struct2fill                
  1684.         )
  1685.         /* --this is not a stream chunk, we read in (after) read_CHUNK_0017 instead (see below function)
  1686.         else if struct2read.ChunkType[1][i] == 0x0000 AND \ --ChunkType_Mesh = 0x1000,   //!< Was 0xCCCC0000 in chunk files with versions <= 0x745.
  1687.         struct2read.ChunkType[2][i] == 0xCCCC then
  1688.         (    
  1689.             --For now we are just developing this for Ryse, but earlier versions of CryEngine might and can have all the chunks
  1690.             --in one single cgf file, thus we need to read these here as well, but for now, let's turn them OFF if the game is "Ryse"
  1691.             if (stricmp ::g_CryGame_dropDown_selection "Ryse") != 0 then  
  1692.             (
  1693.                 struct2fill = MESH_CHUNK_DESC_0801()
  1694.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  1695.                 
  1696.                 if struct2read.ChunkVersion[1][i] == 0x0800 OR \
  1697.                     struct2read.ChunkVersion[1][i] == 0x0801 then --if 0x0823 or 0x0824
  1698.                 (                
  1699.                     A                 = readshort bstream #unsigned --should be 0x0000
  1700.                     B                 = readshort bstream #unsigned --should be 0xCCCC
  1701.                     C                 = readshort bstream --should be 0x0800 or 0x0801            
  1702.                         D             = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  1703.                     F                 = readlong bstream #unsigned
  1704.                     IDx0000     = 0                    
  1705.                     
  1706.                     if fileHeader.version == 0x0745 then
  1707.                     (    
  1708.                         IDx0000 = readlong bstream --chunk ID --//new in version 0x0745        
  1709.                         
  1710.                         --confirm we are on the right chunk
  1711.                         if  A             == 0x0000 AND \
  1712.                             B             == 0xCCCC AND \            
  1713.                             (C         == 0x0800 OR C == 0x0801) AND \
  1714.                             IDx0000 == struct2read.ChunkID[1][i] AND \
  1715.                             F             == struct2read.FileOffset[1][i] then
  1716.                         (
  1717.                             read_MESH_CHUNK_DESC_0801 \
  1718.                                                                         bstream:                bstream \
  1719.                                                                         struct2read:            struct2read \
  1720.                                                                         info_MeshSubset:    info_MeshSubset \
  1721.                                                                         Struct2fill:                Struct2fill
  1722.                         )
  1723.                     )                    
  1724.                     else if fileHeader.version == 0x0744 then
  1725.                     (
  1726.                         --confirm we are on the right chunk
  1727.                         if  A == 0x0000 AND \
  1728.                             B == 0xCCCC AND \            
  1729.                             (C         == 0x0800 OR C == 0x0801) AND \                        
  1730.                             F == struct2read.FileOffset[1][i] then
  1731.                         (
  1732.                             -- not implemented yet                        
  1733.                             print "we are in here"
  1734.                         )
  1735.                     )                    
  1736.                     Append         ::g_MESH_CHUNK_DESC_0801         struct2fill                    
  1737.                 )
  1738.             )
  1739.         )
  1740.         --*/
  1741.         /* --this is not a stream chunk, we read in (after) read_CHUNK_0017 instead (see below function)
  1742.         else if struct2read.ChunkType[1][i] == 0x000B AND \ --0x000B --ChunkType_Mesh cryheaders.h 1086
  1743.         struct2read.ChunkType[2][i] == 0xCCCC then
  1744.         (    
  1745.             --For now we are just developing this for Ryse, but earlier versions of CryEngine might and can have all the chunks
  1746.             --in one single cgf file, thus we need to read these here as well, but for now, let's turn them OFF if the game is "Ryse"
  1747.             if (stricmp ::g_CryGame_dropDown_selection "Ryse") != 0 then  
  1748.             (
  1749.                 struct2fill = NODE_CHUNK_DESC_0824()            
  1750.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  1751.                 
  1752.                 if struct2read.ChunkVersion[1][i] == 0x0823 OR \
  1753.                     struct2read.ChunkVersion[1][i] == 0x0824 then --if 0x0823 or 0x0824
  1754.                 (            
  1755.                     A                 = readshort bstream #unsigned --should be 0x000B
  1756.                     B                 = readshort bstream #unsigned --should be 0xCCCC
  1757.                     C                 = readshort bstream --should be 0x0823 or 0x0824            
  1758.                         D             = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  1759.                     F                 = readlong bstream #unsigned
  1760.                     IDx000B     = 0
  1761.                             
  1762.                     if fileHeader.version == 0x0745 then
  1763.                     (
  1764.                         IDx000B = readlong bstream --chunk ID --//new in version 0x0745
  1765.                                 
  1766.                         --confirm we are on the right chunk
  1767.                         if  A             == 0x000B AND \
  1768.                             B             == 0xCCCC AND \            
  1769.                             (C         == 0x0823 OR C == 0x0824) AND \
  1770.                             IDx000B == struct2read.ChunkID[1][i] AND \
  1771.                             F             == struct2read.FileOffset[1][i] then
  1772.                         (
  1773.                             read_NODE_CHUNK_DESC_0824 \
  1774.                                                                         bstream:                bstream \
  1775.                                                                         struct2read:            struct2read \
  1776.                                                                         info_MeshSubset:    info_MeshSubset \
  1777.                                                                         Struct2fill:                Struct2fill
  1778.                         )
  1779.                     )                    
  1780.                     else if fileHeader.version == 0x0744 then
  1781.                     (
  1782.                         --confirm we are on the right chunk
  1783.                         if  A == 0x000B AND \
  1784.                             B == 0xCCCC AND \            
  1785.                             (C         == 0x0823 OR C == 0x0824) AND \                        
  1786.                             F == struct2read.FileOffset[1][i] then
  1787.                         (
  1788.                             -- not implemented yet                        
  1789.                             print "we are in here"
  1790.                         )
  1791.                     )                
  1792.                 )
  1793.                 
  1794.                 Append ::g_NODE_CHUNK_DESC_0824 struct2fill
  1795.             )
  1796.         )
  1797.         --*/
  1798.         else --End of Stream Subset
  1799.         (
  1800.             format "End of Chunks\n"
  1801.         )
  1802.     )
  1803. )
  1804. ----------------------------------------------
  1805.  
  1806.  
  1807. fn sortObjects_to_layers \
  1808.                                     msh: =
  1809. (
  1810.     if iskindof msh Editable_Mesh OR
  1811.         isValidNode msh then
  1812.     (
  1813.         if (matchpattern msh.name pattern:"*proxy*") then
  1814.         (
  1815.             proxyLayer = "proxy"
  1816.             newLayer            = LayerManager.newLayerFromName proxyLayer
  1817.             
  1818.             if iskindof msh Editable_mesh then
  1819.             (
  1820.                 newLayer.addNode msh
  1821.             )        
  1822.             newLayer.ishidden = true
  1823.         )
  1824.         else if (matchpattern msh.name pattern:"*remain*")  then
  1825.         (
  1826.             destructiblesLayer = "destructibles"
  1827.             newLayer            = LayerManager.newLayerFromName destructiblesLayer
  1828.             
  1829.             if iskindof msh Editable_mesh then
  1830.             (
  1831.                 newLayer.addNode msh
  1832.             )        
  1833.             newLayer.ishidden = true
  1834.         )
  1835.     )
  1836. )
  1837.  
  1838. --/////////////////////////////////// MESH BUILDER ///////////////////////////////////
  1839. fn BUILD_MESH \
  1840.                         info_MeshSubset: \
  1841.                         info_ECgfStreamType: =
  1842. (    
  1843.     if (::g_ECgfStreamType.count == ::g_MESH_SUBSETS_CHUNK_DESC_0800.count) then
  1844.     (
  1845.         local BUILT_MESHES_temp = #()
  1846.         local built_HaveMeshNamedMain = false
  1847.         
  1848.         for s=1 to ::g_ECgfStreamType.count do
  1849.         (
  1850.             if g_MESH_CHUNK_DESC_0801[s].nStreamChunkID[1] > 0 AND \ --we check that there are indeed CGF_STREAM_POSITIONS
  1851.                 g_MESH_CHUNK_DESC_0801[s].nStreamChunkID[6] > 0 then --we check that there are indeed CGF_STREAM_INDICES
  1852.             (
  1853.                 --------------Build Mesh--------------
  1854.                 msh = mesh \
  1855.                                     vertices:    ::g_ECgfStreamType[s].CGF_STREAM_POSITIONS[1] \                
  1856.                                     faces:        ::g_ECgfStreamType[s].CGF_STREAM_INDICES
  1857.                 ----------------------------------------                
  1858.  
  1859.                 if g_MESH_CHUNK_DESC_0801[s].nStreamChunkID[3] > 0 then --we check that there are indeed CGF_STREAM_TEXCOORDS
  1860.                 (
  1861.                     format "================= We will now attempt to set the UVs... =================\n"
  1862.                     
  1863.                     --/*
  1864.                     ------------------UVs------------------
  1865.                     setNumTVerts msh ::g_ECgfStreamType[s].CGF_STREAM_TEXCOORDS.count
  1866.                     buildTVFaces msh
  1867.                         
  1868.                     for x=1 to ::g_ECgfStreamType[s].CGF_STREAM_TEXCOORDS.count do 
  1869.                     (
  1870.                         setTVert msh x ::g_ECgfStreamType[s].CGF_STREAM_TEXCOORDS[x]
  1871.                     )
  1872.                         
  1873.                     for x=1 to ::g_ECgfStreamType[s].CGF_STREAM_INDICES.count do
  1874.                     (
  1875.                         setTVFace msh x ::g_ECgfStreamType[s].CGF_STREAM_INDICES[x]
  1876.                     )
  1877.                     ------------------------------------------
  1878.  
  1879.                     if msh != undefined then
  1880.                     (    
  1881.                         if (classof msh) == Editable_mesh then
  1882.                         (
  1883.                             if isValidNode msh then
  1884.                             (
  1885.                                 if ::g_assetName_From_CDF != "" then
  1886.                                 (
  1887.                                     msh.name = ::g_assetName_From_CDF  --name the mesh
  1888.                                 )
  1889.                                 else
  1890.                                 (
  1891.                                     msh.name = ::g_NODE_CHUNK_DESC_0824[s]._name  --name the mesh
  1892.                                 )
  1893.                                 
  1894.                                 --// Handle Main/Remain meshes used for Destroyable Objects.
  1895.                                 if (stricmp ((::g_NODE_CHUNK_DESC_0824[s]._name) as string) "main") == 0 then
  1896.                                 (
  1897.                                     built_HaveMeshNamedMain = true
  1898.                                 )
  1899.                                 
  1900.                                 --We will set the material IDs for the faces now (using the meshSubset ranges)
  1901.                                 for i=1 to ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr.count do --loop subset meshes (submeshes)
  1902.                                 (    
  1903.                                     local RangeStart     = 0
  1904.                                     local RangeEnd         = 0
  1905.                                     
  1906.                                     if ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nFirstIndexId == 0 then
  1907.                                     (
  1908.                                         RangeStart     = ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nFirstIndexId +1
  1909.                                         RangeEnd         = ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nNumIndices/3
  1910.                                     )
  1911.                                     else
  1912.                                     (
  1913.                                         RangeStart     = ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nFirstIndexId/3
  1914.                                         RangeEnd         = RangeStart + ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nNumIndices/3
  1915.                                     )
  1916.                                     
  1917.                                     if ::g_Mesh_Report then
  1918.                                     (
  1919.                                         format "%..%\n"     RangeStart     RangeEnd
  1920.                                     )    
  1921.                                     
  1922.                                     --Set the Mat ID for each face
  1923.                                     for face=RangeStart to RangeEnd do
  1924.                                     (
  1925.                                         --We must add +1 to every nMatID, because CryEngine starts counting ids from 0, whereas Max counts them from 1
  1926.                                         local offset         = ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[1].nMatID
  1927.                                         offset                 = 1
  1928.                                         
  1929.                                         local nMatID         = ::g_MESH_SUBSETS_CHUNK_DESC_0800[s].MeshSubsetsArr[i].nMatID                                
  1930.                                         
  1931.                                         setFaceMatID msh face (nMatID+offset)
  1932.                                     )
  1933.                                 )
  1934.                                 
  1935.                                 --Just zoom in so we can see the object better
  1936.                                 max tool zoomextents
  1937.                                 
  1938.                                 if (matchPattern (::g_NODE_CHUNK_DESC_0824[s]._name as string) pattern:"*proxy*") then                            
  1939.                                 (
  1940.                                     Append ::g_BUILT_PROXY msh
  1941.                                 )
  1942.                                 else
  1943.                                 (
  1944.                                     Append     BUILT_MESHES_temp     msh                        
  1945.                                 )                        
  1946.                                 
  1947.                                 sortObjects_to_layers msh:msh
  1948.                             )
  1949.                         )
  1950.                     )
  1951.                     --*/
  1952.                 )
  1953.             )
  1954.         )
  1955.         
  1956.          --//////////////////////////////////////////////////////////////////////////
  1957.          --// Handle Main/Remain meshes used for Destroyable Objects. See StatObjLoad.cpp 1034
  1958.         
  1959.         --If no node is named remain, then all pieces other than main will be destruction pieces!
  1960.          --//////////////////////////////////////////////////////////////////////////        
  1961.         if built_HaveMeshNamedMain then
  1962.         (
  1963.             for i=1 to BUILT_MESHES_temp.count do
  1964.             (
  1965.                 _name = BUILT_MESHES_temp[i].name
  1966.                 
  1967.                 if (stricmp _name "main") == 0 then
  1968.                 (
  1969.                     Append ::g_BUILT_MESHES BUILT_MESHES_temp[i]
  1970.                 )
  1971.                 else
  1972.                 (
  1973.                     Append ::g_DESTROYABLE_MESHES BUILT_MESHES_temp[i]
  1974.                 )
  1975.             )
  1976.         )
  1977.         else
  1978.         (
  1979.             ::g_BUILT_MESHES = BUILT_MESHES_temp
  1980.         )
  1981.     )
  1982.     else
  1983.     (
  1984.         format "***Failed to load mesh!*** \n"
  1985.     )
  1986. )
  1987. --///////////////////////////////// END OF MESH BUILDER /////////////////////////////////
  1988.  
  1989.  
  1990. --Here we just read the bones as described in the 0xCCCC0017 - but that seems to be wrong, we need to read all of the bones in the 0xACDC000 first, then apply what we found there to the mesh 
  1991. --according to the info in the 0xCCCC0017 !
  1992.  
  1993. fn read_CryBoneDescData_Comp \
  1994.                                             bstream: \
  1995.                                             struct2read: \
  1996.                                             FileOffset: \
  1997.                                             _filePos: \
  1998.                                             ChunkSize: =
  1999. (    
  2000.     if FileOffset < _filePos then
  2001.     (
  2002.         local boneChunkData_size     = ChunkSize - (_filePos - FileOffset)        
  2003.         
  2004.         if (mod boneChunkData_size 584) == 0.0 then
  2005.         (
  2006.             local nboneChunks = ChunkSize/584
  2007.             format "============== nboneChunks: %==============\n" nboneChunks
  2008.             
  2009.             for idx=1 to nboneChunks do --we loop the number of subsets
  2010.             (
  2011.                 struct2fill                 = CryBoneDescData_Comp()
  2012.                                         
  2013.                 struct2Fill.chunkID             = IDxACDC                            
  2014.                                         
  2015.                 --//!< Unique id of bone (generated from bone name).
  2016.                 struct2fill.m_nControllerID = readlong bstream #unsigned                                                                    
  2017.                                                                                 
  2018.                 --struct CryBonePhysics_Comp
  2019.                 --resetting the arrays as well
  2020.                 struct2Fill._min                     = #()
  2021.                 struct2Fill._max                     = #()
  2022.                 struct2Fill.spring_angle             = #()
  2023.                 struct2Fill.spring_angle             = #()
  2024.                 struct2Fill.spring_tension         = #()
  2025.                 struct2Fill.damping                 = #()
  2026.                 struct2Fill.framemtx                 = #(#(),#(),#())
  2027.                 --------------------------------------
  2028.                 for p=1 to struct2Fill.m_PhysInfo_length do
  2029.                 (        
  2030.                     struct2Fill.nPhysGeom = (readlong bstream)
  2031.                         
  2032.                     --// additional joint parameters
  2033.                     struct2Fill.flags = (readlong bstream)            
  2034.                         
  2035.                     for n=1 to struct2Fill._min_length do
  2036.                     (
  2037.                         Append struct2Fill._min (readfloat bstream)
  2038.                     )
  2039.                         
  2040.                     for n=1 to struct2Fill._max_length do
  2041.                     (
  2042.                         Append struct2Fill._max (readfloat bstream)
  2043.                     )
  2044.                         
  2045.                     for n=1 to struct2Fill.spring_angle_length do
  2046.                     (
  2047.                         Append struct2Fill.spring_angle (readfloat bstream)
  2048.                     )
  2049.                             
  2050.                     for n=1 to struct2Fill.spring_tension_length do
  2051.                     (
  2052.                         Append struct2Fill.spring_tension (readfloat bstream)
  2053.                     )
  2054.                         
  2055.                     for n=1 to struct2Fill.damping_length do
  2056.                     (
  2057.                         Append struct2Fill.damping (readfloat bstream)
  2058.                     )
  2059.                         
  2060.                     for n=1 to struct2Fill.framemtx_length do
  2061.                     (
  2062.                         for d=1 to struct2Fill.framemtx_length do
  2063.                         (
  2064.                             Append struct2Fill.framemtx[n] (readfloat bstream)
  2065.                         )
  2066.                     )
  2067.                 )
  2068.                 --------------------------------------
  2069.  
  2070.                 struct2Fill.m_fMass = (readfloat bstream)                                                                
  2071.                     
  2072.                 --REPORT+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2073.                 --format "                    Begin reading World2Bone Matrix34 ++++++++ __You are here:      %\n" (ftell bstream)                        
  2074.                 --read matrix34 values
  2075.                 --//intitalpose matrix World2Bone
  2076.                 rot_p3 = point3 0 0 0 --create a point3 for the 4th row
  2077.                 --/////////////////////////////// Matrix World2Bone /////////////////////////////// 
  2078.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2079.                 struct2Fill.m_DefaultW2B[1] = [x,y,z]        
  2080.                     rot_p3.x = (readfloat bstream)        
  2081.                     
  2082.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2083.                 struct2Fill.m_DefaultW2B[2] = [x,y,z]        
  2084.                     rot_p3.y = (readfloat bstream)        
  2085.                     
  2086.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2087.                 struct2Fill.m_DefaultW2B[3] = [x,y,z]            
  2088.                     rot_p3.z = (readfloat bstream)        
  2089.                     
  2090.                 struct2Fill.m_DefaultW2B[4] = rot_p3
  2091.                 --/////////////////////////////End of Matrix World2Bone ////////////////////////////                                                                    
  2092.                     
  2093.                     
  2094.                 --REPORT+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2095.                 --format "                    -----Begin reading Bone2World Matrix34 ++++++++ __You are here:      %\n" (ftell bstream)                        
  2096.                 --read matrix34 values
  2097.                 --//intitalpose matrix Bone2World
  2098.                 rot_p3 = point3 0 0 0 --create a point3 for the 4th row
  2099.                 --/////////////////////////////// Matrix Bone2World /////////////////////////////// 
  2100.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2101.                 struct2Fill.m_DefaultB2W[1] = [x,y,z]        
  2102.                     rot_p3.x = (readfloat bstream)        
  2103.                     
  2104.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2105.                 struct2Fill.m_DefaultB2W[2] = [x,y,z]        
  2106.                     rot_p3.y = (readfloat bstream)        
  2107.                     
  2108.                 x = (readfloat bstream);y = (readfloat bstream);z = (readfloat bstream)
  2109.                 struct2Fill.m_DefaultB2W[3] = [x,y,z]            
  2110.                     rot_p3.z = (readfloat bstream)                
  2111.                     
  2112.                 struct2Fill.m_DefaultB2W[4] = rot_p3
  2113.                 --/////////////////////////////End of Matrix Bone2World ////////////////////////////                                                                    
  2114.                     
  2115.                     
  2116.                 --REPORT+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2117.                 --format "                    Begin reading Bone Names ++++++++ __You are here:      %\n\n" (ftell bstream)                        
  2118.                 local _name                                 = ""
  2119.                 for x=1 to struct2Fill.m_arrBoneName_length do
  2120.                 (
  2121.                     _name                                     += (bit.intAsChar (readbyte bstream #unsigned))
  2122.                 )
  2123.                 struct2Fill.m_arrBoneName             = _name
  2124.                     
  2125.                 struct2Fill.m_nLimbId                     = (readlong bstream) --// set by model state class
  2126.                     
  2127.                 --// this bone parent is this[m_nOffsetParent], 0 if the bone is root. Normally this is <= 0
  2128.                 struct2Fill.m_nOffsetParent             = (readlong bstream)
  2129.                     
  2130.                 --// The whole hierarchy of bones is kept in one big array that belongs to the ModelState
  2131.                 --// Each bone that has children has its own range of bone objects in that array,
  2132.                 --// and this points to the beginning of that range and defines the number of bones.
  2133.                 struct2Fill.m_numChildren                 = (readlong bstream #unsigned)
  2134.                     
  2135.                 --// the beginning of the subarray of children is at this[m_nOffsetChildren]
  2136.                 --// this is 0 if there are no children
  2137.                 struct2Fill.m_nOffsetChildren             = (readlong bstream)
  2138.                     
  2139.                 Append ::g_CryBoneDescData_Comp struct2fill    
  2140.             )
  2141.         )
  2142.         else
  2143.         (
  2144.             format "Count mismatch in 0xACDC0000 BoneChunk Data - Aborting Reading Bones\n!"
  2145.         )    
  2146.     )
  2147. )
  2148.  
  2149. fn read_MESH_SUBSETS_CHUNK_DESC_0800_v2 \
  2150.                                                                     &bstream: \
  2151.                                                                     &fileHeader: \
  2152.                                                                     &struct2read: \
  2153.                                                                     &struct2fill: \
  2154.                                                                     i: \
  2155.                                                                     &IDx0017: \
  2156.                                                                     &inst_ECgfStreamType: =
  2157. (
  2158.     struct2fill.chunkID = IDx0017 -- store the chunkID
  2159.     --See CryHeaders.h 655
  2160.                         
  2161.     struct2fill.nFlags = readlong bstream --It seems that for Ryse, 0x0006 seems to indicate that it has bone indices (but below it says 0x0002, maybe we must test for both
  2162.                                                 
  2163.     --Probably:
  2164. --     --See CryHeaders.h 659
  2165. --     enum EFlags
  2166. --     {
  2167. --         SH_HAS_DECOMPR_MAT       = 0x0001, //!< Obsolete.
  2168. --         BONEINDICES              = 0x0002,
  2169. --         HAS_SUBSET_TEXEL_DENSITY = 0x0004,
  2170. --     };                        
  2171.  
  2172.     struct2fill.nCount = readlong bstream
  2173.                         
  2174.     --Reserved[2] int
  2175.     for x=1 to struct2fill.reserved do
  2176.     (
  2177.         readlong bstream
  2178.     )
  2179.                     
  2180.     for n=1 to struct2fill.nCount do
  2181.     (
  2182.         inst_MeshSubset = MeshSubset()
  2183.  
  2184.         inst_MeshSubset.nFirstIndexId         = (readlong bstream)
  2185.         inst_MeshSubset.nNumIndices         = (readlong bstream)
  2186.         inst_MeshSubset.nFirstVertId         = (readlong bstream)
  2187.         inst_MeshSubset.nNumVerts             = (readlong bstream)
  2188.                             
  2189.         inst_MeshSubset.nMatID                 = (readlong bstream)
  2190.                             
  2191.         inst_MeshSubset.fRadius                 = (readfloat bstream)                            
  2192.  
  2193.         x    =(readfloat bstream)
  2194.         y    =(readfloat bstream)
  2195.         z    =(readfloat bstream)
  2196.                                 
  2197.         inst_MeshSubset.vCenter = [x,y,z]                            
  2198.                             
  2199.         Append struct2fill.MeshSubsetsArr inst_MeshSubset
  2200.     )
  2201.                         
  2202.     ------------------------ If has bones ------------------------
  2203.     --It seems that for Ryse, 0x0006 seems to indicate that it has bone indices (but below it says 0x0002, maybe we must test for both
  2204.     --See CryHeaders.h 666
  2205.     if struct2fill.nFlags == 0x00000002 OR struct2fill.nFlags == 0x00000006 then
  2206.     (
  2207.         for n=1 to struct2fill.nCount do --we loop n number of times (that is the number of subsets as given by nCount - a boneset for each submesh)
  2208.         (
  2209.             --Create struct
  2210.             local inst_MeshBoneIDs = MeshBoneIDs()
  2211.                                 
  2212.             inst_MeshBoneIDs.numBoneIDs = readlong bstream #unsigned
  2213.             --Each subset bone description chunk is 260 bytes long (4 + 256) former is uint32 numBonesIds, and the rest is uint16 bone IDs
  2214.             for b=1 to inst_MeshBoneIDs.arrBoneIDs_length do
  2215.             (
  2216.                 id = readshort bstream #unsigned
  2217.                 Append inst_MeshBoneIDs.arrBoneIDs id
  2218.             )
  2219.                                 
  2220. --             struct2fill.MeshBoneIDs = inst_MeshBoneIDs                                
  2221.             Append     struct2fill.MeshBoneSubsetsArr inst_MeshBoneIDs
  2222.         )
  2223.     )                        
  2224.     ------------------- End of reading bones ids --------------------    
  2225.     ------------------------ If has MeshSubsetTexelDensity ------------------------
  2226.     else if struct2fill.nFlags == 0x00000004 then
  2227.     (
  2228.         inst_MeshSubsetTexelDensity                     = MeshSubsetTexelDensity()
  2229.         inst_MeshSubsetTexelDensity.TexelDensity     = readfloat bstream
  2230.         struct2fill.MeshSubsetTexelDensity                 = inst_MeshSubsetTexelDensity
  2231.     )
  2232.     ------------------- End of reading MeshSubsetTexelDensity --------------------
  2233. )
  2234.  
  2235. fn read_CHUNK_0017 \
  2236.                                 &bstream: \
  2237.                                 &fileHeader: \
  2238.                                 &struct2read: =
  2239. (
  2240.     --for i=1 to struct2read.ChunkType[1].count do
  2241.     for i=1 to g_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  2242.     (
  2243.         if struct2read.ChunkType[1][i] == 0x0017 AND \
  2244.             struct2read.ChunkType[2][i] == 0xCCCC then
  2245.         (
  2246.             inst_ECgfStreamType = ECgfStreamType()---------
  2247.             struct2fill = MESH_SUBSETS_CHUNK_DESC_0800()
  2248.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  2249.             
  2250.             if struct2read.ChunkVersion[1][i] == 0x0802 then --if Ox0800
  2251.             (
  2252.                 --not implemented yet
  2253.             )
  2254.             else if struct2read.ChunkVersion[1][i] == 0x0800 OR \ -- see CryHeaders.h 557 why 0x0800 or 0x0801
  2255.                         struct2read.ChunkVersion[1][i] == 0x0801 then --if 0x0800 or 0x0801
  2256.             (            
  2257.                 A             = readshort bstream #unsigned --should be 0x0017
  2258.                 B             = readshort bstream #unsigned --should be 0xCCCC
  2259.                 C             = readshort bstream --should be 0x0800 or 0x0801            
  2260.                     D         = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  2261.                 F             = readlong bstream #unsigned
  2262.                 IDx0017    = 0
  2263.                 
  2264.                 if fileHeader.version == 0x0745 then
  2265.                 (
  2266.                     IDx0017 = readlong bstream --chunk ID --//new in version 0x0745
  2267.                     
  2268.                     --confirm we are on the right chunk
  2269.                     if  A             == 0x0017 AND \
  2270.                         B             == 0xCCCC AND \            
  2271.                         (C == 0x0800 OR C == 0x0801) AND \
  2272.                         IDx0017 == struct2read.ChunkID[1][i] AND \
  2273.                         F             == struct2read.FileOffset[1][i] then
  2274.                     (                        
  2275.                         if ::rollout_Report.chk_Mesh_Report.state then
  2276.                         (
  2277.                             format "######### ftell bstream : % ######## \n" (ftell bstream)
  2278.                             format "IDx0017 \n" IDx0017
  2279.                             format "inst_ECgfStreamType: %\n" inst_ECgfStreamType
  2280.                         )
  2281.                         
  2282.                         read_MESH_SUBSETS_CHUNK_DESC_0800_v2 \
  2283.                                                                                         bstream:                    &bstream \
  2284.                                                                                         fileHeader:                    &fileHeader \
  2285.                                                                                         struct2read:                &struct2read \
  2286.                                                                                         struct2fill:                    &struct2fill \
  2287.                                                                                         i:                                i \
  2288.                                                                                         IDx0017:                    &IDx0017 \
  2289.                                                                                         inst_ECgfStreamType:    &inst_ECgfStreamType                        
  2290.                     )                    
  2291.  
  2292.                     read_STREAM_DATA_CHUNK_DESC_0800 \                                                                        
  2293.                                                                             bstream:                    &bstream \
  2294.                                                                             fileHeader:                    &fileHeader \
  2295.                                                                             struct2read:                &struct2read \                                
  2296.                                                                             info_MeshSubset:        &struct2fill \
  2297.                                                                             IDX:                            i \
  2298.                                                                             IDx0017:                    &IDx0017 \
  2299.                                                                             inst_ECgfStreamType:    &inst_ECgfStreamType                    
  2300.  
  2301.                 )
  2302.                 else if fileHeader.version == 0x0744 then
  2303.                 (
  2304.                     --confirm we are on the right chunk
  2305.                     if  A == 0x0017 AND \
  2306.                         B == 0xCCCC AND \            
  2307.                         C == 0x0800 AND \                        
  2308.                         F == struct2read.FileOffset[1][i] then
  2309.                     (
  2310.                         -- not implemented yet                        
  2311.                         print "we are in here"
  2312.                     )
  2313.                 )
  2314.             )
  2315.             if struct2read.ChunkVersion[1][i] == 0x0745 then --if Ox0745
  2316.             (
  2317.                 --not implemented yet
  2318.                 --To implement, see CryHeaders.h 555 (use the struct MESH_CHUNK_DESC_0745)
  2319.             )
  2320.             
  2321.             Append             ::g_ECgfStreamType                                     inst_ECgfStreamType
  2322.             Append             ::g_MESH_SUBSETS_CHUNK_DESC_0800             struct2fill
  2323.             
  2324.             --Just for info, can be taken out
  2325.             setINISetting ::g_iniFile "fileType" ("fileType2_loaded") "true" --we set this to true so that we can go back and read bones in the first file
  2326.         )
  2327.         else if struct2read.ChunkType[1][i] == 0x0000 AND \ --ChunkType_Mesh = 0x1000,   //!< Was 0xCCCC0000 in chunk files with versions <= 0x745.
  2328.         struct2read.ChunkType[2][i] == 0xCCCC then
  2329.         (
  2330.             struct2fill = MESH_CHUNK_DESC_0801()
  2331.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  2332.             
  2333.             if struct2read.ChunkVersion[1][i] == 0x0800 OR \
  2334.                 struct2read.ChunkVersion[1][i] == 0x0801 then --if 0x0823 or 0x0824
  2335.             (                
  2336.                 A                 = readshort     bstream     #unsigned --should be 0x0000
  2337.                 B                 = readshort     bstream     #unsigned --should be 0xCCCC
  2338.                 C                 = readshort     bstream     --should be 0x0800 or 0x0801            
  2339.                     D             = readshort     bstream     --usually 0x0000 unknown --we do not check for this as we do not know what it is
  2340.                 F                 = readlong         bstream     #unsigned
  2341.                 IDx0000     = 0                
  2342.                 
  2343.                 if fileHeader.version == 0x0745 then
  2344.                 (
  2345.                     IDx0000 = readlong bstream --chunk ID --//new in version 0x0745
  2346.                             
  2347.                     --confirm we are on the right chunk
  2348.                     if  A             == 0x0000 AND \
  2349.                         B             == 0xCCCC AND \            
  2350.                         (C         == 0x0800 OR C == 0x0801) AND \
  2351.                         IDx0000 == struct2read.ChunkID[1][i] AND \
  2352.                         F             == struct2read.FileOffset[1][i] then
  2353.                     (
  2354.                         read_MESH_CHUNK_DESC_0801 \
  2355.                                                                     bstream:                &bstream \
  2356.                                                                     struct2read:            &struct2read \
  2357.                                                                     info_MeshSubset:    &info_MeshSubset \
  2358.                                                                     Struct2fill:                &Struct2fill
  2359.                     )                    
  2360.                 )                    
  2361.                 else if fileHeader.version == 0x0744 then
  2362.                 (
  2363.                     --confirm we are on the right chunk
  2364.                     if  A == 0x0000 AND \
  2365.                         B == 0xCCCC AND \            
  2366.                         (C         == 0x0800 OR C == 0x0801) AND \                        
  2367.                         F == struct2read.FileOffset[1][i] then
  2368.                     (
  2369.                         -- not implemented yet                        
  2370.                         print "we are in here"
  2371.                     )
  2372.                 )
  2373.                 
  2374.                 Append         ::g_MESH_CHUNK_DESC_0801         struct2fill                
  2375.             )
  2376.         )
  2377.         else if struct2read.ChunkType[1][i] == 0x000B AND \ --node info 0xCCCC000B
  2378.                     struct2read.ChunkType[2][i] == 0xCCCC then
  2379.         (                        
  2380.             struct2fill = NODE_CHUNK_DESC_0824()            
  2381.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  2382.             
  2383.             if struct2read.ChunkVersion[1][i] == 0x0823 OR \
  2384.                 struct2read.ChunkVersion[1][i] == 0x0824 then --if 0x0823 or 0x0824
  2385.             (            
  2386.                 A                 = readshort bstream #unsigned --should be 0x000B
  2387.                 B                 = readshort bstream #unsigned --should be 0xCCCC
  2388.                 C                 = readshort bstream --should be 0x0823 or 0x0824            
  2389.                     D             = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  2390.                 F                 = readlong bstream #unsigned
  2391.                 IDx000B     = 0
  2392.                         
  2393.                 if fileHeader.version == 0x0745 then
  2394.                 (
  2395.                     IDx000B = readlong bstream --chunk ID --//new in version 0x0745
  2396.                             
  2397.                     --confirm we are on the right chunk
  2398.                     if  A             == 0x000B AND \
  2399.                         B             == 0xCCCC AND \            
  2400.                         (C         == 0x0823 OR C == 0x0824) AND \
  2401.                         IDx000B == struct2read.ChunkID[1][i] AND \
  2402.                         F             == struct2read.FileOffset[1][i] then
  2403.                     (    
  2404.                         read_NODE_CHUNK_DESC_0824 \
  2405.                                                                     bstream:        &bstream \
  2406.                                                                     struct2read:    &struct2read \                                                                        
  2407.                                                                     Struct2fill:        &Struct2fill
  2408.                     )
  2409.                 )                    
  2410.                 else if fileHeader.version == 0x0744 then
  2411.                 (
  2412.                     --confirm we are on the right chunk
  2413.                     if  A == 0x000B AND \
  2414.                         B == 0xCCCC AND \            
  2415.                         (C         == 0x0823 OR C == 0x0824) AND \                        
  2416.                         F == struct2read.FileOffset[1][i] then
  2417.                     (
  2418.                         -- not implemented yet                        
  2419.                         print "not implemented - fileHeader.version == 0x0744"
  2420.                     )
  2421.                 )                
  2422.             )            
  2423.             Append ::g_NODE_CHUNK_DESC_0824 struct2fill
  2424.         )        
  2425.         else if (struct2read.ChunkType[1][i] == 0x0000 OR struct2read.ChunkType[1][i] == 0x2000 ) AND \ --0x0000 --//!< Was 0xACDC0000 in chunk files with versions <= 0x745.
  2426.                     struct2read.ChunkType[2][i] == 0xACDC then
  2427.         (
  2428.             setINISetting     ::g_iniFile     "boneinfo" "has_bones"     "true"            
  2429.             
  2430.             --For now we are just developing this for Ryse, but earlier versions of CryEngine might and can have all the chunks
  2431.             --in one single cgf file, thus we need to read these here as well, but for now, let's turn them OFF if the game is "Ryse"
  2432. --             if (stricmp ::g_CryGame_dropDown_selection "Ryse") != 0 then  
  2433. --             (
  2434.                 struct2fill                 = CryBoneDescData_Comp()
  2435.             
  2436.                 fseek bstream struct2read.FileOffset[1][i] #seek_set
  2437.  
  2438.                 if struct2read.ChunkVersion[1][i] == 0x0800 then \ --0x0800                
  2439.                 (
  2440.                     A                 = readshort bstream #unsigned     --should be 0x0000 or 0x2000
  2441.                     B                 = readshort bstream #unsigned     --should be 0xACDC
  2442.                     C                 = readshort bstream                 --should be 0x0800
  2443.                         D             = readshort bstream                 --usually 0x0000 unknown --we do not check for this as we do not know what it is
  2444.                     F                 = readlong bstream #unsigned
  2445.                     IDxACDC     = 0
  2446.                                                             
  2447.                     if ::g_Read_Comp_cryBones_Report then
  2448.                     (
  2449.                         format "A: %\n" A
  2450.                         format "B: %\n" B                                            
  2451.                         format "C: %\n" C
  2452.                         format "F: %\n" F
  2453.                         format "IDxACDC: %\n" IDxACDC
  2454.                     )
  2455.                                                             
  2456.                     if fileHeader.version == 0x0745 then
  2457.                     (
  2458.                         IDxACDC = readlong bstream --chunk ID --//new in version 0x0745
  2459.                                                                 
  2460.                         --confirm we are on the right chunk
  2461.                         if  (A == 0x0000 OR A == 0x2000) AND \
  2462.                             B             == 0xACDC AND \            
  2463.                             C             == 0x0800 AND \
  2464.                             IDxACDC == struct2read.ChunkID[1][i] AND \
  2465.                             F             == struct2read.FileOffset[1][i] then
  2466.                         (    
  2467.                             fseek bstream struct2Fill.reserved #seek_cur
  2468.                                                                     
  2469.                             if ::g_Read_Comp_cryBones_Report then
  2470.                             (
  2471.                                 format "We will now read the Compiled Crybones 0xACDC at fileposition: %\n" (ftell bstream)
  2472.                             )
  2473.                             
  2474.                             local ChunkSize         = struct2read.ChunkPlusDescr_size[i]
  2475.                             local _filePos            = (ftell bstream)
  2476.                             
  2477.                             read_CryBoneDescData_Comp \
  2478.                                                                     bstream:bstream \
  2479.                                                                     struct2read:struct2read \                                                                                                                                    
  2480.                                                                     FileOffset:F \    
  2481.                                                                     _filePos: _filePos \
  2482.                                                                     ChunkSize:ChunkSize
  2483.                                                                     
  2484.                         )
  2485.                     )                    
  2486.                 else if fileHeader.version == 0x0744 then
  2487.                 (
  2488.                     --confirm we are on the right chunk
  2489.                     if  A == 0x0000 AND \
  2490.                         B == 0xACDC AND \            
  2491.                         C == 0x0000 AND \                        
  2492.                         F == struct2read.FileOffset[1][i] then
  2493.                         (
  2494.                             -- not implemented yet                        
  2495.                             print "we are in here, 0x0744 - code not implemented yet"
  2496.                         )
  2497.                     )                
  2498.                 )
  2499. --             )
  2500.         )
  2501.         --*/
  2502.         else if struct2read.ChunkType[1][i] == 0x0005 AND \
  2503.                     struct2read.ChunkType[2][i] == 0xAAFC then        
  2504.         (
  2505.             struct2fill = FOLIAGE_INFO_CHUNK_DESC()
  2506.             fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  2507.             
  2508.             if struct2read.ChunkVersion[1][i] == 0x0001 then --if Ox0001
  2509.             (
  2510.                 A             = readshort bstream #unsigned --should be 0x0005
  2511.                 B             = readshort bstream #unsigned --should be 0xAAFC
  2512.                 C             = readshort bstream --should be 0x0001                
  2513.                     D         = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  2514.                 F             = readlong bstream #unsigned
  2515.                 IDx0005    = 0
  2516.                 
  2517.                 if fileHeader.version == 0x0745 then
  2518.                 (
  2519.                     IDx0005 = readlong bstream --chunk ID --//new in version 0x0745
  2520.                     
  2521.                     --confirm we are on the right chunk
  2522.                     if  A             == 0x0005 AND \
  2523.                         B             == 0xAAFC AND \            
  2524.                         C             == 0x0001 AND \
  2525.                         IDx0005 == struct2read.ChunkID[1][i] AND \
  2526.                         F             == struct2read.FileOffset[1][i] then
  2527.                     (                        
  2528.                         struct2fill.nSpines         = readlong bstream
  2529.                         struct2fill.nSpineVtx     = readlong bstream
  2530.                         struct2fill.nSkinnedVtx     = readlong bstream
  2531.                         struct2fill.nBoneIds         = readlong bstream
  2532.                     )                
  2533.                 )
  2534.                 else if fileHeader.version == 0x0744 then
  2535.                 (
  2536.                     --confirm we are on the right chunk
  2537.                     if  A == 0x0005 AND \
  2538.                         B == 0xAAFC AND \            
  2539.                         C == 0x0001 AND \                        
  2540.                         F == struct2read.FileOffset[1][i] then
  2541.                     (
  2542.                         -- not implemented yet                        
  2543.                         print "we are in here"
  2544.                     )
  2545.                 )
  2546.             )            
  2547.             Append         ::g_FOLIAGE_INFO_CHUNK_DESC         struct2fill
  2548.         )
  2549.     )    
  2550.     
  2551.     --/*
  2552.     try
  2553.     (
  2554.         --//////////////////// Build the Meshes ////////////////////
  2555.         BUILD_MESH \ 
  2556.                             info_MeshSubset:struct2read \
  2557.                             info_ECgfStreamType:(::inst_ECgfStreamType)
  2558.         --/////////////////////////////////////////////////////////
  2559.     )
  2560.     catch
  2561.     (
  2562.         format "\n\n\n\n*** *** *** *** *** *** *** BUILD_MESH ERROR *** *** *** *** *** *** *** ***\n"
  2563.         format "%" (getCurrentException())
  2564.         format "\n*** *** *** *** *** *** END OF BUILD_MESH ERROR *** *** *** *** *** *** *** ***\n\n\n\n"        
  2565.     )
  2566.     --*/
  2567. )