Normand Briere
2018-12-15 6ed65dcb597fb2153cef75bf1845978f1115658c
cSpring.java
....@@ -82,7 +82,7 @@
8282
8383 // timestep
8484 double timestep = 1;
85
- double normalpusH = 0; // 1;
85
+ double normalpush = 0; // 1;
8686 static float H0 = 1E1f; // aucune importance...
8787 // mass
8888 double M = 1;
....@@ -967,6 +967,7 @@
967967 for (int i = 0; i < allNodes.size(); i++)
968968 {
969969 DynamicNode dn = allNodes.get(i);
970
+ dn.linked = false;
970971 dn.closestpoint = null;
971972 }
972973 }
....@@ -1057,7 +1058,7 @@
10571058 vect1.set(v);
10581059 LA.xformPos(vect1,toRoot,vect1);
10591060
1060
- handles.get(usedrep.VertexCount()-1-i).set(vect1);
1061
+ handles.get(i).set(vect1);
10611062 }
10621063 }
10631064
....@@ -1416,6 +1417,7 @@
14161417 //transient double rotangle; // Z of axis
14171418 transient boolean reverse = false;
14181419
1420
+ transient boolean linked = false;
14191421 transient Vertex closestpoint = null;
14201422
14211423 //Point3D lastForce = new Point3D();
....@@ -1491,6 +1493,11 @@
14911493 otherForce.add(f.forceOn(this));
14921494 }
14931495 }
1496
+ }
1497
+
1498
+ if (Double.isNaN(springForce.y))
1499
+ {
1500
+ springForce.x = springForce.y = springForce.z = 0;
14941501 }
14951502 }
14961503
....@@ -2325,6 +2332,7 @@
23252332
23262333 abstract Point3D forceOn(DynamicNode N);
23272334 }
2335
+
23282336 Point3D force = new Point3D();
23292337 Point3D dir = new Point3D();
23302338
....@@ -2338,28 +2346,7 @@
23382346 return this;
23392347 }
23402348
2341
- class Avoider extends Force
2342
- {
2343
- static final long serialVersionUID = -8657094699711594990L;
2344
-
2345
- Avoider()
2346
- {
2347
- }
2348
-
2349
- Avoider(Object3D col)
2350
- {
2351
- SetAvoider(col);
2352
- }
2353
-
2354
- void SetParameter(int index, double value)
2355
- {
2356
- parameters.setElementAt(new Double(value), index);
2357
- }
2358
-
2359
- void SetAvoider(Object3D col)
2360
- {
2361
- avoider = col;
2362
- }
2349
+ Object3D avoider;
23632350
23642351 void ResetGlobalTransform()
23652352 {
....@@ -2371,10 +2358,6 @@
23712358
23722359 transient double[][] toRoot; // = new double[4][4];
23732360
2374
- //Vector<Vertex> sortedcollider;
2375
- Object3D avoider;
2376
- Vector<Double> parameters = new Vector<Double>(); // serial issue
2377
-
23782361 Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis)
23792362 {
23802363 if (startindex == endindex)
....@@ -2468,7 +2451,8 @@
24682451
24692452 for (int i=collider.size(); --i>=0;)
24702453 {
2471
- if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0)
2454
+ // Why? 3 dec 2018
2455
+ if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0.5)
24722456 continue;
24732457
24742458 temp.set(N.position);
....@@ -2486,43 +2470,24 @@
24862470 }
24872471 }
24882472
2489
- return cp;
2473
+ return mindist2 < 1 ? cp : null;
24902474 }
24912475
2492
- Point3D forceOn(DynamicNode N)
2476
+ class Avoider extends Force
2477
+ {
2478
+ static final long serialVersionUID = -8657094699711594990L;
2479
+
2480
+ Avoider()
24932481 {
2494
- force.x = 0;
2495
- force.y = 0;
2496
- force.z = 0;
2497
-
2498
- if (avoider.transientrep == null)
2499
- avoider.Revert();
2500
-
2501
- if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
2502
- return force;
2503
-
2504
- ResetGlobalTransform();
2505
- if (N.closestpoint == null)
2506
- {
2507
- //avoider.bRep.GetVertex(0); // "sort"
2508
-
2509
- ResetGlobalTransform();
2510
-
2511
- N.closestpoint = ClosestPoint(avoider.transientrep./*sortedV*/vertices, N, 0,avoider.transientrep./*sortedV*/vertices.size(), 0);
2512
-
2513
- if (N.closestpoint == null) // ????
2514
- return force;
2515
- }
2516
-
2517
- if (avoider == This())
2518
- {
2519
- // good but must freeze the order first... not really...
2520
- // if (cp.index < ((Vertex)N.position).index)
2521
- // return force;
2522
- }
2523
-
2524
- if (normalpusH != 0) // && cp == null /*???*/) // speed == 0)
2525
- {
2482
+ }
2483
+
2484
+ Avoider(Object3D col)
2485
+ {
2486
+ SetAvoider(col);
2487
+ }
2488
+
2489
+ void Avoidance(DynamicNode N)
2490
+ {
25262491 temp.set(N.position);
25272492 if (avoider != This())
25282493 {
....@@ -2530,16 +2495,16 @@
25302495 temp2.mul(0.001);
25312496 temp.sub(temp2); // push outside because of mesh artifacts
25322497 }
2533
-
2498
+
25342499 vect1.set(N.closestpoint);
2535
-
2500
+
25362501 LA.xformPos(vect1,toRoot,vect1);
25372502 //avoider.TransformToWorld(vect1, vect1);
2538
-
2503
+
25392504 temp.sub(vect1);
2540
-
2505
+
25412506 double distance = Math.sqrt(temp.length2());
2542
-
2507
+
25432508 if (distance < 0.01)
25442509 {
25452510 temp2.set(N.closestpoint.norm);
....@@ -2553,9 +2518,98 @@
25532518 if (IsAutoFreeze())
25542519 dot = -dot;
25552520
2556
- temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance));
2521
+ temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance));
25572522 force.add(temp);
25582523 }
2524
+ }
2525
+
2526
+ void Attraction(DynamicNode N)
2527
+ {
2528
+ temp.set(N.position);
2529
+ if (avoider != This())
2530
+ {
2531
+ temp2.set(N.closestpoint.norm);
2532
+ temp2.mul(0.001);
2533
+ temp.sub(temp2); // push outside because of mesh artifacts
2534
+ }
2535
+
2536
+ vect1.set(N.closestpoint);
2537
+
2538
+ LA.xformPos(vect1,toRoot,vect1);
2539
+ //avoider.TransformToWorld(vect1, vect1);
2540
+
2541
+ temp.sub(vect1);
2542
+
2543
+ double distance = Math.sqrt(temp.length2());
2544
+
2545
+ //if (distance < 0.01)
2546
+ {
2547
+ temp2.set(N.closestpoint.norm);
2548
+ double dot = temp2.dot(temp);
2549
+
2550
+// if (dot > 0)
2551
+// dot = 0;
2552
+
2553
+ // normal pushing
2554
+ temp.set(N.closestpoint.norm);
2555
+// if (IsAutoFreeze())
2556
+// dot = -dot;
2557
+
2558
+ temp.mul(normalpush/*/distance*/ * -dot * distance);
2559
+ force.add(temp);
2560
+ }
2561
+ }
2562
+
2563
+ void SetParameter(int index, double value)
2564
+ {
2565
+ parameters.setElementAt(new Double(value), index);
2566
+ }
2567
+
2568
+ void SetAvoider(Object3D col)
2569
+ {
2570
+ avoider = col;
2571
+ }
2572
+
2573
+ //Vector<Vertex> sortedcollider;
2574
+ Vector<Double> parameters = new Vector<Double>(); // serial issue
2575
+
2576
+ Point3D forceOn(DynamicNode N)
2577
+ {
2578
+ force.x = 0;
2579
+ force.y = 0;
2580
+ force.z = 0;
2581
+
2582
+ if (avoider.transientrep == null)
2583
+ avoider.Revert();
2584
+
2585
+ if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
2586
+ return force;
2587
+
2588
+ ResetGlobalTransform();
2589
+ if (!N.linked)
2590
+ {
2591
+ //avoider.bRep.GetVertex(0); // "sort"
2592
+
2593
+ ResetGlobalTransform();
2594
+
2595
+ N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0);
2596
+ N.linked = true;
2597
+ }
2598
+
2599
+ if (avoider == This())
2600
+ {
2601
+ // good but must freeze the order first... not really...
2602
+ // if (cp.index < ((Vertex)N.position).index)
2603
+ // return force;
2604
+ }
2605
+
2606
+ if (normalpush != 0) // && cp == null /*???*/) // speed == 0)
2607
+ {
2608
+ if (N.closestpoint == null)
2609
+ return force;
2610
+
2611
+ //Avoidance(N);
2612
+ Attraction(N);
25592613 }
25602614
25612615 if (parameters.size() > 0)
....@@ -2589,6 +2643,7 @@
25892643 totalforce = new Point3D();
25902644
25912645 totalforce.set(0,0,0);
2646
+
25922647 if (forces.size() == 0)
25932648 totalforce.set(super.forceOn(N));
25942649
....@@ -2659,7 +2714,7 @@
26592714 force.y = 0;
26602715 force.z = 0;
26612716
2662
- if (normalpusH != 0) // speed == 0) // Now normal force
2717
+ if (normalpush != 0) // speed == 0) // Now normal force
26632718 {
26642719 // temp.set(N.position);
26652720 // temp.sub(Phys.reference);
....@@ -2667,7 +2722,7 @@
26672722
26682723 // normal pushing
26692724 temp.set(N.normal);
2670
- temp.mul(normalpusH/distance);
2725
+ temp.mul(normalpush/distance);
26712726 force.add(temp);
26722727 }
26732728
....@@ -2899,6 +2954,7 @@
28992954 return force;
29002955 }
29012956 }
2957
+
29022958 static int TABLESAC = 1024;
29032959 static double[] tablesac = new double[TABLESAC];
29042960
....@@ -2992,6 +3048,40 @@
29923048 // mass = M;
29933049 } // ???
29943050
3051
+ if (avoider != null)
3052
+ {
3053
+ if (avoider.transientrep == null)
3054
+ avoider.Revert();
3055
+
3056
+ if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
3057
+ return force;
3058
+
3059
+ ResetGlobalTransform();
3060
+ if (!N.linked)
3061
+ {
3062
+ //avoider.bRep.GetVertex(0); // "sort"
3063
+
3064
+ //ResetGlobalTransform();
3065
+
3066
+ N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0);
3067
+ N.linked = true;
3068
+ }
3069
+
3070
+ if (N.closestpoint != null)
3071
+ {
3072
+ temp.set(N.position);
3073
+ vect1.set(N.closestpoint);
3074
+ LA.xformPos(vect1,toRoot,vect1);
3075
+ temp.sub(vect1);
3076
+
3077
+ temp2.set(N.closestpoint.norm);
3078
+ double dot = temp2.dot(temp);
3079
+
3080
+ if (dot < 0)
3081
+ mass = Float.NaN;
3082
+ }
3083
+ }
3084
+
29953085 force.x = 0;
29963086 force.y = (float) (-acceleration * mass);
29973087 force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); //
....@@ -3188,7 +3278,7 @@
31883278 }
31893279 if (false) // isHandle)
31903280 {
3191
- double K = Math.exp(-displacement*normalpusH);
3281
+ double K = Math.exp(-displacement*normalpush);
31923282 magnitude /= (displacement*(1-K) + K);
31933283 }
31943284