Example #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);
        }
Example #2
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);
        }