| 149 | } |
| 150 | |
| 151 | static PyObject* PyGetItem( PyObject* self, PyObject* args ) |
| 152 | { |
| 153 | Tr2RuntimeInstanceData* pThis = BluePythonCast<Tr2RuntimeInstanceData*>( self ); |
| 154 | |
| 155 | unsigned index; |
| 156 | if( !PyArg_ParseTuple( args, "I", &index ) ) |
| 157 | { |
| 158 | return nullptr; |
| 159 | } |
| 160 | |
| 161 | if( pThis->GetCount() <= index ) |
| 162 | { |
| 163 | PyErr_SetString( PyExc_IndexError, "Index out of range" ); |
| 164 | return nullptr; |
| 165 | } |
| 166 | |
| 167 | const Tr2VertexDefinition& def = pThis->GetLayout(); |
| 168 | if( def.m_items.empty() ) |
| 169 | { |
| 170 | PyErr_SetString( PyExc_RuntimeError, "No layout set for runtime data" ); |
| 171 | return nullptr; |
| 172 | } |
| 173 | |
| 174 | const float* data = reinterpret_cast<const float*>( reinterpret_cast<const char*>( pThis->GetData() ) + pThis->GetStride() * index ); |
| 175 | |
| 176 | PyObject* pyData = PyTuple_New( def.m_items.size() ); |
| 177 | for( size_t j = 0; j < def.m_items.size(); ++j ) |
| 178 | { |
| 179 | unsigned size = def.GetDataTypeSizeInMembers( def.m_items[j].m_dataType ); |
| 180 | if( size == 1 ) |
| 181 | { |
| 182 | PyTuple_SET_ITEM( pyData, j, PyFloat_FromDouble( *data++ ) ); |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | PyObject* element = PyTuple_New( size ); |
| 187 | for( unsigned k = 0; k < size; ++k ) |
| 188 | { |
| 189 | PyTuple_SET_ITEM( element, k, PyFloat_FromDouble( *data++ ) ); |
| 190 | } |
| 191 | PyTuple_SET_ITEM( pyData, j, PyFloat_FromDouble( *data++ ) ); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return pyData; |
| 196 | } |
| 197 | |
| 198 | static PyObject* PySetItem( PyObject* self, PyObject* args ) |
| 199 | { |