def set_selected_object(self, object_name): selected_object = self.get_object(object_name) if self.selected_object is not selected_object: self.clear_selected_axis_gizmo_id() self.clear_spline_gizmo() self.selected_object_render_info = [] if self.selected_object and hasattr(self.selected_object, "set_selected"): self.selected_object.set_selected(False) # set selected object self.selected_object = selected_object if selected_object is not None: if hasattr(selected_object, "get_object_id"): self.set_selected_object_id( selected_object.get_object_id()) if hasattr(selected_object, "set_selected"): selected_object.set_selected(True) if type(selected_object) in (SkeletonActor, StaticActor): gather_render_infos( culling_func=always_pass, camera=self.main_camera, light=self.main_light, actor_list=[ self.selected_object, ], solid_render_infos=self.selected_object_render_info, translucent_render_infos=self. selected_object_render_info) elif type(selected_object) is Spline3D: self.create_spline_gizmo(selected_object)
def update_skeleton_render_info(self): self.skeleton_solid_render_infos = [] self.skeleton_translucent_render_infos = [] self.skeleton_shadow_render_infos = [] if RenderOption.RENDER_SKELETON_ACTOR: gather_render_infos( culling_func=view_frustum_culling_geometry, camera=self.main_camera, light=self.main_light, actor_list=self.skeleton_actors, solid_render_infos=self.skeleton_solid_render_infos, translucent_render_infos=self.skeleton_translucent_render_infos ) gather_render_infos( culling_func=shadow_culling, camera=self.main_camera, light=self.main_light, actor_list=self.skeleton_actors, solid_render_infos=self.skeleton_shadow_render_infos, translucent_render_infos=None) self.skeleton_solid_render_infos.sort( key=lambda x: (id(x.geometry), id(x.material))) self.skeleton_translucent_render_infos.sort( key=lambda x: (id(x.geometry), id(x.material)))
def update_static_render_info(self): self.static_solid_render_infos = [] self.static_translucent_render_infos = [] self.static_shadow_render_infos = [] gather_render_infos(culling_func=view_frustum_culling_geometry, camera=self.main_camera, light=self.main_light, actor_list=self.static_actors, solid_render_infos=self.static_solid_render_infos, translucent_render_infos=self.static_translucent_render_infos) gather_render_infos(culling_func=shadow_culling, camera=self.main_camera, light=self.main_light, actor_list=self.static_actors, solid_render_infos=self.static_shadow_render_infos, translucent_render_infos=None) self.static_solid_render_infos.sort(key=lambda x: (id(x.geometry), id(x.material))) self.static_translucent_render_infos.sort(key=lambda x: (id(x.geometry), id(x.material)))
def update_scene(self, dt): self.renderer.postprocess.update() for camera in self.cameras: camera.update() if self.main_light is not None: self.main_light.update(self.main_camera) for light in self.point_lights: light.update() for static_actor in self.static_actors: static_actor.update(dt) for skeleton_actor in self.skeleton_actors: skeleton_actor.update(dt) self.atmosphere.update(self.main_light) self.ocean.update(dt) if self.terrain.is_render_terrain: self.terrain.update(dt) self.effect_manager.update(dt) # culling self.update_static_render_info() self.update_skeleton_render_info() self.update_light_render_infos() self.selected_object_render_info = [] if self.selected_object is not None and type(self.selected_object) in (SkeletonActor, StaticActor): gather_render_infos(culling_func=always_pass, camera=self.main_camera, light=self.main_light, actor_list=[self.selected_object, ], solid_render_infos=self.selected_object_render_info, translucent_render_infos=self.selected_object_render_info)
def create_spline_gizmo(self, spline): spline_point_name = spline.name + '_point' control_point_name = spline.name + '_control_point' gizmo_model = self.resource_manager.get_model('Cube') if len(spline.spline_data.spline_points) < 1: return for spline_point in spline.spline_data.spline_points: pos = np.dot(Float4(*spline_point.position, 1.0), spline.transform.matrix)[:3] gizmo_object = StaticActor(name=spline_point_name, model=gizmo_model, pos=Float3(*pos), scale=Float3(0.1, 0.1, 0.1), object_id=self.generate_object_id(), object_color=Float3(0.5, 0.5, 1.0)) self.spline_gizmo_object_map[ gizmo_object.get_object_id()] = gizmo_object spline_point = spline.spline_data.spline_points[0] def create_spline_control_point_gizmo(spline_gizmo_object_map, object_id, inverse): if inverse: pos = np.dot( Float4( *(spline_point.position + spline_point.control_point), 1.0), spline.transform.matrix)[:3] else: pos = np.dot( Float4( *(spline_point.position - spline_point.control_point), 1.0), spline.transform.matrix)[:3] gizmo_object = StaticActor(name=control_point_name, model=gizmo_model, pos=Float3(*pos), scale=Float3(0.075, 0.075, 0.075), object_id=object_id, object_color=Float3(0.0, 1.0, 0.0)) spline_gizmo_object_map[ gizmo_object.get_object_id()] = gizmo_object return gizmo_object.get_object_id() self.spline_control_point_gizmo_id0 = create_spline_control_point_gizmo( self.spline_gizmo_object_map, self.generate_object_id(), inverse=False) self.spline_control_point_gizmo_id1 = create_spline_control_point_gizmo( self.spline_gizmo_object_map, self.generate_object_id(), inverse=True) # select first spline gizmo object # self.set_selected_spline_gizmo_id(list(self.spline_gizmo_object_map.keys())[0]) gather_render_infos(culling_func=always_pass, camera=self.main_camera, light=self.main_light, actor_list=self.spline_gizmo_object_map.values(), solid_render_infos=self.spline_gizmo_render_infos, translucent_render_infos=None)