mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Added texture to VoxelmanPropMesh, and added material, and uv_margin properties to VoxelMesher.
This commit is contained in:
parent
2427e9a2ae
commit
588ed550c8
@ -7,6 +7,13 @@ void VoxelMesher::set_library(Ref<VoxelmanLibrary> library) {
|
||||
_library = library;
|
||||
}
|
||||
|
||||
Ref<Material> VoxelMesher::get_material() {
|
||||
return _material;
|
||||
}
|
||||
void VoxelMesher::set_material(Ref<Material> material) {
|
||||
_material = material;
|
||||
}
|
||||
|
||||
float VoxelMesher::get_ao_strength() const {
|
||||
return _ao_strength;
|
||||
}
|
||||
@ -35,6 +42,13 @@ void VoxelMesher::set_lod_size(const int lod_size) {
|
||||
_lod_size = lod_size;
|
||||
}
|
||||
|
||||
Rect2 VoxelMesher::get_uv_margin() const {
|
||||
return _uv_margin;
|
||||
}
|
||||
void VoxelMesher::set_uv_margin(const Rect2 margin) {
|
||||
_uv_margin = margin;
|
||||
}
|
||||
|
||||
void VoxelMesher::build_mesh(RID mesh) {
|
||||
ERR_FAIL_COND(mesh == RID());
|
||||
|
||||
@ -46,7 +60,11 @@ void VoxelMesher::build_mesh(RID mesh) {
|
||||
}
|
||||
|
||||
_surface_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
|
||||
_surface_tool->set_material(_library->get_material());
|
||||
|
||||
if (_material.is_valid())
|
||||
_surface_tool->set_material(_material);
|
||||
else
|
||||
_surface_tool->set_material(_library->get_material());
|
||||
|
||||
if (_colors.size() != _vertices.size()) {
|
||||
print_error("Colors.size() != vertices.size() -> " + String::num(_colors.size()) + " " + String::num(_vertices.size()));
|
||||
@ -97,17 +115,17 @@ void VoxelMesher::reset() {
|
||||
|
||||
void VoxelMesher::add_buffer(Ref<VoxelBuffer> voxels) {
|
||||
ERR_FAIL_COND(!has_method("_add_buffer"));
|
||||
|
||||
|
||||
call("_add_buffer", voxels);
|
||||
}
|
||||
|
||||
void VoxelMesher::add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position, const Vector3 rotation, const Vector3 scale) {
|
||||
void VoxelMesher::add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position, const Vector3 rotation, const Vector3 scale, const Rect2 uv_rect) {
|
||||
Transform transform = Transform(Basis(rotation).scaled(scale), position);
|
||||
|
||||
add_mesh_data_resource_transform(mesh, transform);
|
||||
add_mesh_data_resource_transform(mesh, transform, uv_rect);
|
||||
}
|
||||
|
||||
void VoxelMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform) {
|
||||
void VoxelMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform, const Rect2 uv_rect) {
|
||||
ERR_FAIL_COND(mesh->get_array().size() == 0);
|
||||
|
||||
Array verts = mesh->get_array().get(Mesh::ARRAY_VERTEX);
|
||||
@ -116,7 +134,7 @@ void VoxelMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, c
|
||||
Vector3 vert = verts[i];
|
||||
|
||||
vert = transform.xform(vert);
|
||||
|
||||
|
||||
add_vertex(vert);
|
||||
}
|
||||
|
||||
@ -172,6 +190,12 @@ void VoxelMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, c
|
||||
for (int i = 0; i < tex_uv.size(); ++i) {
|
||||
Vector2 uv = tex_uv[i];
|
||||
|
||||
uv.x *= uv_rect.size.x;
|
||||
uv.y *= uv_rect.size.y;
|
||||
|
||||
uv.x += uv_rect.position.x;
|
||||
uv.y += uv_rect.position.y;
|
||||
|
||||
add_uv(uv);
|
||||
}
|
||||
|
||||
@ -238,7 +262,7 @@ void VoxelMesher::_bake_colors(Ref<VoxelBuffer> buffer) {
|
||||
if (_vertices.size() != _normals.size()) {
|
||||
print_error("VoxelMesherCubic: Generating normals!");
|
||||
}*/
|
||||
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vector3 vert = _vertices[i];
|
||||
|
||||
@ -486,7 +510,6 @@ void VoxelMesher::remove_uv(int idx) {
|
||||
_uvs.remove(idx);
|
||||
}
|
||||
|
||||
|
||||
Vector<int> *VoxelMesher::get_indices() {
|
||||
return &_indices;
|
||||
}
|
||||
@ -522,6 +545,7 @@ VoxelMesher::VoxelMesher() {
|
||||
_lod_size = 1;
|
||||
_ao_strength = 0.25;
|
||||
_base_light_value = 0.5;
|
||||
_uv_margin = Rect2(0, 0, 1, 1);
|
||||
|
||||
_surface_tool.instance();
|
||||
}
|
||||
@ -547,7 +571,11 @@ void VoxelMesher::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesher::get_library);
|
||||
ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelMesher::set_library);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library"), "set_library", "get_library");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "VoxelmanLibrary"), "set_library", "get_library");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_material"), &VoxelMesher::get_material);
|
||||
ClassDB::bind_method(D_METHOD("set_material", "value"), &VoxelMesher::set_material);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_scale"), &VoxelMesher::get_voxel_scale);
|
||||
ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &VoxelMesher::set_voxel_scale);
|
||||
@ -565,10 +593,13 @@ void VoxelMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_base_light_value", "value"), &VoxelMesher::set_base_light_value);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base_light_value"), "set_base_light_value", "get_base_light_value");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_uv_margin"), &VoxelMesher::get_uv_margin);
|
||||
ClassDB::bind_method(D_METHOD("set_uv_margin", "value"), &VoxelMesher::set_uv_margin);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "uv_margin"), "set_uv_margin", "get_uv_margin");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_buffer", "buffer"), &VoxelMesher::add_buffer);
|
||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "mesh", "position", "rotation", "scale"), &VoxelMesher::add_mesh_data_resource, DEFVAL(Vector3(1.0, 1.0, 1.0)), DEFVAL(Vector3()), DEFVAL(Vector3()));
|
||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform", "transform"), &VoxelMesher::add_mesh_data_resource_transform);
|
||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "mesh", "position", "rotation", "scale", "uv_rect"), &VoxelMesher::add_mesh_data_resource, DEFVAL(Rect2(0, 0, 1, 1)), DEFVAL(Vector3(1.0, 1.0, 1.0)), DEFVAL(Vector3()), DEFVAL(Vector3()));
|
||||
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform", "mesh", "transform", "uv_rect"), &VoxelMesher::add_mesh_data_resource_transform, DEFVAL(Rect2(0, 0, 1, 1)));
|
||||
ClassDB::bind_method(D_METHOD("bake_colors", "buffer"), &VoxelMesher::bake_colors);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_bake_colors", "buffer"), &VoxelMesher::_bake_colors);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "core/color.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/vector.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/resources/material.h"
|
||||
@ -33,6 +34,9 @@ public:
|
||||
Ref<VoxelmanLibrary> get_library();
|
||||
void set_library(Ref<VoxelmanLibrary> library);
|
||||
|
||||
Ref<Material> get_material();
|
||||
void set_material(Ref<Material> material);
|
||||
|
||||
float get_ao_strength() const;
|
||||
void set_ao_strength(float value);
|
||||
|
||||
@ -45,11 +49,14 @@ public:
|
||||
int get_lod_size() const;
|
||||
void set_lod_size(const int lod_size);
|
||||
|
||||
Rect2 get_uv_margin() const;
|
||||
void set_uv_margin(const Rect2 margin);
|
||||
|
||||
void reset();
|
||||
|
||||
void add_buffer(Ref<VoxelBuffer> voxels);
|
||||
void add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position = Vector3(0, 0, 0), const Vector3 rotation = Vector3(0, 0, 0), const Vector3 scale = Vector3(1.0, 1.0, 1.0));
|
||||
void add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform);
|
||||
void add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position = Vector3(0, 0, 0), const Vector3 rotation = Vector3(0, 0, 0), const Vector3 scale = Vector3(1.0, 1.0, 1.0), const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void bake_colors(Ref<VoxelBuffer> voxels);
|
||||
|
||||
void _bake_colors(Ref<VoxelBuffer> buffer);
|
||||
@ -105,6 +112,7 @@ protected:
|
||||
Vector<int> _bones;
|
||||
|
||||
Ref<VoxelmanLibrary> _library;
|
||||
Ref<Material> _material;
|
||||
|
||||
float _voxel_scale;
|
||||
int _lod_size;
|
||||
@ -113,6 +121,7 @@ protected:
|
||||
|
||||
float _ao_strength;
|
||||
float _base_light_value;
|
||||
Rect2 _uv_margin;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,13 @@ void VoxelmanPropMesh::set_mesh(const Ref<MeshDataResource> mesh) {
|
||||
_mesh = mesh;
|
||||
}
|
||||
|
||||
Ref<Texture> VoxelmanPropMesh::get_texture() const {
|
||||
return _texture;
|
||||
}
|
||||
void VoxelmanPropMesh::set_texture(const Ref<Texture> texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
bool VoxelmanPropMesh::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
}
|
||||
@ -35,6 +42,10 @@ void VoxelmanPropMesh::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &VoxelmanPropMesh::set_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_texture"), &VoxelmanPropMesh::get_texture);
|
||||
ClassDB::bind_method(D_METHOD("set_texture", "value"), &VoxelmanPropMesh::set_texture);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &VoxelmanPropMesh::get_snap_to_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &VoxelmanPropMesh::set_snap_to_mesh);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "voxelman_prop_entry.h"
|
||||
#include "core/math/vector3.h"
|
||||
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../../entity_spell_system/meshes/mesh_data_resource.h"
|
||||
|
||||
class VoxelmanPropMesh : public VoxelmanPropEntry {
|
||||
@ -13,6 +15,9 @@ public:
|
||||
Ref<MeshDataResource> get_mesh() const;
|
||||
void set_mesh(const Ref<MeshDataResource> mesh);
|
||||
|
||||
Ref<Texture> get_texture() const;
|
||||
void set_texture(const Ref<Texture> texture);
|
||||
|
||||
bool get_snap_to_mesh();
|
||||
void set_snap_to_mesh(bool value);
|
||||
|
||||
@ -29,6 +34,7 @@ private:
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
Ref<MeshDataResource> _mesh;
|
||||
Ref<Texture> _texture;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user