public void Execute(int index1) { //for (int index1 = 0; index1 < brushesThatNeedIndirectUpdate.Length; index1++) { var brush1IndexOrder = brushesThatNeedIndirectUpdate[index1]; int brush1NodeOrder = brush1IndexOrder.nodeOrder; NativeListArray <BrushIntersectWith> .NativeList brush1Intersections; if (!brushBrushIntersections.IsAllocated(brush1NodeOrder)) { brush1Intersections = brushBrushIntersections.AllocateWithCapacityForIndex(brush1NodeOrder, 16); } else { brush1Intersections = brushBrushIntersections[brush1NodeOrder]; } for (int index0 = 0; index0 < allTreeBrushIndexOrders.Length; index0++) { var brush0IndexOrder = allTreeBrushIndexOrders[index0]; int brush0NodeOrder = brush0IndexOrder.nodeOrder; if (brush0NodeOrder == brush1NodeOrder // TODO: figure out why this optimization causes iterative updates to fail //|| foundBrushes.IsSet(brush0IndexOrder.nodeOrder) ) { continue; } if (brush0NodeOrder > brush1NodeOrder) { var result = IntersectionUtility.FindIntersection(brush0NodeOrder, brush1NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } else { var result = IntersectionUtility.FindIntersection(brush1NodeOrder, brush0NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } } //*/ }
internal override bool Cross(Bounding selectBound, Entity entity) { Ellipse ellipse = entity as Ellipse; if (ellipse == null) { return(false); } var inter = IntersectionUtility.IntersectEllipseRectangle(ellipse.center, ellipse.RadiusX, ellipse.RadiusY, new CADPoint(selectBound.left, selectBound.bottom), new CADPoint(selectBound.right, selectBound.top)); return(inter.Status == IntersectionUtility.Intersection.IntStatus.Intersection); }
internal override bool Hit(PickupBox pkbox, Entity entity) { Ellipse ellipse = entity as Ellipse; if (ellipse == null) { return(false); } var inter = IntersectionUtility.IntersectEllipseRectangle(ellipse.center, ellipse.RadiusX, ellipse.RadiusY, new CADPoint(pkbox.reservedBounding.left, pkbox.reservedBounding.bottom), new CADPoint(pkbox.reservedBounding.right, pkbox.reservedBounding.top)); return(inter.Status == IntersectionUtility.Intersection.IntStatus.Intersection); }
void MaybeRecomputeCache() { if (!this.LightComponent || !this.isActiveAndEnabled) { return; } if (!this.LightComponent.enabled) { //if (ShadowMapCacheSystem.Instance.ActivelyCachedLights.Contains(this.LightComponent)){ // Check if cached light needs to be updated immediately. // It needs to be updated if there are any dynamic objects moving inside the range. // It also needs to be updated for one frame after all dynamic objects left the range. if (this.DoNotCache || this.lightChanged || this.Moved || IntersectionUtility.DidDynamicObjectsChange(a_light: this, dynamic_objects: ref this.dynamicObjects)) { //Debug.Log("MaybeRecomputeCheck1",this); ShadowMapCacheSystem.Instance.RevertToDynamicLighting(a_light: this); } //} } else if (!this.DoNotCache && !this.lightChanged && !this.Moved) { #if DELAYED_RETRY if (penalty_i > 0) { return; } #endif if (!IntersectionUtility.DidDynamicObjectsChange(a_light: this, dynamic_objects: ref this.dynamicObjects)) { ShadowMapCacheSystem.Instance.EnqueueDirtyCandidate(a_light: this); #if DELAYED_RETRY penalty_i = penalty_delay; #endif } } }
void AddToOverlappingLight() { foreach (var cached_light in ShadowMapCacheSystem.Instance._AllCachedLightComponents) { if (!cached_light || !cached_light.isActiveAndEnabled) { continue; } var intersects = false; switch (cached_light.LightComponent.type) { case LightType.Spot: intersects = IntersectionUtility.ConeSphereIntersection(spot_light: cached_light, dynamic_object: this); break; case LightType.Point: intersects = IntersectionUtility.SphereSphereIntersection(point_light: cached_light, dynamic_object: this); break; case LightType.Directional: case LightType.Area: case LightType.Disc: break; default: throw new ArgumentOutOfRangeException(); } if (intersects) { //Debug.Log("Im a this the one destroying everything",this); cached_light.AddDynamicObject(dob: this); } } }
public void Execute(int index1) { if (allTreeBrushIndexOrders.Length == rebuildTreeBrushIndexOrders.Length) { //for (int index1 = 0; index1 < updateBrushIndicesArray.Length; index1++) { var brush1IndexOrder = rebuildTreeBrushIndexOrders[index1]; int brush1NodeOrder = brush1IndexOrder.nodeOrder; NativeListArray <BrushIntersectWith> .NativeList brush1Intersections; if (!brushBrushIntersections.IsAllocated(brush1NodeOrder)) { brush1Intersections = brushBrushIntersections.AllocateWithCapacityForIndex(brush1NodeOrder, 16); } else { brush1Intersections = brushBrushIntersections[brush1NodeOrder]; } for (int index0 = 0; index0 < rebuildTreeBrushIndexOrders.Length; index0++) { var brush0IndexOrder = rebuildTreeBrushIndexOrders[index0]; int brush0NodeOrder = brush0IndexOrder.nodeOrder; if (brush0NodeOrder <= brush1NodeOrder) { continue; } var result = IntersectionUtility.FindIntersection(brush0NodeOrder, brush1NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } return; } NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref foundBrushes, allTreeBrushIndexOrders.Length); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedBrushes, allTreeBrushIndexOrders.Length); // TODO: figure out a way to avoid needing this for (int a = 0; a < rebuildTreeBrushIndexOrders.Length; a++) { foundBrushes.Set(rebuildTreeBrushIndexOrders[a].nodeOrder, true); } //for (int index1 = 0; index1 < updateBrushIndicesArray.Length; index1++) { var brush1IndexOrder = rebuildTreeBrushIndexOrders[index1]; int brush1NodeOrder = brush1IndexOrder.nodeOrder; NativeListArray <BrushIntersectWith> .NativeList brush1Intersections; if (!brushBrushIntersections.IsAllocated(brush1NodeOrder)) { brush1Intersections = brushBrushIntersections.AllocateWithCapacityForIndex(brush1NodeOrder, 16); } else { brush1Intersections = brushBrushIntersections[brush1NodeOrder]; } for (int index0 = 0; index0 < allTreeBrushIndexOrders.Length; index0++) { var brush0IndexOrder = allTreeBrushIndexOrders[index0]; int brush0NodeOrder = brush0IndexOrder.nodeOrder; if (brush0NodeOrder == brush1NodeOrder) { continue; } var found = foundBrushes.IsSet(brush0NodeOrder); if (brush0NodeOrder < brush1NodeOrder && found) { continue; } var result = IntersectionUtility.FindIntersection(brush0NodeOrder, brush1NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } if (!found) { if (!usedBrushes.IsSet(brush0IndexOrder.nodeOrder)) { usedBrushes.Set(brush0IndexOrder.nodeOrder, true); brushesThatNeedIndirectUpdateHashMap.Add(brush0IndexOrder); result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } else { if (brush0NodeOrder > brush1NodeOrder) { result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } } } }
void DidLightChange() { // Most these checks are not necessary apart from spotlight angle this.lightChanged = false; if (this.LightComponent.enabled && ShadowMapCacheSystem.Instance._ActivelyCachedLights.Contains(item: this.LightComponent)) { this.lightChanged = true; ShadowMapCacheSystem.Instance.RevertToDynamicLighting(a_light: this); } #if LIGHT_CHANGED_TEST if (this.LightComponent.type == LightType.Spot) { if (Math.Abs(value: this.LightComponent.spotAngle - this.lp._SpotAngle) > float.Epsilon) { this.lp._SpotAngle = this.LightComponent.spotAngle; this.lightChanged = true; ShadowMapCacheSystem.Instance.RevertToDynamicLighting(a_light: this); } } /* * if (LightComponent.type != lp.type) * { * // If this happens some weird side effects happens, suspected to be caused by something internally in unity * lp.type = LightComponent.type; * light_changed = true; * //ShadowMapCacheSystem.Instance.RemoveLight(this); * //ShadowMapCacheSystem.Instance.AddLight(this); * } * * * if (LightComponent.color != lp.color) * { * lp.color = LightComponent.color; * light_changed = true; * } * * if (LightComponent.intensity != lp.intensity) * { * lp.intensity = LightComponent.intensity; * light_changed = true; * } * * if (LightComponent.shadowRadius != lp.shadowRadius) * { * lp.shadowRadius = LightComponent.shadowRadius; * light_changed = true; * } * * if (LightComponent.range != lp.range) * { * lp.range = LightComponent.range; * light_changed = true; * } */ #endif IntersectionUtility.RemoveNonOverlapping(a_light: this, dynamic_objects: ref this.dynamicObjects); }