|
8 | 8 | '''
|
9 | 9 |
|
10 | 10 | import bpy
|
11 |
| -import math |
| 11 | +#import math |
12 | 12 | import os
|
| 13 | +from mathutils import Vector |
13 | 14 |
|
14 | 15 | from .operators.init_operator import Init
|
15 | 16 |
|
@@ -237,39 +238,123 @@ def get_number_of_sprites(object):
|
237 | 238 | num_sprites = num_sprites + int(props.flat_viewing_angles) * multiplier / 2
|
238 | 239 | return int(num_sprites)
|
239 | 240 |
|
| 241 | + @staticmethod |
| 242 | + def get_min_max_x_bound_box_corners(object): |
| 243 | + bbox_corners = [object.matrix_world * Vector(corner) for corner in object.bound_box] |
| 244 | + min_x = min([x[0] for x in bbox_corners]) |
| 245 | + max_x = max([x[0] for x in bbox_corners]) |
| 246 | + return (min_x, max_x) |
| 247 | + |
| 248 | + @staticmethod |
| 249 | + def get_longest_component_edge(front, back, body): |
| 250 | + mins = [] |
| 251 | + maxs = [] |
| 252 | + 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) |
| 256 | + |
| 257 | + 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) |
| 261 | + |
| 262 | + body_min_x, body_max_x = GraphicsHelperPanel.get_min_max_x_bound_box_corners(body) |
| 263 | + mins.append(body_min_x) |
| 264 | + maxs.append(body_max_x) |
| 265 | + |
| 266 | + min_x = body.location[0] - min(mins) |
| 267 | + max_x = max(maxs) - body.location[0] |
| 268 | + return max(min_x, max_x) |
| 269 | + |
| 270 | + @staticmethod |
| 271 | + def get_bogie_position_from_component(bogie, body, half_width): |
| 272 | + body_x = body.location[0] |
| 273 | + bogie_x = bogie.location[0] |
| 274 | + position_from_centre = max(body_x, bogie_x) - min(body_x, bogie_x) |
| 275 | + return half_width - position_from_centre |
| 276 | + |
| 277 | + @staticmethod |
| 278 | + def get_car_components(bogies, bodies): |
| 279 | + 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] |
| 282 | + if len(component_bogies) != 2: |
| 283 | + components.append((None, None, body)) |
| 284 | + continue |
| 285 | + |
| 286 | + front_bogie = component_bogies[0] if component_bogies[0].location[0] > component_bogies[1].location[0] else component_bogies[1] |
| 287 | + back_bogie = component_bogies[1] if component_bogies[0].location[0] > component_bogies[1].location[0] else component_bogies[0] |
| 288 | + |
| 289 | + components.append((front_bogie, back_bogie, body)) |
| 290 | + return components |
| 291 | + |
| 292 | + @staticmethod |
| 293 | + def blender_to_loco_dist(dist): |
| 294 | + return int(dist * 32 + 0.5) |
| 295 | + |
240 | 296 | def draw_vehicle_panel(self, scene, layout):
|
241 | 297 | general_properties = scene.loco_graphics_helper_general_properties
|
242 |
| - cars = [x for x in scene.objects if x.loco_graphics_helper_object_properties.object_type == "CAR"] |
243 |
| - cars = sorted(cars, key=lambda x: x.loco_graphics_helper_vehicle_properties.index) |
| 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) |
244 | 300 | bogies = [x for x in scene.objects if x.loco_graphics_helper_object_properties.object_type == "BOGIE"]
|
245 | 301 | bogies = sorted(bogies, key=lambda x: x.loco_graphics_helper_vehicle_properties.index)
|
246 | 302 |
|
247 | 303 | total_number_of_sprites = 0
|
248 | 304 |
|
249 |
| - if len(cars) > 0: |
| 305 | + components = self.get_car_components(bogies, bodies) |
| 306 | + if len(components) > 0: |
250 | 307 | row = layout.row()
|
251 | 308 | row.label("Car(s) details:")
|
252 |
| - for idx, car in enumerate(cars): |
| 309 | + |
| 310 | + for component in components: |
| 311 | + front, back, body = component |
| 312 | + idx = body.loco_graphics_helper_vehicle_properties.index |
| 313 | + half_width = self.get_longest_component_edge(front, back, body) |
| 314 | + |
| 315 | + front_position = 0 |
| 316 | + back_position = 0 |
| 317 | + front_idx = 255 |
| 318 | + back_idx = 255 |
| 319 | + |
| 320 | + if not front is None: |
| 321 | + front_position = self.get_bogie_position_from_component(front, body, half_width) |
| 322 | + back_position = self.get_bogie_position_from_component(back, body, half_width) |
| 323 | + |
| 324 | + front_idx = front.loco_graphics_helper_vehicle_properties.index - 1 |
| 325 | + back_idx = back.loco_graphics_helper_vehicle_properties.index - 1 |
| 326 | + |
| 327 | + row = layout.row() |
| 328 | + row.label(" {}. {}, Half-Width: {}, Front Position: {}, Back Position: {}".format(idx, body.name, self.blender_to_loco_dist(half_width), self.blender_to_loco_dist(front_position), self.blender_to_loco_dist(back_position))) |
253 | 329 | row = layout.row()
|
254 |
| - number_of_sprites = self.get_number_of_sprites(car) |
255 |
| - row.label(" {}. {}, Number of sprites: {}".format(idx + 1, car.name, number_of_sprites)) |
| 330 | + row.label(" Body Sprite Index: {}, Front Bogie Sprite Index: {}, Back Bogie Sprite Index: {},".format(idx - 1, front_idx, back_idx)) |
| 331 | + |
| 332 | + if len(bodies) > 0: |
| 333 | + row = layout.row() |
| 334 | + row.label("Body(s) details:") |
| 335 | + for idx, body in enumerate(bodies): |
| 336 | + row = layout.row() |
| 337 | + number_of_sprites = self.get_number_of_sprites(body) |
| 338 | + row.label(" {}. {}, Number of sprites: {}".format(idx + 1, body.name, number_of_sprites)) |
256 | 339 | total_number_of_sprites = total_number_of_sprites + number_of_sprites
|
257 | 340 |
|
258 | 341 | if len(bogies) > 0:
|
259 | 342 | row = layout.row()
|
260 | 343 | row.label("Bogie(s) details:")
|
261 | 344 | for idx, bogie in enumerate(bogies):
|
262 | 345 | row = layout.row()
|
263 |
| - number_of_sprites = self.get_number_of_sprites(bogie) |
| 346 | + number_of_sprites = 0 |
| 347 | + if not bogie.loco_graphics_helper_vehicle_properties.is_clone_bogie: |
| 348 | + number_of_sprites = self.get_number_of_sprites(bogie) |
| 349 | + total_number_of_sprites = total_number_of_sprites + number_of_sprites |
264 | 350 | row.label(" {}. {}, Number of sprites: {}".format(idx + 1, bogie.name, number_of_sprites))
|
265 |
| - total_number_of_sprites = total_number_of_sprites + number_of_sprites |
266 | 351 |
|
267 | 352 | row = layout.row()
|
268 | 353 | row.label("Total number of sprites: {}".format(total_number_of_sprites))
|
269 | 354 |
|
270 | 355 | if total_number_of_sprites == 0:
|
271 | 356 | row = layout.row()
|
272 |
| - row.label("NO CARS OR BOGIES SET!") |
| 357 | + row.label("NO BODIES OR BOGIES SET!") |
273 | 358 | row = layout.row()
|
274 | 359 | row.label("NOTHING WILL BE RENDERED!")
|
275 | 360 |
|
|
0 commit comments