Browse Source

fix Blender script bugs; copy collisionbox to clipboard

master
poikilos 5 years ago
committed by Jacob Gustafson
parent
commit
a7e02142d3
  1. BIN
      Bucket_Game-branches/duck--add-190814/mods/codermobs/codermobs/src/duck3-feathers-collapsed.blend
  2. 5
      utilities/blender/generate_Empty_at_each_vertex.py
  3. 64
      utilities/blender/generate_lua_collisionbox.py

BIN
Bucket_Game-branches/duck--add-190814/mods/codermobs/codermobs/src/duck3-feathers-collapsed.blend

Binary file not shown.

5
utilities/blender/generate_Empty_at_each_vertex.py

@ -56,8 +56,9 @@ else:
# See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes # See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes
mesh = ob1.data mesh = ob1.data
# print("mesh:" + str(mesh)) # print("mesh:" + str(mesh))
# print("hasattr(mesh, 'vertices'):" + str(hasattr(mesh, 'vertices')))] # print("hasattr(mesh, 'vertices'):" + str(hasattr(mesh,
xMin = None # 'vertices')))
xMin = None # Define so None check is possible later.
if (mesh is not None) and (not hasattr(mesh, 'vertices')): if (mesh is not None) and (not hasattr(mesh, 'vertices')):
print("--can't calculate collisionbox for skeleton") print("--can't calculate collisionbox for skeleton")
elif mesh is not None: elif mesh is not None:

64
utilities/blender/generate_lua_collisionbox.py

@ -29,7 +29,7 @@ class MessageBox(bpy.types.Operator):
def execute(self, context): def execute(self, context):
self.report({'INFO'}, self.message) self.report({'INFO'}, self.message)
print(self.message) # print(self.message)
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
@ -69,14 +69,14 @@ else:
# yMax -= yMin # yMax -= yMin
# yMin = 0.0 # yMin = 0.0
print(" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}," # print(" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f},"
" {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax)) # " {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax))
# See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes # See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes
# print("mesh:" + str(mesh)) # print("mesh:" + str(mesh))
# print("hasattr(mesh, 'vertices'):" # print("hasattr(mesh, 'vertices'):"
# + str(hasattr(mesh, 'vertices')))] # + str(hasattr(mesh, 'vertices')))]
xMin = None xMin = None # Define so None check is possible later.
if mesh is not None: if mesh is not None:
xMin = None xMin = None
yMin = None yMin = None
@ -113,31 +113,32 @@ else:
# Use ob1.matrix_world (above) instead of incrementing # Use ob1.matrix_world (above) instead of incrementing
# ob1.location.x, y, and z # ob1.location.x, y, and z
newNamePrefix = "Empty.EDGE." + ob1.name # newNamePrefix = "Empty.EDGE." + ob1.name
i = 0 # i = 0
wm = ob1.matrix_world # wm = ob1.matrix_world
for vert in mesh.vertices: # for vert in mesh.vertices:
newName = newNamePrefix + "." + str(i) # newName = newNamePrefix + "." + str(i)
try: # # This matrix multiplication is NOT transitive.
loc = mat @ vert.co # NOT transitive # try:
except TypeError: # loc = wm @ vert.co
loc = mat * vert.co # Blender <2.8 # except TypeError:
isFar = False # loc = wm * vert.co # Blender <2.8
if loc.x == xMax or loc.y == yMax or loc.z == zMax: # isFar = False
isFar = True # if loc.x == xMax or loc.y == yMax or loc.z == zMax:
elif loc.x == xMin or loc.y == yMin or loc.z == zMin: # isFar = True
isFar = True # elif loc.x == xMin or loc.y == yMin or loc.z == zMin:
if isFar: # isFar = True
pass # if isFar:
# result = bpy.ops.object.add(type='EMPTY', radius=.25, # pass
# location=loc); # # result = bpy.ops.object.add(type='EMPTY', radius=.25,
# NOTE: result is merely {'FINISHED'} # # location=loc);
# print("{:.2f}, {:.2f}, {:.2f}".format(loc.x, loc.y, # # NOTE: result is merely {'FINISHED'}
# loc.z)) # # print("{:.2f}, {:.2f}, {:.2f}".format(loc.x, loc.y,
# # loc.z))
bpy.ops.object.add_named(name=newName, type='EMPTY',
radius=.25, location=loc) # bpy.ops.object.add_named(name=newName, type='EMPTY',
i += 1 # radius=.25, location=loc)
# i += 1
else: else:
extents1 = ob1.scale.copy() extents1 = ob1.scale.copy()
# Object is an empty, so scale up for Minetest # Object is an empty, so scale up for Minetest
@ -175,7 +176,10 @@ else:
msg = (" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}," msg = (" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f},"
" {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, " {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax,
zMax)) zMax))
msg += msgSuffix if len(msgSuffix) > 0:
msgSuffix = " -- " + msgSuffix
bpy.context.window_manager.clipboard = msg + msgSuffix
msg += " --copied to clipboard"
# if enable_minetest: # if enable_minetest:
# msg += " -- *10" # msg += " -- *10"
print(msg) print(msg)

Loading…
Cancel
Save