游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2617|回复: 1

3dmax官方导出插件(3ds,ASE等)导出的文件中,顶点法线有没

[复制链接]

11

主题

23

帖子

23

积分

注册会员

Rank: 2

积分
23
发表于 2007-4-16 11:10:00 | 显示全部楼层 |阅读模式

我看过一些读取3ds文件和ASE文件的OpenGL源码,那些代码里法线都自己重新计算,都不用直接从3dmax导出的法线,3dmax的导出插件(比如3ds和ASE)本身不就导出了顶点法线了吗?何必再自己计算?

另外,我写了一个3dmax的导出插件,也发现顶点,纹理,索引等等都没问题,唯独法线不太对。

请问写过或了解3dmax导出插件的高手,3dmax的法线用到游戏中是不是有问题,是不是要自己重新计算顶点法线?

30

主题

422

帖子

433

积分

中级会员

Rank: 3Rank: 3

积分
433
发表于 2007-4-18 13:41:00 | 显示全部楼层

Re:3dmax官方导出插件(3ds,ASE等)导出的文件中,顶点法线有

自定义的法线导不出来,smooth group的法线可以导出来。

参考nmaxtoolbox,在nebula2/code/contrib/nmax
//-----------------------------------------------------------------------------
/**
   Get vertex normal.
*/
Point3 nMaxMesh::GetVertexNormal(Mesh* mesh, int faceNo, RVertex* rv)
{
    Face* f = &mesh->faces[faceNo];
    DWORD smGroup = f->smGroup;
    int numNormals;
    Point3 vertexNormal;

    // Is normal specified
    // SPECIFIED_NORMAL is not currently used, but may be used in future versions.
    if (rv->rFlags & SPECIFIED_NORMAL) //*** 看注释 ***
    {
        vertexNormal = rv->rn.getNormal();
    }
    // If normal is not specified it's only available if the face belongs
    // to a smoothing group
    else
    if ((numNormals = rv->rFlags & NORCT_MASK) && smGroup)
    {
        // If there is only one vertex is found in the rn member.
        if (numNormals == 1)
        {
            vertexNormal = rv->rn.getNormal();
        }
        else
        {
            // If two or more vertices are there you need to step through them
            // and find the vertex with the same smoothing group as the current face.
            // You will find multiple normals in the ern member.
            for (int i = 0; i < numNormals; i++)
            {
                if (rv->ern.getSmGroup() & smGroup)
                {
                    vertexNormal = rv->ern.getNormal();
                }
            }
        }
    }
    else
    {
        // Get the normal from the Face if no smoothing groups are there
        vertexNormal = mesh->getFaceNormal(faceNo);
    }

    return vertexNormal;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 18:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表