The error 'AttributeError: 'panda3d.core.BoundingSphere' object has no attribute 'getTightBounds'' occurs because the getTightBounds() method is not available for BoundingSphere objects in Panda3D. To get the tight bounds, you need to use the getBounds() method, which returns a BoundingBox object that does have the getTightBounds() method.

Here's the corrected 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()

This code first gets the model's bounding box using model.getBounds(). Then, it converts the BoundingSphere to a BoundingBox using the asBox() method. Finally, it calls getTightBounds() on the BoundingBox to get the minimum and maximum points, which are then used to calculate the vertices of the bounding box.

By using this corrected code, you can successfully obtain the tight bounds of a model in Panda3D and avoid the AttributeError.

Panda3D: Fix AttributeError 'BoundingSphere' object has no attribute 'getTightBounds'

原文地址: https://www.cveoy.top/t/topic/oAWJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录