Clean up Scene3D namespace and header definition
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / navigation-mesh-factory.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // CLASS HEADER
18 #include <dali-scene3d/public-api/loader/navigation-mesh-factory.h>
19
20 // EXTERNAL INCLUDES
21 #include <dali/integration-api/debug.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-scene3d/internal/algorithm/navigation-mesh-impl.h>
25
26 namespace Dali::Scene3D::Loader
27 {
28 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromFile(std::string filename)
29 {
30   std::vector<uint8_t> buffer;
31   auto                 fin = fopen(filename.c_str(), "rb");
32   if(!fin)
33   {
34     DALI_LOG_ERROR("NavigationMesh: Can't open %s for reading: %s", filename.c_str(), strerror(errno));
35     return nullptr;
36   }
37   else
38   {
39     fseek(fin, 0, SEEK_END);
40     auto size = ftell(fin);
41     fseek(fin, 0, SEEK_SET);
42     buffer.resize(size);
43     auto count = fread(buffer.data(), 1, size, fin);
44     if(!count)
45     {
46       DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
47       fclose(fin);
48       return nullptr;
49     }
50     fclose(fin);
51
52     return CreateFromBuffer(buffer);
53   }
54 }
55
56 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromBuffer(const std::vector<uint8_t>& buffer)
57 {
58   auto impl = new Scene3D::Internal::Algorithm::NavigationMesh(buffer);
59   return std::unique_ptr<Algorithm::NavigationMesh>(new Algorithm::NavigationMesh(impl));
60 }
61
62 } // namespace Dali::Scene3D::Loader