playMaker

Author Topic: ArrayList Get Vertex Positions (world space)  (Read 398 times)

looi

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
ArrayList Get Vertex Positions (world space)
« on: April 10, 2019, 06:25:56 PM »
Hello,

I've modified the action ArrayListGetVertexPositions to obtain the world space points of a mesh vertices instead of local points.

I think it might be usefull to upload it to Ecosystem.

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable

// credits: action created by LampRabbit: http://hutonggames.com/playmakerforum/index.php?topic=3982.msg18550#msg18550

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Store mesh vertex positions into an arrayList")]
public class ArrayListGetVertexPositions : ArrayListActions
{

[ActionSection("Set up")]

[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;


[ActionSection("Source")]

[Tooltip("the GameObject to get the mesh from")]
[CheckForComponent(typeof(MeshFilter))]
public FsmGameObject mesh;



public override void Reset()
{
gameObject = null;
reference = null;
mesh = null;

}


public override void OnEnter()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
getVertexPositions();

Finish();
}


public void getVertexPositions()
{
if (! isProxyValid())
return;

proxy.arrayList.Clear();


GameObject _go = mesh.Value;
if (_go==null)
{
return;
}


MeshFilter _mesh = _go.GetComponent<MeshFilter>();
if (_mesh ==null)
{
return;
}
            proxy.arrayList.Clear();
            for (int i = 0; i < _mesh.mesh.vertices.Length; i++) {
                proxy.arrayList.Add(_mesh.transform.TransformPoint(_mesh.mesh.vertices[i]));
            }

//proxy.arrayList.InsertRange(0,_mesh.mesh.vertices);


}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14832
  • Official Playmaker Support
    • View Profile
Re: ArrayList Get Vertex Positions (world space)
« Reply #1 on: April 10, 2019, 11:29:26 PM »
Hi,

 cool, but maybe you could create an FsmBool to let the developer the choice to choose between local or world space? then I can upload it, because as is it would break existing project that rely on local space positions.

 BYe,

 Jean

looi

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Re: ArrayList Get Vertex Positions (world space)
« Reply #2 on: April 12, 2019, 02:43:11 PM »
OK, worldSpace bool added:

Code: [Select]
// (c) Jean Fabre, 2011-2013 All rights reserved.
// http://www.fabrejean.net

// INSTRUCTIONS
// Drop a PlayMakerArrayList script onto a GameObject, and define a unique name for reference if several PlayMakerArrayList coexists on that GameObject.
// In this Action interface, link that GameObject in "arrayListObject" and input the reference name if defined.
// Note: You can directly reference that GameObject or store it in an Fsm variable or global Fsm variable

// credits: action created by LampRabbit: http://hutonggames.com/playmakerforum/index.php?topic=3982.msg18550#msg18550

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Store mesh vertex positions into an arrayList")]
public class ArrayListGetVertexPositions2 : ArrayListActions
{

[ActionSection("Set up")]

[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;


[ActionSection("Source")]

[Tooltip("the GameObject to get the mesh from")]
[CheckForComponent(typeof(MeshFilter))]
public FsmGameObject mesh;
        public bool worldSpace;


public override void Reset()
{
gameObject = null;
reference = null;
mesh = null;
worldSpace = false;
}


public override void OnEnter()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
getVertexPositions();

Finish();
}


public void getVertexPositions()
{
if (! isProxyValid())
return;

proxy.arrayList.Clear();


GameObject _go = mesh.Value;
if (_go==null)
{
return;
}


MeshFilter _mesh = _go.GetComponent<MeshFilter>();
if (_mesh ==null)
{
return;
}

            if (worldSpace)
            {
                for (int i = 0; i < _mesh.mesh.vertices.Length; i++)
                {
                    proxy.arrayList.Add(_mesh.transform.TransformPoint(_mesh.mesh.vertices[i]));
                }
            }
            else
            {
                proxy.arrayList.InsertRange(0, _mesh.mesh.vertices);
            }


}
}
}