2018-02-19 12:46:02 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-02-19 12:46:02 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file FBXExportNode.h
|
|
|
|
* Declares the FBX::Node helper class for fbx export.
|
|
|
|
*/
|
|
|
|
#ifndef AI_FBXEXPORTNODE_H_INC
|
|
|
|
#define AI_FBXEXPORTNODE_H_INC
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
|
|
|
|
|
|
|
|
#include "FBXExportProperty.h"
|
|
|
|
|
|
|
|
#include <assimp/StreamWriter.h> // StreamWriterLE
|
|
|
|
|
|
|
|
#include <string>
|
2022-11-03 16:35:10 +00:00
|
|
|
#include <utility>
|
2018-02-19 12:46:02 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-05-09 12:50:22 +00:00
|
|
|
namespace Assimp {
|
2018-02-19 12:46:02 +00:00
|
|
|
namespace FBX {
|
|
|
|
class Node;
|
|
|
|
}
|
|
|
|
|
2019-05-13 19:41:37 +00:00
|
|
|
class FBX::Node {
|
2021-07-29 11:28:51 +00:00
|
|
|
public:
|
2018-02-19 12:46:02 +00:00
|
|
|
// TODO: accessors
|
|
|
|
std::string name; // node name
|
2019-05-13 19:41:37 +00:00
|
|
|
std::vector<FBX::FBXExportProperty> properties; // node properties
|
2018-02-19 12:46:02 +00:00
|
|
|
std::vector<FBX::Node> children; // child nodes
|
|
|
|
|
2018-03-28 14:09:07 +00:00
|
|
|
// some nodes always pretend they have children...
|
|
|
|
bool force_has_children = false;
|
|
|
|
|
2018-02-19 12:46:02 +00:00
|
|
|
public: // constructors
|
2018-12-27 21:28:23 +00:00
|
|
|
/// The default class constructor.
|
2018-02-19 12:46:02 +00:00
|
|
|
Node() = default;
|
2018-12-27 21:28:23 +00:00
|
|
|
|
|
|
|
/// The class constructor with the name.
|
|
|
|
Node(const std::string& n)
|
|
|
|
: name(n)
|
|
|
|
, properties()
|
|
|
|
, children()
|
|
|
|
, force_has_children( false ) {
|
|
|
|
// empty
|
|
|
|
}
|
2018-03-28 13:47:27 +00:00
|
|
|
|
|
|
|
// convenience template to construct with properties directly
|
|
|
|
template <typename... More>
|
2022-11-07 15:58:28 +00:00
|
|
|
Node(const std::string& n, More&&... more)
|
2018-12-27 21:28:23 +00:00
|
|
|
: name(n)
|
|
|
|
, properties()
|
|
|
|
, children()
|
|
|
|
, force_has_children(false) {
|
2022-11-07 15:58:28 +00:00
|
|
|
AddProperties(std::forward<More>(more)...);
|
2018-12-27 21:28:23 +00:00
|
|
|
}
|
2018-02-19 12:46:02 +00:00
|
|
|
|
|
|
|
public: // functions to add properties or children
|
|
|
|
// add a single property to the node
|
|
|
|
template <typename T>
|
2022-11-07 15:58:28 +00:00
|
|
|
void AddProperty(T&& value) {
|
2022-11-03 16:35:10 +00:00
|
|
|
properties.emplace_back(std::forward<T>(value));
|
2018-02-19 12:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convenience function to add multiple properties at once
|
|
|
|
template <typename T, typename... More>
|
2022-11-07 15:58:28 +00:00
|
|
|
void AddProperties(T&& value, More&&... more) {
|
2022-11-03 16:35:10 +00:00
|
|
|
properties.emplace_back(std::forward<T>(value));
|
|
|
|
AddProperties(std::forward<More>(more)...);
|
2018-02-19 12:46:02 +00:00
|
|
|
}
|
|
|
|
void AddProperties() {}
|
|
|
|
|
|
|
|
// add a child node directly
|
|
|
|
void AddChild(const Node& node) { children.push_back(node); }
|
|
|
|
|
|
|
|
// convenience function to add a child node with a single property
|
|
|
|
template <typename... More>
|
|
|
|
void AddChild(
|
|
|
|
const std::string& name,
|
2022-11-07 15:58:28 +00:00
|
|
|
More&&... more
|
2018-02-19 12:46:02 +00:00
|
|
|
) {
|
|
|
|
FBX::Node c(name);
|
2022-11-03 16:35:10 +00:00
|
|
|
c.AddProperties(std::forward<More>(more)...);
|
2022-11-03 16:36:58 +00:00
|
|
|
children.push_back(std::move(c));
|
2018-02-19 12:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public: // support specifically for dealing with Properties70 nodes
|
|
|
|
|
|
|
|
// it really is simpler to make these all separate functions.
|
|
|
|
// the versions with 'A' suffixes are for animatable properties.
|
|
|
|
// those often follow a completely different format internally in FBX.
|
|
|
|
void AddP70int(const std::string& name, int32_t value);
|
|
|
|
void AddP70bool(const std::string& name, bool value);
|
|
|
|
void AddP70double(const std::string& name, double value);
|
|
|
|
void AddP70numberA(const std::string& name, double value);
|
|
|
|
void AddP70color(const std::string& name, double r, double g, double b);
|
|
|
|
void AddP70colorA(const std::string& name, double r, double g, double b);
|
|
|
|
void AddP70vector(const std::string& name, double x, double y, double z);
|
|
|
|
void AddP70vectorA(const std::string& name, double x, double y, double z);
|
|
|
|
void AddP70string(const std::string& name, const std::string& value);
|
|
|
|
void AddP70enum(const std::string& name, int32_t value);
|
|
|
|
void AddP70time(const std::string& name, int64_t value);
|
|
|
|
|
|
|
|
// template for custom P70 nodes.
|
|
|
|
// anything that doesn't fit in the above can be created manually.
|
|
|
|
template <typename... More>
|
|
|
|
void AddP70(
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& type,
|
|
|
|
const std::string& type2,
|
|
|
|
const std::string& flags,
|
2022-11-07 15:58:28 +00:00
|
|
|
More&&... more
|
2018-02-19 12:46:02 +00:00
|
|
|
) {
|
|
|
|
Node n("P");
|
2022-11-03 16:35:10 +00:00
|
|
|
n.AddProperties(name, type, type2, flags, std::forward<More>(more)...);
|
2018-02-19 12:46:02 +00:00
|
|
|
AddChild(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
public: // member functions for writing data to a file or stream
|
|
|
|
|
2018-03-28 19:40:26 +00:00
|
|
|
// write the full node to the given file or stream
|
|
|
|
void Dump(
|
2021-06-22 16:27:15 +00:00
|
|
|
const std::shared_ptr<Assimp::IOStream> &outfile,
|
|
|
|
bool binary, int indent);
|
2018-03-28 19:40:26 +00:00
|
|
|
void Dump(Assimp::StreamWriterLE &s, bool binary, int indent);
|
2018-02-19 12:46:02 +00:00
|
|
|
|
|
|
|
// these other functions are for writing data piece by piece.
|
|
|
|
// they must be used carefully.
|
|
|
|
// for usage examples see FBXExporter.cpp.
|
2018-03-28 19:40:26 +00:00
|
|
|
void Begin(Assimp::StreamWriterLE &s, bool binary, int indent);
|
|
|
|
void DumpProperties(Assimp::StreamWriterLE& s, bool binary, int indent);
|
|
|
|
void EndProperties(Assimp::StreamWriterLE &s, bool binary, int indent);
|
|
|
|
void EndProperties(
|
|
|
|
Assimp::StreamWriterLE &s, bool binary, int indent,
|
|
|
|
size_t num_properties
|
|
|
|
);
|
|
|
|
void BeginChildren(Assimp::StreamWriterLE &s, bool binary, int indent);
|
|
|
|
void DumpChildren(Assimp::StreamWriterLE& s, bool binary, int indent);
|
|
|
|
void End(
|
|
|
|
Assimp::StreamWriterLE &s, bool binary, int indent,
|
|
|
|
bool has_children
|
|
|
|
);
|
|
|
|
|
|
|
|
private: // internal functions used for writing
|
|
|
|
|
|
|
|
void DumpBinary(Assimp::StreamWriterLE &s);
|
|
|
|
void DumpAscii(Assimp::StreamWriterLE &s, int indent);
|
|
|
|
void DumpAscii(std::ostream &s, int indent);
|
|
|
|
|
|
|
|
void BeginBinary(Assimp::StreamWriterLE &s);
|
|
|
|
void DumpPropertiesBinary(Assimp::StreamWriterLE& s);
|
|
|
|
void EndPropertiesBinary(Assimp::StreamWriterLE &s);
|
|
|
|
void EndPropertiesBinary(Assimp::StreamWriterLE &s, size_t num_properties);
|
|
|
|
void DumpChildrenBinary(Assimp::StreamWriterLE& s);
|
|
|
|
void EndBinary(Assimp::StreamWriterLE &s, bool has_children);
|
|
|
|
|
|
|
|
void BeginAscii(std::ostream &s, int indent);
|
|
|
|
void DumpPropertiesAscii(std::ostream &s, int indent);
|
|
|
|
void BeginChildrenAscii(std::ostream &s, int indent);
|
|
|
|
void DumpChildrenAscii(std::ostream &s, int indent);
|
|
|
|
void EndAscii(std::ostream &s, int indent, bool has_children);
|
2018-02-19 12:46:02 +00:00
|
|
|
|
|
|
|
private: // data used for binary dumps
|
|
|
|
size_t start_pos; // starting position in stream
|
|
|
|
size_t end_pos; // ending position in stream
|
|
|
|
size_t property_start; // starting position of property section
|
|
|
|
|
|
|
|
public: // static member functions
|
|
|
|
|
|
|
|
// convenience function to create a node with a single property,
|
|
|
|
// and write it to the stream.
|
|
|
|
template <typename T>
|
|
|
|
static void WritePropertyNode(
|
|
|
|
const std::string& name,
|
|
|
|
const T value,
|
2018-03-28 19:40:26 +00:00
|
|
|
Assimp::StreamWriterLE& s,
|
|
|
|
bool binary, int indent
|
2018-02-19 12:46:02 +00:00
|
|
|
) {
|
2019-05-13 19:41:37 +00:00
|
|
|
FBX::FBXExportProperty p(value);
|
2022-11-03 16:35:10 +00:00
|
|
|
FBX::Node node(name, std::move(p));
|
2018-03-28 19:40:26 +00:00
|
|
|
node.Dump(s, binary, indent);
|
2018-02-19 12:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convenience function to create and write a property node,
|
|
|
|
// holding a single property which is an array of values.
|
|
|
|
// does not copy the data, so is efficient for large arrays.
|
|
|
|
static void WritePropertyNode(
|
|
|
|
const std::string& name,
|
|
|
|
const std::vector<double>& v,
|
2018-03-28 19:40:26 +00:00
|
|
|
Assimp::StreamWriterLE& s,
|
|
|
|
bool binary, int indent
|
2018-02-19 12:46:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// convenience function to create and write a property node,
|
|
|
|
// holding a single property which is an array of values.
|
|
|
|
// does not copy the data, so is efficient for large arrays.
|
|
|
|
static void WritePropertyNode(
|
2018-03-28 19:40:26 +00:00
|
|
|
const std::string& name,
|
|
|
|
const std::vector<int32_t>& v,
|
|
|
|
Assimp::StreamWriterLE& s,
|
|
|
|
bool binary, int indent
|
|
|
|
);
|
|
|
|
|
|
|
|
private: // static helper functions
|
|
|
|
static void WritePropertyNodeAscii(
|
|
|
|
const std::string& name,
|
|
|
|
const std::vector<double>& v,
|
|
|
|
Assimp::StreamWriterLE& s,
|
|
|
|
int indent
|
|
|
|
);
|
|
|
|
static void WritePropertyNodeAscii(
|
|
|
|
const std::string& name,
|
|
|
|
const std::vector<int32_t>& v,
|
|
|
|
Assimp::StreamWriterLE& s,
|
|
|
|
int indent
|
|
|
|
);
|
|
|
|
static void WritePropertyNodeBinary(
|
|
|
|
const std::string& name,
|
|
|
|
const std::vector<double>& v,
|
|
|
|
Assimp::StreamWriterLE& s
|
|
|
|
);
|
|
|
|
static void WritePropertyNodeBinary(
|
2018-02-19 12:46:02 +00:00
|
|
|
const std::string& name,
|
|
|
|
const std::vector<int32_t>& v,
|
|
|
|
Assimp::StreamWriterLE& s
|
|
|
|
);
|
2018-03-28 19:40:26 +00:00
|
|
|
|
2018-02-19 12:46:02 +00:00
|
|
|
};
|
2019-05-09 12:50:22 +00:00
|
|
|
}
|
2018-02-19 12:46:02 +00:00
|
|
|
|
|
|
|
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
|
|
|
|
|
|
|
|
#endif // AI_FBXEXPORTNODE_H_INC
|