2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-03-28 11:33:56 +00:00
|
|
|
* Copyright (C) 2014-2015 Mario Luzeiro <mrluzeiro@gmail.com>
|
2015-03-17 07:39:15 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-05-22 19:08:34 +00:00
|
|
|
/**
|
|
|
|
* @file 3d_draw.cpp
|
2015-03-28 11:33:56 +00:00
|
|
|
*
|
2013-05-03 17:51:10 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <pcbstruct.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-01-30 08:18:47 +00:00
|
|
|
#include <wxBasePcbFrame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <colors_selection.h>
|
2012-08-23 19:15:58 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2015-03-29 10:59:53 +00:00
|
|
|
#define GLM_FORCE_RADIANS
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
2015-03-28 11:33:56 +00:00
|
|
|
#include <gal/opengl/opengl_compositor.h>
|
2014-07-30 09:34:48 +00:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#include <GL/glew.h> // must be included before gl.h
|
|
|
|
#endif
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <3d_viewer.h>
|
2012-12-15 08:52:02 +00:00
|
|
|
#include <3d_canvas.h>
|
2012-08-11 12:52:13 +00:00
|
|
|
#include <info3d_visu.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trackball.h>
|
2012-08-26 13:59:55 +00:00
|
|
|
#include <3d_draw_basic_functions.h>
|
2015-12-08 22:58:36 +00:00
|
|
|
#include "3d_rendering/3d_render_ogl_legacy/ogl_legacy_utils.h"
|
2016-06-03 13:46:12 +00:00
|
|
|
#include <gl_context_mgr.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2016-05-30 06:31:32 +00:00
|
|
|
#include <cimage.h>
|
2015-04-14 15:12:35 +00:00
|
|
|
#include <reporter.h>
|
2015-03-15 15:51:56 +00:00
|
|
|
|
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
extern SHAPE_POLY_SET::POLYGON_MODE polygonsCalcMode;
|
2015-03-15 15:51:56 +00:00
|
|
|
|
2013-05-03 17:51:10 +00:00
|
|
|
/* returns the Z orientation parameter 1.0 or -1.0 for aLayer
|
|
|
|
* Z orientation is 1.0 for all layers but "back" layers:
|
2014-06-24 16:17:18 +00:00
|
|
|
* B_Cu , B_Adhes, B_Paste ), B_SilkS
|
2013-05-03 17:51:10 +00:00
|
|
|
* used to calculate the Z orientation parameter for glNormal3f
|
|
|
|
*/
|
2015-07-04 16:38:08 +00:00
|
|
|
GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
/**
|
|
|
|
* Class STATUS_TEXT_REPORTER
|
|
|
|
* is a wrapper for reporting to a wxString in a wxFrame status text.
|
|
|
|
*/
|
|
|
|
class STATUS_TEXT_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
wxFrame * m_frame;
|
|
|
|
int m_position;
|
|
|
|
bool m_hasMessage;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
STATUS_TEXT_REPORTER( wxFrame* aFrame, int aPosition = 0 ) :
|
|
|
|
REPORTER(),
|
|
|
|
m_frame( aFrame ), m_position( aPosition )
|
|
|
|
{
|
|
|
|
m_hasMessage = false;
|
|
|
|
}
|
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED )
|
2015-04-14 15:12:35 +00:00
|
|
|
{
|
|
|
|
if( !aText.IsEmpty() )
|
|
|
|
m_hasMessage = true;
|
|
|
|
|
|
|
|
m_frame->SetStatusText( aText, m_position );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasMessage() const { return m_hasMessage; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
void EDA_3D_CANVAS::create_and_render_shadow_buffer( GLuint *aDst_gl_texture,
|
2014-07-30 09:01:25 +00:00
|
|
|
GLuint aTexture_size, bool aDraw_body, int aBlurPasses )
|
|
|
|
{
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
glViewport( 0, 0, aTexture_size, aTexture_size);
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Render body and shapes
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
if( aDraw_body && m_glLists[GL_ID_BODY] )
|
2015-04-17 11:12:59 +00:00
|
|
|
glCallList( m_glLists[GL_ID_BODY] );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
if( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
|
|
|
|
glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Create and Initialize the float depth buffer
|
2015-03-15 15:51:56 +00:00
|
|
|
|
|
|
|
float *depthbufferFloat = (float*) malloc( aTexture_size * aTexture_size * sizeof(float) );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
for( unsigned int i = 0; i < (aTexture_size * aTexture_size); i++ )
|
|
|
|
depthbufferFloat[i] = 1.0f;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glPixelStorei( GL_PACK_ALIGNMENT, 4 );
|
2015-03-15 15:51:56 +00:00
|
|
|
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
|
2014-07-30 09:01:25 +00:00
|
|
|
glReadBuffer( GL_BACK_LEFT );
|
|
|
|
glReadPixels( 0, 0,
|
|
|
|
aTexture_size, aTexture_size,
|
|
|
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthbufferFloat );
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glGenTextures( 1, aDst_gl_texture );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, *aDst_gl_texture );
|
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
CIMAGE imgDepthBuffer( aTexture_size, aTexture_size );
|
|
|
|
CIMAGE imgDepthBufferAux( aTexture_size, aTexture_size );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
imgDepthBuffer.SetPixelsFromNormalizedFloat( depthbufferFloat );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
free( depthbufferFloat );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Debug texture image
|
|
|
|
//wxString filename;
|
2015-03-15 15:51:56 +00:00
|
|
|
//filename.Printf( "imgDepthBuffer_%04d", *aDst_gl_texture );
|
2015-03-28 11:33:56 +00:00
|
|
|
//imgDepthBuffer.SaveAsPNG( filename );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
while( aBlurPasses > 0 )
|
2015-03-15 15:51:56 +00:00
|
|
|
{
|
|
|
|
aBlurPasses--;
|
2015-03-28 11:33:56 +00:00
|
|
|
imgDepthBufferAux.EfxFilter( &imgDepthBuffer, FILTER_GAUSSIAN_BLUR );
|
|
|
|
imgDepthBuffer.EfxFilter( &imgDepthBufferAux, FILTER_GAUSSIAN_BLUR );
|
2015-03-15 15:51:56 +00:00
|
|
|
}
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Debug texture image
|
|
|
|
//filename.Printf( "imgDepthBuffer_blur%04d", *aDst_gl_texture );
|
|
|
|
//imgDepthBuffer.SaveAsPNG( filename );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
unsigned char *depthbufferRGBA = (unsigned char*) malloc( aTexture_size * aTexture_size * 4 );
|
|
|
|
unsigned char *pPixels = imgDepthBuffer.GetBuffer();
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Convert it to a RGBA buffer
|
|
|
|
for( unsigned int i = 0; i < (aTexture_size * aTexture_size); i++ )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
|
|
|
depthbufferRGBA[i * 4 + 0] = 0;
|
|
|
|
depthbufferRGBA[i * 4 + 1] = 0;
|
|
|
|
depthbufferRGBA[i * 4 + 2] = 0;
|
2015-03-28 11:33:56 +00:00
|
|
|
depthbufferRGBA[i * 4 + 3] = 255 - pPixels[i]; // Store in alpha channel the inversion of the image
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
|
|
|
|
|
|
|
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aTexture_size, aTexture_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, depthbufferRGBA );
|
|
|
|
|
|
|
|
free( depthbufferRGBA );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
/// Scale factor to make a bigger BBox in order to blur the texture and dont have artifacts in the edges
|
|
|
|
#define SHADOW_BOUNDING_BOX_SCALE 1.25f
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
void EDA_3D_CANVAS::generateFakeShadowsTextures( REPORTER* aErrorMessages, REPORTER* aActivity )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
|
|
|
if( m_shadow_init == true )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
// Init info 3d parameters and create gl lists:
|
2015-04-14 15:12:35 +00:00
|
|
|
CreateDrawGL_List( aErrorMessages, aActivity );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( unsigned strtime = GetRunningMicroSecs() );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
m_shadow_init = true;
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
glClearColor( 0, 0, 0, 1 );
|
|
|
|
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
2014-08-04 11:28:29 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
const float zDistMax = Millimeter2iu( 3.5 ) * GetPrm3DVisu().m_BiuTo3Dunits;
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
glOrtho( -GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
|
|
|
|
GetPrm3DVisu().m_BoardSize.x * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
|
|
|
|
-GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
|
|
|
|
GetPrm3DVisu().m_BoardSize.y * GetPrm3DVisu().m_BiuTo3Dunits / 2.0f,
|
2015-03-28 11:33:56 +00:00
|
|
|
0.0, zDistMax );
|
|
|
|
|
|
|
|
float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
// Render FRONT shadow
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
2015-03-28 11:33:56 +00:00
|
|
|
glTranslatef( 0.0f, 0.0f, zpos );
|
|
|
|
glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
|
|
|
|
// move the board in order to draw it with its center at 0,0 3D coordinates
|
|
|
|
glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
-GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
0.0f );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
create_and_render_shadow_buffer( &m_text_fake_shadow_front, 512, false, 1 );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
// Render BACK shadow
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
2015-03-28 11:33:56 +00:00
|
|
|
glTranslatef( 0.0f, 0.0f, fabs( zpos ) );
|
|
|
|
|
|
|
|
|
|
|
|
// move the board in order to draw it with its center at 0,0 3D coordinates
|
|
|
|
glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
-GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
0.0f );
|
|
|
|
|
|
|
|
create_and_render_shadow_buffer( &m_text_fake_shadow_back, 512, false, 1 );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Render ALL BOARD shadow
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
// Normalization scale to convert bouding box
|
|
|
|
// to normalize 3D units between -1.0 and +1.0
|
|
|
|
|
|
|
|
S3D_VERTEX v = m_fastAABBox_Shadow.Max() - m_fastAABBox_Shadow.Min();
|
|
|
|
float BoundingBoxBoardiuTo3Dunits = 2.0f / glm::max( v.x, v.y );
|
|
|
|
|
|
|
|
//float zDistance = (m_lightPos.z * zDistMax) / sqrt( (m_lightPos.z - m_fastAABBox_Shadow.Min().z) );
|
|
|
|
float zDistance = (m_lightPos.z - m_fastAABBox_Shadow.Min().z) / 3.0f;
|
|
|
|
|
|
|
|
glOrtho( -v.x * BoundingBoxBoardiuTo3Dunits / 2.0f,
|
|
|
|
v.x * BoundingBoxBoardiuTo3Dunits / 2.0f,
|
|
|
|
-v.y * BoundingBoxBoardiuTo3Dunits / 2.0f,
|
|
|
|
v.y * BoundingBoxBoardiuTo3Dunits / 2.0f,
|
|
|
|
0.0f, zDistance );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// fits the bouding box to scale this size
|
|
|
|
glScalef( BoundingBoxBoardiuTo3Dunits, BoundingBoxBoardiuTo3Dunits, 1.0f );
|
|
|
|
|
|
|
|
// Place the eye in the lowerpoint of boudingbox and turn arround and look up to the model
|
|
|
|
glTranslatef( 0.0f, 0.0f, m_fastAABBox_Shadow.Min().z );
|
|
|
|
glRotatef( 180.0, 0.0f, 1.0f, 0.0f );
|
|
|
|
|
|
|
|
// move the bouding box in order to draw it with its center at 0,0 3D coordinates
|
|
|
|
glTranslatef( -(m_fastAABBox_Shadow.Min().x + v.x / 2.0f), -(m_fastAABBox_Shadow.Min().y + v.y / 2.0f), 0.0f );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
create_and_render_shadow_buffer( &m_text_fake_shadow_board, 512, true, 10 );
|
|
|
|
|
|
|
|
DBG( printf( " generateFakeShadowsTextures total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-05 17:40:23 +00:00
|
|
|
void EDA_3D_CANVAS::Redraw()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-02-02 17:45:37 +00:00
|
|
|
// SwapBuffer requires the window to be shown before calling
|
2015-11-15 17:55:53 +00:00
|
|
|
if( !IsShownOnScreen() )
|
2011-01-29 10:19:54 +00:00
|
|
|
return;
|
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
wxString err_messages;
|
|
|
|
WX_STRING_REPORTER errorReporter( &err_messages );
|
|
|
|
STATUS_TEXT_REPORTER activityReporter( Parent(), 0 );
|
|
|
|
|
|
|
|
// Display build time at the end of build
|
|
|
|
unsigned strtime = GetRunningMicroSecs();
|
2015-03-16 17:39:35 +00:00
|
|
|
|
2016-06-13 14:43:33 +00:00
|
|
|
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
|
2009-08-04 18:21:32 +00:00
|
|
|
|
|
|
|
// Set the OpenGL viewport according to the client size of this canvas.
|
|
|
|
// This is done here rather than in a wxSizeEvent handler because our
|
|
|
|
// OpenGL rendering context (and thus viewport setting) is used with
|
|
|
|
// multiple canvases: If we updated the viewport in the wxSizeEvent
|
|
|
|
// handler, changing the size of one canvas causes a viewport setting that
|
|
|
|
// is wrong when next another canvas is repainted.
|
2014-07-30 09:01:25 +00:00
|
|
|
wxSize size = GetClientSize();
|
|
|
|
|
|
|
|
InitGL();
|
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
2015-04-14 15:12:35 +00:00
|
|
|
generateFakeShadowsTextures( &errorReporter, &activityReporter );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2016-06-03 13:46:12 +00:00
|
|
|
// *MUST* be called *after* GL_CONTEXT_MANAGER::LockCtx():
|
2014-07-30 09:01:25 +00:00
|
|
|
glViewport( 0, 0, size.x, size.y );
|
2009-08-04 18:21:32 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// clear color and depth buffers
|
|
|
|
glClearColor( 0.95, 0.95, 1.0, 1.0 );
|
|
|
|
glClearStencil( 0 );
|
|
|
|
glClearDepth( 1.0 );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
2015-03-16 17:39:35 +00:00
|
|
|
|
2015-03-10 20:15:41 +00:00
|
|
|
glShadeModel( GL_SMOOTH );
|
2015-03-16 17:39:35 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// Draw background
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glDisable( GL_LIGHTING );
|
|
|
|
glDisable( GL_COLOR_MATERIAL );
|
|
|
|
glDisable( GL_DEPTH_TEST );
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
// Draw the background ( rectangle with color gradient)
|
2014-07-30 09:01:25 +00:00
|
|
|
glBegin( GL_QUADS );
|
2014-08-20 17:53:09 +00:00
|
|
|
SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
|
2014-08-04 11:28:29 +00:00
|
|
|
glVertex2f( -1.0, 1.0 ); // Top left corner
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 );
|
2014-08-04 11:28:29 +00:00
|
|
|
glVertex2f( -1.0,-1.0 ); // bottom left corner
|
|
|
|
glVertex2f( 1.0,-1.0 ); // bottom right corner
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
|
2014-08-04 11:28:29 +00:00
|
|
|
glVertex2f( 1.0, 1.0 ); // top right corner
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
|
|
|
|
|
|
|
|
// set viewing projection
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
#define MAX_VIEW_ANGLE 160.0 / 45.0
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE )
|
|
|
|
GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
if( Parent()->ModeIsOrtho() )
|
|
|
|
{
|
|
|
|
// OrthoReductionFactor is chosen to provide roughly the same size as
|
|
|
|
// Perspective View
|
2014-08-20 17:53:09 +00:00
|
|
|
const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom;
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
// Initialize Projection Matrix for Ortographic View
|
|
|
|
glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
|
2014-08-19 14:51:15 +00:00
|
|
|
-size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ratio width / height of the window display
|
|
|
|
double ratio_HV = (double) size.x / size.y;
|
|
|
|
|
|
|
|
// Initialize Projection Matrix for Perspective View
|
2015-03-28 11:33:56 +00:00
|
|
|
gluPerspective( 45.0f * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// position viewer
|
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
glTranslatef( 0.0f, 0.0f, -(m_ZBottom + m_ZTop) / 2.0f );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
// Setup light sources:
|
|
|
|
SetLights();
|
|
|
|
|
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
glMatrixMode( GL_MODELVIEW ); // position viewer
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2012-02-02 17:45:37 +00:00
|
|
|
// transformations
|
2007-05-06 16:03:28 +00:00
|
|
|
GLfloat mat[4][4];
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Translate motion first, so rotations don't mess up the orientation...
|
2012-02-25 19:55:40 +00:00
|
|
|
glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F );
|
2008-03-03 08:00:26 +00:00
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
build_rotmatrix( mat, GetPrm3DVisu().m_Quat );
|
2007-05-06 16:03:28 +00:00
|
|
|
glMultMatrixf( &mat[0][0] );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 );
|
|
|
|
glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 );
|
|
|
|
glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] )
|
2015-04-14 15:12:35 +00:00
|
|
|
CreateDrawGL_List( &errorReporter, &activityReporter );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] )
|
2014-03-08 19:04:23 +00:00
|
|
|
glCallList( m_glLists[GL_ID_AXIS] );
|
|
|
|
|
|
|
|
// move the board in order to draw it with its center at 0,0 3D coordinates
|
2014-08-20 17:53:09 +00:00
|
|
|
glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
-GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
|
2015-03-28 11:33:56 +00:00
|
|
|
0.0f );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isEnabled( FL_MODULE ) )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
|
|
|
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
|
2015-04-14 15:12:35 +00:00
|
|
|
CreateDrawGL_List( &errorReporter, &activityReporter );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
glEnable( GL_LIGHTING );
|
|
|
|
|
2014-08-19 14:51:15 +00:00
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ) )
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
else
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
|
|
|
|
// Set material for the board
|
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
|
|
|
SetOpenGlDefaultMaterial();
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
//glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, FALSE );
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Board Body
|
|
|
|
|
|
|
|
GLint shininess_value = 32;
|
2015-11-29 06:56:27 +00:00
|
|
|
glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
|
2014-08-19 14:51:15 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( isEnabled( FL_SHOW_BOARD_BODY ) )
|
|
|
|
{
|
|
|
|
if( m_glLists[GL_ID_BODY] )
|
|
|
|
{
|
|
|
|
glCallList( m_glLists[GL_ID_BODY] );
|
|
|
|
}
|
|
|
|
}
|
2014-08-19 14:51:15 +00:00
|
|
|
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Board
|
2014-08-19 14:51:15 +00:00
|
|
|
|
2015-11-29 06:56:27 +00:00
|
|
|
// specify material parameters for the lighting model.
|
2015-03-28 11:33:56 +00:00
|
|
|
shininess_value = 52;
|
2015-11-29 06:56:27 +00:00
|
|
|
glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.20f,
|
|
|
|
GetPrm3DVisu().m_CopperColor.m_Green * 0.20f,
|
|
|
|
GetPrm3DVisu().m_CopperColor.m_Blue * 0.20f, 1.0f );
|
2014-08-19 14:51:15 +00:00
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x );
|
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
if( m_glLists[GL_ID_BOARD] )
|
|
|
|
{
|
|
|
|
glCallList( m_glLists[GL_ID_BOARD] );
|
|
|
|
}
|
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Tech layers
|
|
|
|
|
|
|
|
shininess_value = 32;
|
2015-11-29 06:56:27 +00:00
|
|
|
glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
glm::vec4 specularTech( 0.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specularTech.x );
|
2014-08-19 14:51:15 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
if( m_glLists[GL_ID_TECH_LAYERS] )
|
|
|
|
{
|
|
|
|
glCallList( m_glLists[GL_ID_TECH_LAYERS] );
|
|
|
|
}
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2015-07-24 10:23:34 +00:00
|
|
|
if( isEnabled( FL_COMMENTS ) || isEnabled( FL_ECO ) )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
|
|
|
if( ! m_glLists[GL_ID_AUX_LAYERS] )
|
2015-04-14 15:12:35 +00:00
|
|
|
CreateDrawGL_List( &errorReporter, &activityReporter );
|
2014-03-08 19:04:23 +00:00
|
|
|
|
|
|
|
glCallList( m_glLists[GL_ID_AUX_LAYERS] );
|
|
|
|
}
|
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
//glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, TRUE );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// Draw Component Shadow
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isEnabled( FL_MODULE ) && isRealisticMode() &&
|
|
|
|
isEnabled( FL_RENDER_SHADOWS ) )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
|
|
|
glEnable( GL_CULL_FACE );
|
|
|
|
glDisable( GL_DEPTH_TEST );
|
|
|
|
|
|
|
|
glEnable( GL_COLOR_MATERIAL ) ;
|
|
|
|
SetOpenGlDefaultMaterial();
|
2015-03-28 11:33:56 +00:00
|
|
|
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
|
|
|
if( m_glLists[GL_ID_SHADOW_FRONT] )
|
|
|
|
{
|
|
|
|
glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_front );
|
|
|
|
glCallList( m_glLists[GL_ID_SHADOW_FRONT] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_glLists[GL_ID_SHADOW_BACK] )
|
|
|
|
{
|
|
|
|
glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back );
|
|
|
|
glCallList( m_glLists[GL_ID_SHADOW_BACK] );
|
|
|
|
}
|
2015-03-28 11:33:56 +00:00
|
|
|
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
glDisable( GL_CULL_FACE );
|
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
2014-07-30 09:01:25 +00:00
|
|
|
SetOpenGlDefaultMaterial();
|
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
glDisable( GL_BLEND );
|
2014-07-30 09:01:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// Draw Solid Shapes
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isEnabled( FL_MODULE ) )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
|
2015-04-14 15:12:35 +00:00
|
|
|
CreateDrawGL_List( &errorReporter, &activityReporter );
|
2014-03-08 19:04:23 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] );
|
2014-03-18 10:31:13 +00:00
|
|
|
}
|
2014-03-08 19:04:23 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-03-18 10:31:13 +00:00
|
|
|
// Grid uses transparency: draw it after all objects
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2015-06-19 09:06:52 +00:00
|
|
|
if( isEnabled( FL_GRID ) )
|
|
|
|
{
|
|
|
|
if( ! m_glLists[GL_ID_GRID] )
|
|
|
|
CreateDrawGL_List( &errorReporter, &activityReporter );
|
|
|
|
|
2014-03-18 10:31:13 +00:00
|
|
|
glCallList( m_glLists[GL_ID_GRID] );
|
2015-06-19 09:06:52 +00:00
|
|
|
}
|
2014-03-18 10:31:13 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// Draw Board Shadow
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) )
|
2014-07-30 09:01:25 +00:00
|
|
|
{
|
|
|
|
if( m_glLists[GL_ID_SHADOW_BOARD] )
|
|
|
|
{
|
2015-03-15 15:51:56 +00:00
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
2015-03-29 16:13:58 +00:00
|
|
|
glColor4f( 1.0, 1.0, 1.0, 0.75f );
|
2014-07-30 09:01:25 +00:00
|
|
|
glEnable( GL_CULL_FACE );
|
|
|
|
glDisable( GL_COLOR_MATERIAL );
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_board );
|
|
|
|
glCallList( m_glLists[GL_ID_SHADOW_BOARD] );
|
|
|
|
glDisable( GL_CULL_FACE );
|
2015-03-28 11:33:56 +00:00
|
|
|
glDisable( GL_TEXTURE_2D );
|
2014-07-30 09:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-07 11:51:08 +00:00
|
|
|
|
2015-03-15 15:51:56 +00:00
|
|
|
// This list must be drawn last, because it contains the
|
|
|
|
// transparent gl objects, which should be drawn after all
|
|
|
|
// non transparent objects
|
|
|
|
if( isEnabled( FL_MODULE ) && m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
|
|
|
|
{
|
2015-04-16 07:43:27 +00:00
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
2015-04-17 11:12:59 +00:00
|
|
|
SetOpenGlDefaultMaterial();
|
2015-03-15 15:51:56 +00:00
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] );
|
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Debug bounding boxes
|
|
|
|
/*
|
|
|
|
glDisable( GL_BLEND );
|
|
|
|
glDisable( GL_COLOR_MATERIAL );
|
|
|
|
glDisable( GL_LIGHTING );
|
|
|
|
glColor4f( 1.0f, 0.0f, 1.0f, 1.0f );
|
|
|
|
m_fastAABBox_Shadow.GLdebug();
|
|
|
|
|
|
|
|
glColor4f( 0.0f, 1.0f, 1.0f, 1.0f );
|
|
|
|
m_boardAABBox.GLdebug();
|
|
|
|
*/
|
|
|
|
|
2014-08-04 11:28:29 +00:00
|
|
|
SwapBuffers();
|
2016-06-03 13:46:12 +00:00
|
|
|
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
|
2015-03-16 17:39:35 +00:00
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
// Show calculation time if some activity was reported
|
|
|
|
if( activityReporter.HasMessage() )
|
|
|
|
{
|
|
|
|
// Calculation time in seconds
|
|
|
|
double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e6;
|
|
|
|
|
2015-04-14 15:57:07 +00:00
|
|
|
activityReporter.Report( wxString::Format( _( "Build time %.3f s" ),
|
2015-04-14 15:12:35 +00:00
|
|
|
calculation_time ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
activityReporter.Report( wxEmptyString );
|
|
|
|
|
|
|
|
if( !err_messages.IsEmpty() )
|
|
|
|
wxLogMessage( err_messages );
|
2015-03-17 07:39:15 +00:00
|
|
|
|
2013-10-07 11:51:08 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 17:51:10 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
/**
|
2015-03-28 11:33:56 +00:00
|
|
|
* Function buildBoard3DAuxLayers
|
2014-03-08 19:04:23 +00:00
|
|
|
* Called by CreateDrawGL_List()
|
|
|
|
* Fills the OpenGL GL_ID_BOARD draw list with items
|
|
|
|
* on aux layers only
|
|
|
|
*/
|
2015-04-14 15:12:35 +00:00
|
|
|
void EDA_3D_CANVAS::buildBoard3DAuxLayers( REPORTER* aErrorMessages, REPORTER* aActivity )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
2014-07-21 16:26:18 +00:00
|
|
|
const int segcountforcircle = 18;
|
2014-03-08 19:04:23 +00:00
|
|
|
double correctionFactor = 1.0 / cos( M_PI / (segcountforcircle * 2) );
|
2014-06-24 16:17:18 +00:00
|
|
|
BOARD* pcb = GetBoard();
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET bufferPolys;
|
2014-03-08 19:04:23 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
static const LAYER_ID sequence[] = {
|
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
|
|
|
Eco2_User,
|
|
|
|
Edge_Cuts,
|
|
|
|
Margin
|
|
|
|
};
|
|
|
|
|
|
|
|
for( LSEQ aux( sequence, sequence+DIM(sequence) ); aux; ++aux )
|
2014-03-05 17:40:23 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = *aux;
|
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
if( !is3DLayerEnabled( layer ) )
|
2014-03-08 19:04:23 +00:00
|
|
|
continue;
|
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
if( aActivity )
|
|
|
|
aActivity->Report( wxString::Format( _( "Build layer %s" ), LSET::Name( layer ) ) );
|
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
bufferPolys.RemoveAllContours();
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( layer ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
|
|
|
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon(
|
|
|
|
bufferPolys, 0, segcountforcircle, correctionFactor );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet(
|
|
|
|
bufferPolys, 0, segcountforcircle, correctionFactor );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( layer,
|
|
|
|
bufferPolys,
|
|
|
|
0,
|
|
|
|
segcountforcircle,
|
|
|
|
correctionFactor );
|
|
|
|
|
|
|
|
module->TransformGraphicShapesWithClearanceToPolygonSet( layer,
|
|
|
|
bufferPolys,
|
|
|
|
0,
|
|
|
|
segcountforcircle,
|
|
|
|
correctionFactor );
|
|
|
|
}
|
|
|
|
|
|
|
|
// bufferPolys contains polygons to merge. Many overlaps .
|
|
|
|
// Calculate merged polygons and remove pads and vias holes
|
2015-07-27 19:45:57 +00:00
|
|
|
if( bufferPolys.IsEmpty() )
|
2014-03-08 19:04:23 +00:00
|
|
|
continue;
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2015-12-15 20:21:25 +00:00
|
|
|
bufferPolys.Simplify( polygonsCalcMode );
|
2014-03-08 19:04:23 +00:00
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
int thickness = GetPrm3DVisu().GetLayerObjectThicknessBIU( layer );
|
|
|
|
int zpos = GetPrm3DVisu().GetLayerZcoordBIU( layer );
|
2014-03-08 19:04:23 +00:00
|
|
|
// for Draw3D_SolidHorizontalPolyPolygons,
|
|
|
|
// zpos it the middle between bottom and top sides.
|
|
|
|
// However for top layers, zpos should be the bottom layer pos,
|
|
|
|
// and for bottom layers, zpos should be the top layer pos.
|
|
|
|
if( Get3DLayer_Z_Orientation( layer ) > 0 )
|
|
|
|
zpos += thickness/2;
|
|
|
|
else
|
|
|
|
zpos -= thickness/2 ;
|
|
|
|
|
2015-04-16 07:43:27 +00:00
|
|
|
float zNormal = 1.0f; // When using thickness it will draw first the top and then botton (with z inverted)
|
|
|
|
|
|
|
|
// If we are not using thickness, then the znormal must face the layer direction
|
|
|
|
// because it will draw just one plane
|
|
|
|
if( !thickness )
|
|
|
|
zNormal = Get3DLayer_Z_Orientation( layer );
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
setGLTechLayersColor( layer );
|
2014-03-08 19:04:23 +00:00
|
|
|
Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
|
2015-04-16 07:43:27 +00:00
|
|
|
thickness, GetPrm3DVisu().m_BiuTo3Dunits, false,
|
|
|
|
zNormal );
|
2014-03-05 17:40:23 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-04 16:38:08 +00:00
|
|
|
void EDA_3D_CANVAS::buildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList )
|
|
|
|
{
|
|
|
|
// Board shadows are based on board dimension.
|
|
|
|
|
|
|
|
float xmin = m_boardAABBox.Min().x;
|
|
|
|
float xmax = m_boardAABBox.Max().x;
|
|
|
|
float ymin = m_boardAABBox.Min().y;
|
|
|
|
float ymax = m_boardAABBox.Max().y;
|
|
|
|
|
|
|
|
float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;
|
|
|
|
|
|
|
|
// Shadow FRONT
|
|
|
|
glNewList( aFrontList, GL_COMPILE );
|
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
|
|
|
|
glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
|
|
|
|
glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
|
|
|
|
glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glEndList();
|
|
|
|
|
|
|
|
|
|
|
|
// Shadow BACK
|
|
|
|
zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;
|
|
|
|
|
|
|
|
glNewList( aBacklist, GL_COMPILE );
|
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( B_Paste ) );
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
|
|
|
|
glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
|
|
|
|
glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
|
|
|
|
glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glEndList();
|
|
|
|
|
|
|
|
// Shadow BOARD
|
|
|
|
|
|
|
|
// Floor shadow is based on axis alighned bounding box dimension
|
|
|
|
xmin = m_fastAABBox_Shadow.Min().x;
|
|
|
|
xmax = m_fastAABBox_Shadow.Max().x;
|
|
|
|
ymin = m_fastAABBox_Shadow.Min().y;
|
|
|
|
ymax = m_fastAABBox_Shadow.Max().y;
|
|
|
|
|
|
|
|
glNewList( aBoardList, GL_COMPILE );
|
|
|
|
glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, m_fastAABBox_Shadow.Min().z );
|
|
|
|
glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, m_fastAABBox_Shadow.Min().z );
|
|
|
|
glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, m_fastAABBox_Shadow.Min().z );
|
|
|
|
glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, m_fastAABBox_Shadow.Min().z );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glEndList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
void EDA_3D_CANVAS::CreateDrawGL_List( REPORTER* aErrorMessages, REPORTER* aActivity )
|
2012-08-21 10:45:54 +00:00
|
|
|
{
|
2014-03-08 19:04:23 +00:00
|
|
|
BOARD* pcb = GetBoard();
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-05-03 17:51:10 +00:00
|
|
|
wxBusyCursor dummy;
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
// Build 3D board parameters:
|
2014-08-20 17:53:09 +00:00
|
|
|
GetPrm3DVisu().InitSettings( pcb );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
|
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
// Create axis gl list (if it is not shown, the list will be not called
|
2015-03-28 11:33:56 +00:00
|
|
|
draw3DAxis();
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
// Create Board full gl lists:
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
if( ! m_glLists[GL_ID_BOARD] )
|
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( unsigned strtime = GetRunningMicroSecs() );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
m_glLists[GL_ID_BOARD] = glGenLists( 1 );
|
2014-07-30 09:01:25 +00:00
|
|
|
m_glLists[GL_ID_BODY] = glGenLists( 1 );
|
2015-04-14 15:12:35 +00:00
|
|
|
buildBoard3DView(m_glLists[GL_ID_BOARD], m_glLists[GL_ID_BODY], aErrorMessages, aActivity );
|
2014-07-31 07:01:30 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
DBG( printf( " buildBoard3DView total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2014-03-08 19:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ! m_glLists[GL_ID_TECH_LAYERS] )
|
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( unsigned strtime = GetRunningMicroSecs() );
|
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
m_glLists[GL_ID_TECH_LAYERS] = glGenLists( 1 );
|
|
|
|
glNewList( m_glLists[GL_ID_TECH_LAYERS], GL_COMPILE );
|
2015-03-17 07:39:15 +00:00
|
|
|
// when calling BuildTechLayers3DView,
|
2015-03-28 11:33:56 +00:00
|
|
|
// do not show warnings, which are the same as buildBoard3DView
|
2015-04-14 15:12:35 +00:00
|
|
|
buildTechLayers3DView( aErrorMessages, aActivity );
|
2014-03-08 19:04:23 +00:00
|
|
|
glEndList();
|
2014-07-31 07:01:30 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
DBG( printf( " buildTechLayers3DView total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2014-03-08 19:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ! m_glLists[GL_ID_AUX_LAYERS] )
|
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( unsigned strtime = GetRunningMicroSecs() );
|
|
|
|
|
2014-03-08 19:04:23 +00:00
|
|
|
m_glLists[GL_ID_AUX_LAYERS] = glGenLists( 1 );
|
|
|
|
glNewList( m_glLists[GL_ID_AUX_LAYERS], GL_COMPILE );
|
2015-04-14 15:12:35 +00:00
|
|
|
buildBoard3DAuxLayers( aErrorMessages, aActivity );
|
2014-03-08 19:04:23 +00:00
|
|
|
glEndList();
|
2014-07-31 07:01:30 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
DBG( printf( " buildBoard3DAuxLayers total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2014-03-08 19:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw modules 3D shapes
|
2014-08-20 08:39:19 +00:00
|
|
|
if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] && isEnabled( FL_MODULE ) )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
2014-07-30 09:01:25 +00:00
|
|
|
m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] = glGenLists( 1 );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2014-07-30 09:01:25 +00:00
|
|
|
// GL_ID_3DSHAPES_TRANSP_FRONT is an auxiliary list for 3D shapes;
|
2014-03-08 19:04:23 +00:00
|
|
|
// Ensure it is cleared before rebuilding it
|
2014-07-30 09:01:25 +00:00
|
|
|
if( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
|
|
|
|
glDeleteLists( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT], 1 );
|
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
|
|
|
|
|
|
|
|
if( useMaterial )
|
|
|
|
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = glGenLists( 1 );
|
|
|
|
else
|
|
|
|
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = 0;
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
buildFootprintShape3DList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT],
|
2015-04-14 15:12:35 +00:00
|
|
|
m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT],
|
|
|
|
aErrorMessages, aActivity );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2014-07-31 07:01:30 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
2015-03-28 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
calcBBox();
|
|
|
|
|
|
|
|
// Create grid gl list
|
|
|
|
if( ! m_glLists[GL_ID_GRID] )
|
|
|
|
{
|
|
|
|
m_glLists[GL_ID_GRID] = glGenLists( 1 );
|
|
|
|
glNewList( m_glLists[GL_ID_GRID], GL_COMPILE );
|
2014-07-31 07:01:30 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
draw3DGrid( GetPrm3DVisu().m_3D_Grid );
|
|
|
|
|
|
|
|
glEndList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_glLists[GL_ID_SHADOW_FRONT] )
|
2014-07-30 09:01:25 +00:00
|
|
|
m_glLists[GL_ID_SHADOW_FRONT] = glGenLists( 1 );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( !m_glLists[GL_ID_SHADOW_BACK] )
|
2014-07-30 09:01:25 +00:00
|
|
|
m_glLists[GL_ID_SHADOW_BACK] = glGenLists( 1 );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( !m_glLists[GL_ID_SHADOW_BOARD] )
|
2014-07-30 09:01:25 +00:00
|
|
|
m_glLists[GL_ID_SHADOW_BOARD] = glGenLists( 1 );
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
buildShadowList( m_glLists[GL_ID_SHADOW_FRONT],
|
|
|
|
m_glLists[GL_ID_SHADOW_BACK],
|
|
|
|
m_glLists[GL_ID_SHADOW_BOARD] );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
CheckGLError( __FILE__, __LINE__ );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_3D_CANVAS::calcBBox()
|
|
|
|
{
|
|
|
|
BOARD* pcb = GetBoard();
|
|
|
|
|
|
|
|
m_fastAABBox.Reset();
|
|
|
|
|
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
CBBOX tmpFastAABBox;
|
|
|
|
|
|
|
|
// Compute the transformation matrix for this module based on translation, rotation and orientation.
|
|
|
|
float zpos = GetPrm3DVisu().GetModulesZcoord3DIU( module->IsFlipped() );
|
|
|
|
wxPoint pos = module->GetPosition();
|
|
|
|
|
|
|
|
glm::mat4 fullTransformMatrix;
|
|
|
|
fullTransformMatrix = glm::translate( glm::mat4(), S3D_VERTEX( (float)(pos.x * GetPrm3DVisu().m_BiuTo3Dunits),
|
|
|
|
(float)(-pos.y * GetPrm3DVisu().m_BiuTo3Dunits),
|
|
|
|
zpos ) );
|
|
|
|
|
|
|
|
if( module->GetOrientation() )
|
|
|
|
fullTransformMatrix = glm::rotate( fullTransformMatrix,
|
2015-03-29 10:59:53 +00:00
|
|
|
glm::radians( (float)(module->GetOrientation() / 10.0f) ),
|
2015-03-28 11:33:56 +00:00
|
|
|
S3D_VERTEX( 0.0f, 0.0f, 1.0f ) );
|
|
|
|
|
|
|
|
if( module->IsFlipped() )
|
|
|
|
{
|
2015-03-29 10:59:53 +00:00
|
|
|
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 ) );
|
2015-03-28 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute a union bounding box for all the shapes of the model
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
S3D_MASTER* shape3D = module->Models();
|
|
|
|
|
|
|
|
for( ; shape3D; shape3D = shape3D->Next() )
|
|
|
|
{
|
|
|
|
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
|
|
|
|
tmpFastAABBox.Union( shape3D->getFastAABBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpFastAABBox.ApplyTransformationAA( fullTransformMatrix );
|
|
|
|
|
|
|
|
m_fastAABBox.Union( tmpFastAABBox );
|
2014-07-31 07:01:30 +00:00
|
|
|
}
|
2014-08-04 11:28:29 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Create a board bounding box based on board size
|
|
|
|
wxSize brd_size = getBoardSize();
|
|
|
|
wxPoint brd_center_pos = getBoardCenter();
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
float xsize = brd_size.x;
|
|
|
|
float ysize = brd_size.y;
|
|
|
|
|
|
|
|
float scale = GetPrm3DVisu().m_BiuTo3Dunits;
|
|
|
|
float xmin = (brd_center_pos.x - xsize / 2.0) * scale;
|
|
|
|
float xmax = (brd_center_pos.x + xsize / 2.0) * scale;
|
|
|
|
float ymin = (brd_center_pos.y - ysize / 2.0) * scale;
|
|
|
|
float ymax = (brd_center_pos.y + ysize / 2.0) * scale;
|
|
|
|
|
|
|
|
float zmin = GetPrm3DVisu().GetLayerZcoordBIU( B_Adhes ) * scale;
|
|
|
|
float zmax = GetPrm3DVisu().GetLayerZcoordBIU( F_Adhes ) * scale;
|
|
|
|
|
|
|
|
m_boardAABBox = CBBOX( S3D_VERTEX(xmin, ymin, zmin),
|
|
|
|
S3D_VERTEX(xmax, ymax, zmax) );
|
|
|
|
|
|
|
|
// Add BB board with BB models and scale it a bit
|
|
|
|
m_fastAABBox.Union( m_boardAABBox );
|
|
|
|
m_fastAABBox_Shadow = m_fastAABBox;
|
|
|
|
m_fastAABBox_Shadow.Scale( SHADOW_BOUNDING_BOX_SCALE );
|
2014-03-08 19:04:23 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
void EDA_3D_CANVAS::buildFootprintShape3DList( GLuint aOpaqueList,
|
2015-04-14 15:12:35 +00:00
|
|
|
GLuint aTransparentList,
|
|
|
|
REPORTER* aErrorMessages,
|
|
|
|
REPORTER* aActivity )
|
2014-03-08 19:04:23 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( unsigned strtime = GetRunningMicroSecs() );
|
|
|
|
|
2015-04-14 15:12:35 +00:00
|
|
|
if( aActivity )
|
|
|
|
aActivity->Report( _( "Load 3D Shapes" ) );
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// clean the parser list if it have any already loaded files
|
|
|
|
m_model_parsers_list.clear();
|
|
|
|
m_model_filename_list.clear();
|
2015-03-13 19:27:25 +00:00
|
|
|
|
|
|
|
BOARD* pcb = GetBoard();
|
|
|
|
|
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
2015-03-28 11:33:56 +00:00
|
|
|
read3DComponentShape( module );
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( printf( " read3DComponentShape total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( strtime = GetRunningMicroSecs() );
|
2015-03-13 19:27:25 +00:00
|
|
|
|
|
|
|
bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
|
|
|
|
|
|
|
|
if( useMaterial )
|
|
|
|
{
|
2014-03-08 19:04:23 +00:00
|
|
|
// aOpaqueList is the gl list for non transparent items
|
|
|
|
// aTransparentList is the gl list for non transparent items,
|
|
|
|
// which need to be drawn after all other items
|
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
glNewList( aOpaqueList, GL_COMPILE );
|
2015-03-13 19:27:25 +00:00
|
|
|
bool loadOpaqueObjects = true;
|
2014-03-09 18:43:53 +00:00
|
|
|
|
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
2015-03-28 11:33:56 +00:00
|
|
|
render3DComponentShape( module, loadOpaqueObjects,
|
|
|
|
!loadOpaqueObjects );
|
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
glEndList();
|
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2014-03-09 18:43:53 +00:00
|
|
|
glNewList( aTransparentList, GL_COMPILE );
|
2015-03-13 19:27:25 +00:00
|
|
|
bool loadTransparentObjects = true;
|
2014-03-08 19:04:23 +00:00
|
|
|
|
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
2015-03-28 11:33:56 +00:00
|
|
|
render3DComponentShape( module, !loadTransparentObjects,
|
|
|
|
loadTransparentObjects );
|
2015-03-13 19:27:25 +00:00
|
|
|
|
|
|
|
glEndList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just create one list
|
|
|
|
glNewList( aOpaqueList, GL_COMPILE );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
|
2015-03-28 11:33:56 +00:00
|
|
|
render3DComponentShape( module, false, false );
|
2014-03-08 19:04:23 +00:00
|
|
|
glEndList();
|
2015-03-13 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
DBG( printf( " render3DComponentShape total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
|
2012-08-21 10:45:54 +00:00
|
|
|
}
|
|
|
|
|
2008-08-17 18:37:03 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
bool EDA_3D_CANVAS::read3DComponentShape( MODULE* module )
|
2008-08-16 17:42:40 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
if( module )
|
2015-03-13 19:27:25 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
S3D_MASTER* shape3D = module->Models();
|
|
|
|
|
|
|
|
for( ; shape3D; shape3D = shape3D->Next() )
|
2015-03-13 19:27:25 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
|
|
|
|
{
|
|
|
|
bool found = false;
|
2011-02-16 21:51:35 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
unsigned int i;
|
|
|
|
wxString shape_filename = shape3D->GetShape3DFullFilename();
|
2015-03-13 19:27:25 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
// Search for already loaded files
|
|
|
|
for( i = 0; i < m_model_filename_list.size(); i++ )
|
2015-03-13 19:27:25 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
if( shape_filename.Cmp(m_model_filename_list[i]) == 0 )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-03-13 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( found == false )
|
|
|
|
{
|
|
|
|
// Create a new parser
|
|
|
|
S3D_MODEL_PARSER *newParser = S3D_MODEL_PARSER::Create( shape3D, shape3D->GetShape3DExtension() );
|
2015-04-02 11:18:19 +00:00
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
if( newParser )
|
|
|
|
{
|
|
|
|
// Read file
|
|
|
|
if( shape3D->ReadData( newParser ) == 0 )
|
|
|
|
{
|
|
|
|
// Store this couple filename / parsed file
|
|
|
|
m_model_filename_list.push_back( shape_filename );
|
|
|
|
m_model_parsers_list.push_back( newParser );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Reusing file
|
|
|
|
shape3D->m_parser = m_model_parsers_list[i];
|
|
|
|
}
|
2015-03-13 19:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-28 11:33:56 +00:00
|
|
|
void EDA_3D_CANVAS::render3DComponentShape( MODULE* module,
|
2015-03-13 19:27:25 +00:00
|
|
|
bool aIsRenderingJustNonTransparentObjects,
|
2015-03-28 11:33:56 +00:00
|
|
|
bool aIsRenderingJustTransparentObjects )
|
2015-03-13 19:27:25 +00:00
|
|
|
{
|
|
|
|
double zpos = GetPrm3DVisu().GetModulesZcoord3DIU( module->IsFlipped() );
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2014-03-05 17:40:23 +00:00
|
|
|
glPushMatrix();
|
2012-08-27 11:41:22 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
wxPoint pos = module->GetPosition();
|
|
|
|
|
|
|
|
glTranslatef( pos.x * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
-pos.y * GetPrm3DVisu().m_BiuTo3Dunits,
|
|
|
|
zpos );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
if( module->GetOrientation() )
|
2015-03-28 11:33:56 +00:00
|
|
|
glRotatef( (double) module->GetOrientation() / 10.0, 0.0f, 0.0f, 1.0f );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
if( module->IsFlipped() )
|
2014-03-05 17:40:23 +00:00
|
|
|
{
|
2015-03-28 11:33:56 +00:00
|
|
|
glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
glRotatef( 180.0f, 0.0f, 0.0f, 1.0f );
|
2014-03-05 17:40:23 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
S3D_MASTER* shape3D = module->Models();
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
for( ; shape3D; shape3D = shape3D->Next() )
|
2014-03-05 17:40:23 +00:00
|
|
|
{
|
|
|
|
if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) )
|
2014-08-24 13:29:59 +00:00
|
|
|
{
|
|
|
|
glPushMatrix();
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2015-03-13 19:27:25 +00:00
|
|
|
shape3D->Render( aIsRenderingJustNonTransparentObjects,
|
|
|
|
aIsRenderingJustTransparentObjects );
|
2015-03-28 11:33:56 +00:00
|
|
|
|
2016-04-07 01:48:51 +00:00
|
|
|
const CBBOX &shapeBBox = shape3D->getBBox();
|
|
|
|
if( isEnabled( FL_RENDER_SHOW_MODEL_BBOX ) && shapeBBox.IsInitialized() )
|
2015-03-28 11:33:56 +00:00
|
|
|
{
|
2015-12-08 07:56:30 +00:00
|
|
|
// Set the alpha current color to opaque
|
|
|
|
float currentColor[4];
|
|
|
|
glGetFloatv( GL_CURRENT_COLOR,currentColor );
|
|
|
|
currentColor[3] = 1.0f;
|
|
|
|
glColor4fv( currentColor );
|
2016-04-07 01:48:51 +00:00
|
|
|
OGL_draw_bbox( shapeBBox );
|
2015-03-28 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 13:29:59 +00:00
|
|
|
glPopMatrix();
|
2015-03-28 11:33:56 +00:00
|
|
|
|
|
|
|
// Debug AABBox
|
|
|
|
//thisBBox = shape3D->getfastAABBox();
|
|
|
|
//thisBBox.GLdebug();
|
2014-08-24 13:29:59 +00:00
|
|
|
}
|
2008-08-17 18:37:03 +00:00
|
|
|
}
|
2014-03-05 17:40:23 +00:00
|
|
|
|
|
|
|
glPopMatrix();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
|
2014-08-20 08:39:19 +00:00
|
|
|
bool EDA_3D_CANVAS::is3DLayerEnabled( LAYER_ID aLayer ) const
|
2008-08-16 17:42:40 +00:00
|
|
|
{
|
2013-10-07 14:50:23 +00:00
|
|
|
DISPLAY3D_FLG flg;
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2012-04-09 09:16:47 +00:00
|
|
|
// see if layer needs to be shown
|
|
|
|
// check the flags
|
2013-05-03 17:51:10 +00:00
|
|
|
switch( aLayer )
|
2012-04-09 09:16:47 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Adhes:
|
|
|
|
case F_Adhes:
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_ADHESIVE;
|
2013-05-16 19:04:21 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_SOLDERPASTE;
|
2013-05-16 19:04:21 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_SilkS:
|
|
|
|
case F_SilkS:
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_SILKSCREEN;
|
2013-05-03 17:51:10 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Mask:
|
|
|
|
case F_Mask:
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_SOLDERMASK;
|
2013-05-16 19:04:21 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case Dwgs_User:
|
|
|
|
case Cmts_User:
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isRealisticMode() )
|
2013-10-07 11:51:08 +00:00
|
|
|
return false;
|
|
|
|
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_COMMENTS;
|
2013-05-03 17:51:10 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case Eco1_User:
|
|
|
|
case Eco2_User:
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isRealisticMode() )
|
2013-10-07 11:51:08 +00:00
|
|
|
return false;
|
|
|
|
|
2013-10-07 14:50:23 +00:00
|
|
|
flg = FL_ECO;
|
2013-05-03 17:51:10 +00:00
|
|
|
break;
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Cu:
|
|
|
|
case F_Cu:
|
2014-08-20 17:53:09 +00:00
|
|
|
return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer )
|
2014-08-20 08:39:19 +00:00
|
|
|
|| isRealisticMode();
|
2013-10-07 11:51:08 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-03 17:51:10 +00:00
|
|
|
default:
|
2014-08-19 14:51:15 +00:00
|
|
|
// the layer is an internal copper layer, used the visibility
|
|
|
|
//
|
2014-08-20 08:39:19 +00:00
|
|
|
if( isRealisticMode() )
|
2013-10-07 11:51:08 +00:00
|
|
|
return false;
|
|
|
|
|
2014-08-20 17:53:09 +00:00
|
|
|
return GetPrm3DVisu().m_BoardSettings->IsLayerVisible( aLayer );
|
2013-03-31 13:27:46 +00:00
|
|
|
}
|
2008-08-17 18:37:03 +00:00
|
|
|
|
2014-08-19 14:51:15 +00:00
|
|
|
// The layer has a flag, return the flag
|
2014-08-20 08:39:19 +00:00
|
|
|
return isEnabled( flg );
|
2008-08-16 17:42:40 +00:00
|
|
|
}
|