public async Task <bool> LoadObjectModelsAsync(string modelPath)
        {
            IObjectAnchorsService objectAnchorsService = ObjectAnchorsService.GetService();

            Debug.Log($"{Application.persistentDataPath} {objectAnchorsService != null}");
            string[] ouFiles = Directory.GetFiles(modelPath, "*.ou", SearchOption.AllDirectories);
            foreach (var file in ouFiles)
            {
                // Represent a model by TrackableObject, and load its model into OU service.
                var trackableObject = new TrackableObjectData();

                trackableObject.ModelFilePath = file.Replace('/', '\\');
                string appPath = Application.persistentDataPath.Replace('/', '\\');
                if (trackableObject.ModelFilePath.Contains(appPath))
                {
                    trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(trackableObject.ModelFilePath);
                }
                else
                {
#if WINDOWS_UWP
                    byte[] buffer = await ReadFileBytesAsync(trackableObject.ModelFilePath);

                    trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(buffer);
#endif // WINDOWS_UWP
                }

                if (trackableObject.ModelId != Guid.Empty)
                {
                    trackableObject.ModelMesh = new Mesh();
                    await trackableObject.ModelMesh.SetFromObjectModel(trackableObject.ModelId);

                    Debug.Log($"mesh has {trackableObject.ModelMesh.triangles.Length} indices");

                    trackableObject.logicalBoundingBox = objectAnchorsService.GetModelBoundingBox(trackableObject.ModelId);
                    _trackableObjects.Add(trackableObject);
                    _modelIdToTrackableObject.Add(trackableObject.ModelId, trackableObject);

                    Debug.Log($"Loaded Model\n{trackableObject}");
                }
                else
                {
                    Debug.LogError($"failed to load model {trackableObject.ModelFilePath}");
                }
            }
            if (_trackableObjects.Count > 0)
            {
                ModelsLoaded?.Invoke(this, EventArgs.Empty);
            }
            return(_trackableObjects.Count > 0);
        }
Esempio n. 2
0
        public async Task <bool> LoadObjectModelsAsync(string modelPath)
        {
            IObjectAnchorsService objectAnchorsService = ObjectAnchorsService.GetService();

            Debug.Log($"{Application.persistentDataPath} {objectAnchorsService != null}");
            string[] ouFiles = Directory.GetFiles(modelPath, "*.ou", SearchOption.AllDirectories);
            foreach (var file in ouFiles)
            {
                // Represent a model by TrackableObject, and load its model into OU service.
                var trackableObject = new TrackableObjectData();

                trackableObject.ModelFilePath = file.Replace('/', '\\');

                trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(trackableObject.ModelFilePath);

                if (trackableObject.ModelId != Guid.Empty)
                {
                    // Query the default coverage threshold from this object model.
                    ObjectQuery query = objectAnchorsService.CreateObjectQuery(trackableObject.ModelId);
                    trackableObject.MinSurfaceCoverageFromObjectModel = query.MinSurfaceCoverage;

                    trackableObject.ModelMesh          = GenerateMesh(trackableObject.ModelId);
                    trackableObject.logicalBoundingBox = objectAnchorsService.GetModelBoundingBox(trackableObject.ModelId);
                    _trackableObjects.Add(trackableObject);
                    _modelIdToTrackableObject.Add(trackableObject.ModelId, trackableObject);

                    Debug.Log($"Loaded Model\n{trackableObject}");
                }
                else
                {
                    Debug.LogError($"failed to load model {trackableObject.ModelFilePath}");
                }
            }
            if (_trackableObjects.Count > 0)
            {
                ModelsLoaded?.Invoke(this, EventArgs.Empty);
            }
            return(_trackableObjects.Count > 0);
        }
Esempio n. 3
0
 public void SetTrackableObjectData(TrackableObjectData trackableObjectData)
 {
     currentVisualizationData = trackableObjectData;
     meshRenderer.enabled     = currentVisualizationData?.ModelMesh != null;
     meshFilter.sharedMesh    = currentVisualizationData?.ModelMesh;
 }