Skip to content

Commit

Permalink
Added script to toggle morphing on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
manavortex committed Oct 23, 2024
1 parent 1a05a7a commit b569208
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Scripts/Morphtargets_Toggle_Morphing.wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as Logger from 'Logger.wscript';
import * as TypeHelper from 'TypeHelper.wscript';

const enableMorphing = false;


const files = [];

for (let filename of wkit.GetProjectFiles('archive')) {
// Logger.Success(filename);
if (filename.split('.').pop() === "morphtarget") {
files.push(filename);
}
}

// loop over every sector in `sectors`
for (let file in files) {
Logger.Info(`Parsing morphtarget...${files[file]}`);
ParseFile(files[file], null);
}

function ParseFile(filePath) {
if (!wkit.FileExistsInProject(filePath)) {
return;
}
const file = wkit.GetFileFromProject(filePath, OpenAs.GameFile);
const json = TypeHelper.JsonParse(wkit.GameFileToJson(file));
const header = json["Data"]["RootChunk"]["blob"]["Data"]["header"];
header["numTargets"] = enableMorphing ? header["numVertexDiffsInEachChunk"].length : 0;

let jsonString = '';
try {
jsonString = TypeHelper.JsonStringify(json);
} catch (err) {
Logger.Error(`Couldn't parse active file content to json:`);
Logger.Error(err);
return;
}

let cr2wContent;
try {
cr2wContent = wkit.JsonToCR2W(jsonString)
} catch (err) {
Logger.Error(`Couldn't parse active file content to cr2w:`);
Logger.Error(err);
return;
}

try {
wkit.SaveToProject(filePath, cr2wContent);
} catch (err) {
Logger.Error(`Couldn't save ${activeFilePath}:`);
Logger.Error(err);
}
}

0 comments on commit b569208

Please sign in to comment.