public void DestroyProps(List <GameObject> MarkerObjects, bool RegisterUndo = true) { //Unpaint props List <GameObject> Objs = SelectionManager.GetAllSelectedGameobjects(true); int count = Objs.Count; if (count > 0) { Undo.RegisterUndo(new UndoHistory.HistoryPropsChange()); for (int i = 0; i < count; i++) { PropGameObject TestObj = Objs[i].GetComponent <PropGameObject>(); if (TestObj != null) { TestObj.Connected.Group.PropsInstances.Remove(TestObj.Connected); Destroy(TestObj.gameObject); } } ReloadPropStats(); SelectionManager.Current.CleanSelection(); GoToSelection(); } }
PropGameObject SearchClosestProp(Vector3 Pos, float tolerance) //, out int ClosestP { int GroupsCount = AllPropsTypes.Count; int g = 0; //int p = 0; float dist = 0; //int ClosestG = -1; //ClosestP = -1; float ClosestDist = 1000000f; PropGameObject ToReturn = null; for (g = 0; g < AllPropsTypes.Count; g++) { foreach (Prop PropInstance in AllPropsTypes[g].PropsInstances) { dist = Vector3.Distance(Pos, PropInstance.Obj.Tr.localPosition); if (dist < ClosestDist && dist < tolerance) { //ClosestG = g; ToReturn = PropInstance.Obj; //ClosestP = p; ClosestDist = dist; } } } return(ToReturn); }
public void CreateObject(bool AllowFarLod = true) { Obj = Group.PropObject.CreatePropGameObject( ScmapEditor.ScmapPosToWorld(Position), MassMath.QuaternionFromRotationMatrix(RotationX, RotationY, RotationZ), Scale, AllowFarLod ); Obj.Connected = this; }
public void CreateObject(Vector3 WorldPosition, Quaternion WorldRotation, Vector3 WorldScale, bool AllowFarLod = true) { Obj = Group.PropObject.CreatePropGameObject( WorldPosition, WorldRotation, WorldScale, AllowFarLod ); Obj.Connected = this; Bake(); }
void DuplicateAction() { DuplicatePropData.Clear(); List <GameObject> Objs = SelectionManager.GetAllSelectedGameobjects(false); for (int i = 0; i < Objs.Count; i++) { PropGameObject TestObj = Objs[i].GetComponent <PropGameObject>(); DuplicatePropData.Add(new CopyProp( TestObj.Connected.BlueprintPath, Objs[i].transform.localPosition, Objs[i].transform.localRotation, Objs[i].transform.localScale )); } if (DuplicatePropData.Count > 0) { Undo.RegisterUndo(new UndoHistory.HistoryPropsChange()); UndoRegistered = true; IsPasteAction = true; Vector3 PlaceOffset = new Vector3(0.5f, 0f, -0.5f); PastedObjects.Clear(); PlacementManager.BeginPlacement(PropObjectPrefab, Place); for (int p = 0; p < DuplicatePropData.Count; p++) { RandomPropGroup = GetPropType(DuplicatePropData[p].type); //PropGameObject SpawnedProp = Paint(CopyPropData[p].position + PlaceOffset, CopyPropData[p].rotation); PlacementManager.PlaceAtPosition(DuplicatePropData[p].position + PlaceOffset, DuplicatePropData[p].rotation, Vector3.one); } PlacementManager.Clear(); IsPasteAction = false; UndoRegistered = false; } Debug.Log("Pasted " + PastedObjects.Count + " props"); ReloadPropStats(); GoToSelection(); SelectionManager.Current.CleanSelection(); for (int i = 0; i < PastedObjects.Count; i++) { SelectionManager.Current.SelectObjectAdd(PastedObjects[i]); } }
public void CopyAction() { CopyPropData.Clear(); List <GameObject> Objs = SelectionManager.GetAllSelectedGameobjects(false); for (int i = 0; i < Objs.Count; i++) { PropGameObject TestObj = Objs[i].GetComponent <PropGameObject>(); CopyPropData.Add(new CopyProp( TestObj.Connected.BlueprintPath, Objs[i].transform.localPosition, Objs[i].transform.localRotation, Objs[i].transform.localScale )); } Debug.Log("Copied " + CopyPropData.Count + " props"); }
void DoPaintSymmetryPaint() { if (Invert) { float Tolerance = SymmetryWindow.GetTolerance(); BrushGenerator.Current.GenerateSymmetry(BrushPos, 0, Scatter.value, size); float SearchSize = Mathf.Clamp(size, MinimumRenderBrushSize, MaximumBrushSize); PropGameObject ClosestInstance = SearchClosestProp(BrushGenerator.Current.PaintPositions[0], SearchSize); if (ClosestInstance == null) { return; // No props found } BrushPos = ClosestInstance.transform.position; BrushGenerator.Current.GenerateSymmetry(BrushPos, 0, 0, 0); for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++) { if (i == 0) { RegisterUndo(); TotalMassCount -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimMassMax; TotalEnergyCount -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimEnergyMax; TotalReclaimTime -= ClosestInstance.Connected.Group.PropObject.BP.ReclaimTime; ClosestInstance.Connected.Group.PropsInstances.Remove(ClosestInstance.Connected); Destroy(ClosestInstance.gameObject); } else { PropGameObject TestObj = SearchClosestProp(BrushGenerator.Current.PaintPositions[i], Tolerance); if (TestObj != null) { TotalMassCount -= TestObj.Connected.Group.PropObject.BP.ReclaimMassMax; TotalEnergyCount -= TestObj.Connected.Group.PropObject.BP.ReclaimEnergyMax; TotalReclaimTime -= TestObj.Connected.Group.PropObject.BP.ReclaimTime; TestObj.Connected.Group.PropsInstances.Remove(TestObj.Connected); Destroy(TestObj.gameObject); } } } } else { RandomProp = GetRandomProp(); BrushGenerator.Current.GenerateSymmetry(BrushPos, size, Scatter.value, size); float RotMin = PaintButtons[RandomProp].RotationMin.intValue; float RotMax = PaintButtons[RandomProp].RotationMax.intValue; BrushGenerator.Current.GenerateRotationSymmetry(Quaternion.Euler(Vector3.up * Random.Range(RotMin, RotMax))); // Search group id RandomPropGroup = -1; for (int i = 0; i < AllPropsTypes.Count; i++) { if (AllPropsTypes[i].LoadBlueprint == PaintPropObjects[RandomProp].BP.Path) { RandomPropGroup = i; break; } } if (RandomPropGroup < 0) // Create new group { PropTypeGroup NewGroup = new PropTypeGroup(PaintPropObjects[RandomProp]); RandomPropGroup = AllPropsTypes.Count; AllPropsTypes.Add(NewGroup); } //float BrushSlope = ScmapEditor.Current.Teren. int Min = BrushMini.intValue; int Max = BrushMax.intValue; if (Min > 0 || Max < 90) { Vector3 LocalPos = ScmapEditor.Current.Teren.transform.InverseTransformPoint(BrushGenerator.Current.PaintPositions[0]); LocalPos.x /= ScmapEditor.Current.Teren.terrainData.size.x; LocalPos.z /= ScmapEditor.Current.Teren.terrainData.size.z; float angle = Vector3.Angle(Vector3.up, ScmapEditor.Current.Teren.terrainData.GetInterpolatedNormal(LocalPos.x, LocalPos.z)); if ((angle < Min && Min > 0) || (angle > Max && Max < 90)) { return; } } if (!AllowWaterLevel.isOn && ScmapEditor.Current.map.Water.HasWater) { if (ScmapEditor.Current.Teren.SampleHeight(BrushGenerator.Current.PaintPositions[0]) <= ScmapEditor.Current.WaterLevel.position.y) { return; } } for (int i = 0; i < BrushGenerator.Current.PaintPositions.Length; i++) { Paint(BrushGenerator.Current.PaintPositions[i], BrushGenerator.Current.PaintRotations[i]); } } }
public PropGameObject CreatePropGameObject(Vector3 position, Quaternion rotation, Vector3 scale, bool AllowFarLod = true) { //Reset scale, because it's not supported anyway scale = Vector3.one; PropGameObject NewProp = GameObject.Instantiate(PropsInfo.Current.PropObjectPrefab, PropsInfo.Current.PropsParent).GetComponent <PropGameObject>(); NewProp.gameObject.name = BP.Name; if (BP.LODs.Length > 0) { if (BP.LODs[0].Mesh) { NewProp.Mf.sharedMesh = BP.LODs[0].Mesh; NewProp.Mr.sharedMaterial = BP.LODs[0].Mat; NewProp.Col.size = NewProp.Mf.sharedMesh.bounds.size; } bool Lod1Exist = BP.LODs.Length > 1 && BP.LODs[1].Mesh != null; if (Lod1Exist) { NewProp.Mf1.sharedMesh = BP.LODs[1].Mesh; NewProp.Mr1.sharedMaterial = BP.LODs[1].Mat; } else { NewProp.Mf1.gameObject.SetActive(false); } bool Lod2Exist = Lod1Exist && AllowFarLod && BP.LODs.Length > 2 && BP.LODs[2].Mesh != null; if (Lod2Exist) { NewProp.Mf2.sharedMesh = BP.LODs[2].Mesh; NewProp.Mr2.sharedMaterial = BP.LODs[2].Mat; } else { NewProp.Mf2.gameObject.SetActive(false); } scale.x *= BP.LocalScale.x; scale.y *= BP.LocalScale.y; scale.z *= BP.LocalScale.z; NewProp.Tr.localScale = scale; Lods = NewProp.Lodg.GetLODs(); float DeltaSize = 0.01f; if (BP.LODs[0].Mesh != null) { Vector3 bs = BP.LODs[0].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[0].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[0].LODCutoff * 0.1f); } if (Lod1Exist) { Vector3 bs = BP.LODs[1].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[1].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[1].LODCutoff * 0.1f); } if (Lod2Exist) { Vector3 bs = BP.LODs[2].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[2].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[2].LODCutoff * 0.1f); } if (!Lod1Exist && !Lod2Exist) { Lods = new LOD[] { Lods[0] } } ; else if (!Lod2Exist) { Lods = new LOD[] { Lods[0], Lods[1] } } ; NewProp.Lodg.SetLODs(Lods); NewProp.Tr.localPosition = position; NewProp.Tr.localRotation = rotation; } else { Debug.LogWarning("Prop is empty! " + BP.Path); } return(NewProp); } }
public PropGameObject CreatePropGameObject(Vector3 position, Quaternion rotation, Vector3 scale, bool AllowFarLod = true) { if (IsTemp) { IsTemp = false; for (int i = 0; i < BP.LODs.Length; i++) { if (BP.LODs[i].Albedo != null) { AddToMemory(BP.LODs[i].AlbedoName, BP.LODs[i].Albedo); } else if (BP.LODs[i].AlbedoLoaded) { BP.LODs[i].Albedo = LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, BP.LODs[i].AlbedoName, false, !IsTemp, true); BP.LODs[i].Albedo.anisoLevel = 2; BP.LODs[i].Mat.SetTexture("_MainTex", BP.LODs[i].Albedo); } if (BP.LODs[i].Normal != null) { AddToMemory(BP.LODs[i].NormalsName, BP.LODs[i].Normal); } else if (BP.LODs[i].NormalLoaded) { BP.LODs[i].Normal = LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, BP.LODs[i].NormalsName, true, !IsTemp, true); BP.LODs[i].NormalLoaded = BP.LODs[i].Normal != null; BP.LODs[i].Normal.anisoLevel = 2; BP.LODs[i].Mat.SetTexture("_BumpMap", BP.LODs[i].Normal); } } } //Reset scale, because it's not supported anyway scale = Vector3.one; PropGameObject NewProp = GameObject.Instantiate(PropsInfo.Current.PropObjectPrefab, PropsInfo.Current.PropsParent).GetComponent <PropGameObject>(); NewProp.gameObject.name = BP.Name; if (BP.LODs.Length > 0) { if (BP.LODs[0].Mesh) { NewProp.Mf.sharedMesh = BP.LODs[0].Mesh; NewProp.Mr.sharedMaterial = BP.LODs[0].Mat; NewProp.Col.size = NewProp.Mf.sharedMesh.bounds.size; } bool Lod1Exist = BP.LODs.Length > 1 && BP.LODs[1].Mesh != null; if (Lod1Exist) { NewProp.Mf1.sharedMesh = BP.LODs[1].Mesh; NewProp.Mr1.sharedMaterial = BP.LODs[1].Mat; } else { NewProp.Mf1.gameObject.SetActive(false); } bool Lod2Exist = Lod1Exist && AllowFarLod && BP.LODs.Length > 2 && BP.LODs[2].Mesh != null; if (Lod2Exist) { NewProp.Mf2.sharedMesh = BP.LODs[2].Mesh; NewProp.Mr2.sharedMaterial = BP.LODs[2].Mat; } else { NewProp.Mf2.gameObject.SetActive(false); } scale.x *= BP.LocalScale.x; scale.y *= BP.LocalScale.y; scale.z *= BP.LocalScale.z; NewProp.Tr.localScale = scale; Lods = NewProp.Lodg.GetLODs(); float DeltaSize = 0.01f; if (BP.LODs[0].Mesh != null) { Vector3 bs = BP.LODs[0].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[0].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[0].LODCutoff * 0.1f); } if (Lod1Exist) { Vector3 bs = BP.LODs[1].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[1].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[1].LODCutoff * 0.1f); } if (Lod2Exist) { Vector3 bs = BP.LODs[2].Mesh.bounds.size; DeltaSize = Mathf.Max(scale.x * bs.x, scale.y * bs.y, scale.z * bs.z); Lods[2].screenRelativeTransitionHeight = DeltaSize / DecalsInfo.FrustumHeightAtDistance(BP.LODs[2].LODCutoff * 0.1f); } if (!Lod1Exist && !Lod2Exist) { Lods = new LOD[] { Lods[0] } } ; else if (!Lod2Exist) { Lods = new LOD[] { Lods[0], Lods[1] } } ; NewProp.Lodg.SetLODs(Lods); NewProp.Tr.localPosition = position; NewProp.Tr.localRotation = rotation; } else { Debug.LogWarning("Prop is empty! " + BP.Path); } return(NewProp); } }