Skip to content

Commit

Permalink
Changed import workflow
Browse files Browse the repository at this point in the history
-Rearrange favorites in fs dock with drag and drop
-Removed import -> sub-scene, moved to scenetree contextual menu
-Removed import -> re-import , moved and integrated to FS dock
-Added ability in FS dock to re-import more than one resource
simultaneously
-Added ability to drag from native filesystem explorer to Godot, only
works on Windows though
-Removed scene reimport merge options, never worked well. Eventually
merging materials should be re-added
-Added ability to set custom root node type when importing scenes
-Re-Import is now automatic, can be configured back to manual in editor
settings
-Added resource previews in property list for many resource types
  • Loading branch information
reduz committed May 27, 2016
1 parent eb7227a commit 8be2fab
Show file tree
Hide file tree
Showing 54 changed files with 1,258 additions and 636 deletions.
1 change: 1 addition & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p
break;
}


return ret;

}
Expand Down
7 changes: 7 additions & 0 deletions core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,13 +1756,19 @@ bool Object::is_queued_for_deletion() const {
void Object::set_edited(bool p_edited) {

_edited=p_edited;
_edited_version++;
}

bool Object::is_edited() const {

return _edited;

}

uint32_t Object::get_edited_version() const {

return _edited_version;
}
#endif

Object::Object() {
Expand All @@ -1778,6 +1784,7 @@ Object::Object() {
#ifdef TOOLS_ENABLED

_edited=false;
_edited_version=0;
#endif

#ifdef DEBUG_ENABLED
Expand Down
2 changes: 2 additions & 0 deletions core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ friend void postinitialize_handler(Object*);
bool _can_translate;
#ifdef TOOLS_ENABLED
bool _edited;
uint32_t _edited_version;
#endif
ScriptInstance *script_instance;
RefPtr script;
Expand Down Expand Up @@ -589,6 +590,7 @@ friend class ObjectTypeDB;
#ifdef TOOLS_ENABLED
void set_edited(bool p_edited);
bool is_edited() const;
uint32_t get_edited_version() const; //this function is used to check when something changed beyond a point, it's used mainly for generating previews
#endif

void set_script_instance(ScriptInstance *p_instance);
Expand Down
10 changes: 10 additions & 0 deletions core/os/main_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void MainLoop::_bind_methods() {
BIND_VMETHOD( MethodInfo("_initialize") );
BIND_VMETHOD( MethodInfo("_iteration",PropertyInfo(Variant::REAL,"delta")) );
BIND_VMETHOD( MethodInfo("_idle",PropertyInfo(Variant::REAL,"delta")) );
BIND_VMETHOD( MethodInfo("_drop_files",PropertyInfo(Variant::STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) );
BIND_VMETHOD( MethodInfo("_finalize") );

BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER);
Expand Down Expand Up @@ -108,6 +109,15 @@ bool MainLoop::idle(float p_time) {

return false;
}

void MainLoop::drop_files(const Vector<String>& p_files,int p_from_screen) {


if (get_script_instance())
get_script_instance()->call("_drop_files",p_files,p_from_screen);

}

void MainLoop::finish() {

if (get_script_instance()) {
Expand Down
2 changes: 2 additions & 0 deletions core/os/main_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MainLoop : public Object {
virtual bool idle(float p_time);
virtual void finish();

virtual void drop_files(const Vector<String>& p_files,int p_from_screen=0);

void set_init_script(const Ref<Script>& p_init_script);

MainLoop();
Expand Down
27 changes: 27 additions & 0 deletions core/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,31 @@ Ref<ResourceImportMetadata> Resource::get_import_metadata() const {

}

#ifdef TOOLS_ENABLED

uint32_t Resource::hash_edited_version() const {

uint32_t hash = hash_djb2_one_32(get_edited_version());

List<PropertyInfo> plist;
get_property_list(&plist);

for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {

if (E->get().type==Variant::OBJECT && E->get().hint==PROPERTY_HINT_RESOURCE_TYPE) {
RES res = get(E->get().name);
if (res.is_valid()) {
hash = hash_djb2_one_32(res->hash_edited_version(),hash);
}
}
}

return hash;

}

#endif


Resource::Resource() {

Expand All @@ -341,6 +366,8 @@ Resource::Resource() {
}




Resource::~Resource() {

if (path_cache!="")
Expand Down
4 changes: 4 additions & 0 deletions core/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ friend class ResourceCache;
Ref<ResourceImportMetadata> get_import_metadata() const;




#ifdef TOOLS_ENABLED

uint32_t hash_edited_version() const;

virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; }
uint64_t get_last_modified_time() const { return last_modified_time; }

Expand Down
7 changes: 4 additions & 3 deletions drivers/gles2/rasterizer_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4737,10 +4737,10 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
}


void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner) {
void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner,int p_material) {

Material *m=NULL;
RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override : p_geometry->material;
RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override :(p_material>=0?p_instance->materials[p_material]:p_geometry->material);

#ifdef DEBUG_ENABLED
if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) {
Expand Down Expand Up @@ -4988,8 +4988,9 @@ void RasterizerGLES2::add_mesh( const RID& p_mesh, const InstanceData *p_data) {

for (int i=0;i<ssize;i++) {

int mat_idx = p_data->materials[i].is_valid() ? i : -1;
Surface *s = mesh->surfaces[i];
_add_geometry(s,p_data,s,NULL);
_add_geometry(s,p_data,s,NULL,mat_idx);
}

mesh->last_pass=frame;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ class RasterizerGLES2 : public Rasterizer {

Plane camera_plane;

void _add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner);
void _add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner,int p_material=-1);
void _render_list_forward(RenderList *p_render_list,const Transform& p_view_transform,const Transform& p_view_transform_inverse, const CameraMatrix& p_projection,bool p_reverse_cull=false,bool p_fragment_light=false,bool p_alpha_pass=false);

//void _setup_light(LightInstance* p_instance, int p_idx);
Expand Down
28 changes: 28 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,32 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
}

} break;
case WM_DROPFILES: {

HDROP hDropInfo = NULL;
hDropInfo = (HDROP) wParam;
const int buffsize=4096;
wchar_t buf[buffsize];

int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF,NULL,0);

Vector<String> files;

for(int i=0;i<fcount;i++) {

DragQueryFileW(hDropInfo, i, buf, buffsize);
String file=buf;
files.push_back(file);
}

if (files.size() && main_loop) {
main_loop->drop_files(files,0);
}


} break;



default: {

Expand Down Expand Up @@ -1035,6 +1061,8 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_

_ensure_data_dir();

DragAcceptFiles(hWnd,true);


}

Expand Down
87 changes: 74 additions & 13 deletions scene/3d/mesh_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "skeleton.h"
#include "physics_body.h"
#include "body_shape.h"


#include "scene/scene_string_names.h"
#include "core_string_names.h"
bool MeshInstance::_set(const StringName& p_name, const Variant& p_value) {

//this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else.
Expand All @@ -43,13 +43,22 @@ bool MeshInstance::_set(const StringName& p_name, const Variant& p_value) {


Map<StringName,MorphTrack>::Element *E = morph_tracks.find(p_name);
if (!E)
return false;
if (E) {
E->get().value=p_value;
VisualServer::get_singleton()->instance_set_morph_target_weight(get_instance(),E->get().idx,E->get().value);
return true;
}

E->get().value=p_value;
VisualServer::get_singleton()->instance_set_morph_target_weight(get_instance(),E->get().idx,E->get().value);
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/',1).to_int();
if (idx>=materials.size() || idx<0)
return false;

return true;
set_surface_material(idx,p_value);
return true;
}

return false;
}

bool MeshInstance::_get(const StringName& p_name,Variant &r_ret) const {
Expand All @@ -59,12 +68,19 @@ bool MeshInstance::_get(const StringName& p_name,Variant &r_ret) const {
return false;

const Map<StringName,MorphTrack>::Element *E = morph_tracks.find(p_name);
if (!E)
return false;

r_ret = E->get().value;
if (E) {
r_ret = E->get().value;
return true;
}

return true;
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/',1).to_int();
if (idx>=materials.size() || idx<0)
return false;
r_ret=materials[idx];
return true;
}
return false;
}

void MeshInstance::_get_property_list( List<PropertyInfo> *p_list) const {
Expand All @@ -80,13 +96,27 @@ void MeshInstance::_get_property_list( List<PropertyInfo> *p_list) const {
for(List<String>::Element *E=ls.front();E;E=E->next()) {
p_list->push_back( PropertyInfo(Variant::REAL,E->get(),PROPERTY_HINT_RANGE,"0,1,0.01"));
}

if (mesh.is_valid()) {
for(int i=0;i<mesh->get_surface_count();i++) {
p_list->push_back( PropertyInfo(Variant::OBJECT, "material/"+itos(i), PROPERTY_HINT_RESOURCE_TYPE, "Material"));
}
}
}




void MeshInstance::set_mesh(const Ref<Mesh>& p_mesh) {

if (mesh==p_mesh)
return;

if (mesh.is_valid()) {
mesh->disconnect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_mesh_changed);
materials.clear();
}

mesh=p_mesh;

morph_tracks.clear();
Expand All @@ -100,13 +130,17 @@ void MeshInstance::set_mesh(const Ref<Mesh>& p_mesh) {
mt.value=0;
morph_tracks["morph/"+String(mesh->get_morph_target_name(i))]=mt;
}

mesh->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_mesh_changed);
materials.resize(mesh->get_surface_count());

set_base(mesh->get_rid());
} else {

set_base(RID());
}

_change_notify("mesh");
_change_notify();
}
Ref<Mesh> MeshInstance::get_mesh() const {

Expand Down Expand Up @@ -232,6 +266,32 @@ void MeshInstance::_notification(int p_what) {
}


void MeshInstance::set_surface_material(int p_surface,const Ref<Material>& p_material) {

ERR_FAIL_INDEX(p_surface,materials.size());

materials[p_surface]=p_material;

if (materials[p_surface].is_valid())
VS::get_singleton()->instance_set_surface_material(get_instance(),p_surface,materials[p_surface]->get_rid());
else
VS::get_singleton()->instance_set_surface_material(get_instance(),p_surface,RID());

}

Ref<Material> MeshInstance::get_surface_material(int p_surface) const {

ERR_FAIL_INDEX_V(p_surface,materials.size(),Ref<Material>());

return materials[p_surface];
}


void MeshInstance::_mesh_changed() {

materials.resize( mesh->get_surface_count() );
}

void MeshInstance::_bind_methods() {

ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh);
Expand All @@ -243,6 +303,7 @@ void MeshInstance::_bind_methods() {
ObjectTypeDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT);
ObjectTypeDB::bind_method(_MD("create_convex_collision"),&MeshInstance::create_convex_collision);
ObjectTypeDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT);
ObjectTypeDB::bind_method(_MD("_mesh_changed"),&MeshInstance::_mesh_changed);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "mesh/mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh" ), _SCS("set_mesh"), _SCS("get_mesh"));
ADD_PROPERTY( PropertyInfo (Variant::NODE_PATH, "mesh/skeleton"), _SCS("set_skeleton_path"), _SCS("get_skeleton_path"));
}
Expand Down
5 changes: 5 additions & 0 deletions scene/3d/mesh_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class MeshInstance : public GeometryInstance {
};

Map<StringName,MorphTrack> morph_tracks;
Vector<Ref<Material> > materials;

void _mesh_changed();
void _resolve_skeleton_path();

protected:
Expand All @@ -69,6 +71,9 @@ class MeshInstance : public GeometryInstance {
void set_skeleton_path(const NodePath& p_skeleton);
NodePath get_skeleton_path();

void set_surface_material(int p_surface,const Ref<Material>& p_material);
Ref<Material> get_surface_material(int p_surface) const;

Node* create_trimesh_collision_node();
void create_trimesh_collision();

Expand Down
Loading

2 comments on commit 8be2fab

@RandomShaper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overtwrite scene, keep materials was very handy to avoid having to tweak materials not 1:1 exact to Blender/COLLADA.

I guess I can do the same (and better) with a postprocess script, but keeping materials intact on import was a nice way of iterating quickly for prototyping.

@reduz
Copy link
Member Author

@reduz reduz commented on 8be2fab Jun 9, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.