mirror of
https://github.com/aap/librw.git
synced 2025-12-18 16:39:51 +00:00
implemented xbox extra normals plugin
This commit is contained in:
@@ -189,6 +189,78 @@ registerBreakableModelPlugin(void)
|
||||
getSizeBreakableModel);
|
||||
}
|
||||
|
||||
// Extra normals
|
||||
|
||||
int32 extraNormalsOffset;
|
||||
|
||||
static void*
|
||||
createExtraNormals(void *object, int32 offset, int32)
|
||||
{
|
||||
*PLUGINOFFSET(float*, object, offset) = NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
static void*
|
||||
destroyExtraNormals(void *object, int32 offset, int32)
|
||||
{
|
||||
float *extranormals = *PLUGINOFFSET(float*, object, offset);
|
||||
delete[] extranormals;
|
||||
*PLUGINOFFSET(float*, object, offset) = NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
readExtraNormals(Stream *stream, int32, void *object, int32 offset, int32)
|
||||
{
|
||||
Geometry *geo = (Geometry*)object;
|
||||
float **plgp = PLUGINOFFSET(float*, object, offset);
|
||||
if(*plgp)
|
||||
delete[] *plgp;
|
||||
float *extranormals = *plgp = new float[geo->numVertices*3];
|
||||
stream->read(extranormals, geo->numVertices*3*4);
|
||||
|
||||
// for(int i = 0; i < geo->numVertices; i++){
|
||||
// float *nx = extranormals+i*3;
|
||||
// float *n = geo->morphTargets[0].normals;
|
||||
// float len = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
|
||||
// printf("%f %f %f %f\n", n[0], n[1], n[2], len);
|
||||
// printf("%f %f %f\n", nx[0], nx[1], nx[2]);
|
||||
// }
|
||||
}
|
||||
|
||||
static void
|
||||
writeExtraNormals(Stream *stream, int32, void *object, int32 offset, int32)
|
||||
{
|
||||
Geometry *geo = (Geometry*)object;
|
||||
float *extranormals = *PLUGINOFFSET(float*, object, offset);
|
||||
assert(extranormals != NULL);
|
||||
stream->write(extranormals, geo->numVertices*3*4);
|
||||
}
|
||||
|
||||
static int32
|
||||
getSizeExtraNormals(void *object, int32 offset, int32)
|
||||
{
|
||||
Geometry *geo = (Geometry*)object;
|
||||
if(*PLUGINOFFSET(float*, object, offset))
|
||||
return geo->numVertices*3*4;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
registerExtraNormalsPlugin(void)
|
||||
{
|
||||
extraNormalsOffset = Geometry::registerPlugin(sizeof(void*),
|
||||
ID_EXTRANORMALS,
|
||||
createExtraNormals,
|
||||
destroyExtraNormals,
|
||||
NULL);
|
||||
Geometry::registerPluginStream(ID_EXTRANORMALS,
|
||||
readExtraNormals,
|
||||
writeExtraNormals,
|
||||
getSizeExtraNormals);
|
||||
}
|
||||
|
||||
|
||||
// Extra colors
|
||||
|
||||
int32 extraVertColorOffset;
|
||||
@@ -228,6 +300,7 @@ readExtraVertColors(Stream *stream, int32, void *object, int32 offset, int32)
|
||||
colordata->dayColors = new uint8[geometry->numVertices*4];
|
||||
colordata->balance = 1.0f;
|
||||
stream->read(colordata->nightColors, geometry->numVertices*4);
|
||||
printf("extra colors\n");
|
||||
if(geometry->colors)
|
||||
memcpy(colordata->dayColors, geometry->colors,
|
||||
geometry->numVertices*4);
|
||||
|
||||
@@ -3,6 +3,7 @@ using namespace rw;
|
||||
|
||||
enum
|
||||
{
|
||||
ID_EXTRANORMALS = 0x253f2f2,
|
||||
ID_SPECMAT = 0x253f2f6,
|
||||
ID_EXTRAVERTCOLORS = 0x253f2f9,
|
||||
ID_ENVMAT = 0x253f2fc,
|
||||
@@ -37,7 +38,12 @@ struct Breakable
|
||||
extern int32 breakableOffset;
|
||||
void registerBreakableModelPlugin(void);
|
||||
|
||||
// Extra vert colors
|
||||
// Extra normals (only on Xbox)
|
||||
|
||||
extern int32 extraNormalsOffset;
|
||||
void registerExtraNormalsPlugin(void);
|
||||
|
||||
// Extra vert colors (not on Xbox)
|
||||
|
||||
struct ExtraVertColors
|
||||
{
|
||||
|
||||
@@ -151,7 +151,7 @@ extern char *debugFile;
|
||||
inline uint32
|
||||
libraryIDPack(int version, int build)
|
||||
{
|
||||
if(version < 0x32000)
|
||||
if(version <= 0x31000)
|
||||
return version>>8;
|
||||
return (version-0x30000 & 0x3FF00) << 14 | (version&0x3F) << 16 |
|
||||
(build & 0xFFFF);
|
||||
|
||||
@@ -239,7 +239,7 @@ static void
|
||||
readVertexFmt(Stream *stream, int32, void *object, int32 offset, int32)
|
||||
{
|
||||
uint32 fmt = stream->readU32();
|
||||
printf("vertexfmt: %X\n", fmt);
|
||||
// printf("vertexfmt: %X\n", fmt);
|
||||
*PLUGINOFFSET(uint32, object, offset) = fmt;
|
||||
// TODO: create and attach "vertex shader"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user