Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 9, 2024
1 parent bb99835 commit d3fd716
Show file tree
Hide file tree
Showing 3 changed files with 357 additions and 140 deletions.
46 changes: 33 additions & 13 deletions editor/vox/vox_mesh_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ double VoxelVoxMeshImporter::_zn_get_priority() const {
}

void VoxelVoxMeshImporter::_zn_get_import_options(
StdVector<ImportOptionWrapper> &out_options, const String &path, int preset_index) const {
StdVector<ImportOptionWrapper> &out_options,
const String &path,
int preset_index
) const {
// const VoxelStringNames &sn = VoxelStringNames::get_singleton();
out_options.push_back(ImportOptionWrapper(PropertyInfo(Variant::BOOL, "store_colors_in_texture"), false));
out_options.push_back(ImportOptionWrapper(PropertyInfo(Variant::FLOAT, "scale"), 1.f));
out_options.push_back(ImportOptionWrapper(
PropertyInfo(Variant::INT, "pivot_mode", PROPERTY_HINT_ENUM, "LowerCorner,SceneOrigin,Center"), 1));
PropertyInfo(Variant::INT, "pivot_mode", PROPERTY_HINT_ENUM, "LowerCorner,SceneOrigin,Center"), 1
));
}

bool VoxelVoxMeshImporter::_zn_get_option_visibility(
const String &path, const StringName &option_name, const KeyValueWrapper options) const {
const String &path,
const StringName &option_name,
const KeyValueWrapper options
) const {
return true;
}

Expand All @@ -85,8 +92,9 @@ Error for_each_model_instance_in_scene_graph(const Data &data, int node_id, Tran
case Node::TYPE_TRANSFORM: {
const TransformNode *vox_transform_node = reinterpret_cast<const TransformNode *>(vox_node);
// Calculate global transform of the child
const Transform3D child_trans(transform.basis * vox_transform_node->rotation.basis,
transform.xform(vox_transform_node->position));
const Transform3D child_trans(
transform.basis * vox_transform_node->rotation.basis, transform.xform(vox_transform_node->position)
);
for_each_model_instance_in_scene_graph(data, vox_transform_node->child_node_id, child_trans, depth + 1, f);
} break;

Expand Down Expand Up @@ -202,9 +210,12 @@ bool make_single_voxel_grid(Span<const ModelInstance> instances, Vector3i &out_o
// 3 gigabytes
const size_t limit = 3'000'000'000ull;
const size_t volume = Vector3iUtil::get_volume(bounding_box.size);
ERR_FAIL_COND_V_MSG(volume > limit, false,
ERR_FAIL_COND_V_MSG(
volume > limit,
false,
String("Vox data is too big to be meshed as a single mesh ({0}: {0} bytes)")
.format(varray(bounding_box.size, ZN_SIZE_T_TO_VARIANT(volume))));
.format(varray(bounding_box.size, ZN_SIZE_T_TO_VARIANT(volume)))
);

out_voxels.create(bounding_box.size + Vector3iUtil::create(VoxelMesherCubes::PADDING * 2));
out_voxels.set_channel_depth(VoxelBuffer::CHANNEL_COLOR, VoxelBuffer::DEPTH_8_BIT);
Expand All @@ -213,18 +224,26 @@ bool make_single_voxel_grid(Span<const ModelInstance> instances, Vector3i &out_o
for (unsigned int instance_index = 0; instance_index < instances.size(); ++instance_index) {
const ModelInstance &mi = instances[instance_index];
ERR_FAIL_COND_V(mi.voxels == nullptr, false);
out_voxels.copy_channel_from(*mi.voxels, Vector3i(), mi.voxels->get_size(),
out_voxels.copy_channel_from(
*mi.voxels,
Vector3i(),
mi.voxels->get_size(),
mi.position - bounding_box.position + Vector3iUtil::create(VoxelMesherCubes::PADDING),
VoxelBuffer::CHANNEL_COLOR);
VoxelBuffer::CHANNEL_COLOR
);
}

out_origin = bounding_box.position;
return true;
}

Error VoxelVoxMeshImporter::_zn_import(const String &p_source_file, const String &p_save_path,
const KeyValueWrapper p_options, StringListWrapper out_platform_variants,
StringListWrapper out_gen_files) const {
Error VoxelVoxMeshImporter::_zn_import(
const String &p_source_file,
const String &p_save_path,
const KeyValueWrapper p_options,
StringListWrapper out_platform_variants,
StringListWrapper out_gen_files
) const {
//
const bool p_store_colors_in_textures = p_options.get("store_colors_in_texture");
const float p_scale = p_options.get("scale");
Expand Down Expand Up @@ -364,7 +383,8 @@ Error VoxelVoxMeshImporter::_zn_import(const String &p_source_file, const String
String mesh_save_path = String("{0}.mesh").format(varray(p_save_path));
const Error mesh_save_err = save_resource(mesh, mesh_save_path, ResourceSaver::FLAG_NONE);
ERR_FAIL_COND_V_MSG(
mesh_save_err != OK, mesh_save_err, String("Failed to save {0}").format(varray(mesh_save_path)));
mesh_save_err != OK, mesh_save_err, String("Failed to save {0}").format(varray(mesh_save_path))
);
}

return OK;
Expand Down
Loading

0 comments on commit d3fd716

Please sign in to comment.