| | 318 | Libx42.Model m = model.Model; |
|---|
| | 319 | if( m == null ) |
|---|
| | 320 | return; |
|---|
| | 321 | |
|---|
| | 322 | if( topoPreviewFrameCookieNTb != frameCookie ) |
|---|
| | 323 | { |
|---|
| | 324 | GraphicsStream gs = topoNTBVb.Lock( 0, 0, LockFlags.None ); |
|---|
| | 325 | try |
|---|
| | 326 | { |
|---|
| | 327 | |
|---|
| | 328 | Libx42.DataStream<Vector3> vp = modelDXData.AnimationBuffer.PositionStream.Reinterpret<Vector3>(); |
|---|
| | 329 | if( modelDXData.AnimationBuffer.NormalStream != null ) |
|---|
| | 330 | { |
|---|
| | 331 | Libx42.DataStream<Vector3> vn = modelDXData.AnimationBuffer.NormalStream.Reinterpret<Vector3>(); |
|---|
| | 332 | |
|---|
| | 333 | for( int i = 0; i < m.Vertices.Count; i++ ) |
|---|
| | 334 | { |
|---|
| | 335 | gs.Write( new LineVertex( vp[i], Color.Blue ) ); |
|---|
| | 336 | gs.Write( new LineVertex( vp[i] + vn[i], Color.Blue ) ); |
|---|
| | 337 | } |
|---|
| | 338 | } |
|---|
| | 339 | |
|---|
| | 340 | if( modelDXData.AnimationBuffer.TangentStream != null && modelDXData.AnimationBuffer.BinormalStream != null ) |
|---|
| | 341 | { |
|---|
| | 342 | Libx42.DataStream<Vector3> vt = modelDXData.AnimationBuffer.TangentStream.Reinterpret<Vector3>(); |
|---|
| | 343 | Libx42.DataStream<Vector3> vb = modelDXData.AnimationBuffer.BinormalStream.Reinterpret<Vector3>(); |
|---|
| | 344 | |
|---|
| | 345 | for( int i = 0; i < m.Vertices.Count; i++ ) |
|---|
| | 346 | { |
|---|
| | 347 | /* Note: tangents and binormals are not normalized at the |
|---|
| | 348 | * vertex animation stage since that's something that could |
|---|
| | 349 | * be done faster on the GPU (vertex shaders are pretty much |
|---|
| | 350 | * implied when using tangents and binormals). Normalize them |
|---|
| | 351 | * here so the display doesn't look screwy. |
|---|
| | 352 | */ |
|---|
| | 353 | |
|---|
| | 354 | gs.Write( new LineVertex( vp[i], Color.Red ) ); |
|---|
| | 355 | gs.Write( new LineVertex( vp[i] + Vector3.Normalize( vt[i] ), Color.Red ) ); |
|---|
| | 356 | |
|---|
| | 357 | gs.Write( new LineVertex( vp[i], Color.Green ) ); |
|---|
| | 358 | gs.Write( new LineVertex( vp[i] + Vector3.Normalize( vb[i] ), Color.Green ) ); |
|---|
| | 359 | } |
|---|
| | 360 | } |
|---|
| | 361 | } |
|---|
| | 362 | finally |
|---|
| | 363 | { |
|---|
| | 364 | topoNTBVb.Unlock(); |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | topoPreviewFrameCookieNTb = frameCookie; |
|---|
| | 368 | } |
|---|
| 451 | | |
|---|
| | 500 | } |
|---|
| | 501 | |
|---|
| | 502 | private void DrawTopologyView() |
|---|
| | 503 | { |
|---|
| | 504 | Libx42.Model m = model.Model; |
|---|
| | 505 | if( m == null ) |
|---|
| | 506 | return; |
|---|
| | 507 | |
|---|
| | 508 | Device dev = pn3D.Device; |
|---|
| | 509 | |
|---|
| | 510 | switch( pnPreviewOpts.TopologyShadingMode ) |
|---|
| | 511 | { |
|---|
| | 512 | case TopologyShadingMode.Strips: |
|---|
| | 513 | DrawTopologyStrips(); |
|---|
| | 514 | break; |
|---|
| | 515 | |
|---|
| | 516 | case TopologyShadingMode.TexCoords: |
|---|
| | 517 | if( m.Vertices.TextureCoordinateStream == null ) |
|---|
| | 518 | goto case TopologyShadingMode.None; |
|---|
| | 519 | |
|---|
| | 520 | break; |
|---|
| | 521 | |
|---|
| | 522 | case TopologyShadingMode.None: |
|---|
| | 523 | DrawSurfacesView(); |
|---|
| | 524 | break; |
|---|
| | 525 | } |
|---|
| | 526 | |
|---|
| | 527 | if( pnPreviewOpts.TopoShowNormals || pnPreviewOpts.TopoShowTanBasis ) |
|---|
| | 528 | { |
|---|
| | 529 | UpdateTopologyNTbPreviewState(); |
|---|
| | 530 | |
|---|
| | 531 | dev.RenderState.AlphaBlendEnable = false; |
|---|
| | 532 | dev.RenderState.Lighting = false; |
|---|
| | 533 | dev.RenderState.ColorVertex = true; |
|---|
| | 534 | |
|---|
| | 535 | dev.VertexDeclaration = lineVertDecl; |
|---|
| | 536 | dev.SetStreamSource( 0, topoNTBVb, 0, LineVertex.Size ); |
|---|
| | 537 | |
|---|
| | 538 | foreach( GroupContext ctx in pnGroups.Groups ) |
|---|
| | 539 | { |
|---|
| | 540 | if( !ctx.Visible ) |
|---|
| | 541 | continue; |
|---|
| | 542 | |
|---|
| | 543 | Libx42.Group g = ctx.Group; |
|---|
| | 544 | |
|---|
| | 545 | if( pnPreviewOpts.TopoShowNormals && modelDXData.AnimationBuffer.NormalStream != null ) |
|---|
| | 546 | { |
|---|
| | 547 | dev.DrawPrimitives( PrimitiveType.LineList, g.Vertices.Offset * 2, g.Vertices.Count ); |
|---|
| | 548 | } |
|---|
| | 549 | |
|---|
| | 550 | if( pnPreviewOpts.TopoShowTanBasis && |
|---|
| | 551 | modelDXData.AnimationBuffer.TangentStream != null && |
|---|
| | 552 | modelDXData.AnimationBuffer.BinormalStream != null ) |
|---|
| | 553 | { |
|---|
| | 554 | int ofs = modelDXData.AnimationBuffer.NormalStream != null ? m.Vertices.Count * 2 : 0; |
|---|
| | 555 | dev.DrawPrimitives( PrimitiveType.LineList, ofs + g.Vertices.Offset * 4, g.Vertices.Count * 2 ); |
|---|
| | 556 | } |
|---|
| | 557 | } |
|---|
| | 558 | } |
|---|