pyglet_helper.common package

Submodules

pyglet_helper.common.crayola module

pyglet_helper.common.crayola.gray(luminance)
pyglet_helper.common.crayola.hsv_to_rgb(T)
pyglet_helper.common.crayola.rgb_to_grayscale(T)
pyglet_helper.common.crayola.rgb_to_hsv(T)

pyglet_helper.common.materials module

VPython material tools and definitions Stable Interfaces:

materials.unshaded materials.diffuse materials.plastic materials.rough materials.wood materials.marble materials.earth

Individual named materials. The exact look of these might change in future versions of Visual, but the names should continue to work.
materials.texture( data, channels=None, mipmap=True,
interpolate=True, name=”texture” )

Create a material by “extruding”/projecting a 2D image. See VPython documentation for more details.

materials.loadTGA(file) materials.saveTGA(file,data)

Load and save uncompressed TGA files; typically used to supply the data parameter to texture(). file may be a filename or file object.
Unstable interfaces:
materials.shader( name, shader, version, textures=(), translucent=False )

This is the low level interface for constructing a material based on a GLSL shader program.

It is not fully documented because it is subject to change in future versions. In particular, it is likely that some or all programs using materials.shader() directly will require modification to run in future versions of Visual. If you come up with really nice new materials, be sure to post them to the VPython forum, so that they can be considered for incorporation in new versions of Visual. As well as benefitting other users, this will remove from you the burden of updating your shader for new versions. If you want to learn how to write shaders, look at some of the examples below (such as “wood”), and consult the GLSL reference specification which is available online. To minimize the likelihood that you will have to rewrite your shaders for future architectural changes in Visual, avoid accessing the built in gl_* variables defined in that specification; instead use only normal, position, mat_pos, object_color, and object_opacity as inputs and write your output shaded material color to material_color and material_opacity. Many of these are currently simple macros expanding to gl_* variables, but in the future their definitions may change. Use lightAt() instead of the light_* uniforms if possible.

materials.raw_texture( data, interpolate, mipmap ) materials.tx_turb3 materials.tx_wood

raw 2D textures useful only for filling in the textures parameter of materials.shader().
pyglet_helper.common.materials.convert_data(data)
pyglet_helper.common.materials.get_default_channels(data)
pyglet_helper.common.materials.loadTGA(fileid)
class pyglet_helper.common.materials.raw_texture(**kwargs)

Bases: pyglet_helper.util.texture.Texture

pyglet_helper.common.materials.saveTGA(fileid, data)
pyglet_helper.common.materials.shader(name, shader, version, library='\n[vertex]\n uniform mat4 model_material; // object space -> material position\n void basic(void)\n {\n position = vec3(gl_ModelViewMatrix * gl_Vertex);\n normal = normalize(gl_NormalMatrix * gl_Normal);\n gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n gl_FrontColor = gl_Color;\n mat_pos = vec3( model_material * gl_Vertex );\n }\n[varying]\n #version 110\n // These are available to fragment shaders and must be set by vertex shaders.\n\n varying vec3 normal; // eye space surface normal\n varying vec3 position; // eye space surface position\n varying vec3 mat_pos; // surface material position in [0, 1]^3\n #define VPYTHON_SHADER_VERSION 400\n[fragment]\n // Available inputs (see also the varying section)\n\n #define object_color gl_Color.rgb // the .color attribute of the object being rendered\n #define object_opacity gl_Color.a // the .opacity attribute of the object being rendered\n uniform int light_count;\n uniform vec4 light_pos[8];\n uniform vec4 light_color[8];\n // Outputs of a material_main() function\n #define material_color gl_FragColor.rgb\n #define material_opacity gl_FragColor.a\n // Return lit surface color based on the given surface properties and the lights\n // specified by the light_* uniforms.\n vec3 lightAt( vec3 normal, vec3 to_eye, vec3 diffuse_color, vec3 specular_color, float shininess )\n {\n vec3 color = gl_LightModel.ambient.rgb * diffuse_color;\n // All this ugliness is to deal with the need of Geforce 7xxx (and probably similar generation\n // ATI cards) to unroll loops at compile time. If you are trying to understand this code, look\n // at just the else case.\n int count = light_count;\n if (count <= 2) {\n for(int i=0; i<2; i++) {\n if (i<count) {\n vec3 L = normalize( light_pos[i].xyz - position*light_pos[i].w );\n color += (light_color[i].rgb * max(dot(normal, L), 0.0))*diffuse_color;\n if (shininess != 0.0) {\n vec3 R = -reflect(L, normal);\n color += specular_color * light_color[i].rgb * pow(max(dot(R, to_eye), 0.0), shininess);\n }\n }\n }\n } else if (count <= 4) {\n for(int i=0; i<4; i++) {\n if (i<count) {\n vec3 L = normalize( light_pos[i].xyz - position*light_pos[i].w );\n color += (light_color[i].rgb * max(dot(normal, L), 0.0))*diffuse_color;\n if (shininess != 0.0) {\n vec3 R = -reflect(L, normal);\n color += specular_color * light_color[i].rgb * pow(max(dot(R, to_eye), 0.0), shininess);\n }\n }\n }\n } else {\n for(int i=0; i<8; i++) {\n if (i<count) {\n vec3 L = normalize( light_pos[i].xyz - position*light_pos[i].w );\n color += (light_color[i].rgb * max(dot(normal, L), 0.0))*diffuse_color;\n if (shininess != 0.0) {\n vec3 R = -reflect(L, normal);\n color += specular_color * light_color[i].rgb * pow(max(dot(R, to_eye), 0.0), shininess);\n }\n }\n }\n }\n\n return color;\n }\n vec3 noise3D( sampler3D tex, vec3 mat_pos, const float second_octave_scale ) {\n const float octave = 8.;\n return texture3D( tex, mat_pos).rgb + texture3D( tex, mat_pos*octave ).rgb * (second_octave_scale / octave);\n }\n // Eventually there will probably be an "outer" main function which will call material_main\n #define material_main main\n', **kwargs)
class pyglet_helper.common.materials.shader_material(**kwargs)

Bases: pyglet_helper.objects.material.Material

pyglet_helper.common.materials.texture(data, channels=None, mapping='rectangular', mipmap=True, interpolate=True, name='texture')

pyglet_helper.common.rate_function module

class pyglet_helper.common.rate_function.RateKeeper(interactPeriod=0.03333333333333333, interactFunc=<class pyglet_helper.common.rate_function.simulateDelay>)
buildStrategy(rate)
callInteract()
distributeRenders(M, N)
initialize()
class pyglet_helper.common.rate_function.TimingDebug(debug=0)
add(msg)
dump()
class pyglet_helper.common.rate_function.simulateDelay(delayAvg=0.001, delaySigma=0.0001)

Simulate rendering/compute times.. with an average value of delayAvg with a variance of something like delaySigma**2.

Module contents