mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
add methods to directly access vertex and texture data from Python
This commit is contained in:
parent
176e3f7129
commit
18fab235c9
@ -33,3 +33,9 @@ forcetype ConfigVariableString
|
||||
forcetype istream
|
||||
forcetype ostream
|
||||
forcetype iostream
|
||||
|
||||
forcetype PointerToArray<unsigned char>
|
||||
forcetype ConstPointerToArray<unsigned char>
|
||||
|
||||
renametype PointerToArray<unsigned char> PTAUchar
|
||||
renametype ConstPointerToArray<unsigned char> CPTAUchar
|
||||
|
@ -26,7 +26,7 @@ pvector<Element> ConstPointerToArray<Element>::_empty_array;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -39,7 +39,7 @@ PointerToArray(TypeHandle type_handle) :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::empty_array
|
||||
// Access: Published, Static
|
||||
// Access: Public, Static
|
||||
// Description: Return an empty array of size n
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -55,7 +55,7 @@ PointerToArray<Element>::empty_array(size_type n, TypeHandle type_handle) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -70,7 +70,7 @@ PointerToArray(size_type n, const Element &value, TypeHandle type_handle) :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::Copy Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -312,7 +312,7 @@ erase(iterator first, iterator last) {
|
||||
#if !defined(WIN32_VC)
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -330,7 +330,7 @@ operator [](size_type n) const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -340,40 +340,9 @@ operator [](int n) const {
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::get_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE const Element &PointerToArray<Element>::
|
||||
get_element(size_type n) const {
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::set_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE void PointerToArray<Element>::
|
||||
set_element(size_type n, const Element &value) {
|
||||
nassertv(n < ((To *)(this->_void_ptr))->size());
|
||||
(*this)[n] = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::push_back
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -387,7 +356,7 @@ push_back(const Element &x) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::pop_back
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -402,7 +371,7 @@ pop_back() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::make_empty
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description: Empties the array pointed to. This is different from
|
||||
// clear(), which reassigns the pointer to a NULL
|
||||
// pointer.
|
||||
@ -462,6 +431,123 @@ v() const {
|
||||
return *((To *)(this->_void_ptr));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::get_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE const Element &PointerToArray<Element>::
|
||||
get_element(size_type n) const {
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::set_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE void PointerToArray<Element>::
|
||||
set_element(size_type n, const Element &value) {
|
||||
nassertv(n < ((To *)(this->_void_ptr))->size());
|
||||
(*this)[n] = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::get_data
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It returns the entire contents of the vector as a
|
||||
// block of raw data in a string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE string PointerToArray<Element>::
|
||||
get_data() const {
|
||||
return get_subdata(0, size());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::set_data
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It replaces the entire contents of the vector from a
|
||||
// block of raw data in a string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE void PointerToArray<Element>::
|
||||
set_data(const string &data) {
|
||||
set_subdata(0, size(), data);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::get_subdata
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It returns the contents of a portion of the
|
||||
// vector--from element (n) through element (n + count -
|
||||
// 1)--as a block of raw data in a string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE string PointerToArray<Element>::
|
||||
get_subdata(size_type n, size_type count) const {
|
||||
n = min(n, size());
|
||||
count = max(count, n);
|
||||
count = min(count, size() - n);
|
||||
return string((const char *)(p() + n), sizeof(Element) * count);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::set_subdata
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It replaces the contents of a portion of the
|
||||
// vector--from element (n) through element (n + count -
|
||||
// 1)--as a block of raw data in a string. The length
|
||||
// of the string must be an even multiple of Element
|
||||
// size bytes. The array may be expanded or truncated
|
||||
// if the length of the string does not correspond to
|
||||
// exactly count elements.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE void PointerToArray<Element>::
|
||||
set_subdata(size_type n, size_type count, const string &data) {
|
||||
nassertv((data.length() % sizeof(Element)) == 0);
|
||||
size_type ncount = data.length() / sizeof(Element);
|
||||
if (ncount < count) {
|
||||
// Reduce the array.
|
||||
erase(begin() + n + ncount, begin() + n + count);
|
||||
} else if (count < ncount) {
|
||||
// Expand the array.
|
||||
insert(begin() + n + count, ncount - count, Element());
|
||||
}
|
||||
|
||||
// Now boldly replace the data. Hope there aren't any constructors
|
||||
// or destructors involved here. The user better know what she is
|
||||
// doing.
|
||||
memcpy(p() + n, data.data(), sizeof(Element) * ncount);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToArray::get(this->_void_ptr)
|
||||
// Access: Public
|
||||
@ -575,7 +661,7 @@ clear() {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -588,7 +674,7 @@ ConstPointerToArray(TypeHandle type_handle) :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Copy Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -601,7 +687,7 @@ ConstPointerToArray(const PointerToArray<Element> ©) :
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Copy Constructor
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -670,7 +756,7 @@ rend() const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::size
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -755,7 +841,7 @@ back() const {
|
||||
#ifndef WIN32_VC
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -773,7 +859,7 @@ operator [](size_type n) const {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Indexing operator
|
||||
// Access: Published
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
@ -783,21 +869,6 @@ operator [](int n) const {
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE const Element &ConstPointerToArray<Element>::
|
||||
get_element(size_type n) const {
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::Typecast operator
|
||||
// Access: Public
|
||||
@ -843,6 +914,57 @@ v() const {
|
||||
return *(To *)(this->_void_ptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_element
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the elements of
|
||||
// the array easily from a high-level language such as
|
||||
// Python, especially on Windows, where the above index
|
||||
// element accessor methods can't be defined because of
|
||||
// a confusion with the pointer typecast operator.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE const Element &ConstPointerToArray<Element>::
|
||||
get_element(size_type n) const {
|
||||
return (*this)[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_data
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It returns the entire contents of the vector as a
|
||||
// block of raw data in a string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE string ConstPointerToArray<Element>::
|
||||
get_data() const {
|
||||
return get_subdata(0, size());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_subdata
|
||||
// Access: Published
|
||||
// Description: This method exists mainly to access the data of
|
||||
// the array easily from a high-level language such as
|
||||
// Python.
|
||||
//
|
||||
// It returns the contents of a portion of the
|
||||
// vector--from element (n) through element (n + count -
|
||||
// 1)--as a block of raw data in a string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template<class Element>
|
||||
INLINE string ConstPointerToArray<Element>::
|
||||
get_subdata(size_type n, size_type count) const {
|
||||
n = min(n, size());
|
||||
count = max(count, n);
|
||||
count = min(count, size() - n);
|
||||
return string((const char *)(p() + n), sizeof(Element) * count);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ConstPointerToArray::get_ref_count
|
||||
// Access: Public
|
||||
|
@ -102,9 +102,25 @@ class ConstPointerToArray;
|
||||
template <class Element>
|
||||
class PointerToArray : public PointerToArrayBase<Element> {
|
||||
public:
|
||||
// By hiding this template from interrogate, we improve compile-time
|
||||
// speed and memory utilization.
|
||||
#ifndef CPPPARSER
|
||||
// By hiding this template from interrogate, we would improve
|
||||
// compile-time speed and memory utilization. However, we do want
|
||||
// to export a minimal subset of this class. So we define just the
|
||||
// exportable interface here.
|
||||
#ifdef CPPPARSER
|
||||
PUBLISHED:
|
||||
typedef TYPENAME pvector<Element>::size_type size_type;
|
||||
INLINE PointerToArray(TypeHandle type_handle = get_type_handle(Element));
|
||||
INLINE PointerToArray(const PointerToArray<Element> ©);
|
||||
INLINE size_type size() const;
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
INLINE void set_element(size_type n, const Element &value);
|
||||
INLINE string get_data() const;
|
||||
INLINE void set_data(const string &data);
|
||||
INLINE string get_subdata(size_type n, size_type count) const;
|
||||
INLINE void set_subdata(size_type n, size_type count, const string &data);
|
||||
|
||||
#else // CPPPARSER
|
||||
// This is the actual, complete interface.
|
||||
typedef TYPENAME PointerToArrayBase<Element>::To To;
|
||||
typedef TYPENAME pvector<Element>::value_type value_type;
|
||||
typedef TYPENAME pvector<Element>::reference reference;
|
||||
@ -162,8 +178,6 @@ public:
|
||||
INLINE reference operator [](size_type n) const;
|
||||
INLINE reference operator [](int n) const;
|
||||
#endif
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
INLINE void set_element(size_type n, const Element &value);
|
||||
|
||||
INLINE void push_back(const Element &x);
|
||||
INLINE void pop_back();
|
||||
@ -173,6 +187,14 @@ public:
|
||||
INLINE Element *p() const;
|
||||
INLINE pvector<Element> &v() const;
|
||||
|
||||
// Methods to help out Python and other high-level languages.
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
INLINE void set_element(size_type n, const Element &value);
|
||||
INLINE string get_data() const;
|
||||
INLINE void set_data(const string &data);
|
||||
INLINE string get_subdata(size_type n, size_type count) const;
|
||||
INLINE void set_subdata(size_type n, size_type count, const string &data);
|
||||
|
||||
//These functions are only to be used in Reading through BamReader.
|
||||
//They are designed to work in pairs, so that you register what is
|
||||
//returned by get_void_ptr with BamReader and when you are setting
|
||||
@ -218,9 +240,20 @@ private:
|
||||
template <class Element>
|
||||
class ConstPointerToArray : public PointerToArrayBase<Element> {
|
||||
public:
|
||||
// By hiding this template from interrogate, we improve compile-time
|
||||
// speed and memory utilization.
|
||||
#ifndef CPPPARSER
|
||||
// By hiding this template from interrogate, we would improve
|
||||
// compile-time speed and memory utilization. However, we do want
|
||||
// to export a minimal subset of this class. So we define just the
|
||||
// exportable interface here.
|
||||
#ifdef CPPPARSER
|
||||
PUBLISHED:
|
||||
typedef TYPENAME pvector<Element>::size_type size_type;
|
||||
INLINE size_type size() const;
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
INLINE string get_data() const;
|
||||
INLINE string get_subdata(size_type n, size_type count) const;
|
||||
|
||||
#else // CPPPARSER
|
||||
// This is the actual, complete interface.
|
||||
typedef TYPENAME PointerToArrayBase<Element>::To To;
|
||||
typedef TYPENAME pvector<Element>::value_type value_type;
|
||||
typedef TYPENAME pvector<Element>::const_reference reference;
|
||||
@ -264,12 +297,16 @@ public:
|
||||
INLINE reference operator [](size_type n) const;
|
||||
INLINE reference operator [](int n) const;
|
||||
#endif
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
|
||||
INLINE operator const Element *() const;
|
||||
INLINE const Element *p() const;
|
||||
INLINE const pvector<Element> &v() const;
|
||||
|
||||
// Methods to help out Python and other high-level languages.
|
||||
INLINE const Element &get_element(size_type n) const;
|
||||
INLINE string get_data() const;
|
||||
INLINE string get_subdata(size_type n, size_type count) const;
|
||||
|
||||
INLINE int get_ref_count() const;
|
||||
|
||||
INLINE int get_node_ref_count() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user