예제 #1
0
    //
    // Public methods
    //

    public void evaluateAll(MetaBall[] metaballs)
    {
        if (!this.initized)
        {
            this.init();
        }

        this.vertices.Clear();

        // write info about metaballs in format readable by compute shaders
        GPUBall[] gpuBalls = new GPUBall[metaballs.Length];
        for (int i = 0; i < metaballs.Length; i++)
        {
            MetaBall metaball = metaballs[i];
            gpuBalls[i].position = metaball.transform.localPosition;
            gpuBalls[i].factor   = metaball.factor;
        }

        // magic happens here
        GPUEdgeVertices[] edgeVertices = this.runComputeShader(gpuBalls);
        //根据计算结果,更新所有立方参考体的顶点位置。
        // perform rest of the marching cubes algorithm
        for (int x = 0; x < this.width; x++)
        {
            for (int y = 0; y < this.height; y++)
            {
                for (int z = 0; z < this.depth; z++)
                {
                    this.updateVertices2(edgeVertices[x + this.width * (y + this.height * z)]);
                }
            }
        }
    }
예제 #2
0
    //
    // Public methods
    //

    public void evaluateAll(MetaBall[] metaballs)
    {
        if (!this.initized)
        {
            this.init();
        }

        this.vertices.Clear();

        // write info about metaballs in format readable by compute shaders
        GPUBall[] gpuBalls = new GPUBall[metaballs.Length]; // alloc
        for (int i = 0; i < metaballs.Length; i++)
        {
            MetaBall metaball = metaballs[i];
            gpuBalls[i].position = metaball.transform.localPosition;
            gpuBalls[i].factor   = metaball.factor;
        }

        // magic happens here
#if !ASYNC
        GPUEdgeVertices[] edgeVertices = this.runComputeShader(gpuBalls); // alloc
#else
        this.runComputeShaderAsync(gpuBalls);

        GPUEdgeVertices[] edgeVertices = this.GetEdgeVerticesFromAsync();

        if (edgeVertices == null)
        {
            return;
        }
#endif
        Debug.Log("ev lnt: " + edgeVertices.Length + ", total: " + width * height * depth + ", first index: " + edgeVertices[0].index);

        // perform rest of the marching cubes algorithm
        for (int x = 0; x < this.width; x++)
        {
            for (int y = 0; y < this.height; y++)
            {
                for (int z = 0; z < this.depth; z++)
                {
                    this.updateVertices2(edgeVertices[x + this.width * (y + this.height * z)]);
                }
            }
        }
    }