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

free scripts, plugins, models, textures
User avatar
borgcone
Chief Petty Officer
Posts: 113
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?f=6&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?f=6&t=5


Text and script: https://biglode.com/ptsxpy-uforum/viewtopic.php?f=6&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?f=6&t=6

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

Are the tsxAPI*.doc redistributable? License terms?
viewtopic.php?f=4&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: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

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: 113
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: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

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: 113
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: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

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: 113
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: 650
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: 113
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: 113
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?
https://www.united3dartists.com/forum/v ... =12&t=5630

(edited Oct 24 2019: Added link to each text and script.)
borgcone ... or 3DfromNULL at https://biglode.com/ptsxpy
Post Reply