mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 13:44:36 +02:00
Fix loading relative files
This commit is contained in:
parent
840f3a3a2e
commit
ad2c4718a3
3 changed files with 6 additions and 65 deletions
|
@ -40,7 +40,7 @@ public:
|
||||||
auto lastSlash = filename.rfind('/');
|
auto lastSlash = filename.rfind('/');
|
||||||
result = filename.substr(0, lastSlash + 1);
|
result = filename.substr(0, lastSlash + 1);
|
||||||
} else {
|
} else {
|
||||||
std::string result = QFileInfo(filename.c_str()).absoluteDir().canonicalPath().toStdString();
|
result = QFileInfo(filename.c_str()).absoluteDir().canonicalPath().toStdString();
|
||||||
if (*result.rbegin() != '/') {
|
if (*result.rbegin() != '/') {
|
||||||
result += '/';
|
result += '/';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def scriptRelative(*paths):
|
|
||||||
scriptdir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
||||||
result = os.path.join(scriptdir, *paths)
|
|
||||||
result = os.path.realpath(result)
|
|
||||||
result = os.path.normcase(result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FrameProcessor:
|
|
||||||
def __init__(self, filename):
|
|
||||||
self.filename = filename
|
|
||||||
dir, name = os.path.split(self.filename)
|
|
||||||
self.dir = dir
|
|
||||||
self.ktxDir = os.path.join(self.dir, 'ktx')
|
|
||||||
os.makedirs(self.ktxDir, exist_ok=True)
|
|
||||||
self.resDir = scriptRelative("../interface/resources")
|
|
||||||
|
|
||||||
if (name.endswith(".json")):
|
|
||||||
self.name = name[0:-5]
|
|
||||||
else:
|
|
||||||
self.name = name
|
|
||||||
self.filename = self.filename + '.json'
|
|
||||||
|
|
||||||
with open(self.filename, 'r') as f:
|
|
||||||
self.json = json.load(f)
|
|
||||||
|
|
||||||
|
|
||||||
def processKtx(self, texture):
|
|
||||||
if texture is None: return
|
|
||||||
if not 'ktxFile' in texture: return
|
|
||||||
sourceKtx = texture['ktxFile']
|
|
||||||
if sourceKtx.startswith(':'):
|
|
||||||
sourceKtx = sourceKtx[1:]
|
|
||||||
while sourceKtx.startswith('/'):
|
|
||||||
sourceKtx = sourceKtx[1:]
|
|
||||||
sourceKtx = os.path.join(self.resDir, sourceKtx)
|
|
||||||
sourceKtxDir, sourceKtxName = os.path.split(sourceKtx)
|
|
||||||
destKtx = os.path.join(self.ktxDir, sourceKtxName)
|
|
||||||
if not os.path.isfile(destKtx):
|
|
||||||
shutil.copy(sourceKtx, destKtx)
|
|
||||||
newValue = 'ktx/' + sourceKtxName
|
|
||||||
texture['ktxFile'] = newValue
|
|
||||||
|
|
||||||
|
|
||||||
def process(self):
|
|
||||||
for texture in self.json['textures']:
|
|
||||||
self.processKtx(texture)
|
|
||||||
|
|
||||||
with open(self.filename, 'w') as f:
|
|
||||||
json.dump(self.json, f, indent=2)
|
|
||||||
|
|
||||||
fp = FrameProcessor("D:/Frames/20190114_1629.json")
|
|
||||||
fp.process()
|
|
||||||
|
|
||||||
|
|
||||||
#C:\Users\bdavi\git\hifi\interface\resources\meshes
|
|
|
@ -36,7 +36,10 @@ class FrameProcessor:
|
||||||
if not 'ktxFile' in texture: return
|
if not 'ktxFile' in texture: return
|
||||||
sourceKtx = texture['ktxFile']
|
sourceKtx = texture['ktxFile']
|
||||||
if sourceKtx.startswith(':'):
|
if sourceKtx.startswith(':'):
|
||||||
sourceKtx = os.path.join(self.resDir, sourceKtx[3:])
|
sourceKtx = sourceKtx[1:]
|
||||||
|
while sourceKtx.startswith('/'):
|
||||||
|
sourceKtx = sourceKtx[1:]
|
||||||
|
sourceKtx = os.path.join(self.resDir, sourceKtx)
|
||||||
sourceKtxDir, sourceKtxName = os.path.split(sourceKtx)
|
sourceKtxDir, sourceKtxName = os.path.split(sourceKtx)
|
||||||
destKtx = os.path.join(self.ktxDir, sourceKtxName)
|
destKtx = os.path.join(self.ktxDir, sourceKtxName)
|
||||||
if not os.path.isfile(destKtx):
|
if not os.path.isfile(destKtx):
|
||||||
|
@ -52,7 +55,7 @@ class FrameProcessor:
|
||||||
with open(self.filename, 'w') as f:
|
with open(self.filename, 'w') as f:
|
||||||
json.dump(self.json, f, indent=2)
|
json.dump(self.json, f, indent=2)
|
||||||
|
|
||||||
fp = FrameProcessor("D:/Frames/20190110_1635.json")
|
fp = FrameProcessor("D:/Frames/20190112_1647.json")
|
||||||
fp.process()
|
fp.process()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue