Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid primitive restart #248

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Change Log
==========
### Next Release

##### Fixes :wrench:
* Avoid primitive restart issue [#213](https://github.com/KhronosGroup/COLLADA2GLTF/issues/213)

### v2.1.5 - 2019-05-22

##### Additions :tada:
Expand Down
44 changes: 13 additions & 31 deletions src/COLLADA2GLTFWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ bool COLLADA2GLTF::Writer::writeMesh(const COLLADAFW::Mesh* colladaMesh) {

// Create indices accessor
GLTF::Accessor* indices = NULL;
if (index < 65536) {
if (index < 65535) {
// We can fit this in an UNSIGNED_SHORT
std::vector<unsigned short> unsignedShortIndices(buildIndices.begin(), buildIndices.end());
indices = new GLTF::Accessor(GLTF::Accessor::Type::SCALAR, GLTF::Constants::WebGL::UNSIGNED_SHORT, (unsigned char*)&unsignedShortIndices[0], unsignedShortIndices.size(), GLTF::Constants::WebGL::ELEMENT_ARRAY_BUFFER);
Expand Down Expand Up @@ -1769,25 +1769,7 @@ bool COLLADA2GLTF::Writer::writeSkinControllerData(const COLLADAFW::SkinControll

// JOINTS_0 and WEIGHTS_0 must be `vec4`
maxJointsPerVertex = 4;

GLTF::Accessor::Type type;
if (maxJointsPerVertex == 1) {
type = GLTF::Accessor::Type::SCALAR;
} else if (maxJointsPerVertex == 2) {
type = GLTF::Accessor::Type::VEC2;
} else if (maxJointsPerVertex == 3) {
type = GLTF::Accessor::Type::VEC3;
} else if (maxJointsPerVertex == 4) {
type = GLTF::Accessor::Type::VEC4;
} else if (maxJointsPerVertex <= 9) {
type = GLTF::Accessor::Type::MAT3;
} else if (maxJointsPerVertex <= 16) {
type = GLTF::Accessor::Type::MAT4;
} else {
// There is no GLTF accessor type big enough to store this many joint influences
return false;
}
maxJointsPerVertex = GLTF::Accessor::getNumberOfComponents(type);
GLTF::Accessor::Type type = GLTF::Accessor::Type::VEC4;

size_t vertexCount = skinControllerData->getVertexCount();
size_t offset = 0;
Expand Down Expand Up @@ -1855,17 +1837,17 @@ bool COLLADA2GLTF::Writer::writeController(const COLLADAFW::Controller* controll
int numberOfComponents = GLTF::Accessor::getNumberOfComponents(type);

for (size_t i = 0; i < weights.size(); i++) {
float weightSum = 0;
float* weight = weights[i];
for (size_t j = 0; j < numberOfComponents; j++) {
weightSum = weightSum + std::abs(weight[j]);
}
if (weightSum > 0) {
for (size_t j = 0; j < numberOfComponents; j++) {
weight[j] = weight[j] / weightSum;
}
}
}
float weightSum = 0;
float* weight = weights[i];
for (size_t j = 0; j < numberOfComponents; j++) {
weightSum = weightSum + std::abs(weight[j]);
}
if (weightSum > 0) {
for (size_t j = 0; j < numberOfComponents; j++) {
weight[j] = weight[j] / weightSum;
}
}
}

COLLADAFW::UniqueId meshId = skinController->getSource();
GLTF::Mesh* mesh = _meshInstances[meshId];
Expand Down