Merge pull request #615 from delicious-monster/master
I made changes to the Collada importer so it will import SketchUp DAEs.pull/612/merge
commit
a9a62368f8
|
@ -1,82 +1,82 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* DEPRECATED! - use code/TinyFormatter.h instead.
|
/* DEPRECATED! - use code/TinyFormatter.h instead.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
#ifndef AI_BOOST_FORMAT_DUMMY_INCLUDED
|
#ifndef AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||||
#define AI_BOOST_FORMAT_DUMMY_INCLUDED
|
#define AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||||
|
|
||||||
#if (!defined BOOST_FORMAT_HPP) || (defined ASSIMP_FORCE_NOBOOST)
|
#if (!defined BOOST_FORMAT_HPP) || (defined ASSIMP_FORCE_NOBOOST)
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class format
|
class format
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
format (const std::string& _d)
|
format (const std::string& _d)
|
||||||
: d(_d)
|
: d(_d)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
format& operator % (T in)
|
format& operator % (T in)
|
||||||
{
|
{
|
||||||
// XXX add replacement for boost::lexical_cast?
|
// XXX add replacement for boost::lexical_cast?
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << in; // note: ss cannot be an rvalue, or the global operator << (const char*) is not called for T == const char*.
|
ss << in; // note: ss cannot be an rvalue, or the global operator << (const char*) is not called for T == const char*.
|
||||||
chunks.push_back( ss.str());
|
chunks.push_back( ss.str());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
operator std::string () const {
|
operator std::string () const {
|
||||||
std::string res; // pray for NRVO to kick in
|
std::string res; // pray for NRVO to kick in
|
||||||
|
|
||||||
size_t start = 0, last = 0;
|
size_t start = 0, last = 0;
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator chunkin = chunks.begin();
|
std::vector<std::string>::const_iterator chunkin = chunks.begin();
|
||||||
|
|
||||||
for ( start = d.find('%');start != std::string::npos; start = d.find('%',last)) {
|
for ( start = d.find('%');start != std::string::npos; start = d.find('%',last)) {
|
||||||
res += d.substr(last,start-last);
|
res += d.substr(last,start-last);
|
||||||
last = start+2;
|
last = start+2;
|
||||||
if (d[start+1] == '%') {
|
if (d[start+1] == '%') {
|
||||||
res += "%";
|
res += "%";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunkin == chunks.end()) {
|
if (chunkin == chunks.end()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
res += *chunkin++;
|
res += *chunkin++;
|
||||||
}
|
}
|
||||||
res += d.substr(last);
|
res += d.substr(last);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string d;
|
std::string d;
|
||||||
std::vector<std::string> chunks;
|
std::vector<std::string> chunks;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::string str(const std::string& s) {
|
inline std::string str(const std::string& s) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# error "format.h was already included"
|
# error "format.h was already included"
|
||||||
#endif //
|
#endif //
|
||||||
#endif // !! AI_BOOST_FORMAT_DUMMY_INCLUDED
|
#endif // !! AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||||
|
|
||||||
|
|
|
@ -1,260 +1,260 @@
|
||||||
|
|
||||||
#ifndef INCLUDED_AI_BOOST_SHARED_PTR
|
#ifndef INCLUDED_AI_BOOST_SHARED_PTR
|
||||||
#define INCLUDED_AI_BOOST_SHARED_PTR
|
#define INCLUDED_AI_BOOST_SHARED_PTR
|
||||||
|
|
||||||
#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
|
#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
|
||||||
|
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
// Internal stub
|
// Internal stub
|
||||||
|
|
||||||
#include <stddef.h> //NULL
|
#include <stddef.h> //NULL
|
||||||
#include <algorithm> //std::swap
|
#include <algorithm> //std::swap
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
class controller {
|
class controller {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
controller()
|
controller()
|
||||||
: cnt(1)
|
: cnt(1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
controller* decref(T* pt) {
|
controller* decref(T* pt) {
|
||||||
if (--cnt <= 0) {
|
if (--cnt <= 0) {
|
||||||
delete this;
|
delete this;
|
||||||
delete pt;
|
delete pt;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller* incref() {
|
controller* incref() {
|
||||||
++cnt;
|
++cnt;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get() const {
|
long get() const {
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long cnt;
|
long cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct empty {};
|
struct empty {};
|
||||||
|
|
||||||
template <typename DEST, typename SRC>
|
template <typename DEST, typename SRC>
|
||||||
struct is_convertible_stub {
|
struct is_convertible_stub {
|
||||||
|
|
||||||
struct yes {char s[1];};
|
struct yes {char s[1];};
|
||||||
struct no {char s[2];};
|
struct no {char s[2];};
|
||||||
|
|
||||||
static yes foo(DEST*);
|
static yes foo(DEST*);
|
||||||
static no foo(...);
|
static no foo(...);
|
||||||
|
|
||||||
enum {result = (sizeof(foo((SRC*)0)) == sizeof(yes) ? 1 : 0)};
|
enum {result = (sizeof(foo((SRC*)0)) == sizeof(yes) ? 1 : 0)};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <bool> struct enable_if {};
|
template <bool> struct enable_if {};
|
||||||
template <> struct enable_if<true> {
|
template <> struct enable_if<true> {
|
||||||
typedef empty result;
|
typedef empty result;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename DEST, typename SRC>
|
template <typename DEST, typename SRC>
|
||||||
struct is_convertible : public enable_if<is_convertible_stub<DEST,SRC>::result > {
|
struct is_convertible : public enable_if<is_convertible_stub<DEST,SRC>::result > {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
// Small replacement for boost::shared_ptr, not threadsafe because no
|
// Small replacement for boost::shared_ptr, not threadsafe because no
|
||||||
// atomic reference counter is in use.
|
// atomic reference counter is in use.
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
class shared_ptr
|
class shared_ptr
|
||||||
{
|
{
|
||||||
template <typename TT> friend class shared_ptr;
|
template <typename TT> friend class shared_ptr;
|
||||||
|
|
||||||
template<class TT, class U> friend shared_ptr<TT> static_pointer_cast (shared_ptr<U> ptr);
|
template<class TT, class U> friend shared_ptr<TT> static_pointer_cast (shared_ptr<U> ptr);
|
||||||
template<class TT, class U> friend shared_ptr<TT> dynamic_pointer_cast (shared_ptr<U> ptr);
|
template<class TT, class U> friend shared_ptr<TT> dynamic_pointer_cast (shared_ptr<U> ptr);
|
||||||
template<class TT, class U> friend shared_ptr<TT> const_pointer_cast (shared_ptr<U> ptr);
|
template<class TT, class U> friend shared_ptr<TT> const_pointer_cast (shared_ptr<U> ptr);
|
||||||
|
|
||||||
template<class TT> friend bool operator== (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
template<class TT> friend bool operator== (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
||||||
template<class TT> friend bool operator!= (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
template<class TT> friend bool operator!= (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
||||||
template<class TT> friend bool operator< (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
template<class TT> friend bool operator< (const shared_ptr<TT>& a, const shared_ptr<TT>& b);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// provide a default constructor
|
// provide a default constructor
|
||||||
shared_ptr()
|
shared_ptr()
|
||||||
: ptr()
|
: ptr()
|
||||||
, ctr(NULL)
|
, ctr(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// construction from an existing object of type T
|
// construction from an existing object of type T
|
||||||
explicit shared_ptr(T* ptr)
|
explicit shared_ptr(T* ptr)
|
||||||
: ptr(ptr)
|
: ptr(ptr)
|
||||||
, ctr(ptr ? new detail::controller() : NULL)
|
, ctr(ptr ? new detail::controller() : NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr(const shared_ptr& r)
|
shared_ptr(const shared_ptr& r)
|
||||||
: ptr(r.ptr)
|
: ptr(r.ptr)
|
||||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Y>
|
template <typename Y>
|
||||||
shared_ptr(const shared_ptr<Y>& r,typename detail::is_convertible<T,Y>::result = detail::empty())
|
shared_ptr(const shared_ptr<Y>& r,typename detail::is_convertible<T,Y>::result = detail::empty())
|
||||||
: ptr(r.ptr)
|
: ptr(r.ptr)
|
||||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatic destruction of the wrapped object when all
|
// automatic destruction of the wrapped object when all
|
||||||
// references are freed.
|
// references are freed.
|
||||||
~shared_ptr() {
|
~shared_ptr() {
|
||||||
if (ctr) {
|
if (ctr) {
|
||||||
ctr = ctr->decref(ptr);
|
ctr = ctr->decref(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr& operator=(const shared_ptr& r) {
|
shared_ptr& operator=(const shared_ptr& r) {
|
||||||
if (this == &r) {
|
if (this == &r) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
if (ctr) {
|
if (ctr) {
|
||||||
ctr->decref(ptr);
|
ctr->decref(ptr);
|
||||||
}
|
}
|
||||||
ptr = r.ptr;
|
ptr = r.ptr;
|
||||||
ctr = ptr?r.ctr->incref():NULL;
|
ctr = ptr?r.ctr->incref():NULL;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Y>
|
template <typename Y>
|
||||||
shared_ptr& operator=(const shared_ptr<Y>& r) {
|
shared_ptr& operator=(const shared_ptr<Y>& r) {
|
||||||
if (this == &r) {
|
if (this == &r) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
if (ctr) {
|
if (ctr) {
|
||||||
ctr->decref(ptr);
|
ctr->decref(ptr);
|
||||||
}
|
}
|
||||||
ptr = r.ptr;
|
ptr = r.ptr;
|
||||||
ctr = ptr?r.ctr->incref():NULL;
|
ctr = ptr?r.ctr->incref():NULL;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pointer access
|
// pointer access
|
||||||
inline operator T*() const {
|
inline operator T*() const {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline T* operator-> () const {
|
inline T* operator-> () const {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard semantics
|
// standard semantics
|
||||||
inline T* get() {
|
inline T* get() {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const T* get() const {
|
inline const T* get() const {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator bool () const {
|
inline operator bool () const {
|
||||||
return ptr != NULL;
|
return ptr != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool unique() const {
|
inline bool unique() const {
|
||||||
return use_count() == 1;
|
return use_count() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline long use_count() const {
|
inline long use_count() const {
|
||||||
return ctr->get();
|
return ctr->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void reset (T* t = 0) {
|
inline void reset (T* t = 0) {
|
||||||
if (ctr) {
|
if (ctr) {
|
||||||
ctr->decref(ptr);
|
ctr->decref(ptr);
|
||||||
}
|
}
|
||||||
ptr = t;
|
ptr = t;
|
||||||
ctr = ptr?new detail::controller():NULL;
|
ctr = ptr?new detail::controller():NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(shared_ptr & b) {
|
void swap(shared_ptr & b) {
|
||||||
std::swap(ptr, b.ptr);
|
std::swap(ptr, b.ptr);
|
||||||
std::swap(ctr, b.ctr);
|
std::swap(ctr, b.ctr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
// for use by the various xxx_pointer_cast helper templates
|
// for use by the various xxx_pointer_cast helper templates
|
||||||
explicit shared_ptr(T* ptr, detail::controller* ctr)
|
explicit shared_ptr(T* ptr, detail::controller* ctr)
|
||||||
: ptr(ptr)
|
: ptr(ptr)
|
||||||
, ctr(ctr->incref())
|
, ctr(ctr->incref())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// encapsulated object pointer
|
// encapsulated object pointer
|
||||||
T* ptr;
|
T* ptr;
|
||||||
|
|
||||||
// control block
|
// control block
|
||||||
detail::controller* ctr;
|
detail::controller* ctr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
|
inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
|
||||||
{
|
{
|
||||||
a.swap(b);
|
a.swap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool operator== (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
bool operator== (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||||
return a.ptr == b.ptr;
|
return a.ptr == b.ptr;
|
||||||
}
|
}
|
||||||
template<class T>
|
template<class T>
|
||||||
bool operator!= (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
bool operator!= (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||||
return a.ptr != b.ptr;
|
return a.ptr != b.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool operator< (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
bool operator< (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||||
return a.ptr < b.ptr;
|
return a.ptr < b.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline shared_ptr<T> static_pointer_cast( shared_ptr<U> ptr)
|
inline shared_ptr<T> static_pointer_cast( shared_ptr<U> ptr)
|
||||||
{
|
{
|
||||||
return shared_ptr<T>(static_cast<T*>(ptr.ptr),ptr.ctr);
|
return shared_ptr<T>(static_cast<T*>(ptr.ptr),ptr.ctr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> ptr)
|
inline shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> ptr)
|
||||||
{
|
{
|
||||||
return shared_ptr<T>(dynamic_cast<T*>(ptr.ptr),ptr.ctr);
|
return shared_ptr<T>(dynamic_cast<T*>(ptr.ptr),ptr.ctr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
inline shared_ptr<T> const_pointer_cast( shared_ptr<U> ptr)
|
inline shared_ptr<T> const_pointer_cast( shared_ptr<U> ptr)
|
||||||
{
|
{
|
||||||
return shared_ptr<T>(const_cast<T*>(ptr.ptr),ptr.ctr);
|
return shared_ptr<T>(const_cast<T*>(ptr.ptr),ptr.ctr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end of namespace boost
|
} // end of namespace boost
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# error "shared_ptr.h was already included"
|
# error "shared_ptr.h was already included"
|
||||||
#endif
|
#endif
|
||||||
#endif // INCLUDED_AI_BOOST_SHARED_PTR
|
#endif // INCLUDED_AI_BOOST_SHARED_PTR
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
// boost timer.hpp header file ---------------------------------------------//
|
// boost timer.hpp header file ---------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes 1994-99. Distributed under the Boost
|
// Copyright Beman Dawes 1994-99. Distributed under the Boost
|
||||||
// Software License, Version 1.0. (See accompanying file
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// See http://www.boost.org/libs/timer for documentation.
|
// See http://www.boost.org/libs/timer for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
|
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
|
||||||
// 12 Jan 01 Change to inline implementation to allow use without library
|
// 12 Jan 01 Change to inline implementation to allow use without library
|
||||||
// builds. See docs for more rationale. (Beman Dawes)
|
// builds. See docs for more rationale. (Beman Dawes)
|
||||||
// 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
|
// 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
|
||||||
// 16 Jul 99 Second beta
|
// 16 Jul 99 Second beta
|
||||||
// 6 Jul 99 Initial boost version
|
// 6 Jul 99 Initial boost version
|
||||||
|
|
||||||
#ifndef BOOST_TIMER_HPP
|
#ifndef BOOST_TIMER_HPP
|
||||||
#define BOOST_TIMER_HPP
|
#define BOOST_TIMER_HPP
|
||||||
|
|
||||||
//#include <boost/config.hpp>
|
//#include <boost/config.hpp>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
//#include <boost/limits.hpp>
|
//#include <boost/limits.hpp>
|
||||||
|
|
||||||
# ifdef BOOST_NO_STDC_NAMESPACE
|
# ifdef BOOST_NO_STDC_NAMESPACE
|
||||||
namespace std { using ::clock_t; using ::clock; }
|
namespace std { using ::clock_t; using ::clock; }
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
// timer -------------------------------------------------------------------//
|
// timer -------------------------------------------------------------------//
|
||||||
|
|
||||||
// A timer object measures elapsed time.
|
// A timer object measures elapsed time.
|
||||||
|
|
||||||
// It is recommended that implementations measure wall clock rather than CPU
|
// It is recommended that implementations measure wall clock rather than CPU
|
||||||
// time since the intended use is performance measurement on systems where
|
// time since the intended use is performance measurement on systems where
|
||||||
// total elapsed time is more important than just process or CPU time.
|
// total elapsed time is more important than just process or CPU time.
|
||||||
|
|
||||||
// Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
|
// Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
|
||||||
// due to implementation limitations. The accuracy of timings depends on the
|
// due to implementation limitations. The accuracy of timings depends on the
|
||||||
// accuracy of timing information provided by the underlying platform, and
|
// accuracy of timing information provided by the underlying platform, and
|
||||||
// this varies a great deal from platform to platform.
|
// this varies a great deal from platform to platform.
|
||||||
|
|
||||||
class timer
|
class timer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
|
timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
|
||||||
// timer( const timer& src ); // post: elapsed()==src.elapsed()
|
// timer( const timer& src ); // post: elapsed()==src.elapsed()
|
||||||
// ~timer(){}
|
// ~timer(){}
|
||||||
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
|
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
|
||||||
void restart() { _start_time = std::clock(); } // post: elapsed()==0
|
void restart() { _start_time = std::clock(); } // post: elapsed()==0
|
||||||
double elapsed() const // return elapsed time in seconds
|
double elapsed() const // return elapsed time in seconds
|
||||||
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
|
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
|
||||||
|
|
||||||
double elapsed_max() const // return estimated maximum value for elapsed()
|
double elapsed_max() const // return estimated maximum value for elapsed()
|
||||||
// Portability warning: elapsed_max() may return too high a value on systems
|
// Portability warning: elapsed_max() may return too high a value on systems
|
||||||
// where std::clock_t overflows or resets at surprising values.
|
// where std::clock_t overflows or resets at surprising values.
|
||||||
{
|
{
|
||||||
return (double((std::numeric_limits<std::clock_t>::max)())
|
return (double((std::numeric_limits<std::clock_t>::max)())
|
||||||
- double(_start_time)) / double(CLOCKS_PER_SEC);
|
- double(_start_time)) / double(CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
double elapsed_min() const // return minimum value for elapsed()
|
double elapsed_min() const // return minimum value for elapsed()
|
||||||
{ return double(1)/double(CLOCKS_PER_SEC); }
|
{ return double(1)/double(CLOCKS_PER_SEC); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::clock_t _start_time;
|
std::clock_t _start_time;
|
||||||
}; // timer
|
}; // timer
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_TIMER_HPP
|
#endif // BOOST_TIMER_HPP
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,352 @@
|
||||||
|
/*
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2015, assimp team
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the
|
||||||
|
following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file ColladaParser.h
|
||||||
|
* @brief Defines the parser helper class for the collada loader
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AI_COLLADAPARSER_H_INC
|
||||||
|
#define AI_COLLADAPARSER_H_INC
|
||||||
|
|
||||||
|
#include "irrXMLWrapper.h"
|
||||||
|
#include "ColladaHelper.h"
|
||||||
|
#include "../include/assimp/ai_assert.h"
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
namespace Assimp
|
||||||
|
{
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------
|
||||||
|
/** Parser helper class for the Collada loader.
|
||||||
|
*
|
||||||
|
* Does all the XML reading and builds internal data structures from it,
|
||||||
|
* but leaves the resolving of all the references to the loader.
|
||||||
|
*/
|
||||||
|
class ColladaParser
|
||||||
|
{
|
||||||
|
friend class ColladaLoader;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Constructor from XML file */
|
||||||
|
ColladaParser( IOSystem* pIOHandler, const std::string& pFile);
|
||||||
|
|
||||||
|
/** Destructor */
|
||||||
|
~ColladaParser();
|
||||||
|
|
||||||
|
/** Reads the contents of the file */
|
||||||
|
void ReadContents();
|
||||||
|
|
||||||
|
/** Reads the structure of the file */
|
||||||
|
void ReadStructure();
|
||||||
|
|
||||||
|
/** Reads asset informations such as coordinate system informations and legal blah */
|
||||||
|
void ReadAssetInfo();
|
||||||
|
|
||||||
|
/** Reads the animation library */
|
||||||
|
void ReadAnimationLibrary();
|
||||||
|
|
||||||
|
/** Reads an animation into the given parent structure */
|
||||||
|
void ReadAnimation( Collada::Animation* pParent);
|
||||||
|
|
||||||
|
/** Reads an animation sampler into the given anim channel */
|
||||||
|
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
||||||
|
|
||||||
|
/** Reads the skeleton controller library */
|
||||||
|
void ReadControllerLibrary();
|
||||||
|
|
||||||
|
/** Reads a controller into the given mesh structure */
|
||||||
|
void ReadController( Collada::Controller& pController);
|
||||||
|
|
||||||
|
/** Reads the joint definitions for the given controller */
|
||||||
|
void ReadControllerJoints( Collada::Controller& pController);
|
||||||
|
|
||||||
|
/** Reads the joint weights for the given controller */
|
||||||
|
void ReadControllerWeights( Collada::Controller& pController);
|
||||||
|
|
||||||
|
/** Reads the image library contents */
|
||||||
|
void ReadImageLibrary();
|
||||||
|
|
||||||
|
/** Reads an image entry into the given image */
|
||||||
|
void ReadImage( Collada::Image& pImage);
|
||||||
|
|
||||||
|
/** Reads the material library */
|
||||||
|
void ReadMaterialLibrary();
|
||||||
|
|
||||||
|
/** Reads a material entry into the given material */
|
||||||
|
void ReadMaterial( Collada::Material& pMaterial);
|
||||||
|
|
||||||
|
/** Reads the camera library */
|
||||||
|
void ReadCameraLibrary();
|
||||||
|
|
||||||
|
/** Reads a camera entry into the given camera */
|
||||||
|
void ReadCamera( Collada::Camera& pCamera);
|
||||||
|
|
||||||
|
/** Reads the light library */
|
||||||
|
void ReadLightLibrary();
|
||||||
|
|
||||||
|
/** Reads a light entry into the given light */
|
||||||
|
void ReadLight( Collada::Light& pLight);
|
||||||
|
|
||||||
|
/** Reads the effect library */
|
||||||
|
void ReadEffectLibrary();
|
||||||
|
|
||||||
|
/** Reads an effect entry into the given effect*/
|
||||||
|
void ReadEffect( Collada::Effect& pEffect);
|
||||||
|
|
||||||
|
/** Reads an COMMON effect profile */
|
||||||
|
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
||||||
|
|
||||||
|
/** Read sampler properties */
|
||||||
|
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
||||||
|
|
||||||
|
/** Reads an effect entry containing a color or a texture defining that color */
|
||||||
|
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
||||||
|
|
||||||
|
/** Reads an effect entry containing a float */
|
||||||
|
void ReadEffectFloat( float& pFloat);
|
||||||
|
|
||||||
|
/** Reads an effect parameter specification of any kind */
|
||||||
|
void ReadEffectParam( Collada::EffectParam& pParam);
|
||||||
|
|
||||||
|
/** Reads the geometry library contents */
|
||||||
|
void ReadGeometryLibrary();
|
||||||
|
|
||||||
|
/** Reads a geometry from the geometry library. */
|
||||||
|
void ReadGeometry( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
|
/** Reads a mesh from the geometry library */
|
||||||
|
void ReadMesh( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
|
/** Reads a source element - a combination of raw data and an accessor defining
|
||||||
|
* things that should not be redefinable. Yes, that's another rant.
|
||||||
|
*/
|
||||||
|
void ReadSource();
|
||||||
|
|
||||||
|
/** Reads a data array holding a number of elements, and stores it in the global library.
|
||||||
|
* Currently supported are array of floats and arrays of strings.
|
||||||
|
*/
|
||||||
|
void ReadDataArray();
|
||||||
|
|
||||||
|
/** Reads an accessor and stores it in the global library under the given ID -
|
||||||
|
* accessors use the ID of the parent <source> element
|
||||||
|
*/
|
||||||
|
void ReadAccessor( const std::string& pID);
|
||||||
|
|
||||||
|
/** Reads input declarations of per-vertex mesh data into the given mesh */
|
||||||
|
void ReadVertexData( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
|
/** Reads input declarations of per-index mesh data into the given mesh */
|
||||||
|
void ReadIndexData( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
|
/** Reads a single input channel element and stores it in the given array, if valid */
|
||||||
|
void ReadInputChannel( std::vector<Collada::InputChannel>& poChannels);
|
||||||
|
|
||||||
|
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
|
||||||
|
size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||||
|
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType);
|
||||||
|
|
||||||
|
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
|
||||||
|
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
|
||||||
|
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||||
|
size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
|
|
||||||
|
/** Reads one triangle of a tristrip into the mesh */
|
||||||
|
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
||||||
|
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
|
|
||||||
|
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
|
||||||
|
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh);
|
||||||
|
|
||||||
|
/** Reads the library of node hierarchies and scene parts */
|
||||||
|
void ReadSceneLibrary();
|
||||||
|
|
||||||
|
/** Reads a scene node's contents including children and stores it in the given node */
|
||||||
|
void ReadSceneNode( Collada::Node* pNode);
|
||||||
|
|
||||||
|
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
|
||||||
|
void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType);
|
||||||
|
|
||||||
|
/** Reads a mesh reference in a node and adds it to the node's mesh list */
|
||||||
|
void ReadNodeGeometry( Collada::Node* pNode);
|
||||||
|
|
||||||
|
/** Reads the collada scene */
|
||||||
|
void ReadScene();
|
||||||
|
|
||||||
|
// Processes bind_vertex_input and bind elements
|
||||||
|
void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Aborts the file reading with an exception */
|
||||||
|
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX;
|
||||||
|
|
||||||
|
/** Skips all data until the end node of the current element */
|
||||||
|
void SkipElement();
|
||||||
|
|
||||||
|
/** Skips all data until the end node of the given element */
|
||||||
|
void SkipElement( const char* pElement);
|
||||||
|
|
||||||
|
/** Compares the current xml element name to the given string and returns true if equal */
|
||||||
|
bool IsElement( const char* pName) const;
|
||||||
|
|
||||||
|
/** Tests for the opening tag of the given element, throws an exception if not found */
|
||||||
|
void TestOpening( const char* pName);
|
||||||
|
|
||||||
|
/** Tests for the closing tag of the given element, throws an exception if not found */
|
||||||
|
void TestClosing( const char* pName);
|
||||||
|
|
||||||
|
/** Checks the present element for the presence of the attribute, returns its index
|
||||||
|
or throws an exception if not found */
|
||||||
|
int GetAttribute( const char* pAttr) const;
|
||||||
|
|
||||||
|
/** Returns the index of the named attribute or -1 if not found. Does not throw,
|
||||||
|
therefore useful for optional attributes */
|
||||||
|
int TestAttribute( const char* pAttr) const;
|
||||||
|
|
||||||
|
/** Reads the text contents of an element, throws an exception if not given.
|
||||||
|
Skips leading whitespace. */
|
||||||
|
const char* GetTextContent();
|
||||||
|
|
||||||
|
/** Reads the text contents of an element, returns NULL if not given.
|
||||||
|
Skips leading whitespace. */
|
||||||
|
const char* TestTextContent();
|
||||||
|
|
||||||
|
/** Reads a single bool from current text content */
|
||||||
|
bool ReadBoolFromTextContent();
|
||||||
|
|
||||||
|
/** Reads a single float from current text content */
|
||||||
|
float ReadFloatFromTextContent();
|
||||||
|
|
||||||
|
/** Calculates the resulting transformation from all the given transform steps */
|
||||||
|
aiMatrix4x4 CalculateResultTransform( const std::vector<Collada::Transform>& pTransforms) const;
|
||||||
|
|
||||||
|
/** Determines the input data type for the given semantic string */
|
||||||
|
Collada::InputType GetTypeForSemantic( const std::string& pSemantic);
|
||||||
|
|
||||||
|
/** Finds the item in the given library by its reference, throws if not found */
|
||||||
|
template <typename Type> const Type& ResolveLibraryReference(
|
||||||
|
const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Filename, for a verbose error message */
|
||||||
|
std::string mFileName;
|
||||||
|
|
||||||
|
/** XML reader, member for everyday use */
|
||||||
|
irr::io::IrrXMLReader* mReader;
|
||||||
|
|
||||||
|
/** All data arrays found in the file by ID. Might be referred to by actually
|
||||||
|
everyone. Collada, you are a steaming pile of indirection. */
|
||||||
|
typedef std::map<std::string, Collada::Data> DataLibrary;
|
||||||
|
DataLibrary mDataLibrary;
|
||||||
|
|
||||||
|
/** Same for accessors which define how the data in a data array is accessed. */
|
||||||
|
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
|
||||||
|
AccessorLibrary mAccessorLibrary;
|
||||||
|
|
||||||
|
/** Mesh library: mesh by ID */
|
||||||
|
typedef std::map<std::string, Collada::Mesh*> MeshLibrary;
|
||||||
|
MeshLibrary mMeshLibrary;
|
||||||
|
|
||||||
|
/** node library: root node of the hierarchy part by ID */
|
||||||
|
typedef std::map<std::string, Collada::Node*> NodeLibrary;
|
||||||
|
NodeLibrary mNodeLibrary;
|
||||||
|
|
||||||
|
/** Image library: stores texture properties by ID */
|
||||||
|
typedef std::map<std::string, Collada::Image> ImageLibrary;
|
||||||
|
ImageLibrary mImageLibrary;
|
||||||
|
|
||||||
|
/** Effect library: surface attributes by ID */
|
||||||
|
typedef std::map<std::string, Collada::Effect> EffectLibrary;
|
||||||
|
EffectLibrary mEffectLibrary;
|
||||||
|
|
||||||
|
/** Material library: surface material by ID */
|
||||||
|
typedef std::map<std::string, Collada::Material> MaterialLibrary;
|
||||||
|
MaterialLibrary mMaterialLibrary;
|
||||||
|
|
||||||
|
/** Light library: surface light by ID */
|
||||||
|
typedef std::map<std::string, Collada::Light> LightLibrary;
|
||||||
|
LightLibrary mLightLibrary;
|
||||||
|
|
||||||
|
/** Camera library: surface material by ID */
|
||||||
|
typedef std::map<std::string, Collada::Camera> CameraLibrary;
|
||||||
|
CameraLibrary mCameraLibrary;
|
||||||
|
|
||||||
|
/** Controller library: joint controllers by ID */
|
||||||
|
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
|
||||||
|
ControllerLibrary mControllerLibrary;
|
||||||
|
|
||||||
|
/** Pointer to the root node. Don't delete, it just points to one of
|
||||||
|
the nodes in the node library. */
|
||||||
|
Collada::Node* mRootNode;
|
||||||
|
|
||||||
|
/** Root animation container */
|
||||||
|
Collada::Animation mAnims;
|
||||||
|
|
||||||
|
/** Size unit: how large compared to a meter */
|
||||||
|
float mUnitSize;
|
||||||
|
|
||||||
|
/** Which is the up vector */
|
||||||
|
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
||||||
|
|
||||||
|
/** Collada file format version */
|
||||||
|
Collada::FormatVersion mFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// Check for element match
|
||||||
|
inline bool ColladaParser::IsElement( const char* pName) const
|
||||||
|
{
|
||||||
|
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
||||||
|
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// Finds the item in the given library by its reference, throws if not found
|
||||||
|
template <typename Type>
|
||||||
|
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
||||||
|
{
|
||||||
|
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL);
|
||||||
|
if( it == pLibrary.end())
|
||||||
|
ThrowException( boost::str( boost::format( "Unable to resolve library reference \"%s\".") % pURL));
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace Assimp
|
||||||
|
|
||||||
|
#endif // AI_COLLADAPARSER_H_INC
|
File diff suppressed because it is too large
Load Diff
|
@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_COLLADA_IMPORTER
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "ColladaParser.h"
|
#include "ColladaParser.h"
|
||||||
#include "fast_atof.h"
|
#include "fast_atof.h"
|
||||||
#include "ParsingUtils.h"
|
#include "ParsingUtils.h"
|
||||||
|
@ -1998,7 +1999,8 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_DEBUG
|
#ifdef ASSIMP_BUILD_DEBUG
|
||||||
if (primType != Prim_TriFans && primType != Prim_TriStrips) {
|
if (primType != Prim_TriFans && primType != Prim_TriStrips &&
|
||||||
|
primType != Prim_Lines) { // this is ONLY to workaround a bug in SketchUp 15.3.331 where it writes the wrong 'count' when it writes out the 'lines'.
|
||||||
ai_assert(actualPrimitives == numPrimitives);
|
ai_assert(actualPrimitives == numPrimitives);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2107,13 +2109,19 @@ size_t ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector<InputChannel>& pP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// complain if the index count doesn't fit
|
// complain if the index count doesn't fit
|
||||||
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets)
|
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets) {
|
||||||
ThrowException( "Expected different index count in <p> element.");
|
if (pPrimType == Prim_Lines) {
|
||||||
else if( expectedPointCount == 0 && (indices.size() % numOffsets) != 0)
|
// HACK: We just fix this number since SketchUp 15.3.331 writes the wrong 'count' for 'lines'
|
||||||
ThrowException( "Expected different index count in <p> element.");
|
ReportWarning( "Expected different index count in <p> element, %d instead of %d.", indices.size(), expectedPointCount * numOffsets);
|
||||||
|
pNumPrimitives = (indices.size() / numOffsets) / 2;
|
||||||
|
} else
|
||||||
|
ThrowException( "Expected different index count in <p> element.");
|
||||||
|
|
||||||
// find the data for all sources
|
} else if( expectedPointCount == 0 && (indices.size() % numOffsets) != 0)
|
||||||
|
ThrowException( "Expected different index count in <p> element.");
|
||||||
|
|
||||||
|
// find the data for all sources
|
||||||
for( std::vector<InputChannel>::iterator it = pMesh->mPerVertexData.begin(); it != pMesh->mPerVertexData.end(); ++it)
|
for( std::vector<InputChannel>::iterator it = pMesh->mPerVertexData.begin(); it != pMesh->mPerVertexData.end(); ++it)
|
||||||
{
|
{
|
||||||
InputChannel& input = *it;
|
InputChannel& input = *it;
|
||||||
|
@ -2712,6 +2720,21 @@ AI_WONT_RETURN void ColladaParser::ThrowException( const std::string& pError) co
|
||||||
{
|
{
|
||||||
throw DeadlyImportError( boost::str( boost::format( "Collada: %s - %s") % mFileName % pError));
|
throw DeadlyImportError( boost::str( boost::format( "Collada: %s - %s") % mFileName % pError));
|
||||||
}
|
}
|
||||||
|
void ColladaParser::ReportWarning(const char* msg,...)
|
||||||
|
{
|
||||||
|
ai_assert(NULL != msg);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args,msg);
|
||||||
|
|
||||||
|
char szBuffer[3000];
|
||||||
|
const int iLen = vsprintf(szBuffer,msg,args);
|
||||||
|
ai_assert(iLen > 0);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
DefaultLogger::get()->warn("Validation warning: " + std::string(szBuffer,iLen));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Skips all data until the end node of the current element
|
// Skips all data until the end node of the current element
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
/*
|
/*
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2015, assimp team
|
Copyright (c) 2006-2015, assimp team
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
with or without modification, are permitted provided that the
|
with or without modification, are permitted provided that the
|
||||||
following conditions are met:
|
following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above
|
* Redistributions of source code must retain the above
|
||||||
copyright notice, this list of conditions and the
|
copyright notice, this list of conditions and the
|
||||||
following disclaimer.
|
following disclaimer.
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above
|
* Redistributions in binary form must reproduce the above
|
||||||
copyright notice, this list of conditions and the
|
copyright notice, this list of conditions and the
|
||||||
following disclaimer in the documentation and/or other
|
following disclaimer in the documentation and/or other
|
||||||
materials provided with the distribution.
|
materials provided with the distribution.
|
||||||
|
|
||||||
* Neither the name of the assimp team, nor the names of its
|
* Neither the name of the assimp team, nor the names of its
|
||||||
contributors may be used to endorse or promote products
|
contributors may be used to endorse or promote products
|
||||||
derived from this software without specific prior
|
derived from this software without specific prior
|
||||||
written permission of the assimp team.
|
written permission of the assimp team.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @file ColladaParser.h
|
/** @file ColladaParser.h
|
||||||
* @brief Defines the parser helper class for the collada loader
|
* @brief Defines the parser helper class for the collada loader
|
||||||
|
@ -52,301 +52,302 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
{
|
{
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
/** Parser helper class for the Collada loader.
|
/** Parser helper class for the Collada loader.
|
||||||
*
|
*
|
||||||
* Does all the XML reading and builds internal data structures from it,
|
* Does all the XML reading and builds internal data structures from it,
|
||||||
* but leaves the resolving of all the references to the loader.
|
* but leaves the resolving of all the references to the loader.
|
||||||
*/
|
|
||||||
class ColladaParser
|
|
||||||
{
|
|
||||||
friend class ColladaLoader;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/** Constructor from XML file */
|
|
||||||
ColladaParser( IOSystem* pIOHandler, const std::string& pFile);
|
|
||||||
|
|
||||||
/** Destructor */
|
|
||||||
~ColladaParser();
|
|
||||||
|
|
||||||
/** Reads the contents of the file */
|
|
||||||
void ReadContents();
|
|
||||||
|
|
||||||
/** Reads the structure of the file */
|
|
||||||
void ReadStructure();
|
|
||||||
|
|
||||||
/** Reads asset informations such as coordinate system informations and legal blah */
|
|
||||||
void ReadAssetInfo();
|
|
||||||
|
|
||||||
/** Reads the animation library */
|
|
||||||
void ReadAnimationLibrary();
|
|
||||||
|
|
||||||
/** Reads an animation into the given parent structure */
|
|
||||||
void ReadAnimation( Collada::Animation* pParent);
|
|
||||||
|
|
||||||
/** Reads an animation sampler into the given anim channel */
|
|
||||||
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
|
||||||
|
|
||||||
/** Reads the skeleton controller library */
|
|
||||||
void ReadControllerLibrary();
|
|
||||||
|
|
||||||
/** Reads a controller into the given mesh structure */
|
|
||||||
void ReadController( Collada::Controller& pController);
|
|
||||||
|
|
||||||
/** Reads the joint definitions for the given controller */
|
|
||||||
void ReadControllerJoints( Collada::Controller& pController);
|
|
||||||
|
|
||||||
/** Reads the joint weights for the given controller */
|
|
||||||
void ReadControllerWeights( Collada::Controller& pController);
|
|
||||||
|
|
||||||
/** Reads the image library contents */
|
|
||||||
void ReadImageLibrary();
|
|
||||||
|
|
||||||
/** Reads an image entry into the given image */
|
|
||||||
void ReadImage( Collada::Image& pImage);
|
|
||||||
|
|
||||||
/** Reads the material library */
|
|
||||||
void ReadMaterialLibrary();
|
|
||||||
|
|
||||||
/** Reads a material entry into the given material */
|
|
||||||
void ReadMaterial( Collada::Material& pMaterial);
|
|
||||||
|
|
||||||
/** Reads the camera library */
|
|
||||||
void ReadCameraLibrary();
|
|
||||||
|
|
||||||
/** Reads a camera entry into the given camera */
|
|
||||||
void ReadCamera( Collada::Camera& pCamera);
|
|
||||||
|
|
||||||
/** Reads the light library */
|
|
||||||
void ReadLightLibrary();
|
|
||||||
|
|
||||||
/** Reads a light entry into the given light */
|
|
||||||
void ReadLight( Collada::Light& pLight);
|
|
||||||
|
|
||||||
/** Reads the effect library */
|
|
||||||
void ReadEffectLibrary();
|
|
||||||
|
|
||||||
/** Reads an effect entry into the given effect*/
|
|
||||||
void ReadEffect( Collada::Effect& pEffect);
|
|
||||||
|
|
||||||
/** Reads an COMMON effect profile */
|
|
||||||
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
|
||||||
|
|
||||||
/** Read sampler properties */
|
|
||||||
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
|
||||||
|
|
||||||
/** Reads an effect entry containing a color or a texture defining that color */
|
|
||||||
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
|
||||||
|
|
||||||
/** Reads an effect entry containing a float */
|
|
||||||
void ReadEffectFloat( float& pFloat);
|
|
||||||
|
|
||||||
/** Reads an effect parameter specification of any kind */
|
|
||||||
void ReadEffectParam( Collada::EffectParam& pParam);
|
|
||||||
|
|
||||||
/** Reads the geometry library contents */
|
|
||||||
void ReadGeometryLibrary();
|
|
||||||
|
|
||||||
/** Reads a geometry from the geometry library. */
|
|
||||||
void ReadGeometry( Collada::Mesh* pMesh);
|
|
||||||
|
|
||||||
/** Reads a mesh from the geometry library */
|
|
||||||
void ReadMesh( Collada::Mesh* pMesh);
|
|
||||||
|
|
||||||
/** Reads a source element - a combination of raw data and an accessor defining
|
|
||||||
* things that should not be redefinable. Yes, that's another rant.
|
|
||||||
*/
|
*/
|
||||||
void ReadSource();
|
class ColladaParser
|
||||||
|
{
|
||||||
/** Reads a data array holding a number of elements, and stores it in the global library.
|
friend class ColladaLoader;
|
||||||
* Currently supported are array of floats and arrays of strings.
|
|
||||||
*/
|
protected:
|
||||||
void ReadDataArray();
|
/** Constructor from XML file */
|
||||||
|
ColladaParser( IOSystem* pIOHandler, const std::string& pFile);
|
||||||
/** Reads an accessor and stores it in the global library under the given ID -
|
|
||||||
* accessors use the ID of the parent <source> element
|
/** Destructor */
|
||||||
*/
|
~ColladaParser();
|
||||||
void ReadAccessor( const std::string& pID);
|
|
||||||
|
/** Reads the contents of the file */
|
||||||
/** Reads input declarations of per-vertex mesh data into the given mesh */
|
void ReadContents();
|
||||||
void ReadVertexData( Collada::Mesh* pMesh);
|
|
||||||
|
/** Reads the structure of the file */
|
||||||
/** Reads input declarations of per-index mesh data into the given mesh */
|
void ReadStructure();
|
||||||
void ReadIndexData( Collada::Mesh* pMesh);
|
|
||||||
|
/** Reads asset informations such as coordinate system informations and legal blah */
|
||||||
/** Reads a single input channel element and stores it in the given array, if valid */
|
void ReadAssetInfo();
|
||||||
void ReadInputChannel( std::vector<Collada::InputChannel>& poChannels);
|
|
||||||
|
/** Reads the animation library */
|
||||||
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
|
void ReadAnimationLibrary();
|
||||||
size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
|
||||||
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType);
|
/** Reads an animation into the given parent structure */
|
||||||
|
void ReadAnimation( Collada::Animation* pParent);
|
||||||
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
|
|
||||||
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
|
/** Reads an animation sampler into the given anim channel */
|
||||||
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
void ReadAnimationSampler( Collada::AnimationChannel& pChannel);
|
||||||
size_t currentPrimitive, const std::vector<size_t>& indices);
|
|
||||||
|
/** Reads the skeleton controller library */
|
||||||
/** Reads one triangle of a tristrip into the mesh */
|
void ReadControllerLibrary();
|
||||||
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
|
||||||
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
/** Reads a controller into the given mesh structure */
|
||||||
|
void ReadController( Collada::Controller& pController);
|
||||||
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
|
|
||||||
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh);
|
/** Reads the joint definitions for the given controller */
|
||||||
|
void ReadControllerJoints( Collada::Controller& pController);
|
||||||
/** Reads the library of node hierarchies and scene parts */
|
|
||||||
void ReadSceneLibrary();
|
/** Reads the joint weights for the given controller */
|
||||||
|
void ReadControllerWeights( Collada::Controller& pController);
|
||||||
/** Reads a scene node's contents including children and stores it in the given node */
|
|
||||||
void ReadSceneNode( Collada::Node* pNode);
|
/** Reads the image library contents */
|
||||||
|
void ReadImageLibrary();
|
||||||
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
|
|
||||||
void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType);
|
/** Reads an image entry into the given image */
|
||||||
|
void ReadImage( Collada::Image& pImage);
|
||||||
/** Reads a mesh reference in a node and adds it to the node's mesh list */
|
|
||||||
void ReadNodeGeometry( Collada::Node* pNode);
|
/** Reads the material library */
|
||||||
|
void ReadMaterialLibrary();
|
||||||
/** Reads the collada scene */
|
|
||||||
void ReadScene();
|
/** Reads a material entry into the given material */
|
||||||
|
void ReadMaterial( Collada::Material& pMaterial);
|
||||||
// Processes bind_vertex_input and bind elements
|
|
||||||
void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl);
|
/** Reads the camera library */
|
||||||
|
void ReadCameraLibrary();
|
||||||
protected:
|
|
||||||
/** Aborts the file reading with an exception */
|
/** Reads a camera entry into the given camera */
|
||||||
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX;
|
void ReadCamera( Collada::Camera& pCamera);
|
||||||
|
|
||||||
/** Skips all data until the end node of the current element */
|
/** Reads the light library */
|
||||||
void SkipElement();
|
void ReadLightLibrary();
|
||||||
|
|
||||||
/** Skips all data until the end node of the given element */
|
/** Reads a light entry into the given light */
|
||||||
void SkipElement( const char* pElement);
|
void ReadLight( Collada::Light& pLight);
|
||||||
|
|
||||||
/** Compares the current xml element name to the given string and returns true if equal */
|
/** Reads the effect library */
|
||||||
bool IsElement( const char* pName) const;
|
void ReadEffectLibrary();
|
||||||
|
|
||||||
/** Tests for the opening tag of the given element, throws an exception if not found */
|
/** Reads an effect entry into the given effect*/
|
||||||
void TestOpening( const char* pName);
|
void ReadEffect( Collada::Effect& pEffect);
|
||||||
|
|
||||||
/** Tests for the closing tag of the given element, throws an exception if not found */
|
/** Reads an COMMON effect profile */
|
||||||
void TestClosing( const char* pName);
|
void ReadEffectProfileCommon( Collada::Effect& pEffect);
|
||||||
|
|
||||||
/** Checks the present element for the presence of the attribute, returns its index
|
/** Read sampler properties */
|
||||||
or throws an exception if not found */
|
void ReadSamplerProperties( Collada::Sampler& pSampler);
|
||||||
int GetAttribute( const char* pAttr) const;
|
|
||||||
|
/** Reads an effect entry containing a color or a texture defining that color */
|
||||||
/** Returns the index of the named attribute or -1 if not found. Does not throw,
|
void ReadEffectColor( aiColor4D& pColor, Collada::Sampler& pSampler);
|
||||||
therefore useful for optional attributes */
|
|
||||||
int TestAttribute( const char* pAttr) const;
|
/** Reads an effect entry containing a float */
|
||||||
|
void ReadEffectFloat( float& pFloat);
|
||||||
/** Reads the text contents of an element, throws an exception if not given.
|
|
||||||
Skips leading whitespace. */
|
/** Reads an effect parameter specification of any kind */
|
||||||
const char* GetTextContent();
|
void ReadEffectParam( Collada::EffectParam& pParam);
|
||||||
|
|
||||||
/** Reads the text contents of an element, returns NULL if not given.
|
/** Reads the geometry library contents */
|
||||||
Skips leading whitespace. */
|
void ReadGeometryLibrary();
|
||||||
const char* TestTextContent();
|
|
||||||
|
/** Reads a geometry from the geometry library. */
|
||||||
/** Reads a single bool from current text content */
|
void ReadGeometry( Collada::Mesh* pMesh);
|
||||||
bool ReadBoolFromTextContent();
|
|
||||||
|
/** Reads a mesh from the geometry library */
|
||||||
/** Reads a single float from current text content */
|
void ReadMesh( Collada::Mesh* pMesh);
|
||||||
float ReadFloatFromTextContent();
|
|
||||||
|
/** Reads a source element - a combination of raw data and an accessor defining
|
||||||
/** Calculates the resulting transformation from all the given transform steps */
|
* things that should not be redefinable. Yes, that's another rant.
|
||||||
aiMatrix4x4 CalculateResultTransform( const std::vector<Collada::Transform>& pTransforms) const;
|
*/
|
||||||
|
void ReadSource();
|
||||||
/** Determines the input data type for the given semantic string */
|
|
||||||
Collada::InputType GetTypeForSemantic( const std::string& pSemantic);
|
/** Reads a data array holding a number of elements, and stores it in the global library.
|
||||||
|
* Currently supported are array of floats and arrays of strings.
|
||||||
/** Finds the item in the given library by its reference, throws if not found */
|
*/
|
||||||
template <typename Type> const Type& ResolveLibraryReference(
|
void ReadDataArray();
|
||||||
const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
|
|
||||||
|
/** Reads an accessor and stores it in the global library under the given ID -
|
||||||
protected:
|
* accessors use the ID of the parent <source> element
|
||||||
/** Filename, for a verbose error message */
|
*/
|
||||||
std::string mFileName;
|
void ReadAccessor( const std::string& pID);
|
||||||
|
|
||||||
/** XML reader, member for everyday use */
|
/** Reads input declarations of per-vertex mesh data into the given mesh */
|
||||||
irr::io::IrrXMLReader* mReader;
|
void ReadVertexData( Collada::Mesh* pMesh);
|
||||||
|
|
||||||
/** All data arrays found in the file by ID. Might be referred to by actually
|
/** Reads input declarations of per-index mesh data into the given mesh */
|
||||||
everyone. Collada, you are a steaming pile of indirection. */
|
void ReadIndexData( Collada::Mesh* pMesh);
|
||||||
typedef std::map<std::string, Collada::Data> DataLibrary;
|
|
||||||
DataLibrary mDataLibrary;
|
/** Reads a single input channel element and stores it in the given array, if valid */
|
||||||
|
void ReadInputChannel( std::vector<Collada::InputChannel>& poChannels);
|
||||||
/** Same for accessors which define how the data in a data array is accessed. */
|
|
||||||
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
|
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
|
||||||
AccessorLibrary mAccessorLibrary;
|
size_t ReadPrimitives( Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||||
|
size_t pNumPrimitives, const std::vector<size_t>& pVCount, Collada::PrimitiveType pPrimType);
|
||||||
/** Mesh library: mesh by ID */
|
|
||||||
typedef std::map<std::string, Collada::Mesh*> MeshLibrary;
|
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
|
||||||
MeshLibrary mMeshLibrary;
|
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
|
||||||
|
Collada::Mesh* pMesh, std::vector<Collada::InputChannel>& pPerIndexChannels,
|
||||||
/** node library: root node of the hierarchy part by ID */
|
size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
typedef std::map<std::string, Collada::Node*> NodeLibrary;
|
|
||||||
NodeLibrary mNodeLibrary;
|
/** Reads one triangle of a tristrip into the mesh */
|
||||||
|
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh* pMesh,
|
||||||
/** Image library: stores texture properties by ID */
|
std::vector<Collada::InputChannel>& pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t>& indices);
|
||||||
typedef std::map<std::string, Collada::Image> ImageLibrary;
|
|
||||||
ImageLibrary mImageLibrary;
|
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
|
||||||
|
void ExtractDataObjectFromChannel( const Collada::InputChannel& pInput, size_t pLocalIndex, Collada::Mesh* pMesh);
|
||||||
/** Effect library: surface attributes by ID */
|
|
||||||
typedef std::map<std::string, Collada::Effect> EffectLibrary;
|
/** Reads the library of node hierarchies and scene parts */
|
||||||
EffectLibrary mEffectLibrary;
|
void ReadSceneLibrary();
|
||||||
|
|
||||||
/** Material library: surface material by ID */
|
/** Reads a scene node's contents including children and stores it in the given node */
|
||||||
typedef std::map<std::string, Collada::Material> MaterialLibrary;
|
void ReadSceneNode( Collada::Node* pNode);
|
||||||
MaterialLibrary mMaterialLibrary;
|
|
||||||
|
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
|
||||||
/** Light library: surface light by ID */
|
void ReadNodeTransformation( Collada::Node* pNode, Collada::TransformType pType);
|
||||||
typedef std::map<std::string, Collada::Light> LightLibrary;
|
|
||||||
LightLibrary mLightLibrary;
|
/** Reads a mesh reference in a node and adds it to the node's mesh list */
|
||||||
|
void ReadNodeGeometry( Collada::Node* pNode);
|
||||||
/** Camera library: surface material by ID */
|
|
||||||
typedef std::map<std::string, Collada::Camera> CameraLibrary;
|
/** Reads the collada scene */
|
||||||
CameraLibrary mCameraLibrary;
|
void ReadScene();
|
||||||
|
|
||||||
/** Controller library: joint controllers by ID */
|
// Processes bind_vertex_input and bind elements
|
||||||
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
|
void ReadMaterialVertexInputBinding( Collada::SemanticMappingTable& tbl);
|
||||||
ControllerLibrary mControllerLibrary;
|
|
||||||
|
protected:
|
||||||
/** Pointer to the root node. Don't delete, it just points to one of
|
/** Aborts the file reading with an exception */
|
||||||
the nodes in the node library. */
|
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX;
|
||||||
Collada::Node* mRootNode;
|
void ReportWarning(const char* msg,...);
|
||||||
|
|
||||||
/** Root animation container */
|
|
||||||
Collada::Animation mAnims;
|
|
||||||
|
|
||||||
/** Size unit: how large compared to a meter */
|
|
||||||
float mUnitSize;
|
|
||||||
|
|
||||||
/** Which is the up vector */
|
|
||||||
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
|
||||||
|
|
||||||
/** Collada file format version */
|
|
||||||
Collada::FormatVersion mFormat;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// Check for element match
|
|
||||||
inline bool ColladaParser::IsElement( const char* pName) const
|
|
||||||
{
|
|
||||||
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
|
||||||
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// Finds the item in the given library by its reference, throws if not found
|
|
||||||
template <typename Type>
|
|
||||||
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
|
||||||
{
|
|
||||||
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL);
|
|
||||||
if( it == pLibrary.end())
|
|
||||||
ThrowException( boost::str( boost::format( "Unable to resolve library reference \"%s\".") % pURL));
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** Skips all data until the end node of the current element */
|
||||||
|
void SkipElement();
|
||||||
|
|
||||||
|
/** Skips all data until the end node of the given element */
|
||||||
|
void SkipElement( const char* pElement);
|
||||||
|
|
||||||
|
/** Compares the current xml element name to the given string and returns true if equal */
|
||||||
|
bool IsElement( const char* pName) const;
|
||||||
|
|
||||||
|
/** Tests for the opening tag of the given element, throws an exception if not found */
|
||||||
|
void TestOpening( const char* pName);
|
||||||
|
|
||||||
|
/** Tests for the closing tag of the given element, throws an exception if not found */
|
||||||
|
void TestClosing( const char* pName);
|
||||||
|
|
||||||
|
/** Checks the present element for the presence of the attribute, returns its index
|
||||||
|
or throws an exception if not found */
|
||||||
|
int GetAttribute( const char* pAttr) const;
|
||||||
|
|
||||||
|
/** Returns the index of the named attribute or -1 if not found. Does not throw,
|
||||||
|
therefore useful for optional attributes */
|
||||||
|
int TestAttribute( const char* pAttr) const;
|
||||||
|
|
||||||
|
/** Reads the text contents of an element, throws an exception if not given.
|
||||||
|
Skips leading whitespace. */
|
||||||
|
const char* GetTextContent();
|
||||||
|
|
||||||
|
/** Reads the text contents of an element, returns NULL if not given.
|
||||||
|
Skips leading whitespace. */
|
||||||
|
const char* TestTextContent();
|
||||||
|
|
||||||
|
/** Reads a single bool from current text content */
|
||||||
|
bool ReadBoolFromTextContent();
|
||||||
|
|
||||||
|
/** Reads a single float from current text content */
|
||||||
|
float ReadFloatFromTextContent();
|
||||||
|
|
||||||
|
/** Calculates the resulting transformation from all the given transform steps */
|
||||||
|
aiMatrix4x4 CalculateResultTransform( const std::vector<Collada::Transform>& pTransforms) const;
|
||||||
|
|
||||||
|
/** Determines the input data type for the given semantic string */
|
||||||
|
Collada::InputType GetTypeForSemantic( const std::string& pSemantic);
|
||||||
|
|
||||||
|
/** Finds the item in the given library by its reference, throws if not found */
|
||||||
|
template <typename Type> const Type& ResolveLibraryReference(
|
||||||
|
const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Filename, for a verbose error message */
|
||||||
|
std::string mFileName;
|
||||||
|
|
||||||
|
/** XML reader, member for everyday use */
|
||||||
|
irr::io::IrrXMLReader* mReader;
|
||||||
|
|
||||||
|
/** All data arrays found in the file by ID. Might be referred to by actually
|
||||||
|
everyone. Collada, you are a steaming pile of indirection. */
|
||||||
|
typedef std::map<std::string, Collada::Data> DataLibrary;
|
||||||
|
DataLibrary mDataLibrary;
|
||||||
|
|
||||||
|
/** Same for accessors which define how the data in a data array is accessed. */
|
||||||
|
typedef std::map<std::string, Collada::Accessor> AccessorLibrary;
|
||||||
|
AccessorLibrary mAccessorLibrary;
|
||||||
|
|
||||||
|
/** Mesh library: mesh by ID */
|
||||||
|
typedef std::map<std::string, Collada::Mesh*> MeshLibrary;
|
||||||
|
MeshLibrary mMeshLibrary;
|
||||||
|
|
||||||
|
/** node library: root node of the hierarchy part by ID */
|
||||||
|
typedef std::map<std::string, Collada::Node*> NodeLibrary;
|
||||||
|
NodeLibrary mNodeLibrary;
|
||||||
|
|
||||||
|
/** Image library: stores texture properties by ID */
|
||||||
|
typedef std::map<std::string, Collada::Image> ImageLibrary;
|
||||||
|
ImageLibrary mImageLibrary;
|
||||||
|
|
||||||
|
/** Effect library: surface attributes by ID */
|
||||||
|
typedef std::map<std::string, Collada::Effect> EffectLibrary;
|
||||||
|
EffectLibrary mEffectLibrary;
|
||||||
|
|
||||||
|
/** Material library: surface material by ID */
|
||||||
|
typedef std::map<std::string, Collada::Material> MaterialLibrary;
|
||||||
|
MaterialLibrary mMaterialLibrary;
|
||||||
|
|
||||||
|
/** Light library: surface light by ID */
|
||||||
|
typedef std::map<std::string, Collada::Light> LightLibrary;
|
||||||
|
LightLibrary mLightLibrary;
|
||||||
|
|
||||||
|
/** Camera library: surface material by ID */
|
||||||
|
typedef std::map<std::string, Collada::Camera> CameraLibrary;
|
||||||
|
CameraLibrary mCameraLibrary;
|
||||||
|
|
||||||
|
/** Controller library: joint controllers by ID */
|
||||||
|
typedef std::map<std::string, Collada::Controller> ControllerLibrary;
|
||||||
|
ControllerLibrary mControllerLibrary;
|
||||||
|
|
||||||
|
/** Pointer to the root node. Don't delete, it just points to one of
|
||||||
|
the nodes in the node library. */
|
||||||
|
Collada::Node* mRootNode;
|
||||||
|
|
||||||
|
/** Root animation container */
|
||||||
|
Collada::Animation mAnims;
|
||||||
|
|
||||||
|
/** Size unit: how large compared to a meter */
|
||||||
|
float mUnitSize;
|
||||||
|
|
||||||
|
/** Which is the up vector */
|
||||||
|
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
||||||
|
|
||||||
|
/** Collada file format version */
|
||||||
|
Collada::FormatVersion mFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// Check for element match
|
||||||
|
inline bool ColladaParser::IsElement( const char* pName) const
|
||||||
|
{
|
||||||
|
ai_assert( mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
||||||
|
return ::strcmp( mReader->getNodeName(), pName) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// Finds the item in the given library by its reference, throws if not found
|
||||||
|
template <typename Type>
|
||||||
|
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
||||||
|
{
|
||||||
|
typename std::map<std::string, Type>::const_iterator it = pLibrary.find( pURL);
|
||||||
|
if( it == pLibrary.end())
|
||||||
|
ThrowException( boost::str( boost::format( "Unable to resolve library reference \"%s\".") % pURL));
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // AI_COLLADAPARSER_H_INC
|
#endif // AI_COLLADAPARSER_H_INC
|
||||||
|
|
|
@ -1,151 +1,151 @@
|
||||||
// Copyright (C) 2002-2005 Nikolaus Gebhardt
|
// Copyright (C) 2002-2005 Nikolaus Gebhardt
|
||||||
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
||||||
// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
|
// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
|
||||||
|
|
||||||
// Need to include Assimp, too. We're using Assimp's version of fast_atof
|
// Need to include Assimp, too. We're using Assimp's version of fast_atof
|
||||||
// so we need stdint.h. But no PCH.
|
// so we need stdint.h. But no PCH.
|
||||||
|
|
||||||
|
|
||||||
#include "irrXML.h"
|
#include "irrXML.h"
|
||||||
#include "irrString.h"
|
#include "irrString.h"
|
||||||
#include "irrArray.h"
|
#include "irrArray.h"
|
||||||
#include "./../../code/fast_atof.h"
|
#include "./../../code/fast_atof.h"
|
||||||
#include "CXMLReaderImpl.h"
|
#include "CXMLReaderImpl.h"
|
||||||
|
|
||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
//! Implementation of the file read callback for ordinary files
|
//! Implementation of the file read callback for ordinary files
|
||||||
class CFileReadCallBack : public IFileReadCallBack
|
class CFileReadCallBack : public IFileReadCallBack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! construct from filename
|
//! construct from filename
|
||||||
CFileReadCallBack(const char* filename)
|
CFileReadCallBack(const char* filename)
|
||||||
: File(0), Size(0), Close(true)
|
: File(0), Size(0), Close(true)
|
||||||
{
|
{
|
||||||
// open file
|
// open file
|
||||||
File = fopen(filename, "rb");
|
File = fopen(filename, "rb");
|
||||||
|
|
||||||
if (File)
|
if (File)
|
||||||
getFileSize();
|
getFileSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! construct from FILE pointer
|
//! construct from FILE pointer
|
||||||
CFileReadCallBack(FILE* file)
|
CFileReadCallBack(FILE* file)
|
||||||
: File(file), Size(0), Close(false)
|
: File(file), Size(0), Close(false)
|
||||||
{
|
{
|
||||||
if (File)
|
if (File)
|
||||||
getFileSize();
|
getFileSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! destructor
|
//! destructor
|
||||||
virtual ~CFileReadCallBack()
|
virtual ~CFileReadCallBack()
|
||||||
{
|
{
|
||||||
if (Close && File)
|
if (Close && File)
|
||||||
fclose(File);
|
fclose(File);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Reads an amount of bytes from the file.
|
//! Reads an amount of bytes from the file.
|
||||||
virtual int read(void* buffer, int sizeToRead)
|
virtual int read(void* buffer, int sizeToRead)
|
||||||
{
|
{
|
||||||
if (!File)
|
if (!File)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (int)fread(buffer, 1, sizeToRead, File);
|
return (int)fread(buffer, 1, sizeToRead, File);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Returns size of file in bytes
|
//! Returns size of file in bytes
|
||||||
virtual int getSize()
|
virtual int getSize()
|
||||||
{
|
{
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! retrieves the file size of the open file
|
//! retrieves the file size of the open file
|
||||||
void getFileSize()
|
void getFileSize()
|
||||||
{
|
{
|
||||||
fseek(File, 0, SEEK_END);
|
fseek(File, 0, SEEK_END);
|
||||||
Size = ftell(File);
|
Size = ftell(File);
|
||||||
fseek(File, 0, SEEK_SET);
|
fseek(File, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* File;
|
FILE* File;
|
||||||
int Size;
|
int Size;
|
||||||
bool Close;
|
bool Close;
|
||||||
|
|
||||||
}; // end class CFileReadCallBack
|
}; // end class CFileReadCallBack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FACTORY FUNCTIONS:
|
// FACTORY FUNCTIONS:
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||||
IrrXMLReader* createIrrXMLReader(const char* filename)
|
IrrXMLReader* createIrrXMLReader(const char* filename)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
|
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||||
IrrXMLReader* createIrrXMLReader(FILE* file)
|
IrrXMLReader* createIrrXMLReader(FILE* file)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
|
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||||
IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
|
IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char, IXMLBase>(callback, false);
|
return new CXMLReaderImpl<char, IXMLBase>(callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-16 xml parser.
|
//! Creates an instance of an UTF-16 xml parser.
|
||||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
|
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
|
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-16 xml parser.
|
//! Creates an instance of an UTF-16 xml parser.
|
||||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
|
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
|
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-16 xml parser.
|
//! Creates an instance of an UTF-16 xml parser.
|
||||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
|
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
|
return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-32 xml parser.
|
//! Creates an instance of an UTF-32 xml parser.
|
||||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
|
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
|
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-32 xml parser.
|
//! Creates an instance of an UTF-32 xml parser.
|
||||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
|
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
|
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Creates an instance of an UTF-32 xml parser.
|
//! Creates an instance of an UTF-32 xml parser.
|
||||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
|
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
|
||||||
{
|
{
|
||||||
return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
|
return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end namespace io
|
} // end namespace io
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
|
|
@ -1,389 +1,389 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
// Simple sample to prove that Assimp is easy to use with OpenGL.
|
// Simple sample to prove that Assimp is easy to use with OpenGL.
|
||||||
// It takes a file name as command line parameter, loads it using standard
|
// It takes a file name as command line parameter, loads it using standard
|
||||||
// settings and displays it.
|
// settings and displays it.
|
||||||
//
|
//
|
||||||
// If you intend to _use_ this code sample in your app, do yourself a favour
|
// If you intend to _use_ this code sample in your app, do yourself a favour
|
||||||
// and replace immediate mode calls with VBOs ...
|
// and replace immediate mode calls with VBOs ...
|
||||||
//
|
//
|
||||||
// The vc8 solution links against assimp-release-dll_win32 - be sure to
|
// The vc8 solution links against assimp-release-dll_win32 - be sure to
|
||||||
// have this configuration built.
|
// have this configuration built.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <glut.h>
|
#include <glut.h>
|
||||||
#else
|
#else
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* assimp include files. These three are usually needed. */
|
/* assimp include files. These three are usually needed. */
|
||||||
#include <assimp/cimport.h>
|
#include <assimp/cimport.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
|
|
||||||
/* the global Assimp scene object */
|
/* the global Assimp scene object */
|
||||||
const struct aiScene* scene = NULL;
|
const struct aiScene* scene = NULL;
|
||||||
GLuint scene_list = 0;
|
GLuint scene_list = 0;
|
||||||
struct aiVector3D scene_min, scene_max, scene_center;
|
struct aiVector3D scene_min, scene_max, scene_center;
|
||||||
|
|
||||||
/* current rotation angle */
|
/* current rotation angle */
|
||||||
static float angle = 0.f;
|
static float angle = 0.f;
|
||||||
|
|
||||||
#define aisgl_min(x,y) (x<y?x:y)
|
#define aisgl_min(x,y) (x<y?x:y)
|
||||||
#define aisgl_max(x,y) (y>x?y:x)
|
#define aisgl_max(x,y) (y>x?y:x)
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void reshape(int width, int height)
|
void reshape(int width, int height)
|
||||||
{
|
{
|
||||||
const double aspectRatio = (float) width / height, fieldOfView = 45.0;
|
const double aspectRatio = (float) width / height, fieldOfView = 45.0;
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(fieldOfView, aspectRatio,
|
gluPerspective(fieldOfView, aspectRatio,
|
||||||
1.0, 1000.0); /* Znear and Zfar */
|
1.0, 1000.0); /* Znear and Zfar */
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void get_bounding_box_for_node (const struct aiNode* nd,
|
void get_bounding_box_for_node (const struct aiNode* nd,
|
||||||
struct aiVector3D* min,
|
struct aiVector3D* min,
|
||||||
struct aiVector3D* max,
|
struct aiVector3D* max,
|
||||||
struct aiMatrix4x4* trafo
|
struct aiMatrix4x4* trafo
|
||||||
){
|
){
|
||||||
struct aiMatrix4x4 prev;
|
struct aiMatrix4x4 prev;
|
||||||
unsigned int n = 0, t;
|
unsigned int n = 0, t;
|
||||||
|
|
||||||
prev = *trafo;
|
prev = *trafo;
|
||||||
aiMultiplyMatrix4(trafo,&nd->mTransformation);
|
aiMultiplyMatrix4(trafo,&nd->mTransformation);
|
||||||
|
|
||||||
for (; n < nd->mNumMeshes; ++n) {
|
for (; n < nd->mNumMeshes; ++n) {
|
||||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||||
for (t = 0; t < mesh->mNumVertices; ++t) {
|
for (t = 0; t < mesh->mNumVertices; ++t) {
|
||||||
|
|
||||||
struct aiVector3D tmp = mesh->mVertices[t];
|
struct aiVector3D tmp = mesh->mVertices[t];
|
||||||
aiTransformVecByMatrix4(&tmp,trafo);
|
aiTransformVecByMatrix4(&tmp,trafo);
|
||||||
|
|
||||||
min->x = aisgl_min(min->x,tmp.x);
|
min->x = aisgl_min(min->x,tmp.x);
|
||||||
min->y = aisgl_min(min->y,tmp.y);
|
min->y = aisgl_min(min->y,tmp.y);
|
||||||
min->z = aisgl_min(min->z,tmp.z);
|
min->z = aisgl_min(min->z,tmp.z);
|
||||||
|
|
||||||
max->x = aisgl_max(max->x,tmp.x);
|
max->x = aisgl_max(max->x,tmp.x);
|
||||||
max->y = aisgl_max(max->y,tmp.y);
|
max->y = aisgl_max(max->y,tmp.y);
|
||||||
max->z = aisgl_max(max->z,tmp.z);
|
max->z = aisgl_max(max->z,tmp.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||||
get_bounding_box_for_node(nd->mChildren[n],min,max,trafo);
|
get_bounding_box_for_node(nd->mChildren[n],min,max,trafo);
|
||||||
}
|
}
|
||||||
*trafo = prev;
|
*trafo = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void get_bounding_box (struct aiVector3D* min, struct aiVector3D* max)
|
void get_bounding_box (struct aiVector3D* min, struct aiVector3D* max)
|
||||||
{
|
{
|
||||||
struct aiMatrix4x4 trafo;
|
struct aiMatrix4x4 trafo;
|
||||||
aiIdentityMatrix4(&trafo);
|
aiIdentityMatrix4(&trafo);
|
||||||
|
|
||||||
min->x = min->y = min->z = 1e10f;
|
min->x = min->y = min->z = 1e10f;
|
||||||
max->x = max->y = max->z = -1e10f;
|
max->x = max->y = max->z = -1e10f;
|
||||||
get_bounding_box_for_node(scene->mRootNode,min,max,&trafo);
|
get_bounding_box_for_node(scene->mRootNode,min,max,&trafo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void color4_to_float4(const struct aiColor4D *c, float f[4])
|
void color4_to_float4(const struct aiColor4D *c, float f[4])
|
||||||
{
|
{
|
||||||
f[0] = c->r;
|
f[0] = c->r;
|
||||||
f[1] = c->g;
|
f[1] = c->g;
|
||||||
f[2] = c->b;
|
f[2] = c->b;
|
||||||
f[3] = c->a;
|
f[3] = c->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void set_float4(float f[4], float a, float b, float c, float d)
|
void set_float4(float f[4], float a, float b, float c, float d)
|
||||||
{
|
{
|
||||||
f[0] = a;
|
f[0] = a;
|
||||||
f[1] = b;
|
f[1] = b;
|
||||||
f[2] = c;
|
f[2] = c;
|
||||||
f[3] = d;
|
f[3] = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void apply_material(const struct aiMaterial *mtl)
|
void apply_material(const struct aiMaterial *mtl)
|
||||||
{
|
{
|
||||||
float c[4];
|
float c[4];
|
||||||
|
|
||||||
GLenum fill_mode;
|
GLenum fill_mode;
|
||||||
int ret1, ret2;
|
int ret1, ret2;
|
||||||
struct aiColor4D diffuse;
|
struct aiColor4D diffuse;
|
||||||
struct aiColor4D specular;
|
struct aiColor4D specular;
|
||||||
struct aiColor4D ambient;
|
struct aiColor4D ambient;
|
||||||
struct aiColor4D emission;
|
struct aiColor4D emission;
|
||||||
float shininess, strength;
|
float shininess, strength;
|
||||||
int two_sided;
|
int two_sided;
|
||||||
int wireframe;
|
int wireframe;
|
||||||
unsigned int max;
|
unsigned int max;
|
||||||
|
|
||||||
set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
|
set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
|
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
|
||||||
color4_to_float4(&diffuse, c);
|
color4_to_float4(&diffuse, c);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
|
||||||
|
|
||||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
|
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
|
||||||
color4_to_float4(&specular, c);
|
color4_to_float4(&specular, c);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||||
|
|
||||||
set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
|
set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
|
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
|
||||||
color4_to_float4(&ambient, c);
|
color4_to_float4(&ambient, c);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
|
||||||
|
|
||||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
|
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
|
||||||
color4_to_float4(&emission, c);
|
color4_to_float4(&emission, c);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
|
||||||
|
|
||||||
max = 1;
|
max = 1;
|
||||||
ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
|
ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
|
||||||
if(ret1 == AI_SUCCESS) {
|
if(ret1 == AI_SUCCESS) {
|
||||||
max = 1;
|
max = 1;
|
||||||
ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
||||||
if(ret2 == AI_SUCCESS)
|
if(ret2 == AI_SUCCESS)
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
|
||||||
else
|
else
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
|
||||||
set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
|
set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
max = 1;
|
max = 1;
|
||||||
if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
|
if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
|
||||||
fill_mode = wireframe ? GL_LINE : GL_FILL;
|
fill_mode = wireframe ? GL_LINE : GL_FILL;
|
||||||
else
|
else
|
||||||
fill_mode = GL_FILL;
|
fill_mode = GL_FILL;
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
|
glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
|
||||||
|
|
||||||
max = 1;
|
max = 1;
|
||||||
if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
|
if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
else
|
else
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
|
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int n = 0, t;
|
unsigned int n = 0, t;
|
||||||
struct aiMatrix4x4 m = nd->mTransformation;
|
struct aiMatrix4x4 m = nd->mTransformation;
|
||||||
|
|
||||||
/* update transform */
|
/* update transform */
|
||||||
aiTransposeMatrix4(&m);
|
aiTransposeMatrix4(&m);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glMultMatrixf((float*)&m);
|
glMultMatrixf((float*)&m);
|
||||||
|
|
||||||
/* draw all meshes assigned to this node */
|
/* draw all meshes assigned to this node */
|
||||||
for (; n < nd->mNumMeshes; ++n) {
|
for (; n < nd->mNumMeshes; ++n) {
|
||||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||||
|
|
||||||
apply_material(sc->mMaterials[mesh->mMaterialIndex]);
|
apply_material(sc->mMaterials[mesh->mMaterialIndex]);
|
||||||
|
|
||||||
if(mesh->mNormals == NULL) {
|
if(mesh->mNormals == NULL) {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
} else {
|
} else {
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (t = 0; t < mesh->mNumFaces; ++t) {
|
for (t = 0; t < mesh->mNumFaces; ++t) {
|
||||||
const struct aiFace* face = &mesh->mFaces[t];
|
const struct aiFace* face = &mesh->mFaces[t];
|
||||||
GLenum face_mode;
|
GLenum face_mode;
|
||||||
|
|
||||||
switch(face->mNumIndices) {
|
switch(face->mNumIndices) {
|
||||||
case 1: face_mode = GL_POINTS; break;
|
case 1: face_mode = GL_POINTS; break;
|
||||||
case 2: face_mode = GL_LINES; break;
|
case 2: face_mode = GL_LINES; break;
|
||||||
case 3: face_mode = GL_TRIANGLES; break;
|
case 3: face_mode = GL_TRIANGLES; break;
|
||||||
default: face_mode = GL_POLYGON; break;
|
default: face_mode = GL_POLYGON; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBegin(face_mode);
|
glBegin(face_mode);
|
||||||
|
|
||||||
for(i = 0; i < face->mNumIndices; i++) {
|
for(i = 0; i < face->mNumIndices; i++) {
|
||||||
int index = face->mIndices[i];
|
int index = face->mIndices[i];
|
||||||
if(mesh->mColors[0] != NULL)
|
if(mesh->mColors[0] != NULL)
|
||||||
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
|
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
|
||||||
if(mesh->mNormals != NULL)
|
if(mesh->mNormals != NULL)
|
||||||
glNormal3fv(&mesh->mNormals[index].x);
|
glNormal3fv(&mesh->mNormals[index].x);
|
||||||
glVertex3fv(&mesh->mVertices[index].x);
|
glVertex3fv(&mesh->mVertices[index].x);
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw all children */
|
/* draw all children */
|
||||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||||
recursive_render(sc, nd->mChildren[n]);
|
recursive_render(sc, nd->mChildren[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void do_motion (void)
|
void do_motion (void)
|
||||||
{
|
{
|
||||||
static GLint prev_time = 0;
|
static GLint prev_time = 0;
|
||||||
static GLint prev_fps_time = 0;
|
static GLint prev_fps_time = 0;
|
||||||
static int frames = 0;
|
static int frames = 0;
|
||||||
|
|
||||||
int time = glutGet(GLUT_ELAPSED_TIME);
|
int time = glutGet(GLUT_ELAPSED_TIME);
|
||||||
angle += (time-prev_time)*0.01;
|
angle += (time-prev_time)*0.01;
|
||||||
prev_time = time;
|
prev_time = time;
|
||||||
|
|
||||||
frames += 1;
|
frames += 1;
|
||||||
if ((time - prev_fps_time) > 1000) /* update every seconds */
|
if ((time - prev_fps_time) > 1000) /* update every seconds */
|
||||||
{
|
{
|
||||||
int current_fps = frames * 1000 / (time - prev_fps_time);
|
int current_fps = frames * 1000 / (time - prev_fps_time);
|
||||||
printf("%d fps\n", current_fps);
|
printf("%d fps\n", current_fps);
|
||||||
frames = 0;
|
frames = 0;
|
||||||
prev_fps_time = time;
|
prev_fps_time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glutPostRedisplay ();
|
glutPostRedisplay ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
void display(void)
|
void display(void)
|
||||||
{
|
{
|
||||||
float tmp;
|
float tmp;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);
|
gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);
|
||||||
|
|
||||||
/* rotate it around the y axis */
|
/* rotate it around the y axis */
|
||||||
glRotatef(angle,0.f,1.f,0.f);
|
glRotatef(angle,0.f,1.f,0.f);
|
||||||
|
|
||||||
/* scale the whole asset to fit into our view frustum */
|
/* scale the whole asset to fit into our view frustum */
|
||||||
tmp = scene_max.x-scene_min.x;
|
tmp = scene_max.x-scene_min.x;
|
||||||
tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
|
tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
|
||||||
tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
|
tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
|
||||||
tmp = 1.f / tmp;
|
tmp = 1.f / tmp;
|
||||||
glScalef(tmp, tmp, tmp);
|
glScalef(tmp, tmp, tmp);
|
||||||
|
|
||||||
/* center the model */
|
/* center the model */
|
||||||
glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
|
glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
|
||||||
|
|
||||||
/* if the display list has not been made yet, create a new one and
|
/* if the display list has not been made yet, create a new one and
|
||||||
fill it with scene contents */
|
fill it with scene contents */
|
||||||
if(scene_list == 0) {
|
if(scene_list == 0) {
|
||||||
scene_list = glGenLists(1);
|
scene_list = glGenLists(1);
|
||||||
glNewList(scene_list, GL_COMPILE);
|
glNewList(scene_list, GL_COMPILE);
|
||||||
/* now begin at the root node of the imported data and traverse
|
/* now begin at the root node of the imported data and traverse
|
||||||
the scenegraph by multiplying subsequent local transforms
|
the scenegraph by multiplying subsequent local transforms
|
||||||
together on GL's matrix stack. */
|
together on GL's matrix stack. */
|
||||||
recursive_render(scene, scene->mRootNode);
|
recursive_render(scene, scene->mRootNode);
|
||||||
glEndList();
|
glEndList();
|
||||||
}
|
}
|
||||||
|
|
||||||
glCallList(scene_list);
|
glCallList(scene_list);
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
do_motion();
|
do_motion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
int loadasset (const char* path)
|
int loadasset (const char* path)
|
||||||
{
|
{
|
||||||
/* we are taking one of the postprocessing presets to avoid
|
/* we are taking one of the postprocessing presets to avoid
|
||||||
spelling out 20+ single postprocessing flags here. */
|
spelling out 20+ single postprocessing flags here. */
|
||||||
scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);
|
scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);
|
||||||
|
|
||||||
if (scene) {
|
if (scene) {
|
||||||
get_bounding_box(&scene_min,&scene_max);
|
get_bounding_box(&scene_min,&scene_max);
|
||||||
scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
|
scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
|
||||||
scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
|
scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
|
||||||
scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
|
scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct aiLogStream stream;
|
struct aiLogStream stream;
|
||||||
|
|
||||||
glutInitWindowSize(900,600);
|
glutInitWindowSize(900,600);
|
||||||
glutInitWindowPosition(100,100);
|
glutInitWindowPosition(100,100);
|
||||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
|
|
||||||
glutCreateWindow("Assimp - Very simple OpenGL sample");
|
glutCreateWindow("Assimp - Very simple OpenGL sample");
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutReshapeFunc(reshape);
|
glutReshapeFunc(reshape);
|
||||||
|
|
||||||
/* get a handle to the predefined STDOUT log stream and attach
|
/* get a handle to the predefined STDOUT log stream and attach
|
||||||
it to the logging system. It remains active for all further
|
it to the logging system. It remains active for all further
|
||||||
calls to aiImportFile(Ex) and aiApplyPostProcessing. */
|
calls to aiImportFile(Ex) and aiApplyPostProcessing. */
|
||||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
|
stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
|
||||||
aiAttachLogStream(&stream);
|
aiAttachLogStream(&stream);
|
||||||
|
|
||||||
/* ... same procedure, but this stream now writes the
|
/* ... same procedure, but this stream now writes the
|
||||||
log messages to assimp_log.txt */
|
log messages to assimp_log.txt */
|
||||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
|
stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
|
||||||
aiAttachLogStream(&stream);
|
aiAttachLogStream(&stream);
|
||||||
|
|
||||||
/* the model name can be specified on the command line. If none
|
/* the model name can be specified on the command line. If none
|
||||||
is specified, we try to locate one of the more expressive test
|
is specified, we try to locate one of the more expressive test
|
||||||
models from the repository (/models-nonbsd may be missing in
|
models from the repository (/models-nonbsd may be missing in
|
||||||
some distributions so we need a fallback from /models!). */
|
some distributions so we need a fallback from /models!). */
|
||||||
if( 0 != loadasset( argc >= 2 ? argv[1] : "../../test/models-nonbsd/X/dwarf.x")) {
|
if( 0 != loadasset( argc >= 2 ? argv[1] : "../../test/models-nonbsd/X/dwarf.x")) {
|
||||||
if( argc != 1 || (0 != loadasset( "../../../../test/models-nonbsd/X/dwarf.x") && 0 != loadasset( "../../test/models/X/Testwuson.X"))) {
|
if( argc != 1 || (0 != loadasset( "../../../../test/models-nonbsd/X/dwarf.x") && 0 != loadasset( "../../test/models/X/Testwuson.X"))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glClearColor(0.1f,0.1f,0.1f,1.f);
|
glClearColor(0.1f,0.1f,0.1f,1.f);
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0); /* Uses default lighting parameters */
|
glEnable(GL_LIGHT0); /* Uses default lighting parameters */
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
|
|
||||||
/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
|
/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
|
||||||
if(getenv("MODEL_IS_BROKEN"))
|
if(getenv("MODEL_IS_BROKEN"))
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
||||||
|
|
||||||
glutGet(GLUT_ELAPSED_TIME);
|
glutGet(GLUT_ELAPSED_TIME);
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
||||||
keeps internal resources until the scene is freed again. Not
|
keeps internal resources until the scene is freed again. Not
|
||||||
doing so can cause severe resource leaking. */
|
doing so can cause severe resource leaking. */
|
||||||
aiReleaseImport(scene);
|
aiReleaseImport(scene);
|
||||||
|
|
||||||
/* We added a log stream to the library, it's our job to disable it
|
/* We added a log stream to the library, it's our job to disable it
|
||||||
again. This will definitely release the last resources allocated
|
again. This will definitely release the last resources allocated
|
||||||
by Assimp.*/
|
by Assimp.*/
|
||||||
aiDetachAllLogStreams();
|
aiDetachAllLogStreams();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,111 +1,111 @@
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# List of IFC structures needed by Assimp
|
# List of IFC structures needed by Assimp
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# use genentitylist.sh to update this list
|
# use genentitylist.sh to update this list
|
||||||
|
|
||||||
# This machine-generated list is not complete, it lacks many intermediate
|
# This machine-generated list is not complete, it lacks many intermediate
|
||||||
# classes in the inheritance hierarchy. Those are magically augmented by the
|
# classes in the inheritance hierarchy. Those are magically augmented by the
|
||||||
# code generator. Also, the names of all used entities need to be present
|
# code generator. Also, the names of all used entities need to be present
|
||||||
# in the source code for this to work.
|
# in the source code for this to work.
|
||||||
|
|
||||||
IfcAnnotation
|
IfcAnnotation
|
||||||
IfcArbitraryClosedProfileDef
|
IfcArbitraryClosedProfileDef
|
||||||
IfcArbitraryOpenProfileDef
|
IfcArbitraryOpenProfileDef
|
||||||
IfcArbitraryProfileDefWithVoids
|
IfcArbitraryProfileDefWithVoids
|
||||||
IfcAxis1Placement
|
IfcAxis1Placement
|
||||||
IfcAxis2Placement
|
IfcAxis2Placement
|
||||||
IfcAxis2Placement2D
|
IfcAxis2Placement2D
|
||||||
IfcAxis2Placement3D
|
IfcAxis2Placement3D
|
||||||
IfcBooleanClippingResult
|
IfcBooleanClippingResult
|
||||||
IfcBooleanResult
|
IfcBooleanResult
|
||||||
IfcBoundedCurve
|
IfcBoundedCurve
|
||||||
IfcBoundingBox
|
IfcBoundingBox
|
||||||
IfcBSplineCurve
|
IfcBSplineCurve
|
||||||
IfcBuilding
|
IfcBuilding
|
||||||
IfcCartesianPoint
|
IfcCartesianPoint
|
||||||
IfcCartesianTransformationOperator
|
IfcCartesianTransformationOperator
|
||||||
IfcCartesianTransformationOperator3D
|
IfcCartesianTransformationOperator3D
|
||||||
IfcCartesianTransformationOperator3DnonUniform
|
IfcCartesianTransformationOperator3DnonUniform
|
||||||
IfcCircle
|
IfcCircle
|
||||||
IfcCircleHollowProfileDef
|
IfcCircleHollowProfileDef
|
||||||
IfcCircleProfileDef
|
IfcCircleProfileDef
|
||||||
IfcClosedShell
|
IfcClosedShell
|
||||||
IfcColourOrFactor
|
IfcColourOrFactor
|
||||||
IfcColourRgb
|
IfcColourRgb
|
||||||
IfcCompositeCurve
|
IfcCompositeCurve
|
||||||
IfcCompositeCurveSegment
|
IfcCompositeCurveSegment
|
||||||
IfcConic
|
IfcConic
|
||||||
IfcConnectedFaceSet
|
IfcConnectedFaceSet
|
||||||
IfcConversionBasedUnit
|
IfcConversionBasedUnit
|
||||||
IfcCurve
|
IfcCurve
|
||||||
IfcDirection
|
IfcDirection
|
||||||
IfcDoor
|
IfcDoor
|
||||||
IfcEllipse
|
IfcEllipse
|
||||||
IfcExtrudedAreaSolid
|
IfcExtrudedAreaSolid
|
||||||
IfcFace
|
IfcFace
|
||||||
IfcFaceBasedSurfaceModel
|
IfcFaceBasedSurfaceModel
|
||||||
IfcFaceBound
|
IfcFaceBound
|
||||||
IfcFaceOuterBound
|
IfcFaceOuterBound
|
||||||
IfcFeatureElementSubtraction
|
IfcFeatureElementSubtraction
|
||||||
IfcGeometricRepresentationContext
|
IfcGeometricRepresentationContext
|
||||||
IfcGeometricRepresentationItem
|
IfcGeometricRepresentationItem
|
||||||
IfcHalfSpaceSolid
|
IfcHalfSpaceSolid
|
||||||
IfcLine
|
IfcLine
|
||||||
IfcLocalPlacement
|
IfcLocalPlacement
|
||||||
IfcManifoldSolidBrep
|
IfcManifoldSolidBrep
|
||||||
IfcMappedItem
|
IfcMappedItem
|
||||||
IfcMeasureWithUnit
|
IfcMeasureWithUnit
|
||||||
IfcNamedUnit
|
IfcNamedUnit
|
||||||
IfcObjectDefinition
|
IfcObjectDefinition
|
||||||
IfcObjectPlacement
|
IfcObjectPlacement
|
||||||
IfcOpeningElement
|
IfcOpeningElement
|
||||||
IfcParameterizedProfileDef
|
IfcParameterizedProfileDef
|
||||||
IfcPlane
|
IfcPlane
|
||||||
IfcPolygonalBoundedHalfSpace
|
IfcPolygonalBoundedHalfSpace
|
||||||
IfcPolyline
|
IfcPolyline
|
||||||
IfcPolyLoop
|
IfcPolyLoop
|
||||||
IfcPresentationStyleAssignment
|
IfcPresentationStyleAssignment
|
||||||
IfcPresentationStyleSelect
|
IfcPresentationStyleSelect
|
||||||
IfcProduct
|
IfcProduct
|
||||||
IfcProductRepresentation
|
IfcProductRepresentation
|
||||||
IfcProfileDef
|
IfcProfileDef
|
||||||
IfcProject
|
IfcProject
|
||||||
IfcRectangleProfileDef
|
IfcRectangleProfileDef
|
||||||
IfcRelAggregates
|
IfcRelAggregates
|
||||||
IfcRelContainedInSpatialStructure
|
IfcRelContainedInSpatialStructure
|
||||||
IfcRelFillsElement
|
IfcRelFillsElement
|
||||||
IfcRelVoidsElement
|
IfcRelVoidsElement
|
||||||
IfcRepresentation
|
IfcRepresentation
|
||||||
IfcRepresentationContext
|
IfcRepresentationContext
|
||||||
IfcRepresentationItem
|
IfcRepresentationItem
|
||||||
IfcRepresentationMap
|
IfcRepresentationMap
|
||||||
IfcRevolvedAreaSolid
|
IfcRevolvedAreaSolid
|
||||||
IfcShell
|
IfcShell
|
||||||
IfcShellBasedSurfaceModel
|
IfcShellBasedSurfaceModel
|
||||||
IfcSite
|
IfcSite
|
||||||
IfcSIUnit
|
IfcSIUnit
|
||||||
IfcSomething
|
IfcSomething
|
||||||
IfcSpace
|
IfcSpace
|
||||||
IfcSpatialStructureElement
|
IfcSpatialStructureElement
|
||||||
IfcSpatialStructureElements
|
IfcSpatialStructureElements
|
||||||
IfcStyledItem
|
IfcStyledItem
|
||||||
IfcSurfaceStyle
|
IfcSurfaceStyle
|
||||||
IfcSurfaceStyleElementSelect
|
IfcSurfaceStyleElementSelect
|
||||||
IfcSurfaceStyleRendering
|
IfcSurfaceStyleRendering
|
||||||
IfcSurfaceStyleShading
|
IfcSurfaceStyleShading
|
||||||
IfcSurfaceStyleWithTextures
|
IfcSurfaceStyleWithTextures
|
||||||
IfcSweptAreaSolid
|
IfcSweptAreaSolid
|
||||||
IfcSweptDiskSolid
|
IfcSweptDiskSolid
|
||||||
IfcTopologicalRepresentationItem
|
IfcTopologicalRepresentationItem
|
||||||
IfcTrimmedCurve
|
IfcTrimmedCurve
|
||||||
IfcUnit
|
IfcUnit
|
||||||
IfcUnitAssignment
|
IfcUnitAssignment
|
||||||
IfcVector
|
IfcVector
|
||||||
IfcIShapeProfileDef
|
IfcIShapeProfileDef
|
||||||
IfcPropertyListValue
|
IfcPropertyListValue
|
||||||
IfcRelDefinesByProperties
|
IfcRelDefinesByProperties
|
||||||
IfcPropertySet
|
IfcPropertySet
|
||||||
IfcPropertySingleValue
|
IfcPropertySingleValue
|
||||||
IfcProperty
|
IfcProperty
|
||||||
IfcComplexProperty
|
IfcComplexProperty
|
||||||
IfcElementQuantity
|
IfcElementQuantity
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "self:Assimp.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "0700"
|
||||||
|
version = "1.3">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "7F79227F1AB43AC3005A8E5D"
|
||||||
|
BuildableName = "libassimp.a"
|
||||||
|
BlueprintName = "assimp"
|
||||||
|
ReferencedContainer = "container:workspaces/xcode6/Assimp.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
|
<Testables>
|
||||||
|
</Testables>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "7F79227F1AB43AC3005A8E5D"
|
||||||
|
BuildableName = "libassimp.a"
|
||||||
|
BlueprintName = "assimp"
|
||||||
|
ReferencedContainer = "container:workspaces/xcode6/Assimp.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "7F79227F1AB43AC3005A8E5D"
|
||||||
|
BuildableName = "libassimp.a"
|
||||||
|
BlueprintName = "assimp"
|
||||||
|
ReferencedContainer = "container:workspaces/xcode6/Assimp.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
Loading…
Reference in New Issue