예제 #1
0
        // -----------------------------------------
        // DumpMesh
        // -----------------------------------------

        void DumpMesh(Mesh _mesh, GLTF _gltf, BufferInfo _bufInfo, int _accOffset)
        {
            // dump buffer info
            DumpBufferInfoFromMesh(_mesh, _bufInfo);

            // dump mesh
            GLTF_Mesh gltfMesh = DumpGltfMesh(_mesh, _accOffset);

            _gltf.meshes.Add(gltfMesh);
        }
예제 #2
0
        // -----------------------------------------
        // DumpGltfMesh
        // -----------------------------------------

        GLTF_Mesh DumpGltfMesh(Mesh _mesh, int _accOffset)
        {
            GLTF_Mesh result = new GLTF_Mesh();
            Dictionary <string, int> attributes = new Dictionary <string, int>();
            int idx = 0;

            // name
            result.name = _mesh.name;

            // primitives
            result.primitives = new List <GLTF_Primitive>();

            // attributes
            if (_mesh.vertices.Length > 0)
            {
                attributes.Add("POSITION", _accOffset + idx);
                ++idx;
            }

            if (_mesh.normals.Length > 0)
            {
                attributes.Add("NORMAL", _accOffset + idx);
                ++idx;
            }

            if (_mesh.tangents.Length > 0)
            {
                attributes.Add("TANGENT", _accOffset + idx);
                ++idx;
            }

            if (_mesh.colors.Length > 0)
            {
                attributes.Add("COLOR_0", _accOffset + idx);
                ++idx;
            }

            if (_mesh.uv.Length > 0)
            {
                attributes.Add("TEXCOORD_0", _accOffset + idx);
                ++idx;
            }

            if (_mesh.uv2.Length > 0)
            {
                attributes.Add("TEXCOORD_1", _accOffset + idx);
                ++idx;
            }

            if (_mesh.uv3.Length > 0)
            {
                attributes.Add("TEXCOORD_2", _accOffset + idx);
                ++idx;
            }

            if (_mesh.uv4.Length > 0)
            {
                attributes.Add("TEXCOORD_3", _accOffset + idx);
                ++idx;
            }

            if (_mesh.boneWeights.Length > 0)
            {
                attributes.Add("JOINTS_0", _accOffset + idx);
                ++idx;

                attributes.Add("WEIGHTS_0", _accOffset + idx);
                ++idx;
            }

            // primitives
            if (_mesh.triangles.Length > 0)
            {
                int cnt = _mesh.subMeshCount;

                for (int i = 0; i < cnt; ++i)
                {
                    GLTF_Primitive primitive = new GLTF_Primitive();
                    primitive.attributes = attributes;
                    primitive.indices    = _accOffset + idx;
                    ++idx;

                    result.primitives.Add(primitive);
                }
            }
            else
            {
                GLTF_Primitive primitive = new GLTF_Primitive();
                primitive.attributes = attributes;

                result.primitives.Add(primitive);
            }

            return(result);
        }