Skip to content

Commit

Permalink
Merge branch 'feature/bo1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mauserzjeh committed Nov 22, 2023
2 parents 0fe6684 + c31098d commit 6a75c60
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 38 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Blender add-on for importing various Call of Duty assets via the game files.
- XModel - Compiled models
- Call of Duty 5 World at War
- XModel - Compiled models
- Call of Duty Black Ops
- XModel - Compiled models

## Installation & setup
First of all, extract all the necessary game specific contents. Make sure to have the exact same folder structure as they have originally.

### Call of Duty & Call of Duty United Offensive
Files can be found inside the .pk3 files.
Files can be found inside the `.pk3` files.
```
.
├── maps/
Expand All @@ -34,7 +36,7 @@ Files can be found inside the .pk3 files.
```

### Call of Duty 2
Files can be found inside the .iwd files.
Files can be found inside the `.iwd` files.
```
.
├── images/
Expand All @@ -47,7 +49,7 @@ Files can be found inside the .iwd files.
└── xmodelsurfs/
```
### Call of Duty 4 Modern Warfare
Images can be found inside the .iwd files. The rest of the assets can be acquired by installing modtools.
Images can be found inside the `.iwd` files. The rest of the assets can be acquired by installing modtools.
```
.
├── images/
Expand All @@ -60,7 +62,20 @@ Images can be found inside the .iwd files. The rest of the assets can be acquire
```

### Call of Duty 5 World at War
Images can be found inside the .iwd files. The rest of the assets can be acquired by installing modtools.
Images can be found inside the `.iwd` files. The rest of the assets can be acquired by installing modtools.
```
.
├── images/
├── materials/
├── xanim/
├── xmodel/
├── xmodelalias/
├── xmodelparts/
└── xmodelsurfs/
```

### Call of Duty Black Ops
Images can be found inside the `.iwd` files. The rest of the assets can be acquired by installing modtools. There are still some missing assets though (mostly materials and images).
```
.
├── images/
Expand Down
2 changes: 1 addition & 1 deletion python/cod_asset_importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Call of Duty Asset Importer",
"description": "Import Call of Duty assets",
"author": "Soma Rádóczi",
"version": (3, 0, 0),
"version": (3, 1, 0),
"blender": (3, 0, 0),
"location": "File > Import -> CoD Asset Importer",
"category": "Import-Export",
Expand Down
2 changes: 1 addition & 1 deletion python/cod_asset_importer/cod_asset_importer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LoadedModel:
def angles(self) -> List[float]: ...
def origin(self) -> List[float]: ...
def scale(self) -> List[float]: ...
def materials(self) -> List[LoadedMaterial]: ...
def materials(self) -> Dict[str, LoadedMaterial]: ...
def surfaces(self) -> List[LoadedSurface]: ...
def bones(self) -> List[LoadedBone]: ...

Expand Down
7 changes: 3 additions & 4 deletions python/cod_asset_importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def xmodel(self, loaded_model: LoadedModel) -> None:
mesh_objects = []

materials = loaded_model.materials()
for material in materials:
for _, material in materials.items():
append_asset_path = ""
if model_version == XMODEL_VERSION.V14:
append_asset_path = "skins"
Expand Down Expand Up @@ -69,8 +69,7 @@ def xmodel(self, loaded_model: LoadedModel) -> None:
vertex_color_layer.data.foreach_set("color", surface.colors())

obj = bpy.data.objects.new(model_name, mesh)

active_material_name = materials[i].name()
active_material_name = surface.material()
if model_version == XMODEL_VERSION.V14:
active_material_name = os.path.splitext(active_material_name)[0]
obj.active_material = bpy.data.materials.get(active_material_name)
Expand Down Expand Up @@ -797,7 +796,7 @@ def _import_texture(
)
texture_image.pixels = loaded_texture.data()
texture_image.file_format = "TARGA"
texture_image.pack()
texture_image.alpha_mode = "CHANNEL_PACKED"

return texture_image

Expand Down
2 changes: 1 addition & 1 deletion rust/cod_asset_importer/src/assets/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Material {
impl From<String> for TextureType {
fn from(texture_type: String) -> Self {
match texture_type.as_str() {
"colorMap" => TextureType::Color,
"colorMap" | "Diffuse_MapSampler" => TextureType::Color,
"normalMap" | "Normal_Map" => TextureType::Normal,
"detailMap" | "Detail_Map" => TextureType::Detail,
"specularMap" | "Specular_Map" => TextureType::Specular,
Expand Down
16 changes: 12 additions & 4 deletions rust/cod_asset_importer/src/loaded_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use crate::{
assets::{
ibsp::{Ibsp, IbspEntity, IbspSurface},
iwi::IWi,
material::TextureType,
xmodel::XModelVersion,
xmodelpart::XModelPartBone,
xmodelsurf::XModelSurfSurface, xmodel::XModelVersion, material::TextureType,
xmodelsurf::XModelSurfSurface,
},
utils::math::Vec3,
};
Expand Down Expand Up @@ -36,7 +38,7 @@ pub struct LoadedModel {
angles: Vec3,
origin: Vec3,
scale: Vec3,
materials: Vec<LoadedMaterial>,
materials: HashMap<String, LoadedMaterial>,
surfaces: Vec<LoadedSurface>,
bones: Vec<LoadedBone>,
}
Expand Down Expand Up @@ -106,7 +108,7 @@ impl LoadedModel {
self.scale
}

fn materials(&mut self) -> Vec<LoadedMaterial> {
fn materials(&mut self) -> HashMap<String, LoadedMaterial> {
mem::take(&mut self.materials)
}

Expand Down Expand Up @@ -261,7 +263,7 @@ impl LoadedModel {
angles: Vec3,
origin: Vec3,
scale: Vec3,
materials: Vec<LoadedMaterial>,
materials: HashMap<String, LoadedMaterial>,
surfaces: Vec<LoadedSurface>,
bones: Vec<LoadedBone>,
) -> Self {
Expand Down Expand Up @@ -309,6 +311,12 @@ impl LoadedTexture {
}
}

impl LoadedSurface {
pub fn set_material(&mut self, material: String) {
self.material = material;
}
}

impl From<IWi> for LoadedTexture {
fn from(iwi: IWi) -> Self {
Self {
Expand Down
60 changes: 37 additions & 23 deletions rust/cod_asset_importer/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ use crate::{
GameVersion,
},
error_log, info_log,
loaded_assets::{LoadedBone, LoadedIbsp, LoadedMaterial, LoadedModel, LoadedTexture},
loaded_assets::{
LoadedBone, LoadedIbsp, LoadedMaterial, LoadedModel, LoadedSurface, LoadedTexture,
},
utils::{error::Error, path::file_name, Result},
};
use crossbeam_utils::sync::WaitGroup;
use pyo3::{exceptions::PyBaseException, prelude::*};
use rayon::ThreadPoolBuilder;
use std::{
collections::HashMap,
collections::{hash_map::Entry::Vacant, HashMap},
path::PathBuf,
sync::{mpsc::channel, Arc, Mutex},
thread,
Expand Down Expand Up @@ -246,26 +248,28 @@ impl Loader {
let xmodelsurf_file_path = asset_path.join(xmodelsurf::ASSETPATH).join(lod0.name);
let xmodelsurf = XModelSurf::load(xmodelsurf_file_path, xmodelpart.clone())?;

let mut loaded_materials: Vec<LoadedMaterial> = Vec::new();
for mat in lod0.materials {
match xmodel.version {
XModelVersion::V14 => {
loaded_materials.push(LoadedMaterial::new(mat, Vec::new(), xmodel.version))
}
_ => {
let loaded_material = match Self::load_material(
asset_path.clone(),
mat.clone(),
xmodel.version,
) {
Ok(material) => material,
Err(error) => {
error_log!("[MATERIAL] {} - {}", mat, error);
continue;
}
};

loaded_materials.push(loaded_material);
let mut loaded_materials: HashMap<String, LoadedMaterial> = HashMap::new();
for mat in lod0.materials.clone() {
if let Vacant(entry) = loaded_materials.entry(mat.clone()) {
match xmodel.version {
XModelVersion::V14 => {
entry.insert(LoadedMaterial::new(mat, Vec::new(), xmodel.version));
}
_ => {
let loaded_material = match Self::load_material(
asset_path.clone(),
mat.clone(),
xmodel.version,
) {
Ok(material) => material,
Err(error) => {
error_log!("[MATERIAL] {} - {}", mat, error);
continue;
}
};

entry.insert(loaded_material);
}
}
}
}
Expand All @@ -277,7 +281,17 @@ impl Loader {
[0f32; 3],
[1f32; 3],
loaded_materials,
xmodelsurf.surfaces.into_iter().map(|s| s.into()).collect(),
xmodelsurf
.surfaces
.into_iter()
.enumerate()
.map(|(i, s)| {
let mut loaded_surface: LoadedSurface = s.into();
loaded_surface.set_material(lod0.materials[i].clone());

loaded_surface
})
.collect(),
match xmodelpart {
Some(xmodelpart) => xmodelpart.bones.into_iter().map(|b| b.into()).collect(),
None => Vec::<LoadedBone>::new(),
Expand Down

0 comments on commit 6a75c60

Please sign in to comment.