def frame_callback(self): #print("frame") if self.action_flag == False: Tool.update_assigned_user(self) self.RESOURCE_SELECTOR.update_candidate_resources() self.select_active_resource()
def __init__( self, INITIATOR=None, INPUT=None, RAY_LENGHT=10.0, TOOL_THICKNESS=0.01 # in meter , LIGHT_COLOR=avango.gua.Color(1.0, 1.0, 1.0), LIGHT_BRIGHTNESS=10.0, LIGHT_DIMENSIONS=avango.gua.Vec3(1.0, 1.0, 1.0), SHADOW_FLAG=False, SHADOW_MAP_SIZE=512, VIEW_CONTEXT_LIST=[], VISIBILITY_DICTIONARY={}): ## init base class Tool.__init__(self, INITIATOR=INITIATOR, INPUT=INPUT, VIEW_CONTEXT_LIST=VIEW_CONTEXT_LIST, VISIBILITY_DICTIONARY=VISIBILITY_DICTIONARY, RESOURCE_SELECTOR=LightToolResourceSelector( TOOL=self, RAY_LENGTH=RAY_LENGHT)) ### parameters ### self.tool_thickness = 0.01 self.light_geometry_thickness = 0.02 self.light_color = avango.gua.Color(1.0, 1.0, 1.0) self.light_brightness = 10.0 self.light_dimensions = avango.gua.Vec3(1.0, 1.0, 1.0) self.shadow_flag = False self.shadow_map_size = 512 ### variables ### self.active_resource = None self.action_flag = False ### resources ### ## init script self.script = LightToolScript() self.script.my_constructor(self) ## init intersection self.default_intersection = Intersection(PICK_LENGTH=RAY_LENGHT, BLACK_LIST=["invisible"]) ## init intersection node self.intersection_node = avango.gua.nodes.TransformNode( Name="light_intersection_node") builtins.APPLICATION.append_node_to_root(self.intersection_node) self.intersection_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file( "intersection_geometry", "data/objects/sphere.obj", avango.gua.LoaderFlags.DEFAULTS) self.intersection_geometry.Material.value.set_uniform( "Emissivity", 0.5) self.intersection_geometry.ShadowMode.value = 0 # disable for shadowing self.intersection_geometry.Transform.value = avango.gua.make_scale_mat( 0.03) self.intersection_node.Children.value.append( self.intersection_geometry) self.offset_node = avango.gua.nodes.TransformNode(Name="offset_node") self.offset_node.Transform.value = avango.gua.make_trans_mat( 0.0, 0.0, 0.5) self.intersection_node.Children.value.append(self.offset_node) ## init flashlight geometries self.cube_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file( "flashlight_resource_cube_geometry", "data/objects/cube.obj", avango.gua.LoaderFlags.DEFAULTS) self.cube_geometry.Material.value.set_uniform("Emissivity", 0.5) self.cube_geometry.ShadowMode.value = 0 # disable for shadowing self.cube_geometry.Transform.value = avango.gua.make_scale_mat( self.light_geometry_thickness) self.offset_node.Children.value.append(self.cube_geometry) self.cone_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file( "flashlight_resource_cone_geometry", "data/objects/cone.obj", avango.gua.LoaderFlags.DEFAULTS) self.cone_geometry.Material.value.set_uniform("Emissivity", 1.0) # pass through self.cone_geometry.ShadowMode.value = 0 # disable for shadowing self.cone_geometry.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, -self.light_geometry_thickness) * \ avango.gua.make_scale_mat(self.light_geometry_thickness * 2.0) self.offset_node.Children.value.append(self.cone_geometry) ## init light node self.light_node = avango.gua.nodes.LightNode(Name="light_node") self.light_node.Type.value = avango.gua.LightType.SPOT #self.light_node.ShadowNearClippingInSunDirection.value = 0.01 #self.light_node.ShadowNearClippingInSunDirection.value = 0.1 * (1.0/LIGHT_DIMENSIONS.z) self.light_node.ShadowFarClippingInSunDirection.value = 1.1 self.light_node.Falloff.value = 0.5 self.offset_node.Children.value.append(self.light_node) ## trigger callbacks ## @var frame_trigger # Triggers framewise evaluation of respective callback method self.frame_trigger = avango.script.nodes.Update( Callback=self.frame_callback, Active=False) # Triggers framewise evaluation of respective callback method self.update_trigger = avango.script.nodes.Update( Callback=self.update_callback, Active=False) ### set initial states ### ## set tool properties self.set_thickness(TOOL_THICKNESS) ## set light properties self.set_light_color(LIGHT_COLOR) self.set_light_brightness(LIGHT_BRIGHTNESS) self.set_light_dimensions(LIGHT_DIMENSIONS) self.set_shadow_flag(SHADOW_FLAG) self.set_shadow_map_size(SHADOW_MAP_SIZE) print("LightTool initialized:", Tool.get_id(self))
def set_thickness(self, FLOAT): self.tool_thickness = FLOAT for _resource in Tool.get_resource_list(self): _resource.set_thickness(self.tool_thickness)
def connect_matrix(self, SF_MAT4): for _resource in Tool.get_resource_list(self): _resource.connect_matrix(SF_MAT4)
def enable(self, BOOL): Tool.enable(self, BOOL) # call base-class function self.frame_trigger.Active.value = self.enable_flag # enable/disable frame callback
def init(self): Tool.init(self) # call base-class function self.enable(True) self.connect_input()
def __init__( self , INITIATOR = None , INPUT = None , RAY_LENGHT = 10.0 , TOOL_THICKNESS = 0.01 # in meter , LIGHT_COLOR = avango.gua.Color(1.0,1.0,1.0) , LIGHT_BRIGHTNESS = 10.0 , LIGHT_DIMENSIONS = avango.gua.Vec3(1.0,1.0,1.0) , SHADOW_FLAG = False , SHADOW_MAP_SIZE = 512 , VIEW_CONTEXT_LIST = [] , VISIBILITY_DICTIONARY = {} ): ## init base class Tool.__init__( self , INITIATOR = INITIATOR , INPUT = INPUT , VIEW_CONTEXT_LIST = VIEW_CONTEXT_LIST , VISIBILITY_DICTIONARY = VISIBILITY_DICTIONARY , RESOURCE_SELECTOR = LightToolResourceSelector(TOOL = self, RAY_LENGTH = RAY_LENGHT) ) ### parameters ### self.tool_thickness = 0.01 self.light_geometry_thickness = 0.02 self.light_color = avango.gua.Color(1.0,1.0,1.0) self.light_brightness = 10.0 self.light_dimensions = avango.gua.Vec3(1.0,1.0,1.0) self.shadow_flag = False self.shadow_map_size = 512 ### variables ### self.active_resource = None self.action_flag = False ### resources ### ## init script self.script = LightToolScript() self.script.my_constructor(self) ## init intersection self.default_intersection = Intersection( PICK_LENGTH = RAY_LENGHT , BLACK_LIST = ["invisible"] ) ## init intersection node self.intersection_node = avango.gua.nodes.TransformNode(Name = "light_intersection_node") builtins.APPLICATION.append_node_to_root(self.intersection_node) self.intersection_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file("intersection_geometry", "data/objects/sphere.obj", avango.gua.LoaderFlags.DEFAULTS) self.intersection_geometry.Material.value.set_uniform("Emissivity", 0.5) self.intersection_geometry.ShadowMode.value = 0 # disable for shadowing self.intersection_geometry.Transform.value = avango.gua.make_scale_mat(0.03) self.intersection_node.Children.value.append(self.intersection_geometry) self.offset_node = avango.gua.nodes.TransformNode(Name = "offset_node") self.offset_node.Transform.value = avango.gua.make_trans_mat(0.0,0.0,0.5) self.intersection_node.Children.value.append(self.offset_node) ## init flashlight geometries self.cube_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file("flashlight_resource_cube_geometry", "data/objects/cube.obj", avango.gua.LoaderFlags.DEFAULTS) self.cube_geometry.Material.value.set_uniform("Emissivity", 0.5) self.cube_geometry.ShadowMode.value = 0 # disable for shadowing self.cube_geometry.Transform.value = avango.gua.make_scale_mat(self.light_geometry_thickness) self.offset_node.Children.value.append(self.cube_geometry) self.cone_geometry = builtins.TRIMESH_LOADER.create_geometry_from_file("flashlight_resource_cone_geometry", "data/objects/cone.obj", avango.gua.LoaderFlags.DEFAULTS) self.cone_geometry.Material.value.set_uniform("Emissivity", 1.0) # pass through self.cone_geometry.ShadowMode.value = 0 # disable for shadowing self.cone_geometry.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, -self.light_geometry_thickness) * \ avango.gua.make_scale_mat(self.light_geometry_thickness * 2.0) self.offset_node.Children.value.append(self.cone_geometry) ## init light node self.light_node = avango.gua.nodes.LightNode(Name = "light_node") self.light_node.Type.value = avango.gua.LightType.SPOT #self.light_node.ShadowNearClippingInSunDirection.value = 0.01 #self.light_node.ShadowNearClippingInSunDirection.value = 0.1 * (1.0/LIGHT_DIMENSIONS.z) self.light_node.ShadowFarClippingInSunDirection.value = 1.1 self.light_node.Falloff.value = 0.5 self.offset_node.Children.value.append(self.light_node) ## trigger callbacks ## @var frame_trigger # Triggers framewise evaluation of respective callback method self.frame_trigger = avango.script.nodes.Update(Callback = self.frame_callback, Active = False) # Triggers framewise evaluation of respective callback method self.update_trigger = avango.script.nodes.Update(Callback = self.update_callback, Active = False) ### set initial states ### ## set tool properties self.set_thickness(TOOL_THICKNESS) ## set light properties self.set_light_color(LIGHT_COLOR) self.set_light_brightness(LIGHT_BRIGHTNESS) self.set_light_dimensions(LIGHT_DIMENSIONS) self.set_shadow_flag(SHADOW_FLAG) self.set_shadow_map_size(SHADOW_MAP_SIZE) print("LightTool initialized:", Tool.get_id(self))