Guest User

BIOHAZARD 1.5/2/3 .RID (Camera data) Import sample, for Blen

a guest
Jan 8th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.97 KB | None | 0 0
  1. #==========================================================================================
  2. # BIOHAZARD 1.5/2/3 .RID (Camera data) Import sample, for Blender 2.5x+
  3. #==========================================================================================
  4. # 2014, mortician ([email protected])
  5. #==========================================================================================
  6. import struct
  7. import bpy
  8.  
  9. def flip_axis(value):
  10.  
  11.     if (value <= 0):
  12.         value = abs(value)
  13.     else:
  14.         value = -abs(value)
  15.    
  16.     return value
  17.  
  18. def import_rid(filepath):
  19.  
  20.     #Open file...
  21.     rdt_file = open(filepath, 'rb')
  22.     #Jump to offset 1, then obtain the number of cameras (h_cut) in the room...
  23.     rdt_file.seek(1)
  24.     h_cut = int(struct.unpack("B", rdt_file.read(1))[0])
  25.     #Get RID (camera data) offset then jump there
  26.     rdt_file.seek(36)
  27.     o_rid = int(struct.unpack("L", rdt_file.read(4))[0])
  28.     rdt_file.seek(o_rid)
  29.    
  30.     #Read camera data...
  31.     for i in range(h_cut):
  32.    
  33.         e_flg = int(struct.unpack("H", rdt_file.read(2))[0])
  34.         fov = float(struct.unpack("H", rdt_file.read(2))[0]) / 1000.0
  35.         x = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
  36.         y = flip_axis(float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0)
  37.         z = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
  38.         tx = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
  39.         ty = flip_axis(float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0)
  40.         tz = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
  41.         o_pri = int(struct.unpack("L", rdt_file.read(4))[0])
  42.  
  43.         #Create camera object...
  44.         cam = bpy.data.cameras.new('CAM_' + "{0:0>2}".format(i))
  45.         cam_ob = bpy.data.objects.new('CAM_' + "{0:0>2}".format(i), cam)
  46.         bpy.context.scene.objects.link(cam_ob)      
  47.         cam_ob.location = (x, z, y)
  48.         cam_ob.data.lens = fov - 6
  49.          
  50.         #Create target/aim...
  51.         empty = bpy.data.objects.new('CAM_' + "{0:0>2}".format(i) + '_AIM', None)
  52.         bpy.context.scene.objects.link(empty)
  53.         empty.location = (tx, tz, ty)
  54.  
  55.         #Set the target constraint...
  56.         cam_ob.select = True
  57.         bpy.data.objects['CAM_' + "{0:0>2}".format(i) + '_AIM'].select = True
  58.         aim = cam_ob.constraints.new('TRACK_TO')
  59.         aim.target = empty
  60.         aim.track_axis = 'TRACK_NEGATIVE_Z'
  61.         aim.up_axis = 'UP_Y'
  62.        
  63.         #Update scene
  64.         bpy.ops.group.create(name='RID_' + "{0:0>2}".format(i))
  65.         bpy.context.scene.update()
  66.         bpy.ops.object.select_all(action="TOGGLE")
  67.        
  68.         #Set scene render resolution to 640x480...
  69.         bpy.context.scene.render.resolution_x = 640
  70.         bpy.context.scene.render.resolution_y = 480
  71.         bpy.context.scene.render.resolution_percentage = 100
  72.      
  73.     rdt_file.close()
  74.  
  75.  
  76.  
  77. #Call function...
  78. import_rid('C:/room1000.rdt') #Change this path to load the file in question ;)
Advertisement
Add Comment
Please, Sign In to add comment