Changeset 25306
- Timestamp:
- Apr 23, 2021, 4:26:59 PM (3 years ago)
- Location:
- ps/trunk/source/graphics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/graphics/Model.cpp
r25210 r25306 131 131 void CModel::CalcStaticObjectBounds() 132 132 { 133 m_ObjectBounds.SetEmpty(); 134 135 size_t numverts=m_pModelDef->GetNumVertices(); 136 SModelVertex* verts=m_pModelDef->GetVertices(); 137 138 for (size_t i=0;i<numverts;i++) { 139 m_ObjectBounds+=verts[i].m_Coords; 140 } 133 PROFILE2("CalcStaticObjectBounds"); 134 m_pModelDef->GetMaxBounds(nullptr, !(m_Flags & MODELFLAG_NOLOOPANIMATION), m_ObjectBounds); 141 135 } 142 136 … … 145 139 void CModel::CalcAnimatedObjectBounds(CSkeletonAnimDef* anim, CBoundingBoxAligned& result) 146 140 { 147 result.SetEmpty(); 148 149 // Set the current animation on which to perform calculations (if it's necessary) 150 if (anim != m_Anim->m_AnimDef) 151 { 152 CSkeletonAnim dummyanim; 153 dummyanim.m_AnimDef=anim; 154 if (!SetAnimation(&dummyanim)) return; 155 } 156 157 size_t numverts=m_pModelDef->GetNumVertices(); 158 SModelVertex* verts=m_pModelDef->GetVertices(); 159 160 // Remove any transformations, so that we calculate the bounding box 161 // at the origin. The box is later re-transformed onto the object, without 162 // having to recalculate the size of the box. 163 CMatrix3D transform, oldtransform = GetTransform(); 164 CModelAbstract* oldparent = m_Parent; 165 166 m_Parent = 0; 167 transform.SetIdentity(); 168 CRenderableObject::SetTransform(transform); 169 170 // Following seems to stomp over the current animation time - which, unsurprisingly, 171 // introduces artefacts in the currently playing animation. Save it here and restore it 172 // at the end. 173 float AnimTime = m_AnimTime; 174 175 // iterate through every frame of the animation 176 for (size_t j=0;j<anim->GetNumFrames();j++) { 177 m_PositionValid = false; 178 ValidatePosition(); 179 180 // extend bounds by vertex positions at the frame 181 for (size_t i=0;i<numverts;i++) 182 { 183 result += CModelDef::SkinPoint(verts[i], GetAnimatedBoneMatrices()); 184 } 185 // advance to next frame 186 m_AnimTime += anim->GetFrameTime(); 187 } 188 189 m_PositionValid = false; 190 m_Parent = oldparent; 191 SetTransform(oldtransform); 192 m_AnimTime = AnimTime; 141 PROFILE2("CalcAnimatedObjectBounds"); 142 m_pModelDef->GetMaxBounds(anim, !(m_Flags & MODELFLAG_NOLOOPANIMATION), result); 193 143 } 194 144 -
ps/trunk/source/graphics/ModelDef.cpp
r24915 r25306 31 31 # include <xmmintrin.h> 32 32 #endif 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 33 64 34 65 CVector3D CModelDef::SkinPoint(const SModelVertex& vtx, -
ps/trunk/source/graphics/ModelDef.h
r24489 r25306 1 /* Copyright (C) 202 0Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 24 24 25 25 #include "ps/CStr.h" 26 26 27 #include "maths/Matrix3D.h" 27 28 #include "maths/Vector2D.h" … … 30 31 #include "lib/file/vfs/vfs_path.h" 31 32 #include "renderer/VertexArray.h" 33 34 32 35 #include <map> 33 #include < cstring>36 #include <> 34 37 35 38 class CBoneState; 39 36 40 37 41 /** … … 188 192 // null if no match (case insensitive search) 189 193 const SPropPoint* FindPropPoint(const char* name) const; 194 195 196 197 198 190 199 191 200 /** … … 267 276 VfsPath m_Name; // filename 268 277 278 279 280 269 281 // renderdata shared by models of the same modeldef, 270 282 // by render path -
ps/trunk/source/graphics/SkeletonAnimDef.cpp
r24267 r25306 1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 20 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 26 26 #include "maths/Matrix3D.h" 27 27 #include "ps/CStr.h" 28 28 29 #include "ps/FileIo.h" 29 30 31 32 30 33 31 34 /////////////////////////////////////////////////////////////////////////////////////////// 32 35 // CSkeletonAnimDef constructor 33 CSkeletonAnimDef::CSkeletonAnimDef() : m_FrameTime(0), m_NumKeys(0), m_NumFrames(0) , m_Keys(0)36 CSkeletonAnimDef::CSkeletonAnimDef() : m_FrameTime(0), m_NumKeys(0), m_NumFrames(0) 34 37 { 38 39 40 41 42 43 44 45 35 46 } 36 47 … … 39 50 CSkeletonAnimDef::~CSkeletonAnimDef() 40 51 { 41 delete[] m_Keys;42 52 } 43 53 … … 90 100 /////////////////////////////////////////////////////////////////////////////////////////// 91 101 // Load: try to load the anim from given file; return a new anim if successful 92 CSkeletonAnimDef*CSkeletonAnimDef::Load(const VfsPath& filename)102 CSkeletonAnimDef::Load(const VfsPath& filename) 93 103 { 94 104 CFileUnpacker unpacker; … … 101 111 102 112 // unpack the data 103 CSkeletonAnimDef* anim=new CSkeletonAnimDef;113 ; 104 114 try { 105 115 CStr name; // unused - just here to maintain compatibility with the animation files … … 108 118 anim->m_NumKeys = unpacker.UnpackSize(); 109 119 anim->m_NumFrames = unpacker.UnpackSize(); 110 anim->m_Keys =new Key[anim->m_NumKeys*anim->m_NumFrames];111 unpacker.UnpackRaw(anim->m_Keys ,anim->m_NumKeys*anim->m_NumFrames*sizeof(Key));120 anim->m_Keys; 121 unpacker.UnpackRaw(anim->m_Keys)); 112 122 } catch (PSERROR_File&) { 113 delete anim;123 ; 114 124 throw; 115 125 } … … 120 130 /////////////////////////////////////////////////////////////////////////////////////////// 121 131 // Save: try to save anim to file 122 void CSkeletonAnimDef::Save(const VfsPath& pathname, const CSkeletonAnimDef*anim)132 void CSkeletonAnimDef::Save(const VfsPath& pathname, anim) 123 133 { 124 134 CFilePacker packer(FILE_VERSION, "PSSA"); … … 126 136 // pack up all the data 127 137 packer.PackString(""); 128 packer.PackRaw(&anim ->m_FrameTime,sizeof(anim->m_FrameTime));129 const size_t numKeys = anim ->m_NumKeys;138 packer.PackRaw(&animm_FrameTime)); 139 const size_t numKeys = animm_NumKeys; 130 140 packer.PackSize(numKeys); 131 const size_t numFrames = anim ->m_NumFrames;141 const size_t numFrames = animm_NumFrames; 132 142 packer.PackSize(numFrames); 133 packer.PackRaw(anim ->m_Keys,numKeys*numFrames*sizeof(Key));143 packer.PackRaw(anim)); 134 144 135 145 // now write it -
ps/trunk/source/graphics/SkeletonAnimDef.h
r18987 r25306 1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 20 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 26 26 #include "maths/Quaternion.h" 27 27 #include "lib/file/vfs/vfs_path.h" 28 29 30 28 31 29 32 //////////////////////////////////////////////////////////////////////////////////////// … … 79 82 80 83 // anim I/O functions 81 static CSkeletonAnimDef*Load(const VfsPath& filename);82 static void Save(const VfsPath& pathname, const CSkeletonAnimDef *anim);84 static Load(const VfsPath& filename); 85 static void Save(const VfsPath& pathname, const CSkeletonAnimDef anim); 83 86 84 87 public: … … 90 93 size_t m_NumFrames; 91 94 // animation data - m_NumKeys*m_NumFrames total keys 92 Key* m_Keys; 95 std::vector<Key> m_Keys; 96 // Unique identifier - used by CModelDef to cache bounds per-animDef. 97 // (hopefully we won't run into the u32 limit too soon). 98 u32 m_UID; 99 static u32 nextUID; 93 100 }; 94 101 -
ps/trunk/source/graphics/SkeletonAnimManager.cpp
r25004 r25306 41 41 CSkeletonAnimManager::~CSkeletonAnimManager() 42 42 { 43 using Iter = std::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator;44 for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)45 delete i->second;46 43 } 47 44 … … 54 51 55 52 // Find if it's already been loaded 56 std::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);53 std::unordered_map<VfsPath, >::iterator iter = m_Animations.find(name); 57 54 if (iter != m_Animations.end()) 58 return iter->second ;55 return iter->second; 59 56 60 CSkeletonAnimDef* def = NULL;57 ; 61 58 62 59 // Find the file to load … … 64 61 65 62 if (psaFilename.empty()) 66 {67 63 LOGERROR("Could not load animation '%s'", pathname.string8()); 68 def = NULL;69 }70 64 else 71 {72 65 try 73 66 { … … 78 71 LOGERROR("Could not load animation '%s'", psaFilename.string8()); 79 72 } 80 }81 73 82 74 if (def) … … 85 77 LOGERROR("CSkeletonAnimManager::GetAnimation(%s): Failed loading, marked file as bad", pathname.string8()); 86 78 87 // Add to map 88 m_Animations[name] = def; // NULL if failed to load - we won't try loading it again 89 return def; 79 // Add to map, NULL if failed to load - we won't try loading it again 80 return m_Animations.insert_or_assign(name, std::move(def)).first->second.get(); 90 81 } -
ps/trunk/source/graphics/SkeletonAnimManager.h
r25004 r25306 25 25 #include "lib/file/vfs/vfs_path.h" 26 26 27 27 28 #include <unordered_map> 28 29 … … 48 49 private: 49 50 // map of all known animations. Value is NULL if it failed to load. 50 std::unordered_map<VfsPath, CSkeletonAnimDef*> m_Animations;51 std::unordered_map<VfsPath, > m_Animations; 51 52 52 53 CColladaManager& m_ColladaManager;
Note:
See TracChangeset
for help on using the changeset viewer.