KiCad PCB EDA Suite
Loading...
Searching...
No Matches
MODEL_3D Class Reference

#include <3d_model.h>

Classes

struct  MATERIAL
 
struct  VERTEX
 

Public Member Functions

 MODEL_3D (const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialMode)
 Load a 3D model.
 
 ~MODEL_3D ()
 
void DrawOpaque (bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
 Render the model into the current context.
 
void DrawTransparent (float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor=SFVEC3F(0.0f)) const
 Render the model into the current context.
 
void Draw (bool aTransparent, float aOpacity, bool aUseSelectedMaterial, const SFVEC3F &aSelectionColor, const glm::mat4 *aModelWorldMatrix, const SFVEC3F *aCameraWorldPos) const
 Render the model into the current context.
 
bool HasOpaqueMeshes () const
 Return true if have opaque meshes to render.
 
bool HasTransparentMeshes () const
 Return true if have transparent mesh's to render.
 
void DrawBbox () const
 Draw main bounding box of the model.
 
void DrawBboxes () const
 Draw individual bounding boxes of each mesh.
 
const BBOX_3DGetBBox () const
 Get the main bounding box.
 

Static Public Member Functions

static void BeginDrawMulti (bool aUseColorInformation)
 Set some basic render states before drawing multiple models.
 
static void EndDrawMulti ()
 Cleanup render states after drawing multiple models.
 

Static Private Member Functions

static void MakeBbox (const BBOX_3D &aBox, unsigned int aIdxOffset, VERTEX *aVtxOut, GLuint *aIdxOut, const glm::vec4 &aColor)
 

Private Attributes

MATERIAL_MODE m_materialMode
 
BBOX_3D m_model_bbox
 global bounding box for this model
 
std::vector< BBOX_3Dm_meshes_bbox
 individual bbox for each mesh
 
GLuint m_vertex_buffer = 0
 
GLuint m_index_buffer = 0
 
GLenum m_index_buffer_type = GL_INVALID_ENUM
 
std::vector< MATERIALm_materials
 
bool m_have_opaque_meshes = false
 
bool m_have_transparent_meshes = false
 
GLuint m_bbox_vertex_buffer = 0
 
GLuint m_bbox_index_buffer = 0
 
GLenum m_bbox_index_buffer_type = GL_INVALID_ENUM
 

Static Private Attributes

static const wxChar * m_logTrace = wxT( "KI_TRACE_EDA_OGL_3DMODEL" )
 
static constexpr unsigned int bbox_vtx_count = 8
 
static constexpr unsigned int bbox_idx_count = 24
 

Detailed Description

Definition at line 37 of file 3d_model.h.

Constructor & Destructor Documentation

◆ MODEL_3D()

MODEL_3D::MODEL_3D ( const S3DMODEL a3DModel,
MATERIAL_MODE  aMaterialMode 
)

Load a 3D model.

Note
This must be called inside a gl context.
Parameters
a3DModela 3d model data to load.
aMaterialModea mode to render the materials of the model.

WARNING: Horrible hack here! Somehow, buffer values are being shared between pcbnew and the 3d viewer, which then frees the buffer, resulting in errors in pcbnew. To resolve this temporarily, we generate extra buffers in 3dviewer and use the higher numbers. These are freed on close. todo: Correctly separate the OpenGL contexts to prevent overlapping buffer vals

Definition at line 90 of file 3d_model.cpp.

References bbox_idx_count, bbox_vtx_count, BBOX_3D::IsInitialized(), MODEL_3D::MATERIAL::IsTransparent(), MODEL_3D::MATERIAL::m_bbox, m_bbox_index_buffer, m_bbox_index_buffer_type, m_bbox_vertex_buffer, MODEL_3D::VERTEX::m_cad_color, MODEL_3D::VERTEX::m_color, SMESH::m_Color, SMATERIAL::m_Diffuse, SMESH::m_FaceIdx, SMESH::m_FaceIdxSize, m_have_opaque_meshes, m_have_transparent_meshes, m_index_buffer, m_index_buffer_type, m_logTrace, SMESH::m_MaterialIdx, m_materialMode, m_materials, S3DMODEL::m_Materials, S3DMODEL::m_MaterialsSize, S3DMODEL::m_Meshes, m_meshes_bbox, S3DMODEL::m_MeshesSize, m_model_bbox, SMESH::m_Normals, MODEL_3D::VERTEX::m_nrm, MODEL_3D::VERTEX::m_pos, SMESH::m_Positions, MODEL_3D::MATERIAL::m_render_idx_buffer_offset, MODEL_3D::MATERIAL::m_render_idx_count, MODEL_3D::VERTEX::m_tex_uv, SMESH::m_Texcoords, SMATERIAL::m_Transparency, m_vertex_buffer, SMESH::m_VertexSize, MakeBbox(), MaterialDiffuseToColorCAD(), and BBOX_3D::Union().

◆ ~MODEL_3D()

MODEL_3D::~MODEL_3D ( )

Member Function Documentation

◆ BeginDrawMulti()

void MODEL_3D::BeginDrawMulti ( bool  aUseColorInformation)
static

Set some basic render states before drawing multiple models.

Definition at line 388 of file 3d_model.cpp.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), RENDER_3D_OPENGL::renderOpaqueModels(), and RENDER_3D_OPENGL::renderTransparentModels().

◆ Draw()

void MODEL_3D::Draw ( bool  aTransparent,
float  aOpacity,
bool  aUseSelectedMaterial,
const SFVEC3F aSelectionColor,
const glm::mat4 *  aModelWorldMatrix,
const SFVEC3F aCameraWorldPos 
) const

Render the model into the current context.

if aModelWorldMatrix and aCameraWorldPos is provided, it renders the material groups sorted.

Definition at line 417 of file 3d_model.cpp.

References BBOX_3D::GetCenter(), m_index_buffer, m_index_buffer_type, m_materialMode, m_materials, m_vertex_buffer, MaterialDiffuseToColorCAD(), OglSetDiffuseMaterial(), and OglSetMaterial().

Referenced by DrawOpaque(), DrawTransparent(), and RENDER_3D_OPENGL::renderModel().

◆ DrawBbox()

void MODEL_3D::DrawBbox ( ) const

Draw main bounding box of the model.

Definition at line 569 of file 3d_model.cpp.

References bbox_idx_count, m_bbox_index_buffer, m_bbox_index_buffer_type, and m_bbox_vertex_buffer.

Referenced by RENDER_3D_OPENGL::renderModel().

◆ DrawBboxes()

void MODEL_3D::DrawBboxes ( ) const

Draw individual bounding boxes of each mesh.

Definition at line 588 of file 3d_model.cpp.

References bbox_idx_count, m_bbox_index_buffer, m_bbox_index_buffer_type, m_bbox_vertex_buffer, and m_meshes_bbox.

Referenced by RENDER_3D_OPENGL::renderModel().

◆ DrawOpaque()

void MODEL_3D::DrawOpaque ( bool  aUseSelectedMaterial,
SFVEC3F  aSelectionColor = SFVEC3F( 0.0f ) 
) const
inline

Render the model into the current context.

Definition at line 55 of file 3d_model.h.

References Draw().

Referenced by EDA_3D_MODEL_VIEWER::OnPaint().

◆ DrawTransparent()

void MODEL_3D::DrawTransparent ( float  aOpacity,
bool  aUseSelectedMaterial,
SFVEC3F  aSelectionColor = SFVEC3F( 0.0f ) 
) const
inline

Render the model into the current context.

Definition at line 63 of file 3d_model.h.

References Draw().

Referenced by EDA_3D_MODEL_VIEWER::OnPaint().

◆ EndDrawMulti()

void MODEL_3D::EndDrawMulti ( )
static

Cleanup render states after drawing multiple models.

Definition at line 404 of file 3d_model.cpp.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), RENDER_3D_OPENGL::renderOpaqueModels(), and RENDER_3D_OPENGL::renderTransparentModels().

◆ GetBBox()

const BBOX_3D & MODEL_3D::GetBBox ( ) const
inline

Get the main bounding box.

Returns
the main model bounding box.

Definition at line 103 of file 3d_model.h.

References m_model_bbox.

Referenced by EDA_3D_MODEL_VIEWER::OnPaint().

◆ HasOpaqueMeshes()

bool MODEL_3D::HasOpaqueMeshes ( ) const
inline

Return true if have opaque meshes to render.

Definition at line 82 of file 3d_model.h.

References m_have_opaque_meshes.

◆ HasTransparentMeshes()

bool MODEL_3D::HasTransparentMeshes ( ) const
inline

Return true if have transparent mesh's to render.

Definition at line 87 of file 3d_model.h.

References m_have_transparent_meshes.

◆ MakeBbox()

void MODEL_3D::MakeBbox ( const BBOX_3D aBox,
unsigned int  aIdxOffset,
VERTEX aVtxOut,
GLuint *  aIdxOut,
const glm::vec4 &  aColor 
)
staticprivate

Definition at line 51 of file 3d_model.cpp.

References bbox_line, MODEL_3D::VERTEX::m_pos, BBOX_3D::Max(), and BBOX_3D::Min().

Referenced by MODEL_3D().

Member Data Documentation

◆ bbox_idx_count

constexpr unsigned int MODEL_3D::bbox_idx_count = 24
staticconstexprprivate

Definition at line 166 of file 3d_model.h.

Referenced by DrawBbox(), DrawBboxes(), and MODEL_3D().

◆ bbox_vtx_count

constexpr unsigned int MODEL_3D::bbox_vtx_count = 8
staticconstexprprivate

Definition at line 165 of file 3d_model.h.

Referenced by MODEL_3D().

◆ m_bbox_index_buffer

GLuint MODEL_3D::m_bbox_index_buffer = 0
private

Definition at line 169 of file 3d_model.h.

Referenced by DrawBbox(), DrawBboxes(), MODEL_3D(), and ~MODEL_3D().

◆ m_bbox_index_buffer_type

GLenum MODEL_3D::m_bbox_index_buffer_type = GL_INVALID_ENUM
private

Definition at line 170 of file 3d_model.h.

Referenced by DrawBbox(), DrawBboxes(), and MODEL_3D().

◆ m_bbox_vertex_buffer

GLuint MODEL_3D::m_bbox_vertex_buffer = 0
private

Definition at line 168 of file 3d_model.h.

Referenced by DrawBbox(), DrawBboxes(), MODEL_3D(), and ~MODEL_3D().

◆ m_have_opaque_meshes

bool MODEL_3D::m_have_opaque_meshes = false
private

Definition at line 160 of file 3d_model.h.

Referenced by HasOpaqueMeshes(), and MODEL_3D().

◆ m_have_transparent_meshes

bool MODEL_3D::m_have_transparent_meshes = false
private

Definition at line 161 of file 3d_model.h.

Referenced by HasTransparentMeshes(), and MODEL_3D().

◆ m_index_buffer

GLuint MODEL_3D::m_index_buffer = 0
private

Definition at line 139 of file 3d_model.h.

Referenced by Draw(), MODEL_3D(), and ~MODEL_3D().

◆ m_index_buffer_type

GLenum MODEL_3D::m_index_buffer_type = GL_INVALID_ENUM
private

Definition at line 140 of file 3d_model.h.

Referenced by Draw(), and MODEL_3D().

◆ m_logTrace

const wxChar * MODEL_3D::m_logTrace = wxT( "KI_TRACE_EDA_OGL_3DMODEL" )
staticprivate

Definition at line 116 of file 3d_model.h.

Referenced by MODEL_3D().

◆ m_materialMode

MATERIAL_MODE MODEL_3D::m_materialMode
private

Definition at line 121 of file 3d_model.h.

Referenced by Draw(), and MODEL_3D().

◆ m_materials

std::vector<MATERIAL> MODEL_3D::m_materials
private

Definition at line 155 of file 3d_model.h.

Referenced by Draw(), and MODEL_3D().

◆ m_meshes_bbox

std::vector<BBOX_3D> MODEL_3D::m_meshes_bbox
private

individual bbox for each mesh

Definition at line 124 of file 3d_model.h.

Referenced by DrawBboxes(), and MODEL_3D().

◆ m_model_bbox

BBOX_3D MODEL_3D::m_model_bbox
private

global bounding box for this model

Definition at line 123 of file 3d_model.h.

Referenced by GetBBox(), and MODEL_3D().

◆ m_vertex_buffer

GLuint MODEL_3D::m_vertex_buffer = 0
private

Definition at line 138 of file 3d_model.h.

Referenced by Draw(), MODEL_3D(), and ~MODEL_3D().


The documentation for this class was generated from the following files: