[Bf-blender-cvs] [96161c80edd] temp-fracture-modifier-2.8: added duplis as fracture "source"
Martin Felke
noreply at git.blender.org
Thu Nov 29 18:57:36 CET 2018
Commit: 96161c80edde92b83fdc23df97be40b331cff6df
Author: Martin Felke
Date: Thu Nov 29 18:54:50 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB96161c80edde92b83fdc23df97be40b331cff6df
added duplis as fracture "source"
this basically converts e.g. particle duplis to individual rigidbodies
===================================================================
M intern/rigidbody/rb_bullet_api.cpp
M release/scripts/startup/bl_ui/properties_physics_fracture.py
M source/blender/blenkernel/BKE_fracture.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_dynamic.c
M source/blender/blenkernel/intern/fracture_external.c
M source/blender/blenkernel/intern/fracture_prefractured.c
M source/blender/blenkernel/intern/fracture_rigidbody.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/makesdna/DNA_fracture_types.h
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_fracture.c
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index defe28f207b..898d7dbfec0 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -60,6 +60,7 @@ subject to the following restrictions:
#include <errno.h>
#include <iomanip>
#include <sstream>
+#include <vector>
#include "RBI_api.h"
@@ -97,18 +98,48 @@ struct ViewportDebugDraw : public btIDebugDraw
DBG_DrawImpulses = 1 << 15,
};
+//taken from internet, lol
+ struct _LINE {
+ btVector3 from;
+ btVector3 to;
+
+ _LINE(btVector3 f, btVector3 t) {
+ from = f;
+ to = t;
+ }
+ };
+
+ std::vector<_LINE> LINES;
+
+ struct _COLOR {
+ btVector3 col;
+
+ _COLOR(btVector3 c) {
+ col = c;
+ }
+ };
+
+ std::vector<_COLOR> COLORS;
+
+ GLuint vao, vbo[2];
+
+
int m_debugMode;
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
if (m_debugMode >0)
{
+#if 0
//draw lines, TODO, crashes on newer OpenGL ? hmmm
glBegin(GL_LINES);
glColor4f(color[0], color[1], color[2], 1.0f);
glVertex3fv(from);
glVertex3fv(to);
glEnd();
+#endif
+ LINES.push_back(_LINE(from, to));
+ COLORS.push_back(_COLOR(color));
}
}
@@ -137,6 +168,62 @@ struct ViewportDebugDraw : public btIDebugDraw
}
+ void do_drawing() {
+
+#if 0
+ // Debug drawing
+ ///////////////////////////
+ vector<GLfloat> vertices;
+ vector<GLuint> indices;
+ unsigned int indexI = 0;
+
+ for (vector<ViewportDebugDraw::_LINE>::iterator it = LINES.begin(); it != LINES.end(); it++)
+ {
+ ViewportDebugDraw::_LINE l = *it;
+
+ vertices.push_back(l.from.x);
+ vertices.push_back(l.from.y);
+ vertices.push_back(l.from.z);
+
+ vertices.push_back(l.to.x);
+ vertices.push_back(l.to.y);
+ vertices.push_back(l.to.z);
+
+ indices.push_back(indexI);
+ indices.push_back(indexI + 1);
+ indexI += 2;
+ }
+#endif
+ //glDrawElements(GL_LINES, indices.size(), GL_UNSIGNED_INT, (void*)&indices[0]);
+
+
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ glGenBuffers(2, vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
+ glBufferData(GL_ARRAY_BUFFER, LINES.size() * sizeof(_LINE), &LINES[0], GL_STATIC_DRAW);
+ glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(0);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
+ glBufferData(GL_ARRAY_BUFFER, COLORS.size() * sizeof(_COLOR), &COLORS[0], GL_STATIC_DRAW);
+ glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(1);
+
+ glDrawArrays(GL_LINES, 0, LINES.size() * 2);
+
+ LINES.clear();
+ COLORS.clear();
+
+ glBindVertexArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+
+
+ ///////////////////////////
+ }
+
};
@@ -276,6 +363,9 @@ void CallbackDynamicsWorld::debugDrawWorld(draw_string str_callback)
}
}
}
+
+ ViewportDebugDraw *drawer = (ViewportDebugDraw*)getDebugDrawer();
+ drawer->do_drawing();
}
static const char* val_to_str(rbConstraint* con, int precision, int *length)
diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index cab15cb65b5..3fa6ea11170 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -75,6 +75,8 @@ class PHYSICS_PT_fracture_advanced(PhysicButtonsPanel, Panel):
layout.use_property_split = True
flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True);
col = flow.column()
+ col.prop(md, "use_dupli")
+ col.prop(md, "dupli_input")
col.prop(md, "point_source")
if 'GRID' in md.point_source:
col.prop(md, "grid_resolution")
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 38acd4abfdd..eaa52b25ce8 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -142,7 +142,7 @@ struct Mesh* BKE_fracture_assemble_mesh_from_islands(struct FractureModifierData
void BKE_fracture_modifier_free(struct FractureModifierData *fmd, struct Scene *scene);
-void BKE_fracture_mesh_island_free(struct Shard *mi, struct Scene* scene);
+void BKE_fracture_mesh_island_free(struct FractureModifierData *fmd, struct Shard *mi, struct Scene* scene);
short BKE_fracture_collect_materials(struct Main* bmain, struct Object* o, struct Object* ob, int matstart, struct GHash** mat_index_map);
@@ -179,5 +179,11 @@ void BKE_fracture_copy_customdata(struct CustomData* src, struct CustomData* dst
int copyelem, int totelem);
bool BKE_fracture_check_valid_shard(struct FractureModifierData *fmd, struct Shard *mi, struct Scene *scene);
+void BKE_fracture_duplis_to_shards(struct FractureModifierData *fmd, struct Object *ob, struct Scene *scene,
+ struct Depsgraph *depsgraph, struct Main *bmain, int frame);
+
+bool BKE_fracture_handle_initial_shards(struct FractureModifierData* fmd, struct Object* ob,
+ struct Depsgraph *depsgraph, struct Main* bmain,
+ struct Scene* scene, int frame);
#endif /* BKE_FRACTURE_H */
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d8e946e8269..356fb7ae775 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -33,7 +33,9 @@
#include <stdlib.h>
#include "MEM_guardedalloc.h"
+#include "BLI_listbase.h" // for BKE_anim.h
+#include "BKE_anim.h" //for dupli
#include "BKE_collection.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
@@ -60,6 +62,7 @@
#include "BLI_sort.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
+#include "BLI_ghash.h" //for dupli shard map
#include "DNA_scene_types.h"
#include "DNA_fracture_types.h"
@@ -560,7 +563,7 @@ static void process_cells(FractureModifierData* fmd, Shard* mii, Object* ob, Sce
if (fmd->shared->last_islands[k])
{
BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[k]);
- BKE_fracture_mesh_island_free(fmd->shared->last_islands[k], scene);
+ BKE_fracture_mesh_island_free(fmd, fmd->shared->last_islands[k], scene);
}
}
@@ -958,6 +961,7 @@ void BKE_fracture_postprocess_meshisland(FractureModifierData *fmd, Object* ob,
//BKE_rigidbody_shard_validate(scene->rigidbody_world, result, ob, fmd, true,
// true, size, frame);
+
// try with delayed validation; next frame before next bullet step from rigidbody depsgraph eval thread
if (!(result->rigidbody->flag & RBO_FLAG_KINEMATIC))
{
@@ -1009,7 +1013,7 @@ static Shard* fracture_cutter_process(FractureModifierData* fmd, Object *obA, Me
//exchange difference against original mesh
if (temp_meshs[1]) {
BLI_remlink(&fmd->shared->shards, miB);
- BKE_fracture_mesh_island_free(miB, scene);
+ BKE_fracture_mesh_island_free(fmd, miB, scene);
miB = BKE_fracture_mesh_island_create(temp_meshs[1], scene, obB, frame);
BLI_addtail(&fmd->shared->shards, miB);
temp_meshs[1] = NULL;
@@ -1247,6 +1251,7 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, Scene *scene)
int endframe = 250;
int frame = 0;
Shard *mi, *next;
+ bool dynamic = false;
BLI_listbase_clear(&fmd->shared->dynamic_fracture_queue);
@@ -1259,7 +1264,7 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, Scene *scene)
}
mi = fmd->shared->shards.first;
- bool dynamic = fmd->flag & MOD_FRACTURE_USE_DYNAMIC;
+ dynamic = fmd->flag & MOD_FRACTURE_USE_DYNAMIC;
while (mi) {
/*delete non-initial shards on dynamic refresh, or the non-intial prefracture shards*/
@@ -1267,7 +1272,7 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, Scene *scene)
{
next = mi->next;
BLI_remlink(&fmd->shared->shards, mi);
- BKE_fracture_mesh_island_free(mi, scene);
+ BKE_fracture_mesh_island_free(fmd, mi, scene);
mi = next;
}
else {
@@ -1306,13 +1311,23 @@ Mesh* BKE_fracture_assemble_mesh_from_islands(FractureModifierData* fmd, Object*
Mesh *mesh = NULL;
int vertstart, polystart, loopstart, edgestart, num_verts, num_polys, num_loops, num_edges;
vertstart = polystart = loopstart = edgestart = num_verts = num_polys = num_loops = num_edges = 0;
+ bool dupli = (fmd->flag & MOD_FRACTURE_USE_DUPLI) && fmd->dupli_ob && fmd->shared->dupli_shard_map;
+
for (mi = fmd->shared->shards.first; mi; mi = mi->next)
{
+ //printf("MI ID %d\n", mi->id);
if (BKE_fracture_meshisland_check_frame(fmd, mi, (int)ctime)) {
continue;
}
+ if (dupli) {
+ if (!BLI_ghash_lookup(fmd->shared->dupli_shard_map, mi->id))
+ {
+ continue;
+ }
+ }
+
num_verts += mi->mesh->totvert;
num_polys += mi->mesh->totpoly;
num_loops += mi->mesh->totloop;
@@ -1343,6 +1358,13 @@ Mesh* BKE_fracture_assemble_mesh_from_islands(FractureModifierData* fmd, Object*
continue;
}
+ if (dupli) {
+ if (!BLI_ghash_lookup(fmd->shared->dupli_shard_map, POINTER_FROM_INT(mi->id)))
+ {
+ continue;
+ }
+ }
+
memcpy(mesh->mvert + vertstart, mi->mesh->mvert, mi->mesh->totvert * sizeof(MVert));
invert_qt_qt(irot, mi->rot);
@@ -1864,7 +1886,7 @@ void BKE_fracture_meshislands_free(FractureModifierData* fmd, Scene* scene)
while (fmd->shared->shards.first) {
mi = fmd->shared->shards.first;
BLI_remlink_safe(&fmd->shared->shards, mi);
- BKE_fracture_mesh_island_free(mi, scene);
+ BKE_fracture_mesh_island_free(fmd, mi, scene);
mi = NULL;
}
@@ -1928,7 +1950,7 @@ void BKE_fracture_modifier_free(FractureModifierData *fmd, Scene *scene)
for (j = 0; j < fmd->shared->last_islands_count; j++)
{
BLI_remlink(&fmd->shared->shards, fmd->shared->last_islands[j]);
- BKE_fracture_mesh_island_free(fmd->shared->last_islands[j], scene);
+ BKE_fracture_mesh_island_free(fmd, fmd->shared->last_islands[j], scene);
}
MEM_freeN(fmd->shared->last_islands);
@@ -1941,6 +1963,17 @@ void BKE_fracture_modifier_free(FractureModifierData *fmd, Scene *scene)
BLI_rng_free(fmd->shared->rng);
fmd->shared-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list