Changeset 382
- Timestamp:
- 09/17/11 11:38:06 (8 months ago)
- Location:
- cafu/trunk
- Files:
-
- 23 modified
-
CaWE/ModelEditor/SceneView3D.cpp (modified) (3 diffs)
-
Libs/Models/Loader.hpp (modified) (1 diff)
-
Libs/Models/Loader_ase.hpp (modified) (1 diff)
-
Libs/Models/Loader_assimp.hpp (modified) (1 diff)
-
Libs/Models/Loader_cmdl.cpp (modified) (1 diff)
-
Libs/Models/Loader_cmdl.hpp (modified) (1 diff)
-
Libs/Models/Loader_fbx.cpp (modified) (1 diff)
-
Libs/Models/Loader_fbx.hpp (modified) (1 diff)
-
Libs/Models/Loader_lwo.hpp (modified) (1 diff)
-
Libs/Models/Loader_md5.hpp (modified) (1 diff)
-
Libs/Models/Loader_mdl.cpp (modified) (4 diffs)
-
Libs/Models/Loader_mdl.hpp (modified) (3 diffs)
-
Libs/Models/Model.hpp (modified) (3 diffs)
-
Libs/Models/Model_cmdl.cpp (modified) (15 diffs)
-
Libs/Models/Model_cmdl.hpp (modified) (6 diffs)
-
Libs/Models/Model_dlod.cpp (modified) (1 diff)
-
Libs/Models/Model_dlod.hpp (modified) (1 diff)
-
Libs/Models/Model_dummy.cpp (modified) (1 diff)
-
Libs/Models/Model_dummy.hpp (modified) (1 diff)
-
Libs/Models/Model_mdl.cpp (modified) (1 diff)
-
Libs/Models/Model_mdl.hpp (modified) (1 diff)
-
Libs/Models/Model_proxy.cpp (modified) (1 diff)
-
Libs/Models/Model_proxy.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp
r381 r382 104 104 ModelT::TraceResultT Result; 105 105 106 if (m_Parent->GetModelDoc()->GetModel()->TraceRay(AnimSel.Size()==0 ? -1 : AnimSel[0], Anim.FrameNr, RayOrigin, RayDir, Result) && Result.Fraction<BestFraction)106 if (m_Parent->GetModelDoc()->GetModel()->TraceRay(AnimSel.Size()==0 ? -1 : AnimSel[0], Anim.FrameNr, -1 /*SkinNr*/, RayOrigin, RayDir, Result) && Result.Fraction<BestFraction) 107 107 { 108 108 BestFraction=Result.Fraction; … … 388 388 if (ScenePropGrid->m_Model_ShowMesh) 389 389 { 390 Model->Draw(SequNr, Anim.FrameNr, 0.0f /*LodDist*/, (CafuModelT::SuperT*)NULL);390 Model->Draw(SequNr, Anim.FrameNr, -1 /*SkinNr*/, 0.0f /*LodDist*/, (CafuModelT::SuperT*)NULL); 391 391 392 392 for (unsigned long SmNr=0; SmNr<ModelDoc->GetSubmodels().Size(); SmNr++) … … 397 397 SM->GetJointsMap()); 398 398 399 SM->GetSubmodel()->Draw(0, 0.0f, 0.0f /*LodDist*/, &Super);399 SM->GetSubmodel()->Draw(0, 0.0f, -1 /*SkinNr*/, 0.0f /*LodDist*/, &Super); 400 400 } 401 401 } -
cafu/trunk/Libs/Models/Loader.hpp
r358 r382 58 58 /// Actually loads the file data into the appropriate parts of the Cafu model. 59 59 virtual void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan)=0; 60 61 /// Loads the skins of the Cafu model. 62 virtual void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan)=0; 60 63 61 64 /// Loads the GUI fixtures of the Cafu model. -
cafu/trunk/Libs/Models/Loader_ase.hpp
r334 r382 41 41 bool UseGivenTS() const { return true; } 42 42 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 43 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 43 44 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 44 45 -
cafu/trunk/Libs/Models/Loader_assimp.hpp
r334 r382 45 45 bool UseGivenTS() const; 46 46 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 47 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 47 48 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 48 49 -
cafu/trunk/Libs/Models/Loader_cmdl.cpp
r350 r382 393 393 394 394 395 void LoaderCafuT::Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) 396 { 397 // Read the skins. 398 lua_getglobal(m_LuaState, "Skins"); 399 { 400 Skins.Overwrite(); 401 Skins.PushBackEmptyExact(lua_objlen_ul(m_LuaState, -1)); 402 403 for (unsigned long SkinNr=0; SkinNr<Skins.Size(); SkinNr++) 404 { 405 CafuModelT::SkinT& Skin=Skins[SkinNr]; 406 407 lua_rawgeti(m_LuaState, -1, SkinNr+1); 408 { 409 lua_getfield(m_LuaState, -1, "name"); 410 { 411 const char* Name=lua_tostring(m_LuaState, -1); 412 Skin.Name=Name ? Name : "Skin"; 413 } 414 lua_pop(m_LuaState, 1); 415 416 lua_getfield(m_LuaState, -1, "materials"); 417 { 418 const unsigned long NumMats=lua_objlen_ul(m_LuaState, -1); 419 420 Skin.Materials.PushBackEmptyExact(NumMats); 421 Skin.RenderMaterials.PushBackEmptyExact(NumMats); 422 423 for (unsigned int c=0; c<NumMats; c++) 424 { 425 lua_rawgeti(m_LuaState, -1, c+1); 426 { 427 const char* s=lua_tostring(m_LuaState, -1); 428 const std::string MatName=s ? s : ""; 429 430 Skin.Materials[c] =(s!="") ? MaterialMan.GetMaterial(MatName) : NULL; 431 Skin.RenderMaterials[c]=NULL; 432 } 433 lua_pop(m_LuaState, 1); 434 } 435 } 436 lua_pop(m_LuaState, 1); 437 } 438 lua_pop(m_LuaState, 1); 439 } 440 } 441 lua_pop(m_LuaState, 1); 442 } 443 444 395 445 void LoaderCafuT::Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) 396 446 { -
cafu/trunk/Libs/Models/Loader_cmdl.hpp
r349 r382 44 44 bool UseGivenTS() const; 45 45 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 46 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 46 47 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 47 48 -
cafu/trunk/Libs/Models/Loader_fbx.cpp
r358 r382 831 831 832 832 833 void LoaderFbxT::Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) 834 { 835 // TODO... 836 } 837 838 833 839 void LoaderFbxT::Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) 834 840 { -
cafu/trunk/Libs/Models/Loader_fbx.hpp
r334 r382 42 42 bool UseGivenTS() const; 43 43 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 44 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 44 45 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs); 45 46 -
cafu/trunk/Libs/Models/Loader_lwo.hpp
r334 r382 38 38 bool UseGivenTS() const { return true; } 39 39 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 40 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 40 41 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 41 42 -
cafu/trunk/Libs/Models/Loader_md5.hpp
r334 r382 40 40 bool UseGivenTS() const; 41 41 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 42 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) { } 42 43 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 43 44 }; -
cafu/trunk/Libs/Models/Loader_mdl.cpp
r352 r382 202 202 // For clarity and better readibility, break the loading into three separate functions. 203 203 Load(Joints); 204 Load(Meshes );204 Load(Meshes, m_MeshSkinRef); 205 205 Load(Anims); 206 206 } … … 234 234 235 235 236 void LoaderHL1mdlT::Load(ArrayT<CafuModelT::MeshT>& Meshes ) const236 void LoaderHL1mdlT::Load(ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<int>& MeshSkinRef) const 237 237 { 238 238 // This is configurable with BodyNr and SkinNr, but at this time we always take the defaults (index 0 each). … … 292 292 Weight.Pos =Vector3fT(StudioVertices[VertexNr]); 293 293 } 294 295 MeshSkinRef.PushBack(StudioMesh.SkinRef); 294 296 } 295 297 … … 524 526 // TODO: Sequ.LinearMovement ? 525 527 } 528 529 530 void LoaderHL1mdlT::Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan) 531 { 532 const short* SkinRefs0=(short*)((char*)StudioTextureHeader+StudioTextureHeader->SkinIndex); 533 534 if (StudioTextureHeader->NumSkinFamilies <= 1) return; 535 Skins.PushBackEmptyExact(StudioTextureHeader->NumSkinFamilies - 1); 536 537 // Start with SkinNr=1, because the materials of the first (default) skin are kept directly in the mesh definitions. 538 for (int SkinNr=1; SkinNr<StudioTextureHeader->NumSkinFamilies; SkinNr++) 539 { 540 const short* SkinRefs=((short*)((char*)StudioTextureHeader+StudioTextureHeader->SkinIndex)) + SkinNr*StudioTextureHeader->NumSkinRef; 541 CafuModelT::SkinT& Skin =Skins[SkinNr-1]; 542 543 for (unsigned long MeshNr=0; MeshNr<m_MeshSkinRef.Size(); MeshNr++) 544 { 545 const int msr=m_MeshSkinRef[MeshNr]; 546 547 Skin.Materials.PushBack(SkinRefs0[msr]==SkinRefs[msr] ? NULL : m_Materials[SkinRefs[msr]]); 548 Skin.RenderMaterials.PushBack(NULL); 549 } 550 } 551 } -
cafu/trunk/Libs/Models/Loader_mdl.hpp
r334 r382 46 46 bool UseGivenTS() const; 47 47 void Load(ArrayT<CafuModelT::JointT>& Joints, ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<CafuModelT::AnimT>& Anims, MaterialManagerImplT& MaterialMan); 48 void Load(ArrayT<CafuModelT::SkinT>& Skins, const MaterialManagerImplT& MaterialMan); 48 49 void Load(ArrayT<CafuModelT::GuiFixtureT>& GuiFixtures, ArrayT<CafuModelT::GuiLocT>& GuiLocs) { } 49 50 … … 52 53 53 54 void Load(ArrayT<CafuModelT::JointT>& Joints) const; 54 void Load(ArrayT<CafuModelT::MeshT>& Meshes ) const;55 void Load(ArrayT<CafuModelT::MeshT>& Meshes, ArrayT<int>& MeshSkinRef) const; 55 56 void Load(ArrayT<CafuModelT::AnimT>& Anims) const; 56 57 … … 59 60 ArrayT< ArrayT<char> > AnimationData; ///< Animation data ("demand loaded sequences"). 60 61 ArrayT<MaterialT*> m_Materials; ///< The MatSys materials used in the model. 62 ArrayT<int> m_MeshSkinRef; ///< For each mesh, the original StudioMeshT::SkinRef number. 61 63 62 64 // Convenient abbreviations into the above data arrays. -
cafu/trunk/Libs/Models/Model.hpp
r343 r382 44 44 TraceResultT(float Fraction_=0.0f) : Fraction(Fraction_), Material(NULL), MeshNr(-1), TriNr(-1) { } 45 45 46 float Fraction; ///< The scalar along RayDir at which the hit occurred (RayOrigin + RayDir*Fraction).47 Vector3fT Normal; ///< This is the normal vector of the hit surface.48 MaterialT*Material; ///< The material at the point of impact. Can be NULL, e.g. when an edge (i.e. a bevel plane) was hit or the material is not available.49 unsigned int MeshNr; ///< The number of the hit mesh. Can be -1 (that is, \emph{larger} then the number of meshes in the model) if the hit mesh cannot be determined.50 unsigned int TriNr; ///< The number of the hit triangle in the hit mesh. Can be -1 (that is, \emph{larger} then the number of triangles in the mesh) if the hit triangle cannot be determined.46 float Fraction; ///< The scalar along RayDir at which the hit occurred (RayOrigin + RayDir*Fraction). 47 Vector3fT Normal; ///< This is the normal vector of the hit surface. 48 const MaterialT* Material; ///< The material at the point of impact. Can be NULL, e.g. when an edge (i.e. a bevel plane) was hit or the material is not available. 49 unsigned int MeshNr; ///< The number of the hit mesh. Can be -1 (that is, \emph{larger} then the number of meshes in the model) if the hit mesh cannot be determined. 50 unsigned int TriNr; ///< The number of the hit triangle in the hit mesh. Can be -1 (that is, \emph{larger} then the number of triangles in the mesh) if the hit triangle cannot be determined. 51 51 }; 52 52 … … 98 98 /// @param SequenceNr The animation sequence at which the ray should be traced. 99 99 /// @param FrameNr The animation frame at which the ray should be traced. 100 /// @param SkinNr The skin to use for the trace, use -1 for the default skin. 100 101 /// @param RayOrigin The point in model space where the ray starts. 101 102 /// @param RayDir A unit vector in model space that describes the direction the ray extends to. … … 103 104 /// 104 105 /// @returns true if the ray hit the model, false otherwise. When the model was hit, additional details are returned via the Result parameter. 105 virtual bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const=0;106 virtual bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const=0; 106 107 107 108 // Returns the number of frames of sequence SequenceNr. Useful for non-repeating (e.g. death) sequences. -
cafu/trunk/Libs/Models/Model_cmdl.cpp
r358 r382 232 232 // Have the model loader load the model file. 233 233 Loader.Load(m_Joints, m_Meshes, m_Anims, m_MaterialMan); 234 Loader.Load(m_Skins, m_MaterialMan); 234 235 Loader.Load(m_GuiFixtures, m_GuiLocs); 235 236 Loader.Postprocess(m_Meshes); … … 240 241 InitMeshes(); 241 242 242 // Allocate the render materials .243 // Allocate the render materials for the meshes (the default skin). 243 244 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 244 245 { … … 247 248 assert(Mesh.RenderMaterial==NULL); 248 249 Mesh.RenderMaterial=MatSys::Renderer!=NULL ? MatSys::Renderer->RegisterMaterial(Mesh.Material) : NULL; 250 } 251 252 // Allocate the render materials for the skins. 253 for (unsigned long SkinNr=0; SkinNr<m_Skins.Size(); SkinNr++) 254 { 255 SkinT& Skin=m_Skins[SkinNr]; 256 257 assert(Skin.Materials.Size()==m_Meshes.Size()); 258 assert(Skin.Materials.Size()==Skin.RenderMaterials.Size()); 259 260 for (unsigned long MatNr=0; MatNr<Skin.Materials.Size(); MatNr++) 261 { 262 assert(Skin.RenderMaterials[MatNr]==NULL); 263 264 if (Skin.Materials[MatNr]!=NULL && MatSys::Renderer!=NULL) 265 Skin.RenderMaterials[MatNr]=MatSys::Renderer->RegisterMaterial(Skin.Materials[MatNr]); 266 } 249 267 } 250 268 … … 266 284 if (MatSys::Renderer==NULL) return; 267 285 286 // Free all render materials used in skins. 287 for (unsigned long SkinNr=0; SkinNr<m_Skins.Size(); SkinNr++) 288 for (unsigned long MatNr=0; MatNr<m_Skins[SkinNr].RenderMaterials.Size(); MatNr++) 289 MatSys::Renderer->FreeMaterial(m_Skins[SkinNr].RenderMaterials[MatNr]); 290 291 // Free all render materials used in the meshes (the default skin). 268 292 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 269 293 MatSys::Renderer->FreeMaterial(m_Meshes[MeshNr].RenderMaterial); … … 756 780 757 781 782 // *** Write the skins. *** 783 OutStream << "\nSkins=\n{\n"; 784 785 for (unsigned long SkinNr=0; SkinNr<m_Skins.Size(); SkinNr++) 786 { 787 const SkinT& Skin=m_Skins[SkinNr]; 788 789 OutStream << "\t{\n" 790 << "\t\tname=\"" << Skin.Name << "\";\n" 791 << "\t\tmaterials={ "; 792 793 for (unsigned long MatNr=0; MatNr<Skin.Materials.Size(); MatNr++) 794 { 795 OutStream << "\""; 796 if (Skin.Materials[MatNr]!=NULL) OutStream << Skin.Materials[MatNr]->Name; 797 OutStream << "\""; 798 if (MatNr+1 < Skin.Materials.Size()) OutStream << ", "; 799 } 800 801 OutStream << " };\n" 802 << "\t},\n"; 803 } 804 805 OutStream << "}\n"; 806 807 758 808 // *** Write the GUI fixtures. *** 759 809 OutStream << "\nGuiFixtures=\n{\n"; … … 1094 1144 1095 1145 1096 void CafuModelT::Draw(int SequenceNr, float FrameNr, float /*LodDist*/, const SuperT* Super) const 1146 const MaterialT* CafuModelT::GetMaterial(unsigned long MeshNr, int SkinNr) const 1147 { 1148 assert(MeshNr<m_Meshes.Size()); 1149 1150 if (SkinNr<0 || SkinNr>=int(m_Skins.Size())) 1151 return m_Meshes[MeshNr].Material; 1152 1153 if (MeshNr>=m_Skins[SkinNr].Materials.Size()) 1154 return m_Meshes[MeshNr].Material; 1155 1156 if (!m_Skins[SkinNr].Materials[MeshNr]) 1157 return m_Meshes[MeshNr].Material; 1158 1159 return m_Skins[SkinNr].Materials[MeshNr]; 1160 } 1161 1162 1163 MatSys::RenderMaterialT* CafuModelT::GetRenderMaterial(unsigned long MeshNr, int SkinNr) const 1164 { 1165 assert(MeshNr<m_Meshes.Size()); 1166 1167 if (SkinNr<0 || SkinNr>=int(m_Skins.Size())) 1168 return m_Meshes[MeshNr].RenderMaterial; 1169 1170 if (MeshNr>=m_Skins[SkinNr].RenderMaterials.Size()) 1171 return m_Meshes[MeshNr].RenderMaterial; 1172 1173 if (!m_Skins[SkinNr].RenderMaterials[MeshNr]) 1174 return m_Meshes[MeshNr].RenderMaterial; 1175 1176 return m_Skins[SkinNr].RenderMaterials[MeshNr]; 1177 } 1178 1179 1180 void CafuModelT::Draw(int SequenceNr, float FrameNr, int SkinNr, float /*LodDist*/, const SuperT* Super) const 1097 1181 { 1098 1182 // SequenceNr==-1 means "use the bind pose from the model file only (no anim)". … … 1172 1256 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 1173 1257 { 1174 MatSys::Renderer->SetCurrentMaterial( m_Meshes[MeshNr].RenderMaterial);1258 MatSys::Renderer->SetCurrentMaterial(GetRenderMaterial(MeshNr, SkinNr)); 1175 1259 MatSys::Renderer->RenderMesh(m_Draw_Meshes[MeshNr]); 1176 1260 … … 1231 1315 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 1232 1316 { 1233 MatSys::Renderer->SetCurrentMaterial( m_Meshes[MeshNr].RenderMaterial);1317 MatSys::Renderer->SetCurrentMaterial(GetRenderMaterial(MeshNr, SkinNr)); 1234 1318 MatSys::Renderer->RenderMesh(m_Draw_Meshes[MeshNr]); 1235 1319 } … … 1243 1327 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 1244 1328 { 1245 const MeshT& Mesh=m_Meshes[MeshNr]; 1246 1247 if (Mesh.Material==NULL || Mesh.Material->NoShadows) continue; 1329 const MeshT& Mesh =m_Meshes[MeshNr]; 1330 const MaterialT* MeshMat=GetMaterial(MeshNr, SkinNr); 1331 1332 if (MeshMat==NULL || MeshMat->NoShadows) continue; 1248 1333 1249 1334 static ArrayT<bool> TriangleIsFrontFacing; … … 1343 1428 void CafuModelT::Draw(int SequenceNr, float FrameNr, float LodDist, const ModelT* /*SubModel*/) const 1344 1429 { 1345 Draw(SequenceNr, FrameNr, LodDist, (SuperT*)NULL);1430 Draw(SequenceNr, FrameNr, -1 /*default skin*/, LodDist, (SuperT*)NULL); 1346 1431 } 1347 1432 … … 1418 1503 1419 1504 1420 bool CafuModelT::TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const1505 bool CafuModelT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 1421 1506 { 1422 1507 float Fraction=0.0f; … … 1430 1515 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 1431 1516 { 1432 const MeshT& Mesh=m_Meshes[MeshNr]; 1517 const MeshT& Mesh =m_Meshes[MeshNr]; 1518 const MaterialT* MeshMat=GetMaterial(MeshNr, SkinNr); 1433 1519 1434 1520 // If the ClipFlags don't match the ClipMask, this polygon doesn't interfere with the trace. 1435 if (!Mesh .Material) continue;1436 // if ((Mesh .Material->ClipFlags & ClipMask)==0) continue;1521 if (!MeshMat) continue; 1522 // if ((MeshMat->ClipFlags & ClipMask)==0) continue; 1437 1523 1438 1524 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) … … 1452 1538 // Note that Christer Ericson has shown in his blog at http://realtimecollisiondetection.net/blog/?p=13 1453 1539 // that scalar triple products (Spatprodukte) are equivalent and could be used as well. ;-) 1454 if (!Mesh .Material->TwoSided)1540 if (!MeshMat->TwoSided) 1455 1541 { 1456 1542 if (R*PlueckerfT::CreateFromLine(A, B) >= 0) continue; … … 1474 1560 1475 1561 if (Nenner==0) continue; // If Nenner==0, then RayDir is parallel to the triangle plane (no intersection). 1476 assert(Mesh .Material->TwoSided || Nenner<0); // Ifmaterial is single sided, then Nenner<0, a consequence of the Pluecker tests above.1562 assert(MeshMat->TwoSided || Nenner<0); // If the material is single sided, then Nenner<0, a consequence of the Pluecker tests above. 1477 1563 1478 1564 const float Dist=dot(Tri.Draw_Normal, RayOrigin-A); // The distance of RayOrigin to the triangle plane. … … 1485 1571 Result.Fraction=F; 1486 1572 Result.Normal =(Nenner<0) ? Tri.Draw_Normal : -Tri.Draw_Normal; // Handle two-sided materials properly. 1487 Result.Material=Mesh .Material;1573 Result.Material=MeshMat; 1488 1574 Result.MeshNr =MeshNr; 1489 1575 Result.TriNr =TriNr; -
cafu/trunk/Libs/Models/Model_cmdl.hpp
r358 r382 166 166 167 167 168 /// This struct describes additional/alternative skins for this model. 169 struct SkinT 170 { 171 std::string Name; ///< The name of this skin. 172 ArrayT<MaterialT*> Materials; ///< For each mesh \c m, <tt>Materials[m]</tt> is the material for the mesh in this skin. If <tt>Materials[m]</tt> is NULL, the material of the default skin is used. 173 ArrayT<MatSys::RenderMaterialT*> RenderMaterials; ///< Analogous to \c Materials, these are the (possibly NULL) render materials for the meshes in this skin. 174 }; 175 176 168 177 /// This struct defines how and where a GUI can be fixed to the model. 169 178 /// The GUI rectangle is defined by three points: the origin, the x-axis endpoint, and the y-axis endpoint, numbered 0, 1 and 2. … … 239 248 const ArrayT<MeshT>& GetMeshes() const { return m_Meshes; } 240 249 const ArrayT<AnimT>& GetAnims() const { return m_Anims; } 250 const ArrayT<SkinT>& GetSkins() const { return m_Skins; } 241 251 const ArrayT<GuiFixtureT>& GetGuiFixtures() const { return m_GuiFixtures; } 242 252 … … 247 257 /// @param SequenceNr The number of the animation sequence to use, -1 for the bind pose. 248 258 /// @param FrameNr The frame number in the animation sequence to render to model at. 259 /// @param SkinNr The skin to render the model with, -1 for the default skin. 249 260 /// @param LodDist The distance to the camera for reducing the level-of-detail (currently unused). 250 261 /// @param Super Information about a parent or "super" model whose skeleton pose should be used when rendering this model. 251 void Draw(int SequenceNr, float FrameNr, float LodDist, const SuperT* Super=NULL) const;262 void Draw(int SequenceNr, float FrameNr, int SkinNr, float LodDist, const SuperT* Super=NULL) const; 252 263 253 264 /// Determines if <tt>GF.Points[PointNr].MeshNr</tt> is a valid index into this model. … … 264 275 unsigned int GetNrOfSequences() const; 265 276 BoundingBox3fT GetBB(int SequenceNr, float FrameNr) const; 266 bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const;277 bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 267 278 // float GetNrOfFrames(int SequenceNr) const; 268 279 float AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const; … … 286 297 void InitMeshes(); ///< An auxiliary method for the constructors. 287 298 void UpdateCachedDrawData(int SequenceNr, float FrameNr, const SuperT* Super) const; ///< A private auxiliary method. 299 const MaterialT* GetMaterial(unsigned long MeshNr, int SkinNr) const; ///< Returns the proper material for the given mesh in the given skin. 300 MatSys::RenderMaterialT* GetRenderMaterial(unsigned long MeshNr, int SkinNr) const; ///< Returns the proper render material for the given mesh in the given skin. 288 301 289 302 … … 293 306 mutable ArrayT<MeshT> m_Meshes; ///< Array of (sub)meshes of this model. 294 307 ArrayT<AnimT> m_Anims; ///< Array of animations of this model. 308 ArrayT<SkinT> m_Skins; ///< Array of additional/alternative skins for this model. 295 309 296 310 const bool m_UseGivenTangentSpace; ///< Whether this model should use the fixed, given tangent space that was loaded from the model file, or it the tangent space is dynamically recomputed (useful for animated models). -
cafu/trunk/Libs/Models/Model_dlod.cpp
r318 r382 118 118 119 119 120 bool ModelDlodT::TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const120 bool ModelDlodT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 121 121 { 122 122 // for (unsigned long LodModelNr=0; LodModelNr<LodModels.Size(); LodModelNr++) 123 123 // if (LodDist>=LodStartRanges[LodModelNr] && LodDist<LodEndRanges[LodModelNr]) 124 // return LodModels[LodModelNr].TraceRay(SequenceNr, FrameNr, RayOrigin, RayDir, Result);124 // return LodModels[LodModelNr].TraceRay(SequenceNr, FrameNr, SkinNr, RayOrigin, RayDir, Result); 125 125 // 126 126 // return false; 127 return LodModels[0].TraceRay(SequenceNr, FrameNr, RayOrigin, RayDir, Result);127 return LodModels[0].TraceRay(SequenceNr, FrameNr, SkinNr, RayOrigin, RayDir, Result); 128 128 } 129 129 -
cafu/trunk/Libs/Models/Model_dlod.hpp
r318 r382 47 47 unsigned int GetNrOfSequences() const; 48 48 BoundingBox3fT GetBB(int SequenceNr, float FrameNr) const; 49 bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const;49 bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 50 50 // float GetNrOfFrames(int SequenceNr) const; 51 51 float AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const; -
cafu/trunk/Libs/Models/Model_dummy.cpp
r343 r382 73 73 74 74 75 bool ModelDummyT::TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const75 bool ModelDummyT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 76 76 { 77 77 float Fraction=0.0f; -
cafu/trunk/Libs/Models/Model_dummy.hpp
r318 r382 45 45 unsigned int GetNrOfSequences() const; 46 46 BoundingBox3fT GetBB(int SequenceNr, float FrameNr) const; 47 bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const;47 bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 48 48 // float GetNrOfFrames(int SequenceNr) const; 49 49 float AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const; -
cafu/trunk/Libs/Models/Model_mdl.cpp
r318 r382 1575 1575 1576 1576 1577 bool ModelMdlT::TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const1577 bool ModelMdlT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 1578 1578 { 1579 1579 return false; -
cafu/trunk/Libs/Models/Model_mdl.hpp
r318 r382 125 125 unsigned int GetNrOfSequences() const; 126 126 BoundingBox3fT GetBB(int SequenceNr, float FrameNr) const; 127 bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const;127 bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 128 128 // float GetNrOfFrames(int SequenceNr) const; 129 129 float AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const; -
cafu/trunk/Libs/Models/Model_proxy.cpp
r318 r382 242 242 243 243 244 bool ModelProxyT::TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const245 { 246 return ModelPool[PoolIndex]->TraceRay(SequenceNr, FrameNr, RayOrigin, RayDir, Result);244 bool ModelProxyT::TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const 245 { 246 return ModelPool[PoolIndex]->TraceRay(SequenceNr, FrameNr, SkinNr, RayOrigin, RayDir, Result); 247 247 } 248 248 -
cafu/trunk/Libs/Models/Model_proxy.hpp
r318 r382 61 61 unsigned int GetNrOfSequences() const; 62 62 BoundingBox3fT GetBB(int SequenceNr, float FrameNr) const; 63 bool TraceRay(int SequenceNr, float FrameNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const;63 bool TraceRay(int SequenceNr, float FrameNr, int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, TraceResultT& Result) const; 64 64 // float GetNrOfFrames(int SequenceNr) const; 65 65 float AdvanceFrameNr(int SequenceNr, float FrameNr, float DeltaTime, bool Loop=true) const;
