Game Development Community

How to clone (copy) an instance of t2dPath?

by Dmitriy Stukalov · in Torque Game Builder · 07/09/2007 (4:52 am) · 6 replies

Hi,

I need to get a copy of t2dPath instance. Code I use is:

%first_path = new t2dPath();
%first_path.addNode(...);
%first_path.addNode(...);
%first_path.addNode(...);

// ...

%second_path = %first_path.clone(TRUE);

or

// ...

%second_path =  new t2dPath();
%first_path.copy(%second_path, TRUE);

It is not work properly because echo(%second_path.getNodeCount()) return 0.

Could someone help me? Is any way to get the copy (the clone) of the path instance?
Thank you.

#1
07/09/2007 (11:17 am)
T2dPath as of 1.1.3 is not clone-friendly. For now you'd have to create a new t2dPath object and looping through the old path's nodes and adding them manually, effectively writing the clone() functionality in script. Dunno if this has been fixed in 1.5 or not.
#2
07/09/2007 (11:21 am)
Do you ever add the first path to the scene? You can't clone things that don't exist in the scene.

%first_path.addToScene(%scenegraph);
#3
07/09/2007 (9:51 pm)
Thank you Luke and Melissa,

Yes, first thing I do after creationg the first path is adding it to scene (I've exclude several strings from my code).

Unfortunately, I have no some ideas how to get nodes of the first path. I have no found appropriate metod of t2dPath class (i.e. getNode). I have found getNodeCount only!
#4
07/10/2007 (7:35 am)
Quote:Unfortunately, I have no some ideas how to get nodes of the first path.
I make it simple: just add user field like usernode0...usernodeN with same value in addNode(...), while I create path. After, you can access to you nodes like %path.usernode[%i], where %i is index of a node. This is simple way. Another way is modifying t2dPath source and add new console method getNode() (There is already C++ method, you can make it scriptable).
#5
07/10/2007 (9:47 am)
It's currently undocumented (t2dPath seems to be a work-in-progress) but as of 1.1.3 there is a getNode() ConsoleMethod already in the engine, so you can loop through calling %myPath.getNode() and get a string representing " ".
#6
07/10/2007 (9:52 pm)
Thank you Igor,

Really suitable and very simple approach!


Thank you Luke,

It looks like t2dPath is under construction! There are many way to improve its functionality and usefullness.


Recently I developed more powerful Bezier path editor. It helps me to create very complex paths. If you are interested, please look this thread.

Direct links:
Screenshot.
Download link.