/// <summary> /// Adds the specified material (for collection Initializers). /// </summary> /// <param name="material">The mesh.</param> public void Add(MaterialInstance material) { if (material != null) { Materials.Add(material); } }
public void GenerateMaterialsThread() { Debug.WriteLine("start product generation", this.ToString()); if (Status) { thread = new Thread(() => { while (Status) { Debug.WriteLine("add product", this.ToString()); Materials.Add(new Material()); if (thread.Priority == ThreadPriority.Highest) { Thread.Sleep(10); } if (thread.Priority == ThreadPriority.Normal) { Thread.Sleep(1000 - Speed); } if (thread.Priority == ThreadPriority.Lowest) { Thread.Sleep(4000); } } }); thread.Start(); } }
async Task ExecuteLoadMaterialsCommand() { if (IsBusy) { return; } IsBusy = true; try { Materials.Clear(); var materials = await dataStore.GetAuthorMaterials(AuthorId); foreach (var material in materials) { Materials.Add(material); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
private void OpenFileSelectorExecute() { Stream myStream; OpenFileDialog openMaterialDialog = new OpenFileDialog(); openMaterialDialog.FilterIndex = 2; openMaterialDialog.RestoreDirectory = true; if (openMaterialDialog.ShowDialog().Value == true) { if ((myStream = openMaterialDialog.OpenFile()) != null) { IsBusy = true; var bytes = File.ReadAllBytes(openMaterialDialog.FileName); var newMaterial = new Material() { Content = bytes, Name = openMaterialDialog.SafeFileName, SessionId = CurrentSession.SessionId, Session = null, ContentType = "application/octet-stream" }; _eventsClient.MaterialService.AddMaterialAsync(newMaterial, (result) => { App.Current.Dispatcher.BeginInvoke(new Action(delegate() { IsBusy = false; Materials.Add(newMaterial); })); }); } } }
public void BuildModel(int modelIndex) { _srModel = _srFile.Models[modelIndex]; String modelName = _objectName + "-" + modelIndex.ToString(); #region Materials ProgressStage = "Model " + modelIndex.ToString() + " - Creating Materials"; Thread.Sleep(500); for (int materialIndex = 0; materialIndex < _srModel.MaterialCount; materialIndex++) { Material material = new Material(); Color colorDiffuse = Color.FromArgb((int)unchecked (_srModel.Materials[materialIndex].colour)); material.Diffuse = colorDiffuse; material.TextureFileName = GetTextureName(_srModel, materialIndex); Materials.Add(material); progressLevel += _srModel.IndexCount / _srModel.Groups.Length; } #endregion #region Groups for (int groupIndex = 0; groupIndex < _srModel.Groups.Length; groupIndex++) { ProgressStage = "Model " + modelIndex.ToString() + " - Creating Group " + groupIndex.ToString(); Thread.Sleep(100); Tree srGroup = _srModel.Groups[groupIndex]; String groupName = String.Format("{0}-{1}-group-{2}", _objectName, modelIndex, groupIndex); if (srGroup != null && srGroup.mesh != null && srGroup.mesh.indexCount > 0 && srGroup.mesh.polygonCount > 0) { Node group = new Node(); SRMeshParser meshParser = new SRMeshParser(_objectName, _srFile); meshParser.BuildMesh(modelIndex, groupIndex, 0); foreach (SubMesh subMesh in meshParser.SubMeshes) { // If the mesh parser knew the total submeshes for the model, // then this could be done inside BuildMesh. subMesh.MeshIndex = Meshes.Count; group.SubMeshIndices.Add(SubMeshes.Count); SubMeshes.Add(subMesh); } Meshes.Add(meshParser.Mesh); group.Name = groupName; Groups.Add(group); } } #endregion ModelName = modelName; if (_srFile.Asset == CDC.Asset.Unit) { Model = new Unit(this); } else { Model = new Physical(this); } }
/// <summary> /// Adds a new material to the model. /// </summary> public Material AddMaterial(string name, double elasticitymodulus, double poissonsratio, double unitweight) { Material m = new Material(name, elasticitymodulus, poissonsratio, unitweight); Materials.Add(m); return(m); }
public override void LoadFromXml(XElement element) { base.LoadFromXml(element); DesignID = element.ReadAttribute("designID", string.Empty); Materials.Clear(); if (element.HasAttribute("materials", out XAttribute matAttr)) { var materials = matAttr.Value.Split(','); for (int i = 0; i < materials.Length; i++) { if (int.TryParse(materials[i], out int matID)) { Materials.Add(matID); } } } Bone = null; if (element.HasElement("Bone", out XElement boneElem)) { Bone = new Bone(); Bone.LoadFromXml(boneElem); } }
protected override void InitFromMeshData(Device device, GeometryGenerator.MeshData mesh) { var subset = new MeshGeometry.Subset { FaceCount = mesh.Indices.Count / 3, FaceStart = 0, VertexCount = mesh.Vertices.Count, VertexStart = 0 }; Subsets.Add(subset); var max = new Vector3(float.MinValue); var min = new Vector3(float.MaxValue); foreach (var vertex in mesh.Vertices) { max = Vector3.Maximize(max, vertex.Position); min = Vector3.Minimize(min, vertex.Position); } BoundingBox = new BoundingBox(min, max); Vertices.AddRange(mesh.Vertices.Select(v => new PosNormalTexTan(v.Position, v.Normal, v.TexC, v.TangentU)).ToList()); Indices.AddRange(mesh.Indices.Select(i => (short)i)); Materials.Add(new Material { Ambient = Color.Gray, Diffuse = Color.White, Specular = new Color4(16, 1, 1, 1) }); DiffuseMapSRV.Add(null); NormalMapSRV.Add(null); ModelMesh.SetSubsetTable(Subsets); ModelMesh.SetVertices(device, Vertices); ModelMesh.SetIndices(device, Indices); }
public MaterialEditorWindowViewModel(RNumdl rnumdl) { if (rnumdl == null) { return; } this.rnumdl = rnumdl; foreach (var name in rnumdl.TextureByName.Keys) { PossibleTextureNames.Add(name); } // TODO: Allow for editing all matl entries and not just materials assigned to meshes. foreach (var glMaterial in rnumdl.MaterialByName.Values) { var material = new Material { Name = glMaterial.Name, ShaderLabel = glMaterial.ShaderLabel }; AddBooleanParams(glMaterial, material); AddFloatParams(glMaterial, material); AddVec4Params(glMaterial, material); AddTextureParams(glMaterial, material); Materials.Add(material); } }
void OnMaterialAdded(object obj) { var material = obj as Material; Materials.Add(material); Materials.OrderBy(m => m.Name); }
async void GetMaterialsByFilterDates(DateTime StartData, DateTime FinishData) { string stringJson = JsonConvert.SerializeObject(StartData) + "|" + JsonConvert.SerializeObject(FinishData); HttpResponseMessage response = await client.PutAsJsonAsync("AllMaterials/GetMaterialsByFilterDates/", stringJson); if (response.IsSuccessStatusCode) { var materialsTerm = await response.Content.ReadAsAsync <List <Material> >(); for (int i = 0; i < materialsTerm.Count; i++) { response.Dispose(); response = await client.GetAsync("Victims/" + materialsTerm[i].MaterialId); var victims = await response.Content.ReadAsAsync <List <Victim> >(); victims.ForEach(x => materialsTerm[i].Victims.Add(x)); response.Dispose(); response = await client.GetAsync("Employees/GetEmployeesWhereTermToday/" + materialsTerm[i].MaterialId); var employee = await response.Content.ReadAsAsync <List <Employee> >(); employee.ForEach(x => materialsTerm[i].Employees.Add(x)); } materialsTerm.ForEach(x => Materials.Add(x)); } }
async void GetMaterialsWhereNotExecutedAsync() { HttpResponseMessage response = await client.GetAsync("AllMaterials/"); if (response.IsSuccessStatusCode) { var materialsTerm = await response.Content.ReadAsAsync <List <Material> >(); for (int i = 0; i < materialsTerm.Count; i++) { response.Dispose(); response = await client.GetAsync("Victims/" + materialsTerm[i].MaterialId); var victims = await response.Content.ReadAsAsync <List <Victim> >(); victims.ForEach(x => materialsTerm[i].Victims.Add(x)); response.Dispose(); response = await client.GetAsync("Employees/GetEmployeesWhereTermToday/" + materialsTerm[i].MaterialId); var employee = await response.Content.ReadAsAsync <List <Employee> >(); employee.ForEach(x => materialsTerm[i].Employees.Add(x)); } materialsTerm.ForEach(x => Materials.Add(x)); } }
private void LoadOrClear() { if (size != null && !(Commentaries.Any() && Materials.Any() && Pribors.Any())) { using (var db = new SmetaApplication.DbContexts.SmetaDbAppContext()) { Materials.Clear(); db.MaterialGroups.Where(x => x.WorkId == Id).ToList().ForEach(x => { Materials.Add(new MaterialGroupDemView(x, diff + 1)); }); Pribors.Clear(); db.PriborGroups.Where(x => x.WorkId == Id).ToList().ForEach(x => { Pribors.Add(new PriborGroupView(x)); }); Commentaries.Clear(); db.Commentaries.Where(x => x.WorkSectionId == WorkSectionId).ToList().ForEach(x => { Commentaries.Add(new CommentaryView(x)); }); } } else { Commentaries.Clear(); Materials.Clear(); Pribors.Clear(); } }
private void AddMaterial(Material MatToAdd) { if (MaterialIsOpen == true) { /* If map_Ka is empty, set it to map_Kd */ if (MatToAdd.map_Ka == null && MatToAdd.map_Kd != null) { MatToAdd.map_Ka = MatToAdd.map_Kd; } /* Else if map_Kd is empty, set it to map_Ka */ else if (MatToAdd.map_Kd == null && MatToAdd.map_Ka != null) { MatToAdd.map_Kd = MatToAdd.map_Ka; } /* Only add the material if both, map_Ka and map_Kd, aren't empty */ if (MatToAdd.map_Ka != null && MatToAdd.map_Kd != null) { Materials.Add(MatToAdd); } MaterialIsOpen = false; } }
private MtlMaterial NewMaterial(string name) { Materials.Add(CurrentMaterial = new MtlMaterial(this, Materials.Count) { Name = name }); return(CurrentMaterial); }
internal void Read(EndianBinaryReader reader, ObjectSection section = null) { uint signature = reader.ReadUInt32(); reader.SeekCurrent(4); // Unused flags int meshCount, materialCount; long meshesOffset, materialsOffset; // X stores mesh/material count before the bounding sphere if (section?.Format == BinaryFormat.X) { meshCount = reader.ReadInt32(); materialCount = reader.ReadInt32(); BoundingSphere = reader.ReadBoundingSphere(); meshesOffset = reader.ReadOffset(); materialsOffset = reader.ReadOffset(); reader.SkipNulls(4 * sizeof(uint)); Flags = reader.ReadUInt32(); // TODO: Is this available in other games? reader.SkipNulls(sizeof(uint)); } else { BoundingSphere = reader.ReadBoundingSphere(); meshCount = reader.ReadInt32(); meshesOffset = reader.ReadOffset(); materialCount = reader.ReadInt32(); materialsOffset = reader.ReadOffset(); } reader.SkipNulls(10 * sizeof(uint)); Meshes.Capacity = meshCount; for (int i = 0; i < meshCount; i++) { reader.ReadAtOffset(meshesOffset + i * Mesh.GetByteSize(section?.Format ?? BinaryFormat.DT), () => { var mesh = new Mesh(); mesh.Read(reader, section); Meshes.Add(mesh); }); } Materials.Capacity = materialCount; for (int i = 0; i < materialCount; i++) { reader.ReadAtOffset(materialsOffset + i * Material.BYTE_SIZE, () => { var material = new Material(); material.Read(reader); Materials.Add(material); }); } }
protected override void Parse(string keyword, string data) { switch (keyword) { case "newmtl": Materials.Add(_current = new Material(data)); break; case "Kd": _current.Kd = data.ToVect3f(); break; case "Ka": _current.Ka = data.ToVect3f(); break; case "Ks": _current.Ks = data.ToVect3f(); break; case "illum": _current.IllumunationModel = int.Parse(data); break; case "Tr": //TODO not sure what this is _current.Tr = data.ParseFloat(); break; case "Ns": _current.Ns = data.ParseFloat(); break; case "map_Kd": Textures.Add(data, Image.FromStream(FileSource.Get(data))); //TODO load image break; case "map_Ka": break; case "r": break; case "d": break; case "sharpness": break; case "Ni": break; default: throw new Exception(keyword); // } }
public bool AddMaterial(Material material) { if (Materials.Contains(material)) { return(false); } Materials.Add(material); return(true); }
public bool TryAddMaterial(Material material) { if ((material == null) || string.IsNullOrEmpty(material.Name) || Materials.ContainsKey(material.Name)) { return(false); } Materials.Add(material.Name, material); return(true); }
public void LoadAnim(ShaderParamAnim anim, AnimationType type) { Initialize(); Text = anim.Name; AnimType = type; FrameCount = anim.FrameCount; ShaderParamAnim = anim; foreach (ShaderParamMatAnim matAnim in anim.ShaderParamMatAnims) { MaterialAnimEntry matNode = new MaterialAnimEntry(matAnim.Name); matNode.materialAnimData = matAnim; Materials.Add(matNode); //Param info determines which curves to use for each param //Add the curves and keys for left/right for interpolating after foreach (var param in matAnim.ParamAnimInfos) { BfresParamAnim paramInfo = new BfresParamAnim(param.Name); paramInfo.Type = type; matNode.Params.Add(paramInfo); //Get constant anims for (int constant = 0; constant < param.ConstantCount; constant++) { Animation.KeyGroup keyGroup = new Animation.KeyGroup(); keyGroup.Keys.Add(new Animation.KeyFrame() { InterType = InterpolationType.CONSTANT, Frame = 0, Value = matAnim.Constants[constant].Value, }); paramInfo.Values.Add(new Animation.KeyGroup() { AnimDataOffset = matAnim.Constants[constant].AnimDataOffset, Keys = keyGroup.Keys, }); } for (int curve = 0; curve < param.FloatCurveCount + param.IntCurveCount; curve++) { int index = curve + param.BeginCurve; Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(matAnim.Curves[index]); keyGroup.AnimDataOffset = matAnim.Curves[index].AnimDataOffset; paramInfo.Values.Add(new Animation.KeyGroup() { AnimDataOffset = keyGroup.AnimDataOffset, Keys = keyGroup.Keys, }); } } } }
/// <summary> /// Initializes a new instance of the <see cref="RwxSimpleStatistics"/> class. /// </summary> /// <param name="rwxFile"> /// The rwx file. /// </param> public RwxSimpleStatistics(FileInfo rwxFile) { _materials = new List <RwxMaterial>(); _rwxFile = rwxFile; var reader = _rwxFile.OpenText(); string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); var linelower = line.ToLower(); if (linelower.StartsWith("polygon")) { //polygon 6 6 5 4 3 2 1 var dat = linelower.Split(' '); var polygon = new Polygon(); for (var i = 1; i < dat.Length - 1; i = i + 2) { polygon.Points.Add(new Vector2(float.Parse(dat[i]), float.Parse(dat[i + 1]))); } _polygons++; } if (linelower.StartsWith("vertex")) { // vertex -0.367136 0.117699 -0.408144 uv 0.666666 0.000000 #1 var dat = linelower.Split(' '); var position = new Vector3(float.Parse(dat[1]), float.Parse(dat[2]), float.Parse(dat[3])); var uv = new Vector2(float.Parse(dat[5]), float.Parse(dat[6])); var tri = new RwxVertex(position, uv); _verts++; } if (linelower.StartsWith("triangle")) { _triangles++; } if (linelower.StartsWith("quad")) { _quads++; } if (linelower.StartsWith("texture")) { if (!linelower.Substring(7).Trim().StartsWith("modes ")) { if (!linelower.Substring(7).Trim().StartsWith("mode ")) { if (!linelower.Substring(7).Trim().StartsWith("addressmode ")) { Materials.Add(new RwxMaterial(linelower.Substring(7).Trim().Split(' ')[0])); } } } } } }
void OnMaterialAdded(object obj) { var material = obj as Material; Materials.Add(material); Materials = new ObservableCollection <Material>(Materials.OrderBy(m => m.Name)); IsDirty = true; }
public InternalMesh(Mesh meshData, RendererMaterial material) { SetMesh(meshData); if (material == null) { throw new InvalidOperationException(); } Materials.Add(material); }
/// <summary> /// Loads a Material given the location and assigning it the given name /// </summary> /// <param name="location">The file location of the texture file, do not include the file extension</param> /// <param name="name">The name to give the material</param> /// <returns>A SquidEngine Material</returns> public override Material LoadMaterial(string location, string name) { Material _material = new Material(); _material.Name = name; _material.Filename = location; _material.Texture = _content.Load <Texture2D>(location); Materials.Add(_material); return(_material); }
public void NewMaterialAnim() { var mat = new MaterialAnimEntry("NewMaterialTarget"); mat.LoadMaterial(new ShaderParamMatAnim() { Name = mat.Text }); Materials.Add(mat); }
public void NewMaterialAnim() { var mat = new MaterialAnimEntry("NewMaterialTarget"); mat.LoadMaterial(new MaterialAnimData() { Name = mat.Text }, this); Materials.Add(mat); }
public void AddExtraMaterial(List <Material> materials) { if (Extra != null) { foreach (Material item in Extra) { Materials.Add(item); } } }
public void BuildModel(RenderResource resource, int modelIndex, CDC.Objects.ExportOptions options) { _srModel = _srFile.Models[modelIndex]; String modelName = _objectName + "-" + modelIndex.ToString(); #region Materials for (int materialIndex = 0; materialIndex < _srModel.MaterialCount; materialIndex++) { Material material = new Material(); material.Visible = _srModel.Materials[materialIndex].visible; // Breaks early SR1 builds. //material.BlendMode = _srModel.Materials[materialIndex].blendMode; //int sortPush = unchecked((sbyte)_srModel.Materials[materialIndex].sortPush); //sortPush = 128 - sortPush; //material.DepthBias = (1.0f / 100000.0f) * sortPush; // Maybe use a hack for warpgates WARPGATE_DrawWarpGateRim indicates tree 3 should have lower priority. Color colorDiffuse = Color.FromArgb((int)unchecked (_srModel.Materials[materialIndex].colour)); material.Diffuse = colorDiffuse; material.TextureFileName = CDC.Objects.Models.SRModel.GetTextureName(_srModel, materialIndex, options); Materials.Add(material); } #endregion #region Groups for (int groupIndex = 0; groupIndex < _srModel.Groups.Length; groupIndex++) { Tree srGroup = _srModel.Groups[groupIndex]; String groupName = String.Format("{0}-{1}-group-{2}", _objectName, modelIndex, groupIndex); if (srGroup != null && srGroup.mesh != null && srGroup.mesh.indexCount > 0 && srGroup.mesh.polygonCount > 0) { ModelNode group = new ModelNode(); SRMeshParser meshParser = new SRMeshParser(_objectName, _srFile); meshParser.BuildMesh(resource, modelIndex, groupIndex, 0); foreach (SubMesh subMesh in meshParser.SubMeshes) { // If the mesh parser knew the total submeshes for the model, // then this could be done inside BuildMesh. subMesh.MeshIndex = Meshes.Count; group.SubMeshIndices.Add(SubMeshes.Count); SubMeshes.Add(subMesh); } Meshes.Add(meshParser.Mesh); group.Name = groupName; Groups.Add(group); } } #endregion ModelName = modelName; Model = new Model(this); }
public void AddRenderingSteps(Renderer[] renderers, Color outlineColor, int thickness, Shader drawSilhouettesShader) { if ((renderers == null) || (renderers.Length == 0)) { Debug.LogError("target to be rendered not set"); return; } Material currentMat = null; if (materialCounter >= Materials.Count) { currentMat = new Material(drawSilhouettesShader); Materials.Add(currentMat); } else { currentMat = Materials[materialCounter]; } materialCounter++; currentMat.SetColor(silhouetteColorID, OutlineInfo.Encode(outlineColor, thickness)); int renderersStart = Renderers.Count; Renderers.AddRange(renderers); Renderer r = null; for (int i = renderersStart; i < Renderers.Count; i++) { r = Renderers[i]; if (r.isVisible) { if (r is SkinnedMeshRenderer) { SkinnedMeshRenderer skinned = (SkinnedMeshRenderer)r; if (skinned.sharedMesh) { for (int c = 0; c < skinned.sharedMesh.subMeshCount; c++) { CommandBuffer.DrawRenderer(r, currentMat, c, 0); } } } else { CommandBuffer.DrawRenderer(r, currentMat, 0, 0); } } } //TODO: probabilmente Renderers può essere eliminato e può essere usato solo l'array argomento del metodo renderers }
/// <summary> /// /// </summary> /// <param name="materials"></param> /// <returns>The Elements object.</returns> public Elements AddMaterials(List <AbsElement> materials) { { foreach (var material in materials) { Materials.Add(material); } } return(this); }