diff options
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/config.py | 3 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 535 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 22 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 92 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 9 |
5 files changed, 82 insertions, 579 deletions
diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py index 1ab13c4aeb..5698a37295 100644 --- a/modules/gridmap/config.py +++ b/modules/gridmap/config.py @@ -1,8 +1,7 @@ def can_build(platform): - # FIXME: Disabled temporary for gles3 implementation - return False + return True def configure(env): diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 1e6bd11154..d4fb174bfe 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -31,7 +31,7 @@ #include "scene/resources/surface_tool.h" #include "message_queue.h" #include "scene/3d/light.h" -#include "scene/3d/baked_light_instance.h" + #include "io/marshalls.h" #include "scene/scene_string_names.h" #include "os/os.h" @@ -41,25 +41,21 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { String name=p_name; - if (name=="theme/theme") { + if (name=="theme") { set_theme(p_value); - } else if (name=="cell/size") { + } else if (name=="cell_size") { set_cell_size(p_value); - } else if (name=="cell/octant_size") { + } else if (name=="cell_octant_size") { set_octant_size(p_value); - } else if (name=="cell/center_x") { + } else if (name=="cell_center_x") { set_center_x(p_value); - } else if (name=="cell/center_y") { + } else if (name=="cell_center_y") { set_center_y(p_value); - } else if (name=="cell/center_z") { + } else if (name=="cell_center_z") { set_center_z(p_value); - } else if (name=="cell/scale") { + } else if (name=="cell_scale") { set_cell_scale(p_value); - } else if (name=="lighting/bake") { - set_use_baked_light(p_value); - } else if (name=="theme/bake") { - set_bake(p_value); /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); @@ -81,9 +77,6 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { Dictionary d = p_value; - Dictionary baked; - if (d.has("baked")) - baked=d["baked"]; if (d.has("cells")) { PoolVector<int> cells = d["cells"]; @@ -101,33 +94,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { } } - baked_lock=baked.size()!=0; _recreate_octant_data(); - baked_lock=false; - if (!baked.empty()) { - List<Variant> kl; - baked.get_key_list(&kl); - for (List<Variant>::Element *E=kl.front();E;E=E->next()) { - - Plane ikv = E->get(); - Ref<Mesh> b=baked[ikv]; - ERR_CONTINUE(!b.is_valid()); - OctantKey ok; - ok.x=ikv.normal.x; - ok.y=ikv.normal.y; - ok.z=ikv.normal.z; - ok.area=ikv.d; - - ERR_CONTINUE(!octant_map.has(ok)); - - Octant &g = *octant_map[ok]; - - g.baked=b; - g.bake_instance=VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); - VS::get_singleton()->instance_geometry_set_baked_light(g.bake_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - } - } } else if (name.begins_with("areas/")) { @@ -161,24 +128,20 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; - if (name=="theme/theme") { + if (name=="theme") { r_ret= get_theme(); - } else if (name=="cell/size") { + } else if (name=="cell_size") { r_ret= get_cell_size(); - } else if (name=="cell/octant_size") { + } else if (name=="cell_octant_size") { r_ret= get_octant_size(); - } else if (name=="cell/center_x") { + } else if (name=="cell_center_x") { r_ret= get_center_x(); - } else if (name=="cell/center_y") { + } else if (name=="cell_center_y") { r_ret= get_center_y(); - } else if (name=="cell/center_z") { + } else if (name=="cell_center_z") { r_ret= get_center_z(); - } else if (name=="cell/scale") { + } else if (name=="cell_scale") { r_ret= cell_scale; - } else if (name=="lighting/bake") { - r_ret=is_using_baked_light(); - } else if (name=="theme/bake") { - r_ret= bake; } else if (name=="data") { Dictionary d; @@ -197,23 +160,8 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { d["cells"]=cells; - Dictionary baked; - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - Octant &g=*E->get(); - - if (g.baked.is_valid()) { - - baked[Plane(E->key().x,E->key().y,E->key().z,E->key().area)]=g.baked; - } - } - - if (baked.size()) { - d["baked"]=baked; - } - r_ret= d; } else if (name.begins_with("areas/")) { int which = name.get_slicec('/',1).to_int(); @@ -237,15 +185,14 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { void GridMap::_get_property_list( List<PropertyInfo> *p_list) const { - p_list->push_back( PropertyInfo( Variant::OBJECT, "theme/theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); - p_list->push_back( PropertyInfo( Variant::BOOL, "theme/bake")); - p_list->push_back( PropertyInfo( Variant::BOOL, "lighting/bake")); - p_list->push_back( PropertyInfo( Variant::REAL, "cell/size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); - p_list->push_back( PropertyInfo( Variant::INT, "cell/octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_x") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_y") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_z") ); - p_list->push_back( PropertyInfo( Variant::REAL, "cell/scale") ); + p_list->push_back( PropertyInfo( Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); + p_list->push_back( PropertyInfo( Variant::NIL, "Cell", PROPERTY_HINT_NONE,"cell_",PROPERTY_USAGE_GROUP)); + p_list->push_back( PropertyInfo( Variant::REAL, "cell_size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); + p_list->push_back( PropertyInfo( Variant::INT, "cell_octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_x") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_y") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_z") ); + p_list->push_back( PropertyInfo( Variant::REAL, "cell_scale") ); p_list->push_back( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); @@ -380,17 +327,6 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ g.items.erase(prev_item); } - - if (g.items.empty() || !baked_lock) { - //unbake just in case - if (g.baked.is_valid()) { - VS::get_singleton()->free(g.bake_instance); - g.bake_instance=RID(); - g.baked=Ref<Mesh>(); - } - - - } if (g.items.empty()) { PhysicsServer::get_singleton()->free(g.static_body); @@ -454,24 +390,12 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ ii.navmesh=theme->get_item_navmesh(p_item); } ii.multimesh = Ref<MultiMesh>( memnew( MultiMesh ) ); + ii.multimesh->set_color_format(MultiMesh::COLOR_NONE); + ii.multimesh->set_transform_format(MultiMesh::TRANSFORM_3D); ii.multimesh->set_mesh(ii.mesh); ii.multimesh_instance = VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(ii.multimesh_instance,ii.multimesh->get_rid()); - VS::get_singleton()->instance_geometry_set_baked_light(ii.multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - - if (!baked_lock) { - //unbake just in case - if (g.bake_instance.is_valid()) - VS::get_singleton()->free(g.bake_instance); - g.baked=Ref<Mesh>(); - if (is_inside_world()) { - VS::get_singleton()->instance_set_scenario(ii.multimesh_instance,get_world()->get_scenario()); - if (ok.area) { - VS::get_singleton()->instance_set_room( ii.multimesh_instance,area_map[ok.area]->instance); - } - } - } g.items[p_item]=ii; } @@ -585,27 +509,14 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { VS::get_singleton()->instance_set_room(g.collision_debug_instance,area_map[p_key.area]->instance); } } - if (g.baked.is_valid()) { + for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - Transform xf = get_global_transform(); - xf.translate(_octant_get_offset(p_key)); + VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //print_line("INSTANCEPOS: "+get_global_transform()); - VS::get_singleton()->instance_set_transform(g.bake_instance,xf); - VS::get_singleton()->instance_set_scenario(g.bake_instance,get_world()->get_scenario()); if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(g.bake_instance,area_map[p_key.area]->instance); - - } - } else { - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - - VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario()); - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - //print_line("INSTANCEPOS: "+get_global_transform()); - - if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance); - } + VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance); } } } @@ -621,17 +532,10 @@ void GridMap::_octant_transform(const OctantKey &p_key) { VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform()); } - if (g.baked.is_valid()) { - - Transform xf = get_global_transform(); - xf.origin+=_octant_get_offset(p_key); - VS::get_singleton()->instance_set_transform(g.bake_instance,xf); - } else { - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { + for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - //print_line("UPDATEPOS: "+get_global_transform()); - } + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //print_line("UPDATEPOS: "+get_global_transform()); } } @@ -711,7 +615,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { ii.multimesh->set_instance_transform(idx,xform); //ii.multimesh->set_instance_transform(idx,Transform() ); - ii.multimesh->set_instance_color(idx,Color(1,1,1,1)); + //ii.multimesh->set_instance_color(idx,Color(1,1,1,1)); //print_line("MMINST: "+xform); @@ -748,7 +652,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { idx++; } - ii.multimesh->set_aabb(aabb); + //ii.multimesh->set_aabb(aabb); } @@ -760,7 +664,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { arr.resize(VS::ARRAY_MAX); arr[VS::ARRAY_VERTEX]=col_debug; - VS::get_singleton()->mesh_add_surface(g.collision_debug,VS::PRIMITIVE_LINES,arr); + VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug,VS::PRIMITIVE_LINES,arr); SceneTree *st=SceneTree::get_singleton(); if (st) { VS::get_singleton()->mesh_surface_set_material( g.collision_debug, 0,st->get_debug_collision_material()->get_rid() ); @@ -780,13 +684,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { PhysicsServer::get_singleton()->body_set_space(g.static_body,RID()); - if (g.baked.is_valid()) { - - VS::get_singleton()->instance_set_room(g.bake_instance,RID()); - VS::get_singleton()->instance_set_scenario(g.bake_instance,RID()); - - } - if (g.collision_debug_instance.is_valid()) { VS::get_singleton()->instance_set_room(g.collision_debug_instance,RID()); @@ -802,194 +699,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { } -void GridMap::_octant_clear_baked(const OctantKey &p_key) { - - - ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - - if (!g.baked.is_valid()) - return; - - VS::get_singleton()->free(g.bake_instance); - g.bake_instance=RID(); - g.baked=Ref<Mesh>(); - - if (is_inside_tree()) - _octant_enter_world(p_key); - g.dirty=true; - _queue_dirty_map(); -} - -void GridMap::_octant_bake(const OctantKey &p_key, const Ref<TriangleMesh>& p_tmesh,const Vector<BakeLight> &p_lights,List<Vector3> *p_prebake) { - - - ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - - Ref<TriangleMesh> tm=p_tmesh; - if (!p_prebake && is_inside_world()) - _octant_exit_world(p_key); - - Map< Ref<Material>, Ref<SurfaceTool> > surfaces; - Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); - Vector3 octant_ofs=_octant_get_offset(p_key); - - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - - Octant::ItemInstances &ii=E->get(); - - if (ii.mesh.is_null()) - continue; - - for(Set<IndexKey>::Element *F=ii.cells.front();F;F=F->next()) { - - IndexKey ik=F->get(); - Map<IndexKey,Cell>::Element *C=cell_map.find(ik); - ERR_CONTINUE(!C); - Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); - - Transform xform; - xform.basis.set_orthogonal_index(C->get().rot); - xform.set_origin( cellpos*cell_size+ofs); - if (!p_prebake) - xform.origin-=octant_ofs; - - - for(int i=0;i<ii.mesh->get_surface_count();i++) { - - if (p_prebake) { - - if (ii.mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES) - continue; - Array a = ii.mesh->surface_get_arrays(i); - PoolVector<Vector3> av=a[VS::ARRAY_VERTEX]; - int avs = av.size(); - PoolVector<Vector3>::Read vr = av.read(); - - PoolVector<int> ai=a[VS::ARRAY_INDEX]; - int ais=ai.size(); - if (ais) { - - PoolVector<int>::Read ir=ai.read(); - for(int j=0;j<ais;j++) { - - p_prebake->push_back(xform.xform(vr[ir[j]])); - //print_line("V SET: "+xform.xform(vr[ir[j]])); - } - - } else { - - for(int j=0;j<avs;j++) { - - p_prebake->push_back(xform.xform(vr[j])); - } - } - - } else { - - Ref<Material> m = ii.mesh->surface_get_material(i); - - Map< Ref<Material>, Ref<SurfaceTool> >::Element *S=surfaces.find(m); - - if (!S) { - - S=surfaces.insert(m,Ref<SurfaceTool>( memnew( SurfaceTool ))); - } - - Ref<SurfaceTool> st = S->get(); - List<SurfaceTool::Vertex>::Element *V=st->get_vertex_array().back(); - st->append_from(ii.mesh,i,xform); - st->set_material(m); - - - if (tm.is_valid()) { - - if (V) - V=V->next(); - else - V=st->get_vertex_array().front(); - int lc = p_lights.size(); - const BakeLight* bl = p_lights.ptr(); - float ofs = cell_size*0.02; - - - for(;V;V=V->next()) { - - SurfaceTool::Vertex &v=V->get(); - - Vector3 vertex = v.vertex + octant_ofs; - //print_line("V GET: "+vertex); - Vector3 normal = tm->get_area_normal( Rect3( Vector3(-ofs,-ofs,-ofs)+vertex,Vector3(ofs,ofs,ofs)*2.0)); - if (normal==Vector3()) { - print_line("couldn't find for vertex: "+vertex); - } - ERR_CONTINUE( normal== Vector3()); - - float max_l=1.0; - float max_dist=1.0; - - if (lc) { - - for(int j=0;j<lc;j++) { - const BakeLight &l=bl[j]; - switch(l.type) { - case VS::LIGHT_DIRECTIONAL: { - - Vector3 ray_from=vertex + normal *ofs; - Vector3 ray_to=l.dir*5000; - Vector3 n; - Vector3 p; - if (tm->intersect_segment(ray_from,ray_to,p,n)) { - - float dist = 1.0-l.param[VS::LIGHT_PARAM_SHADOW_DARKENING]; - if (dist<=max_dist) { - max_dist=dist; - max_l=1.0-dist; - } - } - } break; - } - - } - } - - v.color=Color(max_l,max_l,max_l,1.0); - - } - - st->add_to_format(VS::ARRAY_FORMAT_COLOR); - if (m.is_valid()) { - Ref<FixedSpatialMaterial> fm = m; - if (fm.is_valid()) - fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY,true); - } - } - } - } - } - } - - if (p_prebake) - return; - - g.baked = Ref<Mesh>( memnew( Mesh )); - - for(Map< Ref<Material>, Ref<SurfaceTool> >::Element *E=surfaces.front();E;E=E->next()) { - - Ref<SurfaceTool> st = E->get(); - st->commit(g.baked); - } - - g.bake_instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); - - if (is_inside_world()) - _octant_enter_world(p_key); - - g.dirty=true; - _queue_dirty_map(); -} void GridMap::_notification(int p_what) { @@ -1011,10 +720,6 @@ void GridMap::_notification(int p_what) { last_transform=get_global_transform(); - if (use_baked_light) { - - _find_baked_light(); - } } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -1036,15 +741,6 @@ void GridMap::_notification(int p_what) { _octant_exit_world(E->key()); } - if (use_baked_light) { - - if (baked_light_instance) { - baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - baked_light_instance=NULL; - } - _baked_light_changed(); - - } //_queue_dirty_map(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_update_dirty_map_callback(); @@ -1122,9 +818,6 @@ void GridMap::_clear_internal(bool p_keep_areas) { VS::get_singleton()->free(F->get().multimesh_instance); } - //unbake just in case - if (E->get()->bake_instance.is_valid()) - VS::get_singleton()->free(E->get()->bake_instance); if (E->get()->collision_debug.is_valid()) VS::get_singleton()->free(E->get()->collision_debug); @@ -1188,9 +881,6 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_theme","theme:MeshLibrary"),&GridMap::set_theme); ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"),&GridMap::get_theme); - ClassDB::bind_method(D_METHOD("set_bake","enable"),&GridMap::set_bake); - ClassDB::bind_method(D_METHOD("is_baking_enabled"),&GridMap::is_baking_enabled); - ClassDB::bind_method(D_METHOD("set_cell_size","size"),&GridMap::set_cell_size); ClassDB::bind_method(D_METHOD("get_cell_size"),&GridMap::get_cell_size); @@ -1226,20 +916,11 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("area_get_portal_disable_color","area"),&GridMap::area_get_portal_disable_color); ClassDB::bind_method(D_METHOD("erase_area","area"),&GridMap::erase_area); ClassDB::bind_method(D_METHOD("get_unused_area_id","area"),&GridMap::get_unused_area_id); - ClassDB::bind_method(D_METHOD("bake_geometry"),&GridMap::bake_geometry); - - ClassDB::bind_method(D_METHOD("_baked_light_changed"),&GridMap::_baked_light_changed); - ClassDB::bind_method(D_METHOD("set_use_baked_light","use"),&GridMap::set_use_baked_light); - ClassDB::bind_method(D_METHOD("is_using_baked_light","use"),&GridMap::is_using_baked_light); - - ClassDB::bind_method(D_METHOD("_get_baked_light_meshes"),&GridMap::_get_baked_light_meshes); - - - - ClassDB::set_method_flags("GridMap","bake_geometry",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ClassDB::bind_method(D_METHOD("clear"),&GridMap::clear); + ClassDB::bind_method(D_METHOD("get_meshes"),&GridMap::get_meshes); + BIND_CONSTANT( INVALID_CELL_ITEM ); } @@ -1622,23 +1303,6 @@ int GridMap::get_unused_area_id() const { return area_map.back()->key()+1; } - -void GridMap::set_bake(bool p_bake) { - - bake=p_bake; - if (bake==false) { - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - _octant_clear_baked(E->key()); - } - } -} - -bool GridMap::is_baking_enabled() const { - - return bake; -} - void GridMap::set_cell_scale(float p_scale) { cell_scale=p_scale; @@ -1652,100 +1316,8 @@ float GridMap::get_cell_scale() const{ -void GridMap::bake_geometry() { - - //used to compute vertex occlusion - Ref<TriangleMesh> tmesh; - Vector<BakeLight> lights; - - if (true) { - - List<Vector3> vertices; - - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - _octant_bake(E->key(),tmesh,lights,&vertices); - - } - - PoolVector<Vector3> vv; - vv.fill_with(vertices); - //print_line("TOTAL VERTICES: "+itos(vv.size())); - tmesh = Ref<TriangleMesh>( memnew( TriangleMesh )); - tmesh->create(vv); - - - for(int i=0;i<get_child_count();i++) { - - if (get_child(i)->cast_to<Light>()) { - Light *l = get_child(i)->cast_to<Light>(); - BakeLight bl; - for(int i=0;i<Light::PARAM_MAX;i++) { - bl.param[i]=l->get_parameter(Light::Parameter(i)); - } - Transform t=l->get_global_transform(); - bl.pos=t.origin; - bl.dir=t.basis.get_axis(2); - bl.type=l->get_light_type(); - lights.push_back(bl); - - } - } - } - - int idx=0; - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - if (E->get()->baked.is_valid()) - _octant_clear_baked(E->key()); - - _octant_bake(E->key(),tmesh,lights); - print_line("baking "+itos(idx)+"/"+itos(octant_map.size())); - idx++; - } - -} - -void GridMap::_baked_light_changed() { - - /* - if (!baked_light_instance) - VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID()); - else - VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance()); - */ - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - for(Map<int,Octant::ItemInstances>::Element *F=E->get()->items.front();F;F=F->next()) { - - VS::get_singleton()->instance_geometry_set_baked_light(F->get().multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - } - - } - -} -void GridMap::_find_baked_light() { - - Node *n=get_parent(); - while(n) { - - BakedLightInstance *bl=n->cast_to<BakedLightInstance>(); - if (bl) { - - baked_light_instance=bl; - baked_light_instance->connect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - _baked_light_changed(); - - return; - } - - n=n->get_parent(); - } - - _baked_light_changed(); -} - - -Array GridMap::_get_baked_light_meshes() { +Array GridMap::get_meshes() { if (theme.is_null()) return Array(); @@ -1783,31 +1355,6 @@ Array GridMap::_get_baked_light_meshes() { return meshes; } -void GridMap::set_use_baked_light(bool p_use) { - - if (use_baked_light==p_use) - return; - - use_baked_light=p_use; - - if (is_inside_world()) { - if (!p_use) { - if (baked_light_instance) { - baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - baked_light_instance=NULL; - } - _baked_light_changed(); - } else { - _find_baked_light(); - } - } - -} - -bool GridMap::is_using_baked_light() const{ - - return use_baked_light; -} @@ -1825,12 +1372,8 @@ GridMap::GridMap() { clip_floor=0; clip_axis=Vector3::AXIS_Z; clip_above=true; - baked_lock=false; - bake=false; cell_scale=1.0; - baked_light_instance=NULL; - use_baked_light=false; navigation = NULL; set_notify_transform(true); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 04d140cdc6..5d4133383b 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -103,8 +103,6 @@ class GridMap : public Spatial { Ref<NavigationMesh> navmesh; }; - Ref<Mesh> baked; - RID bake_instance; RID collision_debug; RID collision_debug_instance; @@ -140,14 +138,12 @@ class GridMap : public Spatial { float cell_size; int octant_size; bool center_x,center_y,center_z; - bool bake; float cell_scale; Navigation *navigation; bool clip; bool clip_above; int clip_floor; - bool baked_lock; Vector3::Axis clip_axis; @@ -205,9 +201,7 @@ class GridMap : public Spatial { void _octant_exit_world(const OctantKey &p_key); void _octant_update(const OctantKey &p_key); void _octant_transform(const OctantKey &p_key); - void _octant_clear_baked(const OctantKey &p_key); void _octant_clear_navmesh(const GridMap::OctantKey&); - void _octant_bake(const OctantKey &p_key,const Ref<TriangleMesh>& p_tmesh=RES(),const Vector<BakeLight> &p_lights=Vector<BakeLight>(),List<Vector3> *r_prebake=NULL); bool awaiting_update; void _queue_dirty_map(); @@ -221,14 +215,6 @@ class GridMap : public Spatial { void _clear_internal(bool p_keep_areas=false); - BakedLightInstance *baked_light_instance; - bool use_baked_light; - void _find_baked_light(); - void _baked_light_changed(); - - - Array _get_baked_light_meshes(); - protected: bool _set(const StringName& p_name, const Variant& p_value); @@ -285,13 +271,11 @@ public: void set_cell_scale(float p_scale); float get_cell_scale() const; - void set_bake(bool p_bake); - bool is_baking_enabled() const; - void bake_geometry(); - void set_use_baked_light(bool p_use); - bool is_using_baked_light() const; + Array get_meshes(); + + void clear(); GridMap(); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index d4c7cb7ca9..2630360058 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -249,7 +249,7 @@ void GridMapEditor::_update_cursor_transform() { if (cursor_instance.is_valid()) { VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform); - VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance,VS::INSTANCE_FLAG_VISIBLE,cursor_visible); + VisualServer::get_singleton()->instance_set_visible(cursor_instance,cursor_visible); } } @@ -852,11 +852,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) { if (!node) { set_process(false); for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); + VisualServer::get_singleton()->instance_set_visible(grid_instance[i],false); } - VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance, VS::INSTANCE_FLAG_VISIBLE,false); + VisualServer::get_singleton()->instance_set_visible(cursor_instance,false); _clear_areas(); @@ -884,13 +884,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) { { //update grids - indicator_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_UNSHADED, true ); - VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_ONTOP, false ); - - VisualServer::get_singleton()->fixed_material_set_param(indicator_mat,VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.8,0.5,0.1)); - VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY, true ); + indicator_mat.instance(); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); + indicator_mat->set_albedo(Color(0.8,0.5,0.1)); Vector<Vector3> grid_points[3]; @@ -937,8 +935,8 @@ void GridMapEditor::edit(GridMap *p_gridmap) { d.resize(VS::ARRAY_MAX); d[VS::ARRAY_VERTEX]=grid_points[i]; d[VS::ARRAY_COLOR]=grid_colors[i]; - VisualServer::get_singleton()->mesh_add_surface(grid[i],VisualServer::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat->get_rid()); } @@ -976,7 +974,7 @@ void GridMapEditor::update_grid() { for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,i==edit_axis); + VisualServer::get_singleton()->instance_set_visible(grid_instance[i],i==edit_axis); } @@ -1103,7 +1101,7 @@ void GridMapEditor::_update_areas_display() { if (!node) { return; } - +#if 0 _clear_areas(); List<int> areas; node->get_area_list(&areas); @@ -1118,6 +1116,8 @@ void GridMapEditor::_update_areas_display() { color=Color(1,1,1,0.2); else color.set_hsv(Math::fmod(area*0.37,1),Math::fmod(area*0.75,1),1.0,0.2); + + RID material = VisualServer::get_singleton()->fixed_material_create(); VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_DIFFUSE,color ); VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_EMISSION,0.5 ); @@ -1149,7 +1149,7 @@ void GridMapEditor::_update_areas_display() { this->areas.push_back(ad); } - +#endif } void GridMapEditor::_edit_mode_changed(int p_what) { @@ -1295,7 +1295,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { hb->add_child(mode_list); mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); - EDITOR_DEF("editors/grid_map/preview_size",64) + EDITOR_DEF("editors/grid_map/preview_size",64); display_mode = DISPLAY_THUMBNAIL; selected_area=-1; @@ -1387,52 +1387,36 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { Array d; d.resize(VS::ARRAY_MAX); - inner_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(inner_mat,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.7,0.7,1.0,0.3)); - VisualServer::get_singleton()->material_set_flag(inner_mat,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(inner_mat,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( inner_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); + inner_mat.instance(); + inner_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + inner_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface(selection_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_TRIANGLES,d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat->get_rid()); - outer_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(outer_mat,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.7,0.7,1.0,0.8)); - VisualServer::get_singleton()->material_set_line_width(outer_mat,3.0); - VisualServer::get_singleton()->material_set_flag(outer_mat,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(outer_mat,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( outer_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); + outer_mat.instance(); + outer_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + outer_mat->set_line_width(3.0); + outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface(selection_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat); - - - inner_mat_dup = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(inner_mat_dup,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(1.0,0.7,0.7,0.3)); - VisualServer::get_singleton()->material_set_flag(inner_mat_dup,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(inner_mat_dup,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( inner_mat_dup, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat->get_rid()); d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat_dup); - - outer_mat_dup = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(outer_mat_dup,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(1.0,0.7,0.7,0.8)); - VisualServer::get_singleton()->material_set_line_width(outer_mat_dup,3.0); - VisualServer::get_singleton()->material_set_flag(outer_mat_dup,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(outer_mat_dup,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( outer_mat_dup, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat->get_rid()); d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface(duplicate_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat_dup); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat->get_rid()); } @@ -1452,14 +1436,10 @@ GridMapEditor::~GridMapEditor() { VisualServer::get_singleton()->free(grid[i]); if (grid_instance[i].is_valid()) VisualServer::get_singleton()->free(grid_instance[i]); - if (cursor_instance) + if (cursor_instance.is_valid()) VisualServer::get_singleton()->free(cursor_instance); } - VisualServer::get_singleton()->free(inner_mat); - VisualServer::get_singleton()->free(outer_mat); - VisualServer::get_singleton()->free(inner_mat_dup); - VisualServer::get_singleton()->free(outer_mat_dup); VisualServer::get_singleton()->free(selection_mesh); if (selection_instance.is_valid()) diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 2c0ff99dc6..66ec5dc4bc 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -112,12 +112,9 @@ class GridMapEditor : public VBoxContainer { RID duplicate_mesh; RID duplicate_instance; - RID indicator_mat; - - RID inner_mat; - RID outer_mat; - RID inner_mat_dup; - RID outer_mat_dup; + Ref<FixedSpatialMaterial> indicator_mat; + Ref<FixedSpatialMaterial> inner_mat; + Ref<FixedSpatialMaterial> outer_mat; bool updating; |