Commit c0518db7 authored by unknown's avatar unknown Committed by jean-pierre charras

3D viewer: Some more support cases to VRML2 parser and fix some issues.

parent 4b680dd5
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <class_pcb_text.h> #include <class_pcb_text.h>
#include <colors_selection.h> #include <colors_selection.h>
#include <convert_basic_shapes_to_polygon.h> #include <convert_basic_shapes_to_polygon.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/glm/gtc/matrix_transform.hpp>
#include <gal/opengl/opengl_compositor.h> #include <gal/opengl/opengl_compositor.h>
#ifdef __WINDOWS__ #ifdef __WINDOWS__
...@@ -1401,13 +1402,13 @@ void EDA_3D_CANVAS::calcBBox() ...@@ -1401,13 +1402,13 @@ void EDA_3D_CANVAS::calcBBox()
if( module->GetOrientation() ) if( module->GetOrientation() )
fullTransformMatrix = glm::rotate( fullTransformMatrix, fullTransformMatrix = glm::rotate( fullTransformMatrix,
(float)(module->GetOrientation() / 10.0f), glm::radians( (float)(module->GetOrientation() / 10.0f) ),
S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); S3D_VERTEX( 0.0f, 0.0f, 1.0f ) );
if( module->IsFlipped() ) if( module->IsFlipped() )
{ {
fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) );
fullTransformMatrix = glm::rotate( fullTransformMatrix, 180.0f, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) );
} }
// Compute a union bounding box for all the shapes of the model // Compute a union bounding box for all the shapes of the model
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <common.h> #include <common.h>
#include <base_struct.h> #include <base_struct.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
class S3D_MASTER; class S3D_MASTER;
......
This diff is collapsed.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define __3D_MESH_MODEL_H__ #define __3D_MESH_MODEL_H__
#include <vector> #include <vector>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
#include "3d_struct.h" #include "3d_struct.h"
#include "3d_material.h" #include "3d_material.h"
...@@ -55,6 +56,7 @@ public: ...@@ -55,6 +56,7 @@ public:
std::vector< S3D_VERTEX > m_Point; std::vector< S3D_VERTEX > m_Point;
std::vector< std::vector<int> > m_CoordIndex; std::vector< std::vector<int> > m_CoordIndex;
std::vector< std::vector<int> > m_NormalIndex; std::vector< std::vector<int> > m_NormalIndex;
std::vector< S3D_VERTEX > m_PerFaceColor;
std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized; std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized;
std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized; std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized;
std::vector< int > m_MaterialIndex; std::vector< int > m_MaterialIndex;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <macros.h> #include <macros.h>
#include <kicad_string.h> #include <kicad_string.h>
#include <pgm_base.h> #include <pgm_base.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/gtc/matrix_transform.hpp> #include <gal/opengl/glm/gtc/matrix_transform.hpp>
#include <3d_viewer.h> #include <3d_viewer.h>
#include <info3d_visu.h> #include <info3d_visu.h>
...@@ -176,11 +177,11 @@ void S3D_MASTER::calcBBox() ...@@ -176,11 +177,11 @@ void S3D_MASTER::calcBBox()
m_MatPosition.z * SCALE_3D_CONV) ); m_MatPosition.z * SCALE_3D_CONV) );
if( m_MatRotation.z != 0.0 ) if( m_MatRotation.z != 0.0 )
fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.z, S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.z), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) );
if( m_MatRotation.y != 0.0 ) if( m_MatRotation.y != 0.0 )
fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.y, S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.y), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) );
if( m_MatRotation.x != 0.0 ) if( m_MatRotation.x != 0.0 )
fullTransformMatrix = glm::rotate( fullTransformMatrix, -(float)m_MatRotation.x, S3D_VERTEX( 1.0f, 0.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians(-(float)m_MatRotation.x), S3D_VERTEX( 1.0f, 0.0f, 0.0f ) );
fullTransformMatrix = glm::scale( fullTransformMatrix, S3D_VERTEX( m_MatScale.x, m_MatScale.y, m_MatScale.z ) ); fullTransformMatrix = glm::scale( fullTransformMatrix, S3D_VERTEX( m_MatScale.x, m_MatScale.y, m_MatScale.z ) );
......
...@@ -178,7 +178,7 @@ void EDA_3D_FRAME::CreateMenuBar() ...@@ -178,7 +178,7 @@ void EDA_3D_FRAME::CreateMenuBar()
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SMOOTH_NORMALS, AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SMOOTH_NORMALS,
_( "Render Smooth Normals" ), _( "Render Smooth Normals" ),
KiBitmap( green_xpm ), wxITEM_CHECK ); KiBitmap( green_xpm ), wxITEM_CHECK );
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_USE_MODEL_NORMALS, AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_USE_MODEL_NORMALS,
_( "Use Model Normals" ), _( "Use Model Normals" ),
KiBitmap( green_xpm ), wxITEM_CHECK ); KiBitmap( green_xpm ), wxITEM_CHECK );
...@@ -188,7 +188,7 @@ void EDA_3D_FRAME::CreateMenuBar() ...@@ -188,7 +188,7 @@ void EDA_3D_FRAME::CreateMenuBar()
KiBitmap( green_xpm ), wxITEM_CHECK ); KiBitmap( green_xpm ), wxITEM_CHECK );
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SHOW_MODEL_BBOX, AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SHOW_MODEL_BBOX,
_( "Show Model Bouding Boxes" ), _( "Show Model Bounding Boxes" ),
KiBitmap( green_xpm ), wxITEM_CHECK ); KiBitmap( green_xpm ), wxITEM_CHECK );
prefsMenu->AppendSeparator(); prefsMenu->AppendSeparator();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#ifndef _3D_TYPES_H_ #ifndef _3D_TYPES_H_
#define _3D_TYPES_H_ #define _3D_TYPES_H_
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
#include <base_units.h> // for IU_PER_MILS #include <base_units.h> // for IU_PER_MILS
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#ifndef CBBox_h #ifndef CBBox_h
#define CBBox_h #define CBBox_h
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
#include <3d_types.h> #include <3d_types.h>
......
...@@ -219,6 +219,9 @@ private: ...@@ -219,6 +219,9 @@ private:
S3D_MODEL_PARSER* m_ModelParser; S3D_MODEL_PARSER* m_ModelParser;
S3D_MASTER* m_Master; S3D_MASTER* m_Master;
wxString m_debugSpacer; ///< Used to give identation space wxString m_debugSpacer; ///< Used to give identation space
int m_counter_DEF_GROUP; ///< Counts the number of DEF * GROUPS used
int m_counter_USE_GROUP; ///< Counts the number of USE * used, in the end, if m_counter_DEF_GROUP > 0 and m_counter_USE_GROUP == 0 then it will add the first group with childs
}; };
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <common.h> #include <common.h>
#include <macros.h> #include <macros.h>
#include <base_struct.h> #include <base_struct.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
#include <vector> #include <vector>
#include <kicad_string.h> #include <kicad_string.h>
......
...@@ -59,6 +59,8 @@ VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser ) ...@@ -59,6 +59,8 @@ VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser )
m_normalPerVertex = true; m_normalPerVertex = true;
colorPerVertex = true; colorPerVertex = true;
m_debugSpacer = ""; m_debugSpacer = "";
m_counter_DEF_GROUP = 0;
m_counter_USE_GROUP = 0;
} }
...@@ -263,6 +265,35 @@ int VRML2_MODEL_PARSER::loadFileModel( S3D_MESH *aTransformationModel ) ...@@ -263,6 +265,35 @@ int VRML2_MODEL_PARSER::loadFileModel( S3D_MESH *aTransformationModel )
} }
} }
// There are VRML2 files, as an example, exported by:
// "Generated by TraceParts CAD VRML Translator" that define the group (DEF * GROUP)
// but don't use it in the end, so force it to add the DEF GROUP
if( ( m_counter_DEF_GROUP > 0 ) && (m_counter_USE_GROUP == 0 ) )
{
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "loadFileModel: groups defined with DEF * GROUP but not used with USE, forcing add it..." ) );
if( m_defGroupMap.size() > 0 )
{
for( VRML2_DEF_GROUP_MAP::iterator groupIt = m_defGroupMap.begin(); groupIt!=m_defGroupMap.end(); ++groupIt )
{
S3D_MESH* ptrModel = groupIt->second;
if( ((ptrModel->m_Point.size() == 0) || (ptrModel->m_CoordIndex.size() == 0)) &&
(ptrModel->childs.size() == 0) )
{
// Skip this because dont have data to add
continue;
}
else
{
m_ModelParser->childs.push_back( ptrModel );
}
}
}
}
debug_exit(); debug_exit();
return 0; return 0;
} }
...@@ -508,6 +539,9 @@ int VRML2_MODEL_PARSER::read_Transform() ...@@ -508,6 +539,9 @@ int VRML2_MODEL_PARSER::read_Transform()
} }
else else
{ {
m_counter_USE_GROUP++;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: USE %s Add child model with %lu points, %lu coordIndex, %lu childs." ), wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: USE %s Add child model with %lu points, %lu coordIndex, %lu childs." ),
useLabel, useLabel,
ptrModel->m_Point.size(), ptrModel->m_Point.size(),
...@@ -784,6 +818,8 @@ int VRML2_MODEL_PARSER::read_DEF() ...@@ -784,6 +818,8 @@ int VRML2_MODEL_PARSER::read_DEF()
// It will be the same as read a new Transform // It will be the same as read a new Transform
if( read_Transform() == 0 ) if( read_Transform() == 0 )
{ {
m_counter_DEF_GROUP++;
std::string groupName = tagName; std::string groupName = tagName;
m_defGroupMap[groupName] = new_mesh_model; m_defGroupMap[groupName] = new_mesh_model;
...@@ -1024,17 +1060,26 @@ int VRML2_MODEL_PARSER::read_appearance() ...@@ -1024,17 +1060,26 @@ int VRML2_MODEL_PARSER::read_appearance()
wxString mat_name; wxString mat_name;
mat_name = FROM_UTF8( text ); mat_name = FROM_UTF8( text );
bool found = false;
for( material = m_Master->m_Materials; material; material = material->Next() ) for( material = m_Master->m_Materials; material; material = material->Next() )
{ {
if( material->m_Name == mat_name ) if( material->m_Name == mat_name )
{ {
m_model->m_Materials = material; m_model->m_Materials = material;
debug_exit(); // We dont exit here, since it seems that VRML can have
return 0; // multiple material defined, so, it will copy the latest one that was defined.
found = true;
} }
} }
debug_exit();
if( found )
return 0;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_appearance error: material not found" ) ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_appearance error: material not found" ) );
return -1;
} }
// Exit loop with error // Exit loop with error
...@@ -1097,17 +1142,19 @@ int VRML2_MODEL_PARSER::read_material() ...@@ -1097,17 +1142,19 @@ int VRML2_MODEL_PARSER::read_material()
{ {
if( strcmp( text, "Material" ) == 0 ) if( strcmp( text, "Material" ) == 0 )
{ {
wxString mat_name; // Check if it is NULL, if not, it is because we come
material = new S3D_MATERIAL( m_Master, mat_name ); // from an appearance DEF and already have a pointer
m_Master->Insert( material ); if( m_model->m_Materials == NULL )
m_model->m_Materials = material;
if( strcmp( text, "Material" ) == 0 )
{ {
int ret = read_Material(); wxString mat_name;
debug_exit(); material = new S3D_MATERIAL( m_Master, mat_name );
return ret; m_Master->Insert( material );
m_model->m_Materials = material;
} }
int ret = read_Material();
debug_exit();
return ret;
} }
else if( strcmp( text, "DEF" ) == 0 ) else if( strcmp( text, "DEF" ) == 0 )
{ {
...@@ -1462,7 +1509,7 @@ int VRML2_MODEL_PARSER::read_coordIndex() ...@@ -1462,7 +1509,7 @@ int VRML2_MODEL_PARSER::read_coordIndex()
} }
} }
//wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_coordIndex m_CoordIndex.size: %u" ), (unsigned int)m_model->m_CoordIndex.size() ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_coordIndex m_CoordIndex.size: %lu" ), m_model->m_CoordIndex.size() );
debug_exit(); debug_exit();
return 0; return 0;
} }
...@@ -1518,11 +1565,10 @@ int VRML2_MODEL_PARSER::read_Normal() ...@@ -1518,11 +1565,10 @@ int VRML2_MODEL_PARSER::read_Normal()
if( *text == '}' ) if( *text == '}' )
{ {
// Debug // Debug
//if( m_normalPerVertex == false ) if( m_normalPerVertex == false )
// wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerFaceNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerFaceNormalsNormalized.size() ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerFaceNormalsNormalized.size: %lu" ), m_model->m_PerFaceNormalsNormalized.size() );
//else else
// wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerVertexNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerVertexNormalsNormalized.size() ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerVertexNormalsNormalized.size: %lu" ), m_model->m_PerVertexNormalsNormalized.size() );
debug_exit(); debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal exit" ) ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal exit" ) );
return 0; return 0;
...@@ -1562,9 +1608,9 @@ int VRML2_MODEL_PARSER::read_Coordinate() ...@@ -1562,9 +1608,9 @@ int VRML2_MODEL_PARSER::read_Coordinate()
if( *text == '}' ) if( *text == '}' )
{ {
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Coordinate m_Point.size: %lu" ), m_model->m_Point.size() );
debug_exit(); debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Coordinate exit" ) ); wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Coordinate exit" ) );
//wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Coordinate m_Point.size: %u" ), (unsigned int)m_model->m_Point.size() );
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment