Change-Id: I287d1156e04c804ef0eeb1830f0b1c970739be3c
if( mObjLoader.IsSceneLoaded() )
{
if( mObjLoader.IsSceneLoaded() )
{
- mMesh = mObjLoader.CreateGeometry(mIlluminationType);
+ mMesh = mObjLoader.CreateGeometry( mIlluminationType );
CreateMaterial();
LoadTextures();
CreateMaterial();
LoadTextures();
{
if( mObjLoader.IsSceneLoaded() )
{
{
if( mObjLoader.IsSceneLoaded() )
{
- mMesh = mObjLoader.CreateGeometry(mIlluminationType);
+ mMesh = mObjLoader.CreateGeometry( mIlluminationType );
{
if( mObjLoader.IsMaterialLoaded() && (mTexture0Url != "") && mObjLoader.IsTexturePresent() )
{
{
if( mObjLoader.IsMaterialLoaded() && (mTexture0Url != "") && mObjLoader.IsTexturePresent() )
{
- if( (mTexture2Url != "") && (mTexture1Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) && mObjLoader.IsNormalMapPresent() )
+ if( (mTexture2Url != "") && (mTexture1Url != "") && (mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP) )
{
mShader = Shader::New( NRMMAP_VERTEX_SHADER, NRMMAP_FRAGMENT_SHADER );
}
{
mShader = Shader::New( NRMMAP_VERTEX_SHADER, NRMMAP_FRAGMENT_SHADER );
}
- else if( mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE )
+ else if( mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE ||
+ mIlluminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP )
{
mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
}
{
mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
}
{
mSceneLoaded = false;
mMaterialLoaded = false;
{
mSceneLoaded = false;
mMaterialLoaded = false;
+ mHasTexturePoints = false;
+ mHasNormalMap = false;
+ mHasDiffuseMap = false;
+ mHasSpecularMap = false;
{
//If we don't have tangents, calculate them
//we need to recalculate the normals too, because we need just one normal,tangent, bitangent per vertex
{
//If we don't have tangents, calculate them
//we need to recalculate the normals too, because we need just one normal,tangent, bitangent per vertex
- //In the case of a textureless object, we don't need tangents and so we skip this step
+ //In the case of a textureless object, we don't need tangents for our shader and so we skip this step
//TODO: Use a better function to calculate tangents
//TODO: Use a better function to calculate tangents
- if( mTangents.Size() == 0 && mHasTexture && mHasNormalMap )
+
+ if( mTangents.Size() == 0 && mHasTexturePoints )
{
mTangents.Resize( mNormals.Size() );
mBiTangents.Resize( mNormals.Size() );
{
mTangents.Resize( mNormals.Size() );
mBiTangents.Resize( mNormals.Size() );
bool mapsCorrespond; //True if the sizes of the arrays necessary for the object agree.
bool mapsCorrespond; //True if the sizes of the arrays necessary for the object agree.
+ if ( mHasTexturePoints )
{
mapsCorrespond = ( mPoints.Size() == mTextures.Size() ) && ( mTextures.Size() == mNormals.Size() );
}
{
mapsCorrespond = ( mPoints.Size() == mTextures.Size() ) && ( mTextures.Size() == mNormals.Size() );
}
vertex.position = mPoints[ui];
vertices[ui] = vertex;
vertex.position = mPoints[ui];
vertices[ui] = vertex;
+ if ( mHasTexturePoints )
{
textures[ui] = Vector2();
verticesExt[ui] = VertexExt();
{
textures[ui] = Vector2();
verticesExt[ui] = VertexExt();
vertices[mTriangles[ui].pntIndex[j]].normal = mNormals[mTriangles[ui].nrmIndex[j]];
vertices[mTriangles[ui].pntIndex[j]].normal = mNormals[mTriangles[ui].nrmIndex[j]];
+ if ( mHasTexturePoints )
{
textures[mTriangles[ui].pntIndex[j]] = mTextures[mTriangles[ui].texIndex[j]];
{
textures[mTriangles[ui].pntIndex[j]] = mTextures[mTriangles[ui].texIndex[j]];
- }
-
- if ( mHasNormalMap && mHasTexture )
- {
verticesExt[mTriangles[ui].pntIndex[j]].tangent = mTangents[mTriangles[ui].nrmIndex[j]];
verticesExt[mTriangles[ui].pntIndex[j]].bitangent = mBiTangents[mTriangles[ui].nrmIndex[j]];
}
verticesExt[mTriangles[ui].pntIndex[j]].tangent = mTangents[mTriangles[ui].nrmIndex[j]];
verticesExt[mTriangles[ui].pntIndex[j]].bitangent = mBiTangents[mTriangles[ui].nrmIndex[j]];
}
vertex.normal = mNormals[mTriangles[ui].nrmIndex[j]];
vertices[index] = vertex;
vertex.normal = mNormals[mTriangles[ui].nrmIndex[j]];
vertices[index] = vertex;
+ if ( mHasTexturePoints )
{
textures[index] = mTextures[mTriangles[ui].texIndex[j]];
{
textures[index] = mTextures[mTriangles[ui].texIndex[j]];
- }
-
- if ( mHasNormalMap && mHasTexture )
- {
VertexExt vertexExt;
vertexExt.tangent = mTangents[mTriangles[ui].nrmIndex[j]];
vertexExt.bitangent = mBiTangents[mTriangles[ui].nrmIndex[j]];
verticesExt[index] = vertexExt;
VertexExt vertexExt;
vertexExt.tangent = mTangents[mTriangles[ui].nrmIndex[j]];
vertexExt.bitangent = mBiTangents[mTriangles[ui].nrmIndex[j]];
verticesExt[index] = vertexExt;
int pntAcum = 0, texAcum = 0, nrmAcum = 0;
bool iniObj = false;
bool hasTexture = false;
int pntAcum = 0, texAcum = 0, nrmAcum = 0;
bool iniObj = false;
bool hasTexture = false;
- bool hasNormalMap = false;
int face = 0;
//Init AABB for the file
int face = 0;
//Init AABB for the file
isline >> point.z;
mTangents.PushBack( point );
isline >> point.z;
mTangents.PushBack( point );
}
else if ( tag == "#_#binormal" )
{
}
else if ( tag == "#_#binormal" )
{
isline >> point.z;
mBiTangents.PushBack( point );
isline >> point.z;
mBiTangents.PushBack( point );
}
else if ( tag == "vt" )
{
}
else if ( tag == "vt" )
{
+ //Hold slashes that separate attributes of the same point.
char separator;
char separator2;
char separator;
char separator2;
- if ( strstr( vet[0].c_str(),"//" ) ) //No texture coordinates.
+ const char * subString; //A pointer to the position in the string as we move through it.
+
+ subString = strstr( vet[0].c_str(),"/" ); //Search for the first '/'
+
+ if( subString )
- for( int i = 0 ; i < numIndices; i++)
+ if( subString[1] == '/' ) // Of the form A//C, so has points and normals but no texture coordinates.
- std::istringstream isindex( vet[i] );
- isindex >> ptIdx[i] >> separator >> separator2 >> nrmIdx[i];
- texIdx[i] = 0;
+ for( int i = 0 ; i < numIndices; i++)
+ {
+ std::istringstream isindex( vet[i] );
+ isindex >> ptIdx[i] >> separator >> separator2 >> nrmIdx[i];
+ texIdx[i] = 0;
+ }
- }
- else if ( strstr( vet[0].c_str(),"/" ) ) //Has texture coordinates, and possibly also normals.
- {
- for( int i = 0 ; i < numIndices; i++ )
+ else if( strstr( subString, "/" ) ) // Of the form A/B/C, so has points, textures and normals.
- std::istringstream isindex( vet[i] );
- isindex >> ptIdx[i] >> separator >> texIdx[i] >> separator2 >> nrmIdx[i];
+ for( int i = 0 ; i < numIndices; i++ )
+ {
+ std::istringstream isindex( vet[i] );
+ isindex >> ptIdx[i] >> separator >> texIdx[i] >> separator2 >> nrmIdx[i];
+ }
+
+ hasTexture = true;
+ }
+ else // Of the form A/B, so has points and textures but no normals.
+ {
+ for( int i = 0 ; i < numIndices; i++ )
+ {
+ std::istringstream isindex( vet[i] );
+ isindex >> ptIdx[i] >> separator >> texIdx[i];
+ nrmIdx[i] = 0;
+ }
+
- else //Has just points.
+ else // Simply of the form A, as in, point indices only.
{
for( int i = 0 ; i < numIndices; i++ )
{
{
for( int i = 0 ; i < numIndices; i++ )
{
{
CenterAndScale( true, mPoints );
mSceneLoaded = true;
{
CenterAndScale( true, mPoints );
mSceneLoaded = true;
- mHasTexture = hasTexture;
- mHasNormalMap = hasNormalMap;
+ mHasTexturePoints = hasTexture;
{
isline >> info;
texture0Url = info;
{
isline >> info;
texture0Url = info;
}
else if ( tag == "bump" )
{
}
else if ( tag == "bump" )
{
{
isline >> info;
texture2Url = info;
{
isline >> info;
texture2Url = info;
+ mHasSpecularMap = true;
Geometry ObjLoader::CreateGeometry( Toolkit::Model3dView::IlluminationType illuminationType )
{
Geometry ObjLoader::CreateGeometry( Toolkit::Model3dView::IlluminationType illuminationType )
{
+ Geometry surface = Geometry::New();
+
Dali::Vector<Vertex> vertices;
Dali::Vector<Vector2> textures;
Dali::Vector<VertexExt> verticesExt;
Dali::Vector<Vertex> vertices;
Dali::Vector<Vector2> textures;
Dali::Vector<VertexExt> verticesExt;
vertexFormat["aNormal"] = Property::VECTOR3;
PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
surfaceVertices.SetData( &vertices[0], vertices.Size() );
vertexFormat["aNormal"] = Property::VECTOR3;
PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
surfaceVertices.SetData( &vertices[0], vertices.Size() );
-
- Geometry surface = Geometry::New();
surface.AddVertexBuffer( surfaceVertices );
//Some need texture coordinates
if( ( (illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP ) ||
surface.AddVertexBuffer( surfaceVertices );
//Some need texture coordinates
if( ( (illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP ) ||
- (illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE ) ) && mHasTexture )
+ (illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_TEXTURE ) ) && mHasTexturePoints && mHasDiffuseMap )
{
Property::Map textureFormat;
textureFormat["aTexCoord"] = Property::VECTOR2;
{
Property::Map textureFormat;
textureFormat["aTexCoord"] = Property::VECTOR2;
}
//Some need tangent and bitangent
}
//Some need tangent and bitangent
- if( illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP && mHasNormalMap && mHasTexture )
+ if( illuminationType == Toolkit::Model3dView::DIFFUSE_WITH_NORMAL_MAP && mHasTexturePoints )
{
Property::Map vertexExtFormat;
vertexExtFormat["aTangent"] = Property::VECTOR3;
{
Property::Map vertexExtFormat;
vertexExtFormat["aTangent"] = Property::VECTOR3;
bool ObjLoader::IsTexturePresent()
{
bool ObjLoader::IsTexturePresent()
{
+ return mHasTexturePoints;
+}
+
+bool ObjLoader::IsDiffuseMapPresent()
+{
+ return mHasDiffuseMap;
}
bool ObjLoader::IsNormalMapPresent()
}
bool ObjLoader::IsNormalMapPresent()
+bool ObjLoader::IsSpecularMapPresent()
+{
+ return mHasSpecularMap;
+}
+
} // namespace Internal
} // namespace Toolkit
} // namespace Dali
} // namespace Internal
} // namespace Toolkit
} // namespace Dali
void ClearArrays();
bool IsTexturePresent();
void ClearArrays();
bool IsTexturePresent();
+ bool IsDiffuseMapPresent();
bool IsNormalMapPresent();
bool IsNormalMapPresent();
+ bool IsSpecularMapPresent();
bool mSceneLoaded;
bool mMaterialLoaded;
bool mSceneLoaded;
bool mMaterialLoaded;
+ bool mHasTexturePoints;
+
+ //Material file properties.
+ bool mHasDiffuseMap;
Dali::Vector<Vector3> mPoints;
Dali::Vector<Vector2> mTextures;
Dali::Vector<Vector3> mPoints;
Dali::Vector<Vector2> mTextures;