Skip to content
Li, Xizhi edited this page Feb 12, 2018 · 3 revisions

MinisceneGraph

MinisceneGraph is a simplified version of SceneObject, which manages a small number of (usually one) 3d object(s) which are rendered into a separate 2D texture or into the global render target.

There can only be one SceneObject in ParaEngine. But we can have multiple MinisceneGraphs as child objects of the global SceneObject.

Mini scene graph does not use a spatial partition for its child objects, instead, it just implements a simple parent/child logical tree relationships. Most scene objects can be attached to the mini scene graph. We can add, delete, show or hide objects like 2D objects in GUI Engine.

There are two modes of mini scene graph:

  • Owner draw mode: the mini scene has its own camera and private render target (texture).
  • Shared mode: objects on mini scene graphs are rendered into the global render target after the main SceneObject.

One can turn the owner draw mode on and off by calling EnableCamera(true)

local scene = ParaScene.GetMiniSceneGraph(sceneName);
-- reset scene, in case this is called multiple times
scene:Reset();
scene:SetRenderTargetSize(128, 128);
-- enable camera and create render target
scene:EnableCamera(true);
-- render it each frame automatically. 
scene:EnableActiveRendering(true);

In owner draw mode, it is used to display live portrait of 3d models(avatars). Because the result of miniscenegraph is just a standard texture that is updated every frame. And one can use the texture on any 2d or 3d objects.

local scene = ParaScene.GetMiniSceneGraph(self.resourceName);
if(scene:IsValid()) then
   local _this=ParaUI.GetUIObject(self.name);
   if(_this:IsValid()) then
      _this:SetBGImage(scene:GetTexture());
   end	
end

In shared mode, mini scene graph is so designed that it can be used to display interactive 3D helper objects in the scene. In most cases, we will want to keep only a small number of objects on a visible mini scene graph node. For example, some rotation handles or attachment points on mesh or helper 3D handles can be created and displayed via mini scene graph. Objects on mini scene graph are not persistent, so they are usually used to display temporary 3D objects. Following is a list of possible usage of mini scene graph

  • Simple snow or rain effects, where we create new particle system around the current camera position every few seconds while deleting all particle systems that are created a few seconds ago. This can be done either in the scripting interface or in the game engine, so long as a timer is used to update the particles.
  • Displaying mount point or attachment point on mesh objects. For example, when a player approaches a mount point, we may display some 3D icon to inform the user that it can interact with it. This is usually done via the scripting interface.
  • Displaying a special 3D cursor, such as a 3D object during mouse move or click. For instance, we can display the situation of dragging a 3D object across the scene.

Note: Overlay is now the preferred way to draw helper objects instead of using miniscenegraph, miniscenegraph is mostly used to display live portrait of 3d models(avatars)

Code Examples

There is a helper class for using mini scene in owner-draw mode. script/ide/Canvas3D.lua

Clone this wiki locally