HoloLens Draw a graph

五迷三道 提交于 2019-12-12 09:10:34

问题


What is the best way to draw a graph for the HoloLens in unity? I am new to this platform and have no idea which packages will work and which dont, the graph gets data dynamically.

EDIT: I have tried LineRenderer but it seems very limited in version 5.4 of Unity


回答1:


A possible Solution for drawing a 3D-Graph is using a particle system:

Simple Example for a Component Script for a particle system:

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);
    }


}

A good tutorial for drawing 2D/3D graphs (including this example) with a particle system from CatLikeCoding (Jasper Flick). Refer to: http://catlikecoding.com/unity/tutorials/graphs/. It's a bit outdated and you must use startSize/startColor instead the depreceated color/size-Properties in this case.

But i'have testet it with the hololens allready and it worked fine. Some experiments with the HoloToolkit shaders for a better performance are necessary if you have a big amount of particles :-)

If you have further questions: Just ask me.



来源:https://stackoverflow.com/questions/40888714/hololens-draw-a-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!