コード例 #1
0
        public async Task LoadItemIntoScene(string itemPath, Vector2 bedCenter = new Vector2(), string itemName = null)
        {
            if (File.Exists(itemPath))
            {
                fileLoadCancellationTokenSource = new CancellationTokenSource();

                // TODO: How to we handle mesh load errors? How do we report success?
                IObject3D loadedItem = await Task.Run(() => Object3D.Load(itemPath, fileLoadCancellationTokenSource.Token));

                if (loadedItem != null)
                {
                    if (itemName != null)
                    {
                        loadedItem.Name = itemName;
                    }

                    // SetMeshAfterLoad
                    scene.Children.Modify(list =>
                    {
                        if (loadedItem.Mesh != null)
                        {
                            // STLs currently load directly into the mesh rather than as a group like AMF
                            list.Add(loadedItem);
                        }
                        else
                        {
                            list.AddRange(loadedItem.Children);
                        }
                    });

                    CreateGlDataObject(loadedItem);
                }
                else
                {
                    // TODO: Error message container moved to Interaction Layer - how could we support this type of error for a loaded scene item?
                    //partProcessingInfo.centeredInfoText.Text = string.Format("Sorry! No 3D view available\nfor this file.");
                }

                // Invoke LoadDone event
                LoadDone?.Invoke(this, null);
            }
            else
            {
                // TODO: Error message container moved to Interaction Layer - how could we support this type of error for a loaded scene item?
                //partProcessingInfo.centeredInfoText.Text = string.Format("{0}\n'{1}'", "File not found on disk.", Path.GetFileName(itemPath));
            }

            fileLoadCancellationTokenSource = null;
        }
コード例 #2
0
        public async Task LoadItemIntoScene(string itemPath, Vector2 bedCenter = new Vector2(), string itemName = null)
        {
            if (File.Exists(itemPath))
            {
                BeginProgressReporting("Loading Mesh");

                // TODO: How to we handle mesh load errors? How do we report success?
                IObject3D loadedItem = await Task.Run(() => Object3D.Load(itemPath, CancellationToken.None, progress: ReportProgress0to100));

                if (loadedItem != null)
                {
                    if (itemName != null)
                    {
                        loadedItem.Name = itemName;
                    }

                    // SetMeshAfterLoad
                    Scene.Children.Modify(children =>
                    {
                        if (loadedItem.Mesh != null)
                        {
                            // STLs currently load directly into the mesh rather than as a group like AMF
                            children.Add(loadedItem);
                        }
                        else
                        {
                            children.AddRange(loadedItem.Children);
                        }
                    });

                    CreateGlDataObject(loadedItem);
                }
                else
                {
                    partProcessingInfo.centeredInfoText.Text = string.Format("Sorry! No 3D view available\nfor this file.");
                }

                EndProgressReporting();

                // Invoke LoadDone event
                LoadDone?.Invoke(this, null);

                Invalidate();
            }
            else
            {
                partProcessingInfo.centeredInfoText.Text = string.Format("{0}\n'{1}'", "File not found on disk.", Path.GetFileName(itemPath));
            }
        }