from panda3dcore import Point3from panda3dcore import NodePathfrom directshowbaseShowBase import ShowBasefrom directactorActor import Actorclass MyAppShowBase def __init__self ShowBase__init
The error is caused by using the getTightBounds() method on a BoundingSphere object, which does not have this method. To fix this, you can use the getBounds() method instead, which returns a BoundingBox object that does have the getTightBounds() method. Here's the updated code:
from panda3d.core import Point3 from panda3d.core import NodePath from direct.showbase.ShowBase import ShowBase from direct.actor.Actor import Actor
class MyApp(ShowBase): def init(self): ShowBase.init(self)
# 加载模型1.glb
model = self.loader.loadModel("models/box")
model.reparentTo(self.render)
# 获取模型边界框
bounds = model.getBounds()
bbox = bounds.asBox()
min_point, max_point = bbox.getTightBounds()
# 计算边框8个顶点坐标
vertices = [
Point3(min_point[0], min_point[1], min_point[2]),
Point3(max_point[0], min_point[1], min_point[2]),
Point3(max_point[0], max_point[1], min_point[2]),
Point3(min_point[0], max_point[1], min_point[2]),
Point3(min_point[0], min_point[1], max_point[2]),
Point3(max_point[0], min_point[1], max_point[2]),
Point3(max_point[0], max_point[1], max_point[2]),
Point3(min_point[0], max_point[1], max_point[2]),
]
print(vertices)
app = MyApp() app.run(
原文地址: https://www.cveoy.top/t/topic/g6Gz 著作权归作者所有。请勿转载和采集!