HoloLens绘制图表

时间:2016-11-30 12:44:07

标签: unity3d graph hololens

为HoloLens统一绘制图形的最佳方法是什么? 我是这个平台的新手,不知道哪些软件包可以工作,哪些不用,图表动态获取数据。

编辑:我尝试过LineRenderer,但在Unity版本5.4中看起来非常有限

1 个答案:

答案 0 :(得分:2)

绘制3D图形的可能解决方案是使用粒子系统:

粒子系统的组件脚本的简单示例:

public class Graph: MonoBehaviour {

    //Particle-Resolution of the Graph
    [Range(10, 100)]
    public int resolution = 10;
    private int currentResolution;

    private ParticleSystem.Particle[] points;

    void Start()
    {
        currentResolution = resolution;
        points = new ParticleSystem.Particle[resolution];
        float increment = 1f / (resolution - 1);
        for (int i = 0; i < resolution; i++)
        {
            float x = i * increment;
            points[i].position = new Vector3(x, 0f, 0f);
            points[i].startColor = new Color(0f, 0f, 0f);
            points[i].startSize = 0.1f;
        }
    }
    void Update()
    {
        if ((currentResolution != resolution) || (points == null))
        {
            CreatePoints();
        }

        FunctionDelegate f = functionDelegates[(int)function];
        for (int i = 0; i < points.Length; i++)
        {
            Vector3 p = points[i].position;
            p.y = Sine(p.x);
            points[i].position = p;

            Color c = points[i].GetCurrentColor(GetComponent<ParticleSystem>());
            c.g = p.y;
            c.r = 1f - p.y;
            points[i].startColor = c;
        }

        GetComponent<ParticleSystem>().SetParticles(points, points.Length);
    }

    private static float Sine(float x)
    {
        return 0.5f + 0.5f * Mathf.Sin(2 * Mathf.PI * x + Time.timeSinceLevelLoad);
    }


}

使用CatLikeCoding(Jasper Flick)的粒子系统绘制2D / 3D图形(包括此示例)的好教程。请参阅:http://catlikecoding.com/unity/tutorials/graphs/。它有点过时了,在这种情况下你必须使用startSize / startColor代替depreceated color / size-Properties。

但是我已经用hololens测试了它并且它运行良好。如果您有大量粒子,必须使用HoloToolkit着色器进行一些实验以获得更好的性能: - )

如果您还有其他问题:请问我。