예제 #1
0
        private IEnumerator PlaceFamily(string familyId)
        {
            if (FamilyLibrary.GetFamily(familyId) != null)
            {
                FamilyInstance newFam = new FamilyInstance
                {
                    FamilyId  = familyId,
                    Transform = new Common.Models.Transform
                    {
                        BasisX = new XYZ
                        {
                            X = this.transform.right.x,
                            Y = this.transform.right.z,
                            Z = this.transform.right.y
                        },
                        BasisY = new XYZ
                        {
                            X = this.transform.forward.x,
                            Y = this.transform.forward.z,
                            Z = this.transform.forward.y
                        },
                        BasisZ = new XYZ
                        {
                            X = this.transform.up.x,
                            Y = this.transform.up.z,
                            Z = this.transform.up.y
                        },
                        Origin = new XYZ
                        {
                            X = this.transform.position.x * Helpers.Constants.FT_PER_M,
                            Y = this.transform.position.z * Helpers.Constants.FT_PER_M,
                            Z = this.transform.position.y * Helpers.Constants.FT_PER_M
                        }
                    }
                };

                Debug.Log($"Requesting new family");

                newFam = StreamVR.Instance.PlaceFamilyInstance(newFam);

                Debug.Log($"Loading family instance");

                yield return(this.LoadInstance(newFam));

                FamilyInstanceLibrary.AddFamily(newFam, this.gameObject);
            }
            else
            {
                Debug.LogError($"Can't create family from missing ID {familyId}");
            }
        }
예제 #2
0
        private IEnumerator LoadInstance(FamilyInstance f)
        {
            this.instanceData = f;
            this.InstanceData = Newtonsoft.Json.JsonConvert.SerializeObject(f);
            this.fam          = FamilyLibrary.GetFamily(f.FamilyId);
            if (this.fam == null)
            {
                throw new System.Exception("Family " + f.FamilyId + " is not loaded");
            }
            if (f.HostId != null)
            {
                this.host = GeometryLibrary.GetObject(f.HostId);
            }

#if UNITY_EDITOR
            this.name = $"Family ({f.Id} - {this.fam.Tag} - {this.fam.ModelName ?? this.fam.FamilyName})";
#else
            this.name = f.Id;
#endif

            // GameObject model = (GameObject)Resources.Load($"Families/{this.fam.Name}/model");
            CoroutineWithData <object> cd = new CoroutineWithData <object>(this, FamilyLibrary.ResolveFamilyOBJ(f.FamilyId, f.VariantId));
            yield return(cd.coroutine);

            object result = cd.result;

            if (result != null)
            {
                byte[] objData = cd.result as byte[];

                // Debug.Log("PLACING FAMILY");

                GameObject modelInstance;
                using (var textStream = new MemoryStream(objData))
                {
                    modelInstance = new OBJLoader().Load(textStream);
                }

                var initialRotation = modelInstance.transform.localRotation;

                modelInstance.transform.parent        = this.transform;
                modelInstance.transform.localPosition = Vector3.zero;
                modelInstance.transform.localRotation = initialRotation;
                modelInstance.transform.localScale    = new Vector3(
                    Helpers.Constants.M_PER_FT,
                    Helpers.Constants.M_PER_FT,
                    Helpers.Constants.M_PER_FT
                    );

                foreach (var l in modelInstance.GetComponentsInChildren <Light>())
                {
                    l.gameObject.transform.rotation = Quaternion.LookRotation(Vector3.down);
                }

                foreach (UnityEngine.Transform child in transform)
                {
                    foreach (UnityEngine.Transform geo in child)
                    {
                        var c = geo.GetComponent <FamilyGeometryController>();
                        if (c != null)
                        {
                            c.CollisionEnter += this.OnCollsionEnterEvent;
                            c.CollisionExit  += this.OnCollisionExitEvent;
                        }
                    }
                }
                // Debug.Log("Children " + count);
            }

#if UNITY_EDITOR
            StartCoroutine(CheckForUpdate());
#endif
        }