lsystem.py 文件源码

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

项目:tree-gen 作者: friggog 项目源码 文件源码
def add_points_to_bez(self, line, point1, point2, width, trunk=False):
        """add point to specific bezier spline"""
        direction = (point2 - point1)
        handle_f = 0.3

        # if exists get middle point in branch
        if len(line.bezier_points) > 1:
            start_point = line.bezier_points[-1]
            # linearly interpolate branch width between start and end of branch
            start_point.radius = line.bezier_points[-2].radius * 0.5 + width * 0.5
            # add bendiness to branch by rotating direction about random axis by random angle
            if self.bendiness > 0:
                acc_dir = direction.rotated(Quaternion(Vector.random(), radians(self.bendiness * (random() * 35 - 20))))
            else:
                acc_dir = direction
            start_point.handle_right = point1 + handle_f * acc_dir
            start_point.handle_left = point1 - handle_f * acc_dir
        else:
            # scale initial handle to match branch length
            start_point = line.bezier_points[-1]
            if trunk:
                # if trunk we also need to set the start width
                start_point.radius = width
                start_point.handle_right = start_point.co + Vector([0, 0, direction.magnitude * handle_f])
            else:
                start_point.handle_right = start_point.co + (start_point.handle_right -
                                                             start_point.co) * direction.magnitude * handle_f
                start_point.handle_left = start_point.co + (start_point.handle_left -
                                                            start_point.co) * direction.magnitude * handle_f

        # add new point to line and set position, direction and width
        line.bezier_points.add()
        end_point = line.bezier_points[-1]
        end_point.co = point2
        end_point.handle_right = point2 + handle_f * direction
        end_point.handle_left = point2 - handle_f * direction
        end_point.radius = width
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号