Godot 3.0 primitives as resources for use with MeshInstance
Adds the following resources: - CapsuleMesh: a capsule object - CubeMesh: a cube that can be subdivided - CylinderMesh: a cylinder - PlaneMesh: a horizontal plane that can be subdivided - PrismMesh: a prism shape - SphereMesh: a sphere - QuadMesh: reintroduction of the original quadmesh Removes the old Quad and TestCube nodes
This commit is contained in:
parent
80929d36be
commit
9483613138
@ -1439,20 +1439,6 @@ VehicleWheelSpatialGizmo::VehicleWheelSpatialGizmo(VehicleWheel *p_car_wheel) {
|
||||
car_wheel = p_car_wheel;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
void TestCubeSpatialGizmo::redraw() {
|
||||
|
||||
clear();
|
||||
add_collision_triangles(SpatialEditorGizmos::singleton->test_cube_tm);
|
||||
}
|
||||
|
||||
TestCubeSpatialGizmo::TestCubeSpatialGizmo(TestCube *p_tc) {
|
||||
|
||||
tc = p_tc;
|
||||
set_spatial_node(p_tc);
|
||||
}
|
||||
|
||||
///////////
|
||||
|
||||
String CollisionShapeSpatialGizmo::get_handle_name(int p_idx) const {
|
||||
@ -3045,12 +3031,6 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) {
|
||||
return misg;
|
||||
}
|
||||
|
||||
if (p_spatial->cast_to<TestCube>()) {
|
||||
|
||||
Ref<TestCubeSpatialGizmo> misg = memnew(TestCubeSpatialGizmo(p_spatial->cast_to<TestCube>()));
|
||||
return misg;
|
||||
}
|
||||
|
||||
if (p_spatial->cast_to<CollisionShape>()) {
|
||||
|
||||
Ref<CollisionShapeSpatialGizmo> misg = memnew(CollisionShapeSpatialGizmo(p_spatial->cast_to<CollisionShape>()));
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include "scene/3d/ray_cast.h"
|
||||
#include "scene/3d/reflection_probe.h"
|
||||
#include "scene/3d/room_instance.h"
|
||||
#include "scene/3d/test_cube.h"
|
||||
#include "scene/3d/vehicle_body.h"
|
||||
#include "scene/3d/visibility_notifier.h"
|
||||
|
||||
@ -187,17 +186,6 @@ public:
|
||||
SkeletonSpatialGizmo(Skeleton *p_skel = NULL);
|
||||
};
|
||||
|
||||
class TestCubeSpatialGizmo : public EditorSpatialGizmo {
|
||||
|
||||
GDCLASS(TestCubeSpatialGizmo, EditorSpatialGizmo);
|
||||
|
||||
TestCube *tc;
|
||||
|
||||
public:
|
||||
void redraw();
|
||||
TestCubeSpatialGizmo(TestCube *p_tc = NULL);
|
||||
};
|
||||
|
||||
class RoomSpatialGizmo : public EditorSpatialGizmo {
|
||||
|
||||
GDCLASS(RoomSpatialGizmo, EditorSpatialGizmo);
|
||||
|
@ -53,7 +53,6 @@
|
||||
#include "scene/main/scene_main_loop.h"
|
||||
|
||||
#include "scene/3d/camera.h"
|
||||
#include "scene/3d/test_cube.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
namespace TestGUI {
|
||||
@ -87,10 +86,6 @@ public:
|
||||
vp->add_child(camera);
|
||||
camera->make_current();
|
||||
|
||||
TestCube *testcube = memnew( TestCube );
|
||||
vp->add_child(testcube);
|
||||
testcube->set_transform(Transform( Basis().rotated(Vector3(0,1,0),Math_PI*0.25), Vector3(0,0,-8)));
|
||||
|
||||
Sprite *sp = memnew( Sprite );
|
||||
sp->set_texture( vp->get_render_target_texture() );
|
||||
//sp->set_texture( ResourceLoader::load("res://ball.png") );
|
||||
@ -375,6 +370,6 @@ MainLoop *test() {
|
||||
|
||||
return memnew(TestMainLoop);
|
||||
}
|
||||
}
|
||||
} // namespace TestGUI
|
||||
|
||||
#endif
|
||||
|
@ -1,226 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* quad.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "quad.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
void Quad::_update() {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
|
||||
Vector3 normal;
|
||||
normal[axis] = 1.0;
|
||||
|
||||
const int axis_order_1[3] = { 1, 2, 0 };
|
||||
const int axis_order_2[3] = { 2, 0, 1 };
|
||||
const int a1 = axis_order_1[axis];
|
||||
const int a2 = axis_order_2[axis];
|
||||
|
||||
PoolVector<Vector3> points;
|
||||
points.resize(4);
|
||||
PoolVector<Vector3>::Write pointsw = points.write();
|
||||
|
||||
Vector2 s2 = size * 0.5;
|
||||
Vector2 o = offset;
|
||||
if (!centered)
|
||||
o += s2;
|
||||
|
||||
pointsw[0][a1] = -s2.x + offset.x;
|
||||
pointsw[0][a2] = s2.y + offset.y;
|
||||
|
||||
pointsw[1][a1] = s2.x + offset.x;
|
||||
pointsw[1][a2] = s2.y + offset.y;
|
||||
|
||||
pointsw[2][a1] = s2.x + offset.x;
|
||||
pointsw[2][a2] = -s2.y + offset.y;
|
||||
|
||||
pointsw[3][a1] = -s2.x + offset.x;
|
||||
pointsw[3][a2] = -s2.y + offset.y;
|
||||
|
||||
aabb = Rect3(pointsw[0], Vector3());
|
||||
for (int i = 1; i < 4; i++)
|
||||
aabb.expand_to(pointsw[i]);
|
||||
|
||||
pointsw = PoolVector<Vector3>::Write();
|
||||
|
||||
PoolVector<Vector3> normals;
|
||||
normals.resize(4);
|
||||
PoolVector<Vector3>::Write normalsw = normals.write();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
normalsw[i] = normal;
|
||||
|
||||
normalsw = PoolVector<Vector3>::Write();
|
||||
|
||||
PoolVector<Vector2> uvs;
|
||||
uvs.resize(4);
|
||||
PoolVector<Vector2>::Write uvsw = uvs.write();
|
||||
|
||||
uvsw[0] = Vector2(0, 0);
|
||||
uvsw[1] = Vector2(1, 0);
|
||||
uvsw[2] = Vector2(1, 1);
|
||||
uvsw[3] = Vector2(0, 1);
|
||||
|
||||
uvsw = PoolVector<Vector2>::Write();
|
||||
|
||||
PoolVector<int> indices;
|
||||
indices.resize(6);
|
||||
|
||||
PoolVector<int>::Write indicesw = indices.write();
|
||||
indicesw[0] = 0;
|
||||
indicesw[1] = 1;
|
||||
indicesw[2] = 2;
|
||||
indicesw[3] = 2;
|
||||
indicesw[4] = 3;
|
||||
indicesw[5] = 0;
|
||||
|
||||
indicesw = PoolVector<int>::Write();
|
||||
|
||||
Array arr;
|
||||
arr.resize(VS::ARRAY_MAX);
|
||||
arr[VS::ARRAY_VERTEX] = points;
|
||||
arr[VS::ARRAY_NORMAL] = normals;
|
||||
arr[VS::ARRAY_TEX_UV] = uvs;
|
||||
arr[VS::ARRAY_INDEX] = indices;
|
||||
|
||||
if (configured) {
|
||||
VS::get_singleton()->mesh_remove_surface(mesh, 0);
|
||||
} else {
|
||||
configured = true;
|
||||
}
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLES, arr);
|
||||
|
||||
pending_update = false;
|
||||
}
|
||||
|
||||
void Quad::set_axis(Vector3::Axis p_axis) {
|
||||
|
||||
axis = p_axis;
|
||||
_update();
|
||||
}
|
||||
|
||||
Vector3::Axis Quad::get_axis() const {
|
||||
|
||||
return axis;
|
||||
}
|
||||
|
||||
void Quad::set_size(const Vector2 &p_size) {
|
||||
|
||||
size = p_size;
|
||||
_update();
|
||||
}
|
||||
Vector2 Quad::get_size() const {
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void Quad::set_offset(const Vector2 &p_offset) {
|
||||
|
||||
offset = p_offset;
|
||||
_update();
|
||||
}
|
||||
Vector2 Quad::get_offset() const {
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
void Quad::set_centered(bool p_enabled) {
|
||||
|
||||
centered = p_enabled;
|
||||
_update();
|
||||
}
|
||||
bool Quad::is_centered() const {
|
||||
|
||||
return centered;
|
||||
}
|
||||
|
||||
void Quad::_notification(int p_what) {
|
||||
|
||||
switch (p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
if (pending_update)
|
||||
_update();
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
pending_update = true;
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
PoolVector<Face3> Quad::get_faces(uint32_t p_usage_flags) const {
|
||||
|
||||
return PoolVector<Face3>();
|
||||
}
|
||||
|
||||
Rect3 Quad::get_aabb() const {
|
||||
|
||||
return aabb;
|
||||
}
|
||||
|
||||
void Quad::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_axis", "axis"), &Quad::set_axis);
|
||||
ClassDB::bind_method(D_METHOD("get_axis"), &Quad::get_axis);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_size", "size"), &Quad::set_size);
|
||||
ClassDB::bind_method(D_METHOD("get_size"), &Quad::get_size);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Quad::set_centered);
|
||||
ClassDB::bind_method(D_METHOD("is_centered"), &Quad::is_centered);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Quad::set_offset);
|
||||
ClassDB::bind_method(D_METHOD("get_offset"), &Quad::get_offset);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "axis", PROPERTY_HINT_ENUM, "X,Y,Z"), "set_axis", "get_axis");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
|
||||
}
|
||||
|
||||
Quad::Quad() {
|
||||
|
||||
pending_update = true;
|
||||
centered = true;
|
||||
//offset=0;
|
||||
size = Vector2(1, 1);
|
||||
axis = Vector3::AXIS_Z;
|
||||
mesh = VisualServer::get_singleton()->mesh_create();
|
||||
set_base(mesh);
|
||||
configured = false;
|
||||
}
|
||||
|
||||
Quad::~Quad() {
|
||||
VisualServer::get_singleton()->free(mesh);
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* quad.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef QUAD_H
|
||||
#define QUAD_H
|
||||
|
||||
#include "rid.h"
|
||||
#include "scene/3d/visual_instance.h"
|
||||
|
||||
class Quad : public GeometryInstance {
|
||||
|
||||
GDCLASS(Quad, GeometryInstance);
|
||||
|
||||
Vector3::Axis axis;
|
||||
bool centered;
|
||||
Vector2 offset;
|
||||
Vector2 size;
|
||||
|
||||
Rect3 aabb;
|
||||
bool configured;
|
||||
bool pending_update;
|
||||
RID mesh;
|
||||
|
||||
void _update();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_axis(Vector3::Axis p_axis);
|
||||
Vector3::Axis get_axis() const;
|
||||
|
||||
void set_size(const Vector2 &p_sizze);
|
||||
Vector2 get_size() const;
|
||||
|
||||
void set_offset(const Vector2 &p_offset);
|
||||
Vector2 get_offset() const;
|
||||
|
||||
void set_centered(bool p_enabled);
|
||||
bool is_centered() const;
|
||||
|
||||
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
||||
virtual Rect3 get_aabb() const;
|
||||
|
||||
Quad();
|
||||
~Quad();
|
||||
};
|
||||
|
||||
#endif // QUAD_H
|
@ -1,48 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* test_cube.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "test_cube.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
Rect3 TestCube::get_aabb() const {
|
||||
|
||||
return Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2));
|
||||
}
|
||||
PoolVector<Face3> TestCube::get_faces(uint32_t p_usage_flags) const {
|
||||
|
||||
return PoolVector<Face3>();
|
||||
}
|
||||
|
||||
TestCube::TestCube() {
|
||||
|
||||
set_base(VisualServer::get_singleton()->get_test_cube());
|
||||
}
|
||||
|
||||
TestCube::~TestCube() {
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* test_cube.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef TEST_CUBE_H
|
||||
#define TEST_CUBE_H
|
||||
|
||||
#include "rid.h"
|
||||
#include "scene/3d/visual_instance.h"
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class TestCube : public GeometryInstance {
|
||||
|
||||
GDCLASS(TestCube, GeometryInstance);
|
||||
|
||||
RID instance;
|
||||
|
||||
public:
|
||||
virtual Rect3 get_aabb() const;
|
||||
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
||||
|
||||
TestCube();
|
||||
~TestCube();
|
||||
};
|
||||
|
||||
#endif
|
@ -74,7 +74,6 @@
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/slider.h"
|
||||
#include "scene/gui/spin_box.h"
|
||||
#include "scene/gui/spin_box.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
#include "scene/gui/tab_container.h"
|
||||
#include "scene/gui/tabs.h"
|
||||
@ -130,7 +129,6 @@
|
||||
#include "scene/animation/tween.h"
|
||||
#include "scene/main/resource_preloader.h"
|
||||
#include "scene/main/scene_main_loop.h"
|
||||
#include "scene/main/scene_main_loop.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
#include "scene/resources/mesh_data_tool.h"
|
||||
@ -172,6 +170,8 @@
|
||||
#include "scene/resources/sky_box.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "scene/resources/primitive_meshes.h"
|
||||
|
||||
#include "scene/resources/shader_graph.h"
|
||||
|
||||
#include "scene/resources/world.h"
|
||||
@ -206,9 +206,7 @@
|
||||
#include "scene/3d/physics_body.h"
|
||||
#include "scene/3d/portal.h"
|
||||
#include "scene/3d/position_3d.h"
|
||||
#include "scene/3d/quad.h"
|
||||
#include "scene/3d/reflection_probe.h"
|
||||
#include "scene/3d/test_cube.h"
|
||||
#include "scene/resources/environment.h"
|
||||
|
||||
#include "scene/3d/area.h"
|
||||
@ -407,7 +405,6 @@ void register_scene_types() {
|
||||
ClassDB::register_class<Camera>();
|
||||
ClassDB::register_class<Listener>();
|
||||
ClassDB::register_class<InterpolatedCamera>();
|
||||
ClassDB::register_class<TestCube>();
|
||||
ClassDB::register_class<MeshInstance>();
|
||||
ClassDB::register_class<ImmediateGeometry>();
|
||||
ClassDB::register_class<Sprite3D>();
|
||||
@ -423,7 +420,6 @@ void register_scene_types() {
|
||||
ClassDB::register_class<Portal>();
|
||||
ClassDB::register_class<Particles>();
|
||||
ClassDB::register_class<Position3D>();
|
||||
ClassDB::register_class<Quad>();
|
||||
ClassDB::register_class<NavigationMeshInstance>();
|
||||
ClassDB::register_class<NavigationMesh>();
|
||||
ClassDB::register_class<Navigation>();
|
||||
@ -522,6 +518,14 @@ void register_scene_types() {
|
||||
#ifndef _3D_DISABLED
|
||||
ClassDB::register_virtual_class<Mesh>();
|
||||
ClassDB::register_class<ArrayMesh>();
|
||||
ClassDB::register_virtual_class<PrimitiveMesh>();
|
||||
ClassDB::register_class<CapsuleMesh>();
|
||||
ClassDB::register_class<CubeMesh>();
|
||||
ClassDB::register_class<CylinderMesh>();
|
||||
ClassDB::register_class<PlaneMesh>();
|
||||
ClassDB::register_class<PrismMesh>();
|
||||
ClassDB::register_class<QuadMesh>();
|
||||
ClassDB::register_class<SphereMesh>();
|
||||
ClassDB::register_virtual_class<Material>();
|
||||
ClassDB::register_class<SpatialMaterial>();
|
||||
ClassDB::add_compatibility_class("FixedSpatialMaterial", "SpatialMaterial");
|
||||
|
@ -1047,72 +1047,3 @@ ArrayMesh::~ArrayMesh() {
|
||||
|
||||
VisualServer::get_singleton()->free(mesh);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
#if 0
|
||||
void QuadMesh::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_material", "material:Material"), &QuadMesh::set_material);
|
||||
ClassDB::bind_method(D_METHOD("get_material:Material"), &QuadMesh::get_material);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material");
|
||||
}
|
||||
|
||||
void QuadMesh::set_material(const Ref<Material> &p_material) {
|
||||
|
||||
surface_set_material(0, p_material);
|
||||
}
|
||||
|
||||
Ref<Material> QuadMesh::get_material() const {
|
||||
|
||||
return surface_get_material(0);
|
||||
}
|
||||
|
||||
QuadMesh::QuadMesh() {
|
||||
|
||||
PoolVector<Vector3> faces;
|
||||
PoolVector<Vector3> normals;
|
||||
PoolVector<float> tangents;
|
||||
PoolVector<Vector2> uvs;
|
||||
|
||||
faces.resize(4);
|
||||
normals.resize(4);
|
||||
tangents.resize(4 * 4);
|
||||
uvs.resize(4);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
static const Vector3 quad_faces[4] = {
|
||||
Vector3(-1, -1, 0),
|
||||
Vector3(-1, 1, 0),
|
||||
Vector3(1, 1, 0),
|
||||
Vector3(1, -1, 0),
|
||||
};
|
||||
|
||||
faces.set(i, quad_faces[i]);
|
||||
normals.set(i, Vector3(0, 0, 1));
|
||||
tangents.set(i * 4 + 0, 1.0);
|
||||
tangents.set(i * 4 + 1, 0.0);
|
||||
tangents.set(i * 4 + 2, 0.0);
|
||||
tangents.set(i * 4 + 3, 1.0);
|
||||
|
||||
static const Vector2 quad_uv[4] = {
|
||||
Vector2(0, 1),
|
||||
Vector2(0, 0),
|
||||
Vector2(1, 0),
|
||||
Vector2(1, 1),
|
||||
};
|
||||
|
||||
uvs.set(i, quad_uv[i]);
|
||||
}
|
||||
|
||||
Array arr;
|
||||
arr.resize(ARRAY_MAX);
|
||||
arr[ARRAY_VERTEX] = faces;
|
||||
arr[ARRAY_NORMAL] = normals;
|
||||
arr[ARRAY_TANGENT] = tangents;
|
||||
arr[ARRAY_TEX_UV] = uvs;
|
||||
|
||||
add_surface_from_arrays(PRIMITIVE_TRIANGLE_FAN, arr);
|
||||
}
|
||||
#endif
|
||||
|
@ -214,23 +214,6 @@ public:
|
||||
~ArrayMesh();
|
||||
};
|
||||
|
||||
#if 0
|
||||
class QuadMesh : public Mesh {
|
||||
|
||||
GDCLASS(QuadMesh, Mesh)
|
||||
|
||||
protected:
|
||||
virtual bool _is_generated() const { return true; }
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
QuadMesh();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
VARIANT_ENUM_CAST(Mesh::ArrayType);
|
||||
VARIANT_ENUM_CAST(Mesh::PrimitiveType);
|
||||
VARIANT_ENUM_CAST(Mesh::BlendShapeMode);
|
||||
|
1455
scene/resources/primitive_meshes.cpp
Normal file
1455
scene/resources/primitive_meshes.cpp
Normal file
File diff suppressed because it is too large
Load Diff
312
scene/resources/primitive_meshes.h
Normal file
312
scene/resources/primitive_meshes.h
Normal file
@ -0,0 +1,312 @@
|
||||
/*************************************************************************/
|
||||
/* primitive_meshes.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef PRIMITIVE_MESHES_H
|
||||
#define PRIMITIVE_MESHES_H
|
||||
|
||||
#include "scene/resources/mesh.h"
|
||||
|
||||
///@TODO probably should change a few integers to unsigned integers...
|
||||
|
||||
/**
|
||||
@author Bastiaan Olij <mux213@gmail.com>
|
||||
|
||||
Base class for all the classes in this file, handles a number of code functions that are shared among all meshes.
|
||||
This class is set appart that it assumes a single surface is always generated for our mesh.
|
||||
*/
|
||||
class PrimitiveMesh : public Mesh {
|
||||
|
||||
GDCLASS(PrimitiveMesh, Mesh);
|
||||
|
||||
private:
|
||||
RID mesh;
|
||||
Rect3 aabb;
|
||||
|
||||
Ref<Material> material;
|
||||
|
||||
bool cache_is_dirty;
|
||||
void _update();
|
||||
|
||||
protected:
|
||||
Mesh::PrimitiveType primitive_type;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
virtual void _create_mesh_array(Array &p_arr) = 0;
|
||||
void _queue_update();
|
||||
|
||||
void set_aabb(Rect3 p_aabb);
|
||||
|
||||
public:
|
||||
virtual int get_surface_count() const;
|
||||
virtual int surface_get_array_len(int p_idx) const;
|
||||
virtual int surface_get_array_index_len(int p_idx) const;
|
||||
virtual Array surface_get_arrays(int p_surface) const;
|
||||
virtual uint32_t surface_get_format(int p_idx) const;
|
||||
virtual Mesh::PrimitiveType surface_get_primitive_type(int p_idx) const;
|
||||
virtual Ref<Material> surface_get_material(int p_idx) const;
|
||||
virtual int get_blend_shape_count() const;
|
||||
virtual StringName get_blend_shape_name(int p_index) const;
|
||||
virtual Rect3 get_aabb() const;
|
||||
virtual RID get_rid() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
PrimitiveMesh();
|
||||
~PrimitiveMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
Mesh for a simple capsule
|
||||
*/
|
||||
class CapsuleMesh : public PrimitiveMesh {
|
||||
GDCLASS(CapsuleMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
float radius;
|
||||
float mid_height;
|
||||
int radial_segments;
|
||||
int rings;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_radius(const float p_radius);
|
||||
float get_radius() const;
|
||||
|
||||
void set_mid_height(const float p_mid_height);
|
||||
float get_mid_height() const;
|
||||
|
||||
void set_radial_segments(const int p_segments);
|
||||
int get_radial_segments() const;
|
||||
|
||||
void set_rings(const int p_rings);
|
||||
int get_rings() const;
|
||||
|
||||
CapsuleMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
Similar to test cube but with subdivision support and different texture coordinates
|
||||
*/
|
||||
class CubeMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(CubeMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
Vector3 size;
|
||||
int subdivide_w;
|
||||
int subdivide_h;
|
||||
int subdivide_d;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_size(const Vector3 &p_size);
|
||||
Vector3 get_size() const;
|
||||
|
||||
void set_subdivide_width(const int p_divisions);
|
||||
int get_subdivide_width() const;
|
||||
|
||||
void set_subdivide_height(const int p_divisions);
|
||||
int get_subdivide_height() const;
|
||||
|
||||
void set_subdivide_depth(const int p_divisions);
|
||||
int get_subdivide_depth() const;
|
||||
|
||||
CubeMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
A cylinder
|
||||
*/
|
||||
|
||||
class CylinderMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(CylinderMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
float top_radius;
|
||||
float bottom_radius;
|
||||
float height;
|
||||
int radial_segments;
|
||||
int rings;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_top_radius(const float p_radius);
|
||||
float get_top_radius() const;
|
||||
|
||||
void set_bottom_radius(const float p_radius);
|
||||
float get_bottom_radius() const;
|
||||
|
||||
void set_height(const float p_height);
|
||||
float get_height() const;
|
||||
|
||||
void set_radial_segments(const int p_segments);
|
||||
int get_radial_segments() const;
|
||||
|
||||
void set_rings(const int p_rings);
|
||||
int get_rings() const;
|
||||
|
||||
CylinderMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
Similar to quadmesh but with tesselation support
|
||||
*/
|
||||
class PlaneMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(PlaneMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
Size2 size;
|
||||
int subdivide_w;
|
||||
int subdivide_d;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_size(const Size2 &p_size);
|
||||
Size2 get_size() const;
|
||||
|
||||
void set_subdivide_width(const int p_divisions);
|
||||
int get_subdivide_width() const;
|
||||
|
||||
void set_subdivide_depth(const int p_divisions);
|
||||
int get_subdivide_depth() const;
|
||||
|
||||
PlaneMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
A prism shapen, handy for ramps, triangles, etc.
|
||||
*/
|
||||
class PrismMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(PrismMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
float left_to_right;
|
||||
Vector3 size;
|
||||
int subdivide_w;
|
||||
int subdivide_h;
|
||||
int subdivide_d;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_left_to_right(const float p_left_to_right);
|
||||
float get_left_to_right() const;
|
||||
|
||||
void set_size(const Vector3 &p_size);
|
||||
Vector3 get_size() const;
|
||||
|
||||
void set_subdivide_width(const int p_divisions);
|
||||
int get_subdivide_width() const;
|
||||
|
||||
void set_subdivide_height(const int p_divisions);
|
||||
int get_subdivide_height() const;
|
||||
|
||||
void set_subdivide_depth(const int p_divisions);
|
||||
int get_subdivide_depth() const;
|
||||
|
||||
PrismMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
Our original quadmesh...
|
||||
*/
|
||||
|
||||
class QuadMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(QuadMesh, PrimitiveMesh)
|
||||
|
||||
private:
|
||||
// nothing? really? Maybe add size some day atleast... :)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
QuadMesh();
|
||||
};
|
||||
|
||||
/**
|
||||
A sphere..
|
||||
*/
|
||||
class SphereMesh : public PrimitiveMesh {
|
||||
|
||||
GDCLASS(SphereMesh, PrimitiveMesh);
|
||||
|
||||
private:
|
||||
float radius;
|
||||
float height;
|
||||
int radial_segments;
|
||||
int rings;
|
||||
bool is_hemisphere;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _create_mesh_array(Array &p_arr);
|
||||
|
||||
public:
|
||||
void set_radius(const float p_radius);
|
||||
float get_radius() const;
|
||||
|
||||
void set_height(const float p_height);
|
||||
float get_height() const;
|
||||
|
||||
void set_radial_segments(const int p_radial_segments);
|
||||
int get_radial_segments() const;
|
||||
|
||||
void set_rings(const int p_rings);
|
||||
int get_rings() const;
|
||||
|
||||
void set_is_hemisphere(const bool p_is_hemisphere);
|
||||
bool get_is_hemisphere() const;
|
||||
|
||||
SphereMesh();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user