コード例 #1
0
    public IEnumerator GLTFScenarios([ValueSource("ModelFilePaths")] string modelPath)
    {
        ActiveGLTFObject = new GameObject();

        GLTFComponent gltfcomponent = ActiveGLTFObject.AddComponent <GLTFComponent>();

        gltfcomponent.GLTFUri = GLTF_ASSETS_PATH + modelPath;

        AssetGenerator.Manifest.Camera cam = cameras[Path.GetFileNameWithoutExtension(modelPath)];
        Camera.main.transform.position = new Vector3(cam.Translation[0], cam.Translation[1], cam.Translation[2]);
        yield return(gltfcomponent.Load());

        //wait one frame for rendering to complete
        yield return(null);

        Camera        mainCamera = Camera.main;
        RenderTexture rt         = new RenderTexture(512, 512, 24);

        mainCamera.targetTexture = rt;
        Texture2D actualContents = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);

        mainCamera.Render();
        RenderTexture.active = rt;
        actualContents.ReadPixels(new Rect(0, 0, 512, 512), 0, 0);
        byte[] pngActualfile  = actualContents.EncodeToPNG();
        string outputpath     = Path.GetDirectoryName(modelPath);
        string outputfullpath = GLTF_SCENARIO_OUTPUT_PATH + outputpath;

        Directory.CreateDirectory(outputfullpath);
        string filename         = Path.GetFileNameWithoutExtension(modelPath);
        string expectedFilePath = outputfullpath + "/" + filename + "_EXPECTED.png";
        string actualFilePath   = outputfullpath + "/" + filename + "_ACTUAL.png";

        if (GENERATE_REFERENCEDATA)
        {
            File.WriteAllBytes(expectedFilePath, pngActualfile);
        }
        else
        {
            if (File.Exists(expectedFilePath))
            {
                byte[] pngActualfileContents = File.ReadAllBytes(expectedFilePath);

                File.WriteAllBytes(actualFilePath, pngActualfile);
                //compare against expected
                Texture2D expectedContents = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
                expectedContents.LoadImage(pngActualfileContents);
                Color[] expectedPixels = expectedContents.GetPixels();
                Color[] actualPixels   = actualContents.GetPixels();
                Assert.AreEqual(expectedPixels.Length, actualPixels.Length);
                string errormessage = "\r\nExpectedPath: " + expectedFilePath + "\r\n ActualPath: " + actualFilePath;

                for (int i = 0; i < expectedPixels.Length; i++)
                {
                    Assert.AreEqual(expectedPixels[i], actualPixels[i], errormessage);
                }
            }
        }
    }
コード例 #2
0
ファイル: cargarArchivo.cs プロジェクト: rafaroman18/LeapVR
    //Realiza un GET al enlace temporal, descarga el .zip
    //y crea el objeto en la escena
    private async void creaObjeto(string link)
    {
        //Descargamos el .zip
        using (WebClient client = new WebClient())
        {
            client.DownloadFile(new Uri(link), "ZIP/objeto.zip");
        }


        //Descomprimimos el .zip
        ZipFile.ExtractToDirectory("ZIP/objeto.zip", "ZIP");


        //Creamos el objeto en la escena
        gltfLoader.GLTFUri = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "ZIP/scene.gltf");
        textBox.CambiarTexto("Cargando");
        try
        {
            await gltfLoader.Load();

            GameObject objectCreated = transform.Find("OSG_Scene").gameObject;
            objectCreated.name = objeto;
            objectCreated.tag  = "objetoCreado";

            //Desactivamos los Box Collider para evitar colisiones con objetos grandes
            MeshCollider[] colls = objectCreated.GetComponentsInChildren <MeshCollider>();
            foreach (MeshCollider meshC in colls)
            {
                meshC.enabled = false;
            }



            //Colocamos el tamaño correcto del objeto
            await textBox.IniciaEscala(objectCreated);

            //Una vez seleccionado la escala, se crean sus componentes
            //para que el objeto sea interactivo
            foreach (MeshCollider meshC in colls)
            {
                meshC.enabled = true;
            }
            objectCreated.AddComponent <Rigidbody>();
            objectCreated.AddComponent <InteractionBehaviour>();
            objectCreated.GetComponent <Rigidbody>().useGravity         = true;
            objectCreated.GetComponent <InteractionBehaviour>().manager = FindObjectOfType <InteractionManager>();

            //Se indica el fin de la ejecucion
            textBox.CambiarTexto("Listo");
        }
        catch (Exception e) { textBox.CambiarTexto("Error al cargar el objeto"); gltfLoader.StopAllCoroutines(); }
        finally { StartCoroutine(cerrarTextBox()); }
    }
コード例 #3
0
    private async void Update()
    {
        if (loadThisFrame)
        {
            loadThisFrame = false;

            var path = pathRoot + modelRelativePath;
            if (loader.LastLoadedScene != null)
            {
                Destroy(loader.LastLoadedScene);
            }
            loader.GLTFUri = path;
            await loader.Load();
        }
    }
コード例 #4
0
    public IEnumerator GLTFScenarios([ValueSource("ModelFilePaths")] string modelPath)
    {
        // Update the camera position
        Manifest.Model  modelManifest = modelManifests[Path.GetFileNameWithoutExtension(modelPath)];
        Manifest.Camera cam           = modelManifest.Camera;
        Camera.main.transform.position = new Vector3(cam.Translation[0], cam.Translation[1], cam.Translation[2]);

        // Load the corresponding model
        gltfComponent.GLTFUri = GLTF_ASSETS_PATH + modelPath;
        yield return(gltfComponent.Load().AsCoroutine());

        // Wait one frame for rendering to complete
        yield return(null);

        // Capture a render of the model
        Camera        mainCamera = Camera.main;
        RenderTexture rt         = new RenderTexture(IMAGE_SIZE, IMAGE_SIZE, 24);

        mainCamera.targetTexture = rt;
        Texture2D actualContents = new Texture2D(IMAGE_SIZE, IMAGE_SIZE, TextureFormat.RGB24, false);

        mainCamera.Render();
        RenderTexture.active = rt;
        actualContents.ReadPixels(new Rect(0, 0, IMAGE_SIZE, IMAGE_SIZE), 0, 0);
        Color[] actualPixels = actualContents.GetPixels();

        // Save the captured contents to a file
        byte[] pngActualfile  = actualContents.EncodeToPNG();
        string outputpath     = Path.GetDirectoryName(modelPath);
        string outputfullpath = GLTF_SCENARIO_OUTPUT_PATH + outputpath;

        Directory.CreateDirectory(outputfullpath);
        string filename       = Path.GetFileNameWithoutExtension(modelPath);
        string actualFilePath = outputfullpath + "/" + filename + "_ACTUAL.png";

        File.WriteAllBytes(actualFilePath, pngActualfile);

        // Read the expected image
        // NOTE: Ideally this would use the expected image from Path.Combine(GLTF_ASSETS_PATH, modelManifest.SampleImageName), but the
        // current rendered image is not close enough to use this as a source of truth, so until they can be closer aligned we instead
        // generate an 'expected' image ourselves.
        string expectedFilePath = Path.Combine(outputfullpath, filename + "_EXPECTED.png");

#if ENABLE_THIS_BLOCK_TO_CREATE_EXPECTED_FILES
        File.WriteAllBytes(expectedFilePath, pngActualfile);
#endif
        if (!File.Exists(expectedFilePath))
        {
            Assert.Fail("Could not find expected image to compare against: '" + expectedFilePath + "'");
        }
        byte[]    expectedFileContents = File.ReadAllBytes(expectedFilePath);
        Texture2D expectedContents     = new Texture2D(IMAGE_SIZE, IMAGE_SIZE, TextureFormat.RGB24, false);
        expectedContents.LoadImage(expectedFileContents);
        Color[] expectedPixels = expectedContents.GetPixels();

        // Compare the capture against the expected image
        Assert.AreEqual(expectedPixels.Length, actualPixels.Length);
        string errormessage = "\r\nImage does not match expected within configured tolerance.\r\nExpectedPath: " + expectedFilePath + "\r\n ActualPath: " + actualFilePath;
        for (int i = 0; i < expectedPixels.Length; i++)
        {
            Assert.That(actualPixels[i], Is.EqualTo(expectedPixels[i]).Using(ColorEqualityComparer));
        }
    }
コード例 #5
0
    public IEnumerator GLTFScenarios([ValueSource("SceneFilePaths")] string scenePath)
    {
        SceneManager.LoadScene(Path.GetFileNameWithoutExtension(scenePath));

        //wait one frame for loading to complete
        yield return(null);

        var objects = GameObject.FindObjectsOfType(typeof(GameObject));

        foreach (GameObject o in objects)
        {
            if (o.name.Contains("GLTF"))
            {
                GLTFComponent gltfcomponent = o.GetComponent <GLTFComponent>();
                gltfcomponent.Load();
            }
        }

        //wait one seconds for textures to load
        yield return(null);

        Camera mainCamera = Camera.main;

        Debug.Assert(mainCamera != null, "Make sure you have a main camera");
        RenderTexture rt = new RenderTexture(512, 512, 24);

        mainCamera.targetTexture = rt;
        Texture2D actualContents = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);

        mainCamera.Render();
        RenderTexture.active = rt;
        actualContents.ReadPixels(new Rect(0, 0, 512, 512), 0, 0);
        byte[] pngActualfile  = actualContents.EncodeToPNG();
        string outputpath     = Path.GetDirectoryName(scenePath);
        string outputfullpath = GLTF_SCENARIO_OUTPUT_PATH + outputpath;

        Directory.CreateDirectory(outputfullpath);
        string filename         = Path.GetFileNameWithoutExtension(scenePath);
        string expectedFilePath = outputfullpath + "/" + filename + "_EXPECTED.png";
        string actualFilePath   = outputfullpath + "/" + filename + "_ACTUAL.png";

        //uncomment to reggenerate master images
        if (GENERATE_REFERENCEDATA)
        {
            File.WriteAllBytes(expectedFilePath, pngActualfile);
        }
        else
        {
            if (File.Exists(expectedFilePath))
            {
                byte[] pngActualfileContents = File.ReadAllBytes(expectedFilePath);

                File.WriteAllBytes(actualFilePath, pngActualfile);
                //compare against expected
                Texture2D expectedContents = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
                expectedContents.LoadImage(pngActualfileContents);
                Color[] expectedPixels = expectedContents.GetPixels();
                Color[] actualPixels   = actualContents.GetPixels();
                Assert.AreEqual(expectedPixels.Length, actualPixels.Length);
                string errormessage = "\r\nExpectedPath: " + expectedFilePath + "\r\n ActualPath: " + actualFilePath;

                for (int i = 0; i < expectedPixels.Length; i++)
                {
                    Assert.AreEqual(expectedPixels[i], actualPixels[i], errormessage);
                }
            }
        }
    }