More cleanups.

This commit is contained in:
Relintai 2024-01-05 14:14:30 +01:00
parent 11a8bde0d9
commit 843dc6baf3
17 changed files with 81 additions and 66 deletions

View File

@ -255,7 +255,7 @@ GameScene::GameScene() {
camera_2d = memnew(Camera2D);
camera_2d->size = Vector2(1920, 1080);
mesh = memnew(Mesh());
mesh = Ref<Mesh>(memnew(Mesh()));
//cmaterial = memnew(ColoredMaterial());
//cmaterial->color = glm::vec4(1, 1, 0, 1);
color_material.instance();
@ -266,11 +266,11 @@ GameScene::GameScene() {
mesh->upload();
mi = memnew(MeshInstance3D());
mi->material = color_material.ptr();
mi->material = color_material;
mi->mesh = mesh;
mi2 = memnew(MeshInstance3D());
mi2->material = color_material.ptr();
mi2->material = color_material;
mi2->mesh = mesh;
mi2->transform.origin.x = 1;

View File

@ -53,7 +53,7 @@ public:
Sprite *sprite;
Camera3D *camera;
Mesh *mesh;
Ref<Mesh> mesh;
MeshInstance3D *mi;
MeshInstance3D *mi2;
Ref<ColorMaterial> color_material;

View File

@ -2,9 +2,10 @@
#include "render_core/mesh_utils.h"
//--STRIP
void MeshUtils::create_cone(Mesh *mesh) {
if (!mesh)
void MeshUtils::create_cone(Ref<Mesh> mesh) {
if (!mesh.is_valid()) {
return;
}
uint32_t vc = mesh->vertices.size();
@ -12,7 +13,7 @@ void MeshUtils::create_cone(Mesh *mesh) {
mesh->add_color(1, 0, 0);
mesh->add_vertex3(0, 0.5, 0);
mesh->add_color(1,0,0);
mesh->add_color(1, 0, 0);
mesh->add_vertex3(-0.5, -0.5, 0.5);
mesh->add_color(1, 0, 0);

View File

@ -7,7 +7,7 @@
class MeshUtils {
public:
static void create_cone(Mesh *mesh);
static void create_cone(Ref<Mesh> mesh);
};
#endif

View File

@ -33,5 +33,9 @@ void MeshInstance2D::render() {
MeshInstance2D::MeshInstance2D() {
}
MeshInstance2D::~MeshInstance2D() {
for (int i = 0; i < children.size(); ++i) {
memdelete(children[i]);
}
children.clear();
}

View File

@ -2,6 +2,8 @@
#define MESH_INSTACE_2D_H
//--STRIP
#include "object_2d.h"
#include "core/vector.h"
#include "render_core/material.h"
@ -10,7 +12,9 @@
#include "core/transform.h"
//--STRIP
class MeshInstance2D {
class MeshInstance2D : public Object2D {
SFW_OBJECT(MeshInstance2D, Object2D);
public:
void render();

View File

@ -1,3 +1,4 @@
//--STRIP
#include "render_objects/mesh_instance_3d.h"
@ -5,7 +6,7 @@
//--STRIP
void MeshInstance3D::render() {
if (!mesh) {
if (!mesh.is_valid()) {
return;
}
@ -13,7 +14,7 @@ void MeshInstance3D::render() {
Camera3D::current_camera->set_model_view_matrix(mat_orig * transform);
if (material) {
if (material.is_valid()) {
material->bind();
}
@ -31,9 +32,11 @@ void MeshInstance3D::render() {
}
MeshInstance3D::MeshInstance3D() {
material = NULL;
mesh = NULL;
}
MeshInstance3D::~MeshInstance3D() {
for (int i = 0; i < children.size(); ++i) {
memdelete(children[i]);
}
children.clear();
}

View File

@ -13,14 +13,16 @@
//--STRIP
class MeshInstance3D : public Object3D {
SFW_OBJECT(MeshInstance3D, Object3D);
public:
void render();
MeshInstance3D();
~MeshInstance3D();
Material *material;
Mesh *mesh;
Ref<Material> material;
Ref<Mesh> mesh;
Vector<MeshInstance3D *> children;
};

View File

@ -6,5 +6,5 @@ cd ..
python tools/merger/join.py --template tools/merger/sfw.h.inl --path . --output tools/merger/out/sfw.h
python tools/merger/join.py --template tools/merger/sfw.cpp.inl --path . --output tools/merger/out/sfw.cpp
python tools/merger/join.py --template tools/merger/sfw.x.inl --path . --output tools/merger/out/sfw
python tools/merger/join.py --template tools/merger/sfw_3rd.x.inl --path . --output tools/merger/out/sfw_3rd.h

View File

@ -721,6 +721,7 @@ SOFTWARE.
//--STRIP
{{FILE:sfw/render_objects/camera_2d.h}}
//--STRIP
//#include "object_2d.h"
//#include "core/vector.h"
//#include "render_core/material.h"
//#include "render_core/mesh.h"