/*public InfoPool CreateNewIvy()
         * {
         *      return CreateNewIvy(this.selectedPreset);
         * }*/

        public InfoPool CreateNewIvy()
        {
            IvyParameters parameters = new IvyParameters();

            parameters.CopyFrom(ivyParametersGUI);
            return(CreateNewIvy(parameters));
        }
예제 #2
0
        public Vector2 GetLastUV(IvyParameters ivyParameters)
        {
            Vector2 res = new Vector2(totalLength * ivyParameters.uvScale.y + ivyParameters.uvOffset.y,
                                      0.5f * ivyParameters.uvScale.x + ivyParameters.uvOffset.x);

            return(res);
        }
예제 #3
0
        private void CalculateLeafRotation(IvyParameters ivyParameters)
        {
            Vector3 left, forward;

            if (!ivyParameters.globalOrientation)
            {
                forward = this.lpForward;
                left    = this.left;
            }
            else
            {
                forward = ivyParameters.globalRotation;
                left    = Vector3.Normalize(Vector3.Cross(ivyParameters.globalRotation, this.lpUpward));
            }

            leafRotation = Quaternion.LookRotation(this.lpUpward, forward);

            leafRotation =
                Quaternion.AngleAxis(ivyParameters.rotation.x, left) * Quaternion.AngleAxis(ivyParameters.rotation.y, lpUpward) *
                Quaternion.AngleAxis(ivyParameters.rotation.z, forward) * leafRotation;

            leafRotation =
                Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.x, ivyParameters.randomRotation.x), left) *
                Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.y, ivyParameters.randomRotation.y), lpUpward) *
                Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.z, ivyParameters.randomRotation.z), forward) *
                leafRotation;
        }
예제 #4
0
        public void CreateVertices(IvyParameters ivyParameters, RTMeshData leafMeshData, GameObject ivyGO)
        {
            Vector3    vertex               = Vector3.zero;
            Vector3    normal               = Vector3.zero;
            Vector2    uv                   = Vector2.zero;
            Color      vertexColor          = Color.black;
            Quaternion ivyGOInverseRotation = Quaternion.Inverse(ivyGO.transform.rotation);

            leafCenter = ivyGO.transform.InverseTransformPoint(point);


            for (int v = 0; v < leafMeshData.vertices.Length; v++)
            {
                Vector3 offset = left * ivyParameters.offset.x +
                                 this.lpUpward * ivyParameters.offset.y +
                                 this.lpForward * ivyParameters.offset.z;

                vertex = leafRotation * leafMeshData.vertices[v] * leafScale + point + offset;
                vertex = vertex - ivyGO.transform.position;
                vertex = ivyGOInverseRotation * vertex;

                normal = leafRotation * leafMeshData.normals[v];
                normal = ivyGOInverseRotation * normal;

                uv          = leafMeshData.uv[v];
                vertexColor = leafMeshData.colors[v];

                this.vertices[v] = new RTVertexData(vertex, normal, uv, Vector2.zero, vertexColor);
            }
        }
예제 #5
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);
        }
예제 #6
0
        public void CalculateVerticesLoop(IvyParameters ivyParameters, RTIvyContainer rtIvyContainer, GameObject ivyGO, Vector3 firstVector, Vector3 axis, float radius)
        {
            this.firstVector = firstVector;
            this.axis        = axis;
            this.radius      = radius;

            CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO);
        }
예제 #7
0
        public void CopyFrom(IvyParameters copyFrom)
        {
            this.stepSize             = copyFrom.stepSize;
            this.branchProvability    = copyFrom.branchProvability;
            this.maxBranchs           = copyFrom.maxBranchs;
            this.layerMask            = copyFrom.layerMask;
            this.minDistanceToSurface = copyFrom.minDistanceToSurface;
            this.maxDistanceToSurface = copyFrom.maxDistanceToSurface;
            this.DTSFrequency         = copyFrom.DTSFrequency;
            this.DTSRandomness        = copyFrom.DTSRandomness;
            this.directionFrequency   = copyFrom.directionFrequency;
            this.directionAmplitude   = copyFrom.directionAmplitude;
            this.directionRandomness  = copyFrom.directionRandomness;
            this.gravity = copyFrom.gravity;
            this.grabProvabilityOnFall = copyFrom.grabProvabilityOnFall;
            this.stiffness             = copyFrom.stiffness;
            this.optAngleBias          = copyFrom.optAngleBias;
            this.leaveEvery            = copyFrom.leaveEvery;
            this.randomLeaveEvery      = copyFrom.randomLeaveEvery;

            this.halfgeom          = copyFrom.halfgeom;
            this.sides             = copyFrom.sides;
            this.minRadius         = copyFrom.minRadius;
            this.maxRadius         = copyFrom.maxRadius;
            this.radiusVarFreq     = copyFrom.radiusVarFreq;
            this.radiusVarOffset   = copyFrom.radiusVarOffset;
            this.tipInfluence      = copyFrom.tipInfluence;
            this.uvScale           = copyFrom.uvScale;
            this.uvOffset          = copyFrom.uvOffset;
            this.minScale          = copyFrom.minScale;
            this.maxScale          = copyFrom.maxScale;
            this.globalOrientation = copyFrom.globalOrientation;
            this.globalRotation    = copyFrom.globalRotation;
            this.rotation          = copyFrom.rotation;
            this.randomRotation    = copyFrom.randomRotation;
            this.offset            = copyFrom.offset;
            this.LMUVPadding       = copyFrom.LMUVPadding;

            this.generateBranches    = copyFrom.generateBranches;
            this.generateLeaves      = copyFrom.generateLeaves;
            this.generateLightmapUVs = copyFrom.generateLightmapUVs;

            this.branchesMaterial = copyFrom.branchesMaterial;

            this.leavesPrefabs = new GameObject[copyFrom.leavesPrefabs.Length];
            for (int i = 0; i < copyFrom.leavesPrefabs.Length; i++)
            {
                this.leavesPrefabs[i] = copyFrom.leavesPrefabs[i];
            }

            this.leavesProb = new float[copyFrom.leavesProb.Length];
            for (int i = 0; i < copyFrom.leavesProb.Length; i++)
            {
                this.leavesProb[i] = copyFrom.leavesProb[i];
            }
        }
        public InfoPool CreateNewIvy(IvyPreset selectedPreset)
        {
            this.selectedPreset = selectedPreset;

            IvyParameters parameters = new IvyParameters();

            parameters.CopyFrom(selectedPreset);

            return(CreateNewIvy(parameters));
        }
예제 #9
0
        public void CalculateVerticesLoop(IvyParameters ivyParameters, RTIvyContainer rtIvyContainer, GameObject ivyGO)
        {
            float angle = 0f;

            if (!ivyParameters.halfgeom)
            {
                angle = Mathf.Rad2Deg * 2 * Mathf.PI / ivyParameters.sides;
            }
            else
            {
                angle = Mathf.Rad2Deg * 2 * Mathf.PI / ivyParameters.sides / 2;
            }



            Vector3    vertex    = Vector3.zero;
            Vector3    normal    = Vector3.zero;
            Vector2    uv        = Vector2.zero;
            Quaternion quat      = Quaternion.identity;
            Vector3    direction = Vector3.zero;


            Quaternion inverseIvyGORotation = Quaternion.Inverse(ivyGO.transform.rotation);



            for (int i = 0; i < ivyParameters.sides + 1; i++)
            {
                quat      = Quaternion.AngleAxis(angle * i, axis);
                direction = quat * firstVector;

                if (ivyParameters.halfgeom && ivyParameters.sides == 1)
                {
                    normal = -grabVector;
                }
                else
                {
                    normal = direction;
                }

                normal = inverseIvyGORotation * normal;



                vertex  = direction * radius + point;
                vertex -= ivyGO.transform.position;
                vertex  = inverseIvyGORotation * vertex;

                uv = new Vector2(length * ivyParameters.uvScale.y + ivyParameters.uvOffset.y - ivyParameters.stepSize,
                                 1f / ivyParameters.sides * i * ivyParameters.uvScale.x + ivyParameters.uvOffset.x);


                verticesLoop[i] = new RTVertexData(vertex, normal, uv, Vector2.zero, Color.black);
            }
        }
예제 #10
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;
        }
예제 #11
0
        protected override void Init(IvyContainer ivyContainer, IvyParameters ivyParameters)
        {
            base.Init(ivyContainer, ivyParameters);

            rtIvyGrowth = new RuntimeIvyGrowth();
            rtIvyGrowth.Init(rtIvyContainer, ivyParameters, gameObject, leavesMeshesByChosenLeaf,
                             GetMaxNumPoints(), GetMaxNumLeaves(), GetMaxNumVerticesPerLeaf());

            for (int i = 0; i < 10; i++)
            {
                rtIvyGrowth.Step();
            }

            this.currentLifetime = this.growthParameters.lifetime;
        }
예제 #12
0
        public bool IsEqualTo(IvyParameters compareTo)
        {
            bool isEqual;

            isEqual =
                stepSize == compareTo.stepSize &&
                branchProvability == compareTo.branchProvability &&
                maxBranchs == compareTo.maxBranchs &&
                layerMask == compareTo.layerMask &&
                minDistanceToSurface == compareTo.minDistanceToSurface &&
                maxDistanceToSurface == compareTo.maxDistanceToSurface &&
                DTSFrequency == compareTo.DTSFrequency &&
                DTSRandomness == compareTo.DTSRandomness &&
                directionFrequency == compareTo.directionFrequency &&
                directionAmplitude == compareTo.directionAmplitude &&
                directionRandomness == compareTo.directionRandomness &&
                gravity == compareTo.gravity &&
                grabProvabilityOnFall == compareTo.grabProvabilityOnFall &&
                stiffness == compareTo.stiffness &&
                optAngleBias == compareTo.optAngleBias &&
                leaveEvery == compareTo.leaveEvery &&
                randomLeaveEvery == compareTo.randomLeaveEvery &&
                buffer32Bits == compareTo.buffer32Bits &&
                halfgeom == compareTo.halfgeom &&
                sides == compareTo.sides &&
                minRadius == compareTo.minRadius &&
                maxRadius == compareTo.maxRadius &&
                radiusVarFreq == compareTo.radiusVarFreq &&
                radiusVarOffset == compareTo.radiusVarOffset &&
                tipInfluence == compareTo.tipInfluence &&
                uvScale == compareTo.uvScale &&
                uvOffset == compareTo.uvOffset &&
                minScale == compareTo.minScale &&
                maxScale == compareTo.maxScale &&
                globalOrientation == compareTo.globalOrientation &&
                globalRotation == compareTo.globalRotation &&
                rotation == compareTo.rotation &&
                randomRotation == compareTo.randomRotation &&
                offset == compareTo.offset &&
                LMUVPadding == compareTo.LMUVPadding &&
                branchesMaterial == compareTo.branchesMaterial &&
                leavesPrefabs.SequenceEqual(compareTo.leavesPrefabs) &&
                leavesProb.SequenceEqual(compareTo.leavesProb) &&
                generateBranches == compareTo.generateBranches &&
                generateLeaves == compareTo.generateLeaves &&
                generateLightmapUVs == compareTo.generateLightmapUVs;
            return(isEqual);
        }
예제 #13
0
        public RTLeafPoint(LeafPoint leafPoint, IvyParameters ivyParameters)
        {
            this.point     = leafPoint.point;
            this.lpLength  = leafPoint.lpLength;
            this.left      = leafPoint.left;
            this.lpForward = leafPoint.lpForward;
            this.lpUpward  = leafPoint.lpUpward;

            this.initSegmentIdx = leafPoint.initSegmentIdx;
            this.endSegmentIdx  = leafPoint.endSegmentIdx;
            this.chosenLeave    = leafPoint.chosenLeave;

            this.vertices     = leafPoint.verticesLeaves.ToArray();
            this.leafCenter   = leafPoint.leafCenter;
            this.leafRotation = leafPoint.leafRotation;
            this.leafScale    = leafPoint.leafScale;

            CalculateLeafRotation(ivyParameters);
        }
        public InfoPool CreateNewIvy(IvyParameters ivyParameters)
        {
            infoPool = ScriptableObject.CreateInstance <InfoPool>();
            infoPool.ivyContainer          = ScriptableObject.CreateInstance <IvyContainer>();
            infoPool.ivyContainer.branches = new List <BranchContainer>();

            infoPool.ivyParameters = ivyParameters;
            infoPool.ivyParameters.UV2IslesSizes = new Dictionary <int, Vector2>();

            infoPool.growth          = ScriptableObject.CreateInstance <EditorIvyGrowth>();
            infoPool.growth.infoPool = infoPool;

            infoPool.meshBuilder          = ScriptableObject.CreateInstance <EditorMeshBuilder>();
            infoPool.meshBuilder.infoPool = infoPool;
            infoPool.meshBuilder.ivyMesh  = new Mesh();

            RealIvyWindow.realIvyProToolsWindow.infoPool = infoPool;

            return(infoPool);
        }
예제 #15
0
 public void InitIvyEditor(RuntimeGrowthParameters growthParameters, IvyContainer ivyContainer, IvyParameters ivyParameters)
 {
     this.growthParameters = growthParameters;
     Init(ivyContainer, ivyParameters);
 }
예제 #16
0
 public void PreInit(IvyParameters ivyParameters)
 {
     this.verticesLoop = new RTVertexData[ivyParameters.sides + 1];
 }
예제 #17
0
 public IvyParameters(IvyParameters copyFrom)
 {
     CopyFrom(copyFrom);
 }
예제 #18
0
        public void SetValues(Vector3 point, float lpLength, Vector3 lpForward, Vector3 lpUpward,
                              int chosenLeave, RTBranchPoint initSegment, RTBranchPoint endSegment, float leafScale, IvyParameters ivyParameters)
        {
            this.point          = point;
            this.lpLength       = lpLength;
            this.lpForward      = lpForward;
            this.lpUpward       = lpUpward;
            this.chosenLeave    = chosenLeave;
            this.initSegmentIdx = initSegment.index;
            this.endSegmentIdx  = endSegment.index;
            this.leafScale      = leafScale;

            this.left = Vector3.Cross(lpForward, lpUpward).normalized;

            CalculateLeafRotation(ivyParameters);
        }
예제 #19
0
        public void InitializeMeshBuilder(IvyParameters ivyParameters, RTIvyContainer ivyContainer,
                                          RTIvyContainer bakedIvyContainer, GameObject ivyGO, Mesh bakedMesh, MeshRenderer meshRenderer,
                                          MeshFilter meshFilter, int numBranches, Mesh processedMesh, float growSpeed, MeshRenderer mrProcessedMesh,
                                          int backtrackingPoints, int[] submeshByChoseLeaf, RTMeshData[] leavesMeshesByChosenLeaf, Material[] materials)
        {
            this.ivyParameters       = ivyParameters;
            this.rtIvyContainer      = ivyContainer;
            this.rtBakedIvyContainer = bakedIvyContainer;
            this.ivyGO = ivyGO;

            this.meshRenderer = meshRenderer;
            this.meshFilter   = meshFilter;

            this.processedMesh             = processedMesh;
            this.processedMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt16;

            this.mrProcessedMesh          = mrProcessedMesh;
            this.submeshByChoseLeaf       = submeshByChoseLeaf;
            this.leavesMeshesByChosenLeaf = leavesMeshesByChosenLeaf;

            activeBranches = new List <RTBranchContainer>();

            this.fromTo  = new int[2];
            this.vectors = new Vector3[2];

            this.growthSpeed        = growSpeed;
            this.backtrackingPoints = backtrackingPoints;

            this.submeshCount = meshRenderer.sharedMaterials.Length;

            vertCountsPerBranch                       = new int[numBranches];
            lastTriangleIndexPerBranch                = new int[numBranches];
            vertCountLeavesPerBranch                  = new int[numBranches];
            processedVerticesIndicesPerBranch         = new List <List <int> >(numBranches);
            processedBranchesVerticesIndicesPerBranch = new List <List <int> >(numBranches);

            for (int i = 0; i < numBranches; i++)
            {
                processedVerticesIndicesPerBranch.Add(new List <int>());
                processedBranchesVerticesIndicesPerBranch.Add(new List <int>());
            }


            this.vertCount = 0;

            ivyMesh = new Mesh();
            ivyMesh.subMeshCount = submeshCount;
            ivyMesh.name         = Constants.IVY_MESH_NAME;

            meshFilter.mesh = ivyMesh;


            ivyGO.GetComponent <MeshRenderer>().sharedMaterials = materials;
            mrProcessedMesh.sharedMaterials = materials;



            leavesDataInitialized = true;



            ivyGoPosition        = ivyGO.transform.position;
            ivyGoRotation        = ivyGO.transform.rotation;
            ivyGoInverseRotation = Quaternion.Inverse(ivyGO.transform.rotation);
            zeroVector3          = Vector3.zero;
            zeroVector2          = Vector2.zero;
            blackColor           = Color.black;
        }
예제 #20
0
 public override void InitIvy(RuntimeGrowthParameters growthParameters, IvyContainer ivyContainer, IvyParameters ivyParameters)
 {
     this.growthParameters = growthParameters;
     Init(null, ivyParameters);
     InitMeshBuilder();
     AddFirstBranch();
 }
예제 #21
0
 protected override void Init(IvyContainer ivyContainer, IvyParameters ivyParameters)
 {
     base.Init(ivyContainer, ivyParameters);
     CalculateLifetime();
 }
예제 #22
0
        public void CopyFrom(IvyParameters copyFrom)
        {
            this.stepSize              = copyFrom.stepSize;
            this.branchProvability     = copyFrom.branchProvability;
            this.maxBranchs            = copyFrom.maxBranchs;
            this.layerMask             = copyFrom.layerMask;
            this.minDistanceToSurface  = copyFrom.minDistanceToSurface;
            this.maxDistanceToSurface  = copyFrom.maxDistanceToSurface;
            this.DTSFrequency          = copyFrom.DTSFrequency;
            this.DTSRandomness         = copyFrom.DTSRandomness;
            this.directionFrequency    = copyFrom.directionFrequency;
            this.directionAmplitude    = copyFrom.directionAmplitude;
            this.directionRandomness   = copyFrom.directionRandomness;
            this.gravityX              = copyFrom.gravity.x;
            this.gravityY              = copyFrom.gravity.y;
            this.gravityZ              = copyFrom.gravity.z;
            this.grabProvabilityOnFall = copyFrom.grabProvabilityOnFall;
            this.stiffness             = copyFrom.stiffness;
            this.optAngleBias          = copyFrom.optAngleBias;
            this.leaveEvery            = copyFrom.leaveEvery;
            this.randomLeaveEvery      = copyFrom.randomLeaveEvery;

            this.buffer32Bits      = copyFrom.buffer32Bits;
            this.halfgeom          = copyFrom.halfgeom;
            this.sides             = copyFrom.sides;
            this.minRadius         = copyFrom.minRadius;
            this.maxRadius         = copyFrom.maxRadius;
            this.radiusVarFreq     = copyFrom.radiusVarFreq;
            this.radiusVarOffset   = copyFrom.radiusVarOffset;
            this.tipInfluence      = copyFrom.tipInfluence;
            this.uvScaleX          = copyFrom.uvScale.x;
            this.uvScaleY          = copyFrom.uvScale.y;
            this.uvOffsetX         = copyFrom.uvOffset.x;
            this.uvOffsetY         = copyFrom.uvOffset.y;
            this.minScale          = copyFrom.minScale;
            this.maxScale          = copyFrom.maxScale;
            this.globalOrientation = copyFrom.globalOrientation;
            this.globalRotationX   = copyFrom.globalRotation.x;
            this.globalRotationY   = copyFrom.globalRotation.y;
            this.globalRotationZ   = copyFrom.globalRotation.z;
            this.rotationX         = copyFrom.rotation.x;
            this.rotationY         = copyFrom.rotation.y;
            this.rotationZ         = copyFrom.rotation.z;
            this.randomRotationX   = copyFrom.randomRotation.x;
            this.randomRotationY   = copyFrom.randomRotation.y;
            this.randomRotationZ   = copyFrom.randomRotation.z;
            this.randomRotationX   = copyFrom.randomRotation.x;
            this.randomRotationY   = copyFrom.randomRotation.y;
            this.randomRotationZ   = copyFrom.randomRotation.z;
            this.offsetX           = copyFrom.offset.x;
            this.offsetY           = copyFrom.offset.y;
            this.offsetZ           = copyFrom.offset.z;
            this.LMUVPadding       = copyFrom.LMUVPadding;

            this.generateBranches    = copyFrom.generateBranches;
            this.generateLeaves      = copyFrom.generateLeaves;
            this.generateLightmapUVs = copyFrom.generateLightmapUVs;

            this.branchesMaterial = copyFrom.branchesMaterial;

            this.leavesProb.Clear();
            for (int i = 0; i < copyFrom.leavesProb.Length; i++)
            {
                this.leavesProb.Add(copyFrom.leavesProb[i]);
            }

            this.leavesPrefabs.Clear();
            for (int i = 0; i < copyFrom.leavesPrefabs.Length; i++)
            {
                this.leavesPrefabs.Add(copyFrom.leavesPrefabs[i]);
            }
            //this.UV2IslesSizes = copyFrom.UV2IslesSizes;
        }
예제 #23
0
        public void Init(RTIvyContainer ivyContainer, IvyParameters ivyParameters,
                         GameObject ivyGO, RTMeshData[] leavesMeshesByChosenLeaf,
                         int numPoints, int numLeaves, int maxNumVerticesPerLeaf)
        {
            this.rtIvyContainer           = ivyContainer;
            this.ivyParameters            = ivyParameters;
            this.ivyGO                    = ivyGO;
            this.leavesMeshesByChosenLeaf = leavesMeshesByChosenLeaf;
            this.numPoints                = numPoints;
            this.numLeaves                = numLeaves;
            this.maxNumVerticesPerLeaf    = maxNumVerticesPerLeaf;

            this.branchPointsPool     = new RTBranchPoint[numPoints];
            this.branchPointPoolIndex = 0;

            for (int i = 0; i < numPoints; i++)
            {
                RTBranchPoint branchPoint = new RTBranchPoint();
                branchPoint.PreInit(ivyParameters);
                branchPointsPool[i] = branchPoint;
            }

            this.leavesPool      = new RTLeafPoint[numLeaves];
            this.leavesPoolIndex = 0;
            for (int i = 0; i < numLeaves; i++)
            {
                RTLeafPoint leafPoint = new RTLeafPoint();
                leafPoint.PreInit(maxNumVerticesPerLeaf);
                leavesPool[i] = leafPoint;
            }

            this.branchesPool = new RTBranchContainer[ivyParameters.maxBranchs];
            for (int i = 0; i < ivyParameters.maxBranchs; i++)
            {
                this.branchesPool[i] = new RTBranchContainer(numPoints, numLeaves);
            }


            Random.InitState(System.Environment.TickCount);


            RTBranchContainer firstBranch = GetNextBranchContainer();



            ivyContainer.AddBranch(firstBranch);



            RTBranchPoint nextRTBranchPoint = GetNextFreeBranchPoint();

            nextRTBranchPoint.SetValues(ivyGO.transform.position, -ivyGO.transform.up, false, 0);
            firstBranch.AddBranchPoint(nextRTBranchPoint, ivyParameters.stepSize);

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



            ivyContainer.branches[0].growDirection = Quaternion.AngleAxis(Random.value * 360f, ivyGO.transform.up) *
                                                     ivyGO.transform.forward;

            ivyContainer.firstVertexVector           = ivyContainer.branches[0].growDirection;
            ivyContainer.branches[0].randomizeHeight = Random.Range(4f, 8f);
            CalculateNewHeight(ivyContainer.branches[0]);
            ivyContainer.branches[0].branchSense = ChooseBranchSense();
            randomstate = Random.state;
        }
예제 #24
0
 public abstract void InitIvy(RuntimeGrowthParameters growthParameters, IvyContainer ivyContainer, IvyParameters ivyParameters);
예제 #25
0
 public void InitializeRuntime(IvyParameters ivyParameters)
 {
     this.verticesLoop = new List <RTVertexData>(ivyParameters.sides + 1);
 }
예제 #26
0
        /* public void InitIvy(RuntimeGrowthParameters growthParameters, IvyContainer ivyContainer,
         *      IvyParameters ivyParameters)
         * {
         *      this.growthParameters = growthParameters;
         *      Init(ivyContainer, ivyParameters);
         *      AddFirstBranch();
         * } */



        protected virtual void Init(IvyContainer ivyContainer, IvyParameters ivyParameters)
        {
            this.rtIvyContainer = new RTIvyContainer();

            this.ivyParameters = new IvyParameters();
            this.ivyParameters.CopyFrom(ivyParameters);

            CreateLeavesDict();

            if (ivyContainer != null)
            {
                this.rtIvyContainer.Initialize(ivyContainer, ivyParameters, gameObject,
                                               leavesMeshesByChosenLeaf, ivyContainer.firstVertexVector);
            }
            else
            {
                this.rtIvyContainer.Initialize();
            }



            SetUpMaxBranches(ivyContainer);


            activeBakedBranches    = new List <RTBranchContainer>(maxBranches);
            activeBuildingBranches = new List <RTBranchContainer>(maxBranches);

            rtBuildingIvyContainer = new RTIvyContainer();

            Vector3 firstVertexVector = ivyContainer == null?CalculateFirstVertexVector() : ivyContainer.firstVertexVector;

            rtBuildingIvyContainer.Initialize(firstVertexVector);
            lastIdxActiveBranch = -1;

            leafLengthCorrrectionFactor = 1;

            int submeshCount = ivyParameters.leavesPrefabs.Length + 1;

            this.processedMesh         = new Mesh();
            processedMesh.subMeshCount = submeshCount;
            mfProcessedMesh.sharedMesh = processedMesh;

            this.refreshProcessedMesh = false;
            this.backtrackingPoints   = GetBacktrackingPoints();

            if (this.bakedMesh == null)
            {
                this.bakedMesh = new Mesh();
                this.bakedMesh.subMeshCount = submeshCount;
            }

            /* meshBuilder = new RTBakedMeshBuilder(rtIvyContainer, gameObject);
             * meshBuilder.InitializeMeshBuilder(ivyParameters, rtBuildingIvyContainer, rtIvyContainer,
             *      gameObject, bakedMesh, meshRenderer, meshFilter, maxBranches,
             *      processedMesh, growthParameters.growthSpeed, mrProcessedMesh,
             *      backtrackingPoints, submeshByChoseLeaf, leavesMeshesDict, leavesMaterials.ToArray()); */



            lastCopiedIndexPerBranch = new List <int>(maxBranches);
            leavesToCopyMesh         = new List <LeafPoint>(50);
            srcPoints = new List <Vector3>(maxBranches);
            dstPoints = new List <Vector3>(maxBranches);
            growingFactorPerBranch  = new List <float>(maxBranches);
            srcTotalLengthPerBranch = new List <float>(maxBranches);
            dstTotalLengthPerBranch = new List <float>(maxBranches);
            lengthPerBranch         = new List <float>(maxBranches);


            for (int i = 0; i < maxBranches; i++)
            {
                srcPoints.Add(Vector3.zero);
                dstPoints.Add(Vector3.zero);
                growingFactorPerBranch.Add(0f);
                srcTotalLengthPerBranch.Add(0f);
                dstTotalLengthPerBranch.Add(0f);
                lastCopiedIndexPerBranch.Add(-1);
                lengthPerBranch.Add(0f);

                int branchPointsSize = GetMaxNumPoints();
                int numLeaves        = GetMaxNumLeaves();

                RTBranchContainer branchContainer = new RTBranchContainer(branchPointsSize, numLeaves);
                activeBuildingBranches.Add(branchContainer);
            }
        }
예제 #27
0
        public RTBranchContainer(BranchContainer branchContainer, IvyParameters ivyParameters, RTIvyContainer rtIvyContainer,
                                 GameObject ivyGO, RTMeshData[] leavesMeshesByChosenLeaf)
        {
            this.totalLength             = branchContainer.totalLenght;
            this.growDirection           = branchContainer.growDirection;
            this.randomizeHeight         = branchContainer.randomizeHeight;
            this.heightVar               = branchContainer.heightVar;
            this.newHeight               = branchContainer.newHeight;
            this.heightParameter         = branchContainer.heightParameter;
            this.deltaHeight             = branchContainer.deltaHeight;
            this.currentHeight           = branchContainer.currentHeight;
            this.branchSense             = branchContainer.branchSense;
            this.falling                 = branchContainer.falling;
            this.rotationOnFallIteration = branchContainer.rotationOnFallIteration;
            this.branchNumber            = branchContainer.branchNumber;



            this.branchPoints = new List <RTBranchPoint>(branchContainer.branchPoints.Count);
            for (int i = 0; i < branchContainer.branchPoints.Count; i++)
            {
                RTBranchPoint rtBranchPoint = new RTBranchPoint(branchContainer.branchPoints[i], this);

                rtBranchPoint.CalculateCenterLoop(ivyGO);
                rtBranchPoint.PreInit(ivyParameters);
                rtBranchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO);

                this.branchPoints.Add(rtBranchPoint);
            }


            branchContainer.PrepareRTLeavesDict();


            if (ivyParameters.generateLeaves)
            {
                this.leavesOrderedByInitSegment = new RTLeafPoint[branchPoints.Count][];
                for (int i = 0; i < branchPoints.Count; i++)
                {
                    List <LeafPoint> leavesToBake = branchContainer.dictRTLeavesByInitSegment[i];
                    int numLeaves = 0;
                    if (leavesToBake != null)
                    {
                        numLeaves = leavesToBake.Count;
                    }


                    this.leavesOrderedByInitSegment[i] = new RTLeafPoint[numLeaves];


                    for (int j = 0; j < numLeaves; j++)
                    {
                        RTLeafPoint rtLeafPoint  = new RTLeafPoint(leavesToBake[j], ivyParameters);
                        RTMeshData  leafMeshData = leavesMeshesByChosenLeaf[rtLeafPoint.chosenLeave];

                        rtLeafPoint.CreateVertices(ivyParameters, leafMeshData, ivyGO);
                        this.leavesOrderedByInitSegment[i][j] = rtLeafPoint;
                    }
                }
            }
        }
예제 #28
0
        public void CreateVertices(IvyParameters ivyParameters, RTMeshData leafMeshData, GameObject ivyGO)
        {
            Vector3    left, forward;
            Quaternion quat;


            //Aquí cálculos de orientación en función de las opciones de rotación
            if (!ivyParameters.globalOrientation)
            {
                forward = lpForward;
                left    = this.left;
                //left = Vector3.Cross(currentLeaf.lpForward, currentLeaf.lpUpward);
            }
            else
            {
                forward = ivyParameters.globalRotation;
                left    = Vector3.Normalize(Vector3.Cross(ivyParameters.globalRotation, this.lpUpward));
            }
            //Y aplicamos la rotación

            quat = Quaternion.LookRotation(this.lpUpward, forward);

            quat = Quaternion.AngleAxis(ivyParameters.rotation.x, left) *
                   Quaternion.AngleAxis(ivyParameters.rotation.y, this.lpUpward) *
                   Quaternion.AngleAxis(ivyParameters.rotation.z, forward) *
                   quat;


            quat = Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.x, ivyParameters.randomRotation.x), left) *
                   Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.y, ivyParameters.randomRotation.y), this.lpUpward) *
                   Quaternion.AngleAxis(Random.Range(-ivyParameters.randomRotation.z, ivyParameters.randomRotation.z), forward) *
                   quat;

            quat = this.forwarRot * quat;



            //Aquí la escala, que es facilita, incluyendo el tip influence
            float scale = Random.Range(ivyParameters.minScale, ivyParameters.maxScale);

            //scale *= Mathf.InverseLerp(infoPool.ivyContainer.branches[b].totalLenght, infoPool.ivyContainer.branches[b].totalLenght - infoPool.ivyParameters.tipInfluence, currentLeaf.lpLength);



            /*******************/
            this.leafRotation = quat;
            //currentLeaf.dstScale = scale;
            /*******************/

            this.leafCenter = this.point - ivyGO.transform.position;
            this.leafCenter = Quaternion.Inverse(ivyGO.transform.rotation) * this.leafCenter;


            if (this.verticesLeaves == null)
            {
                this.verticesLeaves = new List <RTVertexData>(4);
            }
            //this.verticesLeaves.Clear();

            Vector3    vertex               = Vector3.zero;
            Vector3    normal               = Vector3.zero;
            Vector2    uv                   = Vector2.zero;
            Color      vertexColor          = Color.black;
            Quaternion ivyGOInverseRotation = Quaternion.Inverse(ivyGO.transform.rotation);


            for (int v = 0; v < leafMeshData.vertices.Length; v++)
            {
                Vector3 offset = left * ivyParameters.offset.x + this.lpUpward * ivyParameters.offset.y + this.lpForward * ivyParameters.offset.z;

                vertex = quat * leafMeshData.vertices[v] * scale + leafCenter + offset;

                normal = quat * leafMeshData.normals[v];
                normal = ivyGOInverseRotation * normal;

                uv          = leafMeshData.uv[v];
                vertexColor = leafMeshData.colors[v];

                RTVertexData vertexData = new RTVertexData(vertex, normal, uv, Vector2.zero, vertexColor);
                this.verticesLeaves.Add(vertexData);
            }
        }