Search code examples
c#unity-game-enginegrasshopperrhino3d

How to export vertex color baked from Grasshopper,Rhino3d’ analyses in game engines like Unity, Unreal or directly in the webXr in real time?


I am pretty new to this community.

I was wondering how to export Vertex color of Karamba, Ladybug’s analysis (color mapping) from Grasshopper/Rhino 3D in order to create an AR application (with unity, unreal or other)?

I am trying to visualize the analysis, that I baked in Rhino from other grasshopper plug-in like ladybug, karamba, honeybee, butterfly, in unity or unreal. And also, I would like to understand more deeply how the texture, materials and shaders work in Rhino and Unity within the GPU.


Solution

  • Rhino6 Support Export Vertex Color, You can also use from Ladybug Texture Mixer from Antonello di Nunzio that can do the work, replacing the colour vertex with Texture and Material.

    def makeTexture(size, colorTree):
        sb = size * 2 - 1
        bm = System.Drawing.Bitmap(size * 2, size * 2)
        bmb = System.Drawing.Bitmap(size * 4, size * 4)
    
        count = -1
        for x in xrange(size):
            for y in xrange(size):
                count += 1
                if count < len(colorTree):
                    bm.SetPixel((x * 2) + 0, sb - ((y * 2) + 0), colorTree[count][0])
                    bm.SetPixel((x * 2) + 1, sb - ((y * 2) + 0), colorTree[count][1])
                   bm.SetPixel((x * 2) + 1, sb - ((y * 2) + 1), colorTree[count][2])
                    bm.SetPixel((x * 2) + 0, sb - ((y * 2) + 1), colorTree[count][3])
    
        g = System.Drawing.Graphics.FromImage(bmb)
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor
       g.DrawImage(bm, 0, 0, size * 4 + 1, size * 4 + 1)
    
        return bmb