[Bf-blender-cvs] [ef42d29b8a9] soc-2022-soft-bodies: Added unit tests for testing different phases of collision

Aarnav Dhanuka noreply at git.blender.org
Sat Dec 10 16:56:50 CET 2022


Commit: ef42d29b8a9382d0839b72c648f5ec3eb76e9332
Author: Aarnav Dhanuka
Date:   Sat Dec 10 15:21:58 2022 +0000
Branches: soc-2022-soft-bodies
https://developer.blender.org/rBef42d29b8a9382d0839b72c648f5ec3eb76e9332

Added unit tests for testing different phases of collision

===================================================================

A	source/blender/blenkernel/BKE_softbody copy.h
A	source/blender/blenkernel/intern/softbody copy.c
A	source/blender/makesdna/DNA_object_force_types copy.h
A	source/blender/modifiers/intern/MOD_weld copy.cc
M	source/blender/modifiers/intern/MOD_weld.cc
M	source/blender/simulation/intern/xpbd.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_softbody copy.h b/source/blender/blenkernel/BKE_softbody copy.h
new file mode 100644
index 00000000000..09b18d3a731
--- /dev/null
+++ b/source/blender/blenkernel/BKE_softbody copy.h	
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright Blender Foundation. All rights reserved. */
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Depsgraph;
+struct Object;
+struct Scene;
+struct SoftBody;
+
+typedef struct BodyPoint {
+  float origS[3], origE[3], origT[3], pos[3], vec[3], force[3];
+  float goal;
+  float prevpos[3], prevvec[3], prevdx[3], prevdv[3]; /* used for Heun integration */
+  float impdv[3], impdx[3];
+  int nofsprings;
+  int *springs;
+  float choke, choke2, frozen;
+  float colball;
+  short loc_flag; /* reserved by locale module specific states */
+  // char octantflag;
+  float mass;
+  float springweight;
+} BodyPoint;
+
+/**
+ * Allocates and initializes general main data.
+ */
+extern struct SoftBody *sbNew(void);
+
+/**
+ * Frees internal data and soft-body itself.
+ */
+extern void sbFree(struct Object *ob);
+
+/**
+ * Frees simulation data to reset simulation.
+ */
+extern void sbFreeSimulation(struct SoftBody *sb);
+
+/**
+ * Do one simulation step, reading and writing vertex locs from given array.
+ * */
+extern void sbObjectStep(struct Depsgraph *depsgraph,
+                         struct Scene *scene,
+                         struct Object *ob,
+                         float cfra,
+                         float (*vertexCos)[3],
+                         int numVerts);
+
+/**
+ * Makes totally fresh start situation, resets time.
+ */
+extern void sbObjectToSoftbody(struct Object *ob);
+
+/**
+ * Soft-body global visible functions.
+ * Links the soft-body module to a 'test for Interrupt' function, pass NULL to clear the callback.
+ */
+extern void sbSetInterruptCallBack(int (*f)(void));
+
+/**
+ * A precise position vector denoting the motion of the center of mass give a rotation/scale matrix
+ * using averaging method, that's why estimate and not calculate see: this is kind of reverse
+ * engineering: having to states of a point cloud and recover what happened our advantage here we
+ * know the identity of the vertex there are others methods giving other results.
+ *
+ * \param ob: Any object that can do soft-body e.g. mesh, lattice, curve.
+ * \param lloc: Output of the calculated location (or NULL).
+ * \param lrot: Output of the calculated rotation (or NULL).
+ * \param lscale: Output for the calculated scale (or NULL).
+ *
+ * For velocity & 2nd order stuff see: #vcloud_estimate_transform_v3.
+ */
+extern void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float lscale[3][3]);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/intern/softbody copy.c b/source/blender/blenkernel/intern/softbody copy.c
new file mode 100644
index 00000000000..8a90e7123dc
--- /dev/null
+++ b/source/blender/blenkernel/intern/softbody copy.c	
@@ -0,0 +1,3630 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup bke
+ */
+
+/**
+ * variables on the UI for now
+ * <pre>
+ * float mediafrict;  friction to env
+ * float nodemass;    softbody mass of *vertex*
+ * float grav;        softbody amount of gravitation to apply
+ *
+ * float goalspring;  softbody goal springs
+ * float goalfrict;   softbody goal springs friction
+ * float mingoal;     quick limits for goal
+ * float maxgoal;
+ *
+ * float inspring;    softbody inner springs
+ * float infrict;     softbody inner springs friction
+ * </pre>
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "CLG_log.h"
+
+#include "MEM_guardedalloc.h"
+
+/* types */
+#include "DNA_collection_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_force_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_threads.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_collection.h"
+#include "BKE_collision.h"
+#include "BKE_curve.h"
+#include "BKE_deform.h"
+#include "BKE_effect.h"
+#include "BKE_global.h"
+#include "BKE_layer.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+#include "BKE_pointcache.h"
+#include "BKE_scene.h"
+#include "BKE_softbody.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "PIL_time.h"
+
+static CLG_LogRef LOG = {"bke.softbody"};
+
+/* callbacks for errors and interrupts and some goo */
+static int (*SB_localInterruptCallBack)(void) = NULL;
+
+/* ********** soft body engine ******* */
+
+typedef enum { SB_EDGE = 1, SB_BEND = 2, SB_STIFFQUAD = 3, SB_HANDLE = 4 } type_spring;
+
+typedef struct BodySpring {
+  int v1, v2;
+  float len, cf, load;
+  float ext_force[3]; /* edges colliding and sailing */
+  type_spring springtype;
+  short flag;
+} BodySpring;
+
+typedef struct BodyFace {
+  int v1, v2, v3;
+  float ext_force[3]; /* faces colliding */
+  short flag;
+} BodyFace;
+
+typedef struct ReferenceVert {
+  float pos[3]; /* position relative to com */
+  float mass;   /* node mass */
+} ReferenceVert;
+
+typedef struct ReferenceState {
+  float com[3];         /* Center of mass. */
+  ReferenceVert *ivert; /* List of initial values. */
+} ReferenceState;
+
+/* Private scratch pad for caching and other data only needed when alive. */
+typedef struct SBScratch {
+  GHash *colliderhash;
+  short needstobuildcollider;
+  short flag;
+  BodyFace *bodyface;
+  int totface;
+  float aabbmin[3], aabbmax[3];
+  ReferenceState Ref;
+} SBScratch;
+
+typedef struct SB_thread_context {
+  Scene *scene;
+  Object *ob;
+  float forcetime;
+  float timenow;
+  int ifirst;
+  int ilast;
+  ListBase *effectors;
+  int do_deflector;
+  float fieldfactor;
+  float windfactor;
+  int nr;
+  int tot;
+} SB_thread_context;
+
+#define MID_PRESERVE 1
+
+#define SOFTGOALSNAP 0.999f
+/* if bp-> goal is above make it a *forced follow original* and skip all ODE stuff for this bp
+ * removes *unnecessary* stiffness from ODE system
+ */
+#define HEUNWARNLIMIT 1 /* 500 would be fine i think for detecting severe *stiff* stuff */
+
+#define BSF_INTERSECT 1 /* edge intersects collider face */
+
+/* private definitions for bodypoint states */
+#define SBF_DOFUZZY 1        /* Bodypoint do fuzzy. */
+#define SBF_OUTOFCOLLISION 2 /* Bodypoint does not collide. */
+
+#define BFF_INTERSECT 1 /* collider edge   intrudes face. */
+#define BFF_CLOSEVERT 2 /* collider vertex repulses face. */
+
+/* humm .. this should be calculated from sb parameters and sizes. */
+static float SoftHeunTol = 1.0f;
+
+/* local prototypes */
+static void free_softbody_intern(SoftBody *sb);
+
+/*+++ frame based timing +++ */
+
+/* Physical unit of force is `kg * m / sec^2`. */
+
+/**
+ * Since unit of g is [m/sec^2] and F = mass * g we re-scale unit mass of node to 1 gram
+ * put it to a function here, so we can add user options later without touching simulation code.
+ */
+static float sb_grav_force_scale(Object *UNUSED(ob))
+{
+  return (0.001f);
+}
+
+/**
+ * Re-scaling unit of drag [1 / sec] to somehow reasonable
+ * put it to a function here, so we can add user options later without touching simulation code.
+ */
+static float sb_fric_force_scale(Object *UNUSED(ob))
+{
+  return (0.01f);
+}
+
+/**
+ * Defining the frames to *real* time relation.
+ */
+static float sb_time_scale(Object *ob)
+{
+  SoftBody *sb = ob->soft; /* is supposed to be there */
+  if (sb) {
+    return (sb->physics_speed);
+    /* hrms .. this could be IPO as well :)
+     * estimated range [0.001 sluggish slug - 100.0 very fast (i hope ODE solver can handle that)]
+     * 1 approx = a unit 1 pendulum at g = 9.8 [earth conditions]  has period 65 frames
+     * theory would give a 50 frames period .. so there must be something inaccurate ..
+     * looking for that (BM). */
+  }
+  return (1.0f);
+  /*
+   * this would be frames/sec independent timing assuming 25 fps is default
+   * but does not work very well with NLA
+   * return (25.0f/scene->r.frs_sec)
+   */
+}
+/*--- frame based timing ---*/
+
+/* helper functions for everything is animatable jow_go_for2_5 +++++++ */
+/* introducing them here, because i know: steps in properties  ( at frame timing )
+ * will cause unwanted responses of the softbody system (which does inter frame calculations )
+ * so first 'cure' would be: interpolate linear in time ..
+ * Q: why do i write this?
+ * A: because it happened once, that some eager coder 'streamlined' code to fail.
+ * We DO linear interpolation for goals .. and i think we should do on animated properties as well
+ */
+
+/* animate sb->maxgoal, sb->mingoal */
+static float _final_goal(Object *ob, BodyPoint *bp) /* jow_go_for2_5 */
+{
+  float f = -1999.99f;
+  if (ob) {
+    SoftBody *sb = ob->soft; /* is supposed to be there */
+    if (!(ob->softflag & OB_SB_GOAL)) {
+      return (0.0f);
+    }
+    if (sb && bp) {
+      if (bp->goal < 0.0f) {
+        return (0.0f);
+      }
+      f = sb->mingoal + bp->goal * fabsf(sb->maxgoal - sb->mingoal);
+      f = pow(f, 4.0f);
+      return f;
+    }
+  }
+  CLOG_ERROR(&LOG, "sb or bp == NULL");
+  return f; /* Using crude but spot able values some times helps debugging. */
+}
+
+static float _final_mass(Object *ob, BodyPoint *bp)
+{
+  if (ob) {
+    SoftBody *sb = ob->soft; /* is supposed to be there */
+    if (sb && bp) {
+      return (bp->mass * sb->nodemass);
+    }
+  }
+  CLOG_ERROR(&LOG, "sb or bp == NULL");
+  return 1.0f;
+}
+/* helper functions for everything is animateble jow_go_for2_5 ------*/
+
+/* +++ collider caching and dicing +++ */
+
+/*
+ * for each target object/face the axis aligned bounding box (AABB) is stored
+ * faces parallel to global axes
+ * so only simple "value" in [min, max] checks are used
+ * float operations still
+ */
+
+/* just an ID here to reduce the prob for killing objects
+ * ob->sumohandle points to we should not kill :)
+ */
+static const int CCD_SAFETY = 190561;
+
+typedef s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list