0

无论如何,使用 C# 和 XNA 来创建一个可以调用的方法并让它加载一个 3D 模型并显示它?(换句话说,一个通用的 3D Tmodel 加载方法和一个通用的 3D 模型显示方法)。而不是为每个 3D 模型使用长代码?例如,不是所有的长代码都有一个带有加载代码的方法,该方法需要两个参数(3DModelName,fileLocation),然后有一个包含所有 3D 绘图代码的方法,它需要两个参数(3DModelName,位置)。这可能吗?先谢谢了。

4

1 回答 1

0

不确定我是否完全理解您的要求,但以下是非常标准的 Xna,它尽可能简短和简单。

文件位置在 Xna 中实际上是无关紧要的。您只需将文件(fbx 或 x)添加到解决方案资源管理器中的内容项目,您无需关心代码中的文件位置。

//in the fields section of some class
Model myModel;

//in an initialization or loadContent method of the same class
myModel = LoadMyModel(name, Content);

//load & draw methods that can be called any time as long as they are in scope
Model LoadMyModel(string name, ContentManager content)
{
  return content.Load<Model>(name);
}

void DrawModel(Model myModel, Matrix worldTransform, Matrix view, Matrix projection)
{
   myModel.Draw(worldTransform, view, projection);
}
于 2013-08-22T05:03:16.870 回答