Commit 575129eb authored by Jan Möbius's avatar Jan Möbius

Added function to get shadernode from baseObjectData if available

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@2994 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 55106a3d
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
//== TYPEDEFS ================================================================= //== TYPEDEFS =================================================================
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
BaseObjectData::BaseObjectData( SeparatorNode* _rootNode ) : BaseObjectData::BaseObjectData( SeparatorNode* _rootNode ) :
BaseObject(), BaseObject(),
path_("."), path_("."),
rootNode_(_rootNode), rootNode_(_rootNode),
separatorNode_(0), separatorNode_(0),
manipulatorNode_(0), manipulatorNode_(0),
materialNode_(0) materialNode_(0)
...@@ -66,12 +66,12 @@ BaseObjectData::~BaseObjectData() { ...@@ -66,12 +66,12 @@ BaseObjectData::~BaseObjectData() {
if ( separatorNode_ != 0 ) { if ( separatorNode_ != 0 ) {
separatorNode_->delete_subtree(); separatorNode_->delete_subtree();
} }
} }
void BaseObjectData::cleanup() { void BaseObjectData::cleanup() {
path_ = "."; path_ = ".";
// Delete everything below the seperator node on top of the object. This will remove the complete subtree. // Delete everything below the seperator node on top of the object. This will remove the complete subtree.
if ( separatorNode_ == 0 ) if ( separatorNode_ == 0 )
std::cerr << "cleanup : separatorNode_ is already 0" << std::endl; std::cerr << "cleanup : separatorNode_ is already 0" << std::endl;
...@@ -80,12 +80,12 @@ void BaseObjectData::cleanup() { ...@@ -80,12 +80,12 @@ void BaseObjectData::cleanup() {
separatorNode_ = 0; separatorNode_ = 0;
manipulatorNode_ = 0; manipulatorNode_ = 0;
materialNode_ = 0; materialNode_ = 0;
additionalNodes_.clear(); additionalNodes_.clear();
} }
BaseObject::cleanup(); BaseObject::cleanup();
BaseObjectData::init(); BaseObjectData::init();
} }
...@@ -93,14 +93,14 @@ void BaseObjectData::init() { ...@@ -93,14 +93,14 @@ void BaseObjectData::init() {
// Create seperatorNode for Object only if it does not exist. // Create seperatorNode for Object only if it does not exist.
if ( separatorNode_ == 0 ) if ( separatorNode_ == 0 )
separatorNode_ = new SeparatorNode((BaseNode*)rootNode_,"NEW Object"); separatorNode_ = new SeparatorNode((BaseNode*)rootNode_,"NEW Object");
else else
std::cerr << "Separator Node already exists. this should not happen!" << std::endl; std::cerr << "Separator Node already exists. this should not happen!" << std::endl;
if ( manipulatorNode_ == 0 ) { if ( manipulatorNode_ == 0 ) {
manipulatorNode_ = new ManipulatorNode(baseNode(),"NEW ManipulatorNode"); manipulatorNode_ = new ManipulatorNode(baseNode(),"NEW ManipulatorNode");
manipulatorNode_->set_status( ACG::SceneGraph::ManipulatorNode::HideNode ); manipulatorNode_->set_status( ACG::SceneGraph::ManipulatorNode::HideNode );
} }
else else
std::cerr << "Manipulator Node already exists. this should not happen!" << std::endl; std::cerr << "Manipulator Node already exists. this should not happen!" << std::endl;
if ( materialNode_ == 0 ) if ( materialNode_ == 0 )
materialNode_ = new MaterialNode(manipulatorNode(), "New Material"); materialNode_ = new MaterialNode(manipulatorNode(), "New Material");
...@@ -119,13 +119,13 @@ void BaseObjectData::setFromFileName(QString _filename ) { ...@@ -119,13 +119,13 @@ void BaseObjectData::setFromFileName(QString _filename ) {
void BaseObjectData::setName( QString _name ) { void BaseObjectData::setName( QString _name ) {
BaseObject::setName( _name ); BaseObject::setName( _name );
std::string nodename = std::string("SeparatorNode for object " + _name.toUtf8()); std::string nodename = std::string("SeparatorNode for object " + _name.toUtf8());
separatorNode_->name( nodename ); separatorNode_->name( nodename );
nodename = std::string("ManipulatorNode for object " + _name.toUtf8()); nodename = std::string("ManipulatorNode for object " + _name.toUtf8());
manipulatorNode_->name( nodename ); manipulatorNode_->name( nodename );
nodename = std::string(_name.toUtf8() + "'s Material" ); nodename = std::string(_name.toUtf8() + "'s Material" );
materialNode_->name( nodename ); materialNode_->name( nodename );
} }
...@@ -136,7 +136,7 @@ QString BaseObjectData::path(){ ...@@ -136,7 +136,7 @@ QString BaseObjectData::path(){
} }
void BaseObjectData::path(QString _path ) { void BaseObjectData::path(QString _path ) {
path_ = _path; path_ = _path;
} }
// =============================================================================== // ===============================================================================
...@@ -144,29 +144,33 @@ void BaseObjectData::path(QString _path ) { ...@@ -144,29 +144,33 @@ void BaseObjectData::path(QString _path ) {
// =============================================================================== // ===============================================================================
void BaseObjectData::show() { void BaseObjectData::show() {
separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active ); separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active );
visible_ = true; visible_ = true;
} }
void BaseObjectData::hide() { void BaseObjectData::hide() {
separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree ); separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
visible_ = false; visible_ = false;
} }
SeparatorNode* BaseObjectData::baseNode() { SeparatorNode* BaseObjectData::baseNode() {
return separatorNode_; return separatorNode_;
} }
ManipulatorNode* BaseObjectData::manipulatorNode() { ManipulatorNode* BaseObjectData::manipulatorNode() {
return manipulatorNode_; return manipulatorNode_;
}
ACG::SceneGraph::ShaderNode* BaseObjectData::shaderNode() {
return 0;
} }
MaterialNode* BaseObjectData::materialNode() { MaterialNode* BaseObjectData::materialNode() {
return materialNode_; return materialNode_;
} }
void BaseObjectData::setBaseColor(ACG::Vec4f _color) { void BaseObjectData::setBaseColor(ACG::Vec4f _color) {
materialNode_->set_base_color(_color); materialNode_->set_base_color(_color);
} }
bool BaseObjectData::manipPlaced() { bool BaseObjectData::manipPlaced() {
...@@ -188,11 +192,11 @@ void BaseObjectData::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){ ...@@ -188,11 +192,11 @@ void BaseObjectData::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){
} }
// =============================================================================== // ===============================================================================
// Picking // Picking
// =============================================================================== // ===============================================================================
bool BaseObjectData::picked( uint /* _node_idx */ ) { bool BaseObjectData::picked( uint /* _node_idx */ ) {
return false; return false;
} }
void BaseObjectData::enablePicking( bool /*_enable*/ ) { void BaseObjectData::enablePicking( bool /*_enable*/ ) {
...@@ -219,14 +223,14 @@ bool BaseObjectData::hasAdditionalNode(QString _pluginName, QString _nodeName , ...@@ -219,14 +223,14 @@ bool BaseObjectData::hasAdditionalNode(QString _pluginName, QString _nodeName ,
QString index; QString index;
index.setNum(_id); index.setNum(_id);
QString searchname = _pluginName+"#"+_nodeName+"#"+index; QString searchname = _pluginName+"#"+_nodeName+"#"+index;
for ( uint i =0 ; i < additionalNodes_.size() ; ++i ) { for ( uint i =0 ; i < additionalNodes_.size() ; ++i ) {
if (additionalNodes_[i].second == searchname ) if (additionalNodes_[i].second == searchname )
return true; return true;
} }
return false; return false;
} }
//============================================================================= //=============================================================================
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
//============================================================================= //=============================================================================
/** /**
* \file BaseObjectData.hh * \file BaseObjectData.hh
* This File contains the Basic object class for all Objects which show content vi * This File contains the Basic object class for all Objects which show content vi
* the Scenegraph. * the Scenegraph.
*/ */
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#ifndef BASEOBJECTDATA_HH #ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH #define BASEOBJECTDATA_HH
#ifdef WIN32 #ifdef WIN32
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
#else #else
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include <vector> #include <vector>
#include <ACG/Scenegraph/MaterialNode.hh> #include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh> #include <ACG/Scenegraph/SeparatorNode.hh>
#include <ACG/Scenegraph/ShaderNode.hh>
#include <ACG/Scenegraph/BaseNode.hh> #include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/ManipulatorNode.hh> #include <ACG/Scenegraph/ManipulatorNode.hh>
...@@ -89,121 +90,128 @@ class DLLEXPORT BaseObjectData : public BaseObject ...@@ -89,121 +90,128 @@ class DLLEXPORT BaseObjectData : public BaseObject
///destructor ///destructor
virtual ~BaseObjectData(); virtual ~BaseObjectData();
protected: protected:
/** This function creates the scenegraph nodes */ /** This function creates the scenegraph nodes */
virtual void init(); virtual void init();
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Data /** @name Data
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public: public:
/** Clean all data structures of the object /** Clean all data structures of the object
* *
* */ * */
virtual void cleanup(); virtual void cleanup();
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Name and Path handling /** @name Name and Path handling
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public: public:
/** Set the object name from a filename. The function will set the name of the /** Set the object name from a filename. The function will set the name of the
* object to the filename. At the same time the path is set to the one given in * object to the filename. At the same time the path is set to the one given in
* the parameter * the parameter
* *
* @param _filename path to the file. * @param _filename path to the file.
*/ */
void setFromFileName(QString _filename ); void setFromFileName(QString _filename );
/// set the name of the object. ( If you overwrite it, call BaseObjectData::setName(_name ) it in your funtion first) /// set the name of the object. ( If you overwrite it, call BaseObjectData::setName(_name ) it in your funtion first)
virtual void setName( QString _name ); virtual void setName( QString _name );
/// return the path to the object ( defaults to "." if unset ) /// return the path to the object ( defaults to "." if unset )
QString path(); QString path();
/// set the path to the object. /// set the path to the object.
void path(QString _path); void path(QString _path);
private: private:
/// path to the file from which the object is loaded ( defaults to "." ) /// path to the file from which the object is loaded ( defaults to "." )
QString path_; QString path_;
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Object visualization /** @name Object visualization
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public : public :
/// Sets the whole Scenegraph subtree of this node to visible /// Sets the whole Scenegraph subtree of this node to visible
void show(); void show();
/// Sets the whole Scenegraph subtree of this node to invisible /// Sets the whole Scenegraph subtree of this node to invisible
void hide(); void hide();
/** get the base node of this object (Use this node to add custom Nodes to the Object /** get the base node of this object (Use this node to add custom Nodes to the Object
* which should not be transformed with the manipulator of the Object) * which should not be transformed with the manipulator of the Object)
*/ */
SeparatorNode* baseNode(); SeparatorNode* baseNode();
/** get the ManipulatorNode node of this object (Use this node to add custom Nodes to the Object /** get the ManipulatorNode node of this object (Use this node to add custom Nodes to the Object
* which should be transformed with the manipulator of the Object) * which should be transformed with the manipulator of the Object)
*/ */
ManipulatorNode* manipulatorNode(); ManipulatorNode* manipulatorNode();
/** Return pointer to the shader node
* If you want to support shaders, you have to add a shader node into your scenegraph structure
* above your object to be rendered. If you do not have a shader, just ignore this function
* and it will return a 0 pointer.
*/
virtual ACG::SceneGraph::ShaderNode* shaderNode();
/// get a pointer to the materialnode /// get a pointer to the materialnode
MaterialNode* materialNode(); MaterialNode* materialNode();
/// Set the color of the object /// Set the color of the object
void setBaseColor(ACG::Vec4f _color); void setBaseColor(ACG::Vec4f _color);
/// Check if the manipulator has been placed /// Check if the manipulator has been placed
bool manipPlaced(); bool manipPlaced();
/// set the manipulator place status /// set the manipulator place status
void manipPlaced( bool _placed ); void manipPlaced( bool _placed );
/// get the bounding box of the object /// get the bounding box of the object
void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax); void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
private : private :
bool manipPlaced_; bool manipPlaced_;
/// rootNode of global Scenegraph structure /// rootNode of global Scenegraph structure
SeparatorNode* rootNode_; SeparatorNode* rootNode_;
/// Separator at top of Scenegraph structure used for this Object /// Separator at top of Scenegraph structure used for this Object
SeparatorNode* separatorNode_; SeparatorNode* separatorNode_;
/// Manipulator used for this Object /// Manipulator used for this Object
ManipulatorNode* manipulatorNode_; ManipulatorNode* manipulatorNode_;
/// Scenegraph Material Node for the object /// Scenegraph Material Node for the object
MaterialNode* materialNode_; MaterialNode* materialNode_;
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Picking /** @name Picking
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public : public :
/// detect if the node has been picked /// detect if the node has been picked
virtual bool picked( uint _node_idx ); virtual bool picked( uint _node_idx );
...@@ -219,87 +227,87 @@ class DLLEXPORT BaseObjectData : public BaseObject ...@@ -219,87 +227,87 @@ class DLLEXPORT BaseObjectData : public BaseObject
* this function. * this function.
*/ */
virtual bool pickingEnabled(); virtual bool pickingEnabled();
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Content /** @name Content
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public: public:
/// This function is called to update the object /// This function is called to update the object
virtual void update(); virtual void update();
/** @} */ /** @} */
//=========================================================================== //===========================================================================
/** @name Additional nodes /** @name Additional nodes
* @{ */ * @{ */
//=========================================================================== //===========================================================================
public: public:
/** \brief add an additional node to the object /** \brief add an additional node to the object
* *
* This function can be used to store an additional Scenegraph node. If you add nodes there, you do not * This function can be used to store an additional Scenegraph node. If you add nodes there, you do not
* need to keep track of deleted, added objects, as this will be done in the main application. * need to keep track of deleted, added objects, as this will be done in the main application.
* You have to create the node yourself as this function does not know the type. You should add the * You have to create the node yourself as this function does not know the type. You should add the
* new node below the manipulatorNode if you want that it moves with the rest of the data. Otherwise * new node below the manipulatorNode if you want that it moves with the rest of the data. Otherwise
* add it below the seperatorNode of the object. * add it below the seperatorNode of the object.
* *
* @param _node Node to add * @param _node Node to add
* @param _pluginName Name of the current plugin * @param _pluginName Name of the current plugin
* @param _nodeName Name of the New Node * @param _nodeName Name of the New Node
* @param _id extra index, if there will be multiple nodes with this name( defaults to 0) * @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
* @return true if successfull * @return true if successfull
*/ */
template< typename NodeT > template< typename NodeT >
bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0); bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
/** \brief check if an object has the additional node /** \brief check if an object has the additional node
* *
* If you store additional Scenegraph nodes with the objects you can check if they * If you store additional Scenegraph nodes with the objects you can check if they
* exist with this function. * exist with this function.
* *
* @param _pluginName Name of the current plugin * @param _pluginName Name of the current plugin
* @param _nodeName Name of the Node * @param _nodeName Name of the Node
* @param _id extra index, if there are multiple nodes with this name( defaults to 0) * @param _id extra index, if there are multiple nodes with this name( defaults to 0)
* @return true if found * @return true if found
*/ */
bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0); bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);
/** \brief get an addition node from the object /** \brief get an addition node from the object
* *
* If you store additional Scenegraph node with the objects you can get these nodes with this function. * If you store additional Scenegraph node with the objects you can get these nodes with this function.