summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-11-22 01:26:56 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-11-22 01:26:56 -0300
commit943d27f46ded993105928c4a46414aa16d84115e (patch)
treea92784b738f4a25cd332afc725ac4f52523f2336 /scene
parent70d095d8f201bd83a7106015f8f925ec54a8313c (diff)
Instancing is working! (hooray)
Diffstat (limited to 'scene')
-rw-r--r--scene/main/viewport.cpp16
-rw-r--r--scene/resources/multimesh.cpp43
-rw-r--r--scene/resources/multimesh.h5
3 files changed, 4 insertions, 60 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0ca72eaa2a..bd5eb0a4e6 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -462,22 +462,6 @@ void Viewport::_notification(int p_what) {
VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,point_count);
- if (point_count>0) {
- AABB aabb;
-
- Transform t;
- for(int i=0;i<point_count;i++) {
-
- if (i==0)
- aabb.pos=points[i];
- else
- aabb.expand_to(points[i]);
- t.origin=points[i];
- VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh,i,t);
- }
- aabb.grow(aabb.get_longest_axis_size()*0.01);
- VisualServer::get_singleton()->multimesh_set_custom_aabb(contact_3d_debug_multimesh,aabb);
- }
}
diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp
index 0a005d8c54..8515cd28a3 100644
--- a/scene/resources/multimesh.cpp
+++ b/scene/resources/multimesh.cpp
@@ -174,45 +174,13 @@ Color MultiMesh::get_instance_color(int p_instance) const {
}
-void MultiMesh::set_aabb(const AABB& p_aabb) {
- aabb=p_aabb;
- VisualServer::get_singleton()->multimesh_set_custom_aabb(multimesh,p_aabb);
-
-
-}
AABB MultiMesh::get_aabb() const {
- return aabb;
+ return VisualServer::get_singleton()->multimesh_get_aabb(multimesh);
}
-void MultiMesh::generate_aabb() {
-
-
-
- ERR_EXPLAIN("Cannot generate AABB if mesh is null.");
- ERR_FAIL_COND(mesh.is_null());
-
- AABB base_aabb=mesh->get_aabb();
-
- aabb=AABB();
-
- int instance_count = get_instance_count();
- for(int i=0;i<instance_count;i++) {
-
-
- Transform xform = get_instance_transform(i);
- if(i==0)
- aabb=xform.xform(base_aabb);
- else
- aabb.merge_with(xform.xform(base_aabb));
-
- }
-
- set_aabb(aabb);
-
-}
RID MultiMesh::get_rid() const {
@@ -256,10 +224,8 @@ void MultiMesh::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_instance_transform","instance"),&MultiMesh::get_instance_transform);
ObjectTypeDB::bind_method(_MD("set_instance_color","instance","color"),&MultiMesh::set_instance_color);
ObjectTypeDB::bind_method(_MD("get_instance_color","instance"),&MultiMesh::get_instance_color);
- ObjectTypeDB::bind_method(_MD("set_aabb","visibility_aabb"),&MultiMesh::set_aabb);
ObjectTypeDB::bind_method(_MD("get_aabb"),&MultiMesh::get_aabb);
- ObjectTypeDB::bind_method(_MD("generate_aabb"),&MultiMesh::generate_aabb);
ObjectTypeDB::bind_method(_MD("_set_transform_array"),&MultiMesh::_set_transform_array);
ObjectTypeDB::bind_method(_MD("_get_transform_array"),&MultiMesh::_get_transform_array);
@@ -268,15 +234,14 @@ void MultiMesh::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT,"color_format",PROPERTY_HINT_ENUM,"None,Byte,Float"), _SCS("set_color_format"), _SCS("get_color_format"));
- ADD_PROPERTY(PropertyInfo(Variant::INT,"transform_format",PROPERTY_HINT_ENUM,"None,2D,3D"), _SCS("set_transform_format"), _SCS("get_transform_format"));
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"transform_format",PROPERTY_HINT_ENUM,"2D,3D"), _SCS("set_transform_format"), _SCS("get_transform_format"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"instance_count",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_instance_count"), _SCS("get_instance_count"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"mesh",PROPERTY_HINT_RESOURCE_TYPE,"Mesh"), _SCS("set_mesh"), _SCS("get_mesh"));
- ADD_PROPERTY(PropertyInfo(Variant::_AABB,"aabb"), _SCS("set_aabb"), _SCS("get_aabb") );
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3_ARRAY,"transform_array",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_transform_array"), _SCS("_get_transform_array"));
ADD_PROPERTY(PropertyInfo(Variant::COLOR_ARRAY,"color_array",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_color_array"), _SCS("_get_color_array"));
- BIND_CONSTANT( TRANSFORM_NONE );
+
BIND_CONSTANT( TRANSFORM_2D );
BIND_CONSTANT( TRANSFORM_3D );
BIND_CONSTANT( COLOR_NONE );
@@ -289,7 +254,7 @@ MultiMesh::MultiMesh() {
multimesh = VisualServer::get_singleton()->multimesh_create();
color_format=COLOR_NONE;
- transform_format=TRANSFORM_NONE;
+ transform_format=TRANSFORM_2D;
}
MultiMesh::~MultiMesh() {
diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h
index be4ee38fcd..5e28900c32 100644
--- a/scene/resources/multimesh.h
+++ b/scene/resources/multimesh.h
@@ -39,7 +39,6 @@ class MultiMesh : public Resource {
public:
enum TransformFormat {
- TRANSFORM_NONE = VS::MULTIMESH_TRANSFORM_NONE,
TRANSFORM_2D = VS::MULTIMESH_TRANSFORM_2D,
TRANSFORM_3D = VS::MULTIMESH_TRANSFORM_3D
};
@@ -50,7 +49,6 @@ public:
COLOR_FLOAT = VS::MULTIMESH_COLOR_FLOAT,
};
private:
- AABB aabb;
Ref<Mesh> mesh;
RID multimesh;
TransformFormat transform_format;
@@ -87,11 +85,8 @@ public:
void set_instance_color(int p_instance, const Color& p_color);
Color get_instance_color(int p_instance) const;
- void set_aabb(const AABB& p_aabb);
virtual AABB get_aabb() const;
- void generate_aabb();
-
virtual RID get_rid() const;
MultiMesh();