/// <summary>
        /// Updates a surface entity
        /// </summary>
        /// <param name="surface">The MixedReality surface information</param>
        /// <param name="surfaceEntity">The entity to update</param>
        protected override void UpdateSurfaceEntity(SpatialMappingSurface surface, Entity surfaceEntity)
        {
            Transform3D transform = surfaceEntity.FindComponent <Transform3D>();

            transform.LocalPosition    = surface.Position;
            transform.LocalScale       = surface.Scale;
            transform.LocalOrientation = surface.Orientation;
        }
예제 #2
0
        /// <summary>
        /// Handles the SurfaceObserver's OnSurfaceChanged event.
        /// </summary>
        /// <param name="id">The identifier assigned to the surface which has changed.</param>
        /// <param name="surface">The surface</param>
        /// <param name="changeType">The type of change that occurred on the surface.</param>
        /// <param name="updateTime">The date and time at which the change occurred.</param>
        protected virtual void OnSurfaceChanged(Guid id, SpatialMappingSurface surface, SurfaceChange changeType, DateTimeOffset updateTime)
        {
            WaveForegroundTask.Run(() =>
            {
                if (surface.Mesh == null)
                {
                    return;
                }

                Debug.WriteLine("OnSurfaceChanged [" + changeType + "] " + id);

                string entityId = this.GetEntityNameFromSurfaceId(id);

                switch (changeType)
                {
                case SurfaceChange.Added:
                case SurfaceChange.Updated:

                    var surfaceEntity = this.Owner.FindChild(entityId);
                    if (surfaceEntity == null)
                    {
                        surfaceEntity     = this.CreateNewSurfaceEntity(entityId, surface);
                        surfaceEntity.Tag = SurfaceEntityTag;

                        if (surfaceEntity != null)
                        {
                            this.Owner.AddChild(surfaceEntity);
                        }
                    }
                    else
                    {
                        this.RefreshModel(surface, surfaceEntity);
                        this.UpdateSurfaceEntity(surface, surfaceEntity);
                    }

                    break;

                case SurfaceChange.Removed:

                    // Remove the child entity
                    this.Owner.RemoveChild(entityId);

                    break;

                default:
                    break;
                }
            });
        }
        /// <summary>
        /// Refresh the surface mesh
        /// </summary>
        /// <param name="surface">The MixedReality surface information</param>
        /// <param name="surfaceEntity">The entity to update</param>
        protected override void RefreshModel(SpatialMappingSurface surface, Entity surfaceEntity)
        {
            if (!surfaceEntity.IsDisposed)
            {
                surfaceEntity.RemoveComponent <CustomMesh>()
                .RemoveComponent <MeshRenderer>()
                .AddComponent(new CustomMesh()
                {
                    Mesh = surface.Mesh
                });

                if (this.IsVisible && !string.IsNullOrEmpty(this.MaterialPath))
                {
                    surfaceEntity.AddComponent(new MeshRenderer());
                }
            }
        }
        /// <summary>
        /// Creates a new entity from a surface
        /// </summary>
        /// <param name="entityName">The entity Name</param>
        /// <param name="surface">The MixedReality surface information</param>
        /// <returns>The new entity</returns>
        protected override Entity CreateNewSurfaceEntity(string entityName, SpatialMappingSurface surface)
        {
            var surfaceEntity = new Entity(entityName)
            {
                IsSerializable = false,
            }
            .AddComponent(new Transform3D());

            if (!string.IsNullOrEmpty(this.MaterialPath))
            {
                surfaceEntity.AddComponent(new MaterialComponent()
                {
                    MaterialPath = this.MaterialPath,
                    UseCopy      = this.UseMaterialCopy,
                });
            }

            this.RefreshModel(surface, surfaceEntity);
            this.UpdateSurfaceEntity(surface, surfaceEntity);
            this.RefreshCollider(surfaceEntity);

            return(surfaceEntity);
        }
예제 #5
0
 /// <summary>
 /// Refresh the surface mesh
 /// </summary>
 /// <param name="surface">The MixedReality surface information</param>
 /// <param name="surfaceEntity">The entity to update</param>
 protected abstract void RefreshModel(SpatialMappingSurface surface, Entity surfaceEntity);
예제 #6
0
 /// <summary>
 /// Updates a surface entity
 /// </summary>
 /// <param name="surface">The MixedReality surface information</param>
 /// <param name="surfaceEntity">The entity to update</param>
 protected abstract void UpdateSurfaceEntity(SpatialMappingSurface surface, Entity surfaceEntity);
예제 #7
0
 /// <summary>
 /// Creates a new entity from a surface
 /// </summary>
 /// <param name="entityName">The entity Name</param>
 /// <param name="surface">The MixedReality surface information</param>
 /// <returns>The new entity</returns>
 protected abstract Entity CreateNewSurfaceEntity(string entityName, SpatialMappingSurface surface);