summaryrefslogtreecommitdiff
path: root/scene/resources/shape.cpp
diff options
context:
space:
mode:
authorAnton Yabchinskiy <arn@bestmx.ru>2015-11-02 20:25:01 +0300
committerAnton Yabchinskiy <arn@bestmx.ru>2015-11-02 20:25:01 +0300
commit3b9868d2e44740c03861c64020a8b5d4d6da031d (patch)
tree8ff5f9671122f946487848ce286d336c9b650c2c /scene/resources/shape.cpp
parentdc8df8a91a995796f0f330bf6bb6b209f6dfce08 (diff)
parentb2f9acb8c96aed0505cbac21661e21e4acef710f (diff)
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'scene/resources/shape.cpp')
-rw-r--r--scene/resources/shape.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp
index 1120a8d672..143ef82d51 100644
--- a/scene/resources/shape.cpp
+++ b/scene/resources/shape.cpp
@@ -29,9 +29,67 @@
#include "shape.h"
#include "servers/physics_server.h"
+#include "scene/resources/mesh.h"
+#include "os/os.h"
+#include "scene/main/scene_main_loop.h"
+void Shape::add_vertices_to_array(DVector<Vector3> &array, const Transform& p_xform) {
+ Vector<Vector3> toadd = _gen_debug_mesh_lines();
+
+ if (toadd.size()) {
+
+ int base=array.size();
+ array.resize(base+toadd.size());
+ DVector<Vector3>::Write w = array.write();
+ for(int i=0;i<toadd.size();i++) {
+ w[i+base]=p_xform.xform(toadd[i]);
+ }
+
+ }
+}
+
+Ref<Mesh> Shape::get_debug_mesh() {
+
+ if (debug_mesh_cache.is_valid())
+ return debug_mesh_cache;
+
+ Vector<Vector3> lines = _gen_debug_mesh_lines();
+
+ debug_mesh_cache = Ref<Mesh>(memnew(Mesh));
+
+ if (!lines.empty()) {
+ //make mesh
+ DVector<Vector3> array;
+ array.resize(lines.size());
+ {
+
+ DVector<Vector3>::Write w=array.write();
+ for(int i=0;i<lines.size();i++) {
+ w[i]=lines[i];
+ }
+ }
+
+ Array arr;
+ arr.resize(Mesh::ARRAY_MAX);
+ arr[Mesh::ARRAY_VERTEX]=array;
+
+ SceneTree *st=OS::get_singleton()->get_main_loop()->cast_to<SceneTree>();
+
+ debug_mesh_cache->add_surface(Mesh::PRIMITIVE_LINES,arr);
+
+ if (st) {
+ debug_mesh_cache->surface_set_material(0,st->get_debug_collision_material());
+ }
+
+ }
+
+
+
+ return debug_mesh_cache;
+
+}
Shape::Shape() {
@@ -49,3 +107,4 @@ Shape::~Shape() {
PhysicsServer::get_singleton()->free(shape);
}
+