mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-26 20:51:47 -05:00
InitializeCloth
This commit is contained in:
parent
77188fb148
commit
29474d17c7
|
|
@ -1,4 +1,3 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -14,5 +13,62 @@ namespace RotateParticle.Components
|
|||
|
||||
[SerializeField]
|
||||
public List<Warp> Warps = new();
|
||||
|
||||
void Reset()
|
||||
{
|
||||
for (int i = 0; i < transform.childCount; ++i)
|
||||
{
|
||||
var child = transform.GetChild(i);
|
||||
if (child.TryGetComponent<Warp>(out var warp))
|
||||
{
|
||||
Warps.Add(warp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
if (Warps.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Gizmos.color = Color.red;
|
||||
Gizmos.color = new Color(1, 0.5f, 0);
|
||||
for (int i = 0; i < Warps.Count; ++i)
|
||||
{
|
||||
if (i + 1 == Warps.Count)
|
||||
{
|
||||
if (LoopIsClosed)
|
||||
{
|
||||
DrawWeft(Warps[i], Warps[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawWeft(Warps[i], Warps[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrawWeft(Warp w0, Warp w1)
|
||||
{
|
||||
if (w0 == null || w1 == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Gizmos.DrawLine(w0.transform.position, w1.transform.position);
|
||||
|
||||
for (int i = 0; i < w0.Particles.Count && i < w1.Particles.Count; ++i)
|
||||
{
|
||||
var p0 = w0.Particles[i];
|
||||
var p1 = w1.Particles[i];
|
||||
if (p0 != null && p0.Transform != null && p1 != null && p1.Transform != null)
|
||||
{
|
||||
Gizmos.DrawLine(p0.Transform.position, p1.Transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ namespace RotateParticle
|
|||
var child_index = _MakeAParticle(joint, env, particle.Transform,
|
||||
particle.GetSettings(warp.BaseSettings).HitRadius, 1, strand.CollisionMask);
|
||||
var child = _particles[child_index];
|
||||
strand.Particles.Add(child);
|
||||
joint.Children.Add(child);
|
||||
joint = child;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,15 +39,20 @@ namespace RotateParticle
|
|||
foreach (var warp in instance.GetComponentsInChildren<Warp>())
|
||||
{
|
||||
_system._warps.Add(warp);
|
||||
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
|
||||
foreach (var cloth in instance.GetComponentsInChildren<RectCloth>())
|
||||
{
|
||||
_system._cloths.Add(cloth);
|
||||
}
|
||||
|
||||
await awaitCaller.NextFrame();
|
||||
_system.Initialize();
|
||||
}
|
||||
|
||||
public void Process()
|
||||
{
|
||||
if (_system == null) return;
|
||||
_system.Process(Time.deltaTime);
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +75,8 @@ namespace RotateParticle
|
|||
|
||||
public void DrawGizmos()
|
||||
{
|
||||
if (_system == null) return;
|
||||
_system.DrawGizmos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RotateParticle.Components;
|
||||
using SphereTriangle;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -15,7 +16,10 @@ namespace RotateParticle
|
|||
public SimulationEnv Env = new();
|
||||
|
||||
[SerializeField]
|
||||
public List<Components.Warp> _warps = new();
|
||||
public List<Warp> _warps = new();
|
||||
|
||||
[SerializeField]
|
||||
public List<RectCloth> _cloths = new();
|
||||
|
||||
[SerializeField]
|
||||
public List<ColliderGroup> _colliderGroups = new();
|
||||
|
|
@ -96,15 +100,15 @@ namespace RotateParticle
|
|||
HashSet<int> _clothUsedParticles = new();
|
||||
|
||||
public void InitializeCloth(
|
||||
Components.RectCloth g,
|
||||
RectCloth cloth,
|
||||
ParticleList list,
|
||||
List<Strand> strands,
|
||||
List<(SpringConstraint, ClothRectCollision)> clothRects)
|
||||
List<(SpringConstraint, ClothRectCollision)> clothRects,
|
||||
Dictionary<Warp, Strand> strandMap)
|
||||
{
|
||||
for (int i = 1; i < strands.Count; ++i)
|
||||
for (int i = 1; i < cloth.Warps.Count; ++i)
|
||||
{
|
||||
var s0 = strands[i - 1];
|
||||
var s1 = strands[i];
|
||||
var s0 = strandMap[cloth.Warps[i - 1]];
|
||||
var s1 = strandMap[cloth.Warps[i]];
|
||||
for (int j = 1; j < s0.Particles.Count && j < s1.Particles.Count; ++j)
|
||||
{
|
||||
// d x x c
|
||||
|
|
@ -134,13 +138,13 @@ namespace RotateParticle
|
|||
}
|
||||
}
|
||||
|
||||
if (strands.Count >= 3)
|
||||
if (cloth.Warps.Count >= 3)
|
||||
{
|
||||
if (g.LoopIsClosed)
|
||||
if (cloth.LoopIsClosed)
|
||||
{
|
||||
var i = strands.Count;
|
||||
var s0 = strands.Last();
|
||||
var s1 = strands.First();
|
||||
var i = cloth.Warps.Count;
|
||||
var s0 = strandMap[cloth.Warps.Last()];
|
||||
var s1 = strandMap[cloth.Warps.First()];
|
||||
for (int j = 1; j < s0.Particles.Count && j < s1.Particles.Count; ++j)
|
||||
{
|
||||
var a = s0.Particles[j];
|
||||
|
|
@ -173,14 +177,19 @@ namespace RotateParticle
|
|||
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (var g in _warps)
|
||||
var strandMap = new Dictionary<Warp, Strand>();
|
||||
foreach (var warp in _warps)
|
||||
{
|
||||
var strands = new List<Strand>();
|
||||
var strand = _list.MakeParticleStrand(Env, g, default);
|
||||
var strand = _list.MakeParticleStrand(Env, warp, default);
|
||||
strands.Add(strand);
|
||||
|
||||
// InitializeCloth(g, _list, strands, _clothRects);
|
||||
_strands.AddRange(strands);
|
||||
strandMap.Add(warp, strand);
|
||||
}
|
||||
|
||||
foreach (var cloth in _cloths)
|
||||
{
|
||||
InitializeCloth(cloth, _list, _clothRects, strandMap);
|
||||
}
|
||||
|
||||
_newPos = new(_list._particles.Count);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user