Пример #1
0
        static bool GetMeshForComponent(object exporter, ProBuilderMesh pmesh, object node)
        {
            Mesh mesh = new Mesh();

            MeshUtility.Compile(pmesh, mesh, m_FbxOptions.quads ? MeshTopology.Quads : MeshTopology.Triangles);

            // using reflection to call: exporter.ExportMesh(mesh, node, pmesh.GetComponent<MeshRenderer>().sharedMaterials)
            var pMeshRenderer    = pmesh.GetComponent <MeshRenderer>();
            var sharedMaterials  = pMeshRenderer ? pMeshRenderer.sharedMaterials : null;
            var exportMeshMethod = exporter.GetType().GetMethod("ExportMesh", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Mesh), node.GetType(), typeof(Material[]) }, null);

            exportMeshMethod.Invoke(exporter, new object[] { mesh, node, sharedMaterials });

            Object.DestroyImmediate(mesh);

            // probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
            foreach (var type in k_ProBuilderTypes)
            {
                var component = pmesh.GetComponent(type);
                if (component != null)
                {
                    Object.DestroyImmediate(component);
                }
            }

            pmesh.preserveMeshAssetOnDestroy = true;
            Object.DestroyImmediate(pmesh);

            return(true);
        }
Пример #2
0
        static bool GetMeshForPBComponent(ModelExporter exporter, ProBuilderMesh pmesh, Autodesk.Fbx.FbxNode node)
        {
            Mesh mesh = new Mesh();

            MeshUtility.Compile(pmesh, mesh, s_FbxOptions.quads ? MeshTopology.Quads : MeshTopology.Triangles);

            var pMeshRenderer   = pmesh.GetComponent <MeshRenderer>();
            var sharedMaterials = pMeshRenderer ? pMeshRenderer.sharedMaterials : null;

            exporter.ExportMesh(mesh, node, sharedMaterials);

            Object.DestroyImmediate(mesh);

            //Need to have ExportOptions accessible to remove this reflection
            var exporterType = exporter.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                               .First(x => x.Name == "get_ExportOptions").Invoke(exporter, null).GetType();

            if (exporterType == typeof(ConvertToPrefabSettingsSerialize))
            {
                // probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
                StripProBuilderScripts.DoStrip(pmesh);
            }

            return(true);
        }
Пример #3
0
        static bool GetMeshForComponent(ModelExporter exporter, ProBuilderMesh pmesh, FbxNode node)
        {
            Mesh mesh = new Mesh();

            MeshUtility.Compile(pmesh, mesh, m_FbxOptions.quads ? MeshTopology.Quads : MeshTopology.Triangles);
            exporter.ExportMesh(mesh, node, pmesh.GetComponent <MeshRenderer>().sharedMaterials);
            Object.DestroyImmediate(mesh);

            // probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
            foreach (var type in k_ProBuilderTypes)
            {
                var component = pmesh.GetComponent(type);
                if (component != null)
                {
                    Object.DestroyImmediate(component);
                }
            }

            pmesh.preserveMeshAssetOnDestroy = true;
            Object.DestroyImmediate(pmesh);

            return(true);
        }