65.9K
CodeProject 正在变化。 阅读更多。
Home

Game Exchange 2 文件加载器 GE2

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1投票)

2002年5月17日

3分钟阅读

viewsIcon

70738

downloadIcon

841

从 Maya 导出的 GE2 文件中加载 3D 场景。

引言

首先,介绍一下代码的背景知识。

它是什么

这是一个小巧的类,可以加载 Maya 导出的 GE2 文件格式。

它可以用来做什么

你可以使用它来加载由 Maya GE2 文件格式导出的场景或对象。然后,你可以进一步修改这些结构和数据,或者渲染它。总而言之,如果你想加载 Maya 对象,请在你的 3D 引擎中使用它。

它是如何工作的

它的预期使用方式是这样的

  1. 只需将 ge2loader.cpphpp 包含到你的项目中。
  2. 继续创建该对象的实例。
  3. 使用文件名(提供示例对象)调用 loadGroup 方法。

请注意,如果你真的不了解 GE2 是什么,请做一些研究。或者至少看看示例对象(创造性地称为 Dork)中的文件结构。

  1. #include "..\MODULES\objGameExchange2\ge2loader.hpp"
  2. class ge gameExchange;
    void main ( void ) 
    {
  3.   int ret = gameExchange.loadGroup("dork\\dork.grp");
      if ( ret==-1) cout << "error\n\n";
    }

我认为,除非有人打算将其插入 3D 渲染环境中,否则这个类对任何人来说都不会非常有用。在我看来,GE2 导出可能是你在 Maya 中获得的所有可用导出器中最有用的。未来的计划是编写一个编辑器,利用这个 GE2;该编辑器是一个中间工具,用于微调场景以进行游戏开发。诸如纹理、BSP 生成等...我知道这是一个很大的梦想,但我以前也有过很大的梦想,只需看看我的主页即可。

目前,我不会详细介绍文件格式或加载器代码本身。但请放心,它确实有效。请访问 我的主页,以获取有关我的小编码项目的更多信息。

有些人问我如何使用数据结构进行渲染,我包含了这封电子邮件,我在其中解释了如何使用数据结构。

我回复 Mondi 的问题

很抱歉回复晚了,我一直不愿查找信息来帮助你,主要是因为我知道我很久以前就丢失了此代码的源代码 :( 无论如何,我今天很无聊,决定从我的主页下载 ge2loader.zip,快速浏览一下,并尝试向你解释一些事情 :)。因此,参考 ge2loader.zip。该对象名为 a,在我的演示代码中。

a.obj.cout 告诉我总共有 6 个对象需要渲染。这些对象存在于 a.obj.o[0]a.obj.o.[5]

一个对象由以下组成

  • 名称
  • vertList (顶点列表)
  • normList (法线列表)
  • uvList (uv 列表)
  • faceParts (面部部分)
  • triCount (三角形计数)
  • tri (三角形)

好的,让我们来做一个理论上的例子。你想做的是渲染第一个三角形。如果你调试演示代码并查看结构,你会看到第一个名为 "InsideFaceShape" 的对象的第一个 Tri 扩展到

  • v[0] = 454
  • v[1] = 455
  • v[2] = 1

这告诉我要查找那些顶点

所以,要渲染第一个对象的第一个 tri

Beginrender() {

// this demonstrates access to the first vertex
// a. : the entire ge2 structure with all the various files
// a.obj : a pointer to an array with count and another pointer o
// a.obj.o: another pointer to an array of objects

// ok, the first object a.obj.o[0]
// is made up of many triangles a.obj.o[0].tricount
// a.obj.o[0].tri is a pointer to indexes to the real float values
// the idea is to grab an idex a.obj.o[o].tri[0].v[0]
// this is actually the number 454 according to my demo
// this means you want vertex number 454 from the vertex array

// for example, a.obj.o[0].vertList.v[0].x
// this is the first vertex float value for the x-coordinate
// BUT! this is not the X coord for the first point of the first triangle
// it is simply a list of vertecies , and the idea is to access them
// with indexes
// in the same way, you can access the UV's and normals 

// whew.. I hope this helps somewhat.. 

glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[0]].z,
)

glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[1]].z,
)

glvertex3f (
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].x,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].y,
a.obj.o[0].vertList.v[a.obj.o[0].tri[0].v[2]].z,
)
}

好的,现在我知道这看起来非常复杂,当我编写这段代码时,我一直在赶时间,并且没有很好地考虑这些结构。可能让你困惑的事情之一是 Objo... 相反,我应该命名

  • Obj 命名为 ObjList
  • 并将 o 命名为 Obj

另一个是 faceParts,我不记得了... 但它是什么每个三角形都有一个材质描述... 分析它的最好方法是启动调试模式并在监视列表中展开该结构。

就此而言,对于一个大型项目,它可能不够好,但它对于将所有文本文件加载到结构中非常有用,并且希望对于测试非常有用。

> "mondi"  "RJ++" <robertj@nettaxi.com> [CodeProject] 
> Game Exchange 2 File LoaderDate: Sun, 27 Oct 2002 05:32:17 -0500
>
>Hi there,
>
>I've been experimenting with the ge2 format for awhile now, 
>your code helped me clear up a few issues i was having.
>
>question though, being not a terribly good programmer 
>could you point me in the right direction for
>accessing the vertex/face/normal lists so that 
>I could get my app to render the objects?
>
>it would be incredibly helpful :)
>
>thanks
>
>mondi
© . All rights reserved.