Added Static Mesh Exporter from Pose with GLTF for 3d Printing Meshes#305
Open
benMcChesney wants to merge 15 commits intodonkeyProgramming:masterfrom
Open
Added Static Mesh Exporter from Pose with GLTF for 3d Printing Meshes#305benMcChesney wants to merge 15 commits intodonkeyProgramming:masterfrom
benMcChesney wants to merge 15 commits intodonkeyProgramming:masterfrom
Conversation
able to export to OBJ from a static pose of a rigid_pose_v2 model from TW3
Register and add an Rmv->OBJ exporter and its ViewModel, and update exporter logic and quick-export flow. Changes include: registering RmvToObjExporterViewModel in DI and adding RmvToObjExporterViewModel file; update RmvToObjExporter to use model names for exported normal/diffuse filenames, append a Kd line, and change export helper signatures to accept mesh/model name; enhance normal->height conversion with strength/contrast/blur parameters and a simple separable box blur implementation. Also harden QuickExportPosedMeshCommand: manage original mesh visibility, clone typed mesh nodes, temporarily replace LOD children for saving, handle saveResult and in-memory serialization to create PackFile bytes robustly, and restore scene state in a finally block. These changes improve filename consistency, material output, displacement generation quality, and reliability of quick exports.
Re-encode exported PNGs to high-quality 32bpp and apply mask premultiplication for diffuse textures. Adds System.Drawing.Drawing2D import, EnsurePngHighQuality helper to re-save PNGs with high-quality drawing and 32bpp settings, and PremultiplyDiffuseWithMask to combine an exported mask's luminance into diffuse alpha. Calls to re-encode normals, displacements, diffuse maps and exporter outputs were added (wrapped in try/catch to avoid breaking exports). Logging preserved and failures are ignored to keep exports resilient.
Fixes DDS color channel ordering and restructures texture export flow. - Correct Pfim BGRA/BGR -> Bitmap ARGB/RGB conversion in TextureHelper and AlphaMaskCombiner to ensure colors/alpha are written correctly. - DdsToNormalPng: save raw normal PNG and optionally produce a blue normal map variant; return appropriate output path. - GltfTextureHandler: stop combining diffuse+mask into a single RGBA; export mask as a separate inverted _mask.png, add explicit handling for mask textures, and add export of additional normal map variants (raw and offset). - Remove displacement map generation: drop IDdsToDisplacementMap registration and displacement generation from exporter and UI (RmvToGltfStaticExporter and ViewModel updated). - Minor cleanup: explicit System.IO using, fully-qualified ImageFormat usage, small whitespace fixes. - Remove obsolete Docs/Static_Mesh_Export_Guide.md. These changes resolve incorrect color channel outputs from Pfim, provide more explicit texture artifacts (raw/blue/offset normal maps and separate masks), and simplify the exporter by removing automatic displacement map generation.
Remove the optional blue normal-map conversion from DdsToNormalPngExporter — it now always saves the raw PNG and the ConvertToBlueNormalMap method and blue-file save path were removed. Add ExportDisplacementMapPng to GltfTextureHandler which reads the existing raw PNG, computes a height/displacement map by converting to luminance, applying iterative smoothing, contrast adjustment and sharpening, normalizes the result, and saves a *_displacement.png alongside the raw and offset outputs.
Generate displacement maps from normal textures and expose quality settings in the static GLTF exporter. Implemented ExportDisplacementFromNormalMap, improved raw/offset normal handling and alpha compositing, and added a displacement processing pipeline (standard, Poisson, multi-scale), contrast/sharpening, bilateral filtering and 8/16-bit export helpers. Added new RmvToGltfExporterSettings fields for displacement control, a new RmvToGltfStaticExporterView XAML + code-behind and updated RmvToGltfStaticExporterViewModel to surface settings and pass them to the exporter. Minor fix in RmvToGltfExporterView XAML whitespace.
Introduce a new ExportDisplacementMaps setting and gate displacement export behind it. When enabled, normal-map variants and displacement maps are generated (standard pipeline, optional 16-bit output, Poisson and multi-scale comparison variants), with contrast, bilateral sharpening and normalization steps. Poisson reconstruction was tuned (fewer iterations, reduced divergence weight) and multi-scale processing now uses the standard height-map backend. When disabled, the code falls back to the regular DDS->PNG normal exporter. Also update the static GLTF exporter ViewModel to rename the display to "GLTF for 3D Printing" and enable ExportDisplacementMaps by default for that workflow. File outputs include _raw.png, _displacement, _displacement_poisson and _displacement_multiscale variants.
When exporting base color textures, export an additional grayscale alpha mask PNG for 3D printing workflows. Adds a call in DoTextureDefault to ExportAlphaMask when settings.ExportDisplacementMaps is enabled and the texture is KnownChannel.BaseColor. Implements ExportAlphaMask to locate the source pack file, decode DDS via Pfim, verify RGBA32 format, extract the alpha channel into a black/white grayscale mask, and save it as <name>_alphamask.png next to the export output. The method includes early returns for missing services/files or unsupported formats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR includes a set of changes to make it easier to export game models for 3d printing. I added a "File > Advanced Export" in the 3d model preview to be able to export specific poses. Originally tried OBJ export but found GLTF higher quality. If the history is too messy happy to clean it up and resubmit.
Exporter and Builder Enhancements:
RmvToGltfStaticExporterViewModelandRmvToGltfStaticExporterto the dependency injection container, enabling static mesh export functionality.GltfStaticMeshBuilderfor static mesh construction, complementing the existingGltfMeshBuilder.Mesh Building Reliability:
GltfMeshBuilder.Buildand mesh generation logic to support models with or without skeletons, and to robustly handle meshes with partial or missing weight data. This prevents validation errors during GLTF export. [1] [2] [3]SetVertexInfluencesto handle all cases of vertex weight counts (1–4), normalize weights, and provide safe defaults for degenerate or malformed data.Texture Handling:
AlphaMaskCombiner, a helper class for combining a diffuse texture and a mask texture into a single RGBA PNG, using the mask as the alpha channel.Project Structure:
Export Output Consistency:
DdsToNormalPngExporterto output a file named with_raw.pngand removed the blue normal map conversion logic for simplification. [1] [2]Displacement Map Export:
Here's a few FDM prototypes, tested with Warhammer III models
