Пример #1
0
                private void content_SelectionChanged(object sender, SelectionChangedEventArgs e)
                {
                    AssetCacheData data = (AssetCacheData)e.AddedItems[0];

                    switch (data.type)
                    {
                    case AssetType.kMaterial:
                        ReadMaterialData(data.path);
                        break;
                    }
                }
 /**
  * @brief Find an asset by its id.
  * @param[in] id (UInt64) id of the asset to find.
  * @return (sulphur.editor.AssetCacheData) The data stored in the cache of the asset of the given id. If not found an invalid struct is returned.
  * @see sulphur.editor.AssetCacheData
  */
 public AssetCacheData Find(UInt64 id, AssetType type)
 {
     foreach (var pair in data)
     {
         AssetCacheData foundObj = pair.Value.Find(id, type);
         if (foundObj.is_valid)
         {
             return(foundObj);
         }
     }
     return(new AssetCacheData());
 }
            /**
             *@brief instantiate an asset in the engine
             *@param[in] asset (sulphur.editor.AssetCacheData) asset to instantiate
             *@remark when this function is run an instantiate message will be send to the connected engine
             */
            private void Instantiate(AssetCacheData asset)
            {
                if (asset.type != AssetType.kModel)
                {
                    return;
                }

                native.messages.AssetInstantiatedPayload msg_data = new native.messages.AssetInstantiatedPayload();
                msg_data.asset_id = asset.id;
                byte[] data = Utils.StructToBytes(msg_data);
                native.Networking.SNetSendData((uint)native.NetworkMessages.kAssetInstantiated,
                                               data, (uint)data.Length);
            }
Пример #4
0
 /**
  * @brief Handle incomming messages from the attached asset browser control.
  * @param[in] sender (object) The asset browser control that send the notification.
  * @param[in] e (NotificationEventArgs) Argument send with the event.
  */
 void HandleAssetBrowsermessages(object sender, NotificationEventArgs e)
 {
     if (e.notification_id == (int)controls.AssetBrowserControl.Notifications.kAssetInstantiated)
     {
         AssetCacheData data = (AssetCacheData)e.notification_data;
         if (data.type == AssetType.kWorld)
         {
             App.Current.Dispatcher.Invoke(delegate
             {
                 Clear();
                 hierarchy.LoadFromDisk(data.origin);
                 Project.current_world_ = data.origin.Remove(0, Project.directory_path.Length + 1);
             });
         }
         return;
     }
 }
            /**
             * @brief Processes a single entry in an asset cache;
             * @param[in] id (UInt64) id of the asset.
             * @param[in] ptr (sulphur.editor.AssetDatabase.PackagePtr) Package pointer read from the cache.
             */
            private void ProcessCacheFileData(UInt64 id, PackagePtr ptr)
            {
                AssetCacheData cache_data = new AssetCacheData();
                DirectoryInfo  info       = new DirectoryInfo(Project.directory_path + "\\" + ptr.origin);
                int            slash      = ptr.path.LastIndexOf("/") + 1;
                int            dot        = ptr.path.LastIndexOf(".");

                cache_data.id     = id;
                cache_data.path   = ptr.path;
                cache_data.origin = info.FullName.ToLower();
                cache_data.name   = ptr.path.Substring(slash,
                                                       dot - slash);
                cache_data.type     = GetAssetType(ptr.path);
                cache_data.is_valid = true;
                string original_folder = info.FullName.Substring(0, info.FullName.LastIndexOf("\\")).ToLower();

                if (data.ContainsKey(original_folder) == false)
                {
                    AssetList new_list = new AssetList();
                    new_list.CollectionChanged += OnAssetListChanged;
                    data.Add(original_folder, new_list);
                }

                AssetCacheData exists = data[original_folder].Find(cache_data.id, cache_data.type);

                if (exists.is_valid == true)
                {
                    Log.Write(Log.Verbosity.kWarning, "Asset {0} allready exists", cache_data.path);
                    return;
                }

                App.Current.Dispatcher.Invoke(delegate
                {
                    data[original_folder].Add(cache_data);
                });
            }
Пример #6
0
                private void ReadMaterialData(string relative_path)
                {
                    BinaryReader reader = new BinaryReader(Project.directory_path + "\\" + relative_path);

                    if (!reader.is_ok)
                    {
                        return;
                    }

                    MaterialData material_data = new MaterialData();

                    material_data.Read(reader);

                    AssetDatabase asset_database = (AssetDatabase)App.Current.Resources["asset_database"];

                    AssetCacheData pixel_shader_cache = asset_database.Find(material_data.pixel_shader_id, AssetType.kShader);
                    ShaderData     pixelShader        = ReadShaderData(pixel_shader_cache.path);

                    ub = new UniformBuffer(pixelShader, material_data.uniform_buffers[0].data);

                    inspector_.ClearInspectors();

                    foreach (var pair in ub.name_map_)
                    {
                        ShaderVariable var  = ub.data_map_[pair.Value];
                        InspectorTypes type = InspectorTypes.kNumber;

                        switch (var.type_)
                        {
                        case ShaderVarType.kBool:
                            type = InspectorTypes.kCheckbox;
                            break;

                        case ShaderVarType.kFloat:
                        case ShaderVarType.kDouble:
                            type = InspectorTypes.kSlider;
                            break;

                        case ShaderVarType.kUint:
                        case ShaderVarType.kUint8:
                        case ShaderVarType.kInt:
                            type = InspectorTypes.kNumber;
                            break;

                        case ShaderVarType.kMat3:
                            type = InspectorTypes.kMatrix3x3;
                            break;

                        case ShaderVarType.kMat4:
                            type = InspectorTypes.kMatrix4x4;
                            break;

                        case ShaderVarType.kVec2:
                            type = InspectorTypes.kVector2;
                            break;

                        case ShaderVarType.kVec3:
                            type = InspectorTypes.kVector3;
                            break;

                        case ShaderVarType.kVec4:
                            type = InspectorTypes.kVector4;
                            break;
                        }

                        inspector_.AddInspector(pair.Key, type,
                                                new VarRef(() => ub.data_map_[pair.Value].data_,
                                                           val => {
                            ub.data_map_[pair.Value].Set(val);
                            material_data.uniform_buffers[0].data = ub.ConstructDataBuffer();
                            StoreMaterialData(relative_path, material_data);
                        }));
                    }
                }
            /**
             *@brief remove an asset from the asset cache. when the asset is removed succesfully a message is send to the attached engine.
             *@param[in] asset (sulphur.editor.AssetCacheData) asset to remove from the cache
             *@remark this will not delete the raw asset the packed asset originated from.
             *@see sulphur.editor.native.networking.NetworkMessages
             */
            public void DeleteAsset(AssetCacheData asset)
            {
                string folderpath = asset.origin.Substring(0, asset.origin.LastIndexOf("\\"));

                native.bool_ success = false;
                if (data.ContainsKey(folderpath) == false)
                {
                    return;
                }

                foreach (AssetCacheData entry in data[folderpath])
                {
                    if (entry.origin == asset.path)
                    {
                        asset = entry;
                    }
                }

                switch (asset.type)
                {
                case AssetType.kAnimation:
                    success = native.AssetProcessor.DeleteAnimation(asset.id);
                    break;

                case AssetType.kAudio:
                    success = native.AssetProcessor.DeleteAudio(asset.id);
                    break;

                case AssetType.kMaterial:
                    success = native.AssetProcessor.DeleteMaterial(asset.id);
                    break;

                case AssetType.kMesh:
                    success = native.AssetProcessor.DeleteMesh(asset.id);
                    break;

                case AssetType.kModel:
                    success = native.AssetProcessor.DeleteModel(asset.id);
                    break;

                case AssetType.kScript:
                    success = native.AssetProcessor.DeleteScript(asset.id);
                    break;

                case AssetType.kShader:
                    success = native.AssetProcessor.DeleteShader(asset.id);
                    break;

                case AssetType.kSkeleton:
                    success = native.AssetProcessor.DeleteSkeleton(asset.id);
                    break;

                case AssetType.kTexture:
                    success = native.AssetProcessor.DeleteTexture(asset.id);
                    break;
                }

                if (success == true)
                {
                    UpdateDatabase(asset.id, Operation.kRemove, asset.type);
                }
            }