【问题标题】:Coloring 3d model Vuforia Unity着色 3d 模型 Vuforia Unity
【发布时间】:2016-02-09 04:28:03
【问题描述】:

我想实现一个功能,其中特定区域的颜色将由 3d 模型选择。我正在使用 vuforia 和 unity3d 并成功实现了目标检测。在下一步中,我想选择图像的颜色并将该颜色放在 3d 模型上。

很多人已经实现了这个,但我找不到完整的教程。

我也厌倦了使用区域 Cature,但没有成功。

【问题讨论】:

    标签: image unity3d 3d textures vuforia


    【解决方案1】:

    我将获取您所追求的屏幕区域,然后将其放入一个像素数组并平均该数组。

    public Color GetColorFromScreen(int x, int y, int width, int height){
        Texture2D tex = new Texture2D(1, 1);
        tex.ReadPixels(new Rect(x, y, width, height), 0, 0);
        tex.Apply();
        Color [] pix = tex.GetPixels(x, y, width, height);
        float r,g,b,a;
        foreach (Color col in pix){
            r += col.r;
            g += col.g;
            b += col.b;
            a += col.a;
        } 
    
        r /= pix.Length;
        g /= pix.Length;
        b /= pix.Length;
        a /= pix.Length;
        return new Color(r,g,b,a);
    }
    

    然后你抓取模型的材料并应用该颜色

    GetComponent<Renderer>().material.color = GetColorFromScreen(x,y,w,h);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多