Sign in to follow this  
REspawn

[.net] Using user made models

Recommended Posts

REspawn    144
Hi, I have been working on a small 3d engine for myself (C#), I have been using the tutorials from around the net. Where im stuck is with model files, i am trying to view a custom model i have, i can read in all the vertex's, vertex colors, texture cords and the indices for the vertexes. Does anyone have any links to tutorials or samples of how to render custom models in a scene all i have been able to find is tutorials on .x files. Thanks for any help, -Dave

Share this post


Link to post
Share on other sites
REspawn    144
After some google work i found this tutorial on how to create your own mesh.

http://pluralsight.com/wiki/default.aspx/Craig.DirectX/MeshCreationTutorial.html

It compiled and works fine, but then i input myown mesh values i dont see anything on the screen.
Can anyone help me out and tell me why this is?

Thanks,
-Dave


using System;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Craig.Direct3D
{
public class Game : System.Windows.Forms.Form
{
static void Main()
{
Game app = new Game();
app.Text = "Creating a Mesh";
app.InitializeGraphics();
app.Show();
while (app.Created)
{
app.Render();
Application.DoEvents();
}
}

private Device device;
private Mesh mesh;
private int numSubSets;

private bool deviceLost;
private PresentParameters pres = new PresentParameters();

protected bool InitializeGraphics()
{
pres.Windowed = true;
pres.SwapEffect = SwapEffect.Discard;
pres.AutoDepthStencilFormat = DepthFormat.D16;
pres.EnableAutoDepthStencil = true;

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pres);
device.DeviceReset += new EventHandler(this.OnDeviceReset);

device.DeviceLost += new EventHandler(this.OnDeviceLost);
SetupDevice();

return true;
}

protected void OnDeviceReset(object sender, EventArgs e)
{
SetupDevice();
}

protected void OnDeviceLost(object sender, EventArgs e)
{
}

protected void SetupDevice()
{
SetupLights();
device.RenderState.ZBufferEnable = true;
CreateObjects(device);
}

protected void SetupLights()
{
device.RenderState.Lighting = false;
device.RenderState.Ambient = Color.White;
}

protected void SetupMaterials(Color color)
{
Material mat = new Material();

mat.Ambient = color;
device.Material = mat;
}

protected void CreateObjects(Device device)
{
// Create new cube mesh with:
mesh = new Mesh(
154, // 12 faces
267, // 8 vertices
0, // no flags
VertexFormats.Position, // Position information only
device);

CustomVertex.PositionOnly[] vertices = new CustomVertex.PositionOnly[267];
//start
vertices[0] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[1] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.061434E+09f);
vertices[2] = new CustomVertex.PositionOnly(-1.069449E+09f, -1.124914E+09f, -1.061434E+09f);
vertices[3] = new CustomVertex.PositionOnly(-1.061871E+09f, -1.046674E+09f, -1.061434E+09f);
vertices[4] = new CustomVertex.PositionOnly(-1.06948E+09f, -1.046398E+09f, -1.061434E+09f);
vertices[5] = new CustomVertex.PositionOnly(-1.096365E+09f, -1.046306E+09f, -1.061434E+09f);
vertices[6] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.061434E+09f);
vertices[7] = new CustomVertex.PositionOnly(1.084246E+09f, -1.046674E+09f, -1.061434E+09f);
vertices[8] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.061434E+09f);
vertices[9] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.061434E+09f);
vertices[10] = new CustomVertex.PositionOnly(-1.069449E+09f, -1.124914E+09f, -1.061434E+09f);
vertices[11] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.061434E+09f);
vertices[12] = new CustomVertex.PositionOnly(1.072468E+09f, -1.124914E+09f, -1.061434E+09f);
vertices[13] = new CustomVertex.PositionOnly(1.087834E+09f, -1.124914E+09f, -1.061434E+09f);
vertices[14] = new CustomVertex.PositionOnly(1.072468E+09f, -1.124914E+09f, -1.061434E+09f);
vertices[15] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[16] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[17] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.061434E+09f);
vertices[18] = new CustomVertex.PositionOnly(1.075777E+09f, -1.124716E+09f, -1.061434E+09f);
vertices[19] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.061434E+09f);
vertices[20] = new CustomVertex.PositionOnly(1.075746E+09f, 1.101054E+09f, -1.061434E+09f);
vertices[21] = new CustomVertex.PositionOnly(-1.101413E+09f, 1.101146E+09f, -1.061434E+09f);
vertices[22] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.061434E+09f);
vertices[23] = new CustomVertex.PositionOnly(-1.062108E+09f, 1.100778E+09f, -1.061434E+09f);
vertices[24] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.061434E+09f);
vertices[25] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.061434E+09f);
vertices[26] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.061434E+09f);
vertices[27] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.061434E+09f);
vertices[28] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.061434E+09f);
vertices[29] = new CustomVertex.PositionOnly(-1.07212E+09f, -1.124715E+09f, -1.061434E+09f);
vertices[30] = new CustomVertex.PositionOnly(1.075777E+09f, -1.124716E+09f, -1.061434E+09f);
vertices[31] = new CustomVertex.PositionOnly(-1.05852E+09f, -1.124716E+09f, -1.061434E+09f);
vertices[32] = new CustomVertex.PositionOnly(-1.07212E+09f, -1.124715E+09f, -1.061434E+09f);
vertices[33] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[34] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.058732E+09f);
vertices[35] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[36] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.061434E+09f);
vertices[37] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[38] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.061434E+09f);
vertices[39] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[40] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.058732E+09f);
vertices[41] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[42] = new CustomVertex.PositionOnly(-1.061871E+09f, -1.046674E+09f, -1.058732E+09f);
vertices[43] = new CustomVertex.PositionOnly(-1.06948E+09f, -1.046398E+09f, -1.061434E+09f);
vertices[44] = new CustomVertex.PositionOnly(-1.061871E+09f, -1.046674E+09f, -1.061434E+09f);
vertices[45] = new CustomVertex.PositionOnly(-1.06948E+09f, -1.046398E+09f, -1.058732E+09f);
vertices[46] = new CustomVertex.PositionOnly(-1.096365E+09f, -1.046306E+09f, -1.061434E+09f);
vertices[47] = new CustomVertex.PositionOnly(-1.096365E+09f, -1.046306E+09f, -1.058732E+09f);
vertices[48] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.061434E+09f);
vertices[49] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.058732E+09f);
vertices[50] = new CustomVertex.PositionOnly(1.084246E+09f, -1.046674E+09f, -1.061434E+09f);
vertices[51] = new CustomVertex.PositionOnly(1.084246E+09f, -1.046674E+09f, -1.058732E+09f);
vertices[52] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.058732E+09f);
vertices[53] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.061434E+09f);
vertices[54] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.061434E+09f);
vertices[55] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.058732E+09f);
vertices[56] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.058732E+09f);
vertices[57] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[58] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.061434E+09f);
vertices[59] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[60] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.061434E+09f);
vertices[61] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.061434E+09f);
vertices[62] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.058732E+09f);
vertices[63] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[64] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.058732E+09f);
vertices[65] = new CustomVertex.PositionOnly(1.075746E+09f, 1.101054E+09f, -1.061434E+09f);
vertices[66] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.061434E+09f);
vertices[67] = new CustomVertex.PositionOnly(1.075746E+09f, 1.101054E+09f, -1.058732E+09f);
vertices[68] = new CustomVertex.PositionOnly(-1.101413E+09f, 1.101146E+09f, -1.061434E+09f);
vertices[69] = new CustomVertex.PositionOnly(-1.101413E+09f, 1.101146E+09f, -1.058732E+09f);
vertices[70] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.061434E+09f);
vertices[71] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.058732E+09f);
vertices[72] = new CustomVertex.PositionOnly(-1.062108E+09f, 1.100778E+09f, -1.061434E+09f);
vertices[73] = new CustomVertex.PositionOnly(-1.062108E+09f, 1.100778E+09f, -1.058732E+09f);
vertices[74] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.058732E+09f);
vertices[75] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.061434E+09f);
vertices[76] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.061434E+09f);
vertices[77] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.058732E+09f);
vertices[78] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.04898E+09f);
vertices[79] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.04898E+09f);
vertices[80] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.058732E+09f);
vertices[81] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[82] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.058732E+09f);
vertices[83] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[84] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.04898E+09f);
vertices[85] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.04898E+09f);
vertices[86] = new CustomVertex.PositionOnly(-1.061871E+09f, -1.046674E+09f, -1.04898E+09f);
vertices[87] = new CustomVertex.PositionOnly(-1.06948E+09f, -1.046398E+09f, -1.058732E+09f);
vertices[88] = new CustomVertex.PositionOnly(-1.061871E+09f, -1.046674E+09f, -1.058732E+09f);
vertices[89] = new CustomVertex.PositionOnly(-1.06948E+09f, -1.046398E+09f, -1.04898E+09f);
vertices[90] = new CustomVertex.PositionOnly(-1.096365E+09f, -1.046306E+09f, -1.058732E+09f);
vertices[91] = new CustomVertex.PositionOnly(-1.096365E+09f, -1.046306E+09f, -1.04898E+09f);
vertices[92] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.058732E+09f);
vertices[93] = new CustomVertex.PositionOnly(1.075271E+09f, -1.046398E+09f, -1.04898E+09f);
vertices[94] = new CustomVertex.PositionOnly(1.084246E+09f, -1.046674E+09f, -1.058732E+09f);
vertices[95] = new CustomVertex.PositionOnly(1.084246E+09f, -1.046674E+09f, -1.04898E+09f);
vertices[96] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.04898E+09f);
vertices[97] = new CustomVertex.PositionOnly(1.088946E+09f, -1.047073E+09f, -1.058732E+09f);
vertices[98] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.058732E+09f);
vertices[99] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.047053E+09f, -1.04898E+09f);
vertices[100] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.04898E+09f);
vertices[101] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.04898E+09f);
vertices[102] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.058732E+09f);
vertices[103] = new CustomVertex.PositionOnly(-1.057409E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[104] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.058732E+09f);
vertices[105] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.058732E+09f);
vertices[106] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.04898E+09f);
vertices[107] = new CustomVertex.PositionOnly(1.088945E+09f, -1.124815E+09f, -1.04898E+09f);
vertices[108] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.04898E+09f);
vertices[109] = new CustomVertex.PositionOnly(1.075746E+09f, 1.101054E+09f, -1.058732E+09f);
vertices[110] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.058732E+09f);
vertices[111] = new CustomVertex.PositionOnly(1.075746E+09f, 1.101054E+09f, -1.04898E+09f);
vertices[112] = new CustomVertex.PositionOnly(-1.101413E+09f, 1.101146E+09f, -1.058732E+09f);
vertices[113] = new CustomVertex.PositionOnly(-1.101413E+09f, 1.101146E+09f, -1.04898E+09f);
vertices[114] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.058732E+09f);
vertices[115] = new CustomVertex.PositionOnly(-1.069954E+09f, 1.101054E+09f, -1.04898E+09f);
vertices[116] = new CustomVertex.PositionOnly(-1.062108E+09f, 1.100778E+09f, -1.058732E+09f);
vertices[117] = new CustomVertex.PositionOnly(-1.062108E+09f, 1.100778E+09f, -1.04898E+09f);
vertices[118] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.04898E+09f);
vertices[119] = new CustomVertex.PositionOnly(-1.057409E+09f, 1.100379E+09f, -1.058732E+09f);
vertices[120] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.058732E+09f);
vertices[121] = new CustomVertex.PositionOnly(1.088945E+09f, 1.100399E+09f, -1.04898E+09f);
vertices[122] = new CustomVertex.PositionOnly(1.084484E+09f, 1.100778E+09f, -1.04898E+09f);
vertices[123] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[124] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[125] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[126] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[127] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[128] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[129] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[130] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[131] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[132] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[133] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[134] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[135] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[136] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[137] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[138] = new CustomVertex.PositionOnly(1.074603E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[139] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[140] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[141] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[142] = new CustomVertex.PositionOnly(1.074603E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[143] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095067E+09f);
vertices[144] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095067E+09f);
vertices[145] = new CustomVertex.PositionOnly(-1.072925E+09f, -1.056727E+09f, 1.095277E+09f);
vertices[146] = new CustomVertex.PositionOnly(-1.072925E+09f, 1.0907E+09f, 1.095277E+09f);
vertices[147] = new CustomVertex.PositionOnly(-1.077582E+09f, 1.092621E+09f, -1.055708E+09f);
vertices[148] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[149] = new CustomVertex.PositionOnly(1.069193E+09f, 1.092621E+09f, -1.055708E+09f);
vertices[150] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[151] = new CustomVertex.PositionOnly(1.069193E+09f, 1.092621E+09f, -1.055708E+09f);
vertices[152] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[153] = new CustomVertex.PositionOnly(1.069193E+09f, 1.086335E+09f, -1.055708E+09f);
vertices[154] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[155] = new CustomVertex.PositionOnly(1.069193E+09f, 1.086335E+09f, -1.055708E+09f);
vertices[156] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[157] = new CustomVertex.PositionOnly(-1.077582E+09f, 1.086335E+09f, -1.055708E+09f);
vertices[158] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[159] = new CustomVertex.PositionOnly(-1.077582E+09f, 1.086335E+09f, -1.055708E+09f);
vertices[160] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[161] = new CustomVertex.PositionOnly(-1.077582E+09f, 1.092621E+09f, -1.055708E+09f);
vertices[162] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[163] = new CustomVertex.PositionOnly(-1.077582E+09f, -1.054839E+09f, -1.055708E+09f);
vertices[164] = new CustomVertex.PositionOnly(1.069193E+09f, -1.054839E+09f, -1.055708E+09f);
vertices[165] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[166] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[167] = new CustomVertex.PositionOnly(1.069193E+09f, -1.054839E+09f, -1.055708E+09f);
vertices[168] = new CustomVertex.PositionOnly(1.069193E+09f, -1.061103E+09f, -1.055708E+09f);
vertices[169] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[170] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[171] = new CustomVertex.PositionOnly(1.069193E+09f, -1.061103E+09f, -1.055708E+09f);
vertices[172] = new CustomVertex.PositionOnly(-1.077582E+09f, -1.061103E+09f, -1.055708E+09f);
vertices[173] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[174] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[175] = new CustomVertex.PositionOnly(-1.077582E+09f, -1.061103E+09f, -1.055708E+09f);
vertices[176] = new CustomVertex.PositionOnly(-1.077582E+09f, -1.054839E+09f, -1.055708E+09f);
vertices[177] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[178] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[179] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[180] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[181] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[182] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[183] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[184] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[185] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[186] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[187] = new CustomVertex.PositionOnly(1.070907E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[188] = new CustomVertex.PositionOnly(1.070907E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[189] = new CustomVertex.PositionOnly(-1.076595E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[190] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[191] = new CustomVertex.PositionOnly(1.069303E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[192] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[193] = new CustomVertex.PositionOnly(1.070907E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[194] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[195] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[196] = new CustomVertex.PositionOnly(-1.076595E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[197] = new CustomVertex.PositionOnly(-1.076595E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[198] = new CustomVertex.PositionOnly(1.070907E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[199] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[200] = new CustomVertex.PositionOnly(-1.076595E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[201] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[202] = new CustomVertex.PositionOnly(-1.077835E+09f, -1.058892E+09f, 1.092408E+09f);
vertices[203] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[204] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[205] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[206] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[207] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[208] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[209] = new CustomVertex.PositionOnly(-1.076595E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[210] = new CustomVertex.PositionOnly(-1.077743E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[211] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[212] = new CustomVertex.PositionOnly(-1.077358E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[213] = new CustomVertex.PositionOnly(-1.076595E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[214] = new CustomVertex.PositionOnly(-1.077492E+09f, 1.069426E+09f, 1.094077E+09f);
vertices[215] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[216] = new CustomVertex.PositionOnly(-1.077492E+09f, 1.069426E+09f, 1.094077E+09f);
vertices[217] = new CustomVertex.PositionOnly(1.069759E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[218] = new CustomVertex.PositionOnly(1.070907E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[219] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[220] = new CustomVertex.PositionOnly(1.070011E+09f, 1.069426E+09f, 1.094077E+09f);
vertices[221] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[222] = new CustomVertex.PositionOnly(1.070145E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[223] = new CustomVertex.PositionOnly(1.070907E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[224] = new CustomVertex.PositionOnly(1.070145E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[225] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[226] = new CustomVertex.PositionOnly(-1.077492E+09f, -1.077629E+09f, 1.094077E+09f);
vertices[227] = new CustomVertex.PositionOnly(1.070011E+09f, -1.077629E+09f, 1.094077E+09f);
vertices[228] = new CustomVertex.PositionOnly(-1.076595E+09f, -1.057113E+09f, 1.096987E+09f);
vertices[229] = new CustomVertex.PositionOnly(-1.077358E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[230] = new CustomVertex.PositionOnly(-1.077492E+09f, -1.077629E+09f, 1.094077E+09f);
vertices[231] = new CustomVertex.PositionOnly(-1.077358E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[232] = new CustomVertex.PositionOnly(1.070145E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[233] = new CustomVertex.PositionOnly(1.070907E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[234] = new CustomVertex.PositionOnly(-1.077358E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[235] = new CustomVertex.PositionOnly(1.070907E+09f, 1.090325E+09f, 1.096987E+09f);
vertices[236] = new CustomVertex.PositionOnly(-1.077743E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[237] = new CustomVertex.PositionOnly(1.069759E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[238] = new CustomVertex.PositionOnly(-1.077835E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[239] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[240] = new CustomVertex.PositionOnly(-1.077743E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[241] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[242] = new CustomVertex.PositionOnly(1.069303E+09f, 1.088546E+09f, 1.092408E+09f);
vertices[243] = new CustomVertex.PositionOnly(1.069759E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[244] = new CustomVertex.PositionOnly(-1.077833E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[245] = new CustomVertex.PositionOnly(-1.077743E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[246] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[247] = new CustomVertex.PositionOnly(1.069759E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[248] = new CustomVertex.PositionOnly(1.069305E+09f, -1.069208E+09f, 1.092408E+09f);
vertices[249] = new CustomVertex.PositionOnly(-1.077743E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[250] = new CustomVertex.PositionOnly(-1.077492E+09f, -1.077629E+09f, 1.094077E+09f);
vertices[251] = new CustomVertex.PositionOnly(-1.077358E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[252] = new CustomVertex.PositionOnly(1.070011E+09f, -1.077629E+09f, 1.094077E+09f);
vertices[253] = new CustomVertex.PositionOnly(1.070145E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[254] = new CustomVertex.PositionOnly(1.069759E+09f, -1.072313E+09f, 1.09337E+09f);
vertices[255] = new CustomVertex.PositionOnly(-1.077358E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[256] = new CustomVertex.PositionOnly(-1.077492E+09f, 1.069426E+09f, 1.094077E+09f);
vertices[257] = new CustomVertex.PositionOnly(1.070145E+09f, 1.056938E+09f, 1.094454E+09f);
vertices[258] = new CustomVertex.PositionOnly(1.070011E+09f, 1.069426E+09f, 1.094077E+09f);
vertices[259] = new CustomVertex.PositionOnly(-1.077358E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[260] = new CustomVertex.PositionOnly(1.070145E+09f, -1.089674E+09f, 1.094454E+09f);
vertices[261] = new CustomVertex.PositionOnly(-1.077743E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[262] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[263] = new CustomVertex.PositionOnly(1.069759E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[264] = new CustomVertex.PositionOnly(1.069305E+09f, 1.078184E+09f, 1.092408E+09f);
vertices[265] = new CustomVertex.PositionOnly(1.069759E+09f, 1.074956E+09f, 1.09337E+09f);
vertices[266] = new CustomVertex.PositionOnly(-1.077833E+09f, 1.078184E+09f, 1.092408E+09f);
//end

short[] indices = new short[] { 1, 0, 2, 4, 3, 1, 6, 5, 4, 8, 7, 9, 1, 10, 11, 4, 1, 9, 8, 9, 1, 35, 34, 36, 36, 37, 35, 39, 38, 40, 40, 41, 39, 43, 42, 44, 42, 43, 45, 46, 45, 43, 45, 46, 47, 48, 47, 46, 47, 48, 49, 50, 49, 48, 49, 50, 51, 53, 52, 51, 51, 50, 53, 55, 54, 44, 44, 42, 55, 12, 11, 10, 13, 8, 14, 15, 8, 13, 17, 16, 18, 20, 19, 17, 22, 21, 20, 24, 23, 25, 26, 18, 27, 20, 17, 22, 28, 22, 17, 57, 56, 58, 58, 59, 57, 61, 60, 62, 62, 63, 61, 65, 64, 66, 64, 65, 67, 68, 67, 65, 67, 68, 69, 70, 69, 68, 69, 70, 71, 72, 71, 70, 71, 72, 73, 75, 74, 73, 73, 72, 75, 77, 76, 66, 66, 64, 77, 29, 27, 30, 31, 24, 32, 33, 28, 31, 79, 78, 80, 80, 81, 79, 83, 82, 84, 84, 85, 83, 87, 86, 88, 86, 87, 89, 90, 89, 87, 89, 90, 91, 92, 91, 90, 91, 92, 93, 94, 93, 92, 93, 94, 95, 97, 96, 95, 95, 94, 97, 99, 98, 88, 88, 86, 99, 101, 100, 102, 102, 103, 101, 105, 104, 106, 106, 107, 105, 109, 108, 110, 108, 109, 111, 112, 111, 109, 111, 112, 113, 114, 113, 112, 113, 114, 115, 116, 115, 114, 115, 116, 117, 119, 118, 117, 117, 116, 119, 121, 120, 110, 110, 122, 121, 124, 123, 125, 126, 125, 123, 128, 127, 129, 130, 129, 127, 132, 131, 133, 134, 133, 131, 136, 135, 137, 138, 137, 135, 140, 139, 141, 142, 141, 139, 144, 143, 145, 146, 145, 143, 148, 147, 149, 147, 148, 150, 152, 151, 153, 151, 152, 154, 156, 155, 157, 155, 156, 158, 160, 159, 161, 159, 160, 162, 164, 163, 165, 166, 165, 163, 168, 167, 169, 170, 169, 167, 172, 171, 173, 174, 173, 171, 176, 175, 177, 178, 177, 175, 180, 179, 181, 183, 182, 184, 186, 185, 187, 189, 188, 190, 192, 191, 193, 195, 194, 196, 198, 197, 199, 201, 200, 202, 204, 203, 205, 207, 206, 208, 210, 209, 211, 213, 212, 214, 216, 215, 213, 218, 217, 219, 221, 220, 222, 224, 223, 225, 226, 209, 210, 218, 227, 217, 229, 228, 230, 213, 229, 231, 218, 232, 227, 222, 232, 233, 213, 209, 234, 218, 235, 232, 236, 215, 214, 221, 237, 220, 239, 238, 240, 242, 241, 243, 245, 244, 246, 248, 247, 249, 251, 250, 252, 252, 253, 251, 250, 249, 254, 254, 252, 250, 256, 255, 257, 257, 258, 256, 255, 259, 260, 260, 257, 255, 262, 261, 263, 265, 264, 266, 261, 256, 258, 258, 263, 261 };

mesh.SetVertexBufferData(vertices, LockFlags.None);
mesh.SetIndexBufferData(indices, LockFlags.None);

int[] adjacency = new int[mesh.NumberFaces * 3];
mesh.GenerateAdjacency(0.01F, adjacency);
mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency);
numSubSets = mesh.GetAttributeTable().Length;
}


protected void SetupMatrices()
{
float angle = Environment.TickCount / 500.0F;
device.Transform.World = Matrix.RotationYawPitchRoll(angle, angle / 3.0F, 0);
device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0.5F, -1000), new Vector3(0, 0.5F, 0), new Vector3(0, 1, 0));
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 400.0F, 1.0F, 900.0F, 1100.0F);
}


protected void Render()
{
if (deviceLost){
AttemptRecovery();
}

if (deviceLost){
return;
}

device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.SkyBlue, 1.0F, 0);

device.BeginScene();

SetupMatrices();

device.RenderState.FillMode = FillMode.Solid;
SetupMaterials(Color.Red);

device.RenderState.DepthBias = 0.1F;

// Draw the cube
for (int i = 0; i < numSubSets; ++i){
mesh.DrawSubset(i);
}

device.RenderState.DepthBias = 0F;
device.EndScene();

try{
device.Present();
}
catch (DeviceLostException){
deviceLost = true;
}
}


protected void AttemptRecovery()
{
int res;
device.CheckCooperativeLevel(out res);
ResultCode rc = (ResultCode)res;

if (rc == ResultCode.DeviceLost){
}
else if (rc == ResultCode.DeviceNotReset){
try{
device.Reset(pres);
deviceLost = false;
}
catch (DeviceLostException){
}
}
}

//end of everything
}
}

Share this post


Link to post
Share on other sites
ernow    732
Did you compare the range of the values? Chances are that your model is out of bounds or very small or has it's winding reversed...

I learned a lot from the MD2 and MD3 specs (very easy btw) and created yet my own file format (it's MD2 in Xml)

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this