Example #1
0
    int CalRealStep(int i)
    {
        //需要合并,因为采用四叉树,所以需要将当前的index映射成四叉树的坐标,然后根据在四叉树中的位置,判断能合并到的最大的quad
        int max_step = m_list_quad_tree_max_step[i];
        //Debug.Log("[OptimizeMesh-CalMaxStep] index : " + i.ToString() + " max step : " + max_step.ToString());
        int       real_max_step = 1;
        QuadState state         = QuadState.EQS_Normal;

        while (real_max_step <= max_step)
        {
            //迭代合并quad
            QuadState sub_state = CheckQuadState(i, real_max_step);
            if (QuadState.EQS_Normal != sub_state)
            {
                //当前不能合并
                state = sub_state;
                break;
            }
            real_max_step *= 2;
        }

        /*Debug.Log("[OptimizeMeshUtil Quad State Cal Res] index : " + i.ToString()
         + " real_max_step : " + real_max_step.ToString()
         + " state : " + state.ToString());*/
        //clip都是按照最小的size进行
        if (1 == real_max_step)
        {
            if (QuadState.EQS_Clip == state)
            {
                real_max_step = -1;
            }
        }
        else
        {
            real_max_step /= 2;
        }
        return(real_max_step);
    }
Example #2
0
    QuadState CheckQuadState(int index, int step, bool affect_by_all_vertex = true)
    {
        if (step > 1)
        {
            int divide_index = index;
            int size         = 2;
            for (int i = 0; i < size; ++i)
            {
                for (int j = 0; j < size; ++j)
                {
                    divide_index = i * step / 2 * m_height + j * step / 2 + index;
                    QuadState quad_state = CheckQuadState(divide_index, step / 2, false);
                    if (QuadState.EQS_Normal != quad_state)
                    {
                        return(quad_state);
                    }
                }
            }
        }

        //index 设定了quad左下角的起点,step确定quad的大小
        int quad_vetex_count = 4;
        //起点的索引
        int index_x = index % m_width;
        int index_y = index / m_width;

        //quad 4个点的index
        int[] indices =
        {
            index,
            index + step,
            (index_y + step) * m_width + index_x,
            (index_y + step) * m_width + step + index_x,
        };
        float     range      = m_param.Top - m_param.Bottom;
        QuadState state      = QuadState.EQS_Normal;
        int       clip_count = 0;

        for (int i = 0; i < quad_vetex_count; ++i)
        {
            Debug.Log("[OptimizeMeshUtil CheckQuadState] origin index : " + index.ToString() + " vertex index : " + indices[i].ToString() + " step : " + step.ToString());
            VertexState vertex_state = m_list_vertex_state[indices[i]];
            if (VertexState.EQS_Clip == vertex_state)
            {
                if (affect_by_all_vertex)
                {
                    //判断剔除的时候要4个点都可剔除才剔除
                    ++clip_count;
                }
                else
                {
                    //判断合并的时候,有一个clip就不可合并
                    state = QuadState.EQS_Clip;
                    break;
                }
            }
            if (VertexState.EQS_Dirty == vertex_state)
            {
                state = QuadState.EQS_Dirty;
                break;
            }
        }
        if (affect_by_all_vertex && quad_vetex_count == clip_count)
        {
            state = QuadState.EQS_Clip;
        }
        //Debug.Log("[OptimizeMesh-CheckQuadState Res] index : " + index.ToString() + " state : " + state.ToString());
        return(state);
    }