/* -*- c++ -*- Copyright (C) 2003 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * * Copyright (C) 2004, 2006 Mekensleep * * Mekensleep * 24 rue vieille du temple * 75004 Paris * licensing@mekensleep.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * * Authors: * Cedric PINSON * Loic Dachary * Igor Kravtchenko * */ #ifndef __OSGCAL__CORE_MODEL_H__ #define __OSGCAL__CORE_MODEL_H__ #include #include #include #include #include #include #include #include extern "C" { struct _xmlDoc; struct _xmlXPathContext; } typedef _xmlDoc* xmlDocPtr; typedef _xmlXPathContext* xmlXPathContextPtr; namespace osgCal { class Monitor { public: virtual ~Monitor() {} virtual void write(const char *mess) { }; virtual void setProgressLength(int len) { }; virtual void progress() { }; }; class IOOptions : public osgDB::ReaderWriter::Options { public: IOOptions() : mon_(NULL) { }; Monitor *getMonitor() const { return mon_; } void setMonitor(Monitor *_mon) { mon_ = _mon; } protected: Monitor *mon_; }; /**@brief Core Model class that creates a templated core object. * In order to create an animated model, a cal3d core model has to * be created. Given this core model it is possible to instanciate it * by creating a model which is in fact the real animated model and * object which can be inserted into an osg graph. */ class OSGCAL_EXPORT CoreModel: public osg::Object { public: typedef std::vector > Textures2D; typedef std::map CoreMaterialId2Textures2D; typedef std::map Name2Filename; META_Object(osgCal, CoreModel); CoreModel(); CoreModel(const CoreModel&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); protected: virtual ~CoreModel(); public: void setCollisionDefault(bool collisionDefault) { _collisionDefault = collisionDefault; } bool getCollisionDefault() { return _collisionDefault; } void setVersion(int version) { _version = version; } int getVersion() { return _version; } /**@brief Returns the cal3d core model associated with osgCal CoreModel*/ CalCoreModel* getCalCoreModel(void) { return &_calCoreModel; } /**@brief Cleans and releases dead objects*/ void garbageCollect(void); /**Returns a texture2D* given a texture filename * @param strFilename name of the texture file ( typically an image ) * @remark If texture has been already loaded by a previous call of this function, * the stored texture2D pointed is returned */ Textures2D* getTextures2D(const std::string& strFilename); /**@brief Returns the texture associated to a material * @param materialId the Id of the material */ Textures2D* getTextures2D(int materialId); bool getTexturesNameFromMaterialID(int _coreMaterialId, std::vector &_res); /**@brief Sets the mesh name to mesh filename map*/ void setMeshName2Filename(const Name2Filename& meshName2Filename) { _meshName2Filename = meshName2Filename; } /**@brief Returns the mesh name to file mesh name map*/ const Name2Filename& getMeshName2Filename(void) { return _meshName2Filename; } bool SubUsingMeshId(int coreMeshId); bool AddUsingMeshId(int coreMeshId); struct ParameterDescription { struct ColorElement { int value[3]; int tn[3]; int& operator[](int i) { return value[i];} }; struct OpacityDescription { OpacityDescription():_modifiable(false),_opacity(100) {} bool _modifiable; int _opacity; std::string _text; }; struct ColorDescription { ColorDescription():_modifiable(false),_selected(-1) {} bool _modifiable; int _selected; std::map _colors; std::string _text; }; ColorDescription _colors; OpacityDescription _opacity; std::string _type; }; struct LayerDescription { enum TextureFormat { TEXTUREFORMAT_RGB32, TEXTUREFORMAT_RGB16, TEXTUREFORMAT_DXT1, TEXTUREFORMAT_DXT3, TEXTUREFORMAT_DXT5, }; std::string _file; std::string _suffix; std::string _mode; int _textureFormat; }; struct SlotDescription { struct LayerDescription { std::string _layer; std::string _parameter; }; struct TextureDescription { std::string _mask; std::string _alpha; std::vector _layers; }; typedef std::map TextureEntries; TextureEntries _textures; std::vector _meshes; const std::vector& getMeshes() const { return _meshes;} }; typedef std::map MeshDescription; struct Material { std::string targetmap; std::string transparency; std::string envmap; }; typedef std::map SlotBank; std::map _parameters; std::map _layers; std::map _slots; std::map _meshes; std::vector _commonMeshes; std::map _materials; std::map _name2Normal; const std::vector& getCommonMeshes() const { return _commonMeshes;} const std::map& getMeshes() const { return _meshes;} SlotDescription* getSlotFromTypeAndName(const std::string& slotType,const std::string& slotName) { std::map::iterator stype=_slots.find(slotType); if (stype==_slots.end()) return 0; SlotBank::iterator sname=stype->second.find(slotName); if (sname==stype->second.end()) return 0; return &(sname->second); } std::string _path; bool _configurable; const std::map& getSlots() const { return _slots;} const std::string& getFilename() const { return _filename; } void setFilename(const std::string &fname) { _filename = fname; } protected: /**@brief Cal3d core model*/ CalCoreModel _calCoreModel; /**@brief Material Id to associated texture map*/ CoreMaterialId2Textures2D _coreMaterialId2Textures; /**@brief Mesh name to mesh filename map */ Name2Filename _meshName2Filename; std::map _mReferenceCountCoreMeshIds; bool _collisionDefault; int _version; osg::NotifySeverity _notify; std::string _filename; friend class ReaderWriterXFG; }; }; // namespace osgCal #endif