Skip to content

Commit b5e0478

Browse files
Rework to add a car parent
1 parent b36f04f commit b5e0478

File tree

4 files changed

+67
-30
lines changed

4 files changed

+67
-30
lines changed

loco-graphics-helper/loco_object_helper_panel.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ def draw(self, context):
3232
if object_properties.object_type == "BOGIE":
3333
self.draw_bogie_panel(context, layout)
3434

35+
if object_properties.object_type == "CAR":
36+
self.draw_car_panel(context, layout)
37+
38+
def draw_car_panel(self, context, layout):
39+
scene = context.scene
40+
general_properties = scene.loco_graphics_helper_general_properties
41+
row = layout.row()
42+
43+
if not general_properties.render_mode == "VEHICLE":
44+
row.label("Vehicle Render Mode Required")
45+
return
46+
47+
vehicle_properties = context.object.loco_graphics_helper_vehicle_properties
48+
49+
row.prop(vehicle_properties, "index")
50+
row = layout.row()
51+
3552
def draw_bogie_panel(self, context, layout):
3653
scene = context.scene
3754
general_properties = scene.loco_graphics_helper_general_properties
@@ -49,9 +66,6 @@ def draw_bogie_panel(self, context, layout):
4966
if vehicle_properties.is_clone_bogie:
5067
row.prop(vehicle_properties, "index",text="Clone of bogie index:")
5168
row = layout.row()
52-
53-
row.prop(vehicle_properties, "bogie_parent_index")
54-
row = layout.row()
5569
return
5670

5771
box = layout.box()
@@ -78,9 +92,6 @@ def draw_bogie_panel(self, context, layout):
7892
row.prop(vehicle_properties, "index")
7993
row = layout.row()
8094

81-
row.prop(vehicle_properties, "bogie_parent_index")
82-
row = layout.row()
83-
8495
row.prop(vehicle_properties, "number_of_animation_frames")
8596
row = layout.row()
8697

loco-graphics-helper/properties/object_properties.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ObjectProperties(bpy.types.PropertyGroup):
3636
("BODY", "Body", "", 1),
3737
("BOGIE", "Bogie", "", 2),
3838
("CARGO", "Cargo", "", 3),
39+
("CAR", "Car", "", 4),
3940
),
4041
default="NONE",
4142
update=object_type_update_func

loco-graphics-helper/properties/vehicle_properties.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ class VehicleProperties(bpy.types.PropertyGroup):
122122
default=False
123123
)
124124

125-
bogie_parent_index = bpy.props.IntProperty(
126-
name="Parent Body Index",
127-
description="Set to the parent body index",
128-
default=1,
129-
min=1)
130-
131125

132126
def register_vehicles_properties():
133127
bpy.types.Object.loco_graphics_helper_vehicle_properties = bpy.props.PointerProperty(

loco-graphics-helper/rct_graphics_helper_panel.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,25 @@ def get_number_of_sprites(object):
238238
num_sprites = num_sprites + int(props.flat_viewing_angles) * multiplier / 2
239239
return int(num_sprites)
240240

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+
241260
@staticmethod
242261
def get_min_max_x_bound_box_corners(object):
243262
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):
250269
mins = []
251270
maxs = []
252271
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)
256276

257277
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)
261282

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)
263284
mins.append(body_min_x)
264285
maxs.append(body_max_x)
265-
266286
min_x = body.location[0] - min(mins)
267287
max_x = max(maxs) - body.location[0]
268288
return max(min_x, max_x)
@@ -275,18 +295,24 @@ def get_bogie_position_from_component(bogie, body, half_width):
275295
return half_width - position_from_centre
276296

277297
@staticmethod
278-
def get_car_components(bogies, bodies):
298+
def get_car_components(cars):
279299
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+
282308
if len(component_bogies) != 2:
283-
components.append((None, None, body))
309+
components.append((None, None, component_bodies[0]))
284310
continue
285311

286312
front_bogie = component_bogies[0] if component_bogies[0].location[0] > component_bogies[1].location[0] else component_bogies[1]
287313
back_bogie = component_bogies[1] if component_bogies[0].location[0] > component_bogies[1].location[0] else component_bogies[0]
288314

289-
components.append((front_bogie, back_bogie, body))
315+
components.append((front_bogie, back_bogie, component_bodies[0]))
290316
return components
291317

292318
@staticmethod
@@ -295,21 +321,21 @@ def blender_to_loco_dist(dist):
295321

296322
def draw_vehicle_panel(self, scene, layout):
297323
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)
302327

303328
total_number_of_sprites = 0
304329

305-
components = self.get_car_components(bogies, bodies)
330+
components = self.get_car_components(cars)
306331
if len(components) > 0:
307332
row = layout.row()
308333
row.label("Car(s) details:")
309334

310335
for component in components:
311336
front, back, body = component
312337
idx = body.loco_graphics_helper_vehicle_properties.index
338+
print("Car {}".format(idx))
313339
half_width = self.get_longest_component_edge(front, back, body)
314340

315341
front_position = 0
@@ -337,6 +363,11 @@ def draw_vehicle_panel(self, scene, layout):
337363
row = layout.row()
338364
row.label(" WARNING: {},".format(warning))
339365

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+
340371
if len(bodies) > 0:
341372
row = layout.row()
342373
row.label("Body(s) details:")

0 commit comments

Comments
 (0)