Beispiel #1
0
        private void OnCollisionEnter(Collision collision)
        {
            if (collision.gameObject.tag == "paint")
            {
                Debug.Log("PAINT!" + collision.gameObject.name);

                var mat = collision.gameObject.GetComponent <MeshRenderer>().material;
                this.GetComponent <MeshRenderer>().material = mat;

                Debug.Log($"PAINT MAT {mat.name}");

                string baseName = mat.name.Replace("(Instance)", "").Trim();

                Debug.Log($"PAINT MAT* {baseName}");

                currentMaterial = MaterialLibrary.ReverseGetMaterial(baseName);

                Debug.Log($"PAINT NULL {currentMaterial == null}");

                instanceData.MaterialId = currentMaterial.Id;
                StartCoroutine(StreamVR.Instance.PaintFace(instanceData));

                Destroy(collision.gameObject);
            }
        }
Beispiel #2
0
        private static IEnumerator ResolveMaterialTexture(string id)
        {
            Common.Models.Material mat = GetMaterial(id);
            if (mat == null)
            {
                UnityEngine.Debug.Log($"MATERIAL {id} DOES NOT EXIST");
                _totalCalls--;
                yield return(null);

                yield break;
            }

            string url = $"{_ModelServerURL}/api/material/{mat.Id}";

            UnityEngine.Texture materialTexture = null;

            UnityEngine.Debug.Log(url);
            using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(url))
            {
                yield return(webRequest.SendWebRequest());

                if (webRequest.isNetworkError)
                {
                    UnityEngine.Debug.Log("Error: " + webRequest.error);
                    yield return(null);

                    _totalCalls--;
                    yield break;
                }
                else if (webRequest.isHttpError)
                {
                    // UnityEngine.Debug.Log("Error: " + webRequest.error);
                    yield return(null);

                    _totalCalls--;
                    yield break;
                }
                else
                {
                    materialTexture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture;
                }
            }

            if (materialTexture != null)
            {
                UnityEngine.Material baseMaterial = LookupMaterial(mat.Id);

                UnityEngine.Material newMaterial = new UnityEngine.Material(baseMaterial.shader);

                newMaterial.CopyPropertiesFromMaterial(baseMaterial);

                newMaterial.name        = mat.Name + " (With Texture)";
                newMaterial.mainTexture = materialTexture;
                newMaterial.color       = new UnityEngine.Color(
                    220f / 255f,
                    220f / 255f,
                    220f / 255f
                    );
                newMaterial.SetFloat("_Metallic", (float)mat.Shininess / byte.MaxValue);
                newMaterial.SetFloat("_Smoothness", (float)mat.Smoothness / byte.MaxValue);

                matLib.Add("_" + id, newMaterial);

                UnityEngine.Debug.Log(JsonConvert.SerializeObject(mat));

                // UnityEngine.GameObject.Find("Test").GetComponent<UnityEngine.MeshRenderer>().material = newMaterial;
            }

            _totalCalls--;
        }
Beispiel #3
0
 public void LoadInstance(Face f)
 {
     this.instanceData = f;
     currentMaterial   = MaterialLibrary.GetMaterial(f.MaterialId);
 }