feat: added photos;feat: photos shown on camera
This commit is contained in:
parent
ee0362f040
commit
33e2bae05b
28 changed files with 262 additions and 299 deletions
|
|
@ -1,8 +1,12 @@
|
|||
#include "clue_finder.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/3d/xr/xr_nodes.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/material.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "you_done_it/clue_db.h"
|
||||
|
||||
ClueFinder *ClueFinder::singleton_instance{ nullptr };
|
||||
String const ClueFinder::sig_found_marker_changed{ "found_marker_changed" };
|
||||
|
|
@ -10,6 +14,8 @@ String const ClueFinder::sig_found_marker_changed{ "found_marker_changed" };
|
|||
void ClueFinder::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("take_photo"), &ClueFinder::take_photo);
|
||||
ADD_SIGNAL(MethodInfo(sig_found_marker_changed, PropertyInfo(Variant::BOOL, "has_marker")));
|
||||
BIND_HPROPERTY(Variant::OBJECT, empty_texture, PROPERTY_HINT_RESOURCE_TYPE, "Texture");
|
||||
BIND_HPROPERTY(Variant::OBJECT, photo_material, PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D");
|
||||
}
|
||||
|
||||
void ClueFinder::enter_tree() {
|
||||
|
|
@ -65,9 +71,10 @@ ClueMarker *ClueFinder::find_current_clue() {
|
|||
float best_score{ Math::INF };
|
||||
ClueMarker *best_marker{ nullptr };
|
||||
for (ClueMarker *marker : this->clue_markers) {
|
||||
if (marker->score_in_view() < best_score) {
|
||||
print_line("found marker ", marker->get_path());
|
||||
float score{ marker->score_in_view() };
|
||||
if (!Math::is_nan(score) && score < best_score) {
|
||||
best_marker = marker;
|
||||
best_score = score;
|
||||
}
|
||||
}
|
||||
return best_marker;
|
||||
|
|
@ -83,6 +90,13 @@ void ClueFinder::remove_clue_marker(ClueMarker *marker) {
|
|||
|
||||
void ClueFinder::take_photo() {
|
||||
this->found_marker = find_current_clue();
|
||||
if (this->found_marker) {
|
||||
Ref<ClueData> clue{ ClueDB::get_singleton()->get_clue(this->found_marker->get_clue_id()) };
|
||||
print_line("Found clue: ", this->found_marker->get_clue_id(), " ", clue, " ", clue->get_image());
|
||||
photo_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, clue->get_image());
|
||||
} else {
|
||||
photo_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, this->empty_texture);
|
||||
}
|
||||
emit_signal(sig_found_marker_changed, bool(this->found_marker));
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +105,7 @@ void ClueFinder::send_photo() {
|
|||
this->found_marker->reveal();
|
||||
this->found_marker = nullptr;
|
||||
emit_signal(sig_found_marker_changed, false);
|
||||
photo_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, this->empty_texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,5 +113,22 @@ void ClueFinder::delete_photo() {
|
|||
if (this->found_marker) {
|
||||
this->found_marker = nullptr;
|
||||
emit_signal(sig_found_marker_changed, false);
|
||||
photo_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, this->empty_texture);
|
||||
}
|
||||
}
|
||||
|
||||
void ClueFinder::set_empty_texture(Ref<Texture> texture) {
|
||||
this->empty_texture = texture;
|
||||
}
|
||||
|
||||
Ref<Texture> ClueFinder::get_empty_texture() const {
|
||||
return this->empty_texture;
|
||||
}
|
||||
|
||||
void ClueFinder::set_photo_material(Ref<StandardMaterial3D> material) {
|
||||
this->photo_material = material;
|
||||
}
|
||||
|
||||
Ref<StandardMaterial3D> ClueFinder::get_photo_material() const {
|
||||
return this->photo_material;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "core/templates/hash_set.h"
|
||||
#include "scene/3d/node_3d.h"
|
||||
#include "scene/resources/material.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "you_done_it/clue_marker.h"
|
||||
|
||||
class ClueFinder : public Node3D {
|
||||
|
|
@ -23,8 +25,14 @@ public:
|
|||
void take_photo();
|
||||
void send_photo();
|
||||
void delete_photo();
|
||||
void set_empty_texture(Ref<Texture> texture);
|
||||
Ref<Texture> get_empty_texture() const;
|
||||
void set_photo_material(Ref<StandardMaterial3D> material);
|
||||
Ref<StandardMaterial3D> get_photo_material() const;
|
||||
|
||||
private:
|
||||
Ref<StandardMaterial3D> photo_material{};
|
||||
Ref<Texture> empty_texture{};
|
||||
ClueMarker *found_marker{ nullptr };
|
||||
HashSet<ClueMarker *> clue_markers{};
|
||||
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ float ClueMarker::score_in_view() const {
|
|||
Basis const basis{ viewpoint.get_basis() };
|
||||
Vector3 const pos_relative{ get_global_position() - viewpoint.get_origin() };
|
||||
Vector3 const pos_transformed{ basis.get_column(0).dot(pos_relative), basis.get_column(1).dot(pos_relative), basis.get_column(2).dot(pos_relative) };
|
||||
if (pos_transformed.z <= 0.5f) {
|
||||
return false;
|
||||
if (pos_transformed.z <= 0.0f) {
|
||||
return Math::NaN;
|
||||
}
|
||||
Vector3 const transformed_dir{ pos_transformed.normalized() };
|
||||
float max{ pos_transformed.z / 5.f };
|
||||
if (Math::abs(transformed_dir.x) < max && Math::abs(transformed_dir.y) < max) {
|
||||
return Math::INF;
|
||||
float max{ pos_transformed.z / 10.f };
|
||||
if (Math::abs(transformed_dir.x) > max && Math::abs(transformed_dir.y) > max) {
|
||||
return Math::NaN;
|
||||
}
|
||||
return pos_transformed.z * (Math::abs(transformed_dir.x) + Math::abs(transformed_dir.y));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,10 +150,10 @@ namespace receive {
|
|||
FixedVector<NetworkData::ClueID, 3> &conclusion() {
|
||||
static FixedVector<NetworkData::ClueID, 3> thread_safe_conclusion{};
|
||||
if (connection) {
|
||||
thread_safe_conclusion.clear();
|
||||
} else {
|
||||
std::scoped_lock lock{ connection->mtx };
|
||||
thread_safe_conclusion = connection->conclusion;
|
||||
} else {
|
||||
thread_safe_conclusion.clear();
|
||||
}
|
||||
return thread_safe_conclusion;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue