Skip to content

Commit

Permalink
Increase limit for disabling object
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia committed Nov 13, 2024
1 parent cc23d15 commit 57cb019
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine;

namespace AssetBundleConverter.LODsConverter.Utils
Expand All @@ -10,6 +7,7 @@ public class SceneCircumscribedPlanesCalculator
{
private const float PARCEL_SIZE = 16.0f;
private const float EXTEND_AMOUNT = 0.05f;
private const float EXTEND_AMOUNT_FOR_DISABLE = 0.5f;
private const float MAX_HEIGHT = 200f;

private static ParcelCorners CalculateCorners(Vector2Int parcelPosition)
Expand Down Expand Up @@ -55,21 +53,22 @@ public ParcelCorners(Vector3 minXZ, Vector3 minXmaxZ, Vector3 maxXZ, Vector3 max
}
}

private static Bounds CalculateSceneBoundingBox(Vector4 scenePlane, int parcelCount)
private static Bounds CalculateSceneBoundingBox(Vector4 scenePlane)
{
Vector3 center = new Vector3((scenePlane[0] + scenePlane[1]) / 2, 0, (scenePlane[2] + scenePlane[3]) / 2);

//NOTE: I was getting inconsistencies on LOD_1 because weird merging was done underground.
//SO, by setting MAX_HEIGHT * 2, the height wont be larger than MAX_HEIGHT going up,
//And we'll go until MAX_HEIGHT underground
Vector3 size = new Vector3(scenePlane[1] - scenePlane[0] + EXTEND_AMOUNT, MAX_HEIGHT * 2, scenePlane[3] - scenePlane[2] + EXTEND_AMOUNT);
var size = new Vector3(scenePlane[1] - scenePlane[0] + EXTEND_AMOUNT_FOR_DISABLE, MAX_HEIGHT * 2,
scenePlane[3] - scenePlane[2] + EXTEND_AMOUNT_FOR_DISABLE);
return new Bounds(center, size);
}

public static void DisableObjectsOutsideBounds(Parcel parcel, GameObject parent)
{
parent.transform.position = GetPositionByParcelPosition(parcel.GetDecodedBaseParcel());
Bounds sceneBoundingBox = CalculateSceneBoundingBox(CalculateScenePlane(parcel.GetDecodedParcels()), parcel.GetDecodedParcels().Count);
var sceneBoundingBox = CalculateSceneBoundingBox(CalculateScenePlane(parcel.GetDecodedParcels()));
foreach (var renderer in parent.GetComponentsInChildren<MeshFilter>()) {
Bounds meshBounds = renderer.sharedMesh.bounds;
meshBounds.center = renderer.transform.TransformPoint(meshBounds.center);
Expand Down

0 comments on commit 57cb019

Please sign in to comment.