Skip to content

Instantly share code, notes, and snippets.

@heolin
Created July 4, 2018 22:11
Show Gist options
  • Save heolin/ed1139428b8bee02cd3e012ae146edac to your computer and use it in GitHub Desktop.
Save heolin/ed1139428b8bee02cd3e012ae146edac to your computer and use it in GitHub Desktop.
Adjust obj file scale
import os
def adjust_directory(directory_path):
def adjust_file(file_path):
lines = open(file_path).read().split('\n')
scale = 0.1
with open(file_path, "w") as output_file:
for line in lines:
if line.startswith("v "):
splited = line.split(' ')
splited[1] = str(round(float(splited[1]) * scale, 5)-0.5)
splited[2] = str(round(float(splited[2]) * scale, 5))
splited[3] = str(round(float(splited[3]) * scale, 5)+0.5)
line = " ".join(splited)
output_file.write(line+"\n")
for file_name in os.listdir(directory_path):
if not file_name.endswith(".obj"):
continue
file_path = os.path.join(directory_path, file_name)
adjust_file(file_path)
adjust_directory("/home/wojciech/private/asset_forge/Collections/OBJ format")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment