[SOLVED] APIs between vectors and arrays needed

Hi all the Playcanvas team menbers and Playcanvas game developers!
I am a game developer using vue and Playcanvas engine-only. For some reason, I need to convert vector objects into arrays or convert oppositely frequently. I can rebuild the engine to add some methods to finish it, but it is not convenient to test my game scripts on the Playcanvas web editor. Is there any APIs to do this converting easily, or can we have a ‘toArray’ method under the pc.VecN/pc.matN/pc.Color class in future versions of Playcanvas? And it is better if the method pc.VecN().set can accept array-type parameter.
Thanks for reading!

Hi @Aryous,

There is an internal (private) typed array on the pc.Vec/pc.Mat/pc.Color etc. classes, you can access it like this to get a flatten array of the data:


About set accepting an array to fill its values, I understand that can be helpful. You could create your own helper functions for that and you could also extend the class prototype methods to add your own internal functions to the object.

Hope that helps.

1 Like

Hi @Leonidas
This can really help. I used to extend the prototype before and it would cause extra work when I copy my scripts from web editor to the vue project. Accessing ‘.data’ can simplify both the scripts and the development process.
Thanks a lot!

1 Like