12_scene_physic_kapla_interactive.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Tutorials 作者: harfang3d 项目源码 文件源码
def add_kapla_tower(scn, width, height, length, radius, level_count: int, x=0, y=0, z=0):
    """Create a Kapla tower, return a list of created nodes"""
    tower = []
    level_y = y + height / 2

    for i in range(level_count // 2):
        def fill_ring(r, ring_y, size, r_adjust, y_off):
            step = asin((size * 1.01) / 2 / (r - r_adjust)) * 2
            cube_count = (2 * pi) // step
            error = 2 * pi - step * cube_count
            step += error / cube_count  # distribute error

            a = 0
            while a < (2 * pi - error):
                world = gs.Matrix4.TransformationMatrix(gs.Vector3(cos(a) * r + x, ring_y, sin(a) * r + z), gs.Vector3(0, -a + y_off, 0))
                tower.append(plus.AddPhysicCube(scn, world, width, height, length, 2)[0])
                a += step

        fill_ring(radius - length / 2, level_y, width, length / 2, pi / 2)
        level_y += height
        fill_ring(radius - length + width / 2, level_y, length, width / 2, 0)
        fill_ring(radius - width / 2, level_y, length, width / 2, 0)
        level_y += height

    return tower
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号