public bool Equals(ImportedGeometry x, ImportedGeometry y) { return(x.Info.FlipUV_V == y.Info.FlipUV_V && x.Info.FlipX == y.Info.FlipX && x.Info.FlipY == y.Info.FlipY && x.Info.FlipZ == y.Info.FlipZ && x.Info.InvertFaces == y.Info.InvertFaces && _settings.MakeAbsolute(x.Info.Name).Equals(_settings.MakeAbsolute(y.Info.Name)) && x.Info.Path == y.Info.Path && x.Info.Scale == y.Info.Scale && x.Info.SwapXY == y.Info.SwapXY && x.Info.SwapXZ == y.Info.SwapXZ && x.Info.SwapYZ == y.Info.SwapYZ); }
public void Reload(LevelSettings settings, IDialogHandler progressReporter = null) { if (string.IsNullOrEmpty(Path)) { Sounds = null; LoadException = new Exception("Path is empty."); return; } // Load the catalog try { var path = settings.MakeAbsolute(Path); if (File.Exists(path)) { WadSounds newSounds = WadSounds.ReadFromFile(path); Sounds = newSounds; LoadException = null; } else { LoadException = new Exception("File not found: " + path); } } catch (Exception exc) { logger.Warn(exc, "Unable to load catalog '" + Path + "'."); Sounds = null; LoadException = exc; } }
public void Reload(LevelSettings settings, IDialogHandler progressReporter = null) { if (string.IsNullOrEmpty(Path)) { Wad = null; LoadException = new Exception("Path is empty."); return; } // Load wad try { Wad2 newWad = Wad2.ImportFromFile( settings.MakeAbsolute(Path), false, progressReporter ?? new ProgressReporterSimple()); Wad = newWad; LoadException = null; } catch (Exception exc) { logger.Warn(exc, "Unable to load wad '" + Path + "'."); Wad = null; LoadException = exc; } }
public void Reload(LevelSettings settings) { LoadException = null; if (string.IsNullOrEmpty(Path)) { Image = UnloadedPlaceholder; return; } // Load image try { ImageC image = ImageC.FromFile(settings.MakeAbsolute(Path)); if (Convert512PixelsToDoubleRows && image.Width == 512) { ImageC newImage = ImageC.CreateNew(256, image.Height * 2); newImage.FileName = image.FileName; for (int oldY = 0; oldY < image.Height; oldY += 64) { newImage.CopyFrom(0, oldY * 2, image, 0, oldY, 256, 64); newImage.CopyFrom(0, oldY * 2 + 64, image, 256, oldY, 256, 64); } image = newImage; } if (ReplaceMagentaWithTransparency) { image.ReplaceColor(new ColorC(255, 0, 255, 255), new ColorC(0, 0, 0, 0)); } image.CalculatePalette(); Image = image; // Resize sound array ResizeFootStepSounds( (int)Math.Ceiling(Image.Width / FootStepSoundGranularity), (int)Math.Ceiling(Image.Height / FootStepSoundGranularity)); // Resize bump maps ResizeBumpMappingInfos( (int)Math.Ceiling(Image.Width / BumpMappingGranularity), (int)Math.Ceiling(Image.Height / BumpMappingGranularity)); } catch (Exception exc) { logger.Warn(exc, "Unable to load texture '" + Path + "'."); Image = UnloadedPlaceholder; LoadException = exc; } }
public void Update(LevelSettings settings, Dictionary <string, Texture> absolutePathTextureLookup, ImportedGeometryInfo info) { Info = info; LoadException = null; DirectXModel = null; Textures.Clear(); try { string importedGeometryPath = settings.MakeAbsolute(info.Path); string importedGeometryDirectory = Path.GetDirectoryName(importedGeometryPath); // Invoke the TombLib geometry import code var settingsIO = new IOGeometrySettings { Scale = info.Scale, SwapXY = info.SwapXY, SwapXZ = info.SwapXZ, SwapYZ = info.SwapYZ, FlipX = info.FlipX, FlipY = info.FlipY, FlipZ = info.FlipZ, FlipUV_V = info.FlipUV_V, InvertFaces = info.InvertFaces, UseVertexColor = true }; BaseGeometryImporter importer = BaseGeometryImporter.CreateForFile(importedGeometryPath, settingsIO, absoluteTexturePath => { return(GetOrAddTexture(absolutePathTextureLookup, importedGeometryDirectory, absoluteTexturePath)); }); var tmpModel = importer.ImportFromFile(importedGeometryPath); SynchronizationContext.Current.Post(unused => // Synchronize DirectX, we can't 'send' because that may deadlock with the level settings reloader { if (Device == null) { return; } // Create a new static model DirectXModel = new Model(Device, info.Scale); DirectXModel.BoundingBox = tmpModel.BoundingBox; // Create materials foreach (var tmpMaterial in tmpModel.Materials) { var material = new Material(tmpMaterial.Name); material.Texture = tmpMaterial.Texture; material.AdditiveBlending = tmpMaterial.AdditiveBlending; material.DoubleSided = tmpMaterial.DoubleSided; DirectXModel.Materials.Add(material); } // Loop for each mesh loaded in scene foreach (var mesh in tmpModel.Meshes) { var modelMesh = new ImportedGeometryMesh(Device, mesh.Name); modelMesh.HasVertexColors = (mesh.Colors.Count != 0); var currentIndex = 0; var currPoly = 0; foreach (var tmpSubmesh in mesh.Submeshes) { var material = DirectXModel.Materials[tmpModel.Materials.IndexOf(tmpSubmesh.Value.Material)]; var submesh = new Submesh(material); foreach (var tmpPoly in tmpSubmesh.Value.Polygons) { if (tmpPoly.Shape == IOPolygonShape.Quad) { var vertexList = new List <ImportedGeometryVertex>(); for (var i = 0; i < 4; i++) { var vertex = new ImportedGeometryVertex(); vertex.Position = mesh.Positions[tmpPoly.Indices[i]]; vertex.Color = tmpPoly.Indices[i] < mesh.Colors.Count ? mesh.Colors[tmpPoly.Indices[i]].To3() : Vector3.One; vertex.UV = tmpPoly.Indices[i] < mesh.UV.Count ? mesh.UV[tmpPoly.Indices[i]] : Vector2.Zero; vertex.Normal = tmpPoly.Indices[i] < mesh.Normals.Count ? mesh.Normals[tmpPoly.Indices[i]] : Vector3.Zero; vertexList.Add(vertex); } // HACK: Triangulate and disjoint quad faces for imported geometry, because otherwise another hack which joints // disjointed vertices together will fail in Rooms.cs submesh.Indices.Add(currentIndex); submesh.Indices.Add(currentIndex + 1); submesh.Indices.Add(currentIndex + 2); submesh.Indices.Add(currentIndex + 3); submesh.Indices.Add(currentIndex + 4); submesh.Indices.Add(currentIndex + 5); modelMesh.Vertices.Add(vertexList[0]); modelMesh.Vertices.Add(vertexList[1]); modelMesh.Vertices.Add(vertexList[2]); modelMesh.Vertices.Add(vertexList[0]); modelMesh.Vertices.Add(vertexList[2]); modelMesh.Vertices.Add(vertexList[3]); currentIndex += 6; } else { for (var i = 0; i < 3; i++) { var vertex = new ImportedGeometryVertex(); vertex.Position = mesh.Positions[tmpPoly.Indices[i]]; vertex.Color = tmpPoly.Indices[i] < mesh.Colors.Count ? mesh.Colors[tmpPoly.Indices[i]].To3() : Vector3.One; vertex.UV = tmpPoly.Indices[i] < mesh.UV.Count ? mesh.UV[tmpPoly.Indices[i]] : Vector2.Zero; vertex.Normal = tmpPoly.Indices[i] < mesh.Normals.Count ? mesh.Normals[tmpPoly.Indices[i]] : Vector3.Zero; modelMesh.Vertices.Add(vertex); submesh.Indices.Add(currentIndex); currentIndex++; } } currPoly++; } modelMesh.Submeshes.Add(material, submesh); } DirectXModel.Meshes.Add(modelMesh); } DirectXModel.UpdateBuffers(); }, null); } catch (OperationCanceledException) { throw; } catch (Exception exc) { LoadException = exc; DirectXModel = null; logger.Warn(exc, "Unable to load model \"" + info.Name + "\" from \"" + info.Path + "\" because an exception occurred during loading."); } }