示例#1
0
        public IndexedResource <Material> ForceExport(Material mat)
        {
            foreach (var h in Hooks)
            {
                var r = h.Export(this, mat);
                if (r != null)
                {
                    return(r);
                }
            }

            // Maybe, Standard shader...
            // TODO: Support various shaders
            var tex = mat.GetTexture("_MainTex") as Texture2D;
            IndexedResource <Texture2D> textureResource = null;

            if (tex != null)
            {
                textureResource = Textures.Export(tex);
            }

            var gltfMaterial = new Types.Material
            {
                Name = mat.name,

                PbrMetallicRoughness = new Types.Material.PbrMetallicRoughnessType
                {
                    BaseColorTexture = textureResource != null ? new Types.Material.BaseColorTextureInfoType
                    {
                        Index    = textureResource.Index,
                        TexCoord = 0,       // NOTE: mesh.primitive must have TEXCOORD_<TexCoord>.
                    } : null,               // TODO: fix
                    MetallicFactor  = 0.0f, // TODO: fix
                    RoughnessFactor = 1.0f, // TODO: fix
                },
            };

            return(new IndexedResource <Material>
            {
                Index = Types.GltfExtensions.AddMaterial(Gltf, gltfMaterial),
                Value = mat,
            });
        }
示例#2
0
        public IndexedResource <Transform> ForceExport(Transform trans)
        {
            var go = trans.gameObject;

            IndexedResource <Mesh> meshResource = null;
            int?skinIndex = null;
            var mr        = go.GetComponent <MeshRenderer>();
            var smr       = go.GetComponent <SkinnedMeshRenderer>();

            if (mr != null)
            {
                var meshFilter = mr.gameObject.GetComponent <MeshFilter>();
                var sharedMesh = meshFilter.sharedMesh;

                meshResource = Meshes.Export(mr, sharedMesh);
            }
            else if (smr != null)
            {
                var sharedMesh = smr.sharedMesh;
                meshResource = Meshes.Export(smr, sharedMesh);

                if (smr.bones.Length > 0)
                {
                    skinIndex = ExportSkin(smr, sharedMesh).Index;
                }
            }

            var t        = CoordUtils.ConvertSpace(go.transform.localPosition);
            var r        = CoordUtils.ConvertSpace(go.transform.localRotation);
            var s        = go.transform.localScale;
            var gltfNode = new Types.Node
            {
                Name = go.name,

                Mesh = meshResource != null ? (int?)meshResource.Index : null,
                Skin = skinIndex,

                Matrix      = null,
                Translation = new float[] { t.x, t.y, t.z },
                Rotation    = new float[] { r.x, r.y, r.z, r.w },
                Scale       = new float[] { s.x, s.y, s.z },
            };

            var nodesIndices = new List <int>();

            for (int i = 0; i < go.transform.childCount; ++i)
            {
                var c            = go.transform.GetChild(i);
                var nodeResource = Export(c.gameObject);
                nodesIndices.Add(nodeResource.Index);
            }
            if (nodesIndices.Count > 0)
            {
                gltfNode.Children = nodesIndices.ToArray();
            }

            foreach (var h in Hooks)
            {
                h.PostHook(this, trans, gltfNode);
            }

            return(new IndexedResource <Transform>
            {
                Index = Types.GltfExtensions.AddNode(Gltf, gltfNode),
                Value = trans,
            });
        }