Beispiel #1
0
        public void Reset()
        {
            ResetSettings();

            AssignMeshesFromPairs();

            GameObject obj = GameObject.Find("onion");

            if (obj)
            {
                targetObject.SetActive(false);
            }

            else
            {
                obj = GameObject.Find("Meat");
                if (obj)
                {
                    targetObject.SetActive(false);
                }
            }

            targetObject = barabarianRef;
            preserveFace.interactable         = true;
            preservationStrength.interactable = preserveFace.isOn;


            targetObject.SetActive(true);
            objectMeshPairs     = PolyfewRuntime.GetObjectMeshPairs(targetObject, true);
            trianglesCount.text = PolyfewRuntime.CountTriangles(true, targetObject) + "";

            exportButton.interactable         = false;
            importFromWeb.interactable        = true;
            importFromFileSystem.interactable = true;
        }
    public void ImportOBJFromNetwork()
    {
        // This function downloads and imports an obj file named onion.obj from the url below
        // This also loads the associated textures and materials given by the absolute URLs

        GameObject importedObject;

        isImportingFromNetwork = true;


        OBJImportOptions importOptions = new OBJImportOptions();

        importOptions.zUp           = false;
        importOptions.localPosition = new Vector3(0.87815f, 1.4417f, -4.4708f);
        importOptions.localScale    = new Vector3(0.0042f, 0.0042f, 0.0042f);


        string objURL         = "https://dl.dropbox.com/s/v09bh0hiivja10e/onion.obj?dl=1";
        string objName        = "onion";
        string diffuseTexURL  = "https://dl.dropbox.com/s/0u4ij6sddi7a3gc/onion.jpg?dl=1";
        string bumpTexURL     = "";
        string specularTexURL = "";
        string opacityTexURL  = "";
        string materialURL    = "https://dl.dropbox.com/s/fuzryqigs4gxwvv/onion.mtl?dl=1";


        progressSlider.value = 0;
        uninteractivePanel.SetActive(true);
        downloadProgress = new ReferencedNumeric <float>(0);

        StartCoroutine(UpdateProgress());

        PolyfewRuntime.ImportOBJFromNetwork(objURL, objName, diffuseTexURL, bumpTexURL, specularTexURL, opacityTexURL, materialURL, downloadProgress, (GameObject imp) =>
        {
            AssignMeshesFromPairs();
            isImportingFromNetwork = false;
            importedObject         = imp;
            barabarianRef.SetActive(false);
            targetObject = importedObject;
            ResetSettings();
            objectMeshPairs           = PolyfewRuntime.GetObjectMeshPairs(targetObject, true);
            trianglesCount.text       = PolyfewRuntime.CountTriangles(true, targetObject) + "";
            exportButton.interactable = true;
            uninteractivePanel.SetActive(false);
            importFromWeb.interactable        = false;
            importFromFileSystem.interactable = false;
            preserveFace.interactable         = false;
            preservationStrength.interactable = false;
            disableTemporary = true;
            preservationSphere.gameObject.SetActive(false);
            disableTemporary = false;
        },
                                            (Exception ex) =>
        {
            uninteractivePanel.SetActive(false);
            isImportingFromNetwork = false;
            Debug.LogError("Failed to download and import OBJ file.   " + ex.Message);
        }, importOptions);
    }
Beispiel #3
0
        // Start is called before the first frame update
        void Start()
        {
            if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                isWebGL = true;
            }

            uninteractivePanel.SetActive(false);
            exportButton.interactable = false;
            barabarianRef             = targetObject;
            objectMeshPairs           = PolyfewRuntime.GetObjectMeshPairs(targetObject, true);
            trianglesCount.text       = PolyfewRuntime.CountTriangles(true, targetObject) + "";
        }
    public void OnReductionChange(float value)
    {
        if (disableTemporary)
        {
            return;
        }

        didApplyLosslessLast = false;

        //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
        //w.Start();

        if (targetObject == null)
        {
            return;
        }
        if (Mathf.Approximately(0, value))
        {
            return;
        }

        SimplificationOptions options = new SimplificationOptions();

        options.simplificationStrength  = value;
        options.enableSmartlinking      = enableSmartLinking.isOn;
        options.preserveBorderEdges     = preserveBorders.isOn;
        options.preserveUVSeamEdges     = preserveUVSeams.isOn;
        options.preserveUVFoldoverEdges = preserveUVFoldover.isOn;

        if (preserveFace.isOn)
        {
            options.regardPreservationSphere           = true;
            options.preservationSphereCenterWorldSpace = preservationSphere.position;
            options.preservationSphereWorldScale       = preservationSphere.lossyScale;
        }

        else
        {
            options.regardPreservationSphere = false;
        }


        trianglesCount.text = PolyfewRuntime.SimplifyObjectDeep(objectMeshPairs, options, (GameObject go, MeshRendererPair mInfo) =>
        {
            //Debug.Log("Simplified mesh  " + mInfo.mesh.name + " on GameObject  " + go.name);
        }) + "";


        //w.Stop();
        //Debug.Log("Elapsed   " + w.ElapsedMilliseconds);
    }
Beispiel #5
0
        public void OnReductionChange(float value)
        {
            if (disableTemporary)
            {
                return;
            }

            didApplyLosslessLast = false;


            if (targetObject == null)
            {
                return;
            }
            if (Mathf.Approximately(0, value))
            {
                AssignMeshesFromPairs();
                trianglesCount.text = PolyfewRuntime.CountTriangles(true, targetObject) + "";
                return;
            }

            PolyfewRuntime.SimplificationOptions options = new PolyfewRuntime.SimplificationOptions();

            options.simplificationStrength  = value;
            options.enableSmartlinking      = enableSmartLinking.isOn;
            options.preserveBorderEdges     = preserveBorders.isOn;
            options.preserveUVSeamEdges     = preserveUVSeams.isOn;
            options.preserveUVFoldoverEdges = preserveUVFoldover.isOn;
            options.recalculateNormals      = recalculateNormals.isOn;
            options.regardCurvature         = regardCurvature.isOn;


            if (preserveFace.isOn)
            {
                options.regardPreservationSpheres = true;
                options.preservationSpheres.Add(new PolyfewRuntime.PreservationSphere(preservationSphere.position, preservationSphere.lossyScale.x, preservationStrength.value));
            }

            else
            {
                options.regardPreservationSpheres = false;
            }

            trianglesCount.text = PolyfewRuntime.SimplifyObjectDeep(objectMeshPairs, options, (GameObject go, PolyfewRuntime.MeshRendererPair mInfo) =>
            {
                //Debug.Log("Simplified mesh  " + mInfo.mesh.name + " on GameObject  " + go.name);
            }) + "";
        }
    public void SimplifyLossless()
    {
        //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
        //w.Start();

        disableTemporary        = true;
        reductionStrength.value = 0;
        disableTemporary        = false;

        didApplyLosslessLast = true;

        SimplificationOptions options = new SimplificationOptions
        {
            enableSmartlinking      = enableSmartLinking.isOn,
            preserveBorderEdges     = preserveBorders.isOn,
            preserveUVSeamEdges     = preserveUVSeams.isOn,
            preserveUVFoldoverEdges = preserveUVFoldover.isOn,

            simplifyMeshLossless = true
        };

        if (preserveFace.isOn)
        {
            options.regardPreservationSphere           = true;
            options.preservationSphereCenterWorldSpace = preservationSphere.position;
            options.preservationSphereWorldScale       = preservationSphere.lossyScale;
        }

        else
        {
            options.regardPreservationSphere = false;
        }



        trianglesCount.text = PolyfewRuntime.SimplifyObjectDeep(objectMeshPairs, options, (GameObject go, MeshRendererPair mInfo) =>
        {
            Debug.Log("Simplified mesh  " + mInfo.mesh.name + " on GameObject  " + go.name);
        }) + "";


        //w.Stop();
        //Debug.Log("Elapsed   " + w.ElapsedMilliseconds);
    }
Beispiel #7
0
        public void ExportGameObjectToOBJ()
        {
            //The following exports the GameObject Onion to the persistent data path

            string exportPath = Application.persistentDataPath;

            GameObject exportObject = GameObject.Find("onion");

            if (exportObject)
            {
                exportObject = exportObject.transform.GetChild(0).GetChild(0).gameObject;
            }

            else
            {
                exportObject = GameObject.Find("Meat");
                if (!exportObject)
                {
                    return;
                }

                else
                {
                    exportObject = exportObject.transform.GetChild(0).GetChild(0).gameObject;
                }
            }



            PolyfewRuntime.OBJExportOptions exportOptions = new PolyfewRuntime.OBJExportOptions(true, true, true, true, true);

            PolyfewRuntime.ExportGameObjectToOBJ(exportObject, exportPath, () =>
            {
                Debug.Log("Successfully exported GameObject:  " + exportObject.name);
                string message = "Successfully exported the file to:  \n" + Application.persistentDataPath;
                StartCoroutine(ShowMessage(message));
            },
                                                 (Exception ex) =>
            {
                Debug.LogError("Failed to export OBJ. " + ex.ToString());
            }, exportOptions);
        }
    public void ImportOBJ()
    {
        // This function loads an abj file named Meat.obj from the project's asset directory
        // This also loads the associated textures and materials

        GameObject importedObject;

        OBJImportOptions importOptions = new OBJImportOptions();

        importOptions.zUp           = false;
        importOptions.localPosition = new Vector3(-2.199f, -1, -1.7349f);
        importOptions.localScale    = new Vector3(0.045f, 0.045f, 0.045f);

        string objPath             = Application.dataPath + "/PolyFew/demo/TestModels/Meat.obj";
        string texturesFolderPath  = Application.dataPath + "/PolyFew/demo/TestModels/textures";
        string materialsFolderPath = Application.dataPath + "/PolyFew/demo/TestModels/materials";


        PolyfewRuntime.ImportOBJFromFileSystem(objPath, texturesFolderPath, materialsFolderPath, (GameObject imp) =>
        {
            importedObject = imp;
            Debug.Log("Successfully imported GameObject:   " + importedObject.name);
            barabarianRef.SetActive(false);
            targetObject = importedObject;
            ResetSettings();
            objectMeshPairs                   = PolyfewRuntime.GetObjectMeshPairs(targetObject, true);
            trianglesCount.text               = PolyfewRuntime.CountTriangles(true, targetObject) + "";
            exportButton.interactable         = true;
            importFromWeb.interactable        = false;
            importFromFileSystem.interactable = false;
            preserveFace.interactable         = false;
            preservationStrength.interactable = false;
            disableTemporary                  = true;
            preservationSphere.gameObject.SetActive(false);
            disableTemporary = false;
        },
                                               (Exception ex) =>
        {
            Debug.LogError("Failed to load OBJ file.   " + ex.ToString());
        }, importOptions);
    }