Loading 3d-viewer/3d_aux.cpp +24 −6 Original line number Original line Diff line number Diff line Loading @@ -57,13 +57,31 @@ void S3D_MASTER::ObjectCoordsTo3DUnits( std::vector< S3D_VERTEX >& aVertices ) // adjust rotation // adjust rotation if( m_MatRotation.x ) if( m_MatRotation.x ) RotatePoint( &aVertices[ii].y, &aVertices[ii].z, m_MatRotation.x * 10 ); { double a = aVertices[ii].y; double b = aVertices[ii].z; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].y = (float)a; aVertices[ii].z = (float)b; } if( m_MatRotation.y ) if( m_MatRotation.y ) RotatePoint( &aVertices[ii].z, &aVertices[ii].x, m_MatRotation.y * 10 ); { double a = aVertices[ii].z; double b = aVertices[ii].x; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].z = (float)a; aVertices[ii].x = (float)b; } if( m_MatRotation.z ) if( m_MatRotation.z ) RotatePoint( &aVertices[ii].x, &aVertices[ii].y, m_MatRotation.z * 10 ); { double a = aVertices[ii].x; double b = aVertices[ii].y; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].x = (float)a; aVertices[ii].y = (float)b; } /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ #define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) Loading 3d-viewer/3d_canvas.cpp +51 −56 Original line number Original line Diff line number Diff line Loading @@ -16,17 +16,23 @@ #include <gestfich.h> #include <gestfich.h> #ifdef __WINDOWS__ #include <GL/glew.h> // must be included before gl.h #endif #include <3d_viewer.h> #include <3d_viewer.h> #include <3d_canvas.h> #include <3d_canvas.h> #include <info3d_visu.h> #include <info3d_visu.h> #include <trackball.h> #include <trackball.h> #include <3d_viewer_id.h> #include <3d_viewer_id.h> #include <textures/text_silk.c> #include <textures/text_pcb.c> // ----------------- // ----------------- // helper function (from wxWidgets, opengl/cube.cpp sample // helper function (from wxWidgets, opengl/cube.cpp sample // ----------------- // ----------------- void CheckGLError() void CheckGLError(const char *aFileName, int aLineNumber) { { GLenum errLast = GL_NO_ERROR; GLenum errLast = GL_NO_ERROR; Loading @@ -47,7 +53,7 @@ void CheckGLError() errLast = err; errLast = err; wxLogError(wxT("OpenGL error %d"), err); wxLogError( wxT( "OpenGL error %d\nAt: %s, line: %d" ), err, aFileName, aLineNumber ); } } } } Loading Loading @@ -78,6 +84,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList ) : wxFULL_REPAINT_ON_RESIZE ) wxFULL_REPAINT_ON_RESIZE ) { { m_init = false; m_init = false; m_shadow_init = false; // Clear all gl list identifiers: // Clear all gl list identifiers: for( int ii = GL_ID_BEGIN; ii < GL_ID_END; ii++ ) for( int ii = GL_ID_BEGIN; ii < GL_ID_END; ii++ ) Loading Loading @@ -490,15 +497,46 @@ void EDA_3D_CANVAS::OnEraseBackground( wxEraseEvent& event ) // Do nothing, to avoid flashing. // Do nothing, to avoid flashing. } } typedef struct s_sImage { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ unsigned char pixel_data[64 * 64 * 4 + 1]; }tsImage; GLuint load_and_generate_texture( tsImage *image ) { GLuint texture; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glPixelStorei (GL_PACK_ALIGNMENT, 1); glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, image->width, image->height, GL_RGBA, GL_UNSIGNED_BYTE, image->pixel_data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); return texture; } /* Initialize broad parameters for OpenGL */ /* Initialize broad parameters for OpenGL */ void EDA_3D_CANVAS::InitGL() void EDA_3D_CANVAS::InitGL() { { wxSize size = GetClientSize(); if( !m_init ) if( !m_init ) { { m_init = true; m_init = true; m_text_pcb = load_and_generate_texture( (tsImage *)&text_pcb ); m_text_silk = load_and_generate_texture( (tsImage *)&text_silk ); g_Parm_3D_Visu.m_Zoom = 1.0; g_Parm_3D_Visu.m_Zoom = 1.0; m_ZBottom = 1.0; m_ZBottom = 1.0; m_ZTop = 10.0; m_ZTop = 10.0; Loading @@ -513,7 +551,7 @@ void EDA_3D_CANVAS::InitGL() glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); // speedups // speedups glEnable( GL_DITHER ); //glEnable( GL_DITHER ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); Loading @@ -522,51 +560,6 @@ void EDA_3D_CANVAS::InitGL() glEnable( GL_BLEND ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } } // set viewing projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE ) g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) { // OrthoReductionFactor is chosen so as to provide roughly the same size as // Perspective View const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom; // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 10 ); } else { // Ratio width / height of the window display double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 ); } // position viewer glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0F, 0.0F, -( m_ZBottom + m_ZTop) / 2 ); // clear color and depth buffers glClearColor( g_Parm_3D_Visu.m_BgColor.m_Red, g_Parm_3D_Visu.m_BgColor.m_Green, g_Parm_3D_Visu.m_BgColor.m_Blue, 1 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Setup light sources: SetLights(); CheckGLError(); } } Loading @@ -578,16 +571,19 @@ void EDA_3D_CANVAS::SetLights() /* set viewing projection */ /* set viewing projection */ light_color[3] = 1.0; light_color[3] = 1.0; GLfloat Z_axis_pos[4] = { 0.0, 0.0, 3.0, 0.0 }; GLfloat Z_axis_pos[4] = { 0.0, 0.0, 30.0, 0.0 }; GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -3.0, 0.5 }; GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -30.0, 0.5 }; /* activate light */ /* activate light */ light = 1.0; light = 1.0; light_color[0] = light_color[1] = light_color[2] = light; light_color[0] = light_color[1] = light_color[2] = light; glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos ); glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color ); light = 0.3; light_color[0] = light_color[1] = light_color[2] = light; light_color[0] = 0.3; light_color[1] = 0.3; light_color[2] = 0.4; glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos ); glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos ); glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color ); glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color ); glEnable( GL_LIGHT0 ); // White spot on Z axis glEnable( GL_LIGHT0 ); // White spot on Z axis Loading Loading @@ -654,7 +650,6 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) viewport.x, viewport.y, viewport.x, viewport.y, GL_ALPHA, GL_UNSIGNED_BYTE, alphabuffer ); GL_ALPHA, GL_UNSIGNED_BYTE, alphabuffer ); image.SetData( pixelbuffer ); image.SetData( pixelbuffer ); image.SetAlpha( alphabuffer ); image.SetAlpha( alphabuffer ); image = image.Mirror( false ); image = image.Mirror( false ); Loading 3d-viewer/3d_canvas.h +37 −6 Original line number Original line Diff line number Diff line Loading @@ -43,10 +43,11 @@ #endif #endif #include <3d_struct.h> #include <3d_struct.h> #include <convert_basic_shapes_to_polygon.h> class BOARD_DESIGN_SETTINGS; class BOARD_DESIGN_SETTINGS; class EDA_3D_FRAME; class EDA_3D_FRAME; class S3D_VERTEX; class VIA; class VIA; class D_PAD; class D_PAD; Loading @@ -61,8 +62,14 @@ enum GL_LIST_ID GL_ID_BOARD, // List id for copper layers GL_ID_BOARD, // List id for copper layers GL_ID_TECH_LAYERS, // List id for non copper layers (masks...) GL_ID_TECH_LAYERS, // List id for non copper layers (masks...) GL_ID_AUX_LAYERS, // List id for user layers (draw, eco, comment) GL_ID_AUX_LAYERS, // List id for user layers (draw, eco, comment) GL_ID_3DSHAPES_SOLID, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_SOLID_FRONT, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_TRANSP, // List id for 3D shapes, transparent entities GL_ID_3DSHAPES_TRANSP_FRONT,// List id for 3D shapes, transparent entities GL_ID_3DSHAPES_SOLID_BACK, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_TRANSP_BACK,// List id for 3D shapes, transparent entities GL_ID_SHADOW_FRONT, GL_ID_SHADOW_BACK, GL_ID_SHADOW_BOARD, GL_ID_BODY, // Body only list GL_ID_END GL_ID_END }; }; Loading @@ -76,6 +83,16 @@ private: double m_ZBottom; // position of the back layer double m_ZBottom; // position of the back layer double m_ZTop; // position of the front layer double m_ZTop; // position of the front layer GLuint m_text_pcb; GLuint m_text_silk; bool m_shadow_init; GLuint m_text_fake_shadow_front; GLuint m_text_fake_shadow_back; GLuint m_text_fake_shadow_board; void Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, GLuint aTexture_size, bool aDraw_body, int aBlurPasses ); public: public: EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); ~EDA_3D_CANVAS(); ~EDA_3D_CANVAS(); Loading Loading @@ -122,6 +139,9 @@ public: m_draw3dOffset.x = aPosX; m_draw3dOffset.x = aPosX; m_draw3dOffset.y = aPosY; m_draw3dOffset.y = aPosY; } } void SetGLTechLayersColor( LAYER_NUM aLayer ); void SetGLCopperColor(); void SetGLEpoxyColor( double aTransparency = 1.0 ); /** /** * Function BuildBoard3DView * Function BuildBoard3DView Loading @@ -129,7 +149,7 @@ public: * Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers. * Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers. * 3D footprint shapes, tech layers and aux layers are not on this list * 3D footprint shapes, tech layers and aux layers are not on this list */ */ void BuildBoard3DView(); void BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList); /** /** * Function BuildTechLayers3DView * Function BuildTechLayers3DView Loading @@ -138,6 +158,12 @@ public: */ */ void BuildTechLayers3DView(); void BuildTechLayers3DView(); /** * Function BuildShadowList * Called by CreateDrawGL_List() */ void BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ); /** /** * Function BuildFootprintShape3DList * Function BuildFootprintShape3DList * Called by CreateDrawGL_List() * Called by CreateDrawGL_List() Loading @@ -148,7 +174,8 @@ public: * which need to be drawn after all other items * which need to be drawn after all other items */ */ void BuildFootprintShape3DList( GLuint aOpaqueList, void BuildFootprintShape3DList( GLuint aOpaqueList, GLuint aTransparentList); GLuint aTransparentList, bool aSideToLoad ); /** /** * Function BuildBoard3DAuxLayers * Function BuildBoard3DAuxLayers * Called by CreateDrawGL_List() * Called by CreateDrawGL_List() Loading @@ -163,7 +190,11 @@ public: void Draw3DViaHole( const VIA * aVia ); void Draw3DViaHole( const VIA * aVia ); void Draw3DPadHole( const D_PAD * aPad ); void Draw3DPadHole( const D_PAD * aPad ); void GenerateFakeShadowsTextures(); DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE() }; }; void CheckGLError(const char *aFileName, int aLineNumber); #endif /* _3D_CANVAS_H_ */ #endif /* _3D_CANVAS_H_ */ 3d-viewer/3d_class.cpp +11 −31 Original line number Original line Diff line number Diff line Loading @@ -30,36 +30,6 @@ #include <3d_viewer.h> #include <3d_viewer.h> S3D_MATERIAL::S3D_MATERIAL( S3D_MASTER* father, const wxString& name ) : EDA_ITEM( father, NOT_USED ) { m_DiffuseColor.x = m_DiffuseColor.y = m_DiffuseColor.z = 1.0; m_SpecularColor.x = m_SpecularColor.y = m_SpecularColor.z = 1.0; m_AmbientIntensity = 1.0; m_Transparency = 0.0; m_Shininess = 1.0; m_Name = name; } void S3D_MATERIAL::SetMaterial() { S3D_MASTER * s3dParent = (S3D_MASTER *) GetParent(); s3dParent->SetLastTransparency( m_Transparency ); if( ! s3dParent->IsOpenGlAllowed() ) return; glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColor4f( m_DiffuseColor.x * m_AmbientIntensity, m_DiffuseColor.y * m_AmbientIntensity, m_DiffuseColor.z * m_AmbientIntensity, 1.0 - m_Transparency ); #if 0 glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR ); glColor3f( m_SpecularColor.x, m_SpecularColor.y, m_SpecularColor.z ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); #endif } bool S3D_MASTER::IsOpenGlAllowed() bool S3D_MASTER::IsOpenGlAllowed() { { Loading @@ -68,9 +38,12 @@ bool S3D_MASTER::IsOpenGlAllowed() if( m_lastTransparency == 0.0 ) if( m_lastTransparency == 0.0 ) return true; return true; } } if( m_loadTransparentObjects ) // return true for transparent objects only if( m_loadTransparentObjects ) // return true for transparent objects only { if( m_lastTransparency != 0.0 ) if( m_lastTransparency != 0.0 ) return true; return true; } return false; return false; } } Loading Loading @@ -102,6 +75,13 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) : m_3D_Drawings = NULL; m_3D_Drawings = NULL; m_Materials = NULL; m_Materials = NULL; m_ShapeType = FILE3D_NONE; m_ShapeType = FILE3D_NONE; m_use_modelfile_diffuseColor = true; m_use_modelfile_emissiveColor = false; m_use_modelfile_specularColor = false; m_use_modelfile_ambientIntensity = false; m_use_modelfile_transparency = true; m_use_modelfile_shininess = false; } } Loading Loading
3d-viewer/3d_aux.cpp +24 −6 Original line number Original line Diff line number Diff line Loading @@ -57,13 +57,31 @@ void S3D_MASTER::ObjectCoordsTo3DUnits( std::vector< S3D_VERTEX >& aVertices ) // adjust rotation // adjust rotation if( m_MatRotation.x ) if( m_MatRotation.x ) RotatePoint( &aVertices[ii].y, &aVertices[ii].z, m_MatRotation.x * 10 ); { double a = aVertices[ii].y; double b = aVertices[ii].z; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].y = (float)a; aVertices[ii].z = (float)b; } if( m_MatRotation.y ) if( m_MatRotation.y ) RotatePoint( &aVertices[ii].z, &aVertices[ii].x, m_MatRotation.y * 10 ); { double a = aVertices[ii].z; double b = aVertices[ii].x; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].z = (float)a; aVertices[ii].x = (float)b; } if( m_MatRotation.z ) if( m_MatRotation.z ) RotatePoint( &aVertices[ii].x, &aVertices[ii].y, m_MatRotation.z * 10 ); { double a = aVertices[ii].x; double b = aVertices[ii].y; RotatePoint( &a, &b, m_MatRotation.x * 10 ); aVertices[ii].x = (float)a; aVertices[ii].y = (float)b; } /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ #define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) Loading
3d-viewer/3d_canvas.cpp +51 −56 Original line number Original line Diff line number Diff line Loading @@ -16,17 +16,23 @@ #include <gestfich.h> #include <gestfich.h> #ifdef __WINDOWS__ #include <GL/glew.h> // must be included before gl.h #endif #include <3d_viewer.h> #include <3d_viewer.h> #include <3d_canvas.h> #include <3d_canvas.h> #include <info3d_visu.h> #include <info3d_visu.h> #include <trackball.h> #include <trackball.h> #include <3d_viewer_id.h> #include <3d_viewer_id.h> #include <textures/text_silk.c> #include <textures/text_pcb.c> // ----------------- // ----------------- // helper function (from wxWidgets, opengl/cube.cpp sample // helper function (from wxWidgets, opengl/cube.cpp sample // ----------------- // ----------------- void CheckGLError() void CheckGLError(const char *aFileName, int aLineNumber) { { GLenum errLast = GL_NO_ERROR; GLenum errLast = GL_NO_ERROR; Loading @@ -47,7 +53,7 @@ void CheckGLError() errLast = err; errLast = err; wxLogError(wxT("OpenGL error %d"), err); wxLogError( wxT( "OpenGL error %d\nAt: %s, line: %d" ), err, aFileName, aLineNumber ); } } } } Loading Loading @@ -78,6 +84,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList ) : wxFULL_REPAINT_ON_RESIZE ) wxFULL_REPAINT_ON_RESIZE ) { { m_init = false; m_init = false; m_shadow_init = false; // Clear all gl list identifiers: // Clear all gl list identifiers: for( int ii = GL_ID_BEGIN; ii < GL_ID_END; ii++ ) for( int ii = GL_ID_BEGIN; ii < GL_ID_END; ii++ ) Loading Loading @@ -490,15 +497,46 @@ void EDA_3D_CANVAS::OnEraseBackground( wxEraseEvent& event ) // Do nothing, to avoid flashing. // Do nothing, to avoid flashing. } } typedef struct s_sImage { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ unsigned char pixel_data[64 * 64 * 4 + 1]; }tsImage; GLuint load_and_generate_texture( tsImage *image ) { GLuint texture; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glPixelStorei (GL_PACK_ALIGNMENT, 1); glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, image->width, image->height, GL_RGBA, GL_UNSIGNED_BYTE, image->pixel_data ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); return texture; } /* Initialize broad parameters for OpenGL */ /* Initialize broad parameters for OpenGL */ void EDA_3D_CANVAS::InitGL() void EDA_3D_CANVAS::InitGL() { { wxSize size = GetClientSize(); if( !m_init ) if( !m_init ) { { m_init = true; m_init = true; m_text_pcb = load_and_generate_texture( (tsImage *)&text_pcb ); m_text_silk = load_and_generate_texture( (tsImage *)&text_silk ); g_Parm_3D_Visu.m_Zoom = 1.0; g_Parm_3D_Visu.m_Zoom = 1.0; m_ZBottom = 1.0; m_ZBottom = 1.0; m_ZTop = 10.0; m_ZTop = 10.0; Loading @@ -513,7 +551,7 @@ void EDA_3D_CANVAS::InitGL() glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); // speedups // speedups glEnable( GL_DITHER ); //glEnable( GL_DITHER ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); Loading @@ -522,51 +560,6 @@ void EDA_3D_CANVAS::InitGL() glEnable( GL_BLEND ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } } // set viewing projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE ) g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) { // OrthoReductionFactor is chosen so as to provide roughly the same size as // Perspective View const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom; // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 10 ); } else { // Ratio width / height of the window display double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 ); } // position viewer glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0F, 0.0F, -( m_ZBottom + m_ZTop) / 2 ); // clear color and depth buffers glClearColor( g_Parm_3D_Visu.m_BgColor.m_Red, g_Parm_3D_Visu.m_BgColor.m_Green, g_Parm_3D_Visu.m_BgColor.m_Blue, 1 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Setup light sources: SetLights(); CheckGLError(); } } Loading @@ -578,16 +571,19 @@ void EDA_3D_CANVAS::SetLights() /* set viewing projection */ /* set viewing projection */ light_color[3] = 1.0; light_color[3] = 1.0; GLfloat Z_axis_pos[4] = { 0.0, 0.0, 3.0, 0.0 }; GLfloat Z_axis_pos[4] = { 0.0, 0.0, 30.0, 0.0 }; GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -3.0, 0.5 }; GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -30.0, 0.5 }; /* activate light */ /* activate light */ light = 1.0; light = 1.0; light_color[0] = light_color[1] = light_color[2] = light; light_color[0] = light_color[1] = light_color[2] = light; glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos ); glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color ); light = 0.3; light_color[0] = light_color[1] = light_color[2] = light; light_color[0] = 0.3; light_color[1] = 0.3; light_color[2] = 0.4; glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos ); glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos ); glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color ); glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color ); glEnable( GL_LIGHT0 ); // White spot on Z axis glEnable( GL_LIGHT0 ); // White spot on Z axis Loading Loading @@ -654,7 +650,6 @@ void EDA_3D_CANVAS::TakeScreenshot( wxCommandEvent& event ) viewport.x, viewport.y, viewport.x, viewport.y, GL_ALPHA, GL_UNSIGNED_BYTE, alphabuffer ); GL_ALPHA, GL_UNSIGNED_BYTE, alphabuffer ); image.SetData( pixelbuffer ); image.SetData( pixelbuffer ); image.SetAlpha( alphabuffer ); image.SetAlpha( alphabuffer ); image = image.Mirror( false ); image = image.Mirror( false ); Loading
3d-viewer/3d_canvas.h +37 −6 Original line number Original line Diff line number Diff line Loading @@ -43,10 +43,11 @@ #endif #endif #include <3d_struct.h> #include <3d_struct.h> #include <convert_basic_shapes_to_polygon.h> class BOARD_DESIGN_SETTINGS; class BOARD_DESIGN_SETTINGS; class EDA_3D_FRAME; class EDA_3D_FRAME; class S3D_VERTEX; class VIA; class VIA; class D_PAD; class D_PAD; Loading @@ -61,8 +62,14 @@ enum GL_LIST_ID GL_ID_BOARD, // List id for copper layers GL_ID_BOARD, // List id for copper layers GL_ID_TECH_LAYERS, // List id for non copper layers (masks...) GL_ID_TECH_LAYERS, // List id for non copper layers (masks...) GL_ID_AUX_LAYERS, // List id for user layers (draw, eco, comment) GL_ID_AUX_LAYERS, // List id for user layers (draw, eco, comment) GL_ID_3DSHAPES_SOLID, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_SOLID_FRONT, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_TRANSP, // List id for 3D shapes, transparent entities GL_ID_3DSHAPES_TRANSP_FRONT,// List id for 3D shapes, transparent entities GL_ID_3DSHAPES_SOLID_BACK, // List id for 3D shapes, non transparent entities GL_ID_3DSHAPES_TRANSP_BACK,// List id for 3D shapes, transparent entities GL_ID_SHADOW_FRONT, GL_ID_SHADOW_BACK, GL_ID_SHADOW_BOARD, GL_ID_BODY, // Body only list GL_ID_END GL_ID_END }; }; Loading @@ -76,6 +83,16 @@ private: double m_ZBottom; // position of the back layer double m_ZBottom; // position of the back layer double m_ZTop; // position of the front layer double m_ZTop; // position of the front layer GLuint m_text_pcb; GLuint m_text_silk; bool m_shadow_init; GLuint m_text_fake_shadow_front; GLuint m_text_fake_shadow_back; GLuint m_text_fake_shadow_board; void Create_and_Render_Shadow_Buffer( GLuint *aDst_gl_texture, GLuint aTexture_size, bool aDraw_body, int aBlurPasses ); public: public: EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); ~EDA_3D_CANVAS(); ~EDA_3D_CANVAS(); Loading Loading @@ -122,6 +139,9 @@ public: m_draw3dOffset.x = aPosX; m_draw3dOffset.x = aPosX; m_draw3dOffset.y = aPosY; m_draw3dOffset.y = aPosY; } } void SetGLTechLayersColor( LAYER_NUM aLayer ); void SetGLCopperColor(); void SetGLEpoxyColor( double aTransparency = 1.0 ); /** /** * Function BuildBoard3DView * Function BuildBoard3DView Loading @@ -129,7 +149,7 @@ public: * Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers. * Populates the OpenGL GL_ID_BOARD draw list with board items only on copper layers. * 3D footprint shapes, tech layers and aux layers are not on this list * 3D footprint shapes, tech layers and aux layers are not on this list */ */ void BuildBoard3DView(); void BuildBoard3DView(GLuint aBoardList, GLuint aBodyOnlyList); /** /** * Function BuildTechLayers3DView * Function BuildTechLayers3DView Loading @@ -138,6 +158,12 @@ public: */ */ void BuildTechLayers3DView(); void BuildTechLayers3DView(); /** * Function BuildShadowList * Called by CreateDrawGL_List() */ void BuildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList ); /** /** * Function BuildFootprintShape3DList * Function BuildFootprintShape3DList * Called by CreateDrawGL_List() * Called by CreateDrawGL_List() Loading @@ -148,7 +174,8 @@ public: * which need to be drawn after all other items * which need to be drawn after all other items */ */ void BuildFootprintShape3DList( GLuint aOpaqueList, void BuildFootprintShape3DList( GLuint aOpaqueList, GLuint aTransparentList); GLuint aTransparentList, bool aSideToLoad ); /** /** * Function BuildBoard3DAuxLayers * Function BuildBoard3DAuxLayers * Called by CreateDrawGL_List() * Called by CreateDrawGL_List() Loading @@ -163,7 +190,11 @@ public: void Draw3DViaHole( const VIA * aVia ); void Draw3DViaHole( const VIA * aVia ); void Draw3DPadHole( const D_PAD * aPad ); void Draw3DPadHole( const D_PAD * aPad ); void GenerateFakeShadowsTextures(); DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE() }; }; void CheckGLError(const char *aFileName, int aLineNumber); #endif /* _3D_CANVAS_H_ */ #endif /* _3D_CANVAS_H_ */
3d-viewer/3d_class.cpp +11 −31 Original line number Original line Diff line number Diff line Loading @@ -30,36 +30,6 @@ #include <3d_viewer.h> #include <3d_viewer.h> S3D_MATERIAL::S3D_MATERIAL( S3D_MASTER* father, const wxString& name ) : EDA_ITEM( father, NOT_USED ) { m_DiffuseColor.x = m_DiffuseColor.y = m_DiffuseColor.z = 1.0; m_SpecularColor.x = m_SpecularColor.y = m_SpecularColor.z = 1.0; m_AmbientIntensity = 1.0; m_Transparency = 0.0; m_Shininess = 1.0; m_Name = name; } void S3D_MATERIAL::SetMaterial() { S3D_MASTER * s3dParent = (S3D_MASTER *) GetParent(); s3dParent->SetLastTransparency( m_Transparency ); if( ! s3dParent->IsOpenGlAllowed() ) return; glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColor4f( m_DiffuseColor.x * m_AmbientIntensity, m_DiffuseColor.y * m_AmbientIntensity, m_DiffuseColor.z * m_AmbientIntensity, 1.0 - m_Transparency ); #if 0 glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR ); glColor3f( m_SpecularColor.x, m_SpecularColor.y, m_SpecularColor.z ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); #endif } bool S3D_MASTER::IsOpenGlAllowed() bool S3D_MASTER::IsOpenGlAllowed() { { Loading @@ -68,9 +38,12 @@ bool S3D_MASTER::IsOpenGlAllowed() if( m_lastTransparency == 0.0 ) if( m_lastTransparency == 0.0 ) return true; return true; } } if( m_loadTransparentObjects ) // return true for transparent objects only if( m_loadTransparentObjects ) // return true for transparent objects only { if( m_lastTransparency != 0.0 ) if( m_lastTransparency != 0.0 ) return true; return true; } return false; return false; } } Loading Loading @@ -102,6 +75,13 @@ S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) : m_3D_Drawings = NULL; m_3D_Drawings = NULL; m_Materials = NULL; m_Materials = NULL; m_ShapeType = FILE3D_NONE; m_ShapeType = FILE3D_NONE; m_use_modelfile_diffuseColor = true; m_use_modelfile_emissiveColor = false; m_use_modelfile_specularColor = false; m_use_modelfile_ambientIntensity = false; m_use_modelfile_transparency = true; m_use_modelfile_shininess = false; } } Loading