Merge branch 'master' into safe

pull/3946/head
Kim Kulling 2021-06-21 17:53:17 +02:00 committed by GitHub
commit 9512e9ac1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 202 additions and 167 deletions

View File

@ -2203,7 +2203,65 @@ void FBXExporter::WriteObjects ()
bpnode.Dump(outstream, binary, indent); bpnode.Dump(outstream, binary, indent);
}*/ }*/
// TODO: cameras, lights // lights
indent = 1;
lights_uids.clear();
for (size_t li = 0; li < mScene->mNumLights; ++li) {
aiLight* l = mScene->mLights[li];
int64_t uid = generate_uid();
const std::string lightNodeAttributeName = l->mName.C_Str() + FBX::SEPARATOR + "NodeAttribute";
FBX::Node lna("NodeAttribute");
lna.AddProperties(uid, lightNodeAttributeName, "Light");
FBX::Node lnap("Properties70");
// Light color.
lnap.AddP70colorA("Color", l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b);
// TODO Assimp light description is quite concise and do not handle light intensity.
// Default value to 1000W.
lnap.AddP70numberA("Intensity", 1000);
// FBXLight::EType conversion
switch (l->mType) {
case aiLightSource_POINT:
lnap.AddP70enum("LightType", 0);
break;
case aiLightSource_DIRECTIONAL:
lnap.AddP70enum("LightType", 1);
break;
case aiLightSource_SPOT:
lnap.AddP70enum("LightType", 2);
lnap.AddP70numberA("InnerAngle", AI_RAD_TO_DEG(l->mAngleInnerCone));
lnap.AddP70numberA("OuterAngle", AI_RAD_TO_DEG(l->mAngleOuterCone));
break;
// TODO Assimp do not handle 'area' nor 'volume' lights, but FBX does.
/*case aiLightSource_AREA:
lnap.AddP70enum("LightType", 3);
lnap.AddP70enum("AreaLightShape", 0); // 0=Rectangle, 1=Sphere
break;
case aiLightSource_VOLUME:
lnap.AddP70enum("LightType", 4);
break;*/
default:
break;
}
// Did not understood how to configure the decay so disabling attenuation.
lnap.AddP70enum("DecayType", 0);
// Dump to FBX stream
lna.AddChild(lnap);
lna.AddChild("TypeFlags", FBX::FBXExportProperty("Light"));
lna.AddChild("GeometryVersion", FBX::FBXExportProperty(int32_t(124)));
lna.Dump(outstream, binary, indent);
// Store name and uid (will be used later when parsing scene nodes)
lights_uids[l->mName.C_Str()] = uid;
}
// TODO: cameras
// write nodes (i.e. model hierarchy) // write nodes (i.e. model hierarchy)
// start at root node // start at root node
@ -2607,10 +2665,19 @@ void FBXExporter::WriteModelNodes(
// and connect them // and connect them
connections.emplace_back("C", "OO", node_attribute_uid, node_uid); connections.emplace_back("C", "OO", node_attribute_uid, node_uid);
} else { } else {
// generate a null node so we can add children to it const auto& lightIt = lights_uids.find(node->mName.C_Str());
WriteModelNode( if(lightIt != lights_uids.end()) {
outstream, binary, node, node_uid, "Null", transform_chain // Node has a light connected to it.
); WriteModelNode(
outstream, binary, node, node_uid, "Light", transform_chain
);
connections.emplace_back("C", "OO", lightIt->second, node_uid);
} else {
// generate a null node so we can add children to it
WriteModelNode(
outstream, binary, node, node_uid, "Null", transform_chain
);
}
} }
// if more than one child mesh, make nodes for each mesh // if more than one child mesh, make nodes for each mesh

View File

@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct aiScene; struct aiScene;
struct aiNode; struct aiNode;
struct aiLight;
//struct aiMaterial; //struct aiMaterial;
namespace Assimp namespace Assimp
@ -95,6 +96,7 @@ namespace Assimp
std::vector<int64_t> mesh_uids; std::vector<int64_t> mesh_uids;
std::vector<int64_t> material_uids; std::vector<int64_t> material_uids;
std::map<const aiNode*,int64_t> node_uids; std::map<const aiNode*,int64_t> node_uids;
std::map<std::string,int64_t> lights_uids;
// this crude unique-ID system is actually fine // this crude unique-ID system is actually fine
int64_t last_uid = 999999; int64_t last_uid = 999999;

View File

@ -406,11 +406,25 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
// Check whether this texture is an embedded texture. // Check whether this texture is an embedded texture.
// In this case the property looks like this: *<n>, // In this case the property looks like this: *<n>,
// where n is the index of the texture. // where n is the index of the texture.
aiString &s = *((aiString *)prop->mData); // Copy here because we overwrite the string data in-place and the buffer inside of aiString
// will be a lie if we just reinterpret from prop->mData. The size of mData is not guaranteed to be
// MAXLEN in size.
aiString s(*(aiString *)prop->mData);
if ('*' == s.data[0]) { if ('*' == s.data[0]) {
// Offset the index and write it back .. // Offset the index and write it back ..
const unsigned int idx = strtoul10(&s.data[1]) + offset[n]; const unsigned int idx = strtoul10(&s.data[1]) + offset[n];
ASSIMP_itoa10(&s.data[1], sizeof(s.data) - 1, idx); const unsigned int oldLen = s.length;
s.length = 1 + ASSIMP_itoa10(&s.data[1], sizeof(s.data) - 1, idx);
// The string changed in size so we need to reallocate the buffer for the property.
if (oldLen < s.length) {
prop->mDataLength += s.length - oldLen;
delete[] prop->mData;
prop->mData = new char[prop->mDataLength];
}
memcpy(prop->mData, static_cast<void*>(&s), prop->mDataLength);
} }
} }

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2021, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -41,6 +40,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "EmbedTexturesProcess.h" #include "EmbedTexturesProcess.h"
#include <assimp/IOStream.hpp>
#include <assimp/IOSystem.hpp>
#include <assimp/ParsingUtils.h> #include <assimp/ParsingUtils.h>
#include "ProcessHelper.h" #include "ProcessHelper.h"
@ -48,11 +49,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp; using namespace Assimp;
EmbedTexturesProcess::EmbedTexturesProcess() EmbedTexturesProcess::EmbedTexturesProcess() :
: BaseProcess() { BaseProcess() {
// empty
} }
EmbedTexturesProcess::~EmbedTexturesProcess() { EmbedTexturesProcess::~EmbedTexturesProcess() {
// empty
} }
bool EmbedTexturesProcess::IsActive(unsigned int pFlags) const { bool EmbedTexturesProcess::IsActive(unsigned int pFlags) const {
@ -62,15 +65,16 @@ bool EmbedTexturesProcess::IsActive(unsigned int pFlags) const {
void EmbedTexturesProcess::SetupProperties(const Importer* pImp) { void EmbedTexturesProcess::SetupProperties(const Importer* pImp) {
mRootPath = pImp->GetPropertyString("sourceFilePath"); mRootPath = pImp->GetPropertyString("sourceFilePath");
mRootPath = mRootPath.substr(0, mRootPath.find_last_of("\\/") + 1u); mRootPath = mRootPath.substr(0, mRootPath.find_last_of("\\/") + 1u);
mIOHandler = pImp->GetIOHandler();
} }
void EmbedTexturesProcess::Execute(aiScene* pScene) { void EmbedTexturesProcess::Execute(aiScene* pScene) {
if (pScene == nullptr || pScene->mRootNode == nullptr) return; if (pScene == nullptr || pScene->mRootNode == nullptr || mIOHandler == nullptr){
return;
}
aiString path; aiString path;
uint32_t embeddedTexturesCount = 0u; uint32_t embeddedTexturesCount = 0u;
for (auto matId = 0u; matId < pScene->mNumMaterials; ++matId) { for (auto matId = 0u; matId < pScene->mNumMaterials; ++matId) {
auto material = pScene->mMaterials[matId]; auto material = pScene->mMaterials[matId];
@ -101,27 +105,31 @@ bool EmbedTexturesProcess::addTexture(aiScene* pScene, std::string path) const {
std::string imagePath = path; std::string imagePath = path;
// Test path directly // Test path directly
std::ifstream file(imagePath, std::ios::binary | std::ios::ate); if (!mIOHandler->Exists(imagePath)) {
if ((imageSize = file.tellg()) == std::streampos(-1)) {
ASSIMP_LOG_WARN("EmbedTexturesProcess: Cannot find image: ", imagePath, ". Will try to find it in root folder."); ASSIMP_LOG_WARN("EmbedTexturesProcess: Cannot find image: ", imagePath, ". Will try to find it in root folder.");
// Test path in root path // Test path in root path
imagePath = mRootPath + path; imagePath = mRootPath + path;
file.open(imagePath, std::ios::binary | std::ios::ate); if (!mIOHandler->Exists(imagePath)) {
if ((imageSize = file.tellg()) == std::streampos(-1)) {
// Test path basename in root path // Test path basename in root path
imagePath = mRootPath + path.substr(path.find_last_of("\\/") + 1u); imagePath = mRootPath + path.substr(path.find_last_of("\\/") + 1u);
file.open(imagePath, std::ios::binary | std::ios::ate); if (!mIOHandler->Exists(imagePath)) {
if ((imageSize = file.tellg()) == std::streampos(-1)) {
ASSIMP_LOG_ERROR("EmbedTexturesProcess: Unable to embed texture: ", path, "."); ASSIMP_LOG_ERROR("EmbedTexturesProcess: Unable to embed texture: ", path, ".");
return false; return false;
} }
} }
} }
IOStream* pFile = mIOHandler->Open(imagePath);
if (pFile == nullptr) {
ASSIMP_LOG_ERROR("EmbedTexturesProcess: Unable to embed texture: ", path, ".");
return false;
}
imageSize = pFile->FileSize();
aiTexel* imageContent = new aiTexel[ 1ul + static_cast<unsigned long>( imageSize ) / sizeof(aiTexel)]; aiTexel* imageContent = new aiTexel[ 1ul + static_cast<unsigned long>( imageSize ) / sizeof(aiTexel)];
file.seekg(0, std::ios::beg); pFile->Seek(0, aiOrigin_SET);
file.read(reinterpret_cast<char*>(imageContent), imageSize); pFile->Read(reinterpret_cast<char*>(imageContent), imageSize, 1);
mIOHandler->Close(pFile);
// Enlarging the textures table // Enlarging the textures table
unsigned int textureId = pScene->mNumTextures++; unsigned int textureId = pScene->mNumTextures++;

View File

@ -48,6 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct aiNode; struct aiNode;
class IOSystem;
namespace Assimp { namespace Assimp {
/** /**
@ -80,6 +82,7 @@ private:
private: private:
std::string mRootPath; std::string mRootPath;
IOSystem* mIOHandler = nullptr;
}; };
} // namespace Assimp } // namespace Assimp

View File

@ -1 +0,0 @@
2.3.0

View File

@ -1,31 +0,0 @@
cache: ccache
language: cpp
matrix:
include:
- os: linux
dist: xenial
compiler: clang
- os: linux
dist: xenial
compiler: gcc
- os: osx
compiler: clang
addons:
apt:
packages:
- cmake
script:
# Output version info for compilers, cmake, and make
- ${CC} -v
- ${CXX} -v
- cmake --version
- make --version
# Clone googletest
- pushd .. && git clone https://github.com/google/googletest.git && popd
# Configure and build
- mkdir _travis_build && cd _travis_build
- cmake -G "Unix Makefiles" -DENABLE_TESTS=ON ..
- make -j10
- ./draco_tests

View File

@ -804,7 +804,7 @@ else()
draco_points_enc) draco_points_enc)
# Library targets that consume the object collections. # Library targets that consume the object collections.
if(MSVC OR WIN32) if(MSVC)
# In order to produce a DLL and import library the Windows tools require # In order to produce a DLL and import library the Windows tools require
# that the exported symbols are part of the DLL target. The unfortunate side # that the exported symbols are part of the DLL target. The unfortunate side
# effect of this is that a single configuration cannot output both the # effect of this is that a single configuration cannot output both the
@ -889,9 +889,6 @@ else()
# For Mac, we need to build a .bundle for the unity plugin. # For Mac, we need to build a .bundle for the unity plugin.
if(APPLE) if(APPLE)
set_target_properties(dracodec_unity PROPERTIES BUNDLE true) set_target_properties(dracodec_unity PROPERTIES BUNDLE true)
elseif(NOT unity_decoder_lib_type STREQUAL STATIC)
set_target_properties(dracodec_unity
PROPERTIES SOVERSION ${DRACO_SOVERSION})
endif() endif()
endif() endif()
@ -916,9 +913,6 @@ else()
# For Mac, we need to build a .bundle for the plugin. # For Mac, we need to build a .bundle for the plugin.
if(APPLE) if(APPLE)
set_target_properties(draco_maya_wrapper PROPERTIES BUNDLE true) set_target_properties(draco_maya_wrapper PROPERTIES BUNDLE true)
else()
set_target_properties(draco_maya_wrapper
PROPERTIES SOVERSION ${DRACO_SOVERSION})
endif() endif()
endif() endif()

View File

@ -2,16 +2,16 @@
<img width="350px" src="docs/artwork/draco3d-vert.svg" /> <img width="350px" src="docs/artwork/draco3d-vert.svg" />
</p> </p>
![Build Status: master](https://travis-ci.org/google/draco.svg?branch=master) [![Build Status](https://github.com/google/draco/workflows/Build/badge.svg)](https://github.com/google/draco/actions?query=workflow%3ABuild)
News News
======= =======
### Version 1.4.1 release ### Version 1.4.1 release
* Using the versioned gstatic.com WASM and Javascript decoders is now * Using the versioned www.gstatic.com WASM and Javascript decoders is now
recommended. To use v1.4.1, use this URL: recommended. To use v1.4.1, use this URL:
* https://www.gstatic.com/draco/versioned/decoders/1.4.1/* * https://www.gstatic.com/draco/versioned/decoders/1.4.1/*
* Replace the * with the files to load. E.g. * Replace the * with the files to load. E.g.
* https://gstatic.com/draco/versioned/decoders/1.4.1/draco_decoder.js * https://www.gstatic.com/draco/versioned/decoders/1.4.1/draco_decoder.js
* This works with the v1.3.6 and v1.4.0 releases, and will work with future * This works with the v1.3.6 and v1.4.0 releases, and will work with future
Draco releases. Draco releases.
* Bug fixes * Bug fixes

View File

@ -6,7 +6,7 @@ set(DRACO_CMAKE_DRACO_BUILD_DEFINITIONS_CMAKE_ 1)
# Utility for controlling the main draco library dependency. This changes in # Utility for controlling the main draco library dependency. This changes in
# shared builds, and when an optional target requires a shared library build. # shared builds, and when an optional target requires a shared library build.
macro(set_draco_target) macro(set_draco_target)
if(MSVC OR WIN32) if(MSVC)
set(draco_dependency draco) set(draco_dependency draco)
set(draco_plugin_dependency ${draco_dependency}) set(draco_plugin_dependency ${draco_dependency})
else() else()
@ -63,6 +63,11 @@ macro(draco_set_build_definitions)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif() endif()
else()
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
# Ensure 64-bit platforms can support large files.
list(APPEND draco_defines "_LARGEFILE_SOURCE" "_FILE_OFFSET_BITS=64")
endif()
endif() endif()
if(ANDROID) if(ANDROID)
@ -114,4 +119,6 @@ macro(draco_set_build_definitions)
draco_check_emscripten_environment() draco_check_emscripten_environment()
draco_get_required_emscripten_flags(FLAG_LIST_VAR draco_base_cxx_flags) draco_get_required_emscripten_flags(FLAG_LIST_VAR draco_base_cxx_flags)
endif() endif()
draco_configure_sanitizer()
endmacro() endmacro()

View File

@ -1,63 +0,0 @@
if(DRACO_CMAKE_DRACO_FEATURES_CMAKE_)
return()
endif()
set(DRACO_CMAKE_DRACO_FEATURES_CMAKE_ 1)
set(draco_features_file_name "${draco_build_dir}/draco/draco_features.h")
set(draco_features_list)
# Macro that handles tracking of Draco preprocessor symbols for the purpose of
# producing draco_features.h.
#
# draco_enable_feature(FEATURE <feature_name> [TARGETS <target_name>]) FEATURE
# is required. It should be a Draco preprocessor symbol. TARGETS is optional. It
# can be one or more draco targets.
#
# When the TARGETS argument is not present the preproc symbol is added to
# draco_features.h. When it is draco_features.h is unchanged, and
# target_compile_options() is called for each target specified.
macro(draco_enable_feature)
set(def_flags)
set(def_single_arg_opts FEATURE)
set(def_multi_arg_opts TARGETS)
cmake_parse_arguments(DEF "${def_flags}" "${def_single_arg_opts}"
"${def_multi_arg_opts}" ${ARGN})
if("${DEF_FEATURE}" STREQUAL "")
message(FATAL_ERROR "Empty FEATURE passed to draco_enable_feature().")
endif()
# Do nothing/return early if $DEF_FEATURE is already in the list.
list(FIND draco_features_list ${DEF_FEATURE} df_index)
if(NOT df_index EQUAL -1)
return()
endif()
list(LENGTH DEF_TARGETS df_targets_list_length)
if(${df_targets_list_length} EQUAL 0)
list(APPEND draco_features_list ${DEF_FEATURE})
else()
foreach(target ${DEF_TARGETS})
target_compile_definitions(${target} PRIVATE ${DEF_FEATURE})
endforeach()
endif()
endmacro()
# Function for generating draco_features.h.
function(draco_generate_features_h)
file(WRITE "${draco_features_file_name}.new"
"// GENERATED FILE -- DO NOT EDIT\n\n" "#ifndef DRACO_FEATURES_H_\n"
"#define DRACO_FEATURES_H_\n\n")
foreach(feature ${draco_features_list})
file(APPEND "${draco_features_file_name}.new" "#define ${feature}\n")
endforeach()
file(APPEND "${draco_features_file_name}.new"
"\n#endif // DRACO_FEATURES_H_")
# Will replace ${draco_features_file_name} only if the file content has
# changed. This prevents forced Draco rebuilds after CMake runs.
configure_file("${draco_features_file_name}.new"
"${draco_features_file_name}")
file(REMOVE "${draco_features_file_name}.new")
endfunction()

View File

@ -80,6 +80,12 @@ macro(draco_test_cxx_flag)
# Run the actual compile test. # Run the actual compile test.
unset(draco_all_cxx_flags_pass CACHE) unset(draco_all_cxx_flags_pass CACHE)
message("--- Running combined CXX flags test, flags: ${all_cxx_flags}") message("--- Running combined CXX flags test, flags: ${all_cxx_flags}")
# check_cxx_compiler_flag() requires that the flags are a string. When flags
# are passed as a list it will remove the list separators, and attempt to run
# a compile command using list entries concatenated together as a single
# argument. Avoid the problem by forcing the argument to be a string.
draco_set_and_stringify(SOURCE_VARS all_cxx_flags DEST all_cxx_flags)
check_cxx_compiler_flag("${all_cxx_flags}" draco_all_cxx_flags_pass) check_cxx_compiler_flag("${all_cxx_flags}" draco_all_cxx_flags_pass)
if(cxx_test_FLAG_REQUIRED AND NOT draco_all_cxx_flags_pass) if(cxx_test_FLAG_REQUIRED AND NOT draco_all_cxx_flags_pass)
@ -194,6 +200,9 @@ macro(draco_test_exe_linker_flag)
else() else()
unset(CMAKE_EXE_LINKER_FLAGS) unset(CMAKE_EXE_LINKER_FLAGS)
endif() endif()
list(APPEND DRACO_EXE_LINKER_FLAGS ${${link_FLAG_LIST_VAR_NAME}})
list(REMOVE_DUPLICATES DRACO_EXE_LINKER_FLAGS)
endmacro() endmacro()
# Runs the draco compiler tests. This macro builds up the list of list var(s) # Runs the draco compiler tests. This macro builds up the list of list var(s)

View File

@ -55,7 +55,7 @@ macro(draco_setup_install_target)
install(TARGETS draco_encoder DESTINATION install(TARGETS draco_encoder DESTINATION
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
if(WIN32) if(MSVC)
install(TARGETS draco DESTINATION install(TARGETS draco DESTINATION
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
else() else()

View File

@ -5,28 +5,28 @@ set(DRACO_CMAKE_DRACO_SANITIZER_CMAKE_ 1)
# Handles the details of enabling sanitizers. # Handles the details of enabling sanitizers.
macro(draco_configure_sanitizer) macro(draco_configure_sanitizer)
if(DRACO_SANITIZE AND NOT MSVC) if(DRACO_SANITIZE AND NOT EMSCRIPTEN AND NOT MSVC)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(DRACO_SANITIZE MATCHES "cfi") if(DRACO_SANITIZE MATCHES "cfi")
list(APPEND DRACO_CXX_FLAGS "-flto" "-fno-sanitize-trap=cfi") list(APPEND SAN_CXX_FLAGS "-flto" "-fno-sanitize-trap=cfi")
list(APPEND DRACO_EXE_LINKER_FLAGS "-flto" "-fno-sanitize-trap=cfi" list(APPEND SAN_LINKER_FLAGS "-flto" "-fno-sanitize-trap=cfi"
"-fuse-ld=gold") "-fuse-ld=gold")
endif() endif()
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4 if(${CMAKE_SIZEOF_VOID_P} EQUAL 4
AND DRACO_SANITIZE MATCHES "integer|undefined") AND DRACO_SANITIZE MATCHES "integer|undefined")
list(APPEND DRACO_EXE_LINKER_FLAGS "--rtlib=compiler-rt" "-lgcc_s") list(APPEND SAN_LINKER_FLAGS "--rtlib=compiler-rt" "-lgcc_s")
endif() endif()
endif() endif()
list(APPEND DRACO_CXX_FLAGS "-fsanitize=${DRACO_SANITIZE}") list(APPEND SAN_CXX_FLAGS "-fsanitize=${DRACO_SANITIZE}")
list(APPEND DRACO_EXE_LINKER_FLAGS "-fsanitize=${DRACO_SANITIZE}") list(APPEND SAN_LINKER_FLAGS "-fsanitize=${DRACO_SANITIZE}")
# Make sanitizer callstacks accurate. # Make sanitizer callstacks accurate.
list(APPEND DRACO_CXX_FLAGS "-fno-omit-frame-pointer" list(APPEND SAN_CXX_FLAGS "-fno-omit-frame-pointer")
"-fno-optimize-sibling-calls") list(APPEND SAN_CXX_FLAGS "-fno-optimize-sibling-calls")
draco_test_cxx_flag(FLAG_LIST_VAR_NAMES DRACO_CXX_FLAGS FLAG_REQUIRED) draco_test_cxx_flag(FLAG_LIST_VAR_NAMES SAN_CXX_FLAGS FLAG_REQUIRED)
draco_test_exe_linker_flag(FLAG_LIST_VAR_NAME DRACO_EXE_LINKER_FLAGS) draco_test_exe_linker_flag(FLAG_LIST_VAR_NAME SAN_LINKER_FLAGS)
endif() endif()
endmacro() endmacro()

View File

@ -87,6 +87,7 @@ macro(draco_add_executable)
endif() endif()
add_executable(${exe_NAME} ${exe_SOURCES}) add_executable(${exe_NAME} ${exe_SOURCES})
set_target_properties(${exe_NAME} PROPERTIES VERSION ${DRACO_VERSION})
if(exe_OUTPUT_NAME) if(exe_OUTPUT_NAME)
set_target_properties(${exe_NAME} PROPERTIES OUTPUT_NAME ${exe_OUTPUT_NAME}) set_target_properties(${exe_NAME} PROPERTIES OUTPUT_NAME ${exe_OUTPUT_NAME})
@ -109,10 +110,11 @@ macro(draco_add_executable)
if(exe_LINK_FLAGS OR DRACO_EXE_LINKER_FLAGS) if(exe_LINK_FLAGS OR DRACO_EXE_LINKER_FLAGS)
if(${CMAKE_VERSION} VERSION_LESS "3.13") if(${CMAKE_VERSION} VERSION_LESS "3.13")
set(link_flags ${exe_LINK_FLAGS} ${DRACO_EXE_LINKER_FLAGS}) list(APPEND exe_LINK_FLAGS "${DRACO_EXE_LINKER_FLAGS}")
# LINK_FLAGS is managed as a string.
draco_set_and_stringify(SOURCE "${exe_LINK_FLAGS}" DEST exe_LINK_FLAGS)
set_target_properties(${exe_NAME} set_target_properties(${exe_NAME}
PROPERTIES LINK_FLAGS ${exe_LINK_FLAGS} PROPERTIES LINK_FLAGS "${exe_LINK_FLAGS}")
${DRACO_EXE_LINKER_FLAGS})
else() else()
target_link_options(${exe_NAME} PRIVATE ${exe_LINK_FLAGS} target_link_options(${exe_NAME} PRIVATE ${exe_LINK_FLAGS}
${DRACO_EXE_LINKER_FLAGS}) ${DRACO_EXE_LINKER_FLAGS})
@ -130,7 +132,7 @@ macro(draco_add_executable)
endif() endif()
if(BUILD_SHARED_LIBS AND (MSVC OR WIN32)) if(BUILD_SHARED_LIBS AND (MSVC OR WIN32))
target_compile_definitions(${lib_NAME} PRIVATE "DRACO_BUILDING_DLL=0") target_compile_definitions(${exe_NAME} PRIVATE "DRACO_BUILDING_DLL=0")
endif() endif()
if(exe_LIB_DEPS) if(exe_LIB_DEPS)
@ -163,8 +165,8 @@ endmacro()
# cmake-format: off # cmake-format: off
# - OUTPUT_NAME: Override output file basename. Target basename defaults to # - OUTPUT_NAME: Override output file basename. Target basename defaults to
# NAME. OUTPUT_NAME is ignored when BUILD_SHARED_LIBS is enabled and CMake # NAME. OUTPUT_NAME is ignored when BUILD_SHARED_LIBS is enabled and CMake
# is generating a build for which MSVC or WIN32 are true. This is to avoid # is generating a build for which MSVC is true. This is to avoid output
# output basename collisions with DLL import libraries. # basename collisions with DLL import libraries.
# - TEST: Flag. Presence means treat library as a test. # - TEST: Flag. Presence means treat library as a test.
# - DEFINES: List of preprocessor macro definitions. # - DEFINES: List of preprocessor macro definitions.
# - INCLUDES: list of include directories for the target. # - INCLUDES: list of include directories for the target.
@ -259,7 +261,7 @@ macro(draco_add_library)
endif() endif()
if(lib_OUTPUT_NAME) if(lib_OUTPUT_NAME)
if(NOT (BUILD_SHARED_LIBS AND (MSVC OR WIN32))) if(NOT (BUILD_SHARED_LIBS AND MSVC))
set_target_properties(${lib_NAME} set_target_properties(${lib_NAME}
PROPERTIES OUTPUT_NAME ${lib_OUTPUT_NAME}) PROPERTIES OUTPUT_NAME ${lib_OUTPUT_NAME})
endif() endif()
@ -318,8 +320,12 @@ macro(draco_add_library)
set_target_properties(${lib_NAME} PROPERTIES PREFIX "") set_target_properties(${lib_NAME} PROPERTIES PREFIX "")
endif() endif()
if(lib_TYPE STREQUAL SHARED AND NOT MSVC) # VERSION and SOVERSION as necessary
set_target_properties(${lib_NAME} PROPERTIES SOVERSION ${DRACO_SOVERSION}) if(NOT lib_TYPE STREQUAL STATIC AND NOT lib_TYPE STREQUAL MODULE)
set_target_properties(${lib_NAME} PROPERTIES VERSION ${DRACO_VERSION})
if(NOT MSVC)
set_target_properties(${lib_NAME} PROPERTIES SOVERSION ${DRACO_SOVERSION})
endif()
endif() endif()
if(BUILD_SHARED_LIBS AND (MSVC OR WIN32)) if(BUILD_SHARED_LIBS AND (MSVC OR WIN32))

View File

@ -17,31 +17,31 @@
namespace draco { namespace draco {
void DracoTimer::Start() { void DracoTimer::Start() {
#ifdef _WIN32 #ifdef _WIN32
QueryPerformanceCounter(&tv_start); QueryPerformanceCounter(&tv_start_);
#else #else
gettimeofday(&tv_start, nullptr); gettimeofday(&tv_start_, nullptr);
#endif #endif
} }
void DracoTimer::Stop() { void DracoTimer::Stop() {
#ifdef _WIN32 #ifdef _WIN32
QueryPerformanceCounter(&tv_end); QueryPerformanceCounter(&tv_end_);
#else #else
gettimeofday(&tv_end, nullptr); gettimeofday(&tv_end_, nullptr);
#endif #endif
} }
int64_t DracoTimer::GetInMs() { int64_t DracoTimer::GetInMs() {
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER elapsed = {0}; LARGE_INTEGER elapsed = {0};
elapsed.QuadPart = tv_end.QuadPart - tv_start.QuadPart; elapsed.QuadPart = tv_end_.QuadPart - tv_start_.QuadPart;
LARGE_INTEGER frequency = {0}; LARGE_INTEGER frequency = {0};
QueryPerformanceFrequency(&frequency); QueryPerformanceFrequency(&frequency);
return elapsed.QuadPart * 1000 / frequency.QuadPart; return elapsed.QuadPart * 1000 / frequency.QuadPart;
#else #else
const int64_t seconds = (tv_end.tv_sec - tv_start.tv_sec) * 1000; const int64_t seconds = (tv_end_.tv_sec - tv_start_.tv_sec) * 1000;
const int64_t milliseconds = (tv_end.tv_usec - tv_start.tv_usec) / 1000; const int64_t milliseconds = (tv_end_.tv_usec - tv_start_.tv_usec) / 1000;
return seconds + milliseconds; return seconds + milliseconds;
#endif #endif
} }

View File

@ -20,9 +20,10 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>
typedef LARGE_INTEGER timeval; typedef LARGE_INTEGER DracoTimeVal;
#else #else
#include <sys/time.h> #include <sys/time.h>
typedef timeval DracoTimeVal;
#endif #endif
#include <cinttypes> #include <cinttypes>
@ -39,8 +40,8 @@ class DracoTimer {
int64_t GetInMs(); int64_t GetInMs();
private: private:
timeval tv_start; DracoTimeVal tv_start_;
timeval tv_end; DracoTimeVal tv_end_;
}; };
typedef DracoTimer CycleTimer; typedef DracoTimer CycleTimer;

View File

@ -18,6 +18,7 @@
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
#include <iterator> #include <iterator>
#include <limits>
namespace draco { namespace draco {
namespace parser { namespace parser {
@ -252,7 +253,7 @@ DecoderBuffer ParseLineIntoDecoderBuffer(DecoderBuffer *buffer) {
std::string ToLower(const std::string &str) { std::string ToLower(const std::string &str) {
std::string out; std::string out;
std::transform(str.begin(), str.end(), std::back_inserter(out), [](unsigned char c){return tolower(c);}); std::transform(str.begin(), str.end(), std::back_inserter(out), tolower);
return out; return out;
} }

View File

@ -268,14 +268,14 @@ std::vector<std::string> PlyReader::SplitWords(const std::string &line) {
while ((end = line.find_first_of(" \t\n\v\f\r", start)) != while ((end = line.find_first_of(" \t\n\v\f\r", start)) !=
std::string::npos) { std::string::npos) {
const std::string word(line.substr(start, end - start)); const std::string word(line.substr(start, end - start));
if (!std::all_of(word.begin(), word.end(), [](unsigned char c){return isspace(c);})) { if (!std::all_of(word.begin(), word.end(), isspace)) {
output.push_back(word); output.push_back(word);
} }
start = end + 1; start = end + 1;
} }
const std::string last_word(line.substr(start)); const std::string last_word(line.substr(start));
if (!std::all_of(last_word.begin(), last_word.end(), [](unsigned char c){return isspace(c);})) { if (!std::all_of(last_word.begin(), last_word.end(), isspace)) {
output.push_back(last_word); output.push_back(last_word);
} }
return output; return output;

View File

@ -87,7 +87,14 @@ size_t StdioFileReader::GetFileSize() {
return false; return false;
} }
#if _FILE_OFFSET_BITS == 64
const size_t file_size = static_cast<size_t>(ftello(file_));
#elif defined _WIN64
const size_t file_size = static_cast<size_t>(_ftelli64(file_));
#else
const size_t file_size = static_cast<size_t>(ftell(file_)); const size_t file_size = static_cast<size_t>(ftell(file_));
#endif
rewind(file_); rewind(file_);
return file_size; return file_size;

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2021, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -397,22 +395,35 @@ struct aiScene
//! Returns an embedded texture //! Returns an embedded texture
const aiTexture* GetEmbeddedTexture(const char* filename) const { const aiTexture* GetEmbeddedTexture(const char* filename) const {
return GetEmbeddedTextureAndIndex(filename).first;
}
//! Returns an embedded texture and its index
std::pair<const aiTexture*, int> GetEmbeddedTextureAndIndex(const char* filename) const {
if(nullptr==filename) {
return std::make_pair(nullptr, -1);
}
// lookup using texture ID (if referenced like: "*1", "*2", etc.) // lookup using texture ID (if referenced like: "*1", "*2", etc.)
if ('*' == *filename) { if ('*' == *filename) {
int index = std::atoi(filename + 1); int index = std::atoi(filename + 1);
if (0 > index || mNumTextures <= static_cast<unsigned>(index)) if (0 > index || mNumTextures <= static_cast<unsigned>(index)) {
return nullptr; return std::make_pair(nullptr, -1);
return mTextures[index]; }
return std::make_pair(mTextures[index], index);
} }
// lookup using filename // lookup using filename
const char* shortFilename = GetShortFilename(filename); const char* shortFilename = GetShortFilename(filename);
if (nullptr == shortFilename) {
return std::make_pair(nullptr, -1);
}
for (unsigned int i = 0; i < mNumTextures; i++) { for (unsigned int i = 0; i < mNumTextures; i++) {
const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str()); const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str());
if (strcmp(shortTextureFilename, shortFilename) == 0) { if (strcmp(shortTextureFilename, shortFilename) == 0) {
return mTextures[i]; return std::make_pair(mTextures[i], i);
} }
} }
return nullptr; return std::make_pair(nullptr, -1);
} }
#endif // __cplusplus #endif // __cplusplus