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 @@
#include <class_pcb_text.h>
#include <colors_selection.h>
#include <convert_basic_shapes_to_polygon.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/gtc/matrix_transform.hpp>
#include <gal/opengl/opengl_compositor.h>
#ifdef __WINDOWS__
......@@ -1401,13 +1402,13 @@ void EDA_3D_CANVAS::calcBBox()
if( module->GetOrientation() )
fullTransformMatrix = glm::rotate( fullTransformMatrix,
(float)(module->GetOrientation() / 10.0f),
glm::radians( (float)(module->GetOrientation() / 10.0f) ),
S3D_VERTEX( 0.0f, 0.0f, 1.0f ) );
if( module->IsFlipped() )
{
fullTransformMatrix = glm::rotate( fullTransformMatrix, 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, 1.0f, 0.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
......
......@@ -31,6 +31,7 @@
#include <common.h>
#include <base_struct.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp>
class S3D_MASTER;
......
This diff is collapsed.
......@@ -31,6 +31,7 @@
#define __3D_MESH_MODEL_H__
#include <vector>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp>
#include "3d_struct.h"
#include "3d_material.h"
......@@ -55,6 +56,7 @@ public:
std::vector< S3D_VERTEX > m_Point;
std::vector< std::vector<int> > m_CoordIndex;
std::vector< std::vector<int> > m_NormalIndex;
std::vector< S3D_VERTEX > m_PerFaceColor;
std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized;
std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized;
std::vector< int > m_MaterialIndex;
......
......@@ -33,6 +33,7 @@
#include <macros.h>
#include <kicad_string.h>
#include <pgm_base.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/gtc/matrix_transform.hpp>
#include <3d_viewer.h>
#include <info3d_visu.h>
......@@ -176,11 +177,11 @@ void S3D_MASTER::calcBBox()
m_MatPosition.z * SCALE_3D_CONV) );
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 )
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 )
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 ) );
......
......@@ -178,7 +178,7 @@ void EDA_3D_FRAME::CreateMenuBar()
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SMOOTH_NORMALS,
_( "Render Smooth Normals" ),
KiBitmap( green_xpm ), wxITEM_CHECK );
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_USE_MODEL_NORMALS,
_( "Use Model Normals" ),
KiBitmap( green_xpm ), wxITEM_CHECK );
......@@ -188,7 +188,7 @@ void EDA_3D_FRAME::CreateMenuBar()
KiBitmap( green_xpm ), wxITEM_CHECK );
AddMenuItem( renderOptionsMenu, ID_MENU3D_FL_RENDER_SHOW_MODEL_BBOX,
_( "Show Model Bouding Boxes" ),
_( "Show Model Bounding Boxes" ),
KiBitmap( green_xpm ), wxITEM_CHECK );
prefsMenu->AppendSeparator();
......
......@@ -29,6 +29,7 @@
#ifndef _3D_TYPES_H_
#define _3D_TYPES_H_
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp>
#include <base_units.h> // for IU_PER_MILS
......
......@@ -30,7 +30,7 @@
#ifndef CBBox_h
#define CBBox_h
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp>
#include <3d_types.h>
......
......@@ -219,6 +219,9 @@ private:
S3D_MODEL_PARSER* m_ModelParser;
S3D_MASTER* m_Master;
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 @@
#include <common.h>
#include <macros.h>
#include <base_struct.h>
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp>
#include <vector>
#include <kicad_string.h>
......
......@@ -59,6 +59,8 @@ VRML2_MODEL_PARSER::VRML2_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser )
m_normalPerVertex = true;
colorPerVertex = true;
m_debugSpacer = "";
m_counter_DEF_GROUP = 0;
m_counter_USE_GROUP = 0;
}
......@@ -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();
return 0;
}
......@@ -508,6 +539,9 @@ int VRML2_MODEL_PARSER::read_Transform()
}
else
{
m_counter_USE_GROUP++;
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Transform: USE %s Add child model with %lu points, %lu coordIndex, %lu childs." ),
useLabel,
ptrModel->m_Point.size(),
......@@ -784,6 +818,8 @@ int VRML2_MODEL_PARSER::read_DEF()
// It will be the same as read a new Transform
if( read_Transform() == 0 )
{
m_counter_DEF_GROUP++;
std::string groupName = tagName;
m_defGroupMap[groupName] = new_mesh_model;
......@@ -1024,17 +1060,26 @@ int VRML2_MODEL_PARSER::read_appearance()
wxString mat_name;
mat_name = FROM_UTF8( text );
bool found = false;
for( material = m_Master->m_Materials; material; material = material->Next() )
{
if( material->m_Name == mat_name )
{
m_model->m_Materials = material;
debug_exit();
return 0;
// We dont exit here, since it seems that VRML can have
// 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" ) );
return -1;
}
// Exit loop with error
......@@ -1097,17 +1142,19 @@ int VRML2_MODEL_PARSER::read_material()
{
if( strcmp( text, "Material" ) == 0 )
{
wxString mat_name;
material = new S3D_MATERIAL( m_Master, mat_name );
m_Master->Insert( material );
m_model->m_Materials = material;
if( strcmp( text, "Material" ) == 0 )
// Check if it is NULL, if not, it is because we come
// from an appearance DEF and already have a pointer
if( m_model->m_Materials == NULL )
{
int ret = read_Material();
debug_exit();
return ret;
wxString mat_name;
material = new S3D_MATERIAL( m_Master, mat_name );
m_Master->Insert( material );
m_model->m_Materials = material;
}
int ret = read_Material();
debug_exit();
return ret;
}
else if( strcmp( text, "DEF" ) == 0 )
{
......@@ -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();
return 0;
}
......@@ -1518,11 +1565,10 @@ int VRML2_MODEL_PARSER::read_Normal()
if( *text == '}' )
{
// Debug
//if( m_normalPerVertex == false )
// wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerFaceNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerFaceNormalsNormalized.size() );
//else
// wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerVertexNormalsNormalized.size: %u" ), (unsigned int)m_model->m_PerVertexNormalsNormalized.size() );
if( m_normalPerVertex == false )
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerFaceNormalsNormalized.size: %lu" ), m_model->m_PerFaceNormalsNormalized.size() );
else
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal m_PerVertexNormalsNormalized.size: %lu" ), m_model->m_PerVertexNormalsNormalized.size() );
debug_exit();
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Normal exit" ) );
return 0;
......@@ -1562,9 +1608,9 @@ int VRML2_MODEL_PARSER::read_Coordinate()
if( *text == '}' )
{
wxLogTrace( traceVrmlV2Parser, m_debugSpacer + wxT( "read_Coordinate m_Point.size: %lu" ), m_model->m_Point.size() );
debug_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;
}
......
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