void WorldEnvironment::set_environment(const Ref<Environment>& p_environment) { if (is_inside_world() && environment.is_valid() && get_world()->get_environment()==environment) { get_world()->set_environment(Ref<Environment>()); //clean up } environment=p_environment; if (is_inside_world() && environment.is_valid()) { if (get_world()->get_environment().is_valid()) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } get_world()->set_environment(environment); } }
void GeometryInstance::set_flag(Flags p_flag,bool p_value) { ERR_FAIL_INDEX(p_flag,FLAG_MAX); if (flags[p_flag]==p_value) return; flags[p_flag]=p_value; VS::get_singleton()->instance_geometry_set_flag(get_instance(),(VS::InstanceFlags)p_flag,p_value); if (p_flag==FLAG_VISIBLE) { _update_visibility(); } if (p_flag==FLAG_USE_BAKED_LIGHT) { if (is_inside_world()) { if (!p_value) { 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(); } } } }
void Spatial::set_gizmo(const Ref<SpatialGizmo>& p_gizmo) { #ifdef TOOLS_ENABLED if (data.gizmo_disabled) return; if (data.gizmo.is_valid() && is_inside_world()) data.gizmo->free(); data.gizmo=p_gizmo; if (data.gizmo.is_valid() && is_inside_world()) { data.gizmo->create(); data.gizmo->redraw(); data.gizmo->transform(); } #endif }
void GridMap::_queue_dirty_map() { if (awaiting_update) return; if (is_inside_world()) { MessageQueue::get_singleton()->push_call(this, "_update_dirty_map_callback"); awaiting_update = true; } }
void Spatial::update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) return; if (!data.gizmo.is_valid()) return; if (data.gizmo_dirty) return; data.gizmo_dirty=true; MessageQueue::get_singleton()->push_call(this,"_update_gizmo"); #endif }
void VisibilityNotifier::set_aabb(const AABB& p_aabb){ if (aabb==p_aabb) return; aabb=p_aabb; if (is_inside_world()) { get_world()->_update_notifier(this,get_global_transform().xform(aabb)); } _change_notify("aabb"); update_gizmo(); }
Vector<Plane> Camera::get_frustum() const { ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; if (mode == PROJECTION_PERSPECTIVE) cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); else cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); return cm.get_projection_planes(get_camera_transform()); }
void GridMap::_clear_internal() { for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) _octant_exit_world(E->key()); _octant_clean_up(E->key()); memdelete(E->get()); } octant_map.clear(); cell_map.clear(); }
Vector<Plane> ARVRCamera::get_frustum() const { // get our ARVRServer ARVRServer *arvr_server = ARVRServer::get_singleton(); ERR_FAIL_NULL_V(arvr_server, Vector<Plane>()); Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); ERR_FAIL_COND_V(arvr_interface.is_null(), Vector<Plane>()); ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); return cm.get_projection_planes(get_camera_transform()); };
void Spatial::_update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) return; data.gizmo_dirty = false; if (data.gizmo.is_valid()) { if (is_visible_in_tree()) data.gizmo->redraw(); else data.gizmo->clear(); } #endif }
void Spatial::update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) return; if (!data.gizmo.is_valid()) get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this); if (!data.gizmo.is_valid()) return; if (data.gizmo_dirty) return; data.gizmo_dirty = true; MessageQueue::get_singleton()->push_call(this, "_update_gizmo"); #endif }
void BakedLightInstance::set_baked_light(const Ref<BakedLight>& p_baked_light) { baked_light=p_baked_light; RID base_rid; if (baked_light.is_valid()) base_rid=baked_light->get_rid(); else base_rid=RID(); set_base(base_rid); if (is_inside_world()) { emit_signal(SceneStringNames::get_singleton()->baked_light_changed); // for (List<Node*>::Element *E=baked_geometry.front();E;E=E->next()) { // VS::get_singleton()->instance_geometry_set_baked_light(E->get()->get_instance(),baked_light.is_valid()?get_instance():RID()); // } } }
void GridMap::_clear_internal(bool p_keep_areas) { for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) _octant_exit_world(E->key()); for (Map<int, Octant::ItemInstances>::Element *F = E->get()->items.front(); F; F = F->next()) { VS::get_singleton()->free(F->get().multimesh_instance); } if (E->get()->collision_debug.is_valid()) VS::get_singleton()->free(E->get()->collision_debug); if (E->get()->collision_debug_instance.is_valid()) VS::get_singleton()->free(E->get()->collision_debug_instance); PhysicsServer::get_singleton()->free(E->get()->static_body); memdelete(E->get()); } octant_map.clear(); cell_map.clear(); if (p_keep_areas) return; for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { VS::get_singleton()->free(E->get()->base_portal); VS::get_singleton()->free(E->get()->instance); for (int i = 0; i < E->get()->portals.size(); i++) { VS::get_singleton()->free(E->get()->portals[i].instance); } memdelete(E->get()); } }
Ref<World> Spatial::get_world() const { ERR_FAIL_COND_V(!is_inside_world(),Ref<World>()); return data.viewport->find_world(); }
void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { ERR_FAIL_INDEX(ABS(p_x), 1 << 20); ERR_FAIL_INDEX(ABS(p_y), 1 << 20); ERR_FAIL_INDEX(ABS(p_z), 1 << 20); IndexKey key; key.x = p_x; key.y = p_y; key.z = p_z; OctantKey ok; ok.x = p_x / octant_size; ok.y = p_y / octant_size; ok.z = p_z / octant_size; ok.area = _find_area(key); if (cell_map.has(key)) { int prev_item = cell_map[key].item; OctantKey octantkey = ok; ERR_FAIL_COND(!octant_map.has(octantkey)); Octant &g = *octant_map[octantkey]; ERR_FAIL_COND(!g.items.has(prev_item)); ERR_FAIL_COND(!g.items[prev_item].cells.has(key)); g.items[prev_item].cells.erase(key); if (g.items[prev_item].cells.size() == 0) { VS::get_singleton()->free(g.items[prev_item].multimesh_instance); g.items.erase(prev_item); } if (g.items.empty()) { PhysicsServer::get_singleton()->free(g.static_body); if (g.collision_debug.is_valid()) { PhysicsServer::get_singleton()->free(g.collision_debug); PhysicsServer::get_singleton()->free(g.collision_debug_instance); } memdelete(&g); octant_map.erase(octantkey); } else { g.dirty = true; } cell_map.erase(key); _queue_dirty_map(); } if (p_item < 0) return; OctantKey octantkey = ok; //add later if (!octant_map.has(octantkey)) { Octant *g = memnew(Octant); g->dirty = true; g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC); PhysicsServer::get_singleton()->body_attach_object_instance_ID(g->static_body, get_instance_ID()); if (is_inside_world()) PhysicsServer::get_singleton()->body_set_space(g->static_body, get_world()->get_space()); SceneTree *st = SceneTree::get_singleton(); if (st && st->is_debugging_collisions_hint()) { g->collision_debug = VisualServer::get_singleton()->mesh_create(); g->collision_debug_instance = VisualServer::get_singleton()->instance_create(); VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); if (is_inside_world()) { VisualServer::get_singleton()->instance_set_scenario(g->collision_debug_instance, get_world()->get_scenario()); VisualServer::get_singleton()->instance_set_transform(g->collision_debug_instance, get_global_transform()); } } octant_map[octantkey] = g; } Octant &g = *octant_map[octantkey]; if (!g.items.has(p_item)) { Octant::ItemInstances ii; if (theme.is_valid() && theme->has_item(p_item)) { ii.mesh = theme->get_item_mesh(p_item); ii.shape = theme->get_item_shape(p_item); 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()); g.items[p_item] = ii; } Octant::ItemInstances &ii = g.items[p_item]; ii.cells.insert(key); g.dirty = true; _queue_dirty_map(); cell_map[key] = Cell(); Cell &c = cell_map[key]; c.item = p_item; c.rot = p_rot; }
void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { ERR_FAIL_INDEX(ABS(p_x), 1 << 20); ERR_FAIL_INDEX(ABS(p_y), 1 << 20); ERR_FAIL_INDEX(ABS(p_z), 1 << 20); IndexKey key; key.x = p_x; key.y = p_y; key.z = p_z; OctantKey ok; ok.x = p_x / octant_size; ok.y = p_y / octant_size; ok.z = p_z / octant_size; if (p_item < 0) { //erase if (cell_map.has(key)) { OctantKey octantkey = ok; ERR_FAIL_COND(!octant_map.has(octantkey)); Octant &g = *octant_map[octantkey]; g.cells.erase(key); g.dirty = true; cell_map.erase(key); _queue_octants_dirty(); } return; } OctantKey octantkey = ok; if (!octant_map.has(octantkey)) { //create octant because it does not exist Octant *g = memnew(Octant); g->dirty = true; g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC); PhysicsServer::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id()); SceneTree *st = SceneTree::get_singleton(); if (st && st->is_debugging_collisions_hint()) { g->collision_debug = VisualServer::get_singleton()->mesh_create(); g->collision_debug_instance = VisualServer::get_singleton()->instance_create(); VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); } octant_map[octantkey] = g; if (is_inside_world()) { _octant_enter_world(octantkey); _octant_transform(octantkey); } } Octant &g = *octant_map[octantkey]; g.cells.insert(key); g.dirty = true; _queue_octants_dirty(); Cell c; c.item = p_item; c.rot = p_rot; cell_map[key] = c; }