Ejemplo n.º 1
0
        public Vector3 GetLoopAxis(RTBranchPoint rtBranchPoint, RTBranchContainer rtBranchContainer, RTIvyContainer rtIvyContainer, GameObject ivyGo)
        {
            Vector3 axis = Vector3.zero;

            if (rtBranchPoint.index == 0 && rtBranchContainer.branchNumber == 0)
            {
                axis = ivyGo.transform.up;
            }
            else
            {
                if (rtBranchPoint.index == 0)
                {
                    axis = rtBranchPoint.GetNextPoint().point - rtBranchPoint.point;
                }
                else
                {
                    axis = Vector3.Normalize(Vector3.Lerp(rtBranchPoint.point - rtBranchPoint.GetPreviousPoint().point,
                                                          rtBranchPoint.GetNextPoint().point - rtBranchPoint.point, 0.5f));
                }
            }

            return(axis);
        }
Ejemplo n.º 2
0
        public void BuildGeometry02(List <RTBranchContainer> activeBakedBranches,
                                    List <RTBranchContainer> activeBuildingBranches)
        {
            if (!ivyParameters.halfgeom)
            {
                angle = Mathf.Rad2Deg * 2 * Mathf.PI / ivyParameters.sides;
            }
            else
            {
                angle = Mathf.Rad2Deg * 2 * Mathf.PI / ivyParameters.sides / 2;
            }


            if (leavesDataInitialized)
            {
                ClearTipMesh();

                //Recorremos cada rama y definimos el primer vértice que tenemos que escribir del array, recogido del vertcount actualizado en la iteración anterior
                for (int b = 0; b < rtIvyContainer.branches.Count; b++)
                {
                    int firstVertex = vertCount;


                    RTBranchContainer currentBranch = activeBuildingBranches[b];

                    if (currentBranch.branchPoints.Count > 1)
                    {
                        lastVertCount = 0;

                        //Recorremos cada punto de la rama hasta el penúltimo
                        int initIndexPoint = currentBranch.branchPoints.Count - backtrackingPoints;
                        initIndexPoint = Mathf.Clamp(initIndexPoint, 0, int.MaxValue);

                        int endIndexPoint = currentBranch.branchPoints.Count;



                        for (int p = initIndexPoint; p < endIndexPoint; p++)
                        {
                            RTBranchPoint currentBranchPoint = currentBranch.branchPoints[p];

                            Vector3 centerLoop = ivyGO.transform.InverseTransformPoint(currentBranchPoint.point);

                            Vector3 vertex      = zeroVector3;
                            Vector3 normal      = zeroVector3;
                            Vector2 uv          = zeroVector2;
                            Vector2 uv2         = zeroVector2;
                            Color   vertexColor = blackColor;


                            float tipInfluenceFactor = Mathf.InverseLerp(currentBranch.totalLength,
                                                                         currentBranch.totalLength - ivyParameters.tipInfluence,
                                                                         currentBranchPoint.length);



                            if (p < currentBranch.branchPoints.Count - 1)
                            {
                                for (int i = 0; i < currentBranchPoint.verticesLoop.Length; i++)
                                {
                                    if (ivyParameters.generateBranches)
                                    {
                                        vertex = Vector3.LerpUnclamped(currentBranchPoint.centerLoop, currentBranchPoint.verticesLoop[i].vertex, tipInfluenceFactor);
                                        buildingMeshData.AddVertex(vertex, currentBranchPoint.verticesLoop[i].normal, currentBranchPoint.verticesLoop[i].uv,
                                                                   currentBranchPoint.verticesLoop[i].color);



                                        vertCountsPerBranch[b]++;
                                        vertCount++;
                                        lastVertCount++;
                                    }
                                }
                            }
                            else
                            {
                                vertex = centerLoop;


                                normal = Vector3.Normalize(currentBranchPoint.point - currentBranchPoint.GetPreviousPoint().point);
                                normal = ivyGO.transform.InverseTransformVector(normal);

                                uv = currentBranch.GetLastUV(ivyParameters);

                                buildingMeshData.AddVertex(vertex, normal, uv, Color.black);

                                vertCountsPerBranch[b]++;
                                vertCount++;
                                lastVertCount++;
                            }
                        }


                        SetTriangles(currentBranch, vertCount, initIndexPoint, b);
                    }

                    fromTo[0] = firstVertex;
                    fromTo[1] = vertCount - 1;



                    if (ivyParameters.generateLeaves)
                    {
                        BuildLeaves(b, activeBuildingBranches[b], activeBakedBranches[b]);
                    }
                }

                RefreshMesh();
            }
        }