Skip to content

Commit

Permalink
v1.2: Release.
Browse files Browse the repository at this point in the history
  • Loading branch information
loonaticx committed Mar 8, 2021
1 parent 4bb9489 commit b900780
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 43 deletions.
1 change: 1 addition & 0 deletions PANDA_BIN_PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:/Panda3D-1.11.0-x64/bin
2 changes: 1 addition & 1 deletion PPYTHON_PATH
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"C:/Panda3D-1.11.0-x64-MAYAFIX/python/ppython.exe"
"C:/Panda3D-1.11.0-x64/python/ppython.exe"
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# HyperModelConvert / HyperMC
# HyperModelConvert / HyperMC v1.2.0
This tool is used to bulk convert Panda3D models to a different file format.

Currently this script supports:
* bam2egg
* egg2bam
* egg2maya<version> (default:2016)
* egg2maya
* egg2maya_legacy
* maya2egg
* maya2egg_legacy
* egg2obj
* obj2egg
* Legacy conversion*

By default, the Maya version is set to 2016.
With the release of v1.2.0., the script will initially run for a Maya server instead of launching a new instance per model. This speeds up conversion time significantly.
You can run any of the ``_legacy`` commands if you are having issues with the Maya server.

# Dependencies
- Python 3.8+
- argparse Python package.
- psutil Python package.
- Installation of Panda3D with Maya support (optional, only required for maya conversions.)

# Instructions
By default, the program will search for a ``bin`` folder within the same directory. To ensure that the script is pointing to the correct ``bin`` folder, you can either:
- Replace the first line for the correct directory in ``PANDA_BIN_PATH`` file, adding the argument ``--fromfile``
- Set the filepath by adding --bindir <FILEPATH HERE> as an argument.

If you decide to run the batch scripts, please make sure to edit the ``PPYTHON_PATH`` file to point to the correct Panda Python executable location.

For a list of commands, run either
``python convert.py --help``, or ``python convert.py --pargs`` for egg2bam/bam2egg arguments.
Expand All @@ -15,17 +35,8 @@ Example usage:
``python convert.py --bam2egg --phase 5 5.5 6``
Will convert any bam files into egg files located within phase 5, 5.5, and 6.

``python convert.py --bam2egg --legacy panda105 --all_phases``
Will convert any bam files using a legacy method (Panda3D 1.0.5) in all phase files within the directory.

# Dependencies
- Python 3.8+
- argparse Python package.
- Installation of Panda3D with Maya support (optional, only required for maya conversions.)
``python convert.py --egg2maya --mayaver 2019 --all-phases --fromfile``
Will start a maya2egg2019 conversion server, and convert any egg files to maya binaries from all the phases. It will look for the Panda3D binaries from the directory located in the ``PANDA_BIN_PATH`` file.

# Legacy Conversion
Currently, this tool supports older Panda3D versions, including:
- 1.0.5
- 1.5.0
- 1.6.2
- 1.7.2
With the release of v.1.2.0., legacy BAM conversions have been deprecated. However, if you would still like to download the binaries of older Panda versions, check the releases tab.
79 changes: 52 additions & 27 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
Date: 6/26/20
"""
import subprocess, os, time, sys, re
import psutil
import argparse

# todo: custom maya arg(s) incl. file convert (bam2maya, etc.)
# support for panda args, i.e. with bam2egg -h
# bonus: --panda_path <path/to/panda3d/bin>

"""
# Argument Handler #
Expand All @@ -22,13 +22,19 @@
parser.add_argument('--all-phases', '--all_phases', action='store_true', help='Convert all phase files folders. (3 to 14)')
parser.add_argument('--selected_phases', '--phase', action='extend', nargs='+', type=str, metavar='3 3.5 4', help='List phase files folders to convert.')

parser.add_argument('--bindir', '-bin', '-b', action='store', type=str, help='Set folder path to desired Panda3D bin location', default="bin/")
parser.add_argument('--fromfile', '--file', '-f', action='store_true', help='Use this flag to read the path from the PANDA_BIN_PATH folder.')

## Bam
parser.add_argument('--bam2egg', '--to_egg', '--to-egg', action='store_true', help='Convert BAM file(s) into EGG file(s).')
parser.add_argument('--egg2bam', '--to_bam', '--to-bam', action='store_true', help='Convert EGG file(s) into BAM file(s).')

## Maya
parser.add_argument('--egg2maya', action='store_true', help='Convert EGG file(s) into Maya Binary files.')
parser.add_argument('--maya2egg', action='store_true', help='Convert Maya Binary files into EGG file(s).')
parser.add_argument('--egg2maya_legacy', action='store_true', help='Convert EGG file(s) into Maya Binary files. [LEGACY]')

parser.add_argument('--maya2egg', action='store_true', help='Convert Maya Binary file(s) into EGG files.')
parser.add_argument('--maya2egg_legacy', action='store_true', help='Convert Maya Binary files into EGG file(s). [LEGACY]')
parser.add_argument('--mayaver', '--mayaversion', '-mv', action='store', nargs='?', type=str, default='2016', metavar='MayaVersion', help='Use specific maya version. (Default is 2016)')

## Obj
Expand All @@ -43,7 +49,9 @@
parser.add_argument('--verbose', '-v', action='store_true', help='Enable verbose output.')
parser.add_argument('--overwrite', '-o', action='store_true', help='Overwrite preexisting files.')
parser.add_argument('--recursive', '-r', action='store_true', help='Convert all folders in the directory, recursively. Typically used if there are models outside of "phase" folders.')
parser.add_argument('--legacy', '--use-legacy', type=str, choices=['panda105', 'panda150', 'panda162', 'panda172'], action='store', help='Use Panda3D 1.0.5 or Panda3D 1.5.0 instead to convert LEGACY bams.')

# Deprecating this feature. Go get your own Panda!
#parser.add_argument('--legacy', '--use-legacy', type=str, choices=['panda105', 'panda150', 'panda162', 'panda172', 'panda181'], action='store', help='Use Panda3D 1.0.5 or Panda3D 1.5.0 instead to convert LEGACY bams.')
#parser.add_argument('--panda_args', '--pargs', action='extend', nargs='+', type=str, help='Optional Panda3D args to pass. To get a full list, run `convert.py --pargs help`.')
# Note: Removing pargs cause I dunno how to make this pretty at the moment

Expand All @@ -63,8 +71,10 @@
egg2bam = ['.egg', '.bam', 'egg2bam.exe']

## Maya
egg2maya = ['.egg', '.mb', 'egg2maya%s.exe' % args.mayaver]
maya2egg = ['.mb', '.egg', 'maya2egg%s.exe' % args.mayaver]
egg2maya_legacy = ['.egg', '.mb', 'egg2maya%s.exe' % args.mayaver]
egg2maya = ['.egg', '.mb', 'egg2maya_client.exe']
maya2egg_legacy = ['.mb', '.egg', 'maya2egg%s.exe' % args.mayaver]
maya2egg = ['.mb', '.egg', 'egg2maya_client.exe']

## Obj
obj2egg = ['.obj', '.egg', 'obj2egg.exe']
Expand All @@ -80,8 +90,12 @@
settings = bam2egg
elif args.egg2bam:
settings = egg2bam
elif args.egg2maya_legacy:
settings = egg2maya_legacy
elif args.egg2maya:
settings = egg2maya
elif args.maya2egg_legacy:
settings = maya2egg_legacy
elif args.maya2egg:
settings = maya2egg
elif args.obj2egg: # obj->egg
Expand All @@ -93,39 +107,35 @@
elif args.egg2fbx: # egg->fbx
settings = egg2obj

maya_mode = args.egg2maya or args.maya2egg
maya_legacy = args.egg2maya_legacy or args.maya2egg_legacy

#optionalArgs = []
overwriteArg = []
#if args.panda_args is not None:
# args.panda_args = [" -" + arg for arg in args.panda_args]
# Grr this is so hacky.
# optionalArgs = (args.panda_args)

if args.overwrite:
overwriteArg.append('-o')



"""
# Panda3D Version Bam Support [Docme]
Panda3D 1.6.2 ~ 6.14 through 6.19
? RobotToon: 6.14 through 6.18 bams.

"""
legacyDir = {
'panda105': "bin/panda105/",
'panda150': "bin/panda150/",
'panda162': "bin/panda162/",
'panda172': "bin/panda172"
}
defaultBin = "bin/" if not args.legacy else legacyDir[args.legacy]
if args.fromfile:
if not os.path.isfile("PANDA_BIN_PATH"):
print("Error: Cannot read from the PANDA_BIN_PATH file. Please make sure the file exists in this directory and try again.")
sys.exit()
path = open("PANDA_BIN_PATH", 'r').readline()
defaultBin = path
else:
defaultBin = args.bindir

# Make sure a conversion method was properly inputted
if settings is None:
if args.panda_args is not None:
print("########################################################################################################################")
subprocess.call(['%s/%s' % (defaultBin, 'egg2bam'), '-h'])
subprocess.run(['%s/%s' % (defaultBin, 'egg2bam'), '-h'])
print("########################################################################################################################")
subprocess.call(['%s/%s' % (defaultBin, 'bam2egg'), '-h'])
subprocess.run(['%s/%s' % (defaultBin, 'bam2egg'), '-h'])
print("########################################################################################################################")
parser.print_help()
sys.exit()
Expand All @@ -141,6 +151,21 @@
if verbose and selectedPhases:
print(selectedPhases)

DETACHED_PROCESS = 0x00000008 # A tad hacky, but we need this for the Maya service.
mayaProcess = tool[0:8]
mayaServer = str(mayaProcess+args.mayaver+"_bin.exe") # maya2egg20xx_bin.exe
def checkMayaServer():
if not mayaServer in (p.name() for p in psutil.process_iter()):
if verbose:
print("Attempting to start the Maya server...")
subprocess.Popen(['%s/%s%s' % (defaultBin, mayaProcess, args.mayaver), "-server"], creationflags=DETACHED_PROCESS)
if verbose:
print("Sleeping for 5 seconds...")
time.sleep(5) # give it some time
checkMayaServer()
else:
return # It's running, no problem.

# Uses milliseconds for now.
start = int(round(time.time() * 1000))
if recursive: # Recursion time!
Expand Down Expand Up @@ -168,13 +193,13 @@
allFiles.append(file)
for file in allFiles:
newFile = file.replace(inputFile, outputFile)
if os.path.exists(newFile):
if os.path.exists(newFile) and not args.overwrite:
if verbose:
print('%s already exists' % newFile)
continue
if verbose:
print("Converting %s..." % file)
subprocess.call(['%s/%s' % (defaultBin, tool), file] + overwriteArg + [newFile]) # 'bin/panda105' / 'bam2egg[.exe]' optionalArgs file.bam overwriteArg newFile.egg
#print(['%s/%s' % (defaultBin, tool), file] + [overwriteArg] + [newFile])
#print(['%s/%s' % (defaultBin, tool), ''.join(optionalArgs), file] + [overwriteArg] + [newFile])
if maya_mode and not maya_legacy:
checkMayaServer() # Check & run for the Maya server.
subprocess.run(['%s/%s' % (defaultBin, tool), file] + overwriteArg + [newFile]) # 'bin/panda105' / 'bam2egg[.exe]' optionalArgs file.bam overwriteArg newFile.egg
print("Conversion complete. Total time elapsed: %d ms" % (int(round(time.time() * 1000)) - start))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
argparse
psutil

0 comments on commit b900780

Please sign in to comment.