CameraObj: load camera data in the correct way.
parent
82f73b6d03
commit
0d5eb30a28
|
@ -119,7 +119,7 @@ namespace Grammar {
|
||||||
IndexArrayToken,
|
IndexArrayToken,
|
||||||
MaterialToken,
|
MaterialToken,
|
||||||
ColorToken,
|
ColorToken,
|
||||||
Paramtype,
|
ParamToken,
|
||||||
TextureToken,
|
TextureToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -163,8 +163,13 @@ namespace Grammar {
|
||||||
return CameraNodeToken;
|
return CameraNodeToken;
|
||||||
} else if ( LightNodeType == tokenType ) {
|
} else if ( LightNodeType == tokenType ) {
|
||||||
return LightNodeToken;
|
return LightNodeToken;
|
||||||
} else if( GeometryObjectType == tokenType ) {
|
}
|
||||||
|
else if ( GeometryObjectType == tokenType ) {
|
||||||
return GeometryObjectToken;
|
return GeometryObjectToken;
|
||||||
|
} else if ( CameraObjectType == tokenType ) {
|
||||||
|
return CameraObjectToken;
|
||||||
|
} else if ( LightObjectType == tokenType ) {
|
||||||
|
return LightObjectToken;
|
||||||
} else if( TransformType == tokenType ) {
|
} else if( TransformType == tokenType ) {
|
||||||
return TransformToken;
|
return TransformToken;
|
||||||
} else if( MeshType == tokenType ) {
|
} else if( MeshType == tokenType ) {
|
||||||
|
@ -177,6 +182,8 @@ namespace Grammar {
|
||||||
return MaterialToken;
|
return MaterialToken;
|
||||||
} else if ( ColorType == tokenType ) {
|
} else if ( ColorType == tokenType ) {
|
||||||
return ColorToken;
|
return ColorToken;
|
||||||
|
} else if ( ParamType == tokenType ) {
|
||||||
|
return ParamToken;
|
||||||
} else if( TextureType == tokenType ) {
|
} else if( TextureType == tokenType ) {
|
||||||
return TextureToken;
|
return TextureToken;
|
||||||
}
|
}
|
||||||
|
@ -304,6 +311,8 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce
|
||||||
}
|
}
|
||||||
|
|
||||||
copyMeshes( pScene );
|
copyMeshes( pScene );
|
||||||
|
copyCameras( pScene );
|
||||||
|
copyLights( pScene );
|
||||||
resolveReferences();
|
resolveReferences();
|
||||||
createNodeTree( pScene );
|
createNodeTree( pScene );
|
||||||
}
|
}
|
||||||
|
@ -370,7 +379,7 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Grammar::LightObjectToken:
|
case Grammar::LightObjectToken:
|
||||||
handleCameraObject( *it, pScene );
|
handleLightObject( *it, pScene );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Grammar::TransformToken:
|
case Grammar::TransformToken:
|
||||||
|
@ -397,6 +406,10 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
|
||||||
handleColorNode( *it, pScene );
|
handleColorNode( *it, pScene );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Grammar::ParamToken:
|
||||||
|
handleParamNode( *it, pScene );
|
||||||
|
break;
|
||||||
|
|
||||||
case Grammar::TextureToken:
|
case Grammar::TextureToken:
|
||||||
handleTextureNode( *it, pScene );
|
handleTextureNode( *it, pScene );
|
||||||
break;
|
break;
|
||||||
|
@ -494,12 +507,16 @@ void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
|
||||||
|
|
||||||
std::vector<std::string> objRefNames;
|
std::vector<std::string> objRefNames;
|
||||||
getRefNames( node, objRefNames );
|
getRefNames( node, objRefNames );
|
||||||
|
|
||||||
|
// when we are dealing with a geometry node prepare the mesh cache
|
||||||
|
if ( m_tokenType == Grammar::GeometryNodeToken ) {
|
||||||
m_currentNode->mNumMeshes = objRefNames.size();
|
m_currentNode->mNumMeshes = objRefNames.size();
|
||||||
m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
|
m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
|
||||||
if ( !objRefNames.empty() ) {
|
if ( !objRefNames.empty() ) {
|
||||||
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
|
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||||
|
@ -534,9 +551,9 @@ void OpenGEXImporter::handleCameraNode( DDLNode *node, aiScene *pScene ) {
|
||||||
m_currentCamera = camera;
|
m_currentCamera = camera;
|
||||||
|
|
||||||
aiNode *newNode = new aiNode;
|
aiNode *newNode = new aiNode;
|
||||||
|
pushNode( newNode, pScene );
|
||||||
m_tokenType = Grammar::CameraNodeToken;
|
m_tokenType = Grammar::CameraNodeToken;
|
||||||
m_currentNode = newNode;
|
m_currentNode = newNode;
|
||||||
pushNode( newNode, pScene );
|
|
||||||
|
|
||||||
handleNodes( node, pScene );
|
handleNodes( node, pScene );
|
||||||
|
|
||||||
|
@ -573,8 +590,8 @@ void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
void OpenGEXImporter::handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||||
// parameters will be parsed normally in the tree, so just go for it
|
// parameters will be parsed normally in the tree, so just go for it
|
||||||
handleNodes( node, pScene );
|
|
||||||
|
|
||||||
|
handleNodes( node, pScene );
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
|
@ -962,13 +979,14 @@ void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene *pScen
|
||||||
if ( nullptr != prop ) {
|
if ( nullptr != prop ) {
|
||||||
if ( NULL != prop->m_value ) {
|
if ( NULL != prop->m_value ) {
|
||||||
Value *val( node->getValue() );
|
Value *val( node->getValue() );
|
||||||
if ( NULL != val ) {
|
const float floatVal( val->getFloat() );
|
||||||
if ( "fov" == val->getString() ) {
|
if ( NULL != val && prop->m_value != NULL ) {
|
||||||
|
if ( "fov" == prop->m_value->getString() ) {
|
||||||
} else if ( "near" == val->getString() ) {
|
m_currentCamera->mHorizontalFOV = floatVal;
|
||||||
|
} else if ( "near" == prop->m_value->getString() ) {
|
||||||
}else if ( "far" == val->getString() ) {
|
m_currentCamera->mClipPlaneNear = floatVal;
|
||||||
|
} else if ( "far" == prop->m_value->getString() ) {
|
||||||
|
m_currentCamera->mClipPlaneFar = floatVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,6 +995,8 @@ void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene *pScen
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
||||||
|
ai_assert( nullptr != pScene );
|
||||||
|
|
||||||
if( m_meshCache.empty() ) {
|
if( m_meshCache.empty() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -986,6 +1006,32 @@ void OpenGEXImporter::copyMeshes( aiScene *pScene ) {
|
||||||
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
std::copy( m_meshCache.begin(), m_meshCache.end(), pScene->mMeshes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
void OpenGEXImporter::copyCameras( aiScene *pScene ) {
|
||||||
|
ai_assert( nullptr != pScene );
|
||||||
|
|
||||||
|
if ( m_cameraCache.empty() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pScene->mNumCameras = m_cameraCache.size();
|
||||||
|
pScene->mCameras = new aiCamera*[ pScene->mNumCameras ];
|
||||||
|
std::copy( m_cameraCache.begin(), m_cameraCache.end(), pScene->mCameras );
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------
|
||||||
|
void OpenGEXImporter::copyLights( aiScene *pScene ) {
|
||||||
|
ai_assert( nullptr != pScene );
|
||||||
|
|
||||||
|
if ( m_lightCache.empty() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pScene->mNumLights = m_lightCache.size();
|
||||||
|
pScene->mLights = new aiLight*[ pScene->mNumLights ];
|
||||||
|
std::copy( m_lightCache.begin(), m_lightCache.end(), pScene->mLights );
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
void OpenGEXImporter::resolveReferences() {
|
void OpenGEXImporter::resolveReferences() {
|
||||||
if( m_unresolvedRefStack.empty() ) {
|
if( m_unresolvedRefStack.empty() ) {
|
||||||
|
@ -1034,7 +1080,10 @@ void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
|
||||||
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
|
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
|
||||||
ai_assert( NULL != pScene );
|
ai_assert( NULL != pScene );
|
||||||
|
|
||||||
if( NULL != node ) {
|
if ( NULL == node ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChildInfo *info( NULL );
|
ChildInfo *info( NULL );
|
||||||
if( m_nodeStack.empty() ) {
|
if( m_nodeStack.empty() ) {
|
||||||
node->mParent = pScene->mRootNode;
|
node->mParent = pScene->mRootNode;
|
||||||
|
@ -1062,7 +1111,6 @@ void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
|
||||||
}
|
}
|
||||||
m_nodeStack.push_back( node );
|
m_nodeStack.push_back( node );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
aiNode *OpenGEXImporter::popNode() {
|
aiNode *OpenGEXImporter::popNode() {
|
||||||
|
|
|
@ -127,6 +127,9 @@ protected:
|
||||||
void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
void handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
void handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||||
void copyMeshes( aiScene *pScene );
|
void copyMeshes( aiScene *pScene );
|
||||||
|
void copyCameras( aiScene *pScene );
|
||||||
|
void copyLights( aiScene *pScene );
|
||||||
|
|
||||||
void resolveReferences();
|
void resolveReferences();
|
||||||
void pushNode( aiNode *node, aiScene *pScene );
|
void pushNode( aiNode *node, aiScene *pScene );
|
||||||
aiNode *popNode();
|
aiNode *popNode();
|
||||||
|
|
Loading…
Reference in New Issue