public void InitVisual(PoissonModeData modeData, PoissonData data, PoissonPlacer placer, bool isWindow, bool refreshTopMaterial) { if (!isWindow && HelperVisual && refreshTopMaterial) { // Always create new TopMaterial, because when we copy the placer, we don't want the TopMaterial shared TopMaterial = new Material(TopMaterial); UpdateVisualMode(modeData); } if (!HelperVisual) { CreateBoxMesh(); CreateCylinderMesh(); Shader shader = Shader.Find("Poisson/PoissonHelperShader"); TopMaterial = new Material(shader); TopMaterial.SetColor("_OuterColor", new Color(0.0f, 1.0f, 0.0f, 0.8f)); TopMaterial.SetColor("_InnerColor", new Color(1.0f, 0.0f, 0.0f, 0.8f)); TopMaterial.hideFlags = HideFlags.HideInInspector; FaceMaterial = new Material(shader); FaceMaterial.SetColor("_OuterColor", new Color(0.0f, 1.0f, 0.0f, 0.5f)); FaceMaterial.SetColor("_InnerColor", new Color(1.0f, 0.0f, 0.0f, 0.5f)); FaceMaterial.hideFlags = HideFlags.HideInInspector; GameObject parentObj = new GameObject(); if (placer) { parentObj.transform.parent = placer.transform; parentObj.transform.SetAsFirstSibling(); parentObj.transform.parent = parentObj.transform; parentObj.transform.localPosition = Vector3.zero; parentObj.transform.localRotation = Quaternion.identity; parentObj.transform.localScale = Vector3.one; } HelperVisual = new GameObject(); HelperVisual.transform.parent = parentObj.transform; HelperVisual.gameObject.SetActive(false); MeshFilter = HelperVisual.AddComponent <MeshFilter>(); Renderer = HelperVisual.AddComponent <MeshRenderer>(); if (!isWindow) { DeleteHelper = HelperVisual.AddComponent <PoissonDeleteHelper>(); } RefreshVisual(modeData, data, isWindow); } if (placer && !isWindow) { DeleteHelper.Placer = placer; } }
public void RefreshVisual(PoissonModeData modeData, PoissonData data, bool isWindow) { UpdateVisualMode(modeData); UpdateVisualPercentages(modeData); UpdateVisualTexture(modeData, data); UpdateAllowVisualTransformChanges(isWindow); HelperVisual.transform.localPosition = modeData.Position; HelperVisual.transform.localRotation = modeData.Rotation; HelperVisual.transform.localScale = modeData.Scale; }
private void StoreDataHolder() { PoissonModeData.Copy(ModeData, DataHolder.ModeData); PoissonUIData.Copy(UIData, DataHolder.UIData); DataHolder.Data.Resize(Data.Count); for (int i = 0; i < Data.Count; ++i) { PoissonData.Copy(Data[i], DataHolder.Data[i]); } }
public void UpdateVisualTexture(PoissonModeData modeData, PoissonData data) { if (TopMaterial) { TopMaterial.mainTexture = data.Map; TopMaterial.SetInt("_UseMap", (data.Map != null) ? 1 : 0); if (modeData.Mode != DistributionMode.Surface) { SceneView.RepaintAll(); } } }
private void LoadDataHolder() { ModeData = DataHolder.ModeData.DeepCopy(); UIData = DataHolder.UIData.DeepCopy(); Data = new List <PoissonData>(DataHolder.Data.Count); foreach (PoissonData level in DataHolder.Data) { Data.Add(level.DeepCopy()); } SelectedData = Data[UIData.SelectedLevelIndex]; }
private void DistributionInit(int maxNesting) { _activeGrid = EditorData.Grids[_activeLevel]; _activeData = Data[_activeLevel]; if (_activeData.SphereCollisionCheck || _activeData.BoxCollisionCheck) { if (_collidersOverlapHelper == null) { _collidersOverlapHelper = new Collider[1]; } } else { _collidersOverlapHelper = null; } if (_activeData.UseSeed) { Random.InitState(_activeData.Seed); } float cellSize; if (_activeData.Map == null) { cellSize = 1.0f / (_activeData.MinDist / Mathf.Sqrt(2.0f)); } else { cellSize = 1.0f / (_activeData.MaxDist / Mathf.Sqrt(2.0f)); } _activeGrid.GridWidth = Mathf.CeilToInt(_surfaceBounds.size.x * cellSize); _activeGrid.GridDepth = Mathf.CeilToInt(_surfaceBounds.size.z * cellSize); _activeGrid.Grid2D = new Vector2List[_activeGrid.GridWidth * _activeGrid.GridDepth]; if (maxNesting == -1) { _maxNestingLevel = _activeData.MaxSubPlacersNesting; } }
private static bool ValidateLevel(PoissonData data, int index, bool showErrors) { if (data.PoissonObjects == null) { LogError(showErrors, "Poisson -> Poisson Data [Level " + index + "]: variable not set"); return(false); } else if (!data.PoissonObjects.Element.HasWeightedElementsNonNull()) { LogError(showErrors, "Poisson -> Poisson Data [Level " + index + "]: no non null weighted elements inside the weighted data object"); return(false); } if ((!data.ClumpObjects?.Element.HasWeightedElementsNonNull()) ?? false) { LogError(showErrors, "Clumping -> Clump Data [Level " + index + "]: no non null weighted elements inside the weighted data object"); return(false); } return(ValidateMap(data.Map, index, showErrors)); }
private void ValidateSettings(bool showErrors, out bool isValidSurface, out bool preValid, out bool currValid, out bool postValid, out int highestValid) { isValidSurface = ValidateSurfaceBounds(showErrors); preValid = true; currValid = true; postValid = true; highestValid = -1; if (isValidSurface) { for (int i = 0; i < Data.Count; ++i) { PoissonData data = Data[i]; if (i < UIData.SelectedLevelIndex) { preValid &= ValidateLevel(data, i, showErrors); if (preValid) { highestValid = i; } } else if (i > UIData.SelectedLevelIndex) { postValid &= ValidateLevel(data, i, showErrors); if (postValid) { highestValid = i; } } else { currValid = ValidateLevel(data, i, showErrors); if (currValid) { highestValid = i; } } } } }
public PoissonData DeepCopy() { PoissonData data = (PoissonData)MemberwiseClone(); if (PoissonObjectOptions != null) { data.PoissonObjectOptions = new ObjectOptions[PoissonObjectOptions.Length]; for (int i = 0; i < PoissonObjectOptions.Length; ++i) { data.PoissonObjectOptions[i] = PoissonObjectOptions[i].ShallowClone(); } } if (ClumpObjectOptions != null) { data.ClumpObjectOptions = new ObjectOptions[ClumpObjectOptions.Length]; for (int i = 0; i < ClumpObjectOptions.Length; ++i) { data.ClumpObjectOptions[i] = ClumpObjectOptions[i].ShallowClone(); } } return(data); }
public static void Copy(PoissonData from, PoissonData to) { to.Map = from.Map; to.ProjectionLayerMask = from.ProjectionLayerMask; to.ProjectionRaycastTriggerInteraction = from.ProjectionRaycastTriggerInteraction; to.MinDist = from.MinDist; to.MaxDist = from.MaxDist; to.DistToKeepNextLevel = from.DistToKeepNextLevel; to.MinClump = from.MinClump; to.MaxClump = from.MaxClump; to.MinClumpRange = from.MinClumpRange; to.MaxClumpRange = from.MaxClumpRange; to.UseSeed = from.UseSeed; to.Seed = from.Seed; to.Samples = from.Samples; to.SphereCollisionCheck = from.SphereCollisionCheck; to.BoxCollisionCheck = from.BoxCollisionCheck; to.PoissonObjects = from.PoissonObjects; to.ClumpObjects = from.ClumpObjects; int fromLength = (from.PoissonObjectOptions == null) ? -1 : from.PoissonObjectOptions.Length; int toLength = (to.PoissonObjectOptions == null) ? -1 : to.PoissonObjectOptions.Length; if (fromLength != toLength) { if (fromLength == -1) { to.PoissonObjectOptions = null; } else { to.PoissonObjectOptions = new ObjectOptions[fromLength]; to.PoissonObjectOptions.InitNew(); } } for (int i = 0; i < fromLength; ++i) { ObjectOptions.Copy(from.PoissonObjectOptions[i], to.PoissonObjectOptions[i]); } fromLength = (from.ClumpObjectOptions == null) ? -1 : from.ClumpObjectOptions.Length; toLength = (to.ClumpObjectOptions == null) ? -1 : to.ClumpObjectOptions.Length; if (fromLength != toLength) { if (fromLength == -1) { to.ClumpObjectOptions = null; } else { to.ClumpObjectOptions = new ObjectOptions[fromLength]; to.ClumpObjectOptions.InitNew(); } } for (int i = 0; i < fromLength; ++i) { ObjectOptions.Copy(from.ClumpObjectOptions[i], to.ClumpObjectOptions[i]); } to.OverlapLayerMask = from.OverlapLayerMask; to.OverlapRaycastTriggerInteraction = from.OverlapRaycastTriggerInteraction; to.BoundsMode = from.BoundsMode; to.MaxSamples = from.MaxSamples; to.MaxSamplesPreview = from.MaxSamplesPreview; to.MaxSubPlacersNesting = from.MaxSubPlacersNesting; }