|
@ -1,13 +1,14 @@ |
|
|
print("How to use: paste into a Blender Text Editor panel, select object, Run Script") |
|
|
print("How to use: paste into a Blender Text Editor panel, select" |
|
|
|
|
|
" object, Run Script") |
|
|
|
|
|
|
|
|
y_up = True |
|
|
y_up = True |
|
|
enable_minetest = False |
|
|
enable_minetest = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import bpy |
|
|
import bpy |
|
|
#from mathutils import Matrix |
|
|
# from mathutils import Matrix |
|
|
from mathutils import Vector |
|
|
from mathutils import Vector |
|
|
#from mathutils import Euler |
|
|
# from mathutils import Euler |
|
|
|
|
|
|
|
|
ob1 = None |
|
|
ob1 = None |
|
|
try: |
|
|
try: |
|
@ -32,13 +33,14 @@ class MessageBox(bpy.types.Operator): |
|
|
return {'FINISHED'} |
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
|
def invoke(self, context, event): |
|
|
def invoke(self, context, event): |
|
|
return context.window_manager.invoke_props_dialog(self, width = 400) |
|
|
return context.window_manager.invoke_props_dialog(self, |
|
|
|
|
|
width=400) |
|
|
|
|
|
|
|
|
def draw(self, context): |
|
|
def draw(self, context): |
|
|
self.layout.label(self.message) |
|
|
self.layout.label(self.message) |
|
|
self.layout.label("") |
|
|
self.layout.label("") |
|
|
#col = self.layout.column(align = True) |
|
|
# col = self.layout.column(align = True) |
|
|
#col.prop(context.scene, "my_string_prop") |
|
|
# col.prop(context.scene, "my_string_prop") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bpy.utils.register_class(MessageBox) |
|
|
bpy.utils.register_class(MessageBox) |
|
@ -56,32 +58,24 @@ if (mesh is not None) and (not hasattr(mesh, 'vertices')): |
|
|
msg = "Collision box for armatures cannot be calculated." |
|
|
msg = "Collision box for armatures cannot be calculated." |
|
|
bpy.ops.message.messagebox('INVOKE_DEFAULT', message = msg) |
|
|
bpy.ops.message.messagebox('INVOKE_DEFAULT', message = msg) |
|
|
else: |
|
|
else: |
|
|
#print(str(thisO)) |
|
|
# extents1 = ob1.dimensions.copy() |
|
|
#extents1 = ob1.dimensions.copy() |
|
|
|
|
|
#if (extents1.x == 0.0) and (extents1.y == 0.0) and (extents1.z == 0.0) and (ob1.scale.x > 0.0): |
|
|
|
|
|
#extents1.x = extents1.x / 10.0 |
|
|
|
|
|
#extents1.y = extents1.y / 10.0 |
|
|
|
|
|
#extents1.z = extents1.z / 10.0 |
|
|
|
|
|
obj1Loc = ob1.location |
|
|
obj1Loc = ob1.location |
|
|
#obj1Loc = ob1.matrix_world.translation |
|
|
|
|
|
#print(str(extents1)) |
|
|
|
|
|
|
|
|
|
|
|
#see https://blender.stackexchange.com/questions/8459/get-blender-x-y-z-and-bounding-box-with-script |
|
|
# See https://blender.stackexchange.com/questions/8459/get-blender-x-y-z-and-bounding-box-with-script |
|
|
#bbox_corners = [ob1.matrix_world * Vector(corner) for corner in ob1.bound_box] |
|
|
# bbox_corners = [ob1.matrix_world * Vector(corner) for corner in ob1.bound_box] |
|
|
|
|
|
|
|
|
|
|
|
# use ground as bottom (don't do this--it is not the Minetest way) |
|
|
|
|
|
# if zMin < 0.0: |
|
|
|
|
|
# yMax -= yMin |
|
|
|
|
|
# yMin = 0.0 |
|
|
|
|
|
|
|
|
#use ground as bottom |
|
|
print(" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}," |
|
|
#if zMin < 0.0: |
|
|
" {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax)) |
|
|
# yMax -= yMin |
|
|
|
|
|
# yMin = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
#print( |
|
|
# See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes |
|
|
# " collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax) |
|
|
# print("mesh:" + str(mesh)) |
|
|
#) |
|
|
# print("hasattr(mesh, 'vertices'):" |
|
|
|
|
|
# + str(hasattr(mesh, 'vertices')))] |
|
|
#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("hasattr(mesh, 'vertices'):" + str(hasattr(mesh, 'vertices')))] |
|
|
|
|
|
xMin = None |
|
|
xMin = None |
|
|
if mesh is not None: |
|
|
if mesh is not None: |
|
|
xMin = None |
|
|
xMin = None |
|
@ -112,20 +106,13 @@ else: |
|
|
zMax = loc.z |
|
|
zMax = loc.z |
|
|
# print(str(extents1)) |
|
|
# print(str(extents1)) |
|
|
# print("--by vertices (raw):") |
|
|
# print("--by vertices (raw):") |
|
|
# print( |
|
|
print(" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}," |
|
|
# " collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax) |
|
|
" {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, |
|
|
#) |
|
|
zMax)) |
|
|
|
|
|
|
|
|
# use ob1.matrix_world instead of incrementing location. |
|
|
|
|
|
# xMax += ob1.location.x |
|
|
|
|
|
# xMin += ob1.location.x |
|
|
|
|
|
# yMax += ob1.location.y |
|
|
|
|
|
# yMin += ob1.location.y |
|
|
|
|
|
# zMax += ob1.location.z |
|
|
|
|
|
# zMin += ob1.location.z |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Use ob1.matrix_world (above) instead of incrementing |
|
|
|
|
|
# ob1.location.x, y, and z |
|
|
|
|
|
|
|
|
# print("--by vertices:") |
|
|
|
|
|
newNamePrefix = "Empty.EDGE." + ob1.name |
|
|
newNamePrefix = "Empty.EDGE." + ob1.name |
|
|
i = 0 |
|
|
i = 0 |
|
|
wm = ob1.matrix_world |
|
|
wm = ob1.matrix_world |
|
@ -135,17 +122,21 @@ else: |
|
|
loc = mat @ vert.co # NOT transitive |
|
|
loc = mat @ vert.co # NOT transitive |
|
|
except TypeError: |
|
|
except TypeError: |
|
|
loc = mat * vert.co # Blender <2.8 |
|
|
loc = mat * vert.co # Blender <2.8 |
|
|
isFar = True |
|
|
isFar = False |
|
|
if loc.x == xMax or loc.y == yMax or loc.z == zMax: |
|
|
if loc.x == xMax or loc.y == yMax or loc.z == zMax: |
|
|
isFar = True |
|
|
isFar = True |
|
|
elif loc.x == xMin or loc.y == yMin or loc.z == zMin: |
|
|
elif loc.x == xMin or loc.y == yMin or loc.z == zMin: |
|
|
isFar = True |
|
|
isFar = True |
|
|
if isFar: |
|
|
if isFar: |
|
|
# result = bpy.ops.object.add(type = 'EMPTY', radius = .25, location = loc); |
|
|
pass |
|
|
|
|
|
# result = bpy.ops.object.add(type='EMPTY', radius=.25, |
|
|
|
|
|
# location=loc); |
|
|
# NOTE: result is merely {'FINISHED'} |
|
|
# NOTE: result is merely {'FINISHED'} |
|
|
# print("{:.2f}, {:.2f}, {:.2f}".format(loc.x, loc.y, 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', |
|
|
|
|
|
radius=.25, location=loc) |
|
|
i += 1 |
|
|
i += 1 |
|
|
else: |
|
|
else: |
|
|
extents1 = ob1.scale.copy() |
|
|
extents1 = ob1.scale.copy() |
|
@ -161,7 +152,7 @@ else: |
|
|
zMax = obj1Loc.z + extents1.z / 2.0 |
|
|
zMax = obj1Loc.z + extents1.z / 2.0 |
|
|
msgSuffix = " (using Empty object's scale)" |
|
|
msgSuffix = " (using Empty object's scale)" |
|
|
# print("--using empty object:") |
|
|
# print("--using empty object:") |
|
|
#switch y and z for Minetest (y-up): |
|
|
# switch y and z for Minetest (y-up): |
|
|
if enable_minetest: |
|
|
if enable_minetest: |
|
|
xMin /= 10.0 |
|
|
xMin /= 10.0 |
|
|
xMax /= 10.0 |
|
|
xMax /= 10.0 |
|
@ -170,7 +161,8 @@ else: |
|
|
zMin /= 10.0 |
|
|
zMin /= 10.0 |
|
|
zMax /= 10.0 |
|
|
zMax /= 10.0 |
|
|
|
|
|
|
|
|
msg = 'Size is not available. Make sure you have a mesh object selected.' |
|
|
msg = ('Size is not available. Make sure you have a mesh object' |
|
|
|
|
|
' selected.') |
|
|
|
|
|
|
|
|
if xMin is not None: |
|
|
if xMin is not None: |
|
|
if y_up: |
|
|
if y_up: |
|
@ -180,13 +172,15 @@ else: |
|
|
tmp = yMax |
|
|
tmp = yMax |
|
|
yMax = zMax |
|
|
yMax = zMax |
|
|
zMax = tmp |
|
|
zMax = tmp |
|
|
msg = " collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, zMax) |
|
|
msg = (" collisionbox = {{{:.2f}, {:.2f}, {:.2f}, {:.2f}," |
|
|
|
|
|
" {:.2f}, {:.2f}}}".format(xMin, yMin, zMin, xMax, yMax, |
|
|
|
|
|
zMax)) |
|
|
msg += msgSuffix |
|
|
msg += msgSuffix |
|
|
if enable_minetest: |
|
|
# if enable_minetest: |
|
|
msg += " #*10" |
|
|
# msg += " -- *10" |
|
|
print(msg) |
|
|
print(msg) |
|
|
|
|
|
|
|
|
bpy.ops.message.messagebox('INVOKE_DEFAULT', message = msg) |
|
|
bpy.ops.message.messagebox('INVOKE_DEFAULT', message=msg) |
|
|
|
|
|
|
|
|
# Unregistering before user clicks the MessageBox will crash Blender! |
|
|
# Unregistering before user clicks the MessageBox will crash Blender! |
|
|
# bpy.utils.unregister_class(MessageBox) |
|
|
# bpy.utils.unregister_class(MessageBox) |
|
|