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 }
....@@ -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
....@@ -2339,28 +2346,7 @@
23392346 return this;
23402347 }
23412348
2342
- class Avoider extends Force
2343
- {
2344
- static final long serialVersionUID = -8657094699711594990L;
2345
-
2346
- Avoider()
2347
- {
2348
- }
2349
-
2350
- Avoider(Object3D col)
2351
- {
2352
- SetAvoider(col);
2353
- }
2354
-
2355
- void SetParameter(int index, double value)
2356
- {
2357
- parameters.setElementAt(new Double(value), index);
2358
- }
2359
-
2360
- void SetAvoider(Object3D col)
2361
- {
2362
- avoider = col;
2363
- }
2349
+ Object3D avoider;
23642350
23652351 void ResetGlobalTransform()
23662352 {
....@@ -2372,10 +2358,6 @@
23722358
23732359 transient double[][] toRoot; // = new double[4][4];
23742360
2375
- //Vector<Vertex> sortedcollider;
2376
- Object3D avoider;
2377
- Vector<Double> parameters = new Vector<Double>(); // serial issue
2378
-
23792361 Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis)
23802362 {
23812363 if (startindex == endindex)
....@@ -2469,7 +2451,8 @@
24692451
24702452 for (int i=collider.size(); --i>=0;)
24712453 {
2472
- 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)
24732456 continue;
24742457
24752458 temp.set(N.position);
....@@ -2487,43 +2470,24 @@
24872470 }
24882471 }
24892472
2490
- return cp;
2473
+ return mindist2 < 1 ? cp : null;
24912474 }
24922475
2493
- Point3D forceOn(DynamicNode N)
2476
+ class Avoider extends Force
2477
+ {
2478
+ static final long serialVersionUID = -8657094699711594990L;
2479
+
2480
+ Avoider()
24942481 {
2495
- force.x = 0;
2496
- force.y = 0;
2497
- force.z = 0;
2498
-
2499
- if (avoider.transientrep == null)
2500
- avoider.Revert();
2501
-
2502
- if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
2503
- return force;
2504
-
2505
- ResetGlobalTransform();
2506
- if (N.closestpoint == null)
2507
- {
2508
- //avoider.bRep.GetVertex(0); // "sort"
2509
-
2510
- ResetGlobalTransform();
2511
-
2512
- N.closestpoint = ClosestPoint(avoider.transientrep./*sortedV*/vertices, N, 0,avoider.transientrep./*sortedV*/vertices.size(), 0);
2513
-
2514
- if (N.closestpoint == null) // ????
2515
- return force;
2516
- }
2517
-
2518
- if (avoider == This())
2519
- {
2520
- // good but must freeze the order first... not really...
2521
- // if (cp.index < ((Vertex)N.position).index)
2522
- // return force;
2523
- }
2524
-
2525
- if (normalpusH != 0) // && cp == null /*???*/) // speed == 0)
2526
- {
2482
+ }
2483
+
2484
+ Avoider(Object3D col)
2485
+ {
2486
+ SetAvoider(col);
2487
+ }
2488
+
2489
+ void Avoidance(DynamicNode N)
2490
+ {
25272491 temp.set(N.position);
25282492 if (avoider != This())
25292493 {
....@@ -2531,16 +2495,16 @@
25312495 temp2.mul(0.001);
25322496 temp.sub(temp2); // push outside because of mesh artifacts
25332497 }
2534
-
2498
+
25352499 vect1.set(N.closestpoint);
2536
-
2500
+
25372501 LA.xformPos(vect1,toRoot,vect1);
25382502 //avoider.TransformToWorld(vect1, vect1);
2539
-
2503
+
25402504 temp.sub(vect1);
2541
-
2505
+
25422506 double distance = Math.sqrt(temp.length2());
2543
-
2507
+
25442508 if (distance < 0.01)
25452509 {
25462510 temp2.set(N.closestpoint.norm);
....@@ -2554,9 +2518,98 @@
25542518 if (IsAutoFreeze())
25552519 dot = -dot;
25562520
2557
- temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance));
2521
+ temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance));
25582522 force.add(temp);
25592523 }
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);
25602613 }
25612614
25622615 if (parameters.size() > 0)
....@@ -2590,6 +2643,7 @@
25902643 totalforce = new Point3D();
25912644
25922645 totalforce.set(0,0,0);
2646
+
25932647 if (forces.size() == 0)
25942648 totalforce.set(super.forceOn(N));
25952649
....@@ -2660,7 +2714,7 @@
26602714 force.y = 0;
26612715 force.z = 0;
26622716
2663
- if (normalpusH != 0) // speed == 0) // Now normal force
2717
+ if (normalpush != 0) // speed == 0) // Now normal force
26642718 {
26652719 // temp.set(N.position);
26662720 // temp.sub(Phys.reference);
....@@ -2668,7 +2722,7 @@
26682722
26692723 // normal pushing
26702724 temp.set(N.normal);
2671
- temp.mul(normalpusH/distance);
2725
+ temp.mul(normalpush/distance);
26722726 force.add(temp);
26732727 }
26742728
....@@ -2900,6 +2954,7 @@
29002954 return force;
29012955 }
29022956 }
2957
+
29032958 static int TABLESAC = 1024;
29042959 static double[] tablesac = new double[TABLESAC];
29052960
....@@ -2993,6 +3048,40 @@
29933048 // mass = M;
29943049 } // ???
29953050
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
+
29963085 force.x = 0;
29973086 force.y = (float) (-acceleration * mass);
29983087 force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); //
....@@ -3189,7 +3278,7 @@
31893278 }
31903279 if (false) // isHandle)
31913280 {
3192
- double K = Math.exp(-displacement*normalpusH);
3281
+ double K = Math.exp(-displacement*normalpush);
31933282 magnitude /= (displacement*(1-K) + K);
31943283 }
31953284