From 542e56d7a218cfc24c844afdbc5b8997ad33077e Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Mon, 19 Jan 2015 13:32:12 +0100 Subject: [PATCH] Implemented R* env and spec plugins. --- TODO | 3 +- dffwrite.cpp | 3 +- src/gtaplg.cpp | 172 ++++++++++++++++++++++++++++++++++++++++++++++++- src/gtaplg.h | 32 +++++++++ 4 files changed, 206 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index bcaed7d..d0ccf65 100644 --- a/TODO +++ b/TODO @@ -24,12 +24,11 @@ Clump & related: -Skin R* 2dfx Material - R* Reflection mat - R* Specular Mat UV Anim Texture (Sky Mipmap Val) +- PDS Pipelines (at least dummies) - UV Anim Dict diff --git a/dffwrite.cpp b/dffwrite.cpp index 5bd1b79..2cae3fa 100644 --- a/dffwrite.cpp +++ b/dffwrite.cpp @@ -18,8 +18,9 @@ main(int argc, char *argv[]) // Rw::Version = 0x33002; - Rw::RegisterMaterialRightsPlugin(); + Rw::RegisterEnvSpecPlugin(); Rw::RegisterMatFXPlugin(); + Rw::RegisterMaterialRightsPlugin(); Rw::RegisterAtomicRightsPlugin(); Rw::RegisterHAnimPlugin(); Rw::RegisterNodeNamePlugin(); diff --git a/src/gtaplg.cpp b/src/gtaplg.cpp index 6a6ec57..bbcf86a 100644 --- a/src/gtaplg.cpp +++ b/src/gtaplg.cpp @@ -263,11 +263,181 @@ RegisterExtraVertColorPlugin(void) ExtraVertColorOffset = Geometry::registerPlugin(sizeof(ExtraVertColors), ID_EXTRAVERTCOLORS, createExtraVertColors, - destroyExtraVertColors, NULL); + destroyExtraVertColors, + NULL); Geometry::registerPluginStream(ID_EXTRAVERTCOLORS, readExtraVertColors, writeExtraVertColors, getSizeExtraVertColors); } +// Environment mat + +int32 EnvMatOffset; + +static void* +createEnvMat(void *object, int32 offset, int32) +{ + *PLUGINOFFSET(EnvMat*, object, offset) = NULL; + return object; +} + +static void* +destroyEnvMat(void *object, int32 offset, int32) +{ + EnvMat **envmat = PLUGINOFFSET(EnvMat*, object, offset); + delete *envmat; + *envmat = NULL; + return object; +} + +static void* +copyEnvMat(void *dst, void *src, int32 offset, int32) +{ + EnvMat *srcenv = *PLUGINOFFSET(EnvMat*, src, offset); + if(srcenv == NULL) + return dst; + EnvMat *dstenv = new EnvMat; + dstenv->scaleX = srcenv->scaleX; + dstenv->scaleY = srcenv->scaleY; + dstenv->transScaleX = srcenv->transScaleX; + dstenv->transScaleY = srcenv->transScaleY; + dstenv->shininess = srcenv->shininess; + dstenv->texture = NULL; + *PLUGINOFFSET(EnvMat*, dst, offset) = dstenv; + return dst; +} + +struct EnvStream { + float scaleX, scaleY; + float transScaleX, transScaleY; + float shininess; + int32 zero; +}; + +static void +readEnvMat(Stream *stream, int32, void *object, int32 offset, int32) +{ + EnvStream buf; + EnvMat *env = new EnvMat; + *PLUGINOFFSET(EnvMat*, object, offset) = env; + stream->read(&buf, sizeof(buf)); + env->scaleX = (int8)(buf.scaleX*8.0f); + env->scaleY = (int8)(buf.scaleY*8.0f); + env->transScaleX = (int8)(buf.transScaleX*8.0f); + env->transScaleY = (int8)(buf.transScaleY*8.0f); + env->shininess = (int8)(buf.shininess*255.0f); + env->texture = NULL; +} + +static void +writeEnvMat(Stream *stream, int32, void *object, int32 offset, int32) +{ + EnvStream buf; + EnvMat *env = *PLUGINOFFSET(EnvMat*, object, offset); + buf.scaleX = env->scaleX/8.0f; + buf.scaleY = env->scaleY/8.0f; + buf.transScaleX = env->transScaleX/8.0f; + buf.transScaleY = env->transScaleY/8.0f; + buf.shininess = env->shininess/8.0f; + buf.zero = 0; + stream->write(&buf, sizeof(buf)); +} + +static int32 +getSizeEnvMat(void *object, int32 offset, int32) +{ + EnvMat *env = *PLUGINOFFSET(EnvMat*, object, offset); + return env ? sizeof(EnvStream) : -1; +} + +// Specular mat + +int32 SpecMatOffset; + +static void* +createSpecMat(void *object, int32 offset, int32) +{ + *PLUGINOFFSET(SpecMat*, object, offset) = NULL; + return object; +} + +static void* +destroySpecMat(void *object, int32 offset, int32) +{ + SpecMat **specmat = PLUGINOFFSET(SpecMat*, object, offset); + if((*specmat)->texture) + (*specmat)->texture->decRef(); + delete *specmat; + *specmat = NULL; + return object; +} + +static void* +copySpecMat(void *dst, void *src, int32 offset, int32) +{ + SpecMat *srcspec = *PLUGINOFFSET(SpecMat*, src, offset); + if(srcspec == NULL) + return dst; + SpecMat *dstspec = new SpecMat; + *PLUGINOFFSET(SpecMat*, dst, offset) = dstspec; + dstspec->specularity = srcspec->specularity; + dstspec->texture = srcspec->texture; + dstspec->texture->refCount++; + return dst; +} + +struct SpecStream { + float specularity; + char texname[24]; +}; + +static void +readSpecMat(Stream *stream, int32, void *object, int32 offset, int32) +{ + SpecStream buf; + SpecMat *spec = new SpecMat; + *PLUGINOFFSET(SpecMat*, object, offset) = spec; + stream->read(&buf, sizeof(buf)); + spec->specularity = buf.specularity; + spec->texture = new Texture; + strncpy(spec->texture->name, buf.texname, 24); +} + +static void +writeSpecMat(Stream *stream, int32, void *object, int32 offset, int32) +{ + SpecStream buf; + SpecMat *spec = *PLUGINOFFSET(SpecMat*, object, offset); + buf.specularity = spec->specularity; + strncpy(buf.texname, spec->texture->name, 24); + stream->write(&buf, sizeof(buf)); +} + +static int32 +getSizeSpecMat(void *object, int32 offset, int32) +{ + SpecMat *spec = *PLUGINOFFSET(SpecMat*, object, offset); + return spec ? sizeof(SpecStream) : -1; +} + +void +RegisterEnvSpecPlugin(void) +{ + SpecMatOffset = Material::registerPlugin(sizeof(SpecMat*), ID_SPECMAT, + createSpecMat, + destroySpecMat, + copySpecMat); + Material::registerPluginStream(ID_SPECMAT, readSpecMat, + writeSpecMat, + getSizeSpecMat); + EnvMatOffset = Material::registerPlugin(sizeof(EnvMat*), ID_ENVMAT, + createEnvMat, + destroyEnvMat, + copyEnvMat); + Material::registerPluginStream(ID_ENVMAT, readEnvMat, + writeEnvMat, + getSizeEnvMat); +} + } diff --git a/src/gtaplg.h b/src/gtaplg.h index eac55aa..b6887e3 100644 --- a/src/gtaplg.h +++ b/src/gtaplg.h @@ -2,14 +2,20 @@ namespace Rw { enum { + ID_SPECMAT = 0x253f2f6, ID_EXTRAVERTCOLORS = 0x253f2f9, + ID_ENVMAT = 0x253f2fc, ID_BREAKABLE = 0x253f2fd, ID_NODENAME = 0x253f2fe }; +// Node name + extern int32 NodeNameOffset; void RegisterNodeNamePlugin(void); +// Breakable model + struct Breakable { uint32 position; @@ -30,6 +36,8 @@ struct Breakable extern int32 BreakableOffset; void RegisterBreakableModelPlugin(void); +// Extra vert colors + struct ExtraVertColors { uint8 *nightColors; @@ -40,4 +48,28 @@ struct ExtraVertColors extern int32 ExtraVertColorOffset; void RegisterExtraVertColorPlugin(void); +// Environment mat + +struct EnvMat +{ + int8 scaleX, scaleY; + int8 transScaleX, transScaleY; + int8 shininess; + Texture *texture; +}; + +extern int32 EnvMatOffset; + +// Specular mat + +struct SpecMat +{ + float specularity; + Texture *texture; +}; + +extern int32 SpecMatOffset; + +void RegisterEnvSpecPlugin(void); + }