XNA中的自定义内容管道,如何手动设置漫反射纹理?
XNA 非常出色,但我仍然无法完全理解自定义内容管道。
一些基本示例(例如 MSDN 的法线贴图示例)向您展示了如何将 .fbx 文件中不透明数据的法线贴图键分配给要加载的适当法线贴图纹理。我什至不知道他们如何知道密钥应该命名什么,不透明数据实际上是什么,是否在 .fbx 文件中定义。
有趣的是,内容管道中没有代码说明如何设置漫反射纹理 - 这似乎暗示您使用名为“Texture”的阴影参数,并且它们会自动设置。但如果我将参数重命名为其他名称,则模型加载时不会有纹理。
它如何隐式知道加载漫反射纹理,例如,我如何加载要使用不同名称的着色器参数读取的漫反射纹理,并加载默认的中性白色纹理文件(如果不存在)?
就此而言,是否有一个“hello world”示例来学习使用内容管道自定义加载模型?
请注意,我不想通过在属性窗口中设置纹理来覆盖 .fbx 模型中的现有纹理引用。
XNA is the bee's knees but I still can't wrap my head completely around custom content pipelines.
Some basic samples like MSDN's normal map sample shows you how to assign normal map keys from opaque data from an .fbx file to the appropriate normal map textures to load. I don't even know how they knew what the key should be named, what opaque data actually is, if it's defined in the .fbx file or not.
The interesting thing is that there's no code in the content pipeline that says how diffuse textures are set- it seems to imply that you use a shade parameter named "Texture" and they get set automatically. But if I rename the parameter to something else, the models load with no textures.
How does it implicitly know to load diffuse textures, and how can I, for example, load diffuse textures to be read with differently named shader parameter and load a default neutral-white texture file if one doesn't exist?
For that matter, is there a "hello world" example for learning to custom load models with the content pipeline?
Note, that I am not looking to override existing texture references in the .fbx models by setting a texture in the properties window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要了解的是,XNA 允许创建两个单独的自定义内容管道项:一个是导入器,另一个是处理器。
当您编写导入程序时,您可以按照您想要的方式解析任何文件,并将所需的信息存储到您指定的任何类(对象)中。您可以自己编写类或使用 XNA 中的某些类。通过这种方式,您可以简单地编写一个导入器,从您的文件中获取数据,并使用内置的 ModelProcessor 将其转换为 XNA 模型类对象。
以下是自定义模型导入器的示例:
http://create.msdn .com/en-US/education/catalog/sample/custom_model_importer
如果您需要模型以外的其他对象,请编写自定义处理器:
处理器获取导入器指定的类对象并将其转换为另一个类(既然你正在写它,任何类和你指定的任何方式)。此类用于生成 .xnb 文件(XNA 二进制文件),该文件在运行时由游戏读取。因此,所有这些都仅在编译时运行,以便您更好地控制游戏内容。
这是一个很好的入门链接:
http:// /msdn.microsoft.com/en-us/library/bb447754(v=xnagamestudio.20).aspx
对于您的情况,听起来您不满意默认 FBX 导入器的行为。如果是这种情况,您很可能必须自己编写。不过,您很可能不需要编写自己的处理器;将 ModelProcessor 指定为默认值,就像我的第一个链接中的项目所做的那样。
The first thing to understand is that XNA allows two separate custom content pipeline items to be created: one is an importer and the other is a processor.
When you write an importer, you parse any file how you want to and store the information you want into any class (object) that you specify. You can write the class yourself OR use certain classes within XNA. In this fashion you can simply write an importer that takes data from your file and, using the built-in ModelProcessor, makes that into an XNA Model class object.
Here is a sample of a custom model importer:
http://create.msdn.com/en-US/education/catalog/sample/custom_model_importer
If you need some other object than a Model, write a custom processor:
A processor takes the class object specified by the importer and converts this to yet another class (since you're writing it, any class and in any way you specify). This class gets used to generate a .xnb file (XNA binary), which is read at runtime by your game. All of this, therefore, is only run during compile time, in an effort to give you better control of your game's contents.
This is a good link to get started:
http://msdn.microsoft.com/en-us/library/bb447754(v=xnagamestudio.20).aspx
For your case it sounds like you are unhappy with the behavior of the default FBX importer. If this is the case, you would most likely have to write your own. You most likely do not need to write your own processor though; specify ModelProcessor as the default, just as the project in my first link has done.