Ejemplo n.º 1
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode)
        {
            var time = context.Owner.LastUpdateTime;

            if (time != transformPositionByTime1_Time)
            {
                transformPositionByTime2_Time     = transformPositionByTime1_Time;
                transformPositionByTime2_Position = transformPositionByTime1_Position;
                transformPositionByTime1_Time     = time;
                transformPositionByTime1_Position = TransformV.Position;
            }

            if (mode == GetRenderSceneDataMode.InsideFrustum || (mode == GetRenderSceneDataMode.ShadowCasterOutsideFrustum && CastShadows))
            {
                var size = Size.Value;
                //var color = Color.Value;
                //var opacity = Opacity.Value;
                //if( size != Vector2.Zero )//&& color.Alpha != 0 && opacity != 0 )
                //{

                var context2 = context.objectInSpaceRenderingContext;
                context2.disableShowingLabelForThisObject = true;

                var tr             = Transform.Value;
                var cameraSettings = context.Owner.CameraSettings;
                var trPosition     = tr.Position;

                //update and get LOD info
                var contextItem = SceneLODUtility.UpdateAndGetContextItem(ref renderingContextItems, context, null, VisibilityDistance, ref trPosition);

                bool skip = false;
                if (contextItem.currentLOD == -1 && contextItem.transitionTime == 0)
                {
                    skip = true;
                }

                if (!skip)
                {
                    var item = new Component_RenderingPipeline.RenderSceneData.BillboardItem();
                    item.Creator = this;
                    SpaceBounds.CalculatedBoundingBox.GetCenter(out item.BoundingBoxCenter);
                    item.BoundingSphere = SpaceBounds.CalculatedBoundingSphere;
                    item.CastShadows    = CastShadows;
                    item.ReceiveDecals  = ReceiveDecals;
                    item.Material       = Material;

                    //get data for rendering
                    float itemLodValue = 0;
                    {
                        if (contextItem.currentLOD == 0 && contextItem.toLOD == -1)
                        {
                            itemLodValue = contextItem.transitionTime;
                        }
                        else if (contextItem.currentLOD == -1 && contextItem.toLOD == 0)
                        {
                            itemLodValue = -contextItem.transitionTime;
                        }
                    }

                    //set LOD value
                    item.LODValue = itemLodValue;

                    //!!!!double
                    item.Position = tr.Position.ToVector3F();
                    item.Size     = new Vector2(size.X * Math.Max(tr.Scale.X, tr.Scale.Y), size.Y * tr.Scale.Z).ToVector2F();
                    item.Rotation = Rotation.Value.InRadians().ToRadianF();
                    item.Color    = Color;

                    //PositionPreviousFrame
                    var previousTime = time - context.Owner.LastUpdateTimeStep;
                    if (!GetTransformPositionByTime(previousTime, out var previousPosition))
                    {
                        previousPosition = tr.Position;
                    }
                    item.PositionPreviousFrame = previousPosition.ToVector3F();

                    context.FrameData.RenderSceneData.Billboards.Add(ref item);


                    //display editor selection
                    if (mode == GetRenderSceneDataMode.InsideFrustum)
                    {
                        if (context2.selectedObjects.Contains(this) || context2.canSelectObjects.Contains(this))                             // || context.dragDropCreateObject == this )
                        {
                            if (context2.displayBillboardsCounter < context2.displayBillboardsMax)
                            {
                                context2.displayBillboardsCounter++;

                                ColorValue color;
                                if (context2.selectedObjects.Contains(this))
                                {
                                    color = ProjectSettings.Get.SelectedColor;
                                }
                                else
                                {
                                    color = ProjectSettings.Get.CanSelectColor;
                                }
                                color.Alpha *= .5f;

                                var viewport = context.Owner;
                                if (viewport.Simple3DRenderer != null)
                                {
                                    viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                                    item.GetWorldMatrix(out var worldMatrix);

                                    //!!!!double
                                    worldMatrix.ToMatrix4(out var worldMatrix2);
                                    viewport.Simple3DRenderer.AddMesh(GetBillboardMesh().Result, ref worldMatrix2, false, false);
                                }
                            }
                        }
                    }
                }

                //}
            }
        }
Ejemplo n.º 2
0
 public void ResetLodTransitionStates(ViewportRenderingContext resetOnlySpecifiedContext = null)
 {
     SceneLODUtility.ResetLodTransitionStates(ref renderingContextItems, resetOnlySpecifiedContext);
 }
Ejemplo n.º 3
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode, Component_Scene.GetObjectsInSpaceItem modeGetObjectsItem)
        {
            base.OnGetRenderSceneData(context, mode, modeGetObjectsItem);

            var time = context.Owner.LastUpdateTime;

            if (time != transformPositionByTime1_Time)
            {
                transformPositionByTime2_Time     = transformPositionByTime1_Time;
                transformPositionByTime2_Position = transformPositionByTime1_Position;
                transformPositionByTime1_Time     = time;
                transformPositionByTime1_Position = TransformV.Position;
            }

            if (mode == GetRenderSceneDataMode.InsideFrustum || (mode == GetRenderSceneDataMode.ShadowCasterOutsideFrustum && CastShadows))
            {
                var size = Size.Value;
                //var color = Color.Value;
                //var opacity = Opacity.Value;
                //if( size != Vector2.Zero )//&& color.Alpha != 0 && opacity != 0 )
                //{

                var context2 = context.objectInSpaceRenderingContext;
                context2.disableShowingLabelForThisObject = true;

                var tr             = Transform.Value;
                var cameraSettings = context.Owner.CameraSettings;

                var cameraDistanceMinSquared = SceneLODUtility.GetCameraDistanceMinSquared(cameraSettings, SpaceBounds);
                var visibilityDistance       = VisibilityDistance.Value;

                if (cameraDistanceMinSquared < visibilityDistance * visibilityDistance || mode == GetRenderSceneDataMode.ShadowCasterOutsideFrustum)
                {
                    var allowOutlineSelect = context.renderingPipeline.UseRenderTargets && ProjectSettings.Get.SceneEditorSelectOutlineEffectEnabled;

                    var item = new Component_RenderingPipeline.RenderSceneData.BillboardItem();
                    item.Creator = this;
                    SpaceBounds.CalculatedBoundingBox.GetCenter(out item.BoundingBoxCenter);
                    item.BoundingSphere     = SpaceBounds.CalculatedBoundingSphere;
                    item.CastShadows        = CastShadows;
                    item.ShadowOffset       = (float)ShadowOffset.Value;
                    item.ReceiveDecals      = ReceiveDecals;
                    item.Material           = Material;
                    item.VisibilityDistance = (float)visibilityDistance;
                    item.CutVolumes         = CutVolumes;

                    var specialEffects = SpecialEffects.Value;
                    if (specialEffects != null && specialEffects.Count != 0)
                    {
                        item.SpecialEffects = specialEffects;
                    }

                    //display outline effect of editor selection
                    if (mode == GetRenderSceneDataMode.InsideFrustum && allowOutlineSelect && context2.selectedObjects.Contains(this))
                    {
                        if (context2.displayBillboardsCounter < context2.displayBillboardsMax)
                        {
                            context2.displayBillboardsCounter++;

                            var color = ProjectSettings.Get.SelectedColor.Value;
                            //color.Alpha *= .5f;

                            var effect = new ObjectSpecialRenderingEffect_Outline();
                            effect.Group = int.MaxValue;
                            effect.Color = color;

                            if (item.SpecialEffects != null)
                            {
                                item.SpecialEffects = new List <ObjectSpecialRenderingEffect>(item.SpecialEffects);
                            }
                            else
                            {
                                item.SpecialEffects = new List <ObjectSpecialRenderingEffect>();
                            }
                            item.SpecialEffects.Add(effect);
                        }
                    }

                    //!!!!double
                    item.Position = tr.Position.ToVector3F();
                    item.Size     = new Vector2(size.X * Math.Max(tr.Scale.X, tr.Scale.Y), size.Y * tr.Scale.Z).ToVector2F();
                    item.Rotation = Rotation.Value.InRadians().ToRadianF();
                    item.Color    = Color;

                    //PositionPreviousFrame
                    var previousTime = time - context.Owner.LastUpdateTimeStep;
                    if (!GetTransformPositionByTime(previousTime, out var previousPosition))
                    {
                        previousPosition = tr.Position;
                    }
                    item.PositionPreviousFrame = previousPosition.ToVector3F();

                    context.FrameData.RenderSceneData.Billboards.Add(ref item);


                    //display editor selection
                    if (mode == GetRenderSceneDataMode.InsideFrustum)
                    {
                        if ((!allowOutlineSelect && context2.selectedObjects.Contains(this)) || context2.canSelectObjects.Contains(this))                               // || context.dragDropCreateObject == this )
                        {
                            if (context2.displayBillboardsCounter < context2.displayBillboardsMax)
                            {
                                context2.displayBillboardsCounter++;

                                ColorValue color;
                                if (context2.selectedObjects.Contains(this))
                                {
                                    color = ProjectSettings.Get.SelectedColor;
                                }
                                else
                                {
                                    color = ProjectSettings.Get.CanSelectColor;
                                }
                                color.Alpha *= .5f;

                                var viewport = context.Owner;
                                if (viewport.Simple3DRenderer != null)
                                {
                                    viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                                    item.GetWorldMatrix(out var worldMatrix);

                                    //!!!!double
                                    worldMatrix.ToMatrix4(out var worldMatrix2);
                                    viewport.Simple3DRenderer.AddMesh(GetBillboardMesh().Result, ref worldMatrix2, false, false);
                                }
                            }
                        }
                    }
                }

                //}
            }
        }