Exemple #1
0
        public void OnVisibilityEvent(SyncedData <GameObject> gameObject, StreamEvent eventType)
        {
            switch (eventType)
            {
            case StreamEvent.Added:
                if (m_BoundingBoxesByStreamKey.TryGetValue(gameObject.key, out var box))
                {
                    box.gameObject.SetActive(m_DisplayOnlyBoundingBoxes || gameObject.data == null);
                }
                if (m_GameObjectsByStreamKey.TryGetValue(gameObject.key, out var obj))
                {
                    obj.SetActive(!m_DisplayOnlyBoundingBoxes && gameObject.data != null);
                }
                break;

            case StreamEvent.Removed:
                if (m_BoundingBoxesByStreamKey.TryGetValue(gameObject.key, out box))
                {
                    box.gameObject.SetActive(false);
                }
                if (m_GameObjectsByStreamKey.TryGetValue(gameObject.key, out obj))
                {
                    obj.SetActive(false);
                }
                break;
            }
        }
#pragma warning restore 649

        protected override void Import(RpcContext <ConvertResource <SyncMesh> > ctx, SyncedData <SyncMesh> resource)
        {
            MeshImportJob jobData;
            var           vCount = resource.data.Vertices.Count;

            if (vCount > k_MaxUInt16VertexCount)
            {
                jobData = ImportMesh <uint>(resource.data);
            }
            else
            {
                jobData = ImportMesh <ushort>(resource.data);
            }

            var rpc = m_DelegateJobOutput.Call(this, ctx, jobData, new DelegateJob(jobData, MeshConverterMainThreadJob));

            rpc.Success <MeshImportJob>((self, ctx, jobData, _) =>
            {
                ctx.SendSuccess(new ConvertedResource {
                    MainResource = jobData.Result, Dependencies = new List <Guid>()
                });
            });

            rpc.Failure((self, ctx, meshImport, ex) =>
            {
                ctx.SendFailure(ex);
            });
        }
Exemple #3
0
        public void OnGameObjectEvent(SyncedData <GameObject> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                var gameObject = stream.data;
                if (!gameObject.TryGetComponent(out MeshFilter meshFilter))
                {
                    return;
                }

                // When multiple instances of the same SyncObject get converted, instead of creating a GameObject every time from scratch,
                // the InstanceConverterNode duplicates the first generated GameObject.
                // This allows a big performance gain, but the drawback is that the output GameObject is not guaranteed to be "clean" ;
                // because any change that has been performed to the first GameObject (from a Node or anywhere else) will be present
                // in the following instances of the same SyncObject.

                // In this situation, the AddColliderNode automatically adds a MeshCollider to the first GameObject.
                // Any new instance of the same SyncObject will thus trigger the duplication of this first GameObject.
                // For that reason, we add this safety check not to add the same MeshCollider component twice.
                if (gameObject.TryGetComponent(out MeshCollider _))
                {
                    return;
                }

                var collider = gameObject.AddComponent <MeshCollider>();
                collider.sharedMesh = meshFilter.sharedMesh;
            }
        }
Exemple #4
0
 public void OnStreamInstanceEvent(SyncedData <StreamInstance> streamInstance, StreamEvent streamEvent)
 {
     if (streamEvent == StreamEvent.Added)
     {
         OnStreamAdded(streamInstance);
     }
 }
Exemple #5
0
        public void OnGameObjectEvent(SyncedData <GameObject> gameObject, StreamEvent eventType)
        {
            switch (eventType)
            {
            case StreamEvent.Added:
                m_GameObjectsByStreamKey[gameObject.key] = gameObject.data;
                if (m_BoundingBoxesByStreamKey.TryGetValue(gameObject.key, out var box))
                {
                    SetStreamState(box, StreamState.GameObject);
                    // deactivate gameObject if box was inactive for loading hidden objects
                    var wasActive = box.gameObject.activeSelf;
                    gameObject.data.SetActive(wasActive);
                    box.gameObject.SetActive(m_DisplayOnlyBoundingBoxes && wasActive);
                }
                if (m_DisplayOnlyBoundingBoxes)
                {
                    gameObject.data.SetActive(false);
                }
                if (settings.useStaticBatching && m_GameObjectsByStreamKey.Count == m_BoundingBoxesByStreamKey.Count)
                {
                    StaticBatchingUtility.Combine(gameObject.data.transform.parent.gameObject);
                }
                break;

            // TODO: changed
            case StreamEvent.Removed:
                m_GameObjectsByStreamKey.Remove(gameObject.key);
                if (m_BoundingBoxesByStreamKey.TryGetValue(gameObject.key, out box))
                {
                    box.gameObject.SetActive(true);
                }
                break;
            }
        }
Exemple #6
0
        public void OnAssetEvent(SyncedData <StreamAsset> streamAsset, StreamEvent eventType)
        {
            if (!PersistentKey.IsKeyFor <SyncObjectInstance>(streamAsset.key.key) ||
                streamAsset.data.boundingBox.Max.Equals(streamAsset.data.boundingBox.Min))
            {
                return;
            }

            switch (eventType)
            {
            case StreamEvent.Added:
                AddOrEditBoundingBox(streamAsset.data.key, streamAsset.data.boundingBox, StreamState.Asset, false);
                break;

            case StreamEvent.Changed:
                if (!m_BoundingBoxesByStreamKey.TryGetValue(streamAsset.key, out var box))
                {
                    break;
                }
                SetBoundingBoxValues(box, streamAsset.data.boundingBox);
                break;

            case StreamEvent.Removed:
                ReleaseBoundingBoxReference(m_BoundingBoxesByStreamKey[streamAsset.key]);
                m_BoundingBoxesByStreamKey.Remove(streamAsset.key);
                break;
            }
        }
Exemple #7
0
        public void OnStreamEvent(SyncedData <TModel> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                var obj = Import(stream);

                if (m_MemTracker.ContainsKey(m_ObjectHandle, stream.key))
                {
                    Debug.Log("Duplicate " + obj.name);
                }

                m_MemTracker.Set(m_ObjectHandle, stream.key, obj);

                m_Output.SendStreamAdded(new SyncedData <TObject>(stream.key, obj));
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                if (m_MemTracker.TryGetValue(m_ObjectHandle, stream.key, out var obj))
                {
                    ReImport(stream, obj);
                }
                else
                {
                    // We may receive "Changed" for items that were
                    // loaded at some point, but are not in the cache anymore
                    obj = Import(stream);
                    m_MemTracker.Set(m_ObjectHandle, stream.key, obj);
                }

                m_Output.SendStreamChanged(new SyncedData <TObject>(stream.key, obj));
            }
        }
        public void OnStreamGameObjectEvent(SyncedData <GameObject> gameObject, StreamEvent eventType)
        {
            if (!settings.isActive)
            {
                return;
            }

            if (!m_ObjectsByStreamKey.TryGetValue(gameObject.key, out var obj))
            {
                return;
            }

            switch (eventType)
            {
            case StreamEvent.Added:
            case StreamEvent.Changed:
                obj.loadedObject  = gameObject.data;
                obj.MeshRenderers = gameObject.data.GetComponentsInChildren <MeshRenderer>();
                // disable mesh renderers to avoid popping when displaying only bounding boxes
                foreach (var meshRenderer in obj.MeshRenderers)
                {
                    meshRenderer.enabled = false;
                }
                break;

            case StreamEvent.Removed:
                obj.loadedObject  = null;
                obj.MeshRenderers = null;
                break;
            }
            obj.HasMeshRendererChanged = true;
        }
        protected override Material Import(SyncedData <SyncMaterial> syncedMaterial)
        {
            Material material;

            var syncMaterial = syncedMaterial.data;
            var sourceId     = syncedMaterial.key.source;

            if (syncMaterial.Alpha >= 1.0f)
            {
                material = new Material(m_OpaqueShader);

                var map = syncMaterial.AlbedoMap;
                if (map.TextureId != SyncId.None)
                {
                    var textureKey = StreamKey.FromSyncId <SyncTexture>(sourceId, map.TextureId);
                    material.SetTexture("_MainTex", m_TextureCache.GetTexture(textureKey));

                    var offset = map.Offset;
                    material.SetTextureOffset("_MainTex", new Vector2(offset.X, offset.Y));

                    var tiling = map.Tiling;
                    material.SetTextureScale("_MainTex", new Vector2(tiling.X, tiling.Y));
                }
            }
            else
            {
                material = new Material(m_TransparentShader);
                material.SetFloat("_Alpha", syncMaterial.Alpha);
            }

            return(material);
        }
Exemple #10
0
        protected override void UpdateInternal(float unscaledDeltaTime)
        {
            while (m_PendingRemoved.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamRemoved(syncedData);
            }

            while (m_PendingAdded.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamAdded(syncedData);
            }

            while (m_PendingModified.TryDequeue(out var stream))
            {
                var streamAsset = (StreamAsset)stream;
                var syncedData  = new SyncedData <StreamAsset>(streamAsset.key, streamAsset);
                m_AssetOutput.SendStreamChanged(syncedData);
            }

            if (m_Task != null && m_Task.IsCompleted)
            {
                m_AssetOutput.SendEnd();
                m_Task = null;

                LogTimes();
            }
        }
Exemple #11
0
        public void OnGameObjectEvent(SyncedData <GameObject> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                var gameObject = stream.data;
                if (!gameObject.TryGetComponent(out Metadata metadata))
                {
                    return;
                }

                if (!metadata.parameters.dictionary.TryGetValue("Category", out var category))
                {
                    return;
                }

                if (!metadata.parameters.dictionary.TryGetValue("Family", out var family))
                {
                    return;
                }

                foreach (var entry in m_Settings.entries)
                {
                    if (category.value.Contains(entry.category) && family.value.Contains(entry.family))
                    {
                        Object.Instantiate(entry.prefab, gameObject.transform);
                        return;
                    }
                }
            }
        }
Exemple #12
0
        public void OnStreamEvent(SyncedData <GameObject> gameObject, StreamEvent streamEvent)
        {
            var lights = gameObject.data.GetComponentsInChildren <Light>(true);

            if (lights == null || lights.Length == 0)
            {
                return;
            }

            switch (streamEvent)
            {
            case StreamEvent.Added:
                foreach (var light in lights)
                {
                    light.enabled = m_Settings.enableLights;
                    m_Lights.Add(light);
                }
                break;

            case StreamEvent.Removed:
                foreach (var light in lights)
                {
                    m_Lights.Remove(light);
                }
                break;
            }
        }
Exemple #13
0
        void OnStreamAdded(SyncedData <StreamInstance> stream)
        {
            var syncMetadata = stream.data.instance.Metadata;

            if (syncMetadata == null)
            {
                return;
            }


            foreach (var key in m_Settings.m_Safelist)
            {
                if (syncMetadata.Parameters.TryGetValue(key, out SyncParameter category))
                {
                    if (!m_FilterGroups.ContainsKey(key))
                    {
                        m_FilterGroups[key] = new Dictionary <string, FilterData>();
                        m_Settings.groupsChanged?.Invoke(m_FilterGroups.Keys.OrderBy(e => e));
                    }

                    var dicFilterData = m_FilterGroups[key];
                    if (!dicFilterData.ContainsKey(category.Value))
                    {
                        dicFilterData[category.Value] = new FilterData();
                        m_Settings.categoriesChanged?.Invoke(key, dicFilterData.Keys.OrderBy(e => e));
                    }
                }
            }
        }
Exemple #14
0
            /// <summary>
            /// Create SyncedData object directly from a JSON string.
            /// </summary>
            /// <returns>The deserialized data packet.</returns>
            /// <param name="json">JSON string representing the data.</param>
            public static SyncedData FromJSON(string json)
            {
                SyncedData data = new SyncedData();

                SyncedData.PopulateFromJSON(json, data);

                return(data);
            }
Exemple #15
0
        public TAsset Import(SyncedData <TModel> model, object settings)
        {
            var asset = CreateNew(model.data, settings);

            ImportInternal(model, asset, settings);

            return(asset);
        }
            public SpatialObject(SyncedData<StreamAsset> streamAsset)
            {
                StreamAsset = streamAsset;
                SyncedGameObject = new SyncedData<GameObject>(streamAsset.key, null);

                var syncBb = streamAsset.data.boundingBox;
                min = new Vector3(syncBb.Min.X, syncBb.Min.Y, syncBb.Min.Z);
                max = new Vector3(syncBb.Max.X, syncBb.Max.Y, syncBb.Max.Z);
                center = min + (max - min) / 2f;
            }
Exemple #17
0
        public void OnStreamEvent(SyncedData <StreamInstanceData> stream, StreamEvent streamEvent)
        {
            var objectKey = new StreamKey(stream.key.source, PersistentKey.GetKey <SyncObject>(stream.data.syncObject.Id));

            if (streamEvent == StreamEvent.Added)
            {
                m_SyncObjects[objectKey] = stream.data.syncObject;
                var syncObjectBinding = ImportInstance(stream.data.instance);

                var key = stream.data.instance.key;
                m_Instances[key]            = syncObjectBinding;
                syncObjectBinding.streamKey = key;

                m_Output.SendStreamAdded(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                var key = stream.data.instance.key;
                // The instance moved, or the name/metadata changed.
                var syncObjectBinding = m_Instances[key];

                ImportersUtils.SetTransform(syncObjectBinding.transform, stream.data.instance.instance.Transform);
                ImportersUtils.SetMetadata(syncObjectBinding.gameObject, stream.data.instance.instance.Metadata);
                syncObjectBinding.gameObject.name = stream.data.instance.instance.Name;

                m_Output.SendStreamChanged(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                var key = stream.data.instance.key;
                // The instance either moved, or the metadata changed.
                var syncObjectBinding = m_Instances[key];

                m_Instances.Remove(key);

                m_Output.SendStreamRemoved(new SyncedData <GameObject>(key, syncObjectBinding.gameObject));

                if (m_Originals.TryGetValue(objectKey, out var original))
                {
                    UntrackDependencies(original.Dependencies);

                    if (original.NbActiveInstances == 1)
                    {
                        m_Originals.Remove(objectKey);
                    }
                    else
                    {
                        --original.NbActiveInstances;
                        m_Originals[objectKey] = original;
                    }
                }

                Object.Destroy(syncObjectBinding.gameObject);
            }
        }
Exemple #18
0
 public void OnGameObjectAdded(SyncedData <GameObject> gameObject, StreamEvent streamEvent)
 {
     if (streamEvent == StreamEvent.Added)
     {
         OnStreamAdded(gameObject);
     }
     else if (streamEvent == StreamEvent.Removed)
     {
         OnStreamRemoved(gameObject);
     }
 }
Exemple #19
0
        protected override void ImportInternal(SyncedData <SyncTexture> syncTexture, Texture2D texture, object settings)
        {
            var data = syncTexture.data.Source;

            texture.LoadImage(data);

            if (syncTexture.data.ConvertToNormalMap)
            {
                ConvertToNormalMap(texture, k_NormalMapIntensity, false);
            }
        }
Exemple #20
0
 public void OnGameObjectEvent(SyncedData <GameObject> gameObjectData, StreamEvent streamEvent)
 {
     if (streamEvent == StreamEvent.Added)
     {
         OnGameObjectAdded(gameObjectData.data);
     }
     else if (streamEvent == StreamEvent.Removed)
     {
         OnGameObjectRemoved(gameObjectData.data);
     }
 }
Exemple #21
0
 public void OnInstanceDataEvent(SyncedData <StreamInstanceData> streamInstanceData, StreamEvent eventType)
 {
     switch (eventType)
     {
     case StreamEvent.Added:
         if (m_BoundingBoxesByStreamKey.TryGetValue(streamInstanceData.key, out var box))
         {
             SetStreamState(box, StreamState.InstanceData);
         }
         break;
     }
 }
Exemple #22
0
        public void OnStreamRemoved(SyncedData <StreamInstance> stream)
        {
            var metadata = stream.data.instance.Metadata;

            if (metadata != null && metadata.Parameters.TryGetValue("Category", out var category))
            {
                if (m_Instances.TryGetValue(category.Value, out var filter))
                {
                    filter.streams.Remove(stream);
                }
            }

            m_StreamOutput.SendStreamRemoved(stream);
        }
Exemple #23
0
        public void OnStreamInstanceEvent(SyncedData <StreamAsset> stream, StreamEvent streamEvent)
        {
            if (streamEvent == StreamEvent.Added)
            {
                if (!PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    return;
                }

                EnqueueDownloadRequest(stream.data);
            }
            else if (streamEvent == StreamEvent.Changed)
            {
                if (PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    EnqueueDownloadRequest(stream.data);
                }
                else if (PersistentKey.IsKeyFor <SyncObject>(stream.key.key))
                {
                    var instances = m_Instances[stream.key];

                    foreach (var instance in instances)
                    {
                        m_DirtySyncObject.Add(instance.key);
                        EnqueueDownloadRequest(instance);
                    }
                }
            }
            else if (streamEvent == StreamEvent.Removed)
            {
                if (!PersistentKey.IsKeyFor <SyncObjectInstance>(stream.key.key))
                {
                    return;
                }

                var key = stream.key;
                if (m_Cache.TryGetValue(key, out var value))
                {
                    m_Cache.Remove(key);

                    // Removing the deleted instance from m_Instances
                    var persistentKey = PersistentKey.GetKey <SyncObject>(value.instance.ObjectId);
                    var objectKey     = new StreamKey(key.source, persistentKey);
                    var instances     = m_Instances[objectKey];
                    instances.Remove(stream.data);

                    m_InstanceDataOutput.SendStreamRemoved(new SyncedData <StreamInstance>(key, value));
                }
            }
        }
Exemple #24
0
 public void OnStreamEvent(SyncedData <StreamInstance> stream, StreamEvent streamEvent)
 {
     if (streamEvent == StreamEvent.Added)
     {
         OnStreamAdded(stream);
     }
     else if (streamEvent == StreamEvent.Changed)
     {
         OnStreamChanged(stream);
     }
     else if (streamEvent == StreamEvent.Removed)
     {
         OnStreamRemoved(stream);
     }
 }
Exemple #25
0
        public void OnStreamInstanceEvent(SyncedData <StreamInstance> stream, StreamEvent streamEvent)
        {
            if (streamEvent != StreamEvent.Added)
            {
                return;
            }

            var metadata = stream.data.instance.Metadata;

            if (metadata != null && metadata.Parameters.TryGetValue("Category", out var category))
            {
                if (!m_Instances.ContainsKey(category.Value))
                {
                    m_Instances[category.Value] = new FilterData();
                }
            }
        }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var syncTexture = PlayerFile.Load <SyncTexture>(ctx.assetPath);
            var syncedData  = new SyncedData <SyncTexture>(StreamKey.FromSyncId <SyncTexture>(ReflectScriptedImporter.EditorSourceId, syncTexture.Id), syncTexture);

            var textureImporter = new SyncTextureImporter();
            var texture         = textureImporter.Import(syncedData, null);

            texture.name = Path.GetFileNameWithoutExtension(syncTexture.Name);

            ctx.AddObjectToAsset("texture", texture);

            var root = ScriptableObject.CreateInstance <ReflectScriptableObject>();

            ctx.AddObjectToAsset("root", root, AssetPreview.GetMiniThumbnail(texture));
            ctx.SetMainObject(root);
        }
Exemple #27
0
        public void OnInstanceStreamEvent(SyncedData <StreamInstance> streamInstance, StreamEvent eventType)
        {
            switch (eventType)
            {
            case StreamEvent.Added:
                m_InstanceCountData.addedCount++;
                break;

            case StreamEvent.Changed:
                m_InstanceCountData.changedCount++;
                break;

            case StreamEvent.Removed:
                m_InstanceCountData.removedCount++;
                break;
            }
            m_Settings.instanceCountModified?.Invoke(m_InstanceCountData);
        }
Exemple #28
0
        public void OnAssetStreamEvent(SyncedData <StreamAsset> streamAsset, StreamEvent eventType)
        {
            switch (eventType)
            {
            case StreamEvent.Added:
                m_AssetCountData.addedCount++;
                break;

            case StreamEvent.Changed:
                m_AssetCountData.changedCount++;
                break;

            case StreamEvent.Removed:
                m_AssetCountData.removedCount++;
                break;
            }
            m_Settings.assetCountModified?.Invoke(m_AssetCountData);
        }
        public void OnStreamAssetEvent(SyncedData <StreamAsset> streamAsset, StreamEvent eventType)
        {
            if (!settings.isActive ||
                !PersistentKey.IsKeyFor <SyncObjectInstance>(streamAsset.key.key) ||
                streamAsset.data.boundingBox.Max.Equals(streamAsset.data.boundingBox.Min))
            {
                m_StreamOutput.SendStreamEvent(streamAsset, eventType);
                return;
            }

            SpatialObject obj;

            if (eventType == StreamEvent.Added)
            {
                obj = new SpatialObject(streamAsset);
            }
            else if (!m_ObjectsByStreamKey.TryGetValue(streamAsset.key, out obj))
            {
                return;
            }

            switch (eventType)
            {
            case StreamEvent.Added:
                m_ObjectsByStreamKey.Add(streamAsset.key, obj);
                Add(obj);
                break;

            case StreamEvent.Changed:
                Remove(obj);
                Add(obj);
                m_StreamOutput.SendStreamChanged(streamAsset);
                break;

            case StreamEvent.Removed:
                m_ObjectsByStreamKey.Remove(streamAsset.key);
                Remove(obj);
                obj.Dispose();
                m_StreamOutput.SendStreamRemoved(streamAsset);
                break;
            }
        }
Exemple #30
0
        public void OnFilteredAssetEvent(SyncedData <StreamAsset> streamAsset, StreamEvent eventType)
        {
            switch (eventType)
            {
            case StreamEvent.Added:
                if (m_BoundingBoxesByStreamKey.TryGetValue(streamAsset.key, out var box))
                {
                    SetStreamState(box, StreamState.FilteredAsset);
                }
                break;

            case StreamEvent.Removed:
                if (m_BoundingBoxesByStreamKey.TryGetValue(streamAsset.key, out box))
                {
                    SetStreamState(box, StreamState.Removed);
                    box.gameObject.SetActive(true);
                }
                break;
            }
        }
	void Start () {syncdData = new SyncedData (); }