summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_import_collada.cpp250
-rw-r--r--editor/import/resource_importer_scene.cpp4
-rw-r--r--editor/import/resource_importer_scene.h2
3 files changed, 51 insertions, 205 deletions
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 86482dad5a..b1991d755b 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -41,6 +41,7 @@
#include "scene/animation/animation_player.h"
#include "scene/resources/animation.h"
#include "scene/resources/packed_scene.h"
+#include "scene/resources/surface_tool.h"
#include <iostream>
@@ -868,7 +869,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
int normal_pos = (normal_src->stride ? normal_src->stride : 3) * p.indices[src + normal_ofs];
ERR_FAIL_INDEX_V(normal_pos, normal_src->array.size(), ERR_INVALID_DATA);
vertex.normal = Vector3(normal_src->array[normal_pos + 0], normal_src->array[normal_pos + 1], normal_src->array[normal_pos + 2]);
- vertex.normal.snap(Vector3(0.001, 0.001, 0.001));
if (tangent_src && binormal_src) {
@@ -991,18 +991,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
}
}
- PoolVector<int> index_array;
- index_array.resize(indices_list.size());
- PoolVector<int>::Write index_arrayw = index_array.write();
-
- int iidx = 0;
- for (List<int>::Element *F = indices_list.front(); F; F = F->next()) {
-
- index_arrayw[iidx++] = F->get();
- }
-
- index_arrayw = PoolVector<int>::Write();
-
/*****************/
/* MAKE SURFACES */
/*****************/
@@ -1011,9 +999,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
Ref<SpatialMaterial> material;
- //find material
- Mesh::PrimitiveType primitive = Mesh::PRIMITIVE_TRIANGLES;
-
{
if (p_material_map.has(p.material)) {
@@ -1031,212 +1016,73 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
}
}
- PoolVector<Vector3> final_vertex_array;
- PoolVector<Vector3> final_normal_array;
- PoolVector<float> final_tangent_array;
- PoolVector<Color> final_color_array;
- PoolVector<Vector3> final_uv_array;
- PoolVector<Vector3> final_uv2_array;
- PoolVector<int> final_bone_array;
- PoolVector<float> final_weight_array;
-
- uint32_t final_format = 0;
+ Ref<SurfaceTool> surftool;
+ surftool.instance();
+ surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
- //create format
- final_format = Mesh::ARRAY_FORMAT_VERTEX | Mesh::ARRAY_FORMAT_INDEX;
-
- if (normal_src) {
- final_format |= Mesh::ARRAY_FORMAT_NORMAL;
- if (uv_src && binormal_src && tangent_src) {
- final_format |= Mesh::ARRAY_FORMAT_TANGENT;
+ for (int k = 0; k < vertex_array.size(); k++) {
+ if (normal_src) {
+ surftool->add_normal(vertex_array[k].normal);
+ if (binormal_src && tangent_src) {
+ surftool->add_tangent(vertex_array[k].tangent);
+ }
}
- }
-
- if (color_src)
- final_format |= Mesh::ARRAY_FORMAT_COLOR;
- if (uv_src)
- final_format |= Mesh::ARRAY_FORMAT_TEX_UV;
- if (uv2_src)
- final_format |= Mesh::ARRAY_FORMAT_TEX_UV2;
-
- if (has_weights) {
- final_format |= Mesh::ARRAY_FORMAT_WEIGHTS;
- final_format |= Mesh::ARRAY_FORMAT_BONES;
- }
-
- //set arrays
-
- int vlen = vertex_array.size();
- { //vertices
-
- PoolVector<Vector3> varray;
- varray.resize(vertex_array.size());
-
- PoolVector<Vector3>::Write varrayw = varray.write();
-
- for (int k = 0; k < vlen; k++)
- varrayw[k] = vertex_array[k].vertex;
-
- varrayw = PoolVector<Vector3>::Write();
- final_vertex_array = varray;
- }
-
- if (uv_src) { //compute uv first, may be needed for computing tangent/bionrmal
- PoolVector<Vector3> uvarray;
- uvarray.resize(vertex_array.size());
- PoolVector<Vector3>::Write uvarrayw = uvarray.write();
-
- for (int k = 0; k < vlen; k++) {
- uvarrayw[k] = vertex_array[k].uv;
+ if (uv_src) {
+ surftool->add_uv(Vector2(vertex_array[k].uv.x, vertex_array[k].uv.y));
}
-
- uvarrayw = PoolVector<Vector3>::Write();
- final_uv_array = uvarray;
- }
-
- if (uv2_src) { //compute uv first, may be needed for computing tangent/bionrmal
- PoolVector<Vector3> uv2array;
- uv2array.resize(vertex_array.size());
- PoolVector<Vector3>::Write uv2arrayw = uv2array.write();
-
- for (int k = 0; k < vlen; k++) {
- uv2arrayw[k] = vertex_array[k].uv2;
+ if (uv2_src) {
+ surftool->add_uv2(Vector2(vertex_array[k].uv2.x, vertex_array[k].uv2.y));
}
-
- uv2arrayw = PoolVector<Vector3>::Write();
- final_uv2_array = uv2array;
- }
-
- if (normal_src) {
- PoolVector<Vector3> narray;
- narray.resize(vertex_array.size());
- PoolVector<Vector3>::Write narrayw = narray.write();
-
- for (int k = 0; k < vlen; k++) {
- narrayw[k] = vertex_array[k].normal;
+ if (color_src) {
+ surftool->add_color(vertex_array[k].color);
}
- narrayw = PoolVector<Vector3>::Write();
- final_normal_array = narray;
-
- /*
- PoolVector<Vector3> altnaray;
- _generate_normals(index_array,final_vertex_array,altnaray);
-
- for(int i=0;i<altnaray.size();i++)
- print_line(rtos(altnaray[i].dot(final_normal_array[i])));
- */
-
- } else if (primitive == Mesh::PRIMITIVE_TRIANGLES) {
- //generate normals (even if unused later)
-
- _generate_normals(index_array, final_vertex_array, final_normal_array);
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("Collada: Triangle mesh lacks normals, so normals were generated.");
- final_format |= Mesh::ARRAY_FORMAT_NORMAL;
- }
-
- if (final_normal_array.size() && uv_src && binormal_src && tangent_src && !force_make_tangents) {
+ if (has_weights) {
+ Vector<float> weights;
+ Vector<int> bones;
+ weights.resize(VS::ARRAY_WEIGHTS_SIZE);
+ bones.resize(VS::ARRAY_WEIGHTS_SIZE);
+ //float sum=0.0;
+ for (int l = 0; l < VS::ARRAY_WEIGHTS_SIZE; l++) {
+ if (l < vertex_array[k].weights.size()) {
+ weights[l] = vertex_array[k].weights[l].weight;
+ bones[l] = vertex_array[k].weights[l].bone_idx;
+ //sum += vertex_array[k].weights[l].weight;
+ } else {
- PoolVector<real_t> tarray;
- tarray.resize(vertex_array.size() * 4);
- PoolVector<real_t>::Write tarrayw = tarray.write();
+ weights[l] = 0;
+ bones[l] = 0;
+ }
+ }
- for (int k = 0; k < vlen; k++) {
- tarrayw[k * 4 + 0] = vertex_array[k].tangent.normal.x;
- tarrayw[k * 4 + 1] = vertex_array[k].tangent.normal.y;
- tarrayw[k * 4 + 2] = vertex_array[k].tangent.normal.z;
- tarrayw[k * 4 + 3] = vertex_array[k].tangent.d;
+ surftool->add_bones(bones);
+ surftool->add_weights(weights);
}
- tarrayw = PoolVector<real_t>::Write();
-
- final_tangent_array = tarray;
- } else if (final_normal_array.size() && primitive == Mesh::PRIMITIVE_TRIANGLES && final_uv_array.size() && (force_make_tangents || (material.is_valid()))) {
- //if this uses triangles, there are uvs and the material is using a normalmap, generate tangents and binormals, because they WILL be needed
- //generate binormals/tangents
- _generate_tangents_and_binormals(index_array, final_vertex_array, final_uv_array, final_normal_array, final_tangent_array);
- final_format |= Mesh::ARRAY_FORMAT_TANGENT;
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("Collada: Triangle mesh lacks tangents (And normalmap was used), so tangents were generated.");
+ surftool->add_vertex(vertex_array[k].vertex);
}
- if (color_src) {
- PoolVector<Color> colorarray;
- colorarray.resize(vertex_array.size());
- PoolVector<Color>::Write colorarrayw = colorarray.write();
-
- for (int k = 0; k < vlen; k++) {
- colorarrayw[k] = vertex_array[k].color;
- }
-
- colorarrayw = PoolVector<Color>::Write();
-
- final_color_array = colorarray;
+ for (List<int>::Element *E = indices_list.front(); E; E = E->next()) {
+ surftool->add_index(E->get());
}
- if (has_weights) {
- PoolVector<float> weightarray;
- PoolVector<int> bonearray;
-
- weightarray.resize(vertex_array.size() * 4);
- PoolVector<float>::Write weightarrayw = weightarray.write();
- bonearray.resize(vertex_array.size() * 4);
- PoolVector<int>::Write bonearrayw = bonearray.write();
-
- for (int k = 0; k < vlen; k++) {
- float sum = 0;
-
- for (int l = 0; l < VS::ARRAY_WEIGHTS_SIZE; l++) {
- if (l < vertex_array[k].weights.size()) {
- weightarrayw[k * VS::ARRAY_WEIGHTS_SIZE + l] = vertex_array[k].weights[l].weight;
- sum += weightarrayw[k * VS::ARRAY_WEIGHTS_SIZE + l];
- bonearrayw[k * VS::ARRAY_WEIGHTS_SIZE + l] = int(vertex_array[k].weights[l].bone_idx);
- //COLLADA_PRINT(itos(k)+": "+rtos(bonearrayw[k*VS::ARRAY_WEIGHTS_SIZE+l])+":"+rtos(weightarray[k*VS::ARRAY_WEIGHTS_SIZE+l]));
- } else {
-
- weightarrayw[k * VS::ARRAY_WEIGHTS_SIZE + l] = 0;
- bonearrayw[k * VS::ARRAY_WEIGHTS_SIZE + l] = 0;
- }
- }
- /*
- if (sum<0.8)
- COLLADA_PRINT("ERROR SUMMING INDEX "+itos(k)+" had weights: "+itos(vertex_array[k].weights.size()));
- */
- }
+ if (!normal_src) {
+ //should always be normals
+ surftool->generate_normals();
+ }
- weightarrayw = PoolVector<float>::Write();
- bonearrayw = PoolVector<int>::Write();
+ if ((!binormal_src || !tangent_src) && normal_src && uv_src && force_make_tangents) {
- final_weight_array = weightarray;
- final_bone_array = bonearray;
+ surftool->generate_tangents();
}
////////////////////////////
// FINALLY CREATE SUFRACE //
////////////////////////////
- Array d;
+ Array d = surftool->commit_to_arrays();
d.resize(VS::ARRAY_MAX);
- d[Mesh::ARRAY_INDEX] = index_array;
- d[Mesh::ARRAY_VERTEX] = final_vertex_array;
-
- if (final_normal_array.size())
- d[Mesh::ARRAY_NORMAL] = final_normal_array;
- if (final_tangent_array.size())
- d[Mesh::ARRAY_TANGENT] = final_tangent_array;
- if (final_uv_array.size())
- d[Mesh::ARRAY_TEX_UV] = final_uv_array;
- if (final_uv2_array.size())
- d[Mesh::ARRAY_TEX_UV2] = final_uv2_array;
- if (final_color_array.size())
- d[Mesh::ARRAY_COLOR] = final_color_array;
- if (final_weight_array.size())
- d[Mesh::ARRAY_WEIGHTS] = final_weight_array;
- if (final_bone_array.size())
- d[Mesh::ARRAY_BONES] = final_bone_array;
-
Array mr;
////////////////////////////
@@ -1249,10 +1095,10 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
Array a = p_morph_meshes[mi]->surface_get_arrays(surface);
//add valid weight and bone arrays if they exist, TODO check if they are unique to shape (generally not)
- if (final_weight_array.size())
- a[Mesh::ARRAY_WEIGHTS] = final_weight_array;
- if (final_bone_array.size())
- a[Mesh::ARRAY_BONES] = final_bone_array;
+ if (has_weights) {
+ a[Mesh::ARRAY_WEIGHTS] = d[Mesh::ARRAY_WEIGHTS];
+ a[Mesh::ARRAY_BONES] = d[Mesh::ARRAY_BONES];
+ }
a[Mesh::ARRAY_INDEX] = Variant();
//a.resize(Mesh::ARRAY_MAX); //no need for index
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index dd98494504..7fa76713f3 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -933,13 +933,13 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/custom_script", PROPERTY_HINT_FILE, script_ext_hint), ""));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "nodes/storage", PROPERTY_HINT_ENUM, "Single Scene,Instanced Sub-Scenes"), scenes_out ? 1 : 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "materials/location", PROPERTY_HINT_ENUM, "Node,Mesh"), meshes_out ? 1 : 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "materials/location", PROPERTY_HINT_ENUM, "Node,Mesh"), (meshes_out || materials_out) ? 1 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "materials/storage", PROPERTY_HINT_ENUM, "Built-In,Files", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), materials_out ? 1 : 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "materials/keep_on_reimport"), materials_out ? true : false));
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 ? true : false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "external_files/store_in_subdir"), true));
+ 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));
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "animation/filter_script", PROPERTY_HINT_MULTILINE_TEXT), ""));
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index bf8d88ce0a..9c3d5e7876 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -83,9 +83,9 @@ class ResourceImporterScene : public ResourceImporter {
static ResourceImporterScene *singleton;
enum Presets {
- PRESET_SINGLE_SCENE,
PRESET_SEPARATE_MATERIALS,
PRESET_SEPARATE_MESHES,
+ PRESET_SINGLE_SCENE,
PRESET_SEPARATE_MESHES_AND_MATERIALS,
PRESET_MULTIPLE_SCENES,
PRESET_MULTIPLE_SCENES_AND_MATERIALS,