summaryrefslogtreecommitdiffstats
path: root/src/modelinfo/ClumpModelInfo.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2020-04-23 22:25:18 +0200
committeraap <aap@papnet.eu>2020-04-24 11:42:38 +0200
commitf03b4eec4c37eab75a5bd639279cfcc615105b01 (patch)
treec4be4fa57b16c61d45e8156a51dd07b11e049bba /src/modelinfo/ClumpModelInfo.cpp
parentMerge branch 'master' of github.com:gtamodding/re3 (diff)
downloadre3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar.gz
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar.bz2
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar.lz
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar.xz
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.tar.zst
re3-f03b4eec4c37eab75a5bd639279cfcc615105b01.zip
Diffstat (limited to 'src/modelinfo/ClumpModelInfo.cpp')
-rw-r--r--src/modelinfo/ClumpModelInfo.cpp72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/modelinfo/ClumpModelInfo.cpp b/src/modelinfo/ClumpModelInfo.cpp
index 464bda61..44faf3c5 100644
--- a/src/modelinfo/ClumpModelInfo.cpp
+++ b/src/modelinfo/ClumpModelInfo.cpp
@@ -1,5 +1,6 @@
#include "common.h"
+#include "RwHelper.h"
#include "General.h"
#include "NodeName.h"
#include "VisibilityPlugins.h"
@@ -15,12 +16,40 @@ CClumpModelInfo::DeleteRwObject(void)
}
}
+#ifdef PED_SKIN
+static RpAtomic*
+SetHierarchyForSkinAtomic(RpAtomic *atomic, void *data)
+{
+ RpSkinAtomicSetHAnimHierarchy(atomic, (RpHAnimHierarchy*)data);
+ return nil;
+}
+#endif
+
RwObject*
CClumpModelInfo::CreateInstance(void)
{
- if(m_clump)
- return (RwObject*)RpClumpClone(m_clump);
- return nil;
+ if(m_clump == nil)
+ return nil;
+ RpClump *clone = RpClumpClone(m_clump);
+#ifdef PED_SKIN
+ if(IsClumpSkinned(clone)){
+ RpHAnimHierarchy *hier;
+ RpHAnimAnimation *anim;
+
+ hier = GetAnimHierarchyFromClump(clone);
+ assert(hier);
+ // This seems dangerous as only the first atomic will get a hierarchy
+ // can we guarantee this if hands and head are also in the clump?
+ RpClumpForAllAtomics(clone, SetHierarchyForSkinAtomic, hier);
+ anim = HAnimAnimationCreateForHierarchy(hier);
+ RpHAnimHierarchySetCurrentAnim(hier, anim);
+// RpHAnimHierarchySetFlags(hier, (RpHAnimHierarchyFlag)(rpHANIMHIERARCHYUPDATEMODELLINGMATRICES|rpHANIMHIERARCHYUPDATELTMS));
+ // the rest is xbox only:
+ // RpSkinGetNumBones(RpSkinGeometryGetSkin(RpAtomicGetGeometry(IsClumpSkinned(clone))));
+ RpHAnimHierarchyUpdateMatrices(hier);
+ }
+#endif
+ return (RwObject*)clone;
}
RwObject*
@@ -48,8 +77,45 @@ CClumpModelInfo::SetClump(RpClump *clump)
CVisibilityPlugins::SetClumpModelInfo(m_clump, this);
AddTexDictionaryRef();
RpClumpForAllAtomics(clump, SetAtomicRendererCB, nil);
+
+ // TODO: also set for player?
if(strncmp(GetName(), "playerh", 8) == 0)
RpClumpForAllAtomics(clump, SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB);
+
+#ifdef PED_SKIN
+ if(IsClumpSkinned(clump)){
+ int i;
+ RpHAnimHierarchy *hier;
+ RpAtomic *skinAtomic;
+ RpSkin *skin;
+
+ // mobile:
+// hier = nil;
+// RwFrameForAllChildren(RpClumpGetFrame(clump), GetHierarchyFromChildNodesCB, &hier);
+// assert(hier);
+// RpClumpForAllAtomics(clump, SetHierarchyForSkinAtomic, hier);
+// skinAtomic = GetFirstAtomic(clump);
+
+ // xbox:
+ hier = GetAnimHierarchyFromClump(clump);
+ assert(hier);
+ RpSkinAtomicSetHAnimHierarchy(IsClumpSkinned(clump), hier);
+ skinAtomic = IsClumpSkinned(clump);
+
+ assert(skinAtomic);
+ skin = RpSkinGeometryGetSkin(RpAtomicGetGeometry(skinAtomic));
+ // ignore const
+ for(i = 0; i < RpGeometryGetNumVertices(RpAtomicGetGeometry(skinAtomic)); i++){
+ RwMatrixWeights *weights = (RwMatrixWeights*)&RpSkinGetVertexBoneWeights(skin)[i];
+ float sum = weights->w0 + weights->w1 + weights->w2 + weights->w3;
+ weights->w0 /= sum;
+ weights->w1 /= sum;
+ weights->w2 /= sum;
+ weights->w3 /= sum;
+ }
+// RpHAnimHierarchySetFlags(hier, (RpHAnimHierarchyFlag)(rpHANIMHIERARCHYUPDATEMODELLINGMATRICES|rpHANIMHIERARCHYUPDATELTMS));
+ }
+#endif
}
void