Merge branch 'master' into jdumas/ziplib
commit
b0d564467e
|
@ -174,6 +174,22 @@ static void IdentityMatrix4(mat4 &o) {
|
||||||
o[15] = 1;
|
o[15] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsBoneWeightFitted(vec4 &weight) {
|
||||||
|
return weight[0] + weight[1] + weight[2] + weight[3] >= 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int FitBoneWeight(vec4 &weight, float value) {
|
||||||
|
int i = 0;
|
||||||
|
for (; i < 4; ++i) {
|
||||||
|
if (weight[i] < value) {
|
||||||
|
weight[i] = value;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void SetAccessorRange(Ref<Accessor> acc, void *data, size_t count,
|
void SetAccessorRange(Ref<Accessor> acc, void *data, size_t count,
|
||||||
unsigned int numCompsIn, unsigned int numCompsOut) {
|
unsigned int numCompsIn, unsigned int numCompsOut) {
|
||||||
|
@ -950,16 +966,22 @@ void ExportSkin(Asset &mAsset, const aiMesh *aimesh, Ref<Mesh> &meshRef, Ref<Buf
|
||||||
unsigned int vertexId = aib->mWeights[idx_weights].mVertexId;
|
unsigned int vertexId = aib->mWeights[idx_weights].mVertexId;
|
||||||
float vertWeight = aib->mWeights[idx_weights].mWeight;
|
float vertWeight = aib->mWeights[idx_weights].mWeight;
|
||||||
|
|
||||||
// A vertex can only have at most four joint weights. Ignore all others.
|
// A vertex can only have at most four joint weights, which ideally sum up to 1
|
||||||
if (jointsPerVertex[vertexId] > 3) {
|
if (IsBoneWeightFitted(vertexWeightData[vertexId])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (jointsPerVertex[vertexId] > 3) {
|
||||||
|
int boneIndexFitted = FitBoneWeight(vertexWeightData[vertexId], vertWeight);
|
||||||
|
if (boneIndexFitted) {
|
||||||
|
vertexJointData[vertexId][boneIndexFitted] = static_cast<float>(jointNamesIndex);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
vertexJointData[vertexId][jointsPerVertex[vertexId]] = static_cast<float>(jointNamesIndex);
|
vertexJointData[vertexId][jointsPerVertex[vertexId]] = static_cast<float>(jointNamesIndex);
|
||||||
vertexWeightData[vertexId][jointsPerVertex[vertexId]] = vertWeight;
|
vertexWeightData[vertexId][jointsPerVertex[vertexId]] = vertWeight;
|
||||||
|
|
||||||
jointsPerVertex[vertexId] += 1;
|
jointsPerVertex[vertexId] += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // End: for-loop mNumMeshes
|
} // End: for-loop mNumMeshes
|
||||||
|
|
||||||
|
@ -974,7 +996,7 @@ void ExportSkin(Asset &mAsset, const aiMesh *aimesh, Ref<Mesh> &meshRef, Ref<Buf
|
||||||
Ref<Buffer> buf = vertexJointAccessor->bufferView->buffer;
|
Ref<Buffer> buf = vertexJointAccessor->bufferView->buffer;
|
||||||
uint8_t *arrys = new uint8_t[bytesLen];
|
uint8_t *arrys = new uint8_t[bytesLen];
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (unsigned int j = 0; j <= bytesLen; j += bytesPerComp) {
|
for (unsigned int j = 0; j < bytesLen; j += bytesPerComp) {
|
||||||
size_t len_p = offset + j;
|
size_t len_p = offset + j;
|
||||||
float f_value = *(float *)&buf->GetPointer()[len_p];
|
float f_value = *(float *)&buf->GetPointer()[len_p];
|
||||||
unsigned short c = static_cast<unsigned short>(f_value);
|
unsigned short c = static_cast<unsigned short>(f_value);
|
||||||
|
|
|
@ -161,6 +161,7 @@ bool MakeVerboseFormatProcess::MakeVerboseFormat(aiMesh *pcMesh) {
|
||||||
delete[] pcMesh->mBones[i]->mWeights;
|
delete[] pcMesh->mBones[i]->mWeights;
|
||||||
if (!newWeights[i].empty()) {
|
if (!newWeights[i].empty()) {
|
||||||
pcMesh->mBones[i]->mWeights = new aiVertexWeight[newWeights[i].size()];
|
pcMesh->mBones[i]->mWeights = new aiVertexWeight[newWeights[i].size()];
|
||||||
|
pcMesh->mBones[i]->mNumWeights = static_cast<unsigned int>(newWeights[i].size());
|
||||||
aiVertexWeight *weightToCopy = &(newWeights[i][0]);
|
aiVertexWeight *weightToCopy = &(newWeights[i][0]);
|
||||||
memcpy(pcMesh->mBones[i]->mWeights, weightToCopy,
|
memcpy(pcMesh->mBones[i]->mWeights, weightToCopy,
|
||||||
sizeof(aiVertexWeight) * newWeights[i].size());
|
sizeof(aiVertexWeight) * newWeights[i].size());
|
||||||
|
|
Loading…
Reference in New Issue