Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 write_image(filename, channels):
img = core.PNMImage(1, 1, channels)
img.set_xel_a(0, 0, (0.0, 0.25, 0.5, 0.75))
assert img.write(filename)
def generate_dataset_texture_into(self, dest_tex, z):
resolution_vertical = dest_tex.get_y_size()
resolution_horizontal = dest_tex.get_x_size()
dest = PNMImage(resolution_vertical, resolution_horizontal, 1, 65535)
for vert in range(resolution_vertical):
for horiz in range(resolution_horizontal):
vert_angle = vert / (resolution_vertical-1.0)
vert_angle = math.cos(vert_angle * math.pi) * 90.0 + 90.0
horiz_angle = horiz / (resolution_horizontal-1.0) * 360.0
candela = self.get_candela_value(vert_angle, horiz_angle)
dest.set_xel(vert, horiz, candela)
dest_tex.load(dest, z, 0)
def get_tex_image(tex):
"""Returns image (as PNMImage) in `tex`.
Args:
tex (Texture): Texture handle.
Return:
(PNMImage): Image object.
"""
# Remember to call self.trigger_copy() before
# self.render_frame(), or the next frame won't be pushed to RAM.
if not tex.hasRamImage():
img = None
else:
img = PNMImage()
tex.store(img)
return img
mat = Material()
if prim_material:
for prop in prim_material.supported:
value = getattr(prim_material, prop)
if value is None:
continue
if type(value) is tuple:
val4 = value[3] if len(value) > 3 else 1.0
value = VBase4(value[0], value[1], value[2], val4)
if isinstance(value, collada.material.Map):
image_data = value.sampler.surface.image.data
if image_data:
myImage = PNMImage()
myImage.read(StringStream(image_data), posixpath.basename(value.sampler.surface.image.path))
myTexture = Texture(value.sampler.surface.image.id)
myTexture.load(myImage)
state = state.addAttrib(TextureAttrib.make(myTexture))
elif prop == 'emission':
mat.setEmission(value)
elif prop == 'ambient':
mat.setAmbient(value)
elif prop == 'diffuse':
mat.setDiffuse(value)
elif prop == 'specular':
#mat.setSpecular(value)
pass
elif prop == 'shininess':
mat.setShininess(value)
elif prop == 'reflective':
def load_image(self, category, grayscale=False):
image = PNMImage()
if image.read(self.get_terrain_file_name(category)):
if grayscale:
image.makeGrayscale()
return image
else:
return None
for k in xrange(self.log2Size)]
indicesB = [[0 for i in xrange(self.size)]
for k in xrange(self.log2Size)]
weights = [[Vec2(0.0) for i in xrange(self.size)]
for k in xrange(self.log2Size)]
self.debug("Pre-Generating indices ..")
self._generateIndices(indicesA, indicesB)
self._reverseRow(indicesA[0])
self._reverseRow(indicesB[0])
self.debug("Pre-Generating weights ..")
self._generateWeights(weights)
# Create storage for the weights & indices
self.weightsLookup = PNMImage(self.size, self.log2Size, 4)
self.weightsLookup.setMaxval((2 ** 16) - 1)
self.weightsLookup.fill(0.0)
# Populate storage
for x in xrange(self.size):
for y in xrange(self.log2Size):
indexA = indicesA[y][x]
indexB = indicesB[y][x]
weight = weights[y][x]
self.weightsLookup.setRed(x, y, indexA / float(self.size))
self.weightsLookup.setGreen(x, y, indexB / float(self.size))
self.weightsLookup.setBlue(x, y, weight.x * 0.5 + 0.5)
self.weightsLookup.setAlpha(x, y, weight.y * 0.5 + 0.5)
# Convert storage to texture so we can use it in a shader
def load_nth_face(pth, i):
return PNMImage(pth.replace("#", str(i)))