Skip to content

Commit b64ea34

Browse files
authored
Merge pull request #13 from MBCollector672/patch-3
fix crash if dif has interiorPathFollowers but no pathedInteriors
2 parents fb9d267 + 54a1fef commit b64ea34

1 file changed

Lines changed: 74 additions & 73 deletions

File tree

blender_plugin/io_dif/import_dif.py

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -519,81 +519,82 @@ def load(
519519
obj.matrix_world = global_matrix
520520

521521
for mover in dif.interiorPathfollowers:
522-
pos = mover.offset
523-
itr = pathedInteriors[mover.interiorResIndex]
524-
itr: Object = itr.copy()
525-
base = scene.collection.objects.link(itr)
526-
itr.location = [-pos.x, -pos.y, -pos.z]
527-
itr.dif_props.interior_type = "pathed_interior"
528-
itr.dif_props.start_time = int(mover.properties.h.get("initialPosition", 0))
529-
itr.dif_props.reverse = mover.properties.h.get("initialTargetPosition", 0) == "-2"
530-
itr.dif_props.constant_speed = False
531-
532-
waypoints: list[WayPoint] = mover.wayPoint
533-
534-
markerpts = [
535-
(waypt.position.x, waypt.position.y, waypt.position.z)
536-
for waypt in waypoints
537-
]
538-
539-
curve = bpy.data.curves.new("markers", type="CURVE")
540-
curve.dimensions = "3D"
541-
spline = curve.splines.new(type="POLY")
542-
spline.points.add(len(markerpts) - 1)
543-
544-
for p, new_co in zip(spline.points, markerpts):
545-
p.co = new_co + (1.0,)
546-
547-
path = bpy.data.objects.new("path", curve)
548-
scene.collection.objects.link(path)
549-
550-
itr.dif_props.marker_path = curve
551-
552-
total_time = 0
553-
for pt in waypoints:
554-
total_time += pt.msToNext
555-
itr.dif_props.total_time = total_time
556-
557-
if len(waypoints) > 0:
558-
first_type = waypoints[0].smoothingType
559-
if first_type == 0:
560-
itr.dif_props.marker_type = "linear"
561-
elif first_type == 1:
562-
itr.dif_props.marker_type = "spline"
563-
elif first_type == 2:
564-
itr.dif_props.marker_type = "accelerate"
565-
else:
566-
itr.dif_props.marker_type = "linear"
567-
568-
if len(dif.triggers) > 0:
569-
for trigger_id in mover.triggerId:
570-
trigger = dif.triggers[trigger_id]
571-
tobj = bpy.data.objects.new(trigger.datablock, None)
572-
tobj.dif_props.interior_type = "path_trigger"
573-
tobj.dif_props.pathed_interior_target = itr
574-
tobj.dif_props.game_entity_datablock = trigger.datablock
575-
tobj.dif_props.target_marker = False
576-
for key in trigger.properties.h:
577-
prop = tobj.dif_props.game_entity_properties.add()
578-
prop.key = key
579-
prop.value = trigger.properties.get(key)
580-
581-
t_min = mathutils.Vector((float('inf'), float('inf'), float('inf')))
582-
t_max = mathutils.Vector((-float('inf'), -float('inf'), -float('inf')))
583-
for p in trigger.polyhedron.pointList:
584-
t_min.x = min(t_min.x, p.x)
585-
t_min.y = min(t_min.y, p.y)
586-
t_min.z = min(t_min.z, p.z)
522+
if mover.interiorResIndex <= len(pathedInteriors) - 1:
523+
pos = mover.offset
524+
itr = pathedInteriors[mover.interiorResIndex]
525+
itr: Object = itr.copy()
526+
base = scene.collection.objects.link(itr)
527+
itr.location = [-pos.x, -pos.y, -pos.z]
528+
itr.dif_props.interior_type = "pathed_interior"
529+
itr.dif_props.start_time = int(mover.properties.h.get("initialPosition", 0))
530+
itr.dif_props.reverse = mover.properties.h.get("initialTargetPosition", 0) == "-2"
531+
itr.dif_props.constant_speed = False
532+
533+
waypoints: list[WayPoint] = mover.wayPoint
534+
535+
markerpts = [
536+
(waypt.position.x, waypt.position.y, waypt.position.z)
537+
for waypt in waypoints
538+
]
539+
540+
curve = bpy.data.curves.new("markers", type="CURVE")
541+
curve.dimensions = "3D"
542+
spline = curve.splines.new(type="POLY")
543+
spline.points.add(len(markerpts) - 1)
587544

588-
t_max.x = max(t_max.x, p.x)
589-
t_max.y = max(t_max.y, p.y)
590-
t_max.z = max(t_max.z, p.z)
545+
for p, new_co in zip(spline.points, markerpts):
546+
p.co = new_co + (1.0,)
547+
548+
path = bpy.data.objects.new("path", curve)
549+
scene.collection.objects.link(path)
550+
551+
itr.dif_props.marker_path = curve
552+
553+
total_time = 0
554+
for pt in waypoints:
555+
total_time += pt.msToNext
556+
itr.dif_props.total_time = total_time
557+
558+
if len(waypoints) > 0:
559+
first_type = waypoints[0].smoothingType
560+
if first_type == 0:
561+
itr.dif_props.marker_type = "linear"
562+
elif first_type == 1:
563+
itr.dif_props.marker_type = "spline"
564+
elif first_type == 2:
565+
itr.dif_props.marker_type = "accelerate"
566+
else:
567+
itr.dif_props.marker_type = "linear"
568+
569+
if len(dif.triggers) > 0:
570+
for trigger_id in mover.triggerId:
571+
trigger = dif.triggers[trigger_id]
572+
tobj = bpy.data.objects.new(trigger.datablock, None)
573+
tobj.dif_props.interior_type = "path_trigger"
574+
tobj.dif_props.pathed_interior_target = itr
575+
tobj.dif_props.game_entity_datablock = trigger.datablock
576+
tobj.dif_props.target_marker = False
577+
for key in trigger.properties.h:
578+
prop = tobj.dif_props.game_entity_properties.add()
579+
prop.key = key
580+
prop.value = trigger.properties.get(key)
591581

592-
tobj.location = t_min
593-
tobj.scale = mathutils.Vector((t_max.x - t_min.x, t_max.y - t_min.y, t_max.z - t_min.z))
594-
tobj.location.y += tobj.scale.y
595-
tobj.location += mathutils.Vector((trigger.offset.x, trigger.offset.y, trigger.offset.z))
596-
scene.collection.objects.link(tobj)
582+
t_min = mathutils.Vector((float('inf'), float('inf'), float('inf')))
583+
t_max = mathutils.Vector((-float('inf'), -float('inf'), -float('inf')))
584+
for p in trigger.polyhedron.pointList:
585+
t_min.x = min(t_min.x, p.x)
586+
t_min.y = min(t_min.y, p.y)
587+
t_min.z = min(t_min.z, p.z)
588+
589+
t_max.x = max(t_max.x, p.x)
590+
t_max.y = max(t_max.y, p.y)
591+
t_max.z = max(t_max.z, p.z)
592+
593+
tobj.location = t_min
594+
tobj.scale = mathutils.Vector((t_max.x - t_min.x, t_max.y - t_min.y, t_max.z - t_min.z))
595+
tobj.location.y += tobj.scale.y
596+
tobj.location += mathutils.Vector((trigger.offset.x, trigger.offset.y, trigger.offset.z))
597+
scene.collection.objects.link(tobj)
597598

598599
if dif.gameEntities != None:
599600
for ge in dif.gameEntities:

0 commit comments

Comments
 (0)