moonpaladin wrote: ↑Sat Apr 03, 2021 2:50 pm
Bigchillghost, would you mind in explain a bit why you use those values in star vertices, face indices, and the count indices?
I assume you have no question about the fact that the whole vertex data chunk begins at offset 8 and the whole index data chunk begins at offset 0x238AA4.
For face indices, since most usually their values are in an increasing order, it's rather plain and easy to locate the first index of the next mesh by looking for a point where the index value dropped dramatically, which I referenced as a "jump discontinuity". Set the number of columns to 6 in your hex editor, hence there'd be one triangle on each row. Place your cursor at the position before the 1st index of the first mesh, then scroll down and look for the said area at the same column. As a result you'll notice that the indices increased overall and suddenly dropped at address 0x27025C, where the value changed from 0x8D79 to 0xD7B.
idx_addr.png
Therefore you get the index counts for the two meshes:
(0x27025C - 0x238AA4) / 2 = 113628
(0x2A1258 - 0x27025C) / 2 = 100350 or (0x687B4 / 2) - 113628 = 100350
Interpret these two index chunks individually and you'll get the min & max index values and the required vertex counts of them:
1st: min value: 0 | max value: 36218, required vertex count: 36219
2nd: min value: 3451 | max value: 31932, required vertex count: 31933
Note that in Hex2Obj index values begin from 1 whereas in AMR they interpreted as is.
There're (0x238A94 / 36) = 64701 vertices and the 1st mesh takes 36219, hence there're (64701 - 36219) = 28482 vertices left. But the 2nd mesh requires 31933 vertices to construct the mesh, while its min index value is 3451, meaning that the previous 3451 vertices are not used, no mater where its vertices begin. So the actual required vertex amount would be (31932 - 3451) + 1 = 28482, exactly the amount of the vertices left. Now depends on how you'd like to construct the mesh there'd be two sets of params you could use:
1. Keep the face indices untouched and adjust the base vertex address:
Calculate the subscript of the 1st vertex of the 2nd mesh in the entire vertex array as: (64701 - 31933) = 32768, which obviously is a special value.
Then you can obtain the start address: (32768 * 36) + 8 = 0x120008. This set of params can be used in both AMR and Hex2Obj. The shortcoming of this handling is that there'd be extra unused vertices in the mesh.
2. Reset the base of the face indices by subtracting the min value from all these indices, which is referenced as "Zero Calibration" in AMR. An adjust to the base vertex address is also required though: (36219 * 36) + 8 = 0x13E554.
With the "Zero Calibration" option checked in AMR, you'll be able to construct the mesh without these unused vertices.
As you may have noticed, this file has a rather simple layout:
Code: Select all
long chunkID
long chunkSize
byte chunkData[chunkSize]
And there're no available reference info to the data chunks. So you really should check other files for the info you need, instead of trying to apply the above method for every file. Though you can use that as a basis.