Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Marquee tool
#11
(11-06-2019, 09:04 AM)josemendez Wrote: Hi Richard,

You just copy-pasted code straight out the particle editor (which is editor code, that cannot run in-game), without modifying it. You just cannot use this code as-is in your game, it won't work.

Blindly copy-pasting code won't get you far. You need to understand what you're writing and why. For instance, the selectionStatus array is a per-particle array that holds whether each particle is selected or not. This only makes sense in the context of in-editor selection. The "Undo" class only exists in the UnityEditor namespace, so you cannot use it here.

As I've pointed out multiple times before, you must determine whether you're writing an editor tool, or code for a game. You're constantly mixing up both.
Hello.

Is it possible to write code for a game?
Reply
#12
(11-06-2019, 09:14 AM)Richard Wrote: Hello.

Is it possible to write code for a game?

If you are asking whether is it possible to create a marquee selection tool for a game, yes it is. But honestly, I'm still pretty unsure about what your goal is.
Reply
#13
(11-06-2019, 11:06 AM)josemendez Wrote: If you are asking whether is it possible to create a marquee selection tool for a game, yes it is. But honestly, I'm still pretty unsure about what your goal is.

My goal is to make obi handle at runtime and change scale of cloth to fit to object.
Reply
#14
(11-06-2019, 11:38 AM)Richard Wrote: My goal is to make obi handle at runtime and change scale of cloth to fit to object.

You asked this before, and I answered with code to do it:
http://obi.virtualmethodstudio.com/forum...ght=handle

My guess is that you want to let the user click and drag a rectangle on the screen to select multiple particles, then create a handle out of them. All of this, in your own application/game, not in the editor. So you're essentially making your own in-game particle editor. Is this correct?
Reply
#15
(11-06-2019, 12:02 PM)josemendez Wrote: You asked this before, and I answered with code to do it:
http://obi.virtualmethodstudio.com/forum...ght=handle

My guess is that you want to let the user click and drag a rectangle on the screen to select multiple particles, then create a handle out of them. All of this, in your own application/game, not in the editor. So you're essentially making your own in-game particle editor. Is this correct?
No...
Sorry for my English...
I don't let user click and drag or any manipulate... Some clothing like uniform of speed skating, clothing has to be fit to object. Or other clothing like underwear of women need it . I would like to do that automatically.
In the process, I want to choose particles by script, create obi handle and change scale.

ObiSolver.position is below of ObiSolver.cs?

Code:
private void InitializeTransformFrame(){
        Vector4 translation = transform.position;
        Vector4 scale = transform.lossyScale;
        Quaternion rotation = transform.rotation;
        Oni.InitializeFrame(this.oniSolver,ref translation,ref scale, ref rotation);
    }

I could not get variables like translation from there...
In reference of ObiSolver, there is "AlignedVector4Array positions". There is not that in ObiSolver.cs now.



I got position now. However, the position's type becomes float, not vector3...
Reply
#16
(11-06-2019, 04:21 PM)Richard Wrote: No...
Sorry for my English...
I don't let user click and drag or any manipulate... Some clothing like uniform of speed skating, clothing has to be fit to object. Or other clothing like underwear of women need it and pants we usually wear's waist is adjust to our body by rubber or belt. I would like to do that automatically.
In the process, I want to choose particles by script, create obi handle and change scale.

ObiSolver.position is below of ObiSolver.cs?

Code:
private void InitializeTransformFrame(){
Vector4 translation = transform.position;
Vector4 scale = transform.lossyScale;
Quaternion rotation = transform.rotation;
Oni.InitializeFrame(this.oniSolver,ref translation,ref scale, ref rotation);
}

I could not get variables like translation from there...
In reference of ObiSolver, there is "AlignedVector4Array positions". There is not that in ObiSolver.cs now.



I got position now. However, the position's type becomes float, not vector3...

In Obi 4.x, ObiSolver contains multiple per-particle data arrays: positions, velocities, invMasses, etc. The one you're interested in is "positions". Each position is a Vector4, with the w component set to 0.

The InitializeTransformFrame method you posted above has nothing to do with particles or particle data. As the name implies, it initializes the solver's inertial transform frame.
Reply
#17
(12-06-2019, 07:13 AM)josemendez Wrote: In Obi 4.x, ObiSolver contains multiple per-particle data arrays: positions, velocities, invMasses, etc. The one you're interested in is "positions". Each position is a Vector4, with the w component set to 0.

The InitializeTransformFrame method you posted above has nothing to do with particles or particle data. As the name implies, it initializes the solver's inertial transform frame.

How can I get position? Or what is the best way to achieve what I want to do?

I am thinking of AddParticle of ObiParticleHandle.cs
Reply
#18
(12-06-2019, 11:10 AM)Richard Wrote: How can I get position? Or what is the best way to achieve what I want to do?

I am thinking of AddParticle of ObiParticleHandle.cs

solver.positions[solverIndex];

or

actor.GetParticlePosition(actorIndex);

See the docs:
http://obi.virtualmethodstudio.com/tutor...icles.html
Reply
#19
(12-06-2019, 12:23 PM)josemendez Wrote: solver.positions[solverIndex];

or

actor.GetParticlePosition(actorIndex);

See the docs:
http://obi.virtualmethodstudio.com/tutor...icles.html

If I create editor, not in-game. How should I do? Like just put position and create handle... The position is up to the cloth..



What is the difference? And how should I change another script? There is "positions" in ObiSolver.cs, but how and where to change?

Code:
for (int i = 0; i < actor.positions.Length; ++i)
           {
               int indexInSolver = actor.particleIndices[i];

               Vector3 projectedPos = GetComponent<Camera>().WorldToScreenPoint(actor.GetParticlePosition(i));
               selectionStatus[i] = true;
           }
I tried actor.GetParticlePosition

Now, my code is
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Obi
{
   public class CreateHandle : MonoBehaviour
   {
       public ObiActor actor;
       public ObiSolver solver;
       //public Transform anchor;
       static protected Vector3[] wsPositions = new Vector3[0];
       static public bool[] selectionStatus = new bool[0];
       static int lastSelectedParticle = 0;
       //Selection related:
       static protected int selectedCount = 0;
       public static int SelectedParticleCount
       {
           get { return selectedCount; }
       }

       void Awake()
       {
           UpdateParticleEditorInformation();
       }
       
       void Start()
       {
           //actor = GetComponent<ObiActor>();
           ObiSolver solver = actor.Solver;
           //ObiPos = GetComponent<ObiSolver>().translation;
           
           for (int i = 0; i < actor.positions.Length; ++i)
           {
               int indexInSolver = actor.particleIndices[i];

               Vector3 projectedPos = GetComponent<Camera>().WorldToScreenPoint(actor.GetParticlePosition(i));
               selectionStatus[i] = true;
           }


           // Create the handle:
           GameObject c = new GameObject("Obi Handle");
           ObiParticleHandle handle = c.AddComponent<ObiParticleHandle>();
           handle.Actor = actor;

           selectedCount = 0;
           for (int i = 0; i < selectionStatus.Length; i++)
           {
               if (actor.active[i] && selectionStatus[i])
               {
                   selectedCount++;
                   lastSelectedParticle = i;
               }
           }

           // Calculate position of handle from average of particle positions:
           Vector3 average = Vector3.zero;
           for (int i = 0; i < selectionStatus.Length; i++)
           {
               if (selectionStatus[i])
               {
                   average += wsPositions[i];
               }
           }

           c.transform.position = average / selectedCount;

           // Add the selected particles to the handle:
           for (int i = 0; i < selectionStatus.Length; i++)
           {
               if (selectionStatus[i])
               {
                   handle.AddParticle(i, wsPositions[i], actor.invMasses[i]);
               }
           }
       }

       
       void Update()
       {
           UpdateParticleEditorInformation();
       }

       void UpdateParticleEditorInformation()
       {

           for (int i = 0; i < actor.positions.Length; i++)
           {
               if (actor.active[i])
               {
                   wsPositions[i] = actor.transform.TransformPoint(actor.positions[i]);
                   //facingCamera[i] = true;
               }
           }

       }
   }
}

I have an error now

IndexOutOfRangeException: Index was outside the bounds of the array.
Obi.CreateHandle.UpdateParticleEditorInformation () (at Assets/CreateHandle.cs:102)
Obi.CreateHandle.Awake () (at Assets/CreateHandle.cs:25)

I got another error:
transform.position assign attempt for 'Obi Handle' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform;set_position(Vector3)
Obi.CreateHandle:Start() (at Assets/CreateHandle.cs:78)

After that, error erased and result of GetParticlePosition became (0,0,0,0) a lot.

I noticed that I failed to get component of actor..

My try of solver.position is

Code:
void Start()
       {
           
           actor = GetComponent<ObiActor>();
           ObiSolver solver = actor.Solver;
           actor.PullDataFromSolver(ParticleData.POSITIONS | ParticleData.VELOCITIES);
         
           for (int i = 0; i < actor.positions.Length; ++i)
           {
               Debug.Log(actor.positions[i]);
             }

           }

       }

Most of the log is (0,0,0,0)... and a lot of results are like (0.0, 0.2, -0.3)...

I tried renderablePositions, all of the result are (0,0,0,0)...
Reply