summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp18
-rw-r--r--editor/import/resource_importer_obj.cpp1
-rw-r--r--editor/import/resource_importer_scene.cpp18
-rw-r--r--editor/import/resource_importer_scene.h8
4 files changed, 32 insertions, 13 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 397bb6ad68..f704d97373 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -29,7 +29,7 @@ Error EditorSceneImporterGLTF::_parse_json(const String &p_path, GLTFState &stat
Vector<uint8_t> array;
array.resize(f->get_len());
- f->get_buffer(array.ptr(), array.size());
+ f->get_buffer(array.ptrw(), array.size());
String text;
text.parse_utf8((const char *)array.ptr(), array.size());
@@ -65,7 +65,7 @@ Error EditorSceneImporterGLTF::_parse_glb(const String &p_path, GLTFState &state
ERR_FAIL_COND_V(chunk_type != 0x4E4F534A, ERR_PARSE_ERROR); //JSON
Vector<uint8_t> json_data;
json_data.resize(chunk_length);
- uint32_t len = f->get_buffer(json_data.ptr(), chunk_length);
+ uint32_t len = f->get_buffer(json_data.ptrw(), chunk_length);
ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT);
String text;
@@ -94,7 +94,7 @@ Error EditorSceneImporterGLTF::_parse_glb(const String &p_path, GLTFState &state
ERR_FAIL_COND_V(chunk_type != 0x004E4942, ERR_PARSE_ERROR); //BIN
state.glb_data.resize(chunk_length);
- len = f->get_buffer(state.glb_data.ptr(), chunk_length);
+ len = f->get_buffer(state.glb_data.ptrw(), chunk_length);
ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT);
return OK;
@@ -467,9 +467,10 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, int p_buffe
uint32_t offset = bv.byte_offset + byte_offset;
Vector<uint8_t> buffer = state.buffers[bv.buffer]; //copy on write, so no performance hit
+ const uint8_t *bufptr = buffer.ptr();
//use to debug
- print_line("type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count));
+ //print_line("type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count));
print_line("accessor offset" + itos(byte_offset) + " view offset: " + itos(bv.byte_offset) + " total buffer len: " + itos(buffer.size()) + " view len " + itos(bv.byte_length));
int buffer_end = (stride * (count - 1)) + element_size;
@@ -481,7 +482,7 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, int p_buffe
for (int i = 0; i < count; i++) {
- const uint8_t *src = &buffer[offset + i * stride];
+ const uint8_t *src = &bufptr[offset + i * stride];
for (int j = 0; j < component_count; j++) {
@@ -605,7 +606,7 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, int p
Vector<double> dst_buffer;
dst_buffer.resize(component_count * a.count);
- double *dst = dst_buffer.ptr();
+ double *dst = dst_buffer.ptrw();
if (a.buffer_view >= 0) {
@@ -628,13 +629,13 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, int p
indices.resize(a.sparse_count);
int indices_component_size = _get_component_type_size(a.sparse_indices_component_type);
- Error err = _decode_buffer_view(state, a.sparse_indices_buffer_view, indices.ptr(), 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false);
+ Error err = _decode_buffer_view(state, a.sparse_indices_buffer_view, indices.ptrw(), 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false);
if (err != OK)
return Vector<double>();
Vector<double> data;
data.resize(component_count * a.sparse_count);
- err = _decode_buffer_view(state, a.sparse_values_buffer_view, data.ptr(), skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex);
+ err = _decode_buffer_view(state, a.sparse_values_buffer_view, data.ptrw(), skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex);
if (err != OK)
return Vector<double>();
@@ -813,6 +814,7 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
Array meshes = state.json["meshes"];
for (int i = 0; i < meshes.size(); i++) {
+ print_line("on mesh: " + itos(i));
Dictionary d = meshes[i];
GLTFMesh mesh;
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index bd24aac99b..14bda9bb4e 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -58,6 +58,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
current_name = l.replace("newmtl", "").strip_edges();
current.instance();
+ current->set_name(current_name);
material_map[current_name] = current;
} else if (l.begins_with("Ka ")) {
//uv
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 63d4039295..95445693b4 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -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)) {
@@ -947,7 +952,10 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
for (int i = 0; i < mesh->get_surface_count(); i++) {
mat = mesh->surface_get_material(i);
- if (!mat.is_valid() || mat->get_name() == "")
+
+ if (!mat.is_valid())
+ continue;
+ if (mat->get_name() == "")
continue;
if (!p_materials.has(mat)) {
@@ -1022,6 +1030,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 +1140,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);
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index 5bf3145148..92777fafb6 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -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);