Merge pull request #2235 from assimp/issue_2229
closes https://github.com/assimp/assimp/issues/2229: fix count of pol…pull/2236/head
commit
d98f8bbf7b
|
@ -55,28 +55,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace DXF {
|
namespace DXF {
|
||||||
|
|
||||||
|
|
||||||
// read pairs of lines, parse group code and value and provide utilities
|
// read pairs of lines, parse group code and value and provide utilities
|
||||||
// to convert the data to the target data type.
|
// to convert the data to the target data type.
|
||||||
class LineReader
|
// do NOT skip empty lines. In DXF files, they count as valid data.
|
||||||
{
|
class LineReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LineReader(StreamReaderLE& reader)
|
LineReader(StreamReaderLE& reader)
|
||||||
// do NOT skip empty lines. In DXF files, they count as valid data.
|
|
||||||
: splitter(reader,false,true)
|
: splitter(reader,false,true)
|
||||||
, groupcode( 0 )
|
, groupcode( 0 )
|
||||||
, value()
|
, value()
|
||||||
, end()
|
, end() {
|
||||||
{
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
bool Is(int gc, const char* what) const {
|
bool Is(int gc, const char* what) const {
|
||||||
return groupcode == gc && !strcmp(what,value.c_str());
|
return groupcode == gc && !strcmp(what,value.c_str());
|
||||||
|
@ -102,8 +95,6 @@ public:
|
||||||
return !((bool)*this);
|
return !((bool)*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
unsigned int ValueAsUnsignedInt() const {
|
unsigned int ValueAsUnsignedInt() const {
|
||||||
return strtoul10(value.c_str());
|
return strtoul10(value.c_str());
|
||||||
|
@ -119,8 +110,6 @@ public:
|
||||||
return fast_atof(value.c_str());
|
return fast_atof(value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
/** pseudo-iterator increment to advance to the next (groupcode/value) pair */
|
/** pseudo-iterator increment to advance to the next (groupcode/value) pair */
|
||||||
LineReader& operator++() {
|
LineReader& operator++() {
|
||||||
|
@ -175,14 +164,12 @@ private:
|
||||||
int end;
|
int end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// represents a POLYLINE or a LWPOLYLINE. or even a 3DFACE The data is converted as needed.
|
// represents a POLYLINE or a LWPOLYLINE. or even a 3DFACE The data is converted as needed.
|
||||||
struct PolyLine
|
struct PolyLine {
|
||||||
{
|
|
||||||
PolyLine()
|
PolyLine()
|
||||||
: flags()
|
: flags() {
|
||||||
{}
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<aiVector3D> positions;
|
std::vector<aiVector3D> positions;
|
||||||
std::vector<aiColor4D> colors;
|
std::vector<aiColor4D> colors;
|
||||||
|
@ -194,14 +181,15 @@ struct PolyLine
|
||||||
std::string desc;
|
std::string desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// reference to a BLOCK. Specifies its own coordinate system.
|
// reference to a BLOCK. Specifies its own coordinate system.
|
||||||
struct InsertBlock
|
struct InsertBlock {
|
||||||
{
|
|
||||||
InsertBlock()
|
InsertBlock()
|
||||||
: scale(1.f,1.f,1.f)
|
: pos()
|
||||||
|
, scale(1.f,1.f,1.f)
|
||||||
, angle()
|
, angle()
|
||||||
{}
|
, name() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
aiVector3D pos;
|
aiVector3D pos;
|
||||||
aiVector3D scale;
|
aiVector3D scale;
|
||||||
|
@ -228,9 +216,7 @@ struct FileData
|
||||||
std::vector<Block> blocks;
|
std::vector<Block> blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
} // Namespace Assimp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,16 +63,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
// AutoCAD Binary DXF<CR><LF><SUB><NULL>
|
// AutoCAD Binary DXF<CR><LF><SUB><NULL>
|
||||||
#define AI_DXF_BINARY_IDENT ("AutoCAD Binary DXF\r\n\x1a\0")
|
const std::string AI_DXF_BINARY_IDENT = std::string("AutoCAD Binary DXF\r\n\x1a\0");
|
||||||
#define AI_DXF_BINARY_IDENT_LEN (24)
|
const size_t AI_DXF_BINARY_IDENT_LEN = 24u;
|
||||||
|
|
||||||
// default vertex color that all uncolored vertices will receive
|
// default vertex color that all uncolored vertices will receive
|
||||||
#define AI_DXF_DEFAULT_COLOR aiColor4D(0.6f,0.6f,0.6f,0.6f)
|
const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f));
|
||||||
|
|
||||||
// color indices for DXF - 16 are supported, the table is
|
// color indices for DXF - 16 are supported, the table is
|
||||||
// taken directly from the DXF spec.
|
// taken directly from the DXF spec.
|
||||||
static aiColor4D g_aclrDxfIndexColors[] =
|
static aiColor4D g_aclrDxfIndexColors[] = {
|
||||||
{
|
|
||||||
aiColor4D (0.6f, 0.6f, 0.6f, 1.0f),
|
aiColor4D (0.6f, 0.6f, 0.6f, 1.0f),
|
||||||
aiColor4D (1.0f, 0.0f, 0.0f, 1.0f), // red
|
aiColor4D (1.0f, 0.0f, 0.0f, 1.0f), // red
|
||||||
aiColor4D (0.0f, 1.0f, 0.0f, 1.0f), // green
|
aiColor4D (0.0f, 1.0f, 0.0f, 1.0f), // green
|
||||||
|
@ -93,6 +92,10 @@ static aiColor4D g_aclrDxfIndexColors[] =
|
||||||
#define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0]))
|
#define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0]))
|
||||||
#define AI_DXF_ENTITIES_MAGIC_BLOCK "$ASSIMP_ENTITIES_MAGIC"
|
#define AI_DXF_ENTITIES_MAGIC_BLOCK "$ASSIMP_ENTITIES_MAGIC"
|
||||||
|
|
||||||
|
static const int GroupCode_Name = 2;
|
||||||
|
static const int GroupCode_XComp = 10;
|
||||||
|
static const int GroupCode_YComp = 20;
|
||||||
|
static const int GroupCode_ZComp = 30;
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
"Drawing Interchange Format (DXF) Importer",
|
"Drawing Interchange Format (DXF) Importer",
|
||||||
|
@ -110,24 +113,27 @@ static const aiImporterDesc desc = {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
DXFImporter::DXFImporter()
|
DXFImporter::DXFImporter()
|
||||||
{}
|
: BaseImporter() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor, private as well
|
// Destructor, private as well
|
||||||
DXFImporter::~DXFImporter()
|
DXFImporter::~DXFImporter() {
|
||||||
{}
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
bool DXFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const {
|
bool DXFImporter::CanRead( const std::string& filename, IOSystem* pIOHandler, bool checkSig ) const {
|
||||||
const std::string& extension = GetExtension( pFile );
|
const std::string& extension = GetExtension( filename );
|
||||||
if ( extension == "dxf" ) {
|
if ( extension == desc.mFileExtensions ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( extension.empty() || checkSig ) {
|
if ( extension.empty() || checkSig ) {
|
||||||
static const char *pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
const char *pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
||||||
return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 4, 32 );
|
return BaseImporter::SearchFileHeaderForToken(pIOHandler, filename, pTokens, 4, 32 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -135,29 +141,25 @@ bool DXFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Get a list of all supported file extensions
|
// Get a list of all supported file extensions
|
||||||
const aiImporterDesc* DXFImporter::GetInfo () const
|
const aiImporterDesc* DXFImporter::GetInfo () const {
|
||||||
{
|
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void DXFImporter::InternReadFile( const std::string& pFile,
|
void DXFImporter::InternReadFile( const std::string& filename, aiScene* pScene, IOSystem* pIOHandler) {
|
||||||
aiScene* pScene,
|
std::shared_ptr<IOStream> file = std::shared_ptr<IOStream>( pIOHandler->Open( filename) );
|
||||||
IOSystem* pIOHandler)
|
|
||||||
{
|
|
||||||
std::shared_ptr<IOStream> file = std::shared_ptr<IOStream>( pIOHandler->Open( pFile) );
|
|
||||||
|
|
||||||
// Check whether we can read the file
|
// Check whether we can read the file
|
||||||
if( file.get() == NULL) {
|
if( file.get() == nullptr ) {
|
||||||
throw DeadlyImportError( "Failed to open DXF file " + pFile + "");
|
throw DeadlyImportError( "Failed to open DXF file " + filename + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether this is a binaray DXF file - we can't read binary DXF files :-(
|
// Check whether this is a binary DXF file - we can't read binary DXF files :-(
|
||||||
char buff[AI_DXF_BINARY_IDENT_LEN+1] = {0};
|
char buff[AI_DXF_BINARY_IDENT_LEN+1] = {0};
|
||||||
file->Read(buff,AI_DXF_BINARY_IDENT_LEN,1);
|
file->Read(buff,AI_DXF_BINARY_IDENT_LEN,1);
|
||||||
|
|
||||||
if (!strncmp(AI_DXF_BINARY_IDENT,buff,AI_DXF_BINARY_IDENT_LEN)) {
|
if (0 == strncmp(AI_DXF_BINARY_IDENT.c_str(),buff,AI_DXF_BINARY_IDENT_LEN)) {
|
||||||
throw DeadlyImportError("DXF: Binary files are not supported at the moment");
|
throw DeadlyImportError("DXF: Binary files are not supported at the moment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,13 +228,11 @@ void DXFImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output)
|
void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output) {
|
||||||
{
|
|
||||||
// the process of resolving all the INSERT statements can grow the
|
// the process of resolving all the INSERT statements can grow the
|
||||||
// poly-count excessively, so log the original number.
|
// poly-count excessively, so log the original number.
|
||||||
// XXX Option to import blocks as separate nodes?
|
// XXX Option to import blocks as separate nodes?
|
||||||
if (!DefaultLogger::isNullLogger()) {
|
if (!DefaultLogger::isNullLogger()) {
|
||||||
|
|
||||||
unsigned int vcount = 0, icount = 0;
|
unsigned int vcount = 0, icount = 0;
|
||||||
for (const DXF::Block& bl : output.blocks) {
|
for (const DXF::Block& bl : output.blocks) {
|
||||||
for (std::shared_ptr<const DXF::PolyLine> pl : bl.lines) {
|
for (std::shared_ptr<const DXF::PolyLine> pl : bl.lines) {
|
||||||
|
@ -293,7 +293,7 @@ void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pScene->mNumMeshes) {
|
if ( 0 == pScene->mNumMeshes) {
|
||||||
throw DeadlyImportError("DXF: this file contains no 3d data");
|
throw DeadlyImportError("DXF: this file contains no 3d data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,8 +366,7 @@ void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output)
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& blocks_by_name)
|
void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& blocks_by_name) {
|
||||||
{
|
|
||||||
for (const DXF::InsertBlock& insert : bl.insertions) {
|
for (const DXF::InsertBlock& insert : bl.insertions) {
|
||||||
|
|
||||||
// first check if the referenced blocks exists ...
|
// first check if the referenced blocks exists ...
|
||||||
|
@ -407,8 +406,7 @@ void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& bloc
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::GenerateMaterials(aiScene* pScene, DXF::FileData& /*output*/)
|
void DXFImporter::GenerateMaterials(aiScene* pScene, DXF::FileData& /*output*/) {
|
||||||
{
|
|
||||||
// generate an almost-white default material. Reason:
|
// generate an almost-white default material. Reason:
|
||||||
// the default vertex color is GREY, so we are
|
// the default vertex color is GREY, so we are
|
||||||
// already at Assimp's usual default color.
|
// already at Assimp's usual default color.
|
||||||
|
@ -433,8 +431,7 @@ void DXFImporter::GenerateMaterials(aiScene* pScene, DXF::FileData& /*output*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::GenerateHierarchy(aiScene* pScene, DXF::FileData& /*output*/)
|
void DXFImporter::GenerateHierarchy(aiScene* pScene, DXF::FileData& /*output*/) {
|
||||||
{
|
|
||||||
// generate the output scene graph, which is just the root node with a single child for each layer.
|
// generate the output scene graph, which is just the root node with a single child for each layer.
|
||||||
pScene->mRootNode = new aiNode();
|
pScene->mRootNode = new aiNode();
|
||||||
pScene->mRootNode->mName.Set("<DXF_ROOT>");
|
pScene->mRootNode->mName.Set("<DXF_ROOT>");
|
||||||
|
@ -488,17 +485,17 @@ void DXFImporter::ParseBlock(DXF::LineReader& reader, DXF::FileData& output) {
|
||||||
while( !reader.End() && !reader.Is(0,"ENDBLK")) {
|
while( !reader.End() && !reader.Is(0,"ENDBLK")) {
|
||||||
|
|
||||||
switch(reader.GroupCode()) {
|
switch(reader.GroupCode()) {
|
||||||
case 2:
|
case GroupCode_Name:
|
||||||
block.name = reader.Value();
|
block.name = reader.Value();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10:
|
case GroupCode_XComp:
|
||||||
block.base.x = reader.ValueAsFloat();
|
block.base.x = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
case 20:
|
case GroupCode_YComp:
|
||||||
block.base.y = reader.ValueAsFloat();
|
block.base.y = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
case 30:
|
case GroupCode_ZComp:
|
||||||
block.base.z = reader.ValueAsFloat();
|
block.base.z = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -525,9 +522,8 @@ void DXFImporter::ParseBlock(DXF::LineReader& reader, DXF::FileData& output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::ParseEntities(DXF::LineReader& reader, DXF::FileData& output)
|
void DXFImporter::ParseEntities(DXF::LineReader& reader, DXF::FileData& output) {
|
||||||
{
|
// Push a new block onto the stack.
|
||||||
// push a new block onto the stack.
|
|
||||||
output.blocks.push_back( DXF::Block() );
|
output.blocks.push_back( DXF::Block() );
|
||||||
DXF::Block& block = output.blocks.back();
|
DXF::Block& block = output.blocks.back();
|
||||||
|
|
||||||
|
@ -557,27 +553,25 @@ void DXFImporter::ParseEntities(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
" inserted blocks in ENTITIES" );
|
" inserted blocks in ENTITIES" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output)
|
void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output) {
|
||||||
{
|
|
||||||
output.blocks.back().insertions.push_back( DXF::InsertBlock() );
|
output.blocks.back().insertions.push_back( DXF::InsertBlock() );
|
||||||
DXF::InsertBlock& bl = output.blocks.back().insertions.back();
|
DXF::InsertBlock& bl = output.blocks.back().insertions.back();
|
||||||
|
|
||||||
while( !reader.End() && !reader.Is(0)) {
|
while( !reader.End() && !reader.Is(0)) {
|
||||||
switch(reader.GroupCode())
|
switch(reader.GroupCode()) {
|
||||||
{
|
|
||||||
// name of referenced block
|
// name of referenced block
|
||||||
case 2:
|
case GroupCode_Name:
|
||||||
bl.name = reader.Value();
|
bl.name = reader.Value();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// translation
|
// translation
|
||||||
case 10:
|
case GroupCode_XComp:
|
||||||
bl.pos.x = reader.ValueAsFloat();
|
bl.pos.x = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
case 20:
|
case GroupCode_YComp:
|
||||||
bl.pos.y = reader.ValueAsFloat();
|
bl.pos.y = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
case 30:
|
case GroupCode_ZComp:
|
||||||
bl.pos.z = reader.ValueAsFloat();
|
bl.pos.z = reader.ValueAsFloat();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -704,8 +698,7 @@ void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
#define DXF_VERTEX_FLAG_HAS_POSITIONS 0x40
|
#define DXF_VERTEX_FLAG_HAS_POSITIONS 0x40
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& line)
|
void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& line) {
|
||||||
{
|
|
||||||
unsigned int cnti = 0, flags = 0;
|
unsigned int cnti = 0, flags = 0;
|
||||||
unsigned int indices[4];
|
unsigned int indices[4];
|
||||||
|
|
||||||
|
@ -718,8 +711,7 @@ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& li
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (reader.GroupCode())
|
switch (reader.GroupCode()) {
|
||||||
{
|
|
||||||
case 8:
|
case 8:
|
||||||
// layer to which the vertex belongs to - assume that
|
// layer to which the vertex belongs to - assume that
|
||||||
// this is always the layer the top-level poly-line
|
// this is always the layer the top-level poly-line
|
||||||
|
@ -734,9 +726,17 @@ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& li
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// VERTEX COORDINATES
|
// VERTEX COORDINATES
|
||||||
case 10: out.x = reader.ValueAsFloat();break;
|
case GroupCode_XComp:
|
||||||
case 20: out.y = reader.ValueAsFloat();break;
|
out.x = reader.ValueAsFloat();
|
||||||
case 30: out.z = reader.ValueAsFloat();break;
|
break;
|
||||||
|
|
||||||
|
case GroupCode_YComp:
|
||||||
|
out.y = reader.ValueAsFloat();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GroupCode_ZComp:
|
||||||
|
out.z = reader.ValueAsFloat();
|
||||||
|
break;
|
||||||
|
|
||||||
// POLYFACE vertex indices
|
// POLYFACE vertex indices
|
||||||
case 71:
|
case 71:
|
||||||
|
@ -770,6 +770,10 @@ void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& li
|
||||||
if (indices[i] == 0) {
|
if (indices[i] == 0) {
|
||||||
ASSIMP_LOG_WARN("DXF: invalid vertex index, indices are one-based.");
|
ASSIMP_LOG_WARN("DXF: invalid vertex index, indices are one-based.");
|
||||||
--line.counts.back();
|
--line.counts.back();
|
||||||
|
// Workaround to fix issue 2229
|
||||||
|
if (line.counts.back() == 0) {
|
||||||
|
line.counts.pop_back();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line.indices.push_back(indices[i]-1);
|
line.indices.push_back(indices[i]-1);
|
||||||
|
@ -808,62 +812,74 @@ void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// x position of the first corner
|
// x position of the first corner
|
||||||
case 10: vip[0].x = reader.ValueAsFloat();
|
case 10:
|
||||||
|
vip[0].x = reader.ValueAsFloat();
|
||||||
b[2] = true;
|
b[2] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// y position of the first corner
|
// y position of the first corner
|
||||||
case 20: vip[0].y = reader.ValueAsFloat();
|
case 20:
|
||||||
|
vip[0].y = reader.ValueAsFloat();
|
||||||
b[2] = true;
|
b[2] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// z position of the first corner
|
// z position of the first corner
|
||||||
case 30: vip[0].z = reader.ValueAsFloat();
|
case 30:
|
||||||
|
vip[0].z = reader.ValueAsFloat();
|
||||||
b[2] = true;
|
b[2] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// x position of the second corner
|
// x position of the second corner
|
||||||
case 11: vip[1].x = reader.ValueAsFloat();
|
case 11:
|
||||||
|
vip[1].x = reader.ValueAsFloat();
|
||||||
b[3] = true;
|
b[3] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// y position of the second corner
|
// y position of the second corner
|
||||||
case 21: vip[1].y = reader.ValueAsFloat();
|
case 21:
|
||||||
|
vip[1].y = reader.ValueAsFloat();
|
||||||
b[3] = true;
|
b[3] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// z position of the second corner
|
// z position of the second corner
|
||||||
case 31: vip[1].z = reader.ValueAsFloat();
|
case 31:
|
||||||
|
vip[1].z = reader.ValueAsFloat();
|
||||||
b[3] = true;
|
b[3] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// x position of the third corner
|
// x position of the third corner
|
||||||
case 12: vip[2].x = reader.ValueAsFloat();
|
case 12:
|
||||||
|
vip[2].x = reader.ValueAsFloat();
|
||||||
b[0] = true;
|
b[0] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// y position of the third corner
|
// y position of the third corner
|
||||||
case 22: vip[2].y = reader.ValueAsFloat();
|
case 22:
|
||||||
|
vip[2].y = reader.ValueAsFloat();
|
||||||
b[0] = true;
|
b[0] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// z position of the third corner
|
// z position of the third corner
|
||||||
case 32: vip[2].z = reader.ValueAsFloat();
|
case 32:
|
||||||
|
vip[2].z = reader.ValueAsFloat();
|
||||||
b[0] = true;
|
b[0] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// x position of the fourth corner
|
// x position of the fourth corner
|
||||||
case 13: vip[3].x = reader.ValueAsFloat();
|
case 13:
|
||||||
|
vip[3].x = reader.ValueAsFloat();
|
||||||
b[1] = true;
|
b[1] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// y position of the fourth corner
|
// y position of the fourth corner
|
||||||
case 23: vip[3].y = reader.ValueAsFloat();
|
case 23:
|
||||||
|
vip[3].y = reader.ValueAsFloat();
|
||||||
b[1] = true;
|
b[1] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// z position of the fourth corner
|
// z position of the fourth corner
|
||||||
case 33: vip[3].z = reader.ValueAsFloat();
|
case 33:
|
||||||
|
vip[3].z = reader.ValueAsFloat();
|
||||||
b[1] = true;
|
b[1] = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace DXF {
|
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
namespace DXF {
|
||||||
class LineReader;
|
class LineReader;
|
||||||
struct FileData;
|
struct FileData;
|
||||||
struct PolyLine;
|
struct PolyLine;
|
||||||
|
@ -59,23 +60,17 @@ namespace Assimp {
|
||||||
struct InsertBlock;
|
struct InsertBlock;
|
||||||
|
|
||||||
typedef std::map<std::string, const DXF::Block*> BlockMap;
|
typedef std::map<std::string, const DXF::Block*> BlockMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** DXF importer implementation.
|
/**
|
||||||
*
|
* @brief DXF importer implementation.
|
||||||
*/
|
*/
|
||||||
class DXFImporter : public BaseImporter
|
class DXFImporter : public BaseImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
DXFImporter();
|
DXFImporter();
|
||||||
~DXFImporter();
|
~DXFImporter();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details. */
|
* See BaseImporter::CanRead() for details. */
|
||||||
|
@ -83,7 +78,6 @@ public:
|
||||||
bool checkSig) const;
|
bool checkSig) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details*/
|
* See #BaseImporter::GetInfo for the details*/
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -69,3 +69,8 @@ TEST_F( utDXFImporterExporter, importerWithoutExtensionTest ) {
|
||||||
EXPECT_NE( nullptr, scene );
|
EXPECT_NE( nullptr, scene );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(utDXFImporterExporter, issue2229) {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/DXF/issue_2229.dxf", aiProcess_ValidateDataStructure);
|
||||||
|
EXPECT_NE(nullptr, scene);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue