*/
#include "FUiAnim_SceneImpl.h"
+#include "FUiAnimScene.h"
#include "FBaseLog.h"
#include "FBaseSysLog.h"
-#include <FGraphics.h>
+//#include <FGraphics.h>
+#include <FBaseColArrayList.h>
-namespace Tizen { namespace Ui { namespace Animations {
+#include <FGrpFloatMatrix4.h>
+#include <FGrpFloatPoint.h>
+#include <FGrpFloatRectangle.h>
+
+#include "FUiAnimMesh.h"
+#include "FUiAnimMaterial.h"
+#include "FUiAnimLight.h"
+#include "FUiAnimShaderProgram.h"
+#include "FUiAnimShader.h" //for ShaderProgram compile
+
+#include "FUiAnim_MeshImpl.h"
+#include "FUiAnim_MaterialImpl.h"
+#include "FUiAnim_LightImpl.h"
+#include "FUiAnim_ShaderProgramImpl.h"
+
+#include "FUiAnim_MaterialParser.h"
+#include "FUiAnim_LightParser.h"
+
+#include "FUiAnimModelImporter.h"
+
+#include <FBaseUtilStringUtil.h>
+
+#include <stdio.h>
+#include <cstdlib>
+#include <string.h>
+#include <fstream>
+//#define LOCAL_XML_ENCODING "ISO-8859-1" //xml encoding
+#define LOCAL_XML_ENCODING "UTF-8" //xml encoding
+#define SCENE_DESCTRIPTOR_FILE_EXTENSION ".are"
+
+#define SCENE_MESH_RESOURCE_FILE_NAME "_mesh"
+#define SCENE_MESH_RESOURCE_FILE_EXTENSION ".bin"
+#define SCENE_MATERIAL_RESOURCE_FILE_NAME "_material"
+#define SCENE_MATERIAL_RESOURCE_FILE_EXTENSION ".xml"
+
+#define SCENE_LIGHT_RESOURCE_FILE_NAME "_light"
+#define SCENE_LIGHT_RESOURCE_FILE_EXTENSION ".xml"
+
+#define SCENE_VERTEX_SHADER_RESOURCE_FILE_NAME "_shader"
+#define SCENE_VERTEX_SHADER_RESOURCE_FILE_EXTENSION ".vert"
+
+#define SCENE_FRAGMENT_SHADER_RESOURCE_FILE_NAME "_shader"
+#define SCENE_FRAGMENT_SHADER_RESOURCE_FILE_EXTENSION ".frag"
+
+#define MAX_RES_FILES_COUNT 10000
+
+using namespace Tizen::Base;
+using namespace Tizen::Graphics;
using namespace Tizen::Base::Collection;
+using namespace Tizen::Ui::Animations;
+
+namespace Tizen { namespace Ui { namespace Animations {
_SceneImpl::_SceneImpl(void)
- : Tizen::Base::Object()
- , __meshes()
- , __materials()
+ : _name()
+ , _pSceneRootVisualElement(null)
+// , _pSceneFakeRootVisualElement(null)
+ , _meshes()
+ , _materials()
+ , _lights()
+ , _shaderPrograms()
+ , _textureFileNames()
+{
+}
+
+_SceneImpl::~_SceneImpl(void)
{
+ ResetScene();
+
+ _pSceneRootVisualElement = null;
+// _pSceneFakeRootVisualElement->Destroy();
}
result
-_SceneImpl::Construct()
+_SceneImpl::Construct(VisualElement& pSceneRootVisualElement)
{
- __pRootVisualElement = new (std::nothrow) VisualElement();
- __pRootVisualElement->Construct();
+ _pSceneRootVisualElement = &pSceneRootVisualElement;
-// A ce vzagali treba????
- __pRootVisualElement->SetName(L"Node");
- __pRootVisualElement->SetBounds(Tizen::Graphics::FloatRectangle(5, 5, 1, 1));
- __pRootVisualElement->SetShowState(true);
- __pRootVisualElement->SetImplicitAnimationEnabled(false);
+// _pSceneFakeRootVisualElement = new (std::nothrow) VisualElement();
+// SysTryReturnResult(NID_UI_ANIM, _pSceneFakeRootVisualElement != null, E_OUT_OF_MEMORY, \
+// "[E_OUT_OF_MEMORY] Insufficient memory.");
+//
+// _pSceneFakeRootVisualElement->Construct();
+// _pSceneFakeRootVisualElement->SetName("SceneFakeRootVisualElement");
+// _pSceneFakeRootVisualElement->SetBounds(_pSceneRootVisualElement->GetBounds());
+// _pSceneFakeRootVisualElement->SetShowState(true);
+// _pSceneFakeRootVisualElement->SetImplicitAnimationEnabled(_pSceneRootVisualElement->IsImplicitAnimationEnabled());
+// _pSceneRootVisualElement->AttachChild(_pSceneFakeRootVisualElement);
return E_SUCCESS;
}
-_SceneImpl::~_SceneImpl(void)
+result
+_SceneImpl::SetName(const Tizen::Base::String& sceneName)
{
+ _name = sceneName;
+ return E_SUCCESS;
+}
+Tizen::Base::String
+_SceneImpl::GetName(void) const
+{
+ return _name;
}
VisualElement*
_SceneImpl::GetRootVisualElement(void) const
{
- return __pRootVisualElement;
+// return _pSceneFakeRootVisualElement;
+ return _pSceneRootVisualElement;
+}
+
+//result
+//_SceneImpl::RemoveAllVisualElements()
+//{
+// IList* rootVEChildrenList = _pSceneFakeRootVisualElement->GetChildrenN();
+// VisualElement* pChildVE;
+//
+// if (rootVEChildrenList != null)
+// {
+// int count = rootVEChildrenList->GetCount();
+// for (int i = 0; i < count; i++)
+// {
+// pChildVE = (VisualElement*)rootVEChildrenList->GetAt(i);
+// if (pChildVE != null)
+// {
+// pChildVE->Destroy();
+// }
+// }
+// }
+//
+// return E_SUCCESS;
+//}
+
+result
+_SceneImpl::ResetScene(void)
+{
+// RemoveAllVisualElements();
+ RemoveAllMesh();
+ RemoveAllMaterial();
+ RemoveAllLight();
+ RemoveAllShaderProgram();
+ RemoveAllTextureFileName();
+
+ return E_SUCCESS;
+}
+
+_SceneImpl*
+_SceneImpl::GetInstance(Scene& scene)
+{
+ return scene.__pSceneImpl;
+}
+
+const _SceneImpl*
+_SceneImpl::GetInstance(const Scene& scene)
+{
+ return scene.__pSceneImpl;
}
//==========================================================================================MESH
result
-_SceneImpl::AddMesh(Mesh* pMesh)
+_SceneImpl::AddMesh(const Mesh* pMesh)
{
- if (pMesh != null)
+ SysTryReturnResult(NID_UI_ANIM, pMesh != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ SysTryReturnResult(NID_UI_ANIM, !(ContainsMesh(pMesh) >= 0), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh \"%ls\" already exists in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ Mesh* pMeshCopy = new (std::nothrow) Mesh(*pMesh);
+ SysTryReturnResult(NID_UI_ANIM, pMeshCopy != null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ _SceneMeshDescriptor meshDescriptor;
+ meshDescriptor.pMesh = pMeshCopy;
+
+ return _meshes.Add( meshDescriptor);
+}
+
+result
+_SceneImpl::RemoveMesh(const String& meshName)
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex, meshDescriptor);
+ if (meshDescriptor.pMesh != null)
{
- Mesh* pMeshCopy = new (std::nothrow) Mesh(*pMesh);
- SysTryReturnResult(NID_UI, pMeshCopy != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
- __meshes.push_back(pMeshCopy);
+ delete meshDescriptor.pMesh;
+ meshDescriptor.pMesh = null;
}
- return E_SUCCESS;
+
+ return _meshes.RemoveAt(meshIndex);
+}
+
+result
+_SceneImpl::RemoveMesh(const Mesh* pMesh)
+{
+ SysTryReturnResult(NID_UI_ANIM, pMesh != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(pMesh);
+
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex, meshDescriptor);
+ if (meshDescriptor.pMesh != null)
+ {
+ delete meshDescriptor.pMesh;
+ meshDescriptor.pMesh = null;
+ }
+
+ return _meshes.RemoveAt(meshIndex);
}
result
-_SceneImpl::RemoveMesh(const std::string& meshName)
+_SceneImpl::RemoveAllMesh(void)
{
- for (Meshes::iterator i = __meshes.begin(); i != __meshes.end(); i++)
+ _SceneMeshDescriptor meshDescriptor;
+ int count = _meshes.GetCount();
+
+ for (int i = 0; i < count; i++)
{
- Mesh* pMesh = *i;
- if (pMesh->GetName().Equals(Tizen::Base::String(meshName.c_str())))
+ _meshes.GetAt(i, meshDescriptor);
+ if (meshDescriptor.pMesh != null)
{
- __meshes.erase(i);
- delete pMesh;
- pMesh = null;
- return E_SUCCESS;
+ delete meshDescriptor.pMesh;
+ meshDescriptor.pMesh = null;
}
}
+ _meshes.RemoveAll();
- SysTryReturnResult(NID_UI_ANIM, false, E_OBJ_NOT_FOUND, "Mesh '%s' not found.", meshName.c_str());
- return E_OBJ_NOT_FOUND;
+ return E_SUCCESS;
}
Mesh*
-_SceneImpl::GetMeshN(const std::string& meshName) const
+_SceneImpl::GetMeshN(const String& meshName) const
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+
+ SysTryReturn(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ if (meshDescriptor.pMesh == null)
+ {
+ return null;
+ }
+
+ Mesh* pMeshCopy = new (std::nothrow) Mesh(*meshDescriptor.pMesh);
+ SysTryReturn(NID_UI_ANIM, pMeshCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pMeshCopy;
+}
+
+int
+_SceneImpl::GetMeshCount(void) const
+{
+ return _meshes.GetCount();
+}
+
+int
+_SceneImpl::ContainsMesh(const Tizen::Base::String& meshName) const
{
- for (Meshes::const_iterator i = __meshes.begin(); i != __meshes.end(); i++)
+ _SceneMeshDescriptor meshDescriptor;
+ int meshIndex = -1;
+
+ for (int i = 0; i < GetMeshCount();i++)
{
- Mesh* pMesh = *i;
- if (pMesh->GetName().Equals(Tizen::Base::String(meshName.c_str())))
+ _meshes.GetAt(i,meshDescriptor);
+ if (meshDescriptor.pMesh != null)
{
- Mesh* pMeshCopy = new (std::nothrow) Mesh(*pMesh);
- SysTryReturn(NID_UI, pMeshCopy != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
- return pMeshCopy;
+ if (meshDescriptor.pMesh->GetName() == meshName)
+ {
+ meshIndex = i;
+ break;
+ }
}
}
- return null;
+ return meshIndex;
+}
+
+int
+_SceneImpl::ContainsMesh(const Mesh* pMesh) const
+{
+ SysTryReturn(NID_UI_ANIM, pMesh != null, -1, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ _SceneMeshDescriptor meshDescriptor;
+ int meshIndex = -1;
+
+ for (int i = 0; i < GetMeshCount();i++)
+ {
+ _meshes.GetAt(i,meshDescriptor);
+ if (meshDescriptor.pMesh != null)
+ {
+ if (meshDescriptor.pMesh->GetHashCode() == pMesh->GetHashCode())
+ {
+ meshIndex = i;
+ break;
+ }
+ }
+ }
+
+ return meshIndex;
+}
+
+Mesh*
+_SceneImpl::GetMeshAtN(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMeshCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(index,meshDescriptor);
+
+ if (meshDescriptor.pMesh == null)
+ {
+ return null;
+ }
+
+ Mesh* pMeshCopy = new (std::nothrow) Mesh(*meshDescriptor.pMesh);
+ SysTryReturn(NID_UI_ANIM, pMeshCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pMeshCopy;
+}
+
+Tizen::Base::String
+_SceneImpl::GetMeshNameAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMeshCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(index,meshDescriptor);
+
+ if (meshDescriptor.pMesh == null)
+ {
+ return String(L"");
+ }
+
+ return meshDescriptor.pMesh->GetName();
+}
+
+String
+_SceneImpl::GetMeshSourceFileName(const String meshName) const
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+
+ SysTryReturn(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), String(L""), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ return meshDescriptor.sourceFileName;
+}
+result
+_SceneImpl::SetMeshSourceFileName(const String meshName, const String editorFileName)
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ meshDescriptor.sourceFileName = editorFileName;
+
+ return _meshes.SetAt(meshDescriptor, meshIndex);
+}
+
+String
+_SceneImpl::GetMeshModelNameInSourceFile(const String meshName) const
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+
+ SysTryReturn(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), String(L""), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ return meshDescriptor.modelNameInSourceFile;
+}
+
+result
+_SceneImpl::SetMeshModelNameInSourceFile(const String meshName, const String modelNameInSourceFile)
+{
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(meshName);
+
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", meshName.GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ meshDescriptor.modelNameInSourceFile = modelNameInSourceFile;
+
+ return _meshes.SetAt(meshDescriptor, meshIndex);
+}
+//not for public, but for JNI example
+String
+_SceneImpl::GetMeshNameByHashCode(int code) const
+{
+ _MeshImpl* pMeshImpl = (_MeshImpl*)code;
+ if (pMeshImpl != null)
+ {
+ return String(pMeshImpl->GetName().c_str());
+ }
+ else
+ {
+ return String(L"");
+ }
+}
+
+Tizen::Base::String
+_SceneImpl::GetMeshSourceFileName(const Mesh* pMesh) const
+{
+ SysTryReturn(NID_UI_ANIM, pMesh != null, String(L""), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(pMesh);
+
+ SysTryReturn(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), String(L""), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ return meshDescriptor.sourceFileName;
+}
+
+result
+_SceneImpl::SetMeshSourceFileName(const Mesh* pMesh, const Tizen::Base::String sourceFileName)
+{
+ SysTryReturnResult(NID_UI_ANIM, pMesh != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(pMesh);
+
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ meshDescriptor.sourceFileName = sourceFileName;
+
+ return _meshes.SetAt(meshDescriptor, meshIndex);
+}
+
+Tizen::Base::String
+_SceneImpl::GetMeshModelNameInSourceFile(const Mesh* pMesh) const
+{
+ SysTryReturn(NID_UI_ANIM, pMesh != null, String(L""), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(pMesh);
+
+ SysTryReturn(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), String(L""), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ return meshDescriptor.modelNameInSourceFile;
+}
+
+result
+_SceneImpl::SetMeshModelNameInSourceFile(const Mesh* pMesh, const Tizen::Base::String modelNameInSourceFile)
+{
+ SysTryReturnResult(NID_UI_ANIM, pMesh != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Mesh pointer is null.");
+
+ int meshIndex = -1;
+ meshIndex = ContainsMesh(pMesh);
+
+ SysTryReturnResult(NID_UI_ANIM, (meshIndex >= 0) && (meshIndex < GetMeshCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh \"%ls\" not found in scene \"%ls\".", pMesh->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(meshIndex,meshDescriptor);
+
+ meshDescriptor.modelNameInSourceFile = modelNameInSourceFile;
+
+ return _meshes.SetAt(meshDescriptor, meshIndex);
}
-Tizen::Base::Collection::ArrayList*
-_SceneImpl::GetMeshNamesN(void) const
+int
+_SceneImpl::GetMeshCodeAt(int index) const
{
- ArrayList* meshNames = new ArrayList(SingleObjectDeleter);
- for (Meshes::const_iterator i = __meshes.begin(); i != __meshes.end(); i++)
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMeshCount()), 0, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Mesh #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMeshDescriptor meshDescriptor;
+ _meshes.GetAt(index,meshDescriptor);
+ if (meshDescriptor.pMesh != null)
{
+ return meshDescriptor.pMesh->GetHashCode();
+ }
+ return 0;
+}
- Tizen::Base::String* meshName = new Tizen::Base::String((*i)->GetName());
- meshNames->Add(meshName);
+int
+_SceneImpl::ContainsMesh(int code) const
+{
+ _SceneMeshDescriptor meshDescriptor;
+ int meshIndex = -1;
+
+ for (int i = 0; i < GetMeshCount();i++)
+ {
+ _meshes.GetAt(i,meshDescriptor);
+ if (meshDescriptor.pMesh != null)
+ {
+ if (meshDescriptor.pMesh->GetHashCode() == code)
+ {
+ meshIndex = i;
+ break;
+ }
+ }
}
- return meshNames;
+
+ return meshIndex;
+}
+
+Mesh*
+_SceneImpl::GetMeshByHashCodeN(int code) const
+{
+ int meshIndex = ContainsMesh(code);
+ return GetMeshAtN(meshIndex);
}
//==========================================================================================MATERIAL
result
-_SceneImpl::AddMaterial(Material* pMaterial)
+_SceneImpl::AddMaterial(const Material* pMaterial)
{
- if (pMaterial != null)
+ SysTryReturnResult(NID_UI_ANIM, pMaterial != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material pointer is null.");
+
+ SysTryReturnResult(NID_UI_ANIM, !(ContainsMaterial(pMaterial) >= 0), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material \"%ls\" already exists in scene \"%ls\".", pMaterial->GetName().GetPointer(), _name.GetPointer());
+
+ Material* pMaterialCopy = new (std::nothrow) Material(*pMaterial);
+ SysTryReturnResult(NID_UI_ANIM, pMaterialCopy != null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ _SceneMaterialDescriptor materialDescriptor;
+ materialDescriptor.pMaterial = pMaterialCopy;
+
+ return _materials.Add( materialDescriptor);
+}
+
+result
+_SceneImpl::RemoveMaterial(const String& materialName)
+{
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(materialName);
+ SysTryReturnResult(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", materialName.GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex, materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
{
- Material* pMaterialCopy = new (std::nothrow) Material(*pMaterial);
- SysTryReturnResult(NID_UI, pMaterialCopy != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
- __materials.push_back(pMaterialCopy);
+ delete materialDescriptor.pMaterial;
+ materialDescriptor.pMaterial = null;
}
- return E_SUCCESS;
+
+ return _materials.RemoveAt(materialIndex);
+}
+
+result
+_SceneImpl::RemoveMaterial(const Material* pMaterial)
+{
+ SysTryReturnResult(NID_UI_ANIM, pMaterial != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material pointer is null.");
+
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(pMaterial);
+ SysTryReturnResult(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", pMaterial->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex, materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
+ {
+ delete materialDescriptor.pMaterial;
+ materialDescriptor.pMaterial = null;
+ }
+
+ return _materials.RemoveAt(materialIndex);
}
result
-_SceneImpl::RemoveMaterial(const std::string& materialName)
+_SceneImpl::RemoveAllMaterial(void)
{
- for (Materials::iterator i = __materials.begin(); i != __materials.end(); i++)
+ _SceneMaterialDescriptor materialDescriptor;
+ int count = _materials.GetCount();
+
+ for (int i = 0; i < count; i++)
{
- Material* pMaterial = *i;
- if (pMaterial->GetName().Equals(Tizen::Base::String(materialName.c_str())))
+ _materials.GetAt(i, materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
{
- __materials.erase(i);
- delete pMaterial;
- pMaterial = null;
- return E_SUCCESS;
+ delete materialDescriptor.pMaterial;
+ materialDescriptor.pMaterial = null;
}
}
+ _materials.RemoveAll();
- SysTryReturnResult(NID_UI_ANIM, false, E_OBJ_NOT_FOUND, "Material '%s' not found.", materialName.c_str());
- return E_OBJ_NOT_FOUND;
+ return E_SUCCESS;
}
Material*
-_SceneImpl::GetMaterialN(const std::string& materialName) const
+_SceneImpl::GetMaterialN(const String& materialName) const
+{
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(materialName);
+
+ SysTryReturn(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", materialName.GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex,materialDescriptor);
+
+ if (materialDescriptor.pMaterial == null)
+ {
+ return null;
+ }
+
+ Material* pMaterialCopy = new (std::nothrow) Material(*materialDescriptor.pMaterial);
+ SysTryReturn(NID_UI_ANIM, pMaterialCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pMaterialCopy;
+}
+
+int
+_SceneImpl::GetMaterialCount(void) const
+{
+ return _materials.GetCount();
+}
+
+int
+_SceneImpl::ContainsMaterial(const Tizen::Base::String& materialName) const
{
- for (Materials::const_iterator i = __materials.begin(); i != __materials.end(); i++)
+ _SceneMaterialDescriptor materialDescriptor;
+ int materialIndex = -1;
+
+ for (int i = 0; i < GetMaterialCount();i++)
{
- Material* pMaterial = *i;
- if (pMaterial->GetName().Equals(Tizen::Base::String(materialName.c_str())))
+ _materials.GetAt(i,materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
{
- Material* pMaterialCopy = new (std::nothrow) Material(*pMaterial);
- SysTryReturn(NID_UI, pMaterialCopy != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
- return pMaterialCopy;
+ if (materialDescriptor.pMaterial->GetName() == materialName)
+ {
+ materialIndex = i;
+ break;
+ }
}
}
- return null;
+ return materialIndex;
}
-Tizen::Base::Collection::ArrayList*
-_SceneImpl::GetMaterialNamesN(void) const
+int
+_SceneImpl::ContainsMaterial(const Material* pMaterial) const
{
- ArrayList* materialNames = new ArrayList(SingleObjectDeleter);
- for (Materials::const_iterator i = __materials.begin(); i != __materials.end(); i++)
+ SysTryReturn(NID_UI_ANIM, pMaterial != null, -1, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material pointer is null.");
+
+ _SceneMaterialDescriptor materialDescriptor;
+ int materialIndex = -1;
+
+ for (int i = 0; i < GetMaterialCount();i++)
{
- Tizen::Base::String* materialName = new Tizen::Base::String((*i)->GetName());
- materialNames->Add(materialName);
+ _materials.GetAt(i,materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
+ {
+ if (materialDescriptor.pMaterial->GetHashCode() == pMaterial->GetHashCode())
+ {
+ materialIndex = i;
+ break;
+ }
+ }
}
- return materialNames;
-}
-//==========================================================================================TEXTURE
+ return materialIndex;
+}
-result
-_SceneImpl::AddTextureFileName(std::string textureFileName)
+Material*
+_SceneImpl::GetMaterialAtN(int index) const
{
- __textureFileNames.push_back(textureFileName);
- return E_SUCCESS;
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(index,materialDescriptor);
+
+ if (materialDescriptor.pMaterial == null)
+ {
+ return null;
+ }
+
+ Material* pMaterialCopy = new (std::nothrow) Material(*materialDescriptor.pMaterial);
+ SysTryReturn(NID_UI_ANIM, pMaterialCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pMaterialCopy;
}
-Tizen::Base::Collection::ArrayList*
-_SceneImpl::GetTextureFileNamesN(void) const
+Tizen::Base::String
+_SceneImpl::GetMaterialNameAt(int index) const
{
- ArrayList* textureFileNames = new ArrayList(SingleObjectDeleter);
- for (TextureFileNames::const_iterator i = __textureFileNames.begin(); i != __textureFileNames.end(); i++)
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(index,materialDescriptor);
+
+ if (materialDescriptor.pMaterial == null)
{
- Tizen::Base::String* textureFileName = new Tizen::Base::String((*i).c_str());
- textureFileNames->Add(textureFileName);
+ return String(L"");
}
- return textureFileNames;
+
+ return materialDescriptor.pMaterial->GetName();
+}
+
+String
+_SceneImpl::GetMaterialSourceFileName(const String materialName) const
+{
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(materialName);
+
+ SysTryReturn(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", materialName.GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex,materialDescriptor);
+
+ return materialDescriptor.sourceFileName;
+}
+result
+_SceneImpl::SetMaterialSourceFileName(const String materialName, const String sourceFileName)
+{
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(materialName);
+
+ SysTryReturnResult(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", materialName.GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex,materialDescriptor);
+
+ materialDescriptor.sourceFileName = sourceFileName;
+
+ return _materials.SetAt(materialDescriptor, materialIndex);
}
+//not for public, but for JNI example
+String
+_SceneImpl::GetMaterialNameByHashCode(int code) const
+{
+ _MaterialImpl* pMaterialImpl = (_MaterialImpl*)code;
+ if (pMaterialImpl != null)
+ {
+ return String(pMaterialImpl->GetName());
+ }
+ else
+ {
+ return String(L"");
+ }
+}
+
+String
+_SceneImpl::GetMaterialSourceFileName(const Material* pMaterial) const
+{
+ SysTryReturn(NID_UI_ANIM, pMaterial != null, String(L""), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material pointer is null.");
+
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(pMaterial);
+
+ SysTryReturn(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", pMaterial->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex,materialDescriptor);
+
+ return materialDescriptor.sourceFileName;
+}
+result
+_SceneImpl::SetMaterialSourceFileName(const Material* pMaterial, const String sourceFileName)
+{
+ SysTryReturnResult(NID_UI_ANIM, pMaterial != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Material pointer is null.");
+
+ int materialIndex = -1;
+ materialIndex = ContainsMaterial(pMaterial);
+
+ SysTryReturnResult(NID_UI_ANIM, (materialIndex >= 0) && (materialIndex < GetMaterialCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material \"%ls\" not found in scene \"%ls\".", pMaterial->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(materialIndex,materialDescriptor);
+
+ materialDescriptor.sourceFileName = sourceFileName;
+
+ return _materials.SetAt(materialDescriptor, materialIndex);
+}
+
+//not for public, but for JNI example
+int
+_SceneImpl::GetMaterialCodeAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetMaterialCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Material #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneMaterialDescriptor materialDescriptor;
+ _materials.GetAt(index,materialDescriptor);
+
+ if (materialDescriptor.pMaterial != null)
+ {
+ return materialDescriptor.pMaterial->GetHashCode();
+ }
+ return 0;
+}
+
+int
+_SceneImpl::ContainsMaterial(int code) const
+{
+ _SceneMaterialDescriptor materialDescriptor;
+ int materialIndex = -1;
+
+ for (int i = 0; i < GetMaterialCount();i++)
+ {
+ _materials.GetAt(i,materialDescriptor);
+ if (materialDescriptor.pMaterial != null)
+ {
+ if (materialDescriptor.pMaterial->GetHashCode() == code)
+ {
+ materialIndex = i;
+ break;
+ }
+ }
+ }
+
+ return materialIndex;
+}
+
+Material*
+_SceneImpl::GetMaterialByHashCodeN(int code) const
+{
+ int materialIndex = ContainsMaterial(code);
+ return GetMaterialAtN(materialIndex);
+}
+
+//==========================================================================================LIGHT
+
+result
+_SceneImpl::AddLight(const Light* pLight)
+{
+ SysTryReturnResult(NID_UI_ANIM, pLight != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light pointer is null.");
+
+ SysTryReturnResult(NID_UI_ANIM, !(ContainsLight(pLight) >= 0), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light \"%ls\" already exists in scene \"%ls\".", pLight->GetName().GetPointer(), _name.GetPointer());
+
+ Light* pLightCopy = new (std::nothrow) Light(*pLight);
+ SysTryReturnResult(NID_UI_ANIM, pLightCopy != null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ _SceneLightDescriptor lightDescriptor;
+ lightDescriptor.pLight = pLightCopy;
+
+ return _lights.Add( lightDescriptor);
+}
+
+result
+_SceneImpl::RemoveLight(const String& lightName)
+{
+ int lightIndex = -1;
+ lightIndex = ContainsLight(lightName);
+ SysTryReturnResult(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", lightName.GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex, lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ delete lightDescriptor.pLight;
+ lightDescriptor.pLight = null;
+ }
+
+ return _lights.RemoveAt(lightIndex);
+}
+
+result
+_SceneImpl::RemoveLight(const Light* pLight)
+{
+ SysTryReturnResult(NID_UI_ANIM, pLight != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light pointer is null.");
+
+ int lightIndex = -1;
+ lightIndex = ContainsLight(pLight);
+ SysTryReturnResult(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", pLight->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex, lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ delete lightDescriptor.pLight;
+ lightDescriptor.pLight = null;
+ }
+
+ return _lights.RemoveAt(lightIndex);
+}
+
+result
+_SceneImpl::RemoveAllLight(void)
+{
+ _SceneLightDescriptor lightDescriptor;
+ int count = _lights.GetCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ _lights.GetAt(i, lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ delete lightDescriptor.pLight;
+ lightDescriptor.pLight = null;
+ }
+ }
+ _lights.RemoveAll();
+
+ return E_SUCCESS;
+}
+
+Light*
+_SceneImpl::GetLightN(const String& lightName) const
+{
+ int lightIndex = -1;
+ lightIndex = ContainsLight(lightName);
+
+ SysTryReturn(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", lightName.GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex,lightDescriptor);
+
+ if (lightDescriptor.pLight == null)
+ {
+ return null;
+ }
+
+ Light* pLightCopy = new (std::nothrow) Light(*lightDescriptor.pLight);
+ SysTryReturn(NID_UI_ANIM, pLightCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pLightCopy;
+}
+
+int
+_SceneImpl::GetLightCount(void) const
+{
+ return _lights.GetCount();
+}
+
+int
+_SceneImpl::ContainsLight(const Tizen::Base::String& lightName) const
+{
+ _SceneLightDescriptor lightDescriptor;
+ int lightIndex = -1;
+
+ for (int i = 0; i < GetLightCount();i++)
+ {
+ _lights.GetAt(i,lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ if (lightDescriptor.pLight->GetName() == lightName)
+ {
+ lightIndex = i;
+ break;
+ }
+ }
+ }
+
+ return lightIndex;
+}
+
+int
+_SceneImpl::ContainsLight(const Light* pLight) const
+{
+ SysTryReturn(NID_UI_ANIM, pLight != null, -1, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light pointer is null.");
+ _SceneLightDescriptor lightDescriptor;
+ int lightIndex = -1;
+
+ for (int i = 0; i < GetLightCount();i++)
+ {
+ _lights.GetAt(i,lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ if (lightDescriptor.pLight->GetHashCode() == pLight->GetHashCode())
+ {
+ lightIndex = i;
+ break;
+ }
+ }
+ }
+
+ return lightIndex;
+
+}
+
+Light*
+_SceneImpl::GetLightAtN(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(index,lightDescriptor);
+
+ if (lightDescriptor.pLight == null)
+ {
+ return null;
+ }
+
+ Light* pLightCopy = new (std::nothrow) Light(*lightDescriptor.pLight);
+ SysTryReturn(NID_UI_ANIM, pLightCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pLightCopy;
+}
+
+Tizen::Base::String
+_SceneImpl::GetLightNameAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(index,lightDescriptor);
+
+ if (lightDescriptor.pLight == null)
+ {
+ return String(L"");
+ }
+
+ return lightDescriptor.pLight->GetName();
+}
+
+String
+_SceneImpl::GetLightSourceFileName(const String lightName) const
+{
+ int lightIndex = -1;
+ lightIndex = ContainsLight(lightName);
+
+ SysTryReturn(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", lightName.GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex,lightDescriptor);
+
+ return lightDescriptor.sourceFileName;
+}
+result
+_SceneImpl::SetLightSourceFileName(const String lightName, const String sourceFileName)
+{
+ int lightIndex = -1;
+ lightIndex = ContainsLight(lightName);
+
+ SysTryReturnResult(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", lightName.GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex,lightDescriptor);
+
+ lightDescriptor.sourceFileName = sourceFileName;
+
+ return _lights.SetAt(lightDescriptor, lightIndex);
+}
+
+//not for public, but for JNI example
+String
+_SceneImpl::GetLightNameByHashCode(int code) const
+{
+ _LightImpl* pLightImpl = (_LightImpl*)code;
+ if (pLightImpl != null)
+ {
+ return String(pLightImpl->GetName());
+ }
+ else
+ {
+ return String(L"");
+ }
+}
+
+Tizen::Base::String
+_SceneImpl::GetLightSourceFileName(const Light* pLight) const
+{
+ SysTryReturn(NID_UI_ANIM, pLight != null, String(L""), E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light pointer is null.");
+
+ int lightIndex = -1;
+ lightIndex = ContainsLight(pLight);
+
+ SysTryReturn(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", pLight->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex,lightDescriptor);
+
+ return lightDescriptor.sourceFileName;
+
+}
+
+result
+_SceneImpl::SetLightSourceFileName(const Light* pLight, const Tizen::Base::String sourceFileName)
+{
+ SysTryReturnResult(NID_UI_ANIM, pLight != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] Light pointer is null.");
+ int lightIndex = -1;
+ lightIndex = ContainsLight(pLight);
+ SysTryReturnResult(NID_UI_ANIM, (lightIndex >= 0) && (lightIndex < GetLightCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light \"%ls\" not found in scene \"%ls\".", pLight->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(lightIndex,lightDescriptor);
+
+ lightDescriptor.sourceFileName = sourceFileName;
+
+ return _lights.SetAt(lightDescriptor, lightIndex);
+}
+
+int
+_SceneImpl::GetLightCodeAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetLightCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Light #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneLightDescriptor lightDescriptor;
+ _lights.GetAt(index,lightDescriptor);
+
+ if (lightDescriptor.pLight != null)
+ {
+ return lightDescriptor.pLight->GetHashCode();
+ }
+
+ return 0;
+}
+
+int
+_SceneImpl::ContainsLight(int code) const
+{
+ _SceneLightDescriptor lightDescriptor;
+ int lightIndex = -1;
+
+ for (int i = 0; i < GetLightCount();i++)
+ {
+ _lights.GetAt(i,lightDescriptor);
+ if (lightDescriptor.pLight != null)
+ {
+ if (lightDescriptor.pLight->GetHashCode() == code)
+ {
+ lightIndex = i;
+ break;
+ }
+ }
+ }
+
+ return lightIndex;
+}
+
+Light*
+_SceneImpl::GetLightByHashCodeN(int code) const
+{
+ int lightIndex = ContainsLight(code);
+ return GetLightAtN(lightIndex);
+}
+
+//==========================================================================================ShaderProgram
+ShaderProgram*
+_SceneImpl::AddShaderProgramN(const String shaderProgramName, const char* vertexShader, const char* fragmentShader)
+{
+ SysTryReturn(NID_UI_ANIM, vertexShader != null, null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] vertexShader pointer is null.");
+
+ SysTryReturn(NID_UI_ANIM, fragmentShader != null, null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] fragmentShader pointer is null.");
+
+ SysTryReturn(NID_UI_ANIM, !(ContainsShaderProgram(shaderProgramName) >= 0), null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] ShaderProgram \"%ls\" already exists in scene \"%ls\".", shaderProgramName.GetPointer(), _name.GetPointer());
+
+ Shader vertexShaderClass, fragmentShaderClass;
+//
+// String stringT(vertexShader);
+// std::wstring stringW(stringT.GetPointer());
+// std::string stringVertexShader(stringW.begin(), stringW.end());
+ vertexShaderClass.Construct(Shader::SHADER_VERTEX, vertexShader);
+ fragmentShaderClass.Construct(Shader::SHADER_FRAGMENT, fragmentShader);
+
+ ShaderProgram* pNewShaderProgram = new (std::nothrow) ShaderProgram();
+
+ SysTryReturn(NID_UI_ANIM, pNewShaderProgram != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ pNewShaderProgram->Construct(vertexShaderClass, fragmentShaderClass);
+ pNewShaderProgram->SetName(shaderProgramName);
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ shaderProgramDescriptor.pShaderProgram = pNewShaderProgram;
+ shaderProgramDescriptor.vertexShader = vertexShader;
+ shaderProgramDescriptor.fragmentShader = fragmentShader;
+ _shaderPrograms.Add( shaderProgramDescriptor);
+
+// AppLog("vertex shader text: %s ",vertexShader);
+// AppLog("vertex shader saved text: %ls ", shaderProgramDescriptor.vertexShader.GetPointer());
+
+ ShaderProgram* pUserShaderProgram = new (std::nothrow) ShaderProgram(*pNewShaderProgram);
+
+ SysTryReturn(NID_UI_ANIM, pUserShaderProgram != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pUserShaderProgram;
+}
+
+result
+_SceneImpl::RemoveShaderProgram(const String& shaderProgramName)
+{
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(shaderProgramName);
+ SysTryReturnResult(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", shaderProgramName.GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex, shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ delete shaderProgramDescriptor.pShaderProgram;
+ shaderProgramDescriptor.pShaderProgram = null;
+ }
+
+ return _shaderPrograms.RemoveAt(shaderProgramIndex);
+}
+
+result
+_SceneImpl::RemoveShaderProgram(const ShaderProgram* pShaderProgram)
+{
+ SysTryReturnResult(NID_UI_ANIM, pShaderProgram != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] ShaderProgram pointer is null.");
+
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(pShaderProgram);
+ SysTryReturnResult(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", pShaderProgram->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex, shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ delete shaderProgramDescriptor.pShaderProgram;
+ shaderProgramDescriptor.pShaderProgram = null;
+ }
+
+ return _shaderPrograms.RemoveAt(shaderProgramIndex);
+}
+
+result
+_SceneImpl::RemoveAllShaderProgram(void)
+{
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ int count = _shaderPrograms.GetCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ _shaderPrograms.GetAt(i, shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ delete shaderProgramDescriptor.pShaderProgram;
+ shaderProgramDescriptor.pShaderProgram = null;
+ }
+ }
+ _shaderPrograms.RemoveAll();
+
+ return E_SUCCESS;
+}
+
+ShaderProgram*
+_SceneImpl::GetShaderProgramN(const String& shaderProgramName) const
+{
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(shaderProgramName);
+
+ SysTryReturn(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", shaderProgramName.GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex,shaderProgramDescriptor);
+
+ if (shaderProgramDescriptor.pShaderProgram == null)
+ {
+ return null;
+ }
+
+ ShaderProgram* pShaderProgramCopy = new (std::nothrow) ShaderProgram(*shaderProgramDescriptor.pShaderProgram);
+ SysTryReturn(NID_UI_ANIM, pShaderProgramCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pShaderProgramCopy;
+}
+
+int
+_SceneImpl::GetShaderProgramCount(void) const
+{
+ return _shaderPrograms.GetCount();
+}
+
+int
+_SceneImpl::ContainsShaderProgram(const Tizen::Base::String& shaderProgramName) const
+{
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ int shaderProgramIndex = -1;
+
+ for (int i = 0; i < GetShaderProgramCount();i++)
+ {
+ _shaderPrograms.GetAt(i,shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ if (shaderProgramDescriptor.pShaderProgram->GetName() == shaderProgramName)
+ {
+ shaderProgramIndex = i;
+ break;
+ }
+ }
+ }
+
+ return shaderProgramIndex;
+}
+
+int
+_SceneImpl::ContainsShaderProgram(const ShaderProgram* pShaderProgram) const
+{
+ SysTryReturn(NID_UI_ANIM, pShaderProgram != null, -1, E_INVALID_ARG, \
+ "[E_INVALID_ARG] ShaderProgram pointer is null.");
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ int shaderProgramIndex = -1;
+
+ for (int i = 0; i < GetShaderProgramCount();i++)
+ {
+ _shaderPrograms.GetAt(i,shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ if (shaderProgramDescriptor.pShaderProgram->GetHashCode() == pShaderProgram->GetHashCode())
+ {
+ shaderProgramIndex = i;
+ break;
+ }
+ }
+ }
+
+ return shaderProgramIndex;
+}
+
+ShaderProgram*
+_SceneImpl::GetShaderProgramAtN(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(index,shaderProgramDescriptor);
+
+ if (shaderProgramDescriptor.pShaderProgram == null)
+ {
+ return null;
+ }
+
+ ShaderProgram* pShaderProgramCopy = new (std::nothrow) ShaderProgram(*shaderProgramDescriptor.pShaderProgram);
+ SysTryReturn(NID_UI_ANIM, pShaderProgramCopy != null, null, E_OUT_OF_MEMORY, \
+ "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+ return pShaderProgramCopy;
+}
+
+Tizen::Base::String
+_SceneImpl::GetShaderProgramNameAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(index,shaderProgramDescriptor);
+
+ if (shaderProgramDescriptor.pShaderProgram == null)
+ {
+ return String(L"");
+ }
+
+ return shaderProgramDescriptor.pShaderProgram->GetName();
+}
+
+
+String
+_SceneImpl::GetShaderProgramSourceFileName(const String shaderProgramName) const
+{
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(shaderProgramName);
+
+ SysTryReturn(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", shaderProgramName.GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex,shaderProgramDescriptor);
+
+ return shaderProgramDescriptor.sourceFileName;
+}
+result
+_SceneImpl::SetShaderProgramSourceFileName(const String shaderProgramName, const String sourceFileName)
+{
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(shaderProgramName);
+
+ SysTryReturnResult(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", shaderProgramName.GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex,shaderProgramDescriptor);
+
+ shaderProgramDescriptor.sourceFileName = sourceFileName;
+
+ return _shaderPrograms.SetAt(shaderProgramDescriptor, shaderProgramIndex);
+}
+
+//not for public, but for JNI example
+String
+_SceneImpl::GetShaderProgramNameByHashCode(int code) const
+{
+ _ShaderProgramImpl* pShaderProgramImpl = (_ShaderProgramImpl*)code;
+ if (pShaderProgramImpl != null)
+ {
+ return String(pShaderProgramImpl->GetName());
+ }
+ else
+ {
+ return String(L"");
+ }
+}
+
+Tizen::Base::String
+_SceneImpl::GetShaderProgramSourceFileName(const ShaderProgram* pShaderProgram) const
+{
+ SysTryReturn(NID_UI_ANIM, pShaderProgram != null, String(L""), E_INVALID_ARG, \
+ "[E_INVALID_ARG] ShaderProgram pointer is null.");
+
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(pShaderProgram);
+
+ SysTryReturn(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", pShaderProgram->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex,shaderProgramDescriptor);
+
+ return shaderProgramDescriptor.sourceFileName;
+}
+
+result
+_SceneImpl::SetShaderProgramSourceFileName(const ShaderProgram* pShaderProgram, const Tizen::Base::String sourceFileName)
+{
+ SysTryReturnResult(NID_UI_ANIM, pShaderProgram != null, E_INVALID_ARG, \
+ "[E_INVALID_ARG] ShaderProgram pointer is null.");
+
+ int shaderProgramIndex = -1;
+ shaderProgramIndex = ContainsShaderProgram(pShaderProgram);
+
+ SysTryReturnResult(NID_UI_ANIM, (shaderProgramIndex >= 0) && (shaderProgramIndex < GetShaderProgramCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram \"%ls\" not found in scene \"%ls\".", pShaderProgram->GetName().GetPointer(), _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(shaderProgramIndex,shaderProgramDescriptor);
+
+ shaderProgramDescriptor.sourceFileName = sourceFileName;
+
+ return _shaderPrograms.SetAt(shaderProgramDescriptor, shaderProgramIndex);
+}
+
+int
+_SceneImpl::GetShaderProgramCodeAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetShaderProgramCount()), null, E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] ShaderProgram #%d not found in scene \"%ls\".", index, _name.GetPointer());
+
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ _shaderPrograms.GetAt(index,shaderProgramDescriptor);
+
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ return shaderProgramDescriptor.pShaderProgram->GetHashCode();
+ }
+ return 0;
+}
+
+int
+_SceneImpl::ContainsShaderProgram(int code) const
+{
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ int shaderProgramIndex = -1;
+
+ for (int i = 0; i < GetShaderProgramCount();i++)
+ {
+ _shaderPrograms.GetAt(i,shaderProgramDescriptor);
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ if (shaderProgramDescriptor.pShaderProgram->GetHashCode() == code)
+ {
+ shaderProgramIndex = i;
+ break;
+ }
+ }
+ }
+
+ return shaderProgramIndex;
+}
+
+ShaderProgram*
+_SceneImpl::GetShaderProgramByHashCodeN(int code) const
+{
+ int shaderProgramIndex = ContainsShaderProgram(code);
+ return GetShaderProgramAtN(shaderProgramIndex);
+}
+
+//==========================================================================================TEXTURE
+
+result
+_SceneImpl::AddTextureFileName(const String& textureFileName)
+{
+ return _textureFileNames.Add(textureFileName);
+}
+
+int
+_SceneImpl::GetTextureFileNameCount(void) const
+{
+ return _textureFileNames.GetCount();
+}
+
+String
+_SceneImpl::GetTextureFileNameAt(int index) const
+{
+ SysTryReturn(NID_UI_ANIM, (index >= 0) && (index < GetTextureFileNameCount()), String(L""), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Texture File Name #%d not found in scene \"%ls\".", index, _name.GetPointer());
+ String textureFileName;
+ _textureFileNames.GetAt(index, textureFileName);
+ return textureFileName;
+}
+result
+_SceneImpl::RemoveTextureFileNameAt(int index)
+{
+ SysTryReturnResult(NID_UI_ANIM, (index >= 0) && (index < GetTextureFileNameCount()), E_OBJ_NOT_FOUND, \
+ "[E_OBJ_NOT_FOUND] Texture File Name #%d not found in scene \"%ls\".", index, _name.GetPointer());
+ return _textureFileNames.RemoveAt(index);
+}
+
+result
+_SceneImpl::RemoveAllTextureFileName(void)
+{
+ _textureFileNames.RemoveAll();
+ return E_SUCCESS;
+}
+
+//=====================Save/Load
+std::string
+ConvertWStringToString(std::wstring& wString)
+{
+ std::string s(wString.begin(), wString.end());
+ return s;
+}
+
+result
+_SceneImpl::SaveScene(const Tizen::Base::String filesPath, const Tizen::Base::String resourceFilesPath, const Tizen::Base::String scenePrefix) const //in format: home/abc/scenespath/ or c:\\abc\\scenepath\\ ..
+{
+ /*xml structure:
+
+ <sceneName str></>
+
+ Mesh list[]
+ < id, .bin pFile str, sourceFileName str, modelNameInSourceFile str></>
+ ...
+
+ Material list[]
+ < id, .bin pFile str, sourceFileName str></>
+ ...
+
+ Light list[]
+ < id, .bin pFile str, sourceFileName str></>
+ ...
+
+ ShaderProgram list[]
+ < id, sourceFileName str>
+ <vertex shader>str</> <fragment shader>str</>
+ </>
+ ...
+
+ VisualElement []
+ <ve id, ve parent id, mesh id, material id, light id, shaderProgram id>, parentId == 0 if root scene ve, mesh...Id == -1 if non
+ <ve content></>
+ </>
+ ...
+
+ */
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ //LIBXML_TEST_VERSION
+
+ int rc;
+ result r;
+ xmlTextWriterPtr writer;
+
+ _SceneMeshDescriptor meshDescriptor;
+ _SceneMaterialDescriptor materialDescriptor;
+ _SceneLightDescriptor lightDescriptor;
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+ int count;
+ IList* childrenVisualElementList = null;
+ VisualElement* pChildVisualElement = null;
+
+ std::string tempString;
+ std::wstring tempWString;
+ String tempTString;
+
+ //file name generating
+ String xmlFileName = scenePrefix;
+ String meshResFileName = SCENE_MESH_RESOURCE_FILE_NAME;
+ String meshResFileExtension = SCENE_MESH_RESOURCE_FILE_EXTENSION;
+ String materialResFileName = SCENE_MATERIAL_RESOURCE_FILE_NAME;
+ String materialResFileExtension = SCENE_MATERIAL_RESOURCE_FILE_EXTENSION;
+ String lightResFileName = SCENE_LIGHT_RESOURCE_FILE_NAME;
+ String lightResFileExtension = SCENE_LIGHT_RESOURCE_FILE_EXTENSION;
+
+ String vertexShaderResFileName = SCENE_VERTEX_SHADER_RESOURCE_FILE_NAME;
+ String vertexShaderResFileExtension = SCENE_VERTEX_SHADER_RESOURCE_FILE_EXTENSION;
+ String fragmentShaderResFileName = SCENE_FRAGMENT_SHADER_RESOURCE_FILE_NAME;
+ String fragmentShaderResFileExtension = SCENE_FRAGMENT_SHADER_RESOURCE_FILE_EXTENSION;
+
+ //xmlFileName.Format(10,L"scene%5d",_name.GetHashCode());
+ String sceneDescriptorExtension = SCENE_DESCTRIPTOR_FILE_EXTENSION;
+ tempTString.Format(filesPath.GetLength() + xmlFileName.GetLength() + sceneDescriptorExtension.GetLength() + 2, \
+ L"%ls%ls%ls", filesPath.GetPointer(), xmlFileName.GetPointer(), sceneDescriptorExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ /* Create a new XmlWriter for uri, with no compression. */
+ writer = xmlNewTextWriterFilename(tempString.c_str(), 0);
+ xmlError* err = xmlGetLastError();
+ SysTryReturnResult(NID_UI_ANIM, writer != null, E_SYSTEM, \
+ "Failed to create XmlWriter while saving scene \"%ls\" to %s with message: %s file: %s", \
+ _name.GetPointer(), tempString.c_str(), err->message, err->file);
+
+ //create folder for resources
+// tempTString.Format(filesPath.GetLength() + xmlFileName.GetLength() + 4 + 50, L"mkdir %ls%ls_res", filesPath.GetPointer(), xmlFileName.GetPointer());
+// tempWString = tempTString.GetPointer();
+// tempString = ConvertWStringToString(tempWString);
+// system(tempString.c_str());
+
+
+ /* Start the document with the xml default for the version,
+ * encoding ISO 8859-1 and the default for the standalone
+ * declaration. */
+ rc = xmlTextWriterStartDocument(writer, NULL, LOCAL_XML_ENCODING, NULL);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, ,E_SYSTEM, \
+ "Failed to start document with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ /* Start an element named "Scene". Since this is the first
+ * element, this will be the root element of the document. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Scene");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempWString = _name.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
+ BAD_CAST tempString.c_str());
+
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "Meshes" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Meshes");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ count = _meshes.GetCount();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "count", "%d", count);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //write meshes
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+
+ for(int i = 0; i < count && i < MAX_RES_FILES_COUNT; i++)
+ {
+ _meshes.GetAt(i, meshDescriptor);
+
+ //open "Mesh" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Mesh");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempTString.Format(50,L"%d",i);
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ if(meshDescriptor.pMesh != null)
+ {
+ tempWString = meshDescriptor.pMesh->GetName().GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+
+ tempWString = meshDescriptor.sourceFileName.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "sourceFileName", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempWString = meshDescriptor.modelNameInSourceFile.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "modelNameInSourceFile", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //form mesh bin file name
+
+ tempTString.Format(resourceFilesPath.GetLength() + xmlFileName.GetLength() + meshResFileName.GetLength() + meshResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", resourceFilesPath.GetPointer(), xmlFileName.GetPointer(), meshResFileName.GetPointer(), i, meshResFileExtension.GetPointer());
+
+ if(meshDescriptor.pMesh != null)
+ {
+ meshDescriptor.pMesh->SaveMesh(tempTString);
+ }
+
+ //close "Mesh" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ //close "Meshes" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "Materials" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Materials");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ //write materials
+ count = _materials.GetCount();
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "count", "%d", count);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ for (int i = 0; i < count && i < MAX_RES_FILES_COUNT; i++)
+ {
+ _materials.GetAt(i, materialDescriptor);
+
+ //open "Material" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Material");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempTString.Format(50,L"%d",i);
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ if(materialDescriptor.pMaterial != null)
+ {
+ tempWString = materialDescriptor.pMaterial->GetName().GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+
+ tempWString = materialDescriptor.sourceFileName.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "sourceFileName", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //form material xml file name
+ tempTString.Format(resourceFilesPath.GetLength() + xmlFileName.GetLength() + materialResFileName.GetLength() + materialResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", resourceFilesPath.GetPointer(), xmlFileName.GetPointer(), materialResFileName.GetPointer(), i, materialResFileExtension.GetPointer());
+
+
+ if (materialDescriptor.pMaterial != null)
+ {
+ _MaterialParser::SaveMaterial(materialDescriptor.pMaterial, tempTString);
+ //TODO://materialDescriptor.pMaterial->SaveMaterialToXml(tempTString);
+ }
+
+ //close "Material" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ //close "Material" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "Meshes" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Lights");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ //write lights
+ count = _lights.GetCount();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "count", "%d", count);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ for (int i = 0; i < count && i < MAX_RES_FILES_COUNT; i++)
+ {
+ _lights.GetAt(i, lightDescriptor);
+
+ //open "Light" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "Light");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempTString.Format(50,L"%d",i);
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ if(lightDescriptor.pLight != null)
+ {
+ tempWString = lightDescriptor.pLight->GetName().GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+
+ tempWString = lightDescriptor.sourceFileName.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "sourceFileName", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //form light xml file name
+ tempTString.Format(resourceFilesPath.GetLength() + xmlFileName.GetLength() + lightResFileName.GetLength() + lightResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", resourceFilesPath.GetPointer(), xmlFileName.GetPointer(), lightResFileName.GetPointer(), i, lightResFileExtension.GetPointer());
+
+ if (lightDescriptor.pLight != null)
+ {
+ _LightParser::SaveLight(lightDescriptor.pLight, tempTString);
+ //TODO://lightDescriptor.pLight->SaveLightToXml(tempTString);
+ }
+
+ //close "Light" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ //close "Lights" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "ShaderPrograms" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ShaderPrograms");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ //write ShaderPrograms
+ count = _shaderPrograms.GetCount();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "count", "%d", count);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ for (int i = 0; i < count; i++)
+ {
+ _shaderPrograms.GetAt(i, shaderProgramDescriptor);
+
+ //open "ShaderProgram" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ShaderProgram");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempTString.Format(50,L"%d",i);
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ if (shaderProgramDescriptor.pShaderProgram != null)
+ {
+ tempWString = shaderProgramDescriptor.pShaderProgram->GetName().GetPointer();
+ }
+ else
+ {
+ tempWString = L"";
+ }
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempWString = shaderProgramDescriptor.sourceFileName.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "sourceFileName", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //write shader to text file
+ tempTString.Format(resourceFilesPath.GetLength() + xmlFileName.GetLength() + vertexShaderResFileName.GetLength() + vertexShaderResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", resourceFilesPath.GetPointer(), xmlFileName.GetPointer(), vertexShaderResFileName.GetPointer(), i, vertexShaderResFileExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ std::ofstream vertex(tempString.c_str(), std::ofstream::out);
+ if (vertex.good())
+ {
+ tempWString = shaderProgramDescriptor.vertexShader.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ vertex.write(tempString.c_str(), tempString.length());
+ vertex.close();
+ }
+
+////for UTF-8 shader saving in .are
+// rc = xmlTextWriterWriteElement(writer, BAD_CAST "VertexShader", BAD_CAST tempString.c_str());
+// SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ tempTString.Format(resourceFilesPath.GetLength() + xmlFileName.GetLength() + fragmentShaderResFileName.GetLength() + fragmentShaderResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", resourceFilesPath.GetPointer(), xmlFileName.GetPointer(), fragmentShaderResFileName.GetPointer(), i, fragmentShaderResFileExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ std::ofstream fragment(tempString.c_str(), std::ofstream::out);
+ if (fragment.good())
+ {
+ tempWString = shaderProgramDescriptor.fragmentShader.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ fragment.write(tempString.c_str(), tempString.length());
+ fragment.close();
+ }
+
+
+////for UTF-8 shader saving in .are
+// rc = xmlTextWriterWriteElement(writer, BAD_CAST "FragmentShader", BAD_CAST tempString.c_str());
+// SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //close "ShaderProgram" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ //close "ShaderPrograms" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "TextureFileNames" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "TextureFileNames");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ //write TextureFileNames
+ count = _textureFileNames.GetCount();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "count", "%d", count);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ for (int i = 0; i < count; i++)
+ {
+ //open "TextureFileName" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "TextureFileName");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", i);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ _textureFileNames.GetAt(i, tempTString);
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "textureFileName", BAD_CAST tempString.c_str());
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //close "TextureFileName" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ //close "TextureFileNames" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //open "VisualElements" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "VisualElements");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ //write root children VisualElements
+ count = _pSceneRootVisualElement->GetChildrenCount();
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ else
+ {
+ //save root children
+ childrenVisualElementList = _pSceneRootVisualElement->GetChildrenN();
+ if (childrenVisualElementList != null)
+ {
+ count = childrenVisualElementList->GetCount();
+ for (int i = 0; i < count; i++)
+ {
+ pChildVisualElement = (VisualElement*)childrenVisualElementList->GetAt(i);
+ if (pChildVisualElement != null)
+ {
+ r = __SaveSceneVisualElementTree(writer, pChildVisualElement);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS , , r, \
+ "Failed save scene \"%ls\" propagating", _name.GetPointer());
+ }
+ }
+
+ delete childrenVisualElementList;
+ childrenVisualElementList = null;
+ }
+ }
+
+ //close "VisualElements" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //write close "Scene"
+ rc = xmlTextWriterEndElement(writer);
+ SysTryCatch(NID_UI_ANIM, rc >= 0, , E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //close document
+ rc = xmlTextWriterEndDocument(writer);
+
+
+ //finishing document
+ xmlFreeTextWriter(writer);
+
+ return E_SUCCESS;
+CATCH:
+ xmlFreeTextWriter(writer);
+ if (childrenVisualElementList != null)
+ {
+ delete childrenVisualElementList;
+ }
+
+
+ return E_SYSTEM;
+}
+
+result
+_SceneImpl::__SaveSceneVisualElementTree(const xmlTextWriterPtr writer, const VisualElement* pVisualElement) const
+{
+ IList* childrenVisualElementList = null;
+ Mesh* pMesh = null;
+ Material* pMaterial = null;
+ Light* pLight = null;
+ ShaderProgram* pShaderProgram = null;
+ VisualElement* pChildVisualElement = null;
+ int rc;
+ std::string tempString;
+ std::wstring tempWString;
+ String tempTString;
+
+ //open "VisualElement" element
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "VisualElement");
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //save current VE ids to xml
+ pMesh = pVisualElement->GetMeshN();
+ if (pMesh != null)
+ {
+ tempTString.Format(50,L"%d", ContainsMesh(pMesh));
+ delete pMesh;
+ pMesh = null;
+ }
+ else
+ {
+ tempTString.Format(50,L"%d", -1);
+ }
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "meshId", BAD_CAST tempString.c_str());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ pMaterial = pVisualElement->GetMaterialN();
+ if (pMaterial != null)
+ {
+ tempTString.Format(50,L"%d", ContainsMaterial(pMaterial));
+ delete pMaterial;
+ pMaterial = null;
+ }
+ else
+ {
+ tempTString.Format(50,L"%d", -1);
+ }
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "materialId", BAD_CAST tempString.c_str());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ pLight = pVisualElement->GetLightN();
+ if (pLight != null)
+ {
+ tempTString.Format(50,L"%d", ContainsLight(pLight));
+ delete pLight;
+ pLight = null;
+ }
+ else
+ {
+ tempTString.Format(50,L"%d", -1);
+ }
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "lightId", BAD_CAST tempString.c_str());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ pShaderProgram = pVisualElement->GetShaderProgramN();
+ if (pShaderProgram != null)
+ {
+ tempTString.Format(50,L"%d", ContainsShaderProgram(pShaderProgram));
+ delete pShaderProgram;
+ pShaderProgram = null;
+ }
+ else
+ {
+ tempTString.Format(50,L"%d", -1);
+ }
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "shaderProgramId", BAD_CAST tempString.c_str());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //save current ve content
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%ls", pVisualElement->GetName().GetPointer());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ FloatPoint point = pVisualElement->GetAnchor();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "anchor", "%f %f", point.x, point.y);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "anchorZ", "%f", pVisualElement->GetAnchorZ());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ FloatRectangle rectangle = pVisualElement->GetBounds();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "bounds", "%f %f %f %f", rectangle.x, rectangle.y, rectangle.width, rectangle.height);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ FloatMatrix4 matrix = pVisualElement->GetTransformMatrix();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "transformMatrix", "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", \
+ matrix.matrix[0][0], matrix.matrix[0][1], matrix.matrix[0][2], matrix.matrix[0][3],
+ matrix.matrix[1][0], matrix.matrix[1][1], matrix.matrix[1][2], matrix.matrix[1][3],
+ matrix.matrix[2][0], matrix.matrix[2][1], matrix.matrix[2][2], matrix.matrix[2][3],
+ matrix.matrix[3][0], matrix.matrix[3][1], matrix.matrix[3][2], matrix.matrix[3][3]);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ matrix = pVisualElement->GetChildrenTransformMatrix();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "childrenTransformMatrix", "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", \
+ matrix.matrix[0][0], matrix.matrix[0][1], matrix.matrix[0][2], matrix.matrix[0][3],
+ matrix.matrix[1][0], matrix.matrix[1][1], matrix.matrix[1][2], matrix.matrix[1][3],
+ matrix.matrix[2][0], matrix.matrix[2][1], matrix.matrix[2][2], matrix.matrix[2][3],
+ matrix.matrix[3][0], matrix.matrix[3][1], matrix.matrix[3][2], matrix.matrix[3][3]);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "clipChildrenEnabled", "%s", pVisualElement->IsClipChildrenEnabled()?"true":"false");
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rectangle = pVisualElement->GetContentBounds();
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "contentBounds", "%f %f %f %f", rectangle.x, rectangle.y, rectangle.width, rectangle.height);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "implicitAnimationEnabled", "%s", pVisualElement->IsImplicitAnimationEnabled()?"true":"false");
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "opacity", "%f", pVisualElement->GetOpacity());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "renderOperation", "%d", (int)pVisualElement->GetRenderOperation());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "showState", "%s", pVisualElement->GetShowState()?"true":"false");
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "zorderGroup", "%d", pVisualElement->GetZOrderGroup());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "zposition", "%f", pVisualElement->GetOpacity());
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ //write children VisualElements
+ int count = pVisualElement->GetChildrenCount();
+ if (count == 0) //to close tag right way
+ {
+ rc = xmlTextWriterWriteString(writer, BAD_CAST "");
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+ }
+ else
+ {
+ result r = E_SUCCESS;
+ //get children
+ childrenVisualElementList = pVisualElement->GetChildrenN();
+ if (childrenVisualElementList != null)
+ {
+ count = childrenVisualElementList->GetCount();
+ for (int i = 0; i < count; i++)
+ {
+ pChildVisualElement = (VisualElement*)childrenVisualElementList->GetAt(i);
+ if (pChildVisualElement != null)
+ {
+ r = __SaveSceneVisualElementTree(writer, pChildVisualElement);
+ if (r != E_SUCCESS)
+ {
+ delete childrenVisualElementList;
+ childrenVisualElementList = null;
+ return r;
+ }
+ }
+ }
+
+ delete childrenVisualElementList;
+ childrenVisualElementList = null;
+ }
+ }
+
+ //close "VisualElement" element
+ rc = xmlTextWriterEndElement(writer);
+ SysTryReturnResult(NID_UI_ANIM, rc >= 0, E_SYSTEM, \
+ "Failed to write with XmlWriter while saving scene \"%ls\"", _name.GetPointer());
+
+ return E_SUCCESS;
+}
+
+void __LoadSceneOnStartDocument(void* pUserData){}
+void __LoadSceneOnStartElement(void* pUserData, const xmlChar* pName, const xmlChar **pAttributes);
+void __LoadSceneOnContent(void* pUserData, const xmlChar* pContent, int length);
+void __LoadSceneOnEndElement(void* pUserData, const xmlChar* pName);
+void __LoadSceneOnEndDocument(void* pUserData){}
+void __LoadSceneOnError(void* pUserData, const char *pMsg){}
+
+struct __SceneSAXParsingUserData
+{
+ __SceneSAXParsingUserData(void)
+ {
+ parsingResult = E_SUCCESS;
+ pCurrentParentVisualElement = null;
+
+ currentMeshId = -1;
+ currentMaterialId = -1;
+ currentLightId = -1;
+ currentShaderProgramId = -1;
+ currentTexturFileNameId = -1;
+
+ isScene = false;
+ isMeshes = false; isMesh = false;
+ isMaterials = false; isMaterial = false;
+ isLights = false; isLight = false;
+ isShaderPrograms = false; isShaderProgram = false; isVertexShader = false; isFragmentShader = false;
+ isTextureFileNames = false; isTextureFileName = false;
+ isVisualElements = false; isVisualElement = false;
+ }
+ void Clear(void)
+ {
+// currentMeshId = -1;
+// currentMaterialId = -1;
+// currentLightId = -1;
+// currentShaderProgramId = -1;
+// currentTexturFileNameId = -1;
+
+ meshDescriptor.Clear();
+ materialDescriptor.Clear();
+ lightDescriptor.Clear();
+ shaderProgramDescriptor.Clear();
+
+ shaderProgramName.Clear();
+ texfureFileName.Clear();
+ }
+
+ result parsingResult;
+
+ int currentMeshId;
+ int currentMaterialId;
+ int currentLightId;
+ int currentShaderProgramId;
+ int currentTexturFileNameId;
+
+ _SceneMeshDescriptor meshDescriptor;
+ _SceneMaterialDescriptor materialDescriptor;
+ _SceneLightDescriptor lightDescriptor;
+ _SceneShaderProgramDescriptor shaderProgramDescriptor;
+
+ VisualElement* pCurrentParentVisualElement;
+
+ String filesPath, scenePrefix, resourceFilesPath;
+
+ String shaderProgramName;
+ String texfureFileName;
+
+ _SceneImpl* pSceneImpl;
+
+ bool isScene;
+ bool isMeshes, isMesh;
+ bool isMaterials, isMaterial;
+ bool isLights, isLight;
+ bool isShaderPrograms, isShaderProgram, isVertexShader, isFragmentShader;
+ bool isTextureFileNames, isTextureFileName;
+ bool isVisualElements, isVisualElement;
+
+// ArrayListT< __SceneVisualElementDescriptor > children;
+};
+
+Scene*
+_SceneImpl::LoadSceneN(const Tizen::Base::String filesPath, const Tizen::Base::String resourceFilesPath, const Tizen::Base::String scenePrefix, VisualElement& sceneRootVisualElement) //in format: home/abc/scenespath/ or c:\\abc\\scenepath\\ ..
+{
+ std::string tempString;
+ std::wstring tempWString;
+ String tempTString;
+ int rc;
+ xmlError* err;
+ Scene* pScene = null;
+ struct __SceneSAXParsingUserData* pUserData = null;
+ result r;
+
+
+ //file name generating
+ String xmlFileName = scenePrefix;
+ //xmlFileName.Format(10,L"scene%5d",_name.GetHashCode());
+ String sceneDescriptorExtension = SCENE_DESCTRIPTOR_FILE_EXTENSION;
+ tempTString.Format(filesPath.GetLength() + xmlFileName.GetLength() + sceneDescriptorExtension.GetLength() + 2, \
+ L"%ls%ls%ls", filesPath.GetPointer(), xmlFileName.GetPointer(), sceneDescriptorExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ std::ifstream f(tempString.c_str());
+ SysTryReturn(NID_UI_ANIM, f.good(), null, E_FILE_NOT_FOUND, \
+ "Cannot open file %s while loading scene.", tempString.c_str());
+ f.close();
+
+ xmlSAXHandler sceneSAXHandler;
+ memset(&sceneSAXHandler, 0, sizeof(_xmlSAXHandler));
+ //mySAXHandler.startDocument = __LoadSceneOnStartDocument;
+ sceneSAXHandler.startElement = __LoadSceneOnStartElement;
+ sceneSAXHandler.characters = __LoadSceneOnContent;
+ sceneSAXHandler.endElement = __LoadSceneOnEndElement;
+ //mySAXHandler.endDocument = __LoadSceneOnEndDocument;
+ //mySAXHandler.error = __LoadSceneOnError;
+
+ pUserData = new (std::nothrow) struct __SceneSAXParsingUserData;
+ SysTryCatch(NID_UI_ANIM, pUserData != null, , E_OUT_OF_MEMORY, \
+ "Insufficient memory.");
+
+ pScene = new (std::nothrow) Scene();
+ SysTryCatch(NID_UI_ANIM, pScene != null, , E_OUT_OF_MEMORY, \
+ "Insufficient memory.");
+
+ r = pScene->Construct(sceneRootVisualElement);
+
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, \
+ "Scene construct error, propagating.");
+
+ pUserData->pSceneImpl = pScene->__pSceneImpl;
+ pUserData->parsingResult = E_SUCCESS;
+ pUserData->filesPath = filesPath;
+ pUserData->scenePrefix = scenePrefix;
+ pUserData->resourceFilesPath = resourceFilesPath;
+ pUserData->pCurrentParentVisualElement = pScene->GetRootVisualElement();
+
+ //start parsing
+ rc = xmlSAXUserParseFile(&sceneSAXHandler, (void*)pUserData, tempString.c_str());
+ err = xmlGetLastError();
+
+ SysTryCatch(NID_UI_ANIM, rc == 0, , E_SYSTEM, \
+ "Xml error while parsing file %s while loading scene. Error message: %s", tempString.c_str(), err->message);
+
+ SysTryCatch(NID_UI_ANIM, pUserData->parsingResult == E_SUCCESS, , pUserData->parsingResult, \
+ "Error propagating while loading scene .");
+
+ return pScene;
+
+CATCH:
+ if (pUserData != null)
+ {
+ delete pUserData;
+ pUserData = null;
+ }
+ if (pScene != null)
+ {
+ delete pScene;
+ pScene = null;
+ }
+ return null;
+}
+
+void
+__LoadSceneOnStartElement(void* pUserData, const xmlChar* pName, const xmlChar **pAttributes)
+{
+ String elementName((const char*)pName);
+ std::string tempString;
+ std::wstring tempWString;
+ int count;
+ String attributeName;
+ String attributeValue;
+ result r;
+
+ struct __SceneSAXParsingUserData* pUserDataT = (struct __SceneSAXParsingUserData*)pUserData;
+ if (pUserDataT->parsingResult != E_SUCCESS)
+ {
+ return;
+ }
+
+ //read resources properties to create them on element closing
+ if (pUserDataT->isMeshes && !pUserDataT->isMesh)
+ {
+ if (elementName.CompareTo("Mesh") == 0)
+ {
+ pUserDataT->isMesh = true;
+ pUserDataT->currentMeshId = -1;
+ pUserDataT->meshDescriptor.Clear();
+
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+ if (attributeName.CompareTo("id") == 0)
+ {
+ pUserDataT->currentMeshId = atoi((const char*) pAttributes[i+1]);
+ //pUserDataT->currentMeshId = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("sourceFileName") == 0)
+ {
+ pUserDataT->meshDescriptor.sourceFileName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("modelNameInSourceFile") == 0)
+ {
+ pUserDataT->meshDescriptor.modelNameInSourceFile = (const char*) pAttributes[i+1];
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+ }
+
+ if (pUserDataT->isMaterials && !pUserDataT->isMaterial)
+ {
+ if (elementName.CompareTo("Material") == 0)
+ {
+ pUserDataT->isMaterial = true;
+ pUserDataT->currentMaterialId = -1;
+ pUserDataT->materialDescriptor.Clear();
+
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+ if (attributeName.CompareTo("id") == 0)
+ {
+ pUserDataT->currentMaterialId = atoi((const char*) pAttributes[i+1]);
+ //pUserDataT->currentMeshId = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("sourceFileName") == 0)
+ {
+ pUserDataT->materialDescriptor.sourceFileName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+ }
+
+ if (pUserDataT->isLights && !pUserDataT->isLight)
+ {
+ if (elementName.CompareTo("Light") == 0)
+ {
+ pUserDataT->isLight = true;
+ pUserDataT->currentLightId = -1;
+ pUserDataT->lightDescriptor.Clear();
+
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+ if (attributeName.CompareTo("id") == 0)
+ {
+ pUserDataT->currentLightId = atoi((const char*) pAttributes[i+1]);
+ //pUserDataT->currentMeshId = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("sourceFileName") == 0)
+ {
+ pUserDataT->lightDescriptor.sourceFileName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+ }
+
+ if (pUserDataT->isShaderPrograms && !pUserDataT->isShaderProgram)
+ {
+ if (elementName.CompareTo("ShaderProgram") == 0)
+ {
+ pUserDataT->isShaderProgram = true;
+ pUserDataT->currentShaderProgramId = -1;
+ pUserDataT->shaderProgramName.Clear();
+ pUserDataT->shaderProgramDescriptor.Clear();
+
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+ if (attributeName.CompareTo("id") == 0)
+ {
+ pUserDataT->currentShaderProgramId = atoi((const char*) pAttributes[i+1]);
+ continue;
+ }
+ if (attributeName.CompareTo("name") == 0)
+ {
+ pUserDataT->shaderProgramName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("sourceFileName") == 0)
+ {
+ pUserDataT->shaderProgramDescriptor.sourceFileName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+ }
+////for UTF-8 shader saving in .are
+// if (pUserDataT->isShaderProgram && !pUserDataT->isVertexShader && !pUserDataT->isFragmentShader)
+// {
+// if (elementName.CompareTo("VertexShader") == 0)
+// {
+// pUserDataT->isVertexShader = true;
+// return;
+// }
+// }
+//
+//
+// if (pUserDataT->isShaderProgram && !pUserDataT->isVertexShader && !pUserDataT->isFragmentShader)
+// {
+// if (elementName.CompareTo("FragmentShader") == 0)
+// {
+// pUserDataT->isFragmentShader = true;
+// return;
+// }
+// }
+
+ if (pUserDataT->isTextureFileNames && !pUserDataT->isTextureFileName)
+ {
+ if (elementName.CompareTo("TextureFileName") == 0)
+ {
+ pUserDataT->isTextureFileName = true;
+ pUserDataT->currentTexturFileNameId = -1;
+ pUserDataT->texfureFileName.Clear();
+
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+ if (attributeName.CompareTo("id") == 0)
+ {
+ pUserDataT->currentTexturFileNameId = atoi((const char*) pAttributes[i+1]);
+ continue;
+ }
+ if (attributeName.CompareTo("textureFileName") == 0)
+ {
+ pUserDataT->texfureFileName = (const char*) pAttributes[i+1];
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+ }
+
+ if (pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("VisualElement") == 0)
+ {
+ pUserDataT->isVisualElement = true;
+ _SceneVisualElementDescriptor veDescr;
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ //attributeValue = (const char*) pAttributes[i+1];
+
+ if (attributeName.CompareTo("meshId") == 0)
+ {
+ veDescr.meshId = atoi((const char*) pAttributes[i+1]);
+ //sscanf((const char*) pAttributes[i+1], "%d", &visualElementDescriptor.meshId);
+ continue;
+ }
+ if (attributeName.CompareTo("materialId") == 0)
+ {
+ veDescr.materialId = atoi((const char*) pAttributes[i+1]);
+ continue;
+ }
+ if (attributeName.CompareTo("lightId") == 0)
+ {
+ veDescr.lightId = atoi((const char*) pAttributes[i+1]);
+ continue;
+ }
+ if (attributeName.CompareTo("shaderProgramId") == 0)
+ {
+ veDescr.shaderProgramId = atoi((const char*) pAttributes[i+1]);
+ continue;
+ }
+
+ if (attributeName.CompareTo("name") == 0)
+ {
+ veDescr.name = (const char*) pAttributes[i+1];
+ continue;
+ }
+ if (attributeName.CompareTo("anchor") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f %f", \
+ &veDescr.anchor.x, &veDescr.anchor.y);
+ continue;
+ }
+ if (attributeName.CompareTo("anchorZ") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f", &veDescr.anchorZ);
+ continue;
+ }
+ if (attributeName.CompareTo("bounds") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f %f %f %f", \
+ &veDescr.bounds.x, &veDescr.bounds.y, &veDescr.bounds.width, &veDescr.bounds.height);
+ continue;
+ }
+ if (attributeName.CompareTo("transformMatrix") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", \
+ &veDescr.transformMatrix.matrix[0][0], &veDescr.transformMatrix.matrix[0][1], &veDescr.transformMatrix.matrix[0][2], &veDescr.transformMatrix.matrix[0][3], \
+ &veDescr.transformMatrix.matrix[1][0], &veDescr.transformMatrix.matrix[1][1], &veDescr.transformMatrix.matrix[1][2], &veDescr.transformMatrix.matrix[1][3], \
+ &veDescr.transformMatrix.matrix[2][0], &veDescr.transformMatrix.matrix[2][1], &veDescr.transformMatrix.matrix[2][2], &veDescr.transformMatrix.matrix[2][3], \
+ &veDescr.transformMatrix.matrix[3][0], &veDescr.transformMatrix.matrix[3][1], &veDescr.transformMatrix.matrix[3][2], &veDescr.transformMatrix.matrix[3][3]);
+ continue;
+ }
+ if (attributeName.CompareTo("childrenTransformMatrix") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", \
+ &veDescr.childrenTransformMatrix.matrix[0][0], &veDescr.childrenTransformMatrix.matrix[0][1], &veDescr.childrenTransformMatrix.matrix[0][2], &veDescr.childrenTransformMatrix.matrix[0][3], \
+ &veDescr.childrenTransformMatrix.matrix[1][0], &veDescr.childrenTransformMatrix.matrix[1][1], &veDescr.childrenTransformMatrix.matrix[1][2], &veDescr.childrenTransformMatrix.matrix[1][3], \
+ &veDescr.childrenTransformMatrix.matrix[2][0], &veDescr.childrenTransformMatrix.matrix[2][1], &veDescr.childrenTransformMatrix.matrix[2][2], &veDescr.childrenTransformMatrix.matrix[2][3], \
+ &veDescr.childrenTransformMatrix.matrix[3][0], &veDescr.childrenTransformMatrix.matrix[3][1], &veDescr.childrenTransformMatrix.matrix[3][2], &veDescr.childrenTransformMatrix.matrix[3][3]);
+ continue;
+ }
+ if (attributeName.CompareTo("clipChildrenEnabled") == 0)
+ {
+ attributeValue = (const char*) pAttributes[i+1];
+ if (attributeValue.CompareTo("true") == 0)
+ {
+ veDescr.clipChildrenEnabled = true;
+ }
+ else
+ {
+ veDescr.clipChildrenEnabled = false;
+ }
+ continue;
+ }
+ if (attributeName.CompareTo("contentBounds") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f %f %f %f", \
+ &veDescr.contentBounds.x, &veDescr.contentBounds.y, &veDescr.contentBounds.width, &veDescr.contentBounds.height);
+ continue;
+ }
+ if (attributeName.CompareTo("implicitAnimationEnabled") == 0)
+ {
+ attributeValue = (const char*) pAttributes[i+1];
+ if (attributeValue.CompareTo("true") == 0)
+ {
+ veDescr.implicitAnimationEnabled = true;
+ }
+ else
+ {
+ veDescr.implicitAnimationEnabled = false;
+ }
+ continue;
+ }
+ if (attributeName.CompareTo("opacity") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f", &veDescr.opacity);
+ continue;
+ }
+ if (attributeName.CompareTo("renderOperation") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%d", &veDescr.renderOperation);
+ continue;
+ }
+ if (attributeName.CompareTo("showState") == 0)
+ {
+ attributeValue = (const char*) pAttributes[i+1];
+ if (attributeValue.CompareTo("true") == 0)
+ {
+ veDescr.showState = true;
+ }
+ else
+ {
+ veDescr.showState = false;
+ }
+ continue;
+ }
+ if (attributeName.CompareTo("zorderGroup") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%d", &veDescr.zorderGroup);
+ continue;
+ }
+ if (attributeName.CompareTo("zposition") == 0)
+ {
+ sscanf((const char*) pAttributes[i+1], "%f", &veDescr.zposition);
+ continue;
+ }
+ }
+ }
+
+ VisualElement* pVisualElement = new (std::nothrow) VisualElement();
+ if (pVisualElement == null)
+ {
+ SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+ pUserDataT->parsingResult = E_OUT_OF_MEMORY;
+ return;
+ }
+ r = pVisualElement->Construct();
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_UI_ANIM, r, "VisualElement Construct error propagating.");
+ pUserDataT->parsingResult = r;
+ return;
+ }
+
+ if (pUserDataT->pCurrentParentVisualElement != null)
+ {
+ pVisualElement->SetName(veDescr.name);
+
+ pVisualElement->SetAnchor(veDescr.anchor);
+ pVisualElement->SetAnchorZ(veDescr.anchorZ);
+ pVisualElement->SetBounds(veDescr.bounds);
+ pVisualElement->SetTransformMatrix(veDescr.transformMatrix);
+ pVisualElement->SetChildrenTransformMatrix(veDescr.childrenTransformMatrix);
+ pVisualElement->SetClipChildrenEnabled(veDescr.clipChildrenEnabled);
+ pVisualElement->SetContentBounds(veDescr.contentBounds);
+ pVisualElement->SetImplicitAnimationEnabled(veDescr.implicitAnimationEnabled);
+ pVisualElement->SetOpacity(veDescr.opacity);
+ pVisualElement->SetRenderOperation((VisualElement::RenderOperation)veDescr.renderOperation);
+ pVisualElement->SetShowState(veDescr.showState);
+ pVisualElement->SetZOrderGroup(veDescr.zorderGroup);
+ pVisualElement->SetZPosition(veDescr.zposition);
+
+ if (veDescr.meshId != -1)
+ {
+ Mesh* pMesh = pUserDataT->pSceneImpl->GetMeshAtN(veDescr.meshId);
+ pVisualElement->SetMesh(pMesh);
+ }
+ if (veDescr.materialId != -1)
+ {
+ Material* pMaterial = pUserDataT->pSceneImpl->GetMaterialAtN(veDescr.materialId);
+ pVisualElement->SetMaterial(pMaterial);
+ }
+ if (veDescr.lightId != -1)
+ {
+ Light* pLight = pUserDataT->pSceneImpl->GetLightAtN(veDescr.lightId);
+ pVisualElement->SetLight(pLight);
+ }
+ if (veDescr.shaderProgramId != -1)
+ {
+ ShaderProgram* pShaderProgram = pUserDataT->pSceneImpl->GetShaderProgramAtN(veDescr.shaderProgramId);
+ pVisualElement->SetShaderProgram(pShaderProgram);
+ }
+
+ pUserDataT->pCurrentParentVisualElement->AttachChild(pVisualElement);
+ pUserDataT->pCurrentParentVisualElement = pVisualElement;
+ }
+ else
+ {
+ pVisualElement->Destroy();
+ SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Scene tree building error.");
+ pUserDataT->parsingResult = E_INVALID_ARG;
+ }
+
+ return;
+ }
+ }
+
+
+ //create empty recourses in scene lists, to save id structure
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("Meshes") == 0)
+ {
+ pUserDataT->isMeshes = true;
+ if (pAttributes != null)
+ {
+
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("count") == 0)
+ {
+ count = atoi((const char*) pAttributes[i+1]);
+ _SceneMeshDescriptor meshVoidDescriptor;
+ meshVoidDescriptor.Clear();
+
+ for (int j = 0; j < count; j++)
+ {
+ pUserDataT->pSceneImpl->_meshes.Add(meshVoidDescriptor);
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("Materials") == 0)
+ {
+ pUserDataT->isMaterials = true;
+ if (pAttributes != null)
+ {
+
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("count") == 0)
+ {
+ count = atoi((const char*) pAttributes[i+1]);
+ _SceneMaterialDescriptor materialVoidDescriptor;
+ materialVoidDescriptor.Clear();
+ for (int j = 0; j < count; j++)
+ {
+ pUserDataT->pSceneImpl->_materials.Add(materialVoidDescriptor);
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("Lights") == 0)
+ {
+ pUserDataT->isLights = true;
+ if (pAttributes != null)
+ {
+
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("count") == 0)
+ {
+ count = atoi((const char*) pAttributes[i+1]);
+ _SceneLightDescriptor lightVoidDescriptor;
+ lightVoidDescriptor.Clear();
+ for (int j = 0; j < count; j++)
+ {
+ pUserDataT->pSceneImpl->_lights.Add(lightVoidDescriptor);
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("ShaderPrograms") == 0)
+ {
+ pUserDataT->isShaderPrograms = true;
+ if (pAttributes != null)
+ {
+
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("count") == 0)
+ {
+ count = atoi((const char*) pAttributes[i+1]);
+ _SceneShaderProgramDescriptor shaderProgramVoidDescriptor;
+ shaderProgramVoidDescriptor.Clear();
+
+ for (int j = 0; j < count; j++)
+ {
+ pUserDataT->pSceneImpl->_shaderPrograms.Add(shaderProgramVoidDescriptor);
+ }
+ }
+ }
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("TextureFileNames") == 0)
+ {
+ pUserDataT->isTextureFileNames = true;
+ if (pAttributes != null)
+ {
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("count") == 0)
+ {
+ count = atoi((const char*) pAttributes[i+1]);
+ attributeValue.Clear();
+
+ for (int j = 0; j < count; j++)
+ {
+ pUserDataT->pSceneImpl->_textureFileNames.Add(attributeValue);
+ }
+ break;
+ }
+ }
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames && !pUserDataT->isVisualElements)
+ {
+ if (elementName.CompareTo("VisualElements") == 0)
+ {
+ pUserDataT->isVisualElements = true;
+ return;
+ }
+ }
+
+ if (!pUserDataT->isScene)
+ {
+ if (elementName.CompareTo("Scene") == 0)
+ {
+ pUserDataT->isScene = true;
+ if (pAttributes != null)
+ {
+
+ for (int i = 0; pAttributes[i] != null; i+=2)
+ {
+ attributeName = (const char*) pAttributes[i];
+ if (attributeName.CompareTo("name") == 0)
+ {
+ attributeValue = (const char*) pAttributes[i+1];
+ pUserDataT->pSceneImpl->SetName(attributeValue);
+ break;
+ }
+ }
+ }
+ return;
+ }
+ }
+ else
+ {
+ return; //ignore all until meet Scene element
+ }
+
+ //generate error to stop parsing by file structure mistakes
+ SysLogException(NID_UI_ANIM, E_INVALID_FORMAT, "Wrong file structure. Error reading.");
+ pUserDataT->parsingResult = E_INVALID_FORMAT;
+ return;
+}
+
+void
+__LoadSceneOnContent(void* pUserData, const xmlChar* pContent, int length)
+{
+ struct __SceneSAXParsingUserData* pUserDataT = (struct __SceneSAXParsingUserData*)pUserData;
+ if (pUserDataT->parsingResult != E_SUCCESS)
+ {
+ return;
+ }
+
+ if (pUserDataT->isVertexShader)
+ {
+ char* pVertexUtf8Text = new char[length + 2];
+ if (pVertexUtf8Text != null)
+ {
+ strncpy(pVertexUtf8Text, (const char*)pContent, length);
+ pVertexUtf8Text[length] = '\0';
+ Tizen::Base::Utility::StringUtil::Utf8ToString(pVertexUtf8Text, pUserDataT->shaderProgramDescriptor.vertexShader);
+ }
+ else
+ {
+ SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+ pUserDataT->parsingResult = E_OUT_OF_MEMORY;
+ }
+
+// pUserDataT->shaderProgramDescriptor.vertexShader = (const char*)pContent;
+// pUserDataT->shaderProgramDescriptor.vertexShader.SetLength(length);
+ return;
+ }
+
+ if (pUserDataT->isFragmentShader)
+ {
+ char* pFragmentUtf8Text = new char[length + 2];
+ if (pFragmentUtf8Text != null)
+ {
+ strncpy(pFragmentUtf8Text, (const char*)pContent, length);
+ pFragmentUtf8Text[length] = '\0';
+ Tizen::Base::Utility::StringUtil::Utf8ToString(pFragmentUtf8Text, pUserDataT->shaderProgramDescriptor.fragmentShader);
+ }
+ else
+ {
+ SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+ pUserDataT->parsingResult = E_OUT_OF_MEMORY;
+ }
+
+// pUserDataT->shaderProgramDescriptor.fragmentShader = (const char*)pContent;
+// pUserDataT->shaderProgramDescriptor.fragmentShader.SetLength(length);
+ return;
+ }
+}
+
+void
+__LoadSceneOnEndElement(void* pUserData, const xmlChar* pName)
+{
+ String elementName((const char*)pName);
+ std::string tempString;
+ std::wstring tempWString;
+
+ struct __SceneSAXParsingUserData* pUserDataT = (struct __SceneSAXParsingUserData*)pUserData;
+ if (pUserDataT->parsingResult != E_SUCCESS)
+ {
+ return;
+ }
+
+ if (pUserDataT->isVisualElements && pUserDataT->isVisualElement)
+ {
+ if (elementName.CompareTo("VisualElement") == 0)
+ {
+ pUserDataT->isVisualElement = false;
+ if (pUserDataT->pCurrentParentVisualElement != null && pUserDataT->pCurrentParentVisualElement != pUserDataT->pSceneImpl->GetRootVisualElement())
+ {
+ pUserDataT->pCurrentParentVisualElement = pUserDataT->pCurrentParentVisualElement->GetParent();
+ }
+ else
+ {
+ SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Scene tree building error.");
+ pUserDataT->parsingResult = E_INVALID_ARG;
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isMeshes && pUserDataT->isMesh)
+ {
+ if (elementName.CompareTo("Mesh") == 0)
+ {
+ String meshResFileName = SCENE_MESH_RESOURCE_FILE_NAME;
+ String meshResFileExtension = SCENE_MESH_RESOURCE_FILE_EXTENSION;
+
+ pUserDataT->isMesh = false;
+ String meshFileName;
+ meshFileName.Format(pUserDataT->resourceFilesPath.GetLength() + pUserDataT->scenePrefix.GetLength() + meshResFileName.GetLength() + meshResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", pUserDataT->resourceFilesPath.GetPointer(), pUserDataT->scenePrefix.GetPointer(), meshResFileName.GetPointer(), pUserDataT->currentMeshId, meshResFileExtension.GetPointer());
+ pUserDataT->meshDescriptor.pMesh = ModelImporter::LoadMeshN(meshFileName);
+
+ if (pUserDataT->meshDescriptor.pMesh != null)
+ {
+ if (pUserDataT->pSceneImpl->ContainsMesh(pUserDataT->meshDescriptor.pMesh) == -1)
+ {
+ pUserDataT->pSceneImpl->_meshes.SetAt(pUserDataT->meshDescriptor, pUserDataT->currentMeshId);
+ }
+ else
+ {
+ delete pUserDataT->meshDescriptor.pMesh;
+ }
+ }
+ else
+ {
+ pUserDataT->pSceneImpl->_meshes.SetAt(pUserDataT->meshDescriptor, pUserDataT->currentMeshId);
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isMaterials && pUserDataT->isMaterial)
+ {
+ if (elementName.CompareTo("Material") == 0)
+ {
+ String materialResFileName = SCENE_MATERIAL_RESOURCE_FILE_NAME;
+ String materialResFileExtension = SCENE_MATERIAL_RESOURCE_FILE_EXTENSION;
+
+ pUserDataT->isMaterial = false;
+ String materialFileName;
+ materialFileName.Format(pUserDataT->resourceFilesPath.GetLength() + pUserDataT->scenePrefix.GetLength() + materialResFileName.GetLength() + materialResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", pUserDataT->resourceFilesPath.GetPointer(), pUserDataT->scenePrefix.GetPointer(), materialResFileName.GetPointer(), pUserDataT->currentMaterialId, materialResFileExtension.GetPointer());
+ pUserDataT->materialDescriptor.pMaterial = _MaterialParser::LoadMaterialN(materialFileName);
+ //TODO://pUserDataT->materialDescriptor.pMaterial = ModelImporter::LoadMaterialN(ModelImporter::BIN, materialFileName, "", null);
+ //pUserDataT->materialDescriptor.pMaterial = null;
+
+ if (pUserDataT->materialDescriptor.pMaterial != null)
+ {
+ if (pUserDataT->pSceneImpl->ContainsMaterial(pUserDataT->materialDescriptor.pMaterial) == -1)
+ {
+ pUserDataT->pSceneImpl->_materials.SetAt(pUserDataT->materialDescriptor, pUserDataT->currentMaterialId);
+ }
+ else
+ {
+ delete pUserDataT->materialDescriptor.pMaterial;
+ }
+ }
+ else
+ {
+ pUserDataT->pSceneImpl->_materials.SetAt(pUserDataT->materialDescriptor, pUserDataT->currentMaterialId);
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isLights && pUserDataT->isLight)
+ {
+ if (elementName.CompareTo("Light") == 0)
+ {
+ String lightResFileName = SCENE_LIGHT_RESOURCE_FILE_NAME;
+ String lightResFileExtension = SCENE_LIGHT_RESOURCE_FILE_EXTENSION;
+
+ pUserDataT->isLight = false;
+ String lightFileName;
+ lightFileName.Format(pUserDataT->resourceFilesPath.GetLength() + pUserDataT->scenePrefix.GetLength() + lightResFileName.GetLength() + lightResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", pUserDataT->resourceFilesPath.GetPointer(), pUserDataT->scenePrefix.GetPointer(), lightResFileName.GetPointer(), pUserDataT->currentLightId, lightResFileExtension.GetPointer());
+ pUserDataT->lightDescriptor.pLight = _LightParser::LoadLightN(lightFileName);
+ //TODO://pUserDataT->lightDescriptor.pLight = ModelImporter::LoadLightN(ModelImporter::BIN, lightFileName, "", null);
+ //pUserDataT->lightDescriptor.pLight = null;
+
+ if (pUserDataT->lightDescriptor.pLight != null)
+ {
+ if (pUserDataT->pSceneImpl->ContainsLight(pUserDataT->lightDescriptor.pLight) == -1)
+ {
+ pUserDataT->pSceneImpl->_lights.SetAt(pUserDataT->lightDescriptor, pUserDataT->currentLightId);
+ }
+ else
+ {
+ delete pUserDataT->lightDescriptor.pLight;
+ }
+ }
+ else
+ {
+ pUserDataT->pSceneImpl->_lights.SetAt(pUserDataT->lightDescriptor, pUserDataT->currentLightId);
+ }
+ return;
+ }
+ }
+
+ if (pUserDataT->isShaderPrograms && pUserDataT->isShaderProgram)
+ {
+ if (elementName.CompareTo("ShaderProgram") == 0)
+ {
+ pUserDataT->isShaderProgram = false;
+ if (pUserDataT->pSceneImpl->ContainsShaderProgram(pUserDataT->shaderProgramName) != -1)
+ {
+ return;
+ }
+
+ ////for shader loading from file
+ String vertexShaderResFileName = SCENE_VERTEX_SHADER_RESOURCE_FILE_NAME;
+ String vertexShaderResFileExtension = SCENE_VERTEX_SHADER_RESOURCE_FILE_EXTENSION;
+ pUserDataT->shaderProgramDescriptor.vertexShader.Clear();
+
+ String tempTString;
+ tempTString.Format(pUserDataT->resourceFilesPath.GetLength() + pUserDataT->scenePrefix.GetLength() + vertexShaderResFileName.GetLength() + vertexShaderResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", pUserDataT->resourceFilesPath.GetPointer(), pUserDataT->scenePrefix.GetPointer(), vertexShaderResFileName.GetPointer(), pUserDataT->currentShaderProgramId, vertexShaderResFileExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ std::ifstream vertex(tempString.c_str(), std::ifstream::in);
+
+ if (vertex.good())
+ {
+ std::filebuf* pVertexFileBuf = vertex.rdbuf();
+ if (pVertexFileBuf != null)
+ {
+ std::size_t vertexSize = pVertexFileBuf->pubseekoff (0, vertex.end, vertex.in);
+ pVertexFileBuf->pubseekpos (0, vertex.in);
+ char* pVertexText = new (std::nothrow) char[vertexSize+2];
+ if (pVertexText != null)
+ {
+ pVertexFileBuf->sgetn(pVertexText, vertexSize);
+ pVertexText[vertexSize] = '\0';
+ pUserDataT->shaderProgramDescriptor.vertexShader = pVertexText;
+ }
+ }
+ vertex.close();
+ }
+
+ String fragmentShaderResFileName = SCENE_FRAGMENT_SHADER_RESOURCE_FILE_NAME;
+ String fragmentShaderResFileExtension = SCENE_FRAGMENT_SHADER_RESOURCE_FILE_EXTENSION;
+ pUserDataT->shaderProgramDescriptor.fragmentShader.Clear();
+
+ tempTString.Format(pUserDataT->resourceFilesPath.GetLength() + pUserDataT->scenePrefix.GetLength() + fragmentShaderResFileName.GetLength() + fragmentShaderResFileExtension.GetLength() + 8 + 2, \
+ L"%ls%ls%ls%04d%ls", pUserDataT->resourceFilesPath.GetPointer(), pUserDataT->scenePrefix.GetPointer(), fragmentShaderResFileName.GetPointer(), pUserDataT->currentShaderProgramId, fragmentShaderResFileExtension.GetPointer());
+ tempWString = tempTString.GetPointer();
+ tempString = ConvertWStringToString(tempWString);
+
+ std::ifstream fragment(tempString.c_str(), std::ifstream::in);
+
+ if (fragment.good())
+ {
+ std::filebuf* pFragmentFileBuf = fragment.rdbuf();
+ if (pFragmentFileBuf != null)
+ {
+ std::size_t fragmentSize = pFragmentFileBuf->pubseekoff (0, fragment.end, fragment.in);
+ pFragmentFileBuf->pubseekpos (0, fragment.in);
+ char* pFragmentText = new (std::nothrow) char[fragmentSize+2];
+ if (pFragmentText != null)
+ {
+ pFragmentFileBuf->sgetn(pFragmentText, fragmentSize);
+ pFragmentText[fragmentSize] = '\0';
+ pUserDataT->shaderProgramDescriptor.fragmentShader = pFragmentText;
+ }
+ }
+ fragment.close();
+ }
+
+ //shader loaded to String, build'em
+
+ Shader vertexShaderClass, fragmentShaderClass;
+
+ tempWString = pUserDataT->shaderProgramDescriptor.vertexShader.GetPointer();
+ std::string vertexShader = ConvertWStringToString(tempWString);
+ tempWString = pUserDataT->shaderProgramDescriptor.fragmentShader.GetPointer();
+ std::string fragmentShader = ConvertWStringToString(tempWString);
+
+ vertexShaderClass.Construct(Shader::SHADER_VERTEX, vertexShader.c_str());
+ fragmentShaderClass.Construct(Shader::SHADER_FRAGMENT, fragmentShader.c_str());
+
+ ShaderProgram* pNewShaderProgram = new (std::nothrow) ShaderProgram();
+
+ if (pNewShaderProgram == null)
+ {
+ SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+ pUserDataT->parsingResult = E_OUT_OF_MEMORY;
+ return;
+ }
+ pNewShaderProgram->Construct(vertexShaderClass, fragmentShaderClass);
+ pNewShaderProgram->SetName(pUserDataT->shaderProgramName);
+
+ pUserDataT->shaderProgramDescriptor.pShaderProgram = pNewShaderProgram;
+
+ pUserDataT->pSceneImpl->_shaderPrograms.SetAt(pUserDataT->shaderProgramDescriptor, pUserDataT->currentShaderProgramId);
+
+ return;
+ }
+ }
+////for UTF-8 shader saving in .are
+// if (pUserDataT->isVertexShader && !pUserDataT->isFragmentShader)
+// {
+// if (elementName.CompareTo("VertexShader") == 0)
+// {
+// pUserDataT->isVertexShader = false;
+// return;
+// }
+// }
+//
+// if (pUserDataT->isVertexShader && !pUserDataT->isVertexShader)
+// {
+// if (elementName.CompareTo("FragmentShader") == 0)
+// {
+// pUserDataT->isFragmentShader = false;
+// return;
+// }
+// }
+
+ if (pUserDataT->isTextureFileNames && pUserDataT->isTextureFileName)
+ {
+ if (elementName.CompareTo("TextureFileName") == 0)
+ {
+ pUserDataT->isTextureFileName = false;
+ pUserDataT->pSceneImpl->_textureFileNames.SetAt(pUserDataT->texfureFileName, pUserDataT->currentTexturFileNameId);
+ return;
+ }
+ }
+
+ if (pUserDataT->isMeshes && !pUserDataT->isMesh)
+ {
+ if (pUserDataT->isMeshes)
+ {
+ if (elementName.CompareTo("Meshes") == 0)
+ {
+ pUserDataT->isMeshes = false;
+ return;
+ }
+ }
+ }
+
+ if (pUserDataT->isMaterials && !pUserDataT->isMaterial)
+ {
+ if (pUserDataT->isMaterials)
+ {
+ if (elementName.CompareTo("Materials") == 0)
+ {
+ pUserDataT->isMaterials = false;
+ return;
+ }
+ }
+ }
+
+ if (pUserDataT->isLights && !pUserDataT->isLight)
+ {
+ if (elementName.CompareTo("Lights") == 0)
+ {
+ pUserDataT->isLights = false;
+ return;
+ }
+ }
+
+ if (pUserDataT->isShaderPrograms && !pUserDataT->isShaderProgram)
+ {
+ if (elementName.CompareTo("ShaderPrograms") == 0)
+ {
+ pUserDataT->isShaderPrograms = false;
+ return;
+ }
+ }
+
+ if (pUserDataT->isTextureFileNames && !pUserDataT->isTextureFileName)
+ {
+ if (elementName.CompareTo("TextureFileNames") == 0)
+ {
+ pUserDataT->isTextureFileNames = false;
+ return;
+ }
+ }
+
+ if (pUserDataT->isVisualElements && !pUserDataT->isVisualElement)
+ {
+ if (elementName.CompareTo("VisualElements") == 0)
+ {
+ pUserDataT->isVisualElements = false;
+ return;
+ }
+ }
+
+ if (pUserDataT->isScene && !pUserDataT->isVisualElements && !pUserDataT->isMeshes && !pUserDataT->isMaterials && !pUserDataT->isLights && !pUserDataT->isShaderPrograms && !pUserDataT->isTextureFileNames)
+ {
+ if (elementName.CompareTo("Scene") == 0)
+ {
+ pUserDataT->isScene = false;
+ return;
+ }
+ }
+ else
+ {
+ return;
+ }
+
+ //generate error to stop parsing by file structure mistakes
+ SysLogException(NID_UI_ANIM, E_INVALID_FORMAT, "Wrong file structure. Error reading.");
+ pUserDataT->parsingResult = E_INVALID_FORMAT;
+ return;
+}
-}}}
+}}} //Tizen::Ui::Animations