Esempio n. 1
0
        public ColliderManager(VisibleVegetationCellSelector visibleVegetationCellSelector,
                               VegetationSystemPro vegetationSystemPro, VegetationItemInfoPro vegetationItemInfoPro,
                               Transform colliderParent, bool showColliders)
        {
            _showColliders         = showColliders;
            _vegetationSystemPro   = vegetationSystemPro;
            _vegetationItemInfoPro = vegetationItemInfoPro;

            float cullingDistance = vegetationSystemPro.VegetationSettings.GetVegetationDistance() *
                                    vegetationItemInfoPro.ColliderDistanceFactor;


            VegetationItemSelector = new VegetationItemSelector(visibleVegetationCellSelector, vegetationSystemPro,
                                                                vegetationItemInfoPro, false, 1, 0)
            {
                CullingDistance = cullingDistance
            };

            VegetationItemSelector.OnVegetationItemVisibleDelegate   += OnVegetationItemVisible;
            VegetationItemSelector.OnVegetationItemInvisibleDelegate += OnVegetationItemInvisible;
            VegetationItemSelector.OnVegetationCellInvisibleDelegate += OnVegetationCellInvisible;

            VegetationItemModelInfo vegetationItemModelInfo =
                vegetationSystemPro.GetVegetationItemModelInfo(vegetationItemInfoPro.VegetationItemID);

            ColliderPool         = new ColliderPool(vegetationItemInfoPro, vegetationItemModelInfo, vegetationSystemPro, colliderParent, _showColliders);
            RuntimePrefabStorage = new RuntimePrefabStorage(ColliderPool);
        }
Esempio n. 2
0
        void RenderVegetationNow(VegetationSystemPro vegetationSystemPro, ShadowMaskCreator shadowMaskCreator)
        {
            Shader overrideShader = Shader.Find("AwesomeTechnologies/Shadows/ShadowHeight");
            List <VegetationCell> processCellList = new List <VegetationCell>();

            vegetationSystemPro.VegetationCellQuadTree.Query(shadowMaskCreator.AreaRect, processCellList);
            for (int i = 0; i <= vegetationSystemPro.VegetationPackageProList.Count - 1; i++)
            {
                for (int j = 0; j <= vegetationSystemPro.VegetationPackageProList[i].VegetationInfoList.Count - 1; j++)
                {
                    VegetationItemInfoPro vegetationItemInfoPro =
                        vegetationSystemPro.VegetationPackageProList[i].VegetationInfoList[j];

                    if (!RenderVegetationType(vegetationItemInfoPro.VegetationType, shadowMaskCreator))
                    {
                        continue;
                    }
                    for (int k = 0; k <= processCellList.Count - 1; k++)
                    {
                        if (j % 10 == 0)
                        {
                            EditorUtility.DisplayProgressBar("Render vegetation item: " + vegetationItemInfoPro.Name,
                                                             "Render cell " + k + "/" + (processCellList.Count - 1),
                                                             k / ((float)processCellList.Count - 1));
                        }

                        VegetationCell vegetationCell   = processCellList[k];
                        string         vegetationItemID = vegetationItemInfoPro.VegetationItemID;

                        vegetationSystemPro.SpawnVegetationCell(vegetationCell, vegetationItemID);

                        NativeList <MatrixInstance> vegetationInstanceList =
                            vegetationSystemPro.GetVegetationItemInstances(vegetationCell, vegetationItemID);

                        VegetationItemModelInfo vegetationItemModelInfo =
                            vegetationSystemPro.GetVegetationItemModelInfo(vegetationItemID);

                        for (int l = 0; l <= vegetationItemModelInfo.VegetationMeshLod0.subMeshCount - 1; l++)
                        {
                            vegetationItemModelInfo.VegetationMaterialsLOD0[l].SetFloat(CullFarStart, 50000);
                            vegetationItemModelInfo.VegetationMaterialsLOD0[l].SetFloat(CullFarDistance, 20);
                        }

                        for (int l = 0; l <= vegetationItemModelInfo.VegetationMeshLod0.subMeshCount - 1; l++)
                        {
                            Material tempMaterial = new Material(vegetationItemModelInfo.VegetationMaterialsLOD0[l]);
                            tempMaterial.shader = overrideShader;
                            tempMaterial.SetPass(0);
                            for (int m = 0; m <= vegetationInstanceList.Length - 1; m++)
                            {
                                Graphics.DrawMeshNow(vegetationItemModelInfo.VegetationMeshLod0, vegetationInstanceList[m].Matrix);
                            }
                            DestroyImmediate(tempMaterial);
                        }
                    }
                    EditorUtility.ClearProgressBar();
                }
            }
        }
Esempio n. 3
0
        void RenderVegetation(List <VegetationCell> processCellList, VegetationSystemPro vegetationSystemPro,
                              VegetationColorMaskCreator colorMaskCreator)
        {
            for (int i = 0; i <= vegetationSystemPro.VegetationPackageProList.Count - 1; i++)
            {
                for (int j = 0; j <= vegetationSystemPro.VegetationPackageProList[i].VegetationInfoList.Count - 1; j++)
                {
                    VegetationItemInfoPro vegetationItemInfoPro =
                        vegetationSystemPro.VegetationPackageProList[i].VegetationInfoList[j];

                    if (!RenderVegetationType(vegetationItemInfoPro.VegetationType, colorMaskCreator))
                    {
                        continue;
                    }
//
                    for (int k = 0; k <= processCellList.Count - 1; k++)
                    {
                        if (j % 10 == 0)
                        {
                            EditorUtility.DisplayProgressBar("Render vegetation item: " + vegetationItemInfoPro.Name,
                                                             "Render cell " + k + "/" + (processCellList.Count - 1),
                                                             k / ((float)processCellList.Count - 1));
                        }

                        VegetationCell vegetationCell   = processCellList[k];
                        string         vegetationItemID = vegetationItemInfoPro.VegetationItemID;

                        vegetationSystemPro.SpawnVegetationCell(vegetationCell, vegetationItemID);

                        NativeList <MatrixInstance> vegetationInstanceList =
                            vegetationSystemPro.GetVegetationItemInstances(vegetationCell, vegetationItemID);
                        List <Matrix4x4> instanceList = new List <Matrix4x4>();

                        for (int l = 0; l <= vegetationInstanceList.Length - 1; l++)
                        {
                            Vector3 position =
                                MatrixTools.ExtractTranslationFromMatrix(vegetationInstanceList[l].Matrix);
                            Vector3    scale    = MatrixTools.ExtractScaleFromMatrix(vegetationInstanceList[l].Matrix);
                            Quaternion rotation =
                                MatrixTools.ExtractRotationFromMatrix(vegetationInstanceList[l].Matrix);
                            Vector3 newPosition = new Vector3(position.x, 0, position.z);
                            Vector3 newScale;
                            if (vegetationItemInfoPro.VegetationType == VegetationType.Grass ||
                                vegetationItemInfoPro.VegetationType == VegetationType.Plant)
                            {
                                newScale = new Vector3(scale.x * colorMaskCreator.VegetationScale,
                                                       scale.y * colorMaskCreator.VegetationScale,
                                                       scale.z * colorMaskCreator.VegetationScale);
                            }
                            else
                            {
                                newScale = scale;
                            }

                            Matrix4x4 newMatrix = Matrix4x4.TRS(newPosition, rotation, newScale);
                            instanceList.Add(newMatrix);
                        }

                        VegetationItemModelInfo vegetationItemModelInfo =
                            vegetationSystemPro.GetVegetationItemModelInfo(vegetationItemID);

                        for (int l = 0; l <= vegetationItemModelInfo.VegetationMeshLod0.subMeshCount - 1; l++)
                        {
                            Material tempMaterial = new Material(vegetationItemModelInfo.VegetationMaterialsLOD0[l]);
                            tempMaterial.shader =
                                Shader.Find("AwesomeTechnologies/Vegetation/RenderVegetationColorMask");
                            tempMaterial.SetPass(0);
                            for (int m = 0; m <= instanceList.Count - 1; m++)
                            {
                                Graphics.DrawMeshNow(vegetationItemModelInfo.VegetationMeshLod0, instanceList[m]);
                            }

                            DestroyImmediate(tempMaterial);
                        }
                    }

                    EditorUtility.ClearProgressBar();
                }
            }


//            for (int i = 0; i <= vegetationSystem.CurrentVegetationPackage.VegetationInfoList.Count - 1; i++)
//            {
//                VegetationItemInfo vegetationItemInfo = vegetationSystem.CurrentVegetationPackage.VegetationInfoList[i];
//                //for (int l = 0; l <= vegetationSystem.VegetationModelInfoList[i].VegetationMeshLod0.subMeshCount - 1; l++)
//                //{
//                //    vegetationSystem.VegetationModelInfoList[i].VegetationMaterialsLOD0[l].SetFloat("_CullFarStart",50000);
//                //    vegetationSystem.VegetationModelInfoList[i].VegetationMaterialsLOD0[l].SetFloat("_CullFarDistance", 20);
//                //}
//
//                if (!RenderVegetationType(vegetationItemInfo.VegetationType,colorMaskCreator)) continue;
//
//                for (int j = 0; j <= processCellList.Count - 1; j++)
//                {
//                    if (j % 100 == 0)
//                    {
//                        EditorUtility.DisplayProgressBar("Render vegetation item: " + vegetationItemInfo.Name, "Render cell " + j + "/" + (processCellList.Count - 1), j / ((float)processCellList.Count - 1));
//                    }
//
//                    VegetationCell vegetationCell = processCellList[j];
//                    List<Matrix4x4> instanceList =
//                        vegetationCell.DirectSpawnVegetation(vegetationItemInfo.VegetationItemID, true);
//
//                    for (int k = 0; k <= instanceList.Count - 1; k++)
//                    {
//                        Vector3 position = MatrixTools.ExtractTranslationFromMatrix(instanceList[k]);
//                        Vector3 scale = MatrixTools.ExtractScaleFromMatrix(instanceList[k]);
//                        Quaternion rotation = MatrixTools.ExtractRotationFromMatrix(instanceList[k]);
//                        Vector3 newPosition = new Vector3(position.x,0,position.z);
//                        Vector3 newScale;
//                        if (vegetationItemInfo.VegetationType == VegetationType.Grass ||
//                            vegetationItemInfo.VegetationType == VegetationType.Plant)
//                        {
//                             newScale = new Vector3(scale.x * colorMaskCreator.VegetationScale, scale.y * colorMaskCreator.VegetationScale, scale.z * colorMaskCreator.VegetationScale);
//                        }
//                        else
//                        {
//                            newScale = scale;
//                        }
//
//                        Matrix4x4 newMatrix = Matrix4x4.TRS(newPosition, rotation, newScale);
//                        instanceList[k] = newMatrix;
//                    }
//
//                    for (int l = 0; l <= vegetationSystem.VegetationModelInfoList[i].VegetationMeshLod0.subMeshCount - 1; l++)
//                    {
//
//                            Material tempMaterial = new Material(vegetationSystem.VegetationModelInfoList[i].VegetationMaterialsLOD0[l]);
//                            tempMaterial.shader =  Shader.Find("AwesomeTechnologies/Vegetation/RenderVegetationColorMask");
//                            tempMaterial.SetPass(0);
//                            for (int k = 0; k <= instanceList.Count - 1; k++)
//                            {
//                                Graphics.DrawMeshNow(vegetationSystem.VegetationModelInfoList[i].VegetationMeshLod0,
//                                    instanceList[k]);
//                                //Graphics.DrawMesh(vegetationSystem.VegetationModelInfoList[i].VegetationMeshLod0, instanceList[k],
//                                //    vegetationSystem.VegetationModelInfoList[i].VegetationMaterialsLOD0[l],
//                                //    colorMaskCreator.InvisibleLayer, null, l);
//                            }
//
//                        DestroyImmediate(tempMaterial);
//                    }
//                }
//                EditorUtility.ClearProgressBar();
//            }
        }