RSD Export/Obj batch script version 2 (May 2023)

v3.0 fixed exports with no material, added !quit batch command, which quits execution, now export whole image assigned to tri/quad (not UV mapped), reuse existing images from "select image" for RSDExports
v2.2 added Obj export
v2.1 random fixes
v2.0 Run Batch tool plugin
v1.0 RSD Export plugin
About:

This is a plugin for MarbleClay to export PS1's RSD 3D files and viewed in NO$PSX.
MarbleClay is a small and simple, yet modern and powerful 3D modeller with simple skinning and posing for rendering images.


Limitations:

Unfortunately, MarbleClay has no support for per vertex colours, so Gouraud shading is not possible, a combination of flat colour, textured, textured with a flat colour, lit and unlit, and both triangle and quad faces are supported.
The exporter only exports a single root object as a single RSD model, no groups are created. 
If you need a multiple part model (ie body, arms, legs, head), make each individual part as a root object not a object group.

If you need your model in a specific offset from the center, as above, it should be in the correct place required (not centered), before exporting.
The exported RSD should be the same model, except that it is a mirror image or the MarbleClay model, along the MarbleClay X plane.

Pre installed requirements:

The following must be install and in system path:

convert and identify - resizes image and converts the bit width.
ImageMagick from http://www.imagemagick.org version used:  
Version: 6.8.7-10 Q16 i686 2016-12-24 

img2tim - converts image to TIM format and sets the VRAM space.
img2tim from https://github.com/Lameguy64/img2tim version used v0.75

NO$PSX from http://problemkaputt.de/psx.htm version used 2.1

Net Yaroze SDK (DOS/win32 apps)

Everything (except MarbleClay) is set up in this VM: https://archive.org/details/net-yaroze-dev-winxp-vm-2022 (also used to build this plugin!)
Windows 64bit requires for SDK to work (untested): http://www.columbia.edu/~em36/ntvdmx64.html
Linux users: Recommended to use the windows VM or create your own.

Not required in system path:

MarbleClay from http://www.flat2d.com/MarbleClay.html version used beta5.8a
This plugin only works if the rsdn.bat file is in either:
C:\MarbleSDK (preferred)
or
C:\Program Files\MarbleClay

Installation:

Put RSDExporter.mcp and RSDN.BAT in the MarbleClay Plugin folder, ie:
C:\MarbleSDK\Plugin
or
C:\Program Files\MarbleClay\Plugin

The .lua files go in the Script folder.
qtest.lua, a quick script to test quads (faces with 4 vertices) are on a single plane (Coplanar), if it finds a quad that's bad, it will remove it and exit, you will have to find it and replace it with 2 triangles.
MarbleClay can convert the whole model to triangles, but you tried modelling in quad faces (ie only moving lines and faces, not vertices), this script will help.
rsd.lua, was the first implementation, it's bad, it only supports textured models, due to the MarbleClay lua plugin isn't fully completed.
The folder RSDExporter contains the source code and only useful for rebuilding, see RSD_Exporter.pas for more information.

Usage:

MarbleClay creates three shader setting sliders by defaults for materials, RGB values, specular and shininess, these are used in the converter.
Specular: enables light calculations for the object's faces.  
Shininess: enables RGB colour on textured faces.
RGB: Colour values, defaults to white.

If no texture is used, the exporter will default to the material's RGB (Diffuse) colour.
If with textured or RGB, when Specular is over 0 it will enable lighting calculations.
If material contains a texture, the RGB is only applied when Shininess is over 0.
Optimize your final export by removing unused verts: Menu -> select -> single edges, if not, your TMD will be alot bigger then it needs to be.


Note: Textured and RGB coloured faces, can not be lit by using face normals (see the TMD fileformat spec) and conversion (via rsdlink) defaults to using lighting, ignoring the RGB colour.

Using Textures:
Texture names must be unique!

The Net Yaroze program (RSDView) used to view the model is configured in NTSC 640*240 mode.
MarbleClay uses a unified square for texture UV mapping, but your images can still be a rectangle, ie a VRAM TPage.
I suggest changing the default size (option->configuration.. -> texture/template) of your texture width and height, optionally with twice the resolution and keeping the ratio correct.
Note: Hit Enter after changing the object or material name for MarbleClay to update it.

Texture (image) Material must have:

~256x256x8

In the material name, where:
256x256 are width and height
x8 is the bit width, can only be 4,8,16 (no 24bit support)

Note, image size and bit size numbers start from 1, not zero.
This will auto place each image after each other in VRAM.

You can specify the VRAM XY for both image and CLUT by appending:
~256x256x8~640x0x0x480
This will put the image data at 640x0 and CLUT data at 0x480.
Note, the VRAM numbers start from zero.

If a G is put after ~
~G256x256x8~640x0x0x480
It will convert the image to grey scale, there is no extra image compression, but sometimes grey looks better then very limited 16 colour palette.

The max textures size allowed are:
pixels width: 128px(@16bit) 256px(@8bit) 512px(@4bit) (which are all equal to 128 pixels of 16bit width or 2Tpages in VRAM)
pixel height: 256px

Optimal your textured faces to fit into 2kb cache, for example:
16bit = 32px * 32px Maximum
8bit = 64px * 32px  Maximum
4bit = 64px * 64px Maximum


Anything bigger and it'll start slowing down the rendering.
If you use a lot of textures, optimize your colour palette, lower the bit width to lower your pixel data.
This does not really apply to 2D because it's rendering very small amounts of faces, compared to a 3D scene.

The created TIM images aren't meant to be final, although they can be. You are meant to arrange the TIM's in VRAM, configured to  your game, the generated .PSX file will load the TIM and CLUT in TIMTOOL.



Exporting:

Export filename must be less then 7 characters.
The conversion programs only support DOS formatted filenames (8.3), so unfortunately the exporter also requires the same. One character is used for the number of TIM.
Note, the default name comes from the Object panel's model name (default is NewObject), and the exporter only exports the selected object.



Viewing:

Once the RSD files have been created successfully, the rsdn.bat from the plugin folder is run, this batch file packages your model with the net yaroze rdsview program, converted and NO$PSX is run.
If you are familiar with DOS batch files you can make it do whatever you like, ie adding a mode to a scene with rsdform and rsdcat tools  or delete the content and it will not do anything after creating the rsd files.


I assume there are lights pointing down from above and also the camera point, towards the model.
This can make seeing shade hard, it's better to look at the sides and the bottom of the model to see the light shading. 


You need to know how your NO$PSX inputs are configured.


* Rotation is around the model's local coordinate system.
Triangle/Cross - X Rotation* 
Square/Circle - Y Rotation*


Up/Down -  Move Up/Down
Left/Right - Move Left/Right
L1/L2 - Zoom In/Out
R1/R2 - Z Rotation*



For MarbleClay help see:

https://united3dartists.com/forum/viewtopic.php?f=4&t=6424