blender_io_export_psx_mesh/README.md

172 lines
5.9 KiB
Markdown
Raw Normal View History

2020-12-29 15:19:56 +01:00
![Pic or it didn't happen](blender-psx.jpg)
2020-12-27 17:44:19 +01:00
2021-04-03 17:06:09 +02:00
# Blender PSX Level export
2020-12-26 19:11:11 +01:00
2021-06-22 17:29:56 +02:00
Blender <= 2.79b plugin to export gouraud shaded, UV textured PSX meshes in a scene to a C file.
2020-12-27 14:15:58 +01:00
2021-04-03 17:06:09 +02:00
![3d scene](gif/3d.gif)
2021-04-03 17:10:27 +02:00
![pre-rendered BGs](gif/precalc.gif)
![Push things](gif/push.gif)
![Sprite](gif/sprite.gif)
![Vertex animation](gif/vertexanim.gif)
2021-04-03 17:06:09 +02:00
## Features
**Be warned this is WIP** !
### Plugin
* Export UV textured models
* Export vertex painted models
* Export camera positions for in game use
* Export vertex animations
* Export up to 3 light sources
* Export pre-rendered backgrounds for in-game use (8bpp and 4bpp)
2021-04-03 17:10:27 +02:00
2021-04-03 17:11:07 +02:00
![comparison](gif/rt-8b-4b.gif)
2021-04-03 17:10:27 +02:00
Real-time 3D / 8bpp background / 4bpp background
2021-04-03 17:06:09 +02:00
### "Engine"
* Very basic physics / collision detection
* Constrained camera trajectory
* Orbital camera mode
* Basic Spatial partitioning
* Portal based camera angle switch
2021-04-03 17:11:07 +02:00
* 3D sprite
2021-06-22 17:29:56 +02:00
* VRam auto layout for TIMs
2021-04-03 17:06:09 +02:00
## Planned
* Fix and improve all the things !
* Wall collisions
2021-01-04 19:23:57 +01:00
Specifically, it generates a C file containing for each mesh in the scene:
2020-12-27 14:15:58 +01:00
* an array of SVECTOR containing the vertices coordinates
* an array of SVECTOR containing the normals
2020-12-29 15:32:14 +01:00
* an array of SVECTOR containing the UV coordinates of the texture
2020-12-27 17:36:47 +01:00
* an array of CVECTOR containing the color of each vertex
2020-12-27 14:15:58 +01:00
* an array of int that describe the relation between the tri meshes
* a TMESH struct to ease access to those arrays
2020-12-29 15:31:05 +01:00
* declarations of the binary in memory
* a TIM_IMAGE struct ready to host the image data
2020-12-27 14:15:58 +01:00
2021-01-04 19:23:57 +01:00
A few usefull stuff for manipulating the mesh :
* a MATRIX that will hold the mesh tranformations
* a VECTOR holding the object's location in world coordinates
* a SVECTOR holding the object's rotation in PSX angle units (1 == 4096)
* a flag isPrism for a pseudo-refraction effect. If 1, texture is the framebuffer draw area ( __WIP__ )
* a long holding p, the depth-cueing interpolation value used by the PSX
For easy access to those, a MESH struct is defined as :
```c
2021-04-03 17:06:09 +02:00
typedef struct MESH {
2021-06-22 17:29:56 +02:00
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX * mat;
VECTOR * pos;
SVECTOR * rot;
short * isRigidBody;
short * isStaticBody;
short * isPrism;
short * isAnim;
short * isActor;
short * isLevel;
short * isBG;
short * isSprite;
long * p;
long * OTz;
BODY * body;
VANIM * anim;
struct NODE * node;
VECTOR pos2D;
} MESH;
2021-01-04 19:23:57 +01:00
```
## TMESH struct :
2020-12-27 14:15:58 +01:00
From `libgte.h` :
```c
typedef struct {
SVECTOR *v; /*shared vertices*/
SVECTOR *n; /*shared normals*/
SVECTOR *u; /*shared texture addresses*/
CVECTOR *c; /*shared colors*/
u_long len; /*mesh length(=#vertex)*/
} TMESH;
```
2020-12-26 19:11:11 +01:00
2020-12-27 17:36:47 +01:00
# Install the plugin
2020-12-26 19:11:11 +01:00
2021-06-22 17:29:56 +02:00
**This plugin is not compatible with Blender > 2.79.**
2020-12-26 19:11:11 +01:00
2021-06-22 17:29:56 +02:00
1. Download and install Blender 2.79b.
http://download.blender.org/release/Blender2.79/
2021-04-03 17:17:22 +02:00
2021-06-22 17:29:56 +02:00
2. Clone this repository in the [addons folder](https://docs.blender.org/manual/en/latest/advanced/blender_directory_layout.html) of blender 2.79 :
```bash
git clone https://github.com/ABelliqueux/blender_io_export_psx_mesh.git
```
You'll need to have [pngquant](https://pngquant.org/) and [img2tim](https://github.com/Lameguy64/img2tim) utilities installed and in your path for PNG to TIM conversion.
2021-04-03 17:17:22 +02:00
2021-06-22 17:29:56 +02:00
Windows executables are provided for convenience in this repo.
2021-04-04 23:32:34 +02:00
2021-06-22 17:29:56 +02:00
For users with Imagemagick installed, there is an option when exporting to use that instead of pngquant.
2020-12-26 19:11:11 +01:00
2021-06-22 17:29:56 +02:00
On Linux : `~/.config/blender/2.79/scripts/addons`
On macOS : `./Blender.app/Contents/Resources/2.79/addons`
On Windows : `%USERPROFILE%\AppData\Roaming\Blender Foundation\Blender\2.93\`
2020-12-26 19:43:07 +01:00
2020-12-29 15:31:05 +01:00
# Steps to convert your mesh
2020-12-26 19:43:07 +01:00
2020-12-27 12:30:11 +01:00
1. You must first triangulate your mesh (manually or via the modifier).
2020-12-27 13:23:06 +01:00
2020-12-27 12:30:11 +01:00
2. When your model is ready, you can then vertex paint it. If you don't, the vertices colors will default to white.
2020-12-27 12:34:00 +01:00
2020-12-27 12:30:11 +01:00
* If you modify your geometry *after* vertex painting, the plugin will faile to export the mesh. This is because the vertex color data is set to 0 each time you modify your geometry.
2020-12-26 19:43:07 +01:00
2020-12-29 15:31:05 +01:00
3. You can UV unwrap your model and apply a texture. The provided code will look for a tim file corresponding to the name of the image file you use in blender in the 'TIM' folder.
E.g : You use a 'cube.png' file in blender, the psx code will look for a 'cube.tim' file in ./TIM
* If needed, edit the `primdraw.c` file , lines 29 and 30, to reflect the number of tris you want to be able to draw ( Max seems to be ~750 in NTSC, ~910 in PAL )
2020-12-27 13:23:06 +01:00
```c
2021-06-22 17:29:56 +02:00
#define OT_LENGTH 2048 // Maximum number of OT entries
#define MAX_PRIMS 1024 // Maximum number of POLY_GT3 primitives
2020-12-27 13:23:06 +01:00
```
seem to be safe values.
2020-12-26 19:43:07 +01:00
2020-12-27 17:36:47 +01:00
# Compiling
2020-12-26 19:43:07 +01:00
2020-12-27 17:36:47 +01:00
The provided `Makefile` uses the [Nugget+PsyQ setup](https://github.com/ABelliqueux/nolibgs_hello_worlds#setting-up-the-sdk--modern-gcc--psyq-aka-nuggetpsyq).
2020-12-26 19:43:07 +01:00
2020-12-29 15:31:05 +01:00
1. Clone this repo in `(...)/pcsx-redux/src/mips/`
2. Enter the `blender_io_export_psx_mesh` folder
2021-04-03 17:18:57 +02:00
3. Install the plugin in blender, then open `level.blend`
4. Export as 'level.c'
2020-12-29 15:31:05 +01:00
5. Type `Make`
You can use [img2tim](https://github.com/Lameguy64/img2tim) to convert your blender texture in a tim file.
2020-12-26 19:43:07 +01:00
# Credits
2020-12-27 17:36:47 +01:00
Based on the [code](https://pastebin.com/suU9DigB) provided by TheDukeOfZill, 04-2014, on http://www.psxdev.net/forum/viewtopic.php?f=64&t=537#p4088
2020-12-26 19:43:07 +01:00
2020-12-27 17:36:47 +01:00
PSX code based on [example](http://psx.arthus.net/code/primdraw.7z) by [Lameguy64](https://github.com/Lameguy64)
2021-04-03 17:06:09 +02:00
pngquant : [https://github.com/kornelski/pngquant](https://github.com/kornelski/pngquant)
img2tim : [https://github.com/Lameguy64/img2tim](https://github.com/Lameguy64/img2tim)
2021-04-03 17:17:22 +02:00
Freeimage : [https://freeimage.sourceforge.io/](https://freeimage.sourceforge.io/)