Go to the documentation of this file.
32 XFileNode(
XFile *x_file,
const string &name) :
36 if (x_file && x_file->_keep_names) {
39 set_name(make_nice_name(name));
56 ChildrenByName::const_iterator ni;
57 ni = _children_by_name.find(
downcase(name));
58 if (ni != _children_by_name.end()) {
71 ChildrenByName::const_iterator ni;
72 ni = _children_by_name.find(
downcase(name));
73 if (ni != _children_by_name.end()) {
85 for (
int i = 0; i < (int)_children.size(); i++) {
86 if (_children[i] == child) {
101 if (child !=
nullptr) {
105 Children::const_iterator ci;
106 for (ci = _children.begin(); ci != _children.end(); ++ci) {
108 if (child !=
nullptr){
193 _children_by_name[
downcase(node->get_name())] = (int)_children.size();
196 _x_file->_nodes_by_guid[node->
get_guid()] = node;
198 if (node->
is_of_type(XFileDataNode::get_class_type())) {
201 _children.push_back(node);
212 _children_by_name.clear();
219 write_text(std::ostream &out,
int indent_level)
const {
220 Children::const_iterator ci;
221 for (ci = _children.begin(); ci != _children.end(); ++ci) {
222 (*ci)->write_text(out, indent_level);
239 size_t &index,
size_t &sub_index)
const {
245 Children::const_iterator ci;
246 for (ci = _children.begin(); ci != _children.end(); ++ci) {
247 if (!(*ci)->repack_data(
object, parse_data_list,
248 prev_data, index, sub_index)) {
262 Children::const_iterator ci;
263 for (ci = _children.begin(); ci != _children.end(); ++ci) {
264 if (!(*ci)->fill_zero_data(
object)) {
279 if (other->get_type() != get_type()) {
302 nassertr(xtemplate !=
nullptr,
nullptr);
317 nassertr(xtemplate !=
nullptr,
nullptr);
332 nassertr(xtemplate !=
nullptr,
nullptr);
347 nassertr(xtemplate !=
nullptr,
nullptr);
362 nassertr(xtemplate !=
nullptr,
nullptr);
375 add_Material(
const string &name,
const LColor &face_color,
376 double power,
const LRGBColor &specular_color,
377 const LRGBColor &emissive_color) {
379 nassertr(xtemplate !=
nullptr,
nullptr);
385 (*node)[
"faceColor"][
"red"] = face_color[0];
386 (*node)[
"faceColor"][
"green"] = face_color[1];
387 (*node)[
"faceColor"][
"blue"] = face_color[2];
388 (*node)[
"faceColor"][
"alpha"] = face_color[3];
389 (*node)[
"power"] = power;
390 (*node)[
"specularColor"][
"red"] = specular_color[0];
391 (*node)[
"specularColor"][
"green"] = specular_color[1];
392 (*node)[
"specularColor"][
"blue"] = specular_color[2];
393 (*node)[
"emissiveColor"][
"red"] = emissive_color[0];
394 (*node)[
"emissiveColor"][
"green"] = emissive_color[1];
395 (*node)[
"emissiveColor"][
"blue"] = emissive_color[2];
406 nassertr(xtemplate !=
nullptr,
nullptr);
423 nassertr(xtemplate !=
nullptr,
nullptr);
439 nassertr(xtemplate !=
nullptr,
nullptr);
458 xmat[10] = mat(2, 2);
459 xmat[11] = mat(2, 3);
461 xmat[12] = mat(3, 0);
462 xmat[13] = mat(3, 1);
463 xmat[14] = mat(3, 2);
464 xmat[15] = mat(3, 3);
477 string::const_iterator si;
478 for (si = str.begin(); si != str.end(); ++si) {
492 if (str.empty() || isdigit(str[0])) {
495 result =
'_' + result;
void add_child(XFileNode *node)
Adds the indicated node as a child of this node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode * find_child(const std::string &name) const
Returns the child with the indicated name, if any, or NULL if none.
XFileDataNode * add_MeshNormals(const std::string &name)
Creates a new MeshNormals instance, as a child of this node.
The abstract base class for a number of different types of data elements that may be stored in the X ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNode * add_TextureFilename(const std::string &name, const Filename &filename)
Creates a new TextureFilename instance, as a child of this node.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
XFileDataNode * add_MeshTextureCoords(const std::string &name)
Creates a new MeshTextureCoords instance, as a child of this node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
XFileDataNode * add_MeshMaterialList(const std::string &name)
Creates a new MeshMaterialList instance, as a child of this node.
virtual const WindowsGuid & get_guid() const
If has_guid() returned true, returns the particular GUID associated with this node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_children() const
Returns the list of children of this node.
This represents the complete contents of an X file (file.x) in memory.
int find_child_index(const std::string &name) const
Returns the index number of the child with the indicated name, if any, or -1 if none.
virtual bool has_guid() const
Returns true if this node has a GUID associated.
XFileNode * get_child(int n) const
Returns the nth child of this node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single node of an X file.
string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool is_reference() const
Returns true if this node represents an indirect reference to an object defined previously in the fil...
XFileDataNode * add_MeshVertexColors(const std::string &name)
Creates a new MeshVertexColors instance, as a child of this node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state.
TypeHandle is the identifier used to differentiate C++ class types.
A container for a pvector of the above objects.
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A template definition in the X file.
virtual bool fill_zero_data(XFileDataObject *object) const
This is similar to repack_data(), except it is used to fill the initial values for a newly-created te...
This is a node which contains all of the data elements defined by a template.
virtual bool is_object() const
Returns true if this node represents a data object that is the instance of some template,...
static std::string make_nice_name(const std::string &str)
Transforms the indicated egg name to a name that is acceptable for a node in the X File format.
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
XFileDataNode * add_FrameTransformMatrix(const LMatrix4d &mat)
Creates a new FrameTransformMatrix instance, as a child of this node.
XFileDataNode * add_Mesh(const std::string &name)
Creates a new Mesh instance, as a child of this node.
virtual bool repack_data(XFileDataObject *object, const XFileParseDataList &parse_data_list, PrevData &prev_data, size_t &index, size_t &sub_index) const
This is called on the template that defines an object, once the data for the object has been parsed.
virtual bool is_standard_object(const std::string &template_name) const
Returns true if this node represents an instance of the standard template with the indicated name,...
static XFileTemplate * find_standard_template(const std::string &name)
Returns the standard template associated with the indicated name, if any, or NULL if none.
XFileNode * find_descendent(const std::string &name) const
Returns the first child or descendent found with the indicated name after a depth-first search,...
A base class for all things which can have a name.
virtual bool is_template_def() const
Returns true if this node represents the definition of some template.
This is an abstract base class for an XFileNode which is also an XFileDataObject.
XFileDataNode * add_Material(const std::string &name, const LColor &face_color, double power, const LRGBColor &specular_color, const LRGBColor &emissive_color)
Creates a new Material instance, as a child of this node.
XFileDataNode * add_Frame(const std::string &name)
Creates a new Frame instance, as a child of this node.
virtual void write_text(std::ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
void zero_fill()
Fills the data node with zero-valued elements appropriate to the template.
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
The name of a file, such as a texture file or an Egg file.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.