Add importer option to make meshes bakeable by default.

This commit is contained in:
Juan Linietsky 2017-11-25 01:29:15 -03:00
parent 2c7b4c2053
commit 66a8a07c2c
2 changed files with 17 additions and 4 deletions

View file

@ -156,12 +156,12 @@ static String _fixstr(const String &p_what, const String &p_str) {
return p_what;
}
Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map) {
Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode) {
// children first..
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *r = _fix_node(p_node->get_child(i), p_root, collision_map);
Node *r = _fix_node(p_node->get_child(i), p_root, collision_map, p_light_bake_mode);
if (!r) {
print_line("was erased..");
i--; //was erased
@ -205,6 +205,11 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
}
}
}
if (p_light_bake_mode != LIGHT_BAKE_DISABLED) {
mi->set_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT, true);
}
}
if (Object::cast_to<AnimationPlayer>(p_node)) {
@ -1022,6 +1027,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/compress"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/storage", PROPERTY_HINT_ENUM, "Built-In,Files"), meshes_out ? 1 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Enable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "external_files/store_in_subdir"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
@ -1131,10 +1137,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
float anim_optimizer_linerr = p_options["animation/optimizer/max_linear_error"];
float anim_optimizer_angerr = p_options["animation/optimizer/max_angular_error"];
float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"];
int light_bake_mode = p_options["meshes/light_baking"];
Map<Ref<ArrayMesh>, Ref<Shape> > collision_map;
scene = _fix_node(scene, scene, collision_map);
scene = _fix_node(scene, scene, collision_map, LightBakeMode(light_bake_mode));
if (use_optimizer) {
_optimize_animations(scene, anim_optimizer_linerr, anim_optimizer_angerr, anim_optimizer_maxang);

View file

@ -100,6 +100,12 @@ class ResourceImporterScene : public ResourceImporter {
PRESET_MAX
};
enum LightBakeMode {
LIGHT_BAKE_DISABLED,
LIGHT_BAKE_ENABLE,
//LIGHT_BAKE_LIGHTMAPS
};
void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
public:
@ -124,7 +130,7 @@ public:
void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_animations, bool p_make_materials, bool p_keep_materials, bool p_make_meshes, Map<Ref<Animation>, Ref<Animation> > &p_animations, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes);
Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map);
Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode);
void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all);
void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep);