bool calculateTransformedBound(ModelSpawn spawn) { string modelFilename = iSrcDir + spawn.name.TrimEnd('\0'); ModelPosition modelPosition = new ModelPosition(); modelPosition.iDir = spawn.iRot; modelPosition.iScale = spawn.iScale; modelPosition.init(); WorldModel_Raw raw_model = new WorldModel_Raw(); if (!raw_model.Read(modelFilename)) { return(false); } int groups = raw_model.groupsArray.Length; if (groups != 1) { Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!"); } AxisAlignedBox modelBound = AxisAlignedBox.Zero(); modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Lo)); modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Hi)); spawn.iBound = modelBound + spawn.iPos; spawn.flags |= ModelFlags.HasBound; return(true); }
bool calculateTransformedBound(ModelSpawn spawn) { string modelFilename = iSrcDir + spawn.name; ModelPosition modelPosition = new ModelPosition(); modelPosition.iDir = spawn.iRot; modelPosition.iScale = spawn.iScale; modelPosition.init(); WorldModel_Raw raw_model = new WorldModel_Raw(); if (!raw_model.Read(modelFilename)) { return(false); } int groups = raw_model.groupsArray.Length; if (groups != 1) { Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!"); } AxisAlignedBox modelBound = AxisAlignedBox.Zero(); bool boundEmpty = true; for (uint g = 0; g < groups; ++g) // should be only one for M2 files... { var vertices = raw_model.groupsArray[g].vertexArray; if (vertices.Empty()) { Console.WriteLine($"error: model {spawn.name} has no geometry!"); continue; } int nvectors = vertices.Count; for (int i = 0; i < nvectors; ++i) { Vector3 v = modelPosition.transform(vertices[i]); if (boundEmpty) { modelBound = new AxisAlignedBox(v, v); boundEmpty = false; } else { modelBound.merge(v); } } } spawn.iBound = modelBound + spawn.iPos; spawn.flags |= ModelFlags.HasBound; return(true); }