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 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 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); }
//// 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 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); }