- Added Character3D as a C++ class.
- LevelScene now executes a signal when a Character3D falls out of the world. - slice_mesh() now transforms the slice cap normals to match the vertices.
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* ©2023 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* If this source code makes it to the public internet, this software can be
|
||||||
|
* considered to be protected by the MIT licence. Have fun with it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "character_3d.h"
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
|
||||||
|
void Character3D::_ready()
|
||||||
|
{
|
||||||
|
if (this->animation_tree = cast_to<AnimationTree>(Node::get_node_or_null(this->animation_tree_path)))
|
||||||
|
{
|
||||||
|
UtilityFunctions::print("Finally found the god damn animation tree");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Character3D::_on_fell_out_of_world()
|
||||||
|
{
|
||||||
|
this->emit_signal("fell_out_of_world");
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* ©2023 Batty Bovine Productions, LLC. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* If this source code makes it to the public internet, this software can be
|
||||||
|
* considered to be protected by the MIT licence. Have fun with it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "orng_macros.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <godot_cpp/classes/animation_tree.hpp>
|
||||||
|
#include <godot_cpp/classes/character_body3d.hpp>
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
|
||||||
|
class Character3D : public CharacterBody3D
|
||||||
|
{
|
||||||
|
GDCLASS(Character3D, CharacterBody3D);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void _ready() override;
|
||||||
|
|
||||||
|
virtual void _on_fell_out_of_world();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void set_animation_tree_path(NodePath at) { this->animation_tree_path = at; }
|
||||||
|
NodePath get_animation_tree_path() const { return this->animation_tree_path; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
AnimationTree *get_animation_tree() const { return this->animation_tree; }
|
||||||
|
|
||||||
|
NodePath animation_tree_path;
|
||||||
|
AnimationTree *animation_tree = nullptr;
|
||||||
|
|
||||||
|
// Godot boilerplate below
|
||||||
|
protected:
|
||||||
|
static void _bind_methods()
|
||||||
|
{
|
||||||
|
BIND_METHOD(Character3D, _on_fell_out_of_world);
|
||||||
|
|
||||||
|
ADD_SIGNAL(MethodInfo("fell_out_of_world"));
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_animation_tree_path"), &Character3D::get_animation_tree_path);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_animation_tree_path", "animation_tree"), &Character3D::set_animation_tree_path);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "animation_tree", PROPERTY_HINT_NODE_TYPE, "AnimationTree"), "set_animation_tree_path", "get_animation_tree_path");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_animation_tree"), &Character3D::get_animation_tree);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "level_scene.h"
|
#include "level_scene.h"
|
||||||
|
|
||||||
|
#include "character_3d.h"
|
||||||
#include "nodes/player_spawn.h"
|
#include "nodes/player_spawn.h"
|
||||||
#include "singletons/save_manager.h"
|
#include "singletons/save_manager.h"
|
||||||
|
|
||||||
@@ -97,12 +98,12 @@ void LevelScene::_find_player_spawns_recursive(const Node *node, SpawnPointMap &
|
|||||||
|
|
||||||
void LevelScene::_body_fell_out_of_world(Node3D *body)
|
void LevelScene::_body_fell_out_of_world(Node3D *body)
|
||||||
{
|
{
|
||||||
if (body->has_method("on_fell_out_of_world"))
|
if (Character3D *character3d = cast_to<Character3D>(body))
|
||||||
{
|
{
|
||||||
body->call("on_fell_out_of_world");
|
character3d->emit_signal(FELL_OUT_OF_WORLD_SIGNAL);
|
||||||
}
|
}
|
||||||
else
|
else if (body->has_method(FELL_OUT_OF_WORLD_METHOD))
|
||||||
{
|
{
|
||||||
body->queue_free();
|
body->call(FELL_OUT_OF_WORLD_METHOD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
#include <godot_cpp/classes/resource.hpp>
|
#include <godot_cpp/classes/resource.hpp>
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
|
#define FELL_OUT_OF_WORLD_SIGNAL "fell_out_of_world"
|
||||||
|
#define FELL_OUT_OF_WORLD_METHOD "_on_fell_out_of_world"
|
||||||
|
|
||||||
typedef std::map<const class StringName, const class PlayerOrigin*> SpawnPointMap;
|
typedef std::map<const class StringName, const class PlayerOrigin*> SpawnPointMap;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
|||||||
const Mesh *original_mesh = original_mesh_instance->get_mesh().ptr();
|
const Mesh *original_mesh = original_mesh_instance->get_mesh().ptr();
|
||||||
const uint8_t num_surfaces = original_mesh->get_surface_count();
|
const uint8_t num_surfaces = original_mesh->get_surface_count();
|
||||||
|
|
||||||
TypedArray<Transform3D> bone_transforms;
|
std::vector<std::vector<Transform3D>> skinned_vertex_transforms;
|
||||||
const SkinnedSurfaces &skinned_vertex_positions = MeshEditingLibrary::get_skinned_vertex_positions(original_mesh, original_skeleton, bone_transforms);
|
const SkinnedSurfaces &skinned_vertex_positions = MeshEditingLibrary::get_skinned_vertex_positions(original_mesh, original_skeleton, skinned_vertex_transforms);
|
||||||
|
|
||||||
UtilityFunctions::print("Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
UtilityFunctions::print("Got skinned vertices at ", time->get_ticks_msec(), "ms");
|
||||||
|
|
||||||
@@ -501,9 +501,10 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
|||||||
for (const MeshEditVert2D &vertex : polygon_set[polygon_index].vertices)
|
for (const MeshEditVert2D &vertex : polygon_set[polygon_index].vertices)
|
||||||
{
|
{
|
||||||
const Vector3 &position = first_half_section_vertices[vertex.index];
|
const Vector3 &position = first_half_section_vertices[vertex.index];
|
||||||
|
const Vector3 &local_plane_transformed_normal = skinned_vertex_transforms[surface][vertex.index].xform(local_plane_normal).normalized();
|
||||||
|
|
||||||
cap_section_vertices.append(position);
|
cap_section_vertices.append(position);
|
||||||
if (has_normal) { cap_section_normals.append(local_plane_normal * -1.0f); cap_section_flipped_normals.append(local_plane_normal); }
|
if (has_normal) { cap_section_normals.append(local_plane_transformed_normal); cap_section_flipped_normals.append(local_plane_transformed_normal * -1.0f); }
|
||||||
if (has_colour) { cap_section_colours.append(first_half_section_colours[vertex.index]); }
|
if (has_colour) { cap_section_colours.append(first_half_section_colours[vertex.index]); }
|
||||||
if (has_uv) { cap_section_uvs.append(MeshEditingLibrary::calculate_planar_uv(position, mesh_bounds, uv_plane)); }
|
if (has_uv) { cap_section_uvs.append(MeshEditingLibrary::calculate_planar_uv(position, mesh_bounds, uv_plane)); }
|
||||||
if (has_uv2) { cap_section_uv2s.append(first_half_section_uv2s[vertex.index]); }
|
if (has_uv2) { cap_section_uv2s.append(first_half_section_uv2s[vertex.index]); }
|
||||||
@@ -595,7 +596,7 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(const MeshInstance3D *original
|
|||||||
return impact_points;
|
return impact_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton, TypedArray<Transform3D> &bone_transforms)
|
SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton, std::vector<std::vector<Transform3D>> &vertex_transforms)
|
||||||
{
|
{
|
||||||
const uint8_t num_surfaces = mesh->get_surface_count();
|
const uint8_t num_surfaces = mesh->get_surface_count();
|
||||||
SkinnedSurfaces skinned_vertex_surfaces;
|
SkinnedSurfaces skinned_vertex_surfaces;
|
||||||
@@ -604,12 +605,15 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
|||||||
if (skeleton)
|
if (skeleton)
|
||||||
{
|
{
|
||||||
const uint16_t bone_count = skeleton->get_bone_count();
|
const uint16_t bone_count = skeleton->get_bone_count();
|
||||||
|
std::vector<Transform3D> bone_transforms;
|
||||||
bone_transforms.resize(bone_count);
|
bone_transforms.resize(bone_count);
|
||||||
for (uint8_t bone_index = 0; bone_index < bone_count; bone_index++)
|
for (uint8_t bone_index = 0; bone_index < bone_count; bone_index++)
|
||||||
{
|
{
|
||||||
bone_transforms[bone_index] = skeleton->get_bone_global_pose(bone_index) * skeleton->get_bone_global_rest(bone_index).inverse();
|
bone_transforms[bone_index] = skeleton->get_bone_global_pose(bone_index) * skeleton->get_bone_global_rest(bone_index).inverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertex_transforms.resize(num_surfaces);
|
||||||
|
|
||||||
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
for (uint8_t surface = 0; surface < num_surfaces; surface++)
|
||||||
{
|
{
|
||||||
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
const Array &mesh_arrays = mesh->surface_get_arrays(surface);
|
||||||
@@ -620,6 +624,9 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
|||||||
SkinnedVertices skinned_vertex_array;
|
SkinnedVertices skinned_vertex_array;
|
||||||
skinned_vertex_array.resize(mesh_vertex_array_size);
|
skinned_vertex_array.resize(mesh_vertex_array_size);
|
||||||
|
|
||||||
|
std::vector<Transform3D> skinned_vertex_transforms;
|
||||||
|
skinned_vertex_transforms.resize(mesh_vertex_array_size);
|
||||||
|
|
||||||
const PackedInt32Array &mesh_bones_array = mesh_arrays[ArrayMesh::ARRAY_BONES];
|
const PackedInt32Array &mesh_bones_array = mesh_arrays[ArrayMesh::ARRAY_BONES];
|
||||||
const PackedFloat32Array &mesh_weights_array = mesh_arrays[ArrayMesh::ARRAY_WEIGHTS];
|
const PackedFloat32Array &mesh_weights_array = mesh_arrays[ArrayMesh::ARRAY_WEIGHTS];
|
||||||
const uint8_t num_bones_per_vertex = mesh_bones_array.size() / mesh_vertex_array_size;
|
const uint8_t num_bones_per_vertex = mesh_bones_array.size() / mesh_vertex_array_size;
|
||||||
@@ -644,21 +651,19 @@ SkinnedSurfaces MeshEditingLibrary::get_skinned_vertex_positions(const Mesh *mes
|
|||||||
origin += transforms[transform].origin;
|
origin += transforms[transform].origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3 &transformed_vertex = Vector3(
|
const Transform3D &final_bone_transform = Transform3D(
|
||||||
x_basis.dot(vertex) + origin.x,
|
x_basis.x, x_basis.y, x_basis.z,
|
||||||
y_basis.dot(vertex) + origin.y,
|
y_basis.x, y_basis.y, y_basis.z,
|
||||||
z_basis.dot(vertex) + origin.z);
|
z_basis.x, z_basis.y, z_basis.z,
|
||||||
skinned_vertex_array[vertex_index] = transformed_vertex;
|
origin.x, origin.y, origin.z);
|
||||||
// The above is identical to the code seen below, except the below code does not work.
|
skinned_vertex_transforms[vertex_index] = final_bone_transform;
|
||||||
// This is fucking stupid.
|
skinned_vertex_array[vertex_index] = final_bone_transform.xform(vertex);
|
||||||
//
|
|
||||||
// const Transform3D &final_transform = Transform3D(x_basis, y_basis, z_basis, origin);
|
|
||||||
// skinned_vertex_array[vertex_index] = final_transform.xform(vertex);
|
|
||||||
|
|
||||||
delete transforms;
|
delete transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
skinned_vertex_surfaces[surface] = skinned_vertex_array;
|
skinned_vertex_surfaces[surface] = skinned_vertex_array;
|
||||||
|
vertex_transforms[surface] = skinned_vertex_transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
return skinned_vertex_surfaces;
|
return skinned_vertex_surfaces;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static const Vector2 calculate_planar_uv(const Vector3 &vertex, const Vector3 &mesh_bounds, const MeshSlicePlaneOrientation &axis);
|
static const Vector2 calculate_planar_uv(const Vector3 &vertex, const Vector3 &mesh_bounds, const MeshSlicePlaneOrientation &axis);
|
||||||
|
|
||||||
static SkinnedSurfaces get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton = nullptr, TypedArray<Transform3D> &bone_transforms = TypedArray<Transform3D>());
|
static SkinnedSurfaces get_skinned_vertex_positions(const Mesh *mesh, const Skeleton3D *skeleton = nullptr, std::vector<std::vector<Transform3D>> &bone_transforms = std::vector<std::vector<Transform3D>>());
|
||||||
|
|
||||||
static void project_edges(std::vector<MeshEditEdge2D> &out_2d_edges, const Transform3D &to_node_space, const std::vector<MeshEditEdge3D> &in_3d_edges, const Plane &plane);
|
static void project_edges(std::vector<MeshEditEdge2D> &out_2d_edges, const Transform3D &to_node_space, const std::vector<MeshEditEdge3D> &in_3d_edges, const Plane &plane);
|
||||||
static void build_2d_polygons_from_edges(std::vector<MeshEditPolygon2D> &out_polygons, const std::vector<MeshEditEdge2D> &in_edges, std::vector<MeshEditPolygon2D> &error_polygons);
|
static void build_2d_polygons_from_edges(std::vector<MeshEditPolygon2D> &out_polygons, const std::vector<MeshEditEdge2D> &in_edges, std::vector<MeshEditPolygon2D> &error_polygons);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "nodes/player_spawn.h"
|
#include "nodes/player_spawn.h"
|
||||||
#include "nodes/sublevel_loader.h"
|
#include "nodes/sublevel_loader.h"
|
||||||
#include "nodes/sublevel_scene.h"
|
#include "nodes/sublevel_scene.h"
|
||||||
|
#include "nodes/character_nodes/character_3d.h"
|
||||||
|
|
||||||
#include "resources/level_metadata_map.h"
|
#include "resources/level_metadata_map.h"
|
||||||
#include "resources/level_metadata_resource.h"
|
#include "resources/level_metadata_resource.h"
|
||||||
@@ -62,6 +63,7 @@ void initialize_orng_module(ModuleInitializationLevel p_level) {
|
|||||||
|
|
||||||
ClassDB::register_class<MovementHandler>();
|
ClassDB::register_class<MovementHandler>();
|
||||||
|
|
||||||
|
ClassDB::register_class<Character3D>();
|
||||||
ClassDB::register_class<GameClasses>();
|
ClassDB::register_class<GameClasses>();
|
||||||
ClassDB::register_class<LevelScene>();
|
ClassDB::register_class<LevelScene>();
|
||||||
ClassDB::register_class<PlayerOrigin>();
|
ClassDB::register_class<PlayerOrigin>();
|
||||||
|
|||||||
Reference in New Issue
Block a user