コード例 #1
0
    void Start()
    {
        int     step          = 1;
        int     patchSize     = 50;
        Vector3 startPosition = new Vector3();

        for (int y = 0; y <= patchSize; y++)
        {
            for (int x = 0; x <= patchSize; x++)
            {
                Vector3 offset         = startPosition + (Vector3.right * step * x) + (Vector3.up * step * y);
                bool    buildTriangles = x > 0 && y > 0;
                Vector2 uv             = new Vector2();
                bool    swapOrder      = x % 2 == y % 2 ? true: false;
                ProceduralQuad.BuildQuadForGrid(_meshBuilder, offset, uv, buildTriangles, patchSize + 1, swapOrder);
            }
        }
        mesh = _meshBuilder.CreateMesh();
        MeshProvider mp = new MeshProvider(32);

        mesh  = mp.GetStandardMesh();
        mesh1 = Instantiate(PlanetMeshPrefab) as GameObject;
        mesh2 = Instantiate(PlanetMeshPrefab) as GameObject;

        go = new GameObject();
        go.AddComponent("MeshFilter");
        go.AddComponent("MeshRenderer");
//		go.transform.Translate (Vector3.right * 50);

//		mesh1.transform.Translate (Vector3.right * 100);
    }
コード例 #2
0
    private MeshBuilder CreateMesh(MeshBuilder meshBuilder)
    {
        float step = 1f / (_patchSize);

        for (int y = 0; y <= _patchSize; y++)
        {
            for (int x = 0; x <= _patchSize; x++)
            {
                Vector3 offset = (_widthDir * step * x) + (_heightDir * step * y);
//				Vector3 normal = Vector3.Cross(_widthDir, _heightDir);
                Vector2 uv = new Vector2(x, y);

                bool buildTriangles = x > 0 && y > 0;

                bool swapOrder = x % 2 == y % 2 ? true: false;

//				ProceduralQuad.BuildQuadForGrid (meshBuilder, offset, normal, uv, buildTriangles, _patchSize + 1, swapOrder);
                ProceduralQuad.BuildQuadForGrid(meshBuilder, offset, uv, buildTriangles, _patchSize + 1, swapOrder);
            }
        }
        return(meshBuilder);
    }