private void ConvertMaterials(MaterialDictionary materialDictionary) { foreach (var material in materialDictionary.Materials) { mAiScene.Materials.Add(ConvertMaterial(material)); } }
public void loadCardDetails(GameObject cardDetails) { GameObject go = Instantiate(cardDetails, transform.transform); details = go.GetComponent <CardDetails>(); details.character = character; details.cardBase = this; details.prefabRef = cardDetails; name = details.cardName; string subtypesKey = ""; magicParticles.gameObject.SetActive(false); foreach (CardSubType type in details.subTypes) { string subType = type.ToString().ToLower(); if (subType.Equals("magic")) { magicParticles.gameObject.SetActive(true); } else { subtypesKey += subType; } } cardMeshRenderer.material = MaterialDictionary.Instance().materialDictionary[subtypesKey]; cardNameMesh.text = details.cardName; energyPlayCostMesh.text = details.getEnergyPlayCost().ToString(); focusPlayCostMesh.text = (details.getFocusPlayCost() > 0 ? details.getFocusPlayCost().ToString() : ""); artSprite.sprite = details.art; typelineMesh.text = details.getTypeLine(); focusLearnCostMesh.text = details.getFocusLearnCost().ToString(); resetCardInfo(); }
public void MaterialDictionary_retrieveMaterial_propertyOK() { var matDict = new MaterialDictionary(); var mat = new Material(MaterialType.Metal, "steel", .25, 100, 79, 70); matDict.AddMaterial(mat); }
static ModelDataProvider() { SolidColorBrush transparentBrush = new SolidColorBrush(Colors.LightBlue); transparentBrush.Opacity = 0.5; MaterialGroup windowMaterial = new MaterialGroup(); windowMaterial.Children.Add(new DiffuseMaterial(transparentBrush)); windowMaterial.Children.Add(new SpecularMaterial(transparentBrush, 40)); _defaultMaterials = new MaterialDictionary(); _defaultMaterials.Add("IfcProduct", new DiffuseMaterial(new SolidColorBrush(Colors.Wheat))); _defaultMaterials.Add("IfcBuildingElementProxy", new DiffuseMaterial(new SolidColorBrush(Colors.Snow))); _defaultMaterials.Add("IfcWall", new DiffuseMaterial(new SolidColorBrush(Colors.White))); _defaultMaterials.Add("IfcRoof", new DiffuseMaterial(new SolidColorBrush(Colors.LightSteelBlue))); _defaultMaterials.Add("IfcSlab", new DiffuseMaterial(new SolidColorBrush(Colors.LightSteelBlue))); _defaultMaterials.Add("IfcWindow", windowMaterial); _defaultMaterials.Add("IfcPlate", windowMaterial); _defaultMaterials.Add("IfcDoor", new DiffuseMaterial(new SolidColorBrush(Colors.CadetBlue))); _defaultMaterials.Add("IfcStair", new DiffuseMaterial(new SolidColorBrush(Colors.Wheat))); _defaultMaterials.Add("IfcBeam", new DiffuseMaterial(new SolidColorBrush(Colors.LightSlateGray))); _defaultMaterials.Add("IfcColumn", new DiffuseMaterial(new SolidColorBrush(Colors.LightSlateGray))); _defaultMaterials.Add("IfcFurnishingElement", new DiffuseMaterial(new SolidColorBrush(Colors.WhiteSmoke) { Opacity = 0.7 })); _defaultMaterials.Add("IfcDistributionFlowElement", new DiffuseMaterial(new SolidColorBrush(Colors.AntiqueWhite) { Opacity = 1.0 })); _defaultMaterials.Add("IfcFlowFitting", new DiffuseMaterial(new SolidColorBrush(Colors.PaleGoldenrod) { Opacity = 1.0 })); _defaultMaterials.Add("IfcFlowSegment", new DiffuseMaterial(new SolidColorBrush(Colors.PaleVioletRed) { Opacity = 1.0 })); _defaultMaterials.Add("IfcFlowTerminal", new DiffuseMaterial(new SolidColorBrush(Colors.IndianRed) { Opacity = 1.0 })); _defaultMaterials.Add("IfcSpace", new DiffuseMaterial(new SolidColorBrush(Colors.Red) { Opacity = 0.4 })); _defaultMaterials.Add("IfcRailing", new DiffuseMaterial(new SolidColorBrush(Colors.Goldenrod))); _defaultMaterials.Add("IfcOpeningElement", new DiffuseMaterial(new SolidColorBrush(Colors.Red) { Opacity = 0.4 })); }
public void MaterialDictionary_constructor_returnsZeroCount() { var matDict = new MaterialDictionary(); int count = matDict.Count; Assert.AreEqual(0, count); }
private static Material GetWpfMaterial(Xbim.Common.IModel model, int styleId) { var sStyle = model.Instances[styleId] as IIfcSurfaceStyle; var wpfMaterial = new WpfMaterial(); if (sStyle != null) { XbimTexture texture = XbimTexture.Create(sStyle); texture.DefinedObjectId = styleId; wpfMaterial.CreateMaterial(texture); return(wpfMaterial); } MaterialDictionary defaultMaterial = ModelDataProvider.DefaultMaterials; Material material; if (defaultMaterial.TryGetValue(model.GetType().Name, out material)) { return(material); } var color = new XbimColour("black", 1, 1, 1); wpfMaterial.CreateMaterial(color); return(wpfMaterial); }
private MeshData GetOrCreateMeshData(ValveBspFile bsp, GeometryPage page, string matPath, bool cacheVertices = true) { MaterialGroup matGroup; var matDictIndex = MaterialDictionary.GetResourceIndex(bsp, matPath); if (!page.MaterialIndices.TryGetValue(matDictIndex, out int matIndex)) { var vmt = ValveMaterialFile.FromProvider(MaterialDictionary.GetResourcePath(bsp, matDictIndex), bsp.PakFile, Program.Resources); matGroup = new MaterialGroup(matIndex = page.Materials.Count, cacheVertices) { Material = matDictIndex }; page.MaterialIndices.Add(matDictIndex, matIndex); page.Materials.Add(matGroup); FindMaterialAttributes(vmt, matGroup.MeshData.Attributes); } else { matGroup = page.Materials[matIndex]; } return(matGroup.MeshData); }
private static KeyframeRope InitKeyframeRope(KeyframeRope ent, ValveBsp.Entities.Entity value, MapParams mapParams) { var min = (SourceUtils.Vector3)value["origin"]; var max = min; ent.NextKey = value["NextKey"]; if (!string.IsNullOrEmpty(ent.NextKey)) { var next = mapParams.Bsp.Entities.FirstOrDefault(x => ent.NextKey.Equals(x["targetname"])); if (next != null) { var nextOrigin = (SourceUtils.Vector3)next["origin"]; min = SourceUtils.Vector3.Min(min, nextOrigin); max = SourceUtils.Vector3.Max(max, nextOrigin); } } var clusters = GetIntersectingClusters(mapParams.Tree, min, max); if (InitPvsEntity(ent, value, clusters) == null) { return(null); } ent.Width = value["Width"]; ent.TextureScale = value["TextureScale"]; ent.SubDivisions = value["Subdiv"]; ent.Slack = value["Slack"]; ent.RopeMaterial = MaterialDictionary.GetResourceIndex(mapParams.Bsp, value["RopeMaterial"]); ent.MoveSpeed = value["MoveSpeed"]; return(ent); }
// Material private void WriteMaterialDictionaryChunk(MaterialDictionary materialDictionary) { StartWritingChunk(materialDictionary.Version, ResourceChunkType.MaterialDictionary); WriteMaterialDictionary(materialDictionary); FinishWritingChunk(); }
private void WriteMaterialDictionary(MaterialDictionary materialDictionary) { WriteInt(materialDictionary.Count); foreach (var material in materialDictionary.Materials) { WriteMaterial(materialDictionary.Version, material); } }
public static MaterialDictionary Instance() { if (!materialDictionaryInstance) { materialDictionaryInstance = FindObjectOfType <MaterialDictionary>(); } return(materialDictionaryInstance); }
private void LoadMaterials(XElement xmlScene) { if (xmlScene != null && xmlScene.Elements("material_list").Any()) { XElement xmlMaterials = xmlScene.Elements("material_list").First(); foreach (XElement materialNode in xmlMaterials.Elements("material")) { string name = materialNode.Attribute("name").Value; Material material = new Material(name); if (materialNode.Elements("texture").Any()) { material.FileName = materialNode.Elements("texture").First().Attribute("filename").Value; } if (material.FileName != null && material.FileName != String.Empty && File.Exists(material.FileName)) { material.TextureImage = (Bitmap)Bitmap.FromFile(material.FileName); } if (materialNode.Elements("specular").Any()) { material.Specular = LoadSpecular(materialNode.Elements("specular").First()); } if (materialNode.Elements("diffuse").Any()) { material.Diffuse = LoadColor(materialNode.Elements("diffuse").First()); } if (materialNode.Elements("transparent").Any()) { material.Transparent = LoadColor(materialNode.Elements("transparent").First()); } if (materialNode.Elements("reflective").Any()) { material.Reflective = LoadColor(materialNode.Elements("reflective").First()); } if (materialNode.Elements("refraction_index").Any()) { material.RefractionIndex = LoadColor(materialNode.Elements("refraction_index").First()); } MaterialDictionary.Add(name, material); } } else { Material materialDefault = new Material("Yellow"); materialDefault.FileName = ""; materialDefault.Diffuse = new Vector(1, 1, 0); materialDefault.Specular = new Vector(0, 0, 0, 5); if (!MaterialDictionary.ContainsKey("Yellow")) { MaterialDictionary.Add("Yellow", materialDefault); } } }
public static Material GetMaterialByName(MaterialDictionary materialDictionary, string name) { if (!materialDictionary.TryGetMaterial(name, out var mat)) { return(null); } return(mat); }
public MaterialPage GetPage([Url] string map, [Url] int index) { var bsp = Program.GetMap(map); var first = index * MaterialPage.MaterialsPerPage; var count = Math.Min(first + MaterialPage.MaterialsPerPage, MaterialDictionary.GetResourceCount(bsp)) - first; if (count < 0) { first = MaterialDictionary.GetResourceCount(bsp); count = 0; } var texDict = new Dictionary <string, int>(); var page = new MaterialPage(); for (var i = 0; i < count; ++i) { var path = MaterialDictionary.GetResourcePath(bsp, first + i); var mat = Material.Get(bsp, path); page.Materials.Add(mat); if (mat == null) { continue; } foreach (var prop in mat.Properties) { if (prop.Type != MaterialPropertyType.TextureUrl) { continue; } prop.Type = MaterialPropertyType.TextureIndex; var texUrl = (Url)prop.Value; int texIndex; if (texDict.TryGetValue(texUrl, out texIndex)) { prop.Value = texIndex; continue; } prop.Value = texIndex = page.Textures.Count; var texPath = TextureController.GetTexturePath(texUrl); var tex = Texture.Get(bsp, texPath); texDict.Add(texUrl, texIndex); page.Textures.Add(tex); } } return(page); }
public static void CreateMaterialDictionary() { MaterialDictionary asset = ScriptableObject.CreateInstance <MaterialDictionary>(); AssetDatabase.CreateAsset(asset, "Assets/Resources/MaterialDictionary.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public void MaterialDictionary_getNonExistantMaterial_DoesntExist() { var matDict = new MaterialDictionary(); var steel = new Material(MaterialType.Metal, "steel", .25, 100, 79, 70); var alum = new Material(MaterialType.Metal, "aluminum", .25, 100, 79, 70); matDict.AddMaterial(steel); matDict.AddMaterial(alum); bool exists = matDict.MaterialExists("plastic"); Assert.IsFalse(exists); }
public void MaterialDictionary_getMaterial_matOK() { var matDict = new MaterialDictionary(); var mat = new Material(MaterialType.Metal, "steel", .25, 100, 79, 70); matDict.AddMaterial(mat); var matOut = matDict.GetMaterial("steel"); bool exists = matDict.MaterialExists("steel"); Assert.IsTrue(exists); Assert.AreEqual("STEEL", matOut.Name, "name"); Assert.AreEqual(mat.MillMachinability, matOut.MillMachinability); }
public void MaterialDictionary_addMaterial_CountOK() { var matDict = new MaterialDictionary(); var mat = new Material(MaterialType.Metal, "steel", .25, 100, 79, 70); matDict.AddMaterial(mat); var alum = new Material(MaterialType.Metal, "aluminum", .25, 100, 79, 70); matDict.AddMaterial(alum); Assert.AreEqual(2, matDict.Count, "mat count"); var matOut = matDict.GetMaterial("steel"); Assert.AreEqual("STEEL", matOut.Name, "name"); Assert.AreEqual(mat.MillMachinability, matOut.MillMachinability); }
public void UpdateNodeTypes() { var nodeTypeDefines = DefineCenter.Instance().GetDefinesOf <PathFindingNode>(); if (nodeTypeMaterials == null) { nodeTypeMaterials = new MaterialDictionary(); } foreach (var nodeTypeDefine in nodeTypeDefines) { if (!nodeTypeMaterials.ContainsKey(nodeTypeDefine.GetName())) { nodeTypeMaterials.Add(nodeTypeDefine.GetName(), null); } } }
private void CompareMaterialDictionaries(MaterialDictionary a, MaterialDictionary b) { if (a == null || b == null) { Assert.IsTrue(a == null ? (b == null) : (b != null)); return; } Assert.AreEqual(a.ResourceType, b.ResourceType); Assert.AreEqual(a.Version, b.Version); var ordered = a.Materials.OrderBy(x => x.Name).ToList(); var otherOrdered = b.Materials.OrderBy(x => x.Name).ToList(); for (int i = 0; i < a.Materials.Count; i++) { CompareMaterial(ordered[i], otherOrdered[i]); } }
void Start() { inventory = new Inventory(maxSize); materialDictionary = GameObject.FindGameObjectWithTag("MaterialDictionary").GetComponent <MaterialDictionary>(); }
private void HandleConvertMaterialsToolStripMenuItemClick(object sender, EventArgs e) { string directoryPath; using (var dialog = new VistaFolderBrowserDialog()) { dialog.Description = "Select a directory containing GMD files, or subdirectories containing GMD files to convert the materials.\n" + "Note that this will replace the original files."; if (dialog.ShowDialog() != DialogResult.OK) { return; } directoryPath = dialog.SelectedPath; } var failures = new ConcurrentBag <string>(); ModelPackConverterOptions option; using (var dialog = new ModelConverterOptionsDialog(false)) { if (dialog.ShowDialog() != DialogResult.OK) { return; } ModelPackConverterOptions options = new ModelPackConverterOptions() { MaterialPreset = dialog.MaterialPreset, Version = dialog.Version }; option = options; } using (var dialog = new ProgressDialog()) { dialog.DoWork += (o, progress) => { var filePaths = Directory.EnumerateFiles(directoryPath, "*.GMD", SearchOption.AllDirectories).ToList(); var processedFileCount = 0; Parallel.ForEach(filePaths, (filePath, state) => { lock (dialog) { if (dialog.CancellationPending) { state.Stop(); return; } dialog.ReportProgress((int)(((float)++processedFileCount / filePaths.Count) * 100), $"Processing {Path.GetFileName(filePath)}", null); } try { var model = Resource.Load <ModelPack>(filePath); var materials = model.Materials; var materialsConverted = MaterialDictionary.ConvertToMaterialPreset(materials, option); model.Materials = materialsConverted; model.Save(filePath); } catch (Exception) { failures.Add(filePath); } }); }; dialog.ShowDialog(); } if (failures.Count > 0) { MessageBox.Show("An error occured while processing the following files:\n" + string.Join("\n", failures)); } }
public Map GetIndexJson([Url] string map) { var bsp = Program.GetMap(map); var ents = new List <Entity>(); var mapParams = new MapParams(bsp); foreach (var ent in bsp.Entities) { var inst = InitEntity(ent, mapParams); if (inst != null) { ents.Add(inst); } } for (var dispIndex = 0; dispIndex < bsp.DisplacementInfos.Length; ++dispIndex) { SourceUtils.Vector3 min, max; GetDisplacementBounds(bsp, dispIndex, out min, out max, 1f); ents.Add(new Displacement { ClassName = "displacement", Index = dispIndex, Clusters = GetIntersectingClusters(mapParams.Tree, min, max) }); } for (var propIndex = 0; propIndex < bsp.StaticProps.PropCount; ++propIndex) { SourceUtils.Vector3 origin, angles; bsp.StaticProps.GetPropTransform(propIndex, out origin, out angles); StaticPropFlags flags; bool solid; uint diffuseMod; bsp.StaticProps.GetPropInfo(propIndex, out flags, out solid, out diffuseMod); int propModelIndex, skin; bsp.StaticProps.GetPropModelSkin(propIndex, out propModelIndex, out skin); var modelName = bsp.StaticProps.GetModelName(propModelIndex); var modelIndex = StudioModelDictionary.GetResourceIndex(bsp, modelName); ents.Add(new StaticProp { ClassName = "prop_static", Origin = origin, Angles = angles, Flags = flags, Clusters = bsp.StaticProps.GetPropLeaves(propIndex) .Select(x => (int)bsp.Leaves[x].Cluster) .Where(x => x != -1) .Distinct(), Model = modelIndex, VertLighting = (flags & StaticPropFlags.NoPerVertexLighting) == 0 ? (int?)propIndex : null, LightingOrigin = (flags & StaticPropFlags.UseLightingOrigin) == 0 ? null : (Vector3?)bsp.StaticProps.GetLightingOrigin(propIndex), AlbedoModulation = diffuseMod != 0xffffffff ? (uint?)diffuseMod : null }); } return(new Map { Name = bsp.Name, LightmapUrl = $"/maps/{bsp.Name}/lightmap.json", VisPages = GetPageLayout(bsp, bsp.Visibility.NumClusters, VisPage.ClustersPerPage, "/geom/vispage"), AmbientPages = GetPageLayout(bsp, bsp.Leaves.Length, AmbientPage.LeavesPerPage, "/geom/ambientpage"), LeafPages = GetPageLayout(bsp, bsp.Leaves.Length, LeafGeometryPage.LeavesPerPage, "/geom/leafpage"), DispPages = GetPageLayout(bsp, bsp.DisplacementInfos.Length, DispGeometryPage.DisplacementsPerPage, "/geom/disppage"), MaterialPages = GetPageLayout(bsp, MaterialDictionary.GetResourceCount(bsp), MaterialPage.MaterialsPerPage, "/materials/matpage"), BrushModelPages = GetPageLayout(bsp, bsp.Models.Length, BspModelPage.FacesPerPage, "/geom/bsppage", i => bsp.Models[i].NumFaces), StudioModelPages = GetPageLayout(bsp, StudioModelDictionary.GetResourceCount(bsp), StudioModelPage.VerticesPerPage, "/geom/mdlpage", i => StudioModelDictionary.GetVertexCount(bsp, i)), VertexLightingPages = GetPageLayout(bsp, bsp.StaticProps.PropCount, VertexLightingPage.PropsPerPage, "/geom/vhvpage"), Entities = ents }); }