2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-scene3d/public-api/loader/navigation-mesh-factory.h>
21 #include <dali/integration-api/debug.h>
24 #include <dali-scene3d/internal/algorithm/navigation-mesh-impl.h>
25 #include <dali/devel-api/adaptor-framework/file-stream.h>
27 namespace Dali::Scene3D::Loader
29 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromFile(std::string filename)
31 std::vector<uint8_t> buffer;
33 Dali::FileStream fileStream(filename, Dali::FileStream::READ | Dali::FileStream::BINARY);
34 auto fin = fileStream.GetFile();
38 DALI_LOG_ERROR("NavigationMesh: Can't open %s for reading: %s", filename.c_str(), strerror(errno));
43 if(fseek(fin, 0, SEEK_END))
48 auto size = ftell(fin);
54 auto fileSize = size_t(size);
55 if(fseek(fin, 0, SEEK_SET))
61 auto count = fread(buffer.data(), 1, fileSize, fin);
64 DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
67 return CreateFromBuffer(buffer);
71 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromBuffer(const std::vector<uint8_t>& buffer)
73 auto impl = new Scene3D::Internal::Algorithm::NavigationMesh(buffer);
74 return std::unique_ptr<Algorithm::NavigationMesh>(new Algorithm::NavigationMesh(impl));
77 } // namespace Dali::Scene3D::Loader