16-10-2019, 08:10 AM
Creating a Cloth object with Obi before running was a success.
However, the cloth generated at runtime seems to mean that it doesn't move with the red particles as shown. (Attachment 1)
How should I write a script to fix this?
The method I tried is the following script,
Before the initialization coroutine was finished, the value was rewritten, and only the last particle appeared blue, which was meaningless. (Attachment 2)
How can I solve it?
However, the cloth generated at runtime seems to mean that it doesn't move with the red particles as shown. (Attachment 1)
How should I write a script to fix this?
The method I tried is the following script,
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[RequireComponent(typeof(MeshFilter))]
// [RequireComponent(typeof(SkinnedMeshRenderer))]
public class genCloth : MonoBehaviour
{
public Mesh mesh;
public SphereCollider virtualHand;
public float Damping = 0;
public float Stretching = 0;
public float Bending = 0;
public int resolution;
public Vector3 Accelerration;
private Cloth component;
public ObiSolver solver;
public ObiMeshTopology topology;
public void setUpObi() {
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.");
}
ObiCloth cloth = GetComponent<ObiCloth>();
var filter = GetComponent<MeshFilter>();
filter.sharedMesh = mesh;
var skin = GetComponent<SkinnedMeshRenderer>();
skin.sharedMesh = mesh;
topology.InputMesh = mesh;
topology.Generate();
cloth.Solver = solver;
cloth.SharedTopology = topology;
cloth.enabled = true;
StartCoroutine(cloth.GeneratePhysicRepresentationForMesh());
cloth.AddToSolver(null);
for(int i = 0; i < mesh.vertices.Length; i++){
cloth.invMasses[i] = 1.0f / (Mathf.Max(1,0.00001f) * cloth.areaContribution[i]);
cloth.velocities[i] = Vector3.zero;
}
cloth.PushDataToSolver(ParticleData.INV_MASSES | ParticleData.VELOCITIES);
}
}
Before the initialization coroutine was finished, the value was rewritten, and only the last particle appeared blue, which was meaningless. (Attachment 2)
How can I solve it?