这些文件出现问题的原因是大偏移量加上 32 位浮点值。在这种情况下,所有对象都使用相同的地理原点,可能在 0.000N/0.000E 的纬度/经度
几乎所有的 3D 图形程序都使用 32 位浮点值来存储每个点的位置,偏移量和 32 位值的组合会导致部分精度丢失。 32位浮点数大约有7位十进制精度,因此示例文件中4460688的偏移量完全占主导地位,有效地将模型从1mm分辨率的数据切到1m分辨率的数据。长三角形的原因是由于偏移的不对称,在一个方向上丢失的数据较多。
解决方案是在使用 3D 软件导入对象之前应用一些偏移量以使对象靠近原点。
我写了一个可以帮助解决这个问题的快速 python 脚本:https://gitlab.umich.edu/lsa-ts-rsp/xr-shiftOBJ/-/blob/main/shiftOBJ.py
import re # regex
def shiftFile(inFileName, outFileName, offset):
with open(inFileName) as myInFile:
with open(outFileName, 'w') as myOutFile:
for line in myInFile:
myOutFile.write(shiftLine(line, offset))
def shiftLine(inLine, offset):
#if a line is a vertex then apply the shift and drop vertex colors
lineRegex = re.compile('v (\d+\.\d+) (\d+\.\d+) (\d+\.\d+)')
m = lineRegex.match(inLine)
if m and len(m.groups()) >= 3:
outLine = 'v ' + "{:.3f}".format(float(m.groups()[0]) + offset[0]) + ' ' + "{:.3f}".format(float(m.groups()[1]) + offset[1]) + ' ' + "{:.3f}".format(float(m.groups()[2]) + offset[2]) + '\n'
return outLine
else:
return inLine
if __name__ == '__main__':
inFile = '/Users/crstock/Documents/Unreal Projects/Olynthos Data/B88DW18.obj'
outFile = '/Users/crstock/Documents/Unreal Projects/Olynthos Data/B88DW18_shifted.obj'
offset = [-445070, -4460680, -59.0]
shiftFile(inFile, outFile, offset)
这会将偏移量应用于所有顶点线,而不会影响其他线。通过对多个输入文件使用相同的偏移值,您可以保持相对偏移,以便相关对象适当地组合在一起。