Advertisement
Guest User

UnjReader

a guest
Dec 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UnjReader {
  2.  
  3.     constructor() {
  4.         this.materials = []
  5.         this.vertex_groups = [];
  6.         this.bones = [];
  7.         this.direct_calls = [];
  8.     }
  9.  
  10.     parse(arraybuffer) {
  11.         if (arraybuffer.byteLength < 16) {
  12.             return false;
  13.         }
  14.  
  15.         this.view = new DataView(arraybuffer);
  16.         const MAGIC_NUOB = 0x424f554e;
  17.         const magic = this.view.getUint32(0x00, true);
  18.         const length = this.view.getUint32(0x04, true);
  19.         const header_ofs = this.view.getUint32(0x08, true);
  20.         const three = this.view.getUint32(0x0c, true);
  21.  
  22.         if (magic !== MAGIC_NUOB) {
  23.             return false;
  24.         }
  25.  
  26.         if (length !== arraybuffer.byteLength - 8) {
  27.             return false;
  28.         }
  29.  
  30.         if (header_ofs > arraybuffer.byteLength) {
  31.             return false;
  32.         }
  33.  
  34.         this.header_ofs = header_ofs;
  35.  
  36.         if (three !== 3) {
  37.             console.warn("Omg, is this not a three?")
  38.         }
  39.  
  40.         this.readheader();
  41.         this.readMaterials();
  42.         this.readVertexGroups();
  43.         this.readBones();
  44.         this.readDrawCalls();
  45.  
  46.         return true;
  47.     }
  48.  
  49.     readHeader() {
  50.         const ofs = this.header_ofs;
  51.  
  52.         const unj_header_t = {
  53.             center: {
  54.                 x: this.view.getFloat32(ofs + 0x00, true),
  55.                 y: this.view.getFloat32(ofs + 0x04, true),
  56.                 z: this.view.getFloat32(ofs + 0x08, true),
  57.             },
  58.             radius: this.view.getFloat32(ofs + 0x0c, true),
  59.             material_count: this.view.getUint32(ofs + 0x10, true),
  60.             material_ofs: this.view.getUint32(ofs + 0x14, true),
  61.             vertex_group_count: this.view.getUint32(ofs + 0x18, true),
  62.             vertex_group_ofs: this.view.getUint32(ofs + 0x1c, true),
  63.             index_group_count: this.view.getUint32(ofs + 0x20, true),
  64.             index_group_ofs: this.view.getUint32(ofs + 0x24, true),
  65.             bone_count: this.view.getUint32(ofs + 0x28, true),
  66.             bone_tree_depth: this.view.getUint32(ofs + 0x2c, true),
  67.             bone_ofs: this.view.getUint32(ofs + 0x30, true),
  68.             draw_count: this.view.getUint32(ofs + 0x34, true),
  69.             draw_ofs: this.view.getUint32(ofs + 0x38, true)
  70.         };
  71.  
  72.         this.header = unj_header_t;
  73.     }
  74.  
  75.     readMaterials() {
  76.  
  77.         const mat_count = this.header.material_count;
  78.  
  79.         // First we read the number of textures in each material and then get the offset
  80.         // to each of the respective material definitions
  81.  
  82.         for (let i = 0; i < mat_count; i++) {
  83.             const ofs = this.header.material_ofs;;
  84.             const unj_matlist_size = 8;
  85.  
  86.             const unj_matlist_t = {
  87.                 diffuse_texture_count: this.view.getUint8(mat_ofs + i * unj_mat_size + 0x00),
  88.                 effect_texture_count: this.view.getUint8(mat_ofs + i * unj_mat_size + 0x01),
  89.                 material_ofs: this.view.getUint32(mat_ofs + i * unj_matlist_size + 0x04)
  90.             }
  91.  
  92.             this.materials[i] = {
  93.                 color: {},
  94.                 offset: unj_matlist_t.material_ofs,
  95.                 diffuse_textures: new Array(unj_matlist_t.diffuse_texture_count),
  96.                 effect_textures: new Array(unj_matlist_t.effect_texture_count)
  97.             }
  98.  
  99.         }
  100.  
  101.         // Then we 'seek' to each one of the respective material definitions, read the
  102.         // color values for the material, and then the texture preferences
  103.  
  104.         this.materials.forEach(mat => {
  105.             let ofs = mat.offset;
  106.  
  107.             // We skip the first 8 bytes, since we don't know what it does
  108.             ofs += 8;
  109.  
  110.             // Then we read the mapping type of the respective textures
  111.             for (let i = 0; i < mat.diffuse_textures.length; i++) {
  112.                 const byte = this.view.getUint8(ofs + 1);
  113.                 ofs += 4;
  114.  
  115.                 mat.diffuse_textures[i] = {};
  116.  
  117.                 switch (byte) {
  118.                     case 1:
  119.                         mat.diffuse_textures[i].mappingType = "env";
  120.                         break;
  121.                     default:
  122.                         mat.diffuse_textures[i].mappingType = "uv";
  123.                         break;
  124.                 }
  125.             }
  126.  
  127.             // Then we read all of the color values for the material
  128.  
  129.             for (let i = 0; i < 12; i++) {
  130.  
  131.                 const a = this.view.getUint8(ofs + 0);
  132.                 const b = this.view.getUint8(ofs + 1);
  133.                 const c = this.view.getUint8(ofs + 2);
  134.                 const d = this.view.getUint8(ofs + 3);
  135.                 ofs += 4;
  136.  
  137.                 switch (d) {
  138.                     case 0x54:
  139.                         mat.color.emissive = {
  140.                             r: a / 255,
  141.                             g: b / 255,
  142.                             b: c / 255
  143.                         };
  144.                         break;
  145.                     case 0x55:
  146.                         mat.color.ambient = {
  147.                             r: a / 255,
  148.                             g: b / 255,
  149.                             b: c / 255
  150.                         };
  151.                         break;
  152.                     case 0x56:
  153.                         mat.color.diffuse = {
  154.                             r: a / 255,
  155.                             g: b / 255,
  156.                             b: c / 255
  157.                         };
  158.                         break;
  159.                     case 0x57:
  160.                         mat.color.specular = {
  161.                             r: a / 255,
  162.                             g: b / 255,
  163.                             b: c / 255
  164.                         };
  165.                         break;
  166.                     case 0x58:
  167.                         const alpha = a / 255;
  168.                         mat.color.emissive = mat.color.emissive || {};
  169.                         mat.color.ambient = mat.color.ambient || {};
  170.                         mat.color.diffuse = mat.color.diffuse || {};
  171.                         mat.color.specular = mat.color.specular || {};
  172.  
  173.                         mat.color.emissive.a = alpha;
  174.                         mat.color.ambient.a = alpha;
  175.                         mat.color.diffuse.a = alpha;
  176.                         mat.color.specular.a = alpha;
  177.                         break;
  178.                     case 0x5b:
  179.                         // convert bytes to float
  180.                         mat.color.specular_coefficient = [a, b, c, d];
  181.                         break;
  182.                 }
  183.  
  184.             }
  185.  
  186.             // Then we read all of the texture properties
  187.             for (let i = 0; i < mat.diffuse_textures.length; i++) {
  188.  
  189.                 do {
  190.  
  191.                     const a = this.view.getUint8(ofs + 0);
  192.                     const b = this.view.getUint8(ofs + 1);
  193.                     const c = this.view.getUint8(ofs + 2);
  194.                     const d = this.view.getUint8(ofs + 3);
  195.                     ofs += 4;
  196.  
  197.                     switch (d) {
  198.                         case 0x21:
  199.                             mat.diffuse_textures[i].disableLighting = (a === 1);
  200.                             break;
  201.                         case 0x22:
  202.                             mat.diffuse_textures[i].alphaTestEnabled = (a === 1);
  203.                             break;
  204.                         case 0x23:
  205.                             mat.diffuse_textures[i].zTestEnabled = (a === 1);
  206.                             break;
  207.                         case 0x24:
  208.                             mat.diffuse_textures[i].stencilTestEnabled = (a === 1);
  209.                             break;
  210.                         case 0x27:
  211.                             mat.diffuse_textures[i].colorTestEnabled = (a === 1);
  212.                             break;
  213.                         case 0x28:
  214.                             mat.diffuse_textures[i].logicOpEnabled = (a === 1);
  215.                             break;
  216.                         case 0x48:
  217.                             // convert bytes to float
  218.                             mat.diffuse_textures[i].scaleU = [a, b, c, d];
  219.                             break;
  220.                         case 0x49:
  221.                             // convert bytes to float
  222.                             mat.diffuse_textures[i].scaleV = [a, b, c, d]
  223.                             break;
  224.                         case 0x4A:
  225.                             mat.diffuse_textures[i].offsetU = [a, b, c, d];
  226.                             break;
  227.                         case 0x4B:
  228.                             mat.diffuse_textures[i].offsetV = [a, b, c, d];
  229.                             break;
  230.                         case 0x5E:
  231.                             mat.diffuse_textures[i].diffuseEnabled = a < 2;
  232.                             break;
  233.                         case 0xC7:
  234.                             mat.diffuse_textures[i].clampU = (a & 1) !== 0;
  235.                             mat.diffuse_textures[i].clampV = (b & 1) !== 0;
  236.                             break;
  237.                         case 0xC9:
  238.                             mat.diffuse_textures[i].textureFunction = (a & 7);
  239.                             mat.diffuse_textures[i].textureFunctionUsesAlpha = (b === 1);
  240.                             break;
  241.                         case 0xDB:
  242.                             mat.diffuse_textures[i].alphaFunction = a;
  243.                             mat.diffuse_textures[i].alphaRef = b;
  244.                             break;
  245.                         case 0xDE:
  246.                             mat.diffuse_textures[i].zTestFunction = a;
  247.                             break;
  248.                         case 0xDF:
  249.                             mat.diffuse_textures[i].blendMode = b;
  250.                             mat.diffuse_textures[i].blendFactorA = a;
  251.                             mat.diffuse_textures[i].blendFactorB = a;
  252.                             break;
  253.                         case 0xE0:
  254.                             mat.diffuse_textures[i].blendFixedA = (c << 16) | (b << 8) | a;
  255.                             break;
  256.                         case 0xE1:
  257.                             mat.diffuse_textures[i].blendFixedB = (c << 16) | (b << 8) | a;
  258.                             break;
  259.                         case 0xE6:
  260.                             mat.diffuse_textures[i].logicOp = a;
  261.                             break;
  262.                         case 0xE7:
  263.                             mat.diffuse_textures[i].zWriteDisabled = a ? true : false;
  264.                             break;
  265.                         case 0xE8:
  266.                             mat.diffuse_textures[i].maskRGB = (c << 16) | (b << 8) | a;
  267.                             break;
  268.                         case 0xE9:
  269.                             mat.diffuse_textures[i].maskAlpha = (c << 16) | (b << 8) | a;
  270.                             break;
  271.                     }
  272.  
  273.                 } while (d !== 0x0b);
  274.  
  275.             }
  276.  
  277.             // Then we read the texture id
  278.             for (let i = 0; i < mat.diffuse_textures.length; i++) {
  279.  
  280.                 mat.diffuse_textures[i].texture_id = this.view.getUint32(ofs, true);
  281.                 ofs += 4;
  282.  
  283.             }
  284.  
  285.         });
  286.  
  287.     }
  288.  
  289.     readVertexGroups() {
  290.  
  291.         // First we 'seek' to the vertex group definitions and read the
  292.         // uv count and the offset to the vertex list definition
  293.  
  294.         let ofs = this.header.vertex_group_ofs;
  295.  
  296.         for (let i = 0; i < this.header.vertex_group_count; i++) {
  297.             const unj_vertex_group_t = {
  298.                 uv_count: this.view.getUint32(ofs + 0, true),
  299.                 group_ofs: this.view.getUint32(ofs + 4, true)
  300.             }
  301.             this.vertex_groups[i] = unj_vertex_group_t;
  302.             ofs += 8;
  303.         }
  304.  
  305.         // Then we seek to each one of the vertex list definitions and
  306.         // read the number of bone influences, which bones, how many vertices
  307.         // and the format of the stored vertices in the vertex list
  308.  
  309.         for (let i = 0; i < this.header.vertex_group_count; i++) {
  310.  
  311.             ofs = this.vertex_groups[i].group_ofs;
  312.  
  313.             const unj_vertex_list_t = {
  314.                 unkown_1: this.view.getUint32(ofs + 0x00, true),
  315.                 vertex_format: this.view.getUint32(ofs + 0x04, true),
  316.                 unknown_2: this.view.getUint32(ofs + 0x08, true),
  317.                 unknown_3: this.view.getUint8(ofs + 0x09),
  318.                 vertex_length: this.view.getUint8(ofs + 0x0a),
  319.                 nop: this.view.getUint12(ofs + 0x0e, true),
  320.                 vertex_count_ofs: this.view.getUint32(ofs + 0x10, true),
  321.                 vertex_list_ofs: this.view.getUint32(ofs + 0x14, true),
  322.                 bone_binding_ofs: this.view.getUint32(ofs + 0x18, true),
  323.                 bone_binding_count: this.view.getUint32(ofs + 0x1c, true),
  324.                 total_vertex_count: this.view.getUint32(ofs + 0x20, true),
  325.                 unknown_4: this.view.getUint32(ofs + 0x24, true),
  326.                 unknown_5: this.view.getUint32(ofs + 0x28, true),
  327.                 vertex_scale: this.view.getFloat32(ofs + 0x2c, true)
  328.             };
  329.  
  330.             // Read the number of vertices in the vertex list
  331.  
  332.             ofs = unj_vertex_list_t.vertex_count_ofs;
  333.             unj_vertex_list_t.vertex_count = this.view.getUint32(ofs, true);
  334.  
  335.             // Read each of the bone influences for the group
  336.  
  337.             unj_vertex_list_t.bones = new Array();
  338.             ofs = unj_vertex_list_t.bone_binding_ofs;
  339.             for (let k = 0; k < unj_vertex_list_t.bone_binding_count; k++) {
  340.                 unj_vertex_list_t.bones[k] = this.view.getUint32(ofs, true);
  341.                 ofs += 4;
  342.             }
  343.  
  344.             // Then we save all of the values from the struct into instance memory
  345.  
  346.             for (let key in unj_vertex_list_t) {
  347.                 this.vertex_groups[i][key] = unj_vertex_list_t[key];
  348.             }
  349.         }
  350.  
  351.         // Then we seek to the vertex list and read the values for the vertices
  352.  
  353.         for (let i = 0; i < this.header.vertex_group_count; i++) {
  354.  
  355.             const UINT8 = 1;
  356.             const INT8 = 1;
  357.             const INT16 = 2;
  358.             const FLOAT = 3;
  359.  
  360.             const bones = this.vertex_groups[i].bones;
  361.             const vertices = new Array(this.vertex_groups[i].vertex_count);
  362.             const scale = this.vertex_groups[i].scale;
  363.             const format = this.vertex_groups[i].vertex_format;
  364.             const stride = this.vertex_groups[i].vertex_length;
  365.             const uv_count = this.vertex_groups[i].uv_count;
  366.  
  367.             const uvFormat = (format & 0x3);
  368.             const colorFormat = (format >> 2) & 0x7;
  369.             const normalFormat = (format >> 5) & 0x3;
  370.             const positionFormat = (format >> 7) & 0x3;
  371.             const weightFormat = (format >> 9) & 0x3;
  372.  
  373.             // Then we seek to the vertex list and read the values
  374.  
  375.             let ofs = this.vertex_groups[i].vertex_list_ofs;
  376.             for (let k = 0; k < vertices.length; k++) {
  377.                 const vertex = {};
  378.                 const start = ofs;
  379.  
  380.                 // Read bone weight
  381.  
  382.                 vertex.weight = [];
  383.                 switch (weightFormat) {
  384.                     case UINT8:
  385.                         for (let j = 0; j < bones.length; j++) {
  386.                             vertex.weight[j] = {
  387.                                 bone_id: bones[j],
  388.                                 weight: this.view.getUint8(ofs) / 0x7f
  389.                             }
  390.                             ofs++;
  391.                         }
  392.                         break;
  393.                     case INT16:
  394.                         for (let j = 0; j < bones.length; j++) {
  395.                             vertex.weight[j] = {
  396.                                 bone_id: bones[j],
  397.                                 weight: this.view.getInt16(ofs, true) / 0x7fff
  398.                             }
  399.                             ofs += 2;
  400.                         }
  401.                         break;
  402.                     case FLOAT:
  403.                         for (let j = 0; j < bones.length; j++) {
  404.                             vertex.weight[j] = {
  405.                                 bone_id: bones[j],
  406.                                 weight: this.view.getFloat32(ofs, true);
  407.                             }
  408.                             ofs += 4;
  409.                         }
  410.                         break;
  411.                 }
  412.  
  413.                 // Read uv values
  414.  
  415.                 vertex.uvs = [];
  416.                 switch (uvFormat) {
  417.                     case INT8:
  418.                         for (let j = 0; j < uv_count; j++) {
  419.                             vertex.uvs[j] = {
  420.                                 u: this.view.getInt8(ofs + 0) / 0x7f,
  421.                                 v: this.view.getInt8(ofs + 1) / 0x7f
  422.                             }
  423.                             ofs += 2;
  424.                         }
  425.                         break;
  426.                     case INT16:
  427.                         if (ofs % 2) {
  428.                             ofs += 2 - (ofs % 2);
  429.                         }
  430.  
  431.                         for (let j = 0; j < uv_count; j++) {
  432.                             vertex.uvs[j] = {
  433.                                 u: this.view.getInt16(ofs + 0) / 0x7fff,
  434.                                 v: this.view.getInt16(ofs + 2) / 0x7fff
  435.                             }
  436.                             ofs += 4;
  437.                         }
  438.                         break;
  439.                     case FLOAT:
  440.                         if (ofs % 4) {
  441.                             ofs += 4 - (ofs % 4);
  442.                         }
  443.  
  444.                         for (let j = 0; j < bones.length; j++) {
  445.                             vertex.uvs[j] = {
  446.                                 u: this.view.getFloat32(ofs + 0),
  447.                                 v: this.view.getFloat32(ofs + 4)
  448.                             }
  449.                             ofs += 8;
  450.                         }
  451.                         break;
  452.                 }
  453.  
  454.                 // Read colors (we assume ARGB4444)
  455.  
  456.                 if (colorFormat) {
  457.                     if (ofs % 2) {
  458.                         ofs += 2 - (ofs % 2);
  459.                     }
  460.                     let byte1 = this.view.getUint8(ofs + 0);
  461.                     let byte2 = this.view.getUint8(ofs + 1);
  462.                     ofs += 2;
  463.                     vertex.color = {
  464.                         r: ((byte1 >> 0) & 0xf) / 0x0f,
  465.                         g: ((color1 >> 4) & 0xf) / 0x0f,
  466.                         b: ((color2 >> 0) & 0xf) / 0x0f,
  467.                         a: ((color2 >> 4) & 0xf) / 0x0f
  468.                     };
  469.                 }
  470.  
  471.                 // Read normals
  472.  
  473.                 switch (normalFormat) {
  474.                     case UINT8:
  475.                         vertex.normal = {
  476.                             x: this.view.getUint8(ofs + 0) / 0x7f,
  477.                             y: this.view.getUint8(ofs + 1) / 0x7f,
  478.                             z: this.view.getUint8(ofs + 2) / 0x7f
  479.                         }
  480.                         ofs += 3;
  481.                         break;
  482.                     case INT16:
  483.                         if (ofs % 2) {
  484.                             ofs += 2 - (ofs % 2);
  485.                         }
  486.                         vertex.normal = {
  487.                             x: this.view.getInt16(ofs + 0) / 0x7fff,
  488.                             y: this.view.getInt16(ofs + 2) / 0x7fff,
  489.                             z: this.view.getInt16(ofs + 6) / 0x7fff
  490.                         }
  491.                         ofs += 6;
  492.                         break;
  493.                     case FLOAT:
  494.                         if (ofs % 4) {
  495.                             ofs += 4 - (ofs % 4);
  496.                         }
  497.  
  498.                         vertex.normal = {
  499.                             x: this.view.getFloat32(ofs + 0),
  500.                             y: this.view.getFloat32(ofs + 4),
  501.                             z: this.view.getFloat32(ofs + 8)
  502.                         }
  503.                         ofs += 12;
  504.                         break;
  505.                 }
  506.  
  507.                 // Read Position
  508.  
  509.                 switch (positionFormat) {
  510.                     case UINT8:
  511.                         vertex.position = {
  512.                             x: this.view.getUint8(ofs + 0) / 0x7f * scale,
  513.                             y: this.view.getUint8(ofs + 1) / 0x7f * scale,
  514.                             z: this.view.getUint8(ofs + 2) / 0x7f * scale
  515.                         }
  516.                         ofs += 3;
  517.                         break;
  518.                     case INT16:
  519.                         if (ofs % 2) {
  520.                             ofs += 2 - (ofs % 2);
  521.                         }
  522.                         vertex.position = {
  523.                             x: this.view.getInt16(ofs + 0) / 0x7fff * scale,
  524.                             y: this.view.getInt16(ofs + 2) / 0x7fff * scale,
  525.                             z: this.view.getInt16(ofs + 6) / 0x7fff * scale
  526.                         }
  527.                         ofs += 6;
  528.                         break;
  529.                     case FLOAT:
  530.                         if (ofs % 4) {
  531.                             ofs += 4 - (ofs % 4);
  532.                         }
  533.  
  534.                         vertex.position = {
  535.                             x: this.view.getFloat32(ofs + 0) * scale,
  536.                             y: this.view.getFloat32(ofs + 4) * scale,
  537.                             z: this.view.getFloat32(ofs + 8) * scale
  538.                         }
  539.                         ofs += 12;
  540.                         break;
  541.                 }
  542.  
  543.                 const end = ofs;
  544.                 if (end - start !== vertex_length) {
  545.                     throw new Error("Phission Mailed, better luck next time");
  546.                 }
  547.  
  548.                 vertices[k] = vertex;
  549.             }
  550.  
  551.             // Last we replace the vertex group with the finalized vertex list
  552.  
  553.             this.vertex_groups[i] = vertices;
  554.  
  555.         }
  556.  
  557.     }
  558.  
  559.     readBones() {
  560.  
  561.         let ofs = this.header.bone_ofs;
  562.         for (let i = 0; i < this.header.bone_count; i++) {
  563.  
  564.             const unj_bone_t = {
  565.                     flags: this.view.getUint32(ofs + 0x00, true),
  566.                     bone_id: this.view.getUint16(ofs + 0x04, true),
  567.                     parent_id: this.view.getUint16(ofs + 0x06, true),
  568.                     child_id: this.view.getUint16(ofs + 0x08, true),
  569.                     sibling_id: this.view.getUint16(ofs + 0x0a, true),
  570.                     position: {
  571.                         x: this.view.getFloat32(ofs + 0x0c, true),
  572.                         y: this.view.getFloat32(ofs + 0x10, true),
  573.                         z: this.view.getFloat32(ofs + 0x14, true)
  574.                     },
  575.                     rotation: {
  576.                         x: this.view.getInt32(ofs + 0x18, true),
  577.                         y: this.view.getInt32(ofs + 0x1c, true),
  578.                         z: this.view.getInt32(ofs + 0x20, true)
  579.                     },
  580.                     scale: x: this.view.getFloat32(ofs + 0x24, true),
  581.                     y: this.view.getFloat32(ofs + 0x28, true),
  582.                     z: this.view.getFloat32(ofs + 0x2c, true)
  583.                 },
  584.                 transform[16] = [
  585.                     this.view.getFloat32(ofs + 0x30, true),
  586.                     this.view.getFloat32(ofs + 0x34, true),
  587.                     this.view.getFloat32(ofs + 0x38, true),
  588.                     this.view.getFloat32(ofs + 0x3c, true),
  589.  
  590.                     this.view.getFloat32(ofs + 0x40, true),
  591.                     this.view.getFloat32(ofs + 0x44, true),
  592.                     this.view.getFloat32(ofs + 0x48, true),
  593.                     this.view.getFloat32(ofs + 0x4c, true),
  594.  
  595.                     this.view.getFloat32(ofs + 0x50, true),
  596.                     this.view.getFloat32(ofs + 0x54, true),
  597.                     this.view.getFloat32(ofs + 0x58, true),
  598.                     this.view.getFloat32(ofs + 0x5c, true),
  599.  
  600.                     this.view.getFloat32(ofs + 0x50, true),
  601.                     this.view.getFloat32(ofs + 0x54, true),
  602.                     this.view.getFloat32(ofs + 0x58, true),
  603.                     this.view.getFloat32(ofs + 0x5c, true)
  604.                 ],
  605.                 bound_sphere: {
  606.                     x: this.view.getFloat32(ofs + 0x60, true),
  607.                     y: this.view.getFloat32(ofs + 0x64, true),
  608.                     z: this.view.getFloat32(ofs + 0x68, true),
  609.                     r: this.view.getFloat32(ofs + 0x6c, true)
  610.                 },
  611.                 unknown: this.view.getInt32(ofs + 0x70, true),
  612.                 half_dimensions: {
  613.                     x: this.view.getFloat32(ofs + 0x74, true),
  614.                     y: this.view.getFloat32(ofs + 0x78, true),
  615.                     z: this.view.getFloat32(ofs + 0x7c, true)
  616.                 }
  617.         }
  618.  
  619.         this.bones[i] = unj_bone_t;
  620.         ofs += 0x90;
  621.     }
  622.  
  623.     readDrawCalls() {
  624.  
  625.         let ofs = this.header.draw_ofs;
  626.         const groups = [];
  627.  
  628.         for (let i = 0; i < this.header.draw_count; i++) {
  629.  
  630.             const unj_drawgroups_t = {
  631.                 unknown_byte_1: this.view.getUint8(ofs + 0x00),
  632.                 unknown_byte_2: this.view.getUint8(ofs + 0x01),
  633.                 unknown_short_1: this.view.getUint16(ofs + 0x02, true),
  634.                 direct_draw_count: this.view.getUint32(ofs + 0x04, true),
  635.                 direct_draw_ofs: this.view.getUint32(ofs + 0x08, true),
  636.                 indexed_draw_count: this.view.getUint32(ofs + 0x0c, true),
  637.                 indexed_draw_ofs: this.view.getUint32(ofs + 0x10, true)
  638.             }
  639.  
  640.             groups[i] = unj_drawgroups_t;
  641.             ofs += 0x14;
  642.  
  643.         };
  644.  
  645.         groups.forEach(group => {
  646.  
  647.             ofs = group.indexed_draw_ofs;
  648.             for (let i = 0; i < group.indexed_draw_count; i++) {
  649.  
  650.                 const unj_direct_call_t = {
  651.                     center: {
  652.                         x: this.view.getFloat32(ofs + 0x00, true),
  653.                         y: this.view.getFloat32(ofs + 0x04, true),
  654.                         z: this.view.getFloat32(ofs + 0x08, true),
  655.                     },
  656.                     radius: this.view.getFloat32(ofs + 0x0c, true),
  657.                     top_level_bone: this.view.getUint32(ofs + 0x10, true),
  658.                     unknown_int1: this.view.getUint32(ofs + 0x14, true),
  659.                     material_group: this.view.getUint32(ofs + 0x18, true),
  660.                     vertex_group: this.view.getUint32(ofs + 0x1c, true),
  661.                     unknown_int2: this.view.getUint32(ofs + 0x20, true)
  662.                 }
  663.                 ofs += 0x24;
  664.                 this.direct_calls.push(unj_direct_call_t);
  665.             }
  666.  
  667.         });
  668.  
  669.     }
  670.  
  671. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement