示例#1
0
        public static void ImportModel(string path)
        {
            path = Path.Combine(App.MediaLibraryPath(), "Models", path);
            var model = new Model(Model.Location.File(path));

            model.LoadModel();

            var tr = new TrTransform();

            tr.translation = ApiManager.Instance.BrushPosition;
            tr.rotation    = ApiManager.Instance.BrushRotation;
            CreateWidgetCommand createCommand = new CreateWidgetCommand(
                WidgetManager.m_Instance.ModelWidgetPrefab, tr);

            SketchMemoryScript.m_Instance.PerformAndRecordCommand(createCommand);
            ModelWidget modelWidget = createCommand.Widget as ModelWidget;

            modelWidget.Model = model;
            modelWidget.Show(true);
            createCommand.SetWidgetCost(modelWidget.GetTiltMeterCost());

            WidgetManager.m_Instance.WidgetsDormant = false;
            SketchControlsScript.m_Instance.EatGazeObjectInput();
            SelectionManager.m_Instance.RemoveFromSelection(false);
        }
示例#2
0
        public void LoadModels()
        {
            var oldModels = new Dictionary <string, Model>(m_ModelsByRelativePath);

            // If we changed a file, pretend like we don't have it.
            if (m_ChangedFile != null)
            {
                if (oldModels.ContainsKey(m_ChangedFile))
                {
                    oldModels.Remove(m_ChangedFile);
                }
                m_ChangedFile = null;
            }
            m_ModelsByRelativePath.Clear();

            ProcessDirectory(m_ModelsDirectory, oldModels);

            if (oldModels.Count > 0)
            {
                foreach (var entry in oldModels)
                {
                    // Verified that destroy a gameObject removes all children transforms,
                    // all components, and most importantly all textures no longer used by the destroyed objects
                    if (entry.Value.m_ModelParent != null)
                    {
                        Destroy(entry.Value.m_ModelParent.gameObject);
                    }
                }
                Resources.UnloadUnusedAssets();
            }

            m_OrderedModelNames = m_ModelsByRelativePath.Keys.ToList();
            m_OrderedModelNames.Sort();

            foreach (string relativePath in m_OrderedModelNames)
            {
                if (m_MissingModelsByRelativePath.ContainsKey(relativePath))
                {
                    ModelWidget.CreateModelsFromRelativePath(
                        relativePath, null, m_MissingModelsByRelativePath[relativePath], null, null);
                    m_MissingModelsByRelativePath.Remove(relativePath);
                }
                if (m_MissingNormalizedModelsByRelativePath.ContainsKey(relativePath))
                {
                    ModelWidget.CreateModelsFromRelativePath(
                        relativePath, m_MissingNormalizedModelsByRelativePath[relativePath], null, null, null);
                    m_MissingModelsByRelativePath.Remove(relativePath);
                }
            }

            m_FolderChanged = false;
        }
示例#3
0
        override public GrabWidget Clone()
        {
            ModelWidget clone = Instantiate(WidgetManager.m_Instance.ModelWidgetPrefab) as ModelWidget;

            clone.transform.position = transform.position;
            clone.transform.rotation = transform.rotation;
            clone.Model = this.Model;
            // We're obviously not loading from a sketch.  This is to prevent the intro animation.
            // TODO: Change variable name to something more explicit of what this flag does.
            clone.m_LoadingFromSketch = true;
            clone.Show(true, false);
            clone.transform.parent = transform.parent;
            clone.SetSignedWidgetSize(this.m_Size);
            HierarchyUtils.RecursivelySetLayer(clone.transform, gameObject.layer);
            TiltMeterScript.m_Instance.AdjustMeterWithWidget(clone.GetTiltMeterCost(), up: true);

            CanvasScript canvas = transform.parent.GetComponent <CanvasScript>();

            if (canvas != null)
            {
                var materials = clone.GetComponentsInChildren <Renderer>().SelectMany(x => x.materials);
                foreach (var material in materials)
                {
                    foreach (string keyword in canvas.BatchManager.MaterialKeywords)
                    {
                        material.EnableKeyword(keyword);
                    }
                }
            }

            if (!clone.Model.m_Valid)
            {
                App.PolyAssetCatalog.CatalogChanged += clone.OnPacCatalogChanged;
                clone.m_PolyCallbackActive           = true;
            }
            clone.CloneInitialMaterials(this);
            clone.TrySetCanvasKeywordsFromObject(transform);
            return(clone);
        }
示例#4
0
        /// Spawn a model.
        /// Precondition: Model must have m_Valid == true.
        protected void SpawnValidModel(Model model)
        {
            if (!model.m_Valid)
            {
                throw new InvalidOperationException("model must be valid");
            }
            // Button forward is into the panel, not out of the panel; so flip it around
            TrTransform xfSpawn = Coords.AsGlobal[transform]
                                  * TrTransform.R(Quaternion.AngleAxis(180, Vector3.up));
            CreateWidgetCommand createCommand = new CreateWidgetCommand(
                WidgetManager.m_Instance.ModelWidgetPrefab, xfSpawn, m_PreviewBaseRotation);

            SketchMemoryScript.m_Instance.PerformAndRecordCommand(createCommand);
            ModelWidget modelWidget = createCommand.Widget as ModelWidget;

            modelWidget.Model = model;
            modelWidget.Show(true);
            createCommand.SetWidgetCost(modelWidget.GetTiltMeterCost());

            WidgetManager.m_Instance.WidgetsDormant = false;
            SketchControlsScript.m_Instance.EatGazeObjectInput();
            SelectionManager.m_Instance.RemoveFromSelection(false);
        }