// Copyright © 2018 Procedural Worlds Pty Limited. All Rights Reserved. using UnityEngine; using System.Collections.Generic; using System; /* * Scriptable Object containing settings for a stamper */ namespace Gaia { /// Contains information about a Sequence of clips to play and how [CreateAssetMenu(menuName = "Procedural Worlds/Gaia/Stamper Settings")] [System.Serializable] public class StamperSettings : ScriptableObject, ISerializationCallbackReceiver { #region Public Variables /// /// Stamp x location - done this way to expose in the editor as a simple slider /// public double m_x = 0; /// /// Stamp y location - done this way to expose in the editor as a simple slider /// public double m_y = 50; /// /// Stamp z location - done this way to expose in the editor as a simple slider /// public double m_z = 0; /// /// Are these stamper settings folded out when viewed in an editor? /// public bool m_isFoldedOut; /// /// Stamp width - this is the horizontal scaling factor - applied to both x & z /// public float m_width = 10f; /// /// Stamp height - this is the vertical scaling factor /// public float m_height = 10f; /// /// The strength of the blending operation in the stamper /// public float m_blendStrength = 0.5f; /// /// The absolute added / subtracted height for add / subtract height operations /// public float m_absoluteHeightValue; /// /// Stamp rotation /// public float m_rotation = 0f; /// /// Is this stamper intended to be used on world map terrains? /// public bool m_isWorldmapStamper = false; /// /// The current operation that the stamper will perform on the terrain when pressing the stamp button /// public GaiaConstants.FeatureOperation m_operation = GaiaConstants.FeatureOperation.RaiseHeight; /// /// The ground / base level - value in 0..1 that determines where the base of the stamp is as a % pf overall stamp height. /// Initially loaded from scanned value stored in the stamp, but can be overridden. /// public float m_baseLevel = 0f; /// /// Whether or not to draw any portion of the stamp below the base level of the stamp /// public bool m_drawStampBase = true; /// /// Should the base level adapt itself to the existing shape of the terrain? /// public bool m_adaptiveBase = false; /// /// size of the increased features when using Effects>Contrast /// public float m_contrastFeatureSize = 10; /// /// strength of the contrast effect when using Effects>Contrast /// public float m_contrastStrength = 2; /// /// size of the features being included in a terrace when using Effects>Terraces /// public float m_terraceCount = 100f; /// /// Added Jitter when using Effects>Terraces /// public float m_terraceJitterCount = 0.5f; /// /// Bevel Amount when using Effects>Terraces /// public float m_terraceBevelAmountInterior; /// /// Sharpness when using Effects>Sharpen Ridges /// public float m_sharpenRidgesMixStrength = 0.5f; /// /// Erosion Amount when using Effects>Sharpen Ridges /// public float m_sharpenRidgesIterations = 16f; public float m_powerOf; public float m_smoothVerticality = 0f; public float m_smoothBlurRadius = 10f; /// /// A fixed Image masked used as input for some of the operations. /// public ImageMask m_stamperInputImageMask = new ImageMask(); /// /// The mix level of the stamp for the mix height operation. /// public float m_mixMidPoint = 0.5f; /// /// The strength of the mix height operation. /// public float m_mixHeightStrength = 0.5f; public GaiaConstants.AutoSpawnerArea m_autoSpawnerArea = GaiaConstants.AutoSpawnerArea.Local; public GaiaConstants.AutoSpawnerArea m_autoMaskExportArea = GaiaConstants.AutoSpawnerArea.Local; /// /// height transform curve when using Effects > Height Transform /// public AnimationCurve m_heightTransformCurve = ImageMask.NewAnimCurveStraightUpwards(); /// /// The base terrain input type, only relevant if these stamper settings are used in the stamper created by the world designer /// public BaseTerrainInputType m_baseTerrainInputType; /// /// The terrain used for input in the world designer stamper /// public Terrain m_inputTerrain; #region Erosion Settings public float m_erosionSimScale = 0.5f; public float m_erosionHydroTimeDelta = 0.07f; public int m_erosionHydroIterations = 10; public float m_erosionThermalTimeDelta = 0.01f; public int m_erosionThermalIterations = 8; public int m_erosionThermalReposeAngle = 80; public float m_erosionPrecipRate = 0.5f; public float m_erosionEvaporationRate = 0.5f; public float m_erosionFlowRate = 0.5f; public float m_erosionSedimentCapacity = 0.5f; public float m_erosionSedimentDepositRate = 0.8f; public float m_erosionSedimentDissolveRate = 0.5f; public float m_erosionRiverBankDepositRate = 7.0f; public float m_erosionRiverBankDissolveRate = 5.0f; public float m_erosionRiverBedDepositRate = 5.0f; public float m_erosionRiverBedDissolveRate = 5.0f; #endregion //All image filters that are being applied in this stamping process public ImageMask[] m_imageMasks = new ImageMask[0]; /// /// Removes References to Texture2Ds in Image masks. The image mask will still remember the GUID of that texture to load it when needed. /// Call this when you are "done" with the stamper settings to free up memory caused by these references. /// public void ClearImageMaskTextures() { m_stamperInputImageMask.FreeTextureReferences(); if (m_imageMasks != null) { foreach (ImageMask im in m_imageMasks) { im.FreeTextureReferences(); } } Resources.UnloadUnusedAssets(); } private void OnDestroy() { ClearImageMaskTextures(); } #endregion #region Serialization public void OnBeforeSerialize() { } public void OnAfterDeserialize() { //if (m_clipData != null && m_clipData.Length > 0) //{ // m_clipData = new ClipData[m_clips.Length]; // for (int i = 0; i < m_clips.Length; ++i) // { // m_clipData[i] = new ClipData(m_clips[i], 1f); // } // m_clips = null; //} } /// /// Returns the correct stamper scale for an add / subtract operation to add or subtract X meters from the terrain /// /// The terrain the stamp operation is being performed on /// The height value in meter that needs to be added or subtracted. /// public float GetStampScaleByMeter(Terrain terrain, float heightValueInMeter) { //exception for height = 0, we can't put 0 as y-scale on the stamper. if (heightValueInMeter == 0) { return 0.0000001f; } return Mathf.Lerp(0f, 50f, Mathf.InverseLerp(0f, terrain.terrainData.size.y, Mathf.Abs(heightValueInMeter))); } public void CopyFromTerrainModifierStampResource(ResourceProtoTerrainModifierStamp protoTerrainModifierStamp) { m_absoluteHeightValue = protoTerrainModifierStamp.m_absoluteHeightValue; m_rotation = protoTerrainModifierStamp.m_rotation; m_operation = protoTerrainModifierStamp.m_operation; m_blendStrength = protoTerrainModifierStamp.m_blendStrength; m_y = protoTerrainModifierStamp.m_y; m_height = protoTerrainModifierStamp.m_height; m_heightTransformCurve = new AnimationCurve(protoTerrainModifierStamp.m_heightTransformCurve.keys); m_contrastFeatureSize = protoTerrainModifierStamp.m_contrastFeatureSize; m_contrastStrength = protoTerrainModifierStamp.m_contrastStrength; m_terraceCount = protoTerrainModifierStamp.m_terraceCount; m_terraceJitterCount = protoTerrainModifierStamp.m_terraceJitterCount; m_terraceBevelAmountInterior = protoTerrainModifierStamp.m_terraceBevelAmountInterior; m_sharpenRidgesMixStrength = protoTerrainModifierStamp.m_sharpenRidgesMixStrength; m_sharpenRidgesIterations = protoTerrainModifierStamp.m_sharpenRidgesIterations; m_powerOf = protoTerrainModifierStamp.m_powerOf; m_smoothVerticality = protoTerrainModifierStamp.m_smoothVerticality; m_smoothBlurRadius = protoTerrainModifierStamp.m_smoothBlurRadius; m_stamperInputImageMask = ImageMask.Clone(protoTerrainModifierStamp.m_stamperInputImageMask); m_mixMidPoint = protoTerrainModifierStamp.m_mixMidPoint; m_mixHeightStrength = protoTerrainModifierStamp.m_mixHeightStrength; } #endregion } }