This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
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
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::NodeLayer Class

Header: #include <UnigineNodes.h>
Inherits from: 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#

Create an instance of the NodeLayer class. You can also specify such settings as a name, transformation and so on.

AppWorldLogic.cpp

Source code (C++)
#include "AppWorldLogic.h"

#include <UnigineObjects.h>
#include <UnigineWorld.h>

using namespace Unigine;
using namespace Math;

int AppWorldLogic::init()
{

	// create a layer node
	NodeLayerPtr layer = NodeLayer::create("nodes/layer_0.node");
	// set a name for the node
	layer->setName("layer_0");

	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:

AppWorldLogic.cpp

Source code (C++)
#include "AppWorldLogic.h"

#include <UnigineObjects.h>
#include <UnigineWorld.h>

using namespace Unigine;
using namespace Math;

int AppWorldLogic::init()
{

	// create a layer node
	NodeLayerPtr layer = NodeLayer::create("nodes/layer_0.node");
	// set a name for the node
	layer->setName("layer_0");

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

			// create a mesh
			MeshPtr mesh = Mesh::create();
			mesh->addBoxSurface("box_0", vec3(1.0f));
			// create a node (e.g. an instance of the ObjectMeshDynamic class)
			ObjectMeshDynamicPtr node = ObjectMeshDynamic::create(mesh);

			// set node transformation
			node->setWorldTransform(translate(Vec3(x * 2.0f, y * 2.0f, 0.0f)));
			// set a name for the node
			node->setName(String::format("mesh_%d_%d", x + 10, y + 10).get());
			// 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.

AppWorldLogic.cpp

Source code (C++)
#include "AppWorldLogic.h"

#include <UnigineObjects.h>
#include <UnigineWorld.h>

using namespace Unigine;
using namespace Math;

int AppWorldLogic::init()
{

	// create a layer node
	NodeLayerPtr layer = NodeLayer::create("nodes/layer_0.node");
	// set a name for the node
	layer->setName("layer_0");

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

			// create a mesh
			MeshPtr mesh = Mesh::create();
			mesh->addBoxSurface("box_0", vec3(1.0f));
			// create a node (e.g. an instance of the ObjectMeshDynamic class)
			ObjectMeshDynamicPtr node = ObjectMeshDynamic::create(mesh);

			// set node transformation
			node->setWorldTransform(translate(Vec3(x * 2.0f, y * 2.0f, 0.0f)));
			// set a name for the node
			node->setName(String::format("mesh_%d_%d", x + 10, y + 10).get());
			// add the node as a child to the layer node
			layer->addWorldChild(node);
		}
	}

	// check if the node layer and its ancestors can be saved to the .world file
	if (!layer->isSaveToWorldEnabled()) layer->setSaveToWorldEnabledRecursive(true);
	// save the world
	World::saveWorld();

	return 1;
}

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 array of nodes
Vector<NodePtr> nodes;
// append child nodes of the layer to the declared array
for (int i = 0; i < layer->getNumChildren(); i++) {
	nodes.append(layer->getChild(i));
}
// save nodes to the .node file
if (World::saveNodes(layer->getNodePath(), nodes) == 0) {
	Log::error("Layer hasn't been saved\n");
}

See Also#

NodeLayer Class

Members


static NodeLayerPtr create ( const char * name ) #

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

Arguments

  • const char * name - Name of the layer.

void setNodePath ( const char * name ) #

Updates the name of the node layer: a path to a .node file where child nodes of the layer are stored.

Arguments

  • const char * name - Path to a .node file.

const char * getNodePath ( ) #

Returns the name of the node layer: a path to a .node file where child nodes of the layer are stored.

Return value

Path to the .node file.

static int type ( ) #

Returns the type of the node.

Return value

NodeLayer type identifier.
Last update: 2024-08-16
Build: ()