用blender环绕物体拍摄

用blender球形环绕物体拍摄

相机位置

相机位置使用球面函数计算。
相机位置 V:
在这里插入图片描述

在这里插入图片描述

相机旋转根据欧拉角计算

blender中相机坐标系
在这里插入图片描述
xyz的欧拉角旋转是绕世界系的xyz旋转的。
欧拉角计算:
旋转根据当前相机位置:

θz = acos(y*(x,y,0))
如果x >0
θz = 180-θz
反之
θz = θz - 180

θx = acos(z*V)

θy = 恒等于0

def creatCamera(T_location,Rotation_euler,scale):

    scene = bpy.context.scene
    sensor_width_in_mm = K[1][1]*K[0][2] / (K[0][0]*K[1][2])
    sensor_height_in_mm = 1  # doesn't matter
    resolution_x_in_px = K[0][2]*2  # principal point assumed at the center
    resolution_y_in_px = K[1][2]*2  # principal point assumed at the center

    s_u = resolution_x_in_px / sensor_width_in_mm
    s_v = resolution_y_in_px / sensor_height_in_mm
    # TODO include aspect ratio
    f_in_mm = K[0][0] / s_u
    # recover original resolution
    scene.render.resolution_x = resolution_x_in_px / scale
    scene.render.resolution_y = resolution_y_in_px / scale
    scene.render.resolution_percentage = scale * 100
    
    # create a new camera
    bpy.ops.object.add(
        type='CAMERA',
        location=T_location)
    ob = bpy.context.object
    ob.name = 'CamFrom3x4PObj'
    cam = ob.data
    cam.name = 'CamFrom3x4P'

    # Lens
    cam.type = 'PERSP'
    cam.lens = f_in_mm 
    cam.lens_unit = 'MILLIMETERS'
    cam.sensor_width  = sensor_width_in_mm
    
    pi = math.pi
    ob.rotation_mode = 'XYZ'
    
    ob.rotation_euler[0] = Rotation_euler[0] * (pi / 180.0)
    ob.rotation_euler[1] = Rotation_euler[1] * (pi / 180.0)
    ob.rotation_euler[2] = Rotation_euler[2] * (pi / 180.0)

    # Display
    cam.show_name = True
    # Make this the current camera
    scene.camera = ob
    #bpy.context.scene.update()
def getRotationFromLocation(T_location):
    V = T_location

    Y_axis =  Vector((.0 , 1.0 ,.0))
    Z_axis =  Vector((.0 , .0 ,1.0))

    tempV = Vector((T_location[0] , T_location[1] ,.0))
   
    pi = math.pi
    sitaZ = tempV.angle(Y_axis)
    sitaZ = (180.0 * sitaZ) / pi

    sitaX = V.angle(Z_axis)
    sitaX = (180.0 * sitaX) / pi
    if(T_location[0] < 0):
        Rotation_euler = Vector((sitaX , 1.0 ,sitaZ-180.0))
    else:
        Rotation_euler = Vector((sitaX , 1.0 ,180.0-sitaZ))
    print(Rotation_euler)
    
    return Rotation_euler

if __name__ == "__main__":
    pi = math.pi

    nRows = 5
    nCols = 14
    weidu_angles = [30,60,90,120,150]
    r = 10.0
    pi = math.pi

    for j in range(nRows):
        weidu = weidu_angles[j] / 180.0 * pi
        for i in range(nCols):
            jingdu = (i*360.0/nCols - 180.0) / 180.0 * pi
            print(math.sin(weidu))
            x = r*math.sin(weidu)*math.cos(jingdu)
            y = r*math.sin(weidu)*math.sin(jingdu)
            z = r*math.cos(weidu)

            K = Matrix(
            ([2666.666748046875 ,  0 , 960.0],
            [0 ,  2666.666748046875 , 540.0],
            [0 ,  0 , 1])
            )


            T_location = Vector((x , y , z))
            print(T_location)

            #T_location = Vector((-13.9922 , -9.63222 , 4.01505))

            Rotation_euler = getRotationFromLocation(T_location)

            #Rotation_euler = Vector((76.8264 , 0 , -55.3262))
            creatCamera(T_location,Rotation_euler,1)

结果:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值