2 #include <Cry3DEngine/IStatObj.h>
3 #include "MeshBakerPopupPreview.h"
4 #include "DisplayViewportAdapter.h"
5 #include "Material/Material.h"
8 CCMeshBakerPopupPreview::CCMeshBakerPopupPreview(QViewport
* viewPort
):m_ViewPort(viewPort
)
10 m_pViewportAdapter
.reset(new CDisplayViewportAdapter(m_ViewPort
));
14 m_bPrecacheMaterial
= false;
15 m_bDrawWireFrame
= false;
23 l
.m_Flags
|= DLF_SUN
| DLF_DIRECTIONAL
;
24 l
.SetLightColor(ColorF(L
,L
,L
,1));
25 l
.SetPosition( Vec3(100,100,100) );
26 m_lights
.push_back( l
);
30 m_clearColor
.set(0.5f
, 0.5f
, 0.5f
, 1.0f
);
31 m_ambientColor
.set(1.0f
, 1.0f
, 1.0f
, 1.0f
);
32 m_ambientMultiplier
= 0.5f
;
36 void CCMeshBakerPopupPreview::OnKeyEvent(const SKeyEvent
& sKeyEvent
)
41 void CCMeshBakerPopupPreview::OnMouseEvent(const SMouseEvent
& sMouseEvent
)
48 void CCMeshBakerPopupPreview::SetObject(IStatObj
* pObj
)
53 void CCMeshBakerPopupPreview::ReleaseObject()
55 if (m_pObject
!= NULL
)
61 void CCMeshBakerPopupPreview::SetMaterial(IMaterial
* pMat
)
63 m_pMat
= (CMaterial
*)pMat
;
66 void CCMeshBakerPopupPreview::SetRotate(bool rotate
)
71 void CCMeshBakerPopupPreview::SetWireframe(bool wireframe
)
73 m_bDrawWireFrame
= wireframe
;
76 void CCMeshBakerPopupPreview::SetGrid(bool grid
)
82 void CCMeshBakerPopupPreview::OnRender(const SRenderContext
& rc
)
94 bool CCMeshBakerPopupPreview::NoMaterialRender(const SRenderContext
& rc
)
96 IRenderAuxGeom
* aux
= gEnv
->pRenderer
->GetIRenderAuxGeom();
99 m_pViewportAdapter
->EnableXYViewport(true);
100 dc
.SetView(m_pViewportAdapter
.get());
102 aux
->SetRenderFlags(e_Mode3D
|e_AlphaBlended
|e_FillModeSolid
|e_CullModeNone
|e_DepthWriteOff
|e_DepthTestOn
);
106 RenderUnwrappedMesh(dc
,rc
);
113 void CCMeshBakerPopupPreview::RenderUnwrappedMesh(DisplayContext
& dc
,const SRenderContext
& rc
)
118 // CEdGeometry* pCEdGeometry = m_pObject->GetGeometry();m_pObject->GetIndexedMesh(true);
119 // if (NULL == pCEdGeometry)
121 // IIndexedMesh* pIIndexedMesh = pCEdGeometry->GetIndexedMesh();
124 IIndexedMesh
* pIIndexedMesh
= m_pObject
->GetIndexedMesh(true);
125 if (NULL
== pIIndexedMesh
)
128 RenderUnwrappedLodPolygon(dc
, pIIndexedMesh
,rc
);
132 void CCMeshBakerPopupPreview::RenderUnwrappedLodPolygon(DisplayContext
& dc
, IIndexedMesh
* pIIndexedMesh
,const SRenderContext
& rc
)
134 if (pIIndexedMesh
->GetFaceCount() == 0)
136 pIIndexedMesh
->RestoreFacesFromIndices();
139 IIndexedMesh::SMeshDescription sMeshDescription
;
140 pIIndexedMesh
->GetMeshDescription(sMeshDescription
);
143 ColorB color
= ColorB(255,0,0);
146 for (int i
=0; i
<sMeshDescription
.m_nFaceCount
; i
++)
148 const SMeshFace
* pFace
= &(sMeshDescription
.m_pFaces
[i
]);
150 const Vec3
* pSMeshVert0
= &sMeshDescription
.m_pVerts
[pFace
->v
[0]];
151 const Vec3
* pSMeshVert1
= &sMeshDescription
.m_pVerts
[pFace
->v
[1]];
152 const Vec3
* pSMeshVert2
= &sMeshDescription
.m_pVerts
[pFace
->v
[2]];
153 dc
.DrawLine(*pSMeshVert0
, *pSMeshVert1
);
154 dc
.DrawLine(*pSMeshVert1
, *pSMeshVert2
);
155 dc
.DrawLine(*pSMeshVert0
, *pSMeshVert2
);
161 bool CCMeshBakerPopupPreview::MaterialRender(const SRenderContext
& rc
)
166 IRenderer
* renderer
= gEnv
->pRenderer
;
167 int width
= rc
.viewport
->width();
168 int height
= rc
.viewport
->height();
169 if (height
< 2 || width
< 2)
172 SRenderingPassInfo passInfo
= SRenderingPassInfo::CreateGeneralPassRenderingInfo(*rc
.camera
, SRenderingPassInfo::DEFAULT_FLAGS
, true);
174 renderer
->ChangeViewport(0,0,width
,height
);
175 renderer
->SetCamera( *rc
.camera
);
177 CScopedWireFrameMode
scopedWireFrame(renderer
, m_bDrawWireFrame
?R_WIREFRAME_MODE
:R_SOLID_MODE
);
180 for (size_t i
= 0; i
< m_lights
.size(); i
++)
182 renderer
->EF_ADDDlight(&m_lights
[i
], passInfo
);
186 m_pMat
->DisableHighlight();
188 _smart_ptr
<IMaterial
> pMaterial
;
190 pMaterial
= m_pMat
->GetMatInfo();
192 if (m_bPrecacheMaterial
)
194 IMaterial
*pCurMat
=pMaterial
;
198 pCurMat
=m_pObject
->GetMaterial();
199 // else if (m_pEntity)
200 // pCurMat=m_pEntity->GetMaterial();
201 // else if (m_pCharacter)
202 // pCurMat=m_pCharacter->GetIMaterial();
203 // else if (m_pEmitter)
204 // pCurMat=m_pEmitter->GetMaterial();
208 pCurMat
->PrecacheMaterial(0.0f
, NULL
, true, true);
212 { // activate shader item
213 IMaterial
*pCurMat
=pMaterial
;
217 pCurMat
=m_pObject
->GetMaterial();
218 // else if (m_pEntity)
219 // pCurMat=m_pEntity->GetMaterial();
220 // else if (m_pCharacter)
221 // pCurMat=m_pCharacter->GetIMaterial();
222 // else if (m_pEmitter)
223 // pCurMat=m_pEmitter->GetMaterial();
229 RenderObject(pMaterial
, passInfo
);
238 void CCMeshBakerPopupPreview::RenderObject( IMaterial
* pMaterial
, SRenderingPassInfo
& passInfo
)
240 if (pMaterial
== NULL
)
245 //rp.nDLightMask = (1<<m_lights.size())-1;
246 rp
.AmbientColor
= m_ambientColor
* m_ambientMultiplier
;
247 rp
.dwFObjFlags
|= FOB_TRANS_MASK
/*| FOB_GLOBAL_ILLUMINATION*/ | FOB_NO_FOG
/*| FOB_ZPREPASS*/;
248 rp
.pMaterial
= pMaterial
;
256 tm
.SetRotationXYZ(Ang3( 0,0,m_rotateAngle
));
257 m_rotateAngle
+= 0.1f
;
262 // m_pObject->Render( rp, passInfo );
265 // m_pEntity->Render( rp, passInfo );
268 // m_pCharacter->Render( rp, QuatTS(IDENTITY), passInfo );
272 // m_pEmitter->Update();
273 // m_pEmitter->Render( rp, passInfo );
278 void CCMeshBakerPopupPreview::RenderUnwrappedLodPolygonUV(DisplayContext
& dc
, IIndexedMesh
* pIIndexedMesh
)
280 if (pIIndexedMesh
->GetFaceCount() == 0)
282 pIIndexedMesh
->RestoreFacesFromIndices();
285 IIndexedMesh::SMeshDescription sMeshDescription
;
286 pIIndexedMesh
->GetMeshDescription(sMeshDescription
);
288 ColorB color
= ColorB(255,255,255);
291 for (int i
=0; i
<sMeshDescription
.m_nFaceCount
; i
++)
293 const SMeshFace
* pFace
= &(sMeshDescription
.m_pFaces
[i
]);
294 for (int j
=0; j
<3; j
++)
296 const SMeshTexCoord
* pSMeshTexCoord0
= &sMeshDescription
.m_pTexCoord
[pFace
->v
[0]];
297 const SMeshTexCoord
* pSMeshTexCoord1
= &sMeshDescription
.m_pTexCoord
[pFace
->v
[1]];
298 const SMeshTexCoord
* pSMeshTexCoord2
= &sMeshDescription
.m_pTexCoord
[pFace
->v
[2]];
299 Vec2 uv0
= pSMeshTexCoord0
->GetUV();
300 Vec2 uv1
= pSMeshTexCoord1
->GetUV();
301 Vec2 uv2
= pSMeshTexCoord2
->GetUV();
302 dc
.DrawLine(Vec3(uv0
.x
,uv0
.y
,0.01f
), Vec3(uv1
.x
,uv1
.y
,0.01f
));
303 dc
.DrawLine(Vec3(uv0
.x
,uv0
.y
,0.01f
), Vec3(uv2
.x
,uv2
.y
,0.01f
));
304 dc
.DrawLine(Vec3(uv1
.x
,uv1
.y
,0.01f
), Vec3(uv2
.x
,uv2
.y
,0.01f
));