Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Marquee tool
#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


Messages In This Thread
Marquee tool - by Richard - 09-06-2019, 05:06 PM
RE: Marquee tool - by josemendez - 10-06-2019, 08:32 AM
RE: Marquee tool - by Richard - 10-06-2019, 09:21 AM
RE: Marquee tool - by josemendez - 10-06-2019, 02:19 PM
RE: Marquee tool - by Richard - 10-06-2019, 02:37 PM
RE: Marquee tool - by josemendez - 10-06-2019, 03:44 PM
RE: Marquee tool - by Richard - 10-06-2019, 04:14 PM
RE: Marquee tool - by josemendez - 10-06-2019, 07:21 PM
RE: Marquee tool - by Richard - 11-06-2019, 08:38 AM
RE: Marquee tool - by josemendez - 11-06-2019, 09:04 AM
RE: Marquee tool - by Richard - 11-06-2019, 09:14 AM
RE: Marquee tool - by josemendez - 11-06-2019, 11:06 AM
RE: Marquee tool - by Richard - 11-06-2019, 11:38 AM
RE: Marquee tool - by josemendez - 11-06-2019, 12:02 PM
RE: Marquee tool - by Richard - 11-06-2019, 04:21 PM
RE: Marquee tool - by josemendez - 12-06-2019, 07:13 AM
RE: Marquee tool - by Richard - 12-06-2019, 11:10 AM
RE: Marquee tool - by josemendez - 12-06-2019, 12:23 PM
RE: Marquee tool - by Richard - 12-06-2019, 12:49 PM