mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 02:24:04 -05:00
Merge pull request #273 from CesiumGS/eslint-update
Upgrades to eslint-config-cesium/node v9.0.0
This commit is contained in:
commit
9b018ff696
@ -89,7 +89,7 @@ function cloc() {
|
|||||||
|
|
||||||
//Run cloc on primary Source files only
|
//Run cloc on primary Source files only
|
||||||
const source = new Promise(function (resolve, reject) {
|
const source = new Promise(function (resolve, reject) {
|
||||||
cmdLine = "perl " + clocPath + " --quiet --progress-rate=0" + " lib/ bin/";
|
cmdLine = `perl ${clocPath} --quiet --progress-rate=0` + ` lib/ bin/`;
|
||||||
|
|
||||||
child_process.exec(cmdLine, function (error, stdout, stderr) {
|
child_process.exec(cmdLine, function (error, stdout, stderr) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -105,8 +105,7 @@ function cloc() {
|
|||||||
//If running cloc on source succeeded, also run it on the tests.
|
//If running cloc on source succeeded, also run it on the tests.
|
||||||
return source.then(function () {
|
return source.then(function () {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
cmdLine =
|
cmdLine = `perl ${clocPath} --quiet --progress-rate=0` + ` specs/lib/`;
|
||||||
"perl " + clocPath + " --quiet --progress-rate=0" + " specs/lib/";
|
|
||||||
child_process.exec(cmdLine, function (error, stdout, stderr) {
|
child_process.exec(cmdLine, function (error, stdout, stderr) {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(stderr);
|
console.log(stderr);
|
||||||
|
@ -141,7 +141,7 @@ function addCombinedBufferView(gltf, buffers, accessors, byteStride, target) {
|
|||||||
byteLength += buffers[i].length;
|
byteLength += buffers[i].length;
|
||||||
}
|
}
|
||||||
gltf.bufferViews.push({
|
gltf.bufferViews.push({
|
||||||
name: "bufferView_" + bufferViewIndex,
|
name: `bufferView_${bufferViewIndex}`,
|
||||||
buffer: 0,
|
buffer: 0,
|
||||||
byteLength: byteLength,
|
byteLength: byteLength,
|
||||||
byteOffset: byteOffset,
|
byteOffset: byteOffset,
|
||||||
@ -212,7 +212,7 @@ function addSeparateBufferView(
|
|||||||
const bufferViewIndex = gltf.bufferViews.length;
|
const bufferViewIndex = gltf.bufferViews.length;
|
||||||
|
|
||||||
gltf.buffers.push({
|
gltf.buffers.push({
|
||||||
name: name + "_" + bufferIndex,
|
name: `${name}_${bufferIndex}`,
|
||||||
byteLength: buffer.length,
|
byteLength: buffer.length,
|
||||||
extras: {
|
extras: {
|
||||||
_obj2gltf: {
|
_obj2gltf: {
|
||||||
@ -451,7 +451,7 @@ function getSplitMaterialName(
|
|||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
splitMaterialName = originalMaterialName + "-" + suffix++;
|
splitMaterialName = `${originalMaterialName}-${suffix++}`;
|
||||||
}
|
}
|
||||||
return splitMaterialName;
|
return splitMaterialName;
|
||||||
}
|
}
|
||||||
@ -591,7 +591,7 @@ function addPrimitive(
|
|||||||
gltf,
|
gltf,
|
||||||
primitive.positions,
|
primitive.positions,
|
||||||
3,
|
3,
|
||||||
mesh.name + "_" + index + "_positions"
|
`${mesh.name}_${index}_positions`
|
||||||
);
|
);
|
||||||
attributes.POSITION = accessorIndex;
|
attributes.POSITION = accessorIndex;
|
||||||
bufferState.positionBuffers.push(primitive.positions.toFloatBuffer());
|
bufferState.positionBuffers.push(primitive.positions.toFloatBuffer());
|
||||||
@ -602,7 +602,7 @@ function addPrimitive(
|
|||||||
gltf,
|
gltf,
|
||||||
primitive.normals,
|
primitive.normals,
|
||||||
3,
|
3,
|
||||||
mesh.name + "_" + index + "_normals"
|
`${mesh.name}_${index}_normals`
|
||||||
);
|
);
|
||||||
attributes.NORMAL = accessorIndex;
|
attributes.NORMAL = accessorIndex;
|
||||||
bufferState.normalBuffers.push(primitive.normals.toFloatBuffer());
|
bufferState.normalBuffers.push(primitive.normals.toFloatBuffer());
|
||||||
@ -613,7 +613,7 @@ function addPrimitive(
|
|||||||
gltf,
|
gltf,
|
||||||
primitive.uvs,
|
primitive.uvs,
|
||||||
2,
|
2,
|
||||||
mesh.name + "_" + index + "_texcoords"
|
`${mesh.name}_${index}_texcoords`
|
||||||
);
|
);
|
||||||
attributes.TEXCOORD_0 = accessorIndex;
|
attributes.TEXCOORD_0 = accessorIndex;
|
||||||
bufferState.uvBuffers.push(primitive.uvs.toFloatBuffer());
|
bufferState.uvBuffers.push(primitive.uvs.toFloatBuffer());
|
||||||
@ -624,7 +624,7 @@ function addPrimitive(
|
|||||||
gltf,
|
gltf,
|
||||||
primitive.indices,
|
primitive.indices,
|
||||||
uint32Indices,
|
uint32Indices,
|
||||||
mesh.name + "_" + index + "_indices"
|
`${mesh.name}_${index}_indices`
|
||||||
);
|
);
|
||||||
const indexBuffer = uint32Indices
|
const indexBuffer = uint32Indices
|
||||||
? primitive.indices.toUint32Buffer()
|
? primitive.indices.toUint32Buffer()
|
||||||
|
@ -346,9 +346,7 @@ function loadMaterialTexture(
|
|||||||
) {
|
) {
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read texture file at " +
|
`Could not read texture file at ${shallowPath}. This texture will be ignored`
|
||||||
shallowPath +
|
|
||||||
". This texture will be ignored"
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -357,18 +355,14 @@ function loadMaterialTexture(
|
|||||||
// Try looking for the texture in the same directory as the obj
|
// Try looking for the texture in the same directory as the obj
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read texture file at " +
|
`Could not read texture file at ${texturePath}. Attempting to read the texture file from within the obj directory instead.`
|
||||||
texturePath +
|
|
||||||
". Attempting to read the texture file from within the obj directory instead."
|
|
||||||
);
|
);
|
||||||
return loadTexture(shallowPath, textureOptions);
|
return loadTexture(shallowPath, textureOptions);
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read texture file at " +
|
`Could not read texture file at ${shallowPath}. This texture will be ignored.`
|
||||||
shallowPath +
|
|
||||||
". This texture will be ignored."
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -493,17 +487,7 @@ function getMinimumDimensions(textures, options) {
|
|||||||
const texture = textures[i];
|
const texture = textures[i];
|
||||||
if (texture.width !== width || texture.height !== height) {
|
if (texture.width !== width || texture.height !== height) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Texture " +
|
`Texture ${texture.path} will be scaled from ${texture.width}x${texture.height} to ${width}x${height}.`
|
||||||
texture.path +
|
|
||||||
" will be scaled from " +
|
|
||||||
texture.width +
|
|
||||||
"x" +
|
|
||||||
texture.height +
|
|
||||||
" to " +
|
|
||||||
width +
|
|
||||||
"x" +
|
|
||||||
height +
|
|
||||||
"."
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -540,11 +524,7 @@ function createDiffuseAlphaTexture(diffuseTexture, alphaTexture, options) {
|
|||||||
|
|
||||||
if (!defined(diffuseTexture.pixels) || !defined(alphaTexture.pixels)) {
|
if (!defined(diffuseTexture.pixels) || !defined(alphaTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${diffuseTexture.path} or ${alphaTexture.path}. The material will be created without an alpha texture.`
|
||||||
diffuseTexture.path +
|
|
||||||
" or " +
|
|
||||||
alphaTexture.path +
|
|
||||||
". The material will be created without an alpha texture."
|
|
||||||
);
|
);
|
||||||
return diffuseTexture;
|
return diffuseTexture;
|
||||||
}
|
}
|
||||||
@ -633,27 +613,21 @@ function createMetallicRoughnessTexture(
|
|||||||
|
|
||||||
if (packMetallic && !defined(metallicTexture.pixels)) {
|
if (packMetallic && !defined(metallicTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${metallicTexture.path}. The material will be created without a metallicRoughness texture.`
|
||||||
metallicTexture.path +
|
|
||||||
". The material will be created without a metallicRoughness texture."
|
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packRoughness && !defined(roughnessTexture.pixels)) {
|
if (packRoughness && !defined(roughnessTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${roughnessTexture.path}. The material will be created without a metallicRoughness texture.`
|
||||||
roughnessTexture.path +
|
|
||||||
". The material will be created without a metallicRoughness texture."
|
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packOcclusion && !defined(occlusionTexture.pixels)) {
|
if (packOcclusion && !defined(occlusionTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${occlusionTexture.path}. The occlusion texture will not be packed in the metallicRoughness texture.`
|
||||||
occlusionTexture.path +
|
|
||||||
". The occlusion texture will not be packed in the metallicRoughness texture."
|
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -744,18 +718,14 @@ function createSpecularGlossinessTexture(
|
|||||||
|
|
||||||
if (packSpecular && !defined(specularTexture.pixels)) {
|
if (packSpecular && !defined(specularTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${specularTexture.path}. The material will be created without a specularGlossiness texture.`
|
||||||
specularTexture.path +
|
|
||||||
". The material will be created without a specularGlossiness texture."
|
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packGlossiness && !defined(glossinessTexture.pixels)) {
|
if (packGlossiness && !defined(glossinessTexture.pixels)) {
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not get decoded texture data for " +
|
`Could not get decoded texture data for ${glossinessTexture.path}. The material will be created without a specularGlossiness texture.`
|
||||||
glossinessTexture.path +
|
|
||||||
". The material will be created without a specularGlossiness texture."
|
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -204,12 +204,10 @@ function loadObj(objPath, options) {
|
|||||||
function correctVertices(vertices, positions, uvs, normals) {
|
function correctVertices(vertices, positions, uvs, normals) {
|
||||||
const length = vertices.length;
|
const length = vertices.length;
|
||||||
for (let i = 0; i < length; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
vertices[i] =
|
vertices[i] = `${defaultValue(positions[i], "")}/${defaultValue(
|
||||||
defaultValue(positions[i], "") +
|
uvs[i],
|
||||||
"/" +
|
""
|
||||||
defaultValue(uvs[i], "") +
|
)}/${defaultValue(normals[i], "")}`;
|
||||||
"/" +
|
|
||||||
defaultValue(normals[i], "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +536,7 @@ function getMtlPaths(mtllibLine) {
|
|||||||
function finishLoading(nodes, mtlPaths, objPath, usesMaterials, options) {
|
function finishLoading(nodes, mtlPaths, objPath, usesMaterials, options) {
|
||||||
nodes = cleanNodes(nodes);
|
nodes = cleanNodes(nodes);
|
||||||
if (nodes.length === 0) {
|
if (nodes.length === 0) {
|
||||||
throw new RuntimeError(objPath + " does not have any geometry data");
|
throw new RuntimeError(`${objPath} does not have any geometry data`);
|
||||||
}
|
}
|
||||||
const name = path.basename(objPath, path.extname(objPath));
|
const name = path.basename(objPath, path.extname(objPath));
|
||||||
return loadMtls(mtlPaths, objPath, options).then(function (materials) {
|
return loadMtls(mtlPaths, objPath, options).then(function (materials) {
|
||||||
@ -585,9 +583,7 @@ function loadMtls(mtlPaths, objPath, options) {
|
|||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read material file at " +
|
`Could not read material file at ${shallowPath}. Using default material instead.`
|
||||||
shallowPath +
|
|
||||||
". Using default material instead."
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -597,9 +593,7 @@ function loadMtls(mtlPaths, objPath, options) {
|
|||||||
// Try looking for the .mtl in the same directory as the obj
|
// Try looking for the .mtl in the same directory as the obj
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read material file at " +
|
`Could not read material file at ${mtlPath}. Attempting to read the material file from within the obj directory instead.`
|
||||||
mtlPath +
|
|
||||||
". Attempting to read the material file from within the obj directory instead."
|
|
||||||
);
|
);
|
||||||
return loadMtl(shallowPath, options);
|
return loadMtl(shallowPath, options);
|
||||||
})
|
})
|
||||||
@ -609,9 +603,7 @@ function loadMtls(mtlPaths, objPath, options) {
|
|||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
options.logger(error.message);
|
options.logger(error.message);
|
||||||
options.logger(
|
options.logger(
|
||||||
"Could not read material file at " +
|
`Could not read material file at ${shallowPath}. Using default material instead.`
|
||||||
shallowPath +
|
|
||||||
". Using default material instead."
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -722,7 +714,7 @@ function setDefaultNames(items, defaultName, usedNames) {
|
|||||||
const occurrences = usedNames[name];
|
const occurrences = usedNames[name];
|
||||||
if (defined(occurrences)) {
|
if (defined(occurrences)) {
|
||||||
usedNames[name]++;
|
usedNames[name]++;
|
||||||
name = name + "_" + occurrences;
|
name = `${name}_${occurrences}`;
|
||||||
} else {
|
} else {
|
||||||
usedNames[name] = 1;
|
usedNames[name] = 1;
|
||||||
}
|
}
|
||||||
@ -736,7 +728,7 @@ function setDefaults(nodes) {
|
|||||||
const nodesLength = nodes.length;
|
const nodesLength = nodes.length;
|
||||||
for (let i = 0; i < nodesLength; ++i) {
|
for (let i = 0; i < nodesLength; ++i) {
|
||||||
const node = nodes[i];
|
const node = nodes[i];
|
||||||
setDefaultNames(node.meshes, node.name + "-Mesh", usedNames);
|
setDefaultNames(node.meshes, `${node.name}-Mesh`, usedNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ function writeSeparateBuffers(gltf, options) {
|
|||||||
buffers,
|
buffers,
|
||||||
function (buffer) {
|
function (buffer) {
|
||||||
const source = buffer.extras._obj2gltf.source;
|
const source = buffer.extras._obj2gltf.source;
|
||||||
const bufferUri = buffer.name + ".bin";
|
const bufferUri = `${buffer.name}.bin`;
|
||||||
buffer.uri = bufferUri;
|
buffer.uri = bufferUri;
|
||||||
return options.writer(bufferUri, source);
|
return options.writer(bufferUri, source);
|
||||||
},
|
},
|
||||||
@ -169,8 +169,9 @@ function writeEmbeddedBuffer(gltf) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.uri =
|
buffer.uri = `data:application/octet-stream;base64,${source.toString(
|
||||||
"data:application/octet-stream;base64," + source.toString("base64");
|
"base64"
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeEmbeddedTextures(gltf) {
|
function writeEmbeddedTextures(gltf) {
|
||||||
|
@ -38,8 +38,9 @@
|
|||||||
"cloc": "^2.8.0",
|
"cloc": "^2.8.0",
|
||||||
"coveralls": "^3.1.1",
|
"coveralls": "^3.1.1",
|
||||||
"eslint": "^8.0.1",
|
"eslint": "^8.0.1",
|
||||||
"eslint-config-cesium": "^8.0.1",
|
"eslint-config-cesium": "^9.0.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"jasmine": "^3.10.0",
|
"jasmine": "^3.10.0",
|
||||||
|
@ -692,7 +692,7 @@ describe("loadObj", () => {
|
|||||||
}
|
}
|
||||||
expect(thrownError).toEqual(
|
expect(thrownError).toEqual(
|
||||||
new RuntimeError(
|
new RuntimeError(
|
||||||
objInvalidContentsPath + " does not have any geometry data"
|
`${objInvalidContentsPath} does not have any geometry data`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user