public ClothSimulator(ClothMeshModifier meshModifier, ClothSetting setting)
        {
            _meshModifier = meshModifier;
            _setting      = setting;

            var vertexCount = meshModifier.vertexCount;

            _predictPositions = new NativeList <float3>(vertexCount, Allocator.Persistent);
            _predictPositions.AddRange(meshModifier.vertices);

            _velocities = new NativeList <float3>(vertexCount, Allocator.Persistent);
            _velocities.Resize(vertexCount, NativeArrayOptions.ClearMemory);

            _pinConstraints = new NativeList <PinConstraintInfo>(vertexCount, Allocator.Persistent);
            _pinConstraints.Resize(vertexCount, NativeArrayOptions.ClearMemory);

            _collisionConstraints = new NativeList <CollisionConstraintInfo>(vertexCount, Allocator.Persistent);
            _collisionConstraints.Resize(vertexCount, NativeArrayOptions.ClearMemory);

            _constraintTypes = new NativeList <ConstraintType>(vertexCount, Allocator.Persistent);
            _constraintTypes.Resize(vertexCount, NativeArrayOptions.ClearMemory);

            _positionCorrects = new NativeArray <float3>(vertexCount, Allocator.Persistent);

            _colliderDescGroups = new CollidersGroup(Allocator.Persistent);

            _rigidBodyForceApplys = new NativeList <RigidBodyForceApply>(vertexCount * 8, Allocator.Persistent);

            this.BuildMasses();
            this.BuildDistConstraints();
            this.BuildBendConstraints();
        }
Exemple #2
0
 void Awake()
 {
     _meshFilter            = GetComponent <MeshFilter>();
     _meshFilter.sharedMesh = Object.Instantiate(_meshFilter.sharedMesh);
     _mesh         = _meshFilter.sharedMesh;
     _meshModifier = ClothMeshModifier.CreateFromMeshFilter(_meshFilter);
     _simulator    = new ClothSimulator(_meshModifier, this.setting);
     foreach (var c in colliderProxies)
     {
         _simulator.AddCollider(c);
     }
 }