Created
September 19, 2019 15:22
-
-
Save eric-schleicher/b2abd7bb72c24ffd9d602e4e73955f33 to your computer and use it in GitHub Desktop.
Batch Utility for point cloud conversions for ScultprVR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# this process based on the utility located here: | |
# https://github.com/EX0l0N/ply-to-SculptrVR-csv | |
import os, subprocess | |
util_location = "third_party" + os.sep + "ply-to-SculptrVR-csv" + os.sep + "ply2csv.exe" | |
csv_destination = "J:\\SteamLibrary\\steamapps\\common\\sculptrvr\\SculptrVR\\CSVs" | |
def prepare_file(source_file): | |
# TODO IMPLEMENT SOURCE PREP AUTOMATION | |
# do some work here to run meshlab scripts to prepare | |
# 1) screened poisson reconstruction (assumings it's dense) | |
# 2) change layer (based on input filename) | |
# 3) Transform: scale, Normalize | |
# - uniform scaling | |
# - Scale to unit bbox: true | |
# - freeze matrix:true | |
# 4) export | |
print "preparing mesh: " + source_file | |
completed_filename = source_file.split(".")[-1:] + "processed.ply" | |
return completed_filename | |
def convert_file(file_to_process, scale=500, sphere=None): | |
args = [] | |
args.append(util_location) | |
args.append(str(scale)) | |
if sphere is not None: | |
args.append(str(sphere)) | |
args.append(file_to_process) | |
# result =os.system(util_location + " " + " ".join(args)) | |
output = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
stdout, stderr = output.communicate() | |
for item in stdout.split("\n"): | |
print item | |
if stderr is not None: | |
print "there was an error" | |
for item in stderr: | |
print item | |
return False | |
else: | |
# format the details for the response | |
args.pop(0) # remove the first element | |
args[-1] = args[-1].split(os.sep)[-1] # give back the sanitized filename with no extension | |
return True, args | |
def generate_iterations(): | |
# THIS DETERMINES THE SETTING FOR EACH ITERATION | |
# todo consider using open3d library to analyse input files to automatically determine sane values. | |
return [ | |
[400,None], | |
[600,None], | |
[1200,None] | |
] | |
if __name__ == '__main__': | |
# example files | |
# source_file = "J:\\3D\\Arnell - Kitchen\\export-for-scupltrvr2.ply" | |
# source_file = "J:\\SculptrVR-prep\\back-room-700kV.ply" | |
# source_file = "J:\\SculptrVR-prep\\garage-001m-voxel.ply" | |
source_file = "J:\\SculptrVR-prep\\back-room-15mV.ply" | |
#build a list of different settings to try. | |
batch = generate_iterations() | |
for iteration in batch: | |
result, details = convert_file(source_file, iteration[0], iteration[1]) | |
if result: | |
# now copy the file with some | |
filename_token = "sculptrVR" | |
if len(details) == 2: | |
new_filename = os.path.splitext(details[1])[0] + " - " + filename_token + " [scale_" + details[0] + "].csv" | |
else: | |
new_filename = os.path.splitext(details[2])[0] + " - " + filename_token + " [scale_" + details[0] + "__sphere_" + details[1] + "].csv" | |
# Move the file to the | |
os.rename("Data.csv", csv_destination + os.sep + new_filename) | |
# todo // implement some form of error handling | |
# if we get here ; we're all good | |
print "batch process complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment