Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.name = camel_to_snake(self.type)
self.enabled = True # disabled entities wil not be visible nor run code
self.visible = True
self.ignore = False # if True, will not try to run code
self.eternal = False # eternal entities does not get destroyed on scene.clear()
self.ignore_paused = False
self.ignore_input = False
self.parent = scene
self.add_to_scene_entities = add_to_scene_entities # set to False to be ignored by the engine, but still get rendered.
if add_to_scene_entities:
scene.entities.append(self)
self.model = None # set model with model='model_name' (without file type extention)
self.color = color.white
self.texture = None # set model with texture='texture_name'. requires a model to be set beforehand.
self.reflection_map = scene.reflection_map
self.reflectivity = 0
self.render_queue = 0
self.double_sided = False
# self.always_on_top = False
self.collision = False # toggle collision without changing collider.
self.collider = None # set to 'box'/'sphere'/'mesh' for auto fitted collider.
self.scripts = list() # add with add_script(class_instance). will assign an 'entity' variable to the script.
self.animations = list()
self.hovered = False # will return True if mouse hovers entity.
self.origin = Vec3(0,0,0)
self.position = Vec3(0,0,0) # right, up, forward. can also set self.x, self.y, self.z
self.rotation = Vec3(0,0,0) # can also set self.rotation_x, self.rotation_y, self.rotation_z
def __add__(self, other):
self.vertices += other.vertices
self.triangles += other.triangles
if other.colors:
self.colors += other.colors
else:
self.colors += (color.white, ) * len(other.vertices)
self.normals += other.normals
self.uvs += other.uvs
def colorize(model, left=color.white, right=color.blue, down=color.red, up=color.green, back=color.white, forward=color.white, smooth=True, world_space=True):
if not model.normals:
print('generating normals for', model)
model.generate_normals(smooth=smooth)
if world_space:
normals = get_world_normals(model)
else:
normals = model.normals
cols = list()
prev_col = color.white
for n in normals:
# c = color.rgb((n[0]/2)+.5, (n[1]/2)+.5, (n[2]/2)+.5)
c = lerp(down, up, (n[1]/2 +.5))
if n[0] < 0:
c = lerp(c, left, -(n[0]/2))
else:
c = lerp(c, right, (n[0]/2))
if n[2] < 0:
c = lerp(c, back, -(n[2]/2))
else:
c = lerp(c, forward, (n[2]/2))
has_nan = False
for e in c: