Fixed bug in material loader that resulted in corrupted displays for materials with > 64 characters in the name

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4099
This commit is contained in:
kearwood
2012-09-13 23:59:28 +00:00
parent fc1216ffa2
commit 283460acc7
3 changed files with 34 additions and 30 deletions

View File

@@ -90,29 +90,31 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
projectionMatrix = pCamera->getProjectionMatrix(); projectionMatrix = pCamera->getProjectionMatrix();
} }
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || renderPass == RENDER_PASS_SHADOWMAP)) { if(m_pModel != NULL) {
//if(m_pModel != NULL && (getBounds().visible(viewMatrix * projectionMatrix) || renderPass == RENDER_PASS_SHADOWMAP)) { if(getExtents(pContext).test_intersect(frustrumVolume) || renderPass == RENDER_PASS_SHADOWMAP) {
//if(m_pModel != NULL && (getBounds().visible(viewMatrix * projectionMatrix) || renderPass == RENDER_PASS_SHADOWMAP)) {
if(m_pLightMap == NULL && m_lightMap.size()) { if(m_pLightMap == NULL && m_lightMap.size()) {
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str()); m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
}
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP) {
m_pContext->getTextureManager()->selectTexture(3, m_pLightMap);
}
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
matModelToView.invert();
// Transform location of camera to object space for calculation of specular halfVec
KRMat4 inverseModelMatrix = m_modelMatrix;
inverseModelMatrix.invert();
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
m_pModel->render(pCamera, pContext, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
} }
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP) {
m_pContext->getTextureManager()->selectTexture(3, m_pLightMap);
}
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
matModelToView.invert();
// Transform location of camera to object space for calculation of specular halfVec
KRMat4 inverseModelMatrix = m_modelMatrix;
inverseModelMatrix.invert();
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
m_pModel->render(pCamera, pContext, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
} }
} }
} }
@@ -124,13 +126,15 @@ void KRInstance::calcExtents(KRContext *pContext)
calcModelMatrix(); calcModelMatrix();
KRNode::calcExtents(pContext); KRNode::calcExtents(pContext);
loadModel(); loadModel();
KRMesh *pMesh = m_pModel->getMesh(); if(m_pModel != NULL) {
KRBoundingVolume mesh_bounds = KRBoundingVolume(pMesh->getMinPoint(), pMesh->getMaxPoint(), m_modelMatrix); KRMesh *pMesh = m_pModel->getMesh();
if(m_pExtents) { KRBoundingVolume mesh_bounds = KRBoundingVolume(pMesh->getMinPoint(), pMesh->getMaxPoint(), m_modelMatrix);
*m_pExtents = m_pExtents->get_union(mesh_bounds); if(m_pExtents) {
} else { *m_pExtents = m_pExtents->get_union(mesh_bounds);
m_pExtents = new KRBoundingVolume(mesh_bounds); } else {
m_pExtents = new KRBoundingVolume(mesh_bounds);
}
} }
} }
@@ -145,6 +149,7 @@ bool KRInstance::hasTransparency() {
KRAABB KRInstance::getBounds() { KRAABB KRInstance::getBounds() {
calcModelMatrix(); calcModelMatrix();
loadModel(); loadModel();
assert(m_pModel != NULL);
KRMesh *pMesh = m_pModel->getMesh(); KRMesh *pMesh = m_pModel->getMesh();
KRVector3 meshMin = pMesh->getMinPoint(); KRVector3 meshMin = pMesh->getMinPoint();

View File

@@ -97,7 +97,7 @@ vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
pSubmesh->vertex_count = pPackMaterial->vertex_count; pSubmesh->vertex_count = pPackMaterial->vertex_count;
strncpy(pSubmesh->szMaterialName, pPackMaterial->szName, 256); strncpy(pSubmesh->szMaterialName, pPackMaterial->szName, 256);
pSubmesh->szMaterialName[63] = '\0'; pSubmesh->szMaterialName[255] = '\0';
//fprintf(stderr, "Submesh material: \"%s\"\n", pSubmesh->szMaterialName); //fprintf(stderr, "Submesh material: \"%s\"\n", pSubmesh->szMaterialName);
m_submeshes.push_back(pSubmesh); m_submeshes.push_back(pSubmesh);
} }

View File

@@ -67,7 +67,6 @@ KRModel::~KRModel() {
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) { void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
if(renderPass != KRNode::RENDER_PASS_FLARES) { if(renderPass != KRNode::RENDER_PASS_FLARES) {
if(m_materials.size() == 0) { if(m_materials.size() == 0) {