@@ -238,6 +238,25 @@ def get_number_of_sprites(object):
238
238
num_sprites = num_sprites + int (props .flat_viewing_angles ) * multiplier / 2
239
239
return int (num_sprites )
240
240
241
+ @staticmethod
242
+ def get_min_max_x_bound_box_corners_with_children (object ):
243
+ mins = []
244
+ maxs = []
245
+ min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners (object )
246
+ # This can happen if there are no dimensions to this object (or if its 0 width)
247
+ if min_x != max_x :
248
+ mins .append (min_x )
249
+ maxs .append (max_x )
250
+
251
+ for c in object .children :
252
+ min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners_with_children (c )
253
+ if min_x != max_x :
254
+ mins .append (min_x )
255
+ maxs .append (max_x )
256
+ if len (mins ) == 0 or len (maxs ) == 0 :
257
+ return (0 , 0 )
258
+ return (min (mins ), max (maxs ))
259
+
241
260
@staticmethod
242
261
def get_min_max_x_bound_box_corners (object ):
243
262
bbox_corners = [object .matrix_world * Vector (corner ) for corner in object .bound_box ]
@@ -250,19 +269,20 @@ def get_longest_component_edge(front, back, body):
250
269
mins = []
251
270
maxs = []
252
271
if not front is None :
253
- min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners (front )
254
- mins .append (min_x )
255
- maxs .append (max_x )
272
+ min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners_with_children (front )
273
+ if min_x != max_x :
274
+ mins .append (min_x )
275
+ maxs .append (max_x )
256
276
257
277
if not back is None :
258
- min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners (back )
259
- mins .append (min_x )
260
- maxs .append (max_x )
278
+ min_x , max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners_with_children (back )
279
+ if min_x != max_x :
280
+ mins .append (min_x )
281
+ maxs .append (max_x )
261
282
262
- body_min_x , body_max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners (body )
283
+ body_min_x , body_max_x = GraphicsHelperPanel .get_min_max_x_bound_box_corners_with_children (body )
263
284
mins .append (body_min_x )
264
285
maxs .append (body_max_x )
265
-
266
286
min_x = body .location [0 ] - min (mins )
267
287
max_x = max (maxs ) - body .location [0 ]
268
288
return max (min_x , max_x )
@@ -275,18 +295,24 @@ def get_bogie_position_from_component(bogie, body, half_width):
275
295
return half_width - position_from_centre
276
296
277
297
@staticmethod
278
- def get_car_components (bogies , bodies ):
298
+ def get_car_components (cars ):
279
299
components = []
280
- for body in bodies :
281
- component_bogies = [x for x in bogies if x .loco_graphics_helper_vehicle_properties .bogie_parent_index == body .loco_graphics_helper_vehicle_properties .index ]
300
+ for car in cars :
301
+ component_bogies = [x for x in car .children if x .loco_graphics_helper_object_properties .object_type == 'BOGIE' ]
302
+ component_bodies = [x for x in car .children if x .loco_graphics_helper_object_properties .object_type == 'BODY' ]
303
+
304
+ if len (component_bodies ) != 1 :
305
+ print ("Malformed car {}" .format (car .name ))
306
+ continue
307
+
282
308
if len (component_bogies ) != 2 :
283
- components .append ((None , None , body ))
309
+ components .append ((None , None , component_bodies [ 0 ] ))
284
310
continue
285
311
286
312
front_bogie = component_bogies [0 ] if component_bogies [0 ].location [0 ] > component_bogies [1 ].location [0 ] else component_bogies [1 ]
287
313
back_bogie = component_bogies [1 ] if component_bogies [0 ].location [0 ] > component_bogies [1 ].location [0 ] else component_bogies [0 ]
288
314
289
- components .append ((front_bogie , back_bogie , body ))
315
+ components .append ((front_bogie , back_bogie , component_bodies [ 0 ] ))
290
316
return components
291
317
292
318
@staticmethod
@@ -295,21 +321,21 @@ def blender_to_loco_dist(dist):
295
321
296
322
def draw_vehicle_panel (self , scene , layout ):
297
323
general_properties = scene .loco_graphics_helper_general_properties
298
- bodies = [x for x in scene .objects if x .loco_graphics_helper_object_properties .object_type == "BODY" ]
299
- bodies = sorted (bodies , key = lambda x : x .loco_graphics_helper_vehicle_properties .index )
300
- bogies = [x for x in scene .objects if x .loco_graphics_helper_object_properties .object_type == "BOGIE" ]
301
- bogies = sorted (bogies , key = lambda x : x .loco_graphics_helper_vehicle_properties .index )
324
+
325
+ cars = [x for x in scene .objects if x .loco_graphics_helper_object_properties .object_type == "CAR" ]
326
+ cars = sorted (cars , key = lambda x : x .loco_graphics_helper_vehicle_properties .index )
302
327
303
328
total_number_of_sprites = 0
304
329
305
- components = self .get_car_components (bogies , bodies )
330
+ components = self .get_car_components (cars )
306
331
if len (components ) > 0 :
307
332
row = layout .row ()
308
333
row .label ("Car(s) details:" )
309
334
310
335
for component in components :
311
336
front , back , body = component
312
337
idx = body .loco_graphics_helper_vehicle_properties .index
338
+ print ("Car {}" .format (idx ))
313
339
half_width = self .get_longest_component_edge (front , back , body )
314
340
315
341
front_position = 0
@@ -337,6 +363,11 @@ def draw_vehicle_panel(self, scene, layout):
337
363
row = layout .row ()
338
364
row .label (" WARNING: {}," .format (warning ))
339
365
366
+ bodies = [x for x in scene .objects if x .loco_graphics_helper_object_properties .object_type == "BODY" ]
367
+ bodies = sorted (bodies , key = lambda x : x .loco_graphics_helper_vehicle_properties .index )
368
+ bogies = [x for x in scene .objects if x .loco_graphics_helper_object_properties .object_type == "BOGIE" ]
369
+ bogies = sorted (bogies , key = lambda x : x .loco_graphics_helper_vehicle_properties .index )
370
+
340
371
if len (bodies ) > 0 :
341
372
row = layout .row ()
342
373
row .label ("Body(s) details:" )
0 commit comments