public void UnloadResources() { _loadRequestsCDC.Clear(); if (CurrentScene != null) { CurrentScene.Dispose(); CurrentScene = null; } if (CurrentObject != null) { CurrentObject.Dispose(); CurrentObject = null; } while (Resources.Count > 1) { RenderResource resource = Resources[Resources.Keys[1]]; Resources.Remove(Resources.Keys[1]); CurrentObject?.UpdateModels(); CurrentScene?.UpdateModels(); resource.Dispose(); } }
public MeshPCT(RenderResource resource, IMeshParser <PositionColorTexturedVertex, short> meshParser) : base(resource) { Name = meshParser.MeshName; technique = meshParser.Technique; SetIndexBuffer(meshParser); SetVertexBuffer(meshParser); }
public void BuildMesh(RenderResource resource, int modelIndex, int groupIndex, int meshIndex) { _srModel = _srFile.Models[modelIndex]; _srGroup = _srModel.Groups[groupIndex]; String modelName = String.Format("{0}-{1}", _objectName, modelIndex); String groupName = String.Format("{0}-{1}-group-{2}", _objectName, modelIndex, groupIndex); String meshName = String.Format("{0}-{1}-group-{2}-mesh-{3}", _objectName, modelIndex, groupIndex, meshIndex); int startIndexLocation = 0; for (int materialIndex = 0; materialIndex < _srModel.MaterialCount; materialIndex++) { int indexCount = 0; int totalIndexCount = (int)_srGroup.mesh.indexCount; for (int v = 0; v < totalIndexCount; v++) { if (_srGroup.mesh.polygons[v / 3].material.ID == materialIndex) { _vertexList.Add(v); _indexList.Add(_indexList.Count - startIndexLocation); indexCount++; } } if (indexCount > 0) { String subMeshName = String.Format("{0}-{1}-group-{2}-submesh-{3}", _objectName, modelIndex, groupIndex, materialIndex); SubMesh subMesh = new SubMesh { Name = subMeshName, MaterialIndex = materialIndex, indexCount = indexCount, startIndexLocation = startIndexLocation, baseVertexLocation = startIndexLocation }; SubMeshes.Add(subMesh); startIndexLocation += indexCount; } } if (SubMeshes.Count > 0) { MeshName = meshName; Technique = "DefaultRender"; if (_srFile.Asset == CDC.Asset.Unit) { //Mesh = new MeshPCT(this); Mesh = new MeshMorphingUnit(resource, this); } else { Mesh = new MeshPNT(resource, this); } } }
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 ShutDown() { renderThread.Abort(); UnloadResources(); // This should be the unnamed one with the shapes. RenderResource resource = Resources[Resources.Keys[0]]; Resources.Remove(Resources.Keys[0]); resource.Dispose(); _textBlockRenderer.Dispose(); _spriteRenderer.Dispose(); }
public void BuildModel(RenderResource resource) { Material materialA = new Material(); materialA.Visible = true; Color colorDiffuseA = Color.FromArgb(unchecked ((int)0xFF0000FF)); materialA.Diffuse = colorDiffuseA; materialA.TextureFileName = ""; Materials.Add(materialA); Material materialB = new Material(); materialB.Visible = true; Color colorDiffuseB = Color.FromArgb(unchecked ((int)0xFF00FF00)); materialB.Diffuse = colorDiffuseB; materialB.TextureFileName = ""; Materials.Add(materialB); ModelNode group = new ModelNode(); group.Name = "group"; MeshParser meshParser = new MeshParser(ModelName); meshParser.BuildMesh(resource); 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); Groups.Add(group); Model = new Model(this); }
public void UnloadResource(string resourceName) { if (resourceName != "" && Resources.ContainsKey(resourceName)) { RenderResource renderResource = Resources[resourceName]; Resources.Remove(resourceName); CurrentObject?.UpdateModels(); CurrentScene?.UpdateModels(); renderResource.Dispose(); if (CurrentScene != null && CurrentScene.Name == resourceName) { CurrentScene.Dispose(); CurrentScene = null; } if (CurrentObject != null && CurrentObject.Name == resourceName) { CurrentObject.Dispose(); CurrentObject = null; } } }
public void BuildMesh(RenderResource resource) { float v = 1.2f; float h = 1.0f; BasicVertex[] vertices = { new BasicVertex { X = 0, Y = v, Z = 0 }, new BasicVertex { X = -h, Y = 0, Z = h }, new BasicVertex { X = -h, Y = 0, Z = -h }, new BasicVertex { X = h, Y = 0, Z = -h }, new BasicVertex { X = h, Y = 0, Z = h }, new BasicVertex { X = 0, Y = -v, Z = 0 } }; _vertexList.AddRange(vertices); int[] indices = { 0, 1, 2, 5, 3, 2, 0, 3, 4, 5, 1, 4, 5, 2, 1, 0, 2, 3, 5, 4, 3, 0, 4, 1 }; _indexList.AddRange(indices); Technique = "DefaultRender"; Mesh = new MeshPCT(resource, this); SubMesh subMeshA = new SubMesh { Name = MeshName + "-0", MaterialIndex = 0, indexCount = 12, startIndexLocation = 0, baseVertexLocation = 0 }; SubMeshes.Add(subMeshA); SubMesh subMeshB = new SubMesh { Name = MeshName + "-1", MaterialIndex = 1, indexCount = 12, startIndexLocation = 12, baseVertexLocation = 0 }; SubMeshes.Add(subMeshB); }
protected Mesh(RenderResource resource) { renderResource = resource; }