コード例 #1
0
        /// <summary>
        /// Load an OBJ and MTL file from a stream.
        /// </summary>
        /// <param name="input">Input OBJ stream</param>
        /// /// <param name="mtlInput">Input MTL stream</param>
        /// <returns>Returns a GameObject represeting the OBJ file, with each imported object as a child.</returns>
        public GameObject Load(Stream input, Stream mtlInput)
        {
            var mtlLoader = new MTLLoader();

            Materials = mtlLoader.Load(mtlInput);

            return(Load(input));
        }
コード例 #2
0
        /// <summary>
        /// Load an OBJ and MTL file from a stream.
        /// </summary>
        /// <param name="input">Input OBJ stream</param>
        /// /// <param name="mtlInput">Input MTL stream</param>
        /// <returns>Returns a GameObject represeting the OBJ file, with each imported object as a child.</returns>
        public GameObject Load(Stream input, Stream mtlInput)
        {
            if (streamFactory == null)
            {
                streamFactory = new FileStreamFactory();
            }

            var mtlLoader = new MTLLoader(streamFactory);

            Materials = mtlLoader.Load(mtlInput);

            return(Load(input));
        }
コード例 #3
0
        /// <summary>
        /// Load an OBJ and MTL file from a file path.
        /// </summary>
        /// <param name="path">Input OBJ path</param>
        /// /// <param name="mtlPath">Input MTL path</param>
        /// <returns>Returns a GameObject represeting the OBJ file, with each imported object as a child.</returns>
        public GameObject Load(string path, string mtlPath)
        {
            //_objInfo = new FileInfo(path);
            if (mtlPath != null && streamFactory.Exists(mtlPath))
            {
                var mtlLoader = new MTLLoader(streamFactory);
                Materials = mtlLoader.Load(mtlPath);
            }

            using (var fs = streamFactory.OpenStream(path))
            {
                return(Load(fs));
            }
        }
コード例 #4
0
    public GameObject LoadModelFromDir(string product_id)
    {
        string dir = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "models", product_id);

        Debug.Log("MODEL_DIR:" + dir);

        GameObject obj = new OBJLoader().Load(Path.Combine(dir, product_id + ".obj"));

        MTLLoader mtl = new MTLLoader();
        Dictionary <string, Material> textures = mtl.Load(Path.Combine(dir, product_id + ".mtl"));

        FitCollider(obj);
        //obj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
        //BoxCollider collider = obj.GetComponent<BoxCollider>();
        //obj.transform.position -= collider.transform.position;

        Rigidbody rb = obj.AddComponent <Rigidbody>();

        rb.isKinematic = true;

        //foreach (var p in textures) {
        //    obj.GetComponent<Renderer>().material.SetTexture(p.Key, p.Value.mainTexture);
        //}
        obj.transform.localScale *= 20;

        Text text = obj.AddComponent <Text>();

        text.text = product_id;

        GameObject productObj = GameObject.Find("Products");

        if (productObj == null)
        {
            productObj = new GameObject("Products");
        }
        obj.transform.parent = productObj.transform;

        return(obj);

        //for (int i=0; i<obj.transform.childCount; i++) {
        //    GameObject child = obj.transform.GetChild(i);
        //    child.GetComponent<Renderer>().material.
        //}
    }
コード例 #5
0
        /// <summary>
        /// Load an OBJ and MTL file from a file path.
        /// </summary>
        /// <param name="path">Input OBJ path</param>
        /// /// <param name="mtlPath">Input MTL path</param>
        /// <returns>Returns a GameObject represeting the OBJ file, with each imported object as a child.</returns>
        public GameObject Load(string path, string mtlPath)
        {
            _objInfo = new FileInfo(path);
            if (!string.IsNullOrEmpty(mtlPath) && File.Exists(mtlPath))
            {
                var mtlLoader = new MTLLoader();
                Materials = mtlLoader.Load(mtlPath);

                using (var fs = new FileStream(path, FileMode.Open))
                {
                    return(Load(fs));
                }
            }
            else
            {
                using (var fs = new FileStream(path, FileMode.Open))
                {
                    return(Load(fs));
                }
            }
        }
コード例 #6
0
        public async void Start()
        {
            /*
             * Consiguiendo json desde los API para luegos deserializarlos
             * se usa await en la llamada a el metodo para la consulta
             * y async en start para hacer todo el proceso asíncrono
             */
            ObjData      objData        = JsonConvert.DeserializeObject <ObjData>((string)await GetRequest(objUrl));
            ShovelsData  shovelDatas    = JsonConvert.DeserializeObject <ShovelsData>((string)await GetRequest(shovelDataUrl));
            ShovelReport _shovelReports = JsonConvert.DeserializeObject <ShovelReport>((string)await GetRequest(shovelReportUrl));
            // Descargando archivos  necesarios para instanciar
            string mineObjFilePath = (string) await DownloadFile(objData.ObjUrl, "OpenPitMine.obj");

            string mineMtlFilePath = (string) await DownloadFile(objData.MtlUrl, "OpenPitMine.mtl");

            Texture2D mineTex = (Texture2D) await GetTexture(objData.TextureUrl);

            // Creando los importadores de objetos
            OBJLoader oBJLoader = new OBJLoader();
            MTLLoader mTLLoader = new MTLLoader();

            /* Importando e instanciando el objeto y el material a la vez que asigno el shader al material,la textura al material y el material al objeto,
             * el shader que se usa esta creado en shadergraph y es muy similar al lit shader del universal render pipeline.*/
            var        mat  = mTLLoader.Load(mineMtlFilePath)["material_0"];
            GameObject mine = oBJLoader.Load(mineObjFilePath);

            mat.shader = minePitShader;
            mat.SetTexture("Base_Map", mineTex);
            mine.GetComponentInChildren <MeshRenderer>().material = mat;
            // Instanciando las palas y asignandoles ID
            foreach (var shovelData in shovelDatas.Shovels)
            {
                var gobj = Instantiate(shovelPrefab, shovelData.Position, Quaternion.identity);
                gobj.GetComponentInChildren <SelectableShovel>().ID = shovelData.ID;
            }
            // Guardando los reportes para uso global
            shovelReports = _shovelReports;
        }
コード例 #7
0
ファイル: OBJLoader.cs プロジェクト: JAMONGJJ/2019SIGGRAPH
        /// <summary>
        /// Load an OBJ and MTL file from a file path.
        /// </summary>
        /// <param name="path">Input OBJ path</param>
        /// /// <param name="mtlPath">Input MTL path</param>
        /// <returns>Returns a GameObject represeting the OBJ file, with each imported object as a child.</returns>
        public GameObject Load(string vertexPath, string facePath, string uvPath, string partsPath, string mtlPath)
        {
            GameObject obj;

            _objInfo = new FileInfo(vertexPath);
            if (!string.IsNullOrEmpty(mtlPath) && File.Exists(mtlPath))
            {
                var mtlLoader = new MTLLoader();
                Materials = mtlLoader.Load(mtlPath);

                using (var fs1 = new FileStream(vertexPath, FileMode.Open))
                {
                    return(Load(fs1, null, null, null));
                }
            }
            else
            {
                using (var fs1 = new FileStream(vertexPath, FileMode.Open))
                {
                    using (var fs2 = new FileStream(facePath, FileMode.Open))
                    {
                        using (var fs3 = new FileStream(uvPath, FileMode.Open))
                        {
                            using (var fs4 = new FileStream(partsPath, FileMode.Open))
                            {
                                obj = Load(fs1, fs2, fs3, fs4);
                                fs1.Close();
                                fs2.Close();
                                fs3.Close();
                                fs4.Close();
                                return(obj);
                            }
                        }
                    }
                }
            }
        }