Changeset 936 for GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src
- Timestamp:
- 05/09/06 17:13:42 (19 years ago)
- Location:
- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCEntity.cpp
r721 r936 82 82 getMeshVertexColours(mergeSubMeshes); 83 83 getMeshTexCoords(mergeSubMeshes); 84 getMeshFacesVerticesID(mergeSubMeshes);84 //getMeshFacesVerticesID(mergeSubMeshes); 85 85 } 86 86 … … 110 110 size_t shared_offset = 0; 111 111 size_t next_offset = 0; 112 size_t index_offset = 0; 113 size_t vertex_count, index_count; 114 115 vertex_count = index_count = 0; 112 116 113 117 unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes(); 114 118 sincronizeNumSubEntities(); 115 119 120 // Calculate how many vertices and indices we're going to need 121 for(int i = 0; i < mMesh->get()->getNumSubMeshes(); i++) 122 { 123 Ogre::SubMesh* submesh = mMesh->get()->getSubMesh(i); 124 125 // We only need to add the shared vertices once 126 if(submesh->useSharedVertices) 127 { 128 if(!added_shared) 129 { 130 Ogre::VertexData* vertex_data = mMesh->get()->sharedVertexData; 131 vertex_count += vertex_data->vertexCount; 132 added_shared = true; 133 } 134 } 135 else 136 { 137 Ogre::VertexData* vertex_data = submesh->vertexData; 138 vertex_count += vertex_data->vertexCount; 139 } 140 141 // Add the indices 142 Ogre::IndexData* index_data = submesh->indexData; 143 index_count += index_data->indexCount; 144 } 145 146 unsigned int* indices = NULL; 147 if (mergeSubMeshes) 148 { 149 indices = new unsigned[index_count]; 150 } 151 116 152 added_shared = false; 117 153 for (unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); i++) … … 119 155 Ogre::SubMesh* subMesh = mMesh->get()->getSubMesh(i); 120 156 Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->get()->sharedVertexData : subMesh->vertexData; 157 158 if (!mergeSubMeshes) 159 { 160 // Add the indices 161 Ogre::IndexData* index_data = subMesh->indexData; 162 index_count = index_data->indexCount; 163 164 if (indices != NULL) 165 { 166 delete [] indices; 167 } 168 169 indices = new unsigned[index_count]; 170 } 121 171 122 172 if ((!subMesh->useSharedVertices) || (subMesh->useSharedVertices && !added_shared)) … … 154 204 vbuf->unlock(); 155 205 next_offset += vertexData->vertexCount; 156 } 157 } 158 current_offset = next_offset; 206 207 208 Ogre::IndexData* index_data = subMesh->indexData; 209 210 size_t numTris = index_data->indexCount / 3; 211 unsigned short* pShort; 212 unsigned int* pInt; 213 Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer; 214 bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT); 215 if (use32bitindexes) pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); 216 else pShort = static_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); 217 218 index_offset = 0; 219 for(size_t k = 0; k < numTris; ++k) 220 { 221 size_t offset; 222 if (!mergeSubMeshes) 223 { 224 offset = (subMesh->useSharedVertices)?shared_offset:0; 225 } 226 else 227 { 228 offset = (subMesh->useSharedVertices)?shared_offset:current_offset; 229 } 230 231 unsigned int vindex = use32bitindexes? *pInt++ : *pShort++; 232 indices[index_offset + 0] = vindex + offset; 233 234 vindex = use32bitindexes? *pInt++ : *pShort++; 235 indices[index_offset + 1] = vindex + offset; 236 237 vindex = use32bitindexes? *pInt++ : *pShort++; 238 indices[index_offset + 2] = vindex + offset; 239 240 index_offset += 3; 241 } 242 243 for(size_t k = 0; k < index_count; k = k + 3) 244 { 245 if (!mergeSubMeshes) 246 { 247 this->getSubEntity(i)->addFaceVerticesIDs(Ogre::Vector3(indices[k], indices[k+1], indices[k+2])); 248 } 249 else 250 { 251 this->getSubEntity(0)->addFaceVerticesIDs(Ogre::Vector3(indices[k], indices[k+1], indices[k+2])); 252 } 253 } 254 ibuf->unlock(); 255 current_offset = next_offset; 256 } 257 } 258 259 delete [] indices; 159 260 } 160 261 … … 240 341 Ogre::HardwareVertexBufferSharedPtr vbuf = vertexData->vertexBufferBinding->getBuffer(colourElem->getSource()); 241 342 unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); 242 Ogre:: RGBA *pSrcRGBA;343 Ogre::ARGB *pSrcARGB; 243 344 244 345 for(size_t j = 0; j < vertexData->vertexCount; ++j, vertex += vbuf->getVertexSize()) … … 246 347 if (colourElem) 247 348 { 248 colourElem->baseVertexPointerToElement(vertex, &pSrcRGBA); 249 } 349 colourElem->baseVertexPointerToElement(vertex, &pSrcARGB); 250 350 251 Ogre::ColourValue colour((Ogre::RGBA)(*pSrcRGBA)); 252 253 if (!mergeSubMeshes) 254 { 255 this->getSubEntity(i)->setVertexColour(j,colour.getAsRGBA()); 256 } 257 else 258 { 259 this->getSubEntity(0)->setVertexColour(j,colour.getAsRGBA()); 351 Ogre::ColourValue colour; 352 colour.setAsARGB((Ogre::ARGB)(*pSrcARGB)); 353 354 if (!mergeSubMeshes) 355 { 356 this->getSubEntity(i)->setVertexColour(j,colour.getAsARGB()); 357 } 358 else 359 { 360 this->getSubEntity(0)->setVertexColour(j,colour.getAsARGB()); 361 } 260 362 } 261 363 } … … 301 403 } 302 404 303 const Ogre::VertexElement* texcoordElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);304 Ogre::HardwareVertexBufferSharedPtr vbuf = vertexData->vertexBufferBinding->getBuffer(texcoordElem->getSource());305 unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));306 307 Ogre::VertexDeclaration* decl = vertexData->vertexDeclaration;308 Ogre::VertexBufferBinding* bind = vertexData->vertexBufferBinding;309 Ogre::VertexBufferBinding::VertexBufferBindingMap::const_iterator b, bend; 310 bend = bind->getBindings().end();311 // Iterate over buffers312 for (b = bind->getBindings().begin(); b != bend; ++b)313 {314 const Ogre::HardwareVertexBufferSharedPtr vbuf = b->second;315 unsigned short bufferIdx = b->first;316 // Get all the elements that relate to this buffer317 Ogre::VertexDeclaration::VertexElementList elems = decl->findElementsBySource(bufferIdx);318 Ogre::VertexDeclaration::VertexElementList::iterator it, itend;319 itend = elems.end();320 321 // Skim over the elements to set up the general data322 unsigned short numTextureCoords = 0;323 std::vector<unsigned int> baseTexCoordSetIndex; 324 for (it = elems.begin(); it != itend; ++it)325 {326 Ogre::VertexElement& elem = *it;327 if (elem.getSemantic() == Ogre::VES_TEXTURE_COORDINATES)405 const Ogre::VertexElement* texcoordElem = NULL; 406 texcoordElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES); 407 if (texcoordElem != NULL) 408 { 409 Ogre::HardwareVertexBufferSharedPtr vbuf = vertexData->vertexBufferBinding->getBuffer(texcoordElem->getSource()); 410 unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); 411 412 Ogre::VertexDeclaration* decl = vertexData->vertexDeclaration; 413 Ogre::VertexBufferBinding* bind = vertexData->vertexBufferBinding; 414 Ogre::VertexBufferBinding::VertexBufferBindingMap::const_iterator b, bend; 415 bend = bind->getBindings().end(); 416 // Iterate over buffers 417 for (b = bind->getBindings().begin(); b != bend; ++b) 418 { 419 const Ogre::HardwareVertexBufferSharedPtr vbuf = b->second; 420 unsigned short bufferIdx = b->first; 421 // Get all the elements that relate to this buffer 422 Ogre::VertexDeclaration::VertexElementList elems = decl->findElementsBySource(bufferIdx); 423 Ogre::VertexDeclaration::VertexElementList::iterator it, itend; 424 itend = elems.end(); 425 426 // Skim over the elements to set up the general data 427 unsigned short numTextureCoords = 0; 428 std::vector<unsigned int> baseTexCoordSetIndex; 429 for (it = elems.begin(); it != itend; ++it) 328 430 { 329 if (numTextureCoords == 0) 431 Ogre::VertexElement& elem = *it; 432 if (elem.getSemantic() == Ogre::VES_TEXTURE_COORDINATES) 330 433 { 331 baseTexCoordSetIndex.push_back(0); 332 baseTexCoordSetIndex.push_back(Ogre::VertexElement::getTypeCount(elem.getType())); 434 if (numTextureCoords == 0) 435 { 436 baseTexCoordSetIndex.push_back(0); 437 baseTexCoordSetIndex.push_back(Ogre::VertexElement::getTypeCount(elem.getType())); 438 } 439 ++numTextureCoords; 333 440 } 334 ++numTextureCoords;335 441 } 336 } 337 338 // There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double 339 // as a second argument. So make it float, to avoid trouble when Ogre::Real will be 340 // compiled/typedefed as double: 341 // Ogre::Real* pReal; 342 float* pReal; 343 344 unsigned int baseTexCoord = 0; 345 unsigned int texCoordSet = 0; 346 unsigned int dimBaseTexCoord = 0; 347 for (unsigned int texCoordSet = 0; texCoordSet < numTextureCoords; texCoordSet++) 348 { 349 for (unsigned int iTexCoordSet = 0; iTexCoordSet <= texCoordSet; iTexCoordSet++) 442 443 // There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double 444 // as a second argument. So make it float, to avoid trouble when Ogre::Real will be 445 // compiled/typedefed as double: 446 // Ogre::Real* pReal; 447 float* pReal; 448 449 unsigned int baseTexCoord = 0; 450 unsigned int texCoordSet = 0; 451 unsigned int dimBaseTexCoord = 0; 452 for (unsigned int texCoordSet = 0; texCoordSet < numTextureCoords; texCoordSet++) 350 453 { 351 baseTexCoord = baseTexCoord + baseTexCoordSetIndex[iTexCoordSet]; 352 } 353 unsigned short dimTexCoord = (unsigned short)baseTexCoordSetIndex[texCoordSet+1]; 354 for (size_t j = 0; j < vertexData->vertexCount; j++, vertex += vbuf->getVertexSize()) 355 { 356 texcoordElem->baseVertexPointerToElement(vertex, &pReal); 357 Ogre::Vector3 texcoord; 358 if (baseTexCoordSetIndex[texCoordSet+1] == 2) 454 for (unsigned int iTexCoordSet = 0; iTexCoordSet <= texCoordSet; iTexCoordSet++) 359 455 { 360 texcoord = Ogre::Vector3(pReal[baseTexCoord + 0], pReal[baseTexCoord + 1], 0.0); 361 dimBaseTexCoord = 2; 456 baseTexCoord = baseTexCoord + baseTexCoordSetIndex[iTexCoordSet]; 362 457 } 363 else if (baseTexCoordSetIndex[texCoordSet + 1] == 3) 458 unsigned short dimTexCoord = (unsigned short)baseTexCoordSetIndex[texCoordSet+1]; 459 for (size_t j = 0; j < vertexData->vertexCount; j++, vertex += vbuf->getVertexSize()) 364 460 { 365 texcoord = Ogre::Vector3(pReal[baseTexCoord + 0], pReal[baseTexCoord + 1], pReal[baseTexCoord + 2]); 366 dimBaseTexCoord = 3; 367 } 368 461 texcoordElem->baseVertexPointerToElement(vertex, &pReal); 462 Ogre::Vector3 texcoord; 463 if (baseTexCoordSetIndex[texCoordSet+1] == 2) 464 { 465 texcoord = Ogre::Vector3(pReal[baseTexCoord + 0], pReal[baseTexCoord + 1], 0.0); 466 dimBaseTexCoord = 2; 467 } 468 else if (baseTexCoordSetIndex[texCoordSet + 1] == 3) 469 { 470 texcoord = Ogre::Vector3(pReal[baseTexCoord + 0], pReal[baseTexCoord + 1], pReal[baseTexCoord + 2]); 471 dimBaseTexCoord = 3; 472 } 473 474 if (!mergeSubMeshes) 475 { 476 this->getSubEntity(i)->setTexCoord(j,texCoordSet,texcoord); 477 } 478 else 479 { 480 this->getSubEntity(0)->setTexCoord(j,texCoordSet,texcoord); 481 } 482 } 483 369 484 if (!mergeSubMeshes) 370 485 { 371 this->getSubEntity(i)-> setTexCoord(j,texCoordSet,texcoord);486 this->getSubEntity(i)->addTextureCoordSet(dimBaseTexCoord); 372 487 } 373 488 else 374 489 { 375 this->getSubEntity(0)->setTexCoord(j,texCoordSet,texcoord); 490 if (i == 0) 491 { 492 this->getSubEntity(0)->addTextureCoordSet(dimBaseTexCoord); 493 } 376 494 } 377 } 378 379 if (!mergeSubMeshes) 380 { 381 this->getSubEntity(i)->addTextureCoordSet(dimBaseTexCoord); 382 } 383 else 384 { 385 if (i == 0) 386 { 387 this->getSubEntity(0)->addTextureCoordSet(dimBaseTexCoord); 388 } 389 } 390 } 391 } 392 vbuf->unlock(); 393 next_offset += vertexData->vertexCount; 495 } 496 } 497 vbuf->unlock(); 498 next_offset += vertexData->vertexCount; 499 } 394 500 } 395 501 } -
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCSubEntity.cpp
r900 r936 45 45 } 46 46 47 Ogre::Vector3 SubEntity::getTexCoord(unsigned int index, unsigned int set , unsigned int value)47 Ogre::Vector3 SubEntity::getTexCoord(unsigned int index, unsigned int set) 48 48 { 49 49 return mUniqueVertexList[index].uv[set];
Note: See TracChangeset
for help on using the changeset viewer.