Skip to content

Commit

Permalink
add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Dec 31, 2018
1 parent f62dcaf commit 4790232
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions trimesh/visual/objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
objects.py
--------------
Deal with objects which hold visual properties, like
ColorVisuals and TextureVisuals.
"""
import numpy as np
import collections

from .color import ColorVisuals


def create_visual(**kwargs):
"""
Create Visuals object from keyword arguments.
Parameters
----------
face_colors : (n,3|4) uint8, colors
vertex_colors : (n,3|4) uint8, colors
mesh: Trimesh object
Returns
----------
visuals: ColorVisuals object.
"""
return ColorVisuals(**kwargs)


def concatenate(visuals, *args):
"""
Concatenate multiple visual objects.
Parameters
----------
visuals: ColorVisuals object, or list of same
*args: ColorVisuals object, or list of same
Returns
----------
concat: ColorVisuals object
"""
# get a flat list of ColorVisuals objects
if len(args) > 0:
visuals = np.append(visuals, args)
else:
visuals = np.array(visuals)

# get the type of visuals (vertex or face) removing undefined
modes = {v.kind for v in visuals}.difference({None})
if len(modes) == 0:
# none of the visuals have anything defined
return ColorVisuals()
else:
# if we have visuals with different modes defined
# arbitrarily get one of them
mode = modes.pop()

# a linked list to store colors before stacking
colors = collections.deque()
# a string to evaluate which returns the colors we want
append = 'v.{}_colors'.format(mode)
for v in visuals:
# use an eval so we can use the object property
colors.append(eval(append))
# use an eval so we can use the constructor
concat = eval('ColorVisuals({}_colors=np.vstack(colors))'.format(mode))
return concat

0 comments on commit 4790232

Please sign in to comment.