Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

free scripts, plugins, models, textures
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

I finished to remaster my old plugin, "primitive tsxPython" (ptsxpy), for tS4.3, tS5.1, tS6.0, tS6.6, and Model side of ts7.6*.

Primitive tsxPython (ptsxpy) is another Python interpreter plugin for the trueSpace series. You can execute almost all tsxAPI functions defined in tSx (trueSpace extension) document from your script. The plugin would expand application of your Generative 3D Modelings, 3D animations, and 3D printing, etc. Draw out the hidden abilities of the trueSpace!

Visit the web site and download the FREE plugin and sample scripts!
https://biglode.com/ptsxpy

Join the user forum to discuss about the plugin and to exhibit your works! Testers are also welcome.
Your help improves the qualities of the the plugin.

Thank you.

Short movies:


Text and script: https://biglode.com/ptsxpy-uforum/viewtopic.php?t=8


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=17


Text and script: https://biglode.com/ptsxpy-uforum/viewtopic.php?t=5


Text and script: https://biglode.com/ptsxpy-uforum/viewtopic.php?t=7


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=18


Text and script: https://biglode.com/ptsxpy-uforum/viewtopic.php?t=6

Related topics:
Where is the DEVELOPER'S GUIDE?
viewtopic.php?t=5473

Are the tsxAPI*.doc redistributable? License terms?
viewtopic.php?t=5495

---------------------------
KNOWN FATAL BUG
Don't close the (black-and-white) console window using "x" button or Ctrl C key. If you close it with such actions, trueSpace will crash. The console window will close safely when you terminated trueSpace or when you right-clicked the ptsxpy icon and click "OK" button in a message-box.
---------------------------

(edited Mar 6 2019: Added tS6.0 to the first line.)
(edited Oct 24 2019: Added link to each text and script.)
(edited Apr 11 2022: Added a note for the console window.)
Last edited by borgcone on 11 Apr 2022, 12:49, edited 3 times in total.
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
clintonman
Captain
Posts: 5659
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by clintonman »

Looks really nice.
I have python 2.7 64bit installed on my system. Would I be able to use the python 3 32bit version of your plugin without any interference or problems from the other python?
Clinton Reese

http://clintons3d.com
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

clintonman wrote: 04 Mar 2019, 05:06 I have python 2.7 64bit installed on my system. Would I be able to use the python 3 32bit version of your plugin without any interference or problems from the other python?
As I wrote to "Trouble Shooting" in FAQ page, unfortunately pythonxx.dll in the system directory interferes the plugin.
- C:\Windows\SysWOW64 (if 64 bit Windows)
- C:\Windows\System32 (if 32 bit Windows)
The solution to avoid that is to rename or to move pythonXX.dll in the system directory temporally, AFAIK.
Please let me know if you (or someone else) have any hint to solve the problem.

Thank you.

The source code where main dll loads sub dll for each tS is:

Code: Select all

// Load a dll for each tS version
static bool
loaddllforeachtsver()
{
 char *dllnum;
 char loadpath[ 1000 ];
 DWORD errcd;

 // Get trueSpace major/minor version
 tsxGetTsVersionNbrs( &TsverMajor, &TsverMinor );
 dbg1( 1, "tSver=%d.%d \n", TsverMajor, TsverMinor );
 // Get method table pointers
 TSmode =
  ( ( TsverMajor == 500  &&
      TsverMinor == 1 )  ||
    TsverMajor / 100 == 4 )? 4 :
  TsverMajor / 100;
 switch ( TSmode ) {
   case 4:
		dllnum = "43";
		break;
   case 5:
		dllnum = "51";
		break;
   case 6:
   case 7:
		dllnum = "66";
		break;
   default:
		MessageBox( NULL,
			"The tsx does not support this tS version.\n",
			"ptsxpy",
			MB_OK + MB_ICONEXCLAMATION );
		return false;
 }

 dbg1( 2, "(0.5) ThisDLLDir=[%s]\n", ThisDLLDir );
 sprintf_s( loadpath, sizeof( loadpath ), "%s\\ptsx"
#ifdef PY3_BY_PROPERTYSHEET
  "3"
#else
  "2"
#endif
  "pysb%s"
#ifdef _DEBUG
  "_d"
#else
  ""
#endif
  ".dll", ThisDLLDir, dllnum );
 // Add this DLL's directory to Path environment variable
 char wks1[ 3000 ];
 GetEnvironmentVariable( (LPCTSTR)"Path", (LPTSTR)wks1, sizeof( wks1 ) );
 strcat_s( wks1, sizeof( wks1 ), ";" );
 strcat_s( wks1, sizeof( wks1 ), ThisDLLDir );
 SetEnvironmentVariable( (LPCTSTR)"Path", (LPCTSTR)wks1 );
 dbg1( 2, "Path=%s\n", wks1 );
 dbg1( 2, "(1) loadpath=%s\n", loadpath );
 // 
 if ( !is_dllforeachver_loaded ) {
   if ( !( HInst_dllforeachtsver = ::LoadLibrary( loadpath ) ) ) {
     errcd = GetLastError();
     dbg1( 1, "Failed to LoadLibrary( \"%s\" ).  errcd=%ld\n",
      loadpath, errcd );
     return false;
   }
   is_dllforeachver_loaded = true;
 }
 return true;
}
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
clintonman
Captain
Posts: 5659
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by clintonman »

borgcone wrote: 04 Mar 2019, 07:04 As I wrote to "Trouble Shooting" in FAQ page, unfortunately pythonxx.dll in the system directory interferes the plugin.
- C:\Windows\SysWOW64 (if 64 bit Windows)
- C:\Windows\System32 (if 32 bit Windows)
The solution to avoid that is to rename or to move pythonXX.dll in the system directory temporally, AFAIK.
Please let me know if you (or someone else) have any hint to solve the problem.

Thank you.

The source code where main dll loads sub dll for each tS is:
I have an idea, maybe if you place it at the start of the path instead of the end then maybe it finds your dll first. Something like this:

Code: Select all

char wks_pre[ 3000 ];
 GetEnvironmentVariable( (LPCTSTR)"Path", (LPTSTR)wks1, sizeof( wks1 ) );
 strcat_s( wks_pre, sizeof( wks_pre ), ThisDLLDir );
 strcat_s( wks_pre, sizeof( wks_pre ), ";" );
 strcat_s( wks_pre, sizeof( wks_pre ), wks1);
 SetEnvironmentVariable( (LPCTSTR)"Path", (LPCTSTR)wks_pre );

Clinton Reese

http://clintons3d.com
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

clintonman wrote: 04 Mar 2019, 15:44 I have an idea, maybe if you place it at the start of the path instead of the end then maybe it finds your dll first. Something like this:
I'm sorry for confusing you. The code I wrote (mistakingly) in my first reply was not for loading pythonXX.dll but for loading ptsx2pysb66.dll etc. from ptsx2py.tsx etc.
The plugin uses Py_SetPythonHome() and Py_Initialize() to load python2X.dll/python3X.dll in accordance with the manner prescribed by Python.org.

I've just tested (after I read your advice) the latest released version, 0.0.3, and it seems that we don't need to worry about the interference. The test sequence is:
(1) Some Python2.X(32bit) and Python3.X(32bit) have already been installed in my 64bit PC.
--> OK (the tsx loads the right Python dll)
(2) I copied Python36.dll(32bit) to both Windows\SysWOW64 and Windows\System32.
--> OK (the tsx loads the right Python dll)
(3) I deleted the copies.
(4) I uninstalled Python 2.7 (32bit)
--> OK (the tsx loads the right Python dll)
(5) I Installed Python2.7.15(64bit) in order to experience a similar situation.
--> OK (the tsx loads the right Python dll)
(6) I copied Python27.dll(64bit) to both Windows\SysWOW64 and Windows\System32.
--> OK (the tsx loads the right Python dll)

So, when you (or someone else) find any interference, please report to me (here or at the user forum of the plugin).

Thank you.

For your information, my (more inelegant) code for loading a Python dlls is:

Code: Select all

#ifdef PY3_BY_PROPERTYSHEET
 char wks1[ 1000 ];
 strcpy_s( wks1, sizeof( wks1 ), ThisDLLDir );
 size_t sz1;
 static wchar_t *wcp1 = Py_DecodeLocale( wks1, &sz1 );
 if ( wcp1 == NULL ) {
   return false;
 }
 Py_SetPythonHome( wcp1 );
 wchar_t *wcp2 = Py_GetPath();
 size_t pos1;
 char *p2 = Py_EncodeLocale( wcp2, &pos1 );
 //Py_SetPath( wcp1 );

 PyImport_AppendInittab( "ptsxgp", PyInit_ptsxgp );
 PyImport_AppendInittab( "ptsxpy", PyInit_ptsxpy );

 Py_SetProgramName( L"scrxx" );
#else
 ::Py_SetProgramName( "scrxx" );
 Py_SetPythonHome( ThisDLLDir );
#endif

 Py_Initialize();

#ifndef PY3_BY_PROPERTYSHEET
 // Add new module names to python and init method table for each.
 addnewmodule( "myredirect", Myredirect_methods );
 addnewmodule( "ptsxgp",     Gpmethods );
 addnewmodule( "ptsxpy",     Methods );
#endif
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
clintonman
Captain
Posts: 5659
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by clintonman »

Good news then. :bananathumb:
Clinton Reese

http://clintons3d.com
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Added two movies.


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=16


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=20

(edited Oct 24 2019: Added link to each text and script.)
Last edited by borgcone on 24 Oct 2019, 08:42, edited 1 time in total.
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
Emmanuel
Chief Warrant Officer
Posts: 670
Joined: 14 Jun 2009, 06:47

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by Emmanuel »

Very impressive !
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Emmanuel wrote: 08 Mar 2019, 19:28 Very impressive !
Thank you.

Added a sample script for collision detecting functions.

Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=30

(edited Oct 24 2019: Added link to each text and script.)
Last edited by borgcone on 24 Oct 2019, 08:45, edited 1 time in total.
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Added two samples.


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... p?f=6&t=33

Before executing the script for above, you need to select the "Simple volumetric" by hand as a foreground shader.


Text and script: https://biglode.com/ptsxpy-uforum/viewt ... f=6&t=2360

The roulette can be made from the empty. No texture maps needed. Of course, you can select from single-zero "0", double-zero "00", and triple-zero "000" wheel.

Related topic:
Foreground Shader selection from tsxAPI?
v ... =12&t=5630

(edited Oct 24 2019: Added link to each text and script.)
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Added two movies and link to the scripts for them.


Text and scripts: https://biglode.com/ptsxpy-uforum/viewt ... f=6&t=2360

Already autumn in the northern hemisphere? That is certainly true :-)


Text and scripts: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=108526
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Added two movies for the first time in about 1.5 years. Animation of inverse kinematics (IK) is very tricky and hard to get a stable solution for each trueSpace version (tS4 - tS6). Material and shading is also difficult to understand the mechanism because tSxAPIxx.doc does not explain everything. I found a solution that uses "internal name" of shaders just within recent weeks.


Walking Robot (2021)
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309364


Simple material shading (2021)
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309374
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Added two short movies. The detailed features of WIDGET, NURBS control points, Scene Editor (Keyframe Editor, KFE) are also undocumented in tsxAPIxx.doc, and cut-and-try was needed to understand how to manipulate them using tsxAPI functions.


Widget sample emulation (2021)
This python script emulates a good old SDK sample C++ code "WdgSample.cpp" including callback functions.
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309546


Water ripple (2021)
This python script creates a NURBS cylinder like a spider web (i.e. with very small top and very short height) , deforms it as circular wave, makes an animation of that, clones it to several location, and shifts time frame of them.
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309555
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Let me introduce 3 new sample scripts for the ptsxpy.


Diamond (2021)
This script creates a shape of diamond cut by deforming a cone with 16 longitudes (i.e. a 16-sided pyramid). Important functions for deforming are TransformVect3f() and PolyhMakeEdge() but most part of code are for searching faces, edges and vertices.
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309687


Alpha helix and Beta sheet (2021)
Each of three scripts generates a motif appeared in secondary structure of proteins; (1) a flexible (bendable and elastic) alpha-helix using lathe functions and skeleton (2) a beta-sheet of a cylindrical NURBS with squared corners (3) a beta-sheet by blending technique of patches.
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=309709


Simple metaball (2021)
Animation of paints squeezed from tube.
Sample script and brief information: https://biglode.com/ptsxpy-uforum/viewt ... 6&t=310178
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
Emmanuel
Chief Warrant Officer
Posts: 670
Joined: 14 Jun 2009, 06:47

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by Emmanuel »

Your scripts are awesome. The simple metaball animation reminds me a plugin project that never could be achieved :
A Macro/Sweep animation tool.

Basically the idea is to use Modeler's Macro/Sweep PE tool and the paths library to make an animation of a "growing" face : instead of making the sweep at once, trueSpace would build, along the path, a new segment of the selected face at every frame. The object will look like having a growing arm. With metaballs or SubDivision, this may allow to simulate growing organics, somehow the way snail's tentacles/eyes behave !

Do you think ptsxpy could handle such an animation ?
Macro-Sweep animation.jpg
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Thank you for your interest.
Emmanuel wrote: 22 Nov 2021, 15:52 ... a new segment of the selected face at every frame. The object will look like having a growing arm. ... Do you think ptsxpy could handle such an animation ?
Unfortunately, Caligari tSx API seems not to be able to do such sweep animation as far as I tried. We can specify e_tsxKFT_SWEEP to SobjSetFrame() since tSx API for tS5.0 (or 4.3) but the created animation works only in the points selected mode of tS6.6 as the API document says;
e_tsxKFT_SWEEP, // floor move, rotate, and scale (valid only for selected floor of active sweep)

(Besides, unlike move/rotate, key frames are NOT complemented by minor frames automatically for e_tsxKFT_SWEEP and we must calculate the complement to get a smooth animation even if tS can do sweep animation.)

In order to do the sweep animation with tSx API, perhaps it's necessary to make the final form (completely swept to many sections) first, fold all sections like an old folding camera by moving all vertices to the "root", mark the time as 0, and move all sections other than the floor in a unit time, move all sections other than 1st and 2nd floors in next unit time, move other than three...

By the way, my "Glass Slide (2001)" (the 3rd YouTube image in this topic's 1st page) uses the tSx API's incompleteness of sweep animation. The script makes something like a course of a "roller coaster" by repeating single segment sweep, time frame advancing, and camera rotation/translation to the top face's normal. As a result, the camera runs on the "STATIC" course (i.e. the course has no sweep animation) in the shape of a text "trueSpace".
Drawing "t" from the viewpoint z=infinite.
Drawing "t" from the viewpoint z=infinite.
slide_5b.jpg (23.99 KiB) Viewed 4052 times
Emmanuel wrote: 22 Nov 2021, 15:52 With metaballs or SubDivision, this may allow to simulate growing organics, somehow the way snail's tentacles/eyes behave !
To submit such "growing" animations to the Caligari "3D Animation Contest" was one of my motive to develop the ptsxpy in about 2000. I soon noticed tS5 (trial version) takes all night to do repetitive hundreds single sweep though. It was not a matter whether it can do sweep animation or not. :)
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
User avatar
borgcone
Chief Petty Officer
Posts: 134
Joined: 06 May 2018, 21:09
Type the number ten into the box: 10
Location: Japan, or sometimes behind a borg cube

Re: Primitive tsxPython (ptsxpy), another Python interpreter plugin for tS series

Post by borgcone »

Emmanuel wrote: 22 Nov 2021, 15:52 ... simulate growing organics, somehow the way snail's tentacles/eyes behave !
Probably the easiest way to make an animation of growing organics or snail's tentacles/eyes using the ptsxpy might be to move/rotate latitudes of a NURBS cylinder. In case of swept polyhedrons, it would be too complicated work for scripts to select vertices in a latitude, but NURBS's latitudes can be selected easier (though multiple objects are needed for "branch") by scripts. In the image below, the bending was not done by script but by hand. The ptsxpy and scripts can do the same action.
NURBS1a.jpg
NURBS1a.jpg (41.25 KiB) Viewed 4029 times
One of sample script to animate moving/sizing NURBS cylinder's latitude on ptsxpy is "Water ripple (2021)" posted above on 13 Apr 2021.
In addition, metaball animations are a bit tricky and difficult to control because gathering many elements causes honest but unexpected/unreasonable expands.

----Added lines below later in the same day.
I made a experimental script for the growing NURBS above. The NURBS has initially 50 latitudes and short height. The growing point in this example is its foot (like a hair or savanna antelopes' horn?). For simulating apical growth like a botanical vine, you should just reverse the top and bottom.


----Added below on Nov 30 2021.
Experimentally, made also a script that generates an animation of a retractable snail's eye. It's does not sweep but creates and deforms a NURBS cylinder.
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy

Return to “Repositorium”