This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.NodeLayer Class

Inherits: Node

A layer node is a zero-sized node that has no visual representation and enables to save all its child nodes into a separate .node file. Layer nodes should be used to split the world into several logical parts and save each of them in a .node file so that each layer and its child nodes can be edited without affecting the source .world file.

Notice
The layer node itself is not stored in the .node file.

Creating a Layer#

To create a layer node, perform as follows:

  1. Create an instance of the NodeLayer class.
  2. Release script ownership so that the node can be added to UnigineEditor.
  3. Add the node to UnigineEditor (wherein, node ownership will be passed to the editor automatically).

You can also specify such settings as a name, transformation and so on.

Source code (C#)
// AppWorldLogic.cs

using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{

		public override bool Init()
		{
			// create a layer node
			NodeLayer layer = new NodeLayer();
			// set a name
			layer.setName("LayerNode");

			return 1;
		}
	}
}

Editing a Layer#

Editing a layer node includes adding, deleting, modifying its child nodes. For example, you can add new nodes as follows:

Source code (C#)
// AppWorldLogic.cs

using Unigine;

#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Mat4 = Unigine.dmat4;
#else
using Vec3 = Unigine.vec3;
using Mat4 = Unigine.mat4;
#endif

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		public override bool Init()
		{
            // create a layer node
            NodeLayer layer = new NodeLayer();
            // set a name for the node
            layer.setName("layer_0");
            // release script ownership
            layer.release();

			// create a mesh
			Mesh mesh = new Mesh();
			mesh.AddBoxSurface("box_0", new vec3(1.0f));
			// create a node (e.g. an instance of the ObjectMeshDynamic class)
			ObjectMeshDynamic node = new ObjectMeshDynamic(mesh);
			// assign a material to the surfaces of the object
			for (int i = 0; i < node.NumSurfaces; i++)
			{
				node.setMaterial("mesh_base", i);
			}
			// set node transformation
			node.WorldTransform = MathLib.Translate(new Vec3(x * 2, y * 2, 0.0f));
			// set a name for the node
			node.Name = String.Format("mesh_{0}_{1}", x + 10, y + 10);
			// add the node as a child to the layer node
			layer.addWorldChild(node);
			
			return 1;
		}
	}
}

Saving a Layer#

Changes made in the child nodes of the layer node can be saved on the disk by saving the world. The nodes will be saved in the separate .node file specified for the layer, not in the .world file.

Source code (C#)
// AppWorldLogic.cs

using Unigine;

#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Mat4 = Unigine.dmat4;
#else
using Vec3 = Unigine.vec3;
using Mat4 = Unigine.mat4;
#endif

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		public override bool Init()
		{
			// create a layer node
	        NodeLayer layer = new NodeLayer("unigine_project_1/nodes/layer_0.node");
	        // set a name for the node
	        layer.setName("layer_0");
	        // release script ownership
	        layer.release();

	        // create child nodes
	        for (int y = -10; y <= 10; y++)
	        {
		        for (int x = -10; x <= 10; x++)
		        {

			        // create a mesh
			        Mesh mesh = new Mesh();
			        mesh.addBoxSurface("box_0", new vec3(1.0f));
			        // create a node (e.g. an instance of the ObjectMeshDynamic class)
			        ObjectMeshDynamic node = new ObjectMeshDynamic(mesh);
			        // assign a material to the surfaces of the object
			        for (int i = 0; i < node.NumSurfaces; i++)
			        {
				        node.setMaterial("mesh_base", i);
			        }
			        // set node transformation
			        node. WorldTransform = MathLib.Translate(new Vec3(x * 2, y * 2, 0.0f));
			        // set a name for the node
			        node.Name = String.Format("mesh_{0}_{1}", x + 10, y + 10);

			        // add the node as a child to the layer node
			        layer.addWorldChild(node);
		        }
	        }

	        // save the world
	        Console.Run("world_save unigine_project_1");

			return true;
		}
	}
}

Instead of saving the world, you can manually save child nodes of the layer into the .node file by using the World.saveNodes() function:

Source code (C#)
// declare a list of nodes
List<Node> nodes_list = new List<Node>();
// add child nodes of the layer to the declared list
for (int i = 0; i < layer.getNumChildren(); i++) {
    nodes_list.Add(layer.getChild(i));
}
// convert the list to Unigine.Node[] array so that nodes can be saved to a file later
Node[] nodes = nodes_list.ToArray();

// save nodes to the .node file
if (World.SaveNodes(layer.NodeName, nodes) == 0) {
	Log.Error("Layer hasn't been saved\n");
}

See Also#

NodeLayer Class

Properties

string NodeName#

The name of the node layer: a path to a .node file where child nodes of the layer are stored.
set
Updates the name of the node layer: a path to a .node file where child nodes of the layer are stored.
set value - Path to a .node file.

Members


static NodeLayer ( string name ) #

Constructor. Creates a node layer with specified file name to store it.

Arguments

  • string name - Name of the layer.

static int type ( ) #

Returns the type of the node.

Return value

NodeLayer type identifier.
Last update: 2020-04-10
Build: ()