pub struct VmfSystem {
pub files: Vec<VmfFile>,
pub instances: Vec<Instance>,
pub search_dirs: Vec<PathBuf>,
pub warnings: Vec<String>,
}Expand description
A map and every VMF its func_instances pull in, each file loaded once
A file placed ten times is one entry in files and ten in instances:
edits go to the file, world positions come from the instances
use source_vmf::prelude::*;
let map = VmfSystem::open("maps/my_map.vmf")?;
for inst in &map.instances {
for ent in map.files[inst.file].entities.iter() {
if ent.classname() == Some("light") {
let [x, y, z] = inst.transform.point(Transform::from_entity(ent).origin);
println!("light at {x} {y} {z}");
}
}
}Fields§
§files: Vec<VmfFile>files[0] is the root map. Never shrinks, so indices survive relink.
Every VmfFile::path is canonical, that’s the key files get deduplicated by
instances: Vec<Instance>instances[0] is the root map. Parents always come before their children
search_dirs: Vec<PathBuf>Searched after the placing VMF’s directory and its maps directory, like gameinfo’s InstancePath
warnings: Vec<String>Missing, unreadable and self-including instances found by the last relink
Implementations§
Source§impl VmfSystem
impl VmfSystem
Sourcepub fn open(path: impl AsRef<Path>) -> VmfResult<Self>
pub fn open(path: impl AsRef<Path>) -> VmfResult<Self>
Opens a map and every VMF its func_instances pull in
Sourcepub fn open_with(
path: impl AsRef<Path>,
search_dirs: Vec<PathBuf>,
) -> VmfResult<Self>
pub fn open_with( path: impl AsRef<Path>, search_dirs: Vec<PathBuf>, ) -> VmfResult<Self>
Like open, also looking for instance files in search_dirs
Sourcepub fn chain(&self, instance: usize) -> impl Iterator<Item = usize>
pub fn chain(&self, instance: usize) -> impl Iterator<Item = usize>
instance followed by its parents up to the root map
Sourcepub fn iter_entities(&self) -> impl Iterator<Item = (usize, EntId, &Entity)>
pub fn iter_entities(&self) -> impl Iterator<Item = (usize, EntId, &Entity)>
Every entity of every file, hidden ones included like VmfFile::iter_entities.
A file placed ten times is still visited once
Sourcepub fn iter_entities_mut(
&mut self,
) -> impl Iterator<Item = (usize, EntId, &mut Entity)>
pub fn iter_entities_mut( &mut self, ) -> impl Iterator<Item = (usize, EntId, &mut Entity)>
Mutable iter_entities
Sourcepub fn flatten(&self) -> Flattened
pub fn flatten(&self) -> Flattened
Merges the root and every placed instance into one map in world space
Brushes and entities go through Transform::apply_solid and Transform::apply_entity.
func_instance and func_instance_parms are dropped and hidden objects are left out, like VBSP does.
Names, $replace variables, ids and editor data are not fixed up, they stay as they are in their files