33 #include "../3d_rendering/opengl/opengl_utils.h" 34 #include "../3d_cache/3d_cache.h" 35 #include <wx/dcclient.h> 45 #define UNITS3D_TO_UNITSPCB (IU_PER_MM) 70 #ifdef USE_OSX_MAGNIFY_EVENT 71 EVT_MAGNIFY( EDA_3D_MODEL_VIEWER::OnMagnify )
82 #define RANGE_SCALE_3D 8.0f 87 HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
88 wxFULL_REPAINT_ON_RESIZE ),
90 m_cacheManager( aCacheManager )
92 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER" ) );
111 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::~EDA_3D_MODEL_VIEWER" ) );
128 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
132 wxASSERT( a3DModel.
m_Meshes !=
nullptr );
155 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
185 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
186 glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
187 glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
189 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
190 glEnable( GL_DEPTH_TEST );
191 glEnable( GL_CULL_FACE );
192 glShadeModel( GL_SMOOTH );
193 glEnable( GL_LINE_SMOOTH );
194 glEnable( GL_NORMALIZE );
198 const GLfloat ambient[] = { 0.01f, 0.01f, 0.01f, 1.0f };
199 const GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
200 const GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
203 const GLfloat position[] = { 0.0f, 0.0f, 2.0f *
RANGE_SCALE_3D, 0.0f };
205 const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
207 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
208 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
209 glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
210 glLightfv( GL_LIGHT0, GL_POSITION, position );
211 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
217 glEnable( GL_COLOR_MATERIAL );
218 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
222 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
223 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
232 if( !IsShownOnScreen() )
234 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::OnPaint !IsShown" ) );
262 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
274 glViewport( 0, 0, clientSize.x, clientSize.y );
279 glEnable( GL_DEPTH_TEST );
280 glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
281 glClearDepth( 1.0f );
282 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
285 glMatrixMode( GL_PROJECTION );
287 glMatrixMode( GL_MODELVIEW );
289 glEnable( GL_LIGHTING );
290 glEnable( GL_LIGHT0 );
299 glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
300 modelunit_to_3d_units_factor );
305 glTranslatef( -model_center.x, -model_center.y, -model_center.z );
318 glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );
319 glClear( GL_DEPTH_BUFFER_BIT );
321 glMatrixMode( GL_PROJECTION );
325 glMatrixMode( GL_MODELVIEW );
328 const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
333 glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
337 glColor3f( 0.9f, 0.0f, 0.0f );
341 glColor3f( 0.0f, 0.9f, 0.0f );
345 glColor3f( 0.0f, 0.0f, 0.9f );
360 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::OnEraseBackground" ) );
367 wxLogTrace(
m_logTrace, wxT(
"EDA_3D_MODEL_VIEWER::OnMouseWheel" ) );
369 if( event.ShiftDown() )
376 else if( event.ControlDown() )
395 #ifdef USE_OSX_MAGNIFY_EVENT 396 void EDA_3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event )
409 if( event.Dragging() )
411 if( event.LeftIsDown() )
virtual wxSize GetNativePixelSize() const
double m_BiuTo3dUnits
factor to convert the model or any other items to keep it in relation to the +/-RANGE_SCALE_3D (it is...
void OnPaint(wxPaintEvent &event)
void OnMiddleUp(wxMouseEvent &event)
Implementation of conversion functions that require both schematic and board internal units.
TRACK_BALL m_trackBallCamera
Camera used in this canvas.
Implement a canvas based on a wxGLCanvas.
const glm::mat4 & GetProjectionMatrix() const
void OnLeftDown(wxMouseEvent &event)
S3D_CACHE * m_cacheManager
Optional cache manager.
wxGLCanvas wrapper for HiDPI/Retina support.
void OnMiddleDown(wxMouseEvent &event)
EDA_3D_MODEL_VIEWER(wxWindow *aParent, const int *aAttribList=nullptr, S3D_CACHE *aCacheManager=nullptr)
Create a new 3D Canvas with a attribute list.
void OnEraseBackground(wxEraseEvent &event)
bool m_reload_is_needed
Flag that we have a new model and it need to be reloaded when the paint is called.
#define UNITS3D_TO_UNITSPCB
Implements a model viewer canvas.
Cache for storing the 3D shapes.
wxGLContext * m_glRC
openGL context
const glm::mat4 GetRotationMatrix() const
Get the rotation matrix to be applied in a transformation camera.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
void UnlockCtx(wxGLContext *aContext)
Allow other canvases to bind an OpenGL context.
SMESH * m_Meshes
The meshes list of this model.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
S3DMODEL * GetModel(const wxString &aModelFileName)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
static GL_CONTEXT_MANAGER & Get()
Return the GL_CONTEXT_MANAGER instance (singleton).
SFVEC3F GetCenter() const
Return the center point of the bounding box.
void Clear3DModel()
Unload the displayed 3D model.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
Use all material properties from model file.
float GetMaxDimension() const
const glm::mat4 & GetViewMatrix() const
const S3DMODEL * m_3d_model
Original 3d model data.
void SetCurMousePosition(const wxPoint &aPosition)
Update the current mouse position without make any new calculations on camera.
EVT_MIDDLE_DOWN(mpWindow::OnMouseMiddleDown) EVT_MOUSEWHEEL(mpWindow
void OnLeftUp(wxMouseEvent &event)
void ogl_set_arrow_material()
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=nullptr)
Create a managed OpenGL context.
unsigned int m_MaterialsSize
Number of materials in the material array.
void DrawRoundArrow(SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize)
Draw a round arrow.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Set a context as current and prevents other canvases from switching it.
wxPoint GetNativePosition(const wxPoint &aPoint) const
Convert the given point from client coordinates to native pixel coordinates.
bool SetCurWindowSize(const wxSize &aSize)
Update the windows size of the camera.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void DrawOpaque(bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
Render the model into the current context.
static void EndDrawMulti()
Cleanup render states after drawing multiple models.
void OnMouseMove(wxMouseEvent &event)
void OnMouseWheel(wxMouseEvent &event)
void DrawTransparent(float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
Render the model into the current context.
SMATERIAL * m_Materials
The materials list of this model.
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
void OnRightClick(wxMouseEvent &event)
bool m_ogl_initialized
Flag if open gl was initialized.
const BBOX_3D & GetBBox() const
Get the main bounding box.
void Set3DModel(const S3DMODEL &a3DModel)
Set this model to be displayed.
void DestroyCtx(wxGLContext *aContext)
Destroy a managed OpenGL context.
Store the a model based on meshes and materials.
static void BeginDrawMulti(bool aUseColorInformation)
Set some basic render states before drawing multiple models.
unsigned int m_MeshesSize
Number of meshes in the array.
MODEL_3D * m_ogl_3dmodel
Class holder for 3d model to display on openGL.
void Drag(const wxPoint &aNewMousePosition) override
Calculate a new mouse drag position.