Exemplo n.º 1
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);
        }
    public void StripProBuilderScripts_RemovesMeshAndShapeComponents()
    {
        var go    = new GameObject();
        var shape = go.AddComponent <ProBuilderShape>();

        shape.Rebuild(new Bounds(Vector3.zero, Vector3.one), Quaternion.identity, Vector3.zero);

        Assume.That(go.GetComponent <ProBuilderMesh>() != null);
        Assume.That(go.GetComponent <ProBuilderShape>() != null);

        StripProBuilderScripts.DoStrip(go.GetComponent <ProBuilderMesh>());

        Assert.That(go.GetComponent <ProBuilderMesh>() == null);
        Assert.That(go.GetComponent <ProBuilderShape>() == null);

        UObject.DestroyImmediate(go);
    }
Exemplo n.º 3
0
    public void StripProBuilderScripts_RemovesMeshAndPolyShapeComponents()
    {
        var go   = new GameObject();
        var poly = go.AddComponent <PolyShape>();

        go.AddComponent <ProBuilderMesh>();
        poly.CreateShapeFromPolygon();

        Assume.That(go.GetComponent <ProBuilderMesh>() != null);
        Assume.That(go.GetComponent <PolyShape>() != null);

        StripProBuilderScripts.DoStrip(go.GetComponent <ProBuilderMesh>());

        Assert.That(go.GetComponent <ProBuilderMesh>() == null);
        Assert.That(go.GetComponent <PolyShape>() == null);

        UObject.DestroyImmediate(go);
    }
Exemplo n.º 4
0
    public void StripProBuilderScripts_RemovesMeshAndBezierComponents()
    {
        var go = new GameObject();

        go.AddComponent <ProBuilderMesh>();
        var bezier = go.AddComponent <BezierShape>();

        bezier.Init();
        bezier.Refresh();

        Assume.That(go.GetComponent <ProBuilderMesh>() != null);
        Assume.That(go.GetComponent <BezierShape>() != null);

        StripProBuilderScripts.DoStrip(go.GetComponent <ProBuilderMesh>());

        Assert.That(go.GetComponent <ProBuilderMesh>() == null);
        Assert.That(go.GetComponent <BezierShape>() == null);

        UObject.DestroyImmediate(go);
    }
Exemplo n.º 5
0
        public static void OnPostprocessScene()
        {
            var invisibleFaceMaterial = Resources.Load <Material>("Materials/InvisibleFace");

            var pbMeshes = (ProBuilderMesh[])Resources.FindObjectsOfTypeAll(typeof(ProBuilderMesh));

            // Hide nodraw faces if present.
            foreach (var pb in pbMeshes)
            {
                if (pb.GetComponent <MeshRenderer>() == null)
                {
                    continue;
                }

                if (pb.GetComponent <MeshRenderer>().sharedMaterials.Any(x => x != null && x.name.Contains("NoDraw")))
                {
                    Material[] mats = pb.GetComponent <MeshRenderer>().sharedMaterials;

                    for (int i = 0; i < mats.Length; i++)
                    {
                        if (mats[i].name.Contains("NoDraw"))
                        {
                            mats[i] = invisibleFaceMaterial;
                        }
                    }

                    pb.GetComponent <MeshRenderer>().sharedMaterials = mats;
                }
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            foreach (var entity in Resources.FindObjectsOfTypeAll <EntityBehaviour>())
            {
                if (entity.manageVisibility)
                {
                    entity.OnEnterPlayMode();
                }
            }

            foreach (var mesh in pbMeshes)
            {
                EditorUtility.SynchronizeWithMeshFilter(mesh);

                if (mesh.mesh == null)
                {
                    continue;
                }

                GameObject gameObject = mesh.gameObject;
                var        entity     = ProcessLegacyEntity(gameObject);

#if ENABLE_DRIVEN_PROPERTIES
                // clear editor-only HideFlags and serialization ignores
                mesh.ClearDrivenProperties();
                var filter = gameObject.DemandComponent <MeshFilter>();
                filter.hideFlags    = HideFlags.None;
                mesh.mesh.hideFlags = HideFlags.None;

                // Reassign the MeshFilter and MeshCollider properties _after_ clearing HideFlags and driven properties
                // to ensure that they are dirtied for serialization and thus included in the build
                filter.sharedMesh = mesh.mesh;
                if (mesh.TryGetComponent(out MeshCollider collider))
                {
                    collider.sharedMesh = mesh.mesh;
                }
#endif

                // early out if we're not planning to remove the ProBuilderMesh component
                if (m_ScriptStripping == false)
                {
                    continue;
                }

                StripProBuilderScripts.DestroyProBuilderMeshAndDependencies(gameObject, mesh, true);
            }
        }