Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public unsafe static void doAppendMeshBinding(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 * 8);
            int newMeshBindingsPtr = *(int *)inputModelWrapper.getMeshBindingsPtr();

            int modelMeshBindingsPtrAppend = *(int *)appendModelWrapper.getMeshBindingsPtr();

            if (meshCountInput > 0)
            {
                MemoryUtil.MemCpy((void *)newMeshBindingsPtr, (void *)oldMeshBindingsPtr, (uint)(meshCountInput * 8));
            }
            MemoryUtil.MemCpy((void *)(newMeshBindingsPtr + meshCountInput * 8), (void *)modelMeshBindingsPtrAppend, 8);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }