| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.ECS7.InternalComponents; |
| | 3 | | using DCL.ECSRuntime; |
| | 4 | | using DCL.Models; |
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace ECSSystems.ECSSceneBoundsCheckerSystem |
| | 10 | | { |
| | 11 | | public class ECSSceneBoundsCheckerSystem |
| | 12 | | { |
| | 13 | | private readonly IInternalECSComponent<InternalSceneBoundsCheck> sceneBoundsCheckComponent; |
| | 14 | | private readonly IInternalECSComponent<InternalVisibility> visibilityComponent; |
| | 15 | | private readonly IInternalECSComponent<InternalRenderers> renderersComponent; |
| | 16 | | private readonly IInternalECSComponent<InternalColliders> pointerCollidersComponent; |
| | 17 | | private readonly IInternalECSComponent<InternalColliders> physicsCollidersComponent; |
| | 18 | | private readonly IECSOutOfSceneBoundsFeedbackStyle outOfBoundsVisualFeedback; |
| 1 | 19 | | private readonly Dictionary<int, Tuple<Bounds, Vector3>> scenesOuterBounds = new Dictionary<int, Tuple<Bounds, V |
| 1 | 20 | | private readonly Dictionary<int, HashSet<Vector2Int>> scenesHashSetParcels = new Dictionary<int, HashSet<Vector2 |
| | 21 | | private readonly BaseList<IParcelScene> loadedScenes; |
| 1 | 22 | | private readonly HashSet<IDCLEntity> entitiesOutsideSceneBounds = new HashSet<IDCLEntity>(); |
| | 23 | |
|
| 1 | 24 | | public ECSSceneBoundsCheckerSystem( |
| | 25 | | BaseList<IParcelScene> loadedScenes, |
| | 26 | | IInternalECSComponent<InternalSceneBoundsCheck> sbcComponent, |
| | 27 | | IInternalECSComponent<InternalVisibility> visibilityComponent, |
| | 28 | | IInternalECSComponent<InternalRenderers> renderersComponent, |
| | 29 | | IInternalECSComponent<InternalColliders> pointerColliderComponent, |
| | 30 | | IInternalECSComponent<InternalColliders> physicsColliderComponent, |
| | 31 | | bool previewMode = false) |
| | 32 | | { |
| 1 | 33 | | this.loadedScenes = loadedScenes; |
| 1 | 34 | | this.sceneBoundsCheckComponent = sbcComponent; |
| 1 | 35 | | this.visibilityComponent = visibilityComponent; |
| 1 | 36 | | this.renderersComponent = renderersComponent; |
| 1 | 37 | | this.pointerCollidersComponent = pointerColliderComponent; |
| 1 | 38 | | this.physicsCollidersComponent = physicsColliderComponent; |
| | 39 | |
|
| 1 | 40 | | loadedScenes.OnAdded += OnSceneAdded; |
| 1 | 41 | | loadedScenes.OnRemoved += OnSceneRemoved; |
| | 42 | |
|
| 1 | 43 | | outOfBoundsVisualFeedback = previewMode ? new ECSOutOfSceneBoundsFeedback_RedWireframe() : new ECSOutOfScene |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | public void Dispose() |
| | 47 | | { |
| 1 | 48 | | loadedScenes.OnAdded -= OnSceneAdded; |
| 1 | 49 | | loadedScenes.OnRemoved -= OnSceneRemoved; |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | private void OnSceneAdded(IParcelScene scene) |
| | 53 | | { |
| | 54 | | // global scenes do not have boundaries to check |
| 0 | 55 | | if (scene.isPersistent) |
| 0 | 56 | | return; |
| | 57 | |
|
| 0 | 58 | | IReadOnlyList<Vector2Int> parcels = scene.sceneData.parcels; |
| 0 | 59 | | var sceneNumber = scene.sceneData.sceneNumber; |
| | 60 | |
|
| 0 | 61 | | Bounds outerBounds = UtilsScene.CalculateOuterBounds(parcels, scene.GetSceneTransform().position); |
| 0 | 62 | | scenesOuterBounds.Add(sceneNumber, new Tuple<Bounds, Vector3>(outerBounds, outerBounds.center - scene.GetSce |
| | 63 | |
|
| 0 | 64 | | HashSet<Vector2Int> hashSetParcels = new HashSet<Vector2Int>(); |
| 0 | 65 | | for (int i = 0; i < parcels.Count; i++) |
| | 66 | | { |
| 0 | 67 | | hashSetParcels.Add(parcels[i]); |
| | 68 | | } |
| 0 | 69 | | scenesHashSetParcels.Add(sceneNumber, hashSetParcels); |
| 0 | 70 | | } |
| | 71 | |
|
| | 72 | | private void OnSceneRemoved(IParcelScene scene) |
| | 73 | | { |
| 0 | 74 | | var sceneNumber = scene.sceneData.sceneNumber; |
| 0 | 75 | | scenesOuterBounds.Remove(sceneNumber); |
| 0 | 76 | | scenesHashSetParcels.Remove(sceneNumber); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public void Update() |
| | 80 | | { |
| 0 | 81 | | ProcessRendererComponentChanges(sceneBoundsCheckComponent, renderersComponent.GetForAll()); |
| 0 | 82 | | ProcessPhysicColliderComponentChanges(sceneBoundsCheckComponent, physicsCollidersComponent.GetForAll()); |
| 0 | 83 | | ProcessPointerColliderComponentChanges(sceneBoundsCheckComponent, pointerCollidersComponent.GetForAll()); |
| | 84 | |
|
| | 85 | | // Note: the components are traversed backwards as we may free the 'fully defaulted' entities from the compo |
| 0 | 86 | | var sbcComponentGroup = sceneBoundsCheckComponent.GetForAll(); |
| | 87 | |
|
| 0 | 88 | | for (int i = sbcComponentGroup.Count - 1; i >= 0; i--) |
| | 89 | | { |
| 0 | 90 | | var componentData = sbcComponentGroup[i].value; |
| 0 | 91 | | IParcelScene scene = componentData.scene; |
| 0 | 92 | | IDCLEntity entity = componentData.entity; |
| 0 | 93 | | InternalSceneBoundsCheck model = componentData.model; |
| | 94 | |
|
| 0 | 95 | | if (!model.dirty || scene.isPersistent) continue; |
| | 96 | |
|
| 0 | 97 | | bool physicsColliderRemoved = WereColliderComponentRemoved(scene, entity, |
| | 98 | | model.physicsColliders, physicsCollidersComponent); |
| | 99 | |
|
| 0 | 100 | | bool pointerColliderRemoved = WereColliderComponentRemoved(scene, entity, |
| | 101 | | model.pointerColliders, pointerCollidersComponent); |
| | 102 | |
|
| 0 | 103 | | bool renderersRemoved = WereRendererComponentRemoved(scene, entity, |
| | 104 | | model.renderers, renderersComponent); |
| | 105 | |
|
| 0 | 106 | | bool isMeshDirty = model.meshesDirty | physicsColliderRemoved | pointerColliderRemoved | renderersRemove |
| | 107 | |
|
| 0 | 108 | | if (isMeshDirty) |
| | 109 | | { |
| 0 | 110 | | if (physicsColliderRemoved) |
| 0 | 111 | | model.physicsColliders = null; |
| | 112 | |
|
| 0 | 113 | | if (pointerColliderRemoved) |
| 0 | 114 | | model.pointerColliders = null; |
| | 115 | |
|
| 0 | 116 | | if (renderersRemoved) |
| 0 | 117 | | model.renderers = null; |
| | 118 | |
|
| 0 | 119 | | model = RecalculateEntityMeshBounds(entity, model); |
| | 120 | |
|
| | 121 | | // If all meshes were removed we need to reset the feedback. |
| 0 | 122 | | if (model.entityLocalMeshBounds.size == Vector3.zero) |
| | 123 | | { |
| 0 | 124 | | SetInsideBoundsStateForMeshComponents(outOfBoundsVisualFeedback, entity, model, |
| | 125 | | IsEntityVisible(scene, entity, visibilityComponent), true); |
| | 126 | | } |
| | 127 | |
|
| 0 | 128 | | model.meshesDirty = false; |
| 0 | 129 | | sceneBoundsCheckComponent.PutFor(scene, entity, model); |
| | 130 | | } |
| | 131 | |
|
| 0 | 132 | | if (sceneBoundsCheckComponent.IsFullyDefaulted(scene, entity)) |
| | 133 | | { |
| 0 | 134 | | entitiesOutsideSceneBounds.Remove(entity); |
| | 135 | |
|
| | 136 | | // Since no other component is using the internal SBC component, we remove it. |
| 0 | 137 | | sceneBoundsCheckComponent.RemoveFor(scene, entity); |
| 0 | 138 | | continue; |
| | 139 | | } |
| | 140 | |
|
| 0 | 141 | | Bounds sceneOuterBounds = scenesOuterBounds[scene.sceneData.sceneNumber].Item1; |
| 0 | 142 | | sceneOuterBounds.center = scene.GetSceneTransform().position + scenesOuterBounds[scene.sceneData.sceneNu |
| 0 | 143 | | RunEntityEvaluation( |
| | 144 | | scene, |
| | 145 | | entity, |
| | 146 | | scenesHashSetParcels[scene.sceneData.sceneNumber], |
| | 147 | | sceneOuterBounds, |
| | 148 | | entitiesOutsideSceneBounds, |
| | 149 | | model, |
| | 150 | | outOfBoundsVisualFeedback, |
| | 151 | | IsEntityVisible(scene, entity, visibilityComponent) |
| | 152 | | ); |
| | 153 | | } |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | private static void RunEntityEvaluation(IParcelScene scene, IDCLEntity entity, HashSet<Vector2Int> parcels, Boun |
| | 157 | | InternalSceneBoundsCheck sbcComponentModel, IECSOutOfSceneBoundsFeedbackStyle outOfBoundsVisualFeedback, boo |
| | 158 | | { |
| | 159 | | // If it has a mesh we don't evaluate its position due to artists common "pivot point sloppiness", we evalua |
| 0 | 160 | | if (sbcComponentModel.entityLocalMeshBounds.size != Vector3.zero) // has a mesh/collider |
| 0 | 161 | | EvaluateMeshBounds(scene, entity, parcels, sceneOuterBounds, entitiesOutsideSceneBounds, sbcComponentMod |
| | 162 | | else |
| 0 | 163 | | EvaluateEntityPosition(scene, entity, parcels, sceneOuterBounds, entitiesOutsideSceneBounds, sbcComponen |
| | 164 | |
|
| 0 | 165 | | SetInsideBoundsStateForNonMeshComponents(entity, entitiesOutsideSceneBounds, sbcComponentModel); |
| 0 | 166 | | } |
| | 167 | |
|
| | 168 | | private static void EvaluateEntityPosition(IParcelScene scene, IDCLEntity entity, HashSet<Vector2Int> parcels, B |
| | 169 | | { |
| | 170 | | // 1. Cheap outer-bounds check |
| 0 | 171 | | bool isInsideSceneOuterBounds = scene.isPersistent || UtilsScene.IsInsideSceneOuterBounds(sceneOuterBounds, |
| | 172 | |
|
| | 173 | | // 2. Confirm with inner-bounds check only if entity is inside outer bounds |
| 0 | 174 | | Vector3 entityWorldPosition = sbcComponentModel.entityPosition + CommonScriptableObjects.worldOffset.Get(); |
| 0 | 175 | | bool isInsideSceneInnerBounds = scene.isPersistent || (isInsideSceneOuterBounds |
| | 176 | | && UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter.maxCount |
| | 177 | |
|
| 0 | 178 | | UpdateInsideSceneBoundsStatus(entity, entitiesOutsideSceneBounds, isInsideSceneInnerBounds); |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | private static void EvaluateMeshBounds(IParcelScene scene, IDCLEntity entity, HashSet<Vector2Int> parcels, Bound |
| | 182 | | HashSet<IDCLEntity> entitiesOutsideSceneBounds, InternalSceneBoundsCheck sbcComponentModel, IECSOutOfSceneBo |
| | 183 | | { |
| | 184 | | // Since the world's reposition in Unity also affects the entities position, we must use the real entity gam |
| 0 | 185 | | Vector3 entityUnityPosition = entity.gameObject.transform.position; |
| 0 | 186 | | Vector3 globalBoundsMaxPoint = entityUnityPosition + sbcComponentModel.entityLocalMeshBounds.max; |
| 0 | 187 | | Vector3 globalBoundsMinPoint = entityUnityPosition + sbcComponentModel.entityLocalMeshBounds.min; |
| | 188 | |
|
| | 189 | | // 1. Cheap outer-bounds check |
| 0 | 190 | | bool isInsideSceneOuterBounds = scene.isPersistent |
| | 191 | | || (UtilsScene.IsInsideSceneOuterBounds(sceneOuterBounds, globalBoundsMa |
| | 192 | | && UtilsScene.IsInsideSceneOuterBounds(sceneOuterBounds, globalBoundsMin |
| | 193 | |
|
| 0 | 194 | | if (isInsideSceneOuterBounds) |
| | 195 | | { |
| 0 | 196 | | Vector3 worldOffset = CommonScriptableObjects.worldOffset.Get(); |
| | 197 | |
|
| | 198 | | // 2. If entity is inside outer bounds then check full merged bounds AABB |
| 0 | 199 | | bool isInsideSceneInnerBounds = scene.isPersistent |
| | 200 | | || (UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter.max |
| | 201 | | && UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter. |
| | 202 | |
|
| | 203 | | // 3. If merged bounds is detected as outside bounds we need a final check on submeshes (for L-Shaped su |
| 0 | 204 | | if (!isInsideSceneInnerBounds) |
| 0 | 205 | | isInsideSceneInnerBounds = AreSubMeshesAndCollidersInsideBounds(scene, entity, parcels, entitiesOuts |
| | 206 | |
|
| 0 | 207 | | UpdateInsideSceneBoundsStatus(entity, entitiesOutsideSceneBounds, isInsideSceneInnerBounds); |
| | 208 | | } |
| | 209 | | else |
| | 210 | | { |
| 0 | 211 | | UpdateInsideSceneBoundsStatus(entity, entitiesOutsideSceneBounds, false); |
| | 212 | | } |
| | 213 | |
|
| 0 | 214 | | SetInsideBoundsStateForMeshComponents(outOfBoundsVisualFeedback, entity, sbcComponentModel, |
| | 215 | | isVisible, !entitiesOutsideSceneBounds.Contains(entity)); |
| 0 | 216 | | } |
| | 217 | |
|
| | 218 | | private static bool AreSubMeshesAndCollidersInsideBounds(IParcelScene scene, IDCLEntity entity, |
| | 219 | | HashSet<Vector2Int> parcels, HashSet<IDCLEntity> entitiesOutsideSceneBounds, InternalSceneBoundsCheck sbcCom |
| | 220 | | { |
| 0 | 221 | | if (scene.isPersistent) |
| 0 | 222 | | return true; |
| | 223 | |
|
| 0 | 224 | | var renderers = sbcComponentModel.renderers; |
| 0 | 225 | | var physicsColliders = sbcComponentModel.physicsColliders; |
| 0 | 226 | | var pointerColliders = sbcComponentModel.pointerColliders; |
| 0 | 227 | | int renderersCount = renderers?.Count ?? 0; |
| 0 | 228 | | int collidersCount = physicsColliders?.Count ?? 0 + pointerColliders?.Count ?? 0; |
| | 229 | |
|
| | 230 | | // For entities with 1 mesh/collider the already-checked merged bounds already represent its bounds |
| | 231 | | // So we avoid all these unneeded submesh checks for those |
| 0 | 232 | | if (renderersCount + collidersCount <= 1) return !entitiesOutsideSceneBounds.Contains(entity); |
| | 233 | |
|
| 0 | 234 | | if (renderers != null) |
| | 235 | | { |
| 0 | 236 | | for (int i = 0; i < renderersCount; i++) |
| | 237 | | { |
| 0 | 238 | | if (!UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter.maxCount.sceneHeight, rendere |
| 0 | 239 | | return false; |
| | 240 | | } |
| | 241 | | } |
| | 242 | |
|
| 0 | 243 | | if (physicsColliders != null) |
| | 244 | | { |
| 0 | 245 | | var pairs = physicsColliders.Pairs; |
| 0 | 246 | | for (int i = 0; i < pairs.Count; i++) |
| | 247 | | { |
| 0 | 248 | | if (!UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter.maxCount.sceneHeight, pairs[i |
| 0 | 249 | | return false; |
| | 250 | | } |
| | 251 | | } |
| | 252 | |
|
| 0 | 253 | | if (pointerColliders != null) |
| | 254 | | { |
| 0 | 255 | | var pairs = pointerColliders.Pairs; |
| 0 | 256 | | for (int i = 0; i < pairs.Count; i++) |
| | 257 | | { |
| 0 | 258 | | if (!UtilsScene.IsInsideSceneInnerBounds(parcels, scene.metricsCounter.maxCount.sceneHeight, pairs[i |
| 0 | 259 | | return false; |
| | 260 | | } |
| | 261 | | } |
| | 262 | |
|
| 0 | 263 | | return true; |
| | 264 | | } |
| | 265 | |
|
| | 266 | | private static bool WereColliderComponentRemoved(IParcelScene scene, IDCLEntity entity, |
| | 267 | | KeyValueSet<Collider, uint> sbcComponentColliders, IInternalECSComponent<InternalColliders> colliderComponen |
| | 268 | | { |
| 0 | 269 | | return sbcComponentColliders != null && colliderComponent.GetFor(scene, entity) == null; |
| | 270 | | } |
| | 271 | |
|
| | 272 | | private static bool WereRendererComponentRemoved(IParcelScene scene, IDCLEntity entity, |
| | 273 | | IList<Renderer> sbcComponentRenderers, IInternalECSComponent<InternalRenderers> rendererComponent) |
| | 274 | | { |
| 0 | 275 | | return sbcComponentRenderers != null && rendererComponent.GetFor(scene, entity) == null; |
| | 276 | | } |
| | 277 | |
|
| | 278 | | private static void SetInsideBoundsStateForMeshComponents(IECSOutOfSceneBoundsFeedbackStyle outOfBoundsVisualFee |
| | 279 | | InternalSceneBoundsCheck sbcComponentModel, bool isVisible, bool isInsideBounds) |
| | 280 | | { |
| 0 | 281 | | outOfBoundsVisualFeedback.ApplyFeedback(entity, sbcComponentModel, isVisible, isInsideBounds); |
| 0 | 282 | | } |
| | 283 | |
|
| | 284 | | private static void SetInsideBoundsStateForNonMeshComponents(IDCLEntity entity, HashSet<IDCLEntity> entitiesOuts |
| | 285 | | { |
| 0 | 286 | | componentModel.OnSceneBoundsStateChange?.Invoke(!entitiesOutsideSceneBounds.Contains(entity)); |
| 0 | 287 | | } |
| | 288 | |
|
| | 289 | | private static void ProcessRendererComponentChanges(IInternalECSComponent<InternalSceneBoundsCheck> sceneBoundsC |
| | 290 | | IReadOnlyList<KeyValueSetTriplet<IParcelScene, long, ECSComponentData<InternalRenderers>>> rendererComponent |
| | 291 | | { |
| 0 | 292 | | for (int i = 0; i < rendererComponents.Count; i++) |
| | 293 | | { |
| 0 | 294 | | var componentData = rendererComponents[i].value; |
| 0 | 295 | | IParcelScene scene = componentData.scene; |
| 0 | 296 | | IDCLEntity entity = componentData.entity; |
| 0 | 297 | | InternalRenderers model = componentData.model; |
| | 298 | |
|
| 0 | 299 | | if (!model.dirty || scene.isPersistent) continue; |
| | 300 | |
|
| 0 | 301 | | sceneBoundsCheckComponent.SetRenderers(scene, entity, model.renderers); |
| | 302 | | } |
| 0 | 303 | | } |
| | 304 | |
|
| | 305 | | private static void ProcessPointerColliderComponentChanges(IInternalECSComponent<InternalSceneBoundsCheck> scene |
| | 306 | | IReadOnlyList<KeyValueSetTriplet<IParcelScene, long, ECSComponentData<InternalColliders>>> colliderComponent |
| | 307 | | { |
| 0 | 308 | | for (int i = 0; i < colliderComponents.Count; i++) |
| | 309 | | { |
| 0 | 310 | | var componentData = colliderComponents[i].value; |
| 0 | 311 | | IParcelScene scene = componentData.scene; |
| 0 | 312 | | IDCLEntity entity = componentData.entity; |
| 0 | 313 | | InternalColliders model = componentData.model; |
| | 314 | |
|
| 0 | 315 | | if (!model.dirty || scene.isPersistent) continue; |
| | 316 | |
|
| 0 | 317 | | sceneBoundsCheckComponent.SetPointerColliders(scene, entity, model.colliders); |
| | 318 | | } |
| 0 | 319 | | } |
| | 320 | |
|
| | 321 | | private static void ProcessPhysicColliderComponentChanges(IInternalECSComponent<InternalSceneBoundsCheck> sceneB |
| | 322 | | IReadOnlyList<KeyValueSetTriplet<IParcelScene, long, ECSComponentData<InternalColliders>>> colliderComponent |
| | 323 | | { |
| 0 | 324 | | for (int i = 0; i < colliderComponents.Count; i++) |
| | 325 | | { |
| 0 | 326 | | var componentData = colliderComponents[i].value; |
| 0 | 327 | | IParcelScene scene = componentData.scene; |
| 0 | 328 | | IDCLEntity entity = componentData.entity; |
| 0 | 329 | | InternalColliders model = componentData.model; |
| | 330 | |
|
| 0 | 331 | | if (!model.dirty || scene.isPersistent) continue; |
| | 332 | |
|
| 0 | 333 | | sceneBoundsCheckComponent.SetPhysicsColliders(scene, entity, model.colliders); |
| | 334 | | } |
| 0 | 335 | | } |
| | 336 | |
|
| | 337 | | private static bool IsEntityVisible(IParcelScene scene, IDCLEntity entity, IInternalECSComponent<InternalVisibil |
| | 338 | | { |
| 0 | 339 | | return visibilityComponent.GetFor(scene, entity)?.model.visible ?? true; |
| | 340 | | } |
| | 341 | |
|
| | 342 | | private static InternalSceneBoundsCheck RecalculateEntityMeshBounds(IDCLEntity entity, InternalSceneBoundsCheck |
| | 343 | | { |
| | 344 | | // Clean existing bounds object |
| 0 | 345 | | sbcInternalComponentModel.entityLocalMeshBounds.size = Vector3.zero; |
| | 346 | |
|
| | 347 | | // Note: the center shouldn't be modified beyond this point as it affects the bounds relative values |
| 0 | 348 | | sbcInternalComponentModel.entityLocalMeshBounds.center = entity.gameObject.transform.position; |
| | 349 | |
|
| | 350 | | // Encapsulate with global bounds |
| 0 | 351 | | if (sbcInternalComponentModel.renderers != null) |
| | 352 | | { |
| 0 | 353 | | for (var i = 0; i < sbcInternalComponentModel.renderers.Count; i++) |
| | 354 | | { |
| 0 | 355 | | sbcInternalComponentModel.entityLocalMeshBounds.Encapsulate(sbcInternalComponentModel.renderers[i].b |
| | 356 | | } |
| | 357 | | } |
| | 358 | |
|
| 0 | 359 | | if (sbcInternalComponentModel.physicsColliders != null) |
| | 360 | | { |
| 0 | 361 | | var pairs = sbcInternalComponentModel.physicsColliders.Pairs; |
| 0 | 362 | | for (int i = 0; i < pairs.Count; i++) |
| | 363 | | { |
| 0 | 364 | | sbcInternalComponentModel.entityLocalMeshBounds.Encapsulate(GetColliderBounds(pairs[i].key)); |
| | 365 | | } |
| | 366 | | } |
| | 367 | |
|
| 0 | 368 | | if (sbcInternalComponentModel.pointerColliders != null) |
| | 369 | | { |
| 0 | 370 | | var pairs = sbcInternalComponentModel.pointerColliders.Pairs; |
| 0 | 371 | | for (int i = 0; i < pairs.Count; i++) |
| | 372 | | { |
| 0 | 373 | | sbcInternalComponentModel.entityLocalMeshBounds.Encapsulate(GetColliderBounds(pairs[i].key)); |
| | 374 | | } |
| | 375 | | } |
| | 376 | |
|
| | 377 | | // Turn min-max values to local/relative to be usable when the entity has moved |
| 0 | 378 | | Vector3 entityPosition = entity.gameObject.transform.position; |
| | 379 | |
|
| 0 | 380 | | sbcInternalComponentModel.entityLocalMeshBounds.SetMinMax(sbcInternalComponentModel.entityLocalMeshBounds.mi |
| | 381 | | sbcInternalComponentModel.entityLocalMeshBounds.max - entityPosition); |
| | 382 | |
|
| 0 | 383 | | return sbcInternalComponentModel; |
| | 384 | | } |
| | 385 | |
|
| | 386 | | private static Bounds GetColliderBounds(Collider collider) |
| | 387 | | { |
| | 388 | | // Disabled colliders return a size-0 bounds object, so we enable it only to get its bounds |
| 0 | 389 | | if (!collider.enabled) |
| | 390 | | { |
| | 391 | | // Enable collider to copy its real bounds |
| 0 | 392 | | collider.enabled = true; |
| 0 | 393 | | Bounds returnedBounds = collider.bounds; |
| | 394 | |
|
| | 395 | | // Reset modified values |
| 0 | 396 | | collider.enabled = false; |
| | 397 | |
|
| 0 | 398 | | return returnedBounds; |
| | 399 | | } |
| | 400 | |
|
| 0 | 401 | | return collider.bounds; |
| | 402 | | } |
| | 403 | |
|
| | 404 | | private static void UpdateInsideSceneBoundsStatus(IDCLEntity entity, HashSet<IDCLEntity> entitiesOutsideSceneBou |
| | 405 | | { |
| 0 | 406 | | if (isInside) |
| 0 | 407 | | entitiesOutsideSceneBounds.Remove(entity); |
| | 408 | | else |
| 0 | 409 | | entitiesOutsideSceneBounds.Add(entity); |
| 0 | 410 | | } |
| | 411 | | } |
| | 412 | | } |