protected void UpdateBounds()
        {
            GeometryValid = OnCheckGeometry != null?OnCheckGeometry.Invoke(this.geometry) : CheckGeometry();

            if (!GeometryValid)
            {
                Bounds       = DefaultBound;
                BoundsSphere = DefaultBoundSphere;
            }
            else
            {
                if (!HasInstances)
                {
                    Bounds                    = Geometry.Bound;
                    BoundsSphere              = Geometry.BoundingSphere;
                    BoundsWithTransform       = Bounds.Transform(elementCore.TotalModelMatrix);
                    BoundsSphereWithTransform = BoundsSphere.TransformBoundingSphere(elementCore.TotalModelMatrix);
                }
                else
                {
                    var bound       = Geometry.Bound.Transform(Instances[0]);
                    var boundSphere = Geometry.BoundingSphere.TransformBoundingSphere(Instances[0]);
                    if (Instances.Count > 50)
                    {
                        Parallel.Invoke(() =>
                        {
                            foreach (var instance in Instances)
                            {
                                var b = Geometry.Bound.Transform(instance);
                                BoundingBox.Merge(ref bound, ref b, out bound);
                            }
                        },
                                        () =>
                        {
                            foreach (var instance in Instances)
                            {
                                var bs = Geometry.BoundingSphere.TransformBoundingSphere(instance);
                                BoundingSphere.Merge(ref boundSphere, ref bs, out boundSphere);
                            }
                        });
                    }
                    else
                    {
                        foreach (var instance in Instances)
                        {
                            var b = Geometry.Bound.Transform(instance);
                            BoundingBox.Merge(ref bound, ref b, out bound);
                            var bs = Geometry.BoundingSphere.TransformBoundingSphere(instance);
                            BoundingSphere.Merge(ref boundSphere, ref bs, out boundSphere);
                        }
                    }
                    Bounds                    = bound;
                    BoundsSphere              = boundSphere;
                    BoundsWithTransform       = Bounds.Transform(elementCore.TotalModelMatrix);
                    BoundsSphereWithTransform = BoundsSphere.TransformBoundingSphere(elementCore.TotalModelMatrix);
                }
            }
        }
Exemplo n.º 2
0
 protected override void OnTransformChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnTransformChanged(e);
     if (this.geometryInternal != null)
     {
         BoundsWithTransform       = Bounds.Transform(this.modelMatrix);
         BoundsSphereWithTransform = BoundsSphere.TransformBoundingSphere(this.modelMatrix);
     }
     else
     {
         BoundsWithTransform       = Bounds;
         BoundsSphereWithTransform = BoundsSphere;
     }
 }
 private void OnGeometryPropertyChangedPrivate(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals(nameof(Geometry3D.Positions)))
     {
         UpdateBounds();
     }
     else if (e.PropertyName.Equals(nameof(Geometry3D.Bound)))
     {
         Bounds = Geometry.Bound;
         BoundsWithTransform = Bounds.Transform(elementCore.TotalModelMatrix);
     }
     else if (e.PropertyName.Equals(nameof(Geometry3D.BoundingSphere)))
     {
         BoundsSphere = Geometry.BoundingSphere;
         BoundsSphereWithTransform = BoundsSphere.TransformBoundingSphere(elementCore.TotalModelMatrix);
     }
     if (GeometryValid)
     {
         OnGeometryPropertyChanged(sender, e);
     }
 }
 private void OnTransformChanged(object sender, TransformArgs e)
 {
     BoundsWithTransform       = Bounds.Transform(e);
     BoundsSphereWithTransform = BoundsSphere.TransformBoundingSphere(e);
 }