correct isInPlane + checkLine functions
This commit is contained in:
parent
c4220691fd
commit
ccfe14decd
@ -111,44 +111,45 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
def isInPlane(plane, obj):
|
||||
|
||||
# Checks if 'obj' has its coordinates contained between the plane's coordinate.
|
||||
# If 'obj' is partly contained, returns which side (S, W, N, E) it's overlapping.
|
||||
# If 'obj' is contained, returns 1.
|
||||
# If 'obj' is partly contained, returns which side (S == 2, W == 4, N == 8, E == 6) it's overlapping.
|
||||
# If 'obj' is not contained in 'plane', returns 0.
|
||||
|
||||
if (
|
||||
(LvlPlanes[plane]['x1'] < LvlObjects[obj]['x1'] and LvlPlanes[plane]['x2'] > LvlObjects[obj]['x2']) and
|
||||
(LvlPlanes[plane]['y1'] < LvlObjects[obj]['y1'] and LvlPlanes[plane]['y2'] > LvlObjects[obj]['y2'])
|
||||
(plane.get('x1') <= obj.get('x1') and plane.get('x2') >= obj.get('x2') ) and
|
||||
(plane.get('y1') <= obj.get('y1') and plane.get('y2') >= obj.get('y2') )
|
||||
):
|
||||
|
||||
return 1
|
||||
|
||||
# Overlap on the West side of the plane
|
||||
if (
|
||||
( LvlPlanes[plane]['x1'] > LvlObjects[obj]['x1'] and LvlPlanes[plane]['x1'] < LvlObjects[obj]['x2'] ) and
|
||||
( LvlPlanes[plane]['y1'] < LvlObjects[obj]['y1'] and LvlPlanes[plane]['y2'] > LvlObjects[obj]['y2'] )
|
||||
( plane.get('x1') >= obj.get('x1') and plane.get('x1') <= obj.get('x2') ) and
|
||||
( plane.get('y1') <= obj.get('y2') and plane.get('y2') >= obj.get('y1') )
|
||||
):
|
||||
|
||||
return 4
|
||||
|
||||
# Overlap on the East side of the plane
|
||||
if (
|
||||
( LvlPlanes[plane]['x2'] < LvlObjects[obj]['x2'] and LvlPlanes[plane]['x2'] > LvlObjects[obj]['x1'] ) and
|
||||
( LvlPlanes[plane]['y1'] < LvlObjects[obj]['y1'] and LvlPlanes[plane]['y2'] > LvlObjects[obj]['y2'] )
|
||||
( plane.get('x2') <= obj.get('x2') and plane.get('x2') >= obj.get('x1') ) and
|
||||
( plane.get('y1') <= obj.get('y2') and plane.get('y2') >= obj.get('y1') )
|
||||
):
|
||||
|
||||
return 6
|
||||
|
||||
# Overlap on the North side of the plane
|
||||
if (
|
||||
( LvlPlanes[plane]['y2'] < LvlObjects[obj]['y2'] and LvlPlanes[plane]['y2'] > LvlObjects[obj]['y1'] ) and
|
||||
( LvlPlanes[plane]['x1'] < LvlObjects[obj]['x1'] and LvlPlanes[plane]['x2'] > LvlObjects[obj]['x2'] )
|
||||
( plane.get('y2') <= obj.get('y2') and plane.get('y2') >= obj.get('y1') ) and
|
||||
( plane.get('x1') <= obj.get('x1') and plane.get('x2') >= obj.get('x2') )
|
||||
):
|
||||
|
||||
return 8
|
||||
|
||||
# Overlap on the South side of the plane
|
||||
if (
|
||||
( LvlPlanes[plane]['y1'] > LvlObjects[obj]['y1'] and LvlPlanes[plane]['y1'] < LvlObjects[obj]['y2'] ) and
|
||||
( LvlPlanes[plane]['x1'] < LvlObjects[obj]['x1'] and LvlPlanes[plane]['x2'] > LvlObjects[obj]['x2'] )
|
||||
( plane.get('y1') >= obj.get('y1') and plane.get('y1') <= obj.get('y2') ) and
|
||||
( plane.get('x1') <= obj.get('x1') and plane.get('x2') >= obj.get('x2') )
|
||||
):
|
||||
|
||||
return 2
|
||||
@ -162,14 +163,14 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
# Construct the line used for BSP generation from 'plane' 's coordinates, on specified side (S, W, N, E)
|
||||
# Returns an array of 3 values
|
||||
|
||||
if side == 'S':
|
||||
|
||||
return [ LvlPlanes[plane]['x1'], LvlPlanes[plane]['y1'], LvlPlanes[plane]['x2'], LvlPlanes[plane]['y1'] ]
|
||||
|
||||
if side == 'N':
|
||||
|
||||
return [ LvlPlanes[plane]['x1'], LvlPlanes[plane]['y2'], LvlPlanes[plane]['x2'], LvlPlanes[plane]['y2'] ]
|
||||
|
||||
if side == 'S':
|
||||
|
||||
return [ LvlPlanes[plane]['x1'], LvlPlanes[plane]['y1'], LvlPlanes[plane]['x2'], LvlPlanes[plane]['y1'] ]
|
||||
|
||||
if side == 'W':
|
||||
|
||||
return [ LvlPlanes[plane]['x1'], LvlPlanes[plane]['y1'], LvlPlanes[plane]['x1'], LvlPlanes[plane]['y2'] ]
|
||||
@ -1084,6 +1085,10 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
PlanesObjects = defaultdict(dict)
|
||||
|
||||
# List of objects that can travel ( actor , moveable props...)
|
||||
|
||||
Moveables = []
|
||||
|
||||
# Store XY1, XY2 values
|
||||
|
||||
Xvalues = []
|
||||
@ -1129,7 +1134,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
# For each object not a plane, get its coordinates
|
||||
|
||||
# ~ if not o.data.get('isLevel') and not o.data.get('isActor') :
|
||||
# ~ if not o.data.get('isLevel'):
|
||||
if not o.data.get('isLevel'):
|
||||
|
||||
# World matrix is used to convert local to global coordinates
|
||||
@ -1155,6 +1160,12 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
Yvalues = []
|
||||
|
||||
# Add objects that can travel to the
|
||||
|
||||
if o.data.get("isRigidBody"):
|
||||
|
||||
Moveables.append(o.name)
|
||||
|
||||
# Declare LvlPlanes nodes to avoid declaration dependency issues
|
||||
|
||||
# ~ f.write("NODE ")
|
||||
@ -1163,12 +1174,6 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
f.write("NODE node" + CleanName(k) + ";\n\n")
|
||||
|
||||
# ~ if k < len( LvlPlanes.keys() ) - 1:
|
||||
|
||||
# ~ f.write(", ")
|
||||
|
||||
# ~ f.write(";\n\n")
|
||||
|
||||
# Sides of the plane to check
|
||||
|
||||
checkSides = [
|
||||
@ -1197,7 +1202,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
# If object is above plane
|
||||
|
||||
if isInPlane(p, o) == 1:
|
||||
if isInPlane(LvlPlanes[p], LvlObjects[o]) == 1:
|
||||
|
||||
# If actor is on this plane, use it as starting node
|
||||
|
||||
@ -1205,7 +1210,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
nodePtr = p
|
||||
|
||||
break
|
||||
# ~ break
|
||||
|
||||
# Add this object to the plane's list
|
||||
|
||||
@ -1217,6 +1222,21 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
PlanesObjects[p] = { 'objects' : [o] }
|
||||
|
||||
# Add actor in every plane
|
||||
|
||||
for moveable in Moveables:
|
||||
|
||||
if 'objects' in PlanesObjects[p]:
|
||||
|
||||
if moveable not in PlanesObjects[p]['objects']:
|
||||
|
||||
PlanesObjects[p]['objects'].append(CleanName(moveable))
|
||||
|
||||
else:
|
||||
|
||||
PlanesObjects[p] = { 'objects' : [ CleanName(moveable) ] }
|
||||
|
||||
|
||||
# Find surrounding planes
|
||||
|
||||
for op in LvlPlanes:
|
||||
@ -1243,7 +1263,11 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
getSepLine(op, s[1])[2],
|
||||
getSepLine(op, s[1])[3]
|
||||
|
||||
) == 'connected':
|
||||
) == 'connected' and (
|
||||
|
||||
isInPlane( LvlPlanes[p], LvlPlanes[op] )
|
||||
|
||||
):
|
||||
|
||||
# ... add it to the list
|
||||
|
||||
@ -1268,6 +1292,8 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
nSiblings = 0
|
||||
|
||||
if 'siblings' in PlanesObjects[p]:
|
||||
|
||||
if 'S' in PlanesObjects[p]['siblings']:
|
||||
|
||||
nSiblings += len(PlanesObjects[p]['siblings']['S'])
|
||||
@ -1290,11 +1316,21 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
|
||||
if 'siblings' in PlanesObjects[p]:
|
||||
|
||||
i = 0
|
||||
|
||||
for side in PlanesObjects[p]['siblings']:
|
||||
|
||||
for sibling in PlanesObjects[p]['siblings'][side]:
|
||||
|
||||
f.write("\t\t&node" + CleanName(sibling) + ",\n")
|
||||
f.write("\t\t&node" + CleanName(sibling) )
|
||||
|
||||
if i < ( nSiblings - 1 ) :
|
||||
|
||||
f.write(",")
|
||||
|
||||
i += 1
|
||||
|
||||
f.write("\n")
|
||||
|
||||
else:
|
||||
f.write("0,\n")
|
||||
@ -1311,14 +1347,24 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
f.write("\t" + str(len(PlanesObjects[p]['objects'])) + ",\n" +
|
||||
"\t{\n")
|
||||
|
||||
i = 0
|
||||
|
||||
for obj in PlanesObjects[p]['objects']:
|
||||
|
||||
f.write( "\t\t&mesh" + CleanName(obj) + ",\n" )
|
||||
f.write( "\t\t&mesh" + CleanName(obj))
|
||||
|
||||
if i < len(PlanesObjects[p]['objects']) - 1:
|
||||
|
||||
f.write(",")
|
||||
|
||||
i += 1
|
||||
|
||||
f.write("\n")
|
||||
|
||||
else:
|
||||
|
||||
f.write("\t0,\n" +
|
||||
"\t{\n\t0\n")
|
||||
"\t{\n\t\t0\n")
|
||||
|
||||
f.write("\t}\n" +
|
||||
"};\n\n")
|
||||
@ -1331,7 +1377,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
||||
"\t&node" + pName + "_objects\n" +
|
||||
"};\n\n" )
|
||||
|
||||
f.write("NODE * curNode = &node" + nodePtr + ";\n\n")
|
||||
f.write("NODE * curNode = &node" + CleanName(nodePtr) + ";\n\n")
|
||||
|
||||
# Set default camera back in Blender
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user