File: ScenegraphUtils.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (84 lines) | stat: -rw-r--r-- 2,355 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

#include "ipath.h"
#include "inode.h"
#include "math/AABB.h"
#include "iscenegraph.h"
#include "string/convert.h"
#include "itextstream.h"

inline std::string getNameForNodeType(scene::INode::Type type)
{
    switch (type)
    {
	case scene::INode::Type::MapRoot: return "map";
    case scene::INode::Type::Entity: return "entity";
    case scene::INode::Type::Brush: return "brush";
    case scene::INode::Type::Patch: return "patch";
    case scene::INode::Type::Model: return "model";
    case scene::INode::Type::Particle: return "particle";
    case scene::INode::Type::EntityConnection: return "entityconnection";
    case scene::INode::Type::MergeAction: return "mergeaction";
    default: return "unknown";
    };
}

// greebo: Return information about the given node
inline std::string getNodeInfo(const scene::INodePtr& node)
{
	std::string returnValue;

	if (node == NULL) {
		return "NULL";
	}

	returnValue += getNameForNodeType(node->getNodeType());
    returnValue += " (" + node->name() + ")";

	return returnValue;
}

// greebo: Stream insertion operator for scene::INode
inline std::ostream& operator<<(std::ostream& st, const scene::INodePtr& node) {
	st << getNodeInfo(node);
	return st;
}

inline std::string getPathInfo(const scene::Path& path) {
	std::string name;

	for (scene::Path::const_iterator i = path.begin(); i != path.end(); i++) {
		// Cast the INode onto a scene::Node
		scene::INodePtr node = *i;

		name += (name.empty()) ? "" : ", ";
		name += getNodeInfo(node);
	}
	name = std::string("[") + string::to_string(path.size()) + "] {" + name + "} extents: ";
	name += "<" + string::to_string(path.top()->worldAABB().extents.x()) + ",";
	name += string::to_string(path.top()->worldAABB().extents.y()) + ",";
	name += string::to_string(path.top()->worldAABB().extents.z()) + ">";
	return name;
}

// greebo: Stream-insertion operator for scene::Paths, printing out information on the referenced scene::Nodes
inline std::ostream& operator<<(std::ostream& st, const scene::Path& path) {
	st << getPathInfo(path);
	return st;
}

class SceneGraphDumper :
	public scene::NodeVisitor
{
public:
	bool pre(const scene::INodePtr& node)
	{
		rMessage() << getNodeInfo(node) << "\n";
		return true;
	}
};

inline void dumpSceneGraph() {
	SceneGraphDumper dumper;
	GlobalSceneGraph().root()->traverseChildren(dumper);
}