Search Unity

zbrush import Vertex Color rgb

Discussion in 'Asset Importing & Exporting' started by kilik128, May 25, 2014.

  1. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    hi about zbrush export Vertex Color rgb
    i have make try with little cube and see on block note what's we can read about him
    the goal is reimport this in unity i looking on the web and i'm surprised of found nothing about this
    so all help is welcome for sure




     
  2. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    i have start here


    someone have time to look please


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6. public class zbrush : MonoBehaviour {
    7.  
    8.     public string test;
    9.     public Color testco;
    10.    
    11.    
    12.     // Use this for initialization
    13.     void Start () {
    14.  
    15.         //testco = HexToColor (test);
    16.         //ArrayList arr =new ArrayList (test.);
    17.  
    18.         int length = 8;
    19.         int strLength = test.Length;
    20.         int strCount = (strLength + length - 1) / length;
    21.             string[] result = new string[strCount];
    22.  
    23.         for (int i = 0; i < strCount; ++i)
    24.         {
    25.             result[i] = test.Substring(i * length, Mathf.Min(length, strLength));
    26.             strLength -= length;
    27.           }
    28.         // result
    29.         //foreach(string f in result)
    30.         //     Debug.Log(string.Format("[{0}]", f));
    31.  
    32.  
    33.         Mesh mesh = GetComponent<MeshFilter>().mesh;
    34.         Vector3[] vertices = mesh.vertices;
    35.         Color[] colors = new Color[vertices.Length];
    36.  
    37.         Debug.Log (vertices.Length+"  dd  "+result.Length  );
    38.        
    39.         int i2 = 0;
    40.         while (i2 < vertices.Length) {
    41.             colors[i2] =    HexToColor (result[i2].Substring(2,6))  ;   //Color.Lerp(Color.red, Color.green, vertices[i].y);
    42.             i2= i2+2;
    43.         }
    44.        
    45.  
    46.  
    47.  
    48.         mesh.colors = colors;
    49.  
    50.     }
    51.  
    52.  
    53.  
    54.  
    55. Color HexToColor(string hex)
    56.     {
    57.         byte r = byte.Parse(hex.Substring(0,2), System.Globalization.NumberStyles.HexNumber);
    58.         byte g = byte.Parse(hex.Substring(2,2), System.Globalization.NumberStyles.HexNumber);
    59.         byte b = byte.Parse(hex.Substring(4,2), System.Globalization.NumberStyles.HexNumber);
    60.         return new Color32(r,g,b, 255);
    61.     }
    62.  
    63.     // Update is called once per frame
    64.     void Update () {
    65.    
    66.     }
    67. }
    68.  
    69.  
     
    Last edited: May 25, 2014
  3. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    so what's happen i got [vertices.Length] is two length of color
    so only 1/2 is colored and it's not look on good vertex order
    someone can help please
     
  4. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
  5. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    I would see if you could convert that OBJ to FBX outside of Unity. Unity certainly does support loading vertex colors from FBX.
     
  6. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    thank's i have already try this way but yes maybie she exist somethink's for sure
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Use FBX, then use a shader that supports vertex colours.
     
  8. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Zbrush don't export on FBX
    but if get full info how do it
    very interessing by the way
     
  9. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    You can use Blender to import the OBJ and export an FBX.
     
  10. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    thank's i try now
     
  11. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Not Working here any option in blender for import vertex color from zbrush i have make check

    $940p2.png
     
  12. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    OH my god i think's i do it after try with Goz for blender ! oh can say how i many thank's :)