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