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.
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
#ifndef AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
#define AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
|
||||
#if (!defined BOOST_FORMAT_HPP) || (defined ASSIMP_FORCE_NOBOOST)
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
class format
|
||||
{
|
||||
public:
|
||||
format (const std::string& _d)
|
||||
: d(_d)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
format& operator % (T in)
|
||||
{
|
||||
// XXX add replacement for boost::lexical_cast?
|
||||
|
||||
std::ostringstream ss;
|
||||
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());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
operator std::string () const {
|
||||
std::string res; // pray for NRVO to kick in
|
||||
|
||||
size_t start = 0, last = 0;
|
||||
|
||||
std::vector<std::string>::const_iterator chunkin = chunks.begin();
|
||||
|
||||
for ( start = d.find('%');start != std::string::npos; start = d.find('%',last)) {
|
||||
res += d.substr(last,start-last);
|
||||
last = start+2;
|
||||
if (d[start+1] == '%') {
|
||||
res += "%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chunkin == chunks.end()) {
|
||||
break;
|
||||
}
|
||||
|
||||
res += *chunkin++;
|
||||
}
|
||||
res += d.substr(last);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string d;
|
||||
std::vector<std::string> chunks;
|
||||
};
|
||||
|
||||
inline std::string str(const std::string& s) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
# error "format.h was already included"
|
||||
#endif //
|
||||
#endif // !! AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
|
||||
|
||||
|
||||
|
||||
/* DEPRECATED! - use code/TinyFormatter.h instead.
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
#ifndef AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
#define AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
|
||||
#if (!defined BOOST_FORMAT_HPP) || (defined ASSIMP_FORCE_NOBOOST)
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
class format
|
||||
{
|
||||
public:
|
||||
format (const std::string& _d)
|
||||
: d(_d)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
format& operator % (T in)
|
||||
{
|
||||
// XXX add replacement for boost::lexical_cast?
|
||||
|
||||
std::ostringstream ss;
|
||||
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());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
operator std::string () const {
|
||||
std::string res; // pray for NRVO to kick in
|
||||
|
||||
size_t start = 0, last = 0;
|
||||
|
||||
std::vector<std::string>::const_iterator chunkin = chunks.begin();
|
||||
|
||||
for ( start = d.find('%');start != std::string::npos; start = d.find('%',last)) {
|
||||
res += d.substr(last,start-last);
|
||||
last = start+2;
|
||||
if (d[start+1] == '%') {
|
||||
res += "%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chunkin == chunks.end()) {
|
||||
break;
|
||||
}
|
||||
|
||||
res += *chunkin++;
|
||||
}
|
||||
res += d.substr(last);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string d;
|
||||
std::vector<std::string> chunks;
|
||||
};
|
||||
|
||||
inline std::string str(const std::string& s) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
# error "format.h was already included"
|
||||
#endif //
|
||||
#endif // !! AI_BOOST_FORMAT_DUMMY_INCLUDED
|
||||
|
||||
|
|
|
@ -1,260 +1,260 @@
|
|||
|
||||
#ifndef INCLUDED_AI_BOOST_SHARED_PTR
|
||||
#define INCLUDED_AI_BOOST_SHARED_PTR
|
||||
|
||||
#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
|
||||
|
||||
// ------------------------------
|
||||
// Internal stub
|
||||
|
||||
#include <stddef.h> //NULL
|
||||
#include <algorithm> //std::swap
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
class controller {
|
||||
public:
|
||||
|
||||
controller()
|
||||
: cnt(1)
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
controller* decref(T* pt) {
|
||||
if (--cnt <= 0) {
|
||||
delete this;
|
||||
delete pt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
controller* incref() {
|
||||
++cnt;
|
||||
return this;
|
||||
}
|
||||
|
||||
long get() const {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
private:
|
||||
long cnt;
|
||||
};
|
||||
|
||||
struct empty {};
|
||||
|
||||
template <typename DEST, typename SRC>
|
||||
struct is_convertible_stub {
|
||||
|
||||
struct yes {char s[1];};
|
||||
struct no {char s[2];};
|
||||
|
||||
static yes foo(DEST*);
|
||||
static no foo(...);
|
||||
|
||||
enum {result = (sizeof(foo((SRC*)0)) == sizeof(yes) ? 1 : 0)};
|
||||
};
|
||||
|
||||
template <bool> struct enable_if {};
|
||||
template <> struct enable_if<true> {
|
||||
typedef empty result;
|
||||
};
|
||||
|
||||
template <typename DEST, typename SRC>
|
||||
struct is_convertible : public enable_if<is_convertible_stub<DEST,SRC>::result > {
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Small replacement for boost::shared_ptr, not threadsafe because no
|
||||
// atomic reference counter is in use.
|
||||
// ------------------------------
|
||||
template <class T>
|
||||
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> 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> 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:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
public:
|
||||
|
||||
// provide a default constructor
|
||||
shared_ptr()
|
||||
: ptr()
|
||||
, ctr(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
// construction from an existing object of type T
|
||||
explicit shared_ptr(T* ptr)
|
||||
: ptr(ptr)
|
||||
, ctr(ptr ? new detail::controller() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr(const shared_ptr& r)
|
||||
: ptr(r.ptr)
|
||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Y>
|
||||
shared_ptr(const shared_ptr<Y>& r,typename detail::is_convertible<T,Y>::result = detail::empty())
|
||||
: ptr(r.ptr)
|
||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
// automatic destruction of the wrapped object when all
|
||||
// references are freed.
|
||||
~shared_ptr() {
|
||||
if (ctr) {
|
||||
ctr = ctr->decref(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr& operator=(const shared_ptr& r) {
|
||||
if (this == &r) {
|
||||
return *this;
|
||||
}
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = r.ptr;
|
||||
ctr = ptr?r.ctr->incref():NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Y>
|
||||
shared_ptr& operator=(const shared_ptr<Y>& r) {
|
||||
if (this == &r) {
|
||||
return *this;
|
||||
}
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = r.ptr;
|
||||
ctr = ptr?r.ctr->incref():NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// pointer access
|
||||
inline operator T*() const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline T* operator-> () const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// standard semantics
|
||||
inline T* get() {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline const T* get() const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline operator bool () const {
|
||||
return ptr != NULL;
|
||||
}
|
||||
|
||||
inline bool unique() const {
|
||||
return use_count() == 1;
|
||||
}
|
||||
|
||||
inline long use_count() const {
|
||||
return ctr->get();
|
||||
}
|
||||
|
||||
inline void reset (T* t = 0) {
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = t;
|
||||
ctr = ptr?new detail::controller():NULL;
|
||||
}
|
||||
|
||||
void swap(shared_ptr & b) {
|
||||
std::swap(ptr, b.ptr);
|
||||
std::swap(ctr, b.ctr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// for use by the various xxx_pointer_cast helper templates
|
||||
explicit shared_ptr(T* ptr, detail::controller* ctr)
|
||||
: ptr(ptr)
|
||||
, ctr(ctr->incref())
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// encapsulated object pointer
|
||||
T* ptr;
|
||||
|
||||
// control block
|
||||
detail::controller* ctr;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool operator== (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr == b.ptr;
|
||||
}
|
||||
template<class T>
|
||||
bool operator!= (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr != b.ptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool operator< (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr < b.ptr;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> static_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(static_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(dynamic_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> const_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(const_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end of namespace boost
|
||||
|
||||
#else
|
||||
# error "shared_ptr.h was already included"
|
||||
#endif
|
||||
#endif // INCLUDED_AI_BOOST_SHARED_PTR
|
||||
|
||||
#ifndef INCLUDED_AI_BOOST_SHARED_PTR
|
||||
#define INCLUDED_AI_BOOST_SHARED_PTR
|
||||
|
||||
#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
|
||||
|
||||
// ------------------------------
|
||||
// Internal stub
|
||||
|
||||
#include <stddef.h> //NULL
|
||||
#include <algorithm> //std::swap
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
class controller {
|
||||
public:
|
||||
|
||||
controller()
|
||||
: cnt(1)
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
controller* decref(T* pt) {
|
||||
if (--cnt <= 0) {
|
||||
delete this;
|
||||
delete pt;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
controller* incref() {
|
||||
++cnt;
|
||||
return this;
|
||||
}
|
||||
|
||||
long get() const {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
private:
|
||||
long cnt;
|
||||
};
|
||||
|
||||
struct empty {};
|
||||
|
||||
template <typename DEST, typename SRC>
|
||||
struct is_convertible_stub {
|
||||
|
||||
struct yes {char s[1];};
|
||||
struct no {char s[2];};
|
||||
|
||||
static yes foo(DEST*);
|
||||
static no foo(...);
|
||||
|
||||
enum {result = (sizeof(foo((SRC*)0)) == sizeof(yes) ? 1 : 0)};
|
||||
};
|
||||
|
||||
template <bool> struct enable_if {};
|
||||
template <> struct enable_if<true> {
|
||||
typedef empty result;
|
||||
};
|
||||
|
||||
template <typename DEST, typename SRC>
|
||||
struct is_convertible : public enable_if<is_convertible_stub<DEST,SRC>::result > {
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Small replacement for boost::shared_ptr, not threadsafe because no
|
||||
// atomic reference counter is in use.
|
||||
// ------------------------------
|
||||
template <class T>
|
||||
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> 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> 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:
|
||||
|
||||
typedef T element_type;
|
||||
|
||||
public:
|
||||
|
||||
// provide a default constructor
|
||||
shared_ptr()
|
||||
: ptr()
|
||||
, ctr(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
// construction from an existing object of type T
|
||||
explicit shared_ptr(T* ptr)
|
||||
: ptr(ptr)
|
||||
, ctr(ptr ? new detail::controller() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr(const shared_ptr& r)
|
||||
: ptr(r.ptr)
|
||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Y>
|
||||
shared_ptr(const shared_ptr<Y>& r,typename detail::is_convertible<T,Y>::result = detail::empty())
|
||||
: ptr(r.ptr)
|
||||
, ctr(r.ctr ? r.ctr->incref() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
// automatic destruction of the wrapped object when all
|
||||
// references are freed.
|
||||
~shared_ptr() {
|
||||
if (ctr) {
|
||||
ctr = ctr->decref(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr& operator=(const shared_ptr& r) {
|
||||
if (this == &r) {
|
||||
return *this;
|
||||
}
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = r.ptr;
|
||||
ctr = ptr?r.ctr->incref():NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Y>
|
||||
shared_ptr& operator=(const shared_ptr<Y>& r) {
|
||||
if (this == &r) {
|
||||
return *this;
|
||||
}
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = r.ptr;
|
||||
ctr = ptr?r.ctr->incref():NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// pointer access
|
||||
inline operator T*() const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline T* operator-> () const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// standard semantics
|
||||
inline T* get() {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline const T* get() const {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline operator bool () const {
|
||||
return ptr != NULL;
|
||||
}
|
||||
|
||||
inline bool unique() const {
|
||||
return use_count() == 1;
|
||||
}
|
||||
|
||||
inline long use_count() const {
|
||||
return ctr->get();
|
||||
}
|
||||
|
||||
inline void reset (T* t = 0) {
|
||||
if (ctr) {
|
||||
ctr->decref(ptr);
|
||||
}
|
||||
ptr = t;
|
||||
ctr = ptr?new detail::controller():NULL;
|
||||
}
|
||||
|
||||
void swap(shared_ptr & b) {
|
||||
std::swap(ptr, b.ptr);
|
||||
std::swap(ctr, b.ctr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// for use by the various xxx_pointer_cast helper templates
|
||||
explicit shared_ptr(T* ptr, detail::controller* ctr)
|
||||
: ptr(ptr)
|
||||
, ctr(ctr->incref())
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// encapsulated object pointer
|
||||
T* ptr;
|
||||
|
||||
// control block
|
||||
detail::controller* ctr;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool operator== (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr == b.ptr;
|
||||
}
|
||||
template<class T>
|
||||
bool operator!= (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr != b.ptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool operator< (const shared_ptr<T>& a, const shared_ptr<T>& b) {
|
||||
return a.ptr < b.ptr;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> static_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(static_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(dynamic_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline shared_ptr<T> const_pointer_cast( shared_ptr<U> ptr)
|
||||
{
|
||||
return shared_ptr<T>(const_cast<T*>(ptr.ptr),ptr.ctr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end of namespace boost
|
||||
|
||||
#else
|
||||
# error "shared_ptr.h was already included"
|
||||
#endif
|
||||
#endif // INCLUDED_AI_BOOST_SHARED_PTR
|
||||
|
|
|
@ -1,73 +1,73 @@
|
|||
// boost timer.hpp header file ---------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 1994-99. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/timer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
|
||||
// 12 Jan 01 Change to inline implementation to allow use without library
|
||||
// builds. See docs for more rationale. (Beman Dawes)
|
||||
// 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
|
||||
// 16 Jul 99 Second beta
|
||||
// 6 Jul 99 Initial boost version
|
||||
|
||||
#ifndef BOOST_TIMER_HPP
|
||||
#define BOOST_TIMER_HPP
|
||||
|
||||
//#include <boost/config.hpp>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
//#include <boost/limits.hpp>
|
||||
|
||||
# ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std { using ::clock_t; using ::clock; }
|
||||
# endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
// timer -------------------------------------------------------------------//
|
||||
|
||||
// A timer object measures elapsed time.
|
||||
|
||||
// It is recommended that implementations measure wall clock rather than CPU
|
||||
// time since the intended use is performance measurement on systems where
|
||||
// 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
|
||||
// due to implementation limitations. The accuracy of timings depends on the
|
||||
// accuracy of timing information provided by the underlying platform, and
|
||||
// this varies a great deal from platform to platform.
|
||||
|
||||
class timer
|
||||
{
|
||||
public:
|
||||
timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
|
||||
// timer( const timer& src ); // post: elapsed()==src.elapsed()
|
||||
// ~timer(){}
|
||||
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
|
||||
void restart() { _start_time = std::clock(); } // post: elapsed()==0
|
||||
double elapsed() const // return elapsed time in seconds
|
||||
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
|
||||
|
||||
double elapsed_max() const // return estimated maximum value for elapsed()
|
||||
// Portability warning: elapsed_max() may return too high a value on systems
|
||||
// where std::clock_t overflows or resets at surprising values.
|
||||
{
|
||||
return (double((std::numeric_limits<std::clock_t>::max)())
|
||||
- double(_start_time)) / double(CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
double elapsed_min() const // return minimum value for elapsed()
|
||||
{ return double(1)/double(CLOCKS_PER_SEC); }
|
||||
|
||||
private:
|
||||
std::clock_t _start_time;
|
||||
}; // timer
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_TIMER_HPP
|
||||
// boost timer.hpp header file ---------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 1994-99. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/timer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
|
||||
// 12 Jan 01 Change to inline implementation to allow use without library
|
||||
// builds. See docs for more rationale. (Beman Dawes)
|
||||
// 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
|
||||
// 16 Jul 99 Second beta
|
||||
// 6 Jul 99 Initial boost version
|
||||
|
||||
#ifndef BOOST_TIMER_HPP
|
||||
#define BOOST_TIMER_HPP
|
||||
|
||||
//#include <boost/config.hpp>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
//#include <boost/limits.hpp>
|
||||
|
||||
# ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std { using ::clock_t; using ::clock; }
|
||||
# endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
// timer -------------------------------------------------------------------//
|
||||
|
||||
// A timer object measures elapsed time.
|
||||
|
||||
// It is recommended that implementations measure wall clock rather than CPU
|
||||
// time since the intended use is performance measurement on systems where
|
||||
// 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
|
||||
// due to implementation limitations. The accuracy of timings depends on the
|
||||
// accuracy of timing information provided by the underlying platform, and
|
||||
// this varies a great deal from platform to platform.
|
||||
|
||||
class timer
|
||||
{
|
||||
public:
|
||||
timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
|
||||
// timer( const timer& src ); // post: elapsed()==src.elapsed()
|
||||
// ~timer(){}
|
||||
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
|
||||
void restart() { _start_time = std::clock(); } // post: elapsed()==0
|
||||
double elapsed() const // return elapsed time in seconds
|
||||
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
|
||||
|
||||
double elapsed_max() const // return estimated maximum value for elapsed()
|
||||
// Portability warning: elapsed_max() may return too high a value on systems
|
||||
// where std::clock_t overflows or resets at surprising values.
|
||||
{
|
||||
return (double((std::numeric_limits<std::clock_t>::max)())
|
||||
- double(_start_time)) / double(CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
double elapsed_min() const // return minimum value for elapsed()
|
||||
{ return double(1)/double(CLOCKS_PER_SEC); }
|
||||
|
||||
private:
|
||||
std::clock_t _start_time;
|
||||
}; // timer
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#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
|
||||
|
||||
#include <sstream>
|
||||
#include <stdarg.h>
|
||||
#include "ColladaParser.h"
|
||||
#include "fast_atof.h"
|
||||
#include "ParsingUtils.h"
|
||||
|
@ -1998,7 +1999,8 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
|
|||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
|
@ -2107,13 +2109,19 @@ size_t ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector<InputChannel>& pP
|
|||
}
|
||||
}
|
||||
|
||||
// complain if the index count doesn't fit
|
||||
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets)
|
||||
ThrowException( "Expected different index count in <p> element.");
|
||||
else if( expectedPointCount == 0 && (indices.size() % numOffsets) != 0)
|
||||
ThrowException( "Expected different index count in <p> element.");
|
||||
// complain if the index count doesn't fit
|
||||
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets) {
|
||||
if (pPrimType == Prim_Lines) {
|
||||
// HACK: We just fix this number since SketchUp 15.3.331 writes the wrong 'count' for 'lines'
|
||||
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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
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
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
/*
|
||||
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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
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
|
||||
|
@ -52,301 +52,302 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
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.
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
/** 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.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
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;
|
||||
void ReportWarning(const char* msg,...);
|
||||
|
||||
/** 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
|
||||
|
|
|
@ -1,151 +1,151 @@
|
|||
// Copyright (C) 2002-2005 Nikolaus Gebhardt
|
||||
// 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
|
||||
|
||||
// Need to include Assimp, too. We're using Assimp's version of fast_atof
|
||||
// so we need stdint.h. But no PCH.
|
||||
|
||||
|
||||
#include "irrXML.h"
|
||||
#include "irrString.h"
|
||||
#include "irrArray.h"
|
||||
#include "./../../code/fast_atof.h"
|
||||
#include "CXMLReaderImpl.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
//! Implementation of the file read callback for ordinary files
|
||||
class CFileReadCallBack : public IFileReadCallBack
|
||||
{
|
||||
public:
|
||||
|
||||
//! construct from filename
|
||||
CFileReadCallBack(const char* filename)
|
||||
: File(0), Size(0), Close(true)
|
||||
{
|
||||
// open file
|
||||
File = fopen(filename, "rb");
|
||||
|
||||
if (File)
|
||||
getFileSize();
|
||||
}
|
||||
|
||||
//! construct from FILE pointer
|
||||
CFileReadCallBack(FILE* file)
|
||||
: File(file), Size(0), Close(false)
|
||||
{
|
||||
if (File)
|
||||
getFileSize();
|
||||
}
|
||||
|
||||
//! destructor
|
||||
virtual ~CFileReadCallBack()
|
||||
{
|
||||
if (Close && File)
|
||||
fclose(File);
|
||||
}
|
||||
|
||||
//! Reads an amount of bytes from the file.
|
||||
virtual int read(void* buffer, int sizeToRead)
|
||||
{
|
||||
if (!File)
|
||||
return 0;
|
||||
|
||||
return (int)fread(buffer, 1, sizeToRead, File);
|
||||
}
|
||||
|
||||
//! Returns size of file in bytes
|
||||
virtual int getSize()
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//! retrieves the file size of the open file
|
||||
void getFileSize()
|
||||
{
|
||||
fseek(File, 0, SEEK_END);
|
||||
Size = ftell(File);
|
||||
fseek(File, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
FILE* File;
|
||||
int Size;
|
||||
bool Close;
|
||||
|
||||
}; // end class CFileReadCallBack
|
||||
|
||||
|
||||
|
||||
// FACTORY FUNCTIONS:
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
} // end namespace io
|
||||
} // end namespace irr
|
||||
// Copyright (C) 2002-2005 Nikolaus Gebhardt
|
||||
// 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
|
||||
|
||||
// Need to include Assimp, too. We're using Assimp's version of fast_atof
|
||||
// so we need stdint.h. But no PCH.
|
||||
|
||||
|
||||
#include "irrXML.h"
|
||||
#include "irrString.h"
|
||||
#include "irrArray.h"
|
||||
#include "./../../code/fast_atof.h"
|
||||
#include "CXMLReaderImpl.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
//! Implementation of the file read callback for ordinary files
|
||||
class CFileReadCallBack : public IFileReadCallBack
|
||||
{
|
||||
public:
|
||||
|
||||
//! construct from filename
|
||||
CFileReadCallBack(const char* filename)
|
||||
: File(0), Size(0), Close(true)
|
||||
{
|
||||
// open file
|
||||
File = fopen(filename, "rb");
|
||||
|
||||
if (File)
|
||||
getFileSize();
|
||||
}
|
||||
|
||||
//! construct from FILE pointer
|
||||
CFileReadCallBack(FILE* file)
|
||||
: File(file), Size(0), Close(false)
|
||||
{
|
||||
if (File)
|
||||
getFileSize();
|
||||
}
|
||||
|
||||
//! destructor
|
||||
virtual ~CFileReadCallBack()
|
||||
{
|
||||
if (Close && File)
|
||||
fclose(File);
|
||||
}
|
||||
|
||||
//! Reads an amount of bytes from the file.
|
||||
virtual int read(void* buffer, int sizeToRead)
|
||||
{
|
||||
if (!File)
|
||||
return 0;
|
||||
|
||||
return (int)fread(buffer, 1, sizeToRead, File);
|
||||
}
|
||||
|
||||
//! Returns size of file in bytes
|
||||
virtual int getSize()
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//! retrieves the file size of the open file
|
||||
void getFileSize()
|
||||
{
|
||||
fseek(File, 0, SEEK_END);
|
||||
Size = ftell(File);
|
||||
fseek(File, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
FILE* File;
|
||||
int Size;
|
||||
bool Close;
|
||||
|
||||
}; // end class CFileReadCallBack
|
||||
|
||||
|
||||
|
||||
// FACTORY FUNCTIONS:
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-16 xml parser.
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char16, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(filename));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(new CFileReadCallBack(file));
|
||||
}
|
||||
|
||||
|
||||
//! Creates an instance of an UTF-32 xml parser.
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback)
|
||||
{
|
||||
return new CXMLReaderImpl<char32, IXMLBase>(callback, false);
|
||||
}
|
||||
|
||||
|
||||
} // end namespace io
|
||||
} // end namespace irr
|
||||
|
|
|
@ -1,389 +1,389 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
// 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
|
||||
// settings and displays it.
|
||||
//
|
||||
// If you intend to _use_ this code sample in your app, do yourself a favour
|
||||
// and replace immediate mode calls with VBOs ...
|
||||
//
|
||||
// The vc8 solution links against assimp-release-dll_win32 - be sure to
|
||||
// have this configuration built.
|
||||
// ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
/* assimp include files. These three are usually needed. */
|
||||
#include <assimp/cimport.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
/* the global Assimp scene object */
|
||||
const struct aiScene* scene = NULL;
|
||||
GLuint scene_list = 0;
|
||||
struct aiVector3D scene_min, scene_max, scene_center;
|
||||
|
||||
/* current rotation angle */
|
||||
static float angle = 0.f;
|
||||
|
||||
#define aisgl_min(x,y) (x<y?x:y)
|
||||
#define aisgl_max(x,y) (y>x?y:x)
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void reshape(int width, int height)
|
||||
{
|
||||
const double aspectRatio = (float) width / height, fieldOfView = 45.0;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(fieldOfView, aspectRatio,
|
||||
1.0, 1000.0); /* Znear and Zfar */
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void get_bounding_box_for_node (const struct aiNode* nd,
|
||||
struct aiVector3D* min,
|
||||
struct aiVector3D* max,
|
||||
struct aiMatrix4x4* trafo
|
||||
){
|
||||
struct aiMatrix4x4 prev;
|
||||
unsigned int n = 0, t;
|
||||
|
||||
prev = *trafo;
|
||||
aiMultiplyMatrix4(trafo,&nd->mTransformation);
|
||||
|
||||
for (; n < nd->mNumMeshes; ++n) {
|
||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||
for (t = 0; t < mesh->mNumVertices; ++t) {
|
||||
|
||||
struct aiVector3D tmp = mesh->mVertices[t];
|
||||
aiTransformVecByMatrix4(&tmp,trafo);
|
||||
|
||||
min->x = aisgl_min(min->x,tmp.x);
|
||||
min->y = aisgl_min(min->y,tmp.y);
|
||||
min->z = aisgl_min(min->z,tmp.z);
|
||||
|
||||
max->x = aisgl_max(max->x,tmp.x);
|
||||
max->y = aisgl_max(max->y,tmp.y);
|
||||
max->z = aisgl_max(max->z,tmp.z);
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||
get_bounding_box_for_node(nd->mChildren[n],min,max,trafo);
|
||||
}
|
||||
*trafo = prev;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void get_bounding_box (struct aiVector3D* min, struct aiVector3D* max)
|
||||
{
|
||||
struct aiMatrix4x4 trafo;
|
||||
aiIdentityMatrix4(&trafo);
|
||||
|
||||
min->x = min->y = min->z = 1e10f;
|
||||
max->x = max->y = max->z = -1e10f;
|
||||
get_bounding_box_for_node(scene->mRootNode,min,max,&trafo);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void color4_to_float4(const struct aiColor4D *c, float f[4])
|
||||
{
|
||||
f[0] = c->r;
|
||||
f[1] = c->g;
|
||||
f[2] = c->b;
|
||||
f[3] = c->a;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void set_float4(float f[4], float a, float b, float c, float d)
|
||||
{
|
||||
f[0] = a;
|
||||
f[1] = b;
|
||||
f[2] = c;
|
||||
f[3] = d;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void apply_material(const struct aiMaterial *mtl)
|
||||
{
|
||||
float c[4];
|
||||
|
||||
GLenum fill_mode;
|
||||
int ret1, ret2;
|
||||
struct aiColor4D diffuse;
|
||||
struct aiColor4D specular;
|
||||
struct aiColor4D ambient;
|
||||
struct aiColor4D emission;
|
||||
float shininess, strength;
|
||||
int two_sided;
|
||||
int wireframe;
|
||||
unsigned int max;
|
||||
|
||||
set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
|
||||
color4_to_float4(&diffuse, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
|
||||
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
|
||||
color4_to_float4(&specular, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||
|
||||
set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
|
||||
color4_to_float4(&ambient, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
|
||||
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
|
||||
color4_to_float4(&emission, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
|
||||
|
||||
max = 1;
|
||||
ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
|
||||
if(ret1 == AI_SUCCESS) {
|
||||
max = 1;
|
||||
ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
||||
if(ret2 == AI_SUCCESS)
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
|
||||
else
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
||||
}
|
||||
else {
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||
}
|
||||
|
||||
max = 1;
|
||||
if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
|
||||
fill_mode = wireframe ? GL_LINE : GL_FILL;
|
||||
else
|
||||
fill_mode = GL_FILL;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
|
||||
|
||||
max = 1;
|
||||
if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
|
||||
glDisable(GL_CULL_FACE);
|
||||
else
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int n = 0, t;
|
||||
struct aiMatrix4x4 m = nd->mTransformation;
|
||||
|
||||
/* update transform */
|
||||
aiTransposeMatrix4(&m);
|
||||
glPushMatrix();
|
||||
glMultMatrixf((float*)&m);
|
||||
|
||||
/* draw all meshes assigned to this node */
|
||||
for (; n < nd->mNumMeshes; ++n) {
|
||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||
|
||||
apply_material(sc->mMaterials[mesh->mMaterialIndex]);
|
||||
|
||||
if(mesh->mNormals == NULL) {
|
||||
glDisable(GL_LIGHTING);
|
||||
} else {
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
for (t = 0; t < mesh->mNumFaces; ++t) {
|
||||
const struct aiFace* face = &mesh->mFaces[t];
|
||||
GLenum face_mode;
|
||||
|
||||
switch(face->mNumIndices) {
|
||||
case 1: face_mode = GL_POINTS; break;
|
||||
case 2: face_mode = GL_LINES; break;
|
||||
case 3: face_mode = GL_TRIANGLES; break;
|
||||
default: face_mode = GL_POLYGON; break;
|
||||
}
|
||||
|
||||
glBegin(face_mode);
|
||||
|
||||
for(i = 0; i < face->mNumIndices; i++) {
|
||||
int index = face->mIndices[i];
|
||||
if(mesh->mColors[0] != NULL)
|
||||
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
|
||||
if(mesh->mNormals != NULL)
|
||||
glNormal3fv(&mesh->mNormals[index].x);
|
||||
glVertex3fv(&mesh->mVertices[index].x);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* draw all children */
|
||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||
recursive_render(sc, nd->mChildren[n]);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void do_motion (void)
|
||||
{
|
||||
static GLint prev_time = 0;
|
||||
static GLint prev_fps_time = 0;
|
||||
static int frames = 0;
|
||||
|
||||
int time = glutGet(GLUT_ELAPSED_TIME);
|
||||
angle += (time-prev_time)*0.01;
|
||||
prev_time = time;
|
||||
|
||||
frames += 1;
|
||||
if ((time - prev_fps_time) > 1000) /* update every seconds */
|
||||
{
|
||||
int current_fps = frames * 1000 / (time - prev_fps_time);
|
||||
printf("%d fps\n", current_fps);
|
||||
frames = 0;
|
||||
prev_fps_time = time;
|
||||
}
|
||||
|
||||
|
||||
glutPostRedisplay ();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void display(void)
|
||||
{
|
||||
float tmp;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
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 */
|
||||
glRotatef(angle,0.f,1.f,0.f);
|
||||
|
||||
/* scale the whole asset to fit into our view frustum */
|
||||
tmp = scene_max.x-scene_min.x;
|
||||
tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
|
||||
tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
|
||||
tmp = 1.f / tmp;
|
||||
glScalef(tmp, tmp, tmp);
|
||||
|
||||
/* center the model */
|
||||
glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
|
||||
|
||||
/* if the display list has not been made yet, create a new one and
|
||||
fill it with scene contents */
|
||||
if(scene_list == 0) {
|
||||
scene_list = glGenLists(1);
|
||||
glNewList(scene_list, GL_COMPILE);
|
||||
/* now begin at the root node of the imported data and traverse
|
||||
the scenegraph by multiplying subsequent local transforms
|
||||
together on GL's matrix stack. */
|
||||
recursive_render(scene, scene->mRootNode);
|
||||
glEndList();
|
||||
}
|
||||
|
||||
glCallList(scene_list);
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
do_motion();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int loadasset (const char* path)
|
||||
{
|
||||
/* we are taking one of the postprocessing presets to avoid
|
||||
spelling out 20+ single postprocessing flags here. */
|
||||
scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);
|
||||
|
||||
if (scene) {
|
||||
get_bounding_box(&scene_min,&scene_max);
|
||||
scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
|
||||
scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
|
||||
scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct aiLogStream stream;
|
||||
|
||||
glutInitWindowSize(900,600);
|
||||
glutInitWindowPosition(100,100);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInit(&argc, argv);
|
||||
|
||||
glutCreateWindow("Assimp - Very simple OpenGL sample");
|
||||
glutDisplayFunc(display);
|
||||
glutReshapeFunc(reshape);
|
||||
|
||||
/* get a handle to the predefined STDOUT log stream and attach
|
||||
it to the logging system. It remains active for all further
|
||||
calls to aiImportFile(Ex) and aiApplyPostProcessing. */
|
||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
|
||||
aiAttachLogStream(&stream);
|
||||
|
||||
/* ... same procedure, but this stream now writes the
|
||||
log messages to assimp_log.txt */
|
||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
|
||||
aiAttachLogStream(&stream);
|
||||
|
||||
/* the model name can be specified on the command line. If none
|
||||
is specified, we try to locate one of the more expressive test
|
||||
models from the repository (/models-nonbsd may be missing in
|
||||
some distributions so we need a fallback from /models!). */
|
||||
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"))) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.1f,0.1f,0.1f,1.f);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0); /* Uses default lighting parameters */
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
|
||||
if(getenv("MODEL_IS_BROKEN"))
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
||||
|
||||
glutGet(GLUT_ELAPSED_TIME);
|
||||
glutMainLoop();
|
||||
|
||||
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
||||
keeps internal resources until the scene is freed again. Not
|
||||
doing so can cause severe resource leaking. */
|
||||
aiReleaseImport(scene);
|
||||
|
||||
/* We added a log stream to the library, it's our job to disable it
|
||||
again. This will definitely release the last resources allocated
|
||||
by Assimp.*/
|
||||
aiDetachAllLogStreams();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
// 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
|
||||
// settings and displays it.
|
||||
//
|
||||
// If you intend to _use_ this code sample in your app, do yourself a favour
|
||||
// and replace immediate mode calls with VBOs ...
|
||||
//
|
||||
// The vc8 solution links against assimp-release-dll_win32 - be sure to
|
||||
// have this configuration built.
|
||||
// ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
/* assimp include files. These three are usually needed. */
|
||||
#include <assimp/cimport.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
/* the global Assimp scene object */
|
||||
const struct aiScene* scene = NULL;
|
||||
GLuint scene_list = 0;
|
||||
struct aiVector3D scene_min, scene_max, scene_center;
|
||||
|
||||
/* current rotation angle */
|
||||
static float angle = 0.f;
|
||||
|
||||
#define aisgl_min(x,y) (x<y?x:y)
|
||||
#define aisgl_max(x,y) (y>x?y:x)
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void reshape(int width, int height)
|
||||
{
|
||||
const double aspectRatio = (float) width / height, fieldOfView = 45.0;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(fieldOfView, aspectRatio,
|
||||
1.0, 1000.0); /* Znear and Zfar */
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void get_bounding_box_for_node (const struct aiNode* nd,
|
||||
struct aiVector3D* min,
|
||||
struct aiVector3D* max,
|
||||
struct aiMatrix4x4* trafo
|
||||
){
|
||||
struct aiMatrix4x4 prev;
|
||||
unsigned int n = 0, t;
|
||||
|
||||
prev = *trafo;
|
||||
aiMultiplyMatrix4(trafo,&nd->mTransformation);
|
||||
|
||||
for (; n < nd->mNumMeshes; ++n) {
|
||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||
for (t = 0; t < mesh->mNumVertices; ++t) {
|
||||
|
||||
struct aiVector3D tmp = mesh->mVertices[t];
|
||||
aiTransformVecByMatrix4(&tmp,trafo);
|
||||
|
||||
min->x = aisgl_min(min->x,tmp.x);
|
||||
min->y = aisgl_min(min->y,tmp.y);
|
||||
min->z = aisgl_min(min->z,tmp.z);
|
||||
|
||||
max->x = aisgl_max(max->x,tmp.x);
|
||||
max->y = aisgl_max(max->y,tmp.y);
|
||||
max->z = aisgl_max(max->z,tmp.z);
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||
get_bounding_box_for_node(nd->mChildren[n],min,max,trafo);
|
||||
}
|
||||
*trafo = prev;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void get_bounding_box (struct aiVector3D* min, struct aiVector3D* max)
|
||||
{
|
||||
struct aiMatrix4x4 trafo;
|
||||
aiIdentityMatrix4(&trafo);
|
||||
|
||||
min->x = min->y = min->z = 1e10f;
|
||||
max->x = max->y = max->z = -1e10f;
|
||||
get_bounding_box_for_node(scene->mRootNode,min,max,&trafo);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void color4_to_float4(const struct aiColor4D *c, float f[4])
|
||||
{
|
||||
f[0] = c->r;
|
||||
f[1] = c->g;
|
||||
f[2] = c->b;
|
||||
f[3] = c->a;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void set_float4(float f[4], float a, float b, float c, float d)
|
||||
{
|
||||
f[0] = a;
|
||||
f[1] = b;
|
||||
f[2] = c;
|
||||
f[3] = d;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void apply_material(const struct aiMaterial *mtl)
|
||||
{
|
||||
float c[4];
|
||||
|
||||
GLenum fill_mode;
|
||||
int ret1, ret2;
|
||||
struct aiColor4D diffuse;
|
||||
struct aiColor4D specular;
|
||||
struct aiColor4D ambient;
|
||||
struct aiColor4D emission;
|
||||
float shininess, strength;
|
||||
int two_sided;
|
||||
int wireframe;
|
||||
unsigned int max;
|
||||
|
||||
set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
|
||||
color4_to_float4(&diffuse, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
|
||||
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
|
||||
color4_to_float4(&specular, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||
|
||||
set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
|
||||
color4_to_float4(&ambient, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
|
||||
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
|
||||
color4_to_float4(&emission, c);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
|
||||
|
||||
max = 1;
|
||||
ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
|
||||
if(ret1 == AI_SUCCESS) {
|
||||
max = 1;
|
||||
ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
|
||||
if(ret2 == AI_SUCCESS)
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
|
||||
else
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
||||
}
|
||||
else {
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
|
||||
set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
|
||||
}
|
||||
|
||||
max = 1;
|
||||
if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
|
||||
fill_mode = wireframe ? GL_LINE : GL_FILL;
|
||||
else
|
||||
fill_mode = GL_FILL;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
|
||||
|
||||
max = 1;
|
||||
if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
|
||||
glDisable(GL_CULL_FACE);
|
||||
else
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int n = 0, t;
|
||||
struct aiMatrix4x4 m = nd->mTransformation;
|
||||
|
||||
/* update transform */
|
||||
aiTransposeMatrix4(&m);
|
||||
glPushMatrix();
|
||||
glMultMatrixf((float*)&m);
|
||||
|
||||
/* draw all meshes assigned to this node */
|
||||
for (; n < nd->mNumMeshes; ++n) {
|
||||
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
|
||||
|
||||
apply_material(sc->mMaterials[mesh->mMaterialIndex]);
|
||||
|
||||
if(mesh->mNormals == NULL) {
|
||||
glDisable(GL_LIGHTING);
|
||||
} else {
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
for (t = 0; t < mesh->mNumFaces; ++t) {
|
||||
const struct aiFace* face = &mesh->mFaces[t];
|
||||
GLenum face_mode;
|
||||
|
||||
switch(face->mNumIndices) {
|
||||
case 1: face_mode = GL_POINTS; break;
|
||||
case 2: face_mode = GL_LINES; break;
|
||||
case 3: face_mode = GL_TRIANGLES; break;
|
||||
default: face_mode = GL_POLYGON; break;
|
||||
}
|
||||
|
||||
glBegin(face_mode);
|
||||
|
||||
for(i = 0; i < face->mNumIndices; i++) {
|
||||
int index = face->mIndices[i];
|
||||
if(mesh->mColors[0] != NULL)
|
||||
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
|
||||
if(mesh->mNormals != NULL)
|
||||
glNormal3fv(&mesh->mNormals[index].x);
|
||||
glVertex3fv(&mesh->mVertices[index].x);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* draw all children */
|
||||
for (n = 0; n < nd->mNumChildren; ++n) {
|
||||
recursive_render(sc, nd->mChildren[n]);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void do_motion (void)
|
||||
{
|
||||
static GLint prev_time = 0;
|
||||
static GLint prev_fps_time = 0;
|
||||
static int frames = 0;
|
||||
|
||||
int time = glutGet(GLUT_ELAPSED_TIME);
|
||||
angle += (time-prev_time)*0.01;
|
||||
prev_time = time;
|
||||
|
||||
frames += 1;
|
||||
if ((time - prev_fps_time) > 1000) /* update every seconds */
|
||||
{
|
||||
int current_fps = frames * 1000 / (time - prev_fps_time);
|
||||
printf("%d fps\n", current_fps);
|
||||
frames = 0;
|
||||
prev_fps_time = time;
|
||||
}
|
||||
|
||||
|
||||
glutPostRedisplay ();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
void display(void)
|
||||
{
|
||||
float tmp;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
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 */
|
||||
glRotatef(angle,0.f,1.f,0.f);
|
||||
|
||||
/* scale the whole asset to fit into our view frustum */
|
||||
tmp = scene_max.x-scene_min.x;
|
||||
tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
|
||||
tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
|
||||
tmp = 1.f / tmp;
|
||||
glScalef(tmp, tmp, tmp);
|
||||
|
||||
/* center the model */
|
||||
glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
|
||||
|
||||
/* if the display list has not been made yet, create a new one and
|
||||
fill it with scene contents */
|
||||
if(scene_list == 0) {
|
||||
scene_list = glGenLists(1);
|
||||
glNewList(scene_list, GL_COMPILE);
|
||||
/* now begin at the root node of the imported data and traverse
|
||||
the scenegraph by multiplying subsequent local transforms
|
||||
together on GL's matrix stack. */
|
||||
recursive_render(scene, scene->mRootNode);
|
||||
glEndList();
|
||||
}
|
||||
|
||||
glCallList(scene_list);
|
||||
|
||||
glutSwapBuffers();
|
||||
|
||||
do_motion();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int loadasset (const char* path)
|
||||
{
|
||||
/* we are taking one of the postprocessing presets to avoid
|
||||
spelling out 20+ single postprocessing flags here. */
|
||||
scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);
|
||||
|
||||
if (scene) {
|
||||
get_bounding_box(&scene_min,&scene_max);
|
||||
scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
|
||||
scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
|
||||
scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct aiLogStream stream;
|
||||
|
||||
glutInitWindowSize(900,600);
|
||||
glutInitWindowPosition(100,100);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInit(&argc, argv);
|
||||
|
||||
glutCreateWindow("Assimp - Very simple OpenGL sample");
|
||||
glutDisplayFunc(display);
|
||||
glutReshapeFunc(reshape);
|
||||
|
||||
/* get a handle to the predefined STDOUT log stream and attach
|
||||
it to the logging system. It remains active for all further
|
||||
calls to aiImportFile(Ex) and aiApplyPostProcessing. */
|
||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
|
||||
aiAttachLogStream(&stream);
|
||||
|
||||
/* ... same procedure, but this stream now writes the
|
||||
log messages to assimp_log.txt */
|
||||
stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
|
||||
aiAttachLogStream(&stream);
|
||||
|
||||
/* the model name can be specified on the command line. If none
|
||||
is specified, we try to locate one of the more expressive test
|
||||
models from the repository (/models-nonbsd may be missing in
|
||||
some distributions so we need a fallback from /models!). */
|
||||
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"))) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
glClearColor(0.1f,0.1f,0.1f,1.f);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0); /* Uses default lighting parameters */
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
|
||||
if(getenv("MODEL_IS_BROKEN"))
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
||||
|
||||
glutGet(GLUT_ELAPSED_TIME);
|
||||
glutMainLoop();
|
||||
|
||||
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
||||
keeps internal resources until the scene is freed again. Not
|
||||
doing so can cause severe resource leaking. */
|
||||
aiReleaseImport(scene);
|
||||
|
||||
/* We added a log stream to the library, it's our job to disable it
|
||||
again. This will definitely release the last resources allocated
|
||||
by Assimp.*/
|
||||
aiDetachAllLogStreams();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,111 +1,111 @@
|
|||
# ==============================================================================
|
||||
# List of IFC structures needed by Assimp
|
||||
# ==============================================================================
|
||||
# use genentitylist.sh to update this list
|
||||
|
||||
# This machine-generated list is not complete, it lacks many intermediate
|
||||
# classes in the inheritance hierarchy. Those are magically augmented by the
|
||||
# code generator. Also, the names of all used entities need to be present
|
||||
# in the source code for this to work.
|
||||
|
||||
IfcAnnotation
|
||||
IfcArbitraryClosedProfileDef
|
||||
IfcArbitraryOpenProfileDef
|
||||
IfcArbitraryProfileDefWithVoids
|
||||
IfcAxis1Placement
|
||||
IfcAxis2Placement
|
||||
IfcAxis2Placement2D
|
||||
IfcAxis2Placement3D
|
||||
IfcBooleanClippingResult
|
||||
IfcBooleanResult
|
||||
IfcBoundedCurve
|
||||
IfcBoundingBox
|
||||
IfcBSplineCurve
|
||||
IfcBuilding
|
||||
IfcCartesianPoint
|
||||
IfcCartesianTransformationOperator
|
||||
IfcCartesianTransformationOperator3D
|
||||
IfcCartesianTransformationOperator3DnonUniform
|
||||
IfcCircle
|
||||
IfcCircleHollowProfileDef
|
||||
IfcCircleProfileDef
|
||||
IfcClosedShell
|
||||
IfcColourOrFactor
|
||||
IfcColourRgb
|
||||
IfcCompositeCurve
|
||||
IfcCompositeCurveSegment
|
||||
IfcConic
|
||||
IfcConnectedFaceSet
|
||||
IfcConversionBasedUnit
|
||||
IfcCurve
|
||||
IfcDirection
|
||||
IfcDoor
|
||||
IfcEllipse
|
||||
IfcExtrudedAreaSolid
|
||||
IfcFace
|
||||
IfcFaceBasedSurfaceModel
|
||||
IfcFaceBound
|
||||
IfcFaceOuterBound
|
||||
IfcFeatureElementSubtraction
|
||||
IfcGeometricRepresentationContext
|
||||
IfcGeometricRepresentationItem
|
||||
IfcHalfSpaceSolid
|
||||
IfcLine
|
||||
IfcLocalPlacement
|
||||
IfcManifoldSolidBrep
|
||||
IfcMappedItem
|
||||
IfcMeasureWithUnit
|
||||
IfcNamedUnit
|
||||
IfcObjectDefinition
|
||||
IfcObjectPlacement
|
||||
IfcOpeningElement
|
||||
IfcParameterizedProfileDef
|
||||
IfcPlane
|
||||
IfcPolygonalBoundedHalfSpace
|
||||
IfcPolyline
|
||||
IfcPolyLoop
|
||||
IfcPresentationStyleAssignment
|
||||
IfcPresentationStyleSelect
|
||||
IfcProduct
|
||||
IfcProductRepresentation
|
||||
IfcProfileDef
|
||||
IfcProject
|
||||
IfcRectangleProfileDef
|
||||
IfcRelAggregates
|
||||
IfcRelContainedInSpatialStructure
|
||||
IfcRelFillsElement
|
||||
IfcRelVoidsElement
|
||||
IfcRepresentation
|
||||
IfcRepresentationContext
|
||||
IfcRepresentationItem
|
||||
IfcRepresentationMap
|
||||
IfcRevolvedAreaSolid
|
||||
IfcShell
|
||||
IfcShellBasedSurfaceModel
|
||||
IfcSite
|
||||
IfcSIUnit
|
||||
IfcSomething
|
||||
IfcSpace
|
||||
IfcSpatialStructureElement
|
||||
IfcSpatialStructureElements
|
||||
IfcStyledItem
|
||||
IfcSurfaceStyle
|
||||
IfcSurfaceStyleElementSelect
|
||||
IfcSurfaceStyleRendering
|
||||
IfcSurfaceStyleShading
|
||||
IfcSurfaceStyleWithTextures
|
||||
IfcSweptAreaSolid
|
||||
IfcSweptDiskSolid
|
||||
IfcTopologicalRepresentationItem
|
||||
IfcTrimmedCurve
|
||||
IfcUnit
|
||||
IfcUnitAssignment
|
||||
IfcVector
|
||||
IfcIShapeProfileDef
|
||||
IfcPropertyListValue
|
||||
IfcRelDefinesByProperties
|
||||
IfcPropertySet
|
||||
IfcPropertySingleValue
|
||||
IfcProperty
|
||||
IfcComplexProperty
|
||||
IfcElementQuantity
|
||||
# ==============================================================================
|
||||
# List of IFC structures needed by Assimp
|
||||
# ==============================================================================
|
||||
# use genentitylist.sh to update this list
|
||||
|
||||
# This machine-generated list is not complete, it lacks many intermediate
|
||||
# classes in the inheritance hierarchy. Those are magically augmented by the
|
||||
# code generator. Also, the names of all used entities need to be present
|
||||
# in the source code for this to work.
|
||||
|
||||
IfcAnnotation
|
||||
IfcArbitraryClosedProfileDef
|
||||
IfcArbitraryOpenProfileDef
|
||||
IfcArbitraryProfileDefWithVoids
|
||||
IfcAxis1Placement
|
||||
IfcAxis2Placement
|
||||
IfcAxis2Placement2D
|
||||
IfcAxis2Placement3D
|
||||
IfcBooleanClippingResult
|
||||
IfcBooleanResult
|
||||
IfcBoundedCurve
|
||||
IfcBoundingBox
|
||||
IfcBSplineCurve
|
||||
IfcBuilding
|
||||
IfcCartesianPoint
|
||||
IfcCartesianTransformationOperator
|
||||
IfcCartesianTransformationOperator3D
|
||||
IfcCartesianTransformationOperator3DnonUniform
|
||||
IfcCircle
|
||||
IfcCircleHollowProfileDef
|
||||
IfcCircleProfileDef
|
||||
IfcClosedShell
|
||||
IfcColourOrFactor
|
||||
IfcColourRgb
|
||||
IfcCompositeCurve
|
||||
IfcCompositeCurveSegment
|
||||
IfcConic
|
||||
IfcConnectedFaceSet
|
||||
IfcConversionBasedUnit
|
||||
IfcCurve
|
||||
IfcDirection
|
||||
IfcDoor
|
||||
IfcEllipse
|
||||
IfcExtrudedAreaSolid
|
||||
IfcFace
|
||||
IfcFaceBasedSurfaceModel
|
||||
IfcFaceBound
|
||||
IfcFaceOuterBound
|
||||
IfcFeatureElementSubtraction
|
||||
IfcGeometricRepresentationContext
|
||||
IfcGeometricRepresentationItem
|
||||
IfcHalfSpaceSolid
|
||||
IfcLine
|
||||
IfcLocalPlacement
|
||||
IfcManifoldSolidBrep
|
||||
IfcMappedItem
|
||||
IfcMeasureWithUnit
|
||||
IfcNamedUnit
|
||||
IfcObjectDefinition
|
||||
IfcObjectPlacement
|
||||
IfcOpeningElement
|
||||
IfcParameterizedProfileDef
|
||||
IfcPlane
|
||||
IfcPolygonalBoundedHalfSpace
|
||||
IfcPolyline
|
||||
IfcPolyLoop
|
||||
IfcPresentationStyleAssignment
|
||||
IfcPresentationStyleSelect
|
||||
IfcProduct
|
||||
IfcProductRepresentation
|
||||
IfcProfileDef
|
||||
IfcProject
|
||||
IfcRectangleProfileDef
|
||||
IfcRelAggregates
|
||||
IfcRelContainedInSpatialStructure
|
||||
IfcRelFillsElement
|
||||
IfcRelVoidsElement
|
||||
IfcRepresentation
|
||||
IfcRepresentationContext
|
||||
IfcRepresentationItem
|
||||
IfcRepresentationMap
|
||||
IfcRevolvedAreaSolid
|
||||
IfcShell
|
||||
IfcShellBasedSurfaceModel
|
||||
IfcSite
|
||||
IfcSIUnit
|
||||
IfcSomething
|
||||
IfcSpace
|
||||
IfcSpatialStructureElement
|
||||
IfcSpatialStructureElements
|
||||
IfcStyledItem
|
||||
IfcSurfaceStyle
|
||||
IfcSurfaceStyleElementSelect
|
||||
IfcSurfaceStyleRendering
|
||||
IfcSurfaceStyleShading
|
||||
IfcSurfaceStyleWithTextures
|
||||
IfcSweptAreaSolid
|
||||
IfcSweptDiskSolid
|
||||
IfcTopologicalRepresentationItem
|
||||
IfcTrimmedCurve
|
||||
IfcUnit
|
||||
IfcUnitAssignment
|
||||
IfcVector
|
||||
IfcIShapeProfileDef
|
||||
IfcPropertyListValue
|
||||
IfcRelDefinesByProperties
|
||||
IfcPropertySet
|
||||
IfcPropertySingleValue
|
||||
IfcProperty
|
||||
IfcComplexProperty
|
||||
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