mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
Merge pull request #27817 from fire/assimp_d3d98a
Update Assimp to master at d3d98a7ec0c8d38e1952b46dfe53f7e9233dc92d
This commit is contained in:
commit
1e67f214c5
2
thirdparty/README.md
vendored
2
thirdparty/README.md
vendored
@ -4,7 +4,7 @@
|
||||
## assimp
|
||||
|
||||
- Upstream: http://github.com/assimp/assimp
|
||||
- Version: git (d2b45377e4b09a1f43be95e45553afcc06b03f4b)
|
||||
- Version: git (d3d98a7ec0c8d38e1952b46dfe53f7e9233dc92d)
|
||||
- License: BSD-3-Clause
|
||||
|
||||
|
||||
|
35
thirdparty/assimp/code/FBXConverter.cpp
vendored
35
thirdparty/assimp/code/FBXConverter.cpp
vendored
@ -78,6 +78,16 @@ namespace Assimp {
|
||||
|
||||
FBXConverter::FBXConverter(aiScene* out, const Document& doc)
|
||||
: defaultMaterialIndex()
|
||||
, lights()
|
||||
, cameras()
|
||||
, textures()
|
||||
, materials_converted()
|
||||
, textures_converted()
|
||||
, meshes_converted()
|
||||
, node_anim_chain_bits()
|
||||
, mNodeNameInstances()
|
||||
, mNodeNames()
|
||||
, anim_fps()
|
||||
, out(out)
|
||||
, doc(doc) {
|
||||
// animations need to be converted first since this will
|
||||
@ -410,19 +420,24 @@ namespace Assimp {
|
||||
|
||||
void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName)
|
||||
{
|
||||
int i = 0;
|
||||
uniqueName = name;
|
||||
while (mNodeNames.find(uniqueName) != mNodeNames.end())
|
||||
int i = 0;
|
||||
auto it = mNodeNameInstances.find(name); // duplicate node name instance count
|
||||
if (it != mNodeNameInstances.end())
|
||||
{
|
||||
++i;
|
||||
std::stringstream ext;
|
||||
ext << name << std::setfill('0') << std::setw(3) << i;
|
||||
uniqueName = ext.str();
|
||||
i = it->second;
|
||||
while (mNodeNames.find(uniqueName) != mNodeNames.end())
|
||||
{
|
||||
i++;
|
||||
std::stringstream ext;
|
||||
ext << name << std::setfill('0') << std::setw(3) << i;
|
||||
uniqueName = ext.str();
|
||||
}
|
||||
}
|
||||
mNodeNameInstances[name] = i;
|
||||
mNodeNames.insert(uniqueName);
|
||||
}
|
||||
|
||||
|
||||
const char* FBXConverter::NameTransformationComp(TransformationComp comp) {
|
||||
switch (comp) {
|
||||
case TransformationComp_Translation:
|
||||
@ -2041,6 +2056,12 @@ namespace Assimp {
|
||||
CalculatedOpacity = 1.0f - ((Transparent.r + Transparent.g + Transparent.b) / 3.0f);
|
||||
}
|
||||
|
||||
// try to get the transparency factor
|
||||
const float TransparencyFactor = PropertyGet<float>(props, "TransparencyFactor", ok);
|
||||
if (ok) {
|
||||
out_mat->AddProperty(&TransparencyFactor, 1, AI_MATKEY_TRANSPARENCYFACTOR);
|
||||
}
|
||||
|
||||
// use of TransparencyFactor is inconsistent.
|
||||
// Maya always stores it as 1.0,
|
||||
// so we can't use it to set AI_MATKEY_OPACITY.
|
||||
|
20
thirdparty/assimp/code/FBXConverter.h
vendored
20
thirdparty/assimp/code/FBXConverter.h
vendored
@ -58,6 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/texture.h>
|
||||
#include <assimp/camera.h>
|
||||
#include <assimp/StringComparison.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
@ -74,8 +76,6 @@ namespace FBX {
|
||||
|
||||
class Document;
|
||||
|
||||
using NodeNameCache = std::set<std::string>;
|
||||
|
||||
/**
|
||||
* Convert a FBX #Document to #aiScene
|
||||
* @param out Empty scene to be populated
|
||||
@ -419,7 +419,6 @@ private:
|
||||
void TransferDataToScene();
|
||||
|
||||
private:
|
||||
|
||||
// 0: not assigned yet, others: index is value - 1
|
||||
unsigned int defaultMaterialIndex;
|
||||
|
||||
@ -429,22 +428,27 @@ private:
|
||||
std::vector<aiLight*> lights;
|
||||
std::vector<aiCamera*> cameras;
|
||||
std::vector<aiTexture*> textures;
|
||||
|
||||
|
||||
typedef std::map<const Material*, unsigned int> MaterialMap;
|
||||
using MaterialMap = std::map<const Material*, unsigned int>;
|
||||
MaterialMap materials_converted;
|
||||
|
||||
typedef std::map<const Video*, unsigned int> VideoMap;
|
||||
using VideoMap = std::map<const Video*, unsigned int>;
|
||||
VideoMap textures_converted;
|
||||
|
||||
typedef std::map<const Geometry*, std::vector<unsigned int> > MeshMap;
|
||||
using MeshMap = std::map<const Geometry*, std::vector<unsigned int> >;
|
||||
MeshMap meshes_converted;
|
||||
|
||||
// fixed node name -> which trafo chain components have animations?
|
||||
typedef std::map<std::string, unsigned int> NodeAnimBitMap;
|
||||
using NodeAnimBitMap = std::map<std::string, unsigned int> ;
|
||||
NodeAnimBitMap node_anim_chain_bits;
|
||||
|
||||
// number of nodes with the same name
|
||||
using NodeAnimNameMap = std::unordered_map<std::string, unsigned int>;
|
||||
NodeAnimNameMap mNodeNameInstances;
|
||||
|
||||
using NodeNameCache = std::unordered_set<std::string>;
|
||||
NodeNameCache mNodeNames;
|
||||
|
||||
double anim_fps;
|
||||
|
||||
aiScene* const out;
|
||||
|
32
thirdparty/assimp/code/FBXMaterial.cpp
vendored
32
thirdparty/assimp/code/FBXMaterial.cpp
vendored
@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/ByteSwapper.h>
|
||||
|
||||
#include <algorithm> // std::transform
|
||||
#include "FBXUtil.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
@ -206,6 +207,20 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const
|
||||
|
||||
props = GetPropertyTable(doc,"Texture.FbxFileTexture",element,sc);
|
||||
|
||||
// 3DS Max and FBX SDK use "Scaling" and "Translation" instead of "ModelUVScaling" and "ModelUVTranslation". Use these properties if available.
|
||||
bool ok;
|
||||
const aiVector3D& scaling = PropertyGet<aiVector3D>(*props, "Scaling", ok);
|
||||
if (ok) {
|
||||
uvScaling.x = scaling.x;
|
||||
uvScaling.y = scaling.y;
|
||||
}
|
||||
|
||||
const aiVector3D& trans = PropertyGet<aiVector3D>(*props, "Translation", ok);
|
||||
if (ok) {
|
||||
uvTrans.x = trans.x;
|
||||
uvTrans.y = trans.y;
|
||||
}
|
||||
|
||||
// resolve video links
|
||||
if(doc.Settings().readTextures) {
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
|
||||
@ -307,7 +322,22 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std
|
||||
const Token& token = GetRequiredToken(*Content, 0);
|
||||
const char* data = token.begin();
|
||||
if (!token.IsBinary()) {
|
||||
DOMWarning("video content is not binary data, ignoring", &element);
|
||||
if (*data != '"') {
|
||||
DOMError("embedded content is not surrounded by quotation marks", &element);
|
||||
}
|
||||
else {
|
||||
const char* encodedData = data + 1;
|
||||
size_t encodedDataLen = static_cast<size_t>(token.end() - token.begin());
|
||||
// search for last quotation mark
|
||||
while (encodedDataLen > 1 && encodedData[encodedDataLen] != '"')
|
||||
encodedDataLen--;
|
||||
if (encodedDataLen % 4 != 0) {
|
||||
DOMError("embedded content is invalid, needs to be in base64", &element);
|
||||
}
|
||||
else {
|
||||
contentLength = Util::DecodeBase64(encodedData, encodedDataLen, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (static_cast<size_t>(token.end() - data) < 5) {
|
||||
DOMError("binary data array is too short, need five (5) bytes for type signature and element count", &element);
|
||||
|
44
thirdparty/assimp/code/FBXUtil.cpp
vendored
44
thirdparty/assimp/code/FBXUtil.cpp
vendored
@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assimp/TinyFormatter.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
||||
@ -113,6 +114,49 @@ std::string AddTokenText(const std::string& prefix, const std::string& text, con
|
||||
text) );
|
||||
}
|
||||
|
||||
static const uint8_t base64DecodeTable[128] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 64, 0, 0,
|
||||
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
|
||||
0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
uint8_t DecodeBase64(char ch)
|
||||
{
|
||||
return base64DecodeTable[size_t(ch)];
|
||||
}
|
||||
|
||||
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out)
|
||||
{
|
||||
if (inLength < 4) {
|
||||
out = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const size_t outLength = (inLength * 3) / 4;
|
||||
out = new uint8_t[outLength];
|
||||
memset(out, 0, outLength);
|
||||
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
for (i = 0; i < inLength - 4; i += 4)
|
||||
{
|
||||
uint8_t b0 = Util::DecodeBase64(in[i]);
|
||||
uint8_t b1 = Util::DecodeBase64(in[i + 1]);
|
||||
uint8_t b2 = Util::DecodeBase64(in[i + 2]);
|
||||
uint8_t b3 = Util::DecodeBase64(in[i + 3]);
|
||||
|
||||
out[j++] = (uint8_t)((b0 << 2) | (b1 >> 4));
|
||||
out[j++] = (uint8_t)((b1 << 4) | (b2 >> 2));
|
||||
out[j++] = (uint8_t)((b2 << 6) | b3);
|
||||
}
|
||||
return outLength;
|
||||
}
|
||||
|
||||
} // !Util
|
||||
} // !FBX
|
||||
} // !Assimp
|
||||
|
15
thirdparty/assimp/code/FBXUtil.h
vendored
15
thirdparty/assimp/code/FBXUtil.h
vendored
@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "FBXCompileConfig.h"
|
||||
#include "FBXTokenizer.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
@ -98,6 +99,20 @@ std::string AddLineAndColumn(const std::string& prefix, const std::string& text,
|
||||
* @return A string of the following format: {prefix} ({token-type}, line {line}, col {column}) {text}*/
|
||||
std::string AddTokenText(const std::string& prefix, const std::string& text, const Token* tok);
|
||||
|
||||
/** Decode a single Base64-encoded character.
|
||||
*
|
||||
* @param ch Character to decode (from base64 to binary).
|
||||
* @return decoded byte value*/
|
||||
uint8_t DecodeBase64(char ch);
|
||||
|
||||
/** Decode a Base64-encoded string
|
||||
*
|
||||
* @param in Characters to decode.
|
||||
* @param inLength Number of characters to decode.
|
||||
* @param out Reference to pointer where we will store the decoded data.
|
||||
* @return size of the decoded data (number of bytes)*/
|
||||
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
thirdparty/assimp/code/Version.cpp
vendored
2
thirdparty/assimp/code/Version.cpp
vendored
@ -134,7 +134,7 @@ ASSIMP_API aiScene::aiScene()
|
||||
, mCameras(nullptr)
|
||||
, mMetaData(nullptr)
|
||||
, mPrivate(new Assimp::ScenePrivateData()) {
|
||||
// empty
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
1
thirdparty/assimp/include/assimp/material.h
vendored
1
thirdparty/assimp/include/assimp/material.h
vendored
@ -900,6 +900,7 @@ extern "C" {
|
||||
#define AI_MATKEY_ENABLE_WIREFRAME "$mat.wireframe",0,0
|
||||
#define AI_MATKEY_BLEND_FUNC "$mat.blend",0,0
|
||||
#define AI_MATKEY_OPACITY "$mat.opacity",0,0
|
||||
#define AI_MATKEY_TRANSPARENCYFACTOR "$mat.transparencyfactor",0,0
|
||||
#define AI_MATKEY_BUMPSCALING "$mat.bumpscaling",0,0
|
||||
#define AI_MATKEY_SHININESS "$mat.shininess",0,0
|
||||
#define AI_MATKEY_REFLECTIVITY "$mat.reflectivity",0,0
|
||||
|
Loading…
Reference in New Issue
Block a user