__init__.py 文件源码

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

项目:bpy_lambda 作者: bcongdon 项目源码 文件源码
def createObjects(tree, parent=None, objectname=None, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1, maxconnections=2, bunchiness=1.0):

    if (parent is None) or (objectname is None) or (objectname == 'None'):
        return

    # not necessary, we parent the new objects: p=bpy.context.scene.cursor_location

    theobject = bpy.data.objects[objectname]

    t = gauss(1.0 / probability, 0.1)
    bpswithleaves = 0
    for bp in tree.branchpoints:
        if bp.connections < maxconnections:

            dv = tree.branchpoints[bp.parent].v - bp.v if bp.parent else Vector((0, 0, 0))
            dvp = Vector((0, 0, 0))

            bpswithleaves += 1
            nleavesonbp = 0
            while t < bpswithleaves:
                nleavesonbp += 1
                rx = (random() - 0.5) * randomrot * 6.283  # TODO vertical tilt in direction of tropism
                ry = (random() - 0.5) * randomrot * 6.283
                rot = Euler((rx, ry, random() * 6.283), 'ZXY')
                scale = size + (random() - 0.5) * randomsize

                # add new object and parent it
                obj = bpy.data.objects.new(objectname, theobject.data)
                obj.location = bp.v + dvp
                obj.rotation_mode = 'ZXY'
                obj.rotation_euler = rot[:]
                obj.scale = [scale, scale, scale]
                obj.parent = parent
                bpy.context.scene.objects.link(obj)

                t += gauss(1.0 / probability, 0.1)                      # this is not the best choice of distribution because we might get negative values especially if sigma is large
                dvp = nleavesonbp * (dv / (probability ** bunchiness))  # TODO add some randomness to the offset
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号