Panda3D
stTree.cxx
1 // Filename: stTree.cxx
2 // Created by: drose (06Oct10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "stTree.h"
16 #include "speedTreeNode.h"
17 
18 TypeHandle STTree::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: STTree::Constructor
22 // Access: Published
23 // Description: The constructor reads the indicated SRT file
24 // immediately. Check is_valid() to determine whether
25 // the read was successful or not. Note that the
26 // filename must be a fully-qualified pathname; the
27 // STTree constructor does not search the model-path.
28 ////////////////////////////////////////////////////////////////////
30 STTree(const Filename &fullpath) :
31  Namable(fullpath.get_basename_wo_extension()),
32  _fullpath(fullpath)
33 {
34  _is_valid = false;
35 
36  // Ensure we have a license.
37  if (!SpeedTreeNode::authorize()) {
38  speedtree_cat.warning()
39  << "SpeedTree license not available.\n";
40  return;
41  }
42 
43  // Can't use VFS, due to SpeedTree's insistence on using fopen() to
44  // load dds textures and such. So we go ahead and use the low-level
45  // Filename interface directly.
46  /*
47  Filename tree_filename = filename;
48  if (!tree_filename.resolve_filename(get_model_path(), "srt")) {
49  speedtree_cat.warning()
50  << "Couldn't find: " << filename << "\n";
51  return false;
52  }
53  */
54 
55  string os_fullpath = _fullpath.to_os_specific();
56  if (!_tree.LoadTree(os_fullpath.c_str())) {
57  speedtree_cat.warning()
58  << "Couldn't read: " << _fullpath << "\n";
59  SpeedTreeNode::write_error(speedtree_cat.warning());
60  return;
61  }
62 
63  speedtree_cat.info()
64  << "Read " << _fullpath << "\n";
65  _is_valid = true;
66 }
67 
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: STTree::Copy Constructor
71 // Access: Private
72 // Description: An STTree copy constructor is not supported.
73 ////////////////////////////////////////////////////////////////////
75 STTree(const STTree &copy) {
76  nassertv(false);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: STTree::output
81 // Access: Published
82 // Description:
83 ////////////////////////////////////////////////////////////////////
84 void STTree::
85 output(ostream &out) const {
86  if (!is_valid()) {
87  out << "(invalid STTree)";
88  } else {
89  out << "STTree(" << get_name() << ")";
90  }
91 }
static bool authorize(const string &license="")
Make this call to initialized the SpeedTree API and verify the license.
A base class for all things which can have a name.
Definition: namable.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
bool is_valid() const
Returns true if the tree was successfully loaded and is ready to be used, false otherwise.
Definition: stTree.I:34
STTree(const Filename &fullpath)
The constructor reads the indicated SRT file immediately.
Definition: stTree.cxx:30
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
static void write_error(ostream &out)
Writes the current SpeedTree error message to the indicated stream.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
Definition: filename.cxx:1196
Encapsulates a single tree model in the SpeedTree library, as loaded from an SRT file.
Definition: stTree.h:30