Skip to content

Commit

Permalink
Merge pull request #77 from Smithsonian/dev-xnormal
Browse files Browse the repository at this point in the history
Sanitize xNormal paths for XML compatibility
  • Loading branch information
gjcope authored Dec 14, 2023
2 parents 5df18e7 + 9303d1c commit 8482e3c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions source/server/tools/XNormalTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export default class XNormalTool extends Tool<XNormalTool, IXNormalToolSettings>
throw new Error("XNormalTool.writeTaskScript - missing mapSize option");
}

const highPolyMeshPath = instance.getFilePath(settings.highPolyMeshFile);
const highPolyMeshPath = this.sanitize(instance.getFilePath(settings.highPolyMeshFile));
if (!highPolyMeshPath) {
throw new Error("XNormalTool.writeTaskScript - missing highres mesh file");
}

const lowPolyMeshPath = instance.getFilePath(settings.lowPolyUnwrappedMeshFile);
const lowPolyMeshPath = this.sanitize(instance.getFilePath(settings.lowPolyUnwrappedMeshFile));
if (!lowPolyMeshPath) {
throw new Error("XNormalTool.writeTaskScript - missing lowres mesh file");
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export default class XNormalTool extends Tool<XNormalTool, IXNormalToolSettings>
const aoLimitRayDistance = false; // default false
const aoBias = 0.005;

const highpolyDiffuseMapPath = instance.getFilePath(settings.highPolyDiffuseMapFile);
const highpolyDiffuseMapPath = this.sanitize(instance.getFilePath(settings.highPolyDiffuseMapFile));
const bakeDiffuse = !!settings.bakeDiffuse && !!highpolyDiffuseMapPath;
const bakeVertexColor = !!settings.bakeVertexColor;
const isNormalMap = settings.isNormalMap;
Expand All @@ -122,7 +122,7 @@ export default class XNormalTool extends Tool<XNormalTool, IXNormalToolSettings>
throw new Error("XNormalTool.writeTaskScript - missing output base map path");
}

const mapBaseFilePath = instance.getFilePath(settings.mapBaseName);
const mapBaseFilePath = this.sanitize(instance.getFilePath(settings.mapBaseName));

const script = {
fileName: "_xnormal_" + uniqueId() + ".xml",
Expand Down Expand Up @@ -239,4 +239,13 @@ export default class XNormalTool extends Tool<XNormalTool, IXNormalToolSettings>

return Promise.all(fileTasks);
}

protected sanitize(str: string)
{
if (!str) {
return str;
}

return str.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;');
}
}

0 comments on commit 8482e3c

Please sign in to comment.