partition
stringclasses 3
values | func_name
stringlengths 1
134
| docstring
stringlengths 1
46.9k
| path
stringlengths 4
223
| original_string
stringlengths 75
104k
| code
stringlengths 75
104k
| docstring_tokens
listlengths 1
1.97k
| repo
stringlengths 7
55
| language
stringclasses 1
value | url
stringlengths 87
315
| code_tokens
listlengths 19
28.4k
| sha
stringlengths 40
40
|
|---|---|---|---|---|---|---|---|---|---|---|---|
valid
|
Window.swap_buffers
|
Swaps buffers, incement the framecounter and pull events.
|
demosys/context/glfw/window.py
|
def swap_buffers(self):
"""
Swaps buffers, incement the framecounter and pull events.
"""
self.frames += 1
glfw.swap_buffers(self.window)
self.poll_events()
|
def swap_buffers(self):
"""
Swaps buffers, incement the framecounter and pull events.
"""
self.frames += 1
glfw.swap_buffers(self.window)
self.poll_events()
|
[
"Swaps",
"buffers",
"incement",
"the",
"framecounter",
"and",
"pull",
"events",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/glfw/window.py#L99-L105
|
[
"def",
"swap_buffers",
"(",
"self",
")",
":",
"self",
".",
"frames",
"+=",
"1",
"glfw",
".",
"swap_buffers",
"(",
"self",
".",
"window",
")",
"self",
".",
"poll_events",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.resize
|
Sets the new size and buffer size internally
|
demosys/context/glfw/window.py
|
def resize(self, width, height):
"""
Sets the new size and buffer size internally
"""
self.width = width
self.height = height
self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
self.set_default_viewport()
|
def resize(self, width, height):
"""
Sets the new size and buffer size internally
"""
self.width = width
self.height = height
self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
self.set_default_viewport()
|
[
"Sets",
"the",
"new",
"size",
"and",
"buffer",
"size",
"internally"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/glfw/window.py#L107-L114
|
[
"def",
"resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"self",
".",
"width",
"=",
"width",
"self",
".",
"height",
"=",
"height",
"self",
".",
"buffer_width",
",",
"self",
".",
"buffer_height",
"=",
"glfw",
".",
"get_framebuffer_size",
"(",
"self",
".",
"window",
")",
"self",
".",
"set_default_viewport",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.check_glfw_version
|
Ensure glfw library version is compatible
|
demosys/context/glfw/window.py
|
def check_glfw_version(self):
"""
Ensure glfw library version is compatible
"""
print("glfw version: {} (python wrapper version {})".format(glfw.get_version(), glfw.__version__))
if glfw.get_version() < self.min_glfw_version:
raise ValueError("Please update glfw binaries to version {} or later".format(self.min_glfw_version))
|
def check_glfw_version(self):
"""
Ensure glfw library version is compatible
"""
print("glfw version: {} (python wrapper version {})".format(glfw.get_version(), glfw.__version__))
if glfw.get_version() < self.min_glfw_version:
raise ValueError("Please update glfw binaries to version {} or later".format(self.min_glfw_version))
|
[
"Ensure",
"glfw",
"library",
"version",
"is",
"compatible"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/glfw/window.py#L126-L132
|
[
"def",
"check_glfw_version",
"(",
"self",
")",
":",
"print",
"(",
"\"glfw version: {} (python wrapper version {})\"",
".",
"format",
"(",
"glfw",
".",
"get_version",
"(",
")",
",",
"glfw",
".",
"__version__",
")",
")",
"if",
"glfw",
".",
"get_version",
"(",
")",
"<",
"self",
".",
"min_glfw_version",
":",
"raise",
"ValueError",
"(",
"\"Please update glfw binaries to version {} or later\"",
".",
"format",
"(",
"self",
".",
"min_glfw_version",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.key_event_callback
|
Key event callback for glfw.
Translates and forwards keyboard event to :py:func:`keyboard_event`
:param window: Window event origin
:param key: The key that was pressed or released.
:param scancode: The system-specific scancode of the key.
:param action: GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
:param mods: Bit field describing which modifier keys were held down.
|
demosys/context/glfw/window.py
|
def key_event_callback(self, window, key, scancode, action, mods):
"""
Key event callback for glfw.
Translates and forwards keyboard event to :py:func:`keyboard_event`
:param window: Window event origin
:param key: The key that was pressed or released.
:param scancode: The system-specific scancode of the key.
:param action: GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
:param mods: Bit field describing which modifier keys were held down.
"""
self.keyboard_event(key, action, mods)
|
def key_event_callback(self, window, key, scancode, action, mods):
"""
Key event callback for glfw.
Translates and forwards keyboard event to :py:func:`keyboard_event`
:param window: Window event origin
:param key: The key that was pressed or released.
:param scancode: The system-specific scancode of the key.
:param action: GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
:param mods: Bit field describing which modifier keys were held down.
"""
self.keyboard_event(key, action, mods)
|
[
"Key",
"event",
"callback",
"for",
"glfw",
".",
"Translates",
"and",
"forwards",
"keyboard",
"event",
"to",
":",
"py",
":",
"func",
":",
"keyboard_event"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/glfw/window.py#L134-L145
|
[
"def",
"key_event_callback",
"(",
"self",
",",
"window",
",",
"key",
",",
"scancode",
",",
"action",
",",
"mods",
")",
":",
"self",
".",
"keyboard_event",
"(",
"key",
",",
"action",
",",
"mods",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ctx
|
ModernGL context
|
demosys/context/__init__.py
|
def ctx() -> moderngl.Context:
"""ModernGL context"""
win = window()
if not win.ctx:
raise RuntimeError("Attempting to get context before creation")
return win.ctx
|
def ctx() -> moderngl.Context:
"""ModernGL context"""
win = window()
if not win.ctx:
raise RuntimeError("Attempting to get context before creation")
return win.ctx
|
[
"ModernGL",
"context"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/__init__.py#L23-L29
|
[
"def",
"ctx",
"(",
")",
"->",
"moderngl",
".",
"Context",
":",
"win",
"=",
"window",
"(",
")",
"if",
"not",
"win",
".",
"ctx",
":",
"raise",
"RuntimeError",
"(",
"\"Attempting to get context before creation\"",
")",
"return",
"win",
".",
"ctx"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
quad_2d
|
Creates a 2D quad VAO using 2 triangles with normals and texture coordinates.
Args:
width (float): Width of the quad
height (float): Height of the quad
Keyword Args:
xpos (float): Center position x
ypos (float): Center position y
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance.
|
demosys/geometry/quad.py
|
def quad_2d(width, height, xpos=0.0, ypos=0.0) -> VAO:
"""
Creates a 2D quad VAO using 2 triangles with normals and texture coordinates.
Args:
width (float): Width of the quad
height (float): Height of the quad
Keyword Args:
xpos (float): Center position x
ypos (float): Center position y
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance.
"""
pos = numpy.array([
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos - width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos + height / 2.0, 0.0,
], dtype=numpy.float32)
normals = numpy.array([
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
], dtype=numpy.float32)
uvs = numpy.array([
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 0.0,
1.0, 1.0,
], dtype=numpy.float32)
vao = VAO("geometry:quad", mode=moderngl.TRIANGLES)
vao.buffer(pos, '3f', ["in_position"])
vao.buffer(normals, '3f', ["in_normal"])
vao.buffer(uvs, '2f', ["in_uv"])
return vao
|
def quad_2d(width, height, xpos=0.0, ypos=0.0) -> VAO:
"""
Creates a 2D quad VAO using 2 triangles with normals and texture coordinates.
Args:
width (float): Width of the quad
height (float): Height of the quad
Keyword Args:
xpos (float): Center position x
ypos (float): Center position y
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance.
"""
pos = numpy.array([
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos - width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos + height / 2.0, 0.0,
], dtype=numpy.float32)
normals = numpy.array([
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
], dtype=numpy.float32)
uvs = numpy.array([
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 0.0,
1.0, 1.0,
], dtype=numpy.float32)
vao = VAO("geometry:quad", mode=moderngl.TRIANGLES)
vao.buffer(pos, '3f', ["in_position"])
vao.buffer(normals, '3f', ["in_normal"])
vao.buffer(uvs, '2f', ["in_uv"])
return vao
|
[
"Creates",
"a",
"2D",
"quad",
"VAO",
"using",
"2",
"triangles",
"with",
"normals",
"and",
"texture",
"coordinates",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/geometry/quad.py#L17-L64
|
[
"def",
"quad_2d",
"(",
"width",
",",
"height",
",",
"xpos",
"=",
"0.0",
",",
"ypos",
"=",
"0.0",
")",
"->",
"VAO",
":",
"pos",
"=",
"numpy",
".",
"array",
"(",
"[",
"xpos",
"-",
"width",
"/",
"2.0",
",",
"ypos",
"+",
"height",
"/",
"2.0",
",",
"0.0",
",",
"xpos",
"-",
"width",
"/",
"2.0",
",",
"ypos",
"-",
"height",
"/",
"2.0",
",",
"0.0",
",",
"xpos",
"+",
"width",
"/",
"2.0",
",",
"ypos",
"-",
"height",
"/",
"2.0",
",",
"0.0",
",",
"xpos",
"-",
"width",
"/",
"2.0",
",",
"ypos",
"+",
"height",
"/",
"2.0",
",",
"0.0",
",",
"xpos",
"+",
"width",
"/",
"2.0",
",",
"ypos",
"-",
"height",
"/",
"2.0",
",",
"0.0",
",",
"xpos",
"+",
"width",
"/",
"2.0",
",",
"ypos",
"+",
"height",
"/",
"2.0",
",",
"0.0",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"normals",
"=",
"numpy",
".",
"array",
"(",
"[",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"uvs",
"=",
"numpy",
".",
"array",
"(",
"[",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"0.0",
",",
"1.0",
",",
"1.0",
",",
"0.0",
",",
"1.0",
",",
"1.0",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vao",
"=",
"VAO",
"(",
"\"geometry:quad\"",
",",
"mode",
"=",
"moderngl",
".",
"TRIANGLES",
")",
"vao",
".",
"buffer",
"(",
"pos",
",",
"'3f'",
",",
"[",
"\"in_position\"",
"]",
")",
"vao",
".",
"buffer",
"(",
"normals",
",",
"'3f'",
",",
"[",
"\"in_normal\"",
"]",
")",
"vao",
".",
"buffer",
"(",
"uvs",
",",
"'2f'",
",",
"[",
"\"in_uv\"",
"]",
")",
"return",
"vao"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
translate_buffer_format
|
Translate the buffer format
|
demosys/loaders/scene/wavefront.py
|
def translate_buffer_format(vertex_format):
"""Translate the buffer format"""
buffer_format = []
attributes = []
mesh_attributes = []
if "T2F" in vertex_format:
buffer_format.append("2f")
attributes.append("in_uv")
mesh_attributes.append(("TEXCOORD_0", "in_uv", 2))
if "C3F" in vertex_format:
buffer_format.append("3f")
attributes.append("in_color")
mesh_attributes.append(("NORMAL", "in_color", 3))
if "N3F" in vertex_format:
buffer_format.append("3f")
attributes.append("in_normal")
mesh_attributes.append(("NORMAL", "in_normal", 3))
buffer_format.append("3f")
attributes.append("in_position")
mesh_attributes.append(("POSITION", "in_position", 3))
return " ".join(buffer_format), attributes, mesh_attributes
|
def translate_buffer_format(vertex_format):
"""Translate the buffer format"""
buffer_format = []
attributes = []
mesh_attributes = []
if "T2F" in vertex_format:
buffer_format.append("2f")
attributes.append("in_uv")
mesh_attributes.append(("TEXCOORD_0", "in_uv", 2))
if "C3F" in vertex_format:
buffer_format.append("3f")
attributes.append("in_color")
mesh_attributes.append(("NORMAL", "in_color", 3))
if "N3F" in vertex_format:
buffer_format.append("3f")
attributes.append("in_normal")
mesh_attributes.append(("NORMAL", "in_normal", 3))
buffer_format.append("3f")
attributes.append("in_position")
mesh_attributes.append(("POSITION", "in_position", 3))
return " ".join(buffer_format), attributes, mesh_attributes
|
[
"Translate",
"the",
"buffer",
"format"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/scene/wavefront.py#L14-L39
|
[
"def",
"translate_buffer_format",
"(",
"vertex_format",
")",
":",
"buffer_format",
"=",
"[",
"]",
"attributes",
"=",
"[",
"]",
"mesh_attributes",
"=",
"[",
"]",
"if",
"\"T2F\"",
"in",
"vertex_format",
":",
"buffer_format",
".",
"append",
"(",
"\"2f\"",
")",
"attributes",
".",
"append",
"(",
"\"in_uv\"",
")",
"mesh_attributes",
".",
"append",
"(",
"(",
"\"TEXCOORD_0\"",
",",
"\"in_uv\"",
",",
"2",
")",
")",
"if",
"\"C3F\"",
"in",
"vertex_format",
":",
"buffer_format",
".",
"append",
"(",
"\"3f\"",
")",
"attributes",
".",
"append",
"(",
"\"in_color\"",
")",
"mesh_attributes",
".",
"append",
"(",
"(",
"\"NORMAL\"",
",",
"\"in_color\"",
",",
"3",
")",
")",
"if",
"\"N3F\"",
"in",
"vertex_format",
":",
"buffer_format",
".",
"append",
"(",
"\"3f\"",
")",
"attributes",
".",
"append",
"(",
"\"in_normal\"",
")",
"mesh_attributes",
".",
"append",
"(",
"(",
"\"NORMAL\"",
",",
"\"in_normal\"",
",",
"3",
")",
")",
"buffer_format",
".",
"append",
"(",
"\"3f\"",
")",
"attributes",
".",
"append",
"(",
"\"in_position\"",
")",
"mesh_attributes",
".",
"append",
"(",
"(",
"\"POSITION\"",
",",
"\"in_position\"",
",",
"3",
")",
")",
"return",
"\" \"",
".",
"join",
"(",
"buffer_format",
")",
",",
"attributes",
",",
"mesh_attributes"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ObjLoader.load
|
Deferred loading
|
demosys/loaders/scene/wavefront.py
|
def load(self):
"""Deferred loading"""
path = self.find_scene(self.meta.path)
if not path:
raise ValueError("Scene '{}' not found".format(self.meta.path))
if path.suffix == '.bin':
path = path.parent / path.stem
data = pywavefront.Wavefront(str(path), create_materials=True, cache=True)
scene = Scene(self.meta.resolved_path)
texture_cache = {}
for _, mat in data.materials.items():
mesh = Mesh(mat.name)
# Traditional loader
if mat.vertices:
buffer_format, attributes, mesh_attributes = translate_buffer_format(mat.vertex_format)
vbo = numpy.array(mat.vertices, dtype='f4')
vao = VAO(mat.name, mode=moderngl.TRIANGLES)
vao.buffer(vbo, buffer_format, attributes)
mesh.vao = vao
for attrs in mesh_attributes:
mesh.add_attribute(*attrs)
# Binary cache loader
elif hasattr(mat, 'vao'):
mesh = Mesh(mat.name)
mesh.vao = mat.vao
for attrs in mat.mesh_attributes:
mesh.add_attribute(*attrs)
else:
# Empty
continue
scene.meshes.append(mesh)
mesh.material = Material(mat.name)
scene.materials.append(mesh.material)
mesh.material.color = mat.diffuse
if mat.texture:
# A texture can be referenced multiple times, so we need to cache loaded ones
texture = texture_cache.get(mat.texture.path)
if not texture:
print("Loading:", mat.texture.path)
texture = textures.load(TextureDescription(
label=mat.texture.path,
path=mat.texture.path,
mipmap=True,
))
texture_cache[mat.texture.path] = texture
mesh.material.mat_texture = MaterialTexture(
texture=texture,
sampler=None,
)
node = Node(mesh=mesh)
scene.root_nodes.append(node)
# Not supported yet for obj
# self.calc_scene_bbox()
scene.prepare()
return scene
|
def load(self):
"""Deferred loading"""
path = self.find_scene(self.meta.path)
if not path:
raise ValueError("Scene '{}' not found".format(self.meta.path))
if path.suffix == '.bin':
path = path.parent / path.stem
data = pywavefront.Wavefront(str(path), create_materials=True, cache=True)
scene = Scene(self.meta.resolved_path)
texture_cache = {}
for _, mat in data.materials.items():
mesh = Mesh(mat.name)
# Traditional loader
if mat.vertices:
buffer_format, attributes, mesh_attributes = translate_buffer_format(mat.vertex_format)
vbo = numpy.array(mat.vertices, dtype='f4')
vao = VAO(mat.name, mode=moderngl.TRIANGLES)
vao.buffer(vbo, buffer_format, attributes)
mesh.vao = vao
for attrs in mesh_attributes:
mesh.add_attribute(*attrs)
# Binary cache loader
elif hasattr(mat, 'vao'):
mesh = Mesh(mat.name)
mesh.vao = mat.vao
for attrs in mat.mesh_attributes:
mesh.add_attribute(*attrs)
else:
# Empty
continue
scene.meshes.append(mesh)
mesh.material = Material(mat.name)
scene.materials.append(mesh.material)
mesh.material.color = mat.diffuse
if mat.texture:
# A texture can be referenced multiple times, so we need to cache loaded ones
texture = texture_cache.get(mat.texture.path)
if not texture:
print("Loading:", mat.texture.path)
texture = textures.load(TextureDescription(
label=mat.texture.path,
path=mat.texture.path,
mipmap=True,
))
texture_cache[mat.texture.path] = texture
mesh.material.mat_texture = MaterialTexture(
texture=texture,
sampler=None,
)
node = Node(mesh=mesh)
scene.root_nodes.append(node)
# Not supported yet for obj
# self.calc_scene_bbox()
scene.prepare()
return scene
|
[
"Deferred",
"loading"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/scene/wavefront.py#L72-L141
|
[
"def",
"load",
"(",
"self",
")",
":",
"path",
"=",
"self",
".",
"find_scene",
"(",
"self",
".",
"meta",
".",
"path",
")",
"if",
"not",
"path",
":",
"raise",
"ValueError",
"(",
"\"Scene '{}' not found\"",
".",
"format",
"(",
"self",
".",
"meta",
".",
"path",
")",
")",
"if",
"path",
".",
"suffix",
"==",
"'.bin'",
":",
"path",
"=",
"path",
".",
"parent",
"/",
"path",
".",
"stem",
"data",
"=",
"pywavefront",
".",
"Wavefront",
"(",
"str",
"(",
"path",
")",
",",
"create_materials",
"=",
"True",
",",
"cache",
"=",
"True",
")",
"scene",
"=",
"Scene",
"(",
"self",
".",
"meta",
".",
"resolved_path",
")",
"texture_cache",
"=",
"{",
"}",
"for",
"_",
",",
"mat",
"in",
"data",
".",
"materials",
".",
"items",
"(",
")",
":",
"mesh",
"=",
"Mesh",
"(",
"mat",
".",
"name",
")",
"# Traditional loader",
"if",
"mat",
".",
"vertices",
":",
"buffer_format",
",",
"attributes",
",",
"mesh_attributes",
"=",
"translate_buffer_format",
"(",
"mat",
".",
"vertex_format",
")",
"vbo",
"=",
"numpy",
".",
"array",
"(",
"mat",
".",
"vertices",
",",
"dtype",
"=",
"'f4'",
")",
"vao",
"=",
"VAO",
"(",
"mat",
".",
"name",
",",
"mode",
"=",
"moderngl",
".",
"TRIANGLES",
")",
"vao",
".",
"buffer",
"(",
"vbo",
",",
"buffer_format",
",",
"attributes",
")",
"mesh",
".",
"vao",
"=",
"vao",
"for",
"attrs",
"in",
"mesh_attributes",
":",
"mesh",
".",
"add_attribute",
"(",
"*",
"attrs",
")",
"# Binary cache loader",
"elif",
"hasattr",
"(",
"mat",
",",
"'vao'",
")",
":",
"mesh",
"=",
"Mesh",
"(",
"mat",
".",
"name",
")",
"mesh",
".",
"vao",
"=",
"mat",
".",
"vao",
"for",
"attrs",
"in",
"mat",
".",
"mesh_attributes",
":",
"mesh",
".",
"add_attribute",
"(",
"*",
"attrs",
")",
"else",
":",
"# Empty",
"continue",
"scene",
".",
"meshes",
".",
"append",
"(",
"mesh",
")",
"mesh",
".",
"material",
"=",
"Material",
"(",
"mat",
".",
"name",
")",
"scene",
".",
"materials",
".",
"append",
"(",
"mesh",
".",
"material",
")",
"mesh",
".",
"material",
".",
"color",
"=",
"mat",
".",
"diffuse",
"if",
"mat",
".",
"texture",
":",
"# A texture can be referenced multiple times, so we need to cache loaded ones",
"texture",
"=",
"texture_cache",
".",
"get",
"(",
"mat",
".",
"texture",
".",
"path",
")",
"if",
"not",
"texture",
":",
"print",
"(",
"\"Loading:\"",
",",
"mat",
".",
"texture",
".",
"path",
")",
"texture",
"=",
"textures",
".",
"load",
"(",
"TextureDescription",
"(",
"label",
"=",
"mat",
".",
"texture",
".",
"path",
",",
"path",
"=",
"mat",
".",
"texture",
".",
"path",
",",
"mipmap",
"=",
"True",
",",
")",
")",
"texture_cache",
"[",
"mat",
".",
"texture",
".",
"path",
"]",
"=",
"texture",
"mesh",
".",
"material",
".",
"mat_texture",
"=",
"MaterialTexture",
"(",
"texture",
"=",
"texture",
",",
"sampler",
"=",
"None",
",",
")",
"node",
"=",
"Node",
"(",
"mesh",
"=",
"mesh",
")",
"scene",
".",
"root_nodes",
".",
"append",
"(",
"node",
")",
"# Not supported yet for obj",
"# self.calc_scene_bbox()",
"scene",
".",
"prepare",
"(",
")",
"return",
"scene"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.start
|
Start the timer by recoding the current ``time.time()``
preparing to report the number of seconds since this timestamp.
|
demosys/timers/clock.py
|
def start(self):
"""
Start the timer by recoding the current ``time.time()``
preparing to report the number of seconds since this timestamp.
"""
if self.start_time is None:
self.start_time = time.time()
# Play after pause
else:
# Add the duration of the paused interval to the total offset
pause_duration = time.time() - self.pause_time
self.offset += pause_duration
# print("pause duration", pause_duration, "offset", self.offset)
# Exit the paused state
self.pause_time = None
|
def start(self):
"""
Start the timer by recoding the current ``time.time()``
preparing to report the number of seconds since this timestamp.
"""
if self.start_time is None:
self.start_time = time.time()
# Play after pause
else:
# Add the duration of the paused interval to the total offset
pause_duration = time.time() - self.pause_time
self.offset += pause_duration
# print("pause duration", pause_duration, "offset", self.offset)
# Exit the paused state
self.pause_time = None
|
[
"Start",
"the",
"timer",
"by",
"recoding",
"the",
"current",
"time",
".",
"time",
"()",
"preparing",
"to",
"report",
"the",
"number",
"of",
"seconds",
"since",
"this",
"timestamp",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/clock.py#L18-L32
|
[
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"start_time",
"is",
"None",
":",
"self",
".",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"# Play after pause",
"else",
":",
"# Add the duration of the paused interval to the total offset",
"pause_duration",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"pause_time",
"self",
".",
"offset",
"+=",
"pause_duration",
"# print(\"pause duration\", pause_duration, \"offset\", self.offset)",
"# Exit the paused state",
"self",
".",
"pause_time",
"=",
"None"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.stop
|
Stop the timer
Returns:
The time the timer was stopped
|
demosys/timers/clock.py
|
def stop(self) -> float:
"""
Stop the timer
Returns:
The time the timer was stopped
"""
self.stop_time = time.time()
return self.stop_time - self.start_time - self.offset
|
def stop(self) -> float:
"""
Stop the timer
Returns:
The time the timer was stopped
"""
self.stop_time = time.time()
return self.stop_time - self.start_time - self.offset
|
[
"Stop",
"the",
"timer"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/clock.py#L47-L55
|
[
"def",
"stop",
"(",
"self",
")",
"->",
"float",
":",
"self",
".",
"stop_time",
"=",
"time",
".",
"time",
"(",
")",
"return",
"self",
".",
"stop_time",
"-",
"self",
".",
"start_time",
"-",
"self",
".",
"offset"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.get_time
|
Get the current time in seconds
Returns:
The current time in seconds
|
demosys/timers/clock.py
|
def get_time(self) -> float:
"""
Get the current time in seconds
Returns:
The current time in seconds
"""
if self.pause_time is not None:
curr_time = self.pause_time - self.offset - self.start_time
return curr_time
curr_time = time.time()
return curr_time - self.start_time - self.offset
|
def get_time(self) -> float:
"""
Get the current time in seconds
Returns:
The current time in seconds
"""
if self.pause_time is not None:
curr_time = self.pause_time - self.offset - self.start_time
return curr_time
curr_time = time.time()
return curr_time - self.start_time - self.offset
|
[
"Get",
"the",
"current",
"time",
"in",
"seconds"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/clock.py#L57-L69
|
[
"def",
"get_time",
"(",
"self",
")",
"->",
"float",
":",
"if",
"self",
".",
"pause_time",
"is",
"not",
"None",
":",
"curr_time",
"=",
"self",
".",
"pause_time",
"-",
"self",
".",
"offset",
"-",
"self",
".",
"start_time",
"return",
"curr_time",
"curr_time",
"=",
"time",
".",
"time",
"(",
")",
"return",
"curr_time",
"-",
"self",
".",
"start_time",
"-",
"self",
".",
"offset"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.set_time
|
Set the current time. This can be used to jump in the timeline.
Args:
value (float): The new time
|
demosys/timers/clock.py
|
def set_time(self, value: float):
"""
Set the current time. This can be used to jump in the timeline.
Args:
value (float): The new time
"""
if value < 0:
value = 0
self.offset += self.get_time() - value
|
def set_time(self, value: float):
"""
Set the current time. This can be used to jump in the timeline.
Args:
value (float): The new time
"""
if value < 0:
value = 0
self.offset += self.get_time() - value
|
[
"Set",
"the",
"current",
"time",
".",
"This",
"can",
"be",
"used",
"to",
"jump",
"in",
"the",
"timeline",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/clock.py#L71-L81
|
[
"def",
"set_time",
"(",
"self",
",",
"value",
":",
"float",
")",
":",
"if",
"value",
"<",
"0",
":",
"value",
"=",
"0",
"self",
".",
"offset",
"+=",
"self",
".",
"get_time",
"(",
")",
"-",
"value"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Scenes.resolve_loader
|
Resolve scene loader based on file extension
|
demosys/resources/scenes.py
|
def resolve_loader(self, meta: SceneDescription):
"""
Resolve scene loader based on file extension
"""
for loader_cls in self._loaders:
if loader_cls.supports_file(meta):
meta.loader_cls = loader_cls
break
else:
raise ImproperlyConfigured(
"Scene {} has no loader class registered. Check settings.SCENE_LOADERS".format(meta.path))
|
def resolve_loader(self, meta: SceneDescription):
"""
Resolve scene loader based on file extension
"""
for loader_cls in self._loaders:
if loader_cls.supports_file(meta):
meta.loader_cls = loader_cls
break
else:
raise ImproperlyConfigured(
"Scene {} has no loader class registered. Check settings.SCENE_LOADERS".format(meta.path))
|
[
"Resolve",
"scene",
"loader",
"based",
"on",
"file",
"extension"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/scenes.py#L20-L30
|
[
"def",
"resolve_loader",
"(",
"self",
",",
"meta",
":",
"SceneDescription",
")",
":",
"for",
"loader_cls",
"in",
"self",
".",
"_loaders",
":",
"if",
"loader_cls",
".",
"supports_file",
"(",
"meta",
")",
":",
"meta",
".",
"loader_cls",
"=",
"loader_cls",
"break",
"else",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"Scene {} has no loader class registered. Check settings.SCENE_LOADERS\"",
".",
"format",
"(",
"meta",
".",
"path",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.on_key_press
|
Pyglet specific key press callback.
Forwards and translates the events to :py:func:`keyboard_event`
|
demosys/context/pyglet/window.py
|
def on_key_press(self, symbol, modifiers):
"""
Pyglet specific key press callback.
Forwards and translates the events to :py:func:`keyboard_event`
"""
self.keyboard_event(symbol, self.keys.ACTION_PRESS, modifiers)
|
def on_key_press(self, symbol, modifiers):
"""
Pyglet specific key press callback.
Forwards and translates the events to :py:func:`keyboard_event`
"""
self.keyboard_event(symbol, self.keys.ACTION_PRESS, modifiers)
|
[
"Pyglet",
"specific",
"key",
"press",
"callback",
".",
"Forwards",
"and",
"translates",
"the",
"events",
"to",
":",
"py",
":",
"func",
":",
"keyboard_event"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyglet/window.py#L68-L73
|
[
"def",
"on_key_press",
"(",
"self",
",",
"symbol",
",",
"modifiers",
")",
":",
"self",
".",
"keyboard_event",
"(",
"symbol",
",",
"self",
".",
"keys",
".",
"ACTION_PRESS",
",",
"modifiers",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.on_key_release
|
Pyglet specific key release callback.
Forwards and translates the events to :py:func:`keyboard_event`
|
demosys/context/pyglet/window.py
|
def on_key_release(self, symbol, modifiers):
"""
Pyglet specific key release callback.
Forwards and translates the events to :py:func:`keyboard_event`
"""
self.keyboard_event(symbol, self.keys.ACTION_RELEASE, modifiers)
|
def on_key_release(self, symbol, modifiers):
"""
Pyglet specific key release callback.
Forwards and translates the events to :py:func:`keyboard_event`
"""
self.keyboard_event(symbol, self.keys.ACTION_RELEASE, modifiers)
|
[
"Pyglet",
"specific",
"key",
"release",
"callback",
".",
"Forwards",
"and",
"translates",
"the",
"events",
"to",
":",
"py",
":",
"func",
":",
"keyboard_event"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyglet/window.py#L75-L80
|
[
"def",
"on_key_release",
"(",
"self",
",",
"symbol",
",",
"modifiers",
")",
":",
"self",
".",
"keyboard_event",
"(",
"symbol",
",",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
",",
"modifiers",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.on_mouse_motion
|
Pyglet specific mouse motion callback.
Forwards and traslates the event to :py:func:`cursor_event`
|
demosys/context/pyglet/window.py
|
def on_mouse_motion(self, x, y, dx, dy):
"""
Pyglet specific mouse motion callback.
Forwards and traslates the event to :py:func:`cursor_event`
"""
# screen coordinates relative to the lower-left corner
self.cursor_event(x, self.buffer_height - y, dx, dy)
|
def on_mouse_motion(self, x, y, dx, dy):
"""
Pyglet specific mouse motion callback.
Forwards and traslates the event to :py:func:`cursor_event`
"""
# screen coordinates relative to the lower-left corner
self.cursor_event(x, self.buffer_height - y, dx, dy)
|
[
"Pyglet",
"specific",
"mouse",
"motion",
"callback",
".",
"Forwards",
"and",
"traslates",
"the",
"event",
"to",
":",
"py",
":",
"func",
":",
"cursor_event"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyglet/window.py#L82-L88
|
[
"def",
"on_mouse_motion",
"(",
"self",
",",
"x",
",",
"y",
",",
"dx",
",",
"dy",
")",
":",
"# screen coordinates relative to the lower-left corner\r",
"self",
".",
"cursor_event",
"(",
"x",
",",
"self",
".",
"buffer_height",
"-",
"y",
",",
"dx",
",",
"dy",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.on_resize
|
Pyglet specific callback for window resize events.
|
demosys/context/pyglet/window.py
|
def on_resize(self, width, height):
"""
Pyglet specific callback for window resize events.
"""
self.width, self.height = width, height
self.buffer_width, self.buffer_height = width, height
self.resize(width, height)
|
def on_resize(self, width, height):
"""
Pyglet specific callback for window resize events.
"""
self.width, self.height = width, height
self.buffer_width, self.buffer_height = width, height
self.resize(width, height)
|
[
"Pyglet",
"specific",
"callback",
"for",
"window",
"resize",
"events",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyglet/window.py#L90-L96
|
[
"def",
"on_resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"self",
".",
"width",
",",
"self",
".",
"height",
"=",
"width",
",",
"height",
"self",
".",
"buffer_width",
",",
"self",
".",
"buffer_height",
"=",
"width",
",",
"height",
"self",
".",
"resize",
"(",
"width",
",",
"height",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.swap_buffers
|
Swap buffers, increment frame counter and pull events
|
demosys/context/pyglet/window.py
|
def swap_buffers(self):
"""
Swap buffers, increment frame counter and pull events
"""
if not self.window.context:
return
self.frames += 1
self.window.flip()
self.window.dispatch_events()
|
def swap_buffers(self):
"""
Swap buffers, increment frame counter and pull events
"""
if not self.window.context:
return
self.frames += 1
self.window.flip()
self.window.dispatch_events()
|
[
"Swap",
"buffers",
"increment",
"frame",
"counter",
"and",
"pull",
"events"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyglet/window.py#L102-L111
|
[
"def",
"swap_buffers",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"window",
".",
"context",
":",
"return",
"self",
".",
"frames",
"+=",
"1",
"self",
".",
"window",
".",
"flip",
"(",
")",
"self",
".",
"window",
".",
"dispatch_events",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
sphere
|
Creates a sphere.
Keyword Args:
radius (float): Radius or the sphere
rings (int): number or horizontal rings
sectors (int): number of vertical segments
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
|
demosys/geometry/sphere.py
|
def sphere(radius=0.5, sectors=32, rings=16) -> VAO:
"""
Creates a sphere.
Keyword Args:
radius (float): Radius or the sphere
rings (int): number or horizontal rings
sectors (int): number of vertical segments
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
R = 1.0 / (rings - 1)
S = 1.0 / (sectors - 1)
vertices = [0] * (rings * sectors * 3)
normals = [0] * (rings * sectors * 3)
uvs = [0] * (rings * sectors * 2)
v, n, t = 0, 0, 0
for r in range(rings):
for s in range(sectors):
y = math.sin(-math.pi / 2 + math.pi * r * R)
x = math.cos(2 * math.pi * s * S) * math.sin(math.pi * r * R)
z = math.sin(2 * math.pi * s * S) * math.sin(math.pi * r * R)
uvs[t] = s * S
uvs[t + 1] = r * R
vertices[v] = x * radius
vertices[v + 1] = y * radius
vertices[v + 2] = z * radius
normals[n] = x
normals[n + 1] = y
normals[n + 2] = z
t += 2
v += 3
n += 3
indices = [0] * rings * sectors * 6
i = 0
for r in range(rings - 1):
for s in range(sectors - 1):
indices[i] = r * sectors + s
indices[i + 1] = (r + 1) * sectors + (s + 1)
indices[i + 2] = r * sectors + (s + 1)
indices[i + 3] = r * sectors + s
indices[i + 4] = (r + 1) * sectors + s
indices[i + 5] = (r + 1) * sectors + (s + 1)
i += 6
vbo_vertices = numpy.array(vertices, dtype=numpy.float32)
vbo_normals = numpy.array(normals, dtype=numpy.float32)
vbo_uvs = numpy.array(uvs, dtype=numpy.float32)
vbo_elements = numpy.array(indices, dtype=numpy.uint32)
vao = VAO("sphere", mode=mlg.TRIANGLES)
# VBOs
vao.buffer(vbo_vertices, '3f', ['in_position'])
vao.buffer(vbo_normals, '3f', ['in_normal'])
vao.buffer(vbo_uvs, '2f', ['in_uv'])
vao.index_buffer(vbo_elements, index_element_size=4)
return vao
|
def sphere(radius=0.5, sectors=32, rings=16) -> VAO:
"""
Creates a sphere.
Keyword Args:
radius (float): Radius or the sphere
rings (int): number or horizontal rings
sectors (int): number of vertical segments
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
R = 1.0 / (rings - 1)
S = 1.0 / (sectors - 1)
vertices = [0] * (rings * sectors * 3)
normals = [0] * (rings * sectors * 3)
uvs = [0] * (rings * sectors * 2)
v, n, t = 0, 0, 0
for r in range(rings):
for s in range(sectors):
y = math.sin(-math.pi / 2 + math.pi * r * R)
x = math.cos(2 * math.pi * s * S) * math.sin(math.pi * r * R)
z = math.sin(2 * math.pi * s * S) * math.sin(math.pi * r * R)
uvs[t] = s * S
uvs[t + 1] = r * R
vertices[v] = x * radius
vertices[v + 1] = y * radius
vertices[v + 2] = z * radius
normals[n] = x
normals[n + 1] = y
normals[n + 2] = z
t += 2
v += 3
n += 3
indices = [0] * rings * sectors * 6
i = 0
for r in range(rings - 1):
for s in range(sectors - 1):
indices[i] = r * sectors + s
indices[i + 1] = (r + 1) * sectors + (s + 1)
indices[i + 2] = r * sectors + (s + 1)
indices[i + 3] = r * sectors + s
indices[i + 4] = (r + 1) * sectors + s
indices[i + 5] = (r + 1) * sectors + (s + 1)
i += 6
vbo_vertices = numpy.array(vertices, dtype=numpy.float32)
vbo_normals = numpy.array(normals, dtype=numpy.float32)
vbo_uvs = numpy.array(uvs, dtype=numpy.float32)
vbo_elements = numpy.array(indices, dtype=numpy.uint32)
vao = VAO("sphere", mode=mlg.TRIANGLES)
# VBOs
vao.buffer(vbo_vertices, '3f', ['in_position'])
vao.buffer(vbo_normals, '3f', ['in_normal'])
vao.buffer(vbo_uvs, '2f', ['in_uv'])
vao.index_buffer(vbo_elements, index_element_size=4)
return vao
|
[
"Creates",
"a",
"sphere",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/geometry/sphere.py#L9-L75
|
[
"def",
"sphere",
"(",
"radius",
"=",
"0.5",
",",
"sectors",
"=",
"32",
",",
"rings",
"=",
"16",
")",
"->",
"VAO",
":",
"R",
"=",
"1.0",
"/",
"(",
"rings",
"-",
"1",
")",
"S",
"=",
"1.0",
"/",
"(",
"sectors",
"-",
"1",
")",
"vertices",
"=",
"[",
"0",
"]",
"*",
"(",
"rings",
"*",
"sectors",
"*",
"3",
")",
"normals",
"=",
"[",
"0",
"]",
"*",
"(",
"rings",
"*",
"sectors",
"*",
"3",
")",
"uvs",
"=",
"[",
"0",
"]",
"*",
"(",
"rings",
"*",
"sectors",
"*",
"2",
")",
"v",
",",
"n",
",",
"t",
"=",
"0",
",",
"0",
",",
"0",
"for",
"r",
"in",
"range",
"(",
"rings",
")",
":",
"for",
"s",
"in",
"range",
"(",
"sectors",
")",
":",
"y",
"=",
"math",
".",
"sin",
"(",
"-",
"math",
".",
"pi",
"/",
"2",
"+",
"math",
".",
"pi",
"*",
"r",
"*",
"R",
")",
"x",
"=",
"math",
".",
"cos",
"(",
"2",
"*",
"math",
".",
"pi",
"*",
"s",
"*",
"S",
")",
"*",
"math",
".",
"sin",
"(",
"math",
".",
"pi",
"*",
"r",
"*",
"R",
")",
"z",
"=",
"math",
".",
"sin",
"(",
"2",
"*",
"math",
".",
"pi",
"*",
"s",
"*",
"S",
")",
"*",
"math",
".",
"sin",
"(",
"math",
".",
"pi",
"*",
"r",
"*",
"R",
")",
"uvs",
"[",
"t",
"]",
"=",
"s",
"*",
"S",
"uvs",
"[",
"t",
"+",
"1",
"]",
"=",
"r",
"*",
"R",
"vertices",
"[",
"v",
"]",
"=",
"x",
"*",
"radius",
"vertices",
"[",
"v",
"+",
"1",
"]",
"=",
"y",
"*",
"radius",
"vertices",
"[",
"v",
"+",
"2",
"]",
"=",
"z",
"*",
"radius",
"normals",
"[",
"n",
"]",
"=",
"x",
"normals",
"[",
"n",
"+",
"1",
"]",
"=",
"y",
"normals",
"[",
"n",
"+",
"2",
"]",
"=",
"z",
"t",
"+=",
"2",
"v",
"+=",
"3",
"n",
"+=",
"3",
"indices",
"=",
"[",
"0",
"]",
"*",
"rings",
"*",
"sectors",
"*",
"6",
"i",
"=",
"0",
"for",
"r",
"in",
"range",
"(",
"rings",
"-",
"1",
")",
":",
"for",
"s",
"in",
"range",
"(",
"sectors",
"-",
"1",
")",
":",
"indices",
"[",
"i",
"]",
"=",
"r",
"*",
"sectors",
"+",
"s",
"indices",
"[",
"i",
"+",
"1",
"]",
"=",
"(",
"r",
"+",
"1",
")",
"*",
"sectors",
"+",
"(",
"s",
"+",
"1",
")",
"indices",
"[",
"i",
"+",
"2",
"]",
"=",
"r",
"*",
"sectors",
"+",
"(",
"s",
"+",
"1",
")",
"indices",
"[",
"i",
"+",
"3",
"]",
"=",
"r",
"*",
"sectors",
"+",
"s",
"indices",
"[",
"i",
"+",
"4",
"]",
"=",
"(",
"r",
"+",
"1",
")",
"*",
"sectors",
"+",
"s",
"indices",
"[",
"i",
"+",
"5",
"]",
"=",
"(",
"r",
"+",
"1",
")",
"*",
"sectors",
"+",
"(",
"s",
"+",
"1",
")",
"i",
"+=",
"6",
"vbo_vertices",
"=",
"numpy",
".",
"array",
"(",
"vertices",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vbo_normals",
"=",
"numpy",
".",
"array",
"(",
"normals",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vbo_uvs",
"=",
"numpy",
".",
"array",
"(",
"uvs",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vbo_elements",
"=",
"numpy",
".",
"array",
"(",
"indices",
",",
"dtype",
"=",
"numpy",
".",
"uint32",
")",
"vao",
"=",
"VAO",
"(",
"\"sphere\"",
",",
"mode",
"=",
"mlg",
".",
"TRIANGLES",
")",
"# VBOs",
"vao",
".",
"buffer",
"(",
"vbo_vertices",
",",
"'3f'",
",",
"[",
"'in_position'",
"]",
")",
"vao",
".",
"buffer",
"(",
"vbo_normals",
",",
"'3f'",
",",
"[",
"'in_normal'",
"]",
")",
"vao",
".",
"buffer",
"(",
"vbo_uvs",
",",
"'2f'",
",",
"[",
"'in_uv'",
"]",
")",
"vao",
".",
"index_buffer",
"(",
"vbo_elements",
",",
"index_element_size",
"=",
"4",
")",
"return",
"vao"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.draw
|
Calls the superclass ``draw()`` methods and checks ``HEADLESS_FRAMES``/``HEADLESS_DURATION``
|
demosys/context/headless.py
|
def draw(self, current_time, frame_time):
"""
Calls the superclass ``draw()`` methods and checks ``HEADLESS_FRAMES``/``HEADLESS_DURATION``
"""
super().draw(current_time, frame_time)
if self.headless_duration and current_time >= self.headless_duration:
self.close()
|
def draw(self, current_time, frame_time):
"""
Calls the superclass ``draw()`` methods and checks ``HEADLESS_FRAMES``/``HEADLESS_DURATION``
"""
super().draw(current_time, frame_time)
if self.headless_duration and current_time >= self.headless_duration:
self.close()
|
[
"Calls",
"the",
"superclass",
"draw",
"()",
"methods",
"and",
"checks",
"HEADLESS_FRAMES",
"/",
"HEADLESS_DURATION"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/headless.py#L43-L50
|
[
"def",
"draw",
"(",
"self",
",",
"current_time",
",",
"frame_time",
")",
":",
"super",
"(",
")",
".",
"draw",
"(",
"current_time",
",",
"frame_time",
")",
"if",
"self",
".",
"headless_duration",
"and",
"current_time",
">=",
"self",
".",
"headless_duration",
":",
"self",
".",
"close",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.swap_buffers
|
Headless window currently don't support double buffering.
We only increment the frame counter here.
|
demosys/context/headless.py
|
def swap_buffers(self):
"""
Headless window currently don't support double buffering.
We only increment the frame counter here.
"""
self.frames += 1
if self.headless_frames and self.frames >= self.headless_frames:
self.close()
|
def swap_buffers(self):
"""
Headless window currently don't support double buffering.
We only increment the frame counter here.
"""
self.frames += 1
if self.headless_frames and self.frames >= self.headless_frames:
self.close()
|
[
"Headless",
"window",
"currently",
"don",
"t",
"support",
"double",
"buffering",
".",
"We",
"only",
"increment",
"the",
"frame",
"counter",
"here",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/headless.py#L73-L81
|
[
"def",
"swap_buffers",
"(",
"self",
")",
":",
"self",
".",
"frames",
"+=",
"1",
"if",
"self",
".",
"headless_frames",
"and",
"self",
".",
"frames",
">=",
"self",
".",
"headless_frames",
":",
"self",
".",
"close",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseRegistry.load
|
Loads a resource or return existing one
:param meta: The resource description
|
demosys/resources/base.py
|
def load(self, meta: ResourceDescription) -> Any:
"""
Loads a resource or return existing one
:param meta: The resource description
"""
self._check_meta(meta)
self.resolve_loader(meta)
return meta.loader_cls(meta).load()
|
def load(self, meta: ResourceDescription) -> Any:
"""
Loads a resource or return existing one
:param meta: The resource description
"""
self._check_meta(meta)
self.resolve_loader(meta)
return meta.loader_cls(meta).load()
|
[
"Loads",
"a",
"resource",
"or",
"return",
"existing",
"one"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/base.py#L100-L108
|
[
"def",
"load",
"(",
"self",
",",
"meta",
":",
"ResourceDescription",
")",
"->",
"Any",
":",
"self",
".",
"_check_meta",
"(",
"meta",
")",
"self",
".",
"resolve_loader",
"(",
"meta",
")",
"return",
"meta",
".",
"loader_cls",
"(",
"meta",
")",
".",
"load",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseRegistry.add
|
Add a resource to this pool.
The resource is loaded and returned when ``load_pool()`` is called.
:param meta: The resource description
|
demosys/resources/base.py
|
def add(self, meta):
"""
Add a resource to this pool.
The resource is loaded and returned when ``load_pool()`` is called.
:param meta: The resource description
"""
self._check_meta(meta)
self.resolve_loader(meta)
self._resources.append(meta)
|
def add(self, meta):
"""
Add a resource to this pool.
The resource is loaded and returned when ``load_pool()`` is called.
:param meta: The resource description
"""
self._check_meta(meta)
self.resolve_loader(meta)
self._resources.append(meta)
|
[
"Add",
"a",
"resource",
"to",
"this",
"pool",
".",
"The",
"resource",
"is",
"loaded",
"and",
"returned",
"when",
"load_pool",
"()",
"is",
"called",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/base.py#L110-L119
|
[
"def",
"add",
"(",
"self",
",",
"meta",
")",
":",
"self",
".",
"_check_meta",
"(",
"meta",
")",
"self",
".",
"resolve_loader",
"(",
"meta",
")",
"self",
".",
"_resources",
".",
"append",
"(",
"meta",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseRegistry.load_pool
|
Loads all the data files using the configured finders.
|
demosys/resources/base.py
|
def load_pool(self):
"""
Loads all the data files using the configured finders.
"""
for meta in self._resources:
resource = self.load(meta)
yield meta, resource
self._resources = []
|
def load_pool(self):
"""
Loads all the data files using the configured finders.
"""
for meta in self._resources:
resource = self.load(meta)
yield meta, resource
self._resources = []
|
[
"Loads",
"all",
"the",
"data",
"files",
"using",
"the",
"configured",
"finders",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/base.py#L121-L129
|
[
"def",
"load_pool",
"(",
"self",
")",
":",
"for",
"meta",
"in",
"self",
".",
"_resources",
":",
"resource",
"=",
"self",
".",
"load",
"(",
"meta",
")",
"yield",
"meta",
",",
"resource",
"self",
".",
"_resources",
"=",
"[",
"]"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseRegistry.resolve_loader
|
Attempts to assign a loader class to a resource description
:param meta: The resource description instance
|
demosys/resources/base.py
|
def resolve_loader(self, meta: ResourceDescription):
"""
Attempts to assign a loader class to a resource description
:param meta: The resource description instance
"""
meta.loader_cls = self.get_loader(meta, raise_on_error=True)
|
def resolve_loader(self, meta: ResourceDescription):
"""
Attempts to assign a loader class to a resource description
:param meta: The resource description instance
"""
meta.loader_cls = self.get_loader(meta, raise_on_error=True)
|
[
"Attempts",
"to",
"assign",
"a",
"loader",
"class",
"to",
"a",
"resource",
"description"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/base.py#L131-L137
|
[
"def",
"resolve_loader",
"(",
"self",
",",
"meta",
":",
"ResourceDescription",
")",
":",
"meta",
".",
"loader_cls",
"=",
"self",
".",
"get_loader",
"(",
"meta",
",",
"raise_on_error",
"=",
"True",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseRegistry.get_loader
|
Attempts to get a loader
:param meta: The resource description instance
:param raise_on_error: Raise ImproperlyConfigured if the loader cannot be resolved
:returns: The requested loader class
|
demosys/resources/base.py
|
def get_loader(self, meta: ResourceDescription, raise_on_error=False) -> BaseLoader:
"""
Attempts to get a loader
:param meta: The resource description instance
:param raise_on_error: Raise ImproperlyConfigured if the loader cannot be resolved
:returns: The requested loader class
"""
for loader in self._loaders:
if loader.name == meta.loader:
return loader
if raise_on_error:
raise ImproperlyConfigured(
"Resource has invalid loader '{}': {}\nAvailiable loaders: {}".format(
meta.loader, meta, [loader.name for loader in self._loaders]))
|
def get_loader(self, meta: ResourceDescription, raise_on_error=False) -> BaseLoader:
"""
Attempts to get a loader
:param meta: The resource description instance
:param raise_on_error: Raise ImproperlyConfigured if the loader cannot be resolved
:returns: The requested loader class
"""
for loader in self._loaders:
if loader.name == meta.loader:
return loader
if raise_on_error:
raise ImproperlyConfigured(
"Resource has invalid loader '{}': {}\nAvailiable loaders: {}".format(
meta.loader, meta, [loader.name for loader in self._loaders]))
|
[
"Attempts",
"to",
"get",
"a",
"loader"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/base.py#L139-L154
|
[
"def",
"get_loader",
"(",
"self",
",",
"meta",
":",
"ResourceDescription",
",",
"raise_on_error",
"=",
"False",
")",
"->",
"BaseLoader",
":",
"for",
"loader",
"in",
"self",
".",
"_loaders",
":",
"if",
"loader",
".",
"name",
"==",
"meta",
".",
"loader",
":",
"return",
"loader",
"if",
"raise_on_error",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"Resource has invalid loader '{}': {}\\nAvailiable loaders: {}\"",
".",
"format",
"(",
"meta",
".",
"loader",
",",
"meta",
",",
"[",
"loader",
".",
"name",
"for",
"loader",
"in",
"self",
".",
"_loaders",
"]",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.keyPressEvent
|
Pyqt specific key press callback function.
Translates and forwards events to :py:func:`keyboard_event`.
|
demosys/context/pyqt/window.py
|
def keyPressEvent(self, event):
"""
Pyqt specific key press callback function.
Translates and forwards events to :py:func:`keyboard_event`.
"""
self.keyboard_event(event.key(), self.keys.ACTION_PRESS, 0)
|
def keyPressEvent(self, event):
"""
Pyqt specific key press callback function.
Translates and forwards events to :py:func:`keyboard_event`.
"""
self.keyboard_event(event.key(), self.keys.ACTION_PRESS, 0)
|
[
"Pyqt",
"specific",
"key",
"press",
"callback",
"function",
".",
"Translates",
"and",
"forwards",
"events",
"to",
":",
"py",
":",
"func",
":",
"keyboard_event",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyqt/window.py#L94-L99
|
[
"def",
"keyPressEvent",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"keyboard_event",
"(",
"event",
".",
"key",
"(",
")",
",",
"self",
".",
"keys",
".",
"ACTION_PRESS",
",",
"0",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.keyReleaseEvent
|
Pyqt specific key release callback function.
Translates and forwards events to :py:func:`keyboard_event`.
|
demosys/context/pyqt/window.py
|
def keyReleaseEvent(self, event):
"""
Pyqt specific key release callback function.
Translates and forwards events to :py:func:`keyboard_event`.
"""
self.keyboard_event(event.key(), self.keys.ACTION_RELEASE, 0)
|
def keyReleaseEvent(self, event):
"""
Pyqt specific key release callback function.
Translates and forwards events to :py:func:`keyboard_event`.
"""
self.keyboard_event(event.key(), self.keys.ACTION_RELEASE, 0)
|
[
"Pyqt",
"specific",
"key",
"release",
"callback",
"function",
".",
"Translates",
"and",
"forwards",
"events",
"to",
":",
"py",
":",
"func",
":",
"keyboard_event",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyqt/window.py#L101-L106
|
[
"def",
"keyReleaseEvent",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"keyboard_event",
"(",
"event",
".",
"key",
"(",
")",
",",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
",",
"0",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Window.resize
|
Pyqt specific resize callback.
|
demosys/context/pyqt/window.py
|
def resize(self, width, height):
"""
Pyqt specific resize callback.
"""
if not self.fbo:
return
# pyqt reports sizes in actual buffer size
self.width = width // self.widget.devicePixelRatio()
self.height = height // self.widget.devicePixelRatio()
self.buffer_width = width
self.buffer_height = height
super().resize(width, height)
|
def resize(self, width, height):
"""
Pyqt specific resize callback.
"""
if not self.fbo:
return
# pyqt reports sizes in actual buffer size
self.width = width // self.widget.devicePixelRatio()
self.height = height // self.widget.devicePixelRatio()
self.buffer_width = width
self.buffer_height = height
super().resize(width, height)
|
[
"Pyqt",
"specific",
"resize",
"callback",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/pyqt/window.py#L115-L128
|
[
"def",
"resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"if",
"not",
"self",
".",
"fbo",
":",
"return",
"# pyqt reports sizes in actual buffer size",
"self",
".",
"width",
"=",
"width",
"//",
"self",
".",
"widget",
".",
"devicePixelRatio",
"(",
")",
"self",
".",
"height",
"=",
"height",
"//",
"self",
".",
"widget",
".",
"devicePixelRatio",
"(",
")",
"self",
".",
"buffer_width",
"=",
"width",
"self",
".",
"buffer_height",
"=",
"height",
"super",
"(",
")",
".",
"resize",
"(",
"width",
",",
"height",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
TextureHelper.draw
|
Draw texture using a fullscreen quad.
By default this will conver the entire screen.
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
|
demosys/opengl/texture.py
|
def draw(self, texture, pos=(0.0, 0.0), scale=(1.0, 1.0)):
"""
Draw texture using a fullscreen quad.
By default this will conver the entire screen.
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
"""
if not self.initialized:
self.init()
self._texture2d_shader["offset"].value = (pos[0] - 1.0, pos[1] - 1.0)
self._texture2d_shader["scale"].value = (scale[0], scale[1])
texture.use(location=0)
self._texture2d_sampler.use(location=0)
self._texture2d_shader["texture0"].value = 0
self._quad.render(self._texture2d_shader)
self._texture2d_sampler.clear(location=0)
|
def draw(self, texture, pos=(0.0, 0.0), scale=(1.0, 1.0)):
"""
Draw texture using a fullscreen quad.
By default this will conver the entire screen.
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
"""
if not self.initialized:
self.init()
self._texture2d_shader["offset"].value = (pos[0] - 1.0, pos[1] - 1.0)
self._texture2d_shader["scale"].value = (scale[0], scale[1])
texture.use(location=0)
self._texture2d_sampler.use(location=0)
self._texture2d_shader["texture0"].value = 0
self._quad.render(self._texture2d_shader)
self._texture2d_sampler.clear(location=0)
|
[
"Draw",
"texture",
"using",
"a",
"fullscreen",
"quad",
".",
"By",
"default",
"this",
"will",
"conver",
"the",
"entire",
"screen",
".",
":",
"param",
"pos",
":",
"(",
"tuple",
")",
"offset",
"x",
"y",
":",
"param",
"scale",
":",
"(",
"tuple",
")",
"scale",
"x",
"y"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/texture.py#L30-L47
|
[
"def",
"draw",
"(",
"self",
",",
"texture",
",",
"pos",
"=",
"(",
"0.0",
",",
"0.0",
")",
",",
"scale",
"=",
"(",
"1.0",
",",
"1.0",
")",
")",
":",
"if",
"not",
"self",
".",
"initialized",
":",
"self",
".",
"init",
"(",
")",
"self",
".",
"_texture2d_shader",
"[",
"\"offset\"",
"]",
".",
"value",
"=",
"(",
"pos",
"[",
"0",
"]",
"-",
"1.0",
",",
"pos",
"[",
"1",
"]",
"-",
"1.0",
")",
"self",
".",
"_texture2d_shader",
"[",
"\"scale\"",
"]",
".",
"value",
"=",
"(",
"scale",
"[",
"0",
"]",
",",
"scale",
"[",
"1",
"]",
")",
"texture",
".",
"use",
"(",
"location",
"=",
"0",
")",
"self",
".",
"_texture2d_sampler",
".",
"use",
"(",
"location",
"=",
"0",
")",
"self",
".",
"_texture2d_shader",
"[",
"\"texture0\"",
"]",
".",
"value",
"=",
"0",
"self",
".",
"_quad",
".",
"render",
"(",
"self",
".",
"_texture2d_shader",
")",
"self",
".",
"_texture2d_sampler",
".",
"clear",
"(",
"location",
"=",
"0",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
TextureHelper.draw_depth
|
Draw depth buffer linearized.
By default this will draw the texture as a full screen quad.
A sampler will be used to ensure the right conditions to draw the depth buffer.
:param near: Near plane in projection
:param far: Far plane in projection
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
|
demosys/opengl/texture.py
|
def draw_depth(self, texture, near, far, pos=(0.0, 0.0), scale=(1.0, 1.0)):
"""
Draw depth buffer linearized.
By default this will draw the texture as a full screen quad.
A sampler will be used to ensure the right conditions to draw the depth buffer.
:param near: Near plane in projection
:param far: Far plane in projection
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
"""
if not self.initialized:
self.init()
self._depth_shader["offset"].value = (pos[0] - 1.0, pos[1] - 1.0)
self._depth_shader["scale"].value = (scale[0], scale[1])
self._depth_shader["near"].value = near
self._depth_shader["far"].value = far
self._depth_sampler.use(location=0)
texture.use(location=0)
self._depth_shader["texture0"].value = 0
self._quad.render(self._depth_shader)
self._depth_sampler.clear(location=0)
|
def draw_depth(self, texture, near, far, pos=(0.0, 0.0), scale=(1.0, 1.0)):
"""
Draw depth buffer linearized.
By default this will draw the texture as a full screen quad.
A sampler will be used to ensure the right conditions to draw the depth buffer.
:param near: Near plane in projection
:param far: Far plane in projection
:param pos: (tuple) offset x, y
:param scale: (tuple) scale x, y
"""
if not self.initialized:
self.init()
self._depth_shader["offset"].value = (pos[0] - 1.0, pos[1] - 1.0)
self._depth_shader["scale"].value = (scale[0], scale[1])
self._depth_shader["near"].value = near
self._depth_shader["far"].value = far
self._depth_sampler.use(location=0)
texture.use(location=0)
self._depth_shader["texture0"].value = 0
self._quad.render(self._depth_shader)
self._depth_sampler.clear(location=0)
|
[
"Draw",
"depth",
"buffer",
"linearized",
".",
"By",
"default",
"this",
"will",
"draw",
"the",
"texture",
"as",
"a",
"full",
"screen",
"quad",
".",
"A",
"sampler",
"will",
"be",
"used",
"to",
"ensure",
"the",
"right",
"conditions",
"to",
"draw",
"the",
"depth",
"buffer",
".",
":",
"param",
"near",
":",
"Near",
"plane",
"in",
"projection",
":",
"param",
"far",
":",
"Far",
"plane",
"in",
"projection",
":",
"param",
"pos",
":",
"(",
"tuple",
")",
"offset",
"x",
"y",
":",
"param",
"scale",
":",
"(",
"tuple",
")",
"scale",
"x",
"y"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/texture.py#L49-L71
|
[
"def",
"draw_depth",
"(",
"self",
",",
"texture",
",",
"near",
",",
"far",
",",
"pos",
"=",
"(",
"0.0",
",",
"0.0",
")",
",",
"scale",
"=",
"(",
"1.0",
",",
"1.0",
")",
")",
":",
"if",
"not",
"self",
".",
"initialized",
":",
"self",
".",
"init",
"(",
")",
"self",
".",
"_depth_shader",
"[",
"\"offset\"",
"]",
".",
"value",
"=",
"(",
"pos",
"[",
"0",
"]",
"-",
"1.0",
",",
"pos",
"[",
"1",
"]",
"-",
"1.0",
")",
"self",
".",
"_depth_shader",
"[",
"\"scale\"",
"]",
".",
"value",
"=",
"(",
"scale",
"[",
"0",
"]",
",",
"scale",
"[",
"1",
"]",
")",
"self",
".",
"_depth_shader",
"[",
"\"near\"",
"]",
".",
"value",
"=",
"near",
"self",
".",
"_depth_shader",
"[",
"\"far\"",
"]",
".",
"value",
"=",
"far",
"self",
".",
"_depth_sampler",
".",
"use",
"(",
"location",
"=",
"0",
")",
"texture",
".",
"use",
"(",
"location",
"=",
"0",
")",
"self",
".",
"_depth_shader",
"[",
"\"texture0\"",
"]",
".",
"value",
"=",
"0",
"self",
".",
"_quad",
".",
"render",
"(",
"self",
".",
"_depth_shader",
")",
"self",
".",
"_depth_sampler",
".",
"clear",
"(",
"location",
"=",
"0",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
TextureHelper._init_texture2d_draw
|
Initialize geometry and shader for drawing FBO layers
|
demosys/opengl/texture.py
|
def _init_texture2d_draw(self):
"""Initialize geometry and shader for drawing FBO layers"""
if not TextureHelper._quad:
TextureHelper._quad = geometry.quad_fs()
# Shader for drawing color layers
TextureHelper._texture2d_shader = context.ctx().program(
vertex_shader="""
#version 330
in vec3 in_position;
in vec2 in_uv;
out vec2 uv;
uniform vec2 offset;
uniform vec2 scale;
void main() {
uv = in_uv;
gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);
}
""",
fragment_shader="""
#version 330
out vec4 out_color;
in vec2 uv;
uniform sampler2D texture0;
void main() {
out_color = texture(texture0, uv);
}
"""
)
TextureHelper._texture2d_sampler = self.ctx.sampler(
filter=(moderngl.LINEAR, moderngl.LINEAR),
)
|
def _init_texture2d_draw(self):
"""Initialize geometry and shader for drawing FBO layers"""
if not TextureHelper._quad:
TextureHelper._quad = geometry.quad_fs()
# Shader for drawing color layers
TextureHelper._texture2d_shader = context.ctx().program(
vertex_shader="""
#version 330
in vec3 in_position;
in vec2 in_uv;
out vec2 uv;
uniform vec2 offset;
uniform vec2 scale;
void main() {
uv = in_uv;
gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);
}
""",
fragment_shader="""
#version 330
out vec4 out_color;
in vec2 uv;
uniform sampler2D texture0;
void main() {
out_color = texture(texture0, uv);
}
"""
)
TextureHelper._texture2d_sampler = self.ctx.sampler(
filter=(moderngl.LINEAR, moderngl.LINEAR),
)
|
[
"Initialize",
"geometry",
"and",
"shader",
"for",
"drawing",
"FBO",
"layers"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/texture.py#L73-L109
|
[
"def",
"_init_texture2d_draw",
"(",
"self",
")",
":",
"if",
"not",
"TextureHelper",
".",
"_quad",
":",
"TextureHelper",
".",
"_quad",
"=",
"geometry",
".",
"quad_fs",
"(",
")",
"# Shader for drawing color layers\r",
"TextureHelper",
".",
"_texture2d_shader",
"=",
"context",
".",
"ctx",
"(",
")",
".",
"program",
"(",
"vertex_shader",
"=",
"\"\"\"\r\n #version 330\r\n\r\n in vec3 in_position;\r\n in vec2 in_uv;\r\n out vec2 uv;\r\n uniform vec2 offset;\r\n uniform vec2 scale;\r\n\r\n void main() {\r\n uv = in_uv;\r\n gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);\r\n }\r\n \"\"\"",
",",
"fragment_shader",
"=",
"\"\"\"\r\n #version 330\r\n\r\n out vec4 out_color;\r\n in vec2 uv;\r\n uniform sampler2D texture0;\r\n\r\n void main() {\r\n out_color = texture(texture0, uv);\r\n }\r\n \"\"\"",
")",
"TextureHelper",
".",
"_texture2d_sampler",
"=",
"self",
".",
"ctx",
".",
"sampler",
"(",
"filter",
"=",
"(",
"moderngl",
".",
"LINEAR",
",",
"moderngl",
".",
"LINEAR",
")",
",",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
TextureHelper._init_depth_texture_draw
|
Initialize geometry and shader for drawing FBO layers
|
demosys/opengl/texture.py
|
def _init_depth_texture_draw(self):
"""Initialize geometry and shader for drawing FBO layers"""
from demosys import geometry
if not TextureHelper._quad:
TextureHelper._quad = geometry.quad_fs()
# Shader for drawing depth layers
TextureHelper._depth_shader = context.ctx().program(
vertex_shader="""
#version 330
in vec3 in_position;
in vec2 in_uv;
out vec2 uv;
uniform vec2 offset;
uniform vec2 scale;
void main() {
uv = in_uv;
gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);
}
""",
fragment_shader="""
#version 330
out vec4 out_color;
in vec2 uv;
uniform sampler2D texture0;
uniform float near;
uniform float far;
void main() {
float z = texture(texture0, uv).r;
float d = (2.0 * near) / (far + near - z * (far - near));
out_color = vec4(d);
}
"""
)
TextureHelper._depth_sampler = self.ctx.sampler(
filter=(moderngl.LINEAR, moderngl.LINEAR),
compare_func='',
)
|
def _init_depth_texture_draw(self):
"""Initialize geometry and shader for drawing FBO layers"""
from demosys import geometry
if not TextureHelper._quad:
TextureHelper._quad = geometry.quad_fs()
# Shader for drawing depth layers
TextureHelper._depth_shader = context.ctx().program(
vertex_shader="""
#version 330
in vec3 in_position;
in vec2 in_uv;
out vec2 uv;
uniform vec2 offset;
uniform vec2 scale;
void main() {
uv = in_uv;
gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);
}
""",
fragment_shader="""
#version 330
out vec4 out_color;
in vec2 uv;
uniform sampler2D texture0;
uniform float near;
uniform float far;
void main() {
float z = texture(texture0, uv).r;
float d = (2.0 * near) / (far + near - z * (far - near));
out_color = vec4(d);
}
"""
)
TextureHelper._depth_sampler = self.ctx.sampler(
filter=(moderngl.LINEAR, moderngl.LINEAR),
compare_func='',
)
|
[
"Initialize",
"geometry",
"and",
"shader",
"for",
"drawing",
"FBO",
"layers"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/texture.py#L111-L154
|
[
"def",
"_init_depth_texture_draw",
"(",
"self",
")",
":",
"from",
"demosys",
"import",
"geometry",
"if",
"not",
"TextureHelper",
".",
"_quad",
":",
"TextureHelper",
".",
"_quad",
"=",
"geometry",
".",
"quad_fs",
"(",
")",
"# Shader for drawing depth layers\r",
"TextureHelper",
".",
"_depth_shader",
"=",
"context",
".",
"ctx",
"(",
")",
".",
"program",
"(",
"vertex_shader",
"=",
"\"\"\"\r\n #version 330\r\n\r\n in vec3 in_position;\r\n in vec2 in_uv;\r\n out vec2 uv;\r\n uniform vec2 offset;\r\n uniform vec2 scale;\r\n\r\n void main() {\r\n uv = in_uv;\r\n gl_Position = vec4((in_position.xy + vec2(1.0, 1.0)) * scale + offset, 0.0, 1.0);\r\n }\r\n \"\"\"",
",",
"fragment_shader",
"=",
"\"\"\"\r\n #version 330\r\n\r\n out vec4 out_color;\r\n in vec2 uv;\r\n uniform sampler2D texture0;\r\n uniform float near;\r\n uniform float far;\r\n\r\n void main() {\r\n float z = texture(texture0, uv).r;\r\n float d = (2.0 * near) / (far + near - z * (far - near));\r\n out_color = vec4(d);\r\n }\r\n \"\"\"",
")",
"TextureHelper",
".",
"_depth_sampler",
"=",
"self",
".",
"ctx",
".",
"sampler",
"(",
"filter",
"=",
"(",
"moderngl",
".",
"LINEAR",
",",
"moderngl",
".",
"LINEAR",
")",
",",
"compare_func",
"=",
"''",
",",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.draw
|
Draws a frame. Internally it calls the
configured timeline's draw method.
Args:
current_time (float): The current time (preferrably always from the configured timer class)
frame_time (float): The duration of the previous frame in seconds
|
demosys/context/base.py
|
def draw(self, current_time, frame_time):
"""
Draws a frame. Internally it calls the
configured timeline's draw method.
Args:
current_time (float): The current time (preferrably always from the configured timer class)
frame_time (float): The duration of the previous frame in seconds
"""
self.set_default_viewport()
self.timeline.draw(current_time, frame_time, self.fbo)
|
def draw(self, current_time, frame_time):
"""
Draws a frame. Internally it calls the
configured timeline's draw method.
Args:
current_time (float): The current time (preferrably always from the configured timer class)
frame_time (float): The duration of the previous frame in seconds
"""
self.set_default_viewport()
self.timeline.draw(current_time, frame_time, self.fbo)
|
[
"Draws",
"a",
"frame",
".",
"Internally",
"it",
"calls",
"the",
"configured",
"timeline",
"s",
"draw",
"method",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L97-L107
|
[
"def",
"draw",
"(",
"self",
",",
"current_time",
",",
"frame_time",
")",
":",
"self",
".",
"set_default_viewport",
"(",
")",
"self",
".",
"timeline",
".",
"draw",
"(",
"current_time",
",",
"frame_time",
",",
"self",
".",
"fbo",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.clear
|
Clear the window buffer
|
demosys/context/base.py
|
def clear(self):
"""
Clear the window buffer
"""
self.ctx.fbo.clear(
red=self.clear_color[0],
green=self.clear_color[1],
blue=self.clear_color[2],
alpha=self.clear_color[3],
depth=self.clear_depth,
)
|
def clear(self):
"""
Clear the window buffer
"""
self.ctx.fbo.clear(
red=self.clear_color[0],
green=self.clear_color[1],
blue=self.clear_color[2],
alpha=self.clear_color[3],
depth=self.clear_depth,
)
|
[
"Clear",
"the",
"window",
"buffer"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L109-L119
|
[
"def",
"clear",
"(",
"self",
")",
":",
"self",
".",
"ctx",
".",
"fbo",
".",
"clear",
"(",
"red",
"=",
"self",
".",
"clear_color",
"[",
"0",
"]",
",",
"green",
"=",
"self",
".",
"clear_color",
"[",
"1",
"]",
",",
"blue",
"=",
"self",
".",
"clear_color",
"[",
"2",
"]",
",",
"alpha",
"=",
"self",
".",
"clear_color",
"[",
"3",
"]",
",",
"depth",
"=",
"self",
".",
"clear_depth",
",",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.clear_values
|
Sets the clear values for the window buffer.
Args:
red (float): red compoent
green (float): green compoent
blue (float): blue compoent
alpha (float): alpha compoent
depth (float): depth value
|
demosys/context/base.py
|
def clear_values(self, red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0):
"""
Sets the clear values for the window buffer.
Args:
red (float): red compoent
green (float): green compoent
blue (float): blue compoent
alpha (float): alpha compoent
depth (float): depth value
"""
self.clear_color = (red, green, blue, alpha)
self.clear_depth = depth
|
def clear_values(self, red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0):
"""
Sets the clear values for the window buffer.
Args:
red (float): red compoent
green (float): green compoent
blue (float): blue compoent
alpha (float): alpha compoent
depth (float): depth value
"""
self.clear_color = (red, green, blue, alpha)
self.clear_depth = depth
|
[
"Sets",
"the",
"clear",
"values",
"for",
"the",
"window",
"buffer",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L121-L133
|
[
"def",
"clear_values",
"(",
"self",
",",
"red",
"=",
"0.0",
",",
"green",
"=",
"0.0",
",",
"blue",
"=",
"0.0",
",",
"alpha",
"=",
"0.0",
",",
"depth",
"=",
"1.0",
")",
":",
"self",
".",
"clear_color",
"=",
"(",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
")",
"self",
".",
"clear_depth",
"=",
"depth"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.keyboard_event
|
Handles the standard keyboard events such as camera movements,
taking a screenshot, closing the window etc.
Can be overriden add new keyboard events. Ensure this method
is also called if you want to keep the standard features.
Arguments:
key: The key that was pressed or released
action: The key action. Can be `ACTION_PRESS` or `ACTION_RELEASE`
modifier: Modifiers such as holding shift or ctrl
|
demosys/context/base.py
|
def keyboard_event(self, key, action, modifier):
"""
Handles the standard keyboard events such as camera movements,
taking a screenshot, closing the window etc.
Can be overriden add new keyboard events. Ensure this method
is also called if you want to keep the standard features.
Arguments:
key: The key that was pressed or released
action: The key action. Can be `ACTION_PRESS` or `ACTION_RELEASE`
modifier: Modifiers such as holding shift or ctrl
"""
# The well-known standard key for quick exit
if key == self.keys.ESCAPE:
self.close()
return
# Toggle pause time
if key == self.keys.SPACE and action == self.keys.ACTION_PRESS:
self.timer.toggle_pause()
# Camera movement
# Right
if key == self.keys.D:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_right(True)
elif action == self.keys.ACTION_RELEASE:
self.sys_camera.move_right(False)
# Left
elif key == self.keys.A:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_left(True)
elif action == self.keys.ACTION_RELEASE:
self.sys_camera.move_left(False)
# Forward
elif key == self.keys.W:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_forward(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_forward(False)
# Backwards
elif key == self.keys.S:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_backward(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_backward(False)
# UP
elif key == self.keys.Q:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_down(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_down(False)
# Down
elif key == self.keys.E:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_up(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_up(False)
# Screenshots
if key == self.keys.X and action == self.keys.ACTION_PRESS:
screenshot.create()
if key == self.keys.R and action == self.keys.ACTION_PRESS:
project.instance.reload_programs()
if key == self.keys.RIGHT and action == self.keys.ACTION_PRESS:
self.timer.set_time(self.timer.get_time() + 10.0)
if key == self.keys.LEFT and action == self.keys.ACTION_PRESS:
self.timer.set_time(self.timer.get_time() - 10.0)
# Forward the event to the timeline
self.timeline.key_event(key, action, modifier)
|
def keyboard_event(self, key, action, modifier):
"""
Handles the standard keyboard events such as camera movements,
taking a screenshot, closing the window etc.
Can be overriden add new keyboard events. Ensure this method
is also called if you want to keep the standard features.
Arguments:
key: The key that was pressed or released
action: The key action. Can be `ACTION_PRESS` or `ACTION_RELEASE`
modifier: Modifiers such as holding shift or ctrl
"""
# The well-known standard key for quick exit
if key == self.keys.ESCAPE:
self.close()
return
# Toggle pause time
if key == self.keys.SPACE and action == self.keys.ACTION_PRESS:
self.timer.toggle_pause()
# Camera movement
# Right
if key == self.keys.D:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_right(True)
elif action == self.keys.ACTION_RELEASE:
self.sys_camera.move_right(False)
# Left
elif key == self.keys.A:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_left(True)
elif action == self.keys.ACTION_RELEASE:
self.sys_camera.move_left(False)
# Forward
elif key == self.keys.W:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_forward(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_forward(False)
# Backwards
elif key == self.keys.S:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_backward(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_backward(False)
# UP
elif key == self.keys.Q:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_down(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_down(False)
# Down
elif key == self.keys.E:
if action == self.keys.ACTION_PRESS:
self.sys_camera.move_up(True)
if action == self.keys.ACTION_RELEASE:
self.sys_camera.move_up(False)
# Screenshots
if key == self.keys.X and action == self.keys.ACTION_PRESS:
screenshot.create()
if key == self.keys.R and action == self.keys.ACTION_PRESS:
project.instance.reload_programs()
if key == self.keys.RIGHT and action == self.keys.ACTION_PRESS:
self.timer.set_time(self.timer.get_time() + 10.0)
if key == self.keys.LEFT and action == self.keys.ACTION_PRESS:
self.timer.set_time(self.timer.get_time() - 10.0)
# Forward the event to the timeline
self.timeline.key_event(key, action, modifier)
|
[
"Handles",
"the",
"standard",
"keyboard",
"events",
"such",
"as",
"camera",
"movements",
"taking",
"a",
"screenshot",
"closing",
"the",
"window",
"etc",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L194-L270
|
[
"def",
"keyboard_event",
"(",
"self",
",",
"key",
",",
"action",
",",
"modifier",
")",
":",
"# The well-known standard key for quick exit",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"ESCAPE",
":",
"self",
".",
"close",
"(",
")",
"return",
"# Toggle pause time",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"SPACE",
"and",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"timer",
".",
"toggle_pause",
"(",
")",
"# Camera movement",
"# Right",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"D",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_right",
"(",
"True",
")",
"elif",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_right",
"(",
"False",
")",
"# Left",
"elif",
"key",
"==",
"self",
".",
"keys",
".",
"A",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_left",
"(",
"True",
")",
"elif",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_left",
"(",
"False",
")",
"# Forward",
"elif",
"key",
"==",
"self",
".",
"keys",
".",
"W",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_forward",
"(",
"True",
")",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_forward",
"(",
"False",
")",
"# Backwards",
"elif",
"key",
"==",
"self",
".",
"keys",
".",
"S",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_backward",
"(",
"True",
")",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_backward",
"(",
"False",
")",
"# UP",
"elif",
"key",
"==",
"self",
".",
"keys",
".",
"Q",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_down",
"(",
"True",
")",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_down",
"(",
"False",
")",
"# Down",
"elif",
"key",
"==",
"self",
".",
"keys",
".",
"E",
":",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"sys_camera",
".",
"move_up",
"(",
"True",
")",
"if",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_RELEASE",
":",
"self",
".",
"sys_camera",
".",
"move_up",
"(",
"False",
")",
"# Screenshots",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"X",
"and",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"screenshot",
".",
"create",
"(",
")",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"R",
"and",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"project",
".",
"instance",
".",
"reload_programs",
"(",
")",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"RIGHT",
"and",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"timer",
".",
"set_time",
"(",
"self",
".",
"timer",
".",
"get_time",
"(",
")",
"+",
"10.0",
")",
"if",
"key",
"==",
"self",
".",
"keys",
".",
"LEFT",
"and",
"action",
"==",
"self",
".",
"keys",
".",
"ACTION_PRESS",
":",
"self",
".",
"timer",
".",
"set_time",
"(",
"self",
".",
"timer",
".",
"get_time",
"(",
")",
"-",
"10.0",
")",
"# Forward the event to the timeline",
"self",
".",
"timeline",
".",
"key_event",
"(",
"key",
",",
"action",
",",
"modifier",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.cursor_event
|
The standard mouse movement event method.
Can be overriden to add new functionality.
By default this feeds the system camera with new values.
Args:
x: The current mouse x position
y: The current mouse y position
dx: Delta x postion (x position difference from the previous event)
dy: Delta y postion (y position difference from the previous event)
|
demosys/context/base.py
|
def cursor_event(self, x, y, dx, dy):
"""
The standard mouse movement event method.
Can be overriden to add new functionality.
By default this feeds the system camera with new values.
Args:
x: The current mouse x position
y: The current mouse y position
dx: Delta x postion (x position difference from the previous event)
dy: Delta y postion (y position difference from the previous event)
"""
self.sys_camera.rot_state(x, y)
|
def cursor_event(self, x, y, dx, dy):
"""
The standard mouse movement event method.
Can be overriden to add new functionality.
By default this feeds the system camera with new values.
Args:
x: The current mouse x position
y: The current mouse y position
dx: Delta x postion (x position difference from the previous event)
dy: Delta y postion (y position difference from the previous event)
"""
self.sys_camera.rot_state(x, y)
|
[
"The",
"standard",
"mouse",
"movement",
"event",
"method",
".",
"Can",
"be",
"overriden",
"to",
"add",
"new",
"functionality",
".",
"By",
"default",
"this",
"feeds",
"the",
"system",
"camera",
"with",
"new",
"values",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L272-L284
|
[
"def",
"cursor_event",
"(",
"self",
",",
"x",
",",
"y",
",",
"dx",
",",
"dy",
")",
":",
"self",
".",
"sys_camera",
".",
"rot_state",
"(",
"x",
",",
"y",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseWindow.set_default_viewport
|
Calculates the viewport based on the configured aspect ratio in settings.
Will add black borders if the window do not match the viewport.
|
demosys/context/base.py
|
def set_default_viewport(self):
"""
Calculates the viewport based on the configured aspect ratio in settings.
Will add black borders if the window do not match the viewport.
"""
# The expected height with the current viewport width
expected_height = int(self.buffer_width / self.aspect_ratio)
# How much positive or negative y padding
blank_space = self.buffer_height - expected_height
self.fbo.viewport = (0, blank_space // 2, self.buffer_width, expected_height)
|
def set_default_viewport(self):
"""
Calculates the viewport based on the configured aspect ratio in settings.
Will add black borders if the window do not match the viewport.
"""
# The expected height with the current viewport width
expected_height = int(self.buffer_width / self.aspect_ratio)
# How much positive or negative y padding
blank_space = self.buffer_height - expected_height
self.fbo.viewport = (0, blank_space // 2, self.buffer_width, expected_height)
|
[
"Calculates",
"the",
"viewport",
"based",
"on",
"the",
"configured",
"aspect",
"ratio",
"in",
"settings",
".",
"Will",
"add",
"black",
"borders",
"if",
"the",
"window",
"do",
"not",
"match",
"the",
"viewport",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/context/base.py#L299-L309
|
[
"def",
"set_default_viewport",
"(",
"self",
")",
":",
"# The expected height with the current viewport width",
"expected_height",
"=",
"int",
"(",
"self",
".",
"buffer_width",
"/",
"self",
".",
"aspect_ratio",
")",
"# How much positive or negative y padding",
"blank_space",
"=",
"self",
".",
"buffer_height",
"-",
"expected_height",
"self",
".",
"fbo",
".",
"viewport",
"=",
"(",
"0",
",",
"blank_space",
"//",
"2",
",",
"self",
".",
"buffer_width",
",",
"expected_height",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.start
|
Start the timer
|
demosys/timers/rocketmusic.py
|
def start(self):
"""Start the timer"""
self.music.start()
if not self.start_paused:
self.rocket.start()
|
def start(self):
"""Start the timer"""
self.music.start()
if not self.start_paused:
self.rocket.start()
|
[
"Start",
"the",
"timer"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/rocketmusic.py#L13-L17
|
[
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"music",
".",
"start",
"(",
")",
"if",
"not",
"self",
".",
"start_paused",
":",
"self",
".",
"rocket",
".",
"start",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.toggle_pause
|
Toggle pause mode
|
demosys/timers/rocketmusic.py
|
def toggle_pause(self):
"""Toggle pause mode"""
self.controller.playing = not self.controller.playing
self.music.toggle_pause()
|
def toggle_pause(self):
"""Toggle pause mode"""
self.controller.playing = not self.controller.playing
self.music.toggle_pause()
|
[
"Toggle",
"pause",
"mode"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/rocketmusic.py#L43-L46
|
[
"def",
"toggle_pause",
"(",
"self",
")",
":",
"self",
".",
"controller",
".",
"playing",
"=",
"not",
"self",
".",
"controller",
".",
"playing",
"self",
".",
"music",
".",
"toggle_pause",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
SceneLoader.supports_file
|
Check if the loader has a supported file extension
|
demosys/loaders/scene/base.py
|
def supports_file(cls, meta):
"""Check if the loader has a supported file extension"""
path = Path(meta.path)
for ext in cls.file_extensions:
if path.suffixes[:len(ext)] == ext:
return True
return False
|
def supports_file(cls, meta):
"""Check if the loader has a supported file extension"""
path = Path(meta.path)
for ext in cls.file_extensions:
if path.suffixes[:len(ext)] == ext:
return True
return False
|
[
"Check",
"if",
"the",
"loader",
"has",
"a",
"supported",
"file",
"extension"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/scene/base.py#L20-L28
|
[
"def",
"supports_file",
"(",
"cls",
",",
"meta",
")",
":",
"path",
"=",
"Path",
"(",
"meta",
".",
"path",
")",
"for",
"ext",
"in",
"cls",
".",
"file_extensions",
":",
"if",
"path",
".",
"suffixes",
"[",
":",
"len",
"(",
"ext",
")",
"]",
"==",
"ext",
":",
"return",
"True",
"return",
"False"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Tracks.get
|
Get or create a Track object.
:param name: Name of the track
:return: Track object
|
demosys/resources/tracks.py
|
def get(self, name) -> Track:
"""
Get or create a Track object.
:param name: Name of the track
:return: Track object
"""
name = name.lower()
track = self.track_map.get(name)
if not track:
track = Track(name)
self.tacks.append(track)
self.track_map[name] = track
return track
|
def get(self, name) -> Track:
"""
Get or create a Track object.
:param name: Name of the track
:return: Track object
"""
name = name.lower()
track = self.track_map.get(name)
if not track:
track = Track(name)
self.tacks.append(track)
self.track_map[name] = track
return track
|
[
"Get",
"or",
"create",
"a",
"Track",
"object",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/tracks.py#L13-L26
|
[
"def",
"get",
"(",
"self",
",",
"name",
")",
"->",
"Track",
":",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"track",
"=",
"self",
".",
"track_map",
".",
"get",
"(",
"name",
")",
"if",
"not",
"track",
":",
"track",
"=",
"Track",
"(",
"name",
")",
"self",
".",
"tacks",
".",
"append",
"(",
"track",
")",
"self",
".",
"track_map",
"[",
"name",
"]",
"=",
"track",
"return",
"track"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
find_commands
|
Get all command names in the a folder
:return: List of commands names
|
demosys/management/__init__.py
|
def find_commands(command_dir: str) -> List[str]:
"""
Get all command names in the a folder
:return: List of commands names
"""
if not command_dir:
return []
return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir])
if not is_pkg and not name.startswith('_')]
|
def find_commands(command_dir: str) -> List[str]:
"""
Get all command names in the a folder
:return: List of commands names
"""
if not command_dir:
return []
return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir])
if not is_pkg and not name.startswith('_')]
|
[
"Get",
"all",
"command",
"names",
"in",
"the",
"a",
"folder"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/__init__.py#L9-L19
|
[
"def",
"find_commands",
"(",
"command_dir",
":",
"str",
")",
"->",
"List",
"[",
"str",
"]",
":",
"if",
"not",
"command_dir",
":",
"return",
"[",
"]",
"return",
"[",
"name",
"for",
"_",
",",
"name",
",",
"is_pkg",
"in",
"pkgutil",
".",
"iter_modules",
"(",
"[",
"command_dir",
"]",
")",
"if",
"not",
"is_pkg",
"and",
"not",
"name",
".",
"startswith",
"(",
"'_'",
")",
"]"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
execute_from_command_line
|
Currently the only entrypoint (manage.py, demosys-admin)
|
demosys/management/__init__.py
|
def execute_from_command_line(argv=None):
"""
Currently the only entrypoint (manage.py, demosys-admin)
"""
if not argv:
argv = sys.argv
# prog_name = argv[0]
system_commands = find_commands(system_command_dir())
project_commands = find_commands(project_command_dir())
project_package = project_package_name()
command = argv[1] if len(argv) > 1 else None
# Are we running a core command?
if command in system_commands:
cmd = load_command_class('demosys', command)
cmd.run_from_argv(argv)
elif command in project_commands:
cmd = load_command_class(project_package, command)
cmd.run_from_argv(argv)
else:
print("Available commands:")
for name in system_commands:
print(" - {}".format(name))
for name in project_commands:
print(" - {}".format(name))
|
def execute_from_command_line(argv=None):
"""
Currently the only entrypoint (manage.py, demosys-admin)
"""
if not argv:
argv = sys.argv
# prog_name = argv[0]
system_commands = find_commands(system_command_dir())
project_commands = find_commands(project_command_dir())
project_package = project_package_name()
command = argv[1] if len(argv) > 1 else None
# Are we running a core command?
if command in system_commands:
cmd = load_command_class('demosys', command)
cmd.run_from_argv(argv)
elif command in project_commands:
cmd = load_command_class(project_package, command)
cmd.run_from_argv(argv)
else:
print("Available commands:")
for name in system_commands:
print(" - {}".format(name))
for name in project_commands:
print(" - {}".format(name))
|
[
"Currently",
"the",
"only",
"entrypoint",
"(",
"manage",
".",
"py",
"demosys",
"-",
"admin",
")"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/__init__.py#L56-L83
|
[
"def",
"execute_from_command_line",
"(",
"argv",
"=",
"None",
")",
":",
"if",
"not",
"argv",
":",
"argv",
"=",
"sys",
".",
"argv",
"# prog_name = argv[0]",
"system_commands",
"=",
"find_commands",
"(",
"system_command_dir",
"(",
")",
")",
"project_commands",
"=",
"find_commands",
"(",
"project_command_dir",
"(",
")",
")",
"project_package",
"=",
"project_package_name",
"(",
")",
"command",
"=",
"argv",
"[",
"1",
"]",
"if",
"len",
"(",
"argv",
")",
">",
"1",
"else",
"None",
"# Are we running a core command?",
"if",
"command",
"in",
"system_commands",
":",
"cmd",
"=",
"load_command_class",
"(",
"'demosys'",
",",
"command",
")",
"cmd",
".",
"run_from_argv",
"(",
"argv",
")",
"elif",
"command",
"in",
"project_commands",
":",
"cmd",
"=",
"load_command_class",
"(",
"project_package",
",",
"command",
")",
"cmd",
".",
"run_from_argv",
"(",
"argv",
")",
"else",
":",
"print",
"(",
"\"Available commands:\"",
")",
"for",
"name",
"in",
"system_commands",
":",
"print",
"(",
"\" - {}\"",
".",
"format",
"(",
"name",
")",
")",
"for",
"name",
"in",
"project_commands",
":",
"print",
"(",
"\" - {}\"",
".",
"format",
"(",
"name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Settings.update
|
Override settings values
|
demosys/conf/__init__.py
|
def update(self, **kwargs):
"""Override settings values"""
for name, value in kwargs.items():
setattr(self, name, value)
|
def update(self, **kwargs):
"""Override settings values"""
for name, value in kwargs.items():
setattr(self, name, value)
|
[
"Override",
"settings",
"values"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/conf/__init__.py#L49-L52
|
[
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"name",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"setattr",
"(",
"self",
",",
"name",
",",
"value",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Settings.add_program_dir
|
Hack in program directory
|
demosys/conf/__init__.py
|
def add_program_dir(self, directory):
"""Hack in program directory"""
dirs = list(self.PROGRAM_DIRS)
dirs.append(directory)
self.PROGRAM_DIRS = dirs
|
def add_program_dir(self, directory):
"""Hack in program directory"""
dirs = list(self.PROGRAM_DIRS)
dirs.append(directory)
self.PROGRAM_DIRS = dirs
|
[
"Hack",
"in",
"program",
"directory"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/conf/__init__.py#L63-L67
|
[
"def",
"add_program_dir",
"(",
"self",
",",
"directory",
")",
":",
"dirs",
"=",
"list",
"(",
"self",
".",
"PROGRAM_DIRS",
")",
"dirs",
".",
"append",
"(",
"directory",
")",
"self",
".",
"PROGRAM_DIRS",
"=",
"dirs"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Settings.add_texture_dir
|
Hack in texture directory
|
demosys/conf/__init__.py
|
def add_texture_dir(self, directory):
"""Hack in texture directory"""
dirs = list(self.TEXTURE_DIRS)
dirs.append(directory)
self.TEXTURE_DIRS = dirs
|
def add_texture_dir(self, directory):
"""Hack in texture directory"""
dirs = list(self.TEXTURE_DIRS)
dirs.append(directory)
self.TEXTURE_DIRS = dirs
|
[
"Hack",
"in",
"texture",
"directory"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/conf/__init__.py#L69-L73
|
[
"def",
"add_texture_dir",
"(",
"self",
",",
"directory",
")",
":",
"dirs",
"=",
"list",
"(",
"self",
".",
"TEXTURE_DIRS",
")",
"dirs",
".",
"append",
"(",
"directory",
")",
"self",
".",
"TEXTURE_DIRS",
"=",
"dirs"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Settings.add_data_dir
|
Hack in a data directory
|
demosys/conf/__init__.py
|
def add_data_dir(self, directory):
"""Hack in a data directory"""
dirs = list(self.DATA_DIRS)
dirs.append(directory)
self.DATA_DIRS = dirs
|
def add_data_dir(self, directory):
"""Hack in a data directory"""
dirs = list(self.DATA_DIRS)
dirs.append(directory)
self.DATA_DIRS = dirs
|
[
"Hack",
"in",
"a",
"data",
"directory"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/conf/__init__.py#L75-L79
|
[
"def",
"add_data_dir",
"(",
"self",
",",
"directory",
")",
":",
"dirs",
"=",
"list",
"(",
"self",
".",
"DATA_DIRS",
")",
"dirs",
".",
"append",
"(",
"directory",
")",
"self",
".",
"DATA_DIRS",
"=",
"dirs"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BufferInfo.content
|
Build content tuple for the buffer
|
demosys/opengl/vao.py
|
def content(self, attributes: List[str]):
"""Build content tuple for the buffer"""
formats = []
attrs = []
for attrib_format, attrib in zip(self.attrib_formats, self.attributes):
if attrib not in attributes:
formats.append(attrib_format.pad_str())
continue
formats.append(attrib_format.format)
attrs.append(attrib)
attributes.remove(attrib)
if not attrs:
return None
return (
self.buffer,
"{}{}".format(" ".join(formats), '/i' if self.per_instance else ''),
*attrs
)
|
def content(self, attributes: List[str]):
"""Build content tuple for the buffer"""
formats = []
attrs = []
for attrib_format, attrib in zip(self.attrib_formats, self.attributes):
if attrib not in attributes:
formats.append(attrib_format.pad_str())
continue
formats.append(attrib_format.format)
attrs.append(attrib)
attributes.remove(attrib)
if not attrs:
return None
return (
self.buffer,
"{}{}".format(" ".join(formats), '/i' if self.per_instance else ''),
*attrs
)
|
[
"Build",
"content",
"tuple",
"for",
"the",
"buffer"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L48-L70
|
[
"def",
"content",
"(",
"self",
",",
"attributes",
":",
"List",
"[",
"str",
"]",
")",
":",
"formats",
"=",
"[",
"]",
"attrs",
"=",
"[",
"]",
"for",
"attrib_format",
",",
"attrib",
"in",
"zip",
"(",
"self",
".",
"attrib_formats",
",",
"self",
".",
"attributes",
")",
":",
"if",
"attrib",
"not",
"in",
"attributes",
":",
"formats",
".",
"append",
"(",
"attrib_format",
".",
"pad_str",
"(",
")",
")",
"continue",
"formats",
".",
"append",
"(",
"attrib_format",
".",
"format",
")",
"attrs",
".",
"append",
"(",
"attrib",
")",
"attributes",
".",
"remove",
"(",
"attrib",
")",
"if",
"not",
"attrs",
":",
"return",
"None",
"return",
"(",
"self",
".",
"buffer",
",",
"\"{}{}\"",
".",
"format",
"(",
"\" \"",
".",
"join",
"(",
"formats",
")",
",",
"'/i'",
"if",
"self",
".",
"per_instance",
"else",
"''",
")",
",",
"*",
"attrs",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.render
|
Render the VAO.
Args:
program: The ``moderngl.Program``
Keyword Args:
mode: Override the draw mode (``TRIANGLES`` etc)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
|
demosys/opengl/vao.py
|
def render(self, program: moderngl.Program, mode=None, vertices=-1, first=0, instances=1):
"""
Render the VAO.
Args:
program: The ``moderngl.Program``
Keyword Args:
mode: Override the draw mode (``TRIANGLES`` etc)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.render(mode, vertices=vertices, first=first, instances=instances)
|
def render(self, program: moderngl.Program, mode=None, vertices=-1, first=0, instances=1):
"""
Render the VAO.
Args:
program: The ``moderngl.Program``
Keyword Args:
mode: Override the draw mode (``TRIANGLES`` etc)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.render(mode, vertices=vertices, first=first, instances=instances)
|
[
"Render",
"the",
"VAO",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L119-L137
|
[
"def",
"render",
"(",
"self",
",",
"program",
":",
"moderngl",
".",
"Program",
",",
"mode",
"=",
"None",
",",
"vertices",
"=",
"-",
"1",
",",
"first",
"=",
"0",
",",
"instances",
"=",
"1",
")",
":",
"vao",
"=",
"self",
".",
"instance",
"(",
"program",
")",
"if",
"mode",
"is",
"None",
":",
"mode",
"=",
"self",
".",
"mode",
"vao",
".",
"render",
"(",
"mode",
",",
"vertices",
"=",
"vertices",
",",
"first",
"=",
"first",
",",
"instances",
"=",
"instances",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.render_indirect
|
The render primitive (mode) must be the same as the input primitive of the GeometryShader.
The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.Buffer`` containing indirect draw commands
Keyword Args:
mode (int): By default :py:data:`TRIANGLES` will be used.
count (int): The number of draws.
first (int): The index of the first indirect draw command.
|
demosys/opengl/vao.py
|
def render_indirect(self, program: moderngl.Program, buffer, mode=None, count=-1, *, first=0):
"""
The render primitive (mode) must be the same as the input primitive of the GeometryShader.
The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.Buffer`` containing indirect draw commands
Keyword Args:
mode (int): By default :py:data:`TRIANGLES` will be used.
count (int): The number of draws.
first (int): The index of the first indirect draw command.
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.render_indirect(buffer, mode=mode, count=count, first=first)
|
def render_indirect(self, program: moderngl.Program, buffer, mode=None, count=-1, *, first=0):
"""
The render primitive (mode) must be the same as the input primitive of the GeometryShader.
The draw commands are 5 integers: (count, instanceCount, firstIndex, baseVertex, baseInstance).
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.Buffer`` containing indirect draw commands
Keyword Args:
mode (int): By default :py:data:`TRIANGLES` will be used.
count (int): The number of draws.
first (int): The index of the first indirect draw command.
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.render_indirect(buffer, mode=mode, count=count, first=first)
|
[
"The",
"render",
"primitive",
"(",
"mode",
")",
"must",
"be",
"the",
"same",
"as",
"the",
"input",
"primitive",
"of",
"the",
"GeometryShader",
".",
"The",
"draw",
"commands",
"are",
"5",
"integers",
":",
"(",
"count",
"instanceCount",
"firstIndex",
"baseVertex",
"baseInstance",
")",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L139-L158
|
[
"def",
"render_indirect",
"(",
"self",
",",
"program",
":",
"moderngl",
".",
"Program",
",",
"buffer",
",",
"mode",
"=",
"None",
",",
"count",
"=",
"-",
"1",
",",
"*",
",",
"first",
"=",
"0",
")",
":",
"vao",
"=",
"self",
".",
"instance",
"(",
"program",
")",
"if",
"mode",
"is",
"None",
":",
"mode",
"=",
"self",
".",
"mode",
"vao",
".",
"render_indirect",
"(",
"buffer",
",",
"mode",
"=",
"mode",
",",
"count",
"=",
"count",
",",
"first",
"=",
"first",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.transform
|
Transform vertices. Stores the output in a single buffer.
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.buffer`` to store the output
Keyword Args:
mode: Draw mode (for example ``moderngl.POINTS``)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
|
demosys/opengl/vao.py
|
def transform(self, program: moderngl.Program, buffer: moderngl.Buffer,
mode=None, vertices=-1, first=0, instances=1):
"""
Transform vertices. Stores the output in a single buffer.
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.buffer`` to store the output
Keyword Args:
mode: Draw mode (for example ``moderngl.POINTS``)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.transform(buffer, mode=mode, vertices=vertices, first=first, instances=instances)
|
def transform(self, program: moderngl.Program, buffer: moderngl.Buffer,
mode=None, vertices=-1, first=0, instances=1):
"""
Transform vertices. Stores the output in a single buffer.
Args:
program: The ``moderngl.Program``
buffer: The ``moderngl.buffer`` to store the output
Keyword Args:
mode: Draw mode (for example ``moderngl.POINTS``)
vertices (int): The number of vertices to transform
first (int): The index of the first vertex to start with
instances (int): The number of instances
"""
vao = self.instance(program)
if mode is None:
mode = self.mode
vao.transform(buffer, mode=mode, vertices=vertices, first=first, instances=instances)
|
[
"Transform",
"vertices",
".",
"Stores",
"the",
"output",
"in",
"a",
"single",
"buffer",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L160-L180
|
[
"def",
"transform",
"(",
"self",
",",
"program",
":",
"moderngl",
".",
"Program",
",",
"buffer",
":",
"moderngl",
".",
"Buffer",
",",
"mode",
"=",
"None",
",",
"vertices",
"=",
"-",
"1",
",",
"first",
"=",
"0",
",",
"instances",
"=",
"1",
")",
":",
"vao",
"=",
"self",
".",
"instance",
"(",
"program",
")",
"if",
"mode",
"is",
"None",
":",
"mode",
"=",
"self",
".",
"mode",
"vao",
".",
"transform",
"(",
"buffer",
",",
"mode",
"=",
"mode",
",",
"vertices",
"=",
"vertices",
",",
"first",
"=",
"first",
",",
"instances",
"=",
"instances",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.buffer
|
Register a buffer/vbo for the VAO. This can be called multiple times.
adding multiple buffers (interleaved or not)
Args:
buffer: The buffer data. Can be ``numpy.array``, ``moderngl.Buffer`` or ``bytes``.
buffer_format (str): The format of the buffer. (eg. ``3f 3f`` for interleaved positions and normals).
attribute_names: A list of attribute names this buffer should map to.
Keyword Args:
per_instance (bool): Is this buffer per instance data for instanced rendering?
Returns:
The ``moderngl.Buffer`` instance object. This is handy when providing ``bytes`` and ``numpy.array``.
|
demosys/opengl/vao.py
|
def buffer(self, buffer, buffer_format: str, attribute_names, per_instance=False):
"""
Register a buffer/vbo for the VAO. This can be called multiple times.
adding multiple buffers (interleaved or not)
Args:
buffer: The buffer data. Can be ``numpy.array``, ``moderngl.Buffer`` or ``bytes``.
buffer_format (str): The format of the buffer. (eg. ``3f 3f`` for interleaved positions and normals).
attribute_names: A list of attribute names this buffer should map to.
Keyword Args:
per_instance (bool): Is this buffer per instance data for instanced rendering?
Returns:
The ``moderngl.Buffer`` instance object. This is handy when providing ``bytes`` and ``numpy.array``.
"""
if not isinstance(attribute_names, list):
attribute_names = [attribute_names, ]
if not type(buffer) in [moderngl.Buffer, numpy.ndarray, bytes]:
raise VAOError(
(
"buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance"
"(not {})".format(type(buffer))
)
)
if isinstance(buffer, numpy.ndarray):
buffer = self.ctx.buffer(buffer.tobytes())
if isinstance(buffer, bytes):
buffer = self.ctx.buffer(data=buffer)
formats = buffer_format.split()
if len(formats) != len(attribute_names):
raise VAOError("Format '{}' does not describe attributes {}".format(buffer_format, attribute_names))
self.buffers.append(BufferInfo(buffer, buffer_format, attribute_names, per_instance=per_instance))
self.vertex_count = self.buffers[-1].vertices
return buffer
|
def buffer(self, buffer, buffer_format: str, attribute_names, per_instance=False):
"""
Register a buffer/vbo for the VAO. This can be called multiple times.
adding multiple buffers (interleaved or not)
Args:
buffer: The buffer data. Can be ``numpy.array``, ``moderngl.Buffer`` or ``bytes``.
buffer_format (str): The format of the buffer. (eg. ``3f 3f`` for interleaved positions and normals).
attribute_names: A list of attribute names this buffer should map to.
Keyword Args:
per_instance (bool): Is this buffer per instance data for instanced rendering?
Returns:
The ``moderngl.Buffer`` instance object. This is handy when providing ``bytes`` and ``numpy.array``.
"""
if not isinstance(attribute_names, list):
attribute_names = [attribute_names, ]
if not type(buffer) in [moderngl.Buffer, numpy.ndarray, bytes]:
raise VAOError(
(
"buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance"
"(not {})".format(type(buffer))
)
)
if isinstance(buffer, numpy.ndarray):
buffer = self.ctx.buffer(buffer.tobytes())
if isinstance(buffer, bytes):
buffer = self.ctx.buffer(data=buffer)
formats = buffer_format.split()
if len(formats) != len(attribute_names):
raise VAOError("Format '{}' does not describe attributes {}".format(buffer_format, attribute_names))
self.buffers.append(BufferInfo(buffer, buffer_format, attribute_names, per_instance=per_instance))
self.vertex_count = self.buffers[-1].vertices
return buffer
|
[
"Register",
"a",
"buffer",
"/",
"vbo",
"for",
"the",
"VAO",
".",
"This",
"can",
"be",
"called",
"multiple",
"times",
".",
"adding",
"multiple",
"buffers",
"(",
"interleaved",
"or",
"not",
")"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L182-L222
|
[
"def",
"buffer",
"(",
"self",
",",
"buffer",
",",
"buffer_format",
":",
"str",
",",
"attribute_names",
",",
"per_instance",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"attribute_names",
",",
"list",
")",
":",
"attribute_names",
"=",
"[",
"attribute_names",
",",
"]",
"if",
"not",
"type",
"(",
"buffer",
")",
"in",
"[",
"moderngl",
".",
"Buffer",
",",
"numpy",
".",
"ndarray",
",",
"bytes",
"]",
":",
"raise",
"VAOError",
"(",
"(",
"\"buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance\"",
"\"(not {})\"",
".",
"format",
"(",
"type",
"(",
"buffer",
")",
")",
")",
")",
"if",
"isinstance",
"(",
"buffer",
",",
"numpy",
".",
"ndarray",
")",
":",
"buffer",
"=",
"self",
".",
"ctx",
".",
"buffer",
"(",
"buffer",
".",
"tobytes",
"(",
")",
")",
"if",
"isinstance",
"(",
"buffer",
",",
"bytes",
")",
":",
"buffer",
"=",
"self",
".",
"ctx",
".",
"buffer",
"(",
"data",
"=",
"buffer",
")",
"formats",
"=",
"buffer_format",
".",
"split",
"(",
")",
"if",
"len",
"(",
"formats",
")",
"!=",
"len",
"(",
"attribute_names",
")",
":",
"raise",
"VAOError",
"(",
"\"Format '{}' does not describe attributes {}\"",
".",
"format",
"(",
"buffer_format",
",",
"attribute_names",
")",
")",
"self",
".",
"buffers",
".",
"append",
"(",
"BufferInfo",
"(",
"buffer",
",",
"buffer_format",
",",
"attribute_names",
",",
"per_instance",
"=",
"per_instance",
")",
")",
"self",
".",
"vertex_count",
"=",
"self",
".",
"buffers",
"[",
"-",
"1",
"]",
".",
"vertices",
"return",
"buffer"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.index_buffer
|
Set the index buffer for this VAO
Args:
buffer: ``moderngl.Buffer``, ``numpy.array`` or ``bytes``
Keyword Args:
index_element_size (int): Byte size of each element. 1, 2 or 4
|
demosys/opengl/vao.py
|
def index_buffer(self, buffer, index_element_size=4):
"""
Set the index buffer for this VAO
Args:
buffer: ``moderngl.Buffer``, ``numpy.array`` or ``bytes``
Keyword Args:
index_element_size (int): Byte size of each element. 1, 2 or 4
"""
if not type(buffer) in [moderngl.Buffer, numpy.ndarray, bytes]:
raise VAOError("buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance")
if isinstance(buffer, numpy.ndarray):
buffer = self.ctx.buffer(buffer.tobytes())
if isinstance(buffer, bytes):
buffer = self.ctx.buffer(data=buffer)
self._index_buffer = buffer
self._index_element_size = index_element_size
|
def index_buffer(self, buffer, index_element_size=4):
"""
Set the index buffer for this VAO
Args:
buffer: ``moderngl.Buffer``, ``numpy.array`` or ``bytes``
Keyword Args:
index_element_size (int): Byte size of each element. 1, 2 or 4
"""
if not type(buffer) in [moderngl.Buffer, numpy.ndarray, bytes]:
raise VAOError("buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance")
if isinstance(buffer, numpy.ndarray):
buffer = self.ctx.buffer(buffer.tobytes())
if isinstance(buffer, bytes):
buffer = self.ctx.buffer(data=buffer)
self._index_buffer = buffer
self._index_element_size = index_element_size
|
[
"Set",
"the",
"index",
"buffer",
"for",
"this",
"VAO"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L224-L244
|
[
"def",
"index_buffer",
"(",
"self",
",",
"buffer",
",",
"index_element_size",
"=",
"4",
")",
":",
"if",
"not",
"type",
"(",
"buffer",
")",
"in",
"[",
"moderngl",
".",
"Buffer",
",",
"numpy",
".",
"ndarray",
",",
"bytes",
"]",
":",
"raise",
"VAOError",
"(",
"\"buffer parameter must be a moderngl.Buffer, numpy.ndarray or bytes instance\"",
")",
"if",
"isinstance",
"(",
"buffer",
",",
"numpy",
".",
"ndarray",
")",
":",
"buffer",
"=",
"self",
".",
"ctx",
".",
"buffer",
"(",
"buffer",
".",
"tobytes",
"(",
")",
")",
"if",
"isinstance",
"(",
"buffer",
",",
"bytes",
")",
":",
"buffer",
"=",
"self",
".",
"ctx",
".",
"buffer",
"(",
"data",
"=",
"buffer",
")",
"self",
".",
"_index_buffer",
"=",
"buffer",
"self",
".",
"_index_element_size",
"=",
"index_element_size"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.instance
|
Obtain the ``moderngl.VertexArray`` instance for the program.
The instance is only created once and cached internally.
Returns: ``moderngl.VertexArray`` instance
|
demosys/opengl/vao.py
|
def instance(self, program: moderngl.Program) -> moderngl.VertexArray:
"""
Obtain the ``moderngl.VertexArray`` instance for the program.
The instance is only created once and cached internally.
Returns: ``moderngl.VertexArray`` instance
"""
vao = self.vaos.get(program.glo)
if vao:
return vao
program_attributes = [name for name, attr in program._members.items() if isinstance(attr, moderngl.Attribute)]
# Make sure all attributes are covered
for attrib_name in program_attributes:
# Ignore built in attributes for now
if attrib_name.startswith('gl_'):
continue
# Do we have a buffer mapping to this attribute?
if not sum(buffer.has_attribute(attrib_name) for buffer in self.buffers):
raise VAOError("VAO {} doesn't have attribute {} for program {}".format(
self.name, attrib_name, program.name))
vao_content = []
# Pick out the attributes we can actually map
for buffer in self.buffers:
content = buffer.content(program_attributes)
if content:
vao_content.append(content)
# Any attribute left is not accounted for
if program_attributes:
for attrib_name in program_attributes:
if attrib_name.startswith('gl_'):
continue
raise VAOError("Did not find a buffer mapping for {}".format([n for n in program_attributes]))
# Create the vao
if self._index_buffer:
vao = context.ctx().vertex_array(program, vao_content,
self._index_buffer, self._index_element_size)
else:
vao = context.ctx().vertex_array(program, vao_content)
self.vaos[program.glo] = vao
return vao
|
def instance(self, program: moderngl.Program) -> moderngl.VertexArray:
"""
Obtain the ``moderngl.VertexArray`` instance for the program.
The instance is only created once and cached internally.
Returns: ``moderngl.VertexArray`` instance
"""
vao = self.vaos.get(program.glo)
if vao:
return vao
program_attributes = [name for name, attr in program._members.items() if isinstance(attr, moderngl.Attribute)]
# Make sure all attributes are covered
for attrib_name in program_attributes:
# Ignore built in attributes for now
if attrib_name.startswith('gl_'):
continue
# Do we have a buffer mapping to this attribute?
if not sum(buffer.has_attribute(attrib_name) for buffer in self.buffers):
raise VAOError("VAO {} doesn't have attribute {} for program {}".format(
self.name, attrib_name, program.name))
vao_content = []
# Pick out the attributes we can actually map
for buffer in self.buffers:
content = buffer.content(program_attributes)
if content:
vao_content.append(content)
# Any attribute left is not accounted for
if program_attributes:
for attrib_name in program_attributes:
if attrib_name.startswith('gl_'):
continue
raise VAOError("Did not find a buffer mapping for {}".format([n for n in program_attributes]))
# Create the vao
if self._index_buffer:
vao = context.ctx().vertex_array(program, vao_content,
self._index_buffer, self._index_element_size)
else:
vao = context.ctx().vertex_array(program, vao_content)
self.vaos[program.glo] = vao
return vao
|
[
"Obtain",
"the",
"moderngl",
".",
"VertexArray",
"instance",
"for",
"the",
"program",
".",
"The",
"instance",
"is",
"only",
"created",
"once",
"and",
"cached",
"internally",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L246-L294
|
[
"def",
"instance",
"(",
"self",
",",
"program",
":",
"moderngl",
".",
"Program",
")",
"->",
"moderngl",
".",
"VertexArray",
":",
"vao",
"=",
"self",
".",
"vaos",
".",
"get",
"(",
"program",
".",
"glo",
")",
"if",
"vao",
":",
"return",
"vao",
"program_attributes",
"=",
"[",
"name",
"for",
"name",
",",
"attr",
"in",
"program",
".",
"_members",
".",
"items",
"(",
")",
"if",
"isinstance",
"(",
"attr",
",",
"moderngl",
".",
"Attribute",
")",
"]",
"# Make sure all attributes are covered",
"for",
"attrib_name",
"in",
"program_attributes",
":",
"# Ignore built in attributes for now",
"if",
"attrib_name",
".",
"startswith",
"(",
"'gl_'",
")",
":",
"continue",
"# Do we have a buffer mapping to this attribute?",
"if",
"not",
"sum",
"(",
"buffer",
".",
"has_attribute",
"(",
"attrib_name",
")",
"for",
"buffer",
"in",
"self",
".",
"buffers",
")",
":",
"raise",
"VAOError",
"(",
"\"VAO {} doesn't have attribute {} for program {}\"",
".",
"format",
"(",
"self",
".",
"name",
",",
"attrib_name",
",",
"program",
".",
"name",
")",
")",
"vao_content",
"=",
"[",
"]",
"# Pick out the attributes we can actually map",
"for",
"buffer",
"in",
"self",
".",
"buffers",
":",
"content",
"=",
"buffer",
".",
"content",
"(",
"program_attributes",
")",
"if",
"content",
":",
"vao_content",
".",
"append",
"(",
"content",
")",
"# Any attribute left is not accounted for",
"if",
"program_attributes",
":",
"for",
"attrib_name",
"in",
"program_attributes",
":",
"if",
"attrib_name",
".",
"startswith",
"(",
"'gl_'",
")",
":",
"continue",
"raise",
"VAOError",
"(",
"\"Did not find a buffer mapping for {}\"",
".",
"format",
"(",
"[",
"n",
"for",
"n",
"in",
"program_attributes",
"]",
")",
")",
"# Create the vao",
"if",
"self",
".",
"_index_buffer",
":",
"vao",
"=",
"context",
".",
"ctx",
"(",
")",
".",
"vertex_array",
"(",
"program",
",",
"vao_content",
",",
"self",
".",
"_index_buffer",
",",
"self",
".",
"_index_element_size",
")",
"else",
":",
"vao",
"=",
"context",
".",
"ctx",
"(",
")",
".",
"vertex_array",
"(",
"program",
",",
"vao_content",
")",
"self",
".",
"vaos",
"[",
"program",
".",
"glo",
"]",
"=",
"vao",
"return",
"vao"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
VAO.release
|
Destroy the vao object
Keyword Args:
buffers (bool): also release buffers
|
demosys/opengl/vao.py
|
def release(self, buffer=True):
"""
Destroy the vao object
Keyword Args:
buffers (bool): also release buffers
"""
for key, vao in self.vaos:
vao.release()
if buffer:
for buff in self.buffers:
buff.buffer.release()
if self._index_buffer:
self._index_buffer.release()
|
def release(self, buffer=True):
"""
Destroy the vao object
Keyword Args:
buffers (bool): also release buffers
"""
for key, vao in self.vaos:
vao.release()
if buffer:
for buff in self.buffers:
buff.buffer.release()
if self._index_buffer:
self._index_buffer.release()
|
[
"Destroy",
"the",
"vao",
"object"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/vao.py#L296-L311
|
[
"def",
"release",
"(",
"self",
",",
"buffer",
"=",
"True",
")",
":",
"for",
"key",
",",
"vao",
"in",
"self",
".",
"vaos",
":",
"vao",
".",
"release",
"(",
")",
"if",
"buffer",
":",
"for",
"buff",
"in",
"self",
".",
"buffers",
":",
"buff",
".",
"buffer",
".",
"release",
"(",
")",
"if",
"self",
".",
"_index_buffer",
":",
"self",
".",
"_index_buffer",
".",
"release",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
cube
|
Creates a cube VAO with normals and texture coordinates
Args:
width (float): Width of the cube
height (float): Height of the cube
depth (float): Depth of the cube
Keyword Args:
center: center of the cube as a 3-component tuple
normals: (bool) Include normals
uvs: (bool) include uv coordinates
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
|
demosys/geometry/cube.py
|
def cube(width, height, depth, center=(0.0, 0.0, 0.0), normals=True, uvs=True) -> VAO:
"""
Creates a cube VAO with normals and texture coordinates
Args:
width (float): Width of the cube
height (float): Height of the cube
depth (float): Depth of the cube
Keyword Args:
center: center of the cube as a 3-component tuple
normals: (bool) Include normals
uvs: (bool) include uv coordinates
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
width, height, depth = width / 2.0, height / 2.0, depth / 2.0
pos = numpy.array([
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
], dtype=numpy.float32)
if normals:
normal_data = numpy.array([
-0, 0, 1,
-0, 0, 1,
-0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
], dtype=numpy.float32)
if uvs:
uvs_data = numpy.array([
1, 0,
1, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 1,
0, 0,
1, 0,
0, 1,
0, 0,
1, 0,
0, 1,
1, 0,
1, 1,
1, 0,
1, 1,
0, 1,
1, 0,
0, 1,
0, 0,
1, 1,
0, 1,
1, 0,
0, 1,
0, 0,
1, 0
], dtype=numpy.float32)
vao = VAO("geometry:cube")
# Add buffers
vao.buffer(pos, '3f', ['in_position'])
if normals:
vao.buffer(normal_data, '3f', ['in_normal'])
if uvs:
vao.buffer(uvs_data, '2f', ['in_uv'])
return vao
|
def cube(width, height, depth, center=(0.0, 0.0, 0.0), normals=True, uvs=True) -> VAO:
"""
Creates a cube VAO with normals and texture coordinates
Args:
width (float): Width of the cube
height (float): Height of the cube
depth (float): Depth of the cube
Keyword Args:
center: center of the cube as a 3-component tuple
normals: (bool) Include normals
uvs: (bool) include uv coordinates
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
width, height, depth = width / 2.0, height / 2.0, depth / 2.0
pos = numpy.array([
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] + width, center[1] - height, center[2] + depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] + width, center[1] - height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] - width, center[1] - height, center[2] - depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] - depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] + width, center[1] + height, center[2] + depth,
center[0] - width, center[1] + height, center[2] - depth,
center[0] - width, center[1] + height, center[2] + depth,
center[0] + width, center[1] + height, center[2] + depth,
], dtype=numpy.float32)
if normals:
normal_data = numpy.array([
-0, 0, 1,
-0, 0, 1,
-0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
1, 0, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
0, -1, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
-1, -0, 0,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 0, -1,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
], dtype=numpy.float32)
if uvs:
uvs_data = numpy.array([
1, 0,
1, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 1,
0, 1,
0, 0,
1, 1,
0, 0,
1, 0,
0, 1,
0, 0,
1, 0,
0, 1,
1, 0,
1, 1,
1, 0,
1, 1,
0, 1,
1, 0,
0, 1,
0, 0,
1, 1,
0, 1,
1, 0,
0, 1,
0, 0,
1, 0
], dtype=numpy.float32)
vao = VAO("geometry:cube")
# Add buffers
vao.buffer(pos, '3f', ['in_position'])
if normals:
vao.buffer(normal_data, '3f', ['in_normal'])
if uvs:
vao.buffer(uvs_data, '2f', ['in_uv'])
return vao
|
[
"Creates",
"a",
"cube",
"VAO",
"with",
"normals",
"and",
"texture",
"coordinates"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/geometry/cube.py#L6-L153
|
[
"def",
"cube",
"(",
"width",
",",
"height",
",",
"depth",
",",
"center",
"=",
"(",
"0.0",
",",
"0.0",
",",
"0.0",
")",
",",
"normals",
"=",
"True",
",",
"uvs",
"=",
"True",
")",
"->",
"VAO",
":",
"width",
",",
"height",
",",
"depth",
"=",
"width",
"/",
"2.0",
",",
"height",
"/",
"2.0",
",",
"depth",
"/",
"2.0",
"pos",
"=",
"numpy",
".",
"array",
"(",
"[",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"-",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"-",
"depth",
",",
"center",
"[",
"0",
"]",
"-",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"center",
"[",
"0",
"]",
"+",
"width",
",",
"center",
"[",
"1",
"]",
"+",
"height",
",",
"center",
"[",
"2",
"]",
"+",
"depth",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"if",
"normals",
":",
"normal_data",
"=",
"numpy",
".",
"array",
"(",
"[",
"-",
"0",
",",
"0",
",",
"1",
",",
"-",
"0",
",",
"0",
",",
"1",
",",
"-",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"if",
"uvs",
":",
"uvs_data",
"=",
"numpy",
".",
"array",
"(",
"[",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vao",
"=",
"VAO",
"(",
"\"geometry:cube\"",
")",
"# Add buffers",
"vao",
".",
"buffer",
"(",
"pos",
",",
"'3f'",
",",
"[",
"'in_position'",
"]",
")",
"if",
"normals",
":",
"vao",
".",
"buffer",
"(",
"normal_data",
",",
"'3f'",
",",
"[",
"'in_normal'",
"]",
")",
"if",
"uvs",
":",
"vao",
".",
"buffer",
"(",
"uvs_data",
",",
"'2f'",
",",
"[",
"'in_uv'",
"]",
")",
"return",
"vao"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
MeshProgram.draw
|
Draw code for the mesh. Should be overriden.
:param projection_matrix: projection_matrix (bytes)
:param view_matrix: view_matrix (bytes)
:param camera_matrix: camera_matrix (bytes)
:param time: The current time
|
demosys/scene/programs.py
|
def draw(self, mesh, projection_matrix=None, view_matrix=None, camera_matrix=None, time=0):
"""
Draw code for the mesh. Should be overriden.
:param projection_matrix: projection_matrix (bytes)
:param view_matrix: view_matrix (bytes)
:param camera_matrix: camera_matrix (bytes)
:param time: The current time
"""
self.program["m_proj"].write(projection_matrix)
self.program["m_mv"].write(view_matrix)
mesh.vao.render(self.program)
|
def draw(self, mesh, projection_matrix=None, view_matrix=None, camera_matrix=None, time=0):
"""
Draw code for the mesh. Should be overriden.
:param projection_matrix: projection_matrix (bytes)
:param view_matrix: view_matrix (bytes)
:param camera_matrix: camera_matrix (bytes)
:param time: The current time
"""
self.program["m_proj"].write(projection_matrix)
self.program["m_mv"].write(view_matrix)
mesh.vao.render(self.program)
|
[
"Draw",
"code",
"for",
"the",
"mesh",
".",
"Should",
"be",
"overriden",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/scene/programs.py#L17-L28
|
[
"def",
"draw",
"(",
"self",
",",
"mesh",
",",
"projection_matrix",
"=",
"None",
",",
"view_matrix",
"=",
"None",
",",
"camera_matrix",
"=",
"None",
",",
"time",
"=",
"0",
")",
":",
"self",
".",
"program",
"[",
"\"m_proj\"",
"]",
".",
"write",
"(",
"projection_matrix",
")",
"self",
".",
"program",
"[",
"\"m_mv\"",
"]",
".",
"write",
"(",
"view_matrix",
")",
"mesh",
".",
"vao",
".",
"render",
"(",
"self",
".",
"program",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.pause
|
Pause the music
|
demosys/timers/vlc.py
|
def pause(self):
"""Pause the music"""
self.pause_time = self.get_time()
self.paused = True
self.player.pause()
|
def pause(self):
"""Pause the music"""
self.pause_time = self.get_time()
self.paused = True
self.player.pause()
|
[
"Pause",
"the",
"music"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/vlc.py#L30-L34
|
[
"def",
"pause",
"(",
"self",
")",
":",
"self",
".",
"pause_time",
"=",
"self",
".",
"get_time",
"(",
")",
"self",
".",
"paused",
"=",
"True",
"self",
".",
"player",
".",
"pause",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timer.get_time
|
Get the current time in seconds
Returns:
The current time in seconds
|
demosys/timers/vlc.py
|
def get_time(self) -> float:
"""
Get the current time in seconds
Returns:
The current time in seconds
"""
if self.paused:
return self.pause_time
return self.player.get_time() / 1000.0
|
def get_time(self) -> float:
"""
Get the current time in seconds
Returns:
The current time in seconds
"""
if self.paused:
return self.pause_time
return self.player.get_time() / 1000.0
|
[
"Get",
"the",
"current",
"time",
"in",
"seconds"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timers/vlc.py#L53-L63
|
[
"def",
"get_time",
"(",
"self",
")",
"->",
"float",
":",
"if",
"self",
".",
"paused",
":",
"return",
"self",
".",
"pause_time",
"return",
"self",
".",
"player",
".",
"get_time",
"(",
")",
"/",
"1000.0"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
parse_package_string
|
Parse the effect package string.
Can contain the package python path or path to effect class in an effect package.
Examples::
# Path to effect pacakge
examples.cubes
# Path to effect class
examples.cubes.Cubes
Args:
path: python path to effect package. May also include effect class name.
Returns:
tuple: (package_path, effect_class)
|
demosys/effects/registry.py
|
def parse_package_string(path):
"""
Parse the effect package string.
Can contain the package python path or path to effect class in an effect package.
Examples::
# Path to effect pacakge
examples.cubes
# Path to effect class
examples.cubes.Cubes
Args:
path: python path to effect package. May also include effect class name.
Returns:
tuple: (package_path, effect_class)
"""
parts = path.split('.')
# Is the last entry in the path capitalized?
if parts[-1][0].isupper():
return ".".join(parts[:-1]), parts[-1]
return path, ""
|
def parse_package_string(path):
"""
Parse the effect package string.
Can contain the package python path or path to effect class in an effect package.
Examples::
# Path to effect pacakge
examples.cubes
# Path to effect class
examples.cubes.Cubes
Args:
path: python path to effect package. May also include effect class name.
Returns:
tuple: (package_path, effect_class)
"""
parts = path.split('.')
# Is the last entry in the path capitalized?
if parts[-1][0].isupper():
return ".".join(parts[:-1]), parts[-1]
return path, ""
|
[
"Parse",
"the",
"effect",
"package",
"string",
".",
"Can",
"contain",
"the",
"package",
"python",
"path",
"or",
"path",
"to",
"effect",
"class",
"in",
"an",
"effect",
"package",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L9-L34
|
[
"def",
"parse_package_string",
"(",
"path",
")",
":",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
"# Is the last entry in the path capitalized?",
"if",
"parts",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
".",
"isupper",
"(",
")",
":",
"return",
"\".\"",
".",
"join",
"(",
"parts",
"[",
":",
"-",
"1",
"]",
")",
",",
"parts",
"[",
"-",
"1",
"]",
"return",
"path",
",",
"\"\""
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectRegistry.get_dirs
|
Get all effect directories for registered effects.
|
demosys/effects/registry.py
|
def get_dirs(self) -> List[str]:
"""
Get all effect directories for registered effects.
"""
for package in self.packages:
yield os.path.join(package.path, 'resources')
|
def get_dirs(self) -> List[str]:
"""
Get all effect directories for registered effects.
"""
for package in self.packages:
yield os.path.join(package.path, 'resources')
|
[
"Get",
"all",
"effect",
"directories",
"for",
"registered",
"effects",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L49-L54
|
[
"def",
"get_dirs",
"(",
"self",
")",
"->",
"List",
"[",
"str",
"]",
":",
"for",
"package",
"in",
"self",
".",
"packages",
":",
"yield",
"os",
".",
"path",
".",
"join",
"(",
"package",
".",
"path",
",",
"'resources'",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectRegistry.get_effect_resources
|
Get all resources registed in effect packages.
These are typically located in ``resources.py``
|
demosys/effects/registry.py
|
def get_effect_resources(self) -> List[Any]:
"""
Get all resources registed in effect packages.
These are typically located in ``resources.py``
"""
resources = []
for package in self.packages:
resources.extend(package.resources)
return resources
|
def get_effect_resources(self) -> List[Any]:
"""
Get all resources registed in effect packages.
These are typically located in ``resources.py``
"""
resources = []
for package in self.packages:
resources.extend(package.resources)
return resources
|
[
"Get",
"all",
"resources",
"registed",
"in",
"effect",
"packages",
".",
"These",
"are",
"typically",
"located",
"in",
"resources",
".",
"py"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L56-L65
|
[
"def",
"get_effect_resources",
"(",
"self",
")",
"->",
"List",
"[",
"Any",
"]",
":",
"resources",
"=",
"[",
"]",
"for",
"package",
"in",
"self",
".",
"packages",
":",
"resources",
".",
"extend",
"(",
"package",
".",
"resources",
")",
"return",
"resources"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectRegistry.add_package
|
Registers a single package
:param name: (str) The effect package to add
|
demosys/effects/registry.py
|
def add_package(self, name):
"""
Registers a single package
:param name: (str) The effect package to add
"""
name, cls_name = parse_package_string(name)
if name in self.package_map:
return
package = EffectPackage(name)
package.load()
self.packages.append(package)
self.package_map[package.name] = package
# Load effect package dependencies
self.polulate(package.effect_packages)
|
def add_package(self, name):
"""
Registers a single package
:param name: (str) The effect package to add
"""
name, cls_name = parse_package_string(name)
if name in self.package_map:
return
package = EffectPackage(name)
package.load()
self.packages.append(package)
self.package_map[package.name] = package
# Load effect package dependencies
self.polulate(package.effect_packages)
|
[
"Registers",
"a",
"single",
"package"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L76-L94
|
[
"def",
"add_package",
"(",
"self",
",",
"name",
")",
":",
"name",
",",
"cls_name",
"=",
"parse_package_string",
"(",
"name",
")",
"if",
"name",
"in",
"self",
".",
"package_map",
":",
"return",
"package",
"=",
"EffectPackage",
"(",
"name",
")",
"package",
".",
"load",
"(",
")",
"self",
".",
"packages",
".",
"append",
"(",
"package",
")",
"self",
".",
"package_map",
"[",
"package",
".",
"name",
"]",
"=",
"package",
"# Load effect package dependencies",
"self",
".",
"polulate",
"(",
"package",
".",
"effect_packages",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectRegistry.get_package
|
Get a package by python path. Can also contain path to an effect.
Args:
name (str): Path to effect package or effect
Returns:
The requested EffectPackage
Raises:
EffectError when no package is found
|
demosys/effects/registry.py
|
def get_package(self, name) -> 'EffectPackage':
"""
Get a package by python path. Can also contain path to an effect.
Args:
name (str): Path to effect package or effect
Returns:
The requested EffectPackage
Raises:
EffectError when no package is found
"""
name, cls_name = parse_package_string(name)
try:
return self.package_map[name]
except KeyError:
raise EffectError("No package '{}' registered".format(name))
|
def get_package(self, name) -> 'EffectPackage':
"""
Get a package by python path. Can also contain path to an effect.
Args:
name (str): Path to effect package or effect
Returns:
The requested EffectPackage
Raises:
EffectError when no package is found
"""
name, cls_name = parse_package_string(name)
try:
return self.package_map[name]
except KeyError:
raise EffectError("No package '{}' registered".format(name))
|
[
"Get",
"a",
"package",
"by",
"python",
"path",
".",
"Can",
"also",
"contain",
"path",
"to",
"an",
"effect",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L96-L114
|
[
"def",
"get_package",
"(",
"self",
",",
"name",
")",
"->",
"'EffectPackage'",
":",
"name",
",",
"cls_name",
"=",
"parse_package_string",
"(",
"name",
")",
"try",
":",
"return",
"self",
".",
"package_map",
"[",
"name",
"]",
"except",
"KeyError",
":",
"raise",
"EffectError",
"(",
"\"No package '{}' registered\"",
".",
"format",
"(",
"name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectRegistry.find_effect_class
|
Find an effect class by class name or full python path to class
Args:
path (str): effect class name or full python path to effect class
Returns:
Effect class
Raises:
EffectError if no class is found
|
demosys/effects/registry.py
|
def find_effect_class(self, path) -> Type[Effect]:
"""
Find an effect class by class name or full python path to class
Args:
path (str): effect class name or full python path to effect class
Returns:
Effect class
Raises:
EffectError if no class is found
"""
package_name, class_name = parse_package_string(path)
if package_name:
package = self.get_package(package_name)
return package.find_effect_class(class_name, raise_for_error=True)
for package in self.packages:
effect_cls = package.find_effect_class(class_name)
if effect_cls:
return effect_cls
raise EffectError("No effect class '{}' found in any packages".format(class_name))
|
def find_effect_class(self, path) -> Type[Effect]:
"""
Find an effect class by class name or full python path to class
Args:
path (str): effect class name or full python path to effect class
Returns:
Effect class
Raises:
EffectError if no class is found
"""
package_name, class_name = parse_package_string(path)
if package_name:
package = self.get_package(package_name)
return package.find_effect_class(class_name, raise_for_error=True)
for package in self.packages:
effect_cls = package.find_effect_class(class_name)
if effect_cls:
return effect_cls
raise EffectError("No effect class '{}' found in any packages".format(class_name))
|
[
"Find",
"an",
"effect",
"class",
"by",
"class",
"name",
"or",
"full",
"python",
"path",
"to",
"class"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L116-L140
|
[
"def",
"find_effect_class",
"(",
"self",
",",
"path",
")",
"->",
"Type",
"[",
"Effect",
"]",
":",
"package_name",
",",
"class_name",
"=",
"parse_package_string",
"(",
"path",
")",
"if",
"package_name",
":",
"package",
"=",
"self",
".",
"get_package",
"(",
"package_name",
")",
"return",
"package",
".",
"find_effect_class",
"(",
"class_name",
",",
"raise_for_error",
"=",
"True",
")",
"for",
"package",
"in",
"self",
".",
"packages",
":",
"effect_cls",
"=",
"package",
".",
"find_effect_class",
"(",
"class_name",
")",
"if",
"effect_cls",
":",
"return",
"effect_cls",
"raise",
"EffectError",
"(",
"\"No effect class '{}' found in any packages\"",
".",
"format",
"(",
"class_name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectPackage.runnable_effects
|
Returns the runnable effect in the package
|
demosys/effects/registry.py
|
def runnable_effects(self) -> List[Type[Effect]]:
"""Returns the runnable effect in the package"""
return [cls for cls in self.effect_classes if cls.runnable]
|
def runnable_effects(self) -> List[Type[Effect]]:
"""Returns the runnable effect in the package"""
return [cls for cls in self.effect_classes if cls.runnable]
|
[
"Returns",
"the",
"runnable",
"effect",
"in",
"the",
"package"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L158-L160
|
[
"def",
"runnable_effects",
"(",
"self",
")",
"->",
"List",
"[",
"Type",
"[",
"Effect",
"]",
"]",
":",
"return",
"[",
"cls",
"for",
"cls",
"in",
"self",
".",
"effect_classes",
"if",
"cls",
".",
"runnable",
"]"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectPackage.load_package
|
FInd the effect package
|
demosys/effects/registry.py
|
def load_package(self):
"""FInd the effect package"""
try:
self.package = importlib.import_module(self.name)
except ModuleNotFoundError:
raise ModuleNotFoundError("Effect package '{}' not found.".format(self.name))
|
def load_package(self):
"""FInd the effect package"""
try:
self.package = importlib.import_module(self.name)
except ModuleNotFoundError:
raise ModuleNotFoundError("Effect package '{}' not found.".format(self.name))
|
[
"FInd",
"the",
"effect",
"package"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L185-L190
|
[
"def",
"load_package",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"package",
"=",
"importlib",
".",
"import_module",
"(",
"self",
".",
"name",
")",
"except",
"ModuleNotFoundError",
":",
"raise",
"ModuleNotFoundError",
"(",
"\"Effect package '{}' not found.\"",
".",
"format",
"(",
"self",
".",
"name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectPackage.load_effects_classes
|
Iterate the module attributes picking out effects
|
demosys/effects/registry.py
|
def load_effects_classes(self):
"""Iterate the module attributes picking out effects"""
self.effect_classes = []
for _, cls in inspect.getmembers(self.effect_module):
if inspect.isclass(cls):
if cls == Effect:
continue
if issubclass(cls, Effect):
self.effect_classes.append(cls)
self.effect_class_map[cls.__name__] = cls
cls._name = "{}.{}".format(self.effect_module_name, cls.__name__)
|
def load_effects_classes(self):
"""Iterate the module attributes picking out effects"""
self.effect_classes = []
for _, cls in inspect.getmembers(self.effect_module):
if inspect.isclass(cls):
if cls == Effect:
continue
if issubclass(cls, Effect):
self.effect_classes.append(cls)
self.effect_class_map[cls.__name__] = cls
cls._name = "{}.{}".format(self.effect_module_name, cls.__name__)
|
[
"Iterate",
"the",
"module",
"attributes",
"picking",
"out",
"effects"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L205-L217
|
[
"def",
"load_effects_classes",
"(",
"self",
")",
":",
"self",
".",
"effect_classes",
"=",
"[",
"]",
"for",
"_",
",",
"cls",
"in",
"inspect",
".",
"getmembers",
"(",
"self",
".",
"effect_module",
")",
":",
"if",
"inspect",
".",
"isclass",
"(",
"cls",
")",
":",
"if",
"cls",
"==",
"Effect",
":",
"continue",
"if",
"issubclass",
"(",
"cls",
",",
"Effect",
")",
":",
"self",
".",
"effect_classes",
".",
"append",
"(",
"cls",
")",
"self",
".",
"effect_class_map",
"[",
"cls",
".",
"__name__",
"]",
"=",
"cls",
"cls",
".",
"_name",
"=",
"\"{}.{}\"",
".",
"format",
"(",
"self",
".",
"effect_module_name",
",",
"cls",
".",
"__name__",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
EffectPackage.load_resource_module
|
Fetch the resource list
|
demosys/effects/registry.py
|
def load_resource_module(self):
"""Fetch the resource list"""
# Attempt to load the dependencies module
try:
name = '{}.{}'.format(self.name, 'dependencies')
self.dependencies_module = importlib.import_module(name)
except ModuleNotFoundError as err:
raise EffectError(
(
"Effect package '{}' has no 'dependencies' module or the module has errors. "
"Forwarded error from importlib: {}"
).format(self.name, err))
# Fetch the resource descriptions
try:
self.resources = getattr(self.dependencies_module, 'resources')
except AttributeError:
raise EffectError("Effect dependencies module '{}' has no 'resources' attribute".format(name))
if not isinstance(self.resources, list):
raise EffectError(
"Effect dependencies module '{}': 'resources' is of type {} instead of a list".format(
name, type(self.resources)))
# Fetch the effect class list
try:
self.effect_packages = getattr(self.dependencies_module, 'effect_packages')
except AttributeError:
raise EffectError("Effect dependencies module '{}' has 'effect_packages' attribute".format(name))
if not isinstance(self.effect_packages, list):
raise EffectError(
"Effect dependencies module '{}': 'effect_packages' is of type {} instead of a list".format(
name, type(self.effects)))
|
def load_resource_module(self):
"""Fetch the resource list"""
# Attempt to load the dependencies module
try:
name = '{}.{}'.format(self.name, 'dependencies')
self.dependencies_module = importlib.import_module(name)
except ModuleNotFoundError as err:
raise EffectError(
(
"Effect package '{}' has no 'dependencies' module or the module has errors. "
"Forwarded error from importlib: {}"
).format(self.name, err))
# Fetch the resource descriptions
try:
self.resources = getattr(self.dependencies_module, 'resources')
except AttributeError:
raise EffectError("Effect dependencies module '{}' has no 'resources' attribute".format(name))
if not isinstance(self.resources, list):
raise EffectError(
"Effect dependencies module '{}': 'resources' is of type {} instead of a list".format(
name, type(self.resources)))
# Fetch the effect class list
try:
self.effect_packages = getattr(self.dependencies_module, 'effect_packages')
except AttributeError:
raise EffectError("Effect dependencies module '{}' has 'effect_packages' attribute".format(name))
if not isinstance(self.effect_packages, list):
raise EffectError(
"Effect dependencies module '{}': 'effect_packages' is of type {} instead of a list".format(
name, type(self.effects)))
|
[
"Fetch",
"the",
"resource",
"list"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/effects/registry.py#L219-L252
|
[
"def",
"load_resource_module",
"(",
"self",
")",
":",
"# Attempt to load the dependencies module",
"try",
":",
"name",
"=",
"'{}.{}'",
".",
"format",
"(",
"self",
".",
"name",
",",
"'dependencies'",
")",
"self",
".",
"dependencies_module",
"=",
"importlib",
".",
"import_module",
"(",
"name",
")",
"except",
"ModuleNotFoundError",
"as",
"err",
":",
"raise",
"EffectError",
"(",
"(",
"\"Effect package '{}' has no 'dependencies' module or the module has errors. \"",
"\"Forwarded error from importlib: {}\"",
")",
".",
"format",
"(",
"self",
".",
"name",
",",
"err",
")",
")",
"# Fetch the resource descriptions",
"try",
":",
"self",
".",
"resources",
"=",
"getattr",
"(",
"self",
".",
"dependencies_module",
",",
"'resources'",
")",
"except",
"AttributeError",
":",
"raise",
"EffectError",
"(",
"\"Effect dependencies module '{}' has no 'resources' attribute\"",
".",
"format",
"(",
"name",
")",
")",
"if",
"not",
"isinstance",
"(",
"self",
".",
"resources",
",",
"list",
")",
":",
"raise",
"EffectError",
"(",
"\"Effect dependencies module '{}': 'resources' is of type {} instead of a list\"",
".",
"format",
"(",
"name",
",",
"type",
"(",
"self",
".",
"resources",
")",
")",
")",
"# Fetch the effect class list",
"try",
":",
"self",
".",
"effect_packages",
"=",
"getattr",
"(",
"self",
".",
"dependencies_module",
",",
"'effect_packages'",
")",
"except",
"AttributeError",
":",
"raise",
"EffectError",
"(",
"\"Effect dependencies module '{}' has 'effect_packages' attribute\"",
".",
"format",
"(",
"name",
")",
")",
"if",
"not",
"isinstance",
"(",
"self",
".",
"effect_packages",
",",
"list",
")",
":",
"raise",
"EffectError",
"(",
"\"Effect dependencies module '{}': 'effect_packages' is of type {} instead of a list\"",
".",
"format",
"(",
"name",
",",
"type",
"(",
"self",
".",
"effects",
")",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
create
|
Create a screenshot
:param file_format: formats supported by PIL (png, jpeg etc)
|
demosys/view/screenshot.py
|
def create(file_format='png', name=None):
"""
Create a screenshot
:param file_format: formats supported by PIL (png, jpeg etc)
"""
dest = ""
if settings.SCREENSHOT_PATH:
if not os.path.exists(settings.SCREENSHOT_PATH):
print("SCREENSHOT_PATH does not exist. creating: {}".format(settings.SCREENSHOT_PATH))
os.makedirs(settings.SCREENSHOT_PATH)
dest = settings.SCREENSHOT_PATH
else:
print("SCREENSHOT_PATH not defined in settings. Using cwd as fallback.")
if not Config.target:
Config.target = context.window().fbo
image = Image.frombytes(
"RGB",
(Config.target.viewport[2], Config.target.viewport[3]),
Config.target.read(viewport=Config.target.viewport, alignment=Config.alignment),
)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
if not name:
name = "{}.{}".format(datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f"), file_format)
dest = os.path.join(dest, name)
print("Creating screenshot:", dest)
image.save(dest, format=file_format)
|
def create(file_format='png', name=None):
"""
Create a screenshot
:param file_format: formats supported by PIL (png, jpeg etc)
"""
dest = ""
if settings.SCREENSHOT_PATH:
if not os.path.exists(settings.SCREENSHOT_PATH):
print("SCREENSHOT_PATH does not exist. creating: {}".format(settings.SCREENSHOT_PATH))
os.makedirs(settings.SCREENSHOT_PATH)
dest = settings.SCREENSHOT_PATH
else:
print("SCREENSHOT_PATH not defined in settings. Using cwd as fallback.")
if not Config.target:
Config.target = context.window().fbo
image = Image.frombytes(
"RGB",
(Config.target.viewport[2], Config.target.viewport[3]),
Config.target.read(viewport=Config.target.viewport, alignment=Config.alignment),
)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
if not name:
name = "{}.{}".format(datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f"), file_format)
dest = os.path.join(dest, name)
print("Creating screenshot:", dest)
image.save(dest, format=file_format)
|
[
"Create",
"a",
"screenshot",
":",
"param",
"file_format",
":",
"formats",
"supported",
"by",
"PIL",
"(",
"png",
"jpeg",
"etc",
")"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/view/screenshot.py#L16-L45
|
[
"def",
"create",
"(",
"file_format",
"=",
"'png'",
",",
"name",
"=",
"None",
")",
":",
"dest",
"=",
"\"\"",
"if",
"settings",
".",
"SCREENSHOT_PATH",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"settings",
".",
"SCREENSHOT_PATH",
")",
":",
"print",
"(",
"\"SCREENSHOT_PATH does not exist. creating: {}\"",
".",
"format",
"(",
"settings",
".",
"SCREENSHOT_PATH",
")",
")",
"os",
".",
"makedirs",
"(",
"settings",
".",
"SCREENSHOT_PATH",
")",
"dest",
"=",
"settings",
".",
"SCREENSHOT_PATH",
"else",
":",
"print",
"(",
"\"SCREENSHOT_PATH not defined in settings. Using cwd as fallback.\"",
")",
"if",
"not",
"Config",
".",
"target",
":",
"Config",
".",
"target",
"=",
"context",
".",
"window",
"(",
")",
".",
"fbo",
"image",
"=",
"Image",
".",
"frombytes",
"(",
"\"RGB\"",
",",
"(",
"Config",
".",
"target",
".",
"viewport",
"[",
"2",
"]",
",",
"Config",
".",
"target",
".",
"viewport",
"[",
"3",
"]",
")",
",",
"Config",
".",
"target",
".",
"read",
"(",
"viewport",
"=",
"Config",
".",
"target",
".",
"viewport",
",",
"alignment",
"=",
"Config",
".",
"alignment",
")",
",",
")",
"image",
"=",
"image",
".",
"transpose",
"(",
"Image",
".",
"FLIP_TOP_BOTTOM",
")",
"if",
"not",
"name",
":",
"name",
"=",
"\"{}.{}\"",
".",
"format",
"(",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"\"%Y-%m-%d-%H-%M-%S-%f\"",
")",
",",
"file_format",
")",
"dest",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dest",
",",
"name",
")",
"print",
"(",
"\"Creating screenshot:\"",
",",
"dest",
")",
"image",
".",
"save",
"(",
"dest",
",",
"format",
"=",
"file_format",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Timeline.draw
|
Fetch track value for every runnable effect.
If the value is > 0.5 we draw it.
|
demosys/timeline/rocket.py
|
def draw(self, time, frametime, target):
"""
Fetch track value for every runnable effect.
If the value is > 0.5 we draw it.
"""
for effect in self.effects:
value = effect.rocket_timeline_track.time_value(time)
if value > 0.5:
effect.draw(time, frametime, target)
|
def draw(self, time, frametime, target):
"""
Fetch track value for every runnable effect.
If the value is > 0.5 we draw it.
"""
for effect in self.effects:
value = effect.rocket_timeline_track.time_value(time)
if value > 0.5:
effect.draw(time, frametime, target)
|
[
"Fetch",
"track",
"value",
"for",
"every",
"runnable",
"effect",
".",
"If",
"the",
"value",
"is",
">",
"0",
".",
"5",
"we",
"draw",
"it",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/timeline/rocket.py#L28-L36
|
[
"def",
"draw",
"(",
"self",
",",
"time",
",",
"frametime",
",",
"target",
")",
":",
"for",
"effect",
"in",
"self",
".",
"effects",
":",
"value",
"=",
"effect",
".",
"rocket_timeline_track",
".",
"time_value",
"(",
"time",
")",
"if",
"value",
">",
"0.5",
":",
"effect",
".",
"draw",
"(",
"time",
",",
"frametime",
",",
"target",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Loader.load
|
Load a 2d texture
|
demosys/loaders/texture/t2d.py
|
def load(self):
"""Load a 2d texture"""
self._open_image()
components, data = image_data(self.image)
texture = self.ctx.texture(
self.image.size,
components,
data,
)
texture.extra = {'meta': self.meta}
if self.meta.mipmap:
texture.build_mipmaps()
self._close_image()
return texture
|
def load(self):
"""Load a 2d texture"""
self._open_image()
components, data = image_data(self.image)
texture = self.ctx.texture(
self.image.size,
components,
data,
)
texture.extra = {'meta': self.meta}
if self.meta.mipmap:
texture.build_mipmaps()
self._close_image()
return texture
|
[
"Load",
"a",
"2d",
"texture"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/texture/t2d.py#L7-L25
|
[
"def",
"load",
"(",
"self",
")",
":",
"self",
".",
"_open_image",
"(",
")",
"components",
",",
"data",
"=",
"image_data",
"(",
"self",
".",
"image",
")",
"texture",
"=",
"self",
".",
"ctx",
".",
"texture",
"(",
"self",
".",
"image",
".",
"size",
",",
"components",
",",
"data",
",",
")",
"texture",
".",
"extra",
"=",
"{",
"'meta'",
":",
"self",
".",
"meta",
"}",
"if",
"self",
".",
"meta",
".",
"mipmap",
":",
"texture",
".",
"build_mipmaps",
"(",
")",
"self",
".",
"_close_image",
"(",
")",
"return",
"texture"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ProgramShaders.from_single
|
Initialize a single glsl string containing all shaders
|
demosys/opengl/program.py
|
def from_single(cls, meta: ProgramDescription, source: str):
"""Initialize a single glsl string containing all shaders"""
instance = cls(meta)
instance.vertex_source = ShaderSource(
VERTEX_SHADER,
meta.path or meta.vertex_shader,
source
)
if GEOMETRY_SHADER in source:
instance.geometry_source = ShaderSource(
GEOMETRY_SHADER,
meta.path or meta.geometry_shader,
source,
)
if FRAGMENT_SHADER in source:
instance.fragment_source = ShaderSource(
FRAGMENT_SHADER,
meta.path or meta.fragment_shader,
source,
)
if TESS_CONTROL_SHADER in source:
instance.tess_control_source = ShaderSource(
TESS_CONTROL_SHADER,
meta.path or meta.tess_control_shader,
source,
)
if TESS_EVALUATION_SHADER in source:
instance.tess_evaluation_source = ShaderSource(
TESS_EVALUATION_SHADER,
meta.path or meta.tess_evaluation_shader,
source,
)
return instance
|
def from_single(cls, meta: ProgramDescription, source: str):
"""Initialize a single glsl string containing all shaders"""
instance = cls(meta)
instance.vertex_source = ShaderSource(
VERTEX_SHADER,
meta.path or meta.vertex_shader,
source
)
if GEOMETRY_SHADER in source:
instance.geometry_source = ShaderSource(
GEOMETRY_SHADER,
meta.path or meta.geometry_shader,
source,
)
if FRAGMENT_SHADER in source:
instance.fragment_source = ShaderSource(
FRAGMENT_SHADER,
meta.path or meta.fragment_shader,
source,
)
if TESS_CONTROL_SHADER in source:
instance.tess_control_source = ShaderSource(
TESS_CONTROL_SHADER,
meta.path or meta.tess_control_shader,
source,
)
if TESS_EVALUATION_SHADER in source:
instance.tess_evaluation_source = ShaderSource(
TESS_EVALUATION_SHADER,
meta.path or meta.tess_evaluation_shader,
source,
)
return instance
|
[
"Initialize",
"a",
"single",
"glsl",
"string",
"containing",
"all",
"shaders"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/program.py#L32-L69
|
[
"def",
"from_single",
"(",
"cls",
",",
"meta",
":",
"ProgramDescription",
",",
"source",
":",
"str",
")",
":",
"instance",
"=",
"cls",
"(",
"meta",
")",
"instance",
".",
"vertex_source",
"=",
"ShaderSource",
"(",
"VERTEX_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"vertex_shader",
",",
"source",
")",
"if",
"GEOMETRY_SHADER",
"in",
"source",
":",
"instance",
".",
"geometry_source",
"=",
"ShaderSource",
"(",
"GEOMETRY_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"geometry_shader",
",",
"source",
",",
")",
"if",
"FRAGMENT_SHADER",
"in",
"source",
":",
"instance",
".",
"fragment_source",
"=",
"ShaderSource",
"(",
"FRAGMENT_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"fragment_shader",
",",
"source",
",",
")",
"if",
"TESS_CONTROL_SHADER",
"in",
"source",
":",
"instance",
".",
"tess_control_source",
"=",
"ShaderSource",
"(",
"TESS_CONTROL_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"tess_control_shader",
",",
"source",
",",
")",
"if",
"TESS_EVALUATION_SHADER",
"in",
"source",
":",
"instance",
".",
"tess_evaluation_source",
"=",
"ShaderSource",
"(",
"TESS_EVALUATION_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"tess_evaluation_shader",
",",
"source",
",",
")",
"return",
"instance"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ProgramShaders.from_separate
|
Initialize multiple shader strings
|
demosys/opengl/program.py
|
def from_separate(cls, meta: ProgramDescription, vertex_source, geometry_source=None, fragment_source=None,
tess_control_source=None, tess_evaluation_source=None):
"""Initialize multiple shader strings"""
instance = cls(meta)
instance.vertex_source = ShaderSource(
VERTEX_SHADER,
meta.path or meta.vertex_shader,
vertex_source,
)
if geometry_source:
instance.geometry_source = ShaderSource(
GEOMETRY_SHADER,
meta.path or meta.geometry_shader,
geometry_source,
)
if fragment_source:
instance.fragment_source = ShaderSource(
FRAGMENT_SHADER,
meta.path or meta.fragment_shader,
fragment_source,
)
if tess_control_source:
instance.tess_control_source = ShaderSource(
TESS_CONTROL_SHADER,
meta.path or meta.tess_control_shader,
tess_control_source,
)
if tess_evaluation_source:
instance.tess_evaluation_source = ShaderSource(
TESS_EVALUATION_SHADER,
meta.path or meta.tess_control_shader,
tess_evaluation_source,
)
return instance
|
def from_separate(cls, meta: ProgramDescription, vertex_source, geometry_source=None, fragment_source=None,
tess_control_source=None, tess_evaluation_source=None):
"""Initialize multiple shader strings"""
instance = cls(meta)
instance.vertex_source = ShaderSource(
VERTEX_SHADER,
meta.path or meta.vertex_shader,
vertex_source,
)
if geometry_source:
instance.geometry_source = ShaderSource(
GEOMETRY_SHADER,
meta.path or meta.geometry_shader,
geometry_source,
)
if fragment_source:
instance.fragment_source = ShaderSource(
FRAGMENT_SHADER,
meta.path or meta.fragment_shader,
fragment_source,
)
if tess_control_source:
instance.tess_control_source = ShaderSource(
TESS_CONTROL_SHADER,
meta.path or meta.tess_control_shader,
tess_control_source,
)
if tess_evaluation_source:
instance.tess_evaluation_source = ShaderSource(
TESS_EVALUATION_SHADER,
meta.path or meta.tess_control_shader,
tess_evaluation_source,
)
return instance
|
[
"Initialize",
"multiple",
"shader",
"strings"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/program.py#L72-L110
|
[
"def",
"from_separate",
"(",
"cls",
",",
"meta",
":",
"ProgramDescription",
",",
"vertex_source",
",",
"geometry_source",
"=",
"None",
",",
"fragment_source",
"=",
"None",
",",
"tess_control_source",
"=",
"None",
",",
"tess_evaluation_source",
"=",
"None",
")",
":",
"instance",
"=",
"cls",
"(",
"meta",
")",
"instance",
".",
"vertex_source",
"=",
"ShaderSource",
"(",
"VERTEX_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"vertex_shader",
",",
"vertex_source",
",",
")",
"if",
"geometry_source",
":",
"instance",
".",
"geometry_source",
"=",
"ShaderSource",
"(",
"GEOMETRY_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"geometry_shader",
",",
"geometry_source",
",",
")",
"if",
"fragment_source",
":",
"instance",
".",
"fragment_source",
"=",
"ShaderSource",
"(",
"FRAGMENT_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"fragment_shader",
",",
"fragment_source",
",",
")",
"if",
"tess_control_source",
":",
"instance",
".",
"tess_control_source",
"=",
"ShaderSource",
"(",
"TESS_CONTROL_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"tess_control_shader",
",",
"tess_control_source",
",",
")",
"if",
"tess_evaluation_source",
":",
"instance",
".",
"tess_evaluation_source",
"=",
"ShaderSource",
"(",
"TESS_EVALUATION_SHADER",
",",
"meta",
".",
"path",
"or",
"meta",
".",
"tess_control_shader",
",",
"tess_evaluation_source",
",",
")",
"return",
"instance"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ProgramShaders.create
|
Creates a shader program.
Returns:
ModernGL Program instance
|
demosys/opengl/program.py
|
def create(self):
"""
Creates a shader program.
Returns:
ModernGL Program instance
"""
# Get out varyings
out_attribs = []
# If no fragment shader is present we are doing transform feedback
if not self.fragment_source:
# Out attributes is present in geometry shader if present
if self.geometry_source:
out_attribs = self.geometry_source.find_out_attribs()
# Otherwise they are specified in vertex shader
else:
out_attribs = self.vertex_source.find_out_attribs()
program = self.ctx.program(
vertex_shader=self.vertex_source.source,
geometry_shader=self.geometry_source.source if self.geometry_source else None,
fragment_shader=self.fragment_source.source if self.fragment_source else None,
tess_control_shader=self.tess_control_source.source if self.tess_control_source else None,
tess_evaluation_shader=self.tess_evaluation_source.source if self.tess_evaluation_source else None,
varyings=out_attribs,
)
program.extra = {'meta': self.meta}
return program
|
def create(self):
"""
Creates a shader program.
Returns:
ModernGL Program instance
"""
# Get out varyings
out_attribs = []
# If no fragment shader is present we are doing transform feedback
if not self.fragment_source:
# Out attributes is present in geometry shader if present
if self.geometry_source:
out_attribs = self.geometry_source.find_out_attribs()
# Otherwise they are specified in vertex shader
else:
out_attribs = self.vertex_source.find_out_attribs()
program = self.ctx.program(
vertex_shader=self.vertex_source.source,
geometry_shader=self.geometry_source.source if self.geometry_source else None,
fragment_shader=self.fragment_source.source if self.fragment_source else None,
tess_control_shader=self.tess_control_source.source if self.tess_control_source else None,
tess_evaluation_shader=self.tess_evaluation_source.source if self.tess_evaluation_source else None,
varyings=out_attribs,
)
program.extra = {'meta': self.meta}
return program
|
[
"Creates",
"a",
"shader",
"program",
".",
"Returns",
":",
"ModernGL",
"Program",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/program.py#L112-L140
|
[
"def",
"create",
"(",
"self",
")",
":",
"# Get out varyings\r",
"out_attribs",
"=",
"[",
"]",
"# If no fragment shader is present we are doing transform feedback\r",
"if",
"not",
"self",
".",
"fragment_source",
":",
"# Out attributes is present in geometry shader if present\r",
"if",
"self",
".",
"geometry_source",
":",
"out_attribs",
"=",
"self",
".",
"geometry_source",
".",
"find_out_attribs",
"(",
")",
"# Otherwise they are specified in vertex shader\r",
"else",
":",
"out_attribs",
"=",
"self",
".",
"vertex_source",
".",
"find_out_attribs",
"(",
")",
"program",
"=",
"self",
".",
"ctx",
".",
"program",
"(",
"vertex_shader",
"=",
"self",
".",
"vertex_source",
".",
"source",
",",
"geometry_shader",
"=",
"self",
".",
"geometry_source",
".",
"source",
"if",
"self",
".",
"geometry_source",
"else",
"None",
",",
"fragment_shader",
"=",
"self",
".",
"fragment_source",
".",
"source",
"if",
"self",
".",
"fragment_source",
"else",
"None",
",",
"tess_control_shader",
"=",
"self",
".",
"tess_control_source",
".",
"source",
"if",
"self",
".",
"tess_control_source",
"else",
"None",
",",
"tess_evaluation_shader",
"=",
"self",
".",
"tess_evaluation_source",
".",
"source",
"if",
"self",
".",
"tess_evaluation_source",
"else",
"None",
",",
"varyings",
"=",
"out_attribs",
",",
")",
"program",
".",
"extra",
"=",
"{",
"'meta'",
":",
"self",
".",
"meta",
"}",
"return",
"program"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ShaderSource.find_out_attribs
|
Get all out attributes in the shader source.
:return: List of attribute names
|
demosys/opengl/program.py
|
def find_out_attribs(self):
"""
Get all out attributes in the shader source.
:return: List of attribute names
"""
names = []
for line in self.lines:
if line.strip().startswith("out "):
names.append(line.split()[2].replace(';', ''))
return names
|
def find_out_attribs(self):
"""
Get all out attributes in the shader source.
:return: List of attribute names
"""
names = []
for line in self.lines:
if line.strip().startswith("out "):
names.append(line.split()[2].replace(';', ''))
return names
|
[
"Get",
"all",
"out",
"attributes",
"in",
"the",
"shader",
"source",
".",
":",
"return",
":",
"List",
"of",
"attribute",
"names"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/program.py#L165-L175
|
[
"def",
"find_out_attribs",
"(",
"self",
")",
":",
"names",
"=",
"[",
"]",
"for",
"line",
"in",
"self",
".",
"lines",
":",
"if",
"line",
".",
"strip",
"(",
")",
".",
"startswith",
"(",
"\"out \"",
")",
":",
"names",
".",
"append",
"(",
"line",
".",
"split",
"(",
")",
"[",
"2",
"]",
".",
"replace",
"(",
"';'",
",",
"''",
")",
")",
"return",
"names"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
ShaderSource.print
|
Print the shader lines
|
demosys/opengl/program.py
|
def print(self):
"""Print the shader lines"""
print("---[ START {} ]---".format(self.name))
for i, line in enumerate(self.lines):
print("{}: {}".format(str(i).zfill(3), line))
print("---[ END {} ]---".format(self.name))
|
def print(self):
"""Print the shader lines"""
print("---[ START {} ]---".format(self.name))
for i, line in enumerate(self.lines):
print("{}: {}".format(str(i).zfill(3), line))
print("---[ END {} ]---".format(self.name))
|
[
"Print",
"the",
"shader",
"lines"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/opengl/program.py#L177-L184
|
[
"def",
"print",
"(",
"self",
")",
":",
"print",
"(",
"\"---[ START {} ]---\"",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"for",
"i",
",",
"line",
"in",
"enumerate",
"(",
"self",
".",
"lines",
")",
":",
"print",
"(",
"\"{}: {}\"",
".",
"format",
"(",
"str",
"(",
"i",
")",
".",
"zfill",
"(",
"3",
")",
",",
"line",
")",
")",
"print",
"(",
"\"---[ END {} ]---\"",
".",
"format",
"(",
"self",
".",
"name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.create_effect
|
Create an effect instance adding it to the internal effects dictionary using the label as key.
Args:
label (str): The unique label for the effect instance
name (str): Name or full python path to the effect class we want to instantiate
args: Positional arguments to the effect initializer
kwargs: Keyword arguments to the effect initializer
Returns:
The newly created Effect instance
|
demosys/project/base.py
|
def create_effect(self, label: str, name: str, *args, **kwargs) -> Effect:
"""
Create an effect instance adding it to the internal effects dictionary using the label as key.
Args:
label (str): The unique label for the effect instance
name (str): Name or full python path to the effect class we want to instantiate
args: Positional arguments to the effect initializer
kwargs: Keyword arguments to the effect initializer
Returns:
The newly created Effect instance
"""
effect_cls = effects.find_effect_class(name)
effect = effect_cls(*args, **kwargs)
effect._label = label
if label in self._effects:
raise ValueError("An effect with label '{}' already exists".format(label))
self._effects[label] = effect
return effect
|
def create_effect(self, label: str, name: str, *args, **kwargs) -> Effect:
"""
Create an effect instance adding it to the internal effects dictionary using the label as key.
Args:
label (str): The unique label for the effect instance
name (str): Name or full python path to the effect class we want to instantiate
args: Positional arguments to the effect initializer
kwargs: Keyword arguments to the effect initializer
Returns:
The newly created Effect instance
"""
effect_cls = effects.find_effect_class(name)
effect = effect_cls(*args, **kwargs)
effect._label = label
if label in self._effects:
raise ValueError("An effect with label '{}' already exists".format(label))
self._effects[label] = effect
return effect
|
[
"Create",
"an",
"effect",
"instance",
"adding",
"it",
"to",
"the",
"internal",
"effects",
"dictionary",
"using",
"the",
"label",
"as",
"key",
".",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"unique",
"label",
"for",
"the",
"effect",
"instance",
"name",
"(",
"str",
")",
":",
"Name",
"or",
"full",
"python",
"path",
"to",
"the",
"effect",
"class",
"we",
"want",
"to",
"instantiate",
"args",
":",
"Positional",
"arguments",
"to",
"the",
"effect",
"initializer",
"kwargs",
":",
"Keyword",
"arguments",
"to",
"the",
"effect",
"initializer",
"Returns",
":",
"The",
"newly",
"created",
"Effect",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L107-L129
|
[
"def",
"create_effect",
"(",
"self",
",",
"label",
":",
"str",
",",
"name",
":",
"str",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"->",
"Effect",
":",
"effect_cls",
"=",
"effects",
".",
"find_effect_class",
"(",
"name",
")",
"effect",
"=",
"effect_cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"effect",
".",
"_label",
"=",
"label",
"if",
"label",
"in",
"self",
".",
"_effects",
":",
"raise",
"ValueError",
"(",
"\"An effect with label '{}' already exists\"",
".",
"format",
"(",
"label",
")",
")",
"self",
".",
"_effects",
"[",
"label",
"]",
"=",
"effect",
"return",
"effect"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.load
|
Loads this project instance
|
demosys/project/base.py
|
def load(self):
"""
Loads this project instance
"""
self.create_effect_classes()
self._add_resource_descriptions_to_pools(self.create_external_resources())
self._add_resource_descriptions_to_pools(self.create_resources())
for meta, resource in resources.textures.load_pool():
self._textures[meta.label] = resource
for meta, resource in resources.programs.load_pool():
self._programs[meta.label] = resource
for meta, resource in resources.scenes.load_pool():
self._scenes[meta.label] = resource
for meta, resource in resources.data.load_pool():
self._data[meta.label] = resource
self.create_effect_instances()
self.post_load()
|
def load(self):
"""
Loads this project instance
"""
self.create_effect_classes()
self._add_resource_descriptions_to_pools(self.create_external_resources())
self._add_resource_descriptions_to_pools(self.create_resources())
for meta, resource in resources.textures.load_pool():
self._textures[meta.label] = resource
for meta, resource in resources.programs.load_pool():
self._programs[meta.label] = resource
for meta, resource in resources.scenes.load_pool():
self._scenes[meta.label] = resource
for meta, resource in resources.data.load_pool():
self._data[meta.label] = resource
self.create_effect_instances()
self.post_load()
|
[
"Loads",
"this",
"project",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L139-L161
|
[
"def",
"load",
"(",
"self",
")",
":",
"self",
".",
"create_effect_classes",
"(",
")",
"self",
".",
"_add_resource_descriptions_to_pools",
"(",
"self",
".",
"create_external_resources",
"(",
")",
")",
"self",
".",
"_add_resource_descriptions_to_pools",
"(",
"self",
".",
"create_resources",
"(",
")",
")",
"for",
"meta",
",",
"resource",
"in",
"resources",
".",
"textures",
".",
"load_pool",
"(",
")",
":",
"self",
".",
"_textures",
"[",
"meta",
".",
"label",
"]",
"=",
"resource",
"for",
"meta",
",",
"resource",
"in",
"resources",
".",
"programs",
".",
"load_pool",
"(",
")",
":",
"self",
".",
"_programs",
"[",
"meta",
".",
"label",
"]",
"=",
"resource",
"for",
"meta",
",",
"resource",
"in",
"resources",
".",
"scenes",
".",
"load_pool",
"(",
")",
":",
"self",
".",
"_scenes",
"[",
"meta",
".",
"label",
"]",
"=",
"resource",
"for",
"meta",
",",
"resource",
"in",
"resources",
".",
"data",
".",
"load_pool",
"(",
")",
":",
"self",
".",
"_data",
"[",
"meta",
".",
"label",
"]",
"=",
"resource",
"self",
".",
"create_effect_instances",
"(",
")",
"self",
".",
"post_load",
"(",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject._add_resource_descriptions_to_pools
|
Takes a list of resource descriptions adding them
to the resource pool they belong to scheduling them for loading.
|
demosys/project/base.py
|
def _add_resource_descriptions_to_pools(self, meta_list):
"""
Takes a list of resource descriptions adding them
to the resource pool they belong to scheduling them for loading.
"""
if not meta_list:
return
for meta in meta_list:
getattr(resources, meta.resource_type).add(meta)
|
def _add_resource_descriptions_to_pools(self, meta_list):
"""
Takes a list of resource descriptions adding them
to the resource pool they belong to scheduling them for loading.
"""
if not meta_list:
return
for meta in meta_list:
getattr(resources, meta.resource_type).add(meta)
|
[
"Takes",
"a",
"list",
"of",
"resource",
"descriptions",
"adding",
"them",
"to",
"the",
"resource",
"pool",
"they",
"belong",
"to",
"scheduling",
"them",
"for",
"loading",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L163-L172
|
[
"def",
"_add_resource_descriptions_to_pools",
"(",
"self",
",",
"meta_list",
")",
":",
"if",
"not",
"meta_list",
":",
"return",
"for",
"meta",
"in",
"meta_list",
":",
"getattr",
"(",
"resources",
",",
"meta",
".",
"resource_type",
")",
".",
"add",
"(",
"meta",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.reload_programs
|
Reload all shader programs with the reloadable flag set
|
demosys/project/base.py
|
def reload_programs(self):
"""
Reload all shader programs with the reloadable flag set
"""
print("Reloading programs:")
for name, program in self._programs.items():
if getattr(program, 'program', None):
print(" - {}".format(program.meta.label))
program.program = resources.programs.load(program.meta)
|
def reload_programs(self):
"""
Reload all shader programs with the reloadable flag set
"""
print("Reloading programs:")
for name, program in self._programs.items():
if getattr(program, 'program', None):
print(" - {}".format(program.meta.label))
program.program = resources.programs.load(program.meta)
|
[
"Reload",
"all",
"shader",
"programs",
"with",
"the",
"reloadable",
"flag",
"set"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L174-L182
|
[
"def",
"reload_programs",
"(",
"self",
")",
":",
"print",
"(",
"\"Reloading programs:\"",
")",
"for",
"name",
",",
"program",
"in",
"self",
".",
"_programs",
".",
"items",
"(",
")",
":",
"if",
"getattr",
"(",
"program",
",",
"'program'",
",",
"None",
")",
":",
"print",
"(",
"\" - {}\"",
".",
"format",
"(",
"program",
".",
"meta",
".",
"label",
")",
")",
"program",
".",
"program",
"=",
"resources",
".",
"programs",
".",
"load",
"(",
"program",
".",
"meta",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_effect
|
Get an effect instance by label
Args:
label (str): The label for the effect instance
Returns:
Effect class instance
|
demosys/project/base.py
|
def get_effect(self, label: str) -> Effect:
"""
Get an effect instance by label
Args:
label (str): The label for the effect instance
Returns:
Effect class instance
"""
return self._get_resource(label, self._effects, "effect")
|
def get_effect(self, label: str) -> Effect:
"""
Get an effect instance by label
Args:
label (str): The label for the effect instance
Returns:
Effect class instance
"""
return self._get_resource(label, self._effects, "effect")
|
[
"Get",
"an",
"effect",
"instance",
"by",
"label",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"label",
"for",
"the",
"effect",
"instance",
"Returns",
":",
"Effect",
"class",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L184-L194
|
[
"def",
"get_effect",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"Effect",
":",
"return",
"self",
".",
"_get_resource",
"(",
"label",
",",
"self",
".",
"_effects",
",",
"\"effect\"",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_effect_class
|
Get an effect class from the effect registry.
Args:
class_name (str): The exact class name of the effect
Keyword Args:
package_name (str): The python path to the effect package the effect name is located.
This is optional and can be used to avoid issue with class name collisions.
Returns:
Effect class
|
demosys/project/base.py
|
def get_effect_class(self, class_name, package_name=None) -> Type[Effect]:
"""
Get an effect class from the effect registry.
Args:
class_name (str): The exact class name of the effect
Keyword Args:
package_name (str): The python path to the effect package the effect name is located.
This is optional and can be used to avoid issue with class name collisions.
Returns:
Effect class
"""
if package_name:
return effects.find_effect_class("{}.{}".format(package_name, class_name))
return effects.find_effect_class(class_name)
|
def get_effect_class(self, class_name, package_name=None) -> Type[Effect]:
"""
Get an effect class from the effect registry.
Args:
class_name (str): The exact class name of the effect
Keyword Args:
package_name (str): The python path to the effect package the effect name is located.
This is optional and can be used to avoid issue with class name collisions.
Returns:
Effect class
"""
if package_name:
return effects.find_effect_class("{}.{}".format(package_name, class_name))
return effects.find_effect_class(class_name)
|
[
"Get",
"an",
"effect",
"class",
"from",
"the",
"effect",
"registry",
".",
"Args",
":",
"class_name",
"(",
"str",
")",
":",
"The",
"exact",
"class",
"name",
"of",
"the",
"effect",
"Keyword",
"Args",
":",
"package_name",
"(",
"str",
")",
":",
"The",
"python",
"path",
"to",
"the",
"effect",
"package",
"the",
"effect",
"name",
"is",
"located",
".",
"This",
"is",
"optional",
"and",
"can",
"be",
"used",
"to",
"avoid",
"issue",
"with",
"class",
"name",
"collisions",
".",
"Returns",
":",
"Effect",
"class"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L196-L213
|
[
"def",
"get_effect_class",
"(",
"self",
",",
"class_name",
",",
"package_name",
"=",
"None",
")",
"->",
"Type",
"[",
"Effect",
"]",
":",
"if",
"package_name",
":",
"return",
"effects",
".",
"find_effect_class",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"package_name",
",",
"class_name",
")",
")",
"return",
"effects",
".",
"find_effect_class",
"(",
"class_name",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_scene
|
Gets a scene by label
Args:
label (str): The label for the scene to fetch
Returns:
Scene instance
|
demosys/project/base.py
|
def get_scene(self, label: str) -> Scene:
"""
Gets a scene by label
Args:
label (str): The label for the scene to fetch
Returns:
Scene instance
"""
return self._get_resource(label, self._scenes, "scene")
|
def get_scene(self, label: str) -> Scene:
"""
Gets a scene by label
Args:
label (str): The label for the scene to fetch
Returns:
Scene instance
"""
return self._get_resource(label, self._scenes, "scene")
|
[
"Gets",
"a",
"scene",
"by",
"label",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"label",
"for",
"the",
"scene",
"to",
"fetch",
"Returns",
":",
"Scene",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L215-L225
|
[
"def",
"get_scene",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"Scene",
":",
"return",
"self",
".",
"_get_resource",
"(",
"label",
",",
"self",
".",
"_scenes",
",",
"\"scene\"",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_texture
|
Get a texture by label
Args:
label (str): The label for the texture to fetch
Returns:
Texture instance
|
demosys/project/base.py
|
def get_texture(self, label: str) -> Union[moderngl.Texture, moderngl.TextureArray,
moderngl.Texture3D, moderngl.TextureCube]:
"""
Get a texture by label
Args:
label (str): The label for the texture to fetch
Returns:
Texture instance
"""
return self._get_resource(label, self._textures, "texture")
|
def get_texture(self, label: str) -> Union[moderngl.Texture, moderngl.TextureArray,
moderngl.Texture3D, moderngl.TextureCube]:
"""
Get a texture by label
Args:
label (str): The label for the texture to fetch
Returns:
Texture instance
"""
return self._get_resource(label, self._textures, "texture")
|
[
"Get",
"a",
"texture",
"by",
"label",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"label",
"for",
"the",
"texture",
"to",
"fetch",
"Returns",
":",
"Texture",
"instance"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L230-L241
|
[
"def",
"get_texture",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"Union",
"[",
"moderngl",
".",
"Texture",
",",
"moderngl",
".",
"TextureArray",
",",
"moderngl",
".",
"Texture3D",
",",
"moderngl",
".",
"TextureCube",
"]",
":",
"return",
"self",
".",
"_get_resource",
"(",
"label",
",",
"self",
".",
"_textures",
",",
"\"texture\"",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_data
|
Get a data resource by label
Args:
label (str): The labvel for the data resource to fetch
Returns:
The requeted data object
|
demosys/project/base.py
|
def get_data(self, label: str) -> Any:
"""
Get a data resource by label
Args:
label (str): The labvel for the data resource to fetch
Returns:
The requeted data object
"""
return self._get_resource(label, self._data, "data")
|
def get_data(self, label: str) -> Any:
"""
Get a data resource by label
Args:
label (str): The labvel for the data resource to fetch
Returns:
The requeted data object
"""
return self._get_resource(label, self._data, "data")
|
[
"Get",
"a",
"data",
"resource",
"by",
"label",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"labvel",
"for",
"the",
"data",
"resource",
"to",
"fetch",
"Returns",
":",
"The",
"requeted",
"data",
"object"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L243-L253
|
[
"def",
"get_data",
"(",
"self",
",",
"label",
":",
"str",
")",
"->",
"Any",
":",
"return",
"self",
".",
"_get_resource",
"(",
"label",
",",
"self",
".",
"_data",
",",
"\"data\"",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject._get_resource
|
Generic resoure fetcher handling errors.
Args:
label (str): The label to fetch
source (dict): The dictionary to look up the label
resource_type str: The display name of the resource type (used in errors)
|
demosys/project/base.py
|
def _get_resource(self, label: str, source: dict, resource_type: str):
"""
Generic resoure fetcher handling errors.
Args:
label (str): The label to fetch
source (dict): The dictionary to look up the label
resource_type str: The display name of the resource type (used in errors)
"""
try:
return source[label]
except KeyError:
raise ValueError("Cannot find {0} with label '{1}'.\nExisting {0} labels: {2}".format(
resource_type, label, list(source.keys())))
|
def _get_resource(self, label: str, source: dict, resource_type: str):
"""
Generic resoure fetcher handling errors.
Args:
label (str): The label to fetch
source (dict): The dictionary to look up the label
resource_type str: The display name of the resource type (used in errors)
"""
try:
return source[label]
except KeyError:
raise ValueError("Cannot find {0} with label '{1}'.\nExisting {0} labels: {2}".format(
resource_type, label, list(source.keys())))
|
[
"Generic",
"resoure",
"fetcher",
"handling",
"errors",
".",
"Args",
":",
"label",
"(",
"str",
")",
":",
"The",
"label",
"to",
"fetch",
"source",
"(",
"dict",
")",
":",
"The",
"dictionary",
"to",
"look",
"up",
"the",
"label",
"resource_type",
"str",
":",
"The",
"display",
"name",
"of",
"the",
"resource",
"type",
"(",
"used",
"in",
"errors",
")"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L255-L268
|
[
"def",
"_get_resource",
"(",
"self",
",",
"label",
":",
"str",
",",
"source",
":",
"dict",
",",
"resource_type",
":",
"str",
")",
":",
"try",
":",
"return",
"source",
"[",
"label",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"\"Cannot find {0} with label '{1}'.\\nExisting {0} labels: {2}\"",
".",
"format",
"(",
"resource_type",
",",
"label",
",",
"list",
"(",
"source",
".",
"keys",
"(",
")",
")",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseProject.get_runnable_effects
|
Returns all runnable effects in the project.
:return: List of all runnable effects
|
demosys/project/base.py
|
def get_runnable_effects(self) -> List[Effect]:
"""
Returns all runnable effects in the project.
:return: List of all runnable effects
"""
return [effect for name, effect in self._effects.items() if effect.runnable]
|
def get_runnable_effects(self) -> List[Effect]:
"""
Returns all runnable effects in the project.
:return: List of all runnable effects
"""
return [effect for name, effect in self._effects.items() if effect.runnable]
|
[
"Returns",
"all",
"runnable",
"effects",
"in",
"the",
"project",
".",
":",
"return",
":",
"List",
"of",
"all",
"runnable",
"effects"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/project/base.py#L270-L276
|
[
"def",
"get_runnable_effects",
"(",
"self",
")",
"->",
"List",
"[",
"Effect",
"]",
":",
"return",
"[",
"effect",
"for",
"name",
",",
"effect",
"in",
"self",
".",
"_effects",
".",
"items",
"(",
")",
"if",
"effect",
".",
"runnable",
"]"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
image_data
|
Get components and bytes for an image
|
demosys/loaders/texture/pillow.py
|
def image_data(image):
"""Get components and bytes for an image"""
# NOTE: We might want to check the actual image.mode
# and convert to an acceptable format.
# At the moment we load the data as is.
data = image.tobytes()
components = len(data) // (image.size[0] * image.size[1])
return components, data
|
def image_data(image):
"""Get components and bytes for an image"""
# NOTE: We might want to check the actual image.mode
# and convert to an acceptable format.
# At the moment we load the data as is.
data = image.tobytes()
components = len(data) // (image.size[0] * image.size[1])
return components, data
|
[
"Get",
"components",
"and",
"bytes",
"for",
"an",
"image"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/texture/pillow.py#L38-L45
|
[
"def",
"image_data",
"(",
"image",
")",
":",
"# NOTE: We might want to check the actual image.mode\r",
"# and convert to an acceptable format.\r",
"# At the moment we load the data as is.\r",
"data",
"=",
"image",
".",
"tobytes",
"(",
")",
"components",
"=",
"len",
"(",
"data",
")",
"//",
"(",
"image",
".",
"size",
"[",
"0",
"]",
"*",
"image",
".",
"size",
"[",
"1",
"]",
")",
"return",
"components",
",",
"data"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseCommand.run_from_argv
|
Called by the system when executing the command from the command line.
This should not be overridden.
:param argv: Arguments from command line
|
demosys/management/base.py
|
def run_from_argv(self, argv):
"""
Called by the system when executing the command from the command line.
This should not be overridden.
:param argv: Arguments from command line
"""
parser = self.create_parser(argv[0], argv[1])
options = parser.parse_args(argv[2:])
cmd_options = vars(options)
args = cmd_options.pop('args', ())
self.handle(*args, **cmd_options)
|
def run_from_argv(self, argv):
"""
Called by the system when executing the command from the command line.
This should not be overridden.
:param argv: Arguments from command line
"""
parser = self.create_parser(argv[0], argv[1])
options = parser.parse_args(argv[2:])
cmd_options = vars(options)
args = cmd_options.pop('args', ())
self.handle(*args, **cmd_options)
|
[
"Called",
"by",
"the",
"system",
"when",
"executing",
"the",
"command",
"from",
"the",
"command",
"line",
".",
"This",
"should",
"not",
"be",
"overridden",
".",
":",
"param",
"argv",
":",
"Arguments",
"from",
"command",
"line"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/base.py#L39-L50
|
[
"def",
"run_from_argv",
"(",
"self",
",",
"argv",
")",
":",
"parser",
"=",
"self",
".",
"create_parser",
"(",
"argv",
"[",
"0",
"]",
",",
"argv",
"[",
"1",
"]",
")",
"options",
"=",
"parser",
".",
"parse_args",
"(",
"argv",
"[",
"2",
":",
"]",
")",
"cmd_options",
"=",
"vars",
"(",
"options",
")",
"args",
"=",
"cmd_options",
".",
"pop",
"(",
"'args'",
",",
"(",
")",
")",
"self",
".",
"handle",
"(",
"*",
"args",
",",
"*",
"*",
"cmd_options",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseCommand.create_parser
|
Create argument parser and deal with ``add_arguments``.
This method should not be overriden.
:param prog_name: Name of the command (argv[0])
:return: ArgumentParser
|
demosys/management/base.py
|
def create_parser(self, prog_name, subcommand):
"""
Create argument parser and deal with ``add_arguments``.
This method should not be overriden.
:param prog_name: Name of the command (argv[0])
:return: ArgumentParser
"""
parser = argparse.ArgumentParser(prog_name, subcommand)
# Add generic arguments here
self.add_arguments(parser)
return parser
|
def create_parser(self, prog_name, subcommand):
"""
Create argument parser and deal with ``add_arguments``.
This method should not be overriden.
:param prog_name: Name of the command (argv[0])
:return: ArgumentParser
"""
parser = argparse.ArgumentParser(prog_name, subcommand)
# Add generic arguments here
self.add_arguments(parser)
return parser
|
[
"Create",
"argument",
"parser",
"and",
"deal",
"with",
"add_arguments",
".",
"This",
"method",
"should",
"not",
"be",
"overriden",
".",
":",
"param",
"prog_name",
":",
"Name",
"of",
"the",
"command",
"(",
"argv",
"[",
"0",
"]",
")",
":",
"return",
":",
"ArgumentParser"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/base.py#L63-L74
|
[
"def",
"create_parser",
"(",
"self",
",",
"prog_name",
",",
"subcommand",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"prog_name",
",",
"subcommand",
")",
"# Add generic arguments here\r",
"self",
".",
"add_arguments",
"(",
"parser",
")",
"return",
"parser"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
CreateCommand.validate_name
|
Can the name be used as a python module or package?
Raises ``ValueError`` if the name is invalid.
:param name: the name to check
|
demosys/management/base.py
|
def validate_name(self, name):
"""
Can the name be used as a python module or package?
Raises ``ValueError`` if the name is invalid.
:param name: the name to check
"""
if not name:
raise ValueError("Name cannot be empty")
# Can the name be used as an identifier in python (module or package name)
if not name.isidentifier():
raise ValueError("{} is not a valid identifier".format(name))
|
def validate_name(self, name):
"""
Can the name be used as a python module or package?
Raises ``ValueError`` if the name is invalid.
:param name: the name to check
"""
if not name:
raise ValueError("Name cannot be empty")
# Can the name be used as an identifier in python (module or package name)
if not name.isidentifier():
raise ValueError("{} is not a valid identifier".format(name))
|
[
"Can",
"the",
"name",
"be",
"used",
"as",
"a",
"python",
"module",
"or",
"package?",
"Raises",
"ValueError",
"if",
"the",
"name",
"is",
"invalid",
".",
":",
"param",
"name",
":",
"the",
"name",
"to",
"check"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/base.py#L80-L92
|
[
"def",
"validate_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"name",
":",
"raise",
"ValueError",
"(",
"\"Name cannot be empty\"",
")",
"# Can the name be used as an identifier in python (module or package name)\r",
"if",
"not",
"name",
".",
"isidentifier",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"{} is not a valid identifier\"",
".",
"format",
"(",
"name",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
bbox
|
Generates a bounding box with (0.0, 0.0, 0.0) as the center.
This is simply a box with ``LINE_STRIP`` as draw mode.
Keyword Args:
width (float): Width of the box
height (float): Height of the box
depth (float): Depth of the box
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
|
demosys/geometry/bbox.py
|
def bbox(width=1.0, height=1.0, depth=1.0):
"""
Generates a bounding box with (0.0, 0.0, 0.0) as the center.
This is simply a box with ``LINE_STRIP`` as draw mode.
Keyword Args:
width (float): Width of the box
height (float): Height of the box
depth (float): Depth of the box
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
width, height, depth = width / 2.0, height / 2.0, depth / 2.0
pos = numpy.array([
width, -height, depth,
width, height, depth,
-width, -height, depth,
width, height, depth,
-width, height, depth,
-width, -height, depth,
width, -height, -depth,
width, height, -depth,
width, -height, depth,
width, height, -depth,
width, height, depth,
width, -height, depth,
width, -height, -depth,
width, -height, depth,
-width, -height, depth,
width, -height, -depth,
-width, -height, depth,
-width, -height, -depth,
-width, -height, depth,
-width, height, depth,
-width, height, -depth,
-width, -height, depth,
-width, height, -depth,
-width, -height, -depth,
width, height, -depth,
width, -height, -depth,
-width, -height, -depth,
width, height, -depth,
-width, -height, -depth,
-width, height, -depth,
width, height, -depth,
-width, height, -depth,
width, height, depth,
-width, height, -depth,
-width, height, depth,
width, height, depth,
], dtype=numpy.float32)
vao = VAO("geometry:cube", mode=moderngl.LINE_STRIP)
vao.buffer(pos, '3f', ["in_position"])
return vao
|
def bbox(width=1.0, height=1.0, depth=1.0):
"""
Generates a bounding box with (0.0, 0.0, 0.0) as the center.
This is simply a box with ``LINE_STRIP`` as draw mode.
Keyword Args:
width (float): Width of the box
height (float): Height of the box
depth (float): Depth of the box
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance
"""
width, height, depth = width / 2.0, height / 2.0, depth / 2.0
pos = numpy.array([
width, -height, depth,
width, height, depth,
-width, -height, depth,
width, height, depth,
-width, height, depth,
-width, -height, depth,
width, -height, -depth,
width, height, -depth,
width, -height, depth,
width, height, -depth,
width, height, depth,
width, -height, depth,
width, -height, -depth,
width, -height, depth,
-width, -height, depth,
width, -height, -depth,
-width, -height, depth,
-width, -height, -depth,
-width, -height, depth,
-width, height, depth,
-width, height, -depth,
-width, -height, depth,
-width, height, -depth,
-width, -height, -depth,
width, height, -depth,
width, -height, -depth,
-width, -height, -depth,
width, height, -depth,
-width, -height, -depth,
-width, height, -depth,
width, height, -depth,
-width, height, -depth,
width, height, depth,
-width, height, -depth,
-width, height, depth,
width, height, depth,
], dtype=numpy.float32)
vao = VAO("geometry:cube", mode=moderngl.LINE_STRIP)
vao.buffer(pos, '3f', ["in_position"])
return vao
|
[
"Generates",
"a",
"bounding",
"box",
"with",
"(",
"0",
".",
"0",
"0",
".",
"0",
"0",
".",
"0",
")",
"as",
"the",
"center",
".",
"This",
"is",
"simply",
"a",
"box",
"with",
"LINE_STRIP",
"as",
"draw",
"mode",
"."
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/geometry/bbox.py#L7-L63
|
[
"def",
"bbox",
"(",
"width",
"=",
"1.0",
",",
"height",
"=",
"1.0",
",",
"depth",
"=",
"1.0",
")",
":",
"width",
",",
"height",
",",
"depth",
"=",
"width",
"/",
"2.0",
",",
"height",
"/",
"2.0",
",",
"depth",
"/",
"2.0",
"pos",
"=",
"numpy",
".",
"array",
"(",
"[",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"height",
",",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"height",
",",
"depth",
",",
"-",
"width",
",",
"height",
",",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"-",
"depth",
",",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"depth",
",",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"width",
",",
"-",
"height",
",",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"-",
"width",
",",
"height",
",",
"depth",
",",
"-",
"width",
",",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"depth",
",",
"-",
"width",
",",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"-",
"depth",
",",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"-",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"height",
",",
"-",
"depth",
",",
"width",
",",
"height",
",",
"depth",
",",
"-",
"width",
",",
"height",
",",
"-",
"depth",
",",
"-",
"width",
",",
"height",
",",
"depth",
",",
"width",
",",
"height",
",",
"depth",
",",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"vao",
"=",
"VAO",
"(",
"\"geometry:cube\"",
",",
"mode",
"=",
"moderngl",
".",
"LINE_STRIP",
")",
"vao",
".",
"buffer",
"(",
"pos",
",",
"'3f'",
",",
"[",
"\"in_position\"",
"]",
")",
"return",
"vao"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
BaseLoader._find_last_of
|
Find the last occurance of the file in finders
|
demosys/loaders/base.py
|
def _find_last_of(self, path, finders):
"""Find the last occurance of the file in finders"""
found_path = None
for finder in finders:
result = finder.find(path)
if result:
found_path = result
return found_path
|
def _find_last_of(self, path, finders):
"""Find the last occurance of the file in finders"""
found_path = None
for finder in finders:
result = finder.find(path)
if result:
found_path = result
return found_path
|
[
"Find",
"the",
"last",
"occurance",
"of",
"the",
"file",
"in",
"finders"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/loaders/base.py#L51-L59
|
[
"def",
"_find_last_of",
"(",
"self",
",",
"path",
",",
"finders",
")",
":",
"found_path",
"=",
"None",
"for",
"finder",
"in",
"finders",
":",
"result",
"=",
"finder",
".",
"find",
"(",
"path",
")",
"if",
"result",
":",
"found_path",
"=",
"result",
"return",
"found_path"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Command.initial_sanity_check
|
Checks if we can create the project
|
demosys/management/commands/createproject.py
|
def initial_sanity_check(self):
"""Checks if we can create the project"""
# Check for python module collision
self.try_import(self.project_name)
# Is the name a valid identifier?
self.validate_name(self.project_name)
# Make sure we don't mess with existing directories
if os.path.exists(self.project_name):
print("Directory {} already exist. Aborting.".format(self.project_name))
return False
if os.path.exists('manage.py'):
print("A manage.py file already exist in the current directory. Aborting.")
return False
return True
|
def initial_sanity_check(self):
"""Checks if we can create the project"""
# Check for python module collision
self.try_import(self.project_name)
# Is the name a valid identifier?
self.validate_name(self.project_name)
# Make sure we don't mess with existing directories
if os.path.exists(self.project_name):
print("Directory {} already exist. Aborting.".format(self.project_name))
return False
if os.path.exists('manage.py'):
print("A manage.py file already exist in the current directory. Aborting.")
return False
return True
|
[
"Checks",
"if",
"we",
"can",
"create",
"the",
"project"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/commands/createproject.py#L22-L39
|
[
"def",
"initial_sanity_check",
"(",
"self",
")",
":",
"# Check for python module collision\r",
"self",
".",
"try_import",
"(",
"self",
".",
"project_name",
")",
"# Is the name a valid identifier?\r",
"self",
".",
"validate_name",
"(",
"self",
".",
"project_name",
")",
"# Make sure we don't mess with existing directories\r",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"project_name",
")",
":",
"print",
"(",
"\"Directory {} already exist. Aborting.\"",
".",
"format",
"(",
"self",
".",
"project_name",
")",
")",
"return",
"False",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"'manage.py'",
")",
":",
"print",
"(",
"\"A manage.py file already exist in the current directory. Aborting.\"",
")",
"return",
"False",
"return",
"True"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Command.create_entrypoint
|
Write manage.py in the current directory
|
demosys/management/commands/createproject.py
|
def create_entrypoint(self):
"""Write manage.py in the current directory"""
with open(os.path.join(self.template_dir, 'manage.py'), 'r') as fd:
data = fd.read().format(project_name=self.project_name)
with open('manage.py', 'w') as fd:
fd.write(data)
os.chmod('manage.py', 0o777)
|
def create_entrypoint(self):
"""Write manage.py in the current directory"""
with open(os.path.join(self.template_dir, 'manage.py'), 'r') as fd:
data = fd.read().format(project_name=self.project_name)
with open('manage.py', 'w') as fd:
fd.write(data)
os.chmod('manage.py', 0o777)
|
[
"Write",
"manage",
".",
"py",
"in",
"the",
"current",
"directory"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/commands/createproject.py#L49-L57
|
[
"def",
"create_entrypoint",
"(",
"self",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"template_dir",
",",
"'manage.py'",
")",
",",
"'r'",
")",
"as",
"fd",
":",
"data",
"=",
"fd",
".",
"read",
"(",
")",
".",
"format",
"(",
"project_name",
"=",
"self",
".",
"project_name",
")",
"with",
"open",
"(",
"'manage.py'",
",",
"'w'",
")",
"as",
"fd",
":",
"fd",
".",
"write",
"(",
"data",
")",
"os",
".",
"chmod",
"(",
"'manage.py'",
",",
"0o777",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Command.get_template_dir
|
Returns the absolute path to template directory
|
demosys/management/commands/createproject.py
|
def get_template_dir(self):
"""Returns the absolute path to template directory"""
directory = os.path.dirname(os.path.abspath(__file__))
directory = os.path.dirname(os.path.dirname(directory))
directory = os.path.join(directory, 'project_template')
return directory
|
def get_template_dir(self):
"""Returns the absolute path to template directory"""
directory = os.path.dirname(os.path.abspath(__file__))
directory = os.path.dirname(os.path.dirname(directory))
directory = os.path.join(directory, 'project_template')
return directory
|
[
"Returns",
"the",
"absolute",
"path",
"to",
"template",
"directory"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/management/commands/createproject.py#L66-L71
|
[
"def",
"get_template_dir",
"(",
"self",
")",
":",
"directory",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"__file__",
")",
")",
"directory",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"directory",
")",
")",
"directory",
"=",
"os",
".",
"path",
".",
"join",
"(",
"directory",
",",
"'project_template'",
")",
"return",
"directory"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
valid
|
Programs.resolve_loader
|
Resolve program loader
|
demosys/resources/programs.py
|
def resolve_loader(self, meta: ProgramDescription):
"""
Resolve program loader
"""
if not meta.loader:
meta.loader = 'single' if meta.path else 'separate'
for loader_cls in self._loaders:
if loader_cls.name == meta.loader:
meta.loader_cls = loader_cls
break
else:
raise ImproperlyConfigured(
(
"Program {} has no loader class registered."
"Check PROGRAM_LOADERS or PROGRAM_DIRS"
).format(meta.path)
)
|
def resolve_loader(self, meta: ProgramDescription):
"""
Resolve program loader
"""
if not meta.loader:
meta.loader = 'single' if meta.path else 'separate'
for loader_cls in self._loaders:
if loader_cls.name == meta.loader:
meta.loader_cls = loader_cls
break
else:
raise ImproperlyConfigured(
(
"Program {} has no loader class registered."
"Check PROGRAM_LOADERS or PROGRAM_DIRS"
).format(meta.path)
)
|
[
"Resolve",
"program",
"loader"
] |
Contraz/demosys-py
|
python
|
https://github.com/Contraz/demosys-py/blob/6466128a3029c4d09631420ccce73024025bd5b6/demosys/resources/programs.py#L20-L37
|
[
"def",
"resolve_loader",
"(",
"self",
",",
"meta",
":",
"ProgramDescription",
")",
":",
"if",
"not",
"meta",
".",
"loader",
":",
"meta",
".",
"loader",
"=",
"'single'",
"if",
"meta",
".",
"path",
"else",
"'separate'",
"for",
"loader_cls",
"in",
"self",
".",
"_loaders",
":",
"if",
"loader_cls",
".",
"name",
"==",
"meta",
".",
"loader",
":",
"meta",
".",
"loader_cls",
"=",
"loader_cls",
"break",
"else",
":",
"raise",
"ImproperlyConfigured",
"(",
"(",
"\"Program {} has no loader class registered.\"",
"\"Check PROGRAM_LOADERS or PROGRAM_DIRS\"",
")",
".",
"format",
"(",
"meta",
".",
"path",
")",
")"
] |
6466128a3029c4d09631420ccce73024025bd5b6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.