-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDLView.cs
858 lines (758 loc) · 28.2 KB
/
MDLView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//-----------------------------------------------------------------------------
// File: EnhancedMesh.cs
//
// Desc: Sample showing enhanced meshes in D3D
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Windows.Forms;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using MDL;
namespace MDLView
{
/// <summary>
/// Application class. The base class (GraphicsSample) provides the generic
/// functionality needed in all Direct3D samples. MyGraphicsSample adds
/// functionality specific to this sample program.
/// </summary>
public class MyGraphicsSample : GraphicsSample
{
// Menu items specific for this application
private MenuItem mnuOpenMesh = null;
private MenuItem mnuMeshBreak = null;
private GraphicsFont drawingFont = null; // Font for drawing text
string initialDirectory = null;
string meshFilename = "acs01.mdl"; // Filename of mesh
Mesh systemMemoryMesh = null; // system memory version of mesh, lives through resize's
//Mesh enhancedMesh = null; // vid mem version of mesh that is enhanced
int numberSegments; // number of segments per edge (tesselation level)
Direct3D.Material[] meshMaterials = null; // array of materials
Texture[] meshTextures = null; // Array of textures, entries are NULL if no texture specified
GraphicsArcBall arcBall = null; // Mouse rotation utility
Vector3 objectCenter; // Center of bounding sphere of object
float objectRadius = 0.0f; // Radius of bounding sphere of object
//GraphicsStream adjacency = null; // Contains the adjacency info loaded with the mesh
bool isUsingHardwareNPatches;
private System.Windows.Forms.PictureBox target;
private Microsoft.VisualBasic.Compatibility.VB6.DirListBox dirListBox1;
private Microsoft.VisualBasic.Compatibility.VB6.FileListBox fileListBox1;
private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox1;
private System.Windows.Forms.Button BTSolidWire;
private System.Windows.Forms.ComboBox CBLOD;
bool isWireframe = false;
private System.Windows.Forms.Label label1;
MDLFile mdlfile;
MDLObject rootmdl;
Mesh[] Meshes;
bool[] MeshesEnable;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TreeView tvObj;
private System.Windows.Forms.ColorDialog cdBack;
private System.Windows.Forms.Button btBackColor;
private System.Windows.Forms.Button btSave;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
int[] MeshesTex;
/// <summary>
/// Application constructor. Sets attributes for the app.
/// </summary>
public MyGraphicsSample()
{
// Add our new menu options
this.mnuOpenMesh = new MenuItem();
this.mnuMeshBreak = new MenuItem();
// Add the Open File menu to the file menu
this.mnuFile.MenuItems.Add(0, this.mnuMeshBreak);
this.mnuMeshBreak.Text = "-";
this.mnuFile.MenuItems.Add(0, this.mnuOpenMesh);
this.mnuOpenMesh.Text = "Open File...";
this.mnuOpenMesh.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.mnuOpenMesh.ShowShortcut = true;
this.mnuOpenMesh.Click += new System.EventHandler(this.OpenMesh);
InitializeComponent();
this.RenderTarget = target;
// Set the window text
this.Text = "Allegiance MDL Viewer";
try
{
// Load the icon from our resources
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
}
catch
{
// It's no big deal if we can't load our icons, but try to load the embedded one
try { this.Icon = new System.Drawing.Icon(this.GetType(), "directx.ico"); }
catch {}
}
arcBall = new GraphicsArcBall(this.target);
initialDirectory = DXUtil.SdkMediaPath;
driveListBox1.Drive = System.IO.Path.GetPathRoot(initialDirectory);
dirListBox1.Path = initialDirectory;
fileListBox1.Path = initialDirectory;
drawingFont = new GraphicsFont("Arial", System.Drawing.FontStyle.Bold);
enumerationSettings.AppUsesDepthBuffer = true;
numberSegments = 2;
// Set up our event handlers
//this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnPrivateKeyDown);
}
/// <summary>
/// The window has been created, but the device has not been created yet.
/// Here you can perform application-related initialization and cleanup that
/// does not depend on a device.
/// </summary>
protected override void OneTimeSceneInitialization()
{
// Set cursor to indicate that user can move the object with the mouse
this.target.Cursor = System.Windows.Forms.Cursors.SizeAll;
}
/// <summary>
/// Called once per frame, the call is the entry point for animating the scene.
/// </summary>
protected override void FrameMove()
{
// Setup world matrix
Matrix matWorld = Matrix.Translation(-objectCenter.X,
-objectCenter.Y,
-objectCenter.Z);
matWorld.Multiply(arcBall.RotationMatrix);
matWorld.Multiply(arcBall.TranslationMatrix);
device.Transform.World = matWorld;
// Set up view matrix
Vector3 vFrom= new Vector3(0, 0,-3*objectRadius);
Vector3 vAt = new Vector3(0, 0, 0);
Vector3 vUp = new Vector3(0, 1, 0);
device.Transform.View = Matrix.LookAtLH(vFrom, vAt, vUp);
}
/// <summary>
/// Called once per frame, the call is the entry point for 3d rendering. This
/// function sets up render states, clears the viewport, and renders the scene.
/// </summary>
protected override void Render()
{
// Clear the viewport
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer , cdBack.Color, 1.0f, 0);
device.BeginScene();
if (isUsingHardwareNPatches)
{
float fNumSegs;
fNumSegs = (float)numberSegments;
device.NPatchMode = fNumSegs;
}
// set and draw each of the materials in the mesh
// if (meshMaterials != null)
// {
// for (int i = 0; i < meshMaterials.Length; i++)
// {
// device.Material = meshMaterials[i];
// device.SetTexture(0, meshTextures[i]);
//
// enhancedMesh.DrawSubset(i);
// }
// }
// else
// enhancedMesh.DrawSubset(0);
for (int i=0;i<Meshes.Length;i++)
{
if (MeshesEnable[i])
{
if (MeshesTex[i] != -1)
{
device.Material = meshMaterials[MeshesTex[i]];
device.SetTexture(0, meshTextures[MeshesTex[i]]);
Meshes[i].DrawSubset(0);
}
else
Meshes[i].DrawSubset(0);
}
}
if (isUsingHardwareNPatches)
{
device.NPatchMode = 0.0f;
}
// Output statistics
drawingFont.DrawText(2, 1, System.Drawing.Color.Yellow, frameStats);
// Display info on mesh
drawingFont.DrawText(2, 20, System.Drawing.Color.Yellow, "File name: ");
drawingFont.DrawText(150, 20, System.Drawing.Color.White, meshFilename);
// for (int i=0;i<Meshes.Length;i++)
// {
// drawingFont.DrawText(2, 40+i*40, System.Drawing.Color.Yellow, "Number Faces: ");
// drawingFont.DrawText(150, 40+i*40, System.Drawing.Color.White, (Meshes[i] == null) ? "0" : Meshes[i].NumberFaces.ToString());
//
// drawingFont.DrawText(2, 60+i*40, System.Drawing.Color.Yellow, "Number Vertices: ");
// drawingFont.DrawText(150, 60+i*40, System.Drawing.Color.White, (Meshes[i] == null) ? "0" : Meshes[i].NumberVertices.ToString());
// }
device.EndScene();
}
/// <summary>
/// The device has been created. Resources that are not lost on
/// Reset() can be created here -- resources in Pool.Managed,
/// Pool.Scratch, or Pool.SystemMemory. Image surfaces created via
/// CreateImageSurface are never lost and can be created here. Vertex
/// shaders and pixel shaders can also be created here as they are not
/// lost on Reset().
/// </summary>
protected override void InitializeDeviceObjects()
{
// Initialize the drawingFont's internal textures
drawingFont.InitializeDeviceObjects(device);
//ExtendedMaterial[] mtrl = null;
mdlfile = new MDLFile();
string path = DXUtil.FindMediaFile(initialDirectory, meshFilename);
try
{
//systemMemoryMesh = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out adjacency, out mtrl);
if (!mdlfile.ReadFromFile(initialDirectory+ "\\"+meshFilename))
throw new FileLoadException("not a valide MDL file.", meshFilename);
MDLObject obj = mdlfile.RootObject;
rootmdl = obj;
CBLOD.Items.Clear();
if (obj.type == MDLType.mdl_lod)
{
CBLOD.Enabled = true;
for (int i=0;i<obj.nchildren;i++)
{
CBLOD.Items.Add(obj.childrens[i].lodval);
}
obj = obj.childrens[0];
CBLOD.SelectedIndex = 0;
}
else
{
CBLOD.Enabled = false;
}
// while (obj.type != MDLType.mdl_mesh)
// {
// if (obj.childrens[0].type == MDLType.mdl_empty)
// obj = obj.childrens[1];
// else
// obj = obj.childrens[0];
//
// }
// process textures
if (mdlfile.NumTextures >0)
{
meshMaterials = new Material[mdlfile.NumTextures];
meshTextures = new Texture[mdlfile.NumTextures];
for (int i = 0; i< mdlfile.NumTextures; i++)
{
meshMaterials[i] = new Direct3D.Material();
meshMaterials[i].Ambient = Color.White;
meshMaterials[i].Diffuse = Color.White;
MDLFile mdlbmp = new MDLFile();
if (mdlbmp.ReadFromFile(initialDirectory+ "\\"+mdlfile.Textures[i]+".mdl"))
{
if (mdlbmp.RootObject.type == MDLType.mdl_image)
{
MDLImage mdlimg = mdlbmp.RootObject.image;
MemoryStream memstream = new MemoryStream(mdlimg.bitmap);
try
{
//meshTextures[i] = TextureLoader.FromStream(device,memstream,mdlimg.bitmap.Length,mdlimg.w,mdlimg.h,0,0,Format.R5G6B5,Pool.Managed,Filter.Linear,Filter.Linear,0);
//meshTextures[i] = TextureLoader.FromStream(device,memstream,mdlimg.w,mdlimg.h,0,0,Format.R5G6B5,Pool.SystemMemory,Filter.Linear,Filter.Linear,1);
Bitmap bitmap = new Bitmap(mdlimg.w,mdlimg.h,PixelFormat.Format16bppRgb565);
Rectangle rect = new Rectangle(0,0,mdlimg.w,mdlimg.h);
BitmapData bmdata = bitmap.LockBits(rect,ImageLockMode.WriteOnly,PixelFormat.Format16bppRgb565);
IntPtr pixels = bmdata.Scan0;
unsafe
{
byte *pBits = (byte *) pixels.ToPointer();
for (int p=0;p<mdlimg.bitmap.Length;p++)
pBits[p] = mdlimg.bitmap[p];
}
bitmap.UnlockBits(bmdata);
//bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
meshTextures[i] = Texture.FromBitmap(device,bitmap,Usage.AutoGenerateMipMap, Pool.Managed);
}
catch (Exception e)
{
string mess = e.Message;
MessageBox.Show("error loading texture '"+mdlfile.Textures[i]+".mdl'. "+e.Message);
}
}
}
}
}
ArrayList objs = FlattenChildren(obj);
Meshes = new Mesh[objs.Count];
MeshesEnable = new bool[objs.Count];
MeshesTex = new int[objs.Count];
objectRadius = 0;
tvObj.Nodes.Clear();
for (int oi=0;oi<objs.Count;oi++)
{
obj = (MDLObject)objs[oi];
TreeNode tn = new TreeNode("part "+oi.ToString());
tn.Tag = oi;
tn.Checked = true;
tn.Nodes.Add("# vertices = "+obj.mesh.nvertex.ToString());
tn.Nodes.Add("# faces = "+(obj.mesh.nfaces/3).ToString());
if (obj.textidx == -1)
{
tn.Nodes.Add("no texture");
}
else
{
tn.Nodes.Add("texture = "+mdlfile.Textures[obj.textidx]);
}
tvObj.Nodes.Add(tn);
// process mesh
systemMemoryMesh = new Mesh(obj.mesh.nfaces/3,obj.mesh.nvertex,MeshFlags.SystemMemory,VertexFormats.Position | VertexFormats.Normal | VertexFormats.Texture1,device);
//systemMemoryMesh = Mesh.Box(device,12,15,2);
VertexBuffer pVB = systemMemoryMesh.VertexBuffer;
int dwNumVertices = systemMemoryMesh.NumberVertices;
CustomVertex.PositionNormalTextured [] dest =
(CustomVertex.PositionNormalTextured [])pVB.Lock(0,
typeof(CustomVertex.PositionNormalTextured), 0, dwNumVertices);
for(int i = 0; i < dest.Length; i++)
{
dest[i].X = obj.mesh.vertices[i].x;
dest[i].Y = obj.mesh.vertices[i].y;
dest[i].Z = obj.mesh.vertices[i].z;
dest[i].Nx = obj.mesh.vertices[i].nx;
dest[i].Ny = obj.mesh.vertices[i].ny;
dest[i].Nz = obj.mesh.vertices[i].nz;
dest[i].Tu = obj.mesh.vertices[i].mx;
dest[i].Tv = obj.mesh.vertices[i].my;
}
pVB.Unlock();
int dwNumFaces = systemMemoryMesh.NumberFaces*3;
ushort[] idxs = (ushort[])systemMemoryMesh.LockIndexBuffer(typeof(ushort),0,dwNumFaces);
for (int i=0;i<dwNumFaces;i+=3)
{
idxs[i] = obj.mesh.faces[i];
idxs[i+1] = obj.mesh.faces[i+2];
idxs[i+2] = obj.mesh.faces[i+1];
}
systemMemoryMesh.UnlockIndexBuffer();
//systemMemoryMesh.SetIndexBufferData(obj.mesh.faces,LockFlags.None);
// Lock the vertex buffer, to generate a simple bounding sphere
VertexBuffer vb = null;
try
{
vb = systemMemoryMesh.VertexBuffer;
GraphicsStream vbStream = vb.Lock(0, 0, 0);
objectRadius = Math.Max(objectRadius,Geometry.ComputeBoundingSphere(vbStream, systemMemoryMesh.NumberVertices, systemMemoryMesh.VertexFormat, out objectCenter));
}
finally
{
// Make sure we unlock the buffer if we fail
if (vb != null)
vb.Unlock();
}
// Make sure there are normals, which are required for the tesselation
// enhancement
if ((systemMemoryMesh.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal)
{
Mesh tempMesh = systemMemoryMesh.Clone(systemMemoryMesh.Options.Value, systemMemoryMesh.VertexFormat | VertexFormats.Normal, device);
tempMesh.ComputeNormals();
systemMemoryMesh.Dispose();
systemMemoryMesh = tempMesh;
}
Meshes[oi] = systemMemoryMesh;
MeshesEnable[oi] = true;
MeshesTex[oi] = obj.textidx;
} // oi loop
tvObj.ExpandAll();
objectCenter = new Vector3(0,0,0);
} // try
catch
{
// Hide the error so we display a blue screen
return;
}
}
protected ArrayList FlattenChildren(MDLObject obj)
{
ArrayList ares = new ArrayList(0);
if (obj.type == MDLType.mdl_group)
{
MDLMesh[] childmeshes = new MDLMesh[obj.nchildren];
for(int i=0;i<obj.nchildren;i++)
{
ares.AddRange(FlattenChildren(obj.childrens[i]));
}
}
if (obj.type == MDLType.mdl_mesh)
{
ares.Add(obj);
}
return ares;
}
/// <summary>
/// The device exists, but may have just been Reset(). Resources in
/// Pool.Default and any other device state that persists during
/// rendering should be set here. Render states, matrices, textures,
/// etc., that don't change during rendering can be set once here to
/// avoid redundant state setting during Render() or FrameMove().
/// </summary>
protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
{
isUsingHardwareNPatches = Caps.DeviceCaps.SupportsNPatches; // Do we have hardware support?
//enhancedMesh = systemMemoryMesh;
// Setup render state
renderState.Lighting = true;
renderState.DitherEnable = true;
renderState.ZBufferEnable = true;
renderState.Ambient = System.Drawing.Color.FromArgb(0x33333333);
sampleState[0].MagFilter = TextureFilter.Linear;
sampleState[0].MinFilter = TextureFilter.Linear;
// Setup the light
GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.0f, -1.0f, 1.0f);
device.Lights[0].Commit();
device.Lights[0].Enabled = true;
GraphicsUtility.InitLight(device.Lights[1], LightType.Directional, 1.0f, 1.0f, 1.0f);
device.Lights[1].Commit();
device.Lights[1].Enabled = true;
// Set the arcball parameters
arcBall.SetWindow(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 0.85f);
arcBall.Radius = 1.0f;
// Set the projection matrix
float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, fAspect, objectRadius/64.0f,objectRadius*200.0f);
if (isWireframe)
device.RenderState.FillMode = FillMode.WireFrame;
else
device.RenderState.FillMode = FillMode.Solid;
}
/// <summary>
/// Event Handler for windows messages
/// not used anymore
/// </summary>
private void OnPrivateKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == System.Windows.Forms.Keys.W)
{
device.RenderState.FillMode = FillMode.WireFrame;
isWireframe = true;
}
if (e.KeyCode == System.Windows.Forms.Keys.S)
{
device.RenderState.FillMode = FillMode.Solid;
isWireframe = false;
}
}
/// <summary>
/// Fired when a new mesh needs to be opened
/// </summary>
private void OpenMesh(object sender, EventArgs e)
{
// Display the OpenFileName dialog. Then, try to load the specified file
System.Windows.Forms.OpenFileDialog ofn = new OpenFileDialog();
ofn.Filter = "Allegiance MDL Files (*.mdl)|*.mdl";
ofn.FileName = meshFilename;
ofn.InitialDirectory = initialDirectory;
ofn.Title = "Open MDL File";
ofn.CheckFileExists = true;
ofn.Multiselect = false;
ofn.ShowReadOnly = false;
ofn.ShowDialog();
System.IO.FileInfo fo = new System.IO.FileInfo(ofn.FileName);
meshFilename = fo.Name;
System.IO.Directory.SetCurrentDirectory(fo.DirectoryName);
initialDirectory = fo.DirectoryName;
// Destroy and recreate everything
InvalidateDeviceObjects(null, null);
DeleteDeviceObjects(null, null);
try
{
InitializeDeviceObjects();
RestoreDeviceObjects(null, null);
}
catch
{
MessageBox.Show("Error loading mesh: mesh may not\n" +
"be valid. See debug output for\n" +
"more information.\n\nPlease select " +
"a different .x file.","MDLView", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Called during device initialization, this code checks the device for
/// some minimum set of capabilities
/// </summary>
protected override bool ConfirmDevice(Caps caps, VertexProcessingType vertexProcessingType,
Format adapterFormat, Format backBufferFormat)
{
if ((vertexProcessingType == VertexProcessingType.PureHardware) &&
(!caps.DeviceCaps.SupportsNPatches) && (caps.DeviceCaps.SupportsRtPatches))
return false;
return true;
}
private void InitializeComponent()
{
this.driveListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DriveListBox();
this.fileListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.FileListBox();
this.dirListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DirListBox();
this.target = new System.Windows.Forms.PictureBox();
this.BTSolidWire = new System.Windows.Forms.Button();
this.CBLOD = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.btSave = new System.Windows.Forms.Button();
this.tvObj = new System.Windows.Forms.TreeView();
this.cdBack = new System.Windows.Forms.ColorDialog();
this.btBackColor = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// driveListBox1
//
this.driveListBox1.Location = new System.Drawing.Point(8, 16);
this.driveListBox1.Name = "driveListBox1";
this.driveListBox1.Size = new System.Drawing.Size(192, 21);
this.driveListBox1.TabIndex = 2;
this.driveListBox1.SelectedIndexChanged += new System.EventHandler(this.driveListBox1_SelectedIndexChanged);
//
// fileListBox1
//
this.fileListBox1.Location = new System.Drawing.Point(8, 152);
this.fileListBox1.Name = "fileListBox1";
this.fileListBox1.Pattern = "*.mdl";
this.fileListBox1.Size = new System.Drawing.Size(192, 277);
this.fileListBox1.TabIndex = 1;
this.fileListBox1.SelectedIndexChanged += new System.EventHandler(this.fileListBox1_SelectedIndexChanged);
//
// dirListBox1
//
this.dirListBox1.IntegralHeight = false;
this.dirListBox1.Location = new System.Drawing.Point(8, 40);
this.dirListBox1.Name = "dirListBox1";
this.dirListBox1.Size = new System.Drawing.Size(192, 112);
this.dirListBox1.TabIndex = 0;
this.dirListBox1.SelectedIndexChanged += new System.EventHandler(this.dirListBox1_SelectedIndexChanged);
//
// target
//
this.target.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.target.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.target.Location = new System.Drawing.Point(224, 56);
this.target.Name = "target";
this.target.Size = new System.Drawing.Size(472, 416);
this.target.TabIndex = 1;
this.target.TabStop = false;
//
// BTSolidWire
//
this.BTSolidWire.Location = new System.Drawing.Point(224, 24);
this.BTSolidWire.Name = "BTSolidWire";
this.BTSolidWire.TabIndex = 2;
this.BTSolidWire.Text = "Wireframe";
this.BTSolidWire.Click += new System.EventHandler(this.BTSolidWire_Click);
//
// CBLOD
//
this.CBLOD.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.CBLOD.Enabled = false;
this.CBLOD.Location = new System.Drawing.Point(648, 24);
this.CBLOD.Name = "CBLOD";
this.CBLOD.Size = new System.Drawing.Size(48, 21);
this.CBLOD.TabIndex = 3;
//
// label1
//
this.label1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.label1.Location = new System.Drawing.Point(560, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 4;
this.label1.Text = "Level of detail";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage1,
this.tabPage2});
this.tabControl1.Location = new System.Drawing.Point(0, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(216, 464);
this.tabControl1.TabIndex = 5;
//
// tabPage1
//
this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.driveListBox1,
this.dirListBox1,
this.fileListBox1});
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(208, 438);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Browse";
//
// tabPage2
//
this.tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btSave,
this.tvObj});
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(208, 438);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "View";
//
// btSave
//
this.btSave.Location = new System.Drawing.Point(16, 408);
this.btSave.Name = "btSave";
this.btSave.TabIndex = 1;
this.btSave.Text = "Save (test)";
this.btSave.Visible = false;
this.btSave.Click += new System.EventHandler(this.btSave_Click);
//
// tvObj
//
this.tvObj.CheckBoxes = true;
this.tvObj.ImageIndex = -1;
this.tvObj.Location = new System.Drawing.Point(8, 8);
this.tvObj.Name = "tvObj";
this.tvObj.SelectedImageIndex = -1;
this.tvObj.Size = new System.Drawing.Size(192, 392);
this.tvObj.TabIndex = 0;
this.tvObj.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.tvObj_AfterCheck);
this.tvObj.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvObj_AfterSelect);
//
// btBackColor
//
this.btBackColor.Location = new System.Drawing.Point(312, 24);
this.btBackColor.Name = "btBackColor";
this.btBackColor.Size = new System.Drawing.Size(112, 23);
this.btBackColor.TabIndex = 6;
this.btBackColor.Text = "Background color";
this.btBackColor.Click += new System.EventHandler(this.btBackColor_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.FileName = "doc1";
//
// ourRenderTarget
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(712, 477);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btBackColor,
this.tabControl1,
this.label1,
this.CBLOD,
this.BTSolidWire,
this.target});
this.MinimumSize = new System.Drawing.Size(720, 488);
this.Name = "ourRenderTarget";
this.Text = "MDLView";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
using (MyGraphicsSample d3dApp = new MyGraphicsSample())
{
if (d3dApp.CreateGraphicsSample())
d3dApp.Run();
}
}
private void driveListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//MessageBox.Show(driveListBox1.SelectedItem.ToString());
dirListBox1.Path = driveListBox1.Drive;
}
private void dirListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
fileListBox1.Path = dirListBox1.Path;
}
private void fileListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//MessageBox.Show(fileListBox1.FileName);
meshFilename = fileListBox1.FileName;
System.IO.Directory.SetCurrentDirectory(fileListBox1.Path);
initialDirectory = fileListBox1.Path;
InvalidateDeviceObjects(null, null);
DeleteDeviceObjects(null, null);
try
{
InitializeDeviceObjects();
RestoreDeviceObjects(null, null);
}
catch
{
MessageBox.Show("Error loading model: model may not\n" +
"be valid. See debug output for\n" +
"more information.\n\nPlease select " +
"a different .mdl file.","MDLView", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void BTSolidWire_Click(object sender, System.EventArgs e)
{
if (BTSolidWire.Text == "Wireframe")
{
device.RenderState.FillMode = FillMode.WireFrame;
isWireframe = true;
BTSolidWire.Text = "Solid";
return;
}
if (BTSolidWire.Text == "Solid")
{
device.RenderState.FillMode = FillMode.Solid;
isWireframe = false;
BTSolidWire.Text = "Wireframe";
return;
}
}
private void tvObj_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
//MessageBox.Show(tvObj.SelectedNode.Text);
}
private void tvObj_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
TreeNode tn = e.Node;
if (tn == null) return;
if (tn.Parent != null)
{
if (tn.Checked)
tn.Checked = false;
}
else
{
if (!tn.Checked)
tn.Collapse();
else
tn.Expand();
MeshesEnable[(int)tn.Tag] = tn.Checked;
}
}
private void btBackColor_Click(object sender, System.EventArgs e)
{
cdBack.ShowDialog();
}
private void btSave_Click(object sender, System.EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
mdlfile.SaveToFile(saveFileDialog1.FileName);
}
}
}
}