Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==========================================================================================
- # BIOHAZARD 1.5/2/3 .RID (Camera data) Import sample, for Blender 2.5x+
- #==========================================================================================
- # 2014, mortician ([email protected])
- #==========================================================================================
- import struct
- import bpy
- def flip_axis(value):
- if (value <= 0):
- value = abs(value)
- else:
- value = -abs(value)
- return value
- def import_rid(filepath):
- #Open file...
- rdt_file = open(filepath, 'rb')
- #Jump to offset 1, then obtain the number of cameras (h_cut) in the room...
- rdt_file.seek(1)
- h_cut = int(struct.unpack("B", rdt_file.read(1))[0])
- #Get RID (camera data) offset then jump there
- rdt_file.seek(36)
- o_rid = int(struct.unpack("L", rdt_file.read(4))[0])
- rdt_file.seek(o_rid)
- #Read camera data...
- for i in range(h_cut):
- e_flg = int(struct.unpack("H", rdt_file.read(2))[0])
- fov = float(struct.unpack("H", rdt_file.read(2))[0]) / 1000.0
- x = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
- y = flip_axis(float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0)
- z = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
- tx = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
- ty = flip_axis(float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0)
- tz = float(struct.unpack("l", rdt_file.read(4))[0]) / 1000.0
- o_pri = int(struct.unpack("L", rdt_file.read(4))[0])
- #Create camera object...
- cam = bpy.data.cameras.new('CAM_' + "{0:0>2}".format(i))
- cam_ob = bpy.data.objects.new('CAM_' + "{0:0>2}".format(i), cam)
- bpy.context.scene.objects.link(cam_ob)
- cam_ob.location = (x, z, y)
- cam_ob.data.lens = fov - 6
- #Create target/aim...
- empty = bpy.data.objects.new('CAM_' + "{0:0>2}".format(i) + '_AIM', None)
- bpy.context.scene.objects.link(empty)
- empty.location = (tx, tz, ty)
- #Set the target constraint...
- cam_ob.select = True
- bpy.data.objects['CAM_' + "{0:0>2}".format(i) + '_AIM'].select = True
- aim = cam_ob.constraints.new('TRACK_TO')
- aim.target = empty
- aim.track_axis = 'TRACK_NEGATIVE_Z'
- aim.up_axis = 'UP_Y'
- #Update scene
- bpy.ops.group.create(name='RID_' + "{0:0>2}".format(i))
- bpy.context.scene.update()
- bpy.ops.object.select_all(action="TOGGLE")
- #Set scene render resolution to 640x480...
- bpy.context.scene.render.resolution_x = 640
- bpy.context.scene.render.resolution_y = 480
- bpy.context.scene.render.resolution_percentage = 100
- rdt_file.close()
- #Call function...
- import_rid('C:/room1000.rdt') #Change this path to load the file in question ;)
Advertisement
Add Comment
Please, Sign In to add comment