18 #include <sys/types.h> 25 #ifdef OPENHRP_COLLADA_FOUND 26 #include <boost/foreach.hpp> 31 static bool IsColladaFile(
const std::string&
filename)
33 size_t len = filename.size();
37 if( filename[len-4] ==
'.' && ::tolower(filename[len-3]) ==
'd' && ::tolower(filename[len-2]) ==
'a' && ::tolower(filename[len-1]) ==
'e' ) {
40 if( filename[len-4] ==
'.' && ::tolower(filename[len-3]) ==
'z' && ::tolower(filename[len-2]) ==
'a' && ::tolower(filename[len-1]) ==
'e' ) {
49 std::string
path = url;
50 if ( path.find(
"$(PROJECT_DIR)") != std::string::npos ) {
51 std::string shdir = OPENHRP_SHARE_DIR;
52 std::string pjdir = shdir +
"/sample/project";
53 path.replace(path.find(
"$(PROJECT_DIR)"),14, pjdir);
60 orb(CORBA::ORB::_duplicate(orb)),
61 poa(PortableServer::POA::_duplicate(poa))
75 return PortableServer::POA::_duplicate(
poa);
82 if( !!pBodyInfo_impl ) {
86 #ifdef OPENHRP_COLLADA_FOUND 88 if( !!pBodyInfoCollada_impl ) {
93 throw ModelLoader::ModelLoaderException(
"setLastUpdateTime invalid pointer");
98 if( !!pBodyInfo_impl ) {
101 #ifdef OPENHRP_COLLADA_FOUND 103 if( !!pBodyInfoCollada_impl ) {
107 throw ModelLoader::ModelLoaderException(
"getLastUpdateTime invalid pointer");
113 if( !!pBodyInfo_impl ) {
116 #ifdef OPENHRP_COLLADA_FOUND 118 if( !!pBodyInfoCollada_impl ) {
122 throw ModelLoader::ModelLoaderException(
"checkInlineFileUpdateTime invalid pointer");
125 static void setParam(POA_OpenHRP::BodyInfo* bodyInfo, std::string param,
int value)
128 if( !!pBodyInfo_impl ) {
129 pBodyInfo_impl->
setParam(param,value);
132 #ifdef OPENHRP_COLLADA_FOUND 134 if( !!pBodyInfoCollada_impl ) {
135 pBodyInfoCollada_impl->
setParam(param,value);
139 throw ModelLoader::ModelLoaderException(
"setParam(param,value) invalid pointer");
145 if( !!pBodyInfo_impl ) {
149 #ifdef OPENHRP_COLLADA_FOUND 151 if( !!pBodyInfoCollada_impl ) {
156 throw ModelLoader::ModelLoaderException(
"changetoBoundingBox(depth) invalid pointer");
160 throw (CORBA::SystemException, OpenHRP::ModelLoader::ModelLoaderException)
162 OpenHRP::ModelLoader::ModelLoadOption
option;
163 option.readImage =
false;
164 option.AABBdata.length(0);
165 option.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
167 return bodyInfo->_this();
171 throw (CORBA::SystemException, OpenHRP::ModelLoader::ModelLoaderException)
174 if(
option.AABBdata.length()){
177 unsigned int* _AABBdata =
new unsigned int[
length];
183 return bodyInfo->_this();
187 throw (CORBA::SystemException, OpenHRP::ModelLoader::ModelLoaderException)
191 BodyInfo_ptr bodyInfo = 0;
193 struct stat statbuff;
197 if( stat( filename.c_str(), &statbuff ) == 0 ){
198 mtime = statbuff.st_mtime;
203 bodyInfo = p->second->_this();
204 cout << string(
"cache found for ") + url << endl;
205 if(
option.AABBdata.length()){
208 unsigned int* _AABBdata =
new unsigned int[
length];
220 throw (CORBA::SystemException, OpenHRP::ModelLoader::ModelLoaderException)
222 OpenHRP::ModelLoader::ModelLoadOption
option;
223 option.readImage =
false;
224 option.AABBdata.length(0);
225 option.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
231 cout <<
"loading " << url << endl;
232 POA_OpenHRP::BodyInfo* bodyInfo;
234 #ifdef OPENHRP_COLLADA_FOUND 235 if( IsColladaFile(url) ) {
237 p->
setParam(
"readImage", option.readImage);
245 p->
setParam(
"readImage", option.readImage);
250 catch(OpenHRP::ModelLoader::ModelLoaderException& ex){
251 cout <<
"loading failed.\n";
252 cout << ex.description << endl;
257 cout <<
"The model was successfully loaded ! " << endl;
259 #ifdef OPENHRP_COLLADA_FOUND 270 struct stat statbuff;
274 if( stat( filename.c_str(), &statbuff ) == 0 ){
275 mtime = statbuff.st_mtime;
285 throw (CORBA::SystemException, OpenHRP::ModelLoader::ModelLoaderException)
287 cout <<
"loading " << url << endl;
291 #ifdef OPENHRP_COLLADA_FOUND 292 if( IsColladaFile(url) ) {
305 catch(OpenHRP::ModelLoader::ModelLoaderException& ex){
306 cout <<
"loading failed.\n";
307 cout << ex.description << endl;
311 cout << url <<
" was successfully loaded ! " << endl;
315 return sceneInfo->_this();
335 orb->shutdown(
false);
void setParam(std::string param, bool value)
static void setParam(POA_OpenHRP::BodyInfo *bodyInfo, std::string param, int value)
UrlToBodyInfoMap urlToBodyInfoMap
static void setLastUpdateTime(POA_OpenHRP::BodyInfo *bodyInfo, time_t time)
std::string replaceProjectDir(std::string url)
PortableServer::POA_var poa
void setLastUpdateTime(time_t time)
static bool checkInlineFileUpdateTime(POA_OpenHRP::BodyInfo *bodyInfo)
png_bytep png_bytep png_size_t length
virtual SceneInfo_ptr loadSceneInfo(const char *url)
reads in collada files and initializes a BodyInfo struct
void changetoBoundingBox(unsigned int *depth)
virtual BodyInfo_ptr getBodyInfoEx(const char *url, const OpenHRP::ModelLoader::ModelLoadOption &option)
static void changetoBoundingBox(POA_OpenHRP::BodyInfo *bodyInfo, unsigned int *depth)
virtual BodyInfo_ptr loadBodyInfo(const char *url)
virtual ~ModelLoader_impl()
void loadModelFile(const std::string &filename)
void loadModelFile(const std::string &filename)
This function loads a model file and creates a BodyInfo object.
POA_OpenHRP::BodyInfo * loadBodyInfoFromModelFile(const std::string url, const OpenHRP::ModelLoader::ModelLoadOption option)
void setParam(std::string param, bool value)
virtual BodyInfo_ptr loadBodyInfoEx(const char *url, const OpenHRP::ModelLoader::ModelLoadOption &option)
bool checkInlineFileUpdateTime()
time_t getLastUpdateTime()
HRP_UTIL_EXPORT string deleteURLScheme(string url)
void load(const std::string &filename)
virtual BodyInfo_ptr getBodyInfo(const char *url)
void changetoBoundingBox(unsigned int *depth)
void load(const std::string &filename)
static time_t getLastUpdateTime(POA_OpenHRP::BodyInfo *bodyInfo)
bool checkInlineFileUpdateTime()
time_t getLastUpdateTime()
void setLastUpdateTime(time_t time)
ModelLoader_impl(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
virtual PortableServer::POA_ptr _default_POA()