Click or drag to resize
Ab4d.SharpEngine logo

Scene Class

Scene object provides the definition of the 3D scene that is defined by the SceneNode objects that are added to the RootNode and by lights that are added to the Lights collection. Scene is rendered by the SceneView object.
Inheritance Hierarchy
SystemObject
  Ab4d.SharpEngine.CoreComponentBase
    Ab4d.SharpEngineScene

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 1.0.8740+deb2991acfe86a95cca780cd4f82bcae2805c1a5
Syntax
C#
public class Scene : ComponentBase, ICacheProvider, 
	IDisposable

The Scene type exposes the following members.

Constructors
 NameDescription
Public methodScene(String) Creates Scene object without a VulkanDevice. Before rendering the Scene, it needs to be initialized by calling Initialize(VulkanDevice) method.
Public methodScene(VulkanDevice, String) Creates Scene object and provides a VulkanDevice.
Top
Properties
 NameDescription
Public propertyBackgroundRenderingLayer Gets a RenderingLayer that is rendered first. Objects in this layer are not sorted and are rendered in the same order as they are added to the layer.
Public propertyBackgroundSpritesRenderingLayer Gets a RenderingLayer that contains sprites that are rendered before any other 3D object is rendered. This RenderingLayer is not added to RenderingLayers collection but is rendered in RenderSpritesRenderingStep.
Public propertyComplexGeometryRenderingLayer Gets a RenderingLayer that contains opaque and very complex 3D objects that are expected to take a lot of GPU time to render and should therefore start rendering as soon as possible. Usually this layer contains instanced objects, big point cloud objects or standard objects with many triangles. Objects in this layer are not sorted and are rendered in the main thread (no multi-threading rendering) and in the same order as they are added to the layer.
Public propertyDirtyFlags Gets the dirty flags for this Scene. This value is reset to None when calling Update(Boolean) method.
Public propertyEffectsManager Gets the EffectsManager
Public propertyForegroundRenderingLayer Gets a RenderingLayer that is rendered after standard GeometryRenderingLayer but before TransparentRenderingLayer. Objects in this layer are not sorted and are rendered in the same order as they are added to the layer.
Public propertyGpuDevice VulkanDevice that was used to initialized this Scene.
Public propertyHitTestOptions HitTestOptions specifies hit testing parameters that are used with hit testing.
Public propertyIsDefaultCoordinateSystem Gets true when the default coordinate system (YUpRightHanded) is used.
Public propertyIsMaterialSortingEnabled Gets or sets a Boolean that specified if sorting objects by their materials is enabled. Sorting objects usually improves rendering performance because objects with same materials are rendered one after another and this reduces the required DirectX state changes. Objects are sorted by their material hash value only when they are in the MaterialSortedRenderingLayer (usually all standard and opaque geometry objects). But sometimes user wants to have full control of the order in which the objects are sorted. In this case it is possible to disable material sorting. Default value is true.
Public propertyIsRightHandedCoordinateSystem Gets true when the coordinate system is right handed (YUpRightHanded or ZUpRightHanded).
Public propertyIsTransparencySortingEnabled Gets or sets a Boolean that specifies if sorting transparent objects by their distance to the camera is enabled. Default value is false. See remarks for more info.
Public propertyLights Gets a collection of all scene lights.
Public propertyLightsCount Gets the number of non-ambient lights that are defined in the scene.
Public propertyLineGeometryRenderingLayer Gets a RenderingLayer that contains opaque and single-colored 3D line objects that are rendered with ThickLineEffect. Objects in this layer are not sorted but are rendered with using multi-threading.
Public propertyLineRasterizationMode Gets or sets the mode that specifies how the 3D lines are rendered. By default this value is set to GeometryShader. This is the recommended mode because it is supported on most platforms, is the fastest and provides the most customizations. This value needs to be set before the default ThickLineEffect is initialized.
Public propertyMaxLightsCount Gets or sets the maximum number of lights that can be rendered.
Public propertyOtherGeometryRenderingLayer Gets a RenderingLayer that contains opaque objects that cannot be rendered with StandardEffect. Usually this layer contains pixels, objects with physically based rendering material and other objects with non-standard effect (for example vertex colored materials). The objects in this layer are not rendered with using multi-threading. Objects in this layer are sorted so that they are grouped by material to minimize state changes.
Public propertyOverlayRenderingLayer Gets a RenderingLayer that is rendered last. Objects in this layer are not sorted and are rendered in the same order as they are added to the layer.
Public propertyOverlaySpritesRenderingLayer Gets a RenderingLayer that contains sprites that are rendered after 3D objects are rendered. This RenderingLayer is not added to RenderingLayers collection but is rendered in RenderSpritesRenderingStep.
Public propertyRenderingItemsPool Gets the ObjectPool to get RenderingItem objects.
Public propertyRenderingLayers RenderingLayers is a read only collection of rendering layers that represent queues of RenderingItems that are prepared to be rendered in the FillCommandBufferRenderingStep. RenderingLayer are rendered in the same order as in the RenderingLayers list.
Public propertyRootNode RootNode defines the root GroupNode that contains the SceneNode objects that are shown by this Scene.
Public propertyStandardGeometryRenderingLayer Gets a RenderingLayer that contains standard opaque objects that can be rendered with StandardEffect (all objects with StandardMaterial or objects that are created from WPF 3D objects). Objects in this layer are sorted so that they are grouped by material to minimize state changes and are also rendered with using multi-threading.
Public propertySwapChainImagesCount Gets the number of swap chain images count
Public propertyTransparentRenderingLayer Gets a RenderingLayer that contains transparent objects. Objects in this layer are sorted by their distance to the camera - farthest objects are rendered first.
Top
Methods
 NameDescription
Public methodAddAnimation Adds the specified animation to the list of animations that are updated in each update phase.
Public methodAddRenderingLayerAfter Adds the newRenderLayer after the already registered afterRenderLayer. If rendering layer is MaterialSortedRenderingLayer or CameraDistanceSortedRenderingLayer, then also its IsSortingEnabled property is set according to the current settings.
Public methodAddRenderingLayerBefore Adds the newRenderLayer before the already registered afterRenderLayer
Public methodCacheObject CacheObject sets the specified objectToCache to the specified key in the cache. The value can be retrieved by GetCachedObjectT(String) or removed by RemoveCachedObject(String) method. When a Mesh object is cached, this will set IsSceneCached to true and prevent disposing the mesh (by calling Dispose method) before the Scene is disposed or before the mesh is removed from the cache. Mesh and GpuImage objects can be cached only in one Scene object. This method is thread safe and can be called from any thread.
Public methodCleanup Cleanup method can perform various cleanup actions. It can dispose the SceneNodes (and their meshes and materials) that were removed from the RootNode. It can dispose GPU resources that were scheduled to be disposed after a frame has been rendered. It can also check all memory blocks and free those that are empty (if freeEmptyMemoryBlocks is true or when it empty for at least EngineRuntimeOptions.FramesCountToReleaseEmptyMemoryBlock frames).
Public methodStatic memberCollectAmbientLightColor CollectAmbientLightColor returns a Color3 that specifies the ambient color (can be combined by multiple AmbientLight objects).
Public methodCreateBackgroundSpriteBatch Creates a SpriteBatch that will be rendered before the objects in this Scene are rendered. SpriteBatch that is created from Scene object can use only relative coordinates. To use absolute coordinates, call SceneView.CreateBackgroundSpriteBatch(String) or SceneView.CreateOverlaySpriteBatch(String) methods. To remove the created SpriteBatch call the RemoveSpriteBatch(SpriteBatch, Boolean) or RemoveAllSpriteBatches(Boolean) methods. It is also possible to add sprites that are rendered only with a specific SceneView - in this case call SceneView.CreateBackgroundSpriteBatch(String) or SceneView.CreateOverlaySpriteBatch(String) methods.
Public methodCreateOverlaySpriteBatch Creates a SpriteBatch that will be rendered after the objects in this Scene are rendered. SpriteBatch that is created from Scene object can use only relative coordinates. To use absolute coordinates, call SceneView.CreateBackgroundSpriteBatch(String) or SceneView.CreateOverlaySpriteBatch(String) methods. To remove the created SpriteBatch call the RemoveSpriteBatch(SpriteBatch, Boolean) or RemoveAllSpriteBatches(Boolean) methods. It is also possible to add sprites that are rendered only with a specific SceneView - in this case call SceneView.CreateBackgroundSpriteBatch(String) or SceneView.CreateOverlaySpriteBatch(String) methods.
Public methodDispose Dispose
Protected methodDispose(Boolean) Releases unmanaged and managed resources (when disposing is true). This method may be called only from the CheckAndDispose(Boolean) method and must not be called manually by the user.
(Overrides ComponentBaseDispose(Boolean))
Public methodDumpFullMemoryUsage Writes string that shows full memory usage for this Scene, its GpuDevice and all used effects to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodDumpRenderingLayers Writes string that contains details about each RenderingItem in all RenderingLayers to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodDumpSceneNodes Writes string that contains details about all SceneNodes and their hierarchy to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodDumpUsedMaterials Writes string that provides details about used materials to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodGetAllHitObjects GetAllHitObjects method executes a hit testing on the SceneNodes in this Scene (or when specified on rootSceneNode and its children) and returns a list of RayHitTestResult objects sorted from the closest to the farthest object. When no object is hit, an empty list is returned.
Public methodGetAmbientLightColor Returns the Color3 of the ambient light that is used in this scene. When Black is returned, then no ambient light is used. When multiple AmbientLight objects are added to the Light collection, then their colors are summed.
Public methodGetAmbientLightIntensity Returns the float that represents the intensity of the ambient light that is used in this scene. The returned value is between 0 (no ambient light) and 1 (full ambient light). When multiple AmbientLight objects are added to the Light collection, then their intensities are summed.
Public methodGetCachedObjectT GetCachedObject gets the object that was previously stored by the CacheObject(String, Object) method. If the key is not found a default value of T (null for reference types) is returned. This method is thread safe and can be called from any thread.
Public methodGetCachedObjectsReportString Returns a string that shows which objects are cached by this Scene.
Public methodGetClosestHitObject GetClosestHitObject method executes a hit testing on the SceneNodes in this Scene (or when specified on rootSceneNode and its children) and returns a RayHitTestResult object with the closest triangle hit by the specified ray. When no triangle is hit, null is returned.
Public methodGetCoordinateSystem Gets the currently selected coordinate system.
Public methodGetCoordinateSystemInvertedTransform Get null when YUpRightHanded coordinate system is used. Otherwise a MatrixTransform that has an inverted global transform matrix is returned.
Public methodGetCoordinateSystemTransform Get null when YUpRightHanded coordinate system is used. Otherwise a MatrixTransform is assigned to RootNode.Transform is returned. That MatrixTransform converts all the positions in the Scene from the selected coordinate system to YUpRightHanded is returned. Note that it is not allowed to change the returned MatrixTransform.
Public methodGetFullMemoryUsageInfo Returns a string that shows full memory usage for this Scene, its GpuDevice and all used effects.
Public methodGetHitSceneNodeBounds GetHitSceneNodeBounds returns a List of SceneNode objects where the ray intersects the BoundingBox of the SceneNode.
Public methodGetIntoTheScreenVector Returns the vector that points into the screen. This vector is based on the current coordinate system. When using default (YUpRightHanded) then (0, 0, -1) is returned.
Public methodGetRegisteredEffectsInfo Returns a string that contains details about all registered effects.
Public methodGetRenderingLayersInfo Returns string that describes each RenderingItem in all RenderingLayers.
Public methodGetRightDirectionVector Returns the vector that points to the right in the current coordinate system. (1, 0, 0) is returned for all coordinate systems.
Public methodGetSceneMemoryInfo Returns string that shows memory usage for MatricesMemoryBlocks that are used in this Scene.
Public methodGetSceneNodesInfo Returns string that contains details about all SceneNodes and their hierarchy.
Public methodGetUpVector Returns the vector that points up. This vector is based on the current coordinate system. When using default (YUpRightHanded) then (0, 1, 0) is returned.
Public methodGetUsedMaterialsInfo Returns a string that provides details about used materials
Public methodHitTestSceneNode Returns RayHitTestResult if the specified ray hits the specified sceneNode. Otherwise null is returned. Child SceneNodes are not tested.
Public methodInitialize Initialized the Scene by using the specified VulkanDevice.
Public methodNotifyChange NotifyChange method adds the specified ChangeNotifications to the changes flags of this Scene.
Protected methodOnSceneInitialized OnSceneInitialized
Public methodRemoveAllSpriteBatches Removes all SpriteBatches.
Public methodRemoveAnimation Remove the specified animation from the list of animations.
Public methodRemoveCachedObject RemoveCachedObject removes the specified key from the cache. When a Mesh object is removed from the cache, this will set IsSceneCached to false and allow disposing the mesh by calling the Dispose method. This method is thread safe and can be called from any thread.
Public methodRemoveRenderingLayer Removes the renderingLayer that was added before by the AddRenderingLayerAfter(RenderingLayer, RenderingLayer) or AddRenderingLayerBefore(RenderingLayer, RenderingLayer) methods.
Public methodRemoveSpriteBatch Removes the specified SpriteBatch from the list of SpriteBatches associated to this Scene (created by CreateBackgroundSpriteBatch(String) or CreateOverlaySpriteBatch(String) methods).
Public methodSetAmbientLight(Color3) Sets the ambient light for this scene to the specified color.
Public methodSetAmbientLight(Single) Sets the ambient light for this scene to the specified intensity (from 0 to 1).
Public methodSetCoordinateSystem SetCoordinateSystem method can be used to change the coordinate system from the default YUpRightHanded coordinate system (y up, x to the right, z out of the screen) to some other coordinate system, for example to ZUpRightHanded that is usually used for CAD applications.
Public methodSortRenderingLayers SortRenderingLayers method performs sorting of items in the rendering layers that support sorting
Public methodToString
(Overrides ObjectToString)
Public methodUpdate Update method can be called to update the changed materials and SceneNodes that are attached to the RootNode. This method also clears the DirtyFlags. This method is usually called from SceneView's Render(Boolean, Boolean, Boolean) method. It can be also called before hit-testing to update the scene.
Public methodUpdateAnimations Update all animations that are added by calling the AddAnimation(IAnimation) (this is done automatically by the animation classes).
Public methodUpdateGpuBuffers UpdateGpuBuffers method checks if the scene, camera, lights or matrices data were changed and in this case updates the appropriate buffer based on the swapChainImageIndex parameter. This method must be called before each rendering (especially when swapChainImageIndex is changing).
Public methodUpdateSceneAndLightsData UpdateSceneAndLightsData method updated the scene, camera and lights data structures and marks scene and lights buffers as dirty. This method can be called only when there are any camera or light changed. The actual buffers are updated in the UpdateGpuBuffers(RenderingContext) method.
Public methodUpdateSceneNodeWorldMatrixData UpdateSceneNodeWorldMatrixData method get the World matrix from the specified SceneNode and updates the matrix data in the GPU buffers.
Top
Events
 NameDescription
Public eventSceneInitialized SceneInitialized is triggered when the Initialize(VulkanDevice) method is called and after all the objects that require GpuDevice are initialized.
Top
Fields
 NameDescription
Public fieldAllLightsDescriptorSetLayout DescriptorSetLayout for all loghts data
Public fieldAllLightsDescriptorSets All lights DescriptorSet
Public fieldStatic memberDefaultCoordinateSystem Default coordinate system type: YUpRightHanded
Public fieldModelDescriptorSetLayout DescriptorSetLayout for matrices data
Public fieldStatic memberRequireCommandBuffersRecodingDirtyFlagsBit When this bit is set in the DirtyFlags, then command buffer needs to be recorded again.
Public fieldStatic memberRequireDisposeAllRenderingItemsFlagsBit When this bit is set in the DirtyFlags, then all the RenderingItems need to be regenerated.
Public fieldStatic memberRequireRenderingLayersCreationDirtyFlagsBit When this bit is set in the DirtyFlags, then the rendering layers need to be regenerated and command buffer needs to be recorded again.
Public fieldStatic memberRequireSceneNodeUpdateDirtyFlagsBit When this bit is set in the DirtyFlags, then the Update method on all SceneNodes needs to be called.
Public fieldSceneDescriptorSetLayout DescriptorSetLayout for the Scene data
Public fieldSceneDescriptorSets Scene DescriptorSets
Public fieldStatic memberStandardFragmentShaderPushConstantsSize StandardFragmentShaderPushConstantsSize defines the size of PushConstants used in fragment shader by the standard rendering process (push constant value defines the material index). This value is used when defining the PipelineLayout.
Public fieldStatic memberStandardVertexShaderPushConstantsSize StandardVertexShaderPushConstantsSize defines the size of PushConstants used in vertex shader by the standard rendering process (push constant value defines the index of the object world matrix). This value is used when defining the PipelineLayout.
Top
See Also