Browse Source

added checks to see if a collision mesh exists on models, if not we don't put it in the map

Image 4 years ago
parent
commit
32a5e3eccd
1 changed files with 21 additions and 3 deletions
  1. 21 3
      EQ2/devtools/EQ2ModelViewer/EQ2ModelViewer/Model.cs

+ 21 - 3
EQ2/devtools/EQ2ModelViewer/EQ2ModelViewer/Model.cs

@@ -32,7 +32,7 @@ namespace EQ2ModelViewer
 
         public bool Initialize(Device device, string modelFileName, string[] textureFileName)
         {
-            if (!LoadModel(modelFileName))
+            if (!LoadModel(modelFileName, null))
             {
                 Console.WriteLine("Model: Failed to load the model");
                 return false;
@@ -61,6 +61,23 @@ namespace EQ2ModelViewer
 
         public bool Initialize(Device device, VeMeshGeometryNode item, String baseDir)
         {
+            if (item.collisionMeshName == null || item.collisionMeshName.Length < 1)
+            {
+                Console.WriteLine("No collision mesh for MeshGeometryNode");
+                return false;
+            }
+
+            VeCollisionMesh collision = null;
+
+            try
+            {
+                Eq2Reader reader2 = new Eq2Reader(new System.IO.FileStream(frmMain.DirName + item.collisionMeshName, System.IO.FileMode.Open, System.IO.FileAccess.Read));
+                collision = (VeCollisionMesh)reader2.ReadObject();
+                reader2.Dispose();
+            }catch(Exception ex)
+            {
+
+            }
             ArrayList textures = new ArrayList();
 
             string[][] meshes = ((VeMeshGeometryNode)item).renderMeshNames;
@@ -103,7 +120,7 @@ namespace EQ2ModelViewer
                         {
                             textures.Add(pickedTexture);
 
-                            if (!LoadModel(path))
+                            if (!LoadModel(path, collision))
                             {
                                 Console.WriteLine("Model: Failed to load the model " + path);
                                 return false;
@@ -211,7 +228,7 @@ namespace EQ2ModelViewer
             return ret;
         }
 
-        private bool LoadModel(string modelFileName)
+        private bool LoadModel(string modelFileName, VeCollisionMesh collision)
         {
             frmMain.AppendLoadFile("LoadModel: " + modelFileName);
             Eq2Reader reader = new Eq2Reader(File.OpenRead(modelFileName));
@@ -233,6 +250,7 @@ namespace EQ2ModelViewer
                         int indicesIdx = model.indices[index];
                         if (indicesIdx < 0 || indicesIdx >= model.vertices.Length)
                             break;
+
                         float x = model.vertices[model.indices[index]].X;
                         float y = model.vertices[model.indices[index]].Y;
                         float z = model.vertices[model.indices[index]].Z;