Skip to content

Commit

Permalink
Merge pull request #13 from notaspirit/patch-2
Browse files Browse the repository at this point in the history
Update RemoveOcclusionFromSectors.wscript
  • Loading branch information
manavortex authored Oct 14, 2024
2 parents 00215b9 + 7ffadf9 commit 6670471
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Scripts/RemoveOcclusionFromSectors.wscript
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
// Geneates .xl file that removes all occlusion meshes from all streamingsectors in the project
// Special thanks to simarilius for writing most of the code
// @author spirit
// @version 1.0
// @version 1.1
// @description
// This script generates an .xl file that removes all occluder nodes from all sectors in the project.
// Does not include occlusion that is caused by collision nodes.
// Special thanks to Simarilius for helping with the foundation of this script.
// @usage
// Detailed instructions can be found in the wiki.
// 1. Indentify all sectors that add occluder nodes using RedHotTools
// 2. Add all affected sectors to a new project
// 3. Run the script
// 4. Move the generated file into your archive mod folder

import * as Logger from 'Logger.wscript';
import * as TypeHelper from 'TypeHelper.wscript';

let RemoverStr = "streaming:\n sectors:\n"
let sectorNames = "OcclusionRemover_"
let sectorNames = "NoOccl_"
let sectors = []
let removedNodesCount = 0
let removedSectorCount = 0

// Gets FileName only from path
function getFileNameWithoutExt(filePath) {
const fileNameWithExt = filePath.split("\\").pop(); // Get last segment
const ext = fileNameWithExt.lastIndexOf('.');
return ext === -1 ? fileNameWithExt : fileNameWithExt.slice(0, ext); // Remove extension
}

// generates a shortened sector name
function shortenSectorName(sectorName) {
let shortSectorName = ""
let sectorNameArray = sectorName.split("_")
if (sectorNameArray[0] == "exterior") {
shortSectorName += "e"
} else if (sectorNameArray[0] == "interior") {
shortSectorName += "i"
} else {
Logger.warn("Error while shortening sector name, unexpected sector type!")
}
shortSectorName += sectorNameArray[1]+sectorNameArray[2]+sectorNameArray[3]+sectorNameArray[4]+"_"
return shortSectorName
}
// Lists all streamingsectors in Projects
for (let filename of wkit.GetProjectFiles('archive')) {
if (filename.split('.').pop() === "streamingsector") {
Expand All @@ -24,7 +49,7 @@ for (let filename of wkit.GetProjectFiles('archive')) {
}
// Goes through all streamingsectors
for (const fileName of sectors) {

removedSectorCount += 1
let node_data_indexs=[]
if (wkit.FileExistsInProject(fileName)) {
var file = wkit.GetFileFromProject(fileName, OpenAs.GameFile);
Expand All @@ -35,7 +60,7 @@ for (const fileName of sectors) {
let nodeData = json["Data"]["RootChunk"]["nodeData"]["Data"]
// Generates the Path and expected Nodes section
RemoverStr += " - path: "+fileName+"\n"+" expectedNodes: "+nodeData.length.toString()+"\n"+" nodeDeletions:"+"\n";
sectorNames += ""+getFileNameWithoutExt(fileName);
sectorNames += ""+shortenSectorName(getFileNameWithoutExt(fileName));

Logger.Info('Identifying Occulder Nodes in '+fileName)
let nodes = json["Data"]["RootChunk"]["nodes"];
Expand All @@ -53,6 +78,7 @@ for (const fileName of sectors) {
for (let index2 in node_data_indexs) {
if (nodeData[index]["NodeIndex"]==node_data_indexs[index2]["index"]) {
RemoverStr += " - index: "+index+"\n type: "+node_data_indexs[index2]["type"]+"\n";
removedNodesCount += 1;
}
}
}
Expand All @@ -61,3 +87,4 @@ for (const fileName of sectors) {
// Saves the File to Resources
wkit.SaveToResources(sectorNames+".xl", RemoverStr);
Logger.Info("Saved "+sectorNames+".xl to resources!");
Logger.Info("Removed "+removedNodesCount+" nodes from "+removedSectorCount+" sectors!")

0 comments on commit 6670471

Please sign in to comment.