Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_components(self):
""" Internal method to init the widgets components """
self._node.hide()
# Create the texture where the gui component is rendered inside
self._storage_tex = Image.create_2d("ExposureDisplay", 140, 20, Texture.T_unsigned_byte, Texture.F_rgba8)
self._storage_tex.set_clear_color(Vec4(0.2, 0.6, 1.0, 1.0))
self._storage_tex.clear_image()
self._bg_frame = DirectFrame(parent=self._node, frameColor=(0.1, 0.1, 0.1, 1.0),
frameSize=(200, 0, -10, -85), pos=(0, 0, 0))
self._display_img = BetterOnscreenImage(
image=self._storage_tex, parent=self._node, w=140, h=20, x=20, y=50)
self._display_txt = BetterOnscreenText(
text="Current Exposure".upper(), parent=self._node, x=160, y=40, size=13,
color=Vec3(0.8), align="right")
# Create the shader which generates the visualization texture
self._cshader_node = ComputeNode("ExposureWidget")
self._cshader_node.add_dispatch(140 // 10, 20 // 4, 1)
cubemap = loader.loadCubeMap(pth)
node = NodePath("")
node.set_shader(compute_shader)
node.set_shader_input("SourceCubemap", cubemap)
node.set_shader_input("size", size)
node.set_shader_input("blurSize", blur_size)
node.set_shader_input("effectiveSize", effective_size)
final_img = PNMImage(size, size, 3)
for i in range(6):
face_dest = dst_pth.replace("#", str(i))
dst = Texture("Face-" + str(i))
dst.setup_2d_texture(effective_size, effective_size,
Texture.T_float, Texture.F_rgba16)
# Execute compute shader
node.set_shader_input("faceIndex", i)
node.set_shader_input("DestTex", dst)
attr = node.get_attrib(ShaderAttrib)
base.graphicsEngine.dispatch_compute(( (effective_size+15) // 16,
(effective_size+15) // 16, 1),
attr, base.win.get_gsg())
base.graphicsEngine.extract_texture_data(dst, base.win.get_gsg())
img = PNMImage(effective_size, effective_size, 3)
dst.store(img)
img.gaussian_filter(blur_size)
final_img.copy_sub_image(img, 0, 0, blur_size, blur_size, size, size)
final_img.write(face_dest)
self._hint_reloading = Sprite(
image="data/gui/shader_reload_hint.png",
x=float((Globals.base.win.get_x_size()) // 2) / self._gui_scale - 465 // 2, y=220,
parent=self._fullscreen_node)
self.set_reload_hint_visible(False)
if not NATIVE_CXX_LOADED:
# Warning when using the python version
python_warning = Sprite(
image="data/gui/python_warning.png",
x=((Globals.base.win.get_x_size()/self._gui_scale) - 1054) // 2,
y=(Globals.base.win.get_y_size()/self._gui_scale) - 118 - 40, parent=self._fullscreen_node)
Sequence(
python_warning.color_scale_interval(0.7, Vec4(0.3, 1, 1, 0.7), blendType="easeOut"),
python_warning.color_scale_interval(0.7, Vec4(1, 1, 1, 1.0), blendType="easeOut"),
).loop()
# Keybinding hints
self._keybinding_instructions = Sprite(
image="data/gui/keybindings.png", x=30,
y=Globals.base.win.get_y_size()//self._gui_scale - 510.0,
parent=self._fullscreen_node, any_filter=False)
""" Creates the hints like keybindings and when reloading shaders """
self._hint_reloading = Sprite(
image="data/gui/shader_reload_hint.png",
x=float((Globals.base.win.get_x_size()) // 2) / self._gui_scale - 465 // 2, y=220,
parent=self._fullscreen_node)
self.set_reload_hint_visible(False)
if not NATIVE_CXX_LOADED:
# Warning when using the python version
python_warning = Sprite(
image="data/gui/python_warning.png",
x=((Globals.base.win.get_x_size()/self._gui_scale) - 1054) // 2,
y=(Globals.base.win.get_y_size()/self._gui_scale) - 118 - 40, parent=self._fullscreen_node)
Sequence(
python_warning.color_scale_interval(0.7, Vec4(0.3, 1, 1, 0.7), blendType="easeOut"),
python_warning.color_scale_interval(0.7, Vec4(1, 1, 1, 1.0), blendType="easeOut"),
).loop()
# Keybinding hints
self._keybinding_instructions = Sprite(
image="data/gui/keybindings.png", x=30,
y=Globals.base.win.get_y_size()//self._gui_scale - 510.0,
parent=self._fullscreen_node, any_filter=False)
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from __future__ import division, print_function
from panda3d.core import PNMImage
lut_size = 64
lut_cols = 8
lut_rows = (lut_size + lut_cols - 1) // lut_cols
img = PNMImage(lut_size * lut_cols, lut_size * lut_rows, 3, 2**16 - 1)
def to_linear(v):
return float(v) / float(lut_size - 1)
def to_linear_inv(v):
return 1 - to_linear(v)
for r in range(lut_size):
for g in range(lut_size):
for b in range(lut_size):
slice_offset_x = (b % lut_cols) * lut_size
slice_offset_y = (b // lut_cols) * lut_size
img.set_xel(r + slice_offset_x, g + slice_offset_y,
to_linear(r), to_linear_inv(g), to_linear(b))
def test_glsl_sampler(gsg):
tex1 = core.Texture("")
tex1.setup_1d_texture(1, core.Texture.T_unsigned_byte, core.Texture.F_rgba8)
tex1.set_clear_color((0, 2 / 255.0, 1, 1))
tex2 = core.Texture("")
tex2.setup_2d_texture(1, 1, core.Texture.T_float, core.Texture.F_rgba32)
tex2.set_clear_color((1.0, 2.0, -3.14, 0.0))
preamble = """
uniform sampler1D tex1;
uniform sampler2D tex2;
"""
code = """
assert(texelFetch(tex1, 0, 0) == vec4(0, 2 / 255.0, 1, 1));
assert(texelFetch(tex2, ivec2(0, 0), 0) == vec4(1.0, 2.0, -3.14, 0.0));
"""
run_glsl_test(gsg, code, preamble, {'tex1': tex1, 'tex2': tex2})
def do_file_test(dg, verify, filename):
dof = core.DatagramOutputFile()
dof.open(filename)
dof.put_datagram(dg)
dof.close()
dg2 = core.Datagram()
dif = core.DatagramInputFile()
dif.open(filename)
assert dif.get_datagram(dg2)
dif.close()
# This is normally saved by the DatagramOutputFile header. We cheat here.
dg2.set_stdfloat_double(dg.get_stdfloat_double())
dgi = core.DatagramIterator(dg2)
verify(dgi)
def do_file_test(dg, verify, filename):
dof = core.DatagramOutputFile()
dof.open(filename)
dof.put_datagram(dg)
dof.close()
dg2 = core.Datagram()
dif = core.DatagramInputFile()
dif.open(filename)
assert dif.get_datagram(dg2)
dif.close()
# This is normally saved by the DatagramOutputFile header. We cheat here.
dg2.set_stdfloat_double(dg.get_stdfloat_double())
dgi = core.DatagramIterator(dg2)
verify(dgi)
def make_collision(solid_from, solid_into):
node_from = CollisionNode("from")
node_from.add_solid(solid_from)
node_into = CollisionNode("into")
node_into.add_solid(solid_into)
root = NodePath("root")
trav = CollisionTraverser()
queue = CollisionHandlerQueue()
np_from = root.attach_new_node(node_from)
np_into = root.attach_new_node(node_into)
trav.add_collider(np_from, queue)
trav.traverse(root)
entry = None
for e in queue.get_entries():
if e.get_into() == solid_into:
entry = e
return (entry, np_from, np_into)
def test_textnode_flatten_color():
text = core.TextNode("test")
text.text_color = (0, 0, 0, 1)
path = core.NodePath(text)
color = core.LColor(1, 0, 0, 1)
path.set_color(color)
path.flatten_strong()
assert text.text_color.almost_equal(color)
assert text.shadow_color.almost_equal(color)
assert text.frame_color.almost_equal(color)
assert text.card_color.almost_equal(color)