本文整理汇总了C++中CConversionMesh类的典型用法代码示例。如果您正苦于以下问题:C++ CConversionMesh类的具体用法?C++ CConversionMesh怎么用?C++ CConversionMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CConversionMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderSetupSceneNode
void CAOGenerator::RenderSetupSceneNode(CConversionSceneNode* pNode, tvector<tvector<float>>& aaflVerts)
{
if (!pNode)
return;
for (size_t c = 0; c < pNode->GetNumChildren(); c++)
RenderSetupSceneNode(pNode->GetChild(c), aaflVerts);
for (size_t m = 0; m < pNode->GetNumMeshInstances(); m++)
{
CConversionMeshInstance* pMeshInstance = pNode->GetMeshInstance(m);
CConversionMesh* pMesh = pMeshInstance->GetMesh();
for (size_t f = 0; f < pMesh->GetNumFaces(); f++)
{
CConversionFace* pFace = pMesh->GetFace(f);
size_t iMaterial = pMeshInstance->GetMappedMaterial(pFace->m)->m_iMaterial;
while (aaflVerts.size() <= iMaterial)
aaflVerts.push_back();
CConversionVertex* pVertex0 = pFace->GetVertex(0);
for (size_t k = 2; k < pFace->GetNumVertices(); k++)
{
CConversionVertex* pVertex1 = pFace->GetVertex(k-1);
CConversionVertex* pVertex2 = pFace->GetVertex(k);
AddRenderedVertex(aaflVerts[iMaterial], pMeshInstance->GetVertex(pVertex0->v), pMesh->GetUV(pVertex0->vu));
AddRenderedVertex(aaflVerts[iMaterial], pMeshInstance->GetVertex(pVertex1->v), pMesh->GetUV(pVertex1->vu));
AddRenderedVertex(aaflVerts[iMaterial], pMeshInstance->GetVertex(pVertex2->v), pMesh->GetUV(pVertex2->vu));
}
}
}
}
示例2: LoadMeshInstanceIntoToyPhysics
void CGeppetto::LoadMeshInstanceIntoToyPhysics(CConversionScene* pScene, CConversionMeshInstance* pMeshInstance, const Matrix4x4& mParentTransformations, CToyUtil* pToy)
{
if (!pMeshInstance->IsVisible())
return;
CConversionMesh* pMesh = pMeshInstance->GetMesh();
size_t iVertsSize = pToy->GetNumPhysVerts();
for (size_t v = 0; v < pMesh->GetNumVertices(); v++)
pToy->AddPhysVertex(mParentTransformations * pMesh->GetVertex(v));
for (size_t j = 0; j < pMesh->GetNumFaces(); j++)
{
size_t k;
CConversionFace* pFace = pMesh->GetFace(j);
CConversionVertex* pVertex0 = pFace->GetVertex(0);
for (k = 2; k < pFace->GetNumVertices(); k++)
{
CConversionVertex* pVertex1 = pFace->GetVertex(k-1);
CConversionVertex* pVertex2 = pFace->GetVertex(k);
pToy->AddPhysTriangle(iVertsSize + pVertex0->v, iVertsSize + pVertex1->v, iVertsSize + pVertex2->v);
}
}
}
示例3: GenerateNodeByTexel
void CAOGenerator::GenerateNodeByTexel(CConversionSceneNode* pNode, raytrace::CRaytracer* pTracer, size_t& iRendered)
{
for (size_t c = 0; c < pNode->GetNumChildren(); c++)
GenerateNodeByTexel(pNode->GetChild(c), pTracer, iRendered);
for (size_t m = 0; m < pNode->GetNumMeshInstances(); m++)
{
CConversionMeshInstance* pMeshInstance = pNode->GetMeshInstance(m);
CConversionMesh* pMesh = pMeshInstance->GetMesh();
if (!pMesh->GetNumUVs())
continue;
for (size_t f = 0; f < pMesh->GetNumFaces(); f++)
{
CConversionFace* pFace = pMesh->GetFace(f);
if (pFace->m != ~0)
{
if (!pMeshInstance->GetMappedMaterial(pFace->m)->IsVisible())
continue;
CConversionMaterial* pMaterial = m_pScene->GetMaterial(pMeshInstance->GetMappedMaterial(pFace->m)->m_iMaterial);
if (pMaterial && !pMaterial->IsVisible())
continue;
}
tvector<Vector> avecPoints;
tvector<size_t> aiPoints;
for (size_t t = 0; t < pFace->GetNumVertices(); t++)
{
avecPoints.push_back(pMeshInstance->GetVertex(pFace->GetVertex(t)->v));
aiPoints.push_back(t);
}
while (avecPoints.size() > 3)
{
size_t iEar = FindEar(avecPoints);
size_t iLast = iEar==0?avecPoints.size()-1:iEar-1;
size_t iNext = iEar==avecPoints.size()-1?0:iEar+1;
GenerateTriangleByTexel(pMeshInstance, pFace, aiPoints[iLast], aiPoints[iEar], aiPoints[iNext], pTracer, iRendered);
avecPoints.erase(avecPoints.begin()+iEar);
aiPoints.erase(aiPoints.begin()+iEar);
if (m_bStopGenerating)
break;
}
GenerateTriangleByTexel(pMeshInstance, pFace, aiPoints[0], aiPoints[1], aiPoints[2], pTracer, iRendered);
if (m_bStopGenerating)
break;
}
if (m_bStopGenerating)
break;
}
}
示例4: RaytraceSetupThreads
void CAOGenerator::GenerateByTexel()
{
if (m_eAOMethod == AOMETHOD_RAYTRACE)
RaytraceSetupThreads();
float flTotalArea = 0;
for (size_t m = 0; m < m_pScene->GetNumMeshes(); m++)
{
CConversionMesh* pMesh = m_pScene->GetMesh(m);
for (size_t f = 0; f < pMesh->GetNumFaces(); f++)
{
CConversionFace* pFace = pMesh->GetFace(f);
flTotalArea += pFace->GetUVArea();
}
}
raytrace::CRaytracer* pTracer = NULL;
if (m_eAOMethod == AOMETHOD_RAYTRACE)
{
m_pWorkListener->SetAction("Building tree", 0);
pTracer = new raytrace::CRaytracer(m_pScene);
pTracer->AddMeshesFromNode(m_pScene->GetScene(0));
pTracer->BuildTree();
srand((unsigned int)time(0));
}
if (m_eAOMethod == AOMETHOD_RAYTRACE && GetNumberOfProcessors() > 1)
m_pWorkListener->SetAction("Dispatching jobs", (size_t)(flTotalArea*m_iWidth*m_iHeight));
else
m_pWorkListener->SetAction("Rendering", (size_t)(flTotalArea*m_iWidth*m_iHeight));
size_t iRendered = 0;
if (m_pScene->GetNumScenes())
GenerateNodeByTexel(m_pScene->GetScene(0), pTracer, iRendered);
if (m_eAOMethod == AOMETHOD_RAYTRACE)
{
RaytraceJoinThreads();
RaytraceCleanupThreads();
delete pTracer;
}
}
示例5: ShadowMapSetupSceneNode
void CAOGenerator::ShadowMapSetupSceneNode(CConversionSceneNode* pNode, tvector<float>& aflVerts, bool bDepth)
{
if (!pNode)
return;
for (size_t c = 0; c < pNode->GetNumChildren(); c++)
ShadowMapSetupSceneNode(pNode->GetChild(c), aflVerts, bDepth);
for (size_t m = 0; m < pNode->GetNumMeshInstances(); m++)
{
CConversionMeshInstance* pMeshInstance = pNode->GetMeshInstance(m);
CConversionMesh* pMesh = pMeshInstance->GetMesh();
for (size_t f = 0; f < pMesh->GetNumFaces(); f++)
{
CConversionFace* pFace = pMesh->GetFace(f);
if (!bDepth)
{
// Allow this in the depth model so that it still projects a shadow, but we don't produce a map for it.
if (pFace->m != ~0 && pMeshInstance->GetMappedMaterial(pFace->m))
{
if (!pMeshInstance->GetMappedMaterial(pFace->m)->IsVisible())
continue;
CConversionMaterial* pMaterial = m_pScene->GetMaterial(pMeshInstance->GetMappedMaterial(pFace->m)->m_iMaterial);
if (pMaterial && !pMaterial->IsVisible())
continue;
}
}
CConversionVertex* pVertex0 = pFace->GetVertex(0);
for (size_t k = 2; k < pFace->GetNumVertices(); k++)
{
CConversionVertex* pVertex1 = pFace->GetVertex(k-1);
CConversionVertex* pVertex2 = pFace->GetVertex(k);
AddShadowMapVertex(aflVerts, pMeshInstance->GetVertex(pVertex0->v), pMeshInstance->GetNormal(pVertex0->vn), pMesh->GetUV(pVertex0->vu));
AddShadowMapVertex(aflVerts, pMeshInstance->GetVertex(pVertex1->v), pMeshInstance->GetNormal(pVertex1->vn), pMesh->GetUV(pVertex1->vu));
AddShadowMapVertex(aflVerts, pMeshInstance->GetVertex(pVertex2->v), pMeshInstance->GetNormal(pVertex2->vn), pMesh->GetUV(pVertex2->vu));
}
}
}
}
示例6: LoadMeshInstanceIntoToy
void LoadMeshInstanceIntoToy(CConversionScene* pScene, CConversionMeshInstance* pMeshInstance, const Matrix4x4& mParentTransformations)
{
if (!pMeshInstance->IsVisible())
return;
CConversionMesh* pMesh = pMeshInstance->GetMesh();
for (size_t m = 0; m < pScene->GetNumMaterials(); m++)
{
for (size_t j = 0; j < pMesh->GetNumFaces(); j++)
{
size_t k;
CConversionFace* pFace = pMesh->GetFace(j);
if (pFace->m == ~0)
continue;
CConversionMaterial* pMaterial = NULL;
CConversionMaterialMap* pConversionMaterialMap = pMeshInstance->GetMappedMaterial(pFace->m);
if (!pConversionMaterialMap)
continue;
if (!pConversionMaterialMap->IsVisible())
continue;
if (pConversionMaterialMap->m_iMaterial != m)
continue;
while (g_asTextures.size() <= pConversionMaterialMap->m_iMaterial)
{
g_asTextures.push_back(pScene->GetMaterial(pConversionMaterialMap->m_iMaterial)->GetDiffuseTexture());
g_aaflData.push_back();
}
size_t iMaterial = pConversionMaterialMap->m_iMaterial;
CConversionVertex* pVertex0 = pFace->GetVertex(0);
for (k = 2; k < pFace->GetNumVertices(); k++)
{
CConversionVertex* pVertex1 = pFace->GetVertex(k-1);
CConversionVertex* pVertex2 = pFace->GetVertex(k);
AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex0->v), pMesh->GetUV(pVertex0->vu));
AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex1->v), pMesh->GetUV(pVertex1->vu));
AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex2->v), pMesh->GetUV(pVertex2->vu));
}
}
}
}
示例7: tfopen
void CModelConverter::ReadOBJ(const tstring& sFilename)
{
if (m_pWorkListener)
m_pWorkListener->BeginProgress();
FILE* fp = tfopen(sFilename, _T("r"));
if (!fp)
{
printf("No input file. Sorry!\n");
return;
}
CConversionSceneNode* pScene = m_pScene->GetScene(m_pScene->AddScene(GetFilename(sFilename).append(_T(".obj"))));
CConversionMesh* pMesh = m_pScene->GetMesh(m_pScene->AddMesh(GetFilename(sFilename)));
// Make sure it exists.
CConversionSceneNode* pMeshNode = m_pScene->GetDefaultSceneMeshInstance(pScene, pMesh);
size_t iCurrentMaterial = ~0;
size_t iSmoothingGroup = ~0;
bool bSmoothingGroups = false;
tstring sLastTask;
int iTotalVertices = 0;
int iTotalFaces = 0;
int iVerticesComplete = 0;
int iFacesComplete = 0;
if (m_pWorkListener)
m_pWorkListener->SetAction(_T("Reading file into memory..."), 0);
fseek(fp, 0L, SEEK_END);
long iOBJSize = ftell(fp);
fseek(fp, 0L, SEEK_SET);
// Make sure we allocate more than we need just in case.
size_t iFileSize = (iOBJSize+1) * (sizeof(tchar)+1);
tchar* pszEntireFile = (tchar*)malloc(iFileSize);
tchar* pszCurrent = pszEntireFile;
pszCurrent[0] = _T('\0');
// Read the entire file into an array first for faster processing.
tstring sLine;
while (fgetts(sLine, fp))
{
tstrncpy(pszCurrent, iFileSize-(pszCurrent-pszEntireFile), sLine.c_str(), sLine.length());
size_t iLength = sLine.length();
tchar cLastChar = pszCurrent[iLength-1];
while (cLastChar == _T('\n') || cLastChar == _T('\r'))
{
pszCurrent[iLength-1] = _T('\0');
iLength--;
cLastChar = pszCurrent[iLength-1];
}
pszCurrent += iLength;
pszCurrent++;
if (m_pWorkListener)
m_pWorkListener->WorkProgress(0);
}
pszCurrent[0] = _T('\0');
fclose(fp);
const tchar* pszLine = pszEntireFile;
const tchar* pszNextLine = NULL;
while (pszLine < pszCurrent)
{
if (pszNextLine)
pszLine = pszNextLine;
pszNextLine = pszLine + tstrlen(pszLine) + 1;
// This code used to call StripWhitespace() but that's too slow for very large files w/ millions of lines.
// Instead we'll just cut the whitespace off the front and deal with whitespace on the end when we come to it.
while (*pszLine && IsWhitespace(*pszLine))
pszLine++;
if (tstrlen(pszLine) == 0)
continue;
if (pszLine[0] == '#')
{
// ZBrush is kind enough to notate exactly how many vertices and faces we have in the comments at the top of the file.
if (tstrncmp(pszLine, _T("#Vertex Count"), 13) == 0)
{
iTotalVertices = stoi(pszLine+13);
pMesh->SetTotalVertices(iTotalVertices);
}
if (tstrncmp(pszLine, _T("#Face Count"), 11) == 0)
{
iTotalFaces = stoi(pszLine+11);
pMesh->SetTotalFaces(iTotalFaces);
//.........这里部分代码省略.........
示例8: ReadSIAShape
const tchar* CModelConverter::ReadSIAShape(const tchar* pszLine, const tchar* pszEnd, CConversionSceneNode* pScene, bool bCare)
{
size_t iCurrentMaterial = ~0;
CConversionMesh* pMesh = NULL;
CConversionSceneNode* pMeshNode = NULL;
size_t iAddV = 0;
size_t iAddE = 0;
size_t iAddUV = 0;
size_t iAddN = 0;
tstring sLastTask;
tstring sToken;
const tchar* pszNextLine = NULL;
while (pszLine < pszEnd)
{
if (pszNextLine)
pszLine = pszNextLine;
size_t iLineLength = tstrlen(pszLine);
pszNextLine = pszLine + iLineLength + 1;
// This code used to call StripWhitespace() but that's too slow for very large files w/ millions of lines.
// Instead we'll just cut the whitespace off the front and deal with whitespace on the end when we come to it.
while (*pszLine && IsWhitespace(*pszLine))
pszLine++;
if (tstrlen(pszLine) == 0)
continue;
const tchar* pszToken = pszLine;
while (*pszToken && *pszToken != ' ')
pszToken++;
sToken.reserve(iLineLength);
sToken.clear();
sToken.append(pszLine, pszToken-pszLine);
pszToken = sToken.c_str();
if (!bCare)
{
if (tstrncmp(pszToken, "-endShape", 9) == 0)
return pszNextLine;
else
continue;
}
if (tstrncmp(pszToken, "-snam", 5) == 0)
{
// We name our mesh.
tstring sName =pszLine+6;
tvector<tstring> aName;
tstrtok(sName, aName, "\""); // Strip out the quotation marks.
if (bCare)
{
size_t iMesh = m_pScene->FindMesh(aName[0].c_str());
if (iMesh == (size_t)~0)
{
iMesh = m_pScene->AddMesh(aName[0].c_str());
pMesh = m_pScene->GetMesh(iMesh);
pMesh->AddBone(aName[0].c_str());
}
else
{
pMesh = m_pScene->GetMesh(iMesh);
iAddV = pMesh->GetNumVertices();
iAddE = pMesh->GetNumEdges();
iAddUV = pMesh->GetNumUVs();
iAddN = pMesh->GetNumNormals();
}
// Make sure it exists.
pMeshNode = m_pScene->GetDefaultSceneMeshInstance(pScene, pMesh);
}
}
else if (tstrncmp(pszToken, "-vert", 5) == 0)
{
if (m_pWorkListener)
{
if (sLastTask == pszToken)
m_pWorkListener->WorkProgress(0);
else
{
m_pWorkListener->SetAction("Reading vertex data", 0);
sLastTask = tstring(pszToken);
}
}
// A vertex.
float v[3];
// scanf is pretty slow even for such a short string due to lots of mallocs.
const tchar* pszToken = pszLine+5;
int iDimension = 0;
while (*pszToken)
{
while (pszToken[0] == ' ')
pszToken++;
//.........这里部分代码省略.........
示例9: GenerateTexel
void CTexelDiffuseMethod::GenerateTexel(size_t iTexel, CConversionMeshInstance* pMeshInstance, CConversionFace* pFace, CConversionVertex* pV1, CConversionVertex* pV2, CConversionVertex* pV3, raytrace::CTraceResult* tr, const Vector& vecUVPosition, raytrace::CRaytracer* pTracer)
{
CConversionFace* pHitFace = tr->m_pMeshInstance->GetMesh()->GetFace(tr->m_iFace);
CTexture& oTexture = m_aTextures[tr->m_pMeshInstance->GetMappedMaterial(pHitFace->m)->m_iMaterial];
if (!oTexture.m_pclrData)
return;
CConversionMesh* pHitMesh = tr->m_pMeshInstance->GetMesh();
// TODO: Use the nearest triangle in this face.
CConversionVertex* pHitV1 = pHitFace->GetVertex(0);
CConversionVertex* pHitV2 = pHitFace->GetVertex(1);
CConversionVertex* pHitV3 = pHitFace->GetVertex(2);
Vector2D vu1 = pHitMesh->GetUV(pHitV1->vu);
Vector2D vu2 = pHitMesh->GetUV(pHitV2->vu);
Vector2D vu3 = pHitMesh->GetUV(pHitV3->vu);
Vector v1 = tr->m_pMeshInstance->GetVertex(pHitV1->v);
Vector v2 = tr->m_pMeshInstance->GetVertex(pHitV2->v);
Vector v3 = tr->m_pMeshInstance->GetVertex(pHitV3->v);
// Find where the world point is in UV space.
// First convert to barycentric coordinates.
Vector u = v2 - v1;
Vector v = v3 - v1;
float uu = u.Dot(u);
float uv = u.Dot(v);
float vv = v.Dot(v);
Vector w = tr->m_vecHit - v1;
float wu = w.Dot(u);
float wv = w.Dot(v);
float D = uv * uv - uu * vv;
float b1, b2, b3;
b1 = (uv * wu - uu * wv) / D;
b2 = (uv * wv - vv * wu) / D;
b3 = 1 - b1 - b2;
// The position of the traceline's hit in (u, v) texture space
Vector2D vecWorldPosition = vu1 * b1 + vu2 * b2 + vu3 * b3;
// Mutex may be dead, try to bail before.
if (m_pGenerator->IsStopped())
return;
size_t iU = (size_t)((vecWorldPosition.x * oTexture.m_iWidth) - 0.5f);
size_t iV = (size_t)((vecWorldPosition.y * oTexture.m_iHeight) - 0.5f);
iU %= oTexture.m_iWidth;
iV %= oTexture.m_iHeight;
size_t iColorTexel;
m_pGenerator->Texel(iU, iV, iColorTexel, oTexture.m_iWidth, oTexture.m_iHeight);
Color clrData = oTexture.m_pclrData[iColorTexel];
m_pGenerator->GetParallelizer()->LockData();
m_avecDiffuseValues[iTexel] += Vector(clrData);
m_aiDiffuseReads[iTexel]++;
m_pGenerator->MarkTexelUsed(iTexel);
m_pGenerator->GetParallelizer()->UnlockData();
}
示例10: tstring
void CModelConverter::SaveOBJ(const tstring& sFilename)
{
tstring sMaterialFileName = tstring(GetDirectory(sFilename).c_str()) + _T("/") + GetFilename(sFilename).c_str() + _T(".mtl");
std::wofstream sMaterialFile(convertstring<tchar, char>(sMaterialFileName).c_str());
if (!sMaterialFile.is_open())
return;
if (m_pWorkListener)
{
m_pWorkListener->BeginProgress();
m_pWorkListener->SetAction(_T("Writing materials file"), 0);
}
for (size_t i = 0; i < m_pScene->GetNumMaterials(); i++)
{
CConversionMaterial* pMaterial = m_pScene->GetMaterial(i);
sMaterialFile << "newmtl " << pMaterial->GetName().c_str() << std::endl;
sMaterialFile << "Ka " << pMaterial->m_vecAmbient.x << _T(" ") << pMaterial->m_vecAmbient.y << _T(" ") << pMaterial->m_vecAmbient.z << std::endl;
sMaterialFile << "Kd " << pMaterial->m_vecDiffuse.x << _T(" ") << pMaterial->m_vecDiffuse.y << _T(" ") << pMaterial->m_vecDiffuse.z << std::endl;
sMaterialFile << "Ks " << pMaterial->m_vecSpecular.x << _T(" ") << pMaterial->m_vecSpecular.y << _T(" ") << pMaterial->m_vecSpecular.z << std::endl;
sMaterialFile << "d " << pMaterial->m_flTransparency << std::endl;
sMaterialFile << "Ns " << pMaterial->m_flShininess << std::endl;
sMaterialFile << "illum " << pMaterial->m_eIllumType << std::endl;
if (pMaterial->GetDiffuseTexture().length() > 0)
sMaterialFile << "map_Kd " << pMaterial->GetDiffuseTexture().c_str() << std::endl;
sMaterialFile << std::endl;
}
sMaterialFile.close();
for (size_t i = 0; i < m_pScene->GetNumMeshes(); i++)
{
CConversionMesh* pMesh = m_pScene->GetMesh(i);
// Find the default scene for this mesh.
CConversionSceneNode* pScene = NULL;
for (size_t j = 0; j < m_pScene->GetNumScenes(); j++)
{
if (m_pScene->GetScene(j)->GetName() == pMesh->GetName() + _T(".obj"))
{
pScene = m_pScene->GetScene(j);
break;
}
}
tstring sNodeName = pMesh->GetName();
tstring sOBJFilename = tstring(GetDirectory(sFilename).c_str()) + _T("/") + GetFilename(sNodeName).c_str() + _T(".obj");
tstring sMTLFilename = tstring(GetFilename(sFilename).c_str()) + _T(".mtl");
if (m_pScene->GetNumMeshes() == 1)
sOBJFilename = sFilename;
std::wofstream sOBJFile(convertstring<tchar, char>(sOBJFilename).c_str());
sOBJFile.precision(8);
sOBJFile.setf(std::ios::fixed, std::ios::floatfield);
sOBJFile << _T("mtllib ") << sMTLFilename.c_str() << std::endl;
sOBJFile << std::endl;
sOBJFile << _T("o ") << sNodeName.c_str() << std::endl;
if (m_pWorkListener)
m_pWorkListener->SetAction((tstring(_T("Writing ")) + sNodeName + _T(" vertices...")).c_str(), pMesh->GetNumVertices());
for (size_t iVertices = 0; iVertices < pMesh->GetNumVertices(); iVertices++)
{
if (m_pWorkListener)
m_pWorkListener->WorkProgress(iVertices);
Vector vecVertex = pMesh->GetVertex(iVertices);
sOBJFile << _T("v ") << vecVertex.x << _T(" ") << vecVertex.y << _T(" ") << vecVertex.z << std::endl;
}
if (m_pWorkListener)
m_pWorkListener->SetAction((tstring(_T("Writing ")) + sNodeName + _T(" normals...")).c_str(), pMesh->GetNumNormals());
for (size_t iNormals = 0; iNormals < pMesh->GetNumNormals(); iNormals++)
{
if (m_pWorkListener)
m_pWorkListener->WorkProgress(iNormals);
Vector vecNormal = pMesh->GetNormal(iNormals);
sOBJFile << _T("vn ") << vecNormal.x << _T(" ") << vecNormal.y << _T(" ") << vecNormal.z << std::endl;
}
if (m_pWorkListener)
m_pWorkListener->SetAction((tstring(_T("Writing ")) + sNodeName + _T(" UVs...")).c_str(), pMesh->GetNumUVs());
for (size_t iUVs = 0; iUVs < pMesh->GetNumUVs(); iUVs++)
{
if (m_pWorkListener)
m_pWorkListener->WorkProgress(iUVs);
Vector vecUV = pMesh->GetUV(iUVs);
sOBJFile << _T("vt ") << vecUV.x << _T(" ") << vecUV.y << std::endl;
}
if (m_pWorkListener)
//.........这里部分代码省略.........
示例11: GenerateTriangleByTexel
void CTexelGenerator::GenerateTriangleByTexel(CConversionMeshInstance* pMeshInstance, CConversionFace* pFace, size_t v1, size_t v2, size_t v3, raytrace::CRaytracer* pTracer, size_t& iRendered)
{
texel_data_t oJob;
CConversionVertex* pV1 = pFace->GetVertex(v1);
CConversionVertex* pV2 = pFace->GetVertex(v2);
CConversionVertex* pV3 = pFace->GetVertex(v3);
CConversionMesh* pMesh = pMeshInstance->GetMesh();
oJob.pMeshInstance = pMeshInstance;
oJob.pFace = pFace;
oJob.pV1 = pV1;
oJob.pV2 = pV2;
oJob.pV3 = pV3;
oJob.pTracer = pTracer;
oJob.pGenerator = this;
Vector vu1 = pMesh->GetUV(pV1->vu);
Vector vu2 = pMesh->GetUV(pV2->vu);
Vector vu3 = pMesh->GetUV(pV3->vu);
Vector vecLoUV = vu1;
Vector vecHiUV = vu1;
if (vu2.x < vecLoUV.x)
vecLoUV.x = vu2.x;
if (vu3.x < vecLoUV.x)
vecLoUV.x = vu3.x;
if (vu2.x > vecHiUV.x)
vecHiUV.x = vu2.x;
if (vu3.x > vecHiUV.x)
vecHiUV.x = vu3.x;
if (vu2.y < vecLoUV.y)
vecLoUV.y = vu2.y;
if (vu3.y < vecLoUV.y)
vecLoUV.y = vu3.y;
if (vu2.y > vecHiUV.y)
vecHiUV.y = vu2.y;
if (vu3.y > vecHiUV.y)
vecHiUV.y = vu3.y;
size_t iLoX = (size_t)(vecLoUV.x * m_iWidth);
size_t iLoY = (size_t)(vecLoUV.y * m_iHeight);
size_t iHiX = (size_t)(vecHiUV.x * m_iWidth);
size_t iHiY = (size_t)(vecHiUV.y * m_iHeight);
for (size_t i = iLoX; i <= iHiX; i++)
{
for (size_t j = iLoY; j <= iHiY; j++)
{
oJob.x = i;
oJob.y = j;
m_pWorkParallelizer->AddJob(&oJob, sizeof(oJob));
if (m_pWorkListener)
m_pWorkListener->WorkProgress(++iRendered);
if (m_bStopGenerating)
break;
}
if (m_bStopGenerating)
break;
}
}
示例12: FindHiResMeshLocation
void CTexelGenerator::FindHiResMeshLocation(CConversionMeshInstance* pMeshInstance, CConversionFace* pFace, CConversionVertex* pV1, CConversionVertex* pV2, CConversionVertex* pV3, size_t i, size_t j, raytrace::CRaytracer* pTracer)
{
CConversionMesh* pMesh = pMeshInstance->GetMesh();
Vector vu1 = pMesh->GetUV(pV1->vu);
Vector vu2 = pMesh->GetUV(pV2->vu);
Vector vu3 = pMesh->GetUV(pV3->vu);
float flU = ((float)i + 0.5f)/(float)m_iWidth;
float flV = ((float)j + 0.5f)/(float)m_iHeight;
bool bInside = PointInTriangle(Vector(flU,flV,0), vu1, vu2, vu3);
if (!bInside)
return;
Vector v1 = pMeshInstance->GetVertex(pV1->v);
Vector v2 = pMeshInstance->GetVertex(pV2->v);
Vector v3 = pMeshInstance->GetVertex(pV3->v);
// Find where the UV is in world space.
// First build 2x2 a "matrix" of the UV values.
float mta = vu2.x - vu1.x;
float mtb = vu3.x - vu1.x;
float mtc = vu2.y - vu1.y;
float mtd = vu3.y - vu1.y;
// Invert it.
float d = mta*mtd - mtb*mtc;
float mtia = mtd / d;
float mtib = -mtb / d;
float mtic = -mtc / d;
float mtid = mta / d;
// Now build a 2x3 "matrix" of the vertices.
float mva = v2.x - v1.x;
float mvb = v3.x - v1.x;
float mvc = v2.y - v1.y;
float mvd = v3.y - v1.y;
float mve = v2.z - v1.z;
float mvf = v3.z - v1.z;
// Multiply them together.
// [a b] [a b] [a b]
// [c d] * [c d] = [c d]
// [e f] [e f]
// Really wish I had a matrix math library about now!
float mra = mva*mtia + mvb*mtic;
float mrb = mva*mtib + mvb*mtid;
float mrc = mvc*mtia + mvd*mtic;
float mrd = mvc*mtib + mvd*mtid;
float mre = mve*mtia + mvf*mtic;
float mrf = mve*mtib + mvf*mtid;
// These vectors should be the U and V axis in world space.
Vector vecUAxis(mra, mrc, mre);
Vector vecVAxis(mrb, mrd, mrf);
Vector vecUVOrigin = v1 - vecUAxis * vu1.x - vecVAxis * vu1.y;
Vector vecUVPosition = vecUVOrigin + vecUAxis * flU + vecVAxis * flV;
Vector vecNormal = pFace->GetNormal(vecUVPosition, pMeshInstance);
size_t iTexel;
Texel(i, j, iTexel, false);
// Maybe use a closest-poly check here to eliminate the need for some raytracing?
raytrace::CTraceResult trFront;
bool bHitFront = pTracer->Raytrace(Ray(vecUVPosition, vecNormal), &trFront);
raytrace::CTraceResult trBack;
bool bHitBack = pTracer->Raytrace(Ray(vecUVPosition, -vecNormal), &trBack);
#ifdef NORMAL_DEBUG
GetParallelizer()->LockData();
if (bHitFront && (vecUVPosition - trFront.m_vecHit).LengthSqr() > 0.001f)
SMAKWindow()->AddDebugLine(vecUVPosition, trFront.m_vecHit);
if (bHitBack && (vecUVPosition - trBack.m_vecHit).LengthSqr() > 0.001f)
SMAKWindow()->AddDebugLine(vecUVPosition, trBack.m_vecHit);
GetParallelizer()->UnlockData();
#endif
if (!bHitBack && !bHitFront)
return;
raytrace::CTraceResult* trFinal;
if (bHitFront && !bHitBack)
trFinal = &trFront;
else if (bHitBack && !bHitFront)
trFinal = &trBack;
else
{
float flHitFront = (vecUVPosition - trFront.m_vecHit).LengthSqr();
float flHitBack = (vecUVPosition - trBack.m_vecHit).LengthSqr();
if (flHitFront < flHitBack)
//.........这里部分代码省略.........
示例13: GenerateTriangleByTexel
void CAOGenerator::GenerateTriangleByTexel(CConversionMeshInstance* pMeshInstance, CConversionFace* pFace, size_t v1, size_t v2, size_t v3, raytrace::CRaytracer* pTracer, size_t& iRendered)
{
CConversionVertex* pV1 = pFace->GetVertex(v1);
CConversionVertex* pV2 = pFace->GetVertex(v2);
CConversionVertex* pV3 = pFace->GetVertex(v3);
CConversionMesh* pMesh = pMeshInstance->GetMesh();
Vector vu1 = pMesh->GetUV(pV1->vu);
Vector vu2 = pMesh->GetUV(pV2->vu);
Vector vu3 = pMesh->GetUV(pV3->vu);
Vector vecLoUV = vu1;
Vector vecHiUV = vu1;
if (vu2.x < vecLoUV.x)
vecLoUV.x = vu2.x;
if (vu3.x < vecLoUV.x)
vecLoUV.x = vu3.x;
if (vu2.x > vecHiUV.x)
vecHiUV.x = vu2.x;
if (vu3.x > vecHiUV.x)
vecHiUV.x = vu3.x;
if (vu2.y < vecLoUV.y)
vecLoUV.y = vu2.y;
if (vu3.y < vecLoUV.y)
vecLoUV.y = vu3.y;
if (vu2.y > vecHiUV.y)
vecHiUV.y = vu2.y;
if (vu3.y > vecHiUV.y)
vecHiUV.y = vu3.y;
size_t iLoX = (size_t)(vecLoUV.x * m_iWidth);
size_t iLoY = (size_t)(vecLoUV.y * m_iHeight);
size_t iHiX = (size_t)(vecHiUV.x * m_iWidth);
size_t iHiY = (size_t)(vecHiUV.y * m_iHeight);
for (size_t i = iLoX; i <= iHiX; i++)
{
for (size_t j = iLoY; j <= iHiY; j++)
{
float flU = ((float)i + 0.5f)/(float)m_iWidth;
float flV = ((float)j + 0.5f)/(float)m_iHeight;
bool bInside = PointInTriangle(Vector(flU,flV,0), vu1, vu2, vu3);
if (!bInside)
continue;
Vector v1 = pMeshInstance->GetVertex(pV1->v);
Vector v2 = pMeshInstance->GetVertex(pV2->v);
Vector v3 = pMeshInstance->GetVertex(pV3->v);
Vector vn1 = pMeshInstance->GetNormal(pV1->vn);
Vector vn2 = pMeshInstance->GetNormal(pV2->vn);
Vector vn3 = pMeshInstance->GetNormal(pV3->vn);
// Find where the UV is in world space.
// First build 2x2 a "matrix" of the UV values.
float mta = vu2.x - vu1.x;
float mtb = vu3.x - vu1.x;
float mtc = vu2.y - vu1.y;
float mtd = vu3.y - vu1.y;
// Invert it.
float d = mta*mtd - mtb*mtc;
float mtia = mtd / d;
float mtib = -mtb / d;
float mtic = -mtc / d;
float mtid = mta / d;
// Now build a 2x3 "matrix" of the vertices.
float mva = v2.x - v1.x;
float mvb = v3.x - v1.x;
float mvc = v2.y - v1.y;
float mvd = v3.y - v1.y;
float mve = v2.z - v1.z;
float mvf = v3.z - v1.z;
// Multiply them together.
// [a b] [a b] [a b]
// [c d] * [c d] = [c d]
// [e f] [e f]
// Really wish I had a matrix math library about now!
float mra = mva*mtia + mvb*mtic;
float mrb = mva*mtib + mvb*mtid;
float mrc = mvc*mtia + mvd*mtic;
float mrd = mvc*mtib + mvd*mtid;
float mre = mve*mtia + mvf*mtic;
float mrf = mve*mtib + mvf*mtid;
// These vectors should be the U and V axis in world space.
Vector vecUAxis(mra, mrc, mre);
Vector vecVAxis(mrb, mrd, mrf);
Vector vecUVOrigin = v1 - vecUAxis * vu1.x - vecVAxis * vu1.y;
Vector vecUVPosition = vecUVOrigin + vecUAxis * flU + vecVAxis * flV;
//.........这里部分代码省略.........
示例14: LoadMesh
void LoadMesh(CConversionScene* pScene, size_t iMesh)
{
TAssert(iMesh < pScene->GetNumMeshes());
if (iMesh >= pScene->GetNumMeshes())
return;
// Reserve space for n+1, the last one represents the default material.
g_aaflData.resize(pScene->GetNumMaterials()+1);
tvector<Vector> avecPoints;
tvector<size_t> aiPoints;
CConversionMesh* pMesh = pScene->GetMesh(iMesh);
for (size_t j = 0; j < pMesh->GetNumFaces(); j++)
{
CConversionFace* pFace = pMesh->GetFace(j);
size_t iMaterial = pFace->m;
if (iMaterial == ~0)
iMaterial = pScene->GetNumMaterials();
CConversionVertex* pVertex0 = pFace->GetVertex(0);
CConversionVertex* pVertex1 = pFace->GetVertex(1);
CConversionVertex* pLastVertex = pFace->GetVertex(pFace->GetNumVertices()-1);
avecPoints.clear();
aiPoints.clear();
for (size_t t = 0; t < pFace->GetNumVertices(); t++)
{
avecPoints.push_back(pMesh->GetVertex(pFace->GetVertex(t)->v));
aiPoints.push_back(t);
}
CConversionVertex* pVertex2;
while (avecPoints.size() > 3)
{
size_t iEar = FindEar(avecPoints);
size_t iLast = iEar==0?avecPoints.size()-1:iEar-1;
size_t iNext = iEar==avecPoints.size()-1?0:iEar+1;
pVertex0 = pFace->GetVertex(aiPoints[iLast]);
pVertex1 = pFace->GetVertex(aiPoints[iEar]);
pVertex2 = pFace->GetVertex(aiPoints[iNext]);
AddVertex(iMaterial, pMesh->GetVertex(pVertex0->v), pMesh->GetUV(pVertex0->vu));
AddVertex(iMaterial, pMesh->GetVertex(pVertex1->v), pMesh->GetUV(pVertex1->vu));
AddVertex(iMaterial, pMesh->GetVertex(pVertex2->v), pMesh->GetUV(pVertex2->vu));
avecPoints.erase(avecPoints.begin()+iEar);
aiPoints.erase(aiPoints.begin()+iEar);
}
TAssert(aiPoints.size() == 3);
if (aiPoints.size() != 3)
continue;
pVertex0 = pFace->GetVertex(aiPoints[0]);
pVertex1 = pFace->GetVertex(aiPoints[1]);
pVertex2 = pFace->GetVertex(aiPoints[2]);
AddVertex(iMaterial, pMesh->GetVertex(pVertex0->v), pMesh->GetUV(pVertex0->vu));
AddVertex(iMaterial, pMesh->GetVertex(pVertex1->v), pMesh->GetUV(pVertex1->vu));
AddVertex(iMaterial, pMesh->GetVertex(pVertex2->v), pMesh->GetUV(pVertex2->vu));
}
}
示例15: ReadSIAShape
const tchar* CModelConverter::ReadSIAShape(const tchar* pszLine, const tchar* pszEnd, CConversionSceneNode* pScene, bool bCare)
{
size_t iCurrentMaterial = ~0;
CConversionMesh* pMesh = NULL;
CConversionSceneNode* pMeshNode = NULL;
size_t iAddV = 0;
size_t iAddE = 0;
size_t iAddUV = 0;
size_t iAddN = 0;
tstring sLastTask;
tstring sToken;
const tchar* pszNextLine = NULL;
while (pszLine < pszEnd)
{
if (pszNextLine)
pszLine = pszNextLine;
size_t iLineLength = tstrlen(pszLine);
pszNextLine = pszLine + iLineLength + 1;
// This code used to call StripWhitespace() but that's too slow for very large files w/ millions of lines.
// Instead we'll just cut the whitespace off the front and deal with whitespace on the end when we come to it.
while (*pszLine && IsWhitespace(*pszLine))
pszLine++;
if (tstrlen(pszLine) == 0)
continue;
const tchar* pszToken = pszLine;
while (*pszToken && *pszToken != _T(' '))
pszToken++;
sToken.reserve(iLineLength);
sToken.clear();
sToken.append(pszLine, pszToken-pszLine);
sToken[pszToken-pszLine] = _T('\0');
pszToken = sToken.c_str();
if (!bCare)
{
if (tstrncmp(pszToken, _T("-endShape"), 9) == 0)
return pszNextLine;
else
continue;
}
if (tstrncmp(pszToken, _T("-snam"), 5) == 0)
{
// We name our mesh.
tstring sName =pszLine+6;
eastl::vector<tstring> aName;
tstrtok(sName, aName, _T("\"")); // Strip out the quotation marks.
if (bCare)
{
size_t iMesh = m_pScene->FindMesh(aName[0].c_str());
if (iMesh == (size_t)~0)
{
iMesh = m_pScene->AddMesh(aName[0].c_str());
pMesh = m_pScene->GetMesh(iMesh);
pMesh->AddBone(aName[0].c_str());
}
else
{
pMesh = m_pScene->GetMesh(iMesh);
iAddV = pMesh->GetNumVertices();
iAddE = pMesh->GetNumEdges();
iAddUV = pMesh->GetNumUVs();
iAddN = pMesh->GetNumNormals();
}
// Make sure it exists.
pMeshNode = m_pScene->GetDefaultSceneMeshInstance(pScene, pMesh);
}
}
else if (tstrncmp(pszToken, _T("-vert"), 5) == 0)
{
if (m_pWorkListener)
{
if (sLastTask == pszToken)
m_pWorkListener->WorkProgress(0);
else
{
m_pWorkListener->SetAction(_T("Reading vertex data"), 0);
sLastTask = tstring(pszToken);
}
}
// A vertex.
float v[3];
// scanf is pretty slow even for such a short string due to lots of mallocs.
const tchar* pszToken = pszLine+5;
int iDimension = 0;
while (*pszToken)
{
while (pszToken[0] == _T(' '))
pszToken++;
//.........这里部分代码省略.........