Jump to content
Official BF Editor Forums
Sign in to follow this  
Dnamro

A Wip New Navmesh Process Script

Recommended Posts

I am working on a script/batch file that can handle the entire process and automate as much as possible using a combination of batch (bat) file and python scripts. I like starting from a batch file because if I set it to pause at the end, you can see right off if it ended good or if there was an error.

This my WIP script. It is is set up to navmesh bf2 mods, but can easily be set up for any BF2 or BF2142 mod. It displays a selection of levels to navmesh and then asks to create or fix a navmesh. Normally you create the navmesh, edit it with a 3dsmax or maya and then 'fix' the results, load up the editor to convert the 'fixed' mesh into Bf2 pathfinding files (which is the process to load the GTS data and save quad trees). My script combines the create and fix process into one batch file, and loads the editor. It also sets up the navmesh work area and copies the GTSdata from the map to the work area.

I have a script for each mod that I create navmeshes for.

navmesh.bat file:

@echo off
:start
cls
echo --------------------------------------
echo Battlefield 2 XPACK Navmesh Generation
echo (c)2005 Digital Illusions CE
echo --------------------------------------

REM make sure work dir exists
if not exist work md work
set mod_name=edit_Bf2
set level_name=
set cl_userinp=
set fixnavmesh=

rem SET UP CHOOSE LEVEL OPTIONS AND TAKE USER INPUT
:choose_level
echo.
echo ----------Map List------------------
echo.
echo A) Eastern_Showdown
echo  Operation_Blue_Pearl


set /p cl_userinp=Which level would you like to create/fix navmesh for? (A...Z):
set cl_userinp=%cl_userinp:~0,1%
if "%cl_userinp%"=="A" goto level1
if "%cl_userinp%"=="a" goto level1
if "%cl_userinp%"=="B" goto level2
if "%cl_userinp%"=="b" goto level2
rem if "%cl_userinp%"=="C" goto level3
rem if "%cl_userinp%"=="c" goto level3
rem if "%cl_userinp%"=="D" goto level4
rem if "%cl_userinp%"=="d" goto level4
rem if "%cl_userinp%"=="E" goto level5
rem if "%cl_userinp%"=="e" goto level5
rem if "%cl_userinp%"=="F" goto level6
rem if "%cl_userinp%"=="f" goto level6
rem if "%cl_userinp%"=="G" goto level7
rem if "%cl_userinp%"=="g" goto level7
rem if "%cl_userinp%"=="H" goto level8
rem if "%cl_userinp%"=="h" goto level8
rem if "%cl_userinp%"=="I" goto level9
rem if "%cl_userinp%"=="i" goto level9
rem if "%cl_userinp%"=="J" goto level10
rem if "%cl_userinp%"=="j" goto level10
rem if "%cl_userinp%"=="K" goto level11
rem if "%cl_userinp%"=="k" goto level11
rem if "%cl_userinp%"=="L" goto level12
rem if "%cl_userinp%"=="l" goto level12


echo ---- invalid response --------
pause
goto choose_level

:level1
set level_name=Eastern_Showdown
goto fix_or_create
:level2
set level_name=Operation_Blue_Pearl
goto fix_or_create
:level3
set level_name=
goto fix_or_create
:level4
set level_name=
goto fix_or_create
:level5
set level_name=
goto fix_or_create
:level6
set level_name=
goto fix_or_create
:level7
set level_name=
goto fix_or_create
:level8
set level_name=
goto fix_or_create
:level9
set level_name=
goto fix_or_create








rem SET WHETHER TO FIX OR CREATE NAVMESH
:fix_or_create
echo.
echo --------------------------------------
echo Start by creating a new navmesh
echo Only fix a navmesh after you have created one
echo.
echo C) Create new NavMesh
echo F) Fix NavMesh
echo L) Launch editor

set /p cl_userinp=Choice? (C/F/L):
set cl_userinp=%cl_userinp:~0,1%
if "%cl_userinp%"=="C" goto create
if "%cl_userinp%"=="c" goto create
if "%cl_userinp%"=="F" goto fix
if "%cl_userinp%"=="f" goto fix
if "%cl_userinp%"=="L" goto Editor_choice
if "%cl_userinp%"=="l" goto Editor_choice


echo invalid answer
pause

goto fix_or_create



:create


echo Set up navmesh work area if it does not exist

rem create the work\level name folder needed
if not exist work\%level_name% md work\%level_name%

rem check for GTSdtat\meshes - and delete if they exist
if exist work\%level_name%\GTSData\ goto del_GTSdata

rem create GTSData folder
echo setup navmesh\work\%level_name%\GTSData\
md work\%level_name%\GTSData\

goto copy_GTSdata

:del_GTSdata
echo Cleaning up navmesh work area: navmesh\work\%level_name%\
del /Q /F work\%level_name%\GTSData\Meshes\*.*

:copy_GTSdata
rem copy the GTSdata from the map to the work area
echo Copying GTSdata files from the %level_name% to the work area
xcopy ..\mods\%mod_name%\levels\%level_name%\GTSData\Meshes\*.* work\%level_name%\GTSData\Meshes\


REM call python script to create the navmesh
echo Generating navmesh files in: navmesh\work\%level_name%\GTSData\Meshes\
GenerateNavmeshBFSP.py %mod_name% %level_name%

echo Navmesh generated - edit navmesh now and remove islands
pause


:fix
if not exist work\%level_name% goto levelerror

REM remove read-only flag
echo remove read only flag from work\%level_name%\GTSData\debug and \meshes folders
attrib -r work\%level_name%\GTSData\debug\*.* /s
attrib -r work\%level_name%\GTSData\meshes\*.* /s

echo copy work\%level_name%\GTSData\Output\infantry.obj and vehicle.obj to work\%level_name%\GTSData\
copy work\%level_name%\GTSData\Output\infantry.obj work\%level_name%\GTSData\
copy work\%level_name%\GTSData\Output\vehicle.obj work\%level_name%\GTSData\

echo cd work\%level_name%\GTSData
cd work\%level_name%\GTSData

echo delete the infantry and vehicle _fix obj files
if exist infantry_fix.obj del infantry_fix.obj
if exist vehicle_fix.obj del vehicle_fix.obj

REM rename files to what navmesh.exe expects
echo rename infantry and vehicle obj files to [name]_fix
rename infantry.obj infantry_fix.obj
rename vehicle.obj vehicle_fix.obj

cd..
cd..
cd..

echo ready to start navmesh process


navmesh.exe -dir work\%level_name%\gtsdata -cmd export -mode infantry -in infantry_fix.obj
navmesh.exe -dir work\%level_name%\gtsdata -cmd export -mode vehicle -in vehicle_fix.obj

echo navmesh process complete


echo restore read only flag: work\%level_name%\GTSData\debug\ and \meshes
REM restore read-only flag?
REM attrib +r work\%level_name%\GTSData\debug\*.* /s
REM attrib +r work\%level_name%\GTSData\meshes\*.* /s

echo copy navmeshed files to map
echo from: work\%level_name%\GTSData\Output\
echo to: ..\mods\%mod_name%\levels\%level_name%\GTSData\Output\
ROBOCOPY work\%level_name%\GTSData\Output\ ..\mods\%mod_name%\levels\%level_name%\GTSData\Output\


echo delete temp work files
REM delete temp files
del work\%level_name%\GTSData\infantry_fix.obj
del work\%level_name%\GTSData\vehicle_fix.obj



echo navmesh optimization completed
echo load the map in the editor now, load GTSdata and save quadtrees
echo  aipathfinding.loadGTSdata and then aipathfinding.savequadtreees
echo and generate the air height map if needed
echo  ai.createheightmap 

echo =========================
echo Hit any key to load editor
echo warning - the map's Aipathfinding files will be deleted 
echo the editor will attempt to create new ones
echo ==========================
pause

cd ..
echo Deleteing old pathfinding mesh...
set FILE=mods\%mod_name%\levels\%level_name%\aiPathfinding\*.*
if exist %FILE% del /Q /F %FILE%

:Editor_choice
rem determine how to launch editor
echo.
echo --------------------------------------
echo You can launch the the BF2 editor with or without scripts
echo Some mods cause the editor to crash when launching with scripts
echo The scripts will convert the navmeshes into Aipathfinding files
echo 1) Launch BF2Editor With Scripts
echo 2) Launch BF2Editor Without Scripts

set /p cl_userinp=Choice: (1 or 2):
set cl_userinp=%cl_userinp:~0,1%
if "%cl_userinp%"=="1" goto editor_scripts
if "%cl_userinp%"=="2" goto editor_Noscripts



echo invalid answer
pause

goto Editor_choice

:editor_scripts
rem *** Start editor to convert it to qtr
echo Launching editor to create aipathfinding files...
cd ..
bf2editor +loadMod %mod_name% +loadLevel %level_name% +runConFileAndClose "saveQuadNoP4" +forceLoadPlugin 

SinglePlayerEditor

rem not using +enableAsserts 0 

goto editor_complete

:editor_Noscripts
rem launching the editor without scripts
echo -------------------------------------------------------------
echo The editor will be started automatically loading the mod and 
echo map_name you are working on.
echo You will have to select the the following commands manually 
echo from the drop down selection boxes in the lower right corner
echo of the BF2 editor:
echo (1st window)	(2nd window)		 (3rd window)
echo aipathfinding -- create heightmap  --  16
echo ai			-- load GTSdata
echo ai			-- savequadtrees
echo -------------------------------------------------------------
echo This will create new files in the map's aipathfinding folder
pause

cd ..
rem load editor without scripts
echo launching editor ...
bf2editor +loadMod %mod_name% +loadLevel %level_name% +forceLoadPlugin SinglePlayerEditor

:editor_complete
cd Navmesh

goto end



:levelerror

echo Level does not exist!
pause

:end
echo	 ---- complete -----
echo ---- press any key to exit ---
pause

GenerateNavmeshBFSP.py Python script:

import os
import sys
import string



################################################################################
def findNocaseString(strings, toFind):
index = 0
lowerToFind = string.lower(toFind)
for entry in strings:
	if (string.lower(entry) == lowerToFind):
		return index
	index = index + 1

return -1

################################################################################
def executeCommand(commandLine):
print "Executing: " + commandLine
result = os.system(commandLine)
print ""
return result

################################################################################

################################################################################


################################################################################
def runNavMeshControl(level, workingFolder):
return executeCommand("NavMeshControl.py " + workingFolder + "\\" + level + "\\GTSData")

################################################################################


################################################################################
def generateNavmesh(level, levelFolder, workingFolder):
print "-----------------------------------------------------------------------"
print "- Generating navmesh..."

# Generate the navmesh
result = runNavMeshControl(level, workingFolder)

print "Done..."
print ""

if (result == 0):
	return True;
else:
	return False;

################################################################################


################################################################################
def printUsage():
print "Usage: GenerateNavmeshLocal.py <modName> <levelName> [p4]"

################################################################################
def main():
if (len(sys.argv) < 3):
	printUsage()
	return

mod = sys.argv[1]
level = sys.argv[2]
p4 = False
cleanup = True

print "########################################################################"
print "#"
print "# Generating navmesh" 
print "#"
print "# mod  = " + mod
print "# level  = " + level
print "#"
print "########################################################################"

levelFolder = "..\\mods\\" + mod + "\\levels" 
workingFolder = "work" 

# Make sure that the level exists
if ( not os.path.isdir(levelFolder + "\\" + level)):
	print "Error: Failed to find level-directory for " + level
	return



if (not generateNavmesh(level, levelFolder, workingFolder)):
	print "Error: Failed to generate navmesh..."
	return


print "Generation completed" 

main()

Note: The map still has to be prepped for navmesh creation (combat area created in a counter clockwise direction, with the useAIpathfinding checked; GTS data created; extra player and vehicle spawns added to help - especially over large open areas).

With my scripts, during the creating process, instead of having the editor load up 2times, the editor is only used at the end of the process - to convert the navmesh in obj format into the Battlefield game format.

Edited by Dnamro

Share this post


Link to post
Share on other sites

It's a good idea, I made one myself because Python was acting up and wasn't accepting the command line arguments from the batch. I have to say it makes it a lot less tedious because you don't have to be at your computer to babysit the process.

Share this post


Link to post
Share on other sites

Dnamro, Hi! Qualifications are not enough. I found a good map (the author does not know) Alcazar. It has no modes SP and COOP. How to increase the number of bots from 16 to 32 or 64, I know. But how to make bots on the map, on which there was none before, I do not know. Can you please tell me how to make a map modes SP and COOP.

Yours faithfully.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×