Repository navigation
Expand file tree
/
Copy pathscale_analysis.py
More file actions
74 lines (61 loc) · 2.86 KB
/
Copy pathscale_analysis.py
File metadata and controls
74 lines (61 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import trimesh
import numpy as np
import os
import sys
def analyze_sizes(obj1_path, obj2_path):
"""Analyze size differences between two OBJ files"""
# Check if files exist
if not os.path.exists(obj1_path):
print("Error: File {} not found".format(obj1_path))
return
if not os.path.exists(obj2_path):
print("Error: File {} not found".format(obj2_path))
return
# Load meshes
print("Loading {}...".format(obj1_path))
mesh1 = trimesh.load(obj1_path)
print("Loading {}...".format(obj2_path))
mesh2 = trimesh.load(obj2_path)
# Get dimensions
dim1 = mesh1.bounds[1] - mesh1.bounds[0]
dim2 = mesh2.bounds[1] - mesh2.bounds[0]
# Calculate scale ratios (how much bigger/smaller mesh2 is compared to mesh1)
scale_ratios = dim2 / np.maximum(dim1, 1e-8)
# Calculate volume and area ratios
volume_ratio = mesh2.volume / max(mesh1.volume, 1e-8)
area_ratio = mesh2.area / max(mesh1.area, 1e-8)
# Output results
print("\nSize Analysis Results:")
print("-" * 50)
print("Mesh 1 ({}):".format(os.path.basename(obj1_path)))
print(" Dimensions (XYZ): {:.4f} x {:.4f} x {:.4f}".format(dim1[0], dim1[1], dim1[2]))
print(" Volume: {:.4f}".format(mesh1.volume))
print(" Surface Area: {:.4f}".format(mesh1.area))
print("\nMesh 2 ({}):".format(os.path.basename(obj2_path)))
print(" Dimensions (XYZ): {:.4f} x {:.4f} x {:.4f}".format(dim2[0], dim2[1], dim2[2]))
print(" Volume: {:.4f}".format(mesh2.volume))
print(" Surface Area: {:.4f}".format(mesh2.area))
print("\nScaling Factors (Mesh2/Mesh1):")
print(" X-axis scale factor: {:.6f}".format(scale_ratios[0]))
print(" Y-axis scale factor: {:.6f}".format(scale_ratios[1]))
print(" Z-axis scale factor: {:.6f}".format(scale_ratios[2]))
print(" Average scale factor: {:.6f}".format(np.mean(scale_ratios)))
print(" Volume ratio: {:.6f}".format(volume_ratio))
print(" Surface area ratio: {:.6f}".format(area_ratio))
# Check for uniform scaling
scale_variation = np.std(scale_ratios)
if scale_variation < 0.01:
print("\nScaling appears to be uniform across all dimensions")
else:
print("\nNon-uniform scaling detected - different scaling in different dimensions")
print("Scale variation (std dev): {:.6f}".format(scale_variation))
# Interpretation
print("\nInterpretation:")
print("- Scale factor > 1: The second mesh is larger than the first")
print("- Scale factor < 1: The second mesh is smaller than the first")
print("- Non-uniform scaling means the object's proportions differ between meshes")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python scale_analysis.py [reference_obj_file] [comparison_obj_file]")
sys.exit(1)
analyze_sizes(sys.argv[1], sys.argv[2])