本文整理汇总了C++中Model::CreateIndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Model::CreateIndexBuffer方法的具体用法?C++ Model::CreateIndexBuffer怎么用?C++ Model::CreateIndexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::CreateIndexBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init_Buffer
void GenerateLOD::Init_Buffer(fbxsdk::FbxMesh *pMesh, Model &model)
{
model.SetVertexCount(static_cast<int>(ControlP->size()));
model.SetPolygonCount(static_cast<int>(Triangles->size()));
// Create the VertexBuffer
model.CreateVertextBuffer();
IDirect3DVertexBuffer9 *g_pVB = model.GetVertexBuffer();
CUSTOMVERTEX *pVertices;
g_pVB->Lock(0, 0, (void **)&pVertices, 0);
FbxLayerElementArrayTemplate<FbxVector2> *pUVarray = NULL;
bool hasUV = pMesh->GetTextureUV(&pUVarray);
if (!hasUV) {
printf("Has No Textures!\n");
}
WORD count = 0;
std::unordered_map<int, WORD> RemainPoints;
FbxVector4 *pControlPoints = pMesh->GetControlPoints();
for (std::unordered_map<int, Point>::iterator it = (*ControlP).begin(); it != (*ControlP).end(); ++it) {
const FbxVector4 &P = pControlPoints[it->first];
pVertices[count].x = static_cast<FLOAT>(P[0]);
pVertices[count].y = static_cast<FLOAT>(P[1]);
pVertices[count].z = static_cast<FLOAT>(P[2]);
// uv coordinate
pVertices[count].tu = static_cast<FLOAT>((pUVarray->GetAt(*it->second.uvSet.begin()))[0]);
pVertices[count].tv = static_cast<FLOAT>((pUVarray->GetAt(*it->second.uvSet.begin()))[1]);
RemainPoints[it->first] = count;
++count;
}
g_pVB->Unlock();
// Create the IndexBuffer
model.CreateIndexBuffer();
IDirect3DIndexBuffer9 *g_pIB = model.GetIndexBuffer();
WORD *index;
int cnt = 0;
g_pIB->Lock(0, 0, (void **)&index, 0);
for (std::unordered_map<int, Face>::iterator it = (*Triangles).begin(); it != (*Triangles).end(); ++it) {
index[cnt++] = RemainPoints[it->second.points[0]];
index[cnt++] = RemainPoints[it->second.points[1]];
index[cnt++] = RemainPoints[it->second.points[2]];
}
g_pIB->Unlock();
}
示例2: fin
//.........这里部分代码省略.........
// Num vertices
uint32 numVertices;
fin.readUInt32(&numVertices);
// Num indices
uint32 numIndices;
fin.readUInt32(&numIndices);
// Num vertex elements
// TODO: Do we want to store this?
// Vertex buffer desc
D3D11_BUFFER_DESC vertexBufferDesc;
fin.read((char *)&vertexBufferDesc, sizeof(D3D11_BUFFER_DESC));
// Index buffer desc
D3D11_BUFFER_DESC indexBufferDesc;
fin.read((char *)&indexBufferDesc, sizeof(D3D11_BUFFER_DESC));
// Vertex data
char *vertexData = new char[vertexBufferDesc.ByteWidth];
fin.read(vertexData, vertexBufferDesc.ByteWidth);
// Index data
char *indexData = new char[indexBufferDesc.ByteWidth];
fin.read(indexData, indexBufferDesc.ByteWidth);
// Material table
MaterialTableData *materialTable = nullptr;
if ((flags & HAS_MATERIAL_TABLE) == HAS_MATERIAL_TABLE) {
uint32 numMaterials;
fin.readUInt32(&numMaterials);
materialTable = new MaterialTableData[numMaterials];
for (uint i = 0; i < numMaterials; ++i) {
fin.readUInt32(&materialTable[i].HMATFilePathIndex);
uint32 numTextures;
fin.readUInt32(&numTextures);
for (uint j = 0; j < numTextures; ++j) {
TextureData data;
fin.readUInt32(&data.FilePathIndex);
fin.readByte(&data.Sampler);
materialTable[i].Textures.push_back(data);
}
}
}
// Num subsets
uint32 numSubsets;
fin.readUInt32(&numSubsets);
// Subset data
Subset *subsets = new Subset[numSubsets];
fin.read((char *)subsets, sizeof(Subset) * numSubsets);
// Process the subsets
ModelSubset *modelSubsets = new ModelSubset[numSubsets];
for (uint i = 0; i < numSubsets; ++i) {
ZeroMemory(&modelSubsets[i], sizeof(ModelSubset));
modelSubsets[i].VertexStart = subsets[i].VertexStart;
modelSubsets[i].VertexCount = subsets[i].VertexCount;
modelSubsets[i].IndexStart = subsets[i].IndexStart;
modelSubsets[i].IndexCount = subsets[i].IndexCount;
modelSubsets[i].AABB_min = subsets[i].AABB_min;
modelSubsets[i].AABB_max = subsets[i].AABB_max;
MaterialTableData materialData = materialTable[subsets[i].MaterialIndex];
std::wstring hmatFilePath = Common::ToWideStr(stringTable[materialData.HMATFilePathIndex]);
Graphics::MaterialShader *shader = materialShaderManager->GetShader(device, hmatFilePath);
std::vector<ID3D11ShaderResourceView *> textureSRVs;
std::vector<ID3D11SamplerState *> textureSamplers;
for (uint j = 0; j < materialData.Textures.size(); ++j) {
std::wstring wideFileName(stringTable[materialData.Textures[j].FilePathIndex].begin(), stringTable[materialData.Textures[j].FilePathIndex].end());
textureSRVs.push_back(textureManager->GetSRVFromFile(device, wideFileName, D3D11_USAGE_IMMUTABLE));
textureSamplers.push_back(GetSamplerStateFromSamplerType(static_cast<TextureSampler>(materialData.Textures[j].Sampler), samplerStateManager));
}
modelSubsets[i].Material = materialCache->getMaterial(shader, textureSRVs, textureSamplers);
}
// Cleanup
delete[] stringTable;
delete[] materialTable;
delete[] subsets;
// Create the model with the read data
Model *model = new Model();
model->CreateVertexBuffer(device, vertexData, numVertices, vertexBufferDesc);
model->CreateIndexBuffer(device, (uint *)indexData, numIndices, indexBufferDesc);
model->CreateSubsets(modelSubsets, numSubsets);
return model;
}