S&box Wiki

Revision Difference

Scene_System#560474

<cat>Code.Scene</cat> <title>The Scene System</title> ⤶ <note>This is the system used for rendering. Documentation on the scene system for games can be found [here]( https://docs.facepunch.com/s/sbox-dev/doc/the-scene-system-9V88B33VlE).</note>⤶ ⤶ # Introduction⤶ ⤶ Imagine the scene system as what is dealing with all the different types of things for rendering everything to your screen or technically a texture.⤶ ⤶ This is only used for clients, server has no reason to be rendering anything, no one will ever see what's rendered.⤶ ⤶ Everything from your actual main game world with your player and so on is rendered via the scene system.⤶ Every ModelEntity, WorldEntity and so on, is just creating SceneObjects to go in the main game's SceneWorld to be rendered to the players screen!⤶ ⤶ But it can also be used to do additional stuff like creating extra miniature 3D worlds in UI elements, Or adding an extra SceneCamera to render a CCTV camera to a monitor entity and so on, you can do a lot with them!⤶ ⤶ # What does the Scene System consist of?⤶ ⤶ ## SceneWorld⤶ #### Contains all the SceneObjects for a specific world we want in one place⤶ A SceneWorld is just a collection of all the SceneObjects that you want to be contained in one separate world for rendering, then extra options for trace related stuff on all SceneObjects.⤶ ⤶ Every time you want to create anything scene related you need to put it in a SceneWorld.⤶ Entities in the main game will do that for you, but if you are doing your own SceneWorld you will have to keep it in mind.⤶ ⤶ You can actually get the main game's SceneWorld by just doing `Game.SceneWorld` and you can manually add in SceneObjects and lights if you so desired!⤶ ⤶ ## SceneCamera⤶ #### Everything needed for how WE WANT to render everything in a SceneWorld⤶ A SceneCamera holds all the data about how we should render stuff to a texture, or view, or screen.⤶ The camera is provided a world to render, in which it will now render all the SceneObjects within that world!⤶ ⤶ There are also a lot of properties you can mess with to change how the SceneCamera will render everything to the screen. Properties like FOV, Orthographic, ZNear, ZFar and so on.⤶ ⤶ Another thing to remember is you can use [RenderTags](https://wiki.facepunch.com/sbox/RenderTags) to dictate what objects to and not to render, and also [RenderHooks](https://wiki.facepunch.com/sbox/RenderHooks) to hook in and do extra stuff within each render stage when the camera is rendered!⤶ ⤶ Lastly, the global `Sandbox.Camera` is technically a wrapper for the main SceneCamera the main world uses!⤶ so you can do `Camera.Main` and this will allow you to get your main game's SceneCamera!⤶ ⤶ ## SceneObject⤶ #### Objects that are rendered models, anything in the SceneWorld that is rendered HAS to inherit from this⤶ So where Entities are what allow things to exist physically in our main game world, SceneObjects are what allow models to be rendered by the camera in the SceneWorld.⤶ ⤶ WHATEVER that is in a SceneWorld has to inherit from the `SceneObject` class to be able to be added to a SceneWorld.⤶ ⤶ for example all these are children of SceneObjects!⤶ - SceneLight⤶ - SceneModel⤶ - SceneSkybox⤶ - SceneCubemap⤶ ⤶ Now with SceneObjects we now have access to messing with materials, [dynamic expressions](https://wiki.facepunch.com/sbox/Using_Dynamic_Expressions), [attributes](https://wiki.facepunch.com/sbox/material_attributes), body groups, the mesh, interacting with the shaders on the model and so on and so fourth. ⤶ When making a game you'll most often be interacting with a scene. In a scene you can create GameObjects, give them components, and move them around in the viewport.