Repository: mikedh/trimesh

Issue:
Exported mesh as .obj appears as solid black color by default
Hi, 

I am trying to export a mesh as .obj. The code looks like this:
`export, texture = trimesh.exchange.obj.export_obj(mesh, include_color=True, include_texture=True)`

`with trimesh.util.TemporaryDirectory() as path:`
    `obj_path = os.path.join('', 'file_name.obj')`
    `with open(obj_path, 'w') as f:`
        `f.write(export)`
    `for k, v in texture.items():`
        `with open(os.path.join('', k), 'wb') as f:`
            `f.write(v)`

When this obj is loaded again, the model appears in solid black color. As expected the mesh must conserve its color coordinates. I also tried to visualize it in blender API and it displays the mesh in black color by default (as seen in the below image). 

![mesh](https://user-images.githubusercontent.com/22175791/82459996-e8e1e600-9ab8-11ea-9fbe-bf585f2ae5d0.png)

I get the colored model only after changing the mode (display rendered preview in blender api). Could you please tell me how I can get the colored model by default when I load the exported mesh?

Used trimesh version: `3.6.38`

Thank you!

Discussion:

Patch:
diff --git a/trimesh/exchange/dae.py b/trimesh/exchange/dae.py
index 681dc1cd..60c1b43b 100644
--- a/trimesh/exchange/dae.py
+++ b/trimesh/exchange/dae.py
@@ -312,7 +312,8 @@ def _parse_material(effect, resolver):
     # Compute opacity
     if (effect.transparent is not None
             and not isinstance(effect.transparent, collada.material.Map)):
-        baseColorFactor = tuple(np.append(baseColorFactor[:3], effect.transparent[3]))
+        baseColorFactor = tuple(
+            np.append(baseColorFactor[:3], float(int(255 * effect.transparent[3]))))
 
     return visual.material.PBRMaterial(
         emissiveFactor=emissiveFactor,
diff --git a/trimesh/version.py b/trimesh/version.py
index 9b73fde9..f2a6f705 100644
--- a/trimesh/version.py
+++ b/trimesh/version.py
@@ -1,1 +1,1 @@
-__version__ = '3.6.42'
+__version__ = '3.6.43'
diff --git a/trimesh/visual/color.py b/trimesh/visual/color.py
index 682fc53b..961f6044 100644
--- a/trimesh/visual/color.py
+++ b/trimesh/visual/color.py
@@ -439,7 +439,7 @@ class ColorVisuals(Visuals):
         return color
 
     def to_texture(self):
-        from .materials import from_color
+        from .material import from_color
         from .texture import TextureVisuals
         mat, uv = from_color(vertex_colors=self.vertex_colors)
         return TextureVisuals(material=mat, uv=uv)
@@ -584,7 +584,7 @@ def to_rgba(colors, dtype=np.uint8):
             opaque * np.ones(len(colors)))).astype(dtype)
     elif util.is_shape(colors, (3,)):
         # if passed a single RGB color add an alpha
-        colors = np.append(colors, opaque)
+        colors = np.append(colors, opaque).astype(dtype)
 
     if not (util.is_shape(colors, (4,)) or
             util.is_shape(colors, (-1, 4))):
diff --git a/trimesh/visual/material.py b/trimesh/visual/material.py
index 9a750927..4ac7a2d3 100644
--- a/trimesh/visual/material.py
+++ b/trimesh/visual/material.py
@@ -94,10 +94,10 @@ class SimpleMaterial(Material):
         mtl = '\n'.join(
             ['# https://github.com/mikedh/trimesh',
              'newmtl {}'.format(tex_name),
-             'Ka {} {} {}'.format(*Ka),
-             'Kd {} {} {}'.format(*Kd),
-             'Ks {} {} {}'.format(*Ks),
-             'Ns {}'.format(self.glossiness),
+             'Ka {:0.8f} {:0.8f} {:0.8f}'.format(*Ka),
+             'Kd {:0.8f} {:0.8f} {:0.8f}'.format(*Kd),
+             'Ks {:0.8f} {:0.8f} {:0.8f}'.format(*Ks),
+             'Ns {:0.8f}'.format(self.glossiness),
              'map_Kd {}'.format(image_name)])
 
         # save the image texture as bytes in the original format
diff --git a/trimesh/voxel/ops.py b/trimesh/voxel/ops.py
index 30745214..71993f91 100644
--- a/trimesh/voxel/ops.py
+++ b/trimesh/voxel/ops.py
@@ -100,7 +100,7 @@ fill_voxelization = fill_base
 
 def matrix_to_marching_cubes(matrix, pitch=1.0):
     """
-    Convert an (n,m,p) matrix into a mesh, using marching_cubes.
+    Convert an (n, m, p) matrix into a mesh, using marching_cubes.
 
     Parameters
     -----------


Test patch:
diff --git a/tests/test_texture.py b/tests/test_texture.py
index f9cfb0a4..47768d98 100644
--- a/tests/test_texture.py
+++ b/tests/test_texture.py
@@ -119,6 +119,17 @@ class TextureTest(g.unittest.TestCase):
         assert g.np.allclose(c.visual.material.image.size,
                              a.visual.material.image.size)
 
+    def test_to_tex(self):
+
+        m = g.trimesh.creation.box()
+        color = [255, 0, 0, 255]
+        m.visual.face_colors = color
+        # convert color visual to texture
+        m.visual = m.visual.to_texture()
+        # convert back to color
+        m.visual = m.visual.to_color()
+        assert g.np.allclose(m.visual.main_color, color)
+
 
 if __name__ == '__main__':
     g.trimesh.util.attach_to_log()