Skip to content

Commit

Permalink
feat: 1x1 norm/tex2
Browse files Browse the repository at this point in the history
  • Loading branch information
jochumdev committed Dec 17, 2023
1 parent 0d320df commit ecb0c31
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
7 changes: 4 additions & 3 deletions blender/s3o_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def find_obj():
if 'SpringRadius' in obj.name or 'SpringHeight' in obj.name:
continue

if obj.parent == None and (obj.type == 'EMPTY' or obj.type == 'MESH'):
if obj.parent is None and (obj.type == 'EMPTY' or obj.type == 'MESH'):
return obj

return None
Expand Down Expand Up @@ -47,7 +47,7 @@ def convert(par_filename : str):
):
#
# Import
context = bpy.context;
context = bpy.context
if context.mode != "OBJECT":
if not context.scene.objects.active:
context.scene.objects.active = context.scene.objects[0]
Expand All @@ -62,7 +62,7 @@ def convert(par_filename : str):
#
# Save
my_obj = find_obj()
if my_obj == None:
if my_obj is None:
raise Exception("No object found")

texture1_name = "texture1.dds"
Expand All @@ -89,6 +89,7 @@ def convert(par_filename : str):
par_filename,
bpy.context,
use_mesh_modifiers=True,
use_remove_base_plate=True,
use_triangles=True,
remove_suffix=False,
texture1_name=texture1_name,
Expand Down
4 changes: 2 additions & 2 deletions convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ for f in "arm" "core" "gok" "tll" "talon" "rumad"; do
find "../TA/objects3d/${f}" -iname '*.3do' -print0 | xargs -0 -I {} -P ${PROCS} /bin/bash -c '
if [[ ! -f "${2:0:-4}.s3o" ]]; then
./Upspring -r runscripts/convert_with_atlas.lua -- "../TA/unittextures/${1}.yaml" "$2";
# blender -b -P ./blender/s3o_optimize.py -- "${2:0:-4}.s3o"
blender -b -P ./blender/s3o_optimize.py -- "${2:0:-4}.s3o"
fi' '_' "${f}" {}
done

find "../TA/objects3d" -maxdepth 1 -iname '*.3do' -print0 | xargs -0 -I {} -P ${PROCS} /bin/bash -c '
if [[ ! -f "${1:0:-4}.s3o" ]]; then
./Upspring -r runscripts/convert_with_atlas.lua -- ../TA/unittextures/other.yaml "$1";
# blender -b -P ./blender/s3o_optimize.py -- "${2:0:-4}.s3o"
blender -b -P ./blender/s3o_optimize.py -- "${2:0:-4}.s3o"
fi' '_' {}
32 changes: 15 additions & 17 deletions src/Atlas/atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ bool atlas::add_3do_textures(std::vector<ImagePtr> par_images, bool par_power_of
}

auto marginImage = std::make_shared<Image>();

// Copy attributes.
marginImage->name(img->name());
marginImage->owidth(img->width());
marginImage->oheight(img->height());

marginImage->create(img->width() + (ATLAS_MARGIN * 2), img->height() + (ATLAS_MARGIN*2), 4);
marginImage->create(img->width() + (ATLAS_MARGIN * 2), img->height() + (ATLAS_MARGIN * 2), 4);
marginImage->clear_color(0.0f, 0.0f, 0.0f, 0.0f);

if (!marginImage->blit(img, ATLAS_MARGIN, ATLAS_MARGIN, 0, 0, 0, 0, img->width(), img->height(), 1)) {

if (!marginImage->blit(img, ATLAS_MARGIN, ATLAS_MARGIN, 0, 0, 0, 0, img->width(), img->height(),
1)) {
spdlog::error("image->blit failed, error was: {}", img->error());
continue;
}
Expand Down Expand Up @@ -142,7 +143,6 @@ bool atlas::pack() {
return false;
}


spdlog::debug("found '{}' rectangles", rectangles.size());
bin_ = packer_->pack(rectangles, 0, txpk::SizeContraintType::None, false);

Expand All @@ -164,13 +164,9 @@ bool atlas::pack() {
return true;
}

void atlas::info(atlas_info& par_info) {
info_ = par_info;
}
void atlas::info(atlas_info& par_info) { info_ = par_info; }

const atlas_info& atlas::info() const {
return info_;
}
const atlas_info& atlas::info() const { return info_; }

bool atlas::save(const std::string& par_savepath) {
if (!packed_ && !pack()) {
Expand All @@ -189,12 +185,13 @@ bool atlas::save(const std::string& par_savepath) {

// Generate fake other.dds
Image other_image;
if (!other_image.create(bin_.width, bin_.height, 4)) {
if (!other_image.create(1, 1, 4)) {
spdlog::error("other.dds create failed: %s", other_image.error());
return false;
}
other_image.clear_color(0.0f / 255.0f, 129.0f / 255.0f, 79.0f / 255.0f, 1.0f);
auto other_save_path = (yaml_path.parent_path() / (yaml_path.stem().string() + "_tex2.dds")).string();
other_image.clear_color(0.2F, 0.1F, 0.8F, 1.0F);
auto other_save_path =
(yaml_path.parent_path() / (yaml_path.stem().string() + "_tex2.dds")).string();
if (!other_image.save(other_save_path)) {
spdlog::error("normals.dds save failed: %s", other_image.error());
return false;
Expand All @@ -203,12 +200,13 @@ bool atlas::save(const std::string& par_savepath) {

// Generate fake normals.dds
Image normal_image;
if (!normal_image.create(bin_.width, bin_.height, 4)) {
if (!normal_image.create(1, 1, 4)) {
spdlog::error("normals.dds create failed: %s", normal_image.error());
return false;
}
}
normal_image.clear_color(128.0f / 255.0f, 129.0f / 255.0f, 255.0f / 255.0f, 1.0f);
auto normal_save_path = (yaml_path.parent_path() / (yaml_path.stem().string() + "_normals.dds")).string();
auto normal_save_path =
(yaml_path.parent_path() / (yaml_path.stem().string() + "_normals.dds")).string();
if (!normal_image.save(normal_save_path)) {
spdlog::error("normals.dds save failed: %s", normal_image.error());
return false;
Expand Down
16 changes: 12 additions & 4 deletions src/Atlas/atlas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
#define ATLAS_MARGIN 0

struct atlas_info_image {
atlas_info_image() {};
atlas_info_image(){};
atlas_info_image(std::string& par_name, std::uint32_t par_width, std::uint32_t par_height,
std::uint32_t par_orig_width, std::uint32_t par_orig_height,
std::uint32_t par_left, std::uint32_t par_top)
: name(par_name), width(par_width), height(par_height), orig_width(par_orig_width), orig_height(par_orig_height), left(par_left), top(par_top) {}
: name(par_name),
width(par_width),
height(par_height),
orig_width(par_orig_width),
orig_height(par_orig_height),
left(par_left),
top(par_top) {}

std::string name;
std::uint32_t width;
Expand All @@ -27,7 +33,8 @@ struct atlas_info_image {
std::uint32_t top;

inline float U(std::uint32_t par_width, float par_u) {
float result = par_u * float(orig_width) / float(par_width) + (float(left) + float(ATLAS_MARGIN)) / float(par_width);
float result = par_u * float(orig_width) / float(par_width) +
(float(left) + float(ATLAS_MARGIN)) / float(par_width);
if (result > 1.0f) {
return 1.0f;
}
Expand All @@ -38,7 +45,8 @@ struct atlas_info_image {
}

inline float V(std::uint32_t par_height, float par_v) {
float result = par_v * float(orig_height) / float(par_height) + (float(top) + float(ATLAS_MARGIN)) / float(par_height);
float result = par_v * float(orig_height) / float(par_height) +
(float(top) + float(ATLAS_MARGIN)) / float(par_height);
if (result > 1.0f) {
return 1.0f;
}
Expand Down

0 comments on commit ecb0c31

Please sign in to comment.