Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  how to make obi cloth on script
#1
I am trying to make obi cloth on script. I saw scripting Actors of user manual.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class SetupCloth : MonoBehaviour
{
   GameObject obj;

   ObiActor actor;
   public ObiSolver solver;
   
   void Start()
   {
       obj = GameObject.Find("cloth");
       Mesh mesh = obj.GetComponent<MeshFilter>().sharedMesh;

       GameObject clothObject = new GameObject("cloth", typeof(ObiSolver),typeof(ObiCloth));

       // get references to all components:
       ObiCloth cloth = clothObject.GetComponent();
       ObiSolver solver = clothObject.GetComponent();

       // generate the topology:
       ObiMeshTopology topology = ScriptableObject.CreateInstance(sourceTopology);
       topology.InputMesh = mesh;
       topology.Generate();

       // set the cloth topology and solver:
       cloth.Solver = solver;
       cloth.SharedTopology = topology;
   }

}
What is wrong with that? I had three errors.

Assets\SetupCloth.cs(21,38): error CS0411: The type arguments for method 'GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Assets\SetupCloth.cs(22,40): error CS0411: The type arguments for method 'GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Assets\SetupCloth.cs(25,68): error CS0103: The name 'sourceTopology' does not exist in the current context
Reply
#2
(30-05-2019, 12:51 AM)Richard Wrote: I am trying to make obi cloth on script. I saw scripting Actors of user manual.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class SetupCloth : MonoBehaviour
{
   GameObject obj;

   ObiActor actor;
   public ObiSolver solver;
   
   void Start()
   {
       obj = GameObject.Find("cloth");
       Mesh mesh = obj.GetComponent<MeshFilter>().sharedMesh;

       GameObject clothObject = new GameObject("cloth", typeof(ObiSolver),typeof(ObiCloth));

       // get references to all components:
       ObiCloth cloth = clothObject.GetComponent();
       ObiSolver solver = clothObject.GetComponent();

       // generate the topology:
       ObiMeshTopology topology = ScriptableObject.CreateInstance(sourceTopology);
       topology.InputMesh = mesh;
       topology.Generate();

       // set the cloth topology and solver:
       cloth.Solver = solver;
       cloth.SharedTopology = topology;
   }

}
What is wrong with that? I had three errors.

Assets\SetupCloth.cs(21,38): error CS0411: The type arguments for method 'GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Assets\SetupCloth.cs(22,40): error CS0411: The type arguments for method 'GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Assets\SetupCloth.cs(25,68): error CS0103: The name 'sourceTopology' does not exist in the current context

Hi,

Unity's GetComponent function needs a generic argument or a type argument:
https://docs.unity3d.com/ScriptReference...onent.html
https://unity3d.com/es/learn/tutorials/t...tcomponent

Also, you need to declare the "sourceTopology" variable somewhere!

The code in these examples is pseudocode and will not work unless used in the appropriate context.
Reply
#3
(30-05-2019, 07:15 AM)josemendez Wrote: Hi,

Unity's GetComponent function needs a generic argument or a type argument:
https://docs.unity3d.com/ScriptReference...onent.html
https://unity3d.com/es/learn/tutorials/t...tcomponent

Also, you need to declare the "sourceTopology" variable somewhere!

The code in these examples is pseudocode and will not work unless used in the appropriate context.

I did not notice that is just pseudocode, and I could solve errors of cloth and solver. However, how can I "Generate" mesh of Obi Mesh Topology on script?
Reply
#4
(30-05-2019, 10:24 AM)Richard Wrote: I did not notice that is just pseudocode, and I could solve errors of cloth and solver. However, how can I "Generate" mesh of Obi Mesh Topology on script?

Hi,

You have a fully working example of how to procedurally create a mesh, generate a topology, and create the cloth actor in Obi/SampleScenes/RuntimeCloth. It uses the RuntimeClothGenerator.cs and SackGenerator.cs sample scripts.
Reply
#5
(30-05-2019, 10:30 AM)josemendez Wrote: Hi,

You have a fully working example of how to procedurally create a mesh, generate a topology, and create the cloth actor in Obi/SampleScenes/RuntimeCloth. It uses the RuntimeClothGenerator.cs and SackGenerator.cs sample scripts.

I erased error. However my computer displays "There are inconsistent line endings in the 'Assets/SetupCloth.cs' script. Some are Mac OS X (UNIX) and some are Windows.

This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands."
Would you check mine?
Reply
#6
(30-05-2019, 11:26 AM)Richard Wrote: I erased error. However my computer displays "There are inconsistent line endings in the 'Assets/SetupCloth.cs' script. Some are Mac OS X (UNIX) and some are Windows.

This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands."
Would you check mine?

Simply resave the file. This happens when a file has been edited in both macOS and Windows.
Reply
#7
(30-05-2019, 12:13 PM)josemendez Wrote: Simply resave the file. This happens when a file has been edited in both macOS and Windows.

I did, but it does not work.
Reply
#8
(30-05-2019, 12:36 PM)Richard Wrote: I did, but it does not work.

Depending on what text editor/IDE you're using, some need you to specify the line ending format. For instance, if you're using Visual Studio:
https://developercommunity.visualstudio....n-mac.html

And please, refrain from asking questions that are completely unrelated to Obi. I will no longer answer them.
Reply
#9
(30-05-2019, 03:38 PM)josemendez Wrote: Depending on what text editor/IDE you're using, some need you to specify the line ending format. For instance, if you're using Visual Studio:
https://developercommunity.visualstudio....n-mac.html

And please, refrain from asking questions that are completely unrelated to Obi. I will no longer answer them.

Sorry. I thought it was one of obi. If my question is not related to obi, let me know, and you do not have to answer. Is there no problem with my code?
Reply
#10
(30-05-2019, 03:45 PM)Richard Wrote: Sorry. I thought it was one of obi. If my question is not related to obi, let me know, and you do not have to answer. Is there no problem with my code?

If there are no compile errors, it generally means your code makes sense (at least to the compiler). If you post your complete code I can tell for sure if it does what it is supposed to do.
Reply