This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def isOnGround(self): | |
| result= self.world.contactTest(self.physic_node) | |
| if result.getNumContacts()>0: | |
| for contact in result.getContacts(): | |
| n = contact.getManifoldPoint().getNormalWorldOnB() | |
| a = Vec3(0,0,1).angleDeg(Vec3(n)) | |
| if abs(a-180.0)<60.0 or a < 60.0: | |
| self.last_know_ground_pos=self.node.getPos(render) | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from direct.showbase import ShowBase | |
| from collections import deque | |
| import random | |
| def foo(task): | |
| print 'close the window now to have a dead python process' | |
| #python is bad at shuffling deques | |
| #so this will take a Long Time to end | |
| x=deque(range(5000)) | |
| for i in range(999): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from panda3d.core import * | |
| from direct.filter.FilterManager import * | |
| class DeferredRenderer(): | |
| def __init__(self, scene_mask=1, light_mask=2): | |
| # Camera setup | |
| self.light_cam = base.makeCamera(base.win, lens=base.camLens) | |
| self.light_cam.reparentTo(base.cam) | |
| base.cam.node().getLens().setNearFar(0.1, 5000.0) | |
| #masks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WrappedLoader(object): | |
| def __init__(self, original_loader): | |
| self.original_loader=original_loader | |
| def destroy(self): | |
| self.original_loader.destroy() | |
| def loadModel(self, modelPath, loaderOptions = None, noCache = None, | |
| allowInstance = False, okMissing = None, | |
| callback = None, extraArgs = [], priority = None): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Wrapper(object): | |
| def __init__(self,wrapped_object): | |
| self.wrapped_object = wrapped_object | |
| self.pre_hooks={} | |
| self.pre_hooks_args={} | |
| self.post_hooks={} | |
| self.post_hooks_args={} | |
| def set_pre_hook(self, function_name, function_to_call, args=None): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from panda3d.core import * | |
| loadPrcFileData("", "show-buffers 1") | |
| from direct.showbase.ShowBase import ShowBase | |
| from direct.actor.Actor import Actor | |
| from direct.gui.DirectGui import * | |
| class World(): | |
| def __init__(self): | |
| #place the camera | |
| base.trackball.node().setPos(0, 15, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.modelbuffer = self.makeFBO("model buffer", 1) | |
| self.lightbuffer = self.makeFBO("light buffer", 0) | |
| # Create four render textures: depth, normal, albedo, and final. | |
| # attach them to the various bitplanes of the offscreen buffers. | |
| self.depth = Texture() | |
| self.depth.setWrapU(Texture.WM_clamp) | |
| self.depth.setWrapV(Texture.WM_clamp) | |
| self.depth.setFormat(Texture.F_depth_component32) | |
| self.depth.setComponentType(Texture.T_float) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //shadows | |
| vec4 world_pos = p3d_ViewProjectionMatrixInverse * vec4( uv.xy * 2.0 - vec2(1.0), depth, 1.0); | |
| world_pos.xyz /= world_pos.w; | |
| world_pos.xyz-=light_pos.xyz; | |
| vec4 shadow_uv=trans_render_to_shadowcaster*world_pos; | |
| float ldist = max(abs(shadow_uv.x), max(abs(shadow_uv.y), abs(shadow_uv.z))); | |
| ldist = ((light_radius+light_view_pos.w)/(light_radius-light_view_pos.w))+((-2.0*light_radius*light_view_pos.w)/(ldist * (light_radius-light_view_pos.w))); | |
| float shadow= float(texture(shadowcaster.shadowMap, shadow_uv.xyz).r >= ldist * 0.5 + 0.5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //shadows | |
| vec4 world_pos = p3d_ViewProjectionMatrixInverse * vec4( uv.xy * 2.0 - vec2(1.0), depth, 1.0); | |
| world_pos.xyz /= world_pos.w; | |
| world_pos.xyz-=light_pos.xyz; | |
| vec4 shadow_uv=trans_render_to_apiclip_of_spot*world_pos; | |
| //mat4 biasmat = mat4(vec4(0.5, 0.0, 0.0, 0.5), vec4(0.0, 0.5, 0.0, 0.5), vec4(0.0, 0.0, 0.5, 0.5),vec4(0.0, 0.0, 0.0, 1.0)); | |
| //shadow_uv=biasmat*shadow_uv; | |
| float shadow= textureProj(spot.shadowMap,shadow_uv, 0.01); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def loadShader(self, lang=Shader.SL_GLSL, vertex = None, fragment = None, | |
| geometry = None,tess_control = None, tess_evaluation = None, | |
| shaderPath = None, okMissing = False, define = None): | |
| #old way | |
| if shaderPath is not None: | |
| shader = ShaderPool.loadShader (shaderPath) | |
| if not shader and not okMissing: | |
| message = 'Could not load shader file: %s' % (shaderPath) | |
| raise IOError(message) | |
| return shader |
OlderNewer