Exemplo n.º 1
0
        private FBXNode CreateFbxMesh(MeshLodSection section, FBXScene pScene)
        {
            FBXMesh fbxMesh = FBXMesh.Create(pScene, section.matName);
            FBXGeometryElementNormal lGeometryElementNormal = fbxMesh.CreateElementNormal();

            lGeometryElementNormal.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            FBXGeometryElementBinormal lGeometryElementBiNormal = fbxMesh.CreateElementBinormal();

            lGeometryElementBiNormal.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            FBXGeometryElementTangent lGeometryElementTangent = fbxMesh.CreateElementTangent();

            lGeometryElementTangent.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            fbxMesh.InitControlPoints(section.vertices.Count);
            FBXGeometryElementMaterial lMaterialElement = fbxMesh.CreateElementMaterial();

            lMaterialElement.SetMappingMode(FBXWrapper.MappingMode.eByPolygon);
            lMaterialElement.SetReferenceMode(FBXWrapper.ReferenceMode.eIndexToDirect);
            FBXGeometryElementUV lUVDiffuseElement = fbxMesh.CreateElementUV(section.matName);

            lUVDiffuseElement.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            lUVDiffuseElement.SetReferenceMode(FBXWrapper.ReferenceMode.eIndexToDirect);
            lUVDiffuseElement.SetIndexArrayCount(section.vertices.Count);
            for (int j = 0; j < section.vertices.Count; j++)
            {
                FBXVector4 position   = new FBXVector4(section.vertices[j].position.members[0] * exportScale, section.vertices[j].position.members[1] * exportScale, section.vertices[j].position.members[2] * exportScale, 0);
                FBXVector4 normal     = new FBXVector4(section.vertices[j].normals.members[0], section.vertices[j].normals.members[1], section.vertices[j].normals.members[2], section.vertices[j].normals.members[3]);
                FBXVector4 textCoords = new FBXVector4(section.vertices[j].texCoords.members[0], (-section.vertices[j].texCoords.members[1] + 1), 0, 0);
                FBXVector4 bitangent  = new FBXVector4(section.vertices[j].biTangents.members[0], section.vertices[j].biTangents.members[1], section.vertices[j].biTangents.members[2], section.vertices[j].biTangents.members[3]);
                FBXVector4 tangent    = new FBXVector4(section.vertices[j].tangents.members[0], section.vertices[j].tangents.members[1], section.vertices[j].tangents.members[2], section.vertices[j].tangents.members[3]);
                fbxMesh.SetControlPoint(j, position);
                lGeometryElementNormal.Add(normal);
                lGeometryElementBiNormal.Add(bitangent);
                lGeometryElementTangent.Add(tangent);
                lUVDiffuseElement.Add(textCoords);
            }

            for (int j = 0; j < section.indicies.Count; j++)
            {
                if (j % 3 == 0)
                {
                    fbxMesh.EndPolygon();
                    fbxMesh.BeginPolygon();
                }
                fbxMesh.AddPolygon(section.indicies[j]);
            }
            fbxMesh.EndPolygon();
            FBXNode lMeshNode = FBXNode.Create(pScene, section.matName);

            lMeshNode.SetNodeAttribute(fbxMesh);
            lMeshNode.AddMaterial(pScene, section.matName);
            return(lMeshNode);
        }
Exemplo n.º 2
0
        private FBXNode CreateFbxMesh(MeshLOD lod, FBXScene pScene)
        {
            FBXMesh fbxMesh   = FBXMesh.Create(pScene, lod.shortName);
            FBXNode lMeshNode = FBXNode.Create(pScene, lod.shortName);

            lMeshNode.SetNodeAttribute(fbxMesh);
            FBXGeometryElementNormal lGeometryElementNormal = fbxMesh.CreateElementNormal();

            lGeometryElementNormal.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            FBXGeometryElementBinormal lGeometryElementBiNormal = fbxMesh.CreateElementBinormal();

            lGeometryElementBiNormal.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            FBXGeometryElementTangent lGeometryElementTangent = fbxMesh.CreateElementTangent();

            lGeometryElementTangent.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
            FBXGeometryElementMaterial lMaterialElement = fbxMesh.CreateElementMaterial();

            lMaterialElement.SetMappingMode(FBXWrapper.MappingMode.eByPolygon);
            lMaterialElement.SetReferenceMode(FBXWrapper.ReferenceMode.eIndexToDirect);
            int verticesCount = lod.GetLODTotalVertCount();

            fbxMesh.InitControlPoints(verticesCount);
            List <FBXGeometryElementUV> UVs = new List <FBXGeometryElementUV>();

            for (int i = 0; i < lod.sections.Count; i++)
            {
                MeshLodSection       section           = lod.sections[i];
                FBXGeometryElementUV lUVDiffuseElement = fbxMesh.CreateElementUV(section.matName);
                lUVDiffuseElement.SetMappingMode(FBXWrapper.MappingMode.eByControlPoint);
                lUVDiffuseElement.SetReferenceMode(FBXWrapper.ReferenceMode.eDirect);
                UVs.Add(lUVDiffuseElement);
            }
            int VertexOffset = 0;

            for (int i = 0; i < lod.sections.Count; i++)
            {
                MeshLodSection section = lod.sections[i];
                for (int j = 0; j < section.vertices.Count; j++)
                {
                    FBXVector4 position   = new FBXVector4(section.vertices[j].position.members[0] * exportScale, section.vertices[j].position.members[1] * exportScale, section.vertices[j].position.members[2] * exportScale, 0);
                    FBXVector4 normal     = new FBXVector4(section.vertices[j].normals.members[0], section.vertices[j].normals.members[1], section.vertices[j].normals.members[2], section.vertices[j].normals.members[3]);
                    FBXVector4 textCoords = new FBXVector4(section.vertices[j].texCoords.members[0], (-section.vertices[j].texCoords.members[1] + 1), 0, 0);
                    FBXVector4 bitangent  = new FBXVector4(section.vertices[j].biTangents.members[0], section.vertices[j].biTangents.members[1], section.vertices[j].biTangents.members[2], section.vertices[j].biTangents.members[3]);
                    FBXVector4 tangent    = new FBXVector4(section.vertices[j].tangents.members[0], section.vertices[j].tangents.members[1], section.vertices[j].tangents.members[2], section.vertices[j].tangents.members[3]);
                    fbxMesh.SetControlPoint(VertexOffset + j, position);
                    lGeometryElementNormal.Add(normal);
                    lGeometryElementBiNormal.Add(bitangent);
                    lGeometryElementTangent.Add(tangent);
                    int uvI = 0;
                    foreach (FBXGeometryElementUV uv in UVs)
                    {
                        if (uvI == i)
                        {
                            uv.Add(textCoords);
                        }
                        else
                        {
                            uv.Add(new FBXVector4(0, 0, 0, 0));
                        }
                        uvI++;
                    }
                }
                for (int j = 0; j < section.indicies.Count; j++)
                {
                    if (j % 3 == 0)
                    {
                        fbxMesh.EndPolygon();
                        fbxMesh.BeginPolygon(i);
                    }
                    fbxMesh.AddPolygon(VertexOffset + section.indicies[j]);
                }
                fbxMesh.EndPolygon();
                VertexOffset = VertexOffset + section.vertices.Count;
                lMeshNode.AddMaterial(pScene, section.matName);
            }
            return(lMeshNode);
        }