예제 #1
0
    /// <summary>
    /// 获取新生对象
    /// </summary>
    /// <returns></returns>
    private GameObject GetNewGameObject(PairedIndex <OrganIndex> pairedOrganIndex)
    {
        GameObject cloneObject = GameObject.Instantiate(pairedOrganIndex.CurIndex.Belong);

        /*
         * 因枝干顶点已经调整完毕
         * 故可用后一关键帧中枝干所指的顶点索引确定前一关键帧顶点的位置
         */
        Vector3 position = TreeModel.GetBranchTopCenter(m_PreGameObjects[0], pairedOrganIndex.CurIndex.From);

        foreach (GameObject _subObject in GameObjectOperation.GetGameObjects(cloneObject))
        {
            if (!GameObjectValidate.HavaVertices(_subObject))
            {
                continue;
            }

            Vector3[] vertices = GameObjectOperation.GetVertices(_subObject);

            //该对象所有顶点均为该位置
            CopyVertices(_subObject.transform.InverseTransformPoint(position), vertices);
            GameObjectOperation.UpdateMeshInfo(_subObject, vertices);
        }

        //设置阈值为0
        GameObjectOperation.SetThreshold(cloneObject, 0);

        return(cloneObject);
    }
예제 #2
0
    private void CreateBranchModel()
    {
        /*
         * 更新枝干数据
         * 否则不会显示
         */
        GameObjectOperation.UpdateMeshInfo(BranchModel, temp_Vertices.ToArray(), temp_UV.ToArray(), temp_Triangles.ToArray());

        TempVariablesInit();

        /*
         * 养分
         */
        Material material = GameObjectOperation.GetMaterial(BranchModel);

        switch (EnvironmentParams.NutrientType)
        {
        case LightResponseType.N_LACK:
            //material.SetColor("_Color", MaizeParams.lackN_Color);
            break;

        case LightResponseType.P_LACK:
            material.SetColor("_Color", MaizeParams.lackP_Color);
            break;

        case LightResponseType.K_LACK:
            material.SetColor("_Color", MaizeParams.lackK_Color);
            break;
        }
    }
예제 #3
0
    /// <summary>
    /// 调整前后枝干的顶点
    /// </summary>
    private void AdjustBranch()
    {
        if (m_PairedBranchIndexes.Count == 1 && m_PairedBranchIndexes[0].PreIndex == null)
        {
            AdjustFreshBranch();
            return;
        }

        /*
         * 获取前后两个关键帧的枝干对象
         * 用于后续获取顶点以及更改顶点
         */
        GameObject preBranch = m_PairedBranchIndexes[0].PreIndex.Belong;
        GameObject curBranch = m_PairedBranchIndexes[0].CurIndex.Belong;

        Vector3[] preVertices = GameObjectOperation.GetVertices(preBranch);
        Vector3[] vertices    = new Vector3[GameObjectOperation.GetVertices(curBranch).Length]; //该顶点数组用于存放修改后的前关键帧顶点

        /*
         * 遍历已经匹配好的Index
         * 根据PairedIndex中记录的前后Index的数据
         * 对前后关键帧中枝干的数据进行修改
         */
        foreach (PairedIndex <BranchIndex> pairedBranchIndex in m_PairedBranchIndexes)
        {
            BranchIndex preBranchIndex = pairedBranchIndex.PreIndex;
            BranchIndex curBranchIndex = pairedBranchIndex.CurIndex;

            if (curBranchIndex.IsFirstBranch() && preBranchIndex.IsFirstBranch())   //均为第一个枝干
            {
                CopyVertices(preVertices, preBranchIndex.BottomVerticesIndex, vertices, curBranchIndex.BottomVerticesIndex, 40);
            }
            else if (preBranchIndex != null) //若存在匹配的第一个关键帧的枝干索引,则将第一个关键帧枝干索引指向的顶点插入到第二个关键帧枝干索引指向的顶点位置中
            {
                CopyVertices(preVertices, preBranchIndex.TopVerticesIndex, vertices, curBranchIndex.TopVerticesIndex);
            }
            else//若第二个关键帧枝干不存在匹配的第一个关键帧枝干索引,则遍历其前驱,直至有存在的第一个关键帧枝干索引,并将该枝干索引指向的顶点插入到第二个关键帧枝干索引指向的顶点位置中
            {
                CopyVertices(vertices, curBranchIndex.Previous.TopVerticesIndex, vertices, curBranchIndex.TopVerticesIndex);
            }
        }

        //更新对象
        GameObjectOperation.UpdateMeshInfo(preBranch, vertices, GameObjectOperation.GetUV(curBranch), GameObjectOperation.GetTriangleIndexes(curBranch));

        AddPreObject(preBranch);
        AddCurObject(curBranch);
    }
예제 #4
0
    private void AdjustFreshBranch()
    {
        GameObject curBranch = m_PairedBranchIndexes[0].CurIndex.Belong;
        GameObject preBranch = GameObject.Instantiate(curBranch);

        /*
         * 摧毁所有的子对象
         * 防止重复
         */
        GameObjectOperation.DestroyAllChildren(preBranch);

        Vector3[] vertices = GameObjectOperation.GetVertices(curBranch);

        //CopyVertices(curBranch.transform.InverseTransformPoint(Vector3.zero), vertices);
        CopyVertices(TreeModel.GetBranchBottomCenter(curBranch, m_PairedBranchIndexes[0].CurIndex), vertices);

        GameObjectOperation.UpdateMeshInfo(preBranch, vertices);


        AddPreObject(preBranch);
        AddCurObject(curBranch);
    }
예제 #5
0
    /// <summary>
    /// 更新该帧内的对象
    /// </summary>
    private void UpdateGameObject(GameObject preGameObject, GameObject curGameObject, List <Vector3> veticesFragment, WormholeFragment wormholeFragment)
    {
        if (m_AnimationIndex < m_AnimationMaxIndex)
        {
            /*
             * 若该片段为NULL或该片段的个数为0
             * 则说明该对象无顶点
             * 不继续进行计算
             */
            if (!GameObjectValidate.HavaVertices(preGameObject) || veticesFragment == null)
            {
                return;                                                                             //09-05
            }
            //09-05
            if (veticesFragment.Count != 0)
            {
                Vector3[] vertices = GameObjectOperation.GetVertices(preGameObject);

                /*
                 * 根据片段中记录的顶点偏移数据
                 * 计算对象在该帧移动后的位置
                 * 其中该片段记录的是世界坐标系下的数据
                 * 因此要转换成对象所在的局部坐标系下
                 */
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i] += veticesFragment[i];
                }

                /*
                 * 更新该对象
                 * 防止渲染出现异常
                 */
                GameObjectOperation.UpdateMeshInfo(preGameObject, vertices);
            }

            /*
             * 虫洞逐帧变化模拟
             * 当阈值增量为0,说明不变化
             * 当阈值增量不为0
             * 开启虫洞模拟 (_SimWormhole的值为1),并赋予相应的阈值
             */
            if (wormholeFragment.ThresholdDetla == 0)
            {
                return;
            }

            Material material = GameObjectOperation.GetMaterial(preGameObject);
            if (material == null || material.shader.name != "Custom/Leaves")
            {
                return;
            }

            material.SetFloat("_SimWormhole", 1);
            material.SetColor("_Threshold",
                              CellularTexture.DEC2Color(wormholeFragment.InitThreshold + (int)(wormholeFragment.ThresholdDetla * m_AnimationIndex))
                              );
        }
        else //最后一帧
        {
            /*
             * 无需计算
             * 只需设置前一关键帧的对象不可见
             * 后一帧对象可见即可
             */
            preGameObject.SetActive(false);
            curGameObject.SetActive(true);

            GameObjectOperation.ClearMaterials(preGameObject);
            GameObjectOperation.ClearMeshes(preGameObject);

            GameObject.Destroy(preGameObject);
        }
    }