Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
fbx_memory_stream.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#ifdef MOMENTUM_WITH_FBX_SDK
11
12#include <fbxsdk.h>
13#include <fbxsdk/core/fbxstream.h>
14#include <span>
15
16#include <string_view>
17
18#define FBX_VERSION_GE(major, minor, patch) \
19 ((FBXSDK_VERSION_MAJOR > (major)) || \
20 (FBXSDK_VERSION_MAJOR == (major) && FBXSDK_VERSION_MINOR > (minor)) || \
21 (FBXSDK_VERSION_MAJOR == (major) && FBXSDK_VERSION_MINOR == (minor) && \
22 FBXSDK_VERSION_POINT >= (patch)))
23
24namespace momentum {
25
26// Simplest FbxStream to read file from a string_view memory buffer
27class FbxMemoryStream : public FbxStream {
28 public:
29 FbxMemoryStream(std::span<const std::byte> buffer, int pReaderId);
30 ~FbxMemoryStream() override;
31 FbxMemoryStream(const FbxMemoryStream&) = default;
32 FbxMemoryStream& operator=(const FbxMemoryStream&) = default;
33 FbxMemoryStream(FbxMemoryStream&&) = default;
34 FbxMemoryStream& operator=(FbxMemoryStream&&) = default;
35 EState GetState() override;
36 bool Open(void* pStreamData) override;
37 bool Close() override;
38 bool Flush() override;
39#if FBX_VERSION_GE(2020, 3, 2)
40 size_t Write(const void* buffer, FbxUInt64 count) override;
41 size_t Read(void* buffer, FbxUInt64 count) const override;
42#else
43 int Write(const void* buffer, int count) override;
44 int Read(void* buffer, int count) const override;
45#endif
46 int GetReaderID() const override;
47 int GetWriterID() const override;
48 void Seek(const FbxInt64& pOffset, const FbxFile::ESeekPos& pSeekPos) override;
49#if FBX_VERSION_GE(2020, 3, 2)
50 FbxInt64 GetPosition() const override;
51 void SetPosition(FbxInt64 pPosition) override;
52#else
53 long GetPosition() const override;
54 void SetPosition(long pPosition) override;
55#endif
56 int GetError() const override;
57 void ClearError() override;
58
59 private:
60 std::span<const std::byte> buffer_;
61 long length_{0};
62#if FBX_VERSION_GE(2020, 3, 2)
63 mutable FbxInt64 position_{0};
64#else
65 mutable long position_{0};
66#endif
67 EState state_{eEmpty};
68 int readerId_{0};
69 mutable int errorCode_{0};
70};
71
72} // namespace momentum
73
74#endif // MOMENTUM_WITH_FBX_SDK