예제 #1
0
        /// <summary>
        /// Exports texture images and add references to the dae file.
        /// </summary>
        /// <param name="root">Root element.</param>
        /// <param name="dfMesh">DFMesh.</param>
        /// <returns>True if successful.</returns>
        private bool AddImages(ref _daeElement root, ref DFMesh dfMesh)
        {
            // Create <library_images>
            _daeElement imageLib = root.add("library_images");

            // Export all textures.
            foreach (var subMesh in dfMesh.SubMeshes)
            {
                // Construct string
                string materialName   = MakeMaterialName(subMesh.TextureArchive, subMesh.TextureRecord);
                string inputFilename  = TextureFile.IndexToFileName(subMesh.TextureArchive);
                string outputFilename = materialName + "." + imageFormat.ToString().ToLower();

                // Export texture
                string outputPath     = Path.Combine(modelOutputPath, imageOutputRelativePath);
                string outputFilePath = Path.Combine(outputPath, outputFilename);
                if (!File.Exists(outputFilePath))
                {
                    // Load texture file
                    textureFile.Load(
                        Path.Combine(arena2Path, inputFilename),
                        FileUsage.UseDisk,
                        true);

                    // Export image
                    Bitmap bm = textureFile.GetManagedBitmap(
                        subMesh.TextureRecord,
                        0,
                        false,
                        true);
                    bm.Save(outputFilePath, imageFormat);
                }

                // Add <image>
                string relativeOutputPath = Path.Combine(imageOutputRelativePath, outputFilename);
                relativeOutputPath = relativeOutputPath.Replace("\\", "/");
                _daeElement image = imageLib.add("image");
                image.setAttribute("id", materialName + "-image");
                image.add("init_from").setCharData(relativeOutputPath);
            }

            return(true);
        }