Converting to MeshLibrary works again, fixes #8092
This commit is contained in:
parent
fdc2cdef0b
commit
cb0e357d0b
@ -1214,7 +1214,7 @@ void EditorNode::_dialog_action(String p_file) {
|
||||
ml = Ref<MeshLibrary>(memnew(MeshLibrary));
|
||||
}
|
||||
|
||||
//MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(),ml,true);
|
||||
MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true);
|
||||
|
||||
Error err = ResourceSaver::save(p_file, ml);
|
||||
if (err) {
|
||||
@ -1246,7 +1246,7 @@ void EditorNode::_dialog_action(String p_file) {
|
||||
}
|
||||
|
||||
} else {
|
||||
ml = Ref<TileSet>(memnew(TileSet));
|
||||
ml.instance();
|
||||
}
|
||||
|
||||
TileSetEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true);
|
||||
@ -6058,7 +6058,7 @@ EditorNode::EditorNode() {
|
||||
add_editor_plugin(memnew(MultiMeshEditorPlugin(this)));
|
||||
add_editor_plugin(memnew(MeshInstanceEditorPlugin(this)));
|
||||
add_editor_plugin(memnew(AnimationTreeEditorPlugin(this)));
|
||||
//add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) );
|
||||
add_editor_plugin(memnew(MeshLibraryEditorPlugin(this)));
|
||||
add_editor_plugin(memnew(StyleBoxEditorPlugin(this)));
|
||||
add_editor_plugin(memnew(ParticlesEditorPlugin(this)));
|
||||
add_editor_plugin(memnew(ResourcePreloaderEditorPlugin(this)));
|
||||
|
@ -390,7 +390,7 @@ Error ColladaImport::_create_material(const String &p_target) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//material->set_parameter(SpatialMaterial::PARAM_DIFFUSE,effect.diffuse.color);
|
||||
material->set_albedo(effect.diffuse.color);
|
||||
}
|
||||
|
||||
// SPECULAR
|
||||
|
@ -29,7 +29,6 @@
|
||||
/*************************************************************************/
|
||||
#include "cube_grid_theme_editor_plugin.h"
|
||||
|
||||
#if 0
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "main/main.h"
|
||||
@ -44,12 +43,10 @@ void MeshLibraryEditor::edit(const Ref<MeshLibrary>& p_theme) {
|
||||
theme = p_theme;
|
||||
if (theme.is_valid())
|
||||
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !theme->has_meta("_editor_source_scene"));
|
||||
|
||||
}
|
||||
|
||||
void MeshLibraryEditor::_menu_confirm() {
|
||||
|
||||
|
||||
switch (option) {
|
||||
|
||||
case MENU_OPTION_REMOVE_ITEM: {
|
||||
@ -64,19 +61,15 @@ void MeshLibraryEditor::_menu_confirm() {
|
||||
} break;
|
||||
default: {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) {
|
||||
|
||||
if (!p_merge)
|
||||
p_library->clear();
|
||||
|
||||
|
||||
for (int i = 0; i < p_scene->get_child_count(); i++) {
|
||||
|
||||
|
||||
Node *child = p_scene->get_child(i);
|
||||
|
||||
if (!child->cast_to<MeshInstance>()) {
|
||||
@ -88,8 +81,6 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
|
||||
} else
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
|
||||
MeshInstance *mi = child->cast_to<MeshInstance>();
|
||||
@ -105,24 +96,41 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
p_library->set_item_name(id, mi->get_name());
|
||||
}
|
||||
|
||||
|
||||
p_library->set_item_mesh(id, mesh);
|
||||
|
||||
Ref<Shape> collision;
|
||||
|
||||
|
||||
for (int j = 0; j < mi->get_child_count(); j++) {
|
||||
#if 1
|
||||
|
||||
Node *child2 = mi->get_child(j);
|
||||
if (!child2->cast_to<StaticBody>())
|
||||
continue;
|
||||
|
||||
StaticBody *sb = child2->cast_to<StaticBody>();
|
||||
if (sb->get_shape_count()==0)
|
||||
continue;
|
||||
collision=sb->get_shape(0);
|
||||
if (!collision.is_null())
|
||||
List<uint32_t> shapes;
|
||||
sb->get_shape_owners(&shapes);
|
||||
|
||||
for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) {
|
||||
if (sb->is_shape_owner_disabled(E->get())) continue;
|
||||
|
||||
//Transform shape_transform = sb->shape_owner_get_transform(E->get());
|
||||
|
||||
//shape_transform.set_origin(shape_transform.get_origin() - phys_offset);
|
||||
|
||||
for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) {
|
||||
|
||||
collision = sb->shape_owner_get_shape(E->get(), k);
|
||||
if (collision.is_valid())
|
||||
break;
|
||||
#endif
|
||||
/* TileSet::ShapeData shape_data;
|
||||
shape_data.shape = shape;
|
||||
shape_data.shape_transform = shape_transform;
|
||||
shape_data.one_way_collision = one_way;
|
||||
collisions.push_back(shape_data);*/
|
||||
}
|
||||
if (collision.is_valid())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!collision.is_null()) {
|
||||
@ -149,23 +157,39 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
if (1) {
|
||||
Vector<int> ids = p_library->get_item_list();
|
||||
RID vp = VS::get_singleton()->viewport_create();
|
||||
VS::ViewportRect vr;
|
||||
vr.x=0;
|
||||
vr.y=0;
|
||||
vr.width=EditorSettings::get_singleton()->get("editors/grid_map/preview_size");
|
||||
vr.height=EditorSettings::get_singleton()->get("editors/grid_map/preview_size");
|
||||
VS::get_singleton()->viewport_set_rect(vp,vr);
|
||||
VS::get_singleton()->viewport_set_as_render_target(vp,true);
|
||||
VS::get_singleton()->viewport_set_render_target_update_mode(vp,VS::RENDER_TARGET_UPDATE_ALWAYS);
|
||||
RID scen = VS::get_singleton()->scenario_create();
|
||||
VS::get_singleton()->viewport_set_scenario(vp,scen);
|
||||
RID cam = VS::get_singleton()->camera_create();
|
||||
VS::get_singleton()->camera_set_transform(cam, Transform() );
|
||||
VS::get_singleton()->viewport_attach_camera(vp,cam);
|
||||
RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
|
||||
RID lightinst = VS::get_singleton()->instance_create2(light,scen);
|
||||
VS::get_singleton()->camera_set_orthogonal(cam,1.0,0.01,1000.0);
|
||||
int size = EditorSettings::get_singleton()->get("editors/grid_map/preview_size");
|
||||
|
||||
RID scenario = VS::get_singleton()->scenario_create();
|
||||
|
||||
RID viewport = VS::get_singleton()->viewport_create();
|
||||
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ALWAYS);
|
||||
VS::get_singleton()->viewport_set_vflip(viewport, true);
|
||||
VS::get_singleton()->viewport_set_scenario(viewport, scenario);
|
||||
VS::get_singleton()->viewport_set_size(viewport, size, size);
|
||||
VS::get_singleton()->viewport_set_transparent_background(viewport, true);
|
||||
VS::get_singleton()->viewport_set_active(viewport, true);
|
||||
RID viewport_texture = VS::get_singleton()->viewport_get_texture(viewport);
|
||||
|
||||
RID camera = VS::get_singleton()->camera_create();
|
||||
VS::get_singleton()->viewport_attach_camera(viewport, camera);
|
||||
VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3)));
|
||||
//VS::get_singleton()->camera_set_perspective(camera,45,0.1,10);
|
||||
VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0);
|
||||
|
||||
RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
|
||||
RID light_instance = VS::get_singleton()->instance_create2(light, scenario);
|
||||
VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
|
||||
|
||||
RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
|
||||
VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7));
|
||||
//VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0));
|
||||
RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario);
|
||||
|
||||
VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
|
||||
|
||||
//sphere = VS::get_singleton()->mesh_create();
|
||||
RID mesh_instance = VS::get_singleton()->instance_create();
|
||||
VS::get_singleton()->instance_set_scenario(mesh_instance, scenario);
|
||||
|
||||
EditorProgress ep("mlib", TTR("Creating Mesh Library"), ids.size());
|
||||
|
||||
@ -175,14 +199,14 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
Ref<Mesh> mesh = p_library->get_item_mesh(id);
|
||||
if (!mesh.is_valid())
|
||||
continue;
|
||||
AABB aabb= mesh->get_aabb();
|
||||
Rect3 aabb = mesh->get_aabb();
|
||||
print_line("aabb: " + aabb);
|
||||
Vector3 ofs = aabb.pos + aabb.size*0.5;
|
||||
aabb.pos-=ofs;
|
||||
Vector3 ofs = aabb.position + aabb.size * 0.5;
|
||||
aabb.position -= ofs;
|
||||
Transform xform;
|
||||
xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.25);
|
||||
xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.25)*xform.basis;
|
||||
AABB rot_aabb = xform.xform(aabb);
|
||||
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25);
|
||||
xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis;
|
||||
Rect3 rot_aabb = xform.xform(aabb);
|
||||
print_line("rot_aabb: " + rot_aabb);
|
||||
float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
|
||||
if (m == 0)
|
||||
@ -193,13 +217,13 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
xform.basis.scale(Vector3(m, m, m));
|
||||
xform.origin = -xform.basis.xform(ofs); //-ofs*m;
|
||||
xform.origin.z -= rot_aabb.size.z * 2;
|
||||
RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(),scen);
|
||||
RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(), scenario);
|
||||
VS::get_singleton()->instance_set_transform(inst, xform);
|
||||
ep.step(TTR("Thumbnail.."), i);
|
||||
VS::get_singleton()->viewport_queue_screen_capture(vp);
|
||||
Main::iteration();
|
||||
Image img = VS::get_singleton()->viewport_get_screen_capture(vp);
|
||||
ERR_CONTINUE(img.empty());
|
||||
Main::iteration();
|
||||
Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture);
|
||||
ERR_CONTINUE(!img.is_valid() || img->empty());
|
||||
Ref<ImageTexture> it(memnew(ImageTexture));
|
||||
it->create_from_image(img);
|
||||
p_library->set_item_preview(id, it);
|
||||
@ -208,20 +232,19 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
VS::get_singleton()->free(inst);
|
||||
}
|
||||
|
||||
VS::get_singleton()->free(lightinst);
|
||||
VS::get_singleton()->free(mesh_instance);
|
||||
VS::get_singleton()->free(viewport);
|
||||
VS::get_singleton()->free(light);
|
||||
VS::get_singleton()->free(vp);
|
||||
VS::get_singleton()->free(cam);
|
||||
VS::get_singleton()->free(scen);
|
||||
VS::get_singleton()->free(light_instance);
|
||||
VS::get_singleton()->free(light2);
|
||||
VS::get_singleton()->free(light_instance2);
|
||||
VS::get_singleton()->free(camera);
|
||||
VS::get_singleton()->free(scenario);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MeshLibraryEditor::_import_scene_cbk(const String &p_str) {
|
||||
|
||||
|
||||
print_line("Impot Callback!");
|
||||
|
||||
Ref<PackedScene> ps = ResourceLoader::load(p_str, "PackedScene");
|
||||
@ -233,7 +256,6 @@ void MeshLibraryEditor::_import_scene_cbk(const String& p_str) {
|
||||
memdelete(scene);
|
||||
theme->set_meta("_editor_source_scene", p_str);
|
||||
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), false);
|
||||
|
||||
}
|
||||
|
||||
Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge) {
|
||||
@ -242,7 +264,6 @@ Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void MeshLibraryEditor::_menu_cbk(int p_option) {
|
||||
|
||||
option = p_option;
|
||||
@ -274,7 +295,6 @@ void MeshLibraryEditor::_menu_cbk(int p_option) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MeshLibraryEditor::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_menu_cbk", &MeshLibraryEditor::_menu_cbk);
|
||||
@ -317,7 +337,6 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) {
|
||||
cd = memnew(ConfirmationDialog);
|
||||
add_child(cd);
|
||||
cd->get_ok()->connect("pressed", this, "_menu_confirm");
|
||||
|
||||
}
|
||||
|
||||
void MeshLibraryEditorPlugin::edit(Object *p_node) {
|
||||
@ -331,7 +350,7 @@ void MeshLibraryEditorPlugin::edit(Object *p_node) {
|
||||
|
||||
bool MeshLibraryEditorPlugin::handles(Object *p_node) const {
|
||||
|
||||
return p_node->is_type("MeshLibrary");
|
||||
return p_node->is_class("MeshLibrary");
|
||||
}
|
||||
|
||||
void MeshLibraryEditorPlugin::make_visible(bool p_visible) {
|
||||
@ -353,6 +372,4 @@ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) {
|
||||
theme_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN);
|
||||
theme_editor->set_end(Point2(0, 22));
|
||||
theme_editor->hide();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "editor/editor_node.h"
|
||||
#include "scene/resources/mesh_library.h"
|
||||
|
||||
#if 0
|
||||
class MeshLibraryEditor : public Control {
|
||||
|
||||
GDCLASS(MeshLibraryEditor, Control);
|
||||
@ -63,16 +62,14 @@ class MeshLibraryEditor : public Control {
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void edit(const Ref<MeshLibrary> &p_theme);
|
||||
static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true);
|
||||
|
||||
MeshLibraryEditor(EditorNode *p_editor);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MeshLibraryEditorPlugin : public EditorPlugin {
|
||||
|
||||
GDCLASS(MeshLibraryEditorPlugin, EditorPlugin);
|
||||
@ -81,7 +78,6 @@ class MeshLibraryEditorPlugin : public EditorPlugin {
|
||||
EditorNode *editor;
|
||||
|
||||
public:
|
||||
|
||||
virtual String get_name() const { return "MeshLibrary"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
virtual void edit(Object *p_node);
|
||||
@ -89,8 +85,6 @@ public:
|
||||
virtual void make_visible(bool p_visible);
|
||||
|
||||
MeshLibraryEditorPlugin(EditorNode *p_node);
|
||||
|
||||
};
|
||||
|
||||
#endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user