把3ds转化为x文件后有很多问题(试了好多转换工具都不行,如果你有好工具别忘了告诉我),因此决心直接解析3DS文件然后用mesh显示。
解析3DS文件网上有好多代码,但我就只找到一个是C#写的,C#的太多资源仍然稀缺啊
http://www.nabble.com/3DS-File-loader-t1663534.html
它是用OpenGL显示的,我还得把它移植到MDX上来。
(C++写的解析显示3DS的代码,目前我只找到了几个opengl的,没找到directx的,如果你知道不要忘了告诉我啊)
还有许多细节上的问题…………
全部的源代码:http://bbs.gameres.com/showthread.asp?page=end&threadid=83967
代码仅Form1.cs是我写的,其他的是来自(http://www.nabble.com/3DS-File-loader-t1663534.html),仅有少许修改。
当前的显示还有一些问题,有一些三角形显示不出来,又有一些三角形是多余的,可是我的顶点和索引解析不会有问题呀,郁闷,期待大家一起帮忙完善。
Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace ThreeD
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Device device = null;
private Mesh mesh = null;
private Material[] meshMaterials;
private Texture[] meshTextures;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private float angle = 0.0f;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}
/// <summary>
/// We will initialize our graphics device here
/// </summary>
public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters presentParams = new PresentParameters();