def set_loop(self, x_value, y_value): self.loop = [x_value, y_value] self.particles_mesh.__del__() self.particles_mesh = glLibGrid2DMesh(self.size, self.loop)
def __init__(self, size, pos_data, rip_texture=None, stretched=1.0): #TODO: Make kernel size work! #Angle limiting forces #Size if type(size) in [type([]), type(())]: self.size = list(size) else: self.size = [size, size] #Misc. self.view_2d = glLibView2D((0, 0, self.size[0], self.size[1])) #Physics self.forces = [0.0, 0.0, 0.0] #Cloth Parameters self.dampening = 0.98 self.tensor = 1.0 self.angle_tensor = 0.0 #1.0 self.max_jitter_length = 1.0 self.gravity = [0.0, 0.0, 0.0] self.kernel_size = 1 self.steps = 1 self.normal_flip = False self.loop = [False, False] self.time_step = 1.0 #Collision Objects self.num_obstacles = 0 self.collidable = {} self.is_garment = False #Geometry self.particles = glLibGrid2D(self.size) self.particles_mesh = glLibGrid2DMesh(self.size) #Textures self.pos_restrained_tex = glLibTexture2D( pos_data, (0, 0, self.size[0], self.size[1]), GL_RGBA, precision=32) ## self. self.original_pos_restrained_tex = self.pos_restrained_tex self.velocity_tex = glLibTexture2D(None, (0, 0, self.size[0], self.size[1]), GL_RGB, precision=32) self.vec_tex = None self.normal_tex = None self.dist_edges_tex = None self.dist_corners_tex = None self.diffuse_texture = None self.obstacles_tex = None self.obstacles_aux_param_tex = None self.texture_repeat = [1.0, 1.0] #FBOs self.update_framebuffer = glLibFBO(self.size) self.update_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.update_framebuffer.add_render_target(2, precision=32) self.update_framebuffer.add_render_target(3, precision=8) #for debugging self.collision_framebuffer = glLibFBO(self.size) self.collision_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.collision_framebuffer.add_render_target(2, precision=32) self.collision_framebuffer.add_render_target(3, precision=8) self.normal_framebuffer = glLibFBO(self.size) self.normal_framebuffer.add_render_target(1) self.dist_angle_framebuffer = glLibFBO(self.size) self.dist_angle_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.dist_angle_framebuffer.add_render_target(2, precision=32, type=GLLIB_RGBA) self.set_loop(*self.loop) #Shaders ## print "Compiling Update Shader" self.update_shader = glLibShader() self.update_shader.use_prebuilt(GLLIB_CLOTH_UPDATE) ## print "Compiling Collision Shader" self.collision_shader = glLibShader() self.collision_shader.use_prebuilt(GLLIB_CLOTH_COLLIDE) ## print "Compiling Normal Shader" self.normal_shader = glLibShader() self.normal_shader.use_prebuilt(GLLIB_CLOTH_NORMAL) ## print "Compiling Draw Shader" self.draw_shader = glLibShader() self.draw_shader.use_prebuilt(GLLIB_CLOTH_DRAW) ## print "Compiling Distance Shader" self.dist_shader = glLibShader() self.dist_shader.use_prebuilt(GLLIB_CLOTH_DISTANCE) ## self.update_shader.save_vertex() #Get Target Distances self.glLibInternal_push() self.dist_angle_framebuffer.enable([1, 2]) self.glLibInternal_use_dist_shader() self.dist_shader.pass_float("stretched", stretched) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() self.view_2d.set_view() self.particles.draw() glLibUseShader(None) self.dist_angle_framebuffer.disable() self.glLibInternal_pop() self.dist_edges_tex = self.dist_angle_framebuffer.get_texture(1) self.dist_corners_tex = self.dist_angle_framebuffer.get_texture(2) #Initialize Position self.glLibInternal_initialize_position()
def __init__(self, size, pos_data, rip_texture=None, stretched=1.0): # TODO: Make kernel size work! # Angle limiting forces # Size if type(size) in [type([]), type(())]: self.size = list(size) else: self.size = [size, size] # Misc. self.view_2d = glLibView2D((0, 0, self.size[0], self.size[1])) # Physics self.forces = [0.0, 0.0, 0.0] # Cloth Parameters self.scale = 1.0 self.trans = [0.0, 0.0, 0.0] self.dampening = 0.98 self.tensor = 1.0 self.angle_tensor = 0.0 # 1.0 self.max_jitter_length = 1.0 self.gravity = [0.0, 0.0, 0.0] self.kernel_size = 1 self.steps = 1 self.normal_flip = False self.loop = [False, False] self.time_step = 1.0 # Collision Objects self.num_obstacles = 0 self.collidable = {} self.is_garment = False # Geometry self.particles = glLibGrid2D(self.size) self.particles_mesh = glLibGrid2DMesh(self.size) # Textures self.pos_restrained_tex = glLibTexture2D(pos_data, (0, 0, self.size[0], self.size[1]), GL_RGBA, precision=32) ## self. self.original_pos_restrained_tex = self.pos_restrained_tex self.velocity_tex = glLibTexture2D(None, (0, 0, self.size[0], self.size[1]), GL_RGB, precision=32) self.vec_tex = None self.normal_tex = None self.dist_edges_tex = None self.dist_corners_tex = None self.diffuse_texture = None self.obstacles_tex = None self.obstacles_aux_param_tex = None self.texture_repeat = [1.0, 1.0] # FBOs self.update_framebuffer = glLibFBO(self.size) self.update_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.update_framebuffer.add_render_target(2, precision=32) self.update_framebuffer.add_render_target(3, precision=8) self.collision_framebuffer = glLibFBO(self.size) self.collision_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.collision_framebuffer.add_render_target(2, precision=32) self.collision_framebuffer.add_render_target(3, precision=8) self.normal_framebuffer = glLibFBO(self.size) self.normal_framebuffer.add_render_target(1) self.dist_angle_framebuffer = glLibFBO(self.size) self.dist_angle_framebuffer.add_render_target(1, precision=32, type=GLLIB_RGBA) self.dist_angle_framebuffer.add_render_target(2, precision=32, type=GLLIB_RGBA) self.set_loop(*self.loop) # Shaders ## print "Compiling Update Shader" self.update_shader = glLibShader() self.update_shader.use_prebuilt(GLLIB_CLOTH_UPDATE) ## print "Compiling Collision Shader" self.collision_shader = glLibShader() self.collision_shader.use_prebuilt(GLLIB_CLOTH_COLLIDE) ## print "Compiling Normal Shader" self.normal_shader = glLibShader() self.normal_shader.use_prebuilt(GLLIB_CLOTH_NORMAL) ## print "Compiling Draw Shader" self.draw_shader = glLibShader() self.draw_shader.use_prebuilt(GLLIB_CLOTH_DRAW) ## print "Compiling Distance Shader" self.dist_shader = glLibShader() self.dist_shader.use_prebuilt(GLLIB_CLOTH_DISTANCE) ## self.update_shader.save_vertex() # Get Target Distances self.glLibInternal_push() self.dist_angle_framebuffer.enable([1, 2]) self.glLibInternal_use_dist_shader() self.dist_shader.pass_float("stretched", stretched) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() self.view_2d.set_view() self.particles.draw() glLibUseShader(None) self.dist_angle_framebuffer.disable() self.glLibInternal_pop() self.dist_edges_tex = self.dist_angle_framebuffer.get_texture(1) self.dist_corners_tex = self.dist_angle_framebuffer.get_texture(2) # Initialize Position self.glLibInternal_initialize_position()