public unsafe static void doAppendMeshBinding(GrannyContext grannyContext, IGrannyFile inputFile, IGrannyFile appendFile, Int32 currentModelIndex) { // Get wrappers IGrannyModel inputModel = inputFile.Models[currentModelIndex]; GrannyModelWrapper inputModelWrapper = new GrannyModelWrapper(inputModel); IGrannyModel appendModel = appendFile.Models[0]; GrannyModelWrapper appendModelWrapper = new GrannyModelWrapper(appendModel); // Update model inputModel.MeshBindings.Add(appendFile.Meshes[0]); int meshCountInput = inputModelWrapper.getNumMeshBindings(); int newMeshBindingsCount = meshCountInput + 1; inputModelWrapper.setNumMeshBindings(newMeshBindingsCount); // Update model mesh bindings int oldMeshBindingsPtr = *(int *)inputModelWrapper.getMeshBindingsPtr(); *(int *)inputModelWrapper.getMeshBindingsPtr() = (int)Marshal.AllocHGlobal(newMeshBindingsCount * 4); int newMeshBindingsPtr = *(int *)inputModelWrapper.getMeshBindingsPtr(); int modelMeshBindingsPtrAppend = *(int *)appendModelWrapper.getMeshBindingsPtr(); MemoryUtil.MemCpy((void *)newMeshBindingsPtr, (void *)oldMeshBindingsPtr, (uint)(meshCountInput * 4)); MemoryUtil.MemCpy((void *)(newMeshBindingsPtr + meshCountInput * 4), (void *)modelMeshBindingsPtrAppend, 4); }
public static void overwriteMeshes(IGrannyFile file, string sourceFilename, GrannyContext grannyContext, int currentModelIndex, int vertexFormat) { string filename = file.Filename; GrannyModelInfo modelInfo = loadModelInfos(sourceFilename, vertexFormat)[0]; doBoneBindings(modelInfo); GrannyFileWrapper fileWrapper = new GrannyFileWrapper(file); List <IGrannyFile> meshFileList = new List <IGrannyFile>(); foreach (GrannyMeshInfo meshInfo in modelInfo.meshBindings) { meshFileList.Add(writeMesh(meshInfo, getTemplateFilename(vertexFormat))); } IGrannyModel model = file.Models[currentModelIndex]; GrannyModelWrapper modelWrapper = new GrannyModelWrapper(model); modelWrapper.setNumMeshBindings(0); model.MeshBindings.Clear(); foreach (IGrannyFile meshFile in meshFileList) { doAppendMeshBinding(file, meshFile, currentModelIndex); } fileWrapper.setNumMeshes(0); fileWrapper.setNumTriTopologies(0); fileWrapper.setNumVertexDatas(0); file.Meshes.Clear(); int meshesCount = 0; foreach (IGrannyModel loopModel in file.Models) { foreach (IGrannyMesh mesh in loopModel.MeshBindings) { file.AddMeshReference(mesh); meshesCount++; } } fileWrapper.setFromArtToolInfo("Blender", 2, 0); //fileWrapper.setUnitsPerMeter(10.7f); CivNexusSixApplicationForm.SetExporterInfo(fileWrapper); fileWrapper.setFromFileName(sourceFilename); fileWrapper.setNumMeshes(meshesCount); CivNexusSixApplicationForm.form.SaveAsAction(file, filename, false); List <GrannyModelInfo> modelInfos = new List <GrannyModelInfo>(); modelInfos.Add(modelInfo); createAndBindMaterials(filename, file, modelInfos); }
public static void batchExport(GrannyContext grannyContext, string unitListFile) { StreamReader streamReader = new StreamReader(unitListFile); string directory = Path.GetDirectoryName(unitListFile); string regexString = "(.+);(.*);(.*);(.*)"; string outFilename = unitListFile.Replace(".dat", "_new.dat"); StreamWriter outputWriter = new StreamWriter(new FileStream(outFilename, FileMode.Create)); while (!streamReader.EndOfStream) { string currentLine = streamReader.ReadLine(); Regex regex = new Regex(regexString); MatchCollection mc = regex.Matches(currentLine); foreach (Match m in mc) { string gr2Filename = m.Groups[1].Value.Trim().ToLower(); IGrannyFile grannyFile = grannyContext.LoadGrannyFile(directory + "\\" + gr2Filename); NexusBuddyApplicationForm.loadedFile = grannyFile; NexusBuddyApplicationForm.form.refreshAppData(); List <string> fileTextureMaps = exportAllModelsToCN6(grannyFile, true); string animationFilenames = m.Groups[2].Value.Trim(); string textureFilenames = m.Groups[3].Value.Trim(); string prettyName = m.Groups[4].Value.Trim(); var fileTextureSet = new HashSet <string>(fileTextureMaps); if (String.IsNullOrEmpty(textureFilenames)) { textureFilenames = string.Join(",", fileTextureSet); } string newline = gr2Filename + ";" + animationFilenames + ";" + textureFilenames + ";" + prettyName; outputWriter.WriteLine(newline); } } streamReader.Close(); outputWriter.Close(); File.Delete(unitListFile); File.Move(outFilename, unitListFile); }
//// todo - update to create new memory areas //public unsafe static void doAppendMeshBinding(GrannyContext grannyContext, IGrannyFile inputFile, IGrannyFile appendFile) //{ // // UNPACK CURRENT MODEL // IGrannyModel inputModel = inputFile.Models[0]; // GrannyModelWrapper inputModelWrapper = new GrannyModelWrapper(inputModel); // void* m_pkModel_input = inputModelWrapper.m_pkModel; // // UNPACK APPEND MODEL // IGrannyModel appendModel = appendFile.Models[0]; // GrannyModelWrapper appendModelWrapper = new GrannyModelWrapper(appendModel); // void* m_pkModel_app = appendModelWrapper.m_pkModel; // // UNPACK NEW MODEL // IGrannyFile newModelFile = inputFile; // IGrannyModel newModel = newModelFile.Models[0]; // GrannyModelWrapper newModelWrapper = new GrannyModelWrapper(newModel); // void* m_pkModel_new = newModelWrapper.m_pkModel; // // UPDATE NEW MODEL // int meshCountInput = *(int*)((IntPtr)m_pkModel_input + 76); // newModel.MeshBindings.Add(appendFile.Meshes[0]); // // update Mesh Count // *(int*)((IntPtr)m_pkModel_new + 76) = meshCountInput + 1; // //update model mesh bindings // int size = meshCountInput; // void* modelMeshBindingsPtrInput = (void*)*(int*)((IntPtr)m_pkModel_input + 80); // MemoryUtil.MemCpy((void*)*(int*)((IntPtr)m_pkModel_new + 80), (void*)modelMeshBindingsPtrInput, (uint)(size * 4)); // int writeOffset = meshCountInput; // void* modelMeshBindingsPtrAppend = (void*)*(int*)((IntPtr)m_pkModel_app + 80); // MemoryUtil.MemCpy((void*)(*(int*)((IntPtr)m_pkModel_new + 80) + writeOffset * 4), (void*)modelMeshBindingsPtrAppend, (uint)(1 * 4)); // GrannyFileWrapper newModelFileWrapper = new GrannyFileWrapper(newModelFile); // void* m_info = newModelFileWrapper.m_info; // void** grannyMeshPtr = (void**)*(int*)((IntPtr)m_info + 56); // // Add all meshes from input file // *(int*)((IntPtr)m_info + 52) = 0; // Reset Mesh Count to 0 // for (int index = 0; index < inputFile.Meshes.Count; index++) // { // IGrannyMesh mesh = inputFile.Meshes[index]; // GrannyMeshWrapper meshWrapper = new GrannyMeshWrapper(mesh); // void* m_pkMesh = meshWrapper.m_pkMesh; // MemoryUtil.MemCpy((void*)*(int*)((IntPtr)m_info + 56), (void*)grannyMeshPtr, (uint)(*(int*)((IntPtr)m_info + 52) * 4)); // *(int*)(*(int*)((IntPtr)m_info + 56) + *(int*)((IntPtr)m_info + 52) * 4) = (int)m_pkMesh; // *(int*)((IntPtr)m_info + 52) = *(int*)((IntPtr)m_info + 52) + 1; // } // // Add mesh from append file // IGrannyMesh appendMesh = appendFile.Meshes[0]; // GrannyMeshWrapper appendMeshWrapper = new GrannyMeshWrapper(appendMesh); // void* m_pkAppendMesh = appendMeshWrapper.m_pkMesh; // MemoryUtil.MemCpy((void*)*(int*)((IntPtr)m_info + 56), (void*)grannyMeshPtr, (uint)(*(int*)((IntPtr)m_info + 52) * 4)); // *(int*)(*(int*)((IntPtr)m_info + 56) + *(int*)((IntPtr)m_info + 52) * 4) = (int)m_pkAppendMesh; // *(int*)((IntPtr)m_info + 52) = *(int*)((IntPtr)m_info + 52) + 1; //} public static IGrannyFile cleardownTemplate(GrannyContext grannyContext) { //string filename = sourceTemplatePath + "model_template.gr2"; IGrannyFile file = NexusBuddyApplicationForm.form.openFileAsTempFileCopy(NexusBuddyApplicationForm.form.modelTemplateFilename, "tempimport"); GrannyFileWrapper fileWrapper = new GrannyFileWrapper(file); //GrannyMeshWrapper meshWrapper = new GrannyMeshWrapper(file.Meshes[0]); //meshWrapper.setName("BLANK_MESH"); //meshWrapper.setNumVertices(0); //meshWrapper.setNumBoneBindings(0); //meshWrapper.setNumIndices(0); //meshWrapper.setNumIndices16(0); //meshWrapper.setGroup0TriCount(0); ////memProbe(meshWrapper.getBoneBindingsPtr()); //GrannyModelWrapper modelWrapper = new GrannyModelWrapper(file.Models[0]); //modelWrapper.setNumMeshBindings(1); //modelWrapper.setName("BLANK_MODEL"); //GrannySkeletonWrapper skeletonWrapper = new GrannySkeletonWrapper(modelWrapper.wrappedModel.Skeleton); //skeletonWrapper.setNumBones(0); //skeletonWrapper.setName("BLANK_SKELETON"); fileWrapper.setNumMeshes(0); //fileWrapper.setNumModels(0); fileWrapper.setNumVertexDatas(0); fileWrapper.setNumSkeletons(0); fileWrapper.setNumTriTopologies(0); fileWrapper.setNumMaterials(0); file.Meshes.Clear(); //fileWrapper.setFromFileName("My lovely lovely filename"); //fileWrapper.setFromArtToolName("Blender 2.49"); //fileWrapper.setExporterName("Nexus Buddy 2.0 beta 6"); return(file); }
public static void batchExport(GrannyContext grannyContext, string unitListFile) { StreamReader streamReader = new StreamReader(unitListFile); string directory = Path.GetDirectoryName(unitListFile); string regexString = "(.*);(.*);(.*);(.*)"; while (!streamReader.EndOfStream) { string currentLine = streamReader.ReadLine(); Regex regex = new Regex(regexString); MatchCollection mc = regex.Matches(currentLine); foreach (Match m in mc) { string gr2Filename = m.Groups[1].Value.Trim().ToLower(); IGrannyFile grannyFile = grannyContext.LoadGrannyFile(directory + "\\" + gr2Filename); NexusBuddyApplicationForm.loadedFile = grannyFile; NexusBuddyApplicationForm.form.refreshAppData(); exportAllModelsToNB2(grannyFile); } } }
public unsafe static void importBR2(string sourceFilename, string outputFilename, GrannyContext grannyContext) { IGrannyFile file = CivNexusSixApplicationForm.form.OpenFileAsTempFileCopy(CivNexusSixApplicationForm.form.modelTemplateFilename, "tempimport"); GrannyFileWrapper fileWrapper = new GrannyFileWrapper(file); fileWrapper.setNumMeshes(0); fileWrapper.setNumVertexDatas(0); fileWrapper.setNumSkeletons(0); fileWrapper.setNumTriTopologies(0); GrannyModelInfo modelInfo = loadModelInfo(sourceFilename); doBoneBindings(modelInfo); List <IGrannyFile> meshFileList = new List <IGrannyFile>(); foreach (GrannyMeshInfo meshInfo in modelInfo.meshBindings) { meshFileList.Add(writeMesh(meshInfo)); } IGrannyModel model = file.Models[0]; GrannyModelWrapper modelWrapper = new GrannyModelWrapper(model); modelWrapper.setNumMeshBindings(0); model.MeshBindings.Clear(); foreach (IGrannyFile meshFile in meshFileList) { doAppendMeshBinding(file, meshFile, 0); } fileWrapper.setNumMeshes(0); file.Meshes.Clear(); foreach (IGrannyMesh mesh in file.Models[0].MeshBindings) { file.AddMeshReference(mesh); } GrannySkeletonWrapper skeletonWrapper = new GrannySkeletonWrapper(file.Models[0].Skeleton); skeletonWrapper.writeSkeletonInfo(modelInfo.skeleton); string worldBoneName = modelInfo.skeleton.bones[0].name; modelWrapper.setName(worldBoneName); skeletonWrapper.setName(worldBoneName); fileWrapper.setFromArtToolInfo("Blender", 2, 0); float[] matrix = { 1f, 0f, 0f, 0f, 0f, 1f, 0f, -1f, 0f }; fileWrapper.setMatrix(matrix); CivNexusSixApplicationForm.SetExporterInfo(fileWrapper); fileWrapper.setFromFileName(sourceFilename); fileWrapper.addSkeletonPointer((int)skeletonWrapper.m_pkSkeleton); CivNexusSixApplicationForm.form.SaveAsAction(file, outputFilename, false); }
public unsafe static void overwriteMeshes(IGrannyFile file, string sourceFilename, GrannyContext grannyContext, Int32 currentModelIndex) { string filename = file.Filename; GrannyModelInfo modelInfo = loadModelInfo(sourceFilename); doBoneBindings(modelInfo); GrannyFileWrapper fileWrapper = new GrannyFileWrapper(file); List <IGrannyFile> meshFileList = new List <IGrannyFile>(); foreach (GrannyMeshInfo meshInfo in modelInfo.meshBindings) { meshFileList.Add(writeMesh(meshInfo)); } IGrannyModel model = file.Models[currentModelIndex]; GrannyModelWrapper modelWrapper = new GrannyModelWrapper(model); modelWrapper.setNumMeshBindings(0); model.MeshBindings.Clear(); foreach (IGrannyFile meshFile in meshFileList) { doAppendMeshBinding(grannyContext, file, meshFile, currentModelIndex); } fileWrapper.setNumMeshes(0); fileWrapper.setNumTriTopologies(0); fileWrapper.setNumVertexDatas(0); file.Meshes.Clear(); int meshesCount = 0; foreach (IGrannyModel loopModel in file.Models) { foreach (IGrannyMesh mesh in loopModel.MeshBindings) { file.AddMeshReference(mesh); meshesCount++; } } fileWrapper.setFromArtToolInfo("Blender", 2, 0); fileWrapper.setUnitsPerMeter(10.7f); NexusBuddyApplicationForm.setExporterInfo(fileWrapper); fileWrapper.setFromFileName(sourceFilename); fileWrapper.setNumMeshes(meshesCount); NexusBuddyApplicationForm.form.saveAsAction(file, filename, false); }
public UnitOfWork() { grannyContext = new GrannyContext(); }
public Repository(IUnitOfWork unitOfWork) { grannyContext = unitOfWork.grannyContext; ObjectSet = grannyContext.Set <T>(); }
public unsafe static void importCN6(string sourceFilename, string outputFilename, GrannyContext grannyContext, int vertexFormat) { string templateFilename = getTemplateFilename(vertexFormat); IGrannyFile file = CivNexusSixApplicationForm.form.OpenFileAsTempFileCopy(templateFilename, "tempimport"); GrannyFileWrapper fileWrapper = new GrannyFileWrapper(file); fileWrapper.setNumMeshes(0); fileWrapper.setNumVertexDatas(0); fileWrapper.setNumSkeletons(0); fileWrapper.setNumTriTopologies(0); List <GrannyModelInfo> modelInfos = loadModelInfos(sourceFilename, vertexFormat); fileWrapper.setNumMeshes(0); fileWrapper.setNumModels(0); foreach (GrannyModelInfo modelInfo in modelInfos) { doBoneBindings(modelInfo); List <IGrannyFile> meshFileList = new List <IGrannyFile>(); foreach (GrannyMeshInfo meshInfo in modelInfo.meshBindings) { meshFileList.Add(writeMesh(meshInfo, templateFilename)); } IGrannyFile modelFile = CivNexusSixApplicationForm.form.OpenFileAsTempFileCopy(templateFilename, "tempimport"); IGrannyModel model = modelFile.Models[0]; GrannyModelWrapper modelWrapper = new GrannyModelWrapper(model); modelWrapper.setNumMeshBindings(0); model.MeshBindings.Clear(); GrannySkeletonWrapper skeletonWrapper = new GrannySkeletonWrapper(modelFile.Models[0].Skeleton); skeletonWrapper.writeSkeletonInfo(modelInfo.skeleton); string worldBoneName = modelInfo.skeleton.bones[0].name; string modelName = worldBoneName; foreach (GrannyBoneInfo bone in modelInfo.skeleton.bones) { if (!bone.name.Contains("ADJUSTMENT_BONE")) { modelName = bone.name; break; } } modelWrapper.setName(modelName); skeletonWrapper.setName(modelName); foreach (IGrannyFile meshFile in meshFileList) { doAppendMeshBinding(modelFile, meshFile, 0); } foreach (IGrannyMesh mesh in model.MeshBindings) { file.AddMeshReference(mesh); } file.AddModelReference(model); CivNexusSixApplicationForm.form.RefreshAppData(); } fileWrapper.setNumModels(modelInfos.Count()); fileWrapper.setFromArtToolInfo("Blender", 2, 0); float[] matrix = { 1f, 0f, 0f, 0f, 0f, 1f, 0f, -1f, 0f }; fileWrapper.setMatrix(matrix); CivNexusSixApplicationForm.SetExporterInfo(fileWrapper); fileWrapper.setFromFileName(sourceFilename); createAndBindMaterials(outputFilename, file, modelInfos); }