// TODO: Look into making this append image requests instead of replacing
        // them.
        public void RequestLoadImage(ReferenceImage referenceImage)
        {
            Debug.Assert(referenceImage != null);
            int index = ImageToIndex(referenceImage);

            RequestLoadImages(index, index + 1);
        }
 /// Returns an index to a catalog entry, or -1 if the handle is invalid.
 /// The inverse of IndexToHandle.
 /// Indices are not durable, so use the index immediately and do not keep it around.
 public int ImageToIndex(ReferenceImage image)
 {
     for (int i = 0; i < m_Images.Count; ++i)
     {
         if (m_Images[i] == image)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 3
0
        static DynamicExportableMaterial CreateImageQuadMaterial(ReferenceImage ri)
        {
            BrushDescriptor desc = BrushCatalog.m_Instance.GetBrush(kPbrTransparentGuid);

            return(new DynamicExportableMaterial(
                       parent: desc,
                       // GetExportName() not totally guaranteed to be unique; maybe we should detect collisions?
                       durableName: $"image_{ri.GetExportName()}",
                       uniqueName: MakeDeterministicUniqueName(desc.m_Guid, ri, 0),
                       uriBase: Path.GetDirectoryName(ri.FileFullPath))
            {
                BaseColorTex = Path.GetFileName(ri.FileFullPath),
                MetallicFactor = kRefimageMetallicFactor
            });
        }
Exemplo n.º 4
0
        public static void ImportImage(string path)
        {
            path = Path.Combine(App.MediaLibraryPath(), "Images", path);
            var image = new ReferenceImage(path);

            image.RequestLoad(allowMainThread: true);
            var tr = new TrTransform();

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

            SketchMemoryScript.m_Instance.PerformAndRecordCommand(createCommand);
            ImageWidget imageWidget = createCommand.Widget as ImageWidget;

            imageWidget.ReferenceImage = image;
            imageWidget.Show(true);
            createCommand.SetWidgetCost(imageWidget.GetTiltMeterCost());

            WidgetManager.m_Instance.WidgetsDormant = false;
            SketchControlsScript.m_Instance.EatGazeObjectInput();
            SelectionManager.m_Instance.RemoveFromSelection(false);
        }
Exemplo n.º 5
0
        // -------------------------------------------------------------------------------------------- //
        // Public API
        // -------------------------------------------------------------------------------------------- //

        public static SceneStatePayload GetExportPayload(
            AxisConvention axes,
            bool includeLocalMediaContent = false,
            string temporaryDirectory     = null)
        {
            UnityEngine.Profiling.Profiler.BeginSample("GetSceneStatePayload");

            var payload = new SceneStatePayload(axes, temporaryDirectory);

            BuildGenerator(payload);
            BuildEnvironment(payload);
            BuildLights(payload);

            UnityEngine.Profiling.Profiler.BeginSample("BuildBrushMeshes");
            BuildBrushMeshes(payload);
            UnityEngine.Profiling.Profiler.EndSample();

            {
                bool IsModelExportable(ModelWidget w)
                {
                    if (!w.Model.AllowExport)
                    {
                        return(false);
                    }
                    if (w.Model.GetLocation().GetLocationType() == Model.Location.Type.LocalFile)
                    {
                        return(includeLocalMediaContent && App.Config.m_EnableReferenceModelExport);
                    }
                    else
                    {
                        return(true);
                    }
                }

                UnityEngine.Profiling.Profiler.BeginSample("BuildModelMeshes");
                // TODO: inactive ModelWidgets should be fixed in WidgetManager.
                var(exportable, notExportable) = WidgetManager.m_Instance.ModelWidgets
                                                 .Where(w => w.Model != null && w.isActiveAndEnabled)
                                                 .Partition(IsModelExportable);
                BuildModelsAsModelMeshes(payload, exportable);
                BuildEmptyXforms(payload, notExportable);
                UnityEngine.Profiling.Profiler.EndSample();
            }

            {
                bool IsImageExportable(ImageWidget w)
                {
                    return(includeLocalMediaContent && w.ReferenceImage != null);
                }

                var media2dWidgets = WidgetManager.m_Instance.MediaWidgets
                                     .Select(grab => grab.m_WidgetScript as Media2dWidget)
                                     .Where(w => w != null && w.isActiveAndEnabled);
                var(images, notImages)         = media2dWidgets.Partition(w => w is ImageWidget);
                var(exportable, notExportable) = images.Cast <ImageWidget>().Partition(IsImageExportable);

                foreach (var group in exportable.GroupBy(widget => widget.ReferenceImage))
                {
                    ReferenceImage ri = group.Key;
                    if (ri == null)
                    {
                        Debug.Assert(false, "Empty ImageWidgets");
                        continue;
                    }
                    var material = CreateImageQuadMaterial(ri);
                    foreach ((ImageWidget image, int idx) in group.WithIndex())
                    {
                        payload.imageQuads.Add(BuildImageQuadPayload(payload, image, material, idx));
                    }
                }

                BuildEmptyXforms(payload, notImages);
                BuildEmptyXforms(payload, notExportable);
            }

            UnityEngine.Profiling.Profiler.EndSample();
            return(payload);
        }
Exemplo n.º 6
0
        // -------------------------------------------------------------------------------------------- //
        // Image quads
        // -------------------------------------------------------------------------------------------- //

        static Guid MakeDeterministicUniqueName(Guid descriptor, ReferenceImage ri, int id)
        {
            return(GuidUtils.Uuid5(descriptor, string.Format("{0}_{1}", ri.FileFullPath, id)));
        }