예제 #1
0
        public VegetationPackageProModelInfo(VegetationPackagePro vegetationPackagePro, EnvironmentSettings environmentSettings, List <GameObject> windSamplerList, int cameraCount)
        {
            EnvironmentSettings = environmentSettings;

            for (int i = 0; i <= vegetationPackagePro.VegetationInfoList.Count - 1; i++)
            {
                VegetationItemModelInfo vegetationItemModelInfo =
                    new VegetationItemModelInfo(vegetationPackagePro.VegetationInfoList[i], EnvironmentSettings, windSamplerList, cameraCount);
                VegetationItemModelList.Add(vegetationItemModelInfo);
            }
        }
예제 #2
0
        public VegetationItemModelInfo(VegetationItemInfoPro vegetationItemInfo, EnvironmentSettings environmentSettings, List <GameObject> windSamplerList, int cameraCount)
        {
            EnvironmentSettings = environmentSettings;
            VegetationItemInfo  = vegetationItemInfo;
            VegetationModel     = vegetationItemInfo.VegetationPrefab;

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                VegetationModel = Resources.Load("DefaultGrassPatch") as GameObject;
            }

            if (VegetationModel == null)
            {
                VegetationModel = Resources.Load("MissingVegetationItemCube") as GameObject;
                Debug.LogError("The vegetation prefab of item: " + vegetationItemInfo.Name + " is missing. Please replace or delete VegetationItem.");
            }

            DistanceBand = vegetationItemInfo.GetDistanceBand();

#if UNITY_EDITOR
            MaterialUtility.EnableMaterialInstancing(VegetationModel);
#endif
            SelectedVegetationModelLOD0 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD0);
            SelectedVegetationModelLOD1 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD1);
            SelectedVegetationModelLOD2 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD2);
            SelectedVegetationModelLOD3 = MeshUtils.SelectMeshObject(VegetationModel, LODLevel.LOD3);

            ShaderControler = ShaderSelector.GetShaderControler(vegetationItemInfo.ShaderName);
            if (ShaderControler != null)
            {
                ShaderControler.Settings = vegetationItemInfo.ShaderControllerSettings;
            }
            LODCount = MeshUtils.GetLODCount(VegetationModel, ShaderControler);

            CreateCameraWindSamplerItems(windSamplerList);

            if (ShaderControler != null)
            {
                LODFadePercentage = ShaderControler.Settings.LODFadePercentage;
                LODFadeCrossfade  = ShaderControler.Settings.LODFadeCrossfade;
            }

            VegetationMeshLod0 = GetVegetationMesh(VegetationModel, LODLevel.LOD0);
            VegetationMeshLod1 = GetVegetationMesh(VegetationModel, LODLevel.LOD1);
            VegetationMeshLod2 = GetVegetationMesh(VegetationModel, LODLevel.LOD2);
            VegetationMeshLod3 = GetVegetationMesh(VegetationModel, LODLevel.LOD3);

            VegetationRendererLOD0  = SelectedVegetationModelLOD0.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD0 = CreateMaterials(VegetationRendererLOD0.sharedMaterials, 0);

            VegetationRendererLOD1  = SelectedVegetationModelLOD1.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD1 = CreateMaterials(VegetationRendererLOD1.sharedMaterials, 1);

            VegetationRendererLOD2  = SelectedVegetationModelLOD2.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD2 = CreateMaterials(VegetationRendererLOD2.sharedMaterials, 2);

            VegetationRendererLOD3  = SelectedVegetationModelLOD3.GetComponentInChildren <MeshRenderer>();
            VegetationMaterialsLOD3 = CreateMaterials(VegetationRendererLOD3.sharedMaterials, 3);

            if (vegetationItemInfo.PrefabType == VegetationPrefabType.Texture)
            {
                SetGrassTexture(VegetationMaterialsLOD0, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD1, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD2, vegetationItemInfo.VegetationTexture);
                SetGrassTexture(VegetationMaterialsLOD3, vegetationItemInfo.VegetationTexture);
            }

            VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockLOD0);
            if (VegetationMaterialPropertyBlockLOD0 == null)
            {
                VegetationMaterialPropertyBlockLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockLOD1);
            if (VegetationMaterialPropertyBlockLOD1 == null)
            {
                VegetationMaterialPropertyBlockLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockLOD2);
            if (VegetationMaterialPropertyBlockLOD2 == null)
            {
                VegetationMaterialPropertyBlockLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockLOD3);
            if (VegetationMaterialPropertyBlockLOD3 == null)
            {
                VegetationMaterialPropertyBlockLOD3 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            VegetationRendererLOD0.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD0);
            if (VegetationMaterialPropertyBlockShadowsLOD0 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD0 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            VegetationRendererLOD1.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD1);
            if (VegetationMaterialPropertyBlockShadowsLOD1 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD1 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            VegetationRendererLOD2.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD2);
            if (VegetationMaterialPropertyBlockShadowsLOD2 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD2 = new MaterialPropertyBlock();
            }

            VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            VegetationRendererLOD3.GetPropertyBlock(VegetationMaterialPropertyBlockShadowsLOD3);
            if (VegetationMaterialPropertyBlockShadowsLOD3 == null)
            {
                VegetationMaterialPropertyBlockShadowsLOD3 = new MaterialPropertyBlock();
            }

            LOD1Distance = GetLODDistance(VegetationModel, 0);
            LOD2Distance = GetLODDistance(VegetationModel, 1);
            LOD3Distance = GetLODDistance(VegetationModel, 2);

            vegetationItemInfo.Bounds = MeshUtils.CalculateBoundsInstantiate(VegetationModel);
            BoundingSphereRadius      = (vegetationItemInfo.Bounds.extents.magnitude * VegetationItemInfo.MaxScale * VegetationItemInfo.YScale) + 5;

            CreateCameraBuffers(cameraCount);

            HeightRuleCurveArray = new NativeArray <float>(256, Allocator.Persistent);
            UpdateHeightRuleCurve();


            SteepnessRuleCurveArray = new NativeArray <float>(256, Allocator.Persistent);
            UpdateSteepnessRuleCurve();

            //DistanceFalloffCurveArray = new NativeArray<float>(256, Allocator.Persistent);
            //UpdateDistanceFalloutCurve();

            if (vegetationItemInfo.VegetationType == VegetationType.Tree)
            {
                CreateBillboardMaterial();
            }
        }