Panda3D

stTree.cxx

00001 // Filename: stTree.cxx
00002 // Created by:  drose (06Oct10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "stTree.h"
00016 #include "speedTreeNode.h"
00017 
00018 TypeHandle STTree::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: STTree::Constructor
00022 //       Access: Published
00023 //  Description: The constructor reads the indicated SRT file
00024 //               immediately.  Check is_valid() to determine whether
00025 //               the read was successful or not.  Note that the
00026 //               filename must be a fully-qualified pathname; the
00027 //               STTree constructor does not search the model-path.
00028 ////////////////////////////////////////////////////////////////////
00029 STTree::
00030 STTree(const Filename &fullpath) :
00031   Namable(fullpath.get_basename_wo_extension()),
00032   _fullpath(fullpath)
00033 {
00034   _is_valid = false;
00035 
00036   // Ensure we have a license.
00037   if (!SpeedTreeNode::authorize()) {
00038     speedtree_cat.warning()
00039       << "SpeedTree license not available.\n";
00040     return;
00041   }
00042 
00043   // Can't use VFS, due to SpeedTree's insistence on using fopen() to
00044   // load dds textures and such.  So we go ahead and use the low-level
00045   // Filename interface directly.
00046   /*
00047   Filename tree_filename = filename;
00048   if (!tree_filename.resolve_filename(get_model_path(), "srt")) {
00049     speedtree_cat.warning()
00050       << "Couldn't find: " << filename << "\n";
00051     return false;
00052   }
00053   */
00054 
00055   string os_fullpath = _fullpath.to_os_specific();
00056   if (!_tree.LoadTree(os_fullpath.c_str())) {
00057     speedtree_cat.warning()
00058       << "Couldn't read: " << _fullpath << "\n";
00059     SpeedTreeNode::write_error(speedtree_cat.warning());
00060     return;
00061   }
00062 
00063   speedtree_cat.info() 
00064     << "Read " << _fullpath << "\n";
00065   _is_valid = true;
00066 }
00067 
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: STTree::Copy Constructor
00071 //       Access: Private
00072 //  Description: An STTree copy constructor is not supported.
00073 ////////////////////////////////////////////////////////////////////
00074 STTree::
00075 STTree(const STTree &copy) {
00076   nassertv(false);
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: STTree::output
00081 //       Access: Published
00082 //  Description: 
00083 ////////////////////////////////////////////////////////////////////
00084 void STTree::
00085 output(ostream &out) const {
00086   if (!is_valid()) {
00087     out << "(invalid STTree)";
00088   } else {
00089     out << "STTree(" << get_name() << ")";
00090   }
00091 }
 All Classes Functions Variables Enumerations