Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  About "Edit Particles-> Fix Translation" when creating cloth before execution.
#1
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,
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?
Reply
#2
(16-10-2019, 08:10 AM)tukuyo Wrote: 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,
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?

Simply wait for the GeneratePhysicRepresentationForMesh() coroutine to finish before changing particle masses. You're immediately continuing after spawning the coroutine and changing masses/velocities, so the coroutine (whose execution is interleaved with the code after the StartCoroutine call) is overwriting your values.
Reply
#3
(16-10-2019, 08:26 AM)josemendez Wrote: Simply wait for the GeneratePhysicRepresentationForMesh() coroutine to finish before changing particle masses. You're immediately continuing after spawning the coroutine and changing masses/velocities, so the coroutine (whose execution is interleaved with the code after the StartCoroutine call) is overwriting your values.

Thank you for your prompt reply.

By waiting for the coroutine, we were able to fix Fix translation.
However, when executed, it seems to move from the original position to the origin as in the image.

How can I fix it?
Reply
#4
(17-10-2019, 01:45 PM)tukuyo Wrote: Thank you for your prompt reply.

By waiting for the coroutine, we were able to fix Fix translation.
However, when executed, it seems to move from the original position to the origin as in the image.

How can I fix it?



I solved it myself.

The problem was simple: just use MeshRenderer instead of SkinnedMeshRenderer.
Reply