Example #1
0
    public void Reset(Vector2 bottomLeftCoordinates, Vector3 topRightCoordinates)
    {
        Vector3 meshSize = GetComponent <MeshRenderer> ().bounds.size;

        if (meshSize.x != meshSize.z)
        {
            Debug.LogWarning("LOD plane must be square (currently: " +
                             meshSize.x +
                             "x" +
                             meshSize.y +
                             ")");
        }

        float mapSize = Mathf.Max(meshSize.x, meshSize.z);

        rootNode = new QuadtreeLODNode(
            mapSize,
            20,
            bottomLeftCoordinates,
            topRightCoordinates,
            transform,
            this.GetComponent <Material>()
            );
        GetComponent <MeshRenderer> ().enabled = false;
    }
Example #2
0
    private void CreateChildren(Vector3 meshSize)
    {
        Vector3 S = new Vector3(
            1.0f / transform_.lossyScale.x,
            1.0f / transform_.lossyScale.y,
            1.0f / transform_.lossyScale.z
            );

        Vector3[] childLocalPosition = new Vector3[]
        {
            Vector3.Scale(new Vector3(-meshSize.x / 4, 0, meshSize.z / 4), S),
            Vector3.Scale(new Vector3(-meshSize.x / 4, 0, -meshSize.z / 4), S),
            Vector3.Scale(new Vector3(meshSize.x / 4, 0, meshSize.z / 4), S),
            Vector3.Scale(new Vector3(meshSize.x / 4, 0, -meshSize.z / 4), S)
        };

        float x0 = bottomLeftCoordinates_.x;
        float y0 = bottomLeftCoordinates_.y;
        float x1 = topRightCoordinates_.x;
        float y1 = topRightCoordinates_.y;

        float cx = (x0 + x1) / 2.0f;
        float cy = (y0 + y1) / 2.0f;

        Vector2[] childrenBottomLeftCoordinates = new Vector2[]
        {
            new Vector2(x0, cy),
            new Vector2(x0, y0),
            new Vector2(cx, cy),
            new Vector2(cx, y0)
        };

        Vector2[] childrenTopLeftCoordinates = new Vector2[]
        {
            new Vector2(cx, y1),
            new Vector2(cx, cy),
            new Vector2(x1, y1),
            new Vector2(x1, cy)
        };

        Color[] childrenColors = new Color[]
        {
            new Color(1.0f, 0.0f, 0.0f, 1.0f),
            new Color(0.0f, 1.0f, 0.0f, 1.0f),
            new Color(0.0f, 0.0f, 1.0f, 1.0f),
            new Color(1.0f, 1.0f, 0.0f, 1.0f)
        };

        for (int i = 0; i < 4; i++)
        {
            children_[i] = new QuadtreeLODNode(this, childrenColors[i], childLocalPosition[i], childrenBottomLeftCoordinates[i], childrenTopLeftCoordinates[i]);
        }

        int CHILDREN_RESOLUTION = meshVertexResolution_ * 2 - 1;

        Debug.Log(CHILDREN_RESOLUTION);
        childrenHeightMapRequest = RequestHeightMap(bottomLeftCoordinates_, topRightCoordinates_, CHILDREN_RESOLUTION);
    }
Example #3
0
 private void PrintHeightsColumn(QuadtreeLODNode node, int column)
 {
     Debug.LogFormat("Heights column[{0}]: {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
                     column,
                     node.mesh_.vertices [column].y,
                     node.mesh_.vertices [column + 11].y,
                     node.mesh_.vertices [column + 22].y,
                     node.mesh_.vertices [column + 33].y,
                     node.mesh_.vertices [column + 44].y,
                     node.mesh_.vertices [column + 55].y,
                     node.mesh_.vertices [column + 66].y,
                     node.mesh_.vertices [column + 77].y,
                     node.mesh_.vertices [column + 88].y,
                     node.mesh_.vertices [column + 99].y,
                     node.mesh_.vertices [column + 110].y);
 }
Example #4
0
    private void PrintHeightsRow(QuadtreeLODNode node, int row)
    {
        int FIRST_ROW_VERTEX_INDEX = row * 11;

        Debug.LogFormat("Heights row[{0}]: {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
                        row,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 0].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 1].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 2].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 3].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 4].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 5].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 6].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 7].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 8].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 9].y,
                        node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX + 10].y);
    }
Example #5
0
    public QuadtreeLODNode(QuadtreeLODNode parent, Color color, Vector3 localPosition, Vector2 bottomLeftCoordinates, Vector2 topRightCoordinates)
    {
        gameObject_ = GameObject.Instantiate(new GameObject());
        gameObject_.AddComponent <MeshRenderer>();

        // Copy given mesh.
        mesh_           = new Mesh();
        mesh_.vertices  = parent.mesh_.vertices;
        mesh_.triangles = parent.mesh_.triangles;
        mesh_.uv        = parent.mesh_.uv;
        mesh_.RecalculateNormals();
        mesh_.RecalculateBounds();
        meshVertexResolution_ = parent.meshVertexResolution_;
        gameObject_.AddComponent <MeshFilter> ().mesh = mesh_;

        // Make this mesh transform relative to parent.
        transform_        = gameObject_.transform;
        transform_.parent = parent.gameObject_.transform;

        transform_.localScale    = new Vector3(0.5f, 1.0f, 0.5f);
        transform_.localPosition = localPosition;

        material_ = new Material(Shader.Find("Standard"));
        gameObject_.GetComponent <Renderer>().material = material_;
#if PAINT_QUADS
        material_.color = color;
#endif
        depth_ = parent.depth_ + 1;

        visible_ = false;
        gameObject_.GetComponent <MeshRenderer> ().enabled = false;

        bottomLeftCoordinates_ = bottomLeftCoordinates;
        topRightCoordinates_   = topRightCoordinates;

        LoadMap();

        children_ = new QuadtreeLODNode[] { null, null, null, null };
    }
    public QuadtreeLODNode( QuadtreeLODNode parent, Color color, Vector3 localPosition, Vector2 bottomLeftCoordinates, Vector2 topRightCoordinates )
    {
        gameObject_ = GameObject.Instantiate( new GameObject() );
        gameObject_.AddComponent<MeshRenderer>();

        // Copy given mesh.
        mesh_ = new Mesh ();
        mesh_.vertices = parent.mesh_.vertices;
        mesh_.triangles = parent.mesh_.triangles;
        mesh_.uv = parent.mesh_.uv;
        mesh_.RecalculateNormals ();
        mesh_.RecalculateBounds ();
        meshVertexResolution_ = parent.meshVertexResolution_;
        gameObject_.AddComponent<MeshFilter> ().mesh = mesh_;

        // Make this mesh transform relative to parent.
        transform_ = gameObject_.transform;
        transform_.parent = parent.gameObject_.transform;

        transform_.localScale = new Vector3( 0.5f, 1.0f, 0.5f );
        transform_.localPosition = localPosition;

        material_ = new Material (Shader.Find ("Standard"));
        gameObject_.GetComponent<Renderer>().material = material_;
        #if PAINT_QUADS
        material_.color = color;
        #endif
        depth_ = parent.depth_ + 1;

        visible_ = false;
        gameObject_.GetComponent<MeshRenderer> ().enabled = false;

        bottomLeftCoordinates_ = bottomLeftCoordinates;
        topRightCoordinates_ = topRightCoordinates;

        LoadMap ();

        children_ = new QuadtreeLODNode[]{ null, null, null, null };
    }
    public void Reset( Vector2 bottomLeftCoordinates, Vector3 topRightCoordinates )
    {
        Vector3 meshSize = GetComponent<MeshRenderer> ().bounds.size;
        if (meshSize.x != meshSize.z) {
            Debug.LogWarning ("LOD plane must be square (currently: " +
                              meshSize.x +
                              "x" +
                              meshSize.y +
                              ")");
        }

        float mapSize = Mathf.Max ( meshSize.x, meshSize.z );

        rootNode = new QuadtreeLODNode(
                                       mapSize,
                                       20,
                                       bottomLeftCoordinates,
                                       topRightCoordinates,
                                       transform,
                                       this.GetComponent<Material>()
                                       );
        GetComponent<MeshRenderer> ().enabled = false;
    }
 private void PrintHeightsRow( QuadtreeLODNode node, int row )
 {
     int FIRST_ROW_VERTEX_INDEX = row * 11;
     Debug.LogFormat ("Heights row[{0}]: {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
                      row,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+0].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+1].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+2].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+3].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+4].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+5].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+6].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+7].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+8].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+9].y,
                      node.mesh_.vertices [FIRST_ROW_VERTEX_INDEX+10].y);
 }
 private void PrintHeightsColumn( QuadtreeLODNode node, int column )
 {
     Debug.LogFormat ("Heights column[{0}]: {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
                      column,
                      node.mesh_.vertices [column].y,
                      node.mesh_.vertices [column+11].y,
                      node.mesh_.vertices [column+22].y,
                      node.mesh_.vertices [column+33].y,
                      node.mesh_.vertices [column+44].y,
                      node.mesh_.vertices [column+55].y,
                      node.mesh_.vertices [column+66].y,
                      node.mesh_.vertices [column+77].y,
                      node.mesh_.vertices [column+88].y,
                      node.mesh_.vertices [column+99].y,
                      node.mesh_.vertices [column+110].y);
 }
    private void CreateChildren( Vector3 meshSize )
    {
        Vector3 S = new Vector3(
            1.0f / transform_.lossyScale.x,
            1.0f / transform_.lossyScale.y,
            1.0f / transform_.lossyScale.z
            );
        Vector3[] childLocalPosition = new Vector3[]
        {
            Vector3.Scale ( new Vector3( -meshSize.x/4,0,meshSize.z/4 ), S ),
            Vector3.Scale ( new Vector3( -meshSize.x/4,0,-meshSize.z/4 ), S ),
            Vector3.Scale ( new Vector3( meshSize.x/4,0,meshSize.z/4), S ),
            Vector3.Scale ( new Vector3( meshSize.x/4,0,-meshSize.z/4), S )
        };

        float x0 = bottomLeftCoordinates_.x;
        float y0 = bottomLeftCoordinates_.y;
        float x1 = topRightCoordinates_.x;
        float y1 = topRightCoordinates_.y;

        float cx = (x0 + x1)/2.0f;
        float cy = (y0 + y1)/2.0f;

        Vector2[] childrenBottomLeftCoordinates = new Vector2[]
        {
            new Vector2( x0, cy ),
            new Vector2( x0, y0 ),
            new Vector2( cx, cy ),
            new Vector2( cx, y0 )
        };

        Vector2[] childrenTopLeftCoordinates = new Vector2[]
        {
            new Vector2( cx, y1 ),
            new Vector2( cx, cy ),
            new Vector2( x1, y1 ),
            new Vector2( x1, cy )
        };

        Color[] childrenColors = new Color[]
        {
            new Color( 1.0f, 0.0f, 0.0f, 1.0f ),
            new Color( 0.0f, 1.0f, 0.0f, 1.0f ),
            new Color( 0.0f, 0.0f, 1.0f, 1.0f ),
            new Color( 1.0f, 1.0f, 0.0f, 1.0f )
        };

        for( int i=0; i<4; i++ ){
            children_[i] = new QuadtreeLODNode( this, childrenColors[i], childLocalPosition[i], childrenBottomLeftCoordinates[i], childrenTopLeftCoordinates[i] );
        }

        int CHILDREN_RESOLUTION = meshVertexResolution_ * 2 - 1;
        Debug.Log (CHILDREN_RESOLUTION);
        childrenHeightMapRequest = RequestHeightMap (bottomLeftCoordinates_, topRightCoordinates_, CHILDREN_RESOLUTION );
    }