void Start() { //Initialize mesh and state variables radius = transform.lossyScale.x; transform.localScale = Vector3.one; MeshFilter filter = GetComponent <MeshFilter>(); bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); originalVerts = bodyMesh.vertices; filter.mesh = bodyMesh; renderNormalsArray = new Vector3[originalVerts.Length]; bodyVertsArray = new Vector3[originalVerts.Length]; kabschVertsArray = new Vector4[originalVerts.Length]; //Create Distance Constraints from Triangles in Mesh constraintsList = new List <Verlet.DistConstraint>(originalVerts.Length * 3); Verlet.setUpConstraints(bodyMesh, constraintsList, false, radius); softbodyData = new SoftbodyData(bodyMesh, transform, constraintsList, new Vector3(Physics.gravity.x / transform.lossyScale.x, Physics.gravity.y / transform.lossyScale.y, Physics.gravity.z / transform.lossyScale.z), groundPlane, radius, friction); priorDebuggerState = JobsUtility.JobDebuggerEnabled; JobsUtility.JobDebuggerEnabled = false; }
void Start() { //Initialize mesh and state variables MeshFilter filter = GetComponent <MeshFilter>(); bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); bodyVerts = bodyMesh.vertices; kabschVerts = Array.ConvertAll(bodyVerts, (p => new Vector4(p.x, p.y, p.z, 1f))); originalVerts = bodyMesh.vertices; bodyTriangles = bodyMesh.triangles; bodyNormals = bodyMesh.normals; renderNormals = bodyMesh.normals; prevBodyVerts = new Vector3[bodyVerts.Length]; accumulatedDisplacements = new Vector4[bodyVerts.Length]; for (int i = 0; i < bodyVerts.Length; i++) { prevBodyVerts[i] = transform.TransformPoint(bodyVerts[i]); } filter.mesh = bodyMesh; //Create Distance Constraints from Triangles in Mesh constraints = new List <Verlet.DistConstraint>(bodyVerts.Length * 3); Verlet.setUpConstraints(bodyMesh, constraints, false); //Scale gravity by the size of this Mesh Renderer scaledGravity = new Vector3(Physics.gravity.x / transform.lossyScale.x, Physics.gravity.y / transform.lossyScale.y, Physics.gravity.z / transform.lossyScale.z); initialVolume = Verlet.VolumeOfMesh(bodyVerts, bodyTriangles); }
void Start() { MeshFilter filter = GetComponent <MeshFilter>(); clothMesh = Instantiate(filter.mesh); clothMesh.MarkDynamic(); clothVerts = clothMesh.vertices; prevClothVerts = clothMesh.vertices; accumulatedDisplacements = new Vector4[clothVerts.Length]; filter.mesh = clothMesh; //Create Distance Constraints from Triangles in Mesh constraints = new List <Verlet.DistConstraint>(clothVerts.Length * 3); Verlet.setUpConstraints(clothMesh, constraints, false); //Scale gravity by the size of this Mesh Renderer scaledGravity = new Vector3(Physics.gravity.x / transform.lossyScale.x, Physics.gravity.y / transform.lossyScale.y, Physics.gravity.z / transform.lossyScale.z); }
void Start() { //Initialize mesh and state variables MeshFilter filter = GetComponent <MeshFilter>(); bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); bodyVerts = new NativeArray <Vector3>(bodyMesh.vertices, Allocator.Persistent); kabschVerts = new NativeArray <Vector4>(Array.ConvertAll(bodyVerts.ToArray(), (p => new Vector4(p.x, p.y, p.z, 1f))), Allocator.Persistent); originalVerts = bodyMesh.vertices; int[] triangles = bodyMesh.triangles; Vector3Int[] tris = new Vector3Int[triangles.Length / 3]; for (int i = 0; i < tris.Length; i++) { tris[i] = new Vector3Int(triangles[i * 3], triangles[(i * 3) + 1], triangles[(i * 3) + 2]); } bodyTriangles = new NativeArray <Vector3Int>(tris, Allocator.Persistent); bodyNormals = new NativeArray <Vector3>(bodyMesh.normals, Allocator.Persistent); renderNormals = new NativeArray <Vector3>(bodyMesh.normals, Allocator.Persistent); prevBodyVerts = new NativeArray <Vector3>(new Vector3[bodyVerts.Length], Allocator.Persistent); accumulatedDisplacements = new NativeArray <Vector4>(new Vector4[bodyVerts.Length], Allocator.Persistent); for (int i = 0; i < bodyVerts.Length; i++) { prevBodyVerts[i] = transform.TransformPoint(bodyVerts[i]); } filter.mesh = bodyMesh; renderNormalsArray = new Vector3[renderNormals.Length]; bodyVertsArray = new Vector3[bodyVerts.Length]; kabschVertsArray = new Vector4[kabschVerts.Length]; //Create Distance Constraints from Triangles in Mesh constraintsList = new List <Verlet.DistConstraint>(bodyVerts.Length * 3); Verlet.setUpConstraints(bodyMesh, constraintsList, false); constraintsArray = new NativeArray <Verlet.DistConstraint>(constraintsList.ToArray(), Allocator.Persistent); //Scale gravity by the size of this Mesh Renderer scaledGravity = new Vector3(Physics.gravity.x / transform.lossyScale.x, Physics.gravity.y / transform.lossyScale.y, Physics.gravity.z / transform.lossyScale.z); initialVolume = Verlet.VolumeOfMesh(bodyVerts, bodyTriangles); optimizer.CalculateErrorDerivative = CalculateErrorDerivative; optimizer.Add(1f, "xScale"); optimizer.Add(Vector3.up, "yBasis"); optimizer.Add(Vector3.forward, "zBasis"); }
void Start() { //Initialize mesh and state variables MeshFilter filter = GetComponent <MeshFilter>(); bodyMesh = Instantiate(filter.mesh); bodyMesh.MarkDynamic(); bodyVerts = bodyMesh.vertices; originalVerts = bodyMesh.vertices; bodyTriangles = bodyMesh.triangles; bodyNormals = bodyMesh.normals; renderNormals = bodyMesh.normals; accumulatedDisplacements = new Vector4[bodyVerts.Length]; filter.mesh = bodyMesh; //Create Distance Constraints from Triangles in Mesh constraints = new List <Verlet.DistConstraint>(bodyVerts.Length * 3); Verlet.setUpConstraints(bodyMesh, constraints, false); initialVolume = Verlet.VolumeOfMesh(bodyVerts, bodyTriangles); }