mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 02:24:04 -05:00
Don't discard primitives that don't match the attribute layout
This commit is contained in:
parent
b781459234
commit
b3d5407a26
@ -122,25 +122,44 @@ function loadObj(objPath, options) {
|
||||
vertexCount = 0;
|
||||
}
|
||||
|
||||
function useMaterial(name) {
|
||||
var material = getName(name);
|
||||
activeMaterial = material;
|
||||
|
||||
// Look to see if this material has already been used by a primitive in the mesh
|
||||
function reusePrimitive(callback) {
|
||||
var primitives = mesh.primitives;
|
||||
var primitivesLength = primitives.length;
|
||||
for (var i = 0; i < primitivesLength; ++i) {
|
||||
if (primitives[i].material === material) {
|
||||
primitive = primitives[i];
|
||||
clearVertexCache();
|
||||
vertexCount = primitive.positions.length / 3;
|
||||
return;
|
||||
if (primitives[i].material === activeMaterial) {
|
||||
if (!defined(callback) || callback(primitives[i])) {
|
||||
primitive = primitives[i];
|
||||
clearVertexCache();
|
||||
vertexCount = primitive.positions.length / 3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add a new primitive with this material
|
||||
addPrimitive();
|
||||
}
|
||||
|
||||
function useMaterial(name) {
|
||||
activeMaterial = getName(name);
|
||||
reusePrimitive();
|
||||
}
|
||||
|
||||
function faceAndPrimitiveMatch(uvs, normals, primitive) {
|
||||
var faceHasUvs = uvs[0].length > 0;
|
||||
var faceHasNormals = normals[0].length > 0;
|
||||
var primitiveHasUvs = primitive.uvs.length > 0;
|
||||
var primitiveHasNormals = primitive.normals.length > 0;
|
||||
return primitiveHasUvs === faceHasUvs && primitiveHasNormals === faceHasNormals;
|
||||
}
|
||||
|
||||
function checkPrimitive(uvs, normals) {
|
||||
var firstFace = primitive.indices.length === 0;
|
||||
if (!firstFace && !faceAndPrimitiveMatch(uvs, normals, primitive)) {
|
||||
reusePrimitive(function(primitive) {
|
||||
return faceAndPrimitiveMatch(uvs, normals, primitive);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getOffset(a, attributeData, components) {
|
||||
var i = parseInt(a);
|
||||
if (i < 0) {
|
||||
@ -261,16 +280,8 @@ function loadObj(objPath, options) {
|
||||
function addFace(vertices, positions, uvs, normals) {
|
||||
var i;
|
||||
var isWindingCorrect;
|
||||
var firstFace = primitive.indices.length === 0;
|
||||
var faceHasUvs = uvs[0].length > 0;
|
||||
var faceHasNormals = normals[0].length > 0;
|
||||
var primitiveHasUvs = primitive.uvs.length > 0;
|
||||
var primitiveHasNormals = primitive.normals.length > 0;
|
||||
|
||||
if (!firstFace && (faceHasUvs !== primitiveHasUvs || faceHasNormals !== primitiveHasNormals)) {
|
||||
// Discard faces that don't use the same attributes
|
||||
return;
|
||||
}
|
||||
checkPrimitive(uvs, normals);
|
||||
|
||||
if (vertices.length === 3) {
|
||||
isWindingCorrect = checkWindingCorrect(positions[0], positions[1], positions[2], normals[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user