加入所有顶点

This commit is contained in:
xsl
2025-09-27 20:05:03 +08:00
parent cb7b600eda
commit 701187ec11
6 changed files with 5127 additions and 15 deletions
+12 -12
View File
@@ -28,7 +28,7 @@ v 0.488619 0.569468 -0.058394
# 顶点 12
v 0.489100 0.577040 -0.054379
# 顶点 13
v 0.489590 0.582667 -0.048960
v 0.489590 0.582667 -0.148960
# 顶点 14
v 0.489473 0.584441 -0.046532
# 顶点 15
@@ -86,7 +86,7 @@ v 0.442136 0.577787 -0.030592
# 顶点 41
v 0.460486 0.580604 -0.040976
# 顶点 42
v 0.449902 0.585057 -0.029852
v 0.449902 0.585057 -0.129852
# 顶点 43
v 0.424784 0.607133 -0.013466
# 顶点 44
@@ -124,7 +124,7 @@ v 0.457224 0.513448 -0.033789
# 顶点 60
v 0.468835 0.518365 -0.040557
# 顶点 61
v 0.430323 0.595835 -0.006864
v 0.430323 0.595835 -0.016864
# 顶点 62
v 0.434046 0.594322 -0.016066
# 顶点 63
@@ -164,7 +164,7 @@ v 0.462569 0.502973 -0.052049
# 顶点 80
v 0.453032 0.587042 -0.024408
# 顶点 81
v 0.463565 0.584066 -0.032540
v 0.463565 0.584066 -0.132540
# 顶点 82
v 0.475954 0.582743 -0.049292
# 顶点 83
@@ -194,9 +194,9 @@ v 0.489106 0.515433 -0.057748
# 顶点 95
v 0.444558 0.590508 -0.015345
# 顶点 96
v 0.441923 0.592812 -0.021639
v 0.441923 0.592812 -0.121639
# 顶点 97
v 0.472108 0.524822 -0.044049
v 0.472108 0.524822 -0.144049
# 顶点 98
v 0.452429 0.525860 -0.023909
# 顶点 99
@@ -616,15 +616,15 @@ v 0.525280 0.517623 -0.041306
# 顶点 306
v 0.554770 0.598001 -0.030063
# 顶点 307
v 0.546347 0.597644 -0.039092
v 0.546347 0.517644 -0.139092
# 顶点 308
v 0.550659 0.596784 -0.031554
# 顶点 309
v 0.519226 0.502614 -0.061694
# 顶点 310
v 0.531728 0.586989 -0.041326
v 0.531728 0.586989 -0.141326
# 顶点 311
v 0.519403 0.585350 -0.042113
v 0.519403 0.585350 -0.142113
# 顶点 312
v 0.504849 0.583414 -0.043507
# 顶点 313
@@ -652,9 +652,9 @@ v 0.684167 0.542131 0.122129
# 顶点 324
v 0.541925 0.593224 -0.031733
# 顶点 325
v 0.543481 0.595509 -0.038218
v 0.543481 0.635509 -0.138218
# 顶点 326
v 0.510596 0.525039 -0.049117
v 0.510596 0.525039 -0.149117
# 顶点 327
v 0.536637 0.526958 -0.034873
# 顶点 328
@@ -816,7 +816,7 @@ v 0.524505 0.604488 -0.054807
# 顶点 406
v 0.530787 0.623891 -0.049387
# 顶点 407
v 0.544580 0.592745 -0.037092
v 0.544580 0.592745 -0.137092
# 顶点 408
v 0.547562 0.591380 -0.037639
# 顶点 409
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+147
View File
@@ -0,0 +1,147 @@
def process_obj_file(input_file):
"""
处理OBJ文件,统计所有三角形顶点索引并找出缺失的索引
"""
# 用于存储所有三角形顶点索引
triangle_indices = set()
try:
with open(input_file, 'r', encoding='utf-8') as file:
for line_num, line in enumerate(file, 1):
line = line.strip()
# 只处理面数据(以'f'开头)
if line.startswith('f '):
# 分割面数据
parts = line.split()
# 检查是否是三角形面(应该有4个部分:f + 3个顶点)
if len(parts) == 4:
try:
# 提取顶点索引(OBJ索引从1开始,转换为从0开始)
indices = []
for part in parts[1:]: # 跳过第一个'f'
# 处理可能的纹理/法线索引(格式:顶点索引/纹理索引/法线索引)
vertex_part = part.split('/')[0]
index = int(vertex_part) - 1 # 转换为0-based索引
indices.append(index)
# 添加到集合中
triangle_indices.update(indices)
except ValueError as e:
print(f"警告: 第{line_num}行解析错误: {line} - {e}")
else:
print(f"警告: 第{line_num}行不是三角形面: {line}")
except FileNotFoundError:
print(f"错误: 文件 '{input_file}' 未找到")
return
except Exception as e:
print(f"错误: 读取文件时发生错误 - {e}")
return
# 统计结果
print(f"找到的三角形顶点索引数量: {len(triangle_indices)}")
print(f"最大索引值: {max(triangle_indices) if triangle_indices else ''}")
print(f"最小索引值: {min(triangle_indices) if triangle_indices else ''}")
# 找出0-478中缺失的索引
all_indices = set(range(0, 479)) # 0到478
missing_indices = all_indices - triangle_indices
print(f"\n缺失的索引 (0-478中未使用的):")
if missing_indices:
# 将缺失的索引排序并分组显示
missing_sorted = sorted(missing_indices)
print(f"总共缺失 {len(missing_sorted)} 个索引:")
# 分组显示,每行显示10个
for i in range(0, len(missing_sorted), 10):
group = missing_sorted[i:i+10]
print(" ".join(f"{idx:3d}" for idx in group))
else:
print("没有缺失的索引,0-478全部被使用")
# 额外信息:显示使用的索引范围
if triangle_indices:
used_sorted = sorted(triangle_indices)
print(f"\n使用的索引范围: {used_sorted[0]} - {used_sorted[-1]}")
# 检查是否有超出0-478范围的索引
out_of_range = [idx for idx in triangle_indices if idx < 0 or idx > 478]
if out_of_range:
print(f"警告: 发现超出0-478范围的索引: {sorted(out_of_range)}")
def process_obj_file_advanced(input_file):
"""
高级版本:提供更详细的分析信息
"""
triangle_indices = set()
face_count = 0
try:
with open(input_file, 'r', encoding='utf-8') as file:
for line in file:
line = line.strip()
if line.startswith('f '):
parts = line.split()
if len(parts) >= 4: # 三角形或多边形
face_count += 1
try:
for part in parts[1:4]: # 只取前三个顶点(对于三角形)
vertex_part = part.split('/')[0]
index = int(vertex_part) - 1
triangle_indices.add(index)
except ValueError:
continue
except Exception as e:
print(f"错误: {e}")
return
# 基本统计
all_indices = set(range(0, 479))
missing_indices = all_indices - triangle_indices
print("=" * 50)
print("高级版本分析结果:")
print("=" * 50)
print(f"总面数: {face_count}")
print(f"使用的唯一顶点索引数: {len(triangle_indices)}")
print(f"缺失的顶点索引数: {len(missing_indices)}")
print(f"顶点索引使用率: {len(triangle_indices)/479*100:.1f}%")
if missing_indices:
missing_sorted = sorted(missing_indices)
print(f"\n缺失的索引列表:")
# 显示连续的缺失范围
ranges = []
start = missing_sorted[0]
for i in range(1, len(missing_sorted)):
if missing_sorted[i] != missing_sorted[i-1] + 1:
ranges.append((start, missing_sorted[i-1]))
start = missing_sorted[i]
ranges.append((start, missing_sorted[-1]))
for rstart, rend in ranges:
if rstart == rend:
print(f" {rstart}")
else:
print(f" {rstart} - {rend}")
if __name__ == "__main__":
input_file = "face.obj" # 默认输入文件
# 使用基本版本
print("基本版本结果:")
process_obj_file(input_file)
print("\n" + "="*60 + "\n")
# 使用高级版本
print("高级版本结果:")
process_obj_file_advanced(input_file)
+2 -2
View File
@@ -157,7 +157,7 @@ def process_obj_file_advanced(input_file, tolerance=1e-6):
if __name__ == "__main__":
input_file = "face.obj" # 默认输入文件
input_file = "face_new.obj" # 默认输入文件
# 使用基本版本
print("基本版本结果:")
@@ -167,4 +167,4 @@ if __name__ == "__main__":
# 使用高级版本(带容差)
print("高级版本结果(带容差):")
process_obj_file_advanced(input_file, tolerance=0.0024)
process_obj_file_advanced(input_file, tolerance=0.005)
+3 -1
View File
@@ -120,8 +120,10 @@ def write_obj_file(filename, vertices, faces, normals, original_has_normals=Fals
file.write(f"# 面数: {len(faces)}\n\n")
# 写入顶点
# for i, vertex in enumerate(vertices):
# file.write(f"v {vertex[0]:.6f} {vertex[1]:.6f} {vertex[2]:.6f}\n")
for i, vertex in enumerate(vertices):
file.write(f"v {vertex[0]:.6f} {vertex[1]:.6f} {vertex[2]:.6f}\n")
file.write(f"v {vertex[0]*100:.6f} {vertex[1]*100:.6f} {vertex[2]*100:.6f}\n")
file.write("\n")