| 322 | } |
| 323 | |
| 324 | static PyObject* PySetItemElement( PyObject* self, PyObject* args ) |
| 325 | { |
| 326 | Tr2RuntimeInstanceData* pThis = BluePythonCast<Tr2RuntimeInstanceData*>( self ); |
| 327 | |
| 328 | unsigned index; |
| 329 | unsigned elementIndex; |
| 330 | PyObject* element; |
| 331 | if( !PyArg_ParseTuple( args, "IIO", &index, &elementIndex, &element ) ) |
| 332 | { |
| 333 | return nullptr; |
| 334 | } |
| 335 | |
| 336 | if( pThis->GetCount() <= index ) |
| 337 | { |
| 338 | PyErr_SetString( PyExc_IndexError, "Index out of range" ); |
| 339 | return nullptr; |
| 340 | } |
| 341 | |
| 342 | const Tr2VertexDefinition& def = pThis->GetLayout(); |
| 343 | if( def.m_items.empty() ) |
| 344 | { |
| 345 | PyErr_SetString( PyExc_RuntimeError, "Need to set valid element layout with SetElementLayout before calling SetData" ); |
| 346 | return nullptr; |
| 347 | } |
| 348 | |
| 349 | if( elementIndex >= def.m_items.size() ) |
| 350 | { |
| 351 | PyErr_SetString( PyExc_IndexError, "elementIndex out of range" ); |
| 352 | return nullptr; |
| 353 | } |
| 354 | |
| 355 | uint8_t* dataRaw = reinterpret_cast<uint8_t*>( pThis->GetData( pThis->GetCount() ) ); |
| 356 | if( !dataRaw ) |
| 357 | { |
| 358 | PyErr_SetString( PyExc_RuntimeError, "Could not lock data" ); |
| 359 | return nullptr; |
| 360 | } |
| 361 | float* data = static_cast<float*>( static_cast<void*>( dataRaw + pThis->GetStride() * index + def.m_items[elementIndex].m_offset ) ); |
| 362 | |
| 363 | unsigned size = def.GetDataTypeSizeInMembers( def.m_items[elementIndex].m_dataType ); |
| 364 | if( size == 1 ) |
| 365 | { |
| 366 | if( !PyFloat_Check( element ) ) |
| 367 | { |
| 368 | pThis->DestroyData(); |
| 369 | PyErr_SetString( PyExc_TypeError, "Argument 3 needs to be a float" ); |
| 370 | return nullptr; |
| 371 | } |
| 372 | *data++ = float( PyFloat_AsDouble( element ) ); |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | if( !PyTuple_Check( element ) ) |
| 377 | { |
| 378 | pThis->DestroyData(); |
| 379 | PyErr_SetString( PyExc_TypeError, "Argument 3 needs to be a tuple and it needs to match element layout" ); |
| 380 | return nullptr; |
| 381 | } |
nothing calls this directly
no test coverage detected