ClothParams.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace MagicaCloth
  7. {
  8. /// <summary>
  9. /// クロス基本パラメータ
  10. /// </summary>
  11. [System.Serializable]
  12. public class ClothParams
  13. {
  14. // アルゴリズム
  15. public enum Algorithm
  16. {
  17. [InspectorName("Algorithm 1 (Old Style)")]
  18. Algorithm_1 = 0, // 従来
  19. [InspectorName("Algorithm 2")]
  20. Algorithm_2 = 1, // v1.11.0より
  21. }
  22. [SerializeField]
  23. private Algorithm algorithm = Algorithm.Algorithm_1;
  24. // パーティクルサイズ
  25. [SerializeField]
  26. private BezierParam radius = new BezierParam(0.02f, 0.02f, true, 0.0f, false);
  27. // パーティクルの重さ
  28. [SerializeField]
  29. private BezierParam mass = new BezierParam(1.0f, 1.0f, true, 0.0f, false);
  30. // パーティクル重力加速度(m/s)
  31. [SerializeField]
  32. private bool useGravity = true;
  33. [SerializeField]
  34. private BezierParam gravity = new BezierParam(-9.8f, -9.8f, false, 0.0f, false);
  35. [SerializeField]
  36. private Vector3 gravityDirection = new Vector3(0.0f, 1.0f, 0.0f);
  37. //[SerializeField]
  38. //private bool useDirectionalDamping = true;
  39. //[SerializeField]
  40. //private Transform directionalDampingObject = null;
  41. //[SerializeField]
  42. //private BezierParam directionalDamping = new BezierParam(1.0f, 0.1f, true, -0.5f, true);
  43. // パーティクル空気抵抗値
  44. [SerializeField]
  45. private bool useDrag = true;
  46. [SerializeField]
  47. private BezierParam drag = new BezierParam(0.02f, 0.02f, true, 0.0f, false);
  48. // パーティクル最大速度(m/s)
  49. [SerializeField]
  50. private bool useMaxVelocity = true;
  51. [SerializeField]
  52. private BezierParam maxVelocity = new BezierParam(3.0f, 3.0f, false, 0.0f, false);
  53. // ワールド移動影響
  54. [SerializeField]
  55. private Transform influenceTarget = null;
  56. [SerializeField]
  57. private float maxMoveSpeed = 3.0f; // (m/s)
  58. [SerializeField]
  59. private float maxRotationSpeed = 720.0f; // (deg/s)
  60. [SerializeField]
  61. private BezierParam worldMoveInfluence = new BezierParam(0.5f, 0.5f, false, 0.0f, false);
  62. [SerializeField]
  63. private BezierParam worldRotationInfluence = new BezierParam(1.0f, 1.0f, false, 0.0f, false);
  64. // 外力
  65. [SerializeField]
  66. private float massInfluence = 0.3f;
  67. [SerializeField]
  68. private BezierParam depthInfluence = new BezierParam(0.1f, 1.0f, true, 0.5f, true);
  69. [SerializeField]
  70. private float windInfluence = 1.0f;
  71. [SerializeField]
  72. private float windRandomScale = 0.7f;
  73. [SerializeField]
  74. private float windSynchronization = 0.6f;
  75. // 距離無効化
  76. [SerializeField]
  77. private bool useDistanceDisable = false;
  78. [SerializeField]
  79. private Transform disableReferenceObject = null;
  80. [SerializeField]
  81. private float disableDistance = 20.0f;
  82. [SerializeField]
  83. private float disableFadeDistance = 5.0f;
  84. // テレポート
  85. public enum TeleportMode
  86. {
  87. Reset = 0,
  88. Keep = 1,
  89. }
  90. [SerializeField]
  91. private bool useResetTeleport = false;
  92. [SerializeField]
  93. private float teleportDistance = 0.2f;
  94. [SerializeField]
  95. private float teleportRotation = 45.0f;
  96. [SerializeField]
  97. private TeleportMode teleportMode = TeleportMode.Reset;
  98. // リセット後の安定化
  99. [SerializeField]
  100. private float resetStabilizationTime = 0.1f;
  101. // ルートからの最小最大距離拘束
  102. [SerializeField]
  103. private bool useClampDistanceRatio = true;
  104. [SerializeField]
  105. private float clampDistanceMinRatio = 0.7f;
  106. [SerializeField]
  107. private float clampDistanceMaxRatio = 1.05f;
  108. [SerializeField]
  109. private float clampDistanceVelocityInfluence = 0.1f;
  110. // 原点からの移動範囲拘束
  111. [SerializeField]
  112. private bool useClampPositionLength = false;
  113. [SerializeField]
  114. private BezierParam clampPositionLength = new BezierParam(0.03f, 0.2f, true, 0.0f, false);
  115. [SerializeField]
  116. private float clampPositionRatioX = 1.0f;
  117. [SerializeField]
  118. private float clampPositionRatioY = 1.0f;
  119. [SerializeField]
  120. private float clampPositionRatioZ = 1.0f;
  121. [SerializeField]
  122. private float clampPositionVelocityInfluence = 0.2f;
  123. // 最大回転角度拘束
  124. [SerializeField]
  125. private bool useClampRotation = false;
  126. [SerializeField]
  127. private BezierParam clampRotationAngle = new BezierParam(0.0f, 45.0f, true, 0.0f, false); // [Algorithm 1]
  128. [SerializeField]
  129. private BezierParam clampRotationAngle2 = new BezierParam(0.0f, 45.0f, true, 0.0f, false); // [Algorithm 2]
  130. [SerializeField]
  131. private float clampRotationVelocityLimit = 1.0f; // [Algorithm 1]
  132. [SerializeField]
  133. private float clampRotationVelocityInfluence = 0.2f; // [Algorithm 1]
  134. // 距離復元拘束
  135. [SerializeField]
  136. private float restoreDistanceVelocityInfluence = 1.0f;
  137. [SerializeField]
  138. private BezierParam structDistanceStiffness = new BezierParam(1.0f, 1.0f, false, 0.0f, false);
  139. [SerializeField]
  140. private bool useBendDistance = false;
  141. [SerializeField]
  142. private int bendDistanceMaxCount = 2;
  143. [SerializeField]
  144. private BezierParam bendDistanceStiffness = new BezierParam(0.5f, 0.5f, false, 0.0f, false);
  145. [SerializeField]
  146. private bool useNearDistance = false;
  147. [SerializeField]
  148. private int nearDistanceMaxCount = 3;
  149. [SerializeField]
  150. private float nearDistanceMaxDepth = 1.0f;
  151. [SerializeField]
  152. private BezierParam nearDistanceLength = new BezierParam(0.1f, 0.1f, true, 0.0f, false);
  153. [SerializeField]
  154. private BezierParam nearDistanceStiffness = new BezierParam(0.3f, 0.3f, false, 0.0f, false);
  155. // 回転復元拘束
  156. [SerializeField]
  157. private bool useRestoreRotation = false;
  158. [SerializeField]
  159. private BezierParam restoreRotation = new BezierParam(0.05f, 0.005f, true, 0.0f, false); // [Algorithm 1]
  160. [SerializeField]
  161. private BezierParam restoreRotation2 = new BezierParam(0.05f, 0.005f, true, 0.0f, false); // [Algorithm 2]
  162. [SerializeField]
  163. private float restoreRotationVelocityInfluence = 0.2f; // [Algorithm 1]
  164. [SerializeField]
  165. private float restoreRotationVelocityInfluence2 = 0.2f; // [Algorithm 2]
  166. // スプリング拘束
  167. [SerializeField]
  168. private bool useSpring = false;
  169. [SerializeField]
  170. private float springPower = 0.017f;
  171. [SerializeField]
  172. private float springRadius = 0.1f;
  173. [SerializeField]
  174. private float springScaleX = 1;
  175. [SerializeField]
  176. private float springScaleY = 1;
  177. [SerializeField]
  178. private float springScaleZ = 1;
  179. [SerializeField]
  180. private float springIntensity = 1.0f;
  181. [SerializeField]
  182. private BezierParam springDirectionAtten = new BezierParam(1.0f, 0.0f, true, 0.234f, true);
  183. [SerializeField]
  184. private BezierParam springDistanceAtten = new BezierParam(1.0f, 0.0f, true, 0.395f, true);
  185. // スプリング回転調整拘束
  186. public enum AdjustMode
  187. {
  188. Fixed = 0,
  189. XYMove = 1,
  190. XZMove = 2,
  191. YZMove = 3,
  192. }
  193. [SerializeField]
  194. private AdjustMode adjustMode;
  195. [SerializeField]
  196. private float adjustRotationPower = 5.0f;
  197. // トライアングル曲げ拘束
  198. [SerializeField]
  199. private bool useTriangleBend = false;
  200. //[SerializeField]
  201. //private bool useTriangleBendIncludeFixed = false;
  202. [SerializeField]
  203. private BezierParam triangleBend = new BezierParam(1.0f, 1.0f, true, 0.0f, false); // [Algorithm 1]
  204. [SerializeField]
  205. private BezierParam triangleBend2 = new BezierParam(1.0f, 1.0f, true, 0.0f, false); // [Algorithm 2]
  206. // ねじれ補正
  207. [SerializeField]
  208. private bool useTwistCorrection = false;
  209. [SerializeField]
  210. private float twistRecoveryPower = 0.2f;
  211. // ボリューム拘束
  212. [SerializeField]
  213. private bool useVolume = false;
  214. [SerializeField]
  215. private float maxVolumeLength = 0.1f;
  216. [SerializeField]
  217. private BezierParam volumeStretchStiffness = new BezierParam(0.5f, 0.5f, true, 0.0f, false);
  218. [SerializeField]
  219. private BezierParam volumeShearStiffness = new BezierParam(0.5f, 0.5f, true, 0.0f, false);
  220. // コライダーコリジョン拘束
  221. [SerializeField]
  222. private bool useCollision = false;
  223. [SerializeField]
  224. private float friction = 0.1f;
  225. [SerializeField]
  226. private float staticFriction = 0.03f;
  227. // エッジコリジョン
  228. //[SerializeField]
  229. //private bool useEdgeCollision = false;
  230. //[SerializeField]
  231. //private float edgeCollisionRadius = 0.02f;
  232. // 浸透制限
  233. [SerializeField]
  234. private bool usePenetration = false;
  235. public enum PenetrationMode
  236. {
  237. SurfacePenetration = 0,
  238. ColliderPenetration = 1,
  239. //BonePenetration = 2,
  240. }
  241. [SerializeField]
  242. private PenetrationMode penetrationMode = PenetrationMode.SurfacePenetration;
  243. public enum PenetrationAxis
  244. {
  245. X = 0,
  246. Y = 1,
  247. Z = 2,
  248. InverseX = 3,
  249. InverseY = 4,
  250. InverseZ = 5,
  251. }
  252. [SerializeField]
  253. private PenetrationAxis penetrationAxis = PenetrationAxis.InverseZ;
  254. [SerializeField]
  255. private float penetrationMaxDepth = 1.0f;
  256. [SerializeField]
  257. private BezierParam penetrationConnectDistance = new BezierParam(0.1f, 0.2f, true, 0.0f, false);
  258. //[SerializeField]
  259. //private BezierParam penetrationStiffness = new BezierParam(1.0f, 1.0f, false, 0.0f, false);
  260. [SerializeField]
  261. private BezierParam penetrationDistance = new BezierParam(0.02f, 0.05f, true, 0.0f, false);
  262. [SerializeField]
  263. private BezierParam penetrationRadius = new BezierParam(0.3f, 1.0f, true, 0.0f, false);
  264. // 回転補間
  265. [SerializeField]
  266. private bool useLineAvarageRotation = true;
  267. [SerializeField]
  268. private bool useFixedNonRotation = false;
  269. // ベーススキニング
  270. //[SerializeField]
  271. //private bool useBaseSkinning = false;
  272. // コライダー方向移動制限拘束
  273. //[SerializeField]
  274. //private bool useDirectionMoveLimit = false;
  275. //[SerializeField]
  276. //private BezierParam directionMoveLimit = new BezierParam(0.03f, 0.03f, true, 0.0f, false);
  277. // セルフコリジョン拘束
  278. //[SerializeField]
  279. //private bool useSelfCollision = false;
  280. //[SerializeField]
  281. //private float selfCollisionInfluenceRange = 0.2f;
  282. //[SerializeField]
  283. //private int maxSelfCollisionCount = 6;
  284. //[SerializeField]
  285. //private BezierParam selfCollisionStiffness = new BezierParam(0.3f, 0.01f, true, 0.0f, false);
  286. //[SerializeField]
  287. //private BezierParam selfCollisionThickness = new BezierParam(0.01f, 0.01f, true, 0.0f, false);
  288. //=========================================================================================
  289. /// <summary>
  290. /// 変更チェック用(番号は変えないこと!)
  291. /// </summary>
  292. public enum ParamType
  293. {
  294. Radius = 0,
  295. Mass = 1,
  296. Gravity = 2,
  297. Drag = 3,
  298. MaxVelocity = 4,
  299. WorldInfluence = 5,
  300. ClampDistance = 6,
  301. ClampPosition = 7,
  302. ClampRotation = 8,
  303. RestoreDistance = 9,
  304. RestoreRotation = 10,
  305. Spring = 11,
  306. AdjustRotation = 12,
  307. AirLine = 13,
  308. TriangleBend = 14,
  309. Volume = 15,
  310. ColliderCollision = 16,
  311. RotationInterpolation = 17,
  312. DistanceDisable = 18,
  313. ExternalForce = 19,
  314. Penetration = 20,
  315. Algorithm = 21,
  316. BaseSkinning = 22,
  317. //DirectionMoveLimit,
  318. //SelfCollision,
  319. Max, // カウンタ用
  320. }
  321. // 変更記録セット
  322. private HashSet<ParamType> changeSet = new HashSet<ParamType>();
  323. public void SetChangeParam(ParamType ptype)
  324. {
  325. changeSet.Add(ptype);
  326. }
  327. public bool ChangedParam(ParamType ptype)
  328. {
  329. return changeSet.Contains(ptype);
  330. }
  331. public void ClearChangeParam()
  332. {
  333. changeSet.Clear();
  334. }
  335. //=========================================================================================
  336. /// <summary>
  337. /// 各パラメータ別のハッシュを取得する
  338. /// </summary>
  339. /// <param name="ptype"></param>
  340. /// <returns></returns>
  341. public int GetParamHash(BaseCloth cloth, ParamType ptype)
  342. {
  343. int hash = 0;
  344. switch (ptype)
  345. {
  346. case ParamType.Algorithm:
  347. hash += algorithm.GetDataHash();
  348. break;
  349. case ParamType.WorldInfluence:
  350. hash += influenceTarget ? influenceTarget.GetDataHash() : 0;
  351. break;
  352. case ParamType.RestoreDistance:
  353. if (useBendDistance)
  354. {
  355. hash += useBendDistance.GetDataHash();
  356. hash += bendDistanceMaxCount.GetDataHash();
  357. }
  358. if (useNearDistance)
  359. {
  360. hash += useNearDistance.GetDataHash();
  361. hash += nearDistanceMaxCount.GetDataHash();
  362. hash += nearDistanceMaxDepth.GetDataHash();
  363. }
  364. break;
  365. case ParamType.ClampDistance:
  366. if (useClampDistanceRatio)
  367. hash += useClampDistanceRatio.GetDataHash();
  368. break;
  369. case ParamType.ClampPosition:
  370. if (useClampPositionLength)
  371. hash += useClampPositionLength.GetDataHash();
  372. break;
  373. case ParamType.RestoreRotation:
  374. if (useRestoreRotation)
  375. {
  376. hash += algorithm.GetDataHash(); // algorithm
  377. hash += useRestoreRotation.GetDataHash();
  378. }
  379. break;
  380. case ParamType.ClampRotation:
  381. if (useClampRotation)
  382. {
  383. hash += algorithm.GetDataHash(); // algorithm
  384. hash += useClampRotation.GetDataHash();
  385. }
  386. break;
  387. case ParamType.TriangleBend:
  388. if (useTriangleBend)
  389. {
  390. hash += algorithm.GetDataHash(); // algorithm
  391. hash += useTriangleBend.GetDataHash();
  392. hash += useTwistCorrection.GetDataHash();
  393. }
  394. break;
  395. case ParamType.Penetration:
  396. if (usePenetration)
  397. {
  398. hash += usePenetration.GetDataHash();
  399. hash += penetrationMode.GetDataHash();
  400. if (penetrationMode == PenetrationMode.SurfacePenetration)
  401. {
  402. hash += penetrationMaxDepth.GetDataHash();
  403. hash += penetrationAxis.GetDataHash();
  404. }
  405. if (penetrationMode == PenetrationMode.ColliderPenetration)
  406. {
  407. hash += penetrationMaxDepth.GetDataHash();
  408. hash += penetrationConnectDistance.GetDataHash();
  409. hash += cloth.TeamData.ColliderList.GetDataHash();
  410. hash += cloth.TeamData.PenetrationIgnoreColliderList.GetDataHash();
  411. }
  412. }
  413. break;
  414. case ParamType.Spring:
  415. if (useSpring)
  416. {
  417. hash += useSpring.GetDataHash();
  418. hash += springRadius.GetDataHash();
  419. hash += springScaleX.GetDataHash();
  420. hash += springScaleY.GetDataHash();
  421. hash += springScaleZ.GetDataHash();
  422. hash += springDirectionAtten.GetDataHash();
  423. hash += springDistanceAtten.GetDataHash();
  424. hash += springIntensity.GetDataHash();
  425. }
  426. break;
  427. case ParamType.ColliderCollision:
  428. if (useCollision)
  429. {
  430. hash += cloth.TeamData.ColliderList.GetDataHash();
  431. }
  432. break;
  433. case ParamType.BaseSkinning:
  434. // 一旦休眠
  435. //if (cloth.SkinningMode == PhysicsTeam.TeamSkinningMode.GenerateFromBones)
  436. //{
  437. // hash += cloth.SkinningUpdateFixed.GetDataHash();
  438. //}
  439. break;
  440. }
  441. return hash;
  442. }
  443. //=========================================================================================
  444. // algorithm
  445. public Algorithm AlgorithmType
  446. {
  447. get => algorithm;
  448. set => algorithm = value;
  449. }
  450. // radius
  451. public void SetRadius(float sval, float eval)
  452. {
  453. radius.SetParam(sval, eval);
  454. }
  455. public float GetRadius(float depth)
  456. {
  457. return radius.Evaluate(depth);
  458. }
  459. public BezierParam GetRadius()
  460. {
  461. return radius;
  462. }
  463. // mass
  464. public void SetMass(float sval, float eval, bool useEval = true, float cval = 0.0f, bool useCval = false)
  465. {
  466. mass.SetParam(sval, eval, useEval, cval, useCval);
  467. }
  468. public BezierParam GetMass()
  469. {
  470. return mass;
  471. }
  472. // gravity
  473. public void SetGravity(bool sw, float sval = -9.8f, float eval = -9.8f)
  474. {
  475. useGravity = sw;
  476. gravity.SetParam(sval, eval);
  477. }
  478. public bool UseGravity
  479. {
  480. get
  481. {
  482. return useGravity;
  483. }
  484. }
  485. public BezierParam GetGravity()
  486. {
  487. if (useGravity)
  488. return gravity;
  489. else
  490. return new BezierParam(0.0f);
  491. }
  492. public Vector3 GravityDirection
  493. {
  494. get
  495. {
  496. return gravityDirection;
  497. }
  498. set
  499. {
  500. gravityDirection = value;
  501. }
  502. }
  503. #if false
  504. // 重力の方向性減衰(現在は保留)
  505. public void SetDirectionalDamping(bool sw, float sval = 1.0f, float eval = 0.1f, float curve = -0.5f, Transform target = null)
  506. {
  507. useDirectionalDamping = sw;
  508. directionalDamping.SetParam(sval, eval, true, curve, true);
  509. directionalDampingObject = target;
  510. }
  511. public bool UseDirectionalDamping
  512. {
  513. get
  514. {
  515. return useDirectionalDamping;
  516. }
  517. }
  518. public Transform DirectionalDampingObject
  519. {
  520. get
  521. {
  522. return directionalDampingObject;
  523. }
  524. set
  525. {
  526. directionalDampingObject = value;
  527. }
  528. }
  529. public BezierParam GetDirectionalDamping()
  530. {
  531. if (useGravity)
  532. return directionalDamping;
  533. else
  534. return new BezierParam(0.0f);
  535. }
  536. #endif
  537. // drag
  538. public void SetDrag(bool sw, float sval = 0.015f, float eval = 0.015f)
  539. {
  540. useDrag = sw;
  541. drag.SetParam(sval, eval);
  542. }
  543. public bool UseDrag
  544. {
  545. get
  546. {
  547. return useDrag;
  548. }
  549. }
  550. public BezierParam GetDrag()
  551. {
  552. if (useDrag)
  553. return drag;
  554. else
  555. return new BezierParam(0);
  556. }
  557. // max velocity
  558. public void SetMaxVelocity(bool sw, float sval = 3, float eval = 3)
  559. {
  560. useMaxVelocity = sw;
  561. maxVelocity.SetParam(sval, eval);
  562. }
  563. public bool UseMaxVelocity
  564. {
  565. get
  566. {
  567. return useMaxVelocity;
  568. }
  569. }
  570. public BezierParam GetMaxVelocity()
  571. {
  572. if (useMaxVelocity)
  573. return maxVelocity;
  574. else
  575. return new BezierParam(1000);
  576. }
  577. // external force
  578. public void SetExternalForce(float massInfluence, float windInfluence, float windRandomScale, float windSynchronization)
  579. {
  580. this.massInfluence = massInfluence;
  581. this.windInfluence = windInfluence;
  582. this.windRandomScale = windRandomScale;
  583. this.windSynchronization = windSynchronization;
  584. }
  585. public float MassInfluence
  586. {
  587. get => massInfluence;
  588. set => massInfluence = value;
  589. }
  590. public BezierParam GetDepthInfluence() => depthInfluence;
  591. public float WindInfluence
  592. {
  593. get => windInfluence;
  594. set => windInfluence = value;
  595. }
  596. public float WindRandomScale
  597. {
  598. get => windRandomScale;
  599. set => windRandomScale = value;
  600. }
  601. public float WindSynchronization
  602. {
  603. get => windSynchronization;
  604. set => windSynchronization = value;
  605. }
  606. // world move/rot influence
  607. public void SetWorldInfluence(float maxspeed, float moveval, float rotval)
  608. {
  609. maxMoveSpeed = maxspeed;
  610. worldMoveInfluence.SetParam(moveval, moveval, false);
  611. worldRotationInfluence.SetParam(rotval, rotval, false);
  612. }
  613. public BezierParam GetWorldMoveInfluence()
  614. {
  615. return worldMoveInfluence;
  616. }
  617. public BezierParam GetWorldRotationInfluence()
  618. {
  619. return worldRotationInfluence;
  620. }
  621. public Transform GetInfluenceTarget()
  622. {
  623. return influenceTarget;
  624. }
  625. public void SetInfluenceTarget(Transform t)
  626. {
  627. influenceTarget = t;
  628. }
  629. public float MaxMoveSpeed
  630. {
  631. get
  632. {
  633. return maxMoveSpeed;
  634. }
  635. set
  636. {
  637. maxMoveSpeed = value;
  638. }
  639. }
  640. public float MaxRotationSpeed
  641. {
  642. get
  643. {
  644. return maxRotationSpeed;
  645. }
  646. set
  647. {
  648. maxRotationSpeed = value;
  649. }
  650. }
  651. // reset teleport
  652. public void SetTeleport(bool sw, float distance = 0.2f, float rotation = 45.0f, TeleportMode mode = TeleportMode.Reset)
  653. {
  654. useResetTeleport = sw;
  655. teleportDistance = distance;
  656. teleportRotation = rotation;
  657. teleportMode = mode;
  658. }
  659. public bool UseResetTeleport
  660. {
  661. get
  662. {
  663. return useResetTeleport;
  664. }
  665. set
  666. {
  667. useResetTeleport = value;
  668. }
  669. }
  670. public float TeleportDistance
  671. {
  672. get
  673. {
  674. //return useResetTeleport ? teleportDistance : 100000.0f;
  675. return teleportDistance;
  676. }
  677. set
  678. {
  679. teleportDistance = value;
  680. }
  681. }
  682. public float TeleportRotation
  683. {
  684. get
  685. {
  686. //return useResetTeleport ? teleportRotation : 360.0f;
  687. return teleportRotation;
  688. }
  689. set
  690. {
  691. teleportRotation = value;
  692. }
  693. }
  694. public TeleportMode TeleportResetMode
  695. {
  696. get
  697. {
  698. return teleportMode;
  699. }
  700. set
  701. {
  702. teleportMode = value;
  703. }
  704. }
  705. // stabilize after reset
  706. public float ResetStabilizationTime
  707. {
  708. get
  709. {
  710. return resetStabilizationTime;
  711. }
  712. set
  713. {
  714. resetStabilizationTime = value;
  715. }
  716. }
  717. // disable distance
  718. public void SetDistanceDisable(bool sw, float distance = 20.0f, float fadeDistance = 5.0f, Transform referenceObject = null)
  719. {
  720. useDistanceDisable = sw;
  721. disableReferenceObject = referenceObject;
  722. disableDistance = distance;
  723. disableFadeDistance = fadeDistance;
  724. }
  725. public bool UseDistanceDisable
  726. {
  727. get
  728. {
  729. return useDistanceDisable;
  730. }
  731. set
  732. {
  733. useDistanceDisable = value;
  734. }
  735. }
  736. public Transform DisableReferenceObject
  737. {
  738. get
  739. {
  740. return disableReferenceObject;
  741. }
  742. set
  743. {
  744. disableReferenceObject = value;
  745. }
  746. }
  747. public float DisableDistance
  748. {
  749. get
  750. {
  751. return disableDistance;
  752. }
  753. set
  754. {
  755. disableDistance = value;
  756. }
  757. }
  758. public float DisableFadeDistance
  759. {
  760. get
  761. {
  762. return disableFadeDistance;
  763. }
  764. set
  765. {
  766. disableFadeDistance = value;
  767. }
  768. }
  769. // clamp distance
  770. public void SetClampDistanceRatio(bool sw, float minval = 0.1f, float maxval = 1.05f, float influence = 0.2f)
  771. {
  772. useClampDistanceRatio = sw;
  773. clampDistanceMinRatio = minval;
  774. clampDistanceMaxRatio = maxval;
  775. clampDistanceVelocityInfluence = influence;
  776. }
  777. public bool UseClampDistanceRatio
  778. {
  779. get
  780. {
  781. return useClampDistanceRatio;
  782. }
  783. }
  784. public float ClampDistanceMinRatio
  785. {
  786. get
  787. {
  788. return useClampDistanceRatio ? clampDistanceMinRatio : 0;
  789. }
  790. }
  791. public float ClampDistanceMaxRatio
  792. {
  793. get
  794. {
  795. return useClampDistanceRatio ? clampDistanceMaxRatio : 0;
  796. }
  797. }
  798. public float ClampDistanceVelocityInfluence
  799. {
  800. get
  801. {
  802. return useClampDistanceRatio ? clampDistanceVelocityInfluence : 1;
  803. }
  804. }
  805. // clamp position
  806. public void SetClampPositionLength(bool sw, float sval = 0.03f, float eval = 0.2f, float ratioX = 1, float ratioY = 1, float ratioZ = 1, float influence = 0.2f)
  807. {
  808. useClampPositionLength = sw;
  809. clampPositionLength.SetParam(sval, eval);
  810. clampPositionRatioX = ratioX;
  811. clampPositionRatioY = ratioY;
  812. clampPositionRatioZ = ratioZ;
  813. clampPositionVelocityInfluence = influence;
  814. }
  815. public bool UseClampPositionLength
  816. {
  817. get
  818. {
  819. return useClampPositionLength;
  820. }
  821. }
  822. public Vector3 ClampPositionAxisRatio
  823. {
  824. get
  825. {
  826. return new Vector3(clampPositionRatioX, clampPositionRatioY, clampPositionRatioZ);
  827. }
  828. }
  829. public BezierParam GetClampPositionLength()
  830. {
  831. return clampPositionLength;
  832. }
  833. public float ClampPositionVelocityInfluence
  834. {
  835. get
  836. {
  837. return useClampPositionLength ? clampPositionVelocityInfluence : 1;
  838. }
  839. }
  840. // clamp rotation
  841. public void SetClampRotationAngle(bool sw, float sval = 0.0f, float eval = 180.0f, float influence = 0.2f)
  842. {
  843. useClampRotation = sw;
  844. clampRotationAngle.SetParam(sval, eval);
  845. clampRotationAngle2.SetParam(sval, eval);
  846. clampRotationVelocityInfluence = influence;
  847. }
  848. public bool UseClampRotation => useClampRotation;
  849. public BezierParam GetClampRotationAngle(Algorithm algo)
  850. {
  851. if (algo == Algorithm.Algorithm_2)
  852. return clampRotationAngle2;
  853. else
  854. return clampRotationAngle;
  855. }
  856. public float ClampRotationVelocityInfluence
  857. {
  858. get
  859. {
  860. return useClampRotation ? clampRotationVelocityInfluence : 1;
  861. }
  862. }
  863. public float GetClampRotationVelocityLimit(Algorithm algo)
  864. {
  865. if (useClampRotation)
  866. {
  867. if (algo == Algorithm.Algorithm_2)
  868. return 1.0f; // On
  869. else
  870. return clampRotationVelocityLimit;
  871. }
  872. else
  873. return 0.0f;
  874. }
  875. // restore distance
  876. public void SetRestoreDistance(float influence = 1.0f, float structStiffness = 1.0f)
  877. {
  878. restoreDistanceVelocityInfluence = influence;
  879. structDistanceStiffness.SetParam(structStiffness, structStiffness, false);
  880. }
  881. public float RestoreDistanceVelocityInfluence
  882. {
  883. get
  884. {
  885. return restoreDistanceVelocityInfluence;
  886. }
  887. }
  888. public BezierParam GetStructDistanceStiffness()
  889. {
  890. return structDistanceStiffness;
  891. }
  892. public bool UseBendDistance
  893. {
  894. get
  895. {
  896. return useBendDistance;
  897. }
  898. }
  899. public int BendDistanceMaxCount
  900. {
  901. get
  902. {
  903. return bendDistanceMaxCount;
  904. }
  905. }
  906. public BezierParam GetBendDistanceStiffness()
  907. {
  908. return bendDistanceStiffness;
  909. }
  910. public bool UseNearDistance
  911. {
  912. get
  913. {
  914. return useNearDistance;
  915. }
  916. }
  917. public int NearDistanceMaxCount
  918. {
  919. get
  920. {
  921. return nearDistanceMaxCount;
  922. }
  923. }
  924. public float NearDistanceMaxDepth
  925. {
  926. get
  927. {
  928. return nearDistanceMaxDepth;
  929. }
  930. }
  931. public BezierParam GetNearDistanceLength()
  932. {
  933. return nearDistanceLength;
  934. }
  935. public BezierParam GetNearDistanceStiffness()
  936. {
  937. return nearDistanceStiffness;
  938. }
  939. // restore rotation
  940. public void SetRestoreRotation(bool sw, float sval = 0.02f, float eval = 0.001f, float influence = 0.3f)
  941. {
  942. useRestoreRotation = sw;
  943. restoreRotation.SetParam(sval, eval);
  944. restoreRotation2.SetParam(sval, eval);
  945. restoreRotationVelocityInfluence = influence;
  946. restoreRotationVelocityInfluence2 = influence;
  947. }
  948. public bool UseRestoreRotation
  949. {
  950. get
  951. {
  952. return useRestoreRotation;
  953. }
  954. }
  955. public BezierParam GetRestoreRotationPower(Algorithm algo)
  956. {
  957. if (algo == Algorithm.Algorithm_2)
  958. return restoreRotation2;
  959. else
  960. return restoreRotation;
  961. }
  962. public float GetRestoreRotationVelocityInfluence(Algorithm algo)
  963. {
  964. if (algo == Algorithm.Algorithm_2)
  965. return restoreRotationVelocityInfluence2;
  966. else
  967. return restoreRotationVelocityInfluence;
  968. }
  969. // spring
  970. public void SetSpring(bool sw, float power = 0.0f, float r = 0.0f, float sclx = 1, float scly = 1, float sclz = 1, float intensity = 1)
  971. {
  972. useSpring = sw;
  973. springPower = power;
  974. springRadius = r;
  975. springScaleX = sclx;
  976. springScaleY = scly;
  977. springScaleZ = sclz;
  978. springIntensity = intensity;
  979. }
  980. public void SetSpringDirectionAtten(float sval, float eval, float cval)
  981. {
  982. springDirectionAtten.SetParam(sval, eval, true, cval, true);
  983. }
  984. public void SetSpringDistanceAtten(float sval, float eval, float cval)
  985. {
  986. springDistanceAtten.SetParam(sval, eval, true, cval, true);
  987. }
  988. public bool UseSpring
  989. {
  990. get
  991. {
  992. return useSpring;
  993. }
  994. }
  995. public float GetSpringPower()
  996. {
  997. if (useSpring)
  998. return springPower;
  999. else
  1000. return 0;
  1001. }
  1002. public float SpringRadius
  1003. {
  1004. get
  1005. {
  1006. return springRadius;
  1007. }
  1008. }
  1009. public Vector3 SpringRadiusScale
  1010. {
  1011. get
  1012. {
  1013. return new Vector3(springScaleX, springScaleY, springScaleZ);
  1014. }
  1015. }
  1016. public float SpringIntensity
  1017. {
  1018. get
  1019. {
  1020. return springIntensity;
  1021. }
  1022. }
  1023. public float GetSpringDirectionAtten(float ratio)
  1024. {
  1025. return springDirectionAtten.Evaluate(ratio);
  1026. }
  1027. public float GetSpringDistanceAtten(float ratio)
  1028. {
  1029. return springDistanceAtten.Evaluate(ratio);
  1030. }
  1031. // adjust spring rotation
  1032. public void SetAdjustRotation(AdjustMode amode = AdjustMode.Fixed, float power = 0.0f)
  1033. {
  1034. adjustMode = amode;
  1035. adjustRotationPower = power;
  1036. }
  1037. public AdjustMode AdjustRotationMode
  1038. {
  1039. get
  1040. {
  1041. return adjustMode;
  1042. }
  1043. }
  1044. public Vector3 AdjustRotationVector
  1045. {
  1046. get
  1047. {
  1048. // 移動軸調整の場合は、各軸の回転力が入る
  1049. Vector3 vec = Vector3.one;
  1050. vec *= adjustRotationPower;
  1051. return vec;
  1052. }
  1053. }
  1054. // triangle bend
  1055. public void SetTriangleBend(bool sw, float sval = 1.0f, float eval = 1.0f)
  1056. {
  1057. useTriangleBend = sw;
  1058. triangleBend.SetParam(sval, eval);
  1059. triangleBend2.SetParam(sval, eval);
  1060. }
  1061. public bool UseTriangleBend
  1062. {
  1063. get
  1064. {
  1065. return useTriangleBend;
  1066. }
  1067. }
  1068. //public bool UseTrianlgeBendIncludeFixed => useTriangleBendIncludeFixed;
  1069. public BezierParam GetTriangleBendStiffness(Algorithm algo)
  1070. {
  1071. if (algo == Algorithm.Algorithm_2)
  1072. return triangleBend2;
  1073. else
  1074. return triangleBend;
  1075. }
  1076. // Twist
  1077. internal bool GetUseTwistCorrection(Algorithm algo)
  1078. {
  1079. if (algo == Algorithm.Algorithm_2)
  1080. return useTwistCorrection;
  1081. else
  1082. return false;
  1083. }
  1084. internal float TwistRecoveryPower => twistRecoveryPower;
  1085. // volume
  1086. public void SetVolume(bool sw, float maxLength = 0.05f, float stiffness = 0.5f, float shear = 0.5f)
  1087. {
  1088. useVolume = sw;
  1089. maxVolumeLength = maxLength;
  1090. volumeShearStiffness.SetParam(stiffness, stiffness, false);
  1091. volumeShearStiffness.SetParam(shear, shear, false);
  1092. }
  1093. public bool UseVolume
  1094. {
  1095. get
  1096. {
  1097. return useVolume;
  1098. }
  1099. }
  1100. public float GetMaxVolumeLength()
  1101. {
  1102. if (useVolume)
  1103. {
  1104. return maxVolumeLength;
  1105. }
  1106. else
  1107. return 0;
  1108. }
  1109. public BezierParam GetVolumeStretchStiffness()
  1110. {
  1111. return volumeStretchStiffness;
  1112. }
  1113. public BezierParam GetVolumeShearStiffness()
  1114. {
  1115. return volumeShearStiffness;
  1116. }
  1117. // collider collision
  1118. public void SetCollision(bool sw, float dynamicFriction = 0.1f, float staticFriction = 0.03f)
  1119. {
  1120. useCollision = sw;
  1121. this.friction = dynamicFriction;
  1122. this.staticFriction = staticFriction;
  1123. }
  1124. public bool UseCollision => useCollision;
  1125. public float DynamicFriction => friction;
  1126. public float StaticFriction => staticFriction;
  1127. //public bool KeepInitialShape
  1128. //{
  1129. // get
  1130. // {
  1131. // return keepInitialShape;
  1132. // }
  1133. //}
  1134. // penetration
  1135. public bool UsePenetration
  1136. {
  1137. get
  1138. {
  1139. return usePenetration;
  1140. }
  1141. set
  1142. {
  1143. usePenetration = value;
  1144. }
  1145. }
  1146. public PenetrationMode GetPenetrationMode()
  1147. {
  1148. return penetrationMode;
  1149. }
  1150. public PenetrationAxis GetPenetrationAxis()
  1151. {
  1152. return penetrationAxis;
  1153. }
  1154. public float PenetrationMaxDepth
  1155. {
  1156. get
  1157. {
  1158. return penetrationMaxDepth;
  1159. }
  1160. }
  1161. public BezierParam GetPenetrationConnectDistance()
  1162. {
  1163. return penetrationConnectDistance;
  1164. }
  1165. //public BezierParam GetPenetrationStiffness()
  1166. //{
  1167. // return penetrationStiffness;
  1168. //}
  1169. public BezierParam GetPenetrationRadius()
  1170. {
  1171. return penetrationRadius;
  1172. }
  1173. public BezierParam GetPenetrationDistance()
  1174. {
  1175. return penetrationDistance;
  1176. }
  1177. // rotation interpolation
  1178. public bool UseLineAvarageRotation
  1179. {
  1180. get
  1181. {
  1182. return useLineAvarageRotation;
  1183. }
  1184. }
  1185. public bool UseFixedNonRotation
  1186. {
  1187. get
  1188. {
  1189. return useFixedNonRotation;
  1190. }
  1191. }
  1192. // base skinning
  1193. //public bool UseBaseSkinning
  1194. //{
  1195. // get
  1196. // {
  1197. // return useBaseSkinning;
  1198. // }
  1199. //}
  1200. // self collision
  1201. //public void SetSelfCollision(bool sw)
  1202. //{
  1203. // useSelfCollision = sw;
  1204. //}
  1205. //public bool UseSelfCollision
  1206. //{
  1207. // get
  1208. // {
  1209. // return useSelfCollision;
  1210. // }
  1211. //}
  1212. //public float SelfCollisionINfluenceRange
  1213. //{
  1214. // get
  1215. // {
  1216. // return selfCollisionInfluenceRange;
  1217. // }
  1218. //}
  1219. //public int MaxSelfCollisionCount
  1220. //{
  1221. // get
  1222. // {
  1223. // return maxSelfCollisionCount;
  1224. // }
  1225. //}
  1226. //public float GetSelfCollisionStiffness(float depth)
  1227. //{
  1228. // if (useSelfCollision)
  1229. // return selfCollisionStiffness.Evaluate(depth);
  1230. // else
  1231. // return 0.0f;
  1232. //}
  1233. //public float GetSelfCollisionThickness(float depth)
  1234. //{
  1235. // if (useSelfCollision)
  1236. // return selfCollisionThickness.Evaluate(depth);
  1237. // else
  1238. // return 0.0f;
  1239. //}
  1240. // direction move limit
  1241. //public void SetDirectionMoveLimit(bool sw, float sval = 0.05f, float eval = 0.05f)
  1242. //{
  1243. // useDirectionMoveLimit = sw;
  1244. // directionMoveLimit.SetParam(sval, eval);
  1245. //}
  1246. //public bool UseDirectionMoveLimit
  1247. //{
  1248. // get
  1249. // {
  1250. // return useDirectionMoveLimit;
  1251. // }
  1252. //}
  1253. //public float GetDirectionMoveLength(float depth)
  1254. //{
  1255. // if (useDirectionMoveLimit)
  1256. // return directionMoveLimit.Evaluate(depth);
  1257. // else
  1258. // return -1; // 無効
  1259. //}
  1260. //=========================================================================================
  1261. /// <summary>
  1262. /// 古いパラメータを最新アルゴリズム用にコンバートする
  1263. /// </summary>
  1264. public void ConvertToLatestAlgorithmParameter()
  1265. {
  1266. // ClampRotation
  1267. clampRotationAngle2 = clampRotationAngle.Clone();
  1268. // RestoreRotation
  1269. restoreRotation2 = restoreRotation.Clone();
  1270. restoreRotationVelocityInfluence2 = restoreRotationVelocityInfluence;
  1271. // Triangle Bend
  1272. triangleBend2 = triangleBend.Clone();
  1273. }
  1274. }
  1275. }