mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
Merge branch 'bug/meshbatcherror' of scuti/lib3ddevil1 into a/writemesh
This commit is contained in:
commit
c6c57269b9
@ -18,24 +18,42 @@ void writemesh(const struct MeshHeader *mh,
|
|||||||
// mesh header offset batches need to be changed for compability with parsing.
|
// mesh header offset batches need to be changed for compability with parsing.
|
||||||
struct MeshHeader newmh = *(mh);
|
struct MeshHeader newmh = *(mh);
|
||||||
newmh.offsetBatches = sizeof(struct Header) + sizeof(struct MeshHeader);
|
newmh.offsetBatches = sizeof(struct Header) + sizeof(struct MeshHeader);
|
||||||
// batch data the same treatment.
|
|
||||||
struct BatchData newbatch = *(m -> b) -> bd;
|
|
||||||
unsigned int vertices = m -> b -> bd -> numVertex;
|
|
||||||
newbatch.offsetPositions = sizeof(struct MeshHeader) + sizeof(struct BatchData);
|
|
||||||
newbatch.offsetNormals = newbatch.offsetPositions + (sizeof(struct Coordinate) * vertices);
|
|
||||||
newbatch.offsetUVs = newbatch.offsetNormals + (sizeof(struct Coordinate) * vertices);
|
|
||||||
newbatch.offsetBoneIndexes = newbatch.offsetUVs + (sizeof(struct UVs) * vertices);
|
|
||||||
newbatch.offsetBoneWeights = newbatch.offsetBoneIndexes + (sizeof(struct BoneIndexes) * vertices);
|
|
||||||
// write to file.
|
|
||||||
write(fn, (char*)(&h), sizeof(struct Header));
|
write(fn, (char*)(&h), sizeof(struct Header));
|
||||||
append(fn, (char*)(&newmh), sizeof(struct MeshHeader));
|
append(fn, (char*)(&newmh), sizeof(struct MeshHeader));
|
||||||
append(fn, (char*)(&newbatch), sizeof(struct BatchData));
|
|
||||||
append(fn, (char*)(m -> b -> vd.positions), sizeof(struct Coordinate) * vertices);
|
|
||||||
|
|
||||||
|
// batch data the same treatment.
|
||||||
|
struct BatchData * newBatches = malloc(newmh.numBatch * sizeof(struct BatchData));
|
||||||
|
uint64_t previousBatch = 0;
|
||||||
|
for (int i = 0; i < newmh.numBatch; i++) {
|
||||||
|
newBatches[i] = (m -> b) -> bd[i];
|
||||||
|
unsigned int nVertices = m -> b -> bd[i].numVertex;
|
||||||
|
if (previousBatch == 0) {
|
||||||
|
newBatches[i].offsetPositions = newmh.offsetBatches + ( newmh.numBatch * sizeof(struct BatchData));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newBatches[i].offsetPositions = previousBatch;
|
||||||
|
}
|
||||||
|
newBatches[i].offsetNormals = newBatches[i].offsetPositions + (sizeof(struct Coordinate) * nVertices);
|
||||||
|
newBatches[i].offsetUVs = newBatches[i].offsetNormals + (sizeof(struct Coordinate) * nVertices);
|
||||||
|
newBatches[i].offsetBoneIndexes = newBatches[i].offsetUVs + (sizeof(struct UVs) * nVertices);
|
||||||
|
newBatches[i].offsetBoneWeights = newBatches[i].offsetBoneIndexes + (sizeof(struct BoneIndexes) * nVertices);
|
||||||
|
append(fn, (char*)(&newBatches[i]), sizeof(struct BatchData));
|
||||||
|
previousBatch = newBatches[i].offsetBoneWeights + (sizeof(struct BoneWeights) * nVertices);;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < newmh.numBatch; i++) {
|
||||||
|
unsigned int nVertices = m -> b -> bd[i].numVertex;
|
||||||
|
append(fn, (char*)(m -> b[i].vd.positions), sizeof(struct Coordinate) * nVertices);
|
||||||
DEVIL1GEO.printcoordinate(m -> b -> vd.positions, 3);
|
DEVIL1GEO.printcoordinate(m -> b -> vd.positions, 3);
|
||||||
append(fn, (char*)(m -> b -> vd.normals), sizeof(struct Coordinate) * vertices);
|
append(fn, (char*)(m -> b[i].vd.normals), sizeof(struct Coordinate) * nVertices);
|
||||||
append(fn, (char*)(m -> b -> vd.u), sizeof(struct UVs) * vertices);
|
append(fn, (char*)(m -> b[i].vd.u), sizeof(struct UVs) * nVertices);
|
||||||
append(fn, (char*)(m -> b -> vd.bi), sizeof(struct BoneIndexes) * vertices);
|
append(fn, (char*)(m -> b[i].vd.bi), sizeof(struct BoneIndexes) * nVertices);
|
||||||
append(fn, (char*)(m -> b -> vd.bw), sizeof(struct BoneWeights) * vertices);
|
append(fn, (char*)(m -> b[i].vd.bw), sizeof(struct BoneWeights) * nVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(newBatches);
|
||||||
free(fn);
|
free(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user