Beispiel #1
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);
                        }));
                    }
                }