|
@@ -33,7 +33,7 @@ At the core, Godot uses the concept of Servers. They are very low-level APIs to
|
|
|
rendering, physics, sound, etc. The scene system is built on top of them and uses them directly.
|
|
|
The most common servers are:
|
|
|
|
|
|
-* :ref:`VisualServer <class_VisualServer>`: handles everything related to graphics.
|
|
|
+* :ref:`RenderingServer <class_RenderingServer>`: handles everything related to graphics.
|
|
|
* :ref:`PhysicsServer <class_PhysicsServer>`: handles everything related to 3D physics.
|
|
|
* :ref:`Physics2DServer <class_Physics2DServer>`: handles everything related to 2D physics.
|
|
|
* :ref:`AudioServer <class_AudioServer>`: handles everything related to audio.
|
|
@@ -67,11 +67,11 @@ For nodes, there are many functions available:
|
|
|
method will return the viewport RID in the server.
|
|
|
* For 3D, the :ref:`World <class_World>` resource (obtainable in the :ref:`Viewport <class_Viewport>`
|
|
|
and :ref:`Spatial <class_Spatial>` nodes)
|
|
|
- contains functions to get the *VisualServer Scenario*, and the *PhysicsServer Space*. This
|
|
|
+ contains functions to get the *RenderingServer Scenario*, and the *PhysicsServer Space*. This
|
|
|
allows creating 3D objects directly with the server API and using them.
|
|
|
* For 2D, the :ref:`World2D <class_World2D>` resource (obtainable in the :ref:`Viewport <class_Viewport>`
|
|
|
and :ref:`CanvasItem <class_CanvasItem>` nodes)
|
|
|
- contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
|
|
|
+ contains functions to get the *RenderingServer Canvas*, and the *Physics2DServer Space*. This
|
|
|
allows creating 2D objects directly with the server API and using them.
|
|
|
* The :ref:`VisualInstance<class_VisualInstance>` class, allows getting the scenario *instance* and
|
|
|
*instance base* via the :ref:`VisualInstance.get_instance() <class_VisualInstance_method_get_instance>`
|
|
@@ -94,23 +94,23 @@ This is an example of how to create a sprite from code and move it using the low
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
|
- # VisualServer expects references to be kept around.
|
|
|
+ # RenderingServer expects references to be kept around.
|
|
|
var texture
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
# Create a canvas item, child of this node.
|
|
|
- var ci_rid = VisualServer.canvas_item_create()
|
|
|
+ var ci_rid = RenderingServer.canvas_item_create()
|
|
|
# Make this node the parent.
|
|
|
- VisualServer.canvas_item_set_parent(ci_rid, get_canvas_item())
|
|
|
+ RenderingServer.canvas_item_set_parent(ci_rid, get_canvas_item())
|
|
|
# Draw a texture on it.
|
|
|
# Remember, keep this reference.
|
|
|
texture = load("res://my_texture.png")
|
|
|
# Add it, centered.
|
|
|
- VisualServer.canvas_item_add_texture_rect(ci_rid, Rect2(texture.get_size() / 2, texture.get_size()), texture)
|
|
|
+ RenderingServer.canvas_item_add_texture_rect(ci_rid, Rect2(texture.get_size() / 2, texture.get_size()), texture)
|
|
|
# Add the item, rotated 45 degrees and translated.
|
|
|
var xform = Transform2D().rotated(deg2rad(45)).translated(Vector2(20, 30))
|
|
|
- VisualServer.canvas_item_set_transform(ci_rid, xform)
|
|
|
+ RenderingServer.canvas_item_set_transform(ci_rid, xform)
|
|
|
|
|
|
The Canvas Item API in the server allows you to add draw primitives to it. Once added, they can't be modified.
|
|
|
The Item needs to be cleared and the primitives re-added (this is not the case for setting the transform,
|
|
@@ -121,7 +121,7 @@ Primitives are cleared this way:
|
|
|
.. tabs::
|
|
|
.. code-tab:: gdscript GDScript
|
|
|
|
|
|
- VisualServer.canvas_item_clear(ci_rid)
|
|
|
+ RenderingServer.canvas_item_clear(ci_rid)
|
|
|
|
|
|
|
|
|
Instantiating a Mesh into 3D space
|
|
@@ -135,24 +135,24 @@ The 3D APIs are different from the 2D ones, so the instantiation API must be use
|
|
|
extends Spatial
|
|
|
|
|
|
|
|
|
- # VisualServer expects references to be kept around.
|
|
|
+ # RenderingServer expects references to be kept around.
|
|
|
var mesh
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
# Create a visual instance (for 3D).
|
|
|
- var instance = VisualServer.instance_create()
|
|
|
+ var instance = RenderingServer.instance_create()
|
|
|
# Set the scenario from the world, this ensures it
|
|
|
# appears with the same objects as the scene.
|
|
|
var scenario = get_world().scenario
|
|
|
- VisualServer.instance_set_scenario(instance, scenario)
|
|
|
+ RenderingServer.instance_set_scenario(instance, scenario)
|
|
|
# Add a mesh to it.
|
|
|
# Remember, keep the reference.
|
|
|
mesh = load("res://mymesh.obj")
|
|
|
- VisualServer.instance_set_base(instance, mesh)
|
|
|
+ RenderingServer.instance_set_base(instance, mesh)
|
|
|
# Move the mesh around.
|
|
|
var xform = Transform(Basis(), Vector3(20, 100, 0))
|
|
|
- VisualServer.instance_set_transform(instance, xform)
|
|
|
+ RenderingServer.instance_set_transform(instance, xform)
|
|
|
|
|
|
Creating a 2D RigidBody and moving a sprite with it
|
|
|
---------------------------------------------------
|
|
@@ -170,7 +170,7 @@ and moves a :ref:`CanvasItem <class_CanvasItem>` when the body moves.
|
|
|
|
|
|
func _body_moved(state, index):
|
|
|
# Created your own canvas item, use it here.
|
|
|
- VisualServer.canvas_item_set_transform(canvas_item, state.transform)
|
|
|
+ RenderingServer.canvas_item_set_transform(canvas_item, state.transform)
|
|
|
|
|
|
|
|
|
func _ready():
|
|
@@ -198,7 +198,7 @@ The 3D version should be very similar, as 2D and 3D physics servers are identica
|
|
|
Getting data from the servers
|
|
|
-----------------------------
|
|
|
|
|
|
-Try to **never** request any information from ``VisualServer``, ``PhysicsServer`` or ``Physics2DServer``
|
|
|
+Try to **never** request any information from ``RenderingServer``, ``PhysicsServer`` or ``Physics2DServer``
|
|
|
by calling functions unless you know what you are doing. These servers will often run asynchronously
|
|
|
for performance and calling any function that returns a value will stall them and force them to process
|
|
|
anything pending until the function is actually called. This will severely decrease performance if you
|