public IEnumerator Start() { // just some user input checks: if (mesh == null || topology == null) { Debug.LogError("Either the mesh or the topology are null. You must provide a mesh and an empty topology asset in order to generate cloth."); yield break; } // generate a topology for the cloth mesh: topology.InputMesh = mesh; topology.Generate(); // set the cloth topology and solver: cloth.Solver = solver; cloth.SharedTopology = topology; // generate particles (in a coroutine, as it can be quite slow) and add to the solver: yield return(StartCoroutine(GenerateAndAddToSolver())); if (Done != null) { Done(this, EventArgs.Empty); } }
IEnumerator generatecloth() { here = this.gameObject; //Debug.Log(here.name); //Debug.Log(this.name); //ObiMeshTopology.CreateInstance("meshtopology"); ObiMeshTopology meshtopology = ScriptableObject.CreateInstance <ObiMeshTopology>(); meshtopology.InputMesh = here.GetComponent <MeshFilter>().sharedMesh; // Debug.Log(ss.InputMesh.name); meshtopology.Generate(); //for meshtoplogy GameObject solveroriginal = new GameObject(); //get solver from the assets // solveroriginal.AddComponent<ObiSolver>(); here.AddComponent <ObiCloth>(); ObiCloth tmp = here.GetComponent <ObiCloth>(); //tmp.Solver.RelinquishRenderablePositions(); tmp.SelfCollisions = true; //set solve parameters // or tmp.Solver = solveroriginal.AddComponent<ObiSolver>(); tmp.Solver = solveroriginal.AddComponent <ObiSolver>(); tmp.Solver.maxParticles = 6000; tmp.Solver.volumeConstraintParameters.enabled = false; tmp.Solver.skinConstraintParameters.enabled = false; tmp.Solver.tetherConstraintParameters.enabled = false; tmp.Solver.densityConstraintParameters.enabled = false; tmp.Solver.bendingConstraintParameters.evaluationOrder = Oni.ConstraintParameters.EvaluationOrder.Parallel; //sequantial to reduce iterations amount tmp.Solver.distanceConstraintParameters.iterations = 5; tmp.Solver.bendingConstraintParameters.iterations = 5; tmp.Solver.shapeMatchingConstraintParameters.iterations = 5; tmp.Solver.collisionConstraintParameters.iterations = 5; tmp.Solver.shapeMatchingConstraintParameters.iterations = 5; tmp.Solver.stitchConstraintParameters.iterations = 5; tmp.Solver.particleCollisionConstraintParameters.iterations = 5; tmp.Solver.pinConstraintParameters.iterations = 5; // pin constraints for particle tmp.Solver.substeps = 1; //improve substeps for a better quality than manual setting // tmp.Solver. tmp.SharedTopology = meshtopology; yield return(tmp.StartCoroutine(tmp.GeneratePhysicRepresentationForMesh())); tmp.AddToSolver(null); //add constraints back }
public IEnumerator MakeCloth(Vector3 attachmentOffset)//Transform anchoredTo, Vector3 attachmentOffset { /*生成方形碰撞体*/ myCube = GameObject.CreatePrimitive(PrimitiveType.Cube); myCube.name = "myCube"; myCube.transform.position = attachmentOffset; /*生成平面布料*/ myPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); myPlane.name = "myPlane"; myPlane.AddComponent <ObiCloth>(); myPlane.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); myPlane.transform.position = new Vector3(attachmentOffset.x, attachmentOffset.y + 2, attachmentOffset.z); /*生成求解器*/ mySolver = new GameObject("mySolver", typeof(ObiSolver)); /*各组件绑定*/ cloth = myPlane.GetComponent <ObiCloth>(); solver = mySolver.GetComponent <ObiSolver>(); /*生成拓扑*/ topology = ScriptableObject.CreateInstance <ObiMeshTopology>(); topology.InputMesh = myPlane.GetComponent <MeshCollider>().sharedMesh; topology.scale = new Vector3(0.3f, 0.3f, 0.3f); topology.Generate(); /*衣服组件绑定求解器和拓扑*/ cloth.Solver = solver; cloth.SharedTopology = topology; //不需要Init? //碰撞处理 addCollision(); //多线程 yield return(cloth.StartCoroutine(cloth.GeneratePhysicRepresentationForMesh())); cloth.AddToSolver(null); }