Revision Difference
Scene_System#549011
<cat>Code.Scene</cat>⤶
<title>The Scene System</title>⤶
⤶
# 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 whats 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 games 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 you own SceneWorld you will have to keep it in mind.⤶
⤶
You can actually get the main games 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 alot of properties you can mess with to change how the SceneCamera will render everything to the screen.⤶
⤶
Like you can mess with FOV, Orphographic, 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 games 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 is what allowed models to be rendered by the camera in the SceneWorld.⤶
⤶
Everything SceneWHATEVER that is in a SceneWorld has to inherit from the `SceneObject` class in order to be abled 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 and interacting with the shaders on the model and so on and so fourth.