@@ -162,14 +162,7 @@ def color(self, value):
162162
163163 default_color = (0.95 , 0.5 , 0.25 , 1.0 )
164164
165- if isinstance (value , tuple ):
166- value = list (value )
167-
168- if isinstance (value , list ):
169- if len (value ) == 3 :
170- value .append (1.0 )
171- value = tuple (value )
172- elif isinstance (value , str ):
165+ if isinstance (value , str ):
173166 if _mpl :
174167 try :
175168 value = mpc .to_rgba (value )
@@ -183,6 +176,17 @@ def color(self, value):
183176 'Install using: pip install matplotlib' )
184177 elif value is None :
185178 value = default_color
179+ else :
180+
181+ value = np .array (value )
182+
183+ if np .any (value > 1.0 ):
184+ value = value / 255.0
185+
186+ if value .shape [0 ] == 3 :
187+ value = np .r_ [value , 1.0 ]
188+
189+ value = tuple (value )
186190
187191 self ._color = value
188192
@@ -324,10 +328,10 @@ class Mesh(Shape):
324328
325329 """
326330
327- def __init__ (self , filename = None , scale = [1 , 1 , 1 ], base = None ):
331+ def __init__ (self , filename = None , scale = [1 , 1 , 1 ], base = None , color = None ):
328332 super (Mesh , self ).__init__ (
329333 filename = filename , base = base ,
330- scale = scale , stype = 'mesh' )
334+ scale = scale , stype = 'mesh' , color = color )
331335
332336 def _init_pob (self ):
333337 name , file_extension = os .path .splitext (self .filename )
@@ -359,10 +363,10 @@ class Cylinder(Shape):
359363
360364 """
361365
362- def __init__ (self , radius , length , base = None ):
366+ def __init__ (self , radius , length , base = None , color = None ):
363367 super (Cylinder , self ).__init__ (
364368 base = base , radius = radius , length = length ,
365- stype = 'cylinder' )
369+ stype = 'cylinder' , color = color )
366370
367371 def _init_pob (self ):
368372 col = p .createCollisionShape (
@@ -388,9 +392,9 @@ class Sphere(Shape):
388392
389393 """
390394
391- def __init__ (self , radius , base = None ):
395+ def __init__ (self , radius , base = None , color = None ):
392396 super (Sphere , self ).__init__ (
393- base = base , radius = radius , stype = 'sphere' )
397+ base = base , radius = radius , stype = 'sphere' , color = color )
394398
395399 def _init_pob (self ):
396400 col = p .createCollisionShape (
@@ -415,8 +419,9 @@ class Box(Shape):
415419
416420 """
417421
418- def __init__ (self , scale , base = None ):
419- super (Box , self ).__init__ (base = base , scale = scale , stype = 'box' )
422+ def __init__ (self , scale , base = None , color = None ):
423+ super (Box , self ).__init__ (
424+ base = base , scale = scale , stype = 'box' , color = color )
420425
421426 def _init_pob (self ):
422427
0 commit comments