@@ -35,6 +35,20 @@ def get_object(self, sub_component: SubComponent):
35
35
SubComponent .BODY .value :self .body ,
36
36
}
37
37
return object_mapping [sub_component .value ]
38
+
39
+
40
+ def has_sprites (self , sub_component : SubComponent ):
41
+ object = self .get_object (sub_component )
42
+ if object is None :
43
+ return False
44
+ props = object .loco_graphics_helper_vehicle_properties
45
+ if props .is_clone :
46
+ return False
47
+
48
+ if all (v == 0 for v in props .sprite_track_flags ):
49
+ return False
50
+
51
+ return True
38
52
39
53
def get_number_of_sprites (self , sub_component : SubComponent ):
40
54
object = self .get_object (sub_component )
@@ -64,16 +78,22 @@ def get_number_of_sprites(self, sub_component: SubComponent):
64
78
return int (num_sprites )
65
79
66
80
def _get_min_max_x_bound_box_corners_with_children (self , object ):
81
+ return self ._get_min_max_axis_bound_box_corners_with_children (object , 0 )
82
+
83
+ def _get_min_max_z_bound_box_corners_with_children (self , object ):
84
+ return self ._get_min_max_axis_bound_box_corners_with_children (object , 2 )
85
+
86
+ def _get_min_max_axis_bound_box_corners_with_children (self , object , axis ):
67
87
mins = []
68
88
maxs = []
69
- min_x , max_x = self ._get_min_max_x_bound_box_corners (object )
89
+ min_x , max_x = self ._get_min_max_axis_bound_box_corners (object , axis )
70
90
# This can happen if there are no dimensions to this object (or if its 0 width)
71
91
if min_x != max_x :
72
92
mins .append (min_x )
73
93
maxs .append (max_x )
74
94
75
95
for c in object .children :
76
- min_x , max_x = self ._get_min_max_x_bound_box_corners_with_children ( c )
96
+ min_x , max_x = self ._get_min_max_axis_bound_box_corners_with_children ( c , axis )
77
97
if min_x != max_x :
78
98
mins .append (min_x )
79
99
maxs .append (max_x )
@@ -82,10 +102,10 @@ def _get_min_max_x_bound_box_corners_with_children(self, object):
82
102
83
103
return (min (mins ), max (maxs ))
84
104
85
- def _get_min_max_x_bound_box_corners (self , object ):
105
+ def _get_min_max_axis_bound_box_corners (self , object , axis ):
86
106
bbox_corners = [object .matrix_world * Vector (corner ) for corner in object .bound_box ]
87
- min_x = min ([x [0 ] for x in bbox_corners ])
88
- max_x = max ([x [0 ] for x in bbox_corners ])
107
+ min_x = min ([x [axis ] for x in bbox_corners ])
108
+ max_x = max ([x [axis ] for x in bbox_corners ])
89
109
return (min_x , max_x )
90
110
91
111
def get_half_width (self ):
@@ -110,6 +130,16 @@ def get_half_width(self):
110
130
max_x = max (maxs ) - self .body .matrix_world .translation [0 ]
111
131
112
132
return max (min_x , max_x )
133
+
134
+ def get_preferred_body_midpoint (self ):
135
+ if self .has_sprites (SubComponent .FRONT ) or self .has_sprites (SubComponent .BACK ):
136
+ # If it has a real bogey we should put midpoint between the two bogies
137
+ mid_point_x = (self .front .location [0 ] - self .back .location [0 ]) / 2 + self .back .location [0 ]
138
+ else :
139
+ # If it has fake/no bogies we should put midpoint in the centre of the body
140
+ body_min_x , body_max_x = self ._get_min_max_x_bound_box_corners_with_children (self .body )
141
+ mid_point_x = (body_min_x + body_max_x ) / 2
142
+ return mid_point_x
113
143
114
144
def get_bogie_position (self , sub_component : SubComponent ):
115
145
assert sub_component != SubComponent .BODY
@@ -123,10 +153,11 @@ def get_animation_location(self):
123
153
if len (self .animations ) == 0 :
124
154
return 0
125
155
x_diff = self .front .location [0 ] - self .back .location [0 ]
156
+ print ("front_x {} back_x {} anim_x {}" .format (self .front .location [0 ], self .back .location [0 ], self .animations [0 ].location [0 ]))
126
157
x_factor = (1 / x_diff )
127
158
anim_diff = self .front .location [0 ] - self .animations [0 ].location [0 ]
128
159
anim_factor = (anim_diff * x_factor ) * 128
129
- return int (anim_factor ) + 128
160
+ return int (anim_factor ) + 64
130
161
131
162
132
163
def get_car_components (cars ) -> List [VehicleComponent ]:
0 commit comments