update renderer
This commit is contained in:
parent
7ac50c6523
commit
9f0225c6d8
@ -6,7 +6,7 @@ import mathutils
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
from utils.blender_util import BlenderUtils
|
from utils.blender_util import BlenderUtils
|
||||||
|
from utils.material_util import MaterialUtil
|
||||||
|
|
||||||
class DataRenderer:
|
class DataRenderer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -23,8 +23,8 @@ class DataRenderer:
|
|||||||
"near_plane": 0.01,
|
"near_plane": 0.01,
|
||||||
"far_plane": 5,
|
"far_plane": 5,
|
||||||
"fov_vertical": 25,
|
"fov_vertical": 25,
|
||||||
"resolution": [1280, 800],
|
"resolution": [640, 400],
|
||||||
"eye_distance": 0.15,
|
"eye_distance": 0.10,
|
||||||
"eye_angle": 25
|
"eye_angle": 25
|
||||||
},
|
},
|
||||||
"Light": {
|
"Light": {
|
||||||
@ -64,9 +64,17 @@ class DataRenderer:
|
|||||||
if "." in object_name:
|
if "." in object_name:
|
||||||
object_name = object_name.split(".")[0]
|
object_name = object_name.split(".")[0]
|
||||||
BlenderUtils.set_camera_at(cam_pose)
|
BlenderUtils.set_camera_at(cam_pose)
|
||||||
BlenderUtils.render_and_save(temp_dir, temp_file_name, binocular_vision=self.binocular_vision)
|
BlenderUtils.render_mask(temp_dir, temp_file_name, binocular_vision=self.binocular_vision)
|
||||||
|
BlenderUtils.render_normal_and_depth(temp_dir, temp_file_name, binocular_vision=self.binocular_vision)
|
||||||
|
BlenderUtils.save_cam_params(temp_dir, temp_file_name, binocular_vision=self.binocular_vision)
|
||||||
|
depth_dir = os.path.join(temp_dir, "depth")
|
||||||
|
for depth_file in os.listdir(depth_dir):
|
||||||
|
if not depth_file.endswith(".png"):
|
||||||
|
name, _ = os.path.splitext(depth_file)
|
||||||
|
file_path = os.path.join(depth_dir, depth_file)
|
||||||
|
new_file_path = os.path.join(depth_dir, f"{name}.png")
|
||||||
|
os.rename(file_path,new_file_path)
|
||||||
|
|
||||||
def restore_scene(self, restore_info):
|
def restore_scene(self, restore_info):
|
||||||
|
|
||||||
for obj_name, obj_info in restore_info.items():
|
for obj_name, obj_info in restore_info.items():
|
||||||
@ -82,12 +90,7 @@ class DataRenderer:
|
|||||||
obj.location = mathutils.Vector(obj_info["location"])
|
obj.location = mathutils.Vector(obj_info["location"])
|
||||||
obj.rotation_euler = mathutils.Vector(obj_info["rotation_euler"])
|
obj.rotation_euler = mathutils.Vector(obj_info["rotation_euler"])
|
||||||
obj.scale = mathutils.Vector(obj_info["scale"])
|
obj.scale = mathutils.Vector(obj_info["scale"])
|
||||||
mat = bpy.data.materials.new(name="GreenMaterial")
|
MaterialUtil.change_object_material(obj, MaterialUtil.create_mask_material(color=(0, 1.0, 0)))
|
||||||
mat.diffuse_color = (0.0, 1.0, 0.0, 1.0) # Green with full alpha (1.0)
|
|
||||||
if len(obj.data.materials) > 0:
|
|
||||||
obj.data.materials[0] = mat
|
|
||||||
else:
|
|
||||||
obj.data.materials.append(mat)
|
|
||||||
self.target_obj = obj
|
self.target_obj = obj
|
||||||
|
|
||||||
def restore_display_platform(self, platform_info):
|
def restore_display_platform(self, platform_info):
|
||||||
@ -96,16 +99,9 @@ class DataRenderer:
|
|||||||
platform.name = BlenderUtils.DISPLAY_TABLE_NAME
|
platform.name = BlenderUtils.DISPLAY_TABLE_NAME
|
||||||
platform.location = mathutils.Vector(platform_info["location"])
|
platform.location = mathutils.Vector(platform_info["location"])
|
||||||
|
|
||||||
mat = bpy.data.materials.new(name="RedMaterial")
|
|
||||||
mat.diffuse_color = (1.0, 0.0, 0.0, 1.0) # Red with full alpha (1.0)
|
|
||||||
if len(platform.data.materials) > 0:
|
|
||||||
platform.data.materials[0] = mat
|
|
||||||
else:
|
|
||||||
platform.data.materials.append(mat)
|
|
||||||
|
|
||||||
bpy.ops.rigidbody.object_add()
|
bpy.ops.rigidbody.object_add()
|
||||||
bpy.context.object.rigid_body.type = 'PASSIVE'
|
bpy.context.object.rigid_body.type = 'PASSIVE'
|
||||||
bpy.ops.object.shade_auto_smooth()
|
MaterialUtil.change_object_material(platform, MaterialUtil.create_mask_material(color=(1.0, 0, 0)))
|
||||||
|
|
||||||
def main(temp_dir):
|
def main(temp_dir):
|
||||||
params_data_path = os.path.join(temp_dir, "params.json")
|
params_data_path = os.path.join(temp_dir, "params.json")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user