Blender发送FreeD数据

import struct
import bpy
import time
import threading
import socket
import datetime

FREQ = 50
buf = [0x00] * 29

def get_seconds():
 
    datetime_object = datetime.datetime.now()
    now_timetuple = datetime_object.timetuple()
    now_second = time.mktime(now_timetuple)
    mow_millisecond = int(now_second * 1000 + datetime_object.microsecond / 1000)
    
    #print "timetuple-- "+ str(now_timetuple)
    #print "datimeobject-- " + str(datetime_object)
    #print "second-- " + str(now_second)
    #print("millisecond-- " + str(mow_millisecond))
    
    return mow_millisecond

def pack_be24(b, p, r):
    
    b[p + 2] = r & 0xff
    r >>= 8
    b[p + 1] = r & 0xff
    r >>= 8
    b[p] = r & 0xff
    
def pack_be24_15(b, p, d):
    #print(int(d * 32768.0))
    pack_be24(b, p, int(d * 32768.0))
    
def pack_be24_6(b, p, d):
    pack_be24(b, p, int(d * 64.0))

def to_freed_pack(id, loc, rot):
    
    buf[0] = 0xd1
    
    # id
    buf[1] = id & 0xff
    
    # rot
    pack_be24_15(buf, 2, rot.z * 180.0 / 3.1415926) # Pan
    pack_be24_15(buf, 5, rot.x * 180.0 / 3.1415926) # Tilt
    pack_be24_15(buf, 8, rot.y * 180.0 / 3.1415926) # Roll
    
    # loc
    pack_be24_6(buf, 11, loc.x)
    pack_be24_6(buf, 14, loc.y)
    pack_be24_6(buf, 17, loc.z)
    
    pack_be24(buf, 20, 0) # zoom
    pack_be24(buf, 23, 0) # focus
    
    buf[26] = 0
    buf[27] = 0
    
    cs = 0x40
    
    for i in range(0, 28):
        cs -= buf[i]
        
    buf[28] = cs % 256

    return buf

class FreedSender(threading.Thread):
    def __init__(self, obj):
        self.obj = obj
        threading.Thread.__init__(self)
    
    def run(self):
        last_send_time = get_seconds()
        
        s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        
        while True:
            curr_time = get_seconds()
            
            if curr_time - last_send_time >= 20 :
                loc, rot, scale = self.obj.matrix_world.decompose()
                last_send_time = curr_time
                
                #print(type(rot))
                
                right_rot = rot
                right_rot.w *= -1
                right_loc = loc
                right_loc.x *= -1
                right_loc.y *= -1
                euler = right_rot.to_euler('ZXY')

                #print(loc)
                #print(rot)
                
                
                
                b = to_freed_pack(0, right_loc * 1000.0, euler)
                #print(b)
                s.sendto(bytes(b), ("192.168.3.190", 4546))
                
                last_send_time = curr_time
                
            #time.sleep(0.002)
 
'''    
for collection in bpy.data.collections:
   print(collection.name)
   for obj in collection.all_objects:
      print("obj: ", obj.name)  
'''
 
#obj = bpy.context.object
obj = bpy.data.objects['Cube']
print(obj)
runner = FreedSender(obj)
runner.start()

关于使用blender发送freed协议数据的代码,备忘。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用中提到的,本文使用了NeRF提供的synthetic数据集中的lego模型进行稠密重建,其中包含了lego模型的几张图片。NeRF是一种神经辐射场方法,用于进行视图合成和三维场景重建。 如果你想获取更多关于nerf的blender数据的信息,我建议你下载引用中分享的Blender工程和源码,根据你的需求进行验证和替换目标物体。这样你可以得到利用Instant Nerf生成的三维重构结果与真实值(GT)的比较。你也可以尝试将不明物体的STL文件导入到Blender中进行处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [COLMAP利用已知相机内外参重建NeRF的blender模型](https://blog.csdn.net/qq_38677322/article/details/126269726)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [利用Blender合成多视角图像For Nerf](https://blog.csdn.net/weixin_42317727/article/details/126770363)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值