Exemplo n.º 1
0
        //Si no encontramos muro en el paso anterior, entonces buscamos si tenemos suelo. tiramos el rayo y si da positivo, añadimos punto, calculamos growdirection y decimos al sistema que no estamos cayendo. Si por el contrario no
        //hemos encontrado suelo, intenamos agarrarnos al otro lado de la posible esquina.
        void CheckFloor(RTBranchContainer branch, RTBranchPoint potentialPoint, Vector3 oldSurfaceNormal)
        {
            Ray        ray = new Ray(potentialPoint.point, -oldSurfaceNormal);
            RaycastHit RC;

            if (Physics.Raycast(ray, out RC, branch.currentHeight * 2f, ivyParameters.layerMask.value))
            {
                AddPoint(branch, RC.point, RC.normal);
                NewGrowDirection(branch);
                branch.fallIteration = 0f;
                branch.falling       = false;
            }
            else
            {
                if (Random.value < ivyParameters.grabProvabilityOnFall)
                {
                    CheckCorner(branch, potentialPoint, oldSurfaceNormal);
                }
                else
                {
                    AddFallingPoint(branch);
                    branch.fallIteration  += 1f - ivyParameters.stiffness;
                    branch.falling         = true;
                    branch.currentHeight   = 0f;
                    branch.heightParameter = -45f;
                }
            }
        }
Exemplo n.º 2
0
        public void AddBranch(RTBranchContainer rtBranch)
        {
            rtBranch.branchNumber = lastBranchNumberAssigned;
            branches.Add(rtBranch);

            lastBranchNumberAssigned++;
        }
Exemplo n.º 3
0
        protected virtual void Growing(int branchIndex, float deltaTime)
        {
            RTBranchContainer currentBranch = activeBuildingBranches[branchIndex];

            CalculateFactors(srcPoints[branchIndex], dstPoints[branchIndex]);
            meshBuilder.SetLeafLengthCorrectionFactor(leafLengthCorrrectionFactor);
            growingFactorPerBranch[branchIndex] += currentSpeed * deltaTime;
            growingFactorPerBranch[branchIndex]  = Mathf.Clamp(growingFactorPerBranch[branchIndex], 0f, 1f);

            currentBranch.totalLength = Mathf.Lerp(srcTotalLengthPerBranch[branchIndex], dstTotalLengthPerBranch[branchIndex], growingFactorPerBranch[branchIndex]);


            RTBranchPoint lastPoint = currentBranch.GetLastBranchPoint();

            lastPoint.length = currentBranch.totalLength;

            lastPoint.point = Vector3.Lerp(srcPoints[branchIndex], dstPoints[branchIndex], growingFactorPerBranch[branchIndex]);


            if (growingFactorPerBranch[branchIndex] >= 1)
            {
                RefreshGeometry();
                NextPoints(branchIndex);
            }
        }
Exemplo n.º 4
0
        //Añadimos punto y todo lo que ello conlleva. Está la posibilidad de spawnear una rama
        public void AddPoint(RTBranchContainer branch, Vector3 point, Vector3 normal)
        {
            branch.totalLength += ivyParameters.stepSize;

            RTBranchPoint branchPoint = GetNextFreeBranchPoint();

            branchPoint.SetValues(point + normal * branch.currentHeight, -normal);
            branch.AddBranchPoint(branchPoint, ivyParameters.stepSize);


            CalculateVerticesLastPoint(branch);
            //Vector3 axis = GetLoopAxis(branchPoint, branch, rtIvyContainer, ivyGO);
            //Vector3 firstVector = GetFirstVector(branchPoint, branch, rtIvyContainer, ivyParameters, axis);
            //branchPoint.CalculateCenterLoop(ivyGO);
            //branchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO, firstVector, axis);



            /*if(branch.branchPoints.Count >= 1)
             * {
             *      branch.branchPoints[branch.branchPoints.Count - 2].CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO);
             * }*/


            if (Random.value < ivyParameters.branchProvability && rtIvyContainer.branches.Count < ivyParameters.maxBranchs)
            {
                AddBranch(branch, branch.GetLastBranchPoint(), branch.branchPoints[branch.branchPoints.Count - 1].point, normal);
            }


            if (ivyParameters.generateLeaves)
            {
                AddLeave(branch);
            }
        }
Exemplo n.º 5
0
 //Cálculos de nuevas growdirection en diferentes casuísticas
 void NewGrowDirection(RTBranchContainer branch)
 {
     branch.growDirection = Vector3.Normalize(Vector3.ProjectOnPlane(Quaternion.AngleAxis(Mathf.Sin(branch.branchSense * branch.totalLength * ivyParameters.directionFrequency * (1 + Random.Range(-ivyParameters.directionRandomness, ivyParameters.directionRandomness))) *
                                                                                          ivyParameters.directionAmplitude * ivyParameters.stepSize * 10f * Mathf.Max(ivyParameters.directionRandomness, 1f),
                                                                                          branch.GetLastBranchPoint().grabVector) * branch.growDirection,
                                                                     branch.GetLastBranchPoint().grabVector));
 }
Exemplo n.º 6
0
        public Vector3 GetFirstVector(RTBranchPoint rtBranchPoint, RTBranchContainer rtBranchContainer,
                                      RTIvyContainer rtIvyContainer, IvyParameters ivyParameters, Vector3 axis)
        {
            Vector3 firstVector = Vector3.zero;

            if (rtBranchContainer.branchNumber == 0 && rtBranchPoint.index == 0)
            {
                if (!ivyParameters.halfgeom)
                {
                    firstVector = rtIvyContainer.firstVertexVector;
                }
                else
                {
                    firstVector = Quaternion.AngleAxis(90f, axis) * rtIvyContainer.firstVertexVector;
                }
            }
            else
            {
                if (!ivyParameters.halfgeom)
                {
                    firstVector = Vector3.Normalize(Vector3.ProjectOnPlane(rtBranchPoint.grabVector, axis));
                }
                else
                {
                    firstVector = Quaternion.AngleAxis(90f, axis) * Vector3.Normalize(Vector3.ProjectOnPlane(rtBranchPoint.grabVector, axis));
                }
            }

            return(firstVector);
        }
Exemplo n.º 7
0
        protected virtual void AddNextBranch(int branchNumber)
        {
            lastIdxActiveBranch++;

            RTBranchContainer newBuildingBranch = activeBuildingBranches[lastIdxActiveBranch];
            RTBranchContainer bakedBranch       = rtIvyContainer.GetBranchContainerByBranchNumber(branchNumber);

            newBuildingBranch.AddBranchPoint(bakedBranch.branchPoints[0], ivyParameters.stepSize);
            newBuildingBranch.AddBranchPoint(bakedBranch.branchPoints[1], ivyParameters.stepSize);


            newBuildingBranch.leavesOrderedByInitSegment = bakedBranch.leavesOrderedByInitSegment;

            rtBuildingIvyContainer.AddBranch(newBuildingBranch);
            activeBakedBranches.Add(bakedBranch);
            activeBuildingBranches.Add(newBuildingBranch);
            meshBuilder.activeBranches.Add(newBuildingBranch);

            UpdateGrowingPoints(rtBuildingIvyContainer.branches.Count - 1);

            RTBranchPoint lastBranchPoint = newBuildingBranch.GetLastBranchPoint();

            if (lastBranchPoint.newBranch)
            {
                AddNextBranch(lastBranchPoint.newBranchNumber);
            }
        }
Exemplo n.º 8
0
        //Este se usa si estamos en una caída. Está la probabilidad de buscar una superficie donde agarrarnos (checkgrabpoint). Si topamos con una superficie se añade punto y se dice al sistema que no estamos cayendo
        void CheckFall(RTBranchContainer branch)
        {
            Ray        ray = new Ray(branch.branchPoints[branch.branchPoints.Count - 1].point, branch.growDirection);
            RaycastHit RC;

            if (!Physics.Raycast(ray, out RC, ivyParameters.stepSize * 1.15f, ivyParameters.layerMask.value))
            {
                if (Random.value < ivyParameters.grabProvabilityOnFall)
                {
                    CheckGrabPoint(branch);
                }
                else
                {
                    NewGrowDirectionFalling(branch);
                    AddFallingPoint(branch);
                    branch.fallIteration += 1f - ivyParameters.stiffness;
                    branch.falling        = true;
                }
            }
            else
            {
                NewGrowDirectionAfterFall(branch, RC.normal);
                AddPoint(branch, RC.point, RC.normal);
                branch.fallIteration = 0f;
                branch.falling       = false;
            }
        }
Exemplo n.º 9
0
        private RTBranchContainer GetNextBranchContainer()
        {
            RTBranchContainer res = branchesPool[branchesPoolIndex];

            branchesPoolIndex++;

            return(res);
        }
Exemplo n.º 10
0
        private void BuildLeaves(int branchIndex, RTBranchContainer buildingBranchContainer,
                                 RTBranchContainer bakedBranchContainer)
        {
            RTMeshData chosenLeaveMeshData;



            int firstPointIdx = buildingBranchContainer.branchPoints.Count - backtrackingPoints;

            firstPointIdx = Mathf.Clamp(firstPointIdx, 0, int.MaxValue);


            for (int i = firstPointIdx; i < buildingBranchContainer.branchPoints.Count; i++)
            {
                RTLeafPoint[] leaves        = bakedBranchContainer.leavesOrderedByInitSegment[i];
                RTBranchPoint rtBranchPoint = buildingBranchContainer.branchPoints[i];

                for (int j = 0; j < leaves.Length; j++)
                {
                    RTLeafPoint currentLeaf = leaves[j];


                    if (currentLeaf == null)
                    {
                        continue;
                    }


                    float tipInfluenceFactor = Mathf.InverseLerp(buildingBranchContainer.totalLength,
                                                                 (buildingBranchContainer.totalLength - ivyParameters.tipInfluence),
                                                                 rtBranchPoint.length);

                    chosenLeaveMeshData = leavesMeshesByChosenLeaf[currentLeaf.chosenLeave];



                    //Metemos los triángulos correspondientes en el array correspondiente al material que estamos iterando
                    for (int t = 0; t < chosenLeaveMeshData.triangles[0].Length; t++)
                    {
                        int triangleValue = chosenLeaveMeshData.triangles[0][t] + vertCount;

                        int submesh = submeshByChoseLeaf[currentLeaf.chosenLeave];
                        buildingMeshData.AddTriangle(submesh, triangleValue);
                    }

                    for (int v = 0; v < currentLeaf.vertices.Length; v++)
                    {
                        Vector3 vertex = Vector3.LerpUnclamped(currentLeaf.leafCenter, currentLeaf.vertices[v].vertex, tipInfluenceFactor);

                        buildingMeshData.AddVertex(vertex, currentLeaf.vertices[v].normal, currentLeaf.vertices[v].uv, currentLeaf.vertices[v].color);

                        vertCountLeavesPerBranch[branchIndex]++;
                        vertCountsPerBranch[branchIndex]++;
                        vertCount++;
                    }
                }
            }
        }
Exemplo n.º 11
0
        //Este método es para calcular la altura del próximo punto
        void CalculateNewHeight(RTBranchContainer branch)
        {
            branch.heightVar = (Mathf.Sin(branch.heightParameter * ivyParameters.DTSFrequency - 45f) + 1f) / 2f;

            branch.newHeight  = Mathf.Lerp(ivyParameters.minDistanceToSurface, ivyParameters.maxDistanceToSurface, branch.heightVar);
            branch.newHeight += (Mathf.Sin(branch.heightParameter * ivyParameters.DTSFrequency * branch.randomizeHeight) + 1) / 2f * ivyParameters.maxDistanceToSurface / 4f * ivyParameters.DTSRandomness;

            branch.deltaHeight   = branch.currentHeight - branch.newHeight;
            branch.currentHeight = branch.newHeight;
        }
Exemplo n.º 12
0
 //Si la rama no está cayendo (está agarrada a una superficie) calculamos la nueva altura del próximo punto y buscamos un muro delante. Si está cayendo, buscamos el próximo punto de la caída.
 void CalculateNewPoint(RTBranchContainer branch)
 {
     if (!branch.falling)
     {
         CalculateNewHeight(branch);
         CheckWall(branch);
     }
     else
     {
         CheckFall(branch);
     }
 }
Exemplo n.º 13
0
        private void CalculateVerticesLastPoint(RTBranchContainer rtBranchContainer)
        {
            if (rtBranchContainer.branchPoints.Count > 1)
            {
                RTBranchPoint branchPoint = rtBranchContainer.branchPoints[rtBranchContainer.branchPoints.Count - 2];

                float   radius      = CalculateRadius(branchPoint.length);
                Vector3 axis        = GetLoopAxis(branchPoint, rtBranchContainer, rtIvyContainer, ivyGO);
                Vector3 firstVector = GetFirstVector(branchPoint, rtBranchContainer, rtIvyContainer, ivyParameters, axis);
                branchPoint.CalculateCenterLoop(ivyGO);
                branchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO, firstVector, axis, radius);
            }
        }
Exemplo n.º 14
0
        public void Initialize(IvyContainer ivyContainer, IvyParameters ivyParameters, GameObject ivyGO, RTMeshData[] leavesMeshesByChosenLeaf, Vector3 firstVertexVector)
        {
            lastBranchNumberAssigned = 0;
            this.branches            = new List <RTBranchContainer>(ivyContainer.branches.Count);

            for (int i = 0; i < ivyContainer.branches.Count; i++)
            {
                RTBranchContainer rtBranch = new RTBranchContainer(ivyContainer.branches[i], ivyParameters, this, ivyGO, leavesMeshesByChosenLeaf);
                this.branches.Add(rtBranch);
            }

            this.firstVertexVector = firstVertexVector;
        }
Exemplo n.º 15
0
        public void CheckCopyMesh(int branchIndex, List <RTBranchContainer> bakedBranches)
        {
            RTBranchContainer buildingBranch = rtIvyContainer.branches[branchIndex];
            RTBranchContainer bakedBranch    = bakedBranches[branchIndex];

            int initSegment = buildingBranch.branchPoints.Count - backtrackingPoints - 1;

            initSegment = Mathf.Clamp(initSegment, 0, int.MaxValue);

            int initSegmentIdx = initSegment;
            int endSegmentIndx = initSegment + 1;

            CopyToFixedMesh(branchIndex, initSegmentIdx, endSegmentIndx, buildingBranch, bakedBranch);
        }
Exemplo n.º 16
0
        private void SetTriangles(RTBranchContainer branch, int vertCount, int initIndex, int branchIndex)
        {
            int initRound = 0;
            int endRound  = Mathf.Min(branch.branchPoints.Count - 2, ((branch.branchPoints.Count - initIndex) - 2));


            for (int round = initRound; round < endRound; round++)
            {
                for (int i = 0; i < ivyParameters.sides; i++)
                {
                    int offset = vertCount - lastVertCount;

                    int v0 = (i + (round * (ivyParameters.sides + 1))) + offset;
                    int v1 = (i + (round * (ivyParameters.sides + 1)) + 1) + offset;
                    int v2 = (i + (round * (ivyParameters.sides + 1)) + ivyParameters.sides + 1) + offset;
                    int v3 = (i + (round * (ivyParameters.sides + 1)) + 1) + offset;
                    int v4 = (i + (round * (ivyParameters.sides + 1)) + ivyParameters.sides + 2) + offset;
                    int v5 = (i + (round * (ivyParameters.sides + 1)) + ivyParameters.sides + 1) + offset;


                    //int firstIndexTriangle = lastTriangleIndexPerBranch[branchIndex];



                    buildingMeshData.AddTriangle(0, v0);
                    buildingMeshData.AddTriangle(0, v1);
                    buildingMeshData.AddTriangle(0, v2);


                    buildingMeshData.AddTriangle(0, v3);
                    buildingMeshData.AddTriangle(0, v4);
                    buildingMeshData.AddTriangle(0, v5);

                    triCount += 6;
                }
            }


            for (int t = 0, c = 0; t < ivyParameters.sides * 3; t += 3, c++)
            {
                buildingMeshData.AddTriangle(0, vertCount - 1);
                buildingMeshData.AddTriangle(0, vertCount - 3 - c);
                buildingMeshData.AddTriangle(0, vertCount - 2 - c);

                triCount += 3;
            }

            lastTriangleIndexPerBranch[branchIndex] = vertCount - 1;
        }
Exemplo n.º 17
0
        public RTBranchPoint(BranchPoint branchPoint, RTBranchContainer rtBranchContainer)
        {
            this.point           = branchPoint.point;
            this.grabVector      = branchPoint.grabVector;
            this.length          = branchPoint.length;
            this.index           = branchPoint.index;
            this.newBranch       = branchPoint.newBranch;
            this.newBranchNumber = branchPoint.newBranchNumber;

            this.branchContainer = rtBranchContainer;

            this.radius      = branchPoint.radius;
            this.firstVector = branchPoint.firstVector;
            this.axis        = branchPoint.axis;
        }
Exemplo n.º 18
0
        public RTBranchContainer GetBranchContainerByBranchNumber(int newBranchNumber)
        {
            RTBranchContainer res = null;

            for (int i = 0; i < branches.Count; i++)
            {
                if (branches[i].branchNumber == newBranchNumber)
                {
                    res = branches[i];
                    break;
                }
            }

            return(res);
        }
Exemplo n.º 19
0
        void NewGrowDirectionFalling(RTBranchContainer branch)
        {
            Vector3 newGrowDirection = Vector3.Lerp(branch.growDirection, ivyParameters.gravity, branch.fallIteration / 10f);

            newGrowDirection = Quaternion.AngleAxis(Mathf.Sin(branch.branchSense * branch.totalLength * ivyParameters.directionFrequency * (1 + Random.Range(-ivyParameters.directionRandomness / 8f, ivyParameters.directionRandomness / 8f))) *
                                                    ivyParameters.directionAmplitude * ivyParameters.stepSize * 5f * Mathf.Max(ivyParameters.directionRandomness / 8f, 1f),
                                                    branch.GetLastBranchPoint().grabVector) * newGrowDirection;

            newGrowDirection = Quaternion.AngleAxis(Mathf.Sin(branch.branchSense * branch.totalLength * ivyParameters.directionFrequency / 2f * (1 + Random.Range(-ivyParameters.directionRandomness / 8f, ivyParameters.directionRandomness / 8f))) *
                                                    ivyParameters.directionAmplitude * ivyParameters.stepSize * 5f * Mathf.Max(ivyParameters.directionRandomness / 8f, 1f),
                                                    Vector3.Cross(branch.GetLastBranchPoint().grabVector, branch.growDirection)) * newGrowDirection;

            branch.rotationOnFallIteration = Quaternion.FromToRotation(branch.growDirection, newGrowDirection);
            branch.growDirection           = newGrowDirection;
        }
Exemplo n.º 20
0
        protected virtual void NextPoints(int branchIndex)
        {
            if (rtBuildingIvyContainer.branches[branchIndex].branchPoints.Count > 0)
            {
                RTBranchPoint lastBuildingBranchPoint = rtBuildingIvyContainer.branches[branchIndex].GetLastBranchPoint();
                if (lastBuildingBranchPoint.index < activeBakedBranches[branchIndex].branchPoints.Count - 1)
                {
                    int indexBranchPoint = lastBuildingBranchPoint.index;
                    indexBranchPoint++;

                    RTBranchPoint     branchPoint = activeBakedBranches[branchIndex].branchPoints[indexBranchPoint];
                    RTBranchContainer branch      = rtBuildingIvyContainer.branches[branchIndex];

                    branch.AddBranchPoint(branchPoint, ivyParameters.stepSize);

                    if (branchPoint.newBranch)
                    {
                        RTBranchContainer candidateBranch = rtIvyContainer.GetBranchContainerByBranchNumber(branchPoint.newBranchNumber);
                        if (candidateBranch.branchPoints.Count >= 2)
                        {
                            AddNextBranch(branchPoint.newBranchNumber);
                        }
                    }

                    UpdateGrowingPoints(branchIndex);


                    if (rtBuildingIvyContainer.branches[branchIndex].branchPoints.Count > backtrackingPoints)
                    {
                        if (!IsVertexLimitReached())
                        {
                            meshBuilder.CheckCopyMesh(branchIndex, activeBakedBranches);
                            refreshProcessedMesh = true;
                        }
                        else
                        {
                            Debug.LogWarning("Limit vertices reached! --> " + Constants.VERTEX_LIMIT_16 + " vertices", meshBuilder.ivyGO);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        //Todo lo necesario para añadir una rama
        public void AddBranch(RTBranchContainer branch, RTBranchPoint originBranchPoint, Vector3 point, Vector3 normal)
        {
            RTBranchContainer newBranchContainer = GetNextBranchContainer();


            RTBranchPoint nextPoint = GetNextFreeBranchPoint();

            nextPoint.SetValues(point, -normal);
            newBranchContainer.AddBranchPoint(nextPoint, ivyParameters.stepSize);


            newBranchContainer.growDirection   = Vector3.Normalize(Vector3.ProjectOnPlane(branch.growDirection, normal));
            newBranchContainer.randomizeHeight = Random.Range(4f, 8f);
            newBranchContainer.currentHeight   = branch.currentHeight;
            newBranchContainer.heightParameter = branch.heightParameter;
            newBranchContainer.branchSense     = ChooseBranchSense();

            rtIvyContainer.AddBranch(newBranchContainer);

            originBranchPoint.InitBranchInThisPoint(newBranchContainer.branchNumber);
        }
Exemplo n.º 22
0
        //Si hábíamos perdido pie, comprobamos si estamos en una esquina e intentamos seguir por el otro lado de lamisma
        void CheckCorner(RTBranchContainer branch, RTBranchPoint potentialPoint, Vector3 oldSurfaceNormal)
        {
            Ray        ray = new Ray(potentialPoint.point + branch.branchPoints[branch.branchPoints.Count - 1].grabVector * 2f * branch.currentHeight, -branch.growDirection);
            RaycastHit RC;

            if (Physics.Raycast(ray, out RC, ivyParameters.stepSize * 1.15f, ivyParameters.layerMask.value))
            {
                AddPoint(branch, potentialPoint.point, oldSurfaceNormal);
                AddPoint(branch, RC.point, RC.normal);

                NewGrowDirectionAfterCorner(branch, oldSurfaceNormal, RC.normal);
            }
            else
            {
                AddFallingPoint(branch);
                branch.fallIteration  += 1f - ivyParameters.stiffness;
                branch.falling         = true;
                branch.currentHeight   = 0f;
                branch.heightParameter = -45f;
            }
        }
Exemplo n.º 23
0
        //Todo lo necesario para añadir una nueva hoja
        void AddLeave(RTBranchContainer branch)
        {
            if (branch.branchPoints.Count % (ivyParameters.leaveEvery + Random.Range(0, ivyParameters.randomLeaveEvery)) == 0)
            {
                int chosenLeaf = Random.Range(0, ivyParameters.leavesPrefabs.Length);

                RTBranchPoint initSegment = branch.branchPoints[branch.branchPoints.Count - 2];
                RTBranchPoint endSegment  = branch.branchPoints[branch.branchPoints.Count - 1];
                Vector3       leafPoint   = Vector3.Lerp(initSegment.point, endSegment.point, 0.5f);


                float       leafScale = Random.Range(ivyParameters.minScale, ivyParameters.maxScale);
                RTLeafPoint leafAdded = GetNextLeafPoint();
                leafAdded.SetValues(leafPoint, branch.totalLength, branch.growDirection,
                                    -branch.GetLastBranchPoint().grabVector, chosenLeaf, initSegment, endSegment, leafScale, ivyParameters);

                RTMeshData leafMeshData = leavesMeshesByChosenLeaf[leafAdded.chosenLeave];
                leafAdded.CreateVertices(ivyParameters, leafMeshData, ivyGO);

                branch.AddLeaf(leafAdded);
            }
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        //Definimos el punto a checkear y la dirección a él. Tiramos un raycast y si está libre buscamos el suelo. Si por el contrario topamos con un muro, añadimos un punto y calculamos una nueva growdirection
        void CheckWall(RTBranchContainer branch)
        {
            RTBranchPoint checkPoint = GetNextFreeBranchPoint();

            checkPoint.point = branch.GetLastBranchPoint().point + branch.growDirection * ivyParameters.stepSize + branch.GetLastBranchPoint().grabVector *branch.deltaHeight;
            checkPoint.index = branch.branchPoints.Count;
            //checkPoint.length = 0f;


            Vector3 direction = checkPoint.point - branch.GetLastBranchPoint().point;

            Ray        ray = new Ray(branch.branchPoints[branch.branchPoints.Count - 1].point, direction);
            RaycastHit RC;

            if (!Physics.Raycast(ray, out RC, ivyParameters.stepSize * 1.15f, ivyParameters.layerMask.value))
            {
                CheckFloor(branch, checkPoint, -branch.GetLastBranchPoint().grabVector);
            }
            else
            {
                NewGrowDirectionAfterWall(branch, -branch.GetLastBranchPoint().grabVector, RC.normal);
                AddPoint(branch, RC.point, RC.normal);
            }
        }
Exemplo n.º 26
0
        //Añadimos punto y todo lo que ello conlleva. Es ligeramente diferente a AddPoint. Está la posibilidad de spawnear una rama
        void AddFallingPoint(RTBranchContainer branch)
        {
            Vector3 grabVector = branch.rotationOnFallIteration * branch.GetLastBranchPoint().grabVector;


            RTBranchPoint branchPoint = GetNextFreeBranchPoint();

            branchPoint.point      = branch.branchPoints[branch.branchPoints.Count - 1].point + branch.growDirection * ivyParameters.stepSize;
            branchPoint.grabVector = grabVector;
            branch.AddBranchPoint(branchPoint, ivyParameters.stepSize);



            CalculateVerticesLastPoint(branch);
            //Vector3 axis = GetLoopAxis(branchPoint, branch, rtIvyContainer, ivyGO);
            //Vector3 firstVector = GetFirstVector(branchPoint, branch, rtIvyContainer, ivyParameters, axis);
            //branchPoint.CalculateCenterLoop(ivyGO);
            //branchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO, firstVector, axis);


            /*if (branch.branchPoints.Count >= 1)
             * {
             *      branch.branchPoints[branch.branchPoints.Count - 2].CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO);
             * }*/


            if (Random.value < ivyParameters.branchProvability && rtIvyContainer.branches.Count < ivyParameters.maxBranchs)
            {
                AddBranch(branch, branch.GetLastBranchPoint(), branch.branchPoints[branch.branchPoints.Count - 1].point, -branch.GetLastBranchPoint().grabVector);
            }

            if (ivyParameters.generateLeaves)
            {
                AddLeave(branch);
            }
        }
Exemplo n.º 27
0
 //Con esto tiramos rayos alrededor del último punto buscando una superficie donde agarrarnos.
 void CheckGrabPoint(RTBranchContainer branch)
 {
     for (int i = 0; i < 6; i++)
     {
         float      angle = (Mathf.Rad2Deg * 2 * Mathf.PI / 6) * i;
         Ray        ray   = new Ray(branch.branchPoints[branch.branchPoints.Count - 1].point + branch.growDirection * ivyParameters.stepSize, Quaternion.AngleAxis(angle, branch.growDirection) * branch.GetLastBranchPoint().grabVector);
         RaycastHit RC;
         if (Physics.Raycast(ray, out RC, ivyParameters.stepSize * 2f, ivyParameters.layerMask.value))
         {
             AddPoint(branch, RC.point, RC.normal);
             NewGrowDirectionAfterGrab(branch, RC.normal);
             branch.fallIteration = 0f;
             branch.falling       = false;
             break;
         }
         else if (i == 5)
         {
             AddFallingPoint(branch);
             NewGrowDirectionFalling(branch);
             branch.fallIteration += 1f - ivyParameters.stiffness;
             branch.falling        = true;
         }
     }
 }
Exemplo n.º 28
0
 void NewGrowDirectionAfterCorner(RTBranchContainer branch, Vector3 oldSurfaceNormal, Vector3 newSurfaceNormal)
 {
     branch.growDirection = Vector3.Normalize(Vector3.ProjectOnPlane(-oldSurfaceNormal, newSurfaceNormal));
 }
Exemplo n.º 29
0
 void NewGrowDirectionAfterGrab(RTBranchContainer branch, Vector3 newSurfaceNormal)
 {
     branch.growDirection = Vector3.Normalize(Vector3.ProjectOnPlane(branch.growDirection, newSurfaceNormal));
 }
Exemplo n.º 30
0
 void NewGrowDirectionAfterFall(RTBranchContainer branch, Vector3 newSurfaceNormal)
 {
     branch.growDirection = Vector3.Normalize(Vector3.ProjectOnPlane(-branch.GetLastBranchPoint().grabVector, newSurfaceNormal));
 }