Esempio n. 1
0
    async void OnOpenSpeechCommand()
    {
        var filePath = await this.PickFileFrom3DObjectsFolderAsync();

        if (!string.IsNullOrEmpty(filePath))
        {
            var modelDetails = await this.ImportGLTFModelFromFileAsync(filePath);

            if (modelDetails != null)
            {
                // Our new model comes out of the file load.
                var newModel = modelDetails.GameObject;

                // Give the new model a new identity.
                var modelIdentifier = newModel.AddComponent <ModelIdentifier>();

                // Make it focusable.
                newModel.AddComponent <FocusWatcher>();

                // Add positioning.
                var positioningManager = newModel.AddComponent <ModelPositioningManager>();
                positioningManager.InitialiseSizeAndPositioning(
                    this.RootParentProvider.RootParent);

                // Add manipulations to the new model so it can be moved around.
                var manipManager = newModel.AddComponent <ModelUpdatesManager>();
                manipManager.AddHandManipulationsToModel();

                // Add an anchor to the new model's parent such that we can then
                // anchor the parent while moving the model around within it
                // (anchored components can't move).
                var anchorManager = newModel.AddComponent <AnchorManager>();
                anchorManager.AddAnchorToModelParent();

                // Write out all the files that were part of loading this model
                // into a file in case they need sharing in future.
                await FileStorageManager.StoreFileListAsync(
                    (Guid)modelIdentifier.Identifier, modelDetails.FileLoader);

                // And export the anchor into the file system as well.
                // TODO: this will currently wait "for ever" for the world anchor to be
                // located which might be wildly optimistic, we should probably add some
                // notion of a timeout on that here too.
                var exportedAnchorBits = await anchorManager.ExportAnchorAsync();

                if (exportedAnchorBits != null)
                {
                    // Store that into the file system so that the web server can later
                    // serve it up on request.
                    await FileStorageManager.StoreExportedWorldAnchorAsync(
                        (Guid)modelIdentifier.Identifier,
                        exportedAnchorBits);

                    // Message out to the network that we have a new model that they
                    // can optionally grab if they want to.
                    NetworkMessagingProvider.SendNewModelMessage(
                        (Guid)modelIdentifier.Identifier);
                }
            }
        }
    }